[556] | 1 | /****************************************************************************
|
---|
| 2 | **
|
---|
| 3 | ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
---|
| 4 | ** All rights reserved.
|
---|
| 5 | ** Contact: Nokia Corporation ([email protected])
|
---|
| 6 | **
|
---|
| 7 | ** This file is part of the QtGui module of the Qt Toolkit.
|
---|
| 8 | **
|
---|
| 9 | ** $QT_BEGIN_LICENSE:LGPL$
|
---|
| 10 | ** Commercial Usage
|
---|
| 11 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
---|
| 12 | ** accordance with the Qt Commercial License Agreement provided with the
|
---|
| 13 | ** Software or, alternatively, in accordance with the terms contained in
|
---|
| 14 | ** a written agreement between you and Nokia.
|
---|
| 15 | **
|
---|
| 16 | ** GNU Lesser General Public License Usage
|
---|
| 17 | ** Alternatively, this file may be used under the terms of the GNU Lesser
|
---|
| 18 | ** General Public License version 2.1 as published by the Free Software
|
---|
| 19 | ** Foundation and appearing in the file LICENSE.LGPL included in the
|
---|
| 20 | ** packaging of this file. Please review the following information to
|
---|
| 21 | ** ensure the GNU Lesser General Public License version 2.1 requirements
|
---|
| 22 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
---|
| 23 | **
|
---|
| 24 | ** In addition, as a special exception, Nokia gives you certain additional
|
---|
| 25 | ** rights. These rights are described in the Nokia Qt LGPL Exception
|
---|
| 26 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this 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 have questions regarding the use of this file, please contact
|
---|
| 37 | ** Nokia at [email protected].
|
---|
| 38 | ** $QT_END_LICENSE$
|
---|
| 39 | **
|
---|
| 40 | ****************************************************************************/
|
---|
| 41 |
|
---|
| 42 | #include "qanimationstate.h"
|
---|
| 43 |
|
---|
| 44 | #include <QtCore/qstate.h>
|
---|
| 45 |
|
---|
| 46 | QT_BEGIN_NAMESPACE
|
---|
| 47 |
|
---|
| 48 | /*!
|
---|
| 49 | \class QAnimationState
|
---|
| 50 |
|
---|
| 51 | \brief The QAnimationState class provides state that handle an animation and emit
|
---|
| 52 | a signal when this animation is finished.
|
---|
| 53 |
|
---|
| 54 | \ingroup statemachine
|
---|
| 55 |
|
---|
| 56 | QAnimationState provides a state that handle an animation. It will start this animation
|
---|
| 57 | when the state is entered and stop it when it is leaved. When the animation has finished the
|
---|
| 58 | state emit animationFinished signal.
|
---|
| 59 | QAnimationState is part of \l{The State Machine Framework}.
|
---|
| 60 |
|
---|
| 61 | \code
|
---|
| 62 | QStateMachine machine;
|
---|
| 63 | QAnimationState *s = new QAnimationState(machine->rootState());
|
---|
| 64 | QPropertyAnimation *animation = new QPropertyAnimation(obj, "pos");
|
---|
| 65 | s->setAnimation(animation);
|
---|
| 66 | QState *s2 = new QState(machine->rootState());
|
---|
| 67 | s->addTransition(s, SIGNAL(animationFinished()), s2);
|
---|
| 68 | machine.start();
|
---|
| 69 | \endcode
|
---|
| 70 |
|
---|
| 71 | \sa QState, {The Animation Framework}
|
---|
| 72 | */
|
---|
| 73 |
|
---|
| 74 |
|
---|
| 75 | #ifndef QT_NO_ANIMATION
|
---|
| 76 |
|
---|
| 77 | /*!
|
---|
| 78 | Constructs a new state with the given \a parent state.
|
---|
| 79 | */
|
---|
| 80 | QAnimationState::QAnimationState(QState *parent)
|
---|
| 81 | : QState(parent), m_animation(0)
|
---|
| 82 | {
|
---|
| 83 | }
|
---|
| 84 |
|
---|
| 85 | /*!
|
---|
| 86 | Destroys the animation state.
|
---|
| 87 | */
|
---|
| 88 | QAnimationState::~QAnimationState()
|
---|
| 89 | {
|
---|
| 90 | }
|
---|
| 91 |
|
---|
| 92 | /*!
|
---|
| 93 | Set an \a animation for this QAnimationState. If an animation was previously handle by this
|
---|
| 94 | state then it won't emit animationFinished for the old animation. The QAnimationState doesn't
|
---|
| 95 | take the ownership of the animation.
|
---|
| 96 | */
|
---|
| 97 | void QAnimationState::setAnimation(QAbstractAnimation *animation)
|
---|
| 98 | {
|
---|
| 99 | if (animation == m_animation)
|
---|
| 100 | return;
|
---|
| 101 |
|
---|
| 102 | //Disconnect from the previous animation if exist
|
---|
| 103 | if(m_animation)
|
---|
| 104 | disconnect(m_animation, SIGNAL(finished()), this, SIGNAL(animationFinished()));
|
---|
| 105 |
|
---|
| 106 | m_animation = animation;
|
---|
| 107 |
|
---|
| 108 | if (m_animation) {
|
---|
| 109 | //connect the new animation
|
---|
| 110 | connect(m_animation, SIGNAL(finished()), this, SIGNAL(animationFinished()));
|
---|
| 111 | }
|
---|
| 112 | }
|
---|
| 113 |
|
---|
| 114 | /*!
|
---|
| 115 | Returns the animation handle by this animation state, or 0 if there is no animation.
|
---|
| 116 | */
|
---|
| 117 | QAbstractAnimation* QAnimationState::animation() const
|
---|
| 118 | {
|
---|
| 119 | return m_animation;
|
---|
| 120 | }
|
---|
| 121 |
|
---|
| 122 | /*!
|
---|
| 123 | \reimp
|
---|
| 124 | */
|
---|
| 125 | void QAnimationState::onEntry(QEvent *)
|
---|
| 126 | {
|
---|
| 127 | if (m_animation)
|
---|
| 128 | m_animation->start();
|
---|
| 129 | }
|
---|
| 130 |
|
---|
| 131 | /*!
|
---|
| 132 | \reimp
|
---|
| 133 | */
|
---|
| 134 | void QAnimationState::onExit(QEvent *)
|
---|
| 135 | {
|
---|
| 136 | if (m_animation)
|
---|
| 137 | m_animation->stop();
|
---|
| 138 | }
|
---|
| 139 |
|
---|
| 140 | /*!
|
---|
| 141 | \reimp
|
---|
| 142 | */
|
---|
| 143 | bool QAnimationState::event(QEvent *e)
|
---|
| 144 | {
|
---|
| 145 | return QState::event(e);
|
---|
| 146 | }
|
---|
| 147 |
|
---|
| 148 | QT_END_NAMESPACE
|
---|
| 149 |
|
---|
| 150 | #endif
|
---|