Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:09:34

0001 // Copyright (C) 2016 The Qt Company Ltd.
0002 // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
0003 
0004 #ifndef QGRAPHICSITEM_H
0005 #define QGRAPHICSITEM_H
0006 
0007 #include <QtWidgets/qtwidgetsglobal.h>
0008 #include <QtCore/qobject.h>
0009 #include <QtCore/qvariant.h>
0010 #include <QtCore/qrect.h>
0011 #include <QtCore/qscopedpointer.h>
0012 #include <QtGui/qpainterpath.h>
0013 #include <QtGui/qpixmap.h>
0014 
0015 class tst_QGraphicsItem;
0016 
0017 QT_REQUIRE_CONFIG(graphicsview);
0018 
0019 QT_BEGIN_NAMESPACE
0020 
0021 class QBrush;
0022 class QCursor;
0023 class QFocusEvent;
0024 class QGraphicsEffect;
0025 class QGraphicsItemGroup;
0026 class QGraphicsObject;
0027 class QGraphicsSceneContextMenuEvent;
0028 class QGraphicsSceneDragDropEvent;
0029 class QGraphicsSceneEvent;
0030 class QGraphicsSceneHoverEvent;
0031 class QGraphicsSceneMouseEvent;
0032 class QGraphicsSceneWheelEvent;
0033 class QGraphicsScene;
0034 class QGraphicsTransform;
0035 class QGraphicsWidget;
0036 class QInputMethodEvent;
0037 class QKeyEvent;
0038 class QMenu;
0039 class QPainter;
0040 class QPen;
0041 class QPointF;
0042 class QRectF;
0043 class QStyleOptionGraphicsItem;
0044 
0045 class QGraphicsItemPrivate;
0046 class Q_WIDGETS_EXPORT QGraphicsItem
0047 {
0048 public:
0049     enum GraphicsItemFlag {
0050         ItemIsMovable = 0x1,
0051         ItemIsSelectable = 0x2,
0052         ItemIsFocusable = 0x4,
0053         ItemClipsToShape = 0x8,
0054         ItemClipsChildrenToShape = 0x10,
0055         ItemIgnoresTransformations = 0x20,
0056         ItemIgnoresParentOpacity = 0x40,
0057         ItemDoesntPropagateOpacityToChildren = 0x80,
0058         ItemStacksBehindParent = 0x100,
0059         ItemUsesExtendedStyleOption = 0x200,
0060         ItemHasNoContents = 0x400,
0061         ItemSendsGeometryChanges = 0x800,
0062         ItemAcceptsInputMethod = 0x1000,
0063         ItemNegativeZStacksBehindParent = 0x2000,
0064         ItemIsPanel = 0x4000,
0065         ItemIsFocusScope = 0x8000, // internal
0066         ItemSendsScenePositionChanges = 0x10000,
0067         ItemStopsClickFocusPropagation = 0x20000,
0068         ItemStopsFocusHandling = 0x40000,
0069         ItemContainsChildrenInShape = 0x80000
0070         // NB! Don't forget to increase the d_ptr->flags bit field by 1 when adding a new flag.
0071     };
0072     Q_DECLARE_FLAGS(GraphicsItemFlags, GraphicsItemFlag)
0073 
0074     enum GraphicsItemChange {
0075         ItemPositionChange,
0076         ItemVisibleChange = 2,
0077         ItemEnabledChange,
0078         ItemSelectedChange,
0079         ItemParentChange,
0080         ItemChildAddedChange,
0081         ItemChildRemovedChange,
0082         ItemTransformChange,
0083         ItemPositionHasChanged,
0084         ItemTransformHasChanged,
0085         ItemSceneChange,
0086         ItemVisibleHasChanged,
0087         ItemEnabledHasChanged,
0088         ItemSelectedHasChanged,
0089         ItemParentHasChanged,
0090         ItemSceneHasChanged,
0091         ItemCursorChange,
0092         ItemCursorHasChanged,
0093         ItemToolTipChange,
0094         ItemToolTipHasChanged,
0095         ItemFlagsChange,
0096         ItemFlagsHaveChanged,
0097         ItemZValueChange,
0098         ItemZValueHasChanged,
0099         ItemOpacityChange,
0100         ItemOpacityHasChanged,
0101         ItemScenePositionHasChanged,
0102         ItemRotationChange,
0103         ItemRotationHasChanged,
0104         ItemScaleChange,
0105         ItemScaleHasChanged,
0106         ItemTransformOriginPointChange,
0107         ItemTransformOriginPointHasChanged
0108     };
0109 
0110     enum CacheMode {
0111         NoCache,
0112         ItemCoordinateCache,
0113         DeviceCoordinateCache
0114     };
0115 
0116     enum PanelModality
0117     {
0118         NonModal,
0119         PanelModal,
0120         SceneModal
0121     };
0122 
0123     explicit QGraphicsItem(QGraphicsItem *parent = nullptr);
0124     virtual ~QGraphicsItem();
0125 
0126     QGraphicsScene *scene() const;
0127 
0128     QGraphicsItem *parentItem() const;
0129     QGraphicsItem *topLevelItem() const;
0130     QGraphicsObject *parentObject() const;
0131     QGraphicsWidget *parentWidget() const;
0132     QGraphicsWidget *topLevelWidget() const;
0133     QGraphicsWidget *window() const;
0134     QGraphicsItem *panel() const;
0135     void setParentItem(QGraphicsItem *parent);
0136     QList<QGraphicsItem *> childItems() const;
0137     bool isWidget() const;
0138     bool isWindow() const;
0139     bool isPanel() const;
0140 
0141     QGraphicsObject *toGraphicsObject();
0142     const QGraphicsObject *toGraphicsObject() const;
0143 
0144     QGraphicsItemGroup *group() const;
0145     void setGroup(QGraphicsItemGroup *group);
0146 
0147     GraphicsItemFlags flags() const;
0148     void setFlag(GraphicsItemFlag flag, bool enabled = true);
0149     void setFlags(GraphicsItemFlags flags);
0150 
0151     CacheMode cacheMode() const;
0152     void setCacheMode(CacheMode mode, const QSize &cacheSize = QSize());
0153 
0154     PanelModality panelModality() const;
0155     void setPanelModality(PanelModality panelModality);
0156     bool isBlockedByModalPanel(QGraphicsItem **blockingPanel = nullptr) const;
0157 
0158 #if QT_CONFIG(tooltip)
0159     QString toolTip() const;
0160     void setToolTip(const QString &toolTip);
0161 #endif
0162 
0163 #ifndef QT_NO_CURSOR
0164     QCursor cursor() const;
0165     void setCursor(const QCursor &cursor);
0166     bool hasCursor() const;
0167     void unsetCursor();
0168 #endif
0169 
0170     bool isVisible() const;
0171     bool isVisibleTo(const QGraphicsItem *parent) const;
0172     void setVisible(bool visible);
0173     inline void hide() { setVisible(false); }
0174     inline void show() { setVisible(true); }
0175 
0176     bool isEnabled() const;
0177     void setEnabled(bool enabled);
0178 
0179     bool isSelected() const;
0180     void setSelected(bool selected);
0181 
0182     bool acceptDrops() const;
0183     void setAcceptDrops(bool on);
0184 
0185     qreal opacity() const;
0186     qreal effectiveOpacity() const;
0187     void setOpacity(qreal opacity);
0188 
0189 #if QT_CONFIG(graphicseffect)
0190     // Effect
0191     QGraphicsEffect *graphicsEffect() const;
0192     void setGraphicsEffect(QGraphicsEffect *effect);
0193 #endif // QT_CONFIG(graphicseffect)
0194 
0195     Qt::MouseButtons acceptedMouseButtons() const;
0196     void setAcceptedMouseButtons(Qt::MouseButtons buttons);
0197     bool acceptHoverEvents() const;
0198     void setAcceptHoverEvents(bool enabled);
0199     bool acceptTouchEvents() const;
0200     void setAcceptTouchEvents(bool enabled);
0201 
0202     bool filtersChildEvents() const;
0203     void setFiltersChildEvents(bool enabled);
0204 
0205     bool handlesChildEvents() const;
0206     void setHandlesChildEvents(bool enabled);
0207 
0208     bool isActive() const;
0209     void setActive(bool active);
0210 
0211     bool hasFocus() const;
0212     void setFocus(Qt::FocusReason focusReason = Qt::OtherFocusReason);
0213     void clearFocus();
0214 
0215     QGraphicsItem *focusProxy() const;
0216     void setFocusProxy(QGraphicsItem *item);
0217 
0218     QGraphicsItem *focusItem() const;
0219     QGraphicsItem *focusScopeItem() const;
0220 
0221     void grabMouse();
0222     void ungrabMouse();
0223     void grabKeyboard();
0224     void ungrabKeyboard();
0225 
0226     // Positioning in scene coordinates
0227     QPointF pos() const;
0228     inline qreal x() const { return pos().x(); }
0229     void setX(qreal x);
0230     inline qreal y() const { return pos().y(); }
0231     void setY(qreal y);
0232     QPointF scenePos() const;
0233     void setPos(const QPointF &pos);
0234     inline void setPos(qreal x, qreal y);
0235     inline void moveBy(qreal dx, qreal dy) { setPos(pos().x() + dx, pos().y() + dy); }
0236 
0237     void ensureVisible(const QRectF &rect = QRectF(), int xmargin = 50, int ymargin = 50);
0238     inline void ensureVisible(qreal x, qreal y, qreal w, qreal h, int xmargin = 50, int ymargin = 50);
0239 
0240     // Local transformation
0241     QTransform transform() const;
0242     QTransform sceneTransform() const;
0243     QTransform deviceTransform(const QTransform &viewportTransform) const;
0244     QTransform itemTransform(const QGraphicsItem *other, bool *ok = nullptr) const;
0245     void setTransform(const QTransform &matrix, bool combine = false);
0246     void resetTransform();
0247     void setRotation(qreal angle);
0248     qreal rotation() const;
0249 
0250     void setScale(qreal scale);
0251     qreal scale() const;
0252 
0253     QList<QGraphicsTransform *> transformations() const;
0254     void setTransformations(const QList<QGraphicsTransform *> &transformations);
0255 
0256     QPointF transformOriginPoint() const;
0257     void setTransformOriginPoint(const QPointF &origin);
0258     inline void setTransformOriginPoint(qreal ax, qreal ay)
0259     { setTransformOriginPoint(QPointF(ax,ay)); }
0260 
0261     virtual void advance(int phase);
0262 
0263     // Stacking order
0264     qreal zValue() const;
0265     void setZValue(qreal z);
0266     void stackBefore(const QGraphicsItem *sibling);
0267 
0268     // Hit test
0269     virtual QRectF boundingRect() const = 0;
0270     QRectF childrenBoundingRect() const;
0271     QRectF sceneBoundingRect() const;
0272     virtual QPainterPath shape() const;
0273     bool isClipped() const;
0274     QPainterPath clipPath() const;
0275     virtual bool contains(const QPointF &point) const;
0276     virtual bool collidesWithItem(const QGraphicsItem *other, Qt::ItemSelectionMode mode = Qt::IntersectsItemShape) const;
0277     virtual bool collidesWithPath(const QPainterPath &path, Qt::ItemSelectionMode mode = Qt::IntersectsItemShape) const;
0278     QList<QGraphicsItem *> collidingItems(Qt::ItemSelectionMode mode = Qt::IntersectsItemShape) const;
0279     bool isObscured(const QRectF &rect = QRectF()) const;
0280     inline bool isObscured(qreal x, qreal y, qreal w, qreal h) const;
0281     virtual bool isObscuredBy(const QGraphicsItem *item) const;
0282     virtual QPainterPath opaqueArea() const;
0283 
0284     QRegion boundingRegion(const QTransform &itemToDeviceTransform) const;
0285     qreal boundingRegionGranularity() const;
0286     void setBoundingRegionGranularity(qreal granularity);
0287 
0288     // Drawing
0289     virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = nullptr) = 0;
0290     void update(const QRectF &rect = QRectF());
0291     inline void update(qreal x, qreal y, qreal width, qreal height);
0292     void scroll(qreal dx, qreal dy, const QRectF &rect = QRectF());
0293 
0294     // Coordinate mapping
0295     QPointF mapToItem(const QGraphicsItem *item, const QPointF &point) const;
0296     QPointF mapToParent(const QPointF &point) const;
0297     QPointF mapToScene(const QPointF &point) const;
0298     QPolygonF mapToItem(const QGraphicsItem *item, const QRectF &rect) const;
0299     QPolygonF mapToParent(const QRectF &rect) const;
0300     QPolygonF mapToScene(const QRectF &rect) const;
0301     QRectF mapRectToItem(const QGraphicsItem *item, const QRectF &rect) const;
0302     QRectF mapRectToParent(const QRectF &rect) const;
0303     QRectF mapRectToScene(const QRectF &rect) const;
0304     QPolygonF mapToItem(const QGraphicsItem *item, const QPolygonF &polygon) const;
0305     QPolygonF mapToParent(const QPolygonF &polygon) const;
0306     QPolygonF mapToScene(const QPolygonF &polygon) const;
0307     QPainterPath mapToItem(const QGraphicsItem *item, const QPainterPath &path) const;
0308     QPainterPath mapToParent(const QPainterPath &path) const;
0309     QPainterPath mapToScene(const QPainterPath &path) const;
0310     QPointF mapFromItem(const QGraphicsItem *item, const QPointF &point) const;
0311     QPointF mapFromParent(const QPointF &point) const;
0312     QPointF mapFromScene(const QPointF &point) const;
0313     QPolygonF mapFromItem(const QGraphicsItem *item, const QRectF &rect) const;
0314     QPolygonF mapFromParent(const QRectF &rect) const;
0315     QPolygonF mapFromScene(const QRectF &rect) const;
0316     QRectF mapRectFromItem(const QGraphicsItem *item, const QRectF &rect) const;
0317     QRectF mapRectFromParent(const QRectF &rect) const;
0318     QRectF mapRectFromScene(const QRectF &rect) const;
0319     QPolygonF mapFromItem(const QGraphicsItem *item, const QPolygonF &polygon) const;
0320     QPolygonF mapFromParent(const QPolygonF &polygon) const;
0321     QPolygonF mapFromScene(const QPolygonF &polygon) const;
0322     QPainterPath mapFromItem(const QGraphicsItem *item, const QPainterPath &path) const;
0323     QPainterPath mapFromParent(const QPainterPath &path) const;
0324     QPainterPath mapFromScene(const QPainterPath &path) const;
0325 
0326     inline QPointF mapToItem(const QGraphicsItem *item, qreal x, qreal y) const;
0327     inline QPointF mapToParent(qreal x, qreal y) const;
0328     inline QPointF mapToScene(qreal x, qreal y) const;
0329     inline QPolygonF mapToItem(const QGraphicsItem *item, qreal x, qreal y, qreal w, qreal h) const;
0330     inline QPolygonF mapToParent(qreal x, qreal y, qreal w, qreal h) const;
0331     inline QPolygonF mapToScene(qreal x, qreal y, qreal w, qreal h) const;
0332     inline QRectF mapRectToItem(const QGraphicsItem *item, qreal x, qreal y, qreal w, qreal h) const;
0333     inline QRectF mapRectToParent(qreal x, qreal y, qreal w, qreal h) const;
0334     inline QRectF mapRectToScene(qreal x, qreal y, qreal w, qreal h) const;
0335     inline QPointF mapFromItem(const QGraphicsItem *item, qreal x, qreal y) const;
0336     inline QPointF mapFromParent(qreal x, qreal y) const;
0337     inline QPointF mapFromScene(qreal x, qreal y) const;
0338     inline QPolygonF mapFromItem(const QGraphicsItem *item, qreal x, qreal y, qreal w, qreal h) const;
0339     inline QPolygonF mapFromParent(qreal x, qreal y, qreal w, qreal h) const;
0340     inline QPolygonF mapFromScene(qreal x, qreal y, qreal w, qreal h) const;
0341     inline QRectF mapRectFromItem(const QGraphicsItem *item, qreal x, qreal y, qreal w, qreal h) const;
0342     inline QRectF mapRectFromParent(qreal x, qreal y, qreal w, qreal h) const;
0343     inline QRectF mapRectFromScene(qreal x, qreal y, qreal w, qreal h) const;
0344 
0345     bool isAncestorOf(const QGraphicsItem *child) const;
0346     QGraphicsItem *commonAncestorItem(const QGraphicsItem *other) const;
0347     bool isUnderMouse() const;
0348 
0349     // Custom data
0350     QVariant data(int key) const;
0351     void setData(int key, const QVariant &value);
0352 
0353     Qt::InputMethodHints inputMethodHints() const;
0354     void setInputMethodHints(Qt::InputMethodHints hints);
0355 
0356     enum {
0357         Type = 1,
0358         UserType = 65536
0359     };
0360     virtual int type() const;
0361 
0362     void installSceneEventFilter(QGraphicsItem *filterItem);
0363     void removeSceneEventFilter(QGraphicsItem *filterItem);
0364 
0365 protected:
0366     void updateMicroFocus();
0367     virtual bool sceneEventFilter(QGraphicsItem *watched, QEvent *event);
0368     virtual bool sceneEvent(QEvent *event);
0369     virtual void contextMenuEvent(QGraphicsSceneContextMenuEvent *event);
0370     virtual void dragEnterEvent(QGraphicsSceneDragDropEvent *event);
0371     virtual void dragLeaveEvent(QGraphicsSceneDragDropEvent *event);
0372     virtual void dragMoveEvent(QGraphicsSceneDragDropEvent *event);
0373     virtual void dropEvent(QGraphicsSceneDragDropEvent *event);
0374     virtual void focusInEvent(QFocusEvent *event);
0375     virtual void focusOutEvent(QFocusEvent *event);
0376     virtual void hoverEnterEvent(QGraphicsSceneHoverEvent *event);
0377     virtual void hoverMoveEvent(QGraphicsSceneHoverEvent *event);
0378     virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);
0379     virtual void keyPressEvent(QKeyEvent *event);
0380     virtual void keyReleaseEvent(QKeyEvent *event);
0381     virtual void mousePressEvent(QGraphicsSceneMouseEvent *event);
0382     virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
0383     virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
0384     virtual void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event);
0385     virtual void wheelEvent(QGraphicsSceneWheelEvent *event);
0386     virtual void inputMethodEvent(QInputMethodEvent *event);
0387     virtual QVariant inputMethodQuery(Qt::InputMethodQuery query) const;
0388 
0389     virtual QVariant itemChange(GraphicsItemChange change, const QVariant &value);
0390 
0391     enum Extension {
0392         UserExtension = 0x80000000
0393     };
0394     virtual bool supportsExtension(Extension extension) const;
0395     virtual void setExtension(Extension extension, const QVariant &variant);
0396     virtual QVariant extension(const QVariant &variant) const;
0397 
0398 protected:
0399     QGraphicsItem(QGraphicsItemPrivate &dd, QGraphicsItem *parent);
0400     QScopedPointer<QGraphicsItemPrivate> d_ptr;
0401 
0402     void addToIndex();
0403     void removeFromIndex();
0404     void prepareGeometryChange();
0405 
0406 private:
0407     Q_DISABLE_COPY(QGraphicsItem)
0408     Q_DECLARE_PRIVATE(QGraphicsItem)
0409     friend class QGraphicsItemGroup;
0410     friend class QGraphicsScene;
0411     friend class QGraphicsScenePrivate;
0412     friend class QGraphicsSceneFindItemBspTreeVisitor;
0413     friend class QGraphicsSceneBspTree;
0414     friend class QGraphicsView;
0415     friend class QGraphicsViewPrivate;
0416     friend class QGraphicsObject;
0417     friend class QGraphicsWidget;
0418     friend class QGraphicsWidgetPrivate;
0419     friend class QGraphicsProxyWidgetPrivate;
0420     friend class QGraphicsSceneIndex;
0421     friend class QGraphicsSceneIndexPrivate;
0422     friend class QGraphicsSceneBspTreeIndex;
0423     friend class QGraphicsSceneBspTreeIndexPrivate;
0424     friend class QGraphicsItemEffectSourcePrivate;
0425     friend class QGraphicsTransformPrivate;
0426 #ifndef QT_NO_GESTURES
0427     friend class QGestureManager;
0428 #endif
0429     friend class ::tst_QGraphicsItem;
0430     friend bool qt_closestLeaf(const QGraphicsItem *, const QGraphicsItem *);
0431     friend bool qt_closestItemFirst(const QGraphicsItem *, const QGraphicsItem *);
0432 };
0433 
0434 Q_DECLARE_OPERATORS_FOR_FLAGS(QGraphicsItem::GraphicsItemFlags)
0435 #ifndef Q_QDOC
0436 Q_DECLARE_INTERFACE(QGraphicsItem, "org.qt-project.Qt.QGraphicsItem")
0437 #endif
0438 
0439 inline void QGraphicsItem::setPos(qreal ax, qreal ay)
0440 { setPos(QPointF(ax, ay)); }
0441 inline void QGraphicsItem::ensureVisible(qreal ax, qreal ay, qreal w, qreal h, int xmargin, int ymargin)
0442 { ensureVisible(QRectF(ax, ay, w, h), xmargin, ymargin); }
0443 inline void QGraphicsItem::update(qreal ax, qreal ay, qreal width, qreal height)
0444 { update(QRectF(ax, ay, width, height)); }
0445 inline bool QGraphicsItem::isObscured(qreal ax, qreal ay, qreal w, qreal h) const
0446 { return isObscured(QRectF(ax, ay, w, h)); }
0447 inline QPointF QGraphicsItem::mapToItem(const QGraphicsItem *item, qreal ax, qreal ay) const
0448 { return mapToItem(item, QPointF(ax, ay)); }
0449 inline QPointF QGraphicsItem::mapToParent(qreal ax, qreal ay) const
0450 { return mapToParent(QPointF(ax, ay)); }
0451 inline QPointF QGraphicsItem::mapToScene(qreal ax, qreal ay) const
0452 { return mapToScene(QPointF(ax, ay));  }
0453 inline QPointF QGraphicsItem::mapFromItem(const QGraphicsItem *item, qreal ax, qreal ay) const
0454 { return mapFromItem(item, QPointF(ax, ay)); }
0455 inline QPointF QGraphicsItem::mapFromParent(qreal ax, qreal ay) const
0456 { return mapFromParent(QPointF(ax, ay));  }
0457 inline QPointF QGraphicsItem::mapFromScene(qreal ax, qreal ay) const
0458 { return mapFromScene(QPointF(ax, ay));  }
0459 inline QPolygonF QGraphicsItem::mapToItem(const QGraphicsItem *item, qreal ax, qreal ay, qreal w, qreal h) const
0460 { return mapToItem(item, QRectF(ax, ay, w, h)); }
0461 inline QPolygonF QGraphicsItem::mapToParent(qreal ax, qreal ay, qreal w, qreal h) const
0462 { return mapToParent(QRectF(ax, ay, w, h)); }
0463 inline QPolygonF QGraphicsItem::mapToScene(qreal ax, qreal ay, qreal w, qreal h) const
0464 { return mapToScene(QRectF(ax, ay, w, h)); }
0465 inline QRectF QGraphicsItem::mapRectToItem(const QGraphicsItem *item, qreal ax, qreal ay, qreal w, qreal h) const
0466 { return mapRectToItem(item, QRectF(ax, ay, w, h)); }
0467 inline QRectF QGraphicsItem::mapRectToParent(qreal ax, qreal ay, qreal w, qreal h) const
0468 { return mapRectToParent(QRectF(ax, ay, w, h)); }
0469 inline QRectF QGraphicsItem::mapRectToScene(qreal ax, qreal ay, qreal w, qreal h) const
0470 { return mapRectToScene(QRectF(ax, ay, w, h)); }
0471 inline QPolygonF QGraphicsItem::mapFromItem(const QGraphicsItem *item, qreal ax, qreal ay, qreal w, qreal h) const
0472 { return mapFromItem(item, QRectF(ax, ay, w, h)); }
0473 inline QPolygonF QGraphicsItem::mapFromParent(qreal ax, qreal ay, qreal w, qreal h) const
0474 { return mapFromParent(QRectF(ax, ay, w, h)); }
0475 inline QPolygonF QGraphicsItem::mapFromScene(qreal ax, qreal ay, qreal w, qreal h) const
0476 { return mapFromScene(QRectF(ax, ay, w, h)); }
0477 inline QRectF QGraphicsItem::mapRectFromItem(const QGraphicsItem *item, qreal ax, qreal ay, qreal w, qreal h) const
0478 { return mapRectFromItem(item, QRectF(ax, ay, w, h)); }
0479 inline QRectF QGraphicsItem::mapRectFromParent(qreal ax, qreal ay, qreal w, qreal h) const
0480 { return mapRectFromParent(QRectF(ax, ay, w, h)); }
0481 inline QRectF QGraphicsItem::mapRectFromScene(qreal ax, qreal ay, qreal w, qreal h) const
0482 { return mapRectFromScene(QRectF(ax, ay, w, h)); }
0483 
0484 
0485 class Q_WIDGETS_EXPORT QGraphicsObject : public QObject, public QGraphicsItem
0486 {
0487     Q_OBJECT
0488     Q_PROPERTY(QGraphicsObject* parent READ parentObject WRITE setParentItem NOTIFY parentChanged
0489                DESIGNABLE false)
0490     Q_PROPERTY(qreal opacity READ opacity WRITE setOpacity NOTIFY opacityChanged FINAL)
0491     Q_PROPERTY(bool enabled READ isEnabled WRITE setEnabled NOTIFY enabledChanged)
0492     Q_PROPERTY(bool visible READ isVisible WRITE setVisible NOTIFY visibleChanged FINAL)
0493     Q_PROPERTY(QPointF pos READ pos WRITE setPos FINAL)
0494     Q_PROPERTY(qreal x READ x WRITE setX NOTIFY xChanged FINAL)
0495     Q_PROPERTY(qreal y READ y WRITE setY NOTIFY yChanged FINAL)
0496     Q_PROPERTY(qreal z READ zValue WRITE setZValue NOTIFY zChanged FINAL)
0497     Q_PROPERTY(qreal rotation READ rotation WRITE setRotation NOTIFY rotationChanged)
0498     Q_PROPERTY(qreal scale READ scale WRITE setScale NOTIFY scaleChanged)
0499     Q_PROPERTY(QPointF transformOriginPoint READ transformOriginPoint WRITE setTransformOriginPoint)
0500 #if QT_CONFIG(graphicseffect)
0501     Q_PROPERTY(QGraphicsEffect *effect READ graphicsEffect WRITE setGraphicsEffect)
0502 #endif
0503     Q_PRIVATE_PROPERTY(QGraphicsItem::d_func(), qreal width READ width WRITE setWidth
0504                        NOTIFY widthChanged RESET resetWidth FINAL)
0505     Q_PRIVATE_PROPERTY(QGraphicsItem::d_func(), qreal height READ height WRITE setHeight
0506                        NOTIFY heightChanged RESET resetHeight FINAL)
0507     Q_INTERFACES(QGraphicsItem)
0508 public:
0509     explicit QGraphicsObject(QGraphicsItem *parent = nullptr);
0510     ~QGraphicsObject();
0511 
0512     using QObject::children;
0513 
0514 #ifndef QT_NO_GESTURES
0515     void grabGesture(Qt::GestureType type, Qt::GestureFlags flags = Qt::GestureFlags());
0516     void ungrabGesture(Qt::GestureType type);
0517 #endif
0518 
0519 protected Q_SLOTS:
0520     void updateMicroFocus();
0521 
0522 Q_SIGNALS:
0523     void parentChanged();
0524     void opacityChanged();
0525     void visibleChanged();
0526     void enabledChanged();
0527     void xChanged();
0528     void yChanged();
0529     void zChanged();
0530     void rotationChanged();
0531     void scaleChanged();
0532     void childrenChanged();
0533     void widthChanged();
0534     void heightChanged();
0535 
0536 protected:
0537     QGraphicsObject(QGraphicsItemPrivate &dd, QGraphicsItem *parent);
0538 
0539     bool event(QEvent *ev) override;
0540 
0541 private:
0542     friend class QGraphicsItem;
0543     friend class QGraphicsItemPrivate;
0544 };
0545 
0546 
0547 class QAbstractGraphicsShapeItemPrivate;
0548 class Q_WIDGETS_EXPORT QAbstractGraphicsShapeItem : public QGraphicsItem
0549 {
0550 public:
0551     explicit QAbstractGraphicsShapeItem(QGraphicsItem *parent = nullptr);
0552     ~QAbstractGraphicsShapeItem();
0553 
0554     QPen pen() const;
0555     void setPen(const QPen &pen);
0556 
0557     QBrush brush() const;
0558     void setBrush(const QBrush &brush);
0559 
0560     bool isObscuredBy(const QGraphicsItem *item) const override;
0561     QPainterPath opaqueArea() const override;
0562 
0563 protected:
0564     QAbstractGraphicsShapeItem(QAbstractGraphicsShapeItemPrivate &dd,
0565                                QGraphicsItem *parent);
0566 
0567 private:
0568     Q_DISABLE_COPY(QAbstractGraphicsShapeItem)
0569     Q_DECLARE_PRIVATE(QAbstractGraphicsShapeItem)
0570 };
0571 
0572 class QGraphicsPathItemPrivate;
0573 class Q_WIDGETS_EXPORT QGraphicsPathItem : public QAbstractGraphicsShapeItem
0574 {
0575 public:
0576     explicit QGraphicsPathItem(QGraphicsItem *parent = nullptr);
0577     explicit QGraphicsPathItem(const QPainterPath &path, QGraphicsItem *parent = nullptr);
0578     ~QGraphicsPathItem();
0579 
0580     QPainterPath path() const;
0581     void setPath(const QPainterPath &path);
0582 
0583     QRectF boundingRect() const override;
0584     QPainterPath shape() const override;
0585     bool contains(const QPointF &point) const override;
0586 
0587     void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = nullptr) override;
0588 
0589     bool isObscuredBy(const QGraphicsItem *item) const override;
0590     QPainterPath opaqueArea() const override;
0591 
0592     enum { Type = 2 };
0593     int type() const override;
0594 
0595 protected:
0596     bool supportsExtension(Extension extension) const override;
0597     void setExtension(Extension extension, const QVariant &variant) override;
0598     QVariant extension(const QVariant &variant) const override;
0599 
0600 private:
0601     Q_DISABLE_COPY(QGraphicsPathItem)
0602     Q_DECLARE_PRIVATE(QGraphicsPathItem)
0603 };
0604 
0605 class QGraphicsRectItemPrivate;
0606 class Q_WIDGETS_EXPORT QGraphicsRectItem : public QAbstractGraphicsShapeItem
0607 {
0608 public:
0609     explicit QGraphicsRectItem(QGraphicsItem *parent = nullptr);
0610     explicit QGraphicsRectItem(const QRectF &rect, QGraphicsItem *parent = nullptr);
0611     explicit QGraphicsRectItem(qreal x, qreal y, qreal w, qreal h, QGraphicsItem *parent = nullptr);
0612     ~QGraphicsRectItem();
0613 
0614     QRectF rect() const;
0615     void setRect(const QRectF &rect);
0616     inline void setRect(qreal x, qreal y, qreal w, qreal h);
0617 
0618     QRectF boundingRect() const override;
0619     QPainterPath shape() const override;
0620     bool contains(const QPointF &point) const override;
0621 
0622     void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = nullptr) override;
0623 
0624     bool isObscuredBy(const QGraphicsItem *item) const override;
0625     QPainterPath opaqueArea() const override;
0626 
0627     enum { Type = 3 };
0628     int type() const override;
0629 
0630 protected:
0631     bool supportsExtension(Extension extension) const override;
0632     void setExtension(Extension extension, const QVariant &variant) override;
0633     QVariant extension(const QVariant &variant) const override;
0634 
0635 private:
0636     Q_DISABLE_COPY(QGraphicsRectItem)
0637     Q_DECLARE_PRIVATE(QGraphicsRectItem)
0638 };
0639 
0640 inline void QGraphicsRectItem::setRect(qreal ax, qreal ay, qreal w, qreal h)
0641 { setRect(QRectF(ax, ay, w, h)); }
0642 
0643 class QGraphicsEllipseItemPrivate;
0644 class Q_WIDGETS_EXPORT QGraphicsEllipseItem : public QAbstractGraphicsShapeItem
0645 {
0646 public:
0647     explicit QGraphicsEllipseItem(QGraphicsItem *parent = nullptr);
0648     explicit QGraphicsEllipseItem(const QRectF &rect, QGraphicsItem *parent = nullptr);
0649     explicit QGraphicsEllipseItem(qreal x, qreal y, qreal w, qreal h, QGraphicsItem *parent = nullptr);
0650     ~QGraphicsEllipseItem();
0651 
0652     QRectF rect() const;
0653     void setRect(const QRectF &rect);
0654     inline void setRect(qreal x, qreal y, qreal w, qreal h);
0655 
0656     int startAngle() const;
0657     void setStartAngle(int angle);
0658 
0659     int spanAngle() const;
0660     void setSpanAngle(int angle);
0661 
0662     QRectF boundingRect() const override;
0663     QPainterPath shape() const override;
0664     bool contains(const QPointF &point) const override;
0665 
0666     void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = nullptr) override;
0667 
0668     bool isObscuredBy(const QGraphicsItem *item) const override;
0669     QPainterPath opaqueArea() const override;
0670 
0671     enum { Type = 4 };
0672     int type() const override;
0673 
0674 protected:
0675     bool supportsExtension(Extension extension) const override;
0676     void setExtension(Extension extension, const QVariant &variant) override;
0677     QVariant extension(const QVariant &variant) const override;
0678 
0679 private:
0680     Q_DISABLE_COPY(QGraphicsEllipseItem)
0681     Q_DECLARE_PRIVATE(QGraphicsEllipseItem)
0682 };
0683 
0684 inline void QGraphicsEllipseItem::setRect(qreal ax, qreal ay, qreal w, qreal h)
0685 { setRect(QRectF(ax, ay, w, h)); }
0686 
0687 class QGraphicsPolygonItemPrivate;
0688 class Q_WIDGETS_EXPORT QGraphicsPolygonItem : public QAbstractGraphicsShapeItem
0689 {
0690 public:
0691     explicit QGraphicsPolygonItem(QGraphicsItem *parent = nullptr);
0692     explicit QGraphicsPolygonItem(const QPolygonF &polygon,
0693                                   QGraphicsItem *parent = nullptr);
0694     ~QGraphicsPolygonItem();
0695 
0696     QPolygonF polygon() const;
0697     void setPolygon(const QPolygonF &polygon);
0698 
0699     Qt::FillRule fillRule() const;
0700     void setFillRule(Qt::FillRule rule);
0701 
0702     QRectF boundingRect() const override;
0703     QPainterPath shape() const override;
0704     bool contains(const QPointF &point) const override;
0705 
0706     void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = nullptr) override;
0707 
0708     bool isObscuredBy(const QGraphicsItem *item) const override;
0709     QPainterPath opaqueArea() const override;
0710 
0711     enum { Type = 5 };
0712     int type() const override;
0713 
0714 protected:
0715     bool supportsExtension(Extension extension) const override;
0716     void setExtension(Extension extension, const QVariant &variant) override;
0717     QVariant extension(const QVariant &variant) const override;
0718 
0719 private:
0720     Q_DISABLE_COPY(QGraphicsPolygonItem)
0721     Q_DECLARE_PRIVATE(QGraphicsPolygonItem)
0722 };
0723 
0724 class QGraphicsLineItemPrivate;
0725 class Q_WIDGETS_EXPORT QGraphicsLineItem : public QGraphicsItem
0726 {
0727 public:
0728     explicit QGraphicsLineItem(QGraphicsItem *parent = nullptr);
0729     explicit QGraphicsLineItem(const QLineF &line, QGraphicsItem *parent = nullptr);
0730     explicit QGraphicsLineItem(qreal x1, qreal y1, qreal x2, qreal y2, QGraphicsItem *parent = nullptr);
0731     ~QGraphicsLineItem();
0732 
0733     QPen pen() const;
0734     void setPen(const QPen &pen);
0735 
0736     QLineF line() const;
0737     void setLine(const QLineF &line);
0738     inline void setLine(qreal x1, qreal y1, qreal x2, qreal y2)
0739     { setLine(QLineF(x1, y1, x2, y2)); }
0740 
0741     QRectF boundingRect() const override;
0742     QPainterPath shape() const override;
0743     bool contains(const QPointF &point) const override;
0744 
0745     void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = nullptr) override;
0746 
0747     bool isObscuredBy(const QGraphicsItem *item) const override;
0748     QPainterPath opaqueArea() const override;
0749 
0750     enum { Type = 6 };
0751     int type() const override;
0752 
0753 protected:
0754     bool supportsExtension(Extension extension) const override;
0755     void setExtension(Extension extension, const QVariant &variant) override;
0756     QVariant extension(const QVariant &variant) const override;
0757 
0758 private:
0759     Q_DISABLE_COPY(QGraphicsLineItem)
0760     Q_DECLARE_PRIVATE(QGraphicsLineItem)
0761 };
0762 
0763 class QGraphicsPixmapItemPrivate;
0764 class Q_WIDGETS_EXPORT QGraphicsPixmapItem : public QGraphicsItem
0765 {
0766 public:
0767     enum ShapeMode {
0768         MaskShape,
0769         BoundingRectShape,
0770         HeuristicMaskShape
0771     };
0772 
0773     explicit QGraphicsPixmapItem(QGraphicsItem *parent = nullptr);
0774     explicit QGraphicsPixmapItem(const QPixmap &pixmap, QGraphicsItem *parent = nullptr);
0775     ~QGraphicsPixmapItem();
0776 
0777     QPixmap pixmap() const;
0778     void setPixmap(const QPixmap &pixmap);
0779 
0780     Qt::TransformationMode transformationMode() const;
0781     void setTransformationMode(Qt::TransformationMode mode);
0782 
0783     QPointF offset() const;
0784     void setOffset(const QPointF &offset);
0785     inline void setOffset(qreal x, qreal y);
0786 
0787     QRectF boundingRect() const override;
0788     QPainterPath shape() const override;
0789     bool contains(const QPointF &point) const override;
0790 
0791     void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override;
0792 
0793     bool isObscuredBy(const QGraphicsItem *item) const override;
0794     QPainterPath opaqueArea() const override;
0795 
0796     enum { Type = 7 };
0797     int type() const override;
0798 
0799     ShapeMode shapeMode() const;
0800     void setShapeMode(ShapeMode mode);
0801 
0802 protected:
0803     bool supportsExtension(Extension extension) const override;
0804     void setExtension(Extension extension, const QVariant &variant) override;
0805     QVariant extension(const QVariant &variant) const override;
0806 
0807 private:
0808     Q_DISABLE_COPY(QGraphicsPixmapItem)
0809     Q_DECLARE_PRIVATE(QGraphicsPixmapItem)
0810 };
0811 
0812 inline void QGraphicsPixmapItem::setOffset(qreal ax, qreal ay)
0813 { setOffset(QPointF(ax, ay)); }
0814 
0815 class QGraphicsTextItemPrivate;
0816 class QTextDocument;
0817 class QTextCursor;
0818 class Q_WIDGETS_EXPORT QGraphicsTextItem : public QGraphicsObject
0819 {
0820     Q_OBJECT
0821     QDOC_PROPERTY(bool openExternalLinks READ openExternalLinks WRITE setOpenExternalLinks)
0822     QDOC_PROPERTY(QTextCursor textCursor READ textCursor WRITE setTextCursor)
0823 
0824 public:
0825     explicit QGraphicsTextItem(QGraphicsItem *parent = nullptr);
0826     explicit QGraphicsTextItem(const QString &text, QGraphicsItem *parent = nullptr);
0827     ~QGraphicsTextItem();
0828 
0829     QString toHtml() const;
0830     void setHtml(const QString &html);
0831 
0832     QString toPlainText() const;
0833     void setPlainText(const QString &text);
0834 
0835     QFont font() const;
0836     void setFont(const QFont &font);
0837 
0838     void setDefaultTextColor(const QColor &c);
0839     QColor defaultTextColor() const;
0840 
0841     QRectF boundingRect() const override;
0842     QPainterPath shape() const override;
0843     bool contains(const QPointF &point) const override;
0844 
0845     void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override;
0846 
0847     bool isObscuredBy(const QGraphicsItem *item) const override;
0848     QPainterPath opaqueArea() const override;
0849 
0850     enum { Type = 8 };
0851     int type() const override;
0852 
0853     void setTextWidth(qreal width);
0854     qreal textWidth() const;
0855 
0856     void adjustSize();
0857 
0858     void setDocument(QTextDocument *document);
0859     QTextDocument *document() const;
0860 
0861     void setTextInteractionFlags(Qt::TextInteractionFlags flags);
0862     Qt::TextInteractionFlags textInteractionFlags() const;
0863 
0864     void setTabChangesFocus(bool b);
0865     bool tabChangesFocus() const;
0866 
0867     void setOpenExternalLinks(bool open);
0868     bool openExternalLinks() const;
0869 
0870     void setTextCursor(const QTextCursor &cursor);
0871     QTextCursor textCursor() const;
0872 
0873 Q_SIGNALS:
0874     void linkActivated(const QString &);
0875     void linkHovered(const QString &);
0876 
0877 protected:
0878     bool sceneEvent(QEvent *event) override;
0879     void mousePressEvent(QGraphicsSceneMouseEvent *event) override;
0880     void mouseMoveEvent(QGraphicsSceneMouseEvent *event) override;
0881     void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) override;
0882     void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event) override;
0883     void contextMenuEvent(QGraphicsSceneContextMenuEvent *event) override;
0884     void keyPressEvent(QKeyEvent *event) override;
0885     void keyReleaseEvent(QKeyEvent *event) override;
0886     void focusInEvent(QFocusEvent *event) override;
0887     void focusOutEvent(QFocusEvent *event) override;
0888     void dragEnterEvent(QGraphicsSceneDragDropEvent *event) override;
0889     void dragLeaveEvent(QGraphicsSceneDragDropEvent *event) override;
0890     void dragMoveEvent(QGraphicsSceneDragDropEvent *event) override;
0891     void dropEvent(QGraphicsSceneDragDropEvent *event) override;
0892     void inputMethodEvent(QInputMethodEvent *event) override;
0893     void hoverEnterEvent(QGraphicsSceneHoverEvent *event) override;
0894     void hoverMoveEvent(QGraphicsSceneHoverEvent *event) override;
0895     void hoverLeaveEvent(QGraphicsSceneHoverEvent *event) override;
0896 
0897     QVariant inputMethodQuery(Qt::InputMethodQuery query) const override;
0898 
0899     bool supportsExtension(Extension extension) const override;
0900     void setExtension(Extension extension, const QVariant &variant) override;
0901     QVariant extension(const QVariant &variant) const override;
0902 
0903 private:
0904     Q_DISABLE_COPY(QGraphicsTextItem)
0905     QGraphicsTextItemPrivate *dd;
0906     friend class QGraphicsTextItemPrivate;
0907 };
0908 
0909 class QGraphicsSimpleTextItemPrivate;
0910 class Q_WIDGETS_EXPORT QGraphicsSimpleTextItem : public QAbstractGraphicsShapeItem
0911 {
0912 public:
0913     explicit QGraphicsSimpleTextItem(QGraphicsItem *parent = nullptr);
0914     explicit QGraphicsSimpleTextItem(const QString &text, QGraphicsItem *parent = nullptr);
0915     ~QGraphicsSimpleTextItem();
0916 
0917     void setText(const QString &text);
0918     QString text() const;
0919 
0920     void setFont(const QFont &font);
0921     QFont font() const;
0922 
0923     QRectF boundingRect() const override;
0924     QPainterPath shape() const override;
0925     bool contains(const QPointF &point) const override;
0926 
0927     void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override;
0928 
0929     bool isObscuredBy(const QGraphicsItem *item) const override;
0930     QPainterPath opaqueArea() const override;
0931 
0932     enum { Type = 9 };
0933     int type() const override;
0934 
0935 protected:
0936     bool supportsExtension(Extension extension) const override;
0937     void setExtension(Extension extension, const QVariant &variant) override;
0938     QVariant extension(const QVariant &variant) const override;
0939 
0940 private:
0941     Q_DISABLE_COPY(QGraphicsSimpleTextItem)
0942     Q_DECLARE_PRIVATE(QGraphicsSimpleTextItem)
0943 };
0944 
0945 class QGraphicsItemGroupPrivate;
0946 class Q_WIDGETS_EXPORT QGraphicsItemGroup : public QGraphicsItem
0947 {
0948 public:
0949     explicit QGraphicsItemGroup(QGraphicsItem *parent = nullptr);
0950     ~QGraphicsItemGroup();
0951 
0952     void addToGroup(QGraphicsItem *item);
0953     void removeFromGroup(QGraphicsItem *item);
0954 
0955     QRectF boundingRect() const override;
0956     void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = nullptr) override;
0957 
0958     bool isObscuredBy(const QGraphicsItem *item) const override;
0959     QPainterPath opaqueArea() const override;
0960 
0961     enum { Type = 10 };
0962     int type() const override;
0963 
0964 private:
0965     Q_DISABLE_COPY(QGraphicsItemGroup)
0966     Q_DECLARE_PRIVATE(QGraphicsItemGroup)
0967 };
0968 
0969 template <class T> inline T qgraphicsitem_cast(QGraphicsItem *item)
0970 {
0971     typedef typename std::remove_cv<typename std::remove_pointer<T>::type>::type Item;
0972     return int(Item::Type) == int(QGraphicsItem::Type)
0973         || (item && int(Item::Type) == item->type()) ? static_cast<T>(item) : nullptr;
0974 }
0975 
0976 template <class T> inline T qgraphicsitem_cast(const QGraphicsItem *item)
0977 {
0978     typedef typename std::remove_cv<typename std::remove_pointer<T>::type>::type Item;
0979     return int(Item::Type) == int(QGraphicsItem::Type)
0980         || (item && int(Item::Type) == item->type()) ? static_cast<T>(item) : nullptr;
0981 }
0982 
0983 #ifndef QT_NO_DEBUG_STREAM
0984 Q_WIDGETS_EXPORT QDebug operator<<(QDebug debug, const QGraphicsItem *item);
0985 Q_WIDGETS_EXPORT QDebug operator<<(QDebug debug, const QGraphicsObject *item);
0986 Q_WIDGETS_EXPORT QDebug operator<<(QDebug debug, QGraphicsItem::GraphicsItemChange change);
0987 Q_WIDGETS_EXPORT QDebug operator<<(QDebug debug, QGraphicsItem::GraphicsItemFlag flag);
0988 Q_WIDGETS_EXPORT QDebug operator<<(QDebug debug, QGraphicsItem::GraphicsItemFlags flags);
0989 #endif
0990 
0991 QT_END_NAMESPACE
0992 
0993 QT_DECL_METATYPE_EXTERN_TAGGED(QGraphicsItem*, QGraphicsItem_ptr, Q_WIDGETS_EXPORT)
0994 
0995 #endif // QGRAPHICSITEM_H