src/gui/graphicsview/qgraphicsitem_p.h
changeset 30 5dc02b23752f
parent 23 89e065397ea6
child 33 3e2da88830cd
--- a/src/gui/graphicsview/qgraphicsitem_p.h	Wed Jun 23 19:07:03 2010 +0300
+++ b/src/gui/graphicsview/qgraphicsitem_p.h	Tue Jul 06 15:10:48 2010 +0300
@@ -71,6 +71,63 @@
 
 class QGraphicsItemPrivate;
 
+#ifndef QDECLARATIVELISTPROPERTY
+#define QDECLARATIVELISTPROPERTY
+template<typename T>
+class QDeclarativeListProperty {
+public:
+    typedef void (*AppendFunction)(QDeclarativeListProperty<T> *, T*);
+    typedef int (*CountFunction)(QDeclarativeListProperty<T> *);
+    typedef T *(*AtFunction)(QDeclarativeListProperty<T> *, int);
+    typedef void (*ClearFunction)(QDeclarativeListProperty<T> *);
+
+    QDeclarativeListProperty()
+        : object(0), data(0), append(0), count(0), at(0), clear(0), dummy1(0), dummy2(0) {}
+    QDeclarativeListProperty(QObject *o, QList<T *> &list)
+        : object(o), data(&list), append(qlist_append), count(qlist_count), at(qlist_at),
+          clear(qlist_clear), dummy1(0), dummy2(0) {}
+    QDeclarativeListProperty(QObject *o, void *d, AppendFunction a, CountFunction c = 0, AtFunction t = 0,
+                    ClearFunction r = 0)
+        : object(o), data(d), append(a), count(c), at(t), clear(r), dummy1(0), dummy2(0) {}
+
+    bool operator==(const QDeclarativeListProperty &o) const {
+        return object == o.object &&
+               data == o.data &&
+               append == o.append &&
+               count == o.count &&
+               at == o.at &&
+               clear == o.clear;
+    }
+
+    QObject *object;
+    void *data;
+
+    AppendFunction append;
+
+    CountFunction count;
+    AtFunction at;
+
+    ClearFunction clear;
+
+    void *dummy1;
+    void *dummy2;
+
+private:
+    static void qlist_append(QDeclarativeListProperty *p, T *v) {
+        ((QList<T *> *)p->data)->append(v);
+    }
+    static int qlist_count(QDeclarativeListProperty *p) {
+        return ((QList<T *> *)p->data)->count();
+    }
+    static T *qlist_at(QDeclarativeListProperty *p, int idx) {
+        return ((QList<T *> *)p->data)->at(idx);
+    }
+    static void qlist_clear(QDeclarativeListProperty *p) {
+        return ((QList<T *> *)p->data)->clear();
+    }
+};
+#endif
+
 class QGraphicsItemCache
 {
 public:
@@ -156,8 +213,8 @@
         needSortChildren(0),
         allChildrenDirty(0),
         fullUpdatePending(0),
+        dirtyChildrenBoundingRect(1),
         flags(0),
-        dirtyChildrenBoundingRect(1),
         paintedViewBoundingRectsNeedRepaint(0),
         dirtySceneTransform(1),
         geometryChanged(1),
@@ -180,6 +237,7 @@
         scenePosDescendants(0),
         pendingPolish(0),
         mayHaveChildWithGraphicsEffect(0),
+        isDeclarativeItem(0),
         globalStackingOrder(-1),
         q_ptr(0)
     {
@@ -220,11 +278,13 @@
 
     virtual void setPosHelper(const QPointF &pos);
     void setTransformHelper(const QTransform &transform);
+    void prependGraphicsTransform(QGraphicsTransform *t);
     void appendGraphicsTransform(QGraphicsTransform *t);
     void setVisibleHelper(bool newVisible, bool explicitly, bool update = true);
     void setEnabledHelper(bool newEnabled, bool explicitly, bool update = true);
     bool discardUpdateRequest(bool ignoreVisibleBit = false,
                               bool ignoreDirtyBit = false, bool ignoreOpacity = false) const;
+    virtual void transformChanged() {}
     int depth() const;
 #ifndef QT_NO_GRAPHICSEFFECT
     enum InvalidateReason {
@@ -237,6 +297,7 @@
     void resolveDepth();
     void addChild(QGraphicsItem *child);
     void removeChild(QGraphicsItem *child);
+    QDeclarativeListProperty<QGraphicsObject> childrenList();
     void setParentItemHelper(QGraphicsItem *parent, const QVariant *newParentVariant,
                              const QVariant *thisPointerVariant);
     void childrenBoundingRectHelper(QTransform *x, QRectF *rect);
@@ -316,6 +377,7 @@
     QGraphicsItemCache *extraItemCache() const;
     void removeExtraItemCache();
 
+    void updatePaintedViewBoundingRects(bool updateChildren);
     void ensureSceneTransformRecursive(QGraphicsItem **topMostDirtyItem);
     inline void ensureSceneTransform()
     {
@@ -421,6 +483,10 @@
     void resetFocusProxy();
     virtual void subFocusItemChange();
 
+    static void children_append(QDeclarativeListProperty<QGraphicsObject> *list, QGraphicsObject *item);
+    static int children_count(QDeclarativeListProperty<QGraphicsObject> *list);
+    static QGraphicsObject *children_at(QDeclarativeListProperty<QGraphicsObject> *list, int);
+
     inline QTransform transformToParent() const;
     inline void ensureSortedChildren();
     static inline bool insertionOrder(QGraphicsItem *a, QGraphicsItem *b);
@@ -428,6 +494,15 @@
     inline void sendScenePosChange();
     virtual void siblingOrderChange();
 
+    // Private Properties
+    virtual qreal width() const;
+    virtual void setWidth(qreal);
+    virtual void resetWidth();
+
+    virtual qreal height() const;
+    virtual void setHeight(qreal);
+    virtual void resetHeight();
+
     QRectF childrenBoundingRect;
     QRectF needsRepaint;
     QMap<QWidget *, QRect> paintedViewBoundingRects;
@@ -475,11 +550,11 @@
     quint32 inSetPosHelper : 1;
     quint32 needSortChildren : 1;
     quint32 allChildrenDirty : 1;
+    quint32 fullUpdatePending : 1;
+    quint32 dirtyChildrenBoundingRect : 1;
 
     // Packed 32 bits
-    quint32 fullUpdatePending : 1;
     quint32 flags : 17;
-    quint32 dirtyChildrenBoundingRect : 1;
     quint32 paintedViewBoundingRectsNeedRepaint : 1;
     quint32 dirtySceneTransform : 1;
     quint32 geometryChanged : 1;
@@ -493,10 +568,10 @@
     quint32 sceneTransformTranslateOnly : 1;
     quint32 notifyBoundingRectChanged : 1;
     quint32 notifyInvalidated : 1;
+    quint32 mouseSetsFocus : 1;
+    quint32 explicitActivate : 1;
 
     // New 32 bits
-    quint32 mouseSetsFocus : 1;
-    quint32 explicitActivate : 1;
     quint32 wantsActive : 1;
     quint32 holesInSiblingIndex : 1;
     quint32 sequentialOrdering : 1;
@@ -504,6 +579,8 @@
     quint32 scenePosDescendants : 1;
     quint32 pendingPolish : 1;
     quint32 mayHaveChildWithGraphicsEffect : 1;
+    quint32 isDeclarativeItem : 1;
+    quint32 padding : 24;
 
     // Optional stacking order
     int globalStackingOrder;
@@ -609,7 +686,7 @@
         return item->type() == QGraphicsPixmapItem::Type
                && !(item->flags() & QGraphicsItem::ItemIsSelectable)
                && item->d_ptr->children.size() == 0;
-            //|| (item->d_ptr->isObject && qobject_cast<QmlGraphicsImage *>(q_func()));
+            //|| (item->d_ptr->isObject && qobject_cast<QDeclarativeImage *>(q_func()));
     }
 
     inline const QStyleOption *styleOption() const
@@ -792,7 +869,7 @@
                 static_cast<QGraphicsItemEffectSourcePrivate *>(parentp->graphicsEffect->d_func()
                                                                 ->source->d_func())->invalidateCache();
             }
-            if (parentp->graphicsEffect->isEnabled()) {
+            if (parentp->scene && parentp->graphicsEffect->isEnabled()) {
                 parentp->dirty = 1;
                 parentp->fullUpdatePending = 1;
             }