summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlan Alpert <alan.alpert@nokia.com>2009-11-10 00:31:05 (GMT)
committerAlan Alpert <alan.alpert@nokia.com>2009-11-10 00:31:33 (GMT)
commitc99661bb07af4838d3d26dcd6332587985edc7f4 (patch)
tree3d30050e8f28632f033a8be3734e3fd08770dee3
parent1557f3b4714b7bc53eaa850b9fbbec6bc24d3ff9 (diff)
downloadQt-c99661bb07af4838d3d26dcd6332587985edc7f4.zip
Qt-c99661bb07af4838d3d26dcd6332587985edc7f4.tar.gz
Qt-c99661bb07af4838d3d26dcd6332587985edc7f4.tar.bz2
Positioners now watch for sibling order changes
Task-number: QT-2241
-rw-r--r--src/declarative/graphicsitems/qmlgraphicsitem_p.h18
-rw-r--r--src/declarative/graphicsitems/qmlgraphicspositioners.cpp40
-rw-r--r--src/declarative/graphicsitems/qmlgraphicspositioners_p_p.h26
3 files changed, 75 insertions, 9 deletions
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/qmlgraphicspositioners.cpp b/src/declarative/graphicsitems/qmlgraphicspositioners.cpp
index 3b975ba..82ccde0 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){
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