src/declarative/util/qdeclarativeanimation_p.h
changeset 30 5dc02b23752f
child 33 3e2da88830cd
equal deleted inserted replaced
29:b72c6db6890b 30:5dc02b23752f
       
     1 /****************************************************************************
       
     2 **
       
     3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
       
     4 ** All rights reserved.
       
     5 ** Contact: Nokia Corporation (qt-info@nokia.com)
       
     6 **
       
     7 ** This file is part of the QtDeclarative module of the Qt Toolkit.
       
     8 **
       
     9 ** $QT_BEGIN_LICENSE:LGPL$
       
    10 ** No Commercial Usage
       
    11 ** This file contains pre-release code and may not be distributed.
       
    12 ** You may use this file in accordance with the terms and conditions
       
    13 ** contained in the Technology Preview License Agreement accompanying
       
    14 ** this package.
       
    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 ** If you have questions regarding the use of this file, please contact
       
    29 ** Nokia at qt-info@nokia.com.
       
    30 **
       
    31 **
       
    32 **
       
    33 **
       
    34 **
       
    35 **
       
    36 **
       
    37 **
       
    38 ** $QT_END_LICENSE$
       
    39 **
       
    40 ****************************************************************************/
       
    41 
       
    42 #ifndef QDECLARATIVEANIMATION_H
       
    43 #define QDECLARATIVEANIMATION_H
       
    44 
       
    45 #include "private/qdeclarativetransition_p.h"
       
    46 #include "private/qdeclarativestate_p.h"
       
    47 #include <QtGui/qvector3d.h>
       
    48 
       
    49 #include <qdeclarativepropertyvaluesource.h>
       
    50 #include <qdeclarative.h>
       
    51 #include <qdeclarativescriptstring.h>
       
    52 
       
    53 #include <QtCore/qvariant.h>
       
    54 #include <QtCore/qeasingcurve.h>
       
    55 #include <QtCore/QAbstractAnimation>
       
    56 #include <QtGui/qcolor.h>
       
    57 
       
    58 QT_BEGIN_HEADER
       
    59 
       
    60 QT_BEGIN_NAMESPACE
       
    61 
       
    62 QT_MODULE(Declarative)
       
    63 
       
    64 class QDeclarativeAbstractAnimationPrivate;
       
    65 class QDeclarativeAnimationGroup;
       
    66 class Q_AUTOTEST_EXPORT QDeclarativeAbstractAnimation : public QObject, public QDeclarativePropertyValueSource, public QDeclarativeParserStatus
       
    67 {
       
    68     Q_OBJECT
       
    69     Q_DECLARE_PRIVATE(QDeclarativeAbstractAnimation)
       
    70 
       
    71     Q_INTERFACES(QDeclarativeParserStatus)
       
    72     Q_INTERFACES(QDeclarativePropertyValueSource)
       
    73     Q_ENUMS(Loops)
       
    74     Q_PROPERTY(bool running READ isRunning WRITE setRunning NOTIFY runningChanged)
       
    75     Q_PROPERTY(bool paused READ isPaused WRITE setPaused NOTIFY pausedChanged)
       
    76     Q_PROPERTY(bool alwaysRunToEnd READ alwaysRunToEnd WRITE setAlwaysRunToEnd NOTIFY alwaysRunToEndChanged)
       
    77     Q_PROPERTY(int loops READ loops WRITE setLoops NOTIFY loopsChanged)
       
    78     Q_CLASSINFO("DefaultMethod", "start()")
       
    79 
       
    80 public:
       
    81     QDeclarativeAbstractAnimation(QObject *parent=0);
       
    82     virtual ~QDeclarativeAbstractAnimation();
       
    83 
       
    84     enum Loops { Infinite = -2 };
       
    85 
       
    86     bool isRunning() const;
       
    87     void setRunning(bool);
       
    88     bool isPaused() const;
       
    89     void setPaused(bool);
       
    90     bool alwaysRunToEnd() const;
       
    91     void setAlwaysRunToEnd(bool);
       
    92 
       
    93     int loops() const;
       
    94     void setLoops(int);
       
    95 
       
    96     int currentTime();
       
    97     void setCurrentTime(int);
       
    98 
       
    99     QDeclarativeAnimationGroup *group() const;
       
   100     void setGroup(QDeclarativeAnimationGroup *);
       
   101 
       
   102     void setDefaultTarget(const QDeclarativeProperty &);
       
   103     void setDisableUserControl();
       
   104 
       
   105     void classBegin();
       
   106     void componentComplete();
       
   107 
       
   108 Q_SIGNALS:
       
   109     void started();
       
   110     void completed();
       
   111     void runningChanged(bool);
       
   112     void pausedChanged(bool);
       
   113     void alwaysRunToEndChanged(bool);
       
   114     void loopCountChanged(int);
       
   115 
       
   116 public Q_SLOTS:
       
   117     void restart();
       
   118     void start();
       
   119     void pause();
       
   120     void resume();
       
   121     void stop();
       
   122     void complete();
       
   123 
       
   124 protected:
       
   125     QDeclarativeAbstractAnimation(QDeclarativeAbstractAnimationPrivate &dd, QObject *parent);
       
   126 
       
   127 public:
       
   128     enum TransitionDirection { Forward, Backward };
       
   129     virtual void transition(QDeclarativeStateActions &actions,
       
   130                             QDeclarativeProperties &modified,
       
   131                             TransitionDirection direction);
       
   132     virtual QAbstractAnimation *qtAnimation() = 0;
       
   133 
       
   134 private Q_SLOTS:
       
   135     void timelineComplete();
       
   136     void componentFinalized();
       
   137 
       
   138 private:
       
   139     virtual void setTarget(const QDeclarativeProperty &);
       
   140 };
       
   141 
       
   142 class QDeclarativePauseAnimationPrivate;
       
   143 class Q_AUTOTEST_EXPORT QDeclarativePauseAnimation : public QDeclarativeAbstractAnimation
       
   144 {
       
   145     Q_OBJECT
       
   146     Q_DECLARE_PRIVATE(QDeclarativePauseAnimation)
       
   147 
       
   148     Q_PROPERTY(int duration READ duration WRITE setDuration NOTIFY durationChanged)
       
   149 
       
   150 public:
       
   151     QDeclarativePauseAnimation(QObject *parent=0);
       
   152     virtual ~QDeclarativePauseAnimation();
       
   153 
       
   154     int duration() const;
       
   155     void setDuration(int);
       
   156 
       
   157 Q_SIGNALS:
       
   158     void durationChanged(int);
       
   159 
       
   160 protected:
       
   161     virtual QAbstractAnimation *qtAnimation();
       
   162 };
       
   163 
       
   164 class QDeclarativeScriptActionPrivate;
       
   165 class QDeclarativeScriptAction : public QDeclarativeAbstractAnimation
       
   166 {
       
   167     Q_OBJECT
       
   168     Q_DECLARE_PRIVATE(QDeclarativeScriptAction)
       
   169 
       
   170     Q_PROPERTY(QDeclarativeScriptString script READ script WRITE setScript)
       
   171     Q_PROPERTY(QString scriptName READ stateChangeScriptName WRITE setStateChangeScriptName)
       
   172 
       
   173 public:
       
   174     QDeclarativeScriptAction(QObject *parent=0);
       
   175     virtual ~QDeclarativeScriptAction();
       
   176 
       
   177     QDeclarativeScriptString script() const;
       
   178     void setScript(const QDeclarativeScriptString &);
       
   179 
       
   180     QString stateChangeScriptName() const;
       
   181     void setStateChangeScriptName(const QString &);
       
   182 
       
   183 protected:
       
   184     virtual void transition(QDeclarativeStateActions &actions,
       
   185                             QDeclarativeProperties &modified,
       
   186                             TransitionDirection direction);
       
   187     virtual QAbstractAnimation *qtAnimation();
       
   188 };
       
   189 
       
   190 class QDeclarativePropertyActionPrivate;
       
   191 class QDeclarativePropertyAction : public QDeclarativeAbstractAnimation
       
   192 {
       
   193     Q_OBJECT
       
   194     Q_DECLARE_PRIVATE(QDeclarativePropertyAction)
       
   195 
       
   196     Q_PROPERTY(QObject *target READ target WRITE setTarget NOTIFY targetChanged)
       
   197     Q_PROPERTY(QString property READ property WRITE setProperty NOTIFY targetChanged)
       
   198     Q_PROPERTY(QString properties READ properties WRITE setProperties NOTIFY propertiesChanged)
       
   199     Q_PROPERTY(QDeclarativeListProperty<QObject> targets READ targets)
       
   200     Q_PROPERTY(QDeclarativeListProperty<QObject> exclude READ exclude)
       
   201     Q_PROPERTY(QVariant value READ value WRITE setValue NOTIFY valueChanged)
       
   202 
       
   203 public:
       
   204     QDeclarativePropertyAction(QObject *parent=0);
       
   205     virtual ~QDeclarativePropertyAction();
       
   206 
       
   207     QObject *target() const;
       
   208     void setTarget(QObject *);
       
   209 
       
   210     QString property() const;
       
   211     void setProperty(const QString &);
       
   212 
       
   213     QString properties() const;
       
   214     void setProperties(const QString &);
       
   215 
       
   216     QDeclarativeListProperty<QObject> targets();
       
   217     QDeclarativeListProperty<QObject> exclude();
       
   218 
       
   219     QVariant value() const;
       
   220     void setValue(const QVariant &);
       
   221 
       
   222 Q_SIGNALS:
       
   223     void valueChanged(const QVariant &);
       
   224     void propertiesChanged(const QString &);
       
   225     void targetChanged(QObject *, const QString &);
       
   226 
       
   227 protected:
       
   228     virtual void transition(QDeclarativeStateActions &actions,
       
   229                             QDeclarativeProperties &modified,
       
   230                             TransitionDirection direction);
       
   231     virtual QAbstractAnimation *qtAnimation();
       
   232 };
       
   233 
       
   234 class QDeclarativeItem;
       
   235 class QDeclarativePropertyAnimationPrivate;
       
   236 class Q_AUTOTEST_EXPORT QDeclarativePropertyAnimation : public QDeclarativeAbstractAnimation
       
   237 {
       
   238     Q_OBJECT
       
   239     Q_DECLARE_PRIVATE(QDeclarativePropertyAnimation)
       
   240 
       
   241     Q_PROPERTY(int duration READ duration WRITE setDuration NOTIFY durationChanged)
       
   242     Q_PROPERTY(QVariant from READ from WRITE setFrom NOTIFY fromChanged)
       
   243     Q_PROPERTY(QVariant to READ to WRITE setTo NOTIFY toChanged)
       
   244     Q_PROPERTY(QEasingCurve easing READ easing WRITE setEasing NOTIFY easingChanged)
       
   245     Q_PROPERTY(QObject *target READ target WRITE setTarget NOTIFY targetChanged)
       
   246     Q_PROPERTY(QString property READ property WRITE setProperty NOTIFY targetChanged)
       
   247     Q_PROPERTY(QString properties READ properties WRITE setProperties NOTIFY propertiesChanged)
       
   248     Q_PROPERTY(QDeclarativeListProperty<QObject> targets READ targets)
       
   249     Q_PROPERTY(QDeclarativeListProperty<QObject> exclude READ exclude)
       
   250 
       
   251 public:
       
   252     QDeclarativePropertyAnimation(QObject *parent=0);
       
   253     virtual ~QDeclarativePropertyAnimation();
       
   254 
       
   255     virtual int duration() const;
       
   256     virtual void setDuration(int);
       
   257 
       
   258     QVariant from() const;
       
   259     void setFrom(const QVariant &);
       
   260 
       
   261     QVariant to() const;
       
   262     void setTo(const QVariant &);
       
   263 
       
   264     QEasingCurve easing() const;
       
   265     void setEasing(const QEasingCurve &);
       
   266 
       
   267     QObject *target() const;
       
   268     void setTarget(QObject *);
       
   269 
       
   270     QString property() const;
       
   271     void setProperty(const QString &);
       
   272 
       
   273     QString properties() const;
       
   274     void setProperties(const QString &);
       
   275 
       
   276     QDeclarativeListProperty<QObject> targets();
       
   277     QDeclarativeListProperty<QObject> exclude();
       
   278 
       
   279 protected:
       
   280     QDeclarativePropertyAnimation(QDeclarativePropertyAnimationPrivate &dd, QObject *parent);
       
   281     virtual void transition(QDeclarativeStateActions &actions,
       
   282                             QDeclarativeProperties &modified,
       
   283                             TransitionDirection direction);
       
   284     virtual QAbstractAnimation *qtAnimation();
       
   285 
       
   286 Q_SIGNALS:
       
   287     void durationChanged(int);
       
   288     void fromChanged(QVariant);
       
   289     void toChanged(QVariant);
       
   290     void easingChanged(const QEasingCurve &);
       
   291     void propertiesChanged(const QString &);
       
   292     void targetChanged(QObject *, const QString &);
       
   293 };
       
   294 
       
   295 class Q_AUTOTEST_EXPORT QDeclarativeColorAnimation : public QDeclarativePropertyAnimation
       
   296 {
       
   297     Q_OBJECT
       
   298     Q_DECLARE_PRIVATE(QDeclarativePropertyAnimation)
       
   299     Q_PROPERTY(QColor from READ from WRITE setFrom NOTIFY fromChanged)
       
   300     Q_PROPERTY(QColor to READ to WRITE setTo NOTIFY toChanged)
       
   301 
       
   302 public:
       
   303     QDeclarativeColorAnimation(QObject *parent=0);
       
   304     virtual ~QDeclarativeColorAnimation();
       
   305 
       
   306     QColor from() const;
       
   307     void setFrom(const QColor &);
       
   308 
       
   309     QColor to() const;
       
   310     void setTo(const QColor &);
       
   311 };
       
   312 
       
   313 class Q_AUTOTEST_EXPORT QDeclarativeNumberAnimation : public QDeclarativePropertyAnimation
       
   314 {
       
   315     Q_OBJECT
       
   316     Q_DECLARE_PRIVATE(QDeclarativePropertyAnimation)
       
   317 
       
   318     Q_PROPERTY(qreal from READ from WRITE setFrom NOTIFY fromChanged)
       
   319     Q_PROPERTY(qreal to READ to WRITE setTo NOTIFY toChanged)
       
   320 
       
   321 public:
       
   322     QDeclarativeNumberAnimation(QObject *parent=0);
       
   323     virtual ~QDeclarativeNumberAnimation();
       
   324 
       
   325     qreal from() const;
       
   326     void setFrom(qreal);
       
   327 
       
   328     qreal to() const;
       
   329     void setTo(qreal);
       
   330 
       
   331 protected:
       
   332     QDeclarativeNumberAnimation(QDeclarativePropertyAnimationPrivate &dd, QObject *parent);
       
   333 
       
   334 private:
       
   335     void init();
       
   336 };
       
   337 
       
   338 class Q_AUTOTEST_EXPORT QDeclarativeVector3dAnimation : public QDeclarativePropertyAnimation
       
   339 {
       
   340     Q_OBJECT
       
   341     Q_DECLARE_PRIVATE(QDeclarativePropertyAnimation)
       
   342 
       
   343     Q_PROPERTY(QVector3D from READ from WRITE setFrom NOTIFY fromChanged)
       
   344     Q_PROPERTY(QVector3D to READ to WRITE setTo NOTIFY toChanged)
       
   345 
       
   346 public:
       
   347     QDeclarativeVector3dAnimation(QObject *parent=0);
       
   348     virtual ~QDeclarativeVector3dAnimation();
       
   349 
       
   350     QVector3D from() const;
       
   351     void setFrom(QVector3D);
       
   352 
       
   353     QVector3D to() const;
       
   354     void setTo(QVector3D);
       
   355 };
       
   356 
       
   357 class QDeclarativeRotationAnimationPrivate;
       
   358 class Q_AUTOTEST_EXPORT QDeclarativeRotationAnimation : public QDeclarativePropertyAnimation
       
   359 {
       
   360     Q_OBJECT
       
   361     Q_DECLARE_PRIVATE(QDeclarativeRotationAnimation)
       
   362     Q_ENUMS(RotationDirection)
       
   363 
       
   364     Q_PROPERTY(qreal from READ from WRITE setFrom NOTIFY fromChanged)
       
   365     Q_PROPERTY(qreal to READ to WRITE setTo NOTIFY toChanged)
       
   366     Q_PROPERTY(RotationDirection direction READ direction WRITE setDirection NOTIFY directionChanged)
       
   367 
       
   368 public:
       
   369     QDeclarativeRotationAnimation(QObject *parent=0);
       
   370     virtual ~QDeclarativeRotationAnimation();
       
   371 
       
   372     qreal from() const;
       
   373     void setFrom(qreal);
       
   374 
       
   375     qreal to() const;
       
   376     void setTo(qreal);
       
   377 
       
   378     enum RotationDirection { Numerical, Shortest, Clockwise, Counterclockwise };
       
   379     RotationDirection direction() const;
       
   380     void setDirection(RotationDirection direction);
       
   381 
       
   382 Q_SIGNALS:
       
   383     void directionChanged();
       
   384 };
       
   385 
       
   386 class QDeclarativeAnimationGroupPrivate;
       
   387 class QDeclarativeAnimationGroup : public QDeclarativeAbstractAnimation
       
   388 {
       
   389     Q_OBJECT
       
   390     Q_DECLARE_PRIVATE(QDeclarativeAnimationGroup)
       
   391 
       
   392     Q_CLASSINFO("DefaultProperty", "animations")
       
   393     Q_PROPERTY(QDeclarativeListProperty<QDeclarativeAbstractAnimation> animations READ animations)
       
   394 
       
   395 public:
       
   396     QDeclarativeAnimationGroup(QObject *parent);
       
   397     virtual ~QDeclarativeAnimationGroup();
       
   398 
       
   399     QDeclarativeListProperty<QDeclarativeAbstractAnimation> animations();
       
   400     friend class QDeclarativeAbstractAnimation;
       
   401 
       
   402 protected:
       
   403     QDeclarativeAnimationGroup(QDeclarativeAnimationGroupPrivate &dd, QObject *parent);
       
   404 };
       
   405 
       
   406 class QDeclarativeSequentialAnimation : public QDeclarativeAnimationGroup
       
   407 {
       
   408     Q_OBJECT
       
   409     Q_DECLARE_PRIVATE(QDeclarativeAnimationGroup)
       
   410 
       
   411 public:
       
   412     QDeclarativeSequentialAnimation(QObject *parent=0);
       
   413     virtual ~QDeclarativeSequentialAnimation();
       
   414 
       
   415 protected:
       
   416     virtual void transition(QDeclarativeStateActions &actions,
       
   417                             QDeclarativeProperties &modified,
       
   418                             TransitionDirection direction);
       
   419     virtual QAbstractAnimation *qtAnimation();
       
   420 };
       
   421 
       
   422 class QDeclarativeParallelAnimation : public QDeclarativeAnimationGroup
       
   423 {
       
   424     Q_OBJECT
       
   425     Q_DECLARE_PRIVATE(QDeclarativeAnimationGroup)
       
   426 
       
   427 public:
       
   428     QDeclarativeParallelAnimation(QObject *parent=0);
       
   429     virtual ~QDeclarativeParallelAnimation();
       
   430 
       
   431 protected:
       
   432     virtual void transition(QDeclarativeStateActions &actions,
       
   433                             QDeclarativeProperties &modified,
       
   434                             TransitionDirection direction);
       
   435     virtual QAbstractAnimation *qtAnimation();
       
   436 };
       
   437 
       
   438 class QDeclarativeParentAnimationPrivate;
       
   439 class QDeclarativeParentAnimation : public QDeclarativeAnimationGroup
       
   440 {
       
   441     Q_OBJECT
       
   442     Q_DECLARE_PRIVATE(QDeclarativeParentAnimation)
       
   443 
       
   444     Q_PROPERTY(QDeclarativeItem *target READ target WRITE setTarget NOTIFY targetChanged)
       
   445     Q_PROPERTY(QDeclarativeItem *newParent READ newParent WRITE setNewParent NOTIFY newParentChanged)
       
   446     Q_PROPERTY(QDeclarativeItem *via READ via WRITE setVia NOTIFY viaChanged)
       
   447 
       
   448 public:
       
   449     QDeclarativeParentAnimation(QObject *parent=0);
       
   450     virtual ~QDeclarativeParentAnimation();
       
   451 
       
   452     QDeclarativeItem *target() const;
       
   453     void setTarget(QDeclarativeItem *);
       
   454 
       
   455     QDeclarativeItem *newParent() const;
       
   456     void setNewParent(QDeclarativeItem *);
       
   457 
       
   458     QDeclarativeItem *via() const;
       
   459     void setVia(QDeclarativeItem *);
       
   460 
       
   461 Q_SIGNALS:
       
   462     void targetChanged();
       
   463     void newParentChanged();
       
   464     void viaChanged();
       
   465 
       
   466 protected:
       
   467     virtual void transition(QDeclarativeStateActions &actions,
       
   468                             QDeclarativeProperties &modified,
       
   469                             TransitionDirection direction);
       
   470     virtual QAbstractAnimation *qtAnimation();
       
   471 };
       
   472 
       
   473 class QDeclarativeAnchorAnimationPrivate;
       
   474 class QDeclarativeAnchorAnimation : public QDeclarativeAbstractAnimation
       
   475 {
       
   476     Q_OBJECT
       
   477     Q_DECLARE_PRIVATE(QDeclarativeAnchorAnimation)
       
   478     Q_PROPERTY(QDeclarativeListProperty<QDeclarativeItem> targets READ targets)
       
   479     Q_PROPERTY(int duration READ duration WRITE setDuration NOTIFY durationChanged)
       
   480     Q_PROPERTY(QEasingCurve easing READ easing WRITE setEasing NOTIFY easingChanged)
       
   481 
       
   482 public:
       
   483     QDeclarativeAnchorAnimation(QObject *parent=0);
       
   484     virtual ~QDeclarativeAnchorAnimation();
       
   485 
       
   486     QDeclarativeListProperty<QDeclarativeItem> targets();
       
   487 
       
   488     int duration() const;
       
   489     void setDuration(int);
       
   490 
       
   491     QEasingCurve easing() const;
       
   492     void setEasing(const QEasingCurve &);
       
   493 
       
   494 Q_SIGNALS:
       
   495     void durationChanged(int);
       
   496     void easingChanged(const QEasingCurve&);
       
   497 
       
   498 protected:
       
   499     virtual void transition(QDeclarativeStateActions &actions,
       
   500                             QDeclarativeProperties &modified,
       
   501                             TransitionDirection direction);
       
   502     virtual QAbstractAnimation *qtAnimation();
       
   503 };
       
   504 
       
   505 QT_END_NAMESPACE
       
   506 
       
   507 QML_DECLARE_TYPE(QDeclarativeAbstractAnimation)
       
   508 QML_DECLARE_TYPE(QDeclarativePauseAnimation)
       
   509 QML_DECLARE_TYPE(QDeclarativeScriptAction)
       
   510 QML_DECLARE_TYPE(QDeclarativePropertyAction)
       
   511 QML_DECLARE_TYPE(QDeclarativePropertyAnimation)
       
   512 QML_DECLARE_TYPE(QDeclarativeColorAnimation)
       
   513 QML_DECLARE_TYPE(QDeclarativeNumberAnimation)
       
   514 QML_DECLARE_TYPE(QDeclarativeSequentialAnimation)
       
   515 QML_DECLARE_TYPE(QDeclarativeParallelAnimation)
       
   516 QML_DECLARE_TYPE(QDeclarativeVector3dAnimation)
       
   517 QML_DECLARE_TYPE(QDeclarativeRotationAnimation)
       
   518 QML_DECLARE_TYPE(QDeclarativeParentAnimation)
       
   519 QML_DECLARE_TYPE(QDeclarativeAnchorAnimation)
       
   520 
       
   521 QT_END_HEADER
       
   522 
       
   523 #endif // QDECLARATIVEANIMATION_H