00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042 #ifndef QGRAPHICSSCENE_H
00043 #define QGRAPHICSSCENE_H
00044
00045 #include <QtCore/qobject.h>
00046 #include <QtCore/qpoint.h>
00047 #include <QtCore/qrect.h>
00048 #include <QtGui/qbrush.h>
00049 #include <QtGui/qfont.h>
00050 #include <QtGui/qtransform.h>
00051 #include <QtGui/qmatrix.h>
00052 #include <QtGui/qpen.h>
00053
00054 QT_BEGIN_HEADER
00055
00056 QT_BEGIN_NAMESPACE
00057
00058 QT_MODULE(Gui)
00059
00060 #if !defined(QT_NO_GRAPHICSVIEW) || (QT_EDITION & QT_MODULE_GRAPHICSVIEW) != QT_MODULE_GRAPHICSVIEW
00061
00062 template<typename T> class QList;
00063 class QFocusEvent;
00064 class QFont;
00065 class QFontMetrics;
00066 class QGraphicsEllipseItem;
00067 class QGraphicsItem;
00068 class QGraphicsItemGroup;
00069 class QGraphicsLineItem;
00070 class QGraphicsPathItem;
00071 class QGraphicsPixmapItem;
00072 class QGraphicsPolygonItem;
00073 class QGraphicsProxyWidget;
00074 class QGraphicsRectItem;
00075 class QGraphicsSceneContextMenuEvent;
00076 class QGraphicsSceneDragDropEvent;
00077 class QGraphicsSceneEvent;
00078 class QGraphicsSceneHelpEvent;
00079 class QGraphicsSceneHoverEvent;
00080 class QGraphicsSceneMouseEvent;
00081 class QGraphicsSceneWheelEvent;
00082 class QGraphicsSimpleTextItem;
00083 class QGraphicsTextItem;
00084 class QGraphicsView;
00085 class QGraphicsWidget;
00086 class QGraphicsSceneIndex;
00087 class QHelpEvent;
00088 class QInputMethodEvent;
00089 class QKeyEvent;
00090 class QLineF;
00091 class QPainterPath;
00092 class QPixmap;
00093 class QPointF;
00094 class QPolygonF;
00095 class QRectF;
00096 class QSizeF;
00097 class QStyle;
00098 class QStyleOptionGraphicsItem;
00099
00100 class QGraphicsScenePrivate;
00101 class Q_GUI_EXPORT QGraphicsScene : public QObject
00102 {
00103 Q_OBJECT
00104 Q_PROPERTY(QBrush backgroundBrush READ backgroundBrush WRITE setBackgroundBrush)
00105 Q_PROPERTY(QBrush foregroundBrush READ foregroundBrush WRITE setForegroundBrush)
00106 Q_PROPERTY(ItemIndexMethod itemIndexMethod READ itemIndexMethod WRITE setItemIndexMethod)
00107 Q_PROPERTY(QRectF sceneRect READ sceneRect WRITE setSceneRect)
00108 Q_PROPERTY(int bspTreeDepth READ bspTreeDepth WRITE setBspTreeDepth)
00109 Q_PROPERTY(QPalette palette READ palette WRITE setPalette)
00110 Q_PROPERTY(QFont font READ font WRITE setFont)
00111 Q_PROPERTY(bool sortCacheEnabled READ isSortCacheEnabled WRITE setSortCacheEnabled)
00112 Q_PROPERTY(bool stickyFocus READ stickyFocus WRITE setStickyFocus)
00113
00114 public:
00115 enum ItemIndexMethod {
00116 BspTreeIndex,
00117 NoIndex = -1
00118 };
00119
00120 enum SceneLayer {
00121 ItemLayer = 0x1,
00122 BackgroundLayer = 0x2,
00123 ForegroundLayer = 0x4,
00124 AllLayers = 0xffff
00125 };
00126 Q_DECLARE_FLAGS(SceneLayers, SceneLayer)
00127
00128 QGraphicsScene(QObject *parent = 0);
00129 QGraphicsScene(const QRectF &sceneRect, QObject *parent = 0);
00130 QGraphicsScene(qreal x, qreal y, qreal width, qreal height, QObject *parent = 0);
00131 virtual ~QGraphicsScene();
00132
00133 QRectF sceneRect() const;
00134 inline qreal width() const { return sceneRect().width(); }
00135 inline qreal height() const { return sceneRect().height(); }
00136 void setSceneRect(const QRectF &rect);
00137 inline void setSceneRect(qreal x, qreal y, qreal w, qreal h)
00138 { setSceneRect(QRectF(x, y, w, h)); }
00139
00140 void render(QPainter *painter,
00141 const QRectF &target = QRectF(), const QRectF &source = QRectF(),
00142 Qt::AspectRatioMode aspectRatioMode = Qt::KeepAspectRatio);
00143
00144 ItemIndexMethod itemIndexMethod() const;
00145 void setItemIndexMethod(ItemIndexMethod method);
00146
00147 bool isSortCacheEnabled() const;
00148 void setSortCacheEnabled(bool enabled);
00149
00150 int bspTreeDepth() const;
00151 void setBspTreeDepth(int depth);
00152
00153 QRectF itemsBoundingRect() const;
00154
00155 QList<QGraphicsItem *> items() const;
00156 QList<QGraphicsItem *> items(Qt::SortOrder order) const;
00157
00158 QList<QGraphicsItem *> items(const QPointF &pos, Qt::ItemSelectionMode mode, Qt::SortOrder order, const QTransform &deviceTransform = QTransform()) const;
00159 QList<QGraphicsItem *> items(const QRectF &rect, Qt::ItemSelectionMode mode, Qt::SortOrder order, const QTransform &deviceTransform = QTransform()) const;
00160 QList<QGraphicsItem *> items(const QPolygonF &polygon, Qt::ItemSelectionMode mode, Qt::SortOrder order, const QTransform &deviceTransform = QTransform()) const;
00161 QList<QGraphicsItem *> items(const QPainterPath &path, Qt::ItemSelectionMode mode, Qt::SortOrder order, const QTransform &deviceTransform = QTransform()) const;
00162
00163 QList<QGraphicsItem *> items(const QPointF &pos) const;
00164 QList<QGraphicsItem *> items(const QRectF &rect, Qt::ItemSelectionMode mode = Qt::IntersectsItemShape) const;
00165 QList<QGraphicsItem *> items(const QPolygonF &polygon, Qt::ItemSelectionMode mode = Qt::IntersectsItemShape) const;
00166 QList<QGraphicsItem *> items(const QPainterPath &path, Qt::ItemSelectionMode mode = Qt::IntersectsItemShape) const;
00167
00168 QList<QGraphicsItem *> collidingItems(const QGraphicsItem *item, Qt::ItemSelectionMode mode = Qt::IntersectsItemShape) const;
00169
00170 QGraphicsItem *itemAt(const QPointF &pos) const;
00171 QGraphicsItem *itemAt(const QPointF &pos, const QTransform &deviceTransform) const;
00172
00173 inline QList<QGraphicsItem *> items(qreal x, qreal y, qreal w, qreal h, Qt::ItemSelectionMode mode = Qt::IntersectsItemShape) const
00174 { return items(QRectF(x, y, w, h), mode); }
00175 inline QList<QGraphicsItem *> items(qreal x, qreal y, qreal w, qreal h, Qt::ItemSelectionMode mode, Qt::SortOrder order,
00176 const QTransform &deviceTransform = QTransform()) const
00177 { return items(QRectF(x, y, w, h), mode, order, deviceTransform); }
00178 inline QGraphicsItem *itemAt(qreal x, qreal y) const
00179 { return itemAt(QPointF(x, y)); }
00180 inline QGraphicsItem *itemAt(qreal x, qreal y, const QTransform &deviceTransform) const
00181 { return itemAt(QPointF(x, y), deviceTransform); }
00182
00183 QList<QGraphicsItem *> selectedItems() const;
00184 QPainterPath selectionArea() const;
00185 void setSelectionArea(const QPainterPath &path);
00186 void setSelectionArea(const QPainterPath &path, const QTransform &deviceTransform);
00187 void setSelectionArea(const QPainterPath &path, Qt::ItemSelectionMode mode);
00188 void setSelectionArea(const QPainterPath &path, Qt::ItemSelectionMode mode, const QTransform &deviceTransform);
00189
00190 QGraphicsItemGroup *createItemGroup(const QList<QGraphicsItem *> &items);
00191 void destroyItemGroup(QGraphicsItemGroup *group);
00192
00193 void addItem(QGraphicsItem *item);
00194 QGraphicsEllipseItem *addEllipse(const QRectF &rect, const QPen &pen = QPen(), const QBrush &brush = QBrush());
00195 QGraphicsLineItem *addLine(const QLineF &line, const QPen &pen = QPen());
00196 QGraphicsPathItem *addPath(const QPainterPath &path, const QPen &pen = QPen(), const QBrush &brush = QBrush());
00197 QGraphicsPixmapItem *addPixmap(const QPixmap &pixmap);
00198 QGraphicsPolygonItem *addPolygon(const QPolygonF &polygon, const QPen &pen = QPen(), const QBrush &brush = QBrush());
00199 QGraphicsRectItem *addRect(const QRectF &rect, const QPen &pen = QPen(), const QBrush &brush = QBrush());
00200 QGraphicsTextItem *addText(const QString &text, const QFont &font = QFont());
00201 QGraphicsSimpleTextItem *addSimpleText(const QString &text, const QFont &font = QFont());
00202 QGraphicsProxyWidget *addWidget(QWidget *widget, Qt::WindowFlags wFlags = 0);
00203 inline QGraphicsEllipseItem *addEllipse(qreal x, qreal y, qreal w, qreal h, const QPen &pen = QPen(), const QBrush &brush = QBrush())
00204 { return addEllipse(QRectF(x, y, w, h), pen, brush); }
00205 inline QGraphicsLineItem *addLine(qreal x1, qreal y1, qreal x2, qreal y2, const QPen &pen = QPen())
00206 { return addLine(QLineF(x1, y1, x2, y2), pen); }
00207 inline QGraphicsRectItem *addRect(qreal x, qreal y, qreal w, qreal h, const QPen &pen = QPen(), const QBrush &brush = QBrush())
00208 { return addRect(QRectF(x, y, w, h), pen, brush); }
00209 void removeItem(QGraphicsItem *item);
00210
00211 QGraphicsItem *focusItem() const;
00212 void setFocusItem(QGraphicsItem *item, Qt::FocusReason focusReason = Qt::OtherFocusReason);
00213 bool hasFocus() const;
00214 void setFocus(Qt::FocusReason focusReason = Qt::OtherFocusReason);
00215 void clearFocus();
00216
00217 void setStickyFocus(bool enabled);
00218 bool stickyFocus() const;
00219
00220 QGraphicsItem *mouseGrabberItem() const;
00221
00222 QBrush backgroundBrush() const;
00223 void setBackgroundBrush(const QBrush &brush);
00224
00225 QBrush foregroundBrush() const;
00226 void setForegroundBrush(const QBrush &brush);
00227
00228 virtual QVariant inputMethodQuery(Qt::InputMethodQuery query) const;
00229
00230 QList <QGraphicsView *> views() const;
00231
00232 inline void update(qreal x, qreal y, qreal w, qreal h)
00233 { update(QRectF(x, y, w, h)); }
00234 inline void invalidate(qreal x, qreal y, qreal w, qreal h, SceneLayers layers = AllLayers)
00235 { invalidate(QRectF(x, y, w, h), layers); }
00236
00237 QStyle *style() const;
00238 void setStyle(QStyle *style);
00239
00240 QFont font() const;
00241 void setFont(const QFont &font);
00242
00243 QPalette palette() const;
00244 void setPalette(const QPalette &palette);
00245
00246 bool isActive() const;
00247 QGraphicsItem *activePanel() const;
00248 void setActivePanel(QGraphicsItem *item);
00249 QGraphicsWidget *activeWindow() const;
00250 void setActiveWindow(QGraphicsWidget *widget);
00251
00252 bool sendEvent(QGraphicsItem *item, QEvent *event);
00253
00254 public Q_SLOTS:
00255 void update(const QRectF &rect = QRectF());
00256 void invalidate(const QRectF &rect = QRectF(), SceneLayers layers = AllLayers);
00257 void advance();
00258 void clearSelection();
00259 void clear();
00260
00261 protected:
00262 bool event(QEvent *event);
00263 bool eventFilter(QObject *watched, QEvent *event);
00264 virtual void contextMenuEvent(QGraphicsSceneContextMenuEvent *event);
00265 virtual void dragEnterEvent(QGraphicsSceneDragDropEvent *event);
00266 virtual void dragMoveEvent(QGraphicsSceneDragDropEvent *event);
00267 virtual void dragLeaveEvent(QGraphicsSceneDragDropEvent *event);
00268 virtual void dropEvent(QGraphicsSceneDragDropEvent *event);
00269 virtual void focusInEvent(QFocusEvent *event);
00270 virtual void focusOutEvent(QFocusEvent *event);
00271 virtual void helpEvent(QGraphicsSceneHelpEvent *event);
00272 virtual void keyPressEvent(QKeyEvent *event);
00273 virtual void keyReleaseEvent(QKeyEvent *event);
00274 virtual void mousePressEvent(QGraphicsSceneMouseEvent *event);
00275 virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
00276 virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
00277 virtual void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event);
00278 virtual void wheelEvent(QGraphicsSceneWheelEvent *event);
00279 virtual void inputMethodEvent(QInputMethodEvent *event);
00280
00281 virtual void drawBackground(QPainter *painter, const QRectF &rect);
00282 virtual void drawForeground(QPainter *painter, const QRectF &rect);
00283 virtual void drawItems(QPainter *painter, int numItems,
00284 QGraphicsItem *items[],
00285 const QStyleOptionGraphicsItem options[],
00286 QWidget *widget = 0);
00287
00288 protected Q_SLOTS:
00289 bool focusNextPrevChild(bool next);
00290
00291 Q_SIGNALS:
00292 void changed(const QList<QRectF> ®ion);
00293 void sceneRectChanged(const QRectF &rect);
00294 void selectionChanged();
00295
00296 private:
00297 Q_DECLARE_PRIVATE(QGraphicsScene)
00298 Q_DISABLE_COPY(QGraphicsScene)
00299 Q_PRIVATE_SLOT(d_func(), void _q_emitUpdated())
00300 Q_PRIVATE_SLOT(d_func(), void _q_polishItems())
00301 Q_PRIVATE_SLOT(d_func(), void _q_processDirtyItems())
00302 Q_PRIVATE_SLOT(d_func(), void _q_updateScenePosDescendants())
00303 friend class QGraphicsItem;
00304 friend class QGraphicsItemPrivate;
00305 friend class QGraphicsObject;
00306 friend class QGraphicsView;
00307 friend class QGraphicsViewPrivate;
00308 friend class QGraphicsWidget;
00309 friend class QGraphicsWidgetPrivate;
00310 friend class QGraphicsEffect;
00311 friend class QGraphicsSceneIndex;
00312 friend class QGraphicsSceneIndexPrivate;
00313 friend class QGraphicsSceneBspTreeIndex;
00314 friend class QGraphicsSceneBspTreeIndexPrivate;
00315 friend class QGraphicsItemEffectSourcePrivate;
00316 #ifndef QT_NO_GESTURES
00317 friend class QGesture;
00318 #endif
00319 };
00320
00321 Q_DECLARE_OPERATORS_FOR_FLAGS(QGraphicsScene::SceneLayers)
00322
00323 #endif // QT_NO_GRAPHICSVIEW
00324
00325 QT_END_NAMESPACE
00326
00327 QT_END_HEADER
00328
00329 #endif