1 /****************************************************************************
3 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
7 ** This file is part of the QtDeclarative module of the Qt Toolkit.
9 ** $QT_BEGIN_LICENSE:LGPL$
10 ** GNU Lesser General Public License Usage
11 ** This file may be used under the terms of the GNU Lesser General Public
12 ** License version 2.1 as published by the Free Software Foundation and
13 ** appearing in the file LICENSE.LGPL included in the packaging of this
14 ** file. Please review the following information to ensure the GNU Lesser
15 ** General Public License version 2.1 requirements will be met:
16 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
18 ** In addition, as a special exception, Nokia gives you certain additional
19 ** rights. These rights are described in the Nokia Qt LGPL Exception
20 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
22 ** GNU General Public License Usage
23 ** Alternatively, this file may be used under the terms of the GNU General
24 ** Public License version 3.0 as published by the Free Software Foundation
25 ** and appearing in the file LICENSE.GPL included in the packaging of this
26 ** file. Please review the following information to ensure the GNU General
27 ** Public License version 3.0 requirements will be met:
28 ** http://www.gnu.org/copyleft/gpl.html.
31 ** Alternatively, this file may be used in accordance with the terms and
32 ** conditions contained in a signed written agreement between you and Nokia.
40 ****************************************************************************/
42 #include "QtQuick1/private/qdeclarativestateoperations_p.h"
43 #include "QtQuick1/private/qdeclarativeanchors_p_p.h"
44 #include "QtQuick1/private/qdeclarativeitem_p.h"
45 #include "QtDeclarative/private/qdeclarativenullablevalue_p_p.h"
47 #include <QtDeclarative/qdeclarative.h>
48 #include <QtDeclarative/qdeclarativecontext.h>
49 #include <QtDeclarative/qdeclarativeexpression.h>
50 #include <QtDeclarative/qdeclarativeinfo.h>
51 #include <QtDeclarative/private/qdeclarativeguard_p.h>
52 #include <QtDeclarative/private/qdeclarativecontext_p.h>
53 #include <QtDeclarative/private/qdeclarativeproperty_p.h>
54 #include <QtDeclarative/private/qdeclarativebinding_p.h>
55 #include <QtQuick1/private/qdeclarativestate_p_p.h>
57 #include <QtCore/qdebug.h>
58 #include <QtWidgets/qgraphicsitem.h>
59 #include <QtCore/qmath.h>
61 #include <private/qobject_p.h>
67 class QDeclarative1ParentChangePrivate : public QDeclarative1StateOperationPrivate
69 Q_DECLARE_PUBLIC(QDeclarative1ParentChange)
71 QDeclarative1ParentChangePrivate() : target(0), parent(0), origParent(0), origStackBefore(0),
72 rewindParent(0), rewindStackBefore(0) {}
74 QDeclarativeItem *target;
75 QDeclarativeGuard<QDeclarativeItem> parent;
76 QDeclarativeGuard<QDeclarativeItem> origParent;
77 QDeclarativeGuard<QDeclarativeItem> origStackBefore;
78 QDeclarativeItem *rewindParent;
79 QDeclarativeItem *rewindStackBefore;
81 QDeclarativeNullableValue<QDeclarativeScriptString> xString;
82 QDeclarativeNullableValue<QDeclarativeScriptString> yString;
83 QDeclarativeNullableValue<QDeclarativeScriptString> widthString;
84 QDeclarativeNullableValue<QDeclarativeScriptString> heightString;
85 QDeclarativeNullableValue<QDeclarativeScriptString> scaleString;
86 QDeclarativeNullableValue<QDeclarativeScriptString> rotationString;
88 QDeclarativeNullableValue<qreal> x;
89 QDeclarativeNullableValue<qreal> y;
90 QDeclarativeNullableValue<qreal> width;
91 QDeclarativeNullableValue<qreal> height;
92 QDeclarativeNullableValue<qreal> scale;
93 QDeclarativeNullableValue<qreal> rotation;
95 void doChange(QDeclarativeItem *targetParent, QDeclarativeItem *stackBefore = 0);
98 void QDeclarative1ParentChangePrivate::doChange(QDeclarativeItem *targetParent, QDeclarativeItem *stackBefore)
100 if (targetParent && target && target->parentItem()) {
101 Q_Q(QDeclarative1ParentChange);
103 const QTransform &transform = target->parentItem()->itemTransform(targetParent, &ok);
104 if (transform.type() >= QTransform::TxShear || !ok) {
105 qmlInfo(q) << QDeclarative1ParentChange::tr("Unable to preserve appearance under complex transform");
111 bool isRotate = (transform.type() == QTransform::TxRotate) || (transform.m11() < 0);
112 if (ok && !isRotate) {
113 if (transform.m11() == transform.m22())
114 scale = transform.m11();
116 qmlInfo(q) << QDeclarative1ParentChange::tr("Unable to preserve appearance under non-uniform scale");
119 } else if (ok && isRotate) {
120 if (transform.m11() == transform.m22())
121 scale = qSqrt(transform.m11()*transform.m11() + transform.m12()*transform.m12());
123 qmlInfo(q) << QDeclarative1ParentChange::tr("Unable to preserve appearance under non-uniform scale");
128 rotation = atan2(transform.m12()/scale, transform.m11()/scale) * 180/M_PI;
130 qmlInfo(q) << QDeclarative1ParentChange::tr("Unable to preserve appearance under scale of 0");
135 const QPointF &point = transform.map(QPointF(target->x(),target->y()));
139 // setParentItem will update the transformOriginPoint if needed
140 target->setParentItem(targetParent);
142 if (ok && target->transformOrigin() != QDeclarativeItem::TopLeft) {
143 qreal tempxt = target->transformOriginPoint().x();
144 qreal tempyt = target->transformOriginPoint().y();
146 t.translate(-tempxt, -tempyt);
148 t.scale(scale, scale);
149 t.translate(tempxt, tempyt);
150 const QPointF &offset = t.map(QPointF(0,0));
156 //qDebug() << x << y << rotation << scale;
159 target->setRotation(target->rotation() + rotation);
160 target->setScale(target->scale() * scale);
163 target->setParentItem(targetParent);
166 //restore the original stack position.
167 //### if stackBefore has also been reparented this won't work
169 target->stackBefore(stackBefore);
174 \qmlclass ParentChange QDeclarative1ParentChange
175 \inqmlmodule QtQuick 1
176 \ingroup qml-state-elements
177 \brief The ParentChange element allows you to reparent an Item in a state change.
179 ParentChange reparents an item while preserving its visual appearance (position, size,
180 rotation, and scale) on screen. You can then specify a transition to move/resize/rotate/scale
181 the item to its final intended appearance.
183 ParentChange can only preserve visual appearance if no complex transforms are involved.
184 More specifically, it will not work if the transform property has been set for any
185 items involved in the reparenting (i.e. items in the common ancestor tree
186 for the original and new parent).
188 The example below displays a large red rectangle and a small blue rectangle, side by side.
189 When the \c blueRect is clicked, it changes to the "reparented" state: its parent is changed to \c redRect and it is
190 positioned at (10, 10) within the red rectangle, as specified in the ParentChange.
192 \snippet doc/src/snippets/qtquick1/parentchange.qml 0
194 \image parentchange.png
196 You can specify at which point in a transition you want a ParentChange to occur by
197 using a ParentAnimation.
201 QDeclarative1ParentChange::QDeclarative1ParentChange(QObject *parent)
202 : QDeclarative1StateOperation(*(new QDeclarative1ParentChangePrivate), parent)
206 QDeclarative1ParentChange::~QDeclarative1ParentChange()
211 \qmlproperty real QtQuick1::ParentChange::x
212 \qmlproperty real QtQuick1::ParentChange::y
213 \qmlproperty real QtQuick1::ParentChange::width
214 \qmlproperty real QtQuick1::ParentChange::height
215 \qmlproperty real QtQuick1::ParentChange::scale
216 \qmlproperty real QtQuick1::ParentChange::rotation
217 These properties hold the new position, size, scale, and rotation
218 for the item in this state.
220 QDeclarativeScriptString QDeclarative1ParentChange::x() const
222 Q_D(const QDeclarative1ParentChange);
223 return d->xString.value;
226 void tryReal(QDeclarativeNullableValue<qreal> &value, const QString &string)
229 qreal realValue = string.toFloat(&ok);
236 void QDeclarative1ParentChange::setX(QDeclarativeScriptString x)
238 Q_D(QDeclarative1ParentChange);
240 tryReal(d->x, x.script());
243 bool QDeclarative1ParentChange::xIsSet() const
245 Q_D(const QDeclarative1ParentChange);
246 return d->xString.isValid();
249 QDeclarativeScriptString QDeclarative1ParentChange::y() const
251 Q_D(const QDeclarative1ParentChange);
252 return d->yString.value;
255 void QDeclarative1ParentChange::setY(QDeclarativeScriptString y)
257 Q_D(QDeclarative1ParentChange);
259 tryReal(d->y, y.script());
262 bool QDeclarative1ParentChange::yIsSet() const
264 Q_D(const QDeclarative1ParentChange);
265 return d->yString.isValid();
268 QDeclarativeScriptString QDeclarative1ParentChange::width() const
270 Q_D(const QDeclarative1ParentChange);
271 return d->widthString.value;
274 void QDeclarative1ParentChange::setWidth(QDeclarativeScriptString width)
276 Q_D(QDeclarative1ParentChange);
277 d->widthString = width;
278 tryReal(d->width, width.script());
281 bool QDeclarative1ParentChange::widthIsSet() const
283 Q_D(const QDeclarative1ParentChange);
284 return d->widthString.isValid();
287 QDeclarativeScriptString QDeclarative1ParentChange::height() const
289 Q_D(const QDeclarative1ParentChange);
290 return d->heightString.value;
293 void QDeclarative1ParentChange::setHeight(QDeclarativeScriptString height)
295 Q_D(QDeclarative1ParentChange);
296 d->heightString = height;
297 tryReal(d->height, height.script());
300 bool QDeclarative1ParentChange::heightIsSet() const
302 Q_D(const QDeclarative1ParentChange);
303 return d->heightString.isValid();
306 QDeclarativeScriptString QDeclarative1ParentChange::scale() const
308 Q_D(const QDeclarative1ParentChange);
309 return d->scaleString.value;
312 void QDeclarative1ParentChange::setScale(QDeclarativeScriptString scale)
314 Q_D(QDeclarative1ParentChange);
315 d->scaleString = scale;
316 tryReal(d->scale, scale.script());
319 bool QDeclarative1ParentChange::scaleIsSet() const
321 Q_D(const QDeclarative1ParentChange);
322 return d->scaleString.isValid();
325 QDeclarativeScriptString QDeclarative1ParentChange::rotation() const
327 Q_D(const QDeclarative1ParentChange);
328 return d->rotationString.value;
331 void QDeclarative1ParentChange::setRotation(QDeclarativeScriptString rotation)
333 Q_D(QDeclarative1ParentChange);
334 d->rotationString = rotation;
335 tryReal(d->rotation, rotation.script());
338 bool QDeclarative1ParentChange::rotationIsSet() const
340 Q_D(const QDeclarative1ParentChange);
341 return d->rotationString.isValid();
344 QDeclarativeItem *QDeclarative1ParentChange::originalParent() const
346 Q_D(const QDeclarative1ParentChange);
347 return d->origParent;
351 \qmlproperty Item QtQuick1::ParentChange::target
352 This property holds the item to be reparented
355 QDeclarativeItem *QDeclarative1ParentChange::object() const
357 Q_D(const QDeclarative1ParentChange);
361 void QDeclarative1ParentChange::setObject(QDeclarativeItem *target)
363 Q_D(QDeclarative1ParentChange);
368 \qmlproperty Item QtQuick1::ParentChange::parent
369 This property holds the new parent for the item in this state.
372 QDeclarativeItem *QDeclarative1ParentChange::parent() const
374 Q_D(const QDeclarative1ParentChange);
378 void QDeclarative1ParentChange::setParent(QDeclarativeItem *parent)
380 Q_D(QDeclarative1ParentChange);
384 QDeclarative1StateOperation::ActionList QDeclarative1ParentChange::actions()
386 Q_D(QDeclarative1ParentChange);
387 if (!d->target || !d->parent)
392 QDeclarative1Action a;
396 QDeclarativeContext *ctxt = qmlContext(this);
398 if (d->xString.isValid()) {
399 if (d->x.isValid()) {
400 QDeclarative1Action xa(d->target, QLatin1String("x"), ctxt, d->x.value);
403 QDeclarativeBinding *newBinding = new QDeclarativeBinding(d->xString.value.script(), d->target, ctxt);
404 newBinding->setTarget(QDeclarativeProperty(d->target, QLatin1String("x"), ctxt));
405 QDeclarative1Action xa;
406 xa.property = newBinding->property();
407 xa.toBinding = newBinding;
408 xa.fromValue = xa.property.read();
409 xa.deletableToBinding = true;
414 if (d->yString.isValid()) {
415 if (d->y.isValid()) {
416 QDeclarative1Action ya(d->target, QLatin1String("y"), ctxt, d->y.value);
419 QDeclarativeBinding *newBinding = new QDeclarativeBinding(d->yString.value.script(), d->target, ctxt);
420 newBinding->setTarget(QDeclarativeProperty(d->target, QLatin1String("y"), ctxt));
421 QDeclarative1Action ya;
422 ya.property = newBinding->property();
423 ya.toBinding = newBinding;
424 ya.fromValue = ya.property.read();
425 ya.deletableToBinding = true;
430 if (d->scaleString.isValid()) {
431 if (d->scale.isValid()) {
432 QDeclarative1Action sa(d->target, QLatin1String("scale"), ctxt, d->scale.value);
435 QDeclarativeBinding *newBinding = new QDeclarativeBinding(d->scaleString.value.script(), d->target, ctxt);
436 newBinding->setTarget(QDeclarativeProperty(d->target, QLatin1String("scale"), ctxt));
437 QDeclarative1Action sa;
438 sa.property = newBinding->property();
439 sa.toBinding = newBinding;
440 sa.fromValue = sa.property.read();
441 sa.deletableToBinding = true;
446 if (d->rotationString.isValid()) {
447 if (d->rotation.isValid()) {
448 QDeclarative1Action ra(d->target, QLatin1String("rotation"), ctxt, d->rotation.value);
451 QDeclarativeBinding *newBinding = new QDeclarativeBinding(d->rotationString.value.script(), d->target, ctxt);
452 newBinding->setTarget(QDeclarativeProperty(d->target, QLatin1String("rotation"), ctxt));
453 QDeclarative1Action ra;
454 ra.property = newBinding->property();
455 ra.toBinding = newBinding;
456 ra.fromValue = ra.property.read();
457 ra.deletableToBinding = true;
462 if (d->widthString.isValid()) {
463 if (d->width.isValid()) {
464 QDeclarative1Action wa(d->target, QLatin1String("width"), ctxt, d->width.value);
467 QDeclarativeBinding *newBinding = new QDeclarativeBinding(d->widthString.value.script(), d->target, ctxt);
468 newBinding->setTarget(QDeclarativeProperty(d->target, QLatin1String("width"), ctxt));
469 QDeclarative1Action wa;
470 wa.property = newBinding->property();
471 wa.toBinding = newBinding;
472 wa.fromValue = wa.property.read();
473 wa.deletableToBinding = true;
478 if (d->heightString.isValid()) {
479 if (d->height.isValid()) {
480 QDeclarative1Action ha(d->target, QLatin1String("height"), ctxt, d->height.value);
483 QDeclarativeBinding *newBinding = new QDeclarativeBinding(d->heightString.value.script(), d->target, ctxt);
484 newBinding->setTarget(QDeclarativeProperty(d->target, QLatin1String("height"), ctxt));
485 QDeclarative1Action ha;
486 ha.property = newBinding->property();
487 ha.toBinding = newBinding;
488 ha.fromValue = ha.property.read();
489 ha.deletableToBinding = true;
497 class AccessibleFxItem : public QDeclarativeItem
500 Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QDeclarativeItem)
503 Q_D(QDeclarativeItem);
504 return d->siblingIndex;
508 void QDeclarative1ParentChange::saveOriginals()
510 Q_D(QDeclarative1ParentChange);
512 d->origParent = d->rewindParent;
513 d->origStackBefore = d->rewindStackBefore;
516 /*void QDeclarative1ParentChange::copyOriginals(QDeclarative1ActionEvent *other)
518 Q_D(QDeclarative1ParentChange);
519 QDeclarative1ParentChange *pc = static_cast<QDeclarative1ParentChange*>(other);
521 d->origParent = pc->d_func()->rewindParent;
522 d->origStackBefore = pc->d_func()->rewindStackBefore;
527 void QDeclarative1ParentChange::execute(Reason)
529 Q_D(QDeclarative1ParentChange);
530 d->doChange(d->parent);
533 bool QDeclarative1ParentChange::isReversable()
538 void QDeclarative1ParentChange::reverse(Reason)
540 Q_D(QDeclarative1ParentChange);
541 d->doChange(d->origParent, d->origStackBefore);
544 QString QDeclarative1ParentChange::typeName() const
546 return QLatin1String("ParentChange");
549 bool QDeclarative1ParentChange::override(QDeclarative1ActionEvent*other)
551 Q_D(QDeclarative1ParentChange);
552 if (other->typeName() != QLatin1String("ParentChange"))
554 if (QDeclarative1ParentChange *otherPC = static_cast<QDeclarative1ParentChange*>(other))
555 return (d->target == otherPC->object());
559 void QDeclarative1ParentChange::saveCurrentValues()
561 Q_D(QDeclarative1ParentChange);
564 d->rewindStackBefore = 0;
568 d->rewindParent = d->target->parentItem();
569 d->rewindStackBefore = 0;
571 if (!d->rewindParent)
574 //try to determine the item's original stack position so we can restore it
575 int siblingIndex = ((AccessibleFxItem*)d->target)->siblingIndex() + 1;
576 QList<QGraphicsItem*> children = d->rewindParent->childItems();
577 for (int i = 0; i < children.count(); ++i) {
578 QDeclarativeItem *child = qobject_cast<QDeclarativeItem*>(children.at(i));
581 if (((AccessibleFxItem*)child)->siblingIndex() == siblingIndex) {
582 d->rewindStackBefore = child;
588 void QDeclarative1ParentChange::rewind()
590 Q_D(QDeclarative1ParentChange);
591 d->doChange(d->rewindParent, d->rewindStackBefore);
594 class QDeclarative1StateChangeScriptPrivate : public QDeclarative1StateOperationPrivate
597 QDeclarative1StateChangeScriptPrivate() {}
599 QDeclarativeScriptString script;
604 \qmlclass StateChangeScript QDeclarative1StateChangeScript
605 \inqmlmodule QtQuick 1
606 \ingroup qml-state-elements
607 \brief The StateChangeScript element allows you to run a script in a state.
609 A StateChangeScript is run upon entering a state. You can optionally use
610 ScriptAction to specify the point in the transition at which
611 the StateChangeScript should to be run.
613 \snippet snippets/declarative/states/statechangescript.qml state and transition
618 QDeclarative1StateChangeScript::QDeclarative1StateChangeScript(QObject *parent)
619 : QDeclarative1StateOperation(*(new QDeclarative1StateChangeScriptPrivate), parent)
623 QDeclarative1StateChangeScript::~QDeclarative1StateChangeScript()
628 \qmlproperty script QtQuick1::StateChangeScript::script
629 This property holds the script to run when the state is current.
631 QDeclarativeScriptString QDeclarative1StateChangeScript::script() const
633 Q_D(const QDeclarative1StateChangeScript);
637 void QDeclarative1StateChangeScript::setScript(const QDeclarativeScriptString &s)
639 Q_D(QDeclarative1StateChangeScript);
644 \qmlproperty string QtQuick1::StateChangeScript::name
645 This property holds the name of the script. This name can be used by a
646 ScriptAction to target a specific script.
648 \sa ScriptAction::scriptName
650 QString QDeclarative1StateChangeScript::name() const
652 Q_D(const QDeclarative1StateChangeScript);
656 void QDeclarative1StateChangeScript::setName(const QString &n)
658 Q_D(QDeclarative1StateChangeScript);
662 void QDeclarative1StateChangeScript::execute(Reason)
664 Q_D(QDeclarative1StateChangeScript);
665 const QString &script = d->script.script();
666 if (!script.isEmpty()) {
667 QDeclarativeExpression expr(d->script.context(), d->script.scopeObject(), script);
668 QDeclarativeData *ddata = QDeclarativeData::get(this);
669 if (ddata && ddata->outerContext && !ddata->outerContext->url.isEmpty())
670 expr.setSourceLocation(ddata->outerContext->url.toString(), ddata->lineNumber);
673 qmlInfo(this, expr.error());
677 QDeclarative1StateChangeScript::ActionList QDeclarative1StateChangeScript::actions()
680 QDeclarative1Action a;
686 QString QDeclarative1StateChangeScript::typeName() const
688 return QLatin1String("StateChangeScript");
692 \qmlclass AnchorChanges QDeclarative1AnchorChanges
693 \inqmlmodule QtQuick 1
694 \ingroup qml-state-elements
695 \brief The AnchorChanges element allows you to change the anchors of an item in a state.
697 The AnchorChanges element is used to modify the anchors of an item in a \l State.
699 AnchorChanges cannot be used to modify the margins on an item. For this, use
700 PropertyChanges intead.
702 In the following example we change the top and bottom anchors of an item
703 using AnchorChanges, and the top and bottom anchor margins using
706 \snippet doc/src/snippets/qtquick1/anchorchanges.qml 0
708 \image anchorchanges.png
710 AnchorChanges can be animated using AnchorAnimation.
712 //animate our anchor changes
718 Margin animations can be animated using NumberAnimation.
720 For more information on anchors see \l {anchor-layout}{Anchor Layouts}.
723 class QDeclarative1AnchorSetPrivate : public QObjectPrivate
725 Q_DECLARE_PUBLIC(QDeclarative1AnchorSet)
727 QDeclarative1AnchorSetPrivate()
728 : usedAnchors(0), resetAnchors(0), fill(0),
729 centerIn(0)/*, leftMargin(0), rightMargin(0), topMargin(0), bottomMargin(0),
730 margins(0), vCenterOffset(0), hCenterOffset(0), baselineOffset(0)*/
734 QDeclarative1Anchors::Anchors usedAnchors;
735 QDeclarative1Anchors::Anchors resetAnchors;
737 QDeclarativeItem *fill;
738 QDeclarativeItem *centerIn;
740 QDeclarativeScriptString leftScript;
741 QDeclarativeScriptString rightScript;
742 QDeclarativeScriptString topScript;
743 QDeclarativeScriptString bottomScript;
744 QDeclarativeScriptString hCenterScript;
745 QDeclarativeScriptString vCenterScript;
746 QDeclarativeScriptString baselineScript;
755 qreal baselineOffset;*/
758 QDeclarative1AnchorSet::QDeclarative1AnchorSet(QObject *parent)
759 : QObject(*new QDeclarative1AnchorSetPrivate, parent)
763 QDeclarative1AnchorSet::~QDeclarative1AnchorSet()
767 QDeclarativeScriptString QDeclarative1AnchorSet::top() const
769 Q_D(const QDeclarative1AnchorSet);
773 void QDeclarative1AnchorSet::setTop(const QDeclarativeScriptString &edge)
775 Q_D(QDeclarative1AnchorSet);
776 d->usedAnchors |= QDeclarative1Anchors::TopAnchor;
778 if (edge.script() == QLatin1String("undefined"))
782 void QDeclarative1AnchorSet::resetTop()
784 Q_D(QDeclarative1AnchorSet);
785 d->usedAnchors &= ~QDeclarative1Anchors::TopAnchor;
786 d->topScript = QDeclarativeScriptString();
787 d->resetAnchors |= QDeclarative1Anchors::TopAnchor;
790 QDeclarativeScriptString QDeclarative1AnchorSet::bottom() const
792 Q_D(const QDeclarative1AnchorSet);
793 return d->bottomScript;
796 void QDeclarative1AnchorSet::setBottom(const QDeclarativeScriptString &edge)
798 Q_D(QDeclarative1AnchorSet);
799 d->usedAnchors |= QDeclarative1Anchors::BottomAnchor;
800 d->bottomScript = edge;
801 if (edge.script() == QLatin1String("undefined"))
805 void QDeclarative1AnchorSet::resetBottom()
807 Q_D(QDeclarative1AnchorSet);
808 d->usedAnchors &= ~QDeclarative1Anchors::BottomAnchor;
809 d->bottomScript = QDeclarativeScriptString();
810 d->resetAnchors |= QDeclarative1Anchors::BottomAnchor;
813 QDeclarativeScriptString QDeclarative1AnchorSet::verticalCenter() const
815 Q_D(const QDeclarative1AnchorSet);
816 return d->vCenterScript;
819 void QDeclarative1AnchorSet::setVerticalCenter(const QDeclarativeScriptString &edge)
821 Q_D(QDeclarative1AnchorSet);
822 d->usedAnchors |= QDeclarative1Anchors::VCenterAnchor;
823 d->vCenterScript = edge;
824 if (edge.script() == QLatin1String("undefined"))
825 resetVerticalCenter();
828 void QDeclarative1AnchorSet::resetVerticalCenter()
830 Q_D(QDeclarative1AnchorSet);
831 d->usedAnchors &= ~QDeclarative1Anchors::VCenterAnchor;
832 d->vCenterScript = QDeclarativeScriptString();
833 d->resetAnchors |= QDeclarative1Anchors::VCenterAnchor;
836 QDeclarativeScriptString QDeclarative1AnchorSet::baseline() const
838 Q_D(const QDeclarative1AnchorSet);
839 return d->baselineScript;
842 void QDeclarative1AnchorSet::setBaseline(const QDeclarativeScriptString &edge)
844 Q_D(QDeclarative1AnchorSet);
845 d->usedAnchors |= QDeclarative1Anchors::BaselineAnchor;
846 d->baselineScript = edge;
847 if (edge.script() == QLatin1String("undefined"))
851 void QDeclarative1AnchorSet::resetBaseline()
853 Q_D(QDeclarative1AnchorSet);
854 d->usedAnchors &= ~QDeclarative1Anchors::BaselineAnchor;
855 d->baselineScript = QDeclarativeScriptString();
856 d->resetAnchors |= QDeclarative1Anchors::BaselineAnchor;
859 QDeclarativeScriptString QDeclarative1AnchorSet::left() const
861 Q_D(const QDeclarative1AnchorSet);
862 return d->leftScript;
865 void QDeclarative1AnchorSet::setLeft(const QDeclarativeScriptString &edge)
867 Q_D(QDeclarative1AnchorSet);
868 d->usedAnchors |= QDeclarative1Anchors::LeftAnchor;
869 d->leftScript = edge;
870 if (edge.script() == QLatin1String("undefined"))
874 void QDeclarative1AnchorSet::resetLeft()
876 Q_D(QDeclarative1AnchorSet);
877 d->usedAnchors &= ~QDeclarative1Anchors::LeftAnchor;
878 d->leftScript = QDeclarativeScriptString();
879 d->resetAnchors |= QDeclarative1Anchors::LeftAnchor;
882 QDeclarativeScriptString QDeclarative1AnchorSet::right() const
884 Q_D(const QDeclarative1AnchorSet);
885 return d->rightScript;
888 void QDeclarative1AnchorSet::setRight(const QDeclarativeScriptString &edge)
890 Q_D(QDeclarative1AnchorSet);
891 d->usedAnchors |= QDeclarative1Anchors::RightAnchor;
892 d->rightScript = edge;
893 if (edge.script() == QLatin1String("undefined"))
897 void QDeclarative1AnchorSet::resetRight()
899 Q_D(QDeclarative1AnchorSet);
900 d->usedAnchors &= ~QDeclarative1Anchors::RightAnchor;
901 d->rightScript = QDeclarativeScriptString();
902 d->resetAnchors |= QDeclarative1Anchors::RightAnchor;
905 QDeclarativeScriptString QDeclarative1AnchorSet::horizontalCenter() const
907 Q_D(const QDeclarative1AnchorSet);
908 return d->hCenterScript;
911 void QDeclarative1AnchorSet::setHorizontalCenter(const QDeclarativeScriptString &edge)
913 Q_D(QDeclarative1AnchorSet);
914 d->usedAnchors |= QDeclarative1Anchors::HCenterAnchor;
915 d->hCenterScript = edge;
916 if (edge.script() == QLatin1String("undefined"))
917 resetHorizontalCenter();
920 void QDeclarative1AnchorSet::resetHorizontalCenter()
922 Q_D(QDeclarative1AnchorSet);
923 d->usedAnchors &= ~QDeclarative1Anchors::HCenterAnchor;
924 d->hCenterScript = QDeclarativeScriptString();
925 d->resetAnchors |= QDeclarative1Anchors::HCenterAnchor;
928 QDeclarativeItem *QDeclarative1AnchorSet::fill() const
930 Q_D(const QDeclarative1AnchorSet);
934 void QDeclarative1AnchorSet::setFill(QDeclarativeItem *f)
936 Q_D(QDeclarative1AnchorSet);
940 void QDeclarative1AnchorSet::resetFill()
945 QDeclarativeItem *QDeclarative1AnchorSet::centerIn() const
947 Q_D(const QDeclarative1AnchorSet);
951 void QDeclarative1AnchorSet::setCenterIn(QDeclarativeItem* c)
953 Q_D(QDeclarative1AnchorSet);
957 void QDeclarative1AnchorSet::resetCenterIn()
963 class QDeclarative1AnchorChangesPrivate : public QDeclarative1StateOperationPrivate
966 QDeclarative1AnchorChangesPrivate()
967 : target(0), anchorSet(new QDeclarative1AnchorSet),
968 leftBinding(0), rightBinding(0), hCenterBinding(0),
969 topBinding(0), bottomBinding(0), vCenterBinding(0), baselineBinding(0),
970 origLeftBinding(0), origRightBinding(0), origHCenterBinding(0),
971 origTopBinding(0), origBottomBinding(0), origVCenterBinding(0),
972 origBaselineBinding(0)
976 ~QDeclarative1AnchorChangesPrivate() { delete anchorSet; }
978 QDeclarativeItem *target;
979 QDeclarative1AnchorSet *anchorSet;
981 QDeclarativeBinding *leftBinding;
982 QDeclarativeBinding *rightBinding;
983 QDeclarativeBinding *hCenterBinding;
984 QDeclarativeBinding *topBinding;
985 QDeclarativeBinding *bottomBinding;
986 QDeclarativeBinding *vCenterBinding;
987 QDeclarativeBinding *baselineBinding;
989 QDeclarativeAbstractBinding *origLeftBinding;
990 QDeclarativeAbstractBinding *origRightBinding;
991 QDeclarativeAbstractBinding *origHCenterBinding;
992 QDeclarativeAbstractBinding *origTopBinding;
993 QDeclarativeAbstractBinding *origBottomBinding;
994 QDeclarativeAbstractBinding *origVCenterBinding;
995 QDeclarativeAbstractBinding *origBaselineBinding;
997 QDeclarative1AnchorLine rewindLeft;
998 QDeclarative1AnchorLine rewindRight;
999 QDeclarative1AnchorLine rewindHCenter;
1000 QDeclarative1AnchorLine rewindTop;
1001 QDeclarative1AnchorLine rewindBottom;
1002 QDeclarative1AnchorLine rewindVCenter;
1003 QDeclarative1AnchorLine rewindBaseline;
1021 bool applyOrigRight;
1022 bool applyOrigHCenter;
1024 bool applyOrigBottom;
1025 bool applyOrigVCenter;
1026 bool applyOrigBaseline;
1028 QDeclarativeNullableValue<qreal> origWidth;
1029 QDeclarativeNullableValue<qreal> origHeight;
1033 QList<QDeclarativeAbstractBinding*> oldBindings;
1035 QDeclarativeProperty leftProp;
1036 QDeclarativeProperty rightProp;
1037 QDeclarativeProperty hCenterProp;
1038 QDeclarativeProperty topProp;
1039 QDeclarativeProperty bottomProp;
1040 QDeclarativeProperty vCenterProp;
1041 QDeclarativeProperty baselineProp;
1045 \qmlproperty Item QtQuick1::AnchorChanges::target
1046 This property holds the \l Item for which the anchor changes will be applied.
1049 QDeclarative1AnchorChanges::QDeclarative1AnchorChanges(QObject *parent)
1050 : QDeclarative1StateOperation(*(new QDeclarative1AnchorChangesPrivate), parent)
1054 QDeclarative1AnchorChanges::~QDeclarative1AnchorChanges()
1058 QDeclarative1AnchorChanges::ActionList QDeclarative1AnchorChanges::actions()
1060 Q_D(QDeclarative1AnchorChanges);
1061 d->leftBinding = d->rightBinding = d->hCenterBinding = d->topBinding
1062 = d->bottomBinding = d->vCenterBinding = d->baselineBinding = 0;
1064 d->leftProp = QDeclarativeProperty(d->target, QLatin1String("anchors.left"));
1065 d->rightProp = QDeclarativeProperty(d->target, QLatin1String("anchors.right"));
1066 d->hCenterProp = QDeclarativeProperty(d->target, QLatin1String("anchors.horizontalCenter"));
1067 d->topProp = QDeclarativeProperty(d->target, QLatin1String("anchors.top"));
1068 d->bottomProp = QDeclarativeProperty(d->target, QLatin1String("anchors.bottom"));
1069 d->vCenterProp = QDeclarativeProperty(d->target, QLatin1String("anchors.verticalCenter"));
1070 d->baselineProp = QDeclarativeProperty(d->target, QLatin1String("anchors.baseline"));
1072 QDeclarativeContext *ctxt = qmlContext(this);
1074 if (d->anchorSet->d_func()->usedAnchors & QDeclarative1Anchors::LeftAnchor) {
1075 d->leftBinding = new QDeclarativeBinding(d->anchorSet->d_func()->leftScript.script(), d->target, ctxt);
1076 d->leftBinding->setTarget(d->leftProp);
1078 if (d->anchorSet->d_func()->usedAnchors & QDeclarative1Anchors::RightAnchor) {
1079 d->rightBinding = new QDeclarativeBinding(d->anchorSet->d_func()->rightScript.script(), d->target, ctxt);
1080 d->rightBinding->setTarget(d->rightProp);
1082 if (d->anchorSet->d_func()->usedAnchors & QDeclarative1Anchors::HCenterAnchor) {
1083 d->hCenterBinding = new QDeclarativeBinding(d->anchorSet->d_func()->hCenterScript.script(), d->target, ctxt);
1084 d->hCenterBinding->setTarget(d->hCenterProp);
1086 if (d->anchorSet->d_func()->usedAnchors & QDeclarative1Anchors::TopAnchor) {
1087 d->topBinding = new QDeclarativeBinding(d->anchorSet->d_func()->topScript.script(), d->target, ctxt);
1088 d->topBinding->setTarget(d->topProp);
1090 if (d->anchorSet->d_func()->usedAnchors & QDeclarative1Anchors::BottomAnchor) {
1091 d->bottomBinding = new QDeclarativeBinding(d->anchorSet->d_func()->bottomScript.script(), d->target, ctxt);
1092 d->bottomBinding->setTarget(d->bottomProp);
1094 if (d->anchorSet->d_func()->usedAnchors & QDeclarative1Anchors::VCenterAnchor) {
1095 d->vCenterBinding = new QDeclarativeBinding(d->anchorSet->d_func()->vCenterScript.script(), d->target, ctxt);
1096 d->vCenterBinding->setTarget(d->vCenterProp);
1098 if (d->anchorSet->d_func()->usedAnchors & QDeclarative1Anchors::BaselineAnchor) {
1099 d->baselineBinding = new QDeclarativeBinding(d->anchorSet->d_func()->baselineScript.script(), d->target, ctxt);
1100 d->baselineBinding->setTarget(d->baselineProp);
1103 QDeclarative1Action a;
1105 return ActionList() << a;
1108 QDeclarative1AnchorSet *QDeclarative1AnchorChanges::anchors()
1110 Q_D(QDeclarative1AnchorChanges);
1111 return d->anchorSet;
1114 QDeclarativeItem *QDeclarative1AnchorChanges::object() const
1116 Q_D(const QDeclarative1AnchorChanges);
1120 void QDeclarative1AnchorChanges::setObject(QDeclarativeItem *target)
1122 Q_D(QDeclarative1AnchorChanges);
1127 \qmlproperty AnchorLine QtQuick1::AnchorChanges::anchors.left
1128 \qmlproperty AnchorLine QtQuick1::AnchorChanges::anchors.right
1129 \qmlproperty AnchorLine QtQuick1::AnchorChanges::anchors.horizontalCenter
1130 \qmlproperty AnchorLine QtQuick1::AnchorChanges::anchors.top
1131 \qmlproperty AnchorLine QtQuick1::AnchorChanges::anchors.bottom
1132 \qmlproperty AnchorLine QtQuick1::AnchorChanges::anchors.verticalCenter
1133 \qmlproperty AnchorLine QtQuick1::AnchorChanges::anchors.baseline
1135 These properties change the respective anchors of the item.
1137 To reset an anchor you can assign \c undefined:
1141 anchors.left: undefined //remove myItem's left anchor
1142 anchors.right: otherItem.right
1147 void QDeclarative1AnchorChanges::execute(Reason reason)
1149 Q_D(QDeclarative1AnchorChanges);
1153 QDeclarativeItemPrivate *targetPrivate = QDeclarativeItemPrivate::get(d->target);
1154 //incorporate any needed "reverts"
1155 if (d->applyOrigLeft) {
1156 if (!d->origLeftBinding)
1157 targetPrivate->anchors()->resetLeft();
1158 QDeclarativePropertyPrivate::setBinding(d->leftProp, d->origLeftBinding);
1160 if (d->applyOrigRight) {
1161 if (!d->origRightBinding)
1162 targetPrivate->anchors()->resetRight();
1163 QDeclarativePropertyPrivate::setBinding(d->rightProp, d->origRightBinding);
1165 if (d->applyOrigHCenter) {
1166 if (!d->origHCenterBinding)
1167 targetPrivate->anchors()->resetHorizontalCenter();
1168 QDeclarativePropertyPrivate::setBinding(d->hCenterProp, d->origHCenterBinding);
1170 if (d->applyOrigTop) {
1171 if (!d->origTopBinding)
1172 targetPrivate->anchors()->resetTop();
1173 QDeclarativePropertyPrivate::setBinding(d->topProp, d->origTopBinding);
1175 if (d->applyOrigBottom) {
1176 if (!d->origBottomBinding)
1177 targetPrivate->anchors()->resetBottom();
1178 QDeclarativePropertyPrivate::setBinding(d->bottomProp, d->origBottomBinding);
1180 if (d->applyOrigVCenter) {
1181 if (!d->origVCenterBinding)
1182 targetPrivate->anchors()->resetVerticalCenter();
1183 QDeclarativePropertyPrivate::setBinding(d->vCenterProp, d->origVCenterBinding);
1185 if (d->applyOrigBaseline) {
1186 if (!d->origBaselineBinding)
1187 targetPrivate->anchors()->resetBaseline();
1188 QDeclarativePropertyPrivate::setBinding(d->baselineProp, d->origBaselineBinding);
1191 //destroy old bindings
1192 if (reason == ActualChange) {
1193 for (int i = 0; i < d->oldBindings.size(); ++i) {
1194 QDeclarativeAbstractBinding *binding = d->oldBindings.at(i);
1198 d->oldBindings.clear();
1201 //reset any anchors that have been specified as "undefined"
1202 if (d->anchorSet->d_func()->resetAnchors & QDeclarative1Anchors::LeftAnchor) {
1203 targetPrivate->anchors()->resetLeft();
1204 QDeclarativePropertyPrivate::setBinding(d->leftProp, 0);
1206 if (d->anchorSet->d_func()->resetAnchors & QDeclarative1Anchors::RightAnchor) {
1207 targetPrivate->anchors()->resetRight();
1208 QDeclarativePropertyPrivate::setBinding(d->rightProp, 0);
1210 if (d->anchorSet->d_func()->resetAnchors & QDeclarative1Anchors::HCenterAnchor) {
1211 targetPrivate->anchors()->resetHorizontalCenter();
1212 QDeclarativePropertyPrivate::setBinding(d->hCenterProp, 0);
1214 if (d->anchorSet->d_func()->resetAnchors & QDeclarative1Anchors::TopAnchor) {
1215 targetPrivate->anchors()->resetTop();
1216 QDeclarativePropertyPrivate::setBinding(d->topProp, 0);
1218 if (d->anchorSet->d_func()->resetAnchors & QDeclarative1Anchors::BottomAnchor) {
1219 targetPrivate->anchors()->resetBottom();
1220 QDeclarativePropertyPrivate::setBinding(d->bottomProp, 0);
1222 if (d->anchorSet->d_func()->resetAnchors & QDeclarative1Anchors::VCenterAnchor) {
1223 targetPrivate->anchors()->resetVerticalCenter();
1224 QDeclarativePropertyPrivate::setBinding(d->vCenterProp, 0);
1226 if (d->anchorSet->d_func()->resetAnchors & QDeclarative1Anchors::BaselineAnchor) {
1227 targetPrivate->anchors()->resetBaseline();
1228 QDeclarativePropertyPrivate::setBinding(d->baselineProp, 0);
1231 //set any anchors that have been specified
1233 QDeclarativePropertyPrivate::setBinding(d->leftBinding->property(), d->leftBinding);
1234 if (d->rightBinding)
1235 QDeclarativePropertyPrivate::setBinding(d->rightBinding->property(), d->rightBinding);
1236 if (d->hCenterBinding)
1237 QDeclarativePropertyPrivate::setBinding(d->hCenterBinding->property(), d->hCenterBinding);
1239 QDeclarativePropertyPrivate::setBinding(d->topBinding->property(), d->topBinding);
1240 if (d->bottomBinding)
1241 QDeclarativePropertyPrivate::setBinding(d->bottomBinding->property(), d->bottomBinding);
1242 if (d->vCenterBinding)
1243 QDeclarativePropertyPrivate::setBinding(d->vCenterBinding->property(), d->vCenterBinding);
1244 if (d->baselineBinding)
1245 QDeclarativePropertyPrivate::setBinding(d->baselineBinding->property(), d->baselineBinding);
1248 bool QDeclarative1AnchorChanges::isReversable()
1253 void QDeclarative1AnchorChanges::reverse(Reason reason)
1255 Q_D(QDeclarative1AnchorChanges);
1259 QDeclarativeItemPrivate *targetPrivate = QDeclarativeItemPrivate::get(d->target);
1260 //reset any anchors set by the state
1261 if (d->leftBinding) {
1262 targetPrivate->anchors()->resetLeft();
1263 QDeclarativePropertyPrivate::setBinding(d->leftBinding->property(), 0);
1264 if (reason == ActualChange) {
1265 d->leftBinding->destroy(); d->leftBinding = 0;
1268 if (d->rightBinding) {
1269 targetPrivate->anchors()->resetRight();
1270 QDeclarativePropertyPrivate::setBinding(d->rightBinding->property(), 0);
1271 if (reason == ActualChange) {
1272 d->rightBinding->destroy(); d->rightBinding = 0;
1275 if (d->hCenterBinding) {
1276 targetPrivate->anchors()->resetHorizontalCenter();
1277 QDeclarativePropertyPrivate::setBinding(d->hCenterBinding->property(), 0);
1278 if (reason == ActualChange) {
1279 d->hCenterBinding->destroy(); d->hCenterBinding = 0;
1282 if (d->topBinding) {
1283 targetPrivate->anchors()->resetTop();
1284 QDeclarativePropertyPrivate::setBinding(d->topBinding->property(), 0);
1285 if (reason == ActualChange) {
1286 d->topBinding->destroy(); d->topBinding = 0;
1289 if (d->bottomBinding) {
1290 targetPrivate->anchors()->resetBottom();
1291 QDeclarativePropertyPrivate::setBinding(d->bottomBinding->property(), 0);
1292 if (reason == ActualChange) {
1293 d->bottomBinding->destroy(); d->bottomBinding = 0;
1296 if (d->vCenterBinding) {
1297 targetPrivate->anchors()->resetVerticalCenter();
1298 QDeclarativePropertyPrivate::setBinding(d->vCenterBinding->property(), 0);
1299 if (reason == ActualChange) {
1300 d->vCenterBinding->destroy(); d->vCenterBinding = 0;
1303 if (d->baselineBinding) {
1304 targetPrivate->anchors()->resetBaseline();
1305 QDeclarativePropertyPrivate::setBinding(d->baselineBinding->property(), 0);
1306 if (reason == ActualChange) {
1307 d->baselineBinding->destroy(); d->baselineBinding = 0;
1311 //restore previous anchors
1312 if (d->origLeftBinding)
1313 QDeclarativePropertyPrivate::setBinding(d->leftProp, d->origLeftBinding);
1314 if (d->origRightBinding)
1315 QDeclarativePropertyPrivate::setBinding(d->rightProp, d->origRightBinding);
1316 if (d->origHCenterBinding)
1317 QDeclarativePropertyPrivate::setBinding(d->hCenterProp, d->origHCenterBinding);
1318 if (d->origTopBinding)
1319 QDeclarativePropertyPrivate::setBinding(d->topProp, d->origTopBinding);
1320 if (d->origBottomBinding)
1321 QDeclarativePropertyPrivate::setBinding(d->bottomProp, d->origBottomBinding);
1322 if (d->origVCenterBinding)
1323 QDeclarativePropertyPrivate::setBinding(d->vCenterProp, d->origVCenterBinding);
1324 if (d->origBaselineBinding)
1325 QDeclarativePropertyPrivate::setBinding(d->baselineProp, d->origBaselineBinding);
1327 //restore any absolute geometry changed by the state's anchors
1328 QDeclarative1Anchors::Anchors stateVAnchors = d->anchorSet->d_func()->usedAnchors & QDeclarative1Anchors::Vertical_Mask;
1329 QDeclarative1Anchors::Anchors origVAnchors = targetPrivate->anchors()->usedAnchors() & QDeclarative1Anchors::Vertical_Mask;
1330 QDeclarative1Anchors::Anchors stateHAnchors = d->anchorSet->d_func()->usedAnchors & QDeclarative1Anchors::Horizontal_Mask;
1331 QDeclarative1Anchors::Anchors origHAnchors = targetPrivate->anchors()->usedAnchors() & QDeclarative1Anchors::Horizontal_Mask;
1333 bool stateSetWidth = (stateHAnchors &&
1334 stateHAnchors != QDeclarative1Anchors::LeftAnchor &&
1335 stateHAnchors != QDeclarative1Anchors::RightAnchor &&
1336 stateHAnchors != QDeclarative1Anchors::HCenterAnchor);
1337 bool origSetWidth = (origHAnchors &&
1338 origHAnchors != QDeclarative1Anchors::LeftAnchor &&
1339 origHAnchors != QDeclarative1Anchors::RightAnchor &&
1340 origHAnchors != QDeclarative1Anchors::HCenterAnchor);
1341 if (d->origWidth.isValid() && stateSetWidth && !origSetWidth)
1342 d->target->setWidth(d->origWidth.value);
1344 bool stateSetHeight = (stateVAnchors &&
1345 stateVAnchors != QDeclarative1Anchors::TopAnchor &&
1346 stateVAnchors != QDeclarative1Anchors::BottomAnchor &&
1347 stateVAnchors != QDeclarative1Anchors::VCenterAnchor &&
1348 stateVAnchors != QDeclarative1Anchors::BaselineAnchor);
1349 bool origSetHeight = (origVAnchors &&
1350 origVAnchors != QDeclarative1Anchors::TopAnchor &&
1351 origVAnchors != QDeclarative1Anchors::BottomAnchor &&
1352 origVAnchors != QDeclarative1Anchors::VCenterAnchor &&
1353 origVAnchors != QDeclarative1Anchors::BaselineAnchor);
1354 if (d->origHeight.isValid() && stateSetHeight && !origSetHeight)
1355 d->target->setHeight(d->origHeight.value);
1357 if (stateHAnchors && !origHAnchors)
1358 d->target->setX(d->origX);
1360 if (stateVAnchors && !origVAnchors)
1361 d->target->setY(d->origY);
1364 QString QDeclarative1AnchorChanges::typeName() const
1366 return QLatin1String("AnchorChanges");
1369 QList<QDeclarative1Action> QDeclarative1AnchorChanges::additionalActions()
1371 Q_D(QDeclarative1AnchorChanges);
1372 QList<QDeclarative1Action> extra;
1374 QDeclarative1Anchors::Anchors combined = d->anchorSet->d_func()->usedAnchors | d->anchorSet->d_func()->resetAnchors;
1375 bool hChange = combined & QDeclarative1Anchors::Horizontal_Mask;
1376 bool vChange = combined & QDeclarative1Anchors::Vertical_Mask;
1379 QDeclarativeContext *ctxt = qmlContext(this);
1380 QDeclarative1Action a;
1381 if (hChange && d->fromX != d->toX) {
1382 a.property = QDeclarativeProperty(d->target, QLatin1String("x"), ctxt);
1386 if (vChange && d->fromY != d->toY) {
1387 a.property = QDeclarativeProperty(d->target, QLatin1String("y"), ctxt);
1391 if (hChange && d->fromWidth != d->toWidth) {
1392 a.property = QDeclarativeProperty(d->target, QLatin1String("width"), ctxt);
1393 a.toValue = d->toWidth;
1396 if (vChange && d->fromHeight != d->toHeight) {
1397 a.property = QDeclarativeProperty(d->target, QLatin1String("height"), ctxt);
1398 a.toValue = d->toHeight;
1406 bool QDeclarative1AnchorChanges::changesBindings()
1411 void QDeclarative1AnchorChanges::saveOriginals()
1413 Q_D(QDeclarative1AnchorChanges);
1417 d->origLeftBinding = QDeclarativePropertyPrivate::binding(d->leftProp);
1418 d->origRightBinding = QDeclarativePropertyPrivate::binding(d->rightProp);
1419 d->origHCenterBinding = QDeclarativePropertyPrivate::binding(d->hCenterProp);
1420 d->origTopBinding = QDeclarativePropertyPrivate::binding(d->topProp);
1421 d->origBottomBinding = QDeclarativePropertyPrivate::binding(d->bottomProp);
1422 d->origVCenterBinding = QDeclarativePropertyPrivate::binding(d->vCenterProp);
1423 d->origBaselineBinding = QDeclarativePropertyPrivate::binding(d->baselineProp);
1425 QDeclarativeItemPrivate *targetPrivate = QDeclarativeItemPrivate::get(d->target);
1426 if (targetPrivate->widthValid)
1427 d->origWidth = d->target->width();
1428 if (targetPrivate->heightValid)
1429 d->origHeight = d->target->height();
1430 d->origX = d->target->x();
1431 d->origY = d->target->y();
1433 d->applyOrigLeft = d->applyOrigRight = d->applyOrigHCenter = d->applyOrigTop
1434 = d->applyOrigBottom = d->applyOrigVCenter = d->applyOrigBaseline = false;
1436 saveCurrentValues();
1439 void QDeclarative1AnchorChanges::copyOriginals(QDeclarative1ActionEvent *other)
1441 Q_D(QDeclarative1AnchorChanges);
1442 QDeclarative1AnchorChanges *ac = static_cast<QDeclarative1AnchorChanges*>(other);
1443 QDeclarative1AnchorChangesPrivate *acp = ac->d_func();
1445 QDeclarative1Anchors::Anchors combined = acp->anchorSet->d_func()->usedAnchors |
1446 acp->anchorSet->d_func()->resetAnchors;
1448 //probably also need to revert some things
1449 d->applyOrigLeft = (combined & QDeclarative1Anchors::LeftAnchor);
1450 d->applyOrigRight = (combined & QDeclarative1Anchors::RightAnchor);
1451 d->applyOrigHCenter = (combined & QDeclarative1Anchors::HCenterAnchor);
1452 d->applyOrigTop = (combined & QDeclarative1Anchors::TopAnchor);
1453 d->applyOrigBottom = (combined & QDeclarative1Anchors::BottomAnchor);
1454 d->applyOrigVCenter = (combined & QDeclarative1Anchors::VCenterAnchor);
1455 d->applyOrigBaseline = (combined & QDeclarative1Anchors::BaselineAnchor);
1457 d->origLeftBinding = acp->origLeftBinding;
1458 d->origRightBinding = acp->origRightBinding;
1459 d->origHCenterBinding = acp->origHCenterBinding;
1460 d->origTopBinding = acp->origTopBinding;
1461 d->origBottomBinding = acp->origBottomBinding;
1462 d->origVCenterBinding = acp->origVCenterBinding;
1463 d->origBaselineBinding = acp->origBaselineBinding;
1465 d->origWidth = acp->origWidth;
1466 d->origHeight = acp->origHeight;
1467 d->origX = acp->origX;
1468 d->origY = acp->origY;
1470 d->oldBindings.clear();
1471 d->oldBindings << acp->leftBinding << acp->rightBinding << acp->hCenterBinding
1472 << acp->topBinding << acp->bottomBinding << acp->baselineBinding;
1474 saveCurrentValues();
1477 void QDeclarative1AnchorChanges::clearBindings()
1479 Q_D(QDeclarative1AnchorChanges);
1483 //### should this (saving "from" values) be moved to saveCurrentValues()?
1484 d->fromX = d->target->x();
1485 d->fromY = d->target->y();
1486 d->fromWidth = d->target->width();
1487 d->fromHeight = d->target->height();
1489 QDeclarativeItemPrivate *targetPrivate = QDeclarativeItemPrivate::get(d->target);
1490 //reset any anchors with corresponding reverts
1491 //reset any anchors that have been specified as "undefined"
1492 //reset any anchors that we'll be setting in the state
1493 QDeclarative1Anchors::Anchors combined = d->anchorSet->d_func()->resetAnchors |
1494 d->anchorSet->d_func()->usedAnchors;
1495 if (d->applyOrigLeft || (combined & QDeclarative1Anchors::LeftAnchor)) {
1496 targetPrivate->anchors()->resetLeft();
1497 QDeclarativePropertyPrivate::setBinding(d->leftProp, 0);
1499 if (d->applyOrigRight || (combined & QDeclarative1Anchors::RightAnchor)) {
1500 targetPrivate->anchors()->resetRight();
1501 QDeclarativePropertyPrivate::setBinding(d->rightProp, 0);
1503 if (d->applyOrigHCenter || (combined & QDeclarative1Anchors::HCenterAnchor)) {
1504 targetPrivate->anchors()->resetHorizontalCenter();
1505 QDeclarativePropertyPrivate::setBinding(d->hCenterProp, 0);
1507 if (d->applyOrigTop || (combined & QDeclarative1Anchors::TopAnchor)) {
1508 targetPrivate->anchors()->resetTop();
1509 QDeclarativePropertyPrivate::setBinding(d->topProp, 0);
1511 if (d->applyOrigBottom || (combined & QDeclarative1Anchors::BottomAnchor)) {
1512 targetPrivate->anchors()->resetBottom();
1513 QDeclarativePropertyPrivate::setBinding(d->bottomProp, 0);
1515 if (d->applyOrigVCenter || (combined & QDeclarative1Anchors::VCenterAnchor)) {
1516 targetPrivate->anchors()->resetVerticalCenter();
1517 QDeclarativePropertyPrivate::setBinding(d->vCenterProp, 0);
1519 if (d->applyOrigBaseline || (combined & QDeclarative1Anchors::BaselineAnchor)) {
1520 targetPrivate->anchors()->resetBaseline();
1521 QDeclarativePropertyPrivate::setBinding(d->baselineProp, 0);
1525 bool QDeclarative1AnchorChanges::override(QDeclarative1ActionEvent*other)
1527 if (other->typeName() != QLatin1String("AnchorChanges"))
1529 if (static_cast<QDeclarative1ActionEvent*>(this) == other)
1531 if (static_cast<QDeclarative1AnchorChanges*>(other)->object() == object())
1536 void QDeclarative1AnchorChanges::rewind()
1538 Q_D(QDeclarative1AnchorChanges);
1542 QDeclarativeItemPrivate *targetPrivate = QDeclarativeItemPrivate::get(d->target);
1544 //restore previous values (but not previous bindings, i.e. anchors)
1545 d->target->setX(d->rewindX);
1546 d->target->setY(d->rewindY);
1547 if (targetPrivate->widthValid) {
1548 d->target->setWidth(d->rewindWidth);
1550 if (targetPrivate->heightValid) {
1551 d->target->setHeight(d->rewindHeight);
1555 void QDeclarative1AnchorChanges::saveCurrentValues()
1557 Q_D(QDeclarative1AnchorChanges);
1561 QDeclarativeItemPrivate *targetPrivate = QDeclarativeItemPrivate::get(d->target);
1562 d->rewindLeft = targetPrivate->anchors()->left();
1563 d->rewindRight = targetPrivate->anchors()->right();
1564 d->rewindHCenter = targetPrivate->anchors()->horizontalCenter();
1565 d->rewindTop = targetPrivate->anchors()->top();
1566 d->rewindBottom = targetPrivate->anchors()->bottom();
1567 d->rewindVCenter = targetPrivate->anchors()->verticalCenter();
1568 d->rewindBaseline = targetPrivate->anchors()->baseline();
1570 d->rewindX = d->target->x();
1571 d->rewindY = d->target->y();
1572 d->rewindWidth = d->target->width();
1573 d->rewindHeight = d->target->height();
1576 void QDeclarative1AnchorChanges::saveTargetValues()
1578 Q_D(QDeclarative1AnchorChanges);
1582 d->toX = d->target->x();
1583 d->toY = d->target->y();
1584 d->toWidth = d->target->width();
1585 d->toHeight = d->target->height();
1588 #include <qdeclarativestateoperations.moc>
1589 #include <moc_qdeclarativestateoperations_p.cpp>