diff options
author | Warwick Allison <warwick.allison@nokia.com> | 2010-03-11 07:33:49 (GMT) |
---|---|---|
committer | Warwick Allison <warwick.allison@nokia.com> | 2010-03-11 07:33:49 (GMT) |
commit | 79dc9daa146410c7da8d4691e9a4489251980ab3 (patch) | |
tree | 2dbc8acba470d4943ffe5e527da71290812e043e /src | |
parent | 162287900e724947e976ec5bdcc1bcb99639b5ab (diff) | |
parent | 54bdab8b88777488f9f0d944698fbb155cf703af (diff) | |
download | Qt-79dc9daa146410c7da8d4691e9a4489251980ab3.zip Qt-79dc9daa146410c7da8d4691e9a4489251980ab3.tar.gz Qt-79dc9daa146410c7da8d4691e9a4489251980ab3.tar.bz2 |
Merge branch '4.7' of scm.dev.nokia.troll.no:qt/qt-qml into 4.7
Diffstat (limited to 'src')
35 files changed, 767 insertions, 235 deletions
diff --git a/src/declarative/QmlChanges.txt b/src/declarative/QmlChanges.txt index 591fb3d..f83dd58 100644 --- a/src/declarative/QmlChanges.txt +++ b/src/declarative/QmlChanges.txt @@ -1,6 +1,7 @@ ============================================================================= The changes below are pre Qt 4.7.0 alpha +ListView, GridView::positionViewAtIndex() gained a 'mode' parameter Flickable: renamed viewportWidth -> contentWidth Flickable: renamed viewportHeight -> contentHeight Flickable: renamed viewportX -> contentX diff --git a/src/declarative/graphicsitems/graphicsitems.pri b/src/declarative/graphicsitems/graphicsitems.pri index 3ff92b1..d30651b 100644 --- a/src/declarative/graphicsitems/graphicsitems.pri +++ b/src/declarative/graphicsitems/graphicsitems.pri @@ -48,7 +48,6 @@ HEADERS += \ $$PWD/qdeclarativevisualitemmodel_p.h \ $$PWD/qdeclarativelistview_p.h \ $$PWD/qdeclarativegraphicsobjectcontainer_p.h \ - $$PWD/qdeclarativeparticles_p.h \ $$PWD/qdeclarativelayoutitem_p.h \ $$PWD/qdeclarativeitemchangelistener_p.h \ $$PWD/qdeclarativeeffects.cpp @@ -82,5 +81,4 @@ SOURCES += \ $$PWD/qdeclarativevisualitemmodel.cpp \ $$PWD/qdeclarativelistview.cpp \ $$PWD/qdeclarativegraphicsobjectcontainer.cpp \ - $$PWD/qdeclarativeparticles.cpp \ - $$PWD/qdeclarativelayoutitem.cpp \ + $$PWD/qdeclarativelayoutitem.cpp diff --git a/src/declarative/graphicsitems/qdeclarativefocuspanel.cpp b/src/declarative/graphicsitems/qdeclarativefocuspanel.cpp index 0323a59..20524b6 100644 --- a/src/declarative/graphicsitems/qdeclarativefocuspanel.cpp +++ b/src/declarative/graphicsitems/qdeclarativefocuspanel.cpp @@ -41,6 +41,8 @@ #include "qdeclarativefocuspanel_p.h" +#include "qdeclarativeitem_p.h" + #include <QtGui/qgraphicsscene.h> #include <QEvent> @@ -65,7 +67,8 @@ QT_BEGIN_NAMESPACE QDeclarativeFocusPanel::QDeclarativeFocusPanel(QDeclarativeItem *parent) : QDeclarativeItem(parent) { - setFlag(ItemIsPanel); + Q_D(QDeclarativeItem); + d->flags |= QGraphicsItem::ItemIsPanel; } QDeclarativeFocusPanel::~QDeclarativeFocusPanel() diff --git a/src/declarative/graphicsitems/qdeclarativefocuspanel_p.h b/src/declarative/graphicsitems/qdeclarativefocuspanel_p.h index 1ad8b6e..d9ca0b0 100644 --- a/src/declarative/graphicsitems/qdeclarativefocuspanel_p.h +++ b/src/declarative/graphicsitems/qdeclarativefocuspanel_p.h @@ -66,6 +66,7 @@ protected: private: Q_DISABLE_COPY(QDeclarativeFocusPanel) + Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QDeclarativeItem) }; QT_END_NAMESPACE diff --git a/src/declarative/graphicsitems/qdeclarativefocusscope.cpp b/src/declarative/graphicsitems/qdeclarativefocusscope.cpp index 384a47b..484df13 100644 --- a/src/declarative/graphicsitems/qdeclarativefocusscope.cpp +++ b/src/declarative/graphicsitems/qdeclarativefocusscope.cpp @@ -41,6 +41,8 @@ #include "qdeclarativefocusscope_p.h" +#include "qdeclarativeitem_p.h" + QT_BEGIN_NAMESPACE /*! @@ -62,7 +64,8 @@ QT_BEGIN_NAMESPACE QDeclarativeFocusScope::QDeclarativeFocusScope(QDeclarativeItem *parent) : QDeclarativeItem(parent) { - setFlag(QGraphicsItem::ItemIsFocusScope); + Q_D(QDeclarativeItem); + d->flags |= QGraphicsItem::ItemIsFocusScope; } QDeclarativeFocusScope::~QDeclarativeFocusScope() diff --git a/src/declarative/graphicsitems/qdeclarativefocusscope_p.h b/src/declarative/graphicsitems/qdeclarativefocusscope_p.h index cd480b4..c65a07c 100644 --- a/src/declarative/graphicsitems/qdeclarativefocusscope_p.h +++ b/src/declarative/graphicsitems/qdeclarativefocusscope_p.h @@ -54,6 +54,7 @@ QT_MODULE(Declarative) class Q_DECLARATIVE_EXPORT QDeclarativeFocusScope : public QDeclarativeItem { Q_OBJECT + Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QDeclarativeItem) public: QDeclarativeFocusScope(QDeclarativeItem *parent=0); virtual ~QDeclarativeFocusScope(); diff --git a/src/declarative/graphicsitems/qdeclarativegridview.cpp b/src/declarative/graphicsitems/qdeclarativegridview.cpp index e66bcf6..b1391f9 100644 --- a/src/declarative/graphicsitems/qdeclarativegridview.cpp +++ b/src/declarative/graphicsitems/qdeclarativegridview.cpp @@ -1666,47 +1666,84 @@ void QDeclarativeGridView::moveCurrentIndexRight() } /*! - \qmlmethod GridView::positionViewAtIndex(int index) + \qmlmethod GridView::positionViewAtIndex(int index, PositionMode mode) + + Positions the view such that the \a index is at the position specified by + \a mode: + + \list + \o Beginning - position item at the top (or left for TopToBottom flow) of the view. + \o Center- position item in the center of the view. + \o End - position item at bottom (or right for horizontal orientation) of the view. + \o Visible - if any part of the item is visible then take no action, otherwise + bring the item into view. + \o Contain - ensure the entire item is visible. If the item is larger than + the view the item is positioned at the top (or left for TopToBottom flow) of the view. + \endlist - Positions the view such that the \a index is at the top (or left for horizontal orientation) of the view. If positioning the view at the index would cause empty space to be displayed at - the end of the view, the view will be positioned at the end. + the beginning or end of the view, the view will be positioned at the boundary. It is not recommended to use contentX or contentY to position the view at a particular index. This is unreliable since removing items from the start - of the list does not cause all other items to be repositioned. + of the view does not cause all other items to be repositioned. The correct way to bring an item into view is with positionViewAtIndex. */ -void QDeclarativeGridView::positionViewAtIndex(int index) +void QDeclarativeGridView::positionViewAtIndex(int index, int mode) { Q_D(QDeclarativeGridView); if (!d->isValid() || index < 0 || index >= d->model->count()) return; + if (mode < Beginning || mode > Contain) + return; - qreal maxExtent = d->flow == QDeclarativeGridView::LeftToRight ? -maxYExtent() : -maxXExtent(); + qreal pos = d->position(); FxGridItem *item = d->visibleItem(index); - if (item) { - // Already created - just move to top of view - int pos = qMin(item->rowPos(), maxExtent); - d->setPosition(pos); - } else { - int pos = d->rowPosAt(index); + if (!item) { + int itemPos = d->rowPosAt(index); // save the currently visible items in case any of them end up visible again QList<FxGridItem*> oldVisible = d->visibleItems; d->visibleItems.clear(); d->visibleIndex = index - index % d->columns; - d->setPosition(pos); - // setPosition() will cause refill. Adjust if we have moved beyond range - if (d->position() > maxExtent) - d->setPosition(maxExtent); + d->setPosition(itemPos); // now release the reference to all the old visible items. for (int i = 0; i < oldVisible.count(); ++i) d->releaseItem(oldVisible.at(i)); + item = d->visibleItem(index); + } + if (item) { + qreal itemPos = item->rowPos(); + switch (mode) { + case Beginning: + pos = itemPos; + break; + case Center: + pos = itemPos - (d->size() - d->rowSize())/2; + break; + case End: + pos = itemPos - d->size() + d->rowSize(); + break; + case Visible: + if (itemPos > pos + d->size()) + pos = itemPos - d->size() + d->rowSize(); + else if (item->endRowPos() < pos) + pos = itemPos; + break; + case Contain: + if (item->endRowPos() > pos + d->size()) + pos = itemPos - d->size() + d->rowSize(); + if (itemPos < pos) + pos = itemPos; + } + qreal maxExtent = d->flow == QDeclarativeGridView::LeftToRight ? -maxYExtent() : -maxXExtent(); + pos = qMin(pos, maxExtent); + qreal minExtent = d->flow == QDeclarativeGridView::LeftToRight ? -minYExtent() : -minXExtent(); + pos = qMax(pos, minExtent); + d->setPosition(pos); } d->fixupPosition(); } - void QDeclarativeGridView::componentComplete() { Q_D(QDeclarativeGridView); diff --git a/src/declarative/graphicsitems/qdeclarativegridview_p.h b/src/declarative/graphicsitems/qdeclarativegridview_p.h index 8e253e5..f14ec14 100644 --- a/src/declarative/graphicsitems/qdeclarativegridview_p.h +++ b/src/declarative/graphicsitems/qdeclarativegridview_p.h @@ -137,6 +137,9 @@ public: SnapMode snapMode() const; void setSnapMode(SnapMode mode); + enum PositionMode { Beginning, Center, End, Visible, Contain }; + Q_ENUMS(PositionMode) + static QDeclarativeGridViewAttached *qmlAttachedProperties(QObject *); public Q_SLOTS: @@ -144,7 +147,7 @@ public Q_SLOTS: void moveCurrentIndexDown(); void moveCurrentIndexLeft(); void moveCurrentIndexRight(); - void positionViewAtIndex(int index); + void positionViewAtIndex(int index, int mode); Q_SIGNALS: void countChanged(); diff --git a/src/declarative/graphicsitems/qdeclarativeitemsmodule.cpp b/src/declarative/graphicsitems/qdeclarativeitemsmodule.cpp index 2d05c7c..2ac55a4 100644 --- a/src/declarative/graphicsitems/qdeclarativeitemsmodule.cpp +++ b/src/declarative/graphicsitems/qdeclarativeitemsmodule.cpp @@ -65,7 +65,6 @@ #include "qdeclarativelistview_p.h" #include "qdeclarativeloader_p.h" #include "qdeclarativemousearea_p.h" -#include "qdeclarativeparticles_p.h" #include "qdeclarativepath_p.h" #include "qdeclarativepathview_p.h" #include "qdeclarativerectangle_p.h" @@ -108,11 +107,6 @@ void QDeclarativeItemModule::defineModule() qmlRegisterType<QDeclarativeLoader>("Qt",4,6,"Loader"); qmlRegisterType<QDeclarativeMouseArea>("Qt",4,6,"MouseArea"); qmlRegisterType<QGraphicsOpacityEffect>("Qt",4,6,"Opacity"); - qmlRegisterType<QDeclarativeParticleMotion>("Qt",4,6,"ParticleMotion"); - qmlRegisterType<QDeclarativeParticleMotionGravity>("Qt",4,6,"ParticleMotionGravity"); - qmlRegisterType<QDeclarativeParticleMotionLinear>("Qt",4,6,"ParticleMotionLinear"); - qmlRegisterType<QDeclarativeParticleMotionWander>("Qt",4,6,"ParticleMotionWander"); - qmlRegisterType<QDeclarativeParticles>("Qt",4,6,"Particles"); qmlRegisterType<QDeclarativePath>("Qt",4,6,"Path"); qmlRegisterType<QDeclarativePathAttribute>("Qt",4,6,"PathAttribute"); qmlRegisterType<QDeclarativePathCubic>("Qt",4,6,"PathCubic"); diff --git a/src/declarative/graphicsitems/qdeclarativelistview.cpp b/src/declarative/graphicsitems/qdeclarativelistview.cpp index b988e6e..9e6a67a 100644 --- a/src/declarative/graphicsitems/qdeclarativelistview.cpp +++ b/src/declarative/graphicsitems/qdeclarativelistview.cpp @@ -2180,11 +2180,23 @@ void QDeclarativeListView::decrementCurrentIndex() } /*! - \qmlmethod ListView::positionViewAtIndex(int index) + \qmlmethod ListView::positionViewAtIndex(int index, PositionMode mode) + + Positions the view such that the \a index is at the position specified by + \a mode: + + \list + \o Beginning - position item at the top (or left for horizontal orientation) of the view. + \o Center- position item in the center of the view. + \o End - position item at bottom (or right for horizontal orientation) of the view. + \o Visible - if any part of the item is visible then take no action, otherwise + bring the item into view. + \o Contain - ensure the entire item is visible. If the item is larger than + the view the item is positioned at the top (or left for horizontal orientation) of the view. + \endlist - Positions the view such that the \a index is at the top (or left for horizontal orientation) of the view. If positioning the view at the index would cause empty space to be displayed at - the end of the view, the view will be positioned at the end. + the beginning or end of the view, the view will be positioned at the boundary. It is not recommended to use contentX or contentY to position the view at a particular index. This is unreliable since removing items from the start @@ -2192,32 +2204,58 @@ void QDeclarativeListView::decrementCurrentIndex() the actual start of the view can vary based on the size of the delegates. The correct way to bring an item into view is with positionViewAtIndex. */ -void QDeclarativeListView::positionViewAtIndex(int index) +void QDeclarativeListView::positionViewAtIndex(int index, int mode) { Q_D(QDeclarativeListView); if (!d->isValid() || index < 0 || index >= d->model->count()) return; + if (mode < Beginning || mode > Contain) + return; - qreal maxExtent = d->orient == QDeclarativeListView::Vertical ? -maxYExtent() : -maxXExtent(); + qreal pos = d->position(); FxListItem *item = d->visibleItem(index); - if (item) { - // Already created - just move to top of view - int pos = qMin(item->position(), maxExtent); - d->setPosition(pos); - } else { - int pos = d->positionAt(index); + if (!item) { + int itemPos = d->positionAt(index); // save the currently visible items in case any of them end up visible again QList<FxListItem*> oldVisible = d->visibleItems; d->visibleItems.clear(); - d->visiblePos = pos; + d->visiblePos = itemPos; d->visibleIndex = index; - d->setPosition(pos); - // setPosition() will cause refill. Adjust if we have moved beyond range. - if (d->position() > maxExtent) - d->setPosition(maxExtent); + d->setPosition(itemPos); // now release the reference to all the old visible items. for (int i = 0; i < oldVisible.count(); ++i) d->releaseItem(oldVisible.at(i)); + item = d->visibleItem(index); + } + if (item) { + const qreal itemPos = item->position(); + switch (mode) { + case Beginning: + pos = itemPos; + break; + case Center: + pos = itemPos - (d->size() - item->size())/2; + break; + case End: + pos = itemPos - d->size() + item->size(); + break; + case Visible: + if (itemPos > pos + d->size()) + pos = itemPos - d->size() + item->size(); + else if (item->endPosition() < pos) + pos = itemPos; + break; + case Contain: + if (item->endPosition() > pos + d->size()) + pos = itemPos - d->size() + item->size(); + if (itemPos < pos) + pos = itemPos; + } + qreal maxExtent = d->orient == QDeclarativeListView::Vertical ? -maxYExtent() : -maxXExtent(); + pos = qMin(pos, maxExtent); + qreal minExtent = d->orient == QDeclarativeListView::Vertical ? -minYExtent() : -minXExtent(); + pos = qMax(pos, minExtent); + d->setPosition(pos); } d->fixupPosition(); } diff --git a/src/declarative/graphicsitems/qdeclarativelistview_p.h b/src/declarative/graphicsitems/qdeclarativelistview_p.h index 1bf9652..0c2677c 100644 --- a/src/declarative/graphicsitems/qdeclarativelistview_p.h +++ b/src/declarative/graphicsitems/qdeclarativelistview_p.h @@ -191,10 +191,13 @@ public: static QDeclarativeListViewAttached *qmlAttachedProperties(QObject *); + enum PositionMode { Beginning, Center, End, Visible, Contain }; + Q_ENUMS(PositionMode) + public Q_SLOTS: void incrementCurrentIndex(); void decrementCurrentIndex(); - void positionViewAtIndex(int index); + void positionViewAtIndex(int index, int mode); Q_SIGNALS: void countChanged(); diff --git a/src/declarative/qml/qdeclarativebinding.cpp b/src/declarative/qml/qdeclarativebinding.cpp index 88ca5cd..bc78b5b 100644 --- a/src/declarative/qml/qdeclarativebinding.cpp +++ b/src/declarative/qml/qdeclarativebinding.cpp @@ -223,7 +223,7 @@ void QDeclarativeBinding::setEnabled(bool e, QDeclarativePropertyPrivate::WriteF int QDeclarativeBinding::propertyIndex() { Q_D(QDeclarativeBinding); - return d->bindingData()->property.index(); + return QDeclarativePropertyPrivate::bindingIndex(d->bindingData()->property); } bool QDeclarativeBinding::enabled() const @@ -259,23 +259,57 @@ void QDeclarativeAbstractBinding::addToObject(QObject *object) { Q_ASSERT(object); + if (m_object == object) + return; + + int index = propertyIndex(); + removeFromObject(); Q_ASSERT(!m_prevBinding); - QDeclarativeDeclarativeData *data = QDeclarativeDeclarativeData::get(object, true); - m_nextBinding = data->bindings; - if (m_nextBinding) m_nextBinding->m_prevBinding = &m_nextBinding; - m_prevBinding = &data->bindings; - data->bindings = this; m_object = object; + QDeclarativeDeclarativeData *data = QDeclarativeDeclarativeData::get(object, true); + + if (index & 0xFF000000) { + // Value type - data->setBindingBit(m_object, propertyIndex()); + int coreIndex = index & 0xFFFFFF; + + // Find the value type proxy (if there is one) + QDeclarativeValueTypeProxyBinding *proxy = 0; + if (data->hasBindingBit(coreIndex)) { + QDeclarativeAbstractBinding *b = data->bindings; + while (b && b->propertyIndex() != coreIndex) + b = b->m_nextBinding; + Q_ASSERT(b && b->bindingType() == QDeclarativeAbstractBinding::ValueTypeProxy); + proxy = static_cast<QDeclarativeValueTypeProxyBinding *>(b); + } + + if (!proxy) + proxy = new QDeclarativeValueTypeProxyBinding(object, coreIndex); + proxy->addToObject(object); + + m_nextBinding = proxy->m_bindings; + if (m_nextBinding) m_nextBinding->m_prevBinding = &m_nextBinding; + m_prevBinding = &proxy->m_bindings; + proxy->m_bindings = this; + + } else { + m_nextBinding = data->bindings; + if (m_nextBinding) m_nextBinding->m_prevBinding = &m_nextBinding; + m_prevBinding = &data->bindings; + data->bindings = this; + + data->setBindingBit(m_object, index); + } } void QDeclarativeAbstractBinding::removeFromObject() { if (m_prevBinding) { + int index = propertyIndex(); + Q_ASSERT(m_object); *m_prevBinding = m_nextBinding; @@ -283,8 +317,14 @@ void QDeclarativeAbstractBinding::removeFromObject() m_prevBinding = 0; m_nextBinding = 0; - QDeclarativeDeclarativeData *data = QDeclarativeDeclarativeData::get(m_object, false); - if (data) data->clearBindingBit(propertyIndex()); + if (index & 0xFF000000) { + // Value type - we don't remove the proxy from the object. It will sit their happily + // doing nothing for ever more. + } else { + QDeclarativeDeclarativeData *data = QDeclarativeDeclarativeData::get(m_object, false); + if (data) data->clearBindingBit(index); + } + m_object = 0; } } @@ -305,4 +345,88 @@ void QDeclarativeAbstractBinding::setEnabled(bool e, QDeclarativePropertyPrivate if (e) m_mePtr = 0; } +QDeclarativeValueTypeProxyBinding::QDeclarativeValueTypeProxyBinding(QObject *o, int index) +: m_object(o), m_index(index), m_bindings(0) +{ +} + +QDeclarativeValueTypeProxyBinding::~QDeclarativeValueTypeProxyBinding() +{ + while (m_bindings) { + QDeclarativeAbstractBinding *binding = m_bindings; + binding->setEnabled(false, 0); + binding->destroy(); + } +} + +void QDeclarativeValueTypeProxyBinding::setEnabled(bool e, QDeclarativePropertyPrivate::WriteFlags flags) +{ + if (e) { + addToObject(m_object); + + QDeclarativeAbstractBinding *bindings = m_bindings; + m_bindings = 0; + recursiveEnable(bindings, flags); + } else { + removeFromObject(); + + QDeclarativeAbstractBinding *bindings = m_bindings; + m_bindings = 0; + recursiveDisable(bindings); + } +} + +void QDeclarativeValueTypeProxyBinding::recursiveEnable(QDeclarativeAbstractBinding *b, QDeclarativePropertyPrivate::WriteFlags flags) +{ + if (!b) + return; + + QDeclarativeAbstractBinding *next = b->m_nextBinding; + b->m_prevBinding = 0; + b->m_nextBinding = 0; + Q_ASSERT(b->m_mePtr == 0); + b->m_mePtr = &b; + + recursiveEnable(next, flags); + + if (b) + b->setEnabled(true, flags); +} + +void QDeclarativeValueTypeProxyBinding::recursiveDisable(QDeclarativeAbstractBinding *b) +{ + if (!b) + return; + + recursiveDisable(b->m_nextBinding); + + b->setEnabled(false, 0); + + Q_ASSERT(b->m_prevBinding == 0); + Q_ASSERT(b->m_nextBinding == 0); + b->m_nextBinding = m_bindings; + if (b->m_nextBinding) b->m_nextBinding->m_prevBinding = &b->m_nextBinding; + b->m_prevBinding = &m_bindings; + m_bindings = b; +} + +int QDeclarativeValueTypeProxyBinding::propertyIndex() +{ + return m_index; +} + +void QDeclarativeValueTypeProxyBinding::update(QDeclarativePropertyPrivate::WriteFlags) +{ +} + +QDeclarativeAbstractBinding *QDeclarativeValueTypeProxyBinding::binding(int propertyIndex) +{ + QDeclarativeAbstractBinding *binding = m_bindings; + + while (binding && binding->propertyIndex() != propertyIndex) + binding = binding->m_nextBinding; + + return binding; +} + QT_END_NAMESPACE diff --git a/src/declarative/qml/qdeclarativebinding_p.h b/src/declarative/qml/qdeclarativebinding_p.h index 1a714f0..21e3248 100644 --- a/src/declarative/qml/qdeclarativebinding_p.h +++ b/src/declarative/qml/qdeclarativebinding_p.h @@ -74,6 +74,9 @@ public: virtual QString expression() const; + enum Type { PropertyBinding, ValueTypeProxy }; + virtual Type bindingType() const { return PropertyBinding; } + void setEnabled(bool e) { setEnabled(e, QDeclarativePropertyPrivate::DontRemoveBinding); } virtual void setEnabled(bool, QDeclarativePropertyPrivate::WriteFlags) = 0; virtual int propertyIndex() = 0; @@ -92,6 +95,7 @@ private: friend class QDeclarativeProperty; friend class QDeclarativePropertyPrivate; friend class QDeclarativeVME; + friend class QDeclarativeValueTypeProxyBinding; QObject *m_object; QDeclarativeAbstractBinding **m_mePtr; @@ -99,6 +103,30 @@ private: QDeclarativeAbstractBinding *m_nextBinding; }; +class QDeclarativeValueTypeProxyBinding : public QDeclarativeAbstractBinding +{ +public: + QDeclarativeValueTypeProxyBinding(QObject *o, int coreIndex); + virtual ~QDeclarativeValueTypeProxyBinding(); + + virtual Type bindingType() const { return ValueTypeProxy; } + + virtual void setEnabled(bool, QDeclarativePropertyPrivate::WriteFlags); + virtual int propertyIndex(); + virtual void update(QDeclarativePropertyPrivate::WriteFlags); + + QDeclarativeAbstractBinding *binding(int propertyIndex); + +private: + void recursiveEnable(QDeclarativeAbstractBinding *, QDeclarativePropertyPrivate::WriteFlags); + void recursiveDisable(QDeclarativeAbstractBinding *); + + friend class QDeclarativeAbstractBinding; + QObject *m_object; + int m_index; + QDeclarativeAbstractBinding *m_bindings; +}; + class QDeclarativeContext; class QDeclarativeBindingPrivate; class Q_DECLARATIVE_EXPORT QDeclarativeBinding : public QDeclarativeExpression, public QDeclarativeAbstractBinding diff --git a/src/declarative/qml/qdeclarativeobjectscriptclass.cpp b/src/declarative/qml/qdeclarativeobjectscriptclass.cpp index dc4a676..68780b6 100644 --- a/src/declarative/qml/qdeclarativeobjectscriptclass.cpp +++ b/src/declarative/qml/qdeclarativeobjectscriptclass.cpp @@ -351,7 +351,8 @@ void QDeclarativeObjectScriptClass::setProperty(QObject *obj, } } - QDeclarativeAbstractBinding *delBinding = QDeclarativePropertyPrivate::setBinding(obj, *lastData, 0); + QDeclarativeAbstractBinding *delBinding = + QDeclarativePropertyPrivate::setBinding(obj, lastData->coreIndex, -1, 0); if (delBinding) delBinding->destroy(); diff --git a/src/declarative/qml/qdeclarativeproperty.cpp b/src/declarative/qml/qdeclarativeproperty.cpp index 945d098..8ca5406 100644 --- a/src/declarative/qml/qdeclarativeproperty.cpp +++ b/src/declarative/qml/qdeclarativeproperty.cpp @@ -598,7 +598,6 @@ QMetaMethod QDeclarativeProperty::method() const return QMetaMethod(); } - /*! Returns the binding associated with this property, or 0 if no binding exists. @@ -617,13 +616,18 @@ QDeclarativePropertyPrivate::binding(const QDeclarativeProperty &that) return 0; QDeclarativeAbstractBinding *binding = data->bindings; - while (binding) { - // ### This wont work for value types - if (binding->propertyIndex() == that.d->core.coreIndex) - return binding; + while (binding && binding->propertyIndex() != that.d->core.coreIndex) binding = binding->m_nextBinding; + + if (binding && that.d->valueType.valueTypeCoreIdx != -1) { + if (binding->bindingType() == QDeclarativeAbstractBinding::ValueTypeProxy) { + QDeclarativeValueTypeProxyBinding *proxy = static_cast<QDeclarativeValueTypeProxyBinding *>(binding); + + binding = proxy->binding(bindingIndex(that)); + } } - return 0; + + return binding; } /*! @@ -650,36 +654,36 @@ QDeclarativePropertyPrivate::setBinding(const QDeclarativeProperty &that, return 0; } - return that.d->setBinding(that.d->object, that.d->core, newBinding, flags); + return that.d->setBinding(that.d->object, that.d->core.coreIndex, + that.d->valueType.valueTypeCoreIdx, newBinding, flags); } QDeclarativeAbstractBinding * -QDeclarativePropertyPrivate::setBinding(QObject *object, const QDeclarativePropertyCache::Data &core, - QDeclarativeAbstractBinding *newBinding, WriteFlags flags) +QDeclarativePropertyPrivate::setBinding(QObject *object, int coreIndex, int valueTypeIndex, + QDeclarativeAbstractBinding *newBinding, WriteFlags flags) { QDeclarativeDeclarativeData *data = QDeclarativeDeclarativeData::get(object, 0 != newBinding); + QDeclarativeAbstractBinding *binding = 0; - if (data && data->hasBindingBit(core.coreIndex)) { - QDeclarativeAbstractBinding *binding = data->bindings; - while (binding) { - // ### This wont work for value types - if (binding->propertyIndex() == core.coreIndex) { - binding->setEnabled(false); + if (data && data->hasBindingBit(coreIndex)) { + binding = data->bindings; - if (newBinding) - newBinding->setEnabled(true, flags); + while (binding && binding->propertyIndex() != coreIndex) + binding = binding->m_nextBinding; + } - return binding; // ### QDeclarativeAbstractBinding; - } + if (binding && valueTypeIndex != -1 && binding->bindingType() == QDeclarativeAbstractBinding::ValueTypeProxy) { + int index = coreIndex | (valueTypeIndex << 24); + binding = static_cast<QDeclarativeValueTypeProxyBinding *>(binding)->binding(index); + } - binding = binding->m_nextBinding; - } - } + if (binding) + binding->setEnabled(false); - if (newBinding) + if (newBinding) newBinding->setEnabled(true, flags); - return 0; + return binding; } /*! @@ -1253,6 +1257,18 @@ int QDeclarativePropertyPrivate::valueTypeCoreIndex(const QDeclarativeProperty & return that.d->valueType.valueTypeCoreIdx; } +/*! + Returns the "property index" for use in bindings. The top 8 bits are the value type + offset, and 0 otherwise. The bottom 24-bits are the regular property index. +*/ +int QDeclarativePropertyPrivate::bindingIndex(const QDeclarativeProperty &that) +{ + int rv = that.d->core.coreIndex; + if (rv != -1 && that.d->valueType.valueTypeCoreIdx != -1) + rv = rv | (that.d->valueType.valueTypeCoreIdx << 24); + return rv; +} + struct SerializedData { bool isValueType; QDeclarativePropertyCache::Data core; diff --git a/src/declarative/qml/qdeclarativeproperty_p.h b/src/declarative/qml/qdeclarativeproperty_p.h index c31e2d3..26b85b8 100644 --- a/src/declarative/qml/qdeclarativeproperty_p.h +++ b/src/declarative/qml/qdeclarativeproperty_p.h @@ -110,7 +110,7 @@ public: const QVariant &value, int flags); static bool write(QObject *, const QDeclarativePropertyCache::Data &, const QVariant &, QDeclarativeContext *, WriteFlags flags = 0); - static QDeclarativeAbstractBinding *setBinding(QObject *, const QDeclarativePropertyCache::Data &, + static QDeclarativeAbstractBinding *setBinding(QObject *, int coreIndex, int valueTypeIndex /* -1 */, QDeclarativeAbstractBinding *, WriteFlags flags = DontRemoveBinding); @@ -133,6 +133,7 @@ public: QDeclarativeExpression *) ; static bool write(const QDeclarativeProperty &that, const QVariant &, WriteFlags); static int valueTypeCoreIndex(const QDeclarativeProperty &that); + static int bindingIndex(const QDeclarativeProperty &that); }; Q_DECLARE_OPERATORS_FOR_FLAGS(QDeclarativePropertyPrivate::WriteFlags) diff --git a/src/declarative/qml/qdeclarativevaluetypescriptclass.cpp b/src/declarative/qml/qdeclarativevaluetypescriptclass.cpp index 9cb65f8..a567c38 100644 --- a/src/declarative/qml/qdeclarativevaluetypescriptclass.cpp +++ b/src/declarative/qml/qdeclarativevaluetypescriptclass.cpp @@ -41,6 +41,8 @@ #include "qdeclarativevaluetypescriptclass_p.h" +#include "qdeclarativebinding_p.h" +#include "qdeclarativeproperty_p.h" #include "qdeclarativeengine_p.h" #include "qdeclarativeguard_p.h" @@ -115,6 +117,11 @@ void QDeclarativeValueTypeScriptClass::setProperty(Object *obj, const Identifier { QDeclarativeValueTypeReference *ref = static_cast<QDeclarativeValueTypeReference *>(obj); + QDeclarativeAbstractBinding *delBinding = + QDeclarativePropertyPrivate::setBinding(ref->object, ref->property, m_lastIndex, 0); + if (delBinding) + delBinding->destroy(); + QVariant v = QDeclarativeScriptClass::toVariant(engine, value); ref->type->read(ref->object, ref->property); diff --git a/src/declarative/util/qdeclarativeanimation.cpp b/src/declarative/util/qdeclarativeanimation.cpp index 20449d7..d77ef40 100644 --- a/src/declarative/util/qdeclarativeanimation.cpp +++ b/src/declarative/util/qdeclarativeanimation.cpp @@ -2447,12 +2447,15 @@ QDeclarativeParentAnimation::QDeclarativeParentAnimation(QObject *parent) QDeclarative_setParent_noEvent(d->topLevelGroup, this); d->startAction = new QActionAnimation; + QDeclarative_setParent_noEvent(d->startAction, d->topLevelGroup); d->topLevelGroup->addAnimation(d->startAction); d->ag = new QParallelAnimationGroup; + QDeclarative_setParent_noEvent(d->ag, d->topLevelGroup); d->topLevelGroup->addAnimation(d->ag); d->endAction = new QActionAnimation; + QDeclarative_setParent_noEvent(d->endAction, d->topLevelGroup); d->topLevelGroup->addAnimation(d->endAction); } @@ -2743,4 +2746,99 @@ QAbstractAnimation *QDeclarativeParentAnimation::qtAnimation() return d->topLevelGroup; } +/*! + \qmlclass AnchorAnimation QDeclarativeAnchorAnimation + \since 4.7 + \inherits Animation + \brief The AnchorAnimation element allows you to animate anchor changes. + + AnchorAnimation will animated any changes specified by a state's AnchorChanges. + In the following snippet we animate the addition of a right anchor to our item. + \qml + Item { + id: myItem + width: 100 + } + ... + State { + AnchorChanges { + target: myItem + anchors.right: container.right + } + } + ... + Transition { + //smoothly reanchor myItem and move into new position + AnchorAnimation {} + } + \endqml + + \sa AnchorChanges +*/ + +QDeclarativeAnchorAnimation::QDeclarativeAnchorAnimation(QObject *parent) +: QDeclarativeAbstractAnimation(*(new QDeclarativeAnchorAnimationPrivate), parent) +{ + Q_D(QDeclarativeAnchorAnimation); + d->va = new QDeclarativeBulkValueAnimator; + QDeclarative_setParent_noEvent(d->va, this); +} + +QDeclarativeAnchorAnimation::~QDeclarativeAnchorAnimation() +{ +} + +QAbstractAnimation *QDeclarativeAnchorAnimation::qtAnimation() +{ + Q_D(QDeclarativeAnchorAnimation); + return d->va; +} + +/*! + \qmlproperty list<Item> AnchorAnimation::targets + The items to reanchor. + + If no targets are specified all AnchorChanges will be + animated by the AnchorAnimation. +*/ +QDeclarativeListProperty<QDeclarativeItem> QDeclarativeAnchorAnimation::targets() +{ + Q_D(QDeclarativeAnchorAnimation); + return QDeclarativeListProperty<QDeclarativeItem>(this, d->targets); +} + +void QDeclarativeAnchorAnimation::transition(QDeclarativeStateActions &actions, + QDeclarativeProperties &modified, + TransitionDirection direction) +{ + Q_D(QDeclarativeAnchorAnimation); + PropertyUpdater *data = new PropertyUpdater; + data->interpolatorType = QMetaType::QReal; + data->interpolator = d->interpolator; + + data->reverse = direction == Backward ? true : false; + data->fromSourced = false; + data->fromDefined = false; + + for (int ii = 0; ii < actions.count(); ++ii) { + QDeclarativeAction &action = actions[ii]; + if (action.event && action.event->typeName() == QLatin1String("AnchorChanges") + && (d->targets.isEmpty() || d->targets.contains(static_cast<QDeclarativeAnchorChanges*>(action.event)->object()))) { + data->actions << static_cast<QDeclarativeAnchorChanges*>(action.event)->additionalActions(); + } + } + + if (data->actions.count()) { + if (!d->rangeIsSet) { + d->va->setStartValue(qreal(0)); + d->va->setEndValue(qreal(1)); + d->rangeIsSet = true; + } + d->va->setAnimValue(data, QAbstractAnimation::DeleteWhenStopped); + d->va->setFromSourcedValue(&data->fromSourced); + } else { + delete data; + } +} + QT_END_NAMESPACE diff --git a/src/declarative/util/qdeclarativeanimation_p.h b/src/declarative/util/qdeclarativeanimation_p.h index af48309..eb339f6 100644 --- a/src/declarative/util/qdeclarativeanimation_p.h +++ b/src/declarative/util/qdeclarativeanimation_p.h @@ -480,6 +480,26 @@ protected: virtual QAbstractAnimation *qtAnimation(); }; +class QDeclarativeAnchorAnimationPrivate; +class QDeclarativeAnchorAnimation : public QDeclarativeAbstractAnimation +{ + Q_OBJECT + Q_DECLARE_PRIVATE(QDeclarativeAnchorAnimation) + Q_PROPERTY(QDeclarativeListProperty<QDeclarativeItem> targets READ targets) + +public: + QDeclarativeAnchorAnimation(QObject *parent=0); + virtual ~QDeclarativeAnchorAnimation(); + + QDeclarativeListProperty<QDeclarativeItem> targets(); + +protected: + virtual void transition(QDeclarativeStateActions &actions, + QDeclarativeProperties &modified, + TransitionDirection direction); + virtual QAbstractAnimation *qtAnimation(); +}; + QT_END_NAMESPACE QML_DECLARE_TYPE(QDeclarativeAbstractAnimation) @@ -495,6 +515,7 @@ QML_DECLARE_TYPE(QDeclarativeParallelAnimation) QML_DECLARE_TYPE(QDeclarativeVector3dAnimation) QML_DECLARE_TYPE(QDeclarativeRotationAnimation) QML_DECLARE_TYPE(QDeclarativeParentAnimation) +QML_DECLARE_TYPE(QDeclarativeAnchorAnimation) QT_END_HEADER diff --git a/src/declarative/util/qdeclarativeanimation_p_p.h b/src/declarative/util/qdeclarativeanimation_p_p.h index ae82a90..0460312 100644 --- a/src/declarative/util/qdeclarativeanimation_p_p.h +++ b/src/declarative/util/qdeclarativeanimation_p_p.h @@ -393,6 +393,19 @@ public: QPointF computeTransformOrigin(QDeclarativeItem::TransformOrigin origin, qreal width, qreal height) const; }; +class QDeclarativeAnchorAnimationPrivate : public QDeclarativeAbstractAnimationPrivate +{ + Q_DECLARE_PUBLIC(QDeclarativeAnchorAnimation) +public: + QDeclarativeAnchorAnimationPrivate() : rangeIsSet(false), va(0), + interpolator(QVariantAnimationPrivate::getInterpolator(QMetaType::QReal)) {} + + bool rangeIsSet; + QDeclarativeBulkValueAnimator *va; + QVariantAnimation::Interpolator interpolator; + QList<QDeclarativeItem*> targets; +}; + QT_END_NAMESPACE #endif // QDECLARATIVEANIMATION_P_H diff --git a/src/declarative/util/qdeclarativestate.cpp b/src/declarative/util/qdeclarativestate.cpp index 1d70d33..802ff1c 100644 --- a/src/declarative/util/qdeclarativestate.cpp +++ b/src/declarative/util/qdeclarativestate.cpp @@ -96,21 +96,12 @@ void QDeclarativeActionEvent::reverse() { } -QList<QDeclarativeAction> QDeclarativeActionEvent::extraActions() -{ - return QList<QDeclarativeAction>(); -} - bool QDeclarativeActionEvent::changesBindings() { return false; } -void QDeclarativeActionEvent::clearForwardBindings() -{ -} - -void QDeclarativeActionEvent::clearReverseBindings() +void QDeclarativeActionEvent::clearBindings() { } @@ -368,47 +359,60 @@ void QDeclarativeState::apply(QDeclarativeStateGroup *group, QDeclarativeTransit for (int ii = 0; ii < applyList.count(); ++ii) { QDeclarativeAction &action = applyList[ii]; - bool found = false; - - int jj; if (action.event) { if (!action.event->isReversable()) continue; - for (jj = 0; jj < d->revertList.count(); ++jj) { + bool found = false; + for (int jj = 0; jj < d->revertList.count(); ++jj) { QDeclarativeActionEvent *event = d->revertList.at(jj).event; if (event && event->typeName() == action.event->typeName()) { if (action.event->override(event)) { found = true; + + if (action.event != d->revertList.at(jj).event) { + action.event->copyOriginals(d->revertList.at(jj).event); + + QDeclarativeSimpleAction r(action); + additionalReverts << r; + d->revertList.removeAt(jj); + } else if (action.event->isRewindable()) //###why needed? + action.event->saveCurrentValues(); + break; } } } - if (!found || action.event != d->revertList.at(jj).event) + if (!found) { action.event->saveOriginals(); - else if (action.event->isRewindable()) - action.event->saveCurrentValues(); + // Only need to revert the applyList action if the previous + // state doesn't have a higher priority revert already + QDeclarativeSimpleAction r(action); + additionalReverts << r; + } } else { + bool found = false; action.fromBinding = QDeclarativePropertyPrivate::binding(action.property); - for (jj = 0; jj < d->revertList.count(); ++jj) { + for (int jj = 0; jj < d->revertList.count(); ++jj) { if (d->revertList.at(jj).property == action.property) { found = true; + if (d->revertList.at(jj).binding != action.fromBinding) { + action.deleteFromBinding(); + } break; } } - } - if (!found) { - if (!action.restore) { - action.deleteFromBinding(); - } else { - // Only need to revert the applyList action if the previous - // state doesn't have a higher priority revert already - QDeclarativeSimpleAction r(action); - additionalReverts << r; + if (!found) { + if (!action.restore) { + action.deleteFromBinding(); + } else { + // Only need to revert the applyList action if the previous + // state doesn't have a higher priority revert already + QDeclarativeSimpleAction r(action); + additionalReverts << r; + } } - } else if (d->revertList.at(jj).binding != action.fromBinding) { - action.deleteFromBinding(); } } diff --git a/src/declarative/util/qdeclarativestate_p.h b/src/declarative/util/qdeclarativestate_p.h index 0c6e7a3..ee2b7e8 100644 --- a/src/declarative/util/qdeclarativestate_p.h +++ b/src/declarative/util/qdeclarativestate_p.h @@ -92,17 +92,15 @@ public: virtual bool isReversable(); virtual void reverse(); virtual void saveOriginals() {} + virtual void copyOriginals(QDeclarativeActionEvent *) {} virtual bool isRewindable() { return isReversable(); } virtual void rewind() {} virtual void saveCurrentValues() {} - - //virtual bool hasExtraActions(); - virtual QList<QDeclarativeAction> extraActions(); + virtual void saveTargetValues() {} virtual bool changesBindings(); - virtual void clearForwardBindings(); - virtual void clearReverseBindings(); + virtual void clearBindings(); virtual bool override(QDeclarativeActionEvent*other); }; diff --git a/src/declarative/util/qdeclarativestateoperations.cpp b/src/declarative/util/qdeclarativestateoperations.cpp index f13c691..6f5bb66 100644 --- a/src/declarative/util/qdeclarativestateoperations.cpp +++ b/src/declarative/util/qdeclarativestateoperations.cpp @@ -403,6 +403,17 @@ void QDeclarativeParentChange::saveOriginals() d->origStackBefore = d->rewindStackBefore; } +void QDeclarativeParentChange::copyOriginals(QDeclarativeActionEvent *other) +{ + Q_D(QDeclarativeParentChange); + QDeclarativeParentChange *pc = static_cast<QDeclarativeParentChange*>(other); + + d->origParent = pc->d_func()->rewindParent; + d->origStackBefore = pc->d_func()->rewindStackBefore; + + saveCurrentValues(); +} + void QDeclarativeParentChange::execute() { Q_D(QDeclarativeParentChange); @@ -568,11 +579,10 @@ QString QDeclarativeStateChangeScript::typeName() const } \endqml - AnchorChanges will 'inject' \c x, \c y, \c width, and \c height changes into the transition, - so you can animate them as you would normally changes to these properties: + AnchorChanges can be animated using AnchorAnimation. \qml //animate our anchor changes - NumberAnimation { targets: content; properties: "x,y,width,height" } + AnchorAnimation {} \endqml For more information on anchors see \l {anchor-layout}{Anchor Layouts}. @@ -585,10 +595,10 @@ class QDeclarativeAnchorChangesPrivate : public QObjectPrivate public: QDeclarativeAnchorChangesPrivate() : target(0) {} - QString name; QDeclarativeItem *target; QString resetString; QStringList resetList; + QDeclarativeAnchorLine left; QDeclarativeAnchorLine right; QDeclarativeAnchorLine horizontalCenter; @@ -617,6 +627,24 @@ public: 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; }; /*! @@ -769,6 +797,38 @@ void QDeclarativeAnchorChanges::execute() if (!d->target) return; + //incorporate any needed "reverts" + if (d->applyOrigLeft) + d->target->anchors()->setLeft(d->origLeft); + if (d->applyOrigRight) + d->target->anchors()->setRight(d->origRight); + if (d->applyOrigHCenter) + d->target->anchors()->setHorizontalCenter(d->origHCenter); + if (d->applyOrigTop) + d->target->anchors()->setTop(d->origTop); + if (d->applyOrigBottom) + d->target->anchors()->setBottom(d->origBottom); + if (d->applyOrigVCenter) + d->target->anchors()->setVerticalCenter(d->origVCenter); + if (d->applyOrigBaseline) + d->target->anchors()->setBaseline(d->origBaseline); + + //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("horizontalCenter"))) + d->target->anchors()->resetHorizontalCenter(); + if (d->resetList.contains(QLatin1String("top"))) + d->target->anchors()->resetTop(); + if (d->resetList.contains(QLatin1String("bottom"))) + d->target->anchors()->resetBottom(); + if (d->resetList.contains(QLatin1String("verticalCenter"))) + d->target->anchors()->resetVerticalCenter(); + if (d->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); @@ -797,6 +857,22 @@ void QDeclarativeAnchorChanges::reverse() if (!d->target) return; + //reset any anchors set by the state + if (d->left.anchorLine != QDeclarativeAnchorLine::Invalid) + d->target->anchors()->resetLeft(); + if (d->right.anchorLine != QDeclarativeAnchorLine::Invalid) + d->target->anchors()->resetRight(); + if (d->horizontalCenter.anchorLine != QDeclarativeAnchorLine::Invalid) + d->target->anchors()->resetHorizontalCenter(); + if (d->top.anchorLine != QDeclarativeAnchorLine::Invalid) + d->target->anchors()->resetTop(); + if (d->bottom.anchorLine != QDeclarativeAnchorLine::Invalid) + d->target->anchors()->resetBottom(); + if (d->verticalCenter.anchorLine != QDeclarativeAnchorLine::Invalid) + d->target->anchors()->resetVerticalCenter(); + if (d->baseline.anchorLine != QDeclarativeAnchorLine::Invalid) + d->target->anchors()->resetBaseline(); + //restore previous anchors if (d->origLeft.anchorLine != QDeclarativeAnchorLine::Invalid) d->target->anchors()->setLeft(d->origLeft); @@ -819,31 +895,33 @@ QString QDeclarativeAnchorChanges::typeName() const return QLatin1String("AnchorChanges"); } -QList<QDeclarativeAction> QDeclarativeAnchorChanges::extraActions() +QList<QDeclarativeAction> QDeclarativeAnchorChanges::additionalActions() { Q_D(QDeclarativeAnchorChanges); QList<QDeclarativeAction> 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) { QDeclarativeAction a; - a.fromValue = d->fromX; - a.property = QDeclarativeProperty(d->target, QLatin1String("x")); - extra << a; - - a.fromValue = d->fromY; - a.property = QDeclarativeProperty(d->target, QLatin1String("y")); - extra << a; - - a.fromValue = d->fromWidth; - a.property = QDeclarativeProperty(d->target, QLatin1String("width")); - extra << a; - - a.fromValue = d->fromHeight; - a.property = QDeclarativeProperty(d->target, QLatin1String("height")); - extra << a; + if (d->fromX != d->toX) { + a.property = QDeclarativeProperty(d->target, QLatin1String("x")); + a.toValue = d->toX; + extra << a; + } + if (d->fromY != d->toY) { + a.property = QDeclarativeProperty(d->target, QLatin1String("y")); + a.toValue = d->toY; + extra << a; + } + if (d->fromWidth != d->toWidth) { + a.property = QDeclarativeProperty(d->target, QLatin1String("width")); + a.toValue = d->toWidth; + extra << a; + } + if (d->fromHeight != d->toHeight) { + a.property = QDeclarativeProperty(d->target, QLatin1String("height")); + a.toValue = d->toHeight; + extra << a; + } } return extra; @@ -865,10 +943,52 @@ void QDeclarativeAnchorChanges::saveOriginals() d->origVCenter = d->target->anchors()->verticalCenter(); d->origBaseline = d->target->anchors()->baseline(); + d->applyOrigLeft = d->applyOrigRight = d->applyOrigHCenter = d->applyOrigTop + = d->applyOrigBottom = d->applyOrigHCenter = d->applyOrigBaseline = false; + saveCurrentValues(); } -void QDeclarativeAnchorChanges::clearForwardBindings() +void QDeclarativeAnchorChanges::copyOriginals(QDeclarativeActionEvent *other) +{ + Q_D(QDeclarativeAnchorChanges); + QDeclarativeAnchorChanges *ac = static_cast<QDeclarativeAnchorChanges*>(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->applyOrigRight = (acp->right.anchorLine != QDeclarativeAnchorLine::Invalid || + acp->resetList.contains(QLatin1String("right"))); + + d->applyOrigHCenter = (acp->horizontalCenter.anchorLine != QDeclarativeAnchorLine::Invalid || + acp->resetList.contains(QLatin1String("horizontalCenter"))); + + d->applyOrigTop = (acp->top.anchorLine != QDeclarativeAnchorLine::Invalid || + acp->resetList.contains(QLatin1String("top"))); + + d->applyOrigBottom = (acp->bottom.anchorLine != QDeclarativeAnchorLine::Invalid || + acp->resetList.contains(QLatin1String("bottom"))); + + d->applyOrigVCenter = (acp->verticalCenter.anchorLine != QDeclarativeAnchorLine::Invalid || + acp->resetList.contains(QLatin1String("verticalCenter"))); + + d->applyOrigBaseline = (acp->baseline.anchorLine != QDeclarativeAnchorLine::Invalid || + acp->resetList.contains(QLatin1String("baseline"))); + + d->origLeft = ac->d_func()->origLeft; + d->origRight = ac->d_func()->origRight; + d->origHCenter = ac->d_func()->origHCenter; + d->origTop = ac->d_func()->origTop; + d->origBottom = ac->d_func()->origBottom; + d->origVCenter = ac->d_func()->origVCenter; + d->origBaseline = ac->d_func()->origBaseline; + + saveCurrentValues(); +} + +void QDeclarativeAnchorChanges::clearBindings() { Q_D(QDeclarativeAnchorChanges); d->fromX = d->target->x(); @@ -876,6 +996,22 @@ void QDeclarativeAnchorChanges::clearForwardBindings() d->fromWidth = d->target->width(); d->fromHeight = d->target->height(); + //reset any anchors with corresponding reverts + if (d->applyOrigLeft) + d->target->anchors()->resetLeft(); + if (d->applyOrigRight) + d->target->anchors()->resetRight(); + if (d->applyOrigHCenter) + d->target->anchors()->resetHorizontalCenter(); + if (d->applyOrigTop) + d->target->anchors()->resetTop(); + if (d->applyOrigBottom) + d->target->anchors()->resetBottom(); + if (d->applyOrigVCenter) + d->target->anchors()->resetVerticalCenter(); + if (d->applyOrigBaseline) + d->target->anchors()->resetBaseline(); + //reset any anchors that have been specified if (d->resetList.contains(QLatin1String("left"))) d->target->anchors()->resetLeft(); @@ -909,47 +1045,6 @@ void QDeclarativeAnchorChanges::clearForwardBindings() d->target->anchors()->resetBaseline(); } -void QDeclarativeAnchorChanges::clearReverseBindings() -{ - Q_D(QDeclarativeAnchorChanges); - d->fromX = d->target->x(); - d->fromY = d->target->y(); - d->fromWidth = d->target->width(); - d->fromHeight = d->target->height(); - - //reset any anchors that were set in the state - if (d->left.anchorLine != QDeclarativeAnchorLine::Invalid) - d->target->anchors()->resetLeft(); - if (d->right.anchorLine != QDeclarativeAnchorLine::Invalid) - d->target->anchors()->resetRight(); - if (d->horizontalCenter.anchorLine != QDeclarativeAnchorLine::Invalid) - d->target->anchors()->resetHorizontalCenter(); - if (d->top.anchorLine != QDeclarativeAnchorLine::Invalid) - d->target->anchors()->resetTop(); - if (d->bottom.anchorLine != QDeclarativeAnchorLine::Invalid) - d->target->anchors()->resetBottom(); - if (d->verticalCenter.anchorLine != QDeclarativeAnchorLine::Invalid) - d->target->anchors()->resetVerticalCenter(); - if (d->baseline.anchorLine != QDeclarativeAnchorLine::Invalid) - d->target->anchors()->resetBaseline(); - - //reset any anchors that were set in the original state - if (d->origLeft.anchorLine != QDeclarativeAnchorLine::Invalid) - d->target->anchors()->resetLeft(); - if (d->origRight.anchorLine != QDeclarativeAnchorLine::Invalid) - d->target->anchors()->resetRight(); - if (d->origHCenter.anchorLine != QDeclarativeAnchorLine::Invalid) - d->target->anchors()->resetHorizontalCenter(); - if (d->origTop.anchorLine != QDeclarativeAnchorLine::Invalid) - d->target->anchors()->resetTop(); - if (d->origBottom.anchorLine != QDeclarativeAnchorLine::Invalid) - d->target->anchors()->resetBottom(); - if (d->origVCenter.anchorLine != QDeclarativeAnchorLine::Invalid) - d->target->anchors()->resetVerticalCenter(); - if (d->origBaseline.anchorLine != QDeclarativeAnchorLine::Invalid) - d->target->anchors()->resetBaseline(); -} - bool QDeclarativeAnchorChanges::override(QDeclarativeActionEvent*other) { if (other->typeName() != QLatin1String("AnchorChanges")) @@ -982,6 +1077,11 @@ void QDeclarativeAnchorChanges::rewind() d->target->anchors()->setVerticalCenter(d->rewindVCenter); if (d->rewindBaseline.anchorLine != QDeclarativeAnchorLine::Invalid) d->target->anchors()->setBaseline(d->rewindBaseline); + + d->target->setX(d->rewindX); + d->target->setY(d->rewindY); + d->target->setWidth(d->rewindWidth); + d->target->setHeight(d->rewindHeight); } void QDeclarativeAnchorChanges::saveCurrentValues() @@ -994,6 +1094,20 @@ void QDeclarativeAnchorChanges::saveCurrentValues() d->rewindBottom = d->target->anchors()->bottom(); d->rewindVCenter = d->target->anchors()->verticalCenter(); d->rewindBaseline = d->target->anchors()->baseline(); + + d->rewindX = d->target->x(); + d->rewindY = d->target->y(); + d->rewindWidth = d->target->width(); + d->rewindHeight = d->target->height(); +} + +void QDeclarativeAnchorChanges::saveTargetValues() +{ + Q_D(QDeclarativeAnchorChanges); + d->toX = d->target->x(); + d->toY = d->target->y(); + d->toWidth = d->target->width(); + d->toHeight = d->target->height(); } #include <qdeclarativestateoperations.moc> diff --git a/src/declarative/util/qdeclarativestateoperations_p.h b/src/declarative/util/qdeclarativestateoperations_p.h index dd4248023..66a8717 100644 --- a/src/declarative/util/qdeclarativestateoperations_p.h +++ b/src/declarative/util/qdeclarativestateoperations_p.h @@ -107,6 +107,7 @@ public: virtual ActionList actions(); virtual void saveOriginals(); + virtual void copyOriginals(QDeclarativeActionEvent*); virtual void execute(); virtual bool isReversable(); virtual void reverse(); @@ -196,13 +197,15 @@ public: virtual void reverse(); virtual QString typeName() const; virtual bool override(QDeclarativeActionEvent*other); - virtual QList<QDeclarativeAction> extraActions(); virtual bool changesBindings(); virtual void saveOriginals(); - virtual void clearForwardBindings(); - virtual void clearReverseBindings(); + virtual void copyOriginals(QDeclarativeActionEvent*); + virtual void clearBindings(); virtual void rewind(); virtual void saveCurrentValues(); + + QList<QDeclarativeAction> additionalActions(); + virtual void saveTargetValues(); }; QT_END_NAMESPACE diff --git a/src/declarative/util/qdeclarativetransitionmanager.cpp b/src/declarative/util/qdeclarativetransitionmanager.cpp index e1143fa..f07fb23 100644 --- a/src/declarative/util/qdeclarativetransitionmanager.cpp +++ b/src/declarative/util/qdeclarativetransitionmanager.cpp @@ -126,10 +126,7 @@ void QDeclarativeTransitionManager::transition(const QList<QDeclarativeAction> & QDeclarativePropertyPrivate::setBinding(action.property, 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(); + action.event->clearBindings(); } } @@ -144,8 +141,6 @@ void QDeclarativeTransitionManager::transition(const QList<QDeclarativeAction> & if (!d->bindingsList.isEmpty()) { - //### do extra actions here? - // Apply all the property and binding changes for (int ii = 0; ii < applyList.size(); ++ii) { const QDeclarativeAction &action = applyList.at(ii); @@ -158,17 +153,18 @@ void QDeclarativeTransitionManager::transition(const QList<QDeclarativeAction> & action.event->reverse(); else action.event->execute(); - applyList << action.event->extraActions(); } } // Read all the end values for binding changes for (int ii = 0; ii < applyList.size(); ++ii) { QDeclarativeAction *action = &applyList[ii]; - if (action->event) + if (action->event) { + action->event->saveTargetValues(); continue; + } const QDeclarativeProperty &prop = action->property; - if (action->toBinding || !action->toValue.isValid()) { //### is this always right (used for exta actions) + if (action->toBinding || !action->toValue.isValid()) { action->toValue = prop.read(); } } @@ -177,15 +173,9 @@ void QDeclarativeTransitionManager::transition(const QList<QDeclarativeAction> & foreach(const QDeclarativeAction &action, applyList) { if (action.event) { if (action.event->isReversable()) { - if (action.reverseEvent) { //reverse the reverse - action.event->clearForwardBindings(); - action.event->rewind(); - action.event->clearReverseBindings(); - } else { - action.event->clearReverseBindings(); - action.event->rewind(); - action.event->clearForwardBindings(); - } + action.event->clearBindings(); + action.event->rewind(); + action.event->clearBindings(); } continue; } diff --git a/src/declarative/util/qdeclarativeutilmodule.cpp b/src/declarative/util/qdeclarativeutilmodule.cpp index 9c3b0aa..4d4678a 100644 --- a/src/declarative/util/qdeclarativeutilmodule.cpp +++ b/src/declarative/util/qdeclarativeutilmodule.cpp @@ -75,6 +75,7 @@ void QDeclarativeUtilModule::defineModule() { + qmlRegisterType<QDeclarativeAnchorAnimation>("Qt",4,6,"AnchorAnimation"); qmlRegisterType<QDeclarativeAnchorChanges>("Qt",4,6,"AnchorChanges"); qmlRegisterType<QDeclarativeBehavior>("Qt",4,6,"Behavior"); qmlRegisterType<QDeclarativeBind>("Qt",4,6,"Binding"); diff --git a/src/imports/imports.pro b/src/imports/imports.pro index 8b47043..3886f5c 100644 --- a/src/imports/imports.pro +++ b/src/imports/imports.pro @@ -1,6 +1,6 @@ TEMPLATE = subdirs -SUBDIRS += widgets +SUBDIRS += widgets particles contains(QT_CONFIG, webkit): SUBDIRS += webkit contains(QT_CONFIG, multimedia): SUBDIRS += multimedia diff --git a/src/imports/webkit/webkitqmlplugin_export.h b/src/imports/particles/particles.cpp index 974fd24..ae3f318 100644 --- a/src/imports/webkit/webkitqmlplugin_export.h +++ b/src/imports/particles/particles.cpp @@ -1,10 +1,10 @@ /**************************************************************************** ** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). ** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) ** -** This file is part of the QtDeclarative module of the Qt Toolkit. +** This file is part of the plugins of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:LGPL$ ** No Commercial Usage @@ -39,15 +39,31 @@ ** ****************************************************************************/ -#ifndef WEBKITQMLPLUGIN_EXPORT_H -#define WEBKITQMLPLUGIN_EXPORT_H +#include <QtDeclarative/qdeclarativeextensionplugin.h> +#include <QtDeclarative/qdeclarative.h> -#include <QtCore/QtGlobal> +#include "qdeclarativeparticles_p.h" -#if defined WEBKITQMLPLUGIN_EXPORTS -# define WEBKITQMLPLUGIN_EXPORT Q_DECL_EXPORT -#else -# define WEBKITQMLPLUGIN_EXPORT Q_DECL_IMPORT -#endif +QT_BEGIN_NAMESPACE + +class QParticlesQmlModule : public QDeclarativeExtensionPlugin +{ + Q_OBJECT +public: + virtual void registerTypes(const char *uri) + { + Q_ASSERT(QLatin1String(uri) == QLatin1String("Qt.labs.particles")); + qmlRegisterType<QDeclarativeParticleMotion>(uri,1,0,"ParticleMotion"); + qmlRegisterType<QDeclarativeParticleMotionGravity>(uri,1,0,"ParticleMotionGravity"); + qmlRegisterType<QDeclarativeParticleMotionLinear>(uri,1,0,"ParticleMotionLinear"); + qmlRegisterType<QDeclarativeParticleMotionWander>(uri,1,0,"ParticleMotionWander"); + qmlRegisterType<QDeclarativeParticles>(uri,1,0,"Particles"); + } +}; + +QT_END_NAMESPACE + +#include "particles.moc" + +Q_EXPORT_PLUGIN2(particlesqmlmodule, QT_PREPEND_NAMESPACE(QParticlesQmlModule)); -#endif // WEBKITQMLPLUGIN_EXPORT_H diff --git a/src/imports/particles/particles.pro b/src/imports/particles/particles.pro new file mode 100644 index 0000000..2a0b8f5 --- /dev/null +++ b/src/imports/particles/particles.pro @@ -0,0 +1,21 @@ +TARGET = particles +TARGETPATH = Qt/labs/particles +include(../qimportbase.pri) + +QT += declarative + +SOURCES += \ + qdeclarativeparticles.cpp \ + particles.cpp + +HEADERS += \ + qdeclarativeparticles_p.h + +QTDIR_build:DESTDIR = $$QT_BUILD_TREE/imports/$$TARGETPATH +target.path = $$TARGETPATH + +# install qmldir file +qmldir.files += qmldir +qmldir.path = $$[QT_INSTALL_IMPORTS]/$$TARGETPATH + +INSTALLS += target qmldir diff --git a/src/declarative/graphicsitems/qdeclarativeparticles.cpp b/src/imports/particles/qdeclarativeparticles.cpp index 593c80a..caa0754 100644 --- a/src/declarative/graphicsitems/qdeclarativeparticles.cpp +++ b/src/imports/particles/qdeclarativeparticles.cpp @@ -41,13 +41,12 @@ #include "qdeclarativeparticles_p.h" -#include "qdeclarativeitem_p.h" +#include <private/qdeclarativeitem_p.h> -#include <qdeclarativepixmapcache_p.h> -#include <qfxperf_p_p.h> -#include <qdeclarativeanimation_p_p.h> +#include <private/qdeclarativepixmapcache_p.h> +#include <private/qfxperf_p_p.h> +#include <private/qdeclarativeanimation_p_p.h> -#include <QNetworkReply> #include <QPainter> #include <QtGui/qdrawutil.h> #include <QVarLengthArray> diff --git a/src/declarative/graphicsitems/qdeclarativeparticles_p.h b/src/imports/particles/qdeclarativeparticles_p.h index 06acbb9..993796d 100644 --- a/src/declarative/graphicsitems/qdeclarativeparticles_p.h +++ b/src/imports/particles/qdeclarativeparticles_p.h @@ -42,7 +42,7 @@ #ifndef QDECLARATIVEPARTICLES_H #define QDECLARATIVEPARTICLES_H -#include "qdeclarativeitem.h" +#include <QtDeclarative/qdeclarativeitem.h> QT_BEGIN_HEADER @@ -52,7 +52,7 @@ QT_MODULE(Declarative) class QDeclarativeParticle; class QDeclarativeParticles; -class Q_DECLARATIVE_EXPORT QDeclarativeParticleMotion : public QObject +class QDeclarativeParticleMotion : public QObject { Q_OBJECT public: @@ -63,7 +63,7 @@ public: virtual void destroy(QDeclarativeParticle &); }; -class Q_DECLARATIVE_EXPORT QDeclarativeParticleMotionLinear : public QDeclarativeParticleMotion +class QDeclarativeParticleMotionLinear : public QDeclarativeParticleMotion { Q_OBJECT public: @@ -73,7 +73,7 @@ public: virtual void advance(QDeclarativeParticle &, int interval); }; -class Q_DECLARATIVE_EXPORT QDeclarativeParticleMotionGravity : public QDeclarativeParticleMotion +class QDeclarativeParticleMotionGravity : public QDeclarativeParticleMotion { Q_OBJECT @@ -106,7 +106,7 @@ private: qreal _accel; }; -class Q_DECLARATIVE_EXPORT QDeclarativeParticleMotionWander : public QDeclarativeParticleMotion +class QDeclarativeParticleMotionWander : public QDeclarativeParticleMotion { Q_OBJECT public: @@ -142,7 +142,7 @@ Q_SIGNALS: void xvarianceChanged(); void yvarianceChanged(); void paceChanged(); - + private: QDeclarativeParticles *particles; qreal _xvariance; @@ -151,7 +151,7 @@ private: }; class QDeclarativeParticlesPrivate; -class Q_DECLARATIVE_EXPORT QDeclarativeParticles : public QDeclarativeItem +class QDeclarativeParticles : public QDeclarativeItem { Q_OBJECT diff --git a/src/imports/particles/qmldir b/src/imports/particles/qmldir new file mode 100644 index 0000000..15456bb --- /dev/null +++ b/src/imports/particles/qmldir @@ -0,0 +1 @@ +plugin particles diff --git a/src/imports/webkit/qdeclarativewebview_p.h b/src/imports/webkit/qdeclarativewebview_p.h index 95f51d1..36b18a6 100644 --- a/src/imports/webkit/qdeclarativewebview_p.h +++ b/src/imports/webkit/qdeclarativewebview_p.h @@ -42,8 +42,6 @@ #ifndef QDECLARATIVEWEBVIEW_H #define QDECLARATIVEWEBVIEW_H -#include "webkitqmlplugin_export.h" - #include <private/qdeclarativepainteditem_p.h> #include <QtGui/QAction> @@ -64,7 +62,7 @@ class QDeclarativeWebViewPrivate; class QNetworkRequest; class QDeclarativeWebView; -class WEBKITQMLPLUGIN_EXPORT QDeclarativeWebPage : public QWebPage +class QDeclarativeWebPage : public QWebPage { Q_OBJECT public: @@ -88,7 +86,7 @@ class QDeclarativeWebViewAttached; //### TODO: browser plugins -class WEBKITQMLPLUGIN_EXPORT QDeclarativeWebView : public QDeclarativePaintedItem +class QDeclarativeWebView : public QDeclarativePaintedItem { Q_OBJECT diff --git a/src/imports/webkit/qdeclarativewebview_p_p.h b/src/imports/webkit/qdeclarativewebview_p_p.h index 3ad9e9a..258b472 100644 --- a/src/imports/webkit/qdeclarativewebview_p_p.h +++ b/src/imports/webkit/qdeclarativewebview_p_p.h @@ -42,8 +42,6 @@ #ifndef QDECLARATIVEWEBVIEW_P_H #define QDECLARATIVEWEBVIEW_P_H -#include "webkitqmlplugin_export.h" - #include <qdeclarative.h> #include <QtWebKit/QWebPage> @@ -54,7 +52,7 @@ QT_BEGIN_NAMESPACE QT_MODULE(Declarative) -class WEBKITQMLPLUGIN_EXPORT QDeclarativeWebSettings : public QObject { +class QDeclarativeWebSettings : public QObject { Q_OBJECT Q_PROPERTY(QString standardFontFamily READ standardFontFamily WRITE setStandardFontFamily) diff --git a/src/imports/webkit/webkit.pro b/src/imports/webkit/webkit.pro index 9ad9c68..858d3ba 100644 --- a/src/imports/webkit/webkit.pro +++ b/src/imports/webkit/webkit.pro @@ -3,12 +3,10 @@ TARGETPATH = org/webkit include(../qimportbase.pri) QT += webkit declarative -DEFINES += WEBKITQMLPLUGIN_EXPORTS SOURCES += qdeclarativewebview.cpp plugin.cpp HEADERS += qdeclarativewebview_p.h \ - qdeclarativewebview_p_p.h \ - webkitqmlplugin_export.h + qdeclarativewebview_p_p.h QTDIR_build:DESTDIR = $$QT_BUILD_TREE/imports/$$TARGETPATH target.path = $$TARGETPATH |