source: trunk/src/gui/graphicsview/qgraphicsitem_p.h@ 508

Last change on this file since 508 was 2, checked in by Dmitry A. Kuminov, 16 years ago

Initially imported qt-all-opensource-src-4.5.1 from Trolltech.

File size: 10.0 KB
Line 
1/****************************************************************************
2**
3** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
4** Contact: Qt Software Information ([email protected])
5**
6** This file is part of the QtGui module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial Usage
10** Licensees holding valid Qt Commercial licenses may use this file in
11** accordance with the Qt Commercial License Agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and Nokia.
14**
15** GNU Lesser General Public License Usage
16** Alternatively, this file may be used under the terms of the GNU Lesser
17** General Public License version 2.1 as published by the Free Software
18** Foundation and appearing in the file LICENSE.LGPL included in the
19** packaging of this file. Please review the following information to
20** ensure the GNU Lesser General Public License version 2.1 requirements
21** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
22**
23** In addition, as a special exception, Nokia gives you certain
24** additional rights. These rights are described in the Nokia Qt LGPL
25** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
26** package.
27**
28** GNU General Public License Usage
29** Alternatively, this file may be used under the terms of the GNU
30** General Public License version 3.0 as published by the Free Software
31** Foundation and appearing in the file LICENSE.GPL included in the
32** packaging of this file. Please review the following information to
33** ensure the GNU General Public License version 3.0 requirements will be
34** met: http://www.gnu.org/copyleft/gpl.html.
35**
36** If you are unsure which license is appropriate for your use, please
37** contact the sales department at [email protected].
38** $QT_END_LICENSE$
39**
40****************************************************************************/
41
42#ifndef QGRAPHICSITEM_P_H
43#define QGRAPHICSITEM_P_H
44
45//
46// W A R N I N G
47// -------------
48//
49// This file is not part of the Qt API. It exists for the convenience
50// of qapplication_*.cpp, qwidget*.cpp and qfiledialog.cpp. This header
51// file may change from version to version without notice, or even be removed.
52//
53// We mean it.
54//
55
56#include "qgraphicsitem.h"
57
58#if !defined(QT_NO_GRAPHICSVIEW) || (QT_EDITION & QT_MODULE_GRAPHICSVIEW) != QT_MODULE_GRAPHICSVIEW
59
60QT_BEGIN_NAMESPACE
61
62class QGraphicsItemPrivate;
63
64class QGraphicsItemCache
65{
66public:
67 QGraphicsItemCache() : allExposed(false) { }
68
69 // ItemCoordinateCache only
70 QRect boundingRect;
71 QSize fixedSize;
72 QString key;
73
74 // DeviceCoordinateCache only
75 struct DeviceData {
76 QTransform lastTransform;
77 QPoint cacheIndent;
78 QString key;
79 };
80 QMap<QPaintDevice *, DeviceData> deviceData;
81
82 // List of logical exposed rects
83 QVector<QRectF> exposed;
84 bool allExposed;
85
86 // Empty cache
87 void purge();
88};
89
90class Q_AUTOTEST_EXPORT QGraphicsItemPrivate
91{
92 Q_DECLARE_PUBLIC(QGraphicsItem)
93public:
94 enum Extra {
95 ExtraTransform,
96 ExtraToolTip,
97 ExtraCursor,
98 ExtraCacheData,
99 ExtraMaxDeviceCoordCacheSize,
100 ExtraBoundingRegionGranularity,
101 ExtraOpacity,
102 ExtraEffectiveOpacity
103 };
104
105 enum AncestorFlag {
106 NoFlag = 0,
107 AncestorHandlesChildEvents = 0x1,
108 AncestorClipsChildren = 0x2,
109 AncestorIgnoresTransformations = 0x4
110 };
111
112 inline QGraphicsItemPrivate()
113 : z(0),
114 scene(0),
115 parent(0),
116 index(-1),
117 depth(0),
118 acceptedMouseButtons(0x1f),
119 visible(1),
120 explicitlyHidden(0),
121 enabled(1),
122 explicitlyDisabled(0),
123 selected(0),
124 acceptsHover(0),
125 acceptDrops(0),
126 isMemberOfGroup(0),
127 handlesChildEvents(0),
128 itemDiscovered(0),
129 hasTransform(0),
130 hasCursor(0),
131 ancestorFlags(0),
132 cacheMode(0),
133 hasBoundingRegionGranularity(0),
134 flags(0),
135 hasOpacity(0),
136 hasEffectiveOpacity(0),
137 isWidget(0),
138 dirty(0),
139 dirtyChildren(0),
140 localCollisionHack(0),
141 dirtyClipPath(1),
142 emptyClipPath(0),
143 inSetPosHelper(0),
144 allChildrenCombineOpacity(1),
145 globalStackingOrder(-1),
146 sceneTransformIndex(-1),
147 q_ptr(0)
148 {
149 }
150
151 inline virtual ~QGraphicsItemPrivate()
152 { }
153
154 void updateAncestorFlag(QGraphicsItem::GraphicsItemFlag childFlag,
155 AncestorFlag flag = NoFlag, bool enabled = false, bool root = true);
156 void setIsMemberOfGroup(bool enabled);
157 void remapItemPos(QEvent *event, QGraphicsItem *item);
158 QPointF genericMapFromScene(const QPointF &pos, const QWidget *viewport) const;
159 bool itemIsUntransformable() const;
160
161 // ### Qt 5: Remove. Workaround for reimplementation added after Qt 4.4.
162 virtual QVariant inputMethodQueryHelper(Qt::InputMethodQuery query) const;
163 static bool movableAncestorIsSelected(const QGraphicsItem *item);
164
165 void setPosHelper(const QPointF &pos);
166 void setVisibleHelper(bool newVisible, bool explicitly, bool update = true);
167 void setEnabledHelper(bool newEnabled, bool explicitly, bool update = true);
168 bool discardUpdateRequest(bool ignoreClipping = false,
169 bool ignoreVisibleBit = false,
170 bool ignoreDirtyBit = false) const;
171 void updateHelper(const QRectF &rect = QRectF(), bool force = false, bool maybeDirtyClipPath = false);
172 void fullUpdateHelper(bool childrenOnly = false, bool maybeDirtyClipPath = false);
173 void updateEffectiveOpacity();
174 void resolveEffectiveOpacity(qreal effectiveParentOpacity);
175 void resolveDepth(int parentDepth);
176 void invalidateSceneTransformCache();
177
178 virtual void resolveFont(uint inheritedMask)
179 {
180 for (int i = 0; i < children.size(); ++i)
181 children.at(i)->d_ptr->resolveFont(inheritedMask);
182 }
183
184 virtual void resolvePalette(uint inheritedMask)
185 {
186 for (int i = 0; i < children.size(); ++i)
187 children.at(i)->d_ptr->resolveFont(inheritedMask);
188 }
189
190 virtual bool isProxyWidget() const;
191
192 inline QVariant extra(Extra type) const
193 {
194 for (int i = 0; i < extras.size(); ++i) {
195 const ExtraStruct &extra = extras.at(i);
196 if (extra.type == type)
197 return extra.value;
198 }
199 return QVariant();
200 }
201
202 inline void setExtra(Extra type, const QVariant &value)
203 {
204 int index = -1;
205 for (int i = 0; i < extras.size(); ++i) {
206 if (extras.at(i).type == type) {
207 index = i;
208 break;
209 }
210 }
211
212 if (index == -1) {
213 extras << ExtraStruct(type, value);
214 } else {
215 extras[index].value = value;
216 }
217 }
218
219 inline void unsetExtra(Extra type)
220 {
221 for (int i = 0; i < extras.size(); ++i) {
222 if (extras.at(i).type == type) {
223 extras.removeAt(i);
224 return;
225 }
226 }
227 }
228
229 struct ExtraStruct {
230 ExtraStruct(Extra type, QVariant value)
231 : type(type), value(value)
232 { }
233
234 Extra type;
235 QVariant value;
236
237 bool operator<(Extra extra) const
238 { return type < extra; }
239 };
240 QList<ExtraStruct> extras;
241
242 QGraphicsItemCache *extraItemCache() const;
243 void removeExtraItemCache();
244
245 inline void setCachedClipPath(const QPainterPath &path)
246 {
247 cachedClipPath = path;
248 dirtyClipPath = 0;
249 emptyClipPath = 0;
250 }
251
252 inline void setEmptyCachedClipPath()
253 {
254 emptyClipPath = 1;
255 dirtyClipPath = 0;
256 }
257
258 void setEmptyCachedClipPathRecursively(const QRectF &emptyIfOutsideThisRect = QRectF());
259
260 inline void invalidateCachedClipPath()