68 #if !defined(QT_NO_GRAPHICSVIEW) || (QT_EDITION & QT_MODULE_GRAPHICSVIEW) != QT_MODULE_GRAPHICSVIEW |
68 #if !defined(QT_NO_GRAPHICSVIEW) || (QT_EDITION & QT_MODULE_GRAPHICSVIEW) != QT_MODULE_GRAPHICSVIEW |
69 |
69 |
70 QT_BEGIN_NAMESPACE |
70 QT_BEGIN_NAMESPACE |
71 |
71 |
72 class QGraphicsItemPrivate; |
72 class QGraphicsItemPrivate; |
|
73 |
|
74 #ifndef QDECLARATIVELISTPROPERTY |
|
75 #define QDECLARATIVELISTPROPERTY |
|
76 template<typename T> |
|
77 class QDeclarativeListProperty { |
|
78 public: |
|
79 typedef void (*AppendFunction)(QDeclarativeListProperty<T> *, T*); |
|
80 typedef int (*CountFunction)(QDeclarativeListProperty<T> *); |
|
81 typedef T *(*AtFunction)(QDeclarativeListProperty<T> *, int); |
|
82 typedef void (*ClearFunction)(QDeclarativeListProperty<T> *); |
|
83 |
|
84 QDeclarativeListProperty() |
|
85 : object(0), data(0), append(0), count(0), at(0), clear(0), dummy1(0), dummy2(0) {} |
|
86 QDeclarativeListProperty(QObject *o, QList<T *> &list) |
|
87 : object(o), data(&list), append(qlist_append), count(qlist_count), at(qlist_at), |
|
88 clear(qlist_clear), dummy1(0), dummy2(0) {} |
|
89 QDeclarativeListProperty(QObject *o, void *d, AppendFunction a, CountFunction c = 0, AtFunction t = 0, |
|
90 ClearFunction r = 0) |
|
91 : object(o), data(d), append(a), count(c), at(t), clear(r), dummy1(0), dummy2(0) {} |
|
92 |
|
93 bool operator==(const QDeclarativeListProperty &o) const { |
|
94 return object == o.object && |
|
95 data == o.data && |
|
96 append == o.append && |
|
97 count == o.count && |
|
98 at == o.at && |
|
99 clear == o.clear; |
|
100 } |
|
101 |
|
102 QObject *object; |
|
103 void *data; |
|
104 |
|
105 AppendFunction append; |
|
106 |
|
107 CountFunction count; |
|
108 AtFunction at; |
|
109 |
|
110 ClearFunction clear; |
|
111 |
|
112 void *dummy1; |
|
113 void *dummy2; |
|
114 |
|
115 private: |
|
116 static void qlist_append(QDeclarativeListProperty *p, T *v) { |
|
117 ((QList<T *> *)p->data)->append(v); |
|
118 } |
|
119 static int qlist_count(QDeclarativeListProperty *p) { |
|
120 return ((QList<T *> *)p->data)->count(); |
|
121 } |
|
122 static T *qlist_at(QDeclarativeListProperty *p, int idx) { |
|
123 return ((QList<T *> *)p->data)->at(idx); |
|
124 } |
|
125 static void qlist_clear(QDeclarativeListProperty *p) { |
|
126 return ((QList<T *> *)p->data)->clear(); |
|
127 } |
|
128 }; |
|
129 #endif |
73 |
130 |
74 class QGraphicsItemCache |
131 class QGraphicsItemCache |
75 { |
132 { |
76 public: |
133 public: |
77 QGraphicsItemCache() : allExposed(false) { } |
134 QGraphicsItemCache() : allExposed(false) { } |
154 localCollisionHack(0), |
211 localCollisionHack(0), |
155 inSetPosHelper(0), |
212 inSetPosHelper(0), |
156 needSortChildren(0), |
213 needSortChildren(0), |
157 allChildrenDirty(0), |
214 allChildrenDirty(0), |
158 fullUpdatePending(0), |
215 fullUpdatePending(0), |
|
216 dirtyChildrenBoundingRect(1), |
159 flags(0), |
217 flags(0), |
160 dirtyChildrenBoundingRect(1), |
|
161 paintedViewBoundingRectsNeedRepaint(0), |
218 paintedViewBoundingRectsNeedRepaint(0), |
162 dirtySceneTransform(1), |
219 dirtySceneTransform(1), |
163 geometryChanged(1), |
220 geometryChanged(1), |
164 inDestructor(0), |
221 inDestructor(0), |
165 isObject(0), |
222 isObject(0), |
178 sequentialOrdering(1), |
235 sequentialOrdering(1), |
179 updateDueToGraphicsEffect(0), |
236 updateDueToGraphicsEffect(0), |
180 scenePosDescendants(0), |
237 scenePosDescendants(0), |
181 pendingPolish(0), |
238 pendingPolish(0), |
182 mayHaveChildWithGraphicsEffect(0), |
239 mayHaveChildWithGraphicsEffect(0), |
|
240 isDeclarativeItem(0), |
183 globalStackingOrder(-1), |
241 globalStackingOrder(-1), |
184 q_ptr(0) |
242 q_ptr(0) |
185 { |
243 { |
186 } |
244 } |
187 |
245 |
218 virtual QVariant inputMethodQueryHelper(Qt::InputMethodQuery query) const; |
276 virtual QVariant inputMethodQueryHelper(Qt::InputMethodQuery query) const; |
219 static bool movableAncestorIsSelected(const QGraphicsItem *item); |
277 static bool movableAncestorIsSelected(const QGraphicsItem *item); |
220 |
278 |
221 virtual void setPosHelper(const QPointF &pos); |
279 virtual void setPosHelper(const QPointF &pos); |
222 void setTransformHelper(const QTransform &transform); |
280 void setTransformHelper(const QTransform &transform); |
|
281 void prependGraphicsTransform(QGraphicsTransform *t); |
223 void appendGraphicsTransform(QGraphicsTransform *t); |
282 void appendGraphicsTransform(QGraphicsTransform *t); |
224 void setVisibleHelper(bool newVisible, bool explicitly, bool update = true); |
283 void setVisibleHelper(bool newVisible, bool explicitly, bool update = true); |
225 void setEnabledHelper(bool newEnabled, bool explicitly, bool update = true); |
284 void setEnabledHelper(bool newEnabled, bool explicitly, bool update = true); |
226 bool discardUpdateRequest(bool ignoreVisibleBit = false, |
285 bool discardUpdateRequest(bool ignoreVisibleBit = false, |
227 bool ignoreDirtyBit = false, bool ignoreOpacity = false) const; |
286 bool ignoreDirtyBit = false, bool ignoreOpacity = false) const; |
|
287 virtual void transformChanged() {} |
228 int depth() const; |
288 int depth() const; |
229 #ifndef QT_NO_GRAPHICSEFFECT |
289 #ifndef QT_NO_GRAPHICSEFFECT |
230 enum InvalidateReason { |
290 enum InvalidateReason { |
231 OpacityChanged |
291 OpacityChanged |
232 }; |
292 }; |
235 #endif //QT_NO_GRAPHICSEFFECT |
295 #endif //QT_NO_GRAPHICSEFFECT |
236 void invalidateDepthRecursively(); |
296 void invalidateDepthRecursively(); |
237 void resolveDepth(); |
297 void resolveDepth(); |
238 void addChild(QGraphicsItem *child); |
298 void addChild(QGraphicsItem *child); |
239 void removeChild(QGraphicsItem *child); |
299 void removeChild(QGraphicsItem *child); |
|
300 QDeclarativeListProperty<QGraphicsObject> childrenList(); |
240 void setParentItemHelper(QGraphicsItem *parent, const QVariant *newParentVariant, |
301 void setParentItemHelper(QGraphicsItem *parent, const QVariant *newParentVariant, |
241 const QVariant *thisPointerVariant); |
302 const QVariant *thisPointerVariant); |
242 void childrenBoundingRectHelper(QTransform *x, QRectF *rect); |
303 void childrenBoundingRectHelper(QTransform *x, QRectF *rect); |
243 void initStyleOption(QStyleOptionGraphicsItem *option, const QTransform &worldTransform, |
304 void initStyleOption(QStyleOptionGraphicsItem *option, const QTransform &worldTransform, |
244 const QRegion &exposedRegion, bool allItems = false) const; |
305 const QRegion &exposedRegion, bool allItems = false) const; |
314 |
375 |
315 QGraphicsItemCache *maybeExtraItemCache() const; |
376 QGraphicsItemCache *maybeExtraItemCache() const; |
316 QGraphicsItemCache *extraItemCache() const; |
377 QGraphicsItemCache *extraItemCache() const; |
317 void removeExtraItemCache(); |
378 void removeExtraItemCache(); |
318 |
379 |
|
380 void updatePaintedViewBoundingRects(bool updateChildren); |
319 void ensureSceneTransformRecursive(QGraphicsItem **topMostDirtyItem); |
381 void ensureSceneTransformRecursive(QGraphicsItem **topMostDirtyItem); |
320 inline void ensureSceneTransform() |
382 inline void ensureSceneTransform() |
321 { |
383 { |
322 QGraphicsItem *that = q_func(); |
384 QGraphicsItem *that = q_func(); |
323 ensureSceneTransformRecursive(&that); |
385 ensureSceneTransformRecursive(&that); |
419 void setSubFocus(QGraphicsItem *rootItem = 0); |
481 void setSubFocus(QGraphicsItem *rootItem = 0); |
420 void clearSubFocus(QGraphicsItem *rootItem = 0); |
482 void clearSubFocus(QGraphicsItem *rootItem = 0); |
421 void resetFocusProxy(); |
483 void resetFocusProxy(); |
422 virtual void subFocusItemChange(); |
484 virtual void subFocusItemChange(); |
423 |
485 |
|
486 static void children_append(QDeclarativeListProperty<QGraphicsObject> *list, QGraphicsObject *item); |
|
487 static int children_count(QDeclarativeListProperty<QGraphicsObject> *list); |
|
488 static QGraphicsObject *children_at(QDeclarativeListProperty<QGraphicsObject> *list, int); |
|
489 |
424 inline QTransform transformToParent() const; |
490 inline QTransform transformToParent() const; |
425 inline void ensureSortedChildren(); |
491 inline void ensureSortedChildren(); |
426 static inline bool insertionOrder(QGraphicsItem *a, QGraphicsItem *b); |
492 static inline bool insertionOrder(QGraphicsItem *a, QGraphicsItem *b); |
427 void ensureSequentialSiblingIndex(); |
493 void ensureSequentialSiblingIndex(); |
428 inline void sendScenePosChange(); |
494 inline void sendScenePosChange(); |
429 virtual void siblingOrderChange(); |
495 virtual void siblingOrderChange(); |
|
496 |
|
497 // Private Properties |
|
498 virtual qreal width() const; |
|
499 virtual void setWidth(qreal); |
|
500 virtual void resetWidth(); |
|
501 |
|
502 virtual qreal height() const; |
|
503 virtual void setHeight(qreal); |
|
504 virtual void resetHeight(); |
430 |
505 |
431 QRectF childrenBoundingRect; |
506 QRectF childrenBoundingRect; |
432 QRectF needsRepaint; |
507 QRectF needsRepaint; |
433 QMap<QWidget *, QRect> paintedViewBoundingRects; |
508 QMap<QWidget *, QRect> paintedViewBoundingRects; |
434 QPointF pos; |
509 QPointF pos; |
473 quint32 dirtyChildren : 1; |
548 quint32 dirtyChildren : 1; |
474 quint32 localCollisionHack : 1; |
549 quint32 localCollisionHack : 1; |
475 quint32 inSetPosHelper : 1; |
550 quint32 inSetPosHelper : 1; |
476 quint32 needSortChildren : 1; |
551 quint32 needSortChildren : 1; |
477 quint32 allChildrenDirty : 1; |
552 quint32 allChildrenDirty : 1; |
|
553 quint32 fullUpdatePending : 1; |
|
554 quint32 dirtyChildrenBoundingRect : 1; |
478 |
555 |
479 // Packed 32 bits |
556 // Packed 32 bits |
480 quint32 fullUpdatePending : 1; |
|
481 quint32 flags : 17; |
557 quint32 flags : 17; |
482 quint32 dirtyChildrenBoundingRect : 1; |
|
483 quint32 paintedViewBoundingRectsNeedRepaint : 1; |
558 quint32 paintedViewBoundingRectsNeedRepaint : 1; |
484 quint32 dirtySceneTransform : 1; |
559 quint32 dirtySceneTransform : 1; |
485 quint32 geometryChanged : 1; |
560 quint32 geometryChanged : 1; |
486 quint32 inDestructor : 1; |
561 quint32 inDestructor : 1; |
487 quint32 isObject : 1; |
562 quint32 isObject : 1; |
491 quint32 acceptedTouchBeginEvent : 1; |
566 quint32 acceptedTouchBeginEvent : 1; |
492 quint32 filtersDescendantEvents : 1; |
567 quint32 filtersDescendantEvents : 1; |
493 quint32 sceneTransformTranslateOnly : 1; |
568 quint32 sceneTransformTranslateOnly : 1; |
494 quint32 notifyBoundingRectChanged : 1; |
569 quint32 notifyBoundingRectChanged : 1; |
495 quint32 notifyInvalidated : 1; |
570 quint32 notifyInvalidated : 1; |
496 |
|
497 // New 32 bits |
|
498 quint32 mouseSetsFocus : 1; |
571 quint32 mouseSetsFocus : 1; |
499 quint32 explicitActivate : 1; |
572 quint32 explicitActivate : 1; |
|
573 |
|
574 // New 32 bits |
500 quint32 wantsActive : 1; |
575 quint32 wantsActive : 1; |
501 quint32 holesInSiblingIndex : 1; |
576 quint32 holesInSiblingIndex : 1; |
502 quint32 sequentialOrdering : 1; |
577 quint32 sequentialOrdering : 1; |
503 quint32 updateDueToGraphicsEffect : 1; |
578 quint32 updateDueToGraphicsEffect : 1; |
504 quint32 scenePosDescendants : 1; |
579 quint32 scenePosDescendants : 1; |
505 quint32 pendingPolish : 1; |
580 quint32 pendingPolish : 1; |
506 quint32 mayHaveChildWithGraphicsEffect : 1; |
581 quint32 mayHaveChildWithGraphicsEffect : 1; |
|
582 quint32 isDeclarativeItem : 1; |
|
583 quint32 padding : 24; |
507 |
584 |
508 // Optional stacking order |
585 // Optional stacking order |
509 int globalStackingOrder; |
586 int globalStackingOrder; |
510 QGraphicsItem *q_ptr; |
587 QGraphicsItem *q_ptr; |
511 }; |
588 }; |
607 inline bool isPixmap() const |
684 inline bool isPixmap() const |
608 { |
685 { |
609 return item->type() == QGraphicsPixmapItem::Type |
686 return item->type() == QGraphicsPixmapItem::Type |
610 && !(item->flags() & QGraphicsItem::ItemIsSelectable) |
687 && !(item->flags() & QGraphicsItem::ItemIsSelectable) |
611 && item->d_ptr->children.size() == 0; |
688 && item->d_ptr->children.size() == 0; |
612 //|| (item->d_ptr->isObject && qobject_cast<QmlGraphicsImage *>(q_func())); |
689 //|| (item->d_ptr->isObject && qobject_cast<QDeclarativeImage *>(q_func())); |
613 } |
690 } |
614 |
691 |
615 inline const QStyleOption *styleOption() const |
692 inline const QStyleOption *styleOption() const |
616 { return info ? info->option : 0; } |
693 { return info ? info->option : 0; } |
617 |
694 |
790 if (updateBoundingRect) { |
867 if (updateBoundingRect) { |
791 parentp->notifyInvalidated = 1; |
868 parentp->notifyInvalidated = 1; |
792 static_cast<QGraphicsItemEffectSourcePrivate *>(parentp->graphicsEffect->d_func() |
869 static_cast<QGraphicsItemEffectSourcePrivate *>(parentp->graphicsEffect->d_func() |
793 ->source->d_func())->invalidateCache(); |
870 ->source->d_func())->invalidateCache(); |
794 } |
871 } |
795 if (parentp->graphicsEffect->isEnabled()) { |
872 if (parentp->scene && parentp->graphicsEffect->isEnabled()) { |
796 parentp->dirty = 1; |
873 parentp->dirty = 1; |
797 parentp->fullUpdatePending = 1; |
874 parentp->fullUpdatePending = 1; |
798 } |
875 } |
799 } |
876 } |
800 #endif |
877 #endif |