1 | /****************************************************************************
|
---|
2 | **
|
---|
3 | ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
---|
4 | ** Contact: Qt Software Information ([email protected])
|
---|
5 | **
|
---|
6 | ** This file is part of the demonstration applications of the Qt Toolkit.
|
---|
7 | **
|
---|
8 | ** $QT_BEGIN_LICENSE:LGPL$
|
---|
9 | ** Commercial Usage
|
---|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
---|
11 | ** accordance with the Qt Commercial License Agreement provided with the
|
---|
12 | ** Software or, alternatively, in accordance with the terms contained in
|
---|
13 | ** a written agreement between you and Nokia.
|
---|
14 | **
|
---|
15 | ** GNU Lesser General Public License Usage
|
---|
16 | ** Alternatively, this file may be used under the terms of the GNU Lesser
|
---|
17 | ** General Public License version 2.1 as published by the Free Software
|
---|
18 | ** Foundation and appearing in the file LICENSE.LGPL included in the
|
---|
19 | ** packaging of this file. Please review the following information to
|
---|
20 | ** ensure the GNU Lesser General Public License version 2.1 requirements
|
---|
21 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
---|
22 | **
|
---|
23 | ** In addition, as a special exception, Nokia gives you certain
|
---|
24 | ** additional rights. These rights are described in the Nokia Qt LGPL
|
---|
25 | ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
|
---|
26 | ** package.
|
---|
27 | **
|
---|
28 | ** GNU General Public License Usage
|
---|
29 | ** Alternatively, this file may be used under the terms of the GNU
|
---|
30 | ** General Public License version 3.0 as published by the Free Software
|
---|
31 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
---|
32 | ** packaging of this file. Please review the following information to
|
---|
33 | ** ensure the GNU General Public License version 3.0 requirements will be
|
---|
34 | ** met: http://www.gnu.org/copyleft/gpl.html.
|
---|
35 | **
|
---|
36 | ** If you are unsure which license is appropriate for your use, please
|
---|
37 | ** contact the sales department at [email protected].
|
---|
38 | ** $QT_END_LICENSE$
|
---|
39 | **
|
---|
40 | ****************************************************************************/
|
---|
41 |
|
---|
42 | #include "demoitemanimation.h"
|
---|
43 | #include "demoitem.h"
|
---|
44 | #include "colors.h"
|
---|
45 |
|
---|
46 | DemoItemAnimation::DemoItemAnimation(DemoItem *item, INOROUT inOrOut)
|
---|
47 | {
|
---|
48 | this->opacityAt0 = 1.0;
|
---|
49 | this->opacityAt1 = 1.0;
|
---|
50 | this->startDelay = 0;
|
---|
51 | this->inOrOut = inOrOut;
|
---|
52 | this->hideOnFinished = false;
|
---|
53 | this->forcePlay = false;
|
---|
54 | this->timeline = new QTimeLine(5000);
|
---|
55 | this->timeline->setFrameRange(0, 2000);
|
---|
56 | this->timeline->setUpdateInterval(int(1000.0/Colors::fps));
|
---|
57 | this->moveOnPlay = false;
|
---|
58 | setTimeLine(this->timeline);
|
---|
59 | setItem(item);
|
---|
60 | }
|
---|
61 |
|
---|
62 | DemoItemAnimation::~DemoItemAnimation()
|
---|
63 | {
|
---|
64 | // Do not delete demoitem. It is not
|
---|
65 | // owned by an animation
|
---|
66 | delete this->timeline;
|
---|
67 | }
|
---|
68 |
|
---|
69 | void DemoItemAnimation::prepare()
|
---|
70 | {
|
---|
71 | this->demoItem()->prepare();
|
---|
72 | }
|
---|
73 |
|
---|
74 | void DemoItemAnimation::setStartPos(const QPointF &pos){
|
---|
75 | this->startPos = pos;
|
---|
76 | }
|
---|
77 |
|
---|
78 | void DemoItemAnimation::setDuration(int duration)
|
---|
79 | {
|
---|
80 | duration = int(duration * Colors::animSpeed);
|
---|
81 | this->timeline->setDuration(duration);
|
---|
82 | this->moveOnPlay = true;
|
---|
83 | }
|
---|
84 |
|
---|
85 | void DemoItemAnimation::setCurrentTime(int ms)
|
---|
86 | {
|
---|
87 | this->timeline->setCurrentTime(ms);
|
---|
88 | }
|
---|
89 |
|
---|
90 | bool DemoItemAnimation::notOwnerOfItem()
|
---|
91 | {
|
---|
92 | return this != demoItem()->currentAnimation;
|
---|
93 | }
|
---|
94 |
|
---|
95 | void DemoItemAnimation::play(bool fromStart, bool force)
|
---|
96 | {
|
---|
97 | this->fromStart = fromStart;
|
---|
98 | this->forcePlay = force;
|
---|
99 |
|
---|
100 | QPointF currPos = this->demoItem()->pos();
|
---|
101 |
|
---|
102 | // If the item that this animation controls in currently under the
|
---|
103 | // control of another animation, stop that animation first
|
---|
104 | if (this->demoItem()->currentAnimation)
|
---|
105 | this->demoItem()->currentAnimation->timeline->stop();
|
---|
106 | this->demoItem()->currentAnimation = this;
|
---|
107 | this->timeline->stop();
|
---|
108 |
|
---|
109 | if (Colors::noAnimations && !this->forcePlay){
|
---|
110 | this->timeline->setCurrentTime(1);
|
---|
111 | this->demoItem()->setPos(this->posAt(1));
|
---|
112 | }
|
---|
113 | else{
|
---|
114 | if (this->demoItem()->isVisible())
|
---|
115 | // If the item is already visible, start the animation from
|
---|
116 | // the items current position rather than from start.
|
---|
117 | this->setPosAt(0.0, currPos);
|
---|
118 | else
|
---|
119 | this->setPosAt(0.0, this->startPos);
|
---|
120 |
|
---|
121 | if (this->fromStart){
|
---|
122 | this->timeline->setCurrentTime(0);
|
---|
123 | this->demoItem()->setPos(this->posAt(0));
|
---|
124 | }
|
---|
125 | }
|
---|
126 |
|
---|
127 | if (this->inOrOut == ANIM_IN)
|
---|
128 | this->demoItem()->setRecursiveVisible(true);
|
---|
129 |
|
---|
130 | if (this->startDelay){
|
---|
131 | QTimer::singleShot(this->startDelay, this, SLOT(playWithoutDelay()));
|
---|
132 | return;
|
---|
133 | }
|
---|
134 | else
|
---|
|
---|