summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMichael Brasser <michael.brasser@nokia.com>2009-07-23 22:39:32 (GMT)
committerMichael Brasser <michael.brasser@nokia.com>2009-07-23 22:39:32 (GMT)
commite3c7d67be8ae3121dd84a89f9add452fcbb775ac (patch)
tree6b41fb217128387635d6e7dfeb86f5470eb9567d /src
parent1245e7cce64d46600b2535bc7d36474f8ba382e2 (diff)
downloadQt-e3c7d67be8ae3121dd84a89f9add452fcbb775ac.zip
Qt-e3c7d67be8ae3121dd84a89f9add452fcbb775ac.tar.gz
Qt-e3c7d67be8ae3121dd84a89f9add452fcbb775ac.tar.bz2
Get anchor change transitions working.
Diffstat (limited to 'src')
-rw-r--r--src/declarative/util/qmlstate.cpp28
-rw-r--r--src/declarative/util/qmlstate.h10
-rw-r--r--src/declarative/util/qmlstateoperations.cpp120
-rw-r--r--src/declarative/util/qmlstateoperations.h8
-rw-r--r--src/declarative/util/qmltransitionmanager.cpp46
5 files changed, 158 insertions, 54 deletions
diff --git a/src/declarative/util/qmlstate.cpp b/src/declarative/util/qmlstate.cpp
index 1aa7ffe..70b0137 100644
--- a/src/declarative/util/qmlstate.cpp
+++ b/src/declarative/util/qmlstate.cpp
@@ -92,6 +92,24 @@ void ActionEvent::reverse()
{
}
+QList<Action> ActionEvent::extraActions()
+{
+ return QList<Action>();
+}
+
+bool ActionEvent::changesBindings()
+{
+ return false;
+}
+
+void ActionEvent::clearForwardBindings()
+{
+}
+
+void ActionEvent::clearReverseBindings()
+{
+}
+
/*!
\internal
*/
@@ -399,10 +417,12 @@ void QmlState::apply(QmlStateGroup *group, QmlTransition *trans, QmlState *rever
// into this state need to be translated into apply actions
for (int ii = 0; ii < d->revertList.count(); ++ii) {
bool found = false;
- for (int jj = 0; !found && jj < applyList.count(); ++jj) {
- const Action &action = applyList.at(jj);
- if (action.property == d->revertList.at(ii).property)
- found = true;
+ if (!d->revertList.at(ii).event) { //### corresponding test for events?
+ for (int jj = 0; !found && jj < applyList.count(); ++jj) {
+ const Action &action = applyList.at(jj);
+ if (action.property == d->revertList.at(ii).property)
+ found = true;
+ }
}
if (!found) {
QVariant cur = d->revertList.at(ii).property.read();
diff --git a/src/declarative/util/qmlstate.h b/src/declarative/util/qmlstate.h
index b727489..7b3021b 100644
--- a/src/declarative/util/qmlstate.h
+++ b/src/declarative/util/qmlstate.h
@@ -85,9 +85,17 @@ class ActionEvent
public:
virtual ~ActionEvent();
virtual QString typeName() const;
+
virtual void execute();
- virtual bool isReversable(); //### revertable is probably more correct (same below)
+ virtual bool isReversable();
virtual void reverse();
+
+ //virtual bool hasExtraActions();
+ virtual QList<Action> extraActions();
+
+ virtual bool changesBindings();
+ virtual void clearForwardBindings();
+ virtual void clearReverseBindings();
};
class QmlStateGroup;
diff --git a/src/declarative/util/qmlstateoperations.cpp b/src/declarative/util/qmlstateoperations.cpp
index 352f331..c341cd6 100644
--- a/src/declarative/util/qmlstateoperations.cpp
+++ b/src/declarative/util/qmlstateoperations.cpp
@@ -292,11 +292,14 @@ public:
QFxAnchorLine right;
QFxAnchorLine top;
QFxAnchorLine bottom;
-
QFxAnchorLine origLeft;
QFxAnchorLine origRight;
QFxAnchorLine origTop;
QFxAnchorLine origBottom;
+ qreal origX;
+ qreal origY;
+ qreal origWidth;
+ qreal origHeight;
};
QmlSetAnchors::QmlSetAnchors(QObject *parent)
@@ -315,18 +318,6 @@ QmlSetAnchors::ActionList QmlSetAnchors::actions()
return ActionList() << a;
}
-QString QmlSetAnchors::name() const
-{
- Q_D(const QmlSetAnchors);
- return d->name;
-}
-
-void QmlSetAnchors::setName(const QString &name)
-{
- Q_D(QmlSetAnchors);
- d->name = name;
-}
-
QFxItem *QmlSetAnchors::object() const
{
Q_D(const QmlSetAnchors);
@@ -406,22 +397,6 @@ void QmlSetAnchors::execute()
if (!d->target)
return;
- //save original anchors
- d->origLeft = d->target->anchors()->left();
- d->origRight = d->target->anchors()->right();
- d->origTop = d->target->anchors()->top();
- d->origBottom = d->target->anchors()->bottom();
-
- //reset any anchors that have been specified
- if (d->resetList.contains(QLatin1String("left")))
- d->target->anchors()->resetLeft();
- if (d->resetList.contains(QLatin1String("right")))
- d->target->anchors()->resetRight();
- if (d->resetList.contains(QLatin1String("top")))
- d->target->anchors()->resetTop();
- if (d->resetList.contains(QLatin1String("bottom")))
- d->target->anchors()->resetBottom();
-
//set any anchors that have been specified
if (d->left.anchorLine != QFxAnchorLine::Invalid)
d->target->anchors()->setLeft(d->left);
@@ -444,16 +419,6 @@ void QmlSetAnchors::reverse()
if (!d->target)
return;
- //reset any anchors that were set in the state
- if (d->left.anchorLine != QFxAnchorLine::Invalid)
- d->target->anchors()->resetLeft();
- if (d->right.anchorLine != QFxAnchorLine::Invalid)
- d->target->anchors()->resetRight();
- if (d->top.anchorLine != QFxAnchorLine::Invalid)
- d->target->anchors()->resetTop();
- if (d->bottom.anchorLine != QFxAnchorLine::Invalid)
- d->target->anchors()->resetBottom();
-
//restore previous anchors
if (d->origLeft.anchorLine != QFxAnchorLine::Invalid)
d->target->anchors()->setLeft(d->origLeft);
@@ -471,4 +436,81 @@ QString QmlSetAnchors::typeName() const
return QLatin1String("SetAnchors");
}
+QList<Action> QmlSetAnchors::extraActions()
+{
+ Q_D(QmlSetAnchors);
+ QList<Action> extra;
+
+ //### try to be smarter about which ones we add.
+ // or short-circuit later on if they haven't actually changed.
+ // we shouldn't set explicit width if there wasn't one before.
+ if (d->target) {
+ Action a;
+ a.fromValue = d->origX;
+ a.property = QmlMetaProperty(d->target, "x");
+ extra << a;
+
+ a.fromValue = d->origY;
+ a.property = QmlMetaProperty(d->target, "y");
+ extra << a;
+
+ a.fromValue = d->origWidth;
+ a.property = QmlMetaProperty(d->target, "width");
+ extra << a;
+
+ a.fromValue = d->origHeight;
+ a.property = QmlMetaProperty(d->target, "height");
+ extra << a;
+ }
+
+ return extra;
+}
+
+bool QmlSetAnchors::changesBindings()
+{
+ return true;
+}
+
+void QmlSetAnchors::clearForwardBindings()
+{
+ Q_D(QmlSetAnchors);
+ d->origLeft = d->target->anchors()->left();
+ d->origRight = d->target->anchors()->right();
+ d->origTop = d->target->anchors()->top();
+ d->origBottom = d->target->anchors()->bottom();
+ d->origX = d->target->x();
+ d->origY = d->target->y();
+ d->origWidth = d->target->width();
+ d->origHeight = d->target->height();
+
+ //reset any anchors that have been specified
+ if (d->resetList.contains(QLatin1String("left")))
+ d->target->anchors()->resetLeft();
+ if (d->resetList.contains(QLatin1String("right")))
+ d->target->anchors()->resetRight();
+ if (d->resetList.contains(QLatin1String("top")))
+ d->target->anchors()->resetTop();
+ if (d->resetList.contains(QLatin1String("bottom")))
+ d->target->anchors()->resetBottom();
+}
+
+void QmlSetAnchors::clearReverseBindings()
+{
+ Q_D(QmlSetAnchors);
+ d->origX = d->target->x();
+ d->origY = d->target->y();
+ d->origWidth = d->target->width();
+ d->origHeight = d->target->height();
+
+ //reset any anchors that were set in the state
+ if (d->left.anchorLine != QFxAnchorLine::Invalid)
+ d->target->anchors()->resetLeft();
+ if (d->right.anchorLine != QFxAnchorLine::Invalid)
+ d->target->anchors()->resetRight();
+ if (d->top.anchorLine != QFxAnchorLine::Invalid)
+ d->target->anchors()->resetTop();
+ if (d->bottom.anchorLine != QFxAnchorLine::Invalid)
+ d->target->anchors()->resetBottom();
+}
+
QT_END_NAMESPACE
diff --git a/src/declarative/util/qmlstateoperations.h b/src/declarative/util/qmlstateoperations.h
index c4e1539..f595e16 100644
--- a/src/declarative/util/qmlstateoperations.h
+++ b/src/declarative/util/qmlstateoperations.h
@@ -108,7 +108,6 @@ class Q_DECLARATIVE_EXPORT QmlSetAnchors : public QmlStateOperation, public Acti
Q_OBJECT
Q_DECLARE_PRIVATE(QmlSetAnchors)
- Q_PROPERTY(QString name READ name WRITE setName)
Q_PROPERTY(QFxItem *target READ object WRITE setObject)
Q_PROPERTY(QString reset READ reset WRITE setReset)
Q_PROPERTY(QFxAnchorLine left READ left WRITE setLeft)
@@ -122,9 +121,6 @@ public:
virtual ActionList actions();
- QString name() const;
- void setName(const QString &);
-
QFxItem *object() const;
void setObject(QFxItem *);
@@ -147,6 +143,10 @@ public:
virtual bool isReversable();
virtual void reverse();
virtual QString typeName() const;
+ virtual QList<Action> extraActions();
+ virtual bool changesBindings();
+ virtual void clearForwardBindings();
+ virtual void clearReverseBindings();
};
QT_END_NAMESPACE
diff --git a/src/declarative/util/qmltransitionmanager.cpp b/src/declarative/util/qmltransitionmanager.cpp
index 4609de8..b2d9414 100644
--- a/src/declarative/util/qmltransitionmanager.cpp
+++ b/src/declarative/util/qmltransitionmanager.cpp
@@ -95,7 +95,13 @@ void QmlTransitionManagerPrivate::applyBindings()
if (action.toBinding) {
action.property.setBinding(action.toBinding);
action.toBinding->forceUpdate();
+ } else if (action.event) {
+ if (action.reverseEvent)
+ action.event->reverse();
+ else
+ action.event->execute();
}
+
}
bindingsList.clear();
@@ -113,6 +119,13 @@ void QmlTransitionManager::transition(const QList<Action> &list,
d->bindingsList << action;
if (action.fromBinding)
action.property.setBinding(0); // Disable current binding
+ if (action.event && action.event->changesBindings()) { //### assume isReversable()?
+ d->bindingsList << action;
+ if (action.reverseEvent)
+ action.event->clearReverseBindings();
+ else
+ action.event->clearForwardBindings();
+ }
}
// Animated transitions need both the start and the end value for
@@ -126,13 +139,22 @@ void QmlTransitionManager::transition(const QList<Action> &list,
if (!d->bindingsList.isEmpty()) {
+ //### do extra actions here?
+
// Apply all the property and binding changes
- foreach(const Action &action, applyList) {
+ for (int ii = 0; ii < applyList.size(); ++ii) {
+ const Action &action = applyList.at(ii);
if (action.toBinding) {
action.property.setBinding(action.toBinding);
action.toBinding->forceUpdate();
} else if (!action.event) {
action.property.write(action.toValue);
+ } else if (action.event->isReversable()) {
+ if (action.reverseEvent)
+ action.event->reverse();
+ else
+ action.event->execute();
+ applyList << action.event->extraActions();
}
}
@@ -141,16 +163,28 @@ void QmlTransitionManager::transition(const QList<Action> &list,
Action *action = &applyList[ii];
if (action->event)
continue;
-
const QmlMetaProperty &prop = action->property;
- if (action->toBinding)
+ if (action->toBinding || !action->toValue.isValid()) { //### is this always right (used for exta actions)
action->toValue = prop.read();
+ }
}
// Revert back to the original values
foreach(const Action &action, applyList) {
- if (action.event)
+ if (action.event) {
+ if (action.event->isReversable()) {
+ if (action.reverseEvent) { //reverse the reverse
+ action.event->clearForwardBindings();
+ action.event->execute();
+ action.event->clearReverseBindings();
+ } else {
+ action.event->clearReverseBindings();
+ action.event->reverse();
+ action.event->clearForwardBindings();
+ }
+ }
continue;
+ }
if (action.toBinding)
action.property.setBinding(0); // Make sure this is disabled during the transition
@@ -195,12 +229,12 @@ void QmlTransitionManager::transition(const QList<Action> &list,
// applied at the end in applyBindings() to avoid any nastiness mid
// transition
foreach(const Action &action, applyList) {
- if (action.event) {
+ if (action.event && !action.event->changesBindings()) {
if (action.event->isReversable() && action.reverseEvent)
action.event->reverse();
else
action.event->execute();
- } else {
+ } else if (!action.event) {
action.property.write(action.toValue);
}
}