From d373f8b8ee0a5841bcdb264b0b01b262c15e7f89 Mon Sep 17 00:00:00 2001 From: Michael Brasser Date: Thu, 25 Mar 2010 15:01:30 +1000 Subject: Update AnchorChanges to use more natural form for setting anchors. Instead of specifying left, right, etc directly, we keep the regular syntax and specify anchors.left, anchors.right, etc. Also get rid of the hacky "reset" string property and use undefined to reset (like PropertyChanges). --- src/declarative/QmlChanges.txt | 2 + .../util/qdeclarativestateoperations.cpp | 474 +++++++++++++-------- .../util/qdeclarativestateoperations_p.h | 123 +++++- src/declarative/util/qdeclarativeutilmodule.cpp | 1 + .../qdeclarativestates/data/anchorChanges1.qml | 4 +- .../qdeclarativestates/data/anchorChanges2.qml | 4 +- .../qdeclarativestates/data/anchorChanges3.qml | 8 +- .../qdeclarativestates/data/anchorChanges4.qml | 4 +- .../qdeclarativestates/data/anchorChanges5.qml | 4 +- .../qdeclarativestates/tst_qdeclarativestates.cpp | 38 +- .../visual/animation/reanchor/reanchor.qml | 15 +- 11 files changed, 447 insertions(+), 230 deletions(-) diff --git a/src/declarative/QmlChanges.txt b/src/declarative/QmlChanges.txt index 2a35dda..9a55bde 100644 --- a/src/declarative/QmlChanges.txt +++ b/src/declarative/QmlChanges.txt @@ -13,6 +13,8 @@ AnchorAnimation must now be used to animate anchor changes (and not NumberAnimat Removed ParentAction (use ParentAnimation instead) ScriptAction: renamed stateChangeScriptName -> scriptName Animation: replace repeat with loops (loops: Animation.Infinite gives the old repeat behavior) +AnchorChanges: use natural form to specify anchors (anchors.left instead of left) +AnchorChanges: removed reset property. (reset: "left" should now be anchors.left: undefined) C++ API ------- diff --git a/src/declarative/util/qdeclarativestateoperations.cpp b/src/declarative/util/qdeclarativestateoperations.cpp index 0bc81ee..3469136 100644 --- a/src/declarative/util/qdeclarativestateoperations.cpp +++ b/src/declarative/util/qdeclarativestateoperations.cpp @@ -609,209 +609,343 @@ QString QDeclarativeStateChangeScript::typeName() const For more information on anchors see \l {anchor-layout}{Anchor Layouts}. */ - - -class QDeclarativeAnchorChangesPrivate : public QObjectPrivate +class QDeclarativeAnchorSetPrivate : public QObjectPrivate { + Q_DECLARE_PUBLIC(QDeclarativeAnchorSet) public: - QDeclarativeAnchorChangesPrivate() : target(0) {} + QDeclarativeAnchorSetPrivate() + : usedAnchors(0), fill(0), + centerIn(0)/*, leftMargin(0), rightMargin(0), topMargin(0), bottomMargin(0), + margins(0), vCenterOffset(0), hCenterOffset(0), baselineOffset(0)*/ + { + } - QDeclarativeItem *target; - QString resetString; + QDeclarativeAnchors::UsedAnchors usedAnchors; + //### change to QDeclarativeAnchors::UsedAnchors resetAnchors QStringList resetList; + QDeclarativeItem *fill; + QDeclarativeItem *centerIn; + QDeclarativeAnchorLine left; QDeclarativeAnchorLine right; - QDeclarativeAnchorLine horizontalCenter; QDeclarativeAnchorLine top; QDeclarativeAnchorLine bottom; - QDeclarativeAnchorLine verticalCenter; + QDeclarativeAnchorLine vCenter; + QDeclarativeAnchorLine hCenter; QDeclarativeAnchorLine baseline; - QDeclarativeAnchorLine origLeft; - QDeclarativeAnchorLine origRight; - QDeclarativeAnchorLine origHCenter; - QDeclarativeAnchorLine origTop; - QDeclarativeAnchorLine origBottom; - QDeclarativeAnchorLine origVCenter; - QDeclarativeAnchorLine origBaseline; - - QDeclarativeAnchorLine rewindLeft; - QDeclarativeAnchorLine rewindRight; - QDeclarativeAnchorLine rewindHCenter; - QDeclarativeAnchorLine rewindTop; - QDeclarativeAnchorLine rewindBottom; - QDeclarativeAnchorLine rewindVCenter; - QDeclarativeAnchorLine rewindBaseline; + /*qreal leftMargin; + qreal rightMargin; + qreal topMargin; + qreal bottomMargin; + qreal margins; + qreal vCenterOffset; + qreal hCenterOffset; + qreal baselineOffset;*/ +}; - qreal fromX; - qreal fromY; - qreal fromWidth; - qreal fromHeight; +QDeclarativeAnchorSet::QDeclarativeAnchorSet(QObject *parent) + : QObject(*new QDeclarativeAnchorSetPrivate, parent) +{ +} - qreal toX; - qreal toY; - qreal toWidth; - qreal toHeight; +QDeclarativeAnchorSet::~QDeclarativeAnchorSet() +{ +} - qreal rewindX; - qreal rewindY; - qreal rewindWidth; - qreal rewindHeight; +QDeclarativeAnchorLine QDeclarativeAnchorSet::top() const +{ + Q_D(const QDeclarativeAnchorSet); + return d->top; +} - bool applyOrigLeft; - bool applyOrigRight; - bool applyOrigHCenter; - bool applyOrigTop; - bool applyOrigBottom; - bool applyOrigVCenter; - bool applyOrigBaseline; -}; +void QDeclarativeAnchorSet::setTop(const QDeclarativeAnchorLine &edge) +{ + Q_D(QDeclarativeAnchorSet); + d->usedAnchors |= QDeclarativeAnchors::HasTopAnchor; + d->top = edge; +} -/*! - \qmlproperty Item AnchorChanges::target - This property holds the Item whose anchors will change -*/ +void QDeclarativeAnchorSet::resetTop() +{ + Q_D(QDeclarativeAnchorSet); + d->usedAnchors &= ~QDeclarativeAnchors::HasTopAnchor; + d->top = QDeclarativeAnchorLine(); + d->resetList << QLatin1String("top"); +} -QDeclarativeAnchorChanges::QDeclarativeAnchorChanges(QObject *parent) - : QDeclarativeStateOperation(*(new QDeclarativeAnchorChangesPrivate), parent) +QDeclarativeAnchorLine QDeclarativeAnchorSet::bottom() const { + Q_D(const QDeclarativeAnchorSet); + return d->bottom; } -QDeclarativeAnchorChanges::~QDeclarativeAnchorChanges() +void QDeclarativeAnchorSet::setBottom(const QDeclarativeAnchorLine &edge) { + Q_D(QDeclarativeAnchorSet); + d->usedAnchors |= QDeclarativeAnchors::HasBottomAnchor; + d->bottom = edge; } -QDeclarativeAnchorChanges::ActionList QDeclarativeAnchorChanges::actions() +void QDeclarativeAnchorSet::resetBottom() { - QDeclarativeAction a; - a.event = this; - return ActionList() << a; + Q_D(QDeclarativeAnchorSet); + d->usedAnchors &= ~QDeclarativeAnchors::HasBottomAnchor; + d->bottom = QDeclarativeAnchorLine(); + d->resetList << QLatin1String("bottom"); } -QDeclarativeItem *QDeclarativeAnchorChanges::object() const +QDeclarativeAnchorLine QDeclarativeAnchorSet::verticalCenter() const { - Q_D(const QDeclarativeAnchorChanges); - return d->target; + Q_D(const QDeclarativeAnchorSet); + return d->vCenter; } -void QDeclarativeAnchorChanges::setObject(QDeclarativeItem *target) +void QDeclarativeAnchorSet::setVerticalCenter(const QDeclarativeAnchorLine &edge) { - Q_D(QDeclarativeAnchorChanges); - d->target = target; + Q_D(QDeclarativeAnchorSet); + d->usedAnchors |= QDeclarativeAnchors::HasVCenterAnchor; + d->vCenter = edge; } -QString QDeclarativeAnchorChanges::reset() const +void QDeclarativeAnchorSet::resetVerticalCenter() { - Q_D(const QDeclarativeAnchorChanges); - return d->resetString; + Q_D(QDeclarativeAnchorSet); + d->usedAnchors &= ~QDeclarativeAnchors::HasVCenterAnchor; + d->vCenter = QDeclarativeAnchorLine(); + d->resetList << QLatin1String("verticalCenter"); } -void QDeclarativeAnchorChanges::setReset(const QString &reset) +QDeclarativeAnchorLine QDeclarativeAnchorSet::baseline() const { - Q_D(QDeclarativeAnchorChanges); - d->resetString = reset; - d->resetList = d->resetString.split(QLatin1Char(',')); - for (int i = 0; i < d->resetList.count(); ++i) - d->resetList[i] = d->resetList.at(i).trimmed(); + Q_D(const QDeclarativeAnchorSet); + return d->baseline; } -/*! - \qmlproperty AnchorLine AnchorChanges::left - \qmlproperty AnchorLine AnchorChanges::right - \qmlproperty AnchorLine AnchorChanges::horizontalCenter - \qmlproperty AnchorLine AnchorChanges::top - \qmlproperty AnchorLine AnchorChanges::bottom - \qmlproperty AnchorLine AnchorChanges::verticalCenter - \qmlproperty AnchorLine AnchorChanges::baseline +void QDeclarativeAnchorSet::setBaseline(const QDeclarativeAnchorLine &edge) +{ + Q_D(QDeclarativeAnchorSet); + d->usedAnchors |= QDeclarativeAnchors::HasBaselineAnchor; + d->baseline = edge; +} - These properties change the respective anchors of the item. -*/ +void QDeclarativeAnchorSet::resetBaseline() +{ + Q_D(QDeclarativeAnchorSet); + d->usedAnchors &= ~QDeclarativeAnchors::HasBaselineAnchor; + d->baseline = QDeclarativeAnchorLine(); + d->resetList << QLatin1String("baseline"); +} -QDeclarativeAnchorLine QDeclarativeAnchorChanges::left() const +QDeclarativeAnchorLine QDeclarativeAnchorSet::left() const { - Q_D(const QDeclarativeAnchorChanges); + Q_D(const QDeclarativeAnchorSet); return d->left; } -void QDeclarativeAnchorChanges::setLeft(const QDeclarativeAnchorLine &edge) +void QDeclarativeAnchorSet::setLeft(const QDeclarativeAnchorLine &edge) { - Q_D(QDeclarativeAnchorChanges); + Q_D(QDeclarativeAnchorSet); + d->usedAnchors |= QDeclarativeAnchors::HasLeftAnchor; d->left = edge; } -QDeclarativeAnchorLine QDeclarativeAnchorChanges::right() const +void QDeclarativeAnchorSet::resetLeft() { - Q_D(const QDeclarativeAnchorChanges); + Q_D(QDeclarativeAnchorSet); + d->usedAnchors &= ~QDeclarativeAnchors::HasLeftAnchor; + d->left = QDeclarativeAnchorLine(); + d->resetList << QLatin1String("left"); +} + +QDeclarativeAnchorLine QDeclarativeAnchorSet::right() const +{ + Q_D(const QDeclarativeAnchorSet); return d->right; } -void QDeclarativeAnchorChanges::setRight(const QDeclarativeAnchorLine &edge) +void QDeclarativeAnchorSet::setRight(const QDeclarativeAnchorLine &edge) { - Q_D(QDeclarativeAnchorChanges); + Q_D(QDeclarativeAnchorSet); + d->usedAnchors |= QDeclarativeAnchors::HasRightAnchor; d->right = edge; } -QDeclarativeAnchorLine QDeclarativeAnchorChanges::horizontalCenter() const +void QDeclarativeAnchorSet::resetRight() { - Q_D(const QDeclarativeAnchorChanges); - return d->horizontalCenter; + Q_D(QDeclarativeAnchorSet); + d->usedAnchors &= ~QDeclarativeAnchors::HasRightAnchor; + d->right = QDeclarativeAnchorLine(); + d->resetList << QLatin1String("right"); } -void QDeclarativeAnchorChanges::setHorizontalCenter(const QDeclarativeAnchorLine &edge) +QDeclarativeAnchorLine QDeclarativeAnchorSet::horizontalCenter() const { - Q_D(QDeclarativeAnchorChanges); - d->horizontalCenter = edge; + Q_D(const QDeclarativeAnchorSet); + return d->hCenter; } -QDeclarativeAnchorLine QDeclarativeAnchorChanges::top() const +void QDeclarativeAnchorSet::setHorizontalCenter(const QDeclarativeAnchorLine &edge) { - Q_D(const QDeclarativeAnchorChanges); - return d->top; + Q_D(QDeclarativeAnchorSet); + d->usedAnchors |= QDeclarativeAnchors::HasHCenterAnchor; + d->hCenter = edge; } -void QDeclarativeAnchorChanges::setTop(const QDeclarativeAnchorLine &edge) +void QDeclarativeAnchorSet::resetHorizontalCenter() { - Q_D(QDeclarativeAnchorChanges); - d->top = edge; + Q_D(QDeclarativeAnchorSet); + d->usedAnchors &= ~QDeclarativeAnchors::HasHCenterAnchor; + d->hCenter = QDeclarativeAnchorLine(); + d->resetList << QLatin1String("horizontalCenter"); } -QDeclarativeAnchorLine QDeclarativeAnchorChanges::bottom() const +QDeclarativeItem *QDeclarativeAnchorSet::fill() const { - Q_D(const QDeclarativeAnchorChanges); - return d->bottom; + Q_D(const QDeclarativeAnchorSet); + return d->fill; } -void QDeclarativeAnchorChanges::setBottom(const QDeclarativeAnchorLine &edge) +void QDeclarativeAnchorSet::setFill(QDeclarativeItem *f) { - Q_D(QDeclarativeAnchorChanges); - d->bottom = edge; + Q_D(QDeclarativeAnchorSet); + d->fill = f; } -QDeclarativeAnchorLine QDeclarativeAnchorChanges::verticalCenter() const +void QDeclarativeAnchorSet::resetFill() { - Q_D(const QDeclarativeAnchorChanges); - return d->verticalCenter; + setFill(0); +} + +QDeclarativeItem *QDeclarativeAnchorSet::centerIn() const +{ + Q_D(const QDeclarativeAnchorSet); + return d->centerIn; } -void QDeclarativeAnchorChanges::setVerticalCenter(const QDeclarativeAnchorLine &edge) +void QDeclarativeAnchorSet::setCenterIn(QDeclarativeItem* c) +{ + Q_D(QDeclarativeAnchorSet); + d->centerIn = c; +} + +void QDeclarativeAnchorSet::resetCenterIn() +{ + setCenterIn(0); +} + + +class QDeclarativeAnchorChangesPrivate : public QObjectPrivate +{ +public: + QDeclarativeAnchorChangesPrivate() + : target(0), anchorSet(new QDeclarativeAnchorSet) {} + ~QDeclarativeAnchorChangesPrivate() { delete anchorSet; } + + QDeclarativeItem *target; + QDeclarativeAnchorSet *anchorSet; + + QDeclarativeAnchorLine origLeft; + QDeclarativeAnchorLine origRight; + QDeclarativeAnchorLine origHCenter; + QDeclarativeAnchorLine origTop; + QDeclarativeAnchorLine origBottom; + QDeclarativeAnchorLine origVCenter; + QDeclarativeAnchorLine origBaseline; + + QDeclarativeAnchorLine rewindLeft; + QDeclarativeAnchorLine rewindRight; + QDeclarativeAnchorLine rewindHCenter; + QDeclarativeAnchorLine rewindTop; + QDeclarativeAnchorLine rewindBottom; + QDeclarativeAnchorLine rewindVCenter; + QDeclarativeAnchorLine rewindBaseline; + + qreal fromX; + qreal fromY; + qreal fromWidth; + qreal fromHeight; + + qreal toX; + qreal toY; + qreal toWidth; + qreal toHeight; + + qreal rewindX; + qreal rewindY; + qreal rewindWidth; + qreal rewindHeight; + + bool applyOrigLeft; + bool applyOrigRight; + bool applyOrigHCenter; + bool applyOrigTop; + bool applyOrigBottom; + bool applyOrigVCenter; + bool applyOrigBaseline; +}; + +/*! + \qmlproperty Item AnchorChanges::target + This property holds the Item whose anchors will change +*/ + +QDeclarativeAnchorChanges::QDeclarativeAnchorChanges(QObject *parent) + : QDeclarativeStateOperation(*(new QDeclarativeAnchorChangesPrivate), parent) +{ +} + +QDeclarativeAnchorChanges::~QDeclarativeAnchorChanges() +{ +} + +QDeclarativeAnchorChanges::ActionList QDeclarativeAnchorChanges::actions() +{ + QDeclarativeAction a; + a.event = this; + return ActionList() << a; +} + +QDeclarativeAnchorSet *QDeclarativeAnchorChanges::anchors() { Q_D(QDeclarativeAnchorChanges); - d->verticalCenter = edge; + return d->anchorSet; } -QDeclarativeAnchorLine QDeclarativeAnchorChanges::baseline() const +QDeclarativeItem *QDeclarativeAnchorChanges::object() const { Q_D(const QDeclarativeAnchorChanges); - return d->baseline; + return d->target; } -void QDeclarativeAnchorChanges::setBaseline(const QDeclarativeAnchorLine &edge) +void QDeclarativeAnchorChanges::setObject(QDeclarativeItem *target) { Q_D(QDeclarativeAnchorChanges); - d->baseline = edge; + d->target = target; } +/*! + \qmlproperty AnchorLine AnchorChanges::anchors.left + \qmlproperty AnchorLine AnchorChanges::anchors.right + \qmlproperty AnchorLine AnchorChanges::anchors.horizontalCenter + \qmlproperty AnchorLine AnchorChanges::anchors.top + \qmlproperty AnchorLine AnchorChanges::anchors.bottom + \qmlproperty AnchorLine AnchorChanges::anchors.verticalCenter + \qmlproperty AnchorLine AnchorChanges::anchors.baseline + + These properties change the respective anchors of the item. + + To reset an anchor you can assign \c undefined: + \qml + AnchorChanges { + target: myItem + left: undefined //remove myItem's left anchor + right: otherItem.right + } + \endqml +*/ + void QDeclarativeAnchorChanges::execute() { Q_D(QDeclarativeAnchorChanges); @@ -835,36 +969,36 @@ void QDeclarativeAnchorChanges::execute() d->target->anchors()->setBaseline(d->origBaseline); //reset any anchors that have been specified - if (d->resetList.contains(QLatin1String("left"))) + if (d->anchorSet->d_func()->resetList .contains(QLatin1String("left"))) d->target->anchors()->resetLeft(); - if (d->resetList.contains(QLatin1String("right"))) + if (d->anchorSet->d_func()->resetList .contains(QLatin1String("right"))) d->target->anchors()->resetRight(); - if (d->resetList.contains(QLatin1String("horizontalCenter"))) + if (d->anchorSet->d_func()->resetList .contains(QLatin1String("horizontalCenter"))) d->target->anchors()->resetHorizontalCenter(); - if (d->resetList.contains(QLatin1String("top"))) + if (d->anchorSet->d_func()->resetList .contains(QLatin1String("top"))) d->target->anchors()->resetTop(); - if (d->resetList.contains(QLatin1String("bottom"))) + if (d->anchorSet->d_func()->resetList .contains(QLatin1String("bottom"))) d->target->anchors()->resetBottom(); - if (d->resetList.contains(QLatin1String("verticalCenter"))) + if (d->anchorSet->d_func()->resetList .contains(QLatin1String("verticalCenter"))) d->target->anchors()->resetVerticalCenter(); - if (d->resetList.contains(QLatin1String("baseline"))) + if (d->anchorSet->d_func()->resetList .contains(QLatin1String("baseline"))) d->target->anchors()->resetBaseline(); //set any anchors that have been specified - if (d->left.anchorLine != QDeclarativeAnchorLine::Invalid) - d->target->anchors()->setLeft(d->left); - if (d->right.anchorLine != QDeclarativeAnchorLine::Invalid) - d->target->anchors()->setRight(d->right); - if (d->horizontalCenter.anchorLine != QDeclarativeAnchorLine::Invalid) - d->target->anchors()->setHorizontalCenter(d->horizontalCenter); - if (d->top.anchorLine != QDeclarativeAnchorLine::Invalid) - d->target->anchors()->setTop(d->top); - if (d->bottom.anchorLine != QDeclarativeAnchorLine::Invalid) - d->target->anchors()->setBottom(d->bottom); - if (d->verticalCenter.anchorLine != QDeclarativeAnchorLine::Invalid) - d->target->anchors()->setVerticalCenter(d->verticalCenter); - if (d->baseline.anchorLine != QDeclarativeAnchorLine::Invalid) - d->target->anchors()->setBaseline(d->baseline); + if (d->anchorSet->d_func()->left.anchorLine != QDeclarativeAnchorLine::Invalid) + d->target->anchors()->setLeft(d->anchorSet->d_func()->left); + if (d->anchorSet->d_func()->right.anchorLine != QDeclarativeAnchorLine::Invalid) + d->target->anchors()->setRight(d->anchorSet->d_func()->right); + if (d->anchorSet->d_func()->hCenter.anchorLine != QDeclarativeAnchorLine::Invalid) + d->target->anchors()->setHorizontalCenter(d->anchorSet->d_func()->hCenter); + if (d->anchorSet->d_func()->top.anchorLine != QDeclarativeAnchorLine::Invalid) + d->target->anchors()->setTop(d->anchorSet->d_func()->top); + if (d->anchorSet->d_func()->bottom.anchorLine != QDeclarativeAnchorLine::Invalid) + d->target->anchors()->setBottom(d->anchorSet->d_func()->bottom); + if (d->anchorSet->d_func()->vCenter.anchorLine != QDeclarativeAnchorLine::Invalid) + d->target->anchors()->setVerticalCenter(d->anchorSet->d_func()->vCenter); + if (d->anchorSet->d_func()->baseline.anchorLine != QDeclarativeAnchorLine::Invalid) + d->target->anchors()->setBaseline(d->anchorSet->d_func()->baseline); } bool QDeclarativeAnchorChanges::isReversable() @@ -879,19 +1013,19 @@ void QDeclarativeAnchorChanges::reverse() return; //reset any anchors set by the state - if (d->left.anchorLine != QDeclarativeAnchorLine::Invalid) + if (d->anchorSet->d_func()->left.anchorLine != QDeclarativeAnchorLine::Invalid) d->target->anchors()->resetLeft(); - if (d->right.anchorLine != QDeclarativeAnchorLine::Invalid) + if (d->anchorSet->d_func()->right.anchorLine != QDeclarativeAnchorLine::Invalid) d->target->anchors()->resetRight(); - if (d->horizontalCenter.anchorLine != QDeclarativeAnchorLine::Invalid) + if (d->anchorSet->d_func()->hCenter.anchorLine != QDeclarativeAnchorLine::Invalid) d->target->anchors()->resetHorizontalCenter(); - if (d->top.anchorLine != QDeclarativeAnchorLine::Invalid) + if (d->anchorSet->d_func()->top.anchorLine != QDeclarativeAnchorLine::Invalid) d->target->anchors()->resetTop(); - if (d->bottom.anchorLine != QDeclarativeAnchorLine::Invalid) + if (d->anchorSet->d_func()->bottom.anchorLine != QDeclarativeAnchorLine::Invalid) d->target->anchors()->resetBottom(); - if (d->verticalCenter.anchorLine != QDeclarativeAnchorLine::Invalid) + if (d->anchorSet->d_func()->vCenter.anchorLine != QDeclarativeAnchorLine::Invalid) d->target->anchors()->resetVerticalCenter(); - if (d->baseline.anchorLine != QDeclarativeAnchorLine::Invalid) + if (d->anchorSet->d_func()->baseline.anchorLine != QDeclarativeAnchorLine::Invalid) d->target->anchors()->resetBaseline(); //restore previous anchors @@ -977,26 +1111,26 @@ void QDeclarativeAnchorChanges::copyOriginals(QDeclarativeActionEvent *other) QDeclarativeAnchorChangesPrivate *acp = ac->d_func(); //probably also need to revert some things - d->applyOrigLeft = (acp->left.anchorLine != QDeclarativeAnchorLine::Invalid || - acp->resetList.contains(QLatin1String("left"))); + d->applyOrigLeft = (acp->anchorSet->d_func()->left.anchorLine != QDeclarativeAnchorLine::Invalid || + acp->anchorSet->d_func()->resetList.contains(QLatin1String("left"))); - d->applyOrigRight = (acp->right.anchorLine != QDeclarativeAnchorLine::Invalid || - acp->resetList.contains(QLatin1String("right"))); + d->applyOrigRight = (acp->anchorSet->d_func()->right.anchorLine != QDeclarativeAnchorLine::Invalid || + acp->anchorSet->d_func()->resetList.contains(QLatin1String("right"))); - d->applyOrigHCenter = (acp->horizontalCenter.anchorLine != QDeclarativeAnchorLine::Invalid || - acp->resetList.contains(QLatin1String("horizontalCenter"))); + d->applyOrigHCenter = (acp->anchorSet->d_func()->hCenter.anchorLine != QDeclarativeAnchorLine::Invalid || + acp->anchorSet->d_func()->resetList.contains(QLatin1String("horizontalCenter"))); - d->applyOrigTop = (acp->top.anchorLine != QDeclarativeAnchorLine::Invalid || - acp->resetList.contains(QLatin1String("top"))); + d->applyOrigTop = (acp->anchorSet->d_func()->top.anchorLine != QDeclarativeAnchorLine::Invalid || + acp->anchorSet->d_func()->resetList.contains(QLatin1String("top"))); - d->applyOrigBottom = (acp->bottom.anchorLine != QDeclarativeAnchorLine::Invalid || - acp->resetList.contains(QLatin1String("bottom"))); + d->applyOrigBottom = (acp->anchorSet->d_func()->bottom.anchorLine != QDeclarativeAnchorLine::Invalid || + acp->anchorSet->d_func()->resetList.contains(QLatin1String("bottom"))); - d->applyOrigVCenter = (acp->verticalCenter.anchorLine != QDeclarativeAnchorLine::Invalid || - acp->resetList.contains(QLatin1String("verticalCenter"))); + d->applyOrigVCenter = (acp->anchorSet->d_func()->vCenter.anchorLine != QDeclarativeAnchorLine::Invalid || + acp->anchorSet->d_func()->resetList.contains(QLatin1String("verticalCenter"))); - d->applyOrigBaseline = (acp->baseline.anchorLine != QDeclarativeAnchorLine::Invalid || - acp->resetList.contains(QLatin1String("baseline"))); + d->applyOrigBaseline = (acp->anchorSet->d_func()->baseline.anchorLine != QDeclarativeAnchorLine::Invalid || + acp->anchorSet->d_func()->resetList.contains(QLatin1String("baseline"))); d->origLeft = ac->d_func()->origLeft; d->origRight = ac->d_func()->origRight; @@ -1034,35 +1168,35 @@ void QDeclarativeAnchorChanges::clearBindings() d->target->anchors()->resetBaseline(); //reset any anchors that have been specified - if (d->resetList.contains(QLatin1String("left"))) + if (d->anchorSet->d_func()->resetList .contains(QLatin1String("left"))) d->target->anchors()->resetLeft(); - if (d->resetList.contains(QLatin1String("right"))) + if (d->anchorSet->d_func()->resetList .contains(QLatin1String("right"))) d->target->anchors()->resetRight(); - if (d->resetList.contains(QLatin1String("horizontalCenter"))) + if (d->anchorSet->d_func()->resetList .contains(QLatin1String("horizontalCenter"))) d->target->anchors()->resetHorizontalCenter(); - if (d->resetList.contains(QLatin1String("top"))) + if (d->anchorSet->d_func()->resetList .contains(QLatin1String("top"))) d->target->anchors()->resetTop(); - if (d->resetList.contains(QLatin1String("bottom"))) + if (d->anchorSet->d_func()->resetList .contains(QLatin1String("bottom"))) d->target->anchors()->resetBottom(); - if (d->resetList.contains(QLatin1String("verticalCenter"))) + if (d->anchorSet->d_func()->resetList .contains(QLatin1String("verticalCenter"))) d->target->anchors()->resetVerticalCenter(); - if (d->resetList.contains(QLatin1String("baseline"))) + if (d->anchorSet->d_func()->resetList .contains(QLatin1String("baseline"))) d->target->anchors()->resetBaseline(); //reset any anchors that we'll be setting in the state - if (d->left.anchorLine != QDeclarativeAnchorLine::Invalid) + if (d->anchorSet->d_func()->left.anchorLine != QDeclarativeAnchorLine::Invalid) d->target->anchors()->resetLeft(); - if (d->right.anchorLine != QDeclarativeAnchorLine::Invalid) + if (d->anchorSet->d_func()->right.anchorLine != QDeclarativeAnchorLine::Invalid) d->target->anchors()->resetRight(); - if (d->horizontalCenter.anchorLine != QDeclarativeAnchorLine::Invalid) + if (d->anchorSet->d_func()->hCenter.anchorLine != QDeclarativeAnchorLine::Invalid) d->target->anchors()->resetHorizontalCenter(); - if (d->top.anchorLine != QDeclarativeAnchorLine::Invalid) + if (d->anchorSet->d_func()->top.anchorLine != QDeclarativeAnchorLine::Invalid) d->target->anchors()->resetTop(); - if (d->bottom.anchorLine != QDeclarativeAnchorLine::Invalid) + if (d->anchorSet->d_func()->bottom.anchorLine != QDeclarativeAnchorLine::Invalid) d->target->anchors()->resetBottom(); - if (d->verticalCenter.anchorLine != QDeclarativeAnchorLine::Invalid) + if (d->anchorSet->d_func()->vCenter.anchorLine != QDeclarativeAnchorLine::Invalid) d->target->anchors()->resetVerticalCenter(); - if (d->baseline.anchorLine != QDeclarativeAnchorLine::Invalid) + if (d->anchorSet->d_func()->baseline.anchorLine != QDeclarativeAnchorLine::Invalid) d->target->anchors()->resetBaseline(); } diff --git a/src/declarative/util/qdeclarativestateoperations_p.h b/src/declarative/util/qdeclarativestateoperations_p.h index 66a8717..c97b2da 100644 --- a/src/declarative/util/qdeclarativestateoperations_p.h +++ b/src/declarative/util/qdeclarativestateoperations_p.h @@ -143,54 +143,132 @@ public: virtual void execute(); }; -class QDeclarativeAnchorChangesPrivate; -class Q_DECLARATIVE_EXPORT QDeclarativeAnchorChanges : public QDeclarativeStateOperation, public QDeclarativeActionEvent +class QDeclarativeAnchorChanges; +class QDeclarativeAnchorSetPrivate; +class Q_AUTOTEST_EXPORT QDeclarativeAnchorSet : public QObject { Q_OBJECT - Q_DECLARE_PRIVATE(QDeclarativeAnchorChanges) - Q_PROPERTY(QDeclarativeItem *target READ object WRITE setObject) - Q_PROPERTY(QString reset READ reset WRITE setReset) - Q_PROPERTY(QDeclarativeAnchorLine left READ left WRITE setLeft) - Q_PROPERTY(QDeclarativeAnchorLine right READ right WRITE setRight) - Q_PROPERTY(QDeclarativeAnchorLine horizontalCenter READ horizontalCenter WRITE setHorizontalCenter) - Q_PROPERTY(QDeclarativeAnchorLine top READ top WRITE setTop) - Q_PROPERTY(QDeclarativeAnchorLine bottom READ bottom WRITE setBottom) - Q_PROPERTY(QDeclarativeAnchorLine verticalCenter READ verticalCenter WRITE setVerticalCenter) - Q_PROPERTY(QDeclarativeAnchorLine baseline READ baseline WRITE setBaseline) + Q_PROPERTY(QDeclarativeAnchorLine left READ left WRITE setLeft RESET resetLeft) + Q_PROPERTY(QDeclarativeAnchorLine right READ right WRITE setRight RESET resetRight) + Q_PROPERTY(QDeclarativeAnchorLine horizontalCenter READ horizontalCenter WRITE setHorizontalCenter RESET resetHorizontalCenter) + Q_PROPERTY(QDeclarativeAnchorLine top READ top WRITE setTop RESET resetTop) + Q_PROPERTY(QDeclarativeAnchorLine bottom READ bottom WRITE setBottom RESET resetBottom) + Q_PROPERTY(QDeclarativeAnchorLine verticalCenter READ verticalCenter WRITE setVerticalCenter RESET resetVerticalCenter) + Q_PROPERTY(QDeclarativeAnchorLine baseline READ baseline WRITE setBaseline RESET resetBaseline) + //Q_PROPERTY(QDeclarativeItem *fill READ fill WRITE setFill RESET resetFill) + //Q_PROPERTY(QDeclarativeItem *centerIn READ centerIn WRITE setCenterIn RESET resetCenterIn) + + /*Q_PROPERTY(qreal margins READ margins WRITE setMargins NOTIFY marginsChanged) + Q_PROPERTY(qreal leftMargin READ leftMargin WRITE setLeftMargin NOTIFY leftMarginChanged) + Q_PROPERTY(qreal rightMargin READ rightMargin WRITE setRightMargin NOTIFY rightMarginChanged) + Q_PROPERTY(qreal horizontalCenterOffset READ horizontalCenterOffset WRITE setHorizontalCenterOffset NOTIFY horizontalCenterOffsetChanged()) + Q_PROPERTY(qreal topMargin READ topMargin WRITE setTopMargin NOTIFY topMarginChanged) + Q_PROPERTY(qreal bottomMargin READ bottomMargin WRITE setBottomMargin NOTIFY bottomMarginChanged) + Q_PROPERTY(qreal verticalCenterOffset READ verticalCenterOffset WRITE setVerticalCenterOffset NOTIFY verticalCenterOffsetChanged()) + Q_PROPERTY(qreal baselineOffset READ baselineOffset WRITE setBaselineOffset NOTIFY baselineOffsetChanged())*/ public: - QDeclarativeAnchorChanges(QObject *parent=0); - ~QDeclarativeAnchorChanges(); - - virtual ActionList actions(); - - QDeclarativeItem *object() const; - void setObject(QDeclarativeItem *); - - QString reset() const; - void setReset(const QString &); + QDeclarativeAnchorSet(QObject *parent=0); + virtual ~QDeclarativeAnchorSet(); QDeclarativeAnchorLine left() const; void setLeft(const QDeclarativeAnchorLine &edge); + void resetLeft(); QDeclarativeAnchorLine right() const; void setRight(const QDeclarativeAnchorLine &edge); + void resetRight(); QDeclarativeAnchorLine horizontalCenter() const; void setHorizontalCenter(const QDeclarativeAnchorLine &edge); + void resetHorizontalCenter(); QDeclarativeAnchorLine top() const; void setTop(const QDeclarativeAnchorLine &edge); + void resetTop(); QDeclarativeAnchorLine bottom() const; void setBottom(const QDeclarativeAnchorLine &edge); + void resetBottom(); QDeclarativeAnchorLine verticalCenter() const; void setVerticalCenter(const QDeclarativeAnchorLine &edge); + void resetVerticalCenter(); QDeclarativeAnchorLine baseline() const; void setBaseline(const QDeclarativeAnchorLine &edge); + void resetBaseline(); + + QDeclarativeItem *fill() const; + void setFill(QDeclarativeItem *); + void resetFill(); + + QDeclarativeItem *centerIn() const; + void setCenterIn(QDeclarativeItem *); + void resetCenterIn(); + + /*qreal leftMargin() const; + void setLeftMargin(qreal); + + qreal rightMargin() const; + void setRightMargin(qreal); + + qreal horizontalCenterOffset() const; + void setHorizontalCenterOffset(qreal); + + qreal topMargin() const; + void setTopMargin(qreal); + + qreal bottomMargin() const; + void setBottomMargin(qreal); + + qreal margins() const; + void setMargins(qreal); + + qreal verticalCenterOffset() const; + void setVerticalCenterOffset(qreal); + + qreal baselineOffset() const; + void setBaselineOffset(qreal);*/ + + QDeclarativeAnchors::UsedAnchors usedAnchors() const; + +/*Q_SIGNALS: + void leftMarginChanged(); + void rightMarginChanged(); + void topMarginChanged(); + void bottomMarginChanged(); + void marginsChanged(); + void verticalCenterOffsetChanged(); + void horizontalCenterOffsetChanged(); + void baselineOffsetChanged();*/ + +private: + friend class QDeclarativeAnchorChanges; + Q_DISABLE_COPY(QDeclarativeAnchorSet) + Q_DECLARE_PRIVATE(QDeclarativeAnchorSet) +}; + +class QDeclarativeAnchorChangesPrivate; +class Q_DECLARATIVE_EXPORT QDeclarativeAnchorChanges : public QDeclarativeStateOperation, public QDeclarativeActionEvent +{ + Q_OBJECT + Q_DECLARE_PRIVATE(QDeclarativeAnchorChanges) + + Q_PROPERTY(QDeclarativeItem *target READ object WRITE setObject) + Q_PROPERTY(QDeclarativeAnchorSet *anchors READ anchors CONSTANT) + +public: + QDeclarativeAnchorChanges(QObject *parent=0); + ~QDeclarativeAnchorChanges(); + + virtual ActionList actions(); + + QDeclarativeAnchorSet *anchors(); + + QDeclarativeItem *object() const; + void setObject(QDeclarativeItem *); virtual void execute(); virtual bool isReversable(); @@ -212,6 +290,7 @@ QT_END_NAMESPACE QML_DECLARE_TYPE(QDeclarativeParentChange) QML_DECLARE_TYPE(QDeclarativeStateChangeScript) +QML_DECLARE_TYPE(QDeclarativeAnchorSet) QML_DECLARE_TYPE(QDeclarativeAnchorChanges) QT_END_HEADER diff --git a/src/declarative/util/qdeclarativeutilmodule.cpp b/src/declarative/util/qdeclarativeutilmodule.cpp index d79c6ba..2a02ffe 100644 --- a/src/declarative/util/qdeclarativeutilmodule.cpp +++ b/src/declarative/util/qdeclarativeutilmodule.cpp @@ -140,6 +140,7 @@ void QDeclarativeUtilModule::defineModule() qmlRegisterType(); qmlRegisterType(); + qmlRegisterType(); qmlRegisterTypeEnums("Animation"); diff --git a/tests/auto/declarative/qdeclarativestates/data/anchorChanges1.qml b/tests/auto/declarative/qdeclarativestates/data/anchorChanges1.qml index 7dce889..5443e54 100644 --- a/tests/auto/declarative/qdeclarativestates/data/anchorChanges1.qml +++ b/tests/auto/declarative/qdeclarativestates/data/anchorChanges1.qml @@ -16,8 +16,8 @@ Rectangle { AnchorChanges { id: ancCh target: myRect; - reset: "left" - right: container.right + anchors.left: undefined + anchors.right: container.right } } } diff --git a/tests/auto/declarative/qdeclarativestates/data/anchorChanges2.qml b/tests/auto/declarative/qdeclarativestates/data/anchorChanges2.qml index 545345e..56de560 100644 --- a/tests/auto/declarative/qdeclarativestates/data/anchorChanges2.qml +++ b/tests/auto/declarative/qdeclarativestates/data/anchorChanges2.qml @@ -14,8 +14,8 @@ Rectangle { name: "right" AnchorChanges { target: myRect; - reset: "left" - right: parent.right + anchors.left: undefined + anchors.right: parent.right } } } diff --git a/tests/auto/declarative/qdeclarativestates/data/anchorChanges3.qml b/tests/auto/declarative/qdeclarativestates/data/anchorChanges3.qml index 9d5b317..59c3c06 100644 --- a/tests/auto/declarative/qdeclarativestates/data/anchorChanges3.qml +++ b/tests/auto/declarative/qdeclarativestates/data/anchorChanges3.qml @@ -20,10 +20,10 @@ Rectangle { name: "reanchored" AnchorChanges { target: myRect; - left: leftGuideline.left - right: container.right - top: container.top - bottom: bottomGuideline.bottom + anchors.left: leftGuideline.left + anchors.right: container.right + anchors.top: container.top + anchors.bottom: bottomGuideline.bottom } } } diff --git a/tests/auto/declarative/qdeclarativestates/data/anchorChanges4.qml b/tests/auto/declarative/qdeclarativestates/data/anchorChanges4.qml index f128989..7e3ba1c 100644 --- a/tests/auto/declarative/qdeclarativestates/data/anchorChanges4.qml +++ b/tests/auto/declarative/qdeclarativestates/data/anchorChanges4.qml @@ -15,8 +15,8 @@ Rectangle { name: "reanchored" AnchorChanges { target: myRect; - horizontalCenter: bottomGuideline.horizontalCenter - verticalCenter: leftGuideline.verticalCenter + anchors.horizontalCenter: bottomGuideline.horizontalCenter + anchors.verticalCenter: leftGuideline.verticalCenter } } } diff --git a/tests/auto/declarative/qdeclarativestates/data/anchorChanges5.qml b/tests/auto/declarative/qdeclarativestates/data/anchorChanges5.qml index 4e6d34b..b85a922 100644 --- a/tests/auto/declarative/qdeclarativestates/data/anchorChanges5.qml +++ b/tests/auto/declarative/qdeclarativestates/data/anchorChanges5.qml @@ -15,8 +15,8 @@ Rectangle { name: "reanchored" AnchorChanges { target: myRect; - horizontalCenter: bottomGuideline.horizontalCenter - baseline: leftGuideline.baseline + anchors.horizontalCenter: bottomGuideline.horizontalCenter + anchors.baseline: leftGuideline.baseline } } } diff --git a/tests/auto/declarative/qdeclarativestates/tst_qdeclarativestates.cpp b/tests/auto/declarative/qdeclarativestates/tst_qdeclarativestates.cpp index 91883c9..2ab21a4 100644 --- a/tests/auto/declarative/qdeclarativestates/tst_qdeclarativestates.cpp +++ b/tests/auto/declarative/qdeclarativestates/tst_qdeclarativestates.cpp @@ -564,10 +564,10 @@ void tst_qdeclarativestates::anchorChanges() rect->setState("right"); QCOMPARE(innerRect->x(), qreal(150)); - QCOMPARE(aChanges->reset(), QString("left")); + QCOMPARE(aChanges->anchors()->left().anchorLine, QDeclarativeAnchorLine::Invalid); //### was reset (how do we distinguish from not set at all) QCOMPARE(aChanges->object(), qobject_cast(innerRect)); - QCOMPARE(aChanges->right().item, rect->right().item); - QCOMPARE(aChanges->right().anchorLine, rect->right().anchorLine); + QCOMPARE(aChanges->anchors()->right().item, rect->right().item); + QCOMPARE(aChanges->anchors()->right().anchorLine, rect->right().anchorLine); rect->setState(""); QCOMPARE(innerRect->x(), qreal(5)); @@ -623,14 +623,14 @@ void tst_qdeclarativestates::anchorChanges3() rect->setState("reanchored"); QCOMPARE(aChanges->object(), qobject_cast(innerRect)); - QCOMPARE(aChanges->left().item, leftGuideline->left().item); - QCOMPARE(aChanges->left().anchorLine, leftGuideline->left().anchorLine); - QCOMPARE(aChanges->right().item, rect->right().item); - QCOMPARE(aChanges->right().anchorLine, rect->right().anchorLine); - QCOMPARE(aChanges->top().item, rect->top().item); - QCOMPARE(aChanges->top().anchorLine, rect->top().anchorLine); - QCOMPARE(aChanges->bottom().item, bottomGuideline->bottom().item); - QCOMPARE(aChanges->bottom().anchorLine, bottomGuideline->bottom().anchorLine); + QCOMPARE(aChanges->anchors()->left().item, leftGuideline->left().item); + QCOMPARE(aChanges->anchors()->left().anchorLine, leftGuideline->left().anchorLine); + QCOMPARE(aChanges->anchors()->right().item, rect->right().item); + QCOMPARE(aChanges->anchors()->right().anchorLine, rect->right().anchorLine); + QCOMPARE(aChanges->anchors()->top().item, rect->top().item); + QCOMPARE(aChanges->anchors()->top().anchorLine, rect->top().anchorLine); + QCOMPARE(aChanges->anchors()->bottom().item, bottomGuideline->bottom().item); + QCOMPARE(aChanges->anchors()->bottom().anchorLine, bottomGuideline->bottom().anchorLine); QCOMPARE(innerRect->x(), qreal(10)); QCOMPARE(innerRect->y(), qreal(0)); @@ -673,10 +673,10 @@ void tst_qdeclarativestates::anchorChanges4() rect->setState("reanchored"); QCOMPARE(aChanges->object(), qobject_cast(innerRect)); - QCOMPARE(aChanges->horizontalCenter().item, bottomGuideline->horizontalCenter().item); - QCOMPARE(aChanges->horizontalCenter().anchorLine, bottomGuideline->horizontalCenter().anchorLine); - QCOMPARE(aChanges->verticalCenter().item, leftGuideline->verticalCenter().item); - QCOMPARE(aChanges->verticalCenter().anchorLine, leftGuideline->verticalCenter().anchorLine); + QCOMPARE(aChanges->anchors()->horizontalCenter().item, bottomGuideline->horizontalCenter().item); + QCOMPARE(aChanges->anchors()->horizontalCenter().anchorLine, bottomGuideline->horizontalCenter().anchorLine); + QCOMPARE(aChanges->anchors()->verticalCenter().item, leftGuideline->verticalCenter().item); + QCOMPARE(aChanges->anchors()->verticalCenter().anchorLine, leftGuideline->verticalCenter().anchorLine); delete rect; } @@ -708,10 +708,10 @@ void tst_qdeclarativestates::anchorChanges5() rect->setState("reanchored"); QCOMPARE(aChanges->object(), qobject_cast(innerRect)); - QCOMPARE(aChanges->horizontalCenter().item, bottomGuideline->horizontalCenter().item); - QCOMPARE(aChanges->horizontalCenter().anchorLine, bottomGuideline->horizontalCenter().anchorLine); - QCOMPARE(aChanges->baseline().item, leftGuideline->baseline().item); - QCOMPARE(aChanges->baseline().anchorLine, leftGuideline->baseline().anchorLine); + QCOMPARE(aChanges->anchors()->horizontalCenter().item, bottomGuideline->horizontalCenter().item); + QCOMPARE(aChanges->anchors()->horizontalCenter().anchorLine, bottomGuideline->horizontalCenter().anchorLine); + QCOMPARE(aChanges->anchors()->baseline().item, leftGuideline->baseline().item); + QCOMPARE(aChanges->anchors()->baseline().anchorLine, leftGuideline->baseline().anchorLine); delete rect; } diff --git a/tests/auto/declarative/visual/animation/reanchor/reanchor.qml b/tests/auto/declarative/visual/animation/reanchor/reanchor.qml index e41a254..1d0495e 100644 --- a/tests/auto/declarative/visual/animation/reanchor/reanchor.qml +++ b/tests/auto/declarative/visual/animation/reanchor/reanchor.qml @@ -36,18 +36,19 @@ Rectangle { name: "reanchored" AnchorChanges { target: myRect; - left: leftGuideline.left - right: container.right - top: container.top - bottom: bottomGuideline.bottom + anchors.left: leftGuideline.left + anchors.right: container.right + anchors.top: container.top + anchors.bottom: bottomGuideline.bottom } }, State { name: "reanchored2" AnchorChanges { target: myRect; - reset: "left, right" - top: topGuideline2.top - bottom: bottomGuideline2.bottom + anchors.left: undefined + anchors.right: undefined + anchors.top: topGuideline2.top + anchors.bottom: bottomGuideline2.bottom } }] -- cgit v0.12