diff options
author | Warwick Allison <warwick.allison@nokia.com> | 2009-11-10 05:17:20 (GMT) |
---|---|---|
committer | Warwick Allison <warwick.allison@nokia.com> | 2009-11-10 05:17:20 (GMT) |
commit | a1080b89abad16d3889211bae2b1f99891a7dbfe (patch) | |
tree | 58831dfa2c06bf11b3374cbdc2fc910e7d03b8e1 /src/declarative/graphicsitems | |
parent | 6ac64e4b8d7cb86394936a4d5723625bcabf2f59 (diff) | |
parent | d99decf13bc35d0eb8e9da3ccc828a4a947d7dad (diff) | |
download | Qt-a1080b89abad16d3889211bae2b1f99891a7dbfe.zip Qt-a1080b89abad16d3889211bae2b1f99891a7dbfe.tar.gz Qt-a1080b89abad16d3889211bae2b1f99891a7dbfe.tar.bz2 |
Merge branch 'kinetic-declarativeui' of git@scm.dev.nokia.troll.no:qt/kinetic into kinetic-declarativeui
Diffstat (limited to 'src/declarative/graphicsitems')
7 files changed, 144 insertions, 102 deletions
diff --git a/src/declarative/graphicsitems/qmlgraphicsgridview.cpp b/src/declarative/graphicsitems/qmlgraphicsgridview.cpp index 10050f2..1b94426 100644 --- a/src/declarative/graphicsitems/qmlgraphicsgridview.cpp +++ b/src/declarative/graphicsitems/qmlgraphicsgridview.cpp @@ -565,6 +565,7 @@ void QmlGraphicsGridViewPrivate::updateTrackedItem() void QmlGraphicsGridViewPrivate::createHighlight() { Q_Q(QmlGraphicsGridView); + bool changed = false; if (highlight) { if (trackedItem == highlight) trackedItem = 0; @@ -575,6 +576,7 @@ void QmlGraphicsGridViewPrivate::createHighlight() delete highlightYAnimator; highlightXAnimator = 0; highlightYAnimator = 0; + changed = true; } if (currentItem) { @@ -606,8 +608,11 @@ void QmlGraphicsGridViewPrivate::createHighlight() highlightYAnimator->setTarget(QmlMetaProperty(highlight->item, QLatin1String("y"))); highlightYAnimator->setDuration(150); highlightYAnimator->setEnabled(autoHighlight); + changed = true; } } + if (changed) + emit q->highlightChanged(); } void QmlGraphicsGridViewPrivate::updateHighlight() @@ -887,6 +892,25 @@ QmlGraphicsItem *QmlGraphicsGridView::currentItem() } /*! + \qmlproperty Item GridView::highlightItem + + \c highlightItem holds the highlight item, which was created + from the \l highlight component. + + The highlightItem is managed by the view unless + \l highlightFollowsCurrentItem is set to false. + + \sa highlight, highlightFollowsCurrentItem +*/ +QmlGraphicsItem *QmlGraphicsGridView::highlightItem() +{ + Q_D(QmlGraphicsGridView); + if (!d->highlight) + return 0; + return d->highlight->item; +} + +/*! \qmlproperty int GridView::count This property holds the number of items in the view. */ @@ -909,7 +933,7 @@ int QmlGraphicsGridView::count() const The below example demonstrates how to make a simple highlight: \snippet doc/src/snippets/declarative/gridview/gridview.qml 1 - \sa highlightFollowsCurrentItem + \sa highlightItem, highlightFollowsCurrentItem */ QmlComponent *QmlGraphicsGridView::highlight() const { diff --git a/src/declarative/graphicsitems/qmlgraphicsgridview_p.h b/src/declarative/graphicsitems/qmlgraphicsgridview_p.h index 3fd36bd..3e09cf3 100644 --- a/src/declarative/graphicsitems/qmlgraphicsgridview_p.h +++ b/src/declarative/graphicsitems/qmlgraphicsgridview_p.h @@ -62,8 +62,11 @@ class Q_DECLARATIVE_EXPORT QmlGraphicsGridView : public QmlGraphicsFlickable Q_PROPERTY(int currentIndex READ currentIndex WRITE setCurrentIndex NOTIFY currentIndexChanged) Q_PROPERTY(QmlGraphicsItem *currentItem READ currentItem NOTIFY currentIndexChanged) Q_PROPERTY(int count READ count NOTIFY countChanged) + Q_PROPERTY(QmlComponent *highlight READ highlight WRITE setHighlight) + Q_PROPERTY(QmlGraphicsItem *highlightItem READ highlightItem NOTIFY highlightChanged) Q_PROPERTY(bool highlightFollowsCurrentItem READ highlightFollowsCurrentItem WRITE setHighlightFollowsCurrentItem) + Q_PROPERTY(Flow flow READ flow WRITE setFlow) Q_PROPERTY(bool keyNavigationWraps READ isWrapEnabled WRITE setWrapEnabled) Q_PROPERTY(int cacheBuffer READ cacheBuffer WRITE setCacheBuffer) @@ -85,6 +88,7 @@ public: void setCurrentIndex(int idx); QmlGraphicsItem *currentItem(); + QmlGraphicsItem *highlightItem(); int count() const; QmlComponent *highlight() const; @@ -123,6 +127,7 @@ Q_SIGNALS: void currentIndexChanged(); void cellWidthChanged(); void cellHeightChanged(); + void highlightChanged(); protected: virtual void viewportMoved(); diff --git a/src/declarative/graphicsitems/qmlgraphicsitem_p.h b/src/declarative/graphicsitems/qmlgraphicsitem_p.h index f98c121..e1d7342 100644 --- a/src/declarative/graphicsitems/qmlgraphicsitem_p.h +++ b/src/declarative/graphicsitems/qmlgraphicsitem_p.h @@ -232,6 +232,24 @@ public: emit q_func()->wantsFocusChanged(); } + // Reimplemented from QGraphicsItemPrivate + virtual void siblingOrderChange() + { + foreach(QmlGraphicsItemPrivate* other, siblingOrderNotifiees) + other->otherSiblingOrderChange(this); + } + QList<QmlGraphicsItemPrivate*> siblingOrderNotifiees; + void registerSiblingOrderNotification(QmlGraphicsItemPrivate* other) + { + siblingOrderNotifiees << other; + } + void unregisterSiblingOrderNotification(QmlGraphicsItemPrivate* other) + { + siblingOrderNotifiees.removeAll(other); + } + virtual void otherSiblingOrderChange(QmlGraphicsItemPrivate* other) {Q_UNUSED(other)} + + static int consistentTime; static QTime currentTime(); static void Q_DECLARATIVE_EXPORT setConsistentTime(int t); diff --git a/src/declarative/graphicsitems/qmlgraphicslistview.cpp b/src/declarative/graphicsitems/qmlgraphicslistview.cpp index 53287a6..12bf0d8 100644 --- a/src/declarative/graphicsitems/qmlgraphicslistview.cpp +++ b/src/declarative/graphicsitems/qmlgraphicslistview.cpp @@ -641,6 +641,7 @@ void QmlGraphicsListViewPrivate::updateTrackedItem() void QmlGraphicsListViewPrivate::createHighlight() { Q_Q(QmlGraphicsListView); + bool changed = false; if (highlight) { if (trackedItem == highlight) trackedItem = 0; @@ -651,6 +652,7 @@ void QmlGraphicsListViewPrivate::createHighlight() delete highlightSizeAnimator; highlightPosAnimator = 0; highlightSizeAnimator = 0; + changed = true; } if (currentItem) { @@ -687,8 +689,11 @@ void QmlGraphicsListViewPrivate::createHighlight() highlightSizeAnimator->setVelocity(highlightResizeSpeed); highlightSizeAnimator->setTarget(QmlMetaProperty(highlight->item, sizeProp)); highlightSizeAnimator->setEnabled(autoHighlight); + changed = true; } } + if (changed) + emit q->highlightChanged(); } void QmlGraphicsListViewPrivate::updateHighlight() @@ -871,7 +876,7 @@ void QmlGraphicsListViewPrivate::flickX(qreal velocity) if (v > 0) dist = -dist; dist = -_moveX.value() - snapPosAt(-(_moveX.value() - highlightRangeStart) + dist) + highlightRangeStart; - if (v < 0 && dist >= 0 || v > 0 && dist <= 0) { + if ((v < 0 && dist >= 0) || (v > 0 && dist <= 0)) { timeline.reset(_moveX); fixupX(); return; @@ -929,7 +934,7 @@ void QmlGraphicsListViewPrivate::flickY(qreal velocity) if (v > 0) dist = -dist; dist = -_moveY.value() - snapPosAt(-(_moveY.value() - highlightRangeStart) + dist) + highlightRangeStart; - if (v < 0 && dist >= 0 || v > 0 && dist <= 0) { + if ((v < 0 && dist >= 0) || (v > 0 && dist <= 0)) { timeline.reset(_moveY); fixupY(); return; @@ -1202,6 +1207,25 @@ QmlGraphicsItem *QmlGraphicsListView::currentItem() } /*! + \qmlproperty Item ListView::highlightItem + + \c highlightItem holds the highlight item, which was created + from the \l highlight component. + + The highlightItem is managed by the view unless + \l highlightFollowsCurrentItem is set to false. + + \sa highlight, highlightFollowsCurrentItem +*/ +QmlGraphicsItem *QmlGraphicsListView::highlightItem() +{ + Q_D(QmlGraphicsListView); + if (!d->highlight) + return 0; + return d->highlight->item; +} + +/*! \qmlproperty int ListView::count This property holds the number of items in the view. */ @@ -1228,7 +1252,7 @@ int QmlGraphicsListView::count() const \snippet doc/src/snippets/declarative/listview/listview.qml 1 \image trivialListView.png - \sa highlightFollowsCurrentItem + \sa highlightItem, highlightFollowsCurrentItem */ QmlComponent *QmlGraphicsListView::highlight() const { diff --git a/src/declarative/graphicsitems/qmlgraphicslistview_p.h b/src/declarative/graphicsitems/qmlgraphicslistview_p.h index 3f46434..b8a6e1f 100644 --- a/src/declarative/graphicsitems/qmlgraphicslistview_p.h +++ b/src/declarative/graphicsitems/qmlgraphicslistview_p.h @@ -66,6 +66,7 @@ class Q_DECLARATIVE_EXPORT QmlGraphicsListView : public QmlGraphicsFlickable Q_PROPERTY(int count READ count NOTIFY countChanged) Q_PROPERTY(QmlComponent *highlight READ highlight WRITE setHighlight) + Q_PROPERTY(QmlGraphicsItem *highlightItem READ highlightItem NOTIFY highlightChanged) Q_PROPERTY(bool highlightFollowsCurrentItem READ highlightFollowsCurrentItem WRITE setHighlightFollowsCurrentItem) Q_PROPERTY(qreal highlightMoveSpeed READ highlightMoveSpeed WRITE setHighlightMoveSpeed NOTIFY highlightMoveSpeedChanged) Q_PROPERTY(qreal highlightResizeSpeed READ highlightResizeSpeed WRITE setHighlightResizeSpeed NOTIFY highlightResizeSpeedChanged) @@ -99,6 +100,7 @@ public: void setCurrentIndex(int idx); QmlGraphicsItem *currentItem(); + QmlGraphicsItem *highlightItem(); int count() const; QmlComponent *highlight() const; @@ -155,6 +157,7 @@ Q_SIGNALS: void sectionExpressionChanged(); void highlightMoveSpeedChanged(); void highlightResizeSpeedChanged(); + void highlightChanged(); protected: virtual void viewportMoved(); diff --git a/src/declarative/graphicsitems/qmlgraphicspositioners.cpp b/src/declarative/graphicsitems/qmlgraphicspositioners.cpp index 3b975ba..cbb4b13 100644 --- a/src/declarative/graphicsitems/qmlgraphicspositioners.cpp +++ b/src/declarative/graphicsitems/qmlgraphicspositioners.cpp @@ -52,6 +52,36 @@ QT_BEGIN_NAMESPACE +void QmlGraphicsBasePositionerPrivate::watchChanges(QmlGraphicsItem *other) +{ + Q_Q(QmlGraphicsBasePositioner); + QObject::connect(other, SIGNAL(visibleChanged()), + q, SLOT(prePositioning())); + QObject::connect(other, SIGNAL(opacityChanged()), + q, SLOT(prePositioning())); + QObject::connect(other, SIGNAL(heightChanged()), + q, SLOT(prePositioning())); + QObject::connect(other, SIGNAL(widthChanged()), + q, SLOT(prePositioning())); + static_cast<QmlGraphicsItemPrivate*>(QGraphicsItemPrivate::get(other))->registerSiblingOrderNotification(this); + watched << other; +} + +void QmlGraphicsBasePositionerPrivate::unwatchChanges(QmlGraphicsItem* other) +{ + Q_Q(QmlGraphicsBasePositioner); + QObject::disconnect(other, SIGNAL(visibleChanged()), + q, SLOT(prePositioning())); + QObject::disconnect(other, SIGNAL(opacityChanged()), + q, SLOT(prePositioning())); + QObject::disconnect(other, SIGNAL(heightChanged()), + q, SLOT(prePositioning())); + QObject::disconnect(other, SIGNAL(widthChanged()), + q, SLOT(prePositioning())); + static_cast<QmlGraphicsItemPrivate*>(QGraphicsItemPrivate::get(other))->unregisterSiblingOrderNotification(this); + watched.removeAll(other); +} + /*! \internal \class QmlGraphicsBasePositioner @@ -204,6 +234,7 @@ void QmlGraphicsBasePositioner::prePositioning() if (!isComponentComplete() || d->_movingItem) return; + d->queuedPositioning = false; if (!d->_ep) { d->_ep = true; QCoreApplication::postEvent(this, new QEvent(QEvent::User)); @@ -220,14 +251,7 @@ void QmlGraphicsBasePositioner::prePositioning() if (!child) continue; if (!d->_items.contains(child)){ - QObject::connect(child, SIGNAL(visibleChanged()), - this, SLOT(prePositioning())); - QObject::connect(child, SIGNAL(opacityChanged()), - this, SLOT(prePositioning())); - QObject::connect(child, SIGNAL(heightChanged()), - this, SLOT(prePositioning())); - QObject::connect(child, SIGNAL(widthChanged()), - this, SLOT(prePositioning())); + d->watchChanges(child); d->_items += child; } if (child->opacity() == 0.0){ @@ -390,58 +414,24 @@ Column { /*! \qmlproperty Transition Column::remove This property holds the transition to apply when removing an item from the positioner. The transition is only applied to the removed items. + Positioner transitions will only affect the position (x,y) of items. Removed can mean that either the object has been deleted or reparented, and thus is now longer a child of the positioner, or that the object has had its opacity set to zero, and thus is no longer visible. - Note that if the item counts as removed because its opacity is zero it will not be visible during the transition unless you set the opacity in the transition, like in the below example. - - \table - \row - \o \image positioner-remove.gif - \o - \qml -Column { - remove: Transition { - NumberAnimation { - properties: "opacity" - from: 1 - to: 0 - duration: 500 - } - } -} - \endqml - \endtable - */ /*! \qmlproperty Transition Column::add This property holds the transition to be applied when adding an item to the positioner. The transition will only be applied to the added item(s). + Positioner transitions will only affect the position (x,y) of items. Added can mean that either the object has been created or reparented, and thus is now a child or the positioner, or that the object has had its opacity increased from zero, and thus is now visible. - \table - \row - \o \image positioner-add.gif - \o - \qml -Column { - add: Transition { - NumberAnimation { - properties: "opacity" - from: 0 - to: 1 - duration: 500 - } - } -} - \endqml - \endtable */ /*! \qmlproperty Transition Column::move This property holds the transition to apply when moving an item within the positioner. + Positioner transitions will only affect the position (x,y) of items. This can happen when other items are added or removed from the positioner, or when items resize themselves. @@ -564,49 +554,28 @@ Row { \qmlproperty Transition Row::remove This property holds the transition to apply when removing an item from the positioner. The transition will only be applied to the removed item(s). + Positioner transitions will only affect the position (x,y) of items. Removed can mean that either the object has been deleted or reparented, and thus is now longer a child of the positioner, or that the object has had its opacity set to zero, and thus is no longer visible. Note that if the item counts as removed because its opacity is zero it will not be visible during the transition unless you set the opacity in the transition, like in the below example. - \qml -Row { - remove: Transition { - NumberAnimation { - properties: "opacity" - from: 1 - to: 0 - duration: 500 - } - } -} - \endqml */ /*! \qmlproperty Transition Row::add This property holds the transition to apply when adding an item to the positioner. The transition will only be applied to the added item(s). + Positioner transitions will only affect the position (x,y) of items. Added can mean that either the object has been created or reparented, and thus is now a child or the positioner, or that the object has had its opacity increased from zero, and thus is now visible. - \qml -Row { - add: Transition { - NumberAnimation { - properties: "opacity" - from: 0 - to: 1 - duration: 500 - } - } -} - \endqml */ /*! \qmlproperty Transition Row::move This property holds the transition to apply when moving an item within the positioner. + Positioner transitions will only affect the position (x,y) of items. This can happen when other items are added or removed from the positioner, or when items resize themselves. @@ -735,57 +704,32 @@ Grid { \qmlproperty Transition Grid::remove This property holds the transition to apply when removing an item from the positioner. The transition is only applied to the removed item(s). + Positioner transitions will only affect the position (x,y) of items. Removed can mean that either the object has been deleted or reparented, and thus is now longer a child of the positioner, or that the object has had its opacity set to zero, and thus is no longer visible. - Note that if the item counts as removed because its opacity is - zero it will not be visible during the transition unless you set - the opacity in the transition, like in the below example. - - \qml -Grid { - remove: Transition { - NumberAnimation { - properties: "opacity" - from: 1 - to: 0 - duration: 500 - } - } -} - \endqml */ /*! \qmlproperty Transition Grid::add This property holds the transition to apply when adding an item to the positioner. The transition is only applied to the added item(s). + Positioner transitions will only affect the position (x,y) of items. Added can mean that either the object has been created or reparented, and thus is now a child or the positioner, or that the object has had its opacity increased from zero, and thus is now visible. - \qml -Grid { - add: Transition { - NumberAnimation { - properties: "opacity" - from: 0 - to: 1 - duration: 500 - } - } -} - \endqml */ /*! \qmlproperty Transition Grid::move This property holds the transition to apply when moving an item within the positioner. + Positioner transitions will only affect the position (x,y) of items. This can happen when other items are added or removed from the positioner, or when items resize themselves. diff --git a/src/declarative/graphicsitems/qmlgraphicspositioners_p_p.h b/src/declarative/graphicsitems/qmlgraphicspositioners_p_p.h index 61b4497..d7a31a3 100644 --- a/src/declarative/graphicsitems/qmlgraphicspositioners_p_p.h +++ b/src/declarative/graphicsitems/qmlgraphicspositioners_p_p.h @@ -60,6 +60,7 @@ #include <private/qmlstate_p.h> #include <private/qmltransitionmanager_p_p.h> #include <private/qmlstateoperations_p.h> +#include <QtCore/QTimer> QT_BEGIN_NAMESPACE class QmlGraphicsBasePositionerPrivate : public QmlGraphicsItemPrivate @@ -70,10 +71,17 @@ public: QmlGraphicsBasePositionerPrivate() : _ep(false), _componentComplete(false), _spacing(0), aut(QmlGraphicsBasePositioner::None), moveTransition(0), addTransition(0), - removeTransition(0), _movingItem(0) + removeTransition(0), _movingItem(0), queuedPositioning(false) { } + ~QmlGraphicsBasePositionerPrivate() + { + watched.removeAll(0); + foreach(QmlGraphicsItem* other, watched) + unwatchChanges(other);//Need to deregister from a list in QmlGI Private + } + void init(QmlGraphicsBasePositioner::AutoUpdateType at) { aut = at; @@ -99,6 +107,22 @@ public: QmlTransitionManager removeTransitionManager; // QmlStateGroup *stateGroup; QmlGraphicsItem *_movingItem; + + void watchChanges(QmlGraphicsItem *other); + void unwatchChanges(QmlGraphicsItem* other); + QList<QGuard<QmlGraphicsItem> > watched; + bool queuedPositioning; + + virtual void otherSiblingOrderChange(QmlGraphicsItemPrivate* other) + { + Q_Q(QmlGraphicsBasePositioner); + Q_UNUSED(other); + if(!queuedPositioning){ + //Delay is due to many children often being reordered at once + QTimer::singleShot(0,q,SLOT(prePositioning())); + queuedPositioning = true; + } + } }; QT_END_NAMESPACE |