From a30e67378bf56bac642d5480f8b9f3e5749dc2f6 Mon Sep 17 00:00:00 2001 From: Michael Brasser Date: Fri, 4 Dec 2009 12:25:20 +1000 Subject: Cleanup. --- src/declarative/graphicsitems/qmlgraphicstext.cpp | 28 ++++++++++------------ src/declarative/util/qmltransition.cpp | 14 +++++------ .../auto/declarative/animations/data/badtype4.qml | 1 + .../declarative/animations/data/mixedtype1.qml | 1 + .../declarative/animations/data/mixedtype2.qml | 1 + .../auto/declarative/animations/tst_animations.cpp | 6 ++--- 6 files changed, 26 insertions(+), 25 deletions(-) diff --git a/src/declarative/graphicsitems/qmlgraphicstext.cpp b/src/declarative/graphicsitems/qmlgraphicstext.cpp index 854d503..98ea80d 100644 --- a/src/declarative/graphicsitems/qmlgraphicstext.cpp +++ b/src/declarative/graphicsitems/qmlgraphicstext.cpp @@ -485,19 +485,19 @@ void QmlGraphicsTextPrivate::updateSize() //setup instance of QTextLayout for all cases other than richtext if (!richText) - { - tmp = text; - tmp.replace(QLatin1Char('\n'), QChar::LineSeparator); - singleline = !tmp.contains(QChar::LineSeparator); - if (singleline && elideMode != QmlGraphicsText::ElideNone && q->widthValid()) - tmp = fm.elidedText(tmp,(Qt::TextElideMode)elideMode,q->width()); // XXX still worth layout...? - layout.clearLayout(); - layout.setFont(font); - layout.setText(tmp); - size = setupTextLayout(&layout); - cachedLayoutSize = size; - } - if (richText) { + { + tmp = text; + tmp.replace(QLatin1Char('\n'), QChar::LineSeparator); + singleline = !tmp.contains(QChar::LineSeparator); + if (singleline && elideMode != QmlGraphicsText::ElideNone && q->widthValid()) + tmp = fm.elidedText(tmp,(Qt::TextElideMode)elideMode,q->width()); // XXX still worth layout...? + layout.clearLayout(); + layout.setFont(font); + layout.setText(tmp); + size = setupTextLayout(&layout); + cachedLayoutSize = size; + dy -= size.height(); + } else { singleline = false; // richtext can't elide or be optimized for single-line case doc->setDefaultFont(font); QTextOption option((Qt::Alignment)int(hAlign | vAlign)); @@ -511,8 +511,6 @@ void QmlGraphicsTextPrivate::updateSize() else doc->setTextWidth(doc->idealWidth()); // ### Text does not align if width is not set (QTextDoc bug) dy -= (int)doc->size().height(); - } else { - dy -= size.height(); } int yoff = 0; diff --git a/src/declarative/util/qmltransition.cpp b/src/declarative/util/qmltransition.cpp index ec92cf9..dad6c37 100644 --- a/src/declarative/util/qmltransition.cpp +++ b/src/declarative/util/qmltransition.cpp @@ -85,7 +85,7 @@ public: QmlTransitionPrivate() : fromState(QLatin1String("*")), toState(QLatin1String("*")) , reversed(false), reversible(false), group(0), endState(0) { - operations.parent = this; + animations.parent = this; } QString fromState; @@ -115,7 +115,7 @@ public: QmlTransitionPrivate *parent; }; - AnimationList operations; + AnimationList animations; }; void QmlTransitionPrivate::AnimationList::append(QmlAbstractAnimation *a) @@ -169,12 +169,12 @@ void QmlTransition::prepare(QmlStateOperation::ActionList &actions, Q_D(QmlTransition); if (d->reversed) { - for (int ii = d->operations.count() - 1; ii >= 0; --ii) { - d->operations.at(ii)->transition(actions, after, QmlAbstractAnimation::Backward); + for (int ii = d->animations.count() - 1; ii >= 0; --ii) { + d->animations.at(ii)->transition(actions, after, QmlAbstractAnimation::Backward); } } else { - for (int ii = 0; ii < d->operations.count(); ++ii) { - d->operations.at(ii)->transition(actions, after, QmlAbstractAnimation::Forward); + for (int ii = 0; ii < d->animations.count(); ++ii) { + d->animations.at(ii)->transition(actions, after, QmlAbstractAnimation::Forward); } } @@ -254,7 +254,7 @@ void QmlTransition::setToState(const QString &t) QmlList* QmlTransition::animations() { Q_D(QmlTransition); - return &d->operations; + return &d->animations; } QT_END_NAMESPACE diff --git a/tests/auto/declarative/animations/data/badtype4.qml b/tests/auto/declarative/animations/data/badtype4.qml index 5db6c17..347e581 100644 --- a/tests/auto/declarative/animations/data/badtype4.qml +++ b/tests/auto/declarative/animations/data/badtype4.qml @@ -6,6 +6,7 @@ Rectangle { height: 320 Rectangle { id: MyRect + objectName: "MyRect" color: "red" width: 50; height: 50 x: 100; y: 100 diff --git a/tests/auto/declarative/animations/data/mixedtype1.qml b/tests/auto/declarative/animations/data/mixedtype1.qml index 5ecf14f..a91c6d3 100644 --- a/tests/auto/declarative/animations/data/mixedtype1.qml +++ b/tests/auto/declarative/animations/data/mixedtype1.qml @@ -6,6 +6,7 @@ Rectangle { height: 320 Rectangle { id: MyRect + objectName: "MyRect" color: "red" width: 50; height: 50 x: 100; y: 100 diff --git a/tests/auto/declarative/animations/data/mixedtype2.qml b/tests/auto/declarative/animations/data/mixedtype2.qml index 645f1d0..d12e913 100644 --- a/tests/auto/declarative/animations/data/mixedtype2.qml +++ b/tests/auto/declarative/animations/data/mixedtype2.qml @@ -6,6 +6,7 @@ Rectangle { height: 320 Rectangle { id: MyRect + objectName: "MyRect" color: "red" width: 50; height: 50 x: 100; y: 100 diff --git a/tests/auto/declarative/animations/tst_animations.cpp b/tests/auto/declarative/animations/tst_animations.cpp index 73bed79..a6cb490 100644 --- a/tests/auto/declarative/animations/tst_animations.cpp +++ b/tests/auto/declarative/animations/tst_animations.cpp @@ -284,7 +284,7 @@ void tst_animations::badTypes() rect->setState("state1"); QTest::qWait(1000 + 50); - QmlGraphicsRectangle *myRect = qobject_cast(rect->QGraphicsObject::children().at(3)); //### not robust + QmlGraphicsRectangle *myRect = rect->findChild("MyRect"); QVERIFY(myRect); QCOMPARE(myRect->x(),qreal(200)); } @@ -324,7 +324,7 @@ void tst_animations::mixedTypes() rect->setState("state1"); QTest::qWait(500); - QmlGraphicsRectangle *myRect = qobject_cast(rect->QGraphicsObject::children().at(3)); //### not robust + QmlGraphicsRectangle *myRect = rect->findChild("MyRect"); QVERIFY(myRect); //rather inexact -- is there a better way? @@ -340,7 +340,7 @@ void tst_animations::mixedTypes() rect->setState("state1"); QTest::qWait(500); - QmlGraphicsRectangle *myRect = qobject_cast(rect->QGraphicsObject::children().at(3)); //### not robust + QmlGraphicsRectangle *myRect = rect->findChild("MyRect"); QVERIFY(myRect); //rather inexact -- is there a better way? -- cgit v0.12 From 560d32ddd80d5c6b21cd39ae93ea3f580da613da Mon Sep 17 00:00:00 2001 From: Michael Brasser Date: Mon, 7 Dec 2009 13:08:22 +1000 Subject: Minor cleanup/optimization. --- src/declarative/graphicsitems/qmlgraphicsitem_p.h | 2 -- src/declarative/graphicsitems/qmlgraphicstext_p_p.h | 10 +++++----- src/declarative/util/qmlanimation.cpp | 14 +++++++++++--- src/declarative/util/qmlanimation_p_p.h | 9 +++++---- src/declarative/util/qmltransition.cpp | 17 +++++++---------- 5 files changed, 28 insertions(+), 24 deletions(-) diff --git a/src/declarative/graphicsitems/qmlgraphicsitem_p.h b/src/declarative/graphicsitems/qmlgraphicsitem_p.h index 82950c2..a8d77ea 100644 --- a/src/declarative/graphicsitems/qmlgraphicsitem_p.h +++ b/src/declarative/graphicsitems/qmlgraphicsitem_p.h @@ -119,8 +119,6 @@ public: heightIdx = QmlGraphicsItem::staticMetaObject.indexOfSignal("heightChanged()"); } } - ~QmlGraphicsItemPrivate() - { delete _anchors; } void init(QmlGraphicsItem *parent) { diff --git a/src/declarative/graphicsitems/qmlgraphicstext_p_p.h b/src/declarative/graphicsitems/qmlgraphicstext_p_p.h index 0ddae57..6fbee50 100644 --- a/src/declarative/graphicsitems/qmlgraphicstext_p_p.h +++ b/src/declarative/graphicsitems/qmlgraphicstext_p_p.h @@ -101,11 +101,11 @@ public: QPixmap imgStyleCache; QmlGraphicsText::HAlignment hAlign; QmlGraphicsText::VAlignment vAlign; - QmlGraphicsText::TextElideMode elideMode; - bool dirty; - bool wrap; - bool richText; - bool singleline; + QmlGraphicsText::TextElideMode elideMode; + bool dirty:1; + bool wrap:1; + bool richText:1; + bool singleline:1; QTextControl *control; QTextDocument *doc; QTextLayout layout; diff --git a/src/declarative/util/qmlanimation.cpp b/src/declarative/util/qmlanimation.cpp index 00e3056..0143791 100644 --- a/src/declarative/util/qmlanimation.cpp +++ b/src/declarative/util/qmlanimation.cpp @@ -1608,9 +1608,6 @@ void QmlPropertyAnimationPrivate::init() Q_Q(QmlPropertyAnimation); va = new QmlTimeLineValueAnimator; QmlGraphics_setParent_noEvent(va, q); - - va->setStartValue(QVariant(0.0f)); - va->setEndValue(QVariant(1.0f)); } /*! @@ -2022,6 +2019,12 @@ void QmlPropertyAnimation::prepare(QmlMetaProperty &p) else d->property = d->userProperty; + if (!d->rangeIsSet) { + d->va->setStartValue(QVariant(0.0f)); + d->va->setEndValue(QVariant(1.0f)); + d->rangeIsSet = true; + } + int propType = d->property.propertyType(); d->convertVariant(d->to, d->interpolatorType ? d->interpolatorType : propType); if (d->fromIsDefined) @@ -2179,6 +2182,11 @@ void QmlPropertyAnimation::transition(QmlStateActions &actions, } if (data->actions.count()) { + if (!d->rangeIsSet) { + d->va->setStartValue(QVariant(0.0f)); + d->va->setEndValue(QVariant(1.0f)); + d->rangeIsSet = true; + } d->va->setAnimValue(data, QAbstractAnimation::DeleteWhenStopped); } else { delete data; diff --git a/src/declarative/util/qmlanimation_p_p.h b/src/declarative/util/qmlanimation_p_p.h index 71b6caa..71fa9a3 100644 --- a/src/declarative/util/qmlanimation_p_p.h +++ b/src/declarative/util/qmlanimation_p_p.h @@ -343,7 +343,7 @@ class QmlPropertyAnimationPrivate : public QmlAbstractAnimationPrivate public: QmlPropertyAnimationPrivate() : QmlAbstractAnimationPrivate(), fromSourced(false), fromIsDefined(false), toIsDefined(false), - defaultToInterpolatorType(0), interpolatorType(0), interpolator(0), va(0), + rangeIsSet(false), defaultToInterpolatorType(0), interpolatorType(0), interpolator(0), va(0), value(this, &QmlPropertyAnimationPrivate::valueChanged) {} void init(); @@ -358,9 +358,10 @@ public: QList exclude; bool fromSourced; - bool fromIsDefined; - bool toIsDefined; - bool defaultToInterpolatorType; + bool fromIsDefined:1; + bool toIsDefined:1; + bool rangeIsSet:1; + bool defaultToInterpolatorType:1; int interpolatorType; QVariantAnimation::Interpolator interpolator; diff --git a/src/declarative/util/qmltransition.cpp b/src/declarative/util/qmltransition.cpp index dad6c37..b96ff61 100644 --- a/src/declarative/util/qmltransition.cpp +++ b/src/declarative/util/qmltransition.cpp @@ -83,7 +83,7 @@ class QmlTransitionPrivate : public QObjectPrivate Q_DECLARE_PUBLIC(QmlTransition) public: QmlTransitionPrivate() : fromState(QLatin1String("*")), toState(QLatin1String("*")) - , reversed(false), reversible(false), group(0), endState(0) + , reversed(false), reversible(false), endState(0) { animations.parent = this; } @@ -92,13 +92,12 @@ public: QString toState; bool reversed; bool reversible; - ParallelAnimationWrapper *group; + ParallelAnimationWrapper group; QmlTransitionManager *endState; void init() { - group = new ParallelAnimationWrapper; - group->trans = this; + group.trans = this; } void complete() @@ -121,7 +120,7 @@ public: void QmlTransitionPrivate::AnimationList::append(QmlAbstractAnimation *a) { QmlConcreteList::append(a); - parent->group->addAnimation(a->qtAnimation()); + parent->group.addAnimation(a->qtAnimation()); } void ParallelAnimationWrapper::updateState(QAbstractAnimation::State newState, QAbstractAnimation::State oldState) @@ -146,14 +145,12 @@ QmlTransition::QmlTransition(QObject *parent) QmlTransition::~QmlTransition() { - Q_D(QmlTransition); - delete d->group; } void QmlTransition::stop() { Q_D(QmlTransition); - d->group->stop(); + d->group.stop(); } void QmlTransition::setReversed(bool r) @@ -179,8 +176,8 @@ void QmlTransition::prepare(QmlStateOperation::ActionList &actions, } d->endState = endState; - d->group->setDirection(d->reversed ? QAbstractAnimation::Backward : QAbstractAnimation::Forward); - d->group->start(); + d->group.setDirection(d->reversed ? QAbstractAnimation::Backward : QAbstractAnimation::Forward); + d->group.start(); } /*! -- cgit v0.12 From 55a3fda3baf545cc7fbfa6b2c00705be40a7319b Mon Sep 17 00:00:00 2001 From: Michael Brasser Date: Mon, 7 Dec 2009 13:22:25 +1000 Subject: Move target/property functions to their appropriate classes. --- src/declarative/util/qmlanimation.cpp | 138 +++++++++++++++++++++----------- src/declarative/util/qmlanimation_p.h | 21 +++-- src/declarative/util/qmlanimation_p_p.h | 12 +-- 3 files changed, 112 insertions(+), 59 deletions(-) diff --git a/src/declarative/util/qmlanimation.cpp b/src/declarative/util/qmlanimation.cpp index 0143791..8afe667 100644 --- a/src/declarative/util/qmlanimation.cpp +++ b/src/declarative/util/qmlanimation.cpp @@ -422,50 +422,6 @@ void QmlAbstractAnimation::setGroup(QmlAnimationGroup *g) setParent(g); } -QObject *QmlAbstractAnimation::target() const -{ - Q_D(const QmlAbstractAnimation); - return d->target; -} - -void QmlAbstractAnimation::setTarget(QObject *o) -{ - Q_D(QmlAbstractAnimation); - if (d->target == o) - return; - - d->target = o; - if (d->target && !d->propertyName.isEmpty()) { - d->userProperty = d->createProperty(d->target, d->propertyName, this); - } else { - d->userProperty.invalidate(); - } - - emit targetChanged(d->target, d->propertyName); -} - -QString QmlAbstractAnimation::property() const -{ - Q_D(const QmlAbstractAnimation); - return d->propertyName; -} - -void QmlAbstractAnimation::setProperty(const QString &n) -{ - Q_D(QmlAbstractAnimation); - if (d->propertyName == n) - return; - - d->propertyName = n; - if (d->target && !d->propertyName.isEmpty()) { - d->userProperty = d->createProperty(d->target, d->propertyName, this); - } else { - d->userProperty.invalidate(); - } - - emit targetChanged(d->target, d->propertyName); -} - /*! \qmlmethod Animation::start() \brief Starts the animation. @@ -886,6 +842,28 @@ void QmlPropertyActionPrivate::init() is being used. Refer to the \l animation documentation for details. */ +QObject *QmlPropertyAction::target() const +{ + Q_D(const QmlPropertyAction); + return d->target; +} + +void QmlPropertyAction::setTarget(QObject *o) +{ + Q_D(QmlPropertyAction); + if (d->target == o) + return; + + d->target = o; + if (d->target && !d->propertyName.isEmpty()) { + d->userProperty = d->createProperty(d->target, d->propertyName, this); + } else { + d->userProperty.invalidate(); + } + + emit targetChanged(d->target, d->propertyName); +} + /*! \qmlproperty string PropertyAction::property This property holds an explicit property to animated. @@ -894,6 +872,28 @@ void QmlPropertyActionPrivate::init() is being used. Refer to the \l animation documentation for details. */ +QString QmlPropertyAction::property() const +{ + Q_D(const QmlPropertyAction); + return d->propertyName; +} + +void QmlPropertyAction::setProperty(const QString &n) +{ + Q_D(QmlPropertyAction); + if (d->propertyName == n) + return; + + d->propertyName = n; + if (d->target && !d->propertyName.isEmpty()) { + d->userProperty = d->createProperty(d->target, d->propertyName, this); + } else { + d->userProperty.invalidate(); + } + + emit targetChanged(d->target, d->propertyName); +} + /*! \qmlproperty string PropertyAction::matchProperties This property holds a comma-separated list of property names this action @@ -1445,10 +1445,10 @@ void QmlSequentialAnimation::transition(QmlStateActions &actions, } //needed for Behavior - if (d->userProperty.isValid() && d->propertyName.isEmpty() && !target()) { + if (d->userProperty.isValid()) { for (int i = 0; i < d->animations.count(); ++i) d->animations.at(i)->setTarget(d->userProperty); - } + } for (int ii = from; ii < d->animations.count() && ii >= 0; ii += inc) { d->animations.at(ii)->transition(actions, modified, direction); @@ -1517,7 +1517,7 @@ void QmlParallelAnimation::transition(QmlStateActions &actions, Q_D(QmlAnimationGroup); //needed for Behavior - if (d->userProperty.isValid() && d->propertyName.isEmpty() && !target()) { + if (d->userProperty.isValid()) { for (int i = 0; i < d->animations.count(); ++i) d->animations.at(i)->setTarget(d->userProperty); } @@ -1881,6 +1881,28 @@ void QmlPropertyAnimation::setEasing(const QString &e) \sa property matchTargets */ +QObject *QmlPropertyAnimation::target() const +{ + Q_D(const QmlPropertyAnimation); + return d->target; +} + +void QmlPropertyAnimation::setTarget(QObject *o) +{ + Q_D(QmlPropertyAnimation); + if (d->target == o) + return; + + d->target = o; + if (d->target && !d->propertyName.isEmpty()) { + d->userProperty = d->createProperty(d->target, d->propertyName, this); + } else { + d->userProperty.invalidate(); + } + + emit targetChanged(d->target, d->propertyName); +} + /*! \qmlproperty string PropertyAnimation::property This property holds an explicit property name to animate. @@ -1891,6 +1913,28 @@ void QmlPropertyAnimation::setEasing(const QString &e) \sa target matchProperties */ +QString QmlPropertyAnimation::property() const +{ + Q_D(const QmlPropertyAnimation); + return d->propertyName; +} + +void QmlPropertyAnimation::setProperty(const QString &n) +{ + Q_D(QmlPropertyAnimation); + if (d->propertyName == n) + return; + + d->propertyName = n; + if (d->target && !d->propertyName.isEmpty()) { + d->userProperty = d->createProperty(d->target, d->propertyName, this); + } else { + d->userProperty.invalidate(); + } + + emit targetChanged(d->target, d->propertyName); +} + /*! \qmlproperty string PropertyAnimation::matchProperties This property holds a comma-separated list of property names this animation diff --git a/src/declarative/util/qmlanimation_p.h b/src/declarative/util/qmlanimation_p.h index 707ed33..322f048 100644 --- a/src/declarative/util/qmlanimation_p.h +++ b/src/declarative/util/qmlanimation_p.h @@ -94,12 +94,6 @@ public: QmlAnimationGroup *group() const; void setGroup(QmlAnimationGroup *); - //### these belong at a lower level in the hierarchy - QObject *target() const; - void setTarget(QObject *); - QString property() const; - void setProperty(const QString &); - virtual void setTarget(const QmlMetaProperty &); void classBegin(); @@ -111,7 +105,6 @@ Q_SIGNALS: void runningChanged(bool); void pausedChanged(bool); void repeatChanged(bool); - void targetChanged(QObject *, const QString &); void alwaysRunToEndChanged(bool); public Q_SLOTS: @@ -202,6 +195,12 @@ public: QmlPropertyAction(QObject *parent=0); virtual ~QmlPropertyAction(); + QObject *target() const; + void setTarget(QObject *); + + QString property() const; + void setProperty(const QString &); + QString properties() const; void setProperties(const QString &); @@ -214,6 +213,7 @@ public: Q_SIGNALS: void valueChanged(const QVariant &); void propertiesChanged(const QString &); + void targetChanged(QObject *, const QString &); protected: virtual void transition(QmlStateActions &actions, @@ -286,6 +286,12 @@ public: QString easing() const; void setEasing(const QString &); + QObject *target() const; + void setTarget(QObject *); + + QString property() const; + void setProperty(const QString &); + QString properties() const; void setProperties(const QString &); @@ -305,6 +311,7 @@ Q_SIGNALS: void toChanged(QVariant); void easingChanged(const QString &); void propertiesChanged(const QString &); + void targetChanged(QObject *, const QString &); }; class Q_AUTOTEST_EXPORT QmlColorAnimation : public QmlPropertyAnimation diff --git a/src/declarative/util/qmlanimation_p_p.h b/src/declarative/util/qmlanimation_p_p.h index 71fa9a3..fbd7114 100644 --- a/src/declarative/util/qmlanimation_p_p.h +++ b/src/declarative/util/qmlanimation_p_p.h @@ -203,7 +203,7 @@ public: QmlAbstractAnimationPrivate() : running(false), paused(false), alwaysRunToEnd(false), repeat(false), connectedTimeLine(false), componentComplete(true), startOnCompletion(false), - target(0), group(0) {} + group(0) {} bool running:1; bool paused:1; @@ -217,8 +217,6 @@ public: void commence(); QmlNullableValue userProperty; - QObject *target; - QString propertyName; QmlMetaProperty property; QmlAnimationGroup *group; @@ -264,10 +262,12 @@ class QmlPropertyActionPrivate : public QmlAbstractAnimationPrivate Q_DECLARE_PUBLIC(QmlPropertyAction) public: QmlPropertyActionPrivate() - : QmlAbstractAnimationPrivate(), proxy(this), spa(0) {} + : QmlAbstractAnimationPrivate(), target(0), proxy(this), spa(0) {} void init(); + QObject *target; + QString propertyName; QString properties; QList targets; QList exclude; @@ -342,7 +342,7 @@ class QmlPropertyAnimationPrivate : public QmlAbstractAnimationPrivate Q_DECLARE_PUBLIC(QmlPropertyAnimation) public: QmlPropertyAnimationPrivate() - : QmlAbstractAnimationPrivate(), fromSourced(false), fromIsDefined(false), toIsDefined(false), + : QmlAbstractAnimationPrivate(), target(0), fromSourced(false), fromIsDefined(false), toIsDefined(false), rangeIsSet(false), defaultToInterpolatorType(0), interpolatorType(0), interpolator(0), va(0), value(this, &QmlPropertyAnimationPrivate::valueChanged) {} @@ -353,6 +353,8 @@ public: QString easing; + QObject *target; + QString propertyName; QString properties; QList targets; QList exclude; -- cgit v0.12