aboutsummaryrefslogtreecommitdiff
path: root/src/corelib/animation/widget/mwidgetmoveanimation.cpp
blob: 25a73db4bfec70bdcd90e1a8d149fc261bef2fdf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
/***************************************************************************
**
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (directui@nokia.com)
**
** This file is part of libmeegotouch.
**
** If you have questions regarding the use of this file, please contact
** Nokia at directui@nokia.com.
**
** This library is free software; you can redistribute it and/or
** modify it under the terms of the GNU Lesser General Public
** License version 2.1 as published by the Free Software Foundation
** and appearing in the file LICENSE.LGPL included in the packaging
** of this file.
**
****************************************************************************/

#include <QPauseAnimation>
#include <QPropertyAnimation>
#include <QSequentialAnimationGroup>

#include "mwidgetmoveanimation.h"
#include "mwidgetmoveanimation_p.h"
#include "mwidgetcontroller.h"

void MWidgetMoveAnimationPrivate::init()
{
    Q_Q(MWidgetMoveAnimation);

    widget = 0;

    QSequentialAnimationGroup *delayedAnimation = new QSequentialAnimationGroup;

    delay = new QPauseAnimation;
    delay->setDuration(q->style()->delay());
    positionAnimation = new QPropertyAnimation;
    positionAnimation->setPropertyName("pos");
    positionAnimation->setDuration(q->style()->duration());
    positionAnimation->setEasingCurve(q->style()->easingCurve());

    delayedAnimation->addAnimation(delay);
    delayedAnimation->addAnimation(positionAnimation);
    q->addAnimation(delayedAnimation);
}

MWidgetMoveAnimation::MWidgetMoveAnimation(QObject *parent) :
    MParallelAnimationGroup(new MWidgetMoveAnimationPrivate, parent)
{
    Q_D(MWidgetMoveAnimation);

    d->init();
}

MWidgetMoveAnimation::MWidgetMoveAnimation(MWidgetMoveAnimationPrivate *dd, QObject *parent) :
    MParallelAnimationGroup(dd, parent)
{
    Q_D(MWidgetMoveAnimation);

    d->init();
}

void MWidgetMoveAnimation::setWidget(MWidgetController *widget)
{
    Q_D(MWidgetMoveAnimation);

    d->widget = widget;
}

void MWidgetMoveAnimation::setFinalPos(const QPointF &pos)
{
    Q_D(MWidgetMoveAnimation);

    d->finalPos = pos;
}

void MWidgetMoveAnimation::updateState(QAbstractAnimation::State newState,
        QAbstractAnimation::State oldState)
{
    Q_D(MWidgetMoveAnimation);

    if (oldState == QAbstractAnimation::Stopped &&
        newState == QAbstractAnimation::Running)
    {
        d->positionAnimation->setTargetObject(d->widget);
        d->positionAnimation->setStartValue(d->widget->pos());
        d->positionAnimation->setEndValue(d->finalPos);
    }
}

#include "moc_mwidgetmoveanimation.cpp"