src/gui/graphicsview/qgraphicsscene.h
changeset 0 1918ee327afb
child 3 41300fa6a67c
equal deleted inserted replaced
-1:000000000000 0:1918ee327afb
       
     1 /****************************************************************************
       
     2 **
       
     3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     4 ** All rights reserved.
       
     5 ** Contact: Nokia Corporation (qt-info@nokia.com)
       
     6 **
       
     7 ** This file is part of the QtGui module of the Qt Toolkit.
       
     8 **
       
     9 ** $QT_BEGIN_LICENSE:LGPL$
       
    10 ** No Commercial Usage
       
    11 ** This file contains pre-release code and may not be distributed.
       
    12 ** You may use this file in accordance with the terms and conditions
       
    13 ** contained in the Technology Preview License Agreement accompanying
       
    14 ** this package.
       
    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 ** If you have questions regarding the use of this file, please contact
       
    29 ** Nokia at qt-info@nokia.com.
       
    30 **
       
    31 **
       
    32 **
       
    33 **
       
    34 **
       
    35 **
       
    36 **
       
    37 **
       
    38 ** $QT_END_LICENSE$
       
    39 **
       
    40 ****************************************************************************/
       
    41 
       
    42 #ifndef QGRAPHICSSCENE_H
       
    43 #define QGRAPHICSSCENE_H
       
    44 
       
    45 #include <QtCore/qobject.h>
       
    46 #include <QtCore/qpoint.h>
       
    47 #include <QtCore/qrect.h>
       
    48 #include <QtGui/qbrush.h>
       
    49 #include <QtGui/qfont.h>
       
    50 #include <QtGui/qtransform.h>
       
    51 #include <QtGui/qmatrix.h>
       
    52 #include <QtGui/qpen.h>
       
    53 
       
    54 QT_BEGIN_HEADER
       
    55 
       
    56 QT_BEGIN_NAMESPACE
       
    57 
       
    58 QT_MODULE(Gui)
       
    59 
       
    60 #if !defined(QT_NO_GRAPHICSVIEW) || (QT_EDITION & QT_MODULE_GRAPHICSVIEW) != QT_MODULE_GRAPHICSVIEW
       
    61 
       
    62 template<typename T> class QList;
       
    63 class QFocusEvent;
       
    64 class QFont;
       
    65 class QFontMetrics;
       
    66 class QGraphicsEllipseItem;
       
    67 class QGraphicsItem;
       
    68 class QGraphicsItemGroup;
       
    69 class QGraphicsLineItem;
       
    70 class QGraphicsPathItem;
       
    71 class QGraphicsPixmapItem;
       
    72 class QGraphicsPolygonItem;
       
    73 class QGraphicsProxyWidget;
       
    74 class QGraphicsRectItem;
       
    75 class QGraphicsSceneContextMenuEvent;
       
    76 class QGraphicsSceneDragDropEvent;
       
    77 class QGraphicsSceneEvent;
       
    78 class QGraphicsSceneHelpEvent;
       
    79 class QGraphicsSceneHoverEvent;
       
    80 class QGraphicsSceneMouseEvent;
       
    81 class QGraphicsSceneWheelEvent;
       
    82 class QGraphicsSimpleTextItem;
       
    83 class QGraphicsTextItem;
       
    84 class QGraphicsView;
       
    85 class QGraphicsWidget;
       
    86 class QGraphicsSceneIndex;
       
    87 class QHelpEvent;
       
    88 class QInputMethodEvent;
       
    89 class QKeyEvent;
       
    90 class QLineF;
       
    91 class QPainterPath;
       
    92 class QPixmap;
       
    93 class QPointF;
       
    94 class QPolygonF;
       
    95 class QRectF;
       
    96 class QSizeF;
       
    97 class QStyle;
       
    98 class QStyleOptionGraphicsItem;
       
    99 
       
   100 class QGraphicsScenePrivate;
       
   101 class Q_GUI_EXPORT QGraphicsScene : public QObject
       
   102 {
       
   103     Q_OBJECT
       
   104     Q_PROPERTY(QBrush backgroundBrush READ backgroundBrush WRITE setBackgroundBrush)
       
   105     Q_PROPERTY(QBrush foregroundBrush READ foregroundBrush WRITE setForegroundBrush)
       
   106     Q_PROPERTY(ItemIndexMethod itemIndexMethod READ itemIndexMethod WRITE setItemIndexMethod)
       
   107     Q_PROPERTY(QRectF sceneRect READ sceneRect WRITE setSceneRect)
       
   108     Q_PROPERTY(int bspTreeDepth READ bspTreeDepth WRITE setBspTreeDepth)
       
   109     Q_PROPERTY(QPalette palette READ palette WRITE setPalette)
       
   110     Q_PROPERTY(QFont font READ font WRITE setFont)
       
   111     Q_PROPERTY(bool sortCacheEnabled READ isSortCacheEnabled WRITE setSortCacheEnabled)
       
   112     Q_PROPERTY(bool stickyFocus READ stickyFocus WRITE setStickyFocus)
       
   113 
       
   114 public:
       
   115     enum ItemIndexMethod {
       
   116         BspTreeIndex,
       
   117         NoIndex = -1
       
   118     };
       
   119 
       
   120     enum SceneLayer {
       
   121         ItemLayer = 0x1,
       
   122         BackgroundLayer = 0x2,
       
   123         ForegroundLayer = 0x4,
       
   124         AllLayers = 0xffff
       
   125     };
       
   126     Q_DECLARE_FLAGS(SceneLayers, SceneLayer)
       
   127 
       
   128     QGraphicsScene(QObject *parent = 0);
       
   129     QGraphicsScene(const QRectF &sceneRect, QObject *parent = 0);
       
   130     QGraphicsScene(qreal x, qreal y, qreal width, qreal height, QObject *parent = 0);
       
   131     virtual ~QGraphicsScene();
       
   132 
       
   133     QRectF sceneRect() const;
       
   134     inline qreal width() const { return sceneRect().width(); }
       
   135     inline qreal height() const { return sceneRect().height(); }
       
   136     void setSceneRect(const QRectF &rect);
       
   137     inline void setSceneRect(qreal x, qreal y, qreal w, qreal h)
       
   138     { setSceneRect(QRectF(x, y, w, h)); }
       
   139 
       
   140     void render(QPainter *painter,
       
   141                 const QRectF &target = QRectF(), const QRectF &source = QRectF(),
       
   142                 Qt::AspectRatioMode aspectRatioMode = Qt::KeepAspectRatio);
       
   143 
       
   144     ItemIndexMethod itemIndexMethod() const;
       
   145     void setItemIndexMethod(ItemIndexMethod method);
       
   146 
       
   147     bool isSortCacheEnabled() const;
       
   148     void setSortCacheEnabled(bool enabled);
       
   149 
       
   150     int bspTreeDepth() const;
       
   151     void setBspTreeDepth(int depth);
       
   152 
       
   153     QRectF itemsBoundingRect() const;
       
   154 
       
   155     QList<QGraphicsItem *> items() const;
       
   156     QList<QGraphicsItem *> items(Qt::SortOrder order) const; // ### Qt 5: unify
       
   157 
       
   158     QList<QGraphicsItem *> items(const QPointF &pos, Qt::ItemSelectionMode mode, Qt::SortOrder order, const QTransform &deviceTransform = QTransform()) const;
       
   159     QList<QGraphicsItem *> items(const QRectF &rect, Qt::ItemSelectionMode mode, Qt::SortOrder order, const QTransform &deviceTransform = QTransform()) const;
       
   160     QList<QGraphicsItem *> items(const QPolygonF &polygon, Qt::ItemSelectionMode mode, Qt::SortOrder order, const QTransform &deviceTransform = QTransform()) const;
       
   161     QList<QGraphicsItem *> items(const QPainterPath &path, Qt::ItemSelectionMode mode, Qt::SortOrder order, const QTransform &deviceTransform = QTransform()) const;
       
   162 
       
   163     QList<QGraphicsItem *> items(const QPointF &pos) const; // ### obsolete
       
   164     QList<QGraphicsItem *> items(const QRectF &rect, Qt::ItemSelectionMode mode = Qt::IntersectsItemShape) const; // ### obsolete
       
   165     QList<QGraphicsItem *> items(const QPolygonF &polygon, Qt::ItemSelectionMode mode = Qt::IntersectsItemShape) const; // ### obsolete
       
   166     QList<QGraphicsItem *> items(const QPainterPath &path, Qt::ItemSelectionMode mode = Qt::IntersectsItemShape) const; // ### obsolete
       
   167 
       
   168     QList<QGraphicsItem *> collidingItems(const QGraphicsItem *item, Qt::ItemSelectionMode mode = Qt::IntersectsItemShape) const;
       
   169 
       
   170     QGraphicsItem *itemAt(const QPointF &pos) const; // ### obsolete
       
   171     QGraphicsItem *itemAt(const QPointF &pos, const QTransform &deviceTransform) const;
       
   172 
       
   173     inline QList<QGraphicsItem *> items(qreal x, qreal y, qreal w, qreal h, Qt::ItemSelectionMode mode = Qt::IntersectsItemShape) const
       
   174     { return items(QRectF(x, y, w, h), mode); } // ### obsolete
       
   175     inline QList<QGraphicsItem *> items(qreal x, qreal y, qreal w, qreal h, Qt::ItemSelectionMode mode, Qt::SortOrder order,
       
   176                                         const QTransform &deviceTransform = QTransform()) const
       
   177     { return items(QRectF(x, y, w, h), mode, order, deviceTransform); }
       
   178     inline QGraphicsItem *itemAt(qreal x, qreal y) const // ### obsolete
       
   179     { return itemAt(QPointF(x, y)); }
       
   180     inline QGraphicsItem *itemAt(qreal x, qreal y, const QTransform &deviceTransform) const
       
   181     { return itemAt(QPointF(x, y), deviceTransform); }
       
   182 
       
   183     QList<QGraphicsItem *> selectedItems() const;
       
   184     QPainterPath selectionArea() const;
       
   185     void setSelectionArea(const QPainterPath &path); // ### obsolete
       
   186     void setSelectionArea(const QPainterPath &path, const QTransform &deviceTransform);
       
   187     void setSelectionArea(const QPainterPath &path, Qt::ItemSelectionMode mode); // ### obsolete
       
   188     void setSelectionArea(const QPainterPath &path, Qt::ItemSelectionMode mode, const QTransform &deviceTransform);
       
   189 
       
   190     QGraphicsItemGroup *createItemGroup(const QList<QGraphicsItem *> &items);
       
   191     void destroyItemGroup(QGraphicsItemGroup *group);
       
   192 
       
   193     void addItem(QGraphicsItem *item);
       
   194     QGraphicsEllipseItem *addEllipse(const QRectF &rect, const QPen &pen = QPen(), const QBrush &brush = QBrush());
       
   195     QGraphicsLineItem *addLine(const QLineF &line, const QPen &pen = QPen());
       
   196     QGraphicsPathItem *addPath(const QPainterPath &path, const QPen &pen = QPen(), const QBrush &brush = QBrush());
       
   197     QGraphicsPixmapItem *addPixmap(const QPixmap &pixmap);
       
   198     QGraphicsPolygonItem *addPolygon(const QPolygonF &polygon, const QPen &pen = QPen(), const QBrush &brush = QBrush());
       
   199     QGraphicsRectItem *addRect(const QRectF &rect, const QPen &pen = QPen(), const QBrush &brush = QBrush());
       
   200     QGraphicsTextItem *addText(const QString &text, const QFont &font = QFont());
       
   201     QGraphicsSimpleTextItem *addSimpleText(const QString &text, const QFont &font = QFont());
       
   202     QGraphicsProxyWidget *addWidget(QWidget *widget, Qt::WindowFlags wFlags = 0);
       
   203     inline QGraphicsEllipseItem *addEllipse(qreal x, qreal y, qreal w, qreal h, const QPen &pen = QPen(), const QBrush &brush = QBrush())
       
   204     { return addEllipse(QRectF(x, y, w, h), pen, brush); }
       
   205     inline QGraphicsLineItem *addLine(qreal x1, qreal y1, qreal x2, qreal y2, const QPen &pen = QPen())
       
   206     { return addLine(QLineF(x1, y1, x2, y2), pen); }
       
   207     inline QGraphicsRectItem *addRect(qreal x, qreal y, qreal w, qreal h, const QPen &pen = QPen(), const QBrush &brush = QBrush())
       
   208     { return addRect(QRectF(x, y, w, h), pen, brush); }
       
   209     void removeItem(QGraphicsItem *item);
       
   210 
       
   211     QGraphicsItem *focusItem() const;
       
   212     void setFocusItem(QGraphicsItem *item, Qt::FocusReason focusReason = Qt::OtherFocusReason);
       
   213     bool hasFocus() const;
       
   214     void setFocus(Qt::FocusReason focusReason = Qt::OtherFocusReason);
       
   215     void clearFocus();
       
   216 
       
   217     void setStickyFocus(bool enabled);
       
   218     bool stickyFocus() const;
       
   219 
       
   220     QGraphicsItem *mouseGrabberItem() const;
       
   221 
       
   222     QBrush backgroundBrush() const;
       
   223     void setBackgroundBrush(const QBrush &brush);
       
   224 
       
   225     QBrush foregroundBrush() const;
       
   226     void setForegroundBrush(const QBrush &brush);
       
   227 
       
   228     virtual QVariant inputMethodQuery(Qt::InputMethodQuery query) const;
       
   229 
       
   230     QList <QGraphicsView *> views() const;
       
   231 
       
   232     inline void update(qreal x, qreal y, qreal w, qreal h)
       
   233     { update(QRectF(x, y, w, h)); }
       
   234     inline void invalidate(qreal x, qreal y, qreal w, qreal h, SceneLayers layers = AllLayers)
       
   235     { invalidate(QRectF(x, y, w, h), layers); }
       
   236 
       
   237     QStyle *style() const;
       
   238     void setStyle(QStyle *style);
       
   239 
       
   240     QFont font() const;
       
   241     void setFont(const QFont &font);
       
   242 
       
   243     QPalette palette() const;
       
   244     void setPalette(const QPalette &palette);
       
   245 
       
   246     bool isActive() const;
       
   247     QGraphicsItem *activePanel() const;
       
   248     void setActivePanel(QGraphicsItem *item);
       
   249     QGraphicsWidget *activeWindow() const;
       
   250     void setActiveWindow(QGraphicsWidget *widget);
       
   251 
       
   252     bool sendEvent(QGraphicsItem *item, QEvent *event);
       
   253 
       
   254 public Q_SLOTS:
       
   255     void update(const QRectF &rect = QRectF());
       
   256     void invalidate(const QRectF &rect = QRectF(), SceneLayers layers = AllLayers);
       
   257     void advance();
       
   258     void clearSelection();
       
   259     void clear();
       
   260 
       
   261 protected:
       
   262     bool event(QEvent *event);
       
   263     bool eventFilter(QObject *watched, QEvent *event);
       
   264     virtual void contextMenuEvent(QGraphicsSceneContextMenuEvent *event);
       
   265     virtual void dragEnterEvent(QGraphicsSceneDragDropEvent *event);
       
   266     virtual void dragMoveEvent(QGraphicsSceneDragDropEvent *event);
       
   267     virtual void dragLeaveEvent(QGraphicsSceneDragDropEvent *event);
       
   268     virtual void dropEvent(QGraphicsSceneDragDropEvent *event);
       
   269     virtual void focusInEvent(QFocusEvent *event);
       
   270     virtual void focusOutEvent(QFocusEvent *event);
       
   271     virtual void helpEvent(QGraphicsSceneHelpEvent *event);
       
   272     virtual void keyPressEvent(QKeyEvent *event);
       
   273     virtual void keyReleaseEvent(QKeyEvent *event);
       
   274     virtual void mousePressEvent(QGraphicsSceneMouseEvent *event);
       
   275     virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
       
   276     virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
       
   277     virtual void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event);
       
   278     virtual void wheelEvent(QGraphicsSceneWheelEvent *event);
       
   279     virtual void inputMethodEvent(QInputMethodEvent *event);
       
   280 
       
   281     virtual void drawBackground(QPainter *painter, const QRectF &rect);
       
   282     virtual void drawForeground(QPainter *painter, const QRectF &rect);
       
   283     virtual void drawItems(QPainter *painter, int numItems,
       
   284                            QGraphicsItem *items[],
       
   285                            const QStyleOptionGraphicsItem options[],
       
   286                            QWidget *widget = 0);
       
   287 
       
   288 protected Q_SLOTS:
       
   289     bool focusNextPrevChild(bool next);
       
   290 
       
   291 Q_SIGNALS:
       
   292     void changed(const QList<QRectF> &region);
       
   293     void sceneRectChanged(const QRectF &rect);
       
   294     void selectionChanged();
       
   295 
       
   296 private:
       
   297     Q_DECLARE_PRIVATE(QGraphicsScene)
       
   298     Q_DISABLE_COPY(QGraphicsScene)
       
   299     Q_PRIVATE_SLOT(d_func(), void _q_emitUpdated())
       
   300     Q_PRIVATE_SLOT(d_func(), void _q_polishItems())
       
   301     Q_PRIVATE_SLOT(d_func(), void _q_processDirtyItems())
       
   302     friend class QGraphicsItem;
       
   303     friend class QGraphicsItemPrivate;
       
   304     friend class QGraphicsView;
       
   305     friend class QGraphicsViewPrivate;
       
   306     friend class QGraphicsWidget;
       
   307     friend class QGraphicsWidgetPrivate;
       
   308     friend class QGraphicsEffect;
       
   309     friend class QGraphicsSceneIndex;
       
   310     friend class QGraphicsSceneIndexPrivate;
       
   311     friend class QGraphicsSceneBspTreeIndex;
       
   312     friend class QGraphicsSceneBspTreeIndexPrivate;
       
   313     friend class QGraphicsItemEffectSourcePrivate;
       
   314     friend class QGesture;
       
   315 };
       
   316 
       
   317 Q_DECLARE_OPERATORS_FOR_FLAGS(QGraphicsScene::SceneLayers)
       
   318 
       
   319 #endif // QT_NO_GRAPHICSVIEW
       
   320 
       
   321 QT_END_NAMESPACE
       
   322 
       
   323 QT_END_HEADER
       
   324 
       
   325 #endif