src/declarative/util/qdeclarativestate_p.h
branchGCC_SURGE
changeset 31 5daf16870df6
parent 30 5dc02b23752f
child 33 3e2da88830cd
equal deleted inserted replaced
27:93b982ccede2 31:5daf16870df6
       
     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 QDECLARATIVESTATE_H
       
    43 #define QDECLARATIVESTATE_H
       
    44 
       
    45 #include <qdeclarative.h>
       
    46 #include <qdeclarativeproperty.h>
       
    47 #include <QtCore/qobject.h>
       
    48 
       
    49 QT_BEGIN_HEADER
       
    50 
       
    51 QT_BEGIN_NAMESPACE
       
    52 
       
    53 QT_MODULE(Declarative)
       
    54 
       
    55 class QDeclarativeActionEvent;
       
    56 class QDeclarativeAbstractBinding;
       
    57 class QDeclarativeBinding;
       
    58 class QDeclarativeExpression;
       
    59 class Q_DECLARATIVE_EXPORT QDeclarativeAction
       
    60 {
       
    61 public:
       
    62     QDeclarativeAction();
       
    63     QDeclarativeAction(QObject *, const QString &, const QVariant &);
       
    64     QDeclarativeAction(QObject *, const QString &,
       
    65                        QDeclarativeContext *, const QVariant &);
       
    66 
       
    67     bool restore:1;
       
    68     bool actionDone:1;
       
    69     bool reverseEvent:1;
       
    70     bool deletableToBinding:1;
       
    71 
       
    72     QDeclarativeProperty property;
       
    73     QVariant fromValue;
       
    74     QVariant toValue;
       
    75 
       
    76     QDeclarativeAbstractBinding *fromBinding;
       
    77     QDeclarativeAbstractBinding *toBinding;
       
    78     QDeclarativeActionEvent *event;
       
    79 
       
    80     //strictly for matching
       
    81     QObject *specifiedObject;
       
    82     QString specifiedProperty;
       
    83 
       
    84     void deleteFromBinding();
       
    85 };
       
    86 
       
    87 class QDeclarativeActionEvent
       
    88 {
       
    89 public:
       
    90     virtual ~QDeclarativeActionEvent();
       
    91     virtual QString typeName() const;
       
    92 
       
    93     enum Reason { ActualChange, FastForward };
       
    94 
       
    95     virtual void execute(Reason reason = ActualChange);
       
    96     virtual bool isReversable();
       
    97     virtual void reverse(Reason reason = ActualChange);
       
    98     virtual void saveOriginals() {}
       
    99     virtual bool needsCopy() { return false; }
       
   100     virtual void copyOriginals(QDeclarativeActionEvent *) {}
       
   101 
       
   102     virtual bool isRewindable() { return isReversable(); }
       
   103     virtual void rewind() {}
       
   104     virtual void saveCurrentValues() {}
       
   105     virtual void saveTargetValues() {}
       
   106 
       
   107     virtual bool changesBindings();
       
   108     virtual void clearBindings();
       
   109     virtual bool override(QDeclarativeActionEvent*other);
       
   110 };
       
   111 
       
   112 //### rename to QDeclarativeStateChange?
       
   113 class QDeclarativeStateGroup;
       
   114 class Q_DECLARATIVE_EXPORT QDeclarativeStateOperation : public QObject
       
   115 {
       
   116     Q_OBJECT
       
   117 public:
       
   118     QDeclarativeStateOperation(QObject *parent = 0)
       
   119         : QObject(parent) {}
       
   120     typedef QList<QDeclarativeAction> ActionList;
       
   121 
       
   122     virtual ActionList actions();
       
   123 
       
   124 protected:
       
   125     QDeclarativeStateOperation(QObjectPrivate &dd, QObject *parent = 0);
       
   126 };
       
   127 
       
   128 typedef QDeclarativeStateOperation::ActionList QDeclarativeStateActions;
       
   129 
       
   130 class QDeclarativeTransition;
       
   131 class QDeclarativeStatePrivate;
       
   132 class Q_DECLARATIVE_EXPORT QDeclarativeState : public QObject
       
   133 {
       
   134     Q_OBJECT
       
   135 
       
   136     Q_PROPERTY(QString name READ name WRITE setName)
       
   137     Q_PROPERTY(QDeclarativeBinding *when READ when WRITE setWhen)
       
   138     Q_PROPERTY(QString extend READ extends WRITE setExtends)
       
   139     Q_PROPERTY(QDeclarativeListProperty<QDeclarativeStateOperation> changes READ changes)
       
   140     Q_CLASSINFO("DefaultProperty", "changes")
       
   141     Q_CLASSINFO("DeferredPropertyNames", "changes")
       
   142 
       
   143 public:
       
   144     QDeclarativeState(QObject *parent=0);
       
   145     virtual ~QDeclarativeState();
       
   146 
       
   147     QString name() const;
       
   148     void setName(const QString &);
       
   149 
       
   150     /*'when' is a QDeclarativeBinding to limit state changes oscillation
       
   151      due to the unpredictable order of evaluation of bound expressions*/
       
   152     bool isWhenKnown() const;
       
   153     QDeclarativeBinding *when() const;
       
   154     void setWhen(QDeclarativeBinding *);
       
   155 
       
   156     QString extends() const;
       
   157     void setExtends(const QString &);
       
   158 
       
   159     QDeclarativeListProperty<QDeclarativeStateOperation> changes();
       
   160     int operationCount() const;
       
   161     QDeclarativeStateOperation *operationAt(int) const;
       
   162 
       
   163     QDeclarativeState &operator<<(QDeclarativeStateOperation *);
       
   164 
       
   165     void apply(QDeclarativeStateGroup *, QDeclarativeTransition *, QDeclarativeState *revert);
       
   166     void cancel();
       
   167 
       
   168     QDeclarativeStateGroup *stateGroup() const;
       
   169     void setStateGroup(QDeclarativeStateGroup *);
       
   170 
       
   171 Q_SIGNALS:
       
   172     void completed();
       
   173 
       
   174 private:
       
   175     Q_DECLARE_PRIVATE(QDeclarativeState)
       
   176     Q_DISABLE_COPY(QDeclarativeState)
       
   177 };
       
   178 
       
   179 QT_END_NAMESPACE
       
   180 
       
   181 QML_DECLARE_TYPE(QDeclarativeStateOperation)
       
   182 QML_DECLARE_TYPE(QDeclarativeState)
       
   183 
       
   184 QT_END_HEADER
       
   185 
       
   186 #endif // QDECLARATIVESTATE_H