source: trunk/src/gui/graphicsview/qgraphicsview.h@ 500

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

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

File size: 12.5 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 QGRAPHICSVIEW_H
43#define QGRAPHICSVIEW_H
44
45#include <QtCore/qmetatype.h>
46#include <QtGui/qpainter.h>
47#include <QtGui/qscrollarea.h>
48#include <QtGui/qgraphicsscene.h>
49
50QT_BEGIN_HEADER
51
52QT_BEGIN_NAMESPACE
53
54QT_MODULE(Gui)
55
56#if !defined(QT_NO_GRAPHICSVIEW) || (QT_EDITION & QT_MODULE_GRAPHICSVIEW) != QT_MODULE_GRAPHICSVIEW
57
58class QGraphicsItem;
59class QPainterPath;
60class QPolygonF;
61class QStyleOptionGraphicsItem;
62
63class QGraphicsViewPrivate;
64class Q_GUI_EXPORT QGraphicsView : public QAbstractScrollArea
65{
66 Q_OBJECT
67 Q_FLAGS(QPainter::RenderHints CacheMode OptimizationFlags)
68 Q_ENUMS(ViewportAnchor DragMode ViewportUpdateMode)
69 Q_PROPERTY(QBrush backgroundBrush READ backgroundBrush WRITE setBackgroundBrush)
70 Q_PROPERTY(QBrush foregroundBrush READ foregroundBrush WRITE setForegroundBrush)
71 Q_PROPERTY(bool interactive READ isInteractive WRITE setInteractive)
72 Q_PROPERTY(QRectF sceneRect READ sceneRect WRITE setSceneRect)
73 Q_PROPERTY(Qt::Alignment alignment READ alignment WRITE setAlignment)
74 Q_PROPERTY(QPainter::RenderHints renderHints READ renderHints WRITE setRenderHints)
75 Q_PROPERTY(DragMode dragMode READ dragMode WRITE setDragMode)
76 Q_PROPERTY(CacheMode cacheMode READ cacheMode WRITE setCacheMode)
77 Q_PROPERTY(ViewportAnchor transformationAnchor READ transformationAnchor WRITE setTransformationAnchor)
78 Q_PROPERTY(ViewportAnchor resizeAnchor READ resizeAnchor WRITE setResizeAnchor)
79 Q_PROPERTY(ViewportUpdateMode viewportUpdateMode READ viewportUpdateMode WRITE setViewportUpdateMode)
80#ifndef QT_NO_RUBBERBAND
81 Q_PROPERTY(Qt::ItemSelectionMode rubberBandSelectionMode READ rubberBandSelectionMode WRITE setRubberBandSelectionMode)
82#endif
83 Q_PROPERTY(OptimizationFlags optimizationFlags READ optimizationFlags WRITE setOptimizationFlags)
84
85public:
86 enum ViewportAnchor {
87 NoAnchor,
88 AnchorViewCenter,
89 AnchorUnderMouse
90 };
91
92 enum CacheModeFlag {
93 CacheNone = 0x0,
94 CacheBackground = 0x1
95 };
96 Q_DECLARE_FLAGS(CacheMode, CacheModeFlag)
97
98 enum DragMode {
99 NoDrag,
100 ScrollHandDrag,
101 RubberBandDrag
102 };
103
104 enum ViewportUpdateMode {
105 FullViewportUpdate,
106 MinimalViewportUpdate,
107 SmartViewportUpdate,
108 NoViewportUpdate,
109 BoundingRectViewportUpdate
110 };
111
112 enum OptimizationFlag {
113 DontClipPainter = 0x1,
114 DontSavePainterState = 0x2,
115 DontAdjustForAntialiasing = 0x4
116 };
117 Q_DECLARE_FLAGS(OptimizationFlags, OptimizationFlag)
118
119 QGraphicsView(QWidget *parent = 0);
120 QGraphicsView(QGraphicsScene *scene, QWidget *parent = 0);
121 ~QGraphicsView();
122
123 QSize sizeHint() const;
124
125 QPainter::RenderHints renderHints() const;
126 void setRenderHint(QPainter::RenderHint hint, bool enabled = true);
127 void setRenderHints(QPainter::RenderHints hints);
128
129 Qt::Alignment alignment() const;
130 void setAlignment(Qt::Alignment alignment);
131
132 ViewportAnchor transformationAnchor() const;
133 void setTransformationAnchor(ViewportAnchor anchor);
134
135 ViewportAnchor resizeAnchor() const;
136 void setResizeAnchor(ViewportAnchor anchor);
137
138 ViewportUpdateMode viewportUpdateMode() const;
139 void setViewportUpdateMode(ViewportUpdateMode mode);
140
141 OptimizationFlags optimizationFlags() const;
142 void setOptimizationFlag(OptimizationFlag flag, bool enabled = true);
143 void setOptimizationFlags(OptimizationFlags flags);
144
145 DragMode dragMode() const;
146 void setDragMode(DragMode mode);
147
148#ifndef QT_NO_RUBBERBAND
149 Qt::ItemSelectionMode rubberBandSelectionMode() const;
150 void setRubberBandSelectionMode(Qt::ItemSelectionMode mode);
151#endif
152
153 CacheMode cacheMode() const;
154 void setCacheMode(CacheMode mode);
155 void resetCachedContent();
156
157 bool isInteractive() const;
158 void setInteractive(bool allowed);
159
160 QGraphicsScene *scene() const;
161 void setScene(QGraphicsScene *scene);
162
163 QRectF sceneRect() const;
164 void setSceneRect(const QRectF &rect);
165 inline void setSceneRect(qreal x, qreal y, qreal w, qreal h);
166
167 QMatrix matrix() const;
168 void setMatrix(const QMatrix &matrix, bool combine = false);
169 void resetMatrix();
170 QTransform transform() const;
171 QTransform viewportTransform() const;
172 void setTransform(const QTransform &matrix, bool combine = false);
173 void resetTransform();
174 void rotate(qreal angle);
175 void scale(qreal sx, qreal sy);
176 void shear(qreal sh, qreal sv);
177 void translate(qreal dx, qreal dy);
178
179 void centerOn(const QPointF &pos);
180 inline void centerOn(qreal x, qreal y);
181 void centerOn(const QGraphicsItem *item);
182 void ensureVisible(const QRectF &rect, int xmargin = 50, int ymargin = 50);
183 inline void ensureVisible(qreal x, qreal y, qreal w, qreal h, int xmargin = 50, int ymargin = 50);
184 void ensureVisible(const QGraphicsItem *item, int xmargin = 50, int ymargin = 50);
185 void fitInView(const QRectF &rect, Qt::AspectRatioMode aspectRadioMode = Qt::IgnoreAspectRatio);
186 inline void fitInView(qreal x, qreal y, qreal w, qreal h,
187 Qt::AspectRatioMode aspectRadioMode = Qt::IgnoreAspectRatio);
188 void fitInView(const QGraphicsItem *item,
189 Qt::AspectRatioMode aspectRadioMode = Qt::IgnoreAspectRatio);
190
191 void render(QPainter *painter, const QRectF &target = QRectF(), const QRect &source = QRect(),
192 Qt::AspectRatioMode aspectRatioMode = Qt::KeepAspectRatio);
193
194 QList<QGraphicsItem *> items() const;
195 QList<QGraphicsItem *> items(const QPoint &pos) const;
196 inline QList<QGraphicsItem *> items(int x, int y) const;
197 QList<QGraphicsItem *> items(const QRect &rect, Qt::ItemSelectionMode mode = Qt::IntersectsItemShape) const;
198 inline QList<QGraphicsItem *> items(int x, int y, int w, int h, Qt::ItemSelectionMode mode = Qt::IntersectsItemShape) const;
199 QList<QGraphicsItem *> items(const QPolygon &polygon, Qt::ItemSelectionMode mode = Qt::IntersectsItemShape) const;
200 QList<QGraphicsItem *> items(const QPainterPath &path, Qt::ItemSelectionMode mode = Qt::IntersectsItemShape) const;
201 QGraphicsItem *itemAt(const QPoint &pos) const;
202 inline QGraphicsItem *itemAt(int x, int y) const;
203
204 QPointF mapToScene(const QPoint &point) const;
205 QPolygonF mapToScene(const QRect &rect) const;
206 QPolygonF mapToScene(const QPolygon &polygon) const;
207 QPainterPath mapToScene(const QPainterPath &path) const;
208 QPoint mapFromScene(const QPointF &point) const;
209 QPolygon mapFromScene(const QRectF &rect) const;
210 QPolygon mapFromScene(const QPolygonF &polygon) const;
211 QPainterPath mapFromScene(const QPainterPath &path) const;
212 inline QPointF mapToScene(int x, int y) const;
213 inline QPolygonF mapToScene(int x, int y, int w, int h) const;
214 inline QPoint mapFromScene(qreal x, qreal y) const;
215 inline QPolygon mapFromScene(qreal x, qreal y, qreal w, qreal h) const;
216
217 QVariant inputMethodQuery(Qt::InputMethodQuery query) const;
218
219 QBrush backgroundBrush() const;
220 void setBackgroundBrush(const QBrush &brush);
221
222 QBrush foregroundBrush() const;
223 void setForegroundBrush(const QBrush &brush);
224
225public Q_SLOTS:
226 void updateScene(const QList<QRectF> &rects);
227 void invalidateScene(const QRectF &rect = QRectF(), QGraphicsScene::SceneLayers layers = QGraphicsScene::AllLayers);
228 void updateSceneRect(const QRectF &rect);
229
230protected Q_SLOTS:
231 void setupViewport(QWidget *widget);
232
233protected:
234 QGraphicsView(QGraphicsViewPrivate &, QWidget *parent = 0);
235 bool event(QEvent *event);
236 bool viewportEvent(QEvent *event);
237
238#ifndef QT_NO_CONTEXTMENU
239 void contextMenuEvent(QContextMenuEvent *event);
240#endif
241 void dragEnterEvent(QDragEnterEvent *event);
242 void dragLeaveEvent(QDragLeaveEvent *event);
243 void dragMoveEvent(QDragMoveEvent *event);
244 void dropEvent(QDropEvent *event);
245 void focusInEvent(QFocusEvent *event);
246 bool focusNextPrevChild(bool next);
247 void focusOutEvent(QFocusEvent *event);
248 void keyPressEvent(QKeyEvent *event);
249 void keyReleaseEvent(QKeyEvent *event);
250 void mouseDoubleClickEvent(QMouseEvent *event);
251 void mousePressEvent(QMouseEvent *event);
252 void mouseMoveEvent(QMouseEvent *event);
253 void mouseReleaseEvent(QMouseEvent *event);
254#ifndef QT_NO_WHEELEVENT
255 void wheelEvent(QWheelEvent *event);
256#endif
257 void paintEvent(QPaintEvent *event);
258 void resizeEvent(QResizeEvent *event);
259 void scrollContentsBy(int dx, int dy);
260 void showEvent(QShowEvent *event);
261 void inputMethodEvent(QInputMethodEvent *event);
262
263 virtual void drawBackground(QPainter *painter, const QRectF &rect);
264 virtual void drawForeground(QPainter *painter, const QRectF &rect);
265 virtual void drawItems(QPainter *painter, int numItems,
266 QGraphicsItem *items[],
267 const QStyleOptionGraphicsItem options[]);
268
269private:
270 Q_DECLARE_PRIVATE(QGraphicsView)
271 Q_DISABLE_COPY(QGraphicsView)
272#ifndef QT_NO_CURSOR
273 Q_PRIVATE_SLOT(d_func(), void _q_setViewportCursor(const QCursor &))
274 Q_PRIVATE_SLOT(d_func(), void _q_unsetViewportCursor())
275#endif
276 Q_PRIVATE_SLOT(d_func(), void _q_updateLaterSlot())
277 friend class QGraphicsSceneWidget;
278 friend class QGraphicsScene;
279 friend class QGraphicsScenePrivate;
280};
281
282Q_DECLARE_OPERATORS_FOR_FLAGS(QGraphicsView::CacheMode)
283Q_DECLARE_OPERATORS_FOR_FLAGS(QGraphicsView::OptimizationFlags)
284
285inline void QGraphicsView::setSceneRect(qreal ax, qreal ay, qreal aw, qreal ah)
286{ setSceneRect(QRectF(ax, ay, aw, ah)); }
287inline void QGraphicsView::centerOn(qreal ax, qreal ay)
288{ centerOn(QPointF(ax, ay)); }
289inline void QGraphicsView::ensureVisible(qreal ax, qreal ay, qreal aw, qreal ah, int xmargin, int ymargin)
290{ ensureVisible(QRectF(ax, ay, aw, ah), xmargin, ymargin); }
291inline void QGraphicsView::fitInView(qreal ax, qreal ay, qreal w, qreal h, Qt::AspectRatioMode mode)
292{ fitInView(QRectF(ax, ay, w, h), mode); }
293inline QList<QGraphicsItem *> QGraphicsView::items(int ax, int ay) const
294{ return items(QPoint(ax, ay)); }
295inline QList<QGraphicsItem *> QGraphicsView::items(int ax, int ay, int w, int h, Qt::ItemSelectionMode mode) const
296{ return items(QRect(ax, ay, w, h), mode); }
297inline QGraphicsItem *QGraphicsView::itemAt(int ax, int ay) const
298{ return itemAt(QPoint(ax, ay)); }
299inline QPointF QGraphicsView::mapToScene(int ax, int ay) const
300{ return mapToScene(QPoint(ax, ay)); }
301inline QPolygonF QGraphicsView::mapToScene(int ax, int ay, int w, int h) const
302{ return mapToScene(QRect(ax, ay, w, h)); }
303inline QPoint QGraphicsView::mapFromScene(qreal ax, qreal ay) const
304{ return mapFromScene(QPointF(ax, ay)); }
305inline QPolygon QGraphicsView::mapFromScene(qreal ax, qreal ay, qreal w, qreal h) const
306{ return mapFromScene(QRectF(ax, ay, w, h)); }
307
308#endif // QT_NO_GRAPHICSVIEW
309
310QT_END_NAMESPACE
311
312QT_END_HEADER
313
314#endif // QGRAPHICSVIEW_H
Note: See TracBrowser for help on using the repository browser.