summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/declarative/util/qmlstate.h3
-rw-r--r--src/declarative/util/qmlstateoperations.cpp199
-rw-r--r--src/declarative/util/qmlstateoperations.h49
3 files changed, 250 insertions, 1 deletions
diff --git a/src/declarative/util/qmlstate.h b/src/declarative/util/qmlstate.h
index e453446..b727489 100644
--- a/src/declarative/util/qmlstate.h
+++ b/src/declarative/util/qmlstate.h
@@ -73,6 +73,7 @@ public:
QmlBinding *toBinding;
ActionEvent *event;
+ //strictly for matching
QObject *specifiedObject;
QString specifiedProperty;
@@ -85,7 +86,7 @@ public:
virtual ~ActionEvent();
virtual QString typeName() const;
virtual void execute();
- virtual bool isReversable();
+ virtual bool isReversable(); //### revertable is probably more correct (same below)
virtual void reverse();
};
diff --git a/src/declarative/util/qmlstateoperations.cpp b/src/declarative/util/qmlstateoperations.cpp
index 3e114d2..352f331 100644
--- a/src/declarative/util/qmlstateoperations.cpp
+++ b/src/declarative/util/qmlstateoperations.cpp
@@ -272,4 +272,203 @@ QmlRunScript::ActionList QmlRunScript::actions()
return rv;
}
+/*!
+ \qmlclass SetAnchors
+ \brief The SetAnchors element allows you to change anchors in a state.
+*/
+
+QML_DEFINE_TYPE(QmlSetAnchors,SetAnchors)
+
+class QmlSetAnchorsPrivate : public QObjectPrivate
+{
+public:
+ QmlSetAnchorsPrivate() : target(0) {}
+
+ QString name;
+ QFxItem *target;
+ QString resetString;
+ QStringList resetList;
+ QFxAnchorLine left;
+ QFxAnchorLine right;
+ QFxAnchorLine top;
+ QFxAnchorLine bottom;
+
+ QFxAnchorLine origLeft;
+ QFxAnchorLine origRight;
+ QFxAnchorLine origTop;
+ QFxAnchorLine origBottom;
+};
+
+QmlSetAnchors::QmlSetAnchors(QObject *parent)
+ : QmlStateOperation(*(new QmlSetAnchorsPrivate), parent)
+{
+}
+
+QmlSetAnchors::~QmlSetAnchors()
+{
+}
+
+QmlSetAnchors::ActionList QmlSetAnchors::actions()
+{
+ Action a;
+ a.event = this;
+ 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);
+ return d->target;
+}
+
+void QmlSetAnchors::setObject(QFxItem *target)
+{
+ Q_D(QmlSetAnchors);
+ d->target = target;
+}
+
+QString QmlSetAnchors::reset() const
+{
+ Q_D(const QmlSetAnchors);
+ return d->resetString;
+}
+
+void QmlSetAnchors::setReset(const QString &reset)
+{
+ Q_D(QmlSetAnchors);
+ d->resetString = reset;
+ d->resetList = d->resetString.split(QLatin1Char(','));
+}
+
+QFxAnchorLine QmlSetAnchors::left() const
+{
+ Q_D(const QmlSetAnchors);
+ return d->left;
+}
+
+void QmlSetAnchors::setLeft(const QFxAnchorLine &edge)
+{
+ Q_D(QmlSetAnchors);
+ d->left = edge;
+}
+
+QFxAnchorLine QmlSetAnchors::right() const
+{
+ Q_D(const QmlSetAnchors);
+ return d->right;
+}
+
+void QmlSetAnchors::setRight(const QFxAnchorLine &edge)
+{
+ Q_D(QmlSetAnchors);
+ d->right = edge;
+}
+
+QFxAnchorLine QmlSetAnchors::top() const
+{
+ Q_D(const QmlSetAnchors);
+ return d->top;
+}
+
+void QmlSetAnchors::setTop(const QFxAnchorLine &edge)
+{
+ Q_D(QmlSetAnchors);
+ d->top = edge;
+}
+
+QFxAnchorLine QmlSetAnchors::bottom() const
+{
+ Q_D(const QmlSetAnchors);
+ return d->bottom;
+}
+
+void QmlSetAnchors::setBottom(const QFxAnchorLine &edge)
+{
+ Q_D(QmlSetAnchors);
+ d->bottom = edge;
+}
+
+void QmlSetAnchors::execute()
+{
+ Q_D(QmlSetAnchors);
+ 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);
+ if (d->right.anchorLine != QFxAnchorLine::Invalid)
+ d->target->anchors()->setRight(d->right);
+ if (d->top.anchorLine != QFxAnchorLine::Invalid)
+ d->target->anchors()->setTop(d->top);
+ if (d->bottom.anchorLine != QFxAnchorLine::Invalid)
+ d->target->anchors()->setBottom(d->bottom);
+}
+
+bool QmlSetAnchors::isReversable()
+{
+ return true;
+}
+
+void QmlSetAnchors::reverse()
+{
+ Q_D(QmlSetAnchors);
+ 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);
+ if (d->origRight.anchorLine != QFxAnchorLine::Invalid)
+ d->target->anchors()->setRight(d->origRight);
+ if (d->origTop.anchorLine != QFxAnchorLine::Invalid)
+ d->target->anchors()->setTop(d->origTop);
+ if (d->origBottom.anchorLine != QFxAnchorLine::Invalid)
+ d->target->anchors()->setBottom(d->origBottom);
+
+}
+
+QString QmlSetAnchors::typeName() const
+{
+ return QLatin1String("SetAnchors");
+}
+
QT_END_NAMESPACE
diff --git a/src/declarative/util/qmlstateoperations.h b/src/declarative/util/qmlstateoperations.h
index 67cd1cf..c4e1539 100644
--- a/src/declarative/util/qmlstateoperations.h
+++ b/src/declarative/util/qmlstateoperations.h
@@ -44,6 +44,7 @@
#include <QtDeclarative/qmlstate.h>
#include <QtDeclarative/qfxitem.h>
+#include <QtDeclarative/qfxanchors.h>
QT_BEGIN_HEADER
@@ -101,10 +102,58 @@ public:
virtual void execute();
};
+class QmlSetAnchorsPrivate;
+class Q_DECLARATIVE_EXPORT QmlSetAnchors : public QmlStateOperation, public ActionEvent
+{
+ 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)
+ Q_PROPERTY(QFxAnchorLine right READ right WRITE setRight)
+ Q_PROPERTY(QFxAnchorLine top READ top WRITE setTop)
+ Q_PROPERTY(QFxAnchorLine bottom READ bottom WRITE setBottom)
+
+public:
+ QmlSetAnchors(QObject *parent=0);
+ ~QmlSetAnchors();
+
+ virtual ActionList actions();
+
+ QString name() const;
+ void setName(const QString &);
+
+ QFxItem *object() const;
+ void setObject(QFxItem *);
+
+ QString reset() const;
+ void setReset(const QString &);
+
+ QFxAnchorLine left() const;
+ void setLeft(const QFxAnchorLine &edge);
+
+ QFxAnchorLine right() const;
+ void setRight(const QFxAnchorLine &edge);
+
+ QFxAnchorLine top() const;
+ void setTop(const QFxAnchorLine &edge);
+
+ QFxAnchorLine bottom() const;
+ void setBottom(const QFxAnchorLine &edge);
+
+ virtual void execute();
+ virtual bool isReversable();
+ virtual void reverse();
+ virtual QString typeName() const;
+};
+
QT_END_NAMESPACE
QML_DECLARE_TYPE(QmlParentChange)
QML_DECLARE_TYPE(QmlRunScript)
+QML_DECLARE_TYPE(QmlSetAnchors)
QT_END_HEADER