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 QGRAPHICSSCENE_H
0005 #define QGRAPHICSSCENE_H
0006 
0007 #include <QtWidgets/qtwidgetsglobal.h>
0008 #include <QtCore/qobject.h>
0009 #include <QtCore/qpoint.h>
0010 #include <QtCore/qrect.h>
0011 #include <QtGui/qbrush.h>
0012 #include <QtGui/qfont.h>
0013 #include <QtGui/qtransform.h>
0014 #include <QtGui/qpen.h>
0015 
0016 QT_REQUIRE_CONFIG(graphicsview);
0017 
0018 QT_BEGIN_NAMESPACE
0019 
0020 class QFocusEvent;
0021 class QFont;
0022 class QFontMetrics;
0023 class QGraphicsEllipseItem;
0024 class QGraphicsItem;
0025 class QGraphicsItemGroup;
0026 class QGraphicsLineItem;
0027 class QGraphicsPathItem;
0028 class QGraphicsPixmapItem;
0029 class QGraphicsPolygonItem;
0030 class QGraphicsProxyWidget;
0031 class QGraphicsRectItem;
0032 class QGraphicsSceneContextMenuEvent;
0033 class QGraphicsSceneDragDropEvent;
0034 class QGraphicsSceneEvent;
0035 class QGraphicsSceneHelpEvent;
0036 class QGraphicsSceneHoverEvent;
0037 class QGraphicsSceneMouseEvent;
0038 class QGraphicsSceneWheelEvent;
0039 class QGraphicsSimpleTextItem;
0040 class QGraphicsTextItem;
0041 class QGraphicsView;
0042 class QGraphicsWidget;
0043 class QGraphicsSceneIndex;
0044 class QHelpEvent;
0045 class QInputMethodEvent;
0046 class QKeyEvent;
0047 class QLineF;
0048 class QPainterPath;
0049 class QPixmap;
0050 class QPointF;
0051 class QPolygonF;
0052 class QRectF;
0053 class QSizeF;
0054 class QStyle;
0055 class QStyleOptionGraphicsItem;
0056 
0057 class QGraphicsScenePrivate;
0058 class Q_WIDGETS_EXPORT QGraphicsScene : public QObject
0059 {
0060     Q_OBJECT
0061     Q_PROPERTY(QBrush backgroundBrush READ backgroundBrush WRITE setBackgroundBrush)
0062     Q_PROPERTY(QBrush foregroundBrush READ foregroundBrush WRITE setForegroundBrush)
0063     Q_PROPERTY(ItemIndexMethod itemIndexMethod READ itemIndexMethod WRITE setItemIndexMethod)
0064     Q_PROPERTY(QRectF sceneRect READ sceneRect WRITE setSceneRect)
0065     Q_PROPERTY(int bspTreeDepth READ bspTreeDepth WRITE setBspTreeDepth)
0066     Q_PROPERTY(QPalette palette READ palette WRITE setPalette)
0067     Q_PROPERTY(QFont font READ font WRITE setFont)
0068     Q_PROPERTY(bool stickyFocus READ stickyFocus WRITE setStickyFocus)
0069     Q_PROPERTY(qreal minimumRenderSize READ minimumRenderSize WRITE setMinimumRenderSize)
0070     Q_PROPERTY(bool focusOnTouch READ focusOnTouch WRITE setFocusOnTouch)
0071 
0072 public:
0073     enum ItemIndexMethod {
0074         BspTreeIndex,
0075         NoIndex = -1
0076     };
0077     Q_ENUM(ItemIndexMethod)
0078     enum SceneLayer {
0079         ItemLayer = 0x1,
0080         BackgroundLayer = 0x2,
0081         ForegroundLayer = 0x4,
0082         AllLayers = 0xffff
0083     };
0084     Q_DECLARE_FLAGS(SceneLayers, SceneLayer)
0085 
0086     QGraphicsScene(QObject *parent = nullptr);
0087     QGraphicsScene(const QRectF &sceneRect, QObject *parent = nullptr);
0088     QGraphicsScene(qreal x, qreal y, qreal width, qreal height, QObject *parent = nullptr);
0089     virtual ~QGraphicsScene();
0090 
0091     QRectF sceneRect() const;
0092     inline qreal width() const { return sceneRect().width(); }
0093     inline qreal height() const { return sceneRect().height(); }
0094     void setSceneRect(const QRectF &rect);
0095     inline void setSceneRect(qreal x, qreal y, qreal w, qreal h)
0096     { setSceneRect(QRectF(x, y, w, h)); }
0097 
0098     void render(QPainter *painter,
0099                 const QRectF &target = QRectF(), const QRectF &source = QRectF(),
0100                 Qt::AspectRatioMode aspectRatioMode = Qt::KeepAspectRatio);
0101 
0102     ItemIndexMethod itemIndexMethod() const;
0103     void setItemIndexMethod(ItemIndexMethod method);
0104 
0105     int bspTreeDepth() const;
0106     void setBspTreeDepth(int depth);
0107 
0108     QRectF itemsBoundingRect() const;
0109 
0110     QList<QGraphicsItem *> items(Qt::SortOrder order = Qt::DescendingOrder) const;
0111 
0112     QList<QGraphicsItem *> items(const QPointF &pos, Qt::ItemSelectionMode mode = Qt::IntersectsItemShape, Qt::SortOrder order = Qt::DescendingOrder, const QTransform &deviceTransform = QTransform()) const;
0113     QList<QGraphicsItem *> items(const QRectF &rect, Qt::ItemSelectionMode mode = Qt::IntersectsItemShape, Qt::SortOrder order = Qt::DescendingOrder, const QTransform &deviceTransform = QTransform()) const;
0114     QList<QGraphicsItem *> items(const QPolygonF &polygon, Qt::ItemSelectionMode mode = Qt::IntersectsItemShape, Qt::SortOrder order = Qt::DescendingOrder, const QTransform &deviceTransform = QTransform()) const;
0115     QList<QGraphicsItem *> items(const QPainterPath &path, Qt::ItemSelectionMode mode = Qt::IntersectsItemShape, Qt::SortOrder order = Qt::DescendingOrder, const QTransform &deviceTransform = QTransform()) const;
0116     inline QList<QGraphicsItem *> items(qreal x, qreal y, qreal w, qreal h, Qt::ItemSelectionMode mode, Qt::SortOrder order,
0117                                         const QTransform &deviceTransform = QTransform()) const
0118     { return items(QRectF(x, y, w, h), mode, order, deviceTransform); }
0119 
0120     QList<QGraphicsItem *> collidingItems(const QGraphicsItem *item, Qt::ItemSelectionMode mode = Qt::IntersectsItemShape) const;
0121     QGraphicsItem *itemAt(const QPointF &pos, const QTransform &deviceTransform) const;
0122     inline QGraphicsItem *itemAt(qreal x, qreal y, const QTransform &deviceTransform) const
0123     { return itemAt(QPointF(x, y), deviceTransform); }
0124 
0125     QList<QGraphicsItem *> selectedItems() const;
0126     QPainterPath selectionArea() const;
0127     void setSelectionArea(const QPainterPath &path, const QTransform &deviceTransform);
0128     void setSelectionArea(const QPainterPath &path, Qt::ItemSelectionOperation selectionOperation = Qt::ReplaceSelection, Qt::ItemSelectionMode mode = Qt::IntersectsItemShape, const QTransform &deviceTransform = QTransform());
0129 
0130     QGraphicsItemGroup *createItemGroup(const QList<QGraphicsItem *> &items);
0131     void destroyItemGroup(QGraphicsItemGroup *group);
0132 
0133     void addItem(QGraphicsItem *item);
0134     QGraphicsEllipseItem *addEllipse(const QRectF &rect, const QPen &pen = QPen(), const QBrush &brush = QBrush());
0135     QGraphicsLineItem *addLine(const QLineF &line, const QPen &pen = QPen());
0136     QGraphicsPathItem *addPath(const QPainterPath &path, const QPen &pen = QPen(), const QBrush &brush = QBrush());
0137     QGraphicsPixmapItem *addPixmap(const QPixmap &pixmap);
0138     QGraphicsPolygonItem *addPolygon(const QPolygonF &polygon, const QPen &pen = QPen(), const QBrush &brush = QBrush());
0139     QGraphicsRectItem *addRect(const QRectF &rect, const QPen &pen = QPen(), const QBrush &brush = QBrush());
0140     QGraphicsTextItem *addText(const QString &text, const QFont &font = QFont());
0141     QGraphicsSimpleTextItem *addSimpleText(const QString &text, const QFont &font = QFont());
0142     QGraphicsProxyWidget *addWidget(QWidget *widget, Qt::WindowFlags wFlags = Qt::WindowFlags());
0143     inline QGraphicsEllipseItem *addEllipse(qreal x, qreal y, qreal w, qreal h, const QPen &pen = QPen(), const QBrush &brush = QBrush())
0144     { return addEllipse(QRectF(x, y, w, h), pen, brush); }
0145     inline QGraphicsLineItem *addLine(qreal x1, qreal y1, qreal x2, qreal y2, const QPen &pen = QPen())
0146     { return addLine(QLineF(x1, y1, x2, y2), pen); }
0147     inline QGraphicsRectItem *addRect(qreal x, qreal y, qreal w, qreal h, const QPen &pen = QPen(), const QBrush &brush = QBrush())
0148     { return addRect(QRectF(x, y, w, h), pen, brush); }
0149     void removeItem(QGraphicsItem *item);
0150 
0151     QGraphicsItem *focusItem() const;
0152     void setFocusItem(QGraphicsItem *item, Qt::FocusReason focusReason = Qt::OtherFocusReason);
0153     bool hasFocus() const;
0154     void setFocus(Qt::FocusReason focusReason = Qt::OtherFocusReason);
0155     void clearFocus();
0156 
0157     void setStickyFocus(bool enabled);
0158     bool stickyFocus() const;
0159 
0160     QGraphicsItem *mouseGrabberItem() const;
0161 
0162     QBrush backgroundBrush() const;
0163     void setBackgroundBrush(const QBrush &brush);
0164 
0165     QBrush foregroundBrush() const;
0166     void setForegroundBrush(const QBrush &brush);
0167 
0168     virtual QVariant inputMethodQuery(Qt::InputMethodQuery query) const;
0169 
0170     QList <QGraphicsView *> views() const;
0171 
0172     inline void update(qreal x, qreal y, qreal w, qreal h)
0173     { update(QRectF(x, y, w, h)); }
0174     inline void invalidate(qreal x, qreal y, qreal w, qreal h, SceneLayers layers = AllLayers)
0175     { invalidate(QRectF(x, y, w, h), layers); }
0176 
0177     QStyle *style() const;
0178     void setStyle(QStyle *style);
0179 
0180     QFont font() const;
0181     void setFont(const QFont &font);
0182 
0183     QPalette palette() const;
0184     void setPalette(const QPalette &palette);
0185 
0186     bool isActive() const;
0187     QGraphicsItem *activePanel() const;
0188     void setActivePanel(QGraphicsItem *item);
0189     QGraphicsWidget *activeWindow() const;
0190     void setActiveWindow(QGraphicsWidget *widget);
0191 
0192     bool sendEvent(QGraphicsItem *item, QEvent *event);
0193 
0194     qreal minimumRenderSize() const;
0195     void setMinimumRenderSize(qreal minSize);
0196 
0197     bool focusOnTouch() const;
0198     void setFocusOnTouch(bool enabled);
0199 
0200 public Q_SLOTS:
0201     void update(const QRectF &rect = QRectF());
0202     void invalidate(const QRectF &rect = QRectF(), SceneLayers layers = AllLayers);
0203     void advance();
0204     void clearSelection();
0205     void clear();
0206 
0207 protected:
0208     bool event(QEvent *event) override;
0209     bool eventFilter(QObject *watched, QEvent *event) override;
0210     virtual void contextMenuEvent(QGraphicsSceneContextMenuEvent *event);
0211     virtual void dragEnterEvent(QGraphicsSceneDragDropEvent *event);
0212     virtual void dragMoveEvent(QGraphicsSceneDragDropEvent *event);
0213     virtual void dragLeaveEvent(QGraphicsSceneDragDropEvent *event);
0214     virtual void dropEvent(QGraphicsSceneDragDropEvent *event);
0215     virtual void focusInEvent(QFocusEvent *event);
0216     virtual void focusOutEvent(QFocusEvent *event);
0217     virtual void helpEvent(QGraphicsSceneHelpEvent *event);
0218     virtual void keyPressEvent(QKeyEvent *event);
0219     virtual void keyReleaseEvent(QKeyEvent *event);
0220     virtual void mousePressEvent(QGraphicsSceneMouseEvent *event);
0221     virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
0222     virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
0223     virtual void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event);
0224     virtual void wheelEvent(QGraphicsSceneWheelEvent *event);
0225     virtual void inputMethodEvent(QInputMethodEvent *event);
0226 
0227     virtual void drawBackground(QPainter *painter, const QRectF &rect);
0228     virtual void drawForeground(QPainter *painter, const QRectF &rect);
0229     virtual void drawItems(QPainter *painter, int numItems,
0230                            QGraphicsItem *items[],
0231                            const QStyleOptionGraphicsItem options[],
0232                            QWidget *widget = nullptr);
0233 
0234 protected Q_SLOTS:
0235     virtual bool focusNextPrevChild(bool next);
0236 
0237 Q_SIGNALS:
0238     void changed(const QList<QRectF> &region);
0239     void sceneRectChanged(const QRectF &rect);
0240     void selectionChanged();
0241     void focusItemChanged(QGraphicsItem *newFocus, QGraphicsItem *oldFocus, Qt::FocusReason reason);
0242 
0243 private:
0244     Q_DECLARE_PRIVATE(QGraphicsScene)
0245     Q_DISABLE_COPY(QGraphicsScene)
0246     Q_PRIVATE_SLOT(d_func(), void _q_emitUpdated())
0247     Q_PRIVATE_SLOT(d_func(), void _q_polishItems())
0248     Q_PRIVATE_SLOT(d_func(), void _q_processDirtyItems())
0249     Q_PRIVATE_SLOT(d_func(), void _q_updateScenePosDescendants())
0250     friend class QGraphicsItem;
0251     friend class QGraphicsItemPrivate;
0252     friend class QGraphicsObject;
0253     friend class QGraphicsView;
0254     friend class QGraphicsViewPrivate;
0255     friend class QGraphicsWidget;
0256     friend class QGraphicsWidgetPrivate;
0257     friend class QGraphicsEffect;
0258     friend class QGraphicsSceneIndex;
0259     friend class QGraphicsSceneIndexPrivate;
0260     friend class QGraphicsSceneBspTreeIndex;
0261     friend class QGraphicsSceneBspTreeIndexPrivate;
0262     friend class QGraphicsItemEffectSourcePrivate;
0263 #ifndef QT_NO_GESTURES
0264     friend class QGesture;
0265 #endif
0266 };
0267 
0268 Q_DECLARE_OPERATORS_FOR_FLAGS(QGraphicsScene::SceneLayers)
0269 
0270 QT_END_NAMESPACE
0271 
0272 #endif