source: trunk/src/gui/graphicsview/qgraphicsitem.h@ 561

Last change on this file since 561 was 561, checked in by Dmitry A. Kuminov, 15 years ago

trunk: Merged in qt 4.6.1 sources.

File size: 39.5 KB
Line 
1/****************************************************************************
2**
3** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
4** All rights reserved.
5** Contact: Nokia Corporation ([email protected])
6**
7** This file is part of the QtGui module of the Qt Toolkit.
8**
9** $QT_BEGIN_LICENSE:LGPL$
10** Commercial Usage
11** Licensees holding valid Qt Commercial licenses may use this file in
12** accordance with the Qt Commercial License Agreement provided with the
13** Software or, alternatively, in accordance with the terms contained in
14** a written agreement between you and Nokia.
15**
16** GNU Lesser General Public License Usage
17** Alternatively, this file may be used under the terms of the GNU Lesser
18** General Public License version 2.1 as published by the Free Software
19** Foundation and appearing in the file LICENSE.LGPL included in the
20** packaging of this file. Please review the following information to
21** ensure the GNU Lesser General Public License version 2.1 requirements
22** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
23**
24** In addition, as a special exception, Nokia gives you certain additional
25** rights. These rights are described in the Nokia Qt LGPL Exception
26** version 1.1, included in the file LGPL_EXCEPTION.txt in this 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 have questions regarding the use of this file, please contact
37** Nokia at [email protected].
38** $QT_END_LICENSE$
39**
40****************************************************************************/
41
42#ifndef QGRAPHICSITEM_H
43#define QGRAPHICSITEM_H
44
45#include <QtCore/qglobal.h>
46#include <QtCore/qobject.h>
47#include <QtCore/qvariant.h>
48#include <QtCore/qrect.h>
49#include <QtCore/qscopedpointer.h>
50#include <QtGui/qpainterpath.h>
51#include <QtGui/qpixmap.h>
52
53class tst_QGraphicsItem;
54
55QT_BEGIN_HEADER
56
57QT_BEGIN_NAMESPACE
58
59QT_MODULE(Gui)
60
61#if !defined(QT_NO_GRAPHICSVIEW) || (QT_EDITION & QT_MODULE_GRAPHICSVIEW) != QT_MODULE_GRAPHICSVIEW
62
63class QBrush;
64class QCursor;
65class QFocusEvent;
66class QGraphicsEffect;
67class QGraphicsItemGroup;
68class QGraphicsObject;
69class QGraphicsSceneContextMenuEvent;
70class QGraphicsSceneDragDropEvent;
71class QGraphicsSceneEvent;
72class QGraphicsSceneHoverEvent;
73class QGraphicsSceneMouseEvent;
74class QGraphicsSceneWheelEvent;
75class QGraphicsScene;
76class QGraphicsTransform;
77class QGraphicsWidget;
78class QInputMethodEvent;
79class QKeyEvent;
80class QMatrix;
81class QMenu;
82class QPainter;
83class QPen;
84class QPointF;
85class QRectF;
86class QStyleOptionGraphicsItem;
87
88class QGraphicsItemPrivate;
89class Q_GUI_EXPORT QGraphicsItem
90{
91public:
92 enum GraphicsItemFlag {
93 ItemIsMovable = 0x1,
94 ItemIsSelectable = 0x2,
95 ItemIsFocusable = 0x4,
96 ItemClipsToShape = 0x8,
97 ItemClipsChildrenToShape = 0x10,
98 ItemIgnoresTransformations = 0x20,
99 ItemIgnoresParentOpacity = 0x40,
100 ItemDoesntPropagateOpacityToChildren = 0x80,
101 ItemStacksBehindParent = 0x100,
102 ItemUsesExtendedStyleOption = 0x200,
103 ItemHasNoContents = 0x400,
104 ItemSendsGeometryChanges = 0x800,
105 ItemAcceptsInputMethod = 0x1000,
106 ItemNegativeZStacksBehindParent = 0x2000,
107 ItemIsPanel = 0x4000,
108 ItemIsFocusScope = 0x8000, // internal
109 ItemSendsScenePositionChanges = 0x10000
110 // NB! Don't forget to increase the d_ptr->flags bit field by 1 when adding a new flag.
111 };
112 Q_DECLARE_FLAGS(GraphicsItemFlags, GraphicsItemFlag)
113
114 enum GraphicsItemChange {
115 ItemPositionChange,
116 ItemMatrixChange,
117 ItemVisibleChange,
118 ItemEnabledChange,
119 ItemSelectedChange,
120 ItemParentChange,
121 ItemChildAddedChange,
122 ItemChildRemovedChange,
123 ItemTransformChange,
124 ItemPositionHasChanged,
125 ItemTransformHasChanged,
126 ItemSceneChange,
127 ItemVisibleHasChanged,
128 ItemEnabledHasChanged,
129 ItemSelectedHasChanged,
130 ItemParentHasChanged,
131 ItemSceneHasChanged,
132 ItemCursorChange,
133 ItemCursorHasChanged,
134 ItemToolTipChange,
135 ItemToolTipHasChanged,
136 ItemFlagsChange,
137 ItemFlagsHaveChanged,
138 ItemZValueChange,
139 ItemZValueHasChanged,
140 ItemOpacityChange,
141 ItemOpacityHasChanged,
142 ItemScenePositionHasChanged
143 };
144
145 enum CacheMode {
146 NoCache,
147 ItemCoordinateCache,
148 DeviceCoordinateCache
149 };
150
151 enum PanelModality
152 {
153 NonModal,
154 PanelModal,
155 SceneModal
156 };
157
158 QGraphicsItem(QGraphicsItem *parent = 0
159#ifndef Q_QDOC
160 // ### obsolete argument
161 , QGraphicsScene *scene = 0
162#endif
163 );
164 virtual ~QGraphicsItem();
165
166 QGraphicsScene *scene() const;
167
168 QGraphicsItem *parentItem() const;
169 QGraphicsItem *topLevelItem() const;
170 QGraphicsObject *parentObject() const;
171 QGraphicsWidget *parentWidget() const;
172 QGraphicsWidget *topLevelWidget() const;
173 QGraphicsWidget *window() const;
174 QGraphicsItem *panel() const;
175 void setParentItem(QGraphicsItem *parent);
176 QList<QGraphicsItem *> children() const; // ### obsolete
177 QList<QGraphicsItem *> childItems() const;
178 bool isWidget() const;
179 bool isWindow() const;
180 bool isPanel() const;
181
182 QGraphicsObject *toGraphicsObject();
183 const QGraphicsObject *toGraphicsObject() const;
184
185 QGraphicsItemGroup *group() const;
186 void setGroup(QGraphicsItemGroup *group);
187
188 GraphicsItemFlags flags() const;
189 void setFlag(GraphicsItemFlag flag, bool enabled = true);
190 void setFlags(GraphicsItemFlags flags);
191
192 CacheMode cacheMode() const;
193 void setCacheMode(CacheMode mode, const QSize &cacheSize = QSize());
194
195 PanelModality panelModality() const;
196 void setPanelModality(PanelModality panelModality);
197 bool isBlockedByModalPanel(QGraphicsItem **blockingPanel = 0) const;
198
199#ifndef QT_NO_TOOLTIP
200 QString toolTip() const;
201 void setToolTip(const QString &toolTip);
202#endif
203
204#ifndef QT_NO_CURSOR
205 QCursor cursor() const;
206 void setCursor(const QCursor &cursor);
207 bool hasCursor() const;
208 void unsetCursor();
209#endif
210
211 bool isVisible() const;
212 bool isVisibleTo(const QGraphicsItem *parent) const;
213 void setVisible(bool visible);
214 inline void hide() { setVisible(false); }
215 inline void show() { setVisible(true); }
216
217 bool isEnabled() const;
218 void setEnabled(bool enabled);
219
220 bool isSelected() const;
221 void setSelected(bool selected);
222
223 bool acceptDrops() const;
224 void setAcceptDrops(bool on);
225
226 qreal opacity() const;
227 qreal effectiveOpacity() const;
228 void setOpacity(qreal opacity);
229
230#ifndef QT_NO_GRAPHICSEFFECT
231 // Effect
232 QGraphicsEffect *graphicsEffect() const;
233 void setGraphicsEffect(QGraphicsEffect *effect);
234#endif //QT_NO_GRAPHICSEFFECT
235
236 Qt::MouseButtons acceptedMouseButtons() const;
237 void setAcceptedMouseButtons(Qt::MouseButtons buttons);
238
239 bool acceptsHoverEvents() const; // ### obsolete
240 void setAcceptsHoverEvents(bool enabled); // ### obsolete
241 bool acceptHoverEvents() const;
242 void setAcceptHoverEvents(bool enabled);
243 bool acceptTouchEvents() const;
244 void setAcceptTouchEvents(bool enabled);
245
246 bool filtersChildEvents() const;
247 void setFiltersChildEvents(bool enabled);
248
249 bool handlesChildEvents() const;
250 void setHandlesChildEvents(bool enabled);
251
252 bool isActive() const;
253 void setActive(bool active);
254
255 bool hasFocus() const;
256 void setFocus(Qt::FocusReason focusReason = Qt::OtherFocusReason);
257 void clearFocus();
258
259 QGraphicsItem *focusProxy() const;
260 void setFocusProxy(QGraphicsItem *item);
261
262 QGraphicsItem *focusItem() const;
263 QGraphicsItem *focusScopeItem() const;
264
265 void grabMouse();
266 void ungrabMouse();
267 void grabKeyboard();
268 void ungrabKeyboard();
269
270 // Positioning in scene coordinates
271 QPointF pos() const;
272 inline qreal x() const { return pos().x(); }
273 void setX(qreal x);
274 inline qreal y() const { return pos().y(); }
275 void setY(qreal y);
276 QPointF scenePos() const;
277 void setPos(const QPointF &pos);
278 inline void setPos(qreal x, qreal y);
279 inline void moveBy(qreal dx, qreal dy) { setPos(pos().x() + dx, pos().y() + dy); }
280
281 void ensureVisible(const QRectF &rect = QRectF(), int xmargin = 50, int ymargin = 50);
282 inline void ensureVisible(qreal x, qreal y, qreal w, qreal h, int xmargin = 50, int ymargin = 50);
283
284 // Local transformation
285 QMatrix matrix() const;
286 QMatrix sceneMatrix() const;
287 void setMatrix(const QMatrix &matrix, bool combine = false);
288 void resetMatrix();
289 QTransform transform() const;
290 QTransform sceneTransform() const;
291 QTransform deviceTransform(const QTransform &viewportTransform) const;
292 QTransform itemTransform(const QGraphicsItem *other, bool *ok = 0) const;
293 void setTransform(const QTransform &matrix, bool combine = false);
294 void resetTransform();
295
296 void rotate(qreal angle); // ### obsolete
297 void scale(qreal sx, qreal sy); // ### obsolete
298 void shear(qreal sh, qreal sv); // ### obsolete
299 void translate(qreal dx, qreal dy); // ### obsolete
300
301 void setRotation(qreal angle);
302 qreal rotation() const;
303
304 void setScale(qreal scale);
305 qreal scale() const;
306
307 QList<QGraphicsTransform *> transformations() const;
308 void setTransformations(const QList<QGraphicsTransform *> &transformations);
309
310 QPointF transformOriginPoint() const;
311 void setTransformOriginPoint(const QPointF &origin);
312 inline void setTransformOriginPoint(qreal ax, qreal ay)
313 { setTransformOriginPoint(QPointF(ax,ay)); }
314
315 virtual void advance(int phase);
316
317 // Stacking order
318 qreal zValue() const;
319 void setZValue(qreal z);
320 void stackBefore(const QGraphicsItem *sibling);
321
322 // Hit test
323 virtual QRectF boundingRect() const = 0;
324 QRectF childrenBoundingRect() const;
325 QRectF sceneBoundingRect() const;
326 virtual QPainterPath shape() const;
327 bool isClipped() const;
328 QPainterPath clipPath() const;
329 virtual bool contains(const QPointF &point) const;
330 virtual bool collidesWithItem(const QGraphicsItem *other, Qt::ItemSelectionMode mode = Qt::IntersectsItemShape) const;
331 virtual bool collidesWithPath(const QPainterPath &path, Qt::ItemSelectionMode mode = Qt::IntersectsItemShape) const;
332 QList<QGraphicsItem *> collidingItems(Qt::ItemSelectionMode mode = Qt::IntersectsItemShape) const;
333 bool isObscured() const;
334 bool isObscured(const QRectF &rect) const; // ### Qt 5: merge with isObscured(), add QRectF arg to isObscuredBy()
335 inline bool isObscured(qreal x, qreal y, qreal w, qreal h) const;
336 virtual bool isObscuredBy(const QGraphicsItem *item) const;
337 virtual QPainterPath opaqueArea() const;
338
339 QRegion boundingRegion(const QTransform &itemToDeviceTransform) const;
340 qreal boundingRegionGranularity() const;
341 void setBoundingRegionGranularity(qreal granularity);
342
343 // Drawing
344 virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0) = 0;
345 void update(const QRectF &rect = QRectF());
346 inline void update(qreal x, qreal y, qreal width, qreal height);
347 void scroll(qreal dx, qreal dy, const QRectF &rect = QRectF());
348
349 // Coordinate mapping
350 QPointF mapToItem(const QGraphicsItem *item, const QPointF &point) const;
351 QPointF mapToParent(const QPointF &point) const;
352 QPointF mapToScene(const QPointF &point) const;
353 QPolygonF mapToItem(const QGraphicsItem *item, const QRectF &rect) const;
354 QPolygonF mapToParent(const QRectF &rect) const;
355 QPolygonF mapToScene(const QRectF &rect) const;
356 QRectF mapRectToItem(const QGraphicsItem *item, const QRectF &rect) const;
357 QRectF mapRectToParent(const QRectF &rect) const;
358 QRectF mapRectToScene(const QRectF &rect) const;
359 QPolygonF mapToItem(const QGraphicsItem *item, const QPolygonF &polygon) const;
360 QPolygonF mapToParent(const QPolygonF &polygon) const;
361 QPolygonF mapToScene(const QPolygonF &polygon) const;
362 QPainterPath mapToItem(const QGraphicsItem *item, const QPainterPath &path) const;
363 QPainterPath mapToParent(const QPainterPath &path) const;
364 QPainterPath mapToScene(const QPainterPath &path) const;
365 QPointF mapFromItem(const QGraphicsItem *item, const QPointF &point) const;
366 QPointF mapFromParent(const QPointF &point) const;
367 QPointF mapFromScene(const QPointF &point) const;
368 QPolygonF mapFromItem(const QGraphicsItem *item, const QRectF &rect) const;
369 QPolygonF mapFromParent(const QRectF &rect) const;
370 QPolygonF mapFromScene(const QRectF &rect) const;
371 QRectF mapRectFromItem(const QGraphicsItem *item, const QRectF &rect) const;
372 QRectF mapRectFromParent(const QRectF &rect) const;
373 QRectF mapRectFromScene(const QRectF &rect) const;
374 QPolygonF mapFromItem(const QGraphicsItem *item, const QPolygonF &polygon) const;
375 QPolygonF mapFromParent(const QPolygonF &polygon) const;
376 QPolygonF mapFromScene(const QPolygonF &polygon) const;
377 QPainterPath mapFromItem(const QGraphicsItem *item, const QPainterPath &path) const;
378 QPainterPath mapFromParent(const QPainterPath &path) const;
379 QPainterPath mapFromScene(const QPainterPath &path) const;
380
381 inline QPointF mapToItem(const QGraphicsItem *item, qreal x, qreal y) const;
382 inline QPointF mapToParent(qreal x, qreal y) const;
383 inline QPointF mapToScene(qreal x, qreal y) const;
384 inline QPolygonF mapToItem(const QGraphicsItem *item, qreal x, qreal y, qreal w, qreal h) const;
385 inline QPolygonF mapToParent(qreal x, qreal y, qreal w, qreal h) const;
386 inline QPolygonF mapToScene(qreal x, qreal y, qreal w, qreal h) const;
387 inline QRectF mapRectToItem(const QGraphicsItem *item, qreal x, qreal y, qreal w, qreal h) const;
388 inline QRectF mapRectToParent(qreal x, qreal y, qreal w, qreal h) const;
389 inline QRectF mapRectToScene(qreal x, qreal y, qreal w, qreal h) const;
390 inline QPointF mapFromItem(const QGraphicsItem *item, qreal x, qreal y) const;
391 inline QPointF mapFromParent(qreal x, qreal y) const;
392 inline QPointF mapFromScene(qreal x, qreal y) const;
393 inline QPolygonF mapFromItem(const QGraphicsItem *item, qreal x, qreal y, qreal w, qreal h) const;
394 inline QPolygonF mapFromParent(qreal x, qreal y, qreal w, qreal h) const;
395 inline QPolygonF mapFromScene(qreal x, qreal y, qreal w, qreal h) const;
396 inline QRectF mapRectFromItem(const QGraphicsItem *item, qreal x, qreal y, qreal w, qreal h) const;
397 inline QRectF mapRectFromParent(qreal x, qreal y, qreal w, qreal h) const;
398 inline QRectF mapRectFromScene(qreal x, qreal y, qreal w, qreal h) const;
399
400 bool isAncestorOf(const QGraphicsItem *child) const;
401 QGraphicsItem *commonAncestorItem(const QGraphicsItem *other) const;
402 bool isUnderMouse() const;
403
404 // Custom data
405 QVariant data(int key) const;
406 void setData(int key, const QVariant &value);
407
408 Qt::InputMethodHints inputMethodHints() const;
409 void setInputMethodHints(Qt::InputMethodHints hints);
410
411 enum {
412 Type = 1,
413 UserType = 65536
414 };
415 virtual int type() const;
416
417 void installSceneEventFilter(QGraphicsItem *filterItem);
418 void removeSceneEventFilter(QGraphicsItem *filterItem);
419
420protected:
421 virtual bool sceneEventFilter(QGraphicsItem *watched, QEvent *event);
422 virtual bool sceneEvent(QEvent *event);
423 virtual void contextMenuEvent(QGraphicsSceneContextMenuEvent *event);
424 virtual void dragEnterEvent(QGraphicsSceneDragDropEvent *event);
425 virtual void dragLeaveEvent(QGraphicsSceneDragDropEvent *event);
426 virtual void dragMoveEvent(QGraphicsSceneDragDropEvent *event);
427 virtual void dropEvent(QGraphicsSceneDragDropEvent *event);
428 virtual void focusInEvent(QFocusEvent *event);
429 virtual void focusOutEvent(QFocusEvent *event);
430 virtual void hoverEnterEvent(QGraphicsSceneHoverEvent *event);
431 virtual void hoverMoveEvent(QGraphicsSceneHoverEvent *event);
432 virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);
433 virtual void keyPressEvent(QKeyEvent *event);
434 virtual void keyReleaseEvent(QKeyEvent *event);
435 virtual void mousePressEvent(QGraphicsSceneMouseEvent *event);
436 virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
437 virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
438 virtual void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event);
439 virtual void wheelEvent(QGraphicsSceneWheelEvent *event);
440 virtual void inputMethodEvent(QInputMethodEvent *event);
441 virtual QVariant inputMethodQuery(Qt::InputMethodQuery query) const;
442
443 virtual QVariant itemChange(GraphicsItemChange change, const QVariant &value);
444
445 enum Extension {
446 UserExtension = 0x80000000
447 };
448 virtual bool supportsExtension(Extension extension) const;
449 virtual void setExtension(Extension extension, const QVariant &variant);
450 virtual QVariant extension(const QVariant &variant) const;
451
452protected:
453 QGraphicsItem(QGraphicsItemPrivate &dd,
454 QGraphicsItem *parent, QGraphicsScene *scene);
455 QScopedPointer<QGraphicsItemPrivate> d_ptr;
456
457 void addToIndex();
458 void removeFromIndex();
459 void prepareGeometryChange();
460
461private:
462 Q_DISABLE_COPY(QGraphicsItem)
463 Q_DECLARE_PRIVATE(QGraphicsItem)
464 friend class QGraphicsItemGroup;
465 friend class QGraphicsScene;
466 friend class QGraphicsScenePrivate;
467 friend class QGraphicsSceneFindItemBspTreeVisitor;
468 friend class QGraphicsSceneBspTree;
469 friend class QGraphicsView;
470 friend class QGraphicsViewPrivate;
471 friend class QGraphicsObject;
472 friend class QGraphicsWidget;
473 friend class QGraphicsWidgetPrivate;
474 friend class QGraphicsProxyWidgetPrivate;
475 friend class QGraphicsSceneIndex;
476 friend class QGraphicsSceneIndexPrivate;
477 friend class QGraphicsSceneBspTreeIndex;
478 friend class QGraphicsSceneBspTreeIndexPrivate;
479 friend class QGraphicsItemEffectSourcePrivate;
480 friend class QGraphicsTransformPrivate;
481 friend class QGestureManager;
482 friend class ::tst_QGraphicsItem;
483 friend bool qt_closestLeaf(const QGraphicsItem *, const QGraphicsItem *);
484 friend bool qt_closestItemFirst(const QGraphicsItem *, const QGraphicsItem *);
485};
486
487Q_DECLARE_OPERATORS_FOR_FLAGS(QGraphicsItem::GraphicsItemFlags)
488Q_DECLARE_INTERFACE(QGraphicsItem, "com.trolltech.Qt.QGraphicsItem")
489
490inline void QGraphicsItem::setPos(qreal ax, qreal ay)
491{ setPos(QPointF(ax, ay)); }
492inline void QGraphicsItem::ensureVisible(qreal ax, qreal ay, qreal w, qreal h, int xmargin, int ymargin)
493{ ensureVisible(QRectF(ax, ay, w, h), xmargin, ymargin); }
494inline void QGraphicsItem::update(qreal ax, qreal ay, qreal width, qreal height)
495{ update(QRectF(ax, ay, width, height)); }
496inline bool QGraphicsItem::isObscured(qreal ax, qreal ay, qreal w, qreal h) const
497{ return isObscured(QRectF(ax, ay, w, h)); }
498inline QPointF QGraphicsItem::mapToItem(const QGraphicsItem *item, qreal ax, qreal ay) const
499{ return mapToItem(item, QPointF(ax, ay)); }
500inline QPointF QGraphicsItem::mapToParent(qreal ax, qreal ay) const
501{ return mapToParent(QPointF(ax, ay)); }
502inline QPointF QGraphicsItem::mapToScene(qreal ax, qreal ay) const
503{ return mapToScene(QPointF(ax, ay)); }
504inline QPointF QGraphicsItem::mapFromItem(const QGraphicsItem *item, qreal ax, qreal ay) const
505{ return mapFromItem(item, QPointF(ax, ay)); }
506inline QPointF QGraphicsItem::mapFromParent(qreal ax, qreal ay) const
507{ return mapFromParent(QPointF(ax, ay)); }
508inline QPointF QGraphicsItem::mapFromScene(qreal ax, qreal ay) const
509{ return mapFromScene(QPointF(ax, ay)); }
510inline QPolygonF QGraphicsItem::mapToItem(const QGraphicsItem *item, qreal ax, qreal ay, qreal w, qreal h) const
511{ return mapToItem(item, QRectF(ax, ay, w, h)); }
512inline QPolygonF QGraphicsItem::mapToParent(qreal ax, qreal ay, qreal w, qreal h) const
513{ return mapToParent(QRectF(ax, ay, w, h)); }
514inline QPolygonF QGraphicsItem::mapToScene(qreal ax, qreal ay, qreal w, qreal h) const
515{ return mapToScene(QRectF(ax, ay, w, h)); }
516inline QRectF QGraphicsItem::mapRectToItem(const QGraphicsItem *item, qreal ax, qreal ay, qreal w, qreal h) const
517{ return mapRectToItem(item, QRectF(ax, ay, w, h)); }
518inline QRectF QGraphicsItem::mapRectToParent(qreal ax, qreal ay, qreal w, qreal h) const
519{ return mapRectToParent(QRectF(ax, ay, w, h)); }
520inline QRectF QGraphicsItem::mapRectToScene(qreal ax, qreal ay, qreal w, qreal h) const
521{ return mapRectToScene(QRectF(ax, ay, w, h)); }
522inline QPolygonF QGraphicsItem::mapFromItem(const QGraphicsItem *item, qreal ax, qreal ay, qreal w, qreal h) const
523{ return mapFromItem(item, QRectF(ax, ay, w, h)); }
524inline QPolygonF QGraphicsItem::mapFromParent(qreal ax, qreal ay, qreal w, qreal h) const
525{ return mapFromParent(QRectF(ax, ay, w, h)); }
526inline QPolygonF QGraphicsItem::mapFromScene(qreal ax, qreal ay, qreal w, qreal h) const
527{ return mapFromScene(QRectF(ax, ay, w, h)); }
528inline QRectF QGraphicsItem::mapRectFromItem(const QGraphicsItem *item, qreal ax, qreal ay, qreal w, qreal h) const
529{ return mapRectFromItem(item, QRectF(ax, ay, w, h)); }
530inline QRectF QGraphicsItem::mapRectFromParent(qreal ax, qreal ay, qreal w, qreal h) const
531{ return mapRectFromParent(QRectF(ax, ay, w, h)); }
532inline QRectF QGraphicsItem::mapRectFromScene(qreal ax, qreal ay, qreal w, qreal h) const
533{ return mapRectFromScene(QRectF(ax, ay, w, h)); }
534
535
536class Q_GUI_EXPORT QGraphicsObject : public QObject, public QGraphicsItem
537{
538 Q_OBJECT
539 Q_PROPERTY(QGraphicsObject * parent READ parentObject WRITE setParentItem NOTIFY parentChanged DESIGNABLE false)
540 Q_PROPERTY(qreal opacity READ opacity WRITE setOpacity NOTIFY opacityChanged FINAL)
541 Q_PROPERTY(bool enabled READ isEnabled WRITE setEnabled NOTIFY enabledChanged)
542 Q_PROPERTY(bool visible READ isVisible WRITE setVisible NOTIFY visibleChanged FINAL)
543 Q_PROPERTY(QPointF pos READ pos WRITE setPos)
544 Q_PROPERTY(qreal x READ x WRITE setX NOTIFY xChanged)
545 Q_PROPERTY(qreal y READ y WRITE setY NOTIFY yChanged)
546 Q_PROPERTY(qreal z READ zValue WRITE setZValue NOTIFY zChanged)
547 Q_PROPERTY(qreal rotation READ rotation WRITE setRotation NOTIFY rotationChanged)
548 Q_PROPERTY(qreal scale READ scale WRITE setScale NOTIFY scaleChanged)
549 Q_PROPERTY(QPointF transformOriginPoint READ transformOriginPoint WRITE setTransformOriginPoint)
550 Q_INTERFACES(QGraphicsItem)
551public:
552 QGraphicsObject(QGraphicsItem *parent = 0);
553
554 // ### Qt 5: Disambiguate
555#ifdef Q_NO_USING_KEYWORD
556 const QObjectList &children() const { return QObject::children(); }
557#else
558 using QObject::children;
559#endif
560
561 void grabGesture(Qt::GestureType type, Qt::GestureFlags flags = Qt::GestureFlags());
562 void ungrabGesture(Qt::GestureType type);
563
564Q_SIGNALS:
565 void parentChanged();
566 void opacityChanged();
567 void visibleChanged();
568 void enabledChanged();
569 void xChanged();
570 void yChanged();
571 void zChanged();
572 void rotationChanged();
573 void scaleChanged();
574
575protected:
576 QGraphicsObject(QGraphicsItemPrivate &dd, QGraphicsItem *parent, QGraphicsScene *scene);
577private:
578 friend class QGraphicsItem;
579 friend class QGraphicsItemPrivate;
580};
581
582
583class QAbstractGraphicsShapeItemPrivate;
584class Q_GUI_EXPORT QAbstractGraphicsShapeItem : public QGraphicsItem
585{
586public:
587 QAbstractGraphicsShapeItem(QGraphicsItem *parent = 0
588#ifndef Q_QDOC
589 // ### obsolete argument
590 , QGraphicsScene *scene = 0
591#endif
592 );
593 ~QAbstractGraphicsShapeItem();
594
595 QPen pen() const;
596 void setPen(const QPen &pen);
597
598 QBrush brush() const;
599 void setBrush(const QBrush &brush);
600
601 bool isObscuredBy(const QGraphicsItem *item) const;
602 QPainterPath opaqueArea() const;
603
604protected:
605 QAbstractGraphicsShapeItem(QAbstractGraphicsShapeItemPrivate &dd,
606 QGraphicsItem *parent, QGraphicsScene *scene);
607
608private:
609 Q_DISABLE_COPY(QAbstractGraphicsShapeItem)
610 Q_DECLARE_PRIVATE(QAbstractGraphicsShapeItem)
611};
612
613class QGraphicsPathItemPrivate;
614class Q_GUI_EXPORT QGraphicsPathItem : public QAbstractGraphicsShapeItem
615{
616public:
617 QGraphicsPathItem(QGraphicsItem *parent = 0
618#ifndef Q_QDOC
619 // ### obsolete argument
620 , QGraphicsScene *scene = 0
621#endif
622 );
623 QGraphicsPathItem(const QPainterPath &path, QGraphicsItem *parent = 0
624#ifndef Q_QDOC
625 // ### obsolete argument
626 , QGraphicsScene *scene = 0
627#endif
628 );
629 ~QGraphicsPathItem();
630
631 QPainterPath path() const;
632 void setPath(const QPainterPath &path);
633
634 QRectF boundingRect() const;
635 QPainterPath shape() const;
636 bool contains(const QPointF &point) const;
637
638 void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
639
640 bool isObscuredBy(const QGraphicsItem *item) const;
641 QPainterPath opaqueArea() const;
642
643 enum { Type = 2 };
644 int type() const;
645
646protected:
647 bool supportsExtension(Extension extension) const;
648 void setExtension(Extension extension, const QVariant &variant);
649 QVariant extension(const QVariant &variant) const;
650
651private:
652 Q_DISABLE_COPY(QGraphicsPathItem)
653 Q_DECLARE_PRIVATE(QGraphicsPathItem)
654};
655
656class QGraphicsRectItemPrivate;
657class Q_GUI_EXPORT QGraphicsRectItem : public QAbstractGraphicsShapeItem
658{
659public:
660 QGraphicsRectItem(QGraphicsItem *parent = 0
661#ifndef Q_QDOC
662 // ### obsolete argument
663 , QGraphicsScene *scene = 0
664#endif
665 );
666 QGraphicsRectItem(const QRectF &rect, QGraphicsItem *parent = 0
667#ifndef Q_QDOC
668 // ### obsolete argument
669 , QGraphicsScene *scene = 0
670#endif
671 );
672 QGraphicsRectItem(qreal x, qreal y, qreal w, qreal h, QGraphicsItem *parent = 0
673#ifndef Q_QDOC
674 // ### obsolete argument
675 , QGraphicsScene *scene = 0
676#endif
677 );
678 ~QGraphicsRectItem();
679
680 QRectF rect() const;
681 void setRect(const QRectF &rect);
682 inline void setRect(qreal x, qreal y, qreal w, qreal h);
683
684 QRectF boundingRect() const;
685 QPainterPath shape() const;
686 bool contains(const QPointF &point) const;
687
688 void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
689
690 bool isObscuredBy(const QGraphicsItem *item) const;
691 QPainterPath opaqueArea() const;
692
693 enum { Type = 3 };
694 int type() const;
695
696protected:
697 bool supportsExtension(Extension extension) const;
698 void setExtension(Extension extension, const QVariant &variant);
699 QVariant extension(const QVariant &variant) const;
700
701private:
702 Q_DISABLE_COPY(QGraphicsRectItem)
703 Q_DECLARE_PRIVATE(QGraphicsRectItem)
704};
705
706inline void QGraphicsRectItem::setRect(qreal ax, qreal ay, qreal w, qreal h)
707{ setRect(QRectF(ax, ay, w, h)); }
708
709class QGraphicsEllipseItemPrivate;
710class Q_GUI_EXPORT QGraphicsEllipseItem : public QAbstractGraphicsShapeItem
711{
712public:
713 QGraphicsEllipseItem(QGraphicsItem *parent = 0
714#ifndef Q_QDOC
715 // ### obsolete argument
716 , QGraphicsScene *scene = 0
717#endif
718 );
719 QGraphicsEllipseItem(const QRectF &rect, QGraphicsItem *parent = 0
720#ifndef Q_QDOC
721 // ### obsolete argument
722 , QGraphicsScene *scene = 0
723#endif
724 );
725 QGraphicsEllipseItem(qreal x, qreal y, qreal w, qreal h, QGraphicsItem *parent = 0
726#ifndef Q_QDOC
727 // ### obsolete argument
728 , QGraphicsScene *scene = 0
729#endif
730 );
731 ~QGraphicsEllipseItem();
732
733 QRectF rect() const;
734 void setRect(const QRectF &rect);
735 inline void setRect(qreal x, qreal y, qreal w, qreal h);
736
737 int startAngle() const;
738 void setStartAngle(int angle);
739
740 int spanAngle() const;
741 void setSpanAngle(int angle);
742
743 QRectF boundingRect() const;
744 QPainterPath shape() const;
745 bool contains(const QPointF &point) const;
746
747 void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
748
749 bool isObscuredBy(const QGraphicsItem *item) const;
750 QPainterPath opaqueArea() const;
751
752 enum { Type = 4 };
753 int type() const;
754
755protected:
756 bool supportsExtension(Extension extension) const;
757 void setExtension(Extension extension, const QVariant &variant);
758 QVariant extension(const QVariant &variant) const;
759
760private:
761 Q_DISABLE_COPY(QGraphicsEllipseItem)
762 Q_DECLARE_PRIVATE(QGraphicsEllipseItem)
763};
764
765inline void QGraphicsEllipseItem::setRect(qreal ax, qreal ay, qreal w, qreal h)
766{ setRect(QRectF(ax, ay, w, h)); }
767
768class QGraphicsPolygonItemPrivate;
769class Q_GUI_EXPORT QGraphicsPolygonItem : public QAbstractGraphicsShapeItem
770{
771public:
772 QGraphicsPolygonItem(QGraphicsItem *parent = 0
773#ifndef Q_QDOC
774 // ### obsolete argument
775 , QGraphicsScene *scene = 0
776#endif
777 );
778 QGraphicsPolygonItem(const QPolygonF &polygon,
779 QGraphicsItem *parent = 0
780#ifndef Q_QDOC
781 // ### obsolete argument
782 , QGraphicsScene *scene = 0
783#endif
784 );
785 ~QGraphicsPolygonItem();
786
787 QPolygonF polygon() const;
788 void setPolygon(const QPolygonF &polygon);
789
790 Qt::FillRule fillRule() const;
791 void setFillRule(Qt::FillRule rule);
792
793 QRectF boundingRect() const;
794 QPainterPath shape() const;
795 bool contains(const QPointF &point) const;
796
797 void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
798
799 bool isObscuredBy(const QGraphicsItem *item) const;
800 QPainterPath opaqueArea() const;
801
802 enum { Type = 5 };
803 int type() const;
804
805protected:
806 bool supportsExtension(Extension extension) const;
807 void setExtension(Extension extension, const QVariant &variant);
808 QVariant extension(const QVariant &variant) const;
809
810private:
811 Q_DISABLE_COPY(QGraphicsPolygonItem)
812 Q_DECLARE_PRIVATE(QGraphicsPolygonItem)
813};
814
815class QGraphicsLineItemPrivate;
816class Q_GUI_EXPORT QGraphicsLineItem : public QGraphicsItem
817{
818public:
819 QGraphicsLineItem(QGraphicsItem *parent = 0
820#ifndef Q_QDOC
821 // ### obsolete argument
822 , QGraphicsScene *scene = 0
823#endif
824 );
825 QGraphicsLineItem(const QLineF &line, QGraphicsItem *parent = 0
826#ifndef Q_QDOC
827 // ### obsolete argument
828 , QGraphicsScene *scene = 0
829#endif
830 );
831 QGraphicsLineItem(qreal x1, qreal y1, qreal x2, qreal y2, QGraphicsItem *parent = 0
832#ifndef Q_QDOC
833 // ### obsolete argument
834 , QGraphicsScene *scene = 0
835#endif
836 );
837 ~QGraphicsLineItem();
838
839 QPen pen() const;
840 void setPen(const QPen &pen);
841
842 QLineF line() const;
843 void setLine(const QLineF &line);
844 inline void setLine(qreal x1, qreal y1, qreal x2, qreal y2)
845 { setLine(QLineF(x1, y1, x2, y2)); }
846
847 QRectF boundingRect() const;
848 QPainterPath shape() const;
849 bool contains(const QPointF &point) const;
850
851 void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
852
853 bool isObscuredBy(const QGraphicsItem *item) const;
854 QPainterPath opaqueArea() const;
855
856 enum { Type = 6 };
857 int type() const;
858
859protected:
860 bool supportsExtension(Extension extension) const;
861 void setExtension(Extension extension, const QVariant &variant);
862 QVariant extension(const QVariant &variant) const;
863
864private:
865 Q_DISABLE_COPY(QGraphicsLineItem)
866 Q_DECLARE_PRIVATE(QGraphicsLineItem)
867};
868
869class QGraphicsPixmapItemPrivate;
870class Q_GUI_EXPORT QGraphicsPixmapItem : public QGraphicsItem
871{
872public:
873 enum ShapeMode {
874 MaskShape,
875 BoundingRectShape,
876 HeuristicMaskShape
877 };
878
879 QGraphicsPixmapItem(QGraphicsItem *parent = 0
880#ifndef Q_QDOC
881 // ### obsolete argument
882 , QGraphicsScene *scene = 0
883#endif
884 );
885 QGraphicsPixmapItem(const QPixmap &pixmap, QGraphicsItem *parent = 0
886#ifndef Q_QDOC
887 // ### obsolete argument
888 , QGraphicsScene *scene = 0
889#endif
890 );
891 ~QGraphicsPixmapItem();
892
893 QPixmap pixmap() const;
894 void setPixmap(const QPixmap &pixmap);
895
896 Qt::TransformationMode transformationMode() const;
897 void setTransformationMode(Qt::TransformationMode mode);
898
899 QPointF offset() const;
900 void setOffset(const QPointF &offset);
901 inline void setOffset(qreal x, qreal y);
902
903 QRectF boundingRect() const;
904 QPainterPath shape() const;
905 bool contains(const QPointF &point) const;
906
907 void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
908
909 bool isObscuredBy(const QGraphicsItem *item) const;
910 QPainterPath opaqueArea() const;
911
912 enum { Type = 7 };
913 int type() const;
914
915 ShapeMode shapeMode() const;
916 void setShapeMode(ShapeMode mode);
917
918protected:
919 bool supportsExtension(Extension extension) const;
920 void setExtension(Extension extension, const QVariant &variant);
921 QVariant extension(const QVariant &variant) const;
922
923private:
924 Q_DISABLE_COPY(QGraphicsPixmapItem)
925 Q_DECLARE_PRIVATE(QGraphicsPixmapItem)
926};
927
928inline void QGraphicsPixmapItem::setOffset(qreal ax, qreal ay)
929{ setOffset(QPointF(ax, ay)); }
930
931class QGraphicsTextItemPrivate;
932class QTextDocument;
933class QTextCursor;
934class Q_GUI_EXPORT QGraphicsTextItem : public QGraphicsObject
935{
936 Q_OBJECT
937 QDOC_PROPERTY(bool openExternalLinks READ openExternalLinks WRITE setOpenExternalLinks)
938 QDOC_PROPERTY(QTextCursor textCursor READ textCursor WRITE setTextCursor)
939
940public:
941 QGraphicsTextItem(QGraphicsItem *parent = 0
942#ifndef Q_QDOC
943 // ### obsolete argument
944 , QGraphicsScene *scene = 0
945#endif
946 );
947 QGraphicsTextItem(const QString &text, QGraphicsItem *parent = 0
948#ifndef Q_QDOC
949 // ### obsolete argument
950 , QGraphicsScene *scene = 0
951#endif
952 );
953 ~QGraphicsTextItem();
954
955 QString toHtml() const;
956 void setHtml(const QString &html);
957
958 QString toPlainText() const;
959 void setPlainText(const QString &text);
960
961 QFont font() const;
962 void setFont(const QFont &font);
963
964 void setDefaultTextColor(const QColor &c);
965 QColor defaultTextColor() const;
966
967 QRectF boundingRect() const;
968 QPainterPath shape() const;
969 bool contains(const QPointF &point) const;
970
971 void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
972
973 bool isObscuredBy(const QGraphicsItem *item) const;
974 QPainterPath opaqueArea() const;
975
976 enum { Type = 8 };
977 int type() const;
978
979 void setTextWidth(qreal width);
980 qreal textWidth() const;
981
982 void adjustSize();
983
984 void setDocument(QTextDocument *document);
985 QTextDocument *document() const;
986
987 void setTextInteractionFlags(Qt::TextInteractionFlags flags);
988 Qt::TextInteractionFlags textInteractionFlags() const;
989
990 void setTabChangesFocus(bool b);
991 bool tabChangesFocus() const;
992
993 void setOpenExternalLinks(bool open);
994 bool openExternalLinks() const;
995
996 void setTextCursor(const QTextCursor &cursor);
997 QTextCursor textCursor() const;
998
999Q_SIGNALS:
1000 void linkActivated(const QString &);
1001 void linkHovered(const QString &);
1002
1003protected:
1004 bool sceneEvent(QEvent *event);
1005 void mousePressEvent(QGraphicsSceneMouseEvent *event);
1006 void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
1007 void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
1008 void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event);
1009 void contextMenuEvent(QGraphicsSceneContextMenuEvent *event);
1010 void keyPressEvent(QKeyEvent *event);
1011 void keyReleaseEvent(QKeyEvent *event);
1012 void focusInEvent(QFocusEvent *event);
1013 void focusOutEvent(QFocusEvent *event);
1014 void dragEnterEvent(QGraphicsSceneDragDropEvent *event);
1015 void dragLeaveEvent(QGraphicsSceneDragDropEvent *event);
1016 void dragMoveEvent(QGraphicsSceneDragDropEvent *event);
1017 void dropEvent(QGraphicsSceneDragDropEvent *event);
1018 void inputMethodEvent(QInputMethodEvent *event);
1019 void hoverEnterEvent(QGraphicsSceneHoverEvent *event);
1020 void hoverMoveEvent(QGraphicsSceneHoverEvent *event);
1021 void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);
1022
1023 QVariant inputMethodQuery(Qt::InputMethodQuery query) const;
1024
1025 bool supportsExtension(Extension extension) const;
1026 void setExtension(Extension extension, const QVariant &variant);
1027 QVariant extension(const QVariant &variant) const;
1028
1029private:
1030 Q_DISABLE_COPY(QGraphicsTextItem)
1031 Q_PRIVATE_SLOT(dd, void _q_updateBoundingRect(const QSizeF &))
1032 Q_PRIVATE_SLOT(dd, void _q_update(QRectF))
1033 Q_PRIVATE_SLOT(dd, void _q_ensureVisible(QRectF))
1034 QGraphicsTextItemPrivate *dd;
1035 friend class QGraphicsTextItemPrivate;
1036};
1037
1038class QGraphicsSimpleTextItemPrivate;
1039class Q_GUI_EXPORT QGraphicsSimpleTextItem : public QAbstractGraphicsShapeItem
1040{
1041public:
1042 QGraphicsSimpleTextItem(QGraphicsItem *parent = 0
1043#ifndef Q_QDOC
1044 // ### obsolete argument
1045 , QGraphicsScene *scene = 0
1046#endif
1047 );
1048 QGraphicsSimpleTextItem(const QString &text, QGraphicsItem *parent = 0
1049#ifndef Q_QDOC
1050 // ### obsolete argument
1051 , QGraphicsScene *scene = 0
1052#endif
1053 );
1054 ~QGraphicsSimpleTextItem();
1055
1056 void setText(const QString &text);
1057 QString text() const;
1058
1059 void setFont(const QFont &font);
1060 QFont font() const;
1061
1062 QRectF boundingRect() const;
1063 QPainterPath shape() const;
1064 bool contains(const QPointF &point) const;
1065
1066 void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
1067
1068 bool isObscuredBy(const QGraphicsItem *item) const;
1069 QPainterPath opaqueArea() const;
1070
1071 enum { Type = 9 };
1072 int type() const;
1073
1074protected:
1075 bool supportsExtension(Extension extension) const;
1076 void setExtension(Extension extension, const QVariant &variant);
1077 QVariant extension(const QVariant &variant) const;
1078
1079private:
1080 Q_DISABLE_COPY(QGraphicsSimpleTextItem)
1081 Q_DECLARE_PRIVATE(QGraphicsSimpleTextItem)
1082};
1083
1084class QGraphicsItemGroupPrivate;
1085class Q_GUI_EXPORT QGraphicsItemGroup : public QGraphicsItem
1086{
1087public:
1088 QGraphicsItemGroup(QGraphicsItem *parent = 0
1089#ifndef Q_QDOC
1090 // ### obsolete argument
1091 , QGraphicsScene *scene = 0
1092#endif
1093 );
1094 ~QGraphicsItemGroup();
1095
1096 void addToGroup(QGraphicsItem *item);
1097 void removeFromGroup(QGraphicsItem *item);
1098
1099 QRectF boundingRect() const;
1100 void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
1101
1102 bool isObscuredBy(const QGraphicsItem *item) const;
1103 QPainterPath opaqueArea() const;
1104
1105 enum { Type = 10 };
1106 int type() const;
1107
1108private:
1109 Q_DISABLE_COPY(QGraphicsItemGroup)
1110 Q_DECLARE_PRIVATE(QGraphicsItemGroup)
1111};
1112
1113template <class T> inline T qgraphicsitem_cast(QGraphicsItem *item)
1114{
1115 return int(static_cast<T>(0)->Type) == int(QGraphicsItem::Type)
1116 || (item && int(static_cast<T>(0)->Type) == item->type()) ? static_cast<T>(item) : 0;
1117}
1118
1119template <class T> inline T qgraphicsitem_cast(const QGraphicsItem *item)
1120{
1121 return int(static_cast<T>(0)->Type) == int(QGraphicsItem::Type)
1122 || (item && int(static_cast<T>(0)->Type) == item->type()) ? static_cast<T>(item) : 0;
1123}
1124
1125#ifndef QT_NO_DEBUG_STREAM
1126Q_GUI_EXPORT QDebug operator<<(QDebug debug, QGraphicsItem *item);
1127Q_GUI_EXPORT QDebug operator<<(QDebug debug, QGraphicsObject *item);
1128Q_GUI_EXPORT QDebug operator<<(QDebug debug, QGraphicsItem::GraphicsItemChange change);
1129Q_GUI_EXPORT QDebug operator<<(QDebug debug, QGraphicsItem::GraphicsItemFlag flag);
1130Q_GUI_EXPORT QDebug operator<<(QDebug debug, QGraphicsItem::GraphicsItemFlags flags);
1131#endif
1132
1133QT_END_NAMESPACE
1134
1135Q_DECLARE_METATYPE(QGraphicsItem *)
1136Q_DECLARE_METATYPE(QGraphicsScene *)
1137
1138QT_BEGIN_NAMESPACE
1139
1140#endif // QT_NO_GRAPHICSVIEW
1141
1142QT_END_NAMESPACE
1143
1144QT_END_HEADER
1145
1146#endif // QGRAPHICSITEM_H
Note: See TracBrowser for help on using the repository browser.