diff options
author | Martin Jones <martin.jones@nokia.com> | 2009-07-27 07:08:23 (GMT) |
---|---|---|
committer | Martin Jones <martin.jones@nokia.com> | 2009-07-27 07:08:23 (GMT) |
commit | 10c75fb244f57b7caaf72cd570883e8c8bb5da7d (patch) | |
tree | 886ef437f51a4f4973d876bf368e25752e815258 /src/declarative/util | |
parent | 2ea4aec304eefa10a554e40c5f9ea948d18617a7 (diff) | |
parent | 27bc8c55608f0363ef49ce79efa9e0cd9f464fae (diff) | |
download | Qt-10c75fb244f57b7caaf72cd570883e8c8bb5da7d.zip Qt-10c75fb244f57b7caaf72cd570883e8c8bb5da7d.tar.gz Qt-10c75fb244f57b7caaf72cd570883e8c8bb5da7d.tar.bz2 |
Merge branch 'kinetic-declarativeui' of git@scm.dev.nokia.troll.no:qt/kinetic into kinetic-declarativeui
Diffstat (limited to 'src/declarative/util')
-rw-r--r-- | src/declarative/util/qmlfontfamily.cpp | 13 | ||||
-rw-r--r-- | src/declarative/util/qmlfontfamily.h | 4 | ||||
-rw-r--r-- | src/declarative/util/qmlscript.cpp | 4 | ||||
-rw-r--r-- | src/declarative/util/qmlstate.cpp | 28 | ||||
-rw-r--r-- | src/declarative/util/qmlstate.h | 9 | ||||
-rw-r--r-- | src/declarative/util/qmlstateoperations.cpp | 241 | ||||
-rw-r--r-- | src/declarative/util/qmlstateoperations.h | 49 | ||||
-rw-r--r-- | src/declarative/util/qmltransitionmanager.cpp | 46 |
8 files changed, 381 insertions, 13 deletions
diff --git a/src/declarative/util/qmlfontfamily.cpp b/src/declarative/util/qmlfontfamily.cpp index 407d2ab..e539085 100644 --- a/src/declarative/util/qmlfontfamily.cpp +++ b/src/declarative/util/qmlfontfamily.cpp @@ -57,13 +57,14 @@ class QmlFontFamilyPrivate : public QObjectPrivate Q_DECLARE_PUBLIC(QmlFontFamily); public: - QmlFontFamilyPrivate() : reply(0) {} + QmlFontFamilyPrivate() : reply(0), loading(false) {} void addFontToDatabase(const QByteArray &); QUrl url; QString name; QNetworkReply *reply; + bool loading; }; QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,FontFamily,QmlFontFamily) @@ -94,6 +95,8 @@ void QmlFontFamily::setSource(const QUrl &url) return; d->url = qmlContext(this)->resolvedUrl(url); + d->loading = true; + emit loadingChanged(); #ifndef QT_NO_LOCALFILE_OPTIMIZED_QML if (d->url.scheme() == QLatin1String("file")) { QFile file(d->url.toLocalFile()); @@ -125,6 +128,12 @@ void QmlFontFamily::setName(const QString &name) emit nameChanged(); } +bool QmlFontFamily::isLoading() const +{ + Q_D(const QmlFontFamily); + return d->loading; +} + void QmlFontFamily::replyFinished() { Q_D(QmlFontFamily); @@ -144,6 +153,8 @@ void QmlFontFamilyPrivate::addFontToDatabase(const QByteArray &ba) if (id != -1) { name = QFontDatabase::applicationFontFamilies(id).at(0); emit q->nameChanged(); + loading = false; + emit q->loadingChanged(); } else { qWarning() << "Cannot load font: " << name << url; } diff --git a/src/declarative/util/qmlfontfamily.h b/src/declarative/util/qmlfontfamily.h index 739a553..c647f67 100644 --- a/src/declarative/util/qmlfontfamily.h +++ b/src/declarative/util/qmlfontfamily.h @@ -59,6 +59,7 @@ class Q_DECLARATIVE_EXPORT QmlFontFamily : public QObject Q_PROPERTY(QUrl source READ source WRITE setSource NOTIFY sourceChanged) Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged) + Q_PROPERTY(bool loading READ isLoading NOTIFY loadingChanged) public: QmlFontFamily(QObject *parent = 0); @@ -70,11 +71,14 @@ public: QString name() const; void setName(const QString &name); + bool isLoading() const; + private Q_SLOTS: void replyFinished(); Q_SIGNALS: void nameChanged(); + void loadingChanged(); }; QT_END_NAMESPACE diff --git a/src/declarative/util/qmlscript.cpp b/src/declarative/util/qmlscript.cpp index cfe5a1e..ca9aad5 100644 --- a/src/declarative/util/qmlscript.cpp +++ b/src/declarative/util/qmlscript.cpp @@ -185,9 +185,9 @@ void QmlScriptPrivate::addScriptToEngine(const QString &script, const QString &s Q_Q(QmlScript); QmlEngine *engine = qmlEngine(q); QmlContext *context = qmlContext(q); - QScriptEngine *scriptEngine = engine->scriptEngine(); + QScriptEngine *scriptEngine = QmlEnginePrivate::getScriptEngine(engine); - QScriptContext *currentContext = engine->scriptEngine()->currentContext(); + QScriptContext *currentContext = scriptEngine->currentContext(); QScriptValueList oldScopeChain = currentContext->scopeChain(); QScriptValue oldact = currentContext->activationObject(); diff --git a/src/declarative/util/qmlstate.cpp b/src/declarative/util/qmlstate.cpp index a5fe8a7..c41c31a 100644 --- a/src/declarative/util/qmlstate.cpp +++ b/src/declarative/util/qmlstate.cpp @@ -92,6 +92,24 @@ void ActionEvent::reverse() { } +QList<Action> ActionEvent::extraActions() +{ + return QList<Action>(); +} + +bool ActionEvent::changesBindings() +{ + return false; +} + +void ActionEvent::clearForwardBindings() +{ +} + +void ActionEvent::clearReverseBindings() +{ +} + /*! \internal */ @@ -399,10 +417,12 @@ void QmlState::apply(QmlStateGroup *group, QmlTransition *trans, QmlState *rever // into this state need to be translated into apply actions for (int ii = 0; ii < d->revertList.count(); ++ii) { bool found = false; - for (int jj = 0; !found && jj < applyList.count(); ++jj) { - const Action &action = applyList.at(jj); - if (action.property == d->revertList.at(ii).property) - found = true; + if (!d->revertList.at(ii).event) { //### corresponding test for events? + for (int jj = 0; !found && jj < applyList.count(); ++jj) { + const Action &action = applyList.at(jj); + if (action.property == d->revertList.at(ii).property) + found = true; + } } if (!found) { QVariant cur = d->revertList.at(ii).property.read(); diff --git a/src/declarative/util/qmlstate.h b/src/declarative/util/qmlstate.h index e453446..7b3021b 100644 --- a/src/declarative/util/qmlstate.h +++ b/src/declarative/util/qmlstate.h @@ -73,6 +73,7 @@ public: QmlBinding *toBinding; ActionEvent *event; + //strictly for matching QObject *specifiedObject; QString specifiedProperty; @@ -84,9 +85,17 @@ class ActionEvent public: virtual ~ActionEvent(); virtual QString typeName() const; + virtual void execute(); virtual bool isReversable(); virtual void reverse(); + + //virtual bool hasExtraActions(); + virtual QList<Action> extraActions(); + + virtual bool changesBindings(); + virtual void clearForwardBindings(); + virtual void clearReverseBindings(); }; class QmlStateGroup; diff --git a/src/declarative/util/qmlstateoperations.cpp b/src/declarative/util/qmlstateoperations.cpp index 791628c..e2cbae4 100644 --- a/src/declarative/util/qmlstateoperations.cpp +++ b/src/declarative/util/qmlstateoperations.cpp @@ -272,4 +272,245 @@ QmlRunScript::ActionList QmlRunScript::actions() return rv; } +/*! + \qmlclass SetAnchors + \brief The SetAnchors element allows you to change anchors in a state. +*/ + +QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,SetAnchors,QmlSetAnchors) + +class QmlSetAnchorsPrivate : public QObjectPrivate +{ +public: + QmlSetAnchorsPrivate() : target(0) {} + + QString name; + QFxItem *target; + QString resetString; + QStringList resetList; + QFxAnchorLine left; + QFxAnchorLine right; + QFxAnchorLine top; + QFxAnchorLine bottom; + QFxAnchorLine origLeft; + QFxAnchorLine origRight; + QFxAnchorLine origTop; + QFxAnchorLine origBottom; + qreal origX; + qreal origY; + qreal origWidth; + qreal origHeight; +}; + +QmlSetAnchors::QmlSetAnchors(QObject *parent) + : QmlStateOperation(*(new QmlSetAnchorsPrivate), parent) +{ +} + +QmlSetAnchors::~QmlSetAnchors() +{ +} + +QmlSetAnchors::ActionList QmlSetAnchors::actions() +{ + Action a; + a.event = this; + return ActionList() << a; +} + +QFxItem *QmlSetAnchors::object() const +{ + Q_D(const QmlSetAnchors); + return d->target; +} + +void QmlSetAnchors::setObject(QFxItem *target) +{ + Q_D(QmlSetAnchors); + d->target = target; +} + +QString QmlSetAnchors::reset() const +{ + Q_D(const QmlSetAnchors); + return d->resetString; +} + +void QmlSetAnchors::setReset(const QString &reset) +{ + Q_D(QmlSetAnchors); + d->resetString = reset; + d->resetList = d->resetString.split(QLatin1Char(',')); +} + +QFxAnchorLine QmlSetAnchors::left() const +{ + Q_D(const QmlSetAnchors); + return d->left; +} + +void QmlSetAnchors::setLeft(const QFxAnchorLine &edge) +{ + Q_D(QmlSetAnchors); + d->left = edge; +} + +QFxAnchorLine QmlSetAnchors::right() const +{ + Q_D(const QmlSetAnchors); + return d->right; +} + +void QmlSetAnchors::setRight(const QFxAnchorLine &edge) +{ + Q_D(QmlSetAnchors); + d->right = edge; +} + +QFxAnchorLine QmlSetAnchors::top() const +{ + Q_D(const QmlSetAnchors); + return d->top; +} + +void QmlSetAnchors::setTop(const QFxAnchorLine &edge) +{ + Q_D(QmlSetAnchors); + d->top = edge; +} + +QFxAnchorLine QmlSetAnchors::bottom() const +{ + Q_D(const QmlSetAnchors); + return d->bottom; +} + +void QmlSetAnchors::setBottom(const QFxAnchorLine &edge) +{ + Q_D(QmlSetAnchors); + d->bottom = edge; +} + +void QmlSetAnchors::execute() +{ + Q_D(QmlSetAnchors); + if (!d->target) + return; + + //set any anchors that have been specified + if (d->left.anchorLine != QFxAnchorLine::Invalid) + d->target->anchors()->setLeft(d->left); + if (d->right.anchorLine != QFxAnchorLine::Invalid) + d->target->anchors()->setRight(d->right); + if (d->top.anchorLine != QFxAnchorLine::Invalid) + d->target->anchors()->setTop(d->top); + if (d->bottom.anchorLine != QFxAnchorLine::Invalid) + d->target->anchors()->setBottom(d->bottom); +} + +bool QmlSetAnchors::isReversable() +{ + return true; +} + +void QmlSetAnchors::reverse() +{ + Q_D(QmlSetAnchors); + if (!d->target) + return; + + //restore previous anchors + if (d->origLeft.anchorLine != QFxAnchorLine::Invalid) + d->target->anchors()->setLeft(d->origLeft); + if (d->origRight.anchorLine != QFxAnchorLine::Invalid) + d->target->anchors()->setRight(d->origRight); + if (d->origTop.anchorLine != QFxAnchorLine::Invalid) + d->target->anchors()->setTop(d->origTop); + if (d->origBottom.anchorLine != QFxAnchorLine::Invalid) + d->target->anchors()->setBottom(d->origBottom); + +} + +QString QmlSetAnchors::typeName() const +{ + return QLatin1String("SetAnchors"); +} + +QList<Action> QmlSetAnchors::extraActions() +{ + Q_D(QmlSetAnchors); + QList<Action> extra; + + //### try to be smarter about which ones we add. + // or short-circuit later on if they haven't actually changed. + // we shouldn't set explicit width if there wasn't one before. + if (d->target) { + Action a; + a.fromValue = d->origX; + a.property = QmlMetaProperty(d->target, "x"); + extra << a; + + a.fromValue = d->origY; + a.property = QmlMetaProperty(d->target, "y"); + extra << a; + + a.fromValue = d->origWidth; + a.property = QmlMetaProperty(d->target, "width"); + extra << a; + + a.fromValue = d->origHeight; + a.property = QmlMetaProperty(d->target, "height"); + extra << a; + } + + return extra; +} + +bool QmlSetAnchors::changesBindings() +{ + return true; +} + +void QmlSetAnchors::clearForwardBindings() +{ + Q_D(QmlSetAnchors); + d->origLeft = d->target->anchors()->left(); + d->origRight = d->target->anchors()->right(); + d->origTop = d->target->anchors()->top(); + d->origBottom = d->target->anchors()->bottom(); + d->origX = d->target->x(); + d->origY = d->target->y(); + d->origWidth = d->target->width(); + d->origHeight = d->target->height(); + + //reset any anchors that have been specified + if (d->resetList.contains(QLatin1String("left"))) + d->target->anchors()->resetLeft(); + if (d->resetList.contains(QLatin1String("right"))) + d->target->anchors()->resetRight(); + if (d->resetList.contains(QLatin1String("top"))) + d->target->anchors()->resetTop(); + if (d->resetList.contains(QLatin1String("bottom"))) + d->target->anchors()->resetBottom(); +} + +void QmlSetAnchors::clearReverseBindings() +{ + Q_D(QmlSetAnchors); + d->origX = d->target->x(); + d->origY = d->target->y(); + d->origWidth = d->target->width(); + d->origHeight = d->target->height(); + + //reset any anchors that were set in the state + if (d->left.anchorLine != QFxAnchorLine::Invalid) + d->target->anchors()->resetLeft(); + if (d->right.anchorLine != QFxAnchorLine::Invalid) + d->target->anchors()->resetRight(); + if (d->top.anchorLine != QFxAnchorLine::Invalid) + d->target->anchors()->resetTop(); + if (d->bottom.anchorLine != QFxAnchorLine::Invalid) + d->target->anchors()->resetBottom(); +} + QT_END_NAMESPACE diff --git a/src/declarative/util/qmlstateoperations.h b/src/declarative/util/qmlstateoperations.h index 67cd1cf..f595e16 100644 --- a/src/declarative/util/qmlstateoperations.h +++ b/src/declarative/util/qmlstateoperations.h @@ -44,6 +44,7 @@ #include <QtDeclarative/qmlstate.h> #include <QtDeclarative/qfxitem.h> +#include <QtDeclarative/qfxanchors.h> QT_BEGIN_HEADER @@ -101,10 +102,58 @@ public: virtual void execute(); }; +class QmlSetAnchorsPrivate; +class Q_DECLARATIVE_EXPORT QmlSetAnchors : public QmlStateOperation, public ActionEvent +{ + Q_OBJECT + Q_DECLARE_PRIVATE(QmlSetAnchors) + + Q_PROPERTY(QFxItem *target READ object WRITE setObject) + Q_PROPERTY(QString reset READ reset WRITE setReset) + Q_PROPERTY(QFxAnchorLine left READ left WRITE setLeft) + Q_PROPERTY(QFxAnchorLine right READ right WRITE setRight) + Q_PROPERTY(QFxAnchorLine top READ top WRITE setTop) + Q_PROPERTY(QFxAnchorLine bottom READ bottom WRITE setBottom) + +public: + QmlSetAnchors(QObject *parent=0); + ~QmlSetAnchors(); + + virtual ActionList actions(); + + QFxItem *object() const; + void setObject(QFxItem *); + + QString reset() const; + void setReset(const QString &); + + QFxAnchorLine left() const; + void setLeft(const QFxAnchorLine &edge); + + QFxAnchorLine right() const; + void setRight(const QFxAnchorLine &edge); + + QFxAnchorLine top() const; + void setTop(const QFxAnchorLine &edge); + + QFxAnchorLine bottom() const; + void setBottom(const QFxAnchorLine &edge); + + virtual void execute(); + virtual bool isReversable(); + virtual void reverse(); + virtual QString typeName() const; + virtual QList<Action> extraActions(); + virtual bool changesBindings(); + virtual void clearForwardBindings(); + virtual void clearReverseBindings(); +}; + QT_END_NAMESPACE QML_DECLARE_TYPE(QmlParentChange) QML_DECLARE_TYPE(QmlRunScript) +QML_DECLARE_TYPE(QmlSetAnchors) QT_END_HEADER diff --git a/src/declarative/util/qmltransitionmanager.cpp b/src/declarative/util/qmltransitionmanager.cpp index 4609de8..b2d9414 100644 --- a/src/declarative/util/qmltransitionmanager.cpp +++ b/src/declarative/util/qmltransitionmanager.cpp @@ -95,7 +95,13 @@ void QmlTransitionManagerPrivate::applyBindings() if (action.toBinding) { action.property.setBinding(action.toBinding); action.toBinding->forceUpdate(); + } else if (action.event) { + if (action.reverseEvent) + action.event->reverse(); + else + action.event->execute(); } + } bindingsList.clear(); @@ -113,6 +119,13 @@ void QmlTransitionManager::transition(const QList<Action> &list, d->bindingsList << action; if (action.fromBinding) action.property.setBinding(0); // Disable current binding + if (action.event && action.event->changesBindings()) { //### assume isReversable()? + d->bindingsList << action; + if (action.reverseEvent) + action.event->clearReverseBindings(); + else + action.event->clearForwardBindings(); + } } // Animated transitions need both the start and the end value for @@ -126,13 +139,22 @@ void QmlTransitionManager::transition(const QList<Action> &list, if (!d->bindingsList.isEmpty()) { + //### do extra actions here? + // Apply all the property and binding changes - foreach(const Action &action, applyList) { + for (int ii = 0; ii < applyList.size(); ++ii) { + const Action &action = applyList.at(ii); if (action.toBinding) { action.property.setBinding(action.toBinding); action.toBinding->forceUpdate(); } else if (!action.event) { action.property.write(action.toValue); + } else if (action.event->isReversable()) { + if (action.reverseEvent) + action.event->reverse(); + else + action.event->execute(); + applyList << action.event->extraActions(); } } @@ -141,16 +163,28 @@ void QmlTransitionManager::transition(const QList<Action> &list, Action *action = &applyList[ii]; if (action->event) continue; - const QmlMetaProperty &prop = action->property; - if (action->toBinding) + if (action->toBinding || !action->toValue.isValid()) { //### is this always right (used for exta actions) action->toValue = prop.read(); + } } // Revert back to the original values foreach(const Action &action, applyList) { - if (action.event) + if (action.event) { + if (action.event->isReversable()) { + if (action.reverseEvent) { //reverse the reverse + action.event->clearForwardBindings(); + action.event->execute(); + action.event->clearReverseBindings(); + } else { + action.event->clearReverseBindings(); + action.event->reverse(); + action.event->clearForwardBindings(); + } + } continue; + } if (action.toBinding) action.property.setBinding(0); // Make sure this is disabled during the transition @@ -195,12 +229,12 @@ void QmlTransitionManager::transition(const QList<Action> &list, // applied at the end in applyBindings() to avoid any nastiness mid // transition foreach(const Action &action, applyList) { - if (action.event) { + if (action.event && !action.event->changesBindings()) { if (action.event->isReversable() && action.reverseEvent) action.event->reverse(); else action.event->execute(); - } else { + } else if (!action.event) { action.property.write(action.toValue); } } |