source: trunk/src/gui/graphicsview/qgraphicsscene.h@ 371

Last change on this file since 371 was 2, checked in by Dmitry A. Kuminov, 16 years ago

Initially imported qt-all-opensource-src-4.5.1 from Trolltech.

File size: 11.8 KB
Line 
1/****************************************************************************
2**
3** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
4** Contact: Qt Software Information ([email protected])
5**
6** This file is part of the QtGui module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial Usage
10** Licensees holding valid Qt Commercial licenses may use this file in
11** accordance with the Qt Commercial License Agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and Nokia.
14**
15** GNU Lesser General Public License Usage
16** Alternatively, this file may be used under the terms of the GNU Lesser
17** General Public License version 2.1 as published by the Free Software
18** Foundation and appearing in the file LICENSE.LGPL included in the
19** packaging of this file. Please review the following information to
20** ensure the GNU Lesser General Public License version 2.1 requirements
21** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
22**
23** In addition, as a special exception, Nokia gives you certain
24** additional rights. These rights are described in the Nokia Qt LGPL
25** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
26** 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 are unsure which license is appropriate for your use, please
37** contact the sales department at [email protected].
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
54QT_BEGIN_HEADER
55
56QT_BEGIN_NAMESPACE
57
58QT_MODULE(Gui)
59
60#if !defined(QT_NO_GRAPHICSVIEW) || (QT_EDITION & QT_MODULE_GRAPHICSVIEW) != QT_MODULE_GRAPHICSVIEW
61
62template<typename T> class QList;
63class QFocusEvent;
64class QFont;
65class QFontMetrics;
66class QGraphicsEllipseItem;
67class QGraphicsItem;
68class QGraphicsItemGroup;
69class QGraphicsLineItem;
70class QGraphicsPathItem;
71class QGraphicsPixmapItem;
72class QGraphicsPolygonItem;
73class QGraphicsProxyWidget;
74class QGraphicsRectItem;
75class QGraphicsSceneContextMenuEvent;
76class QGraphicsSceneDragDropEvent;
77class QGraphicsSceneEvent;
78class QGraphicsSceneHelpEvent;
79class QGraphicsSceneHoverEvent;
80class QGraphicsSceneMouseEvent;
81class QGraphicsSceneWheelEvent;
82class QGraphicsSimpleTextItem;
83class QGraphicsTextItem;
84class QGraphicsView;
85class QGraphicsWidget;
86class QHelpEvent;
87class QInputMethodEvent;
88class QKeyEvent;
89class QLineF;
90class QPainterPath;
91class QPixmap;
92class QPointF;
93class QPolygonF;
94class QRectF;
95class QSizeF;
96class QStyle;
97class QStyleOptionGraphicsItem;
98
99class QGraphicsScenePrivate;
100class Q_GUI_EXPORT QGraphicsScene : public QObject
101{
102 Q_OBJECT
103 Q_PROPERTY(QBrush backgroundBrush READ backgroundBrush WRITE setBackgroundBrush)
104 Q_PROPERTY(QBrush foregroundBrush READ foregroundBrush WRITE setForegroundBrush)
105 Q_PROPERTY(ItemIndexMethod itemIndexMethod READ itemIndexMethod WRITE setItemIndexMethod)
106 Q_PROPERTY(QRectF sceneRect READ sceneRect WRITE setSceneRect)
107 Q_PROPERTY(int bspTreeDepth READ bspTreeDepth WRITE setBspTreeDepth)
108 Q_PROPERTY(QPalette palette READ palette WRITE setPalette)
109 Q_PROPERTY(QFont font READ font WRITE setFont)
110 Q_PROPERTY(bool sortCacheEnabled READ isSortCacheEnabled WRITE setSortCacheEnabled)
111 Q_PROPERTY(bool stickyFocus READ stickyFocus WRITE setStickyFocus)
112
113public:
114 enum ItemIndexMethod {
115 BspTreeIndex,
116 NoIndex = -1
117 };
118
119 enum SceneLayer {
120 ItemLayer = 0x1,
121 BackgroundLayer = 0x2,
122 ForegroundLayer = 0x4,
123 AllLayers = 0xffff
124 };
125 Q_DECLARE_FLAGS(SceneLayers, SceneLayer)
126
127 QGraphicsScene(QObject *parent = 0);
128 QGraphicsScene(const QRectF &sceneRect, QObject *parent = 0);
129 QGraphicsScene(qreal x, qreal y, qreal width, qreal height, QObject *parent = 0);
130 virtual ~QGraphicsScene();
131
132 QRectF sceneRect() const;
133 inline qreal width() const { return sceneRect().width(); }
134 inline qreal height() const { return sceneRect().height(); }
135 void setSceneRect(const QRectF &rect);
136 inline void setSceneRect(qreal x, qreal y, qreal w, qreal h)
137 { setSceneRect(QRectF(x, y, w, h)); }
138
139 void render(QPainter *painter,
140 const QRectF &target = QRectF(), const QRectF &source = QRectF(),
141 Qt::AspectRatioMode aspectRatioMode = Qt::KeepAspectRatio);
142
143 ItemIndexMethod itemIndexMethod() const;
144 void setItemIndexMethod(ItemIndexMethod method);
145
146 bool isSortCacheEnabled() const;
147 void setSortCacheEnabled(bool enabled);
148
149 int bspTreeDepth() const;
150 void setBspTreeDepth(int depth);
151
152 QRectF itemsBoundingRect() const;
153
154 QList<QGraphicsItem *> items() const;
155 QList<QGraphicsItem *> items(const QPointF &pos) const;
156 QList<QGraphicsItem *> items(const QRectF &rect, Qt::ItemSelectionMode mode = Qt::IntersectsItemShape) const;
157 QList<QGraphicsItem *> items(const QPolygonF &polygon, Qt::ItemSelectionMode mode = Qt::IntersectsItemShape) const;
158 QList<QGraphicsItem *> items(const QPainterPath &path, Qt::ItemSelectionMode mode = Qt::IntersectsItemShape) const;
159 QList<QGraphicsItem *> collidingItems(const QGraphicsItem *item, Qt::ItemSelectionMode mode = Qt::IntersectsItemShape) const;
160 QGraphicsItem *itemAt(const QPointF &pos) const;
161
162 inline QList<QGraphicsItem *> items(qreal x, qreal y, qreal w, qreal h, Qt::ItemSelectionMode mode = Qt::IntersectsItemShape) const
163 { return items(QRectF(x, y, w, h), mode); }
164 inline QGraphicsItem *itemAt(qreal x, qreal y) const
165 { return itemAt(QPointF(x, y)); }
166
167 QList<QGraphicsItem *> selectedItems() const;
168 QPainterPath selectionArea() const;
169 void setSelectionArea(const QPainterPath &path);
170 void setSelectionArea(const QPainterPath &path, Qt::ItemSelectionMode);
171
172 QGraphicsItemGroup *createItemGroup(const QList<QGraphicsItem *> &items);
173 void destroyItemGroup(QGraphicsItemGroup *group);
174
175 void addItem(QGraphicsItem *item);
176 QGraphicsEllipseItem *addEllipse(const QRectF &rect, const QPen &pen = QPen(), const QBrush &brush = QBrush());
177 QGraphicsLineItem *addLine(const QLineF &line, const QPen &pen = QPen());
178 QGraphicsPathItem *addPath(const QPainterPath &path, const QPen &pen = QPen(), const QBrush &brush = QBrush());
179 QGraphicsPixmapItem *addPixmap(const QPixmap &pixmap);
180 QGraphicsPolygonItem *addPolygon(const QPolygonF &polygon, const QPen &pen = QPen(), const QBrush &brush = QBrush());
181 QGraphicsRectItem *addRect(const QRectF &rect, const QPen &pen = QPen(), const QBrush &brush = QBrush());
182 QGraphicsTextItem *addText(const QString &text, const QFont &font = QFont());
183 QGraphicsSimpleTextItem *addSimpleText(const QString &text, const QFont &font = QFont());
184 QGraphicsProxyWidget *addWidget(QWidget *widget, Qt::WindowFlags wFlags = 0);
185 inline QGraphicsEllipseItem *addEllipse(qreal x, qreal y, qreal w, qreal h, const QPen &pen = QPen(), const QBrush &brush = QBrush())
186 { return addEllipse(QRectF(x, y, w, h), pen, brush); }
187 inline QGraphicsLineItem *addLine(qreal x1, qreal y1, qreal x2, qreal y2, const QPen &pen = QPen())
188 { return addLine(QLineF(x1, y1, x2, y2), pen); }
189 inline QGraphicsRectItem *addRect(qreal x, qreal y, qreal w, qreal h, const QPen &pen = QPen(), const QBrush &brush = QBrush())
190 { return addRect(QRectF(x, y, w, h), pen, brush); }
191 void removeItem(QGraphicsItem *item);
192
193 QGraphicsItem *focusItem() const;
194 void setFocusItem(QGraphicsItem *item, Qt::FocusReason focusReason = Qt::OtherFocusReason);
195 bool hasFocus() const;
196 void setFocus(Qt::FocusReason focusReason = Qt::OtherFocusReason);
197 void clearFocus();
198
199 void setStickyFocus(bool enabled);
200 bool stickyFocus() const;
201
202 QGraphicsItem *mouseGrabberItem() const;
203
204 QBrush backgroundBrush() const;
205 void setBackgroundBrush(const QBrush &brush);
206
207 QBrush foregroundBrush() const;
208 void setForegroundBrush(const QBrush &brush);
209
210 virtual QVariant inputMethodQuery(Qt::InputMethodQuery query) const;
211
212 QList <QGraphicsView *> views() const;
213
214 inline void update(qreal x, qreal y, qreal w, qreal h)
215 { update(QRectF(x, y, w, h)); }
216 inline void invalidate(qreal x, qreal y, qreal w, qreal h, SceneLayers layers = AllLayers)
217 { invalidate(QRectF(x, y, w, h), layers); }
218
219 QStyle *style() const;
220 void setStyle(QStyle *style);
221
222 QFont font() const;
223 void setFont(const QFont &font);
224
225 QPalette palette() const;
226 void setPalette(const QPalette &palette);
227
228 QGraphicsWidget *activeWindow() const;
229 void setActiveWindow(QGraphicsWidget *widget);
230
231public Q_SLOTS:
232 void update(const QRectF &rect = QRectF());
233 void invalidate(const QRectF &rect = QRectF(), SceneLayers layers = AllLayers);
234 void advance();
235 void clearSelection();
236 void clear();
237
238protected:
239 bool event(QEvent *event);
240 bool eventFilter(QObject *watched, QEvent *event);
241 virtual void contextMenuEvent(QGraphicsSceneContextMenuEvent *event);
242 virtual void dragEnterEvent(QGraphicsSceneDragDropEvent *event);
243 virtual void dragMoveEvent(QGraphicsSceneDragDropEvent *event);
244 virtual void dragLeaveEvent(QGraphicsSceneDragDropEvent *event);
245 virtual void dropEvent(QGraphicsSceneDragDropEvent *event);
246 virtual void focusInEvent(QFocusEvent *event);
247 virtual void focusOutEvent(QFocusEvent *event);
248 virtual void helpEvent(QGraphicsSceneHelpEvent *event);
249 virtual void keyPressEvent(QKeyEvent *event);
250 virtual void keyReleaseEvent(QKeyEvent *event);
251 virtual void mousePressEvent(QGraphicsSceneMouseEvent *event);
252 virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
253 virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
254 virtual void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event);
255 virtual void wheelEvent(QGraphicsSceneWheelEvent *event);
256 virtual void inputMethodEvent(QInputMethodEvent *event);
257
258 virtual void drawBackground(QPainter *painter, const QRectF &rect);
259 virtual void drawForeground(QPainter *painter, const QRectF &rect);
260 virtual void drawItems(QPainter *painter, int numItems,
261 QGraphicsItem *items[],
262 const QStyleOptionGraphicsItem options[],
263 QWidget *widget = 0);
264
265protected Q_SLOTS:
266 bool focusNextPrevChild(bool next);
267
268Q_SIGNALS:
269 void changed(const QList<QRectF> &region);
270 void sceneRectChanged(const QRectF &rect);
271 void selectionChanged();
272
273private:
274 void itemUpdated(QGraphicsItem *item, const QRectF &rect);
275
276 Q_DECLARE_PRIVATE(QGraphicsScene)
277 Q_DISABLE_COPY(QGraphicsScene)
278 Q_PRIVATE_SLOT(d_func(), void _q_updateIndex())
279 Q_PRIVATE_SLOT(d_func(), void _q_emitUpdated())
280 Q_PRIVATE_SLOT(d_func(), void _q_removeItemLater(QGraphicsItem *item))
281 Q_PRIVATE_SLOT(d_func(), void _q_updateLater())
282 Q_PRIVATE_SLOT(d_func(), void _q_polishItems())
283 Q_PRIVATE_SLOT(d_func(), void _q_updateSortCache())
284 Q_PRIVATE_SLOT(d_func(), void _q_resetDirtyItems())
285 friend class QGraphicsItem;
286 friend class QGraphicsItemPrivate;
287 friend class QGraphicsView;
288 friend class QGraphicsViewPrivate;
289 friend class QGraphicsWidget;
290 friend class QGraphicsWidgetPrivate;
291};
292
293Q_DECLARE_OPERATORS_FOR_FLAGS(QGraphicsScene::SceneLayers)
294
295#endif // QT_NO_GRAPHICSVIEW
296
297QT_END_NAMESPACE
298
299QT_END_HEADER
300
301#endif
Note: See TracBrowser for help on using the repository browser.