diff options
Diffstat (limited to 'src/declarative/util')
-rw-r--r-- | src/declarative/util/qmlfollow.cpp | 53 | ||||
-rw-r--r-- | src/declarative/util/qmlfollow.h | 5 | ||||
-rw-r--r-- | src/declarative/util/qmlpalette.cpp | 11 | ||||
-rw-r--r-- | src/declarative/util/qmlpalette.h | 16 | ||||
-rw-r--r-- | src/declarative/util/qmltimer.cpp | 11 | ||||
-rw-r--r-- | src/declarative/util/qmltimer.h | 1 |
6 files changed, 77 insertions, 20 deletions
diff --git a/src/declarative/util/qmlfollow.cpp b/src/declarative/util/qmlfollow.cpp index 36e7f14..987ccb0 100644 --- a/src/declarative/util/qmlfollow.cpp +++ b/src/declarative/util/qmlfollow.cpp @@ -56,7 +56,8 @@ class QmlFollowPrivate : public QObjectPrivate public: QmlFollowPrivate() : sourceValue(0), maxVelocity(0), lastTime(0) - , mass(1.0), spring(0.), damping(0.), velocity(0), epsilon(0.01), modulus(0.0), enabled(true), mode(Track), clock(this) {} + , mass(1.0), useMass(false), spring(0.), damping(0.), velocity(0), epsilon(0.01) + , modulus(0.0), haveModulus(false), enabled(true), mode(Track), clock(this) {} QmlMetaProperty property; qreal currentValue; @@ -70,6 +71,8 @@ public: qreal velocity; qreal epsilon; qreal modulus; + bool haveModulus; + bool useMass; bool enabled; enum Mode { @@ -95,7 +98,7 @@ void QmlFollowPrivate::tick(int time) if (!elapsed) return; qreal srcVal = sourceValue; - if (modulus != 0.0) { + if (haveModulus) { currentValue = fmod(currentValue, modulus); srcVal = fmod(srcVal, modulus); } @@ -107,15 +110,16 @@ void QmlFollowPrivate::tick(int time) int count = elapsed / 16; for (int i = 0; i < count; ++i) { qreal diff = srcVal - currentValue; - if (modulus != 0.0 && qAbs(diff) > modulus / 2) { + if (haveModulus && qAbs(diff) > modulus / 2) { if (diff < 0) diff += modulus; else diff -= modulus; } - velocity = velocity + spring * diff - damping * velocity; - // The following line supports mass. Not sure its worth the extra divisions. - // velocity = velocity + spring / mass * diff - damping / mass * velocity; + if (useMass) + velocity = velocity + (spring * diff - damping * velocity) / mass; + else + velocity = velocity + spring * diff - damping * velocity; if (maxVelocity > 0.) { // limit velocity if (velocity > maxVelocity) @@ -124,7 +128,7 @@ void QmlFollowPrivate::tick(int time) velocity = -maxVelocity; } currentValue += velocity * 16.0 / 1000.0; - if (modulus != 0.0) { + if (haveModulus) { currentValue = fmod(currentValue, modulus); if (currentValue < 0.0) currentValue += modulus; @@ -139,7 +143,7 @@ void QmlFollowPrivate::tick(int time) } else { qreal moveBy = elapsed * velocityms; qreal diff = srcVal - currentValue; - if (modulus != 0.0 && qAbs(diff) > modulus / 2) { + if (haveModulus && qAbs(diff) > modulus / 2) { if (diff < 0) diff += modulus; else @@ -147,7 +151,7 @@ void QmlFollowPrivate::tick(int time) } if (diff > 0) { currentValue += moveBy; - if (modulus != 0.0) + if (haveModulus) currentValue = fmod(currentValue, modulus); if (currentValue > sourceValue) { currentValue = sourceValue; @@ -155,7 +159,7 @@ void QmlFollowPrivate::tick(int time) } } else { currentValue -= moveBy; - if (modulus != 0.0 && currentValue < 0.0) + if (haveModulus && currentValue < 0.0) currentValue = fmod(currentValue, modulus) + modulus; if (currentValue < sourceValue) { currentValue = sourceValue; @@ -375,7 +379,34 @@ qreal QmlFollow::modulus() const void QmlFollow::setModulus(qreal modulus) { Q_D(QmlFollow); - d->modulus = modulus; + if (d->modulus != modulus) { + d->haveModulus = modulus != 0.0; + d->modulus = modulus; + emit modulusChanged(); + } +} + +/*! + \qmlproperty qreal Follow::mass + This property holds the "mass" of the property being moved. + + mass is 1.0 by default. Setting a different mass changes the dynamics of + a \l spring follow. +*/ +qreal QmlFollow::mass() const +{ + Q_D(const QmlFollow); + return d->mass; +} + +void QmlFollow::setMass(qreal mass) +{ + Q_D(QmlFollow); + if (d->mass != mass && mass > 0.0) { + d->useMass = mass != 1.0; + d->mass = mass; + emit massChanged(); + } } /*! diff --git a/src/declarative/util/qmlfollow.h b/src/declarative/util/qmlfollow.h index e0a588b..5c1093e 100644 --- a/src/declarative/util/qmlfollow.h +++ b/src/declarative/util/qmlfollow.h @@ -68,6 +68,7 @@ class Q_DECLARATIVE_EXPORT QmlFollow : public QmlPropertyValueSource, Q_PROPERTY(bool enabled READ enabled WRITE setEnabled) Q_PROPERTY(qreal followValue READ value NOTIFY valueChanged) Q_PROPERTY(qreal modulus READ modulus WRITE setModulus NOTIFY modulusChanged) + Q_PROPERTY(qreal mass READ mass WRITE setMass NOTIFY massChanged) Q_PROPERTY(bool inSync READ inSync NOTIFY syncChanged) public: @@ -86,6 +87,8 @@ public: void setDamping(qreal damping); qreal epsilon() const; void setEpsilon(qreal epsilon); + qreal mass() const; + void setMass(qreal modulus); qreal modulus() const; void setModulus(qreal modulus); bool enabled() const; @@ -96,6 +99,8 @@ public: Q_SIGNALS: void valueChanged(qreal); + void modulusChanged(); + void massChanged(); void syncChanged(); }; diff --git a/src/declarative/util/qmlpalette.cpp b/src/declarative/util/qmlpalette.cpp index 01b5ad3..3a6dadc 100644 --- a/src/declarative/util/qmlpalette.cpp +++ b/src/declarative/util/qmlpalette.cpp @@ -161,10 +161,17 @@ QColor QmlPalette::darker(const QColor& color) const return color.darker(); } -void QmlPalette::setColorGroup(QPalette::ColorGroup colorGroup) +QmlPalette::ColorGroup QmlPalette::colorGroup() const +{ + Q_D(const QmlPalette); + return (QmlPalette::ColorGroup)int(d->group); +} + +void QmlPalette::setColorGroup(ColorGroup colorGroup) { Q_D(QmlPalette); - d->group = colorGroup; + d->group = (QPalette::ColorGroup)int(colorGroup); + emit paletteChanged(); } QPalette QmlPalette::palette() const diff --git a/src/declarative/util/qmlpalette.h b/src/declarative/util/qmlpalette.h index 7f26f9a..3030557 100644 --- a/src/declarative/util/qmlpalette.h +++ b/src/declarative/util/qmlpalette.h @@ -57,11 +57,9 @@ class Q_DECLARATIVE_EXPORT QmlPalette : public QObject { Q_OBJECT Q_DECLARE_PRIVATE(QmlPalette) + Q_ENUMS(ColorGroup) -public: - QmlPalette(QObject *parent=0); - ~QmlPalette(); - + Q_PROPERTY(ColorGroup colorGroup READ colorGroup WRITE setColorGroup NOTIFY paletteChanged) Q_PROPERTY(QColor window READ window NOTIFY paletteChanged) Q_PROPERTY(QColor windowText READ windowText NOTIFY paletteChanged) Q_PROPERTY(QColor base READ base NOTIFY paletteChanged) @@ -76,6 +74,13 @@ public: Q_PROPERTY(QColor highlight READ highlight NOTIFY paletteChanged) Q_PROPERTY(QColor highlightedText READ highlightedText NOTIFY paletteChanged) +public: + QmlPalette(QObject *parent=0); + ~QmlPalette(); + + enum ColorGroup { Disabled = QPalette::Disabled, Active = QPalette::Active, + Inactive = QPalette::Inactive, Normal = QPalette::Normal }; + QColor window() const; QColor windowText() const; @@ -96,7 +101,8 @@ public: QPalette palette() const; - void setColorGroup(QPalette::ColorGroup); + ColorGroup colorGroup() const; + void setColorGroup(ColorGroup); bool virtual eventFilter(QObject *watched, QEvent *event); bool virtual event(QEvent *event); diff --git a/src/declarative/util/qmltimer.cpp b/src/declarative/util/qmltimer.cpp index 456b2ef..2d3a343 100644 --- a/src/declarative/util/qmltimer.cpp +++ b/src/declarative/util/qmltimer.cpp @@ -55,12 +55,13 @@ class QmlTimerPrivate : public QObjectPrivate public: QmlTimerPrivate() : interval(1000), running(false), repeating(false), triggeredOnStart(false) - , componentComplete(false) {} + , classBegun(false), componentComplete(false) {} int interval; bool running; bool repeating; bool triggeredOnStart; QPauseAnimation pause; + bool classBegun; bool componentComplete; }; @@ -190,7 +191,7 @@ void QmlTimer::setTriggeredOnStart(bool triggeredOnStart) void QmlTimer::update() { Q_D(QmlTimer); - if (!d->componentComplete) + if (d->classBegun && !d->componentComplete) return; d->pause.stop(); if (d->running) { @@ -204,6 +205,12 @@ void QmlTimer::update() } } +void QmlTimer::classBegin() +{ + Q_D(QmlTimer); + d->classBegun = true; +} + void QmlTimer::componentComplete() { Q_D(QmlTimer); diff --git a/src/declarative/util/qmltimer.h b/src/declarative/util/qmltimer.h index 0df4cb9..d376834 100644 --- a/src/declarative/util/qmltimer.h +++ b/src/declarative/util/qmltimer.h @@ -80,6 +80,7 @@ public: void setTriggeredOnStart(bool triggeredOnStart); protected: + void classBegin(); void componentComplete(); Q_SIGNALS: |