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 QGRAPHICSVIEW_H
00043 #define QGRAPHICSVIEW_H
00044
00045 #include <QtCore/qmetatype.h>
00046 #include <QtGui/qpainter.h>
00047 #include <QtGui/qscrollarea.h>
00048 #include <QtGui/qgraphicsscene.h>
00049
00050 QT_BEGIN_HEADER
00051
00052 QT_BEGIN_NAMESPACE
00053
00054 QT_MODULE(Gui)
00055
00056 #if !defined(QT_NO_GRAPHICSVIEW) || (QT_EDITION & QT_MODULE_GRAPHICSVIEW) != QT_MODULE_GRAPHICSVIEW
00057
00058 class QGraphicsItem;
00059 class QPainterPath;
00060 class QPolygonF;
00061 class QStyleOptionGraphicsItem;
00062
00063 class QGraphicsViewPrivate;
00064 class Q_GUI_EXPORT QGraphicsView : public QAbstractScrollArea
00065 {
00066 Q_OBJECT
00067 Q_FLAGS(QPainter::RenderHints CacheMode OptimizationFlags)
00068 Q_ENUMS(ViewportAnchor DragMode ViewportUpdateMode)
00069 Q_PROPERTY(QBrush backgroundBrush READ backgroundBrush WRITE setBackgroundBrush)
00070 Q_PROPERTY(QBrush foregroundBrush READ foregroundBrush WRITE setForegroundBrush)
00071 Q_PROPERTY(bool interactive READ isInteractive WRITE setInteractive)
00072 Q_PROPERTY(QRectF sceneRect READ sceneRect WRITE setSceneRect)
00073 Q_PROPERTY(Qt::Alignment alignment READ alignment WRITE setAlignment)
00074 Q_PROPERTY(QPainter::RenderHints renderHints READ renderHints WRITE setRenderHints)
00075 Q_PROPERTY(DragMode dragMode READ dragMode WRITE setDragMode)
00076 Q_PROPERTY(CacheMode cacheMode READ cacheMode WRITE setCacheMode)
00077 Q_PROPERTY(ViewportAnchor transformationAnchor READ transformationAnchor WRITE setTransformationAnchor)
00078 Q_PROPERTY(ViewportAnchor resizeAnchor READ resizeAnchor WRITE setResizeAnchor)
00079 Q_PROPERTY(ViewportUpdateMode viewportUpdateMode READ viewportUpdateMode WRITE setViewportUpdateMode)
00080 #ifndef QT_NO_RUBBERBAND
00081 Q_PROPERTY(Qt::ItemSelectionMode rubberBandSelectionMode READ rubberBandSelectionMode WRITE setRubberBandSelectionMode)
00082 #endif
00083 Q_PROPERTY(OptimizationFlags optimizationFlags READ optimizationFlags WRITE setOptimizationFlags)
00084
00085 public:
00086 enum ViewportAnchor {
00087 NoAnchor,
00088 AnchorViewCenter,
00089 AnchorUnderMouse
00090 };
00091
00092 enum CacheModeFlag {
00093 CacheNone = 0x0,
00094 CacheBackground = 0x1
00095 };
00096 Q_DECLARE_FLAGS(CacheMode, CacheModeFlag)
00097
00098 enum DragMode {
00099 NoDrag,
00100 ScrollHandDrag,
00101 RubberBandDrag
00102 };
00103
00104 enum ViewportUpdateMode {
00105 FullViewportUpdate,
00106 MinimalViewportUpdate,
00107 SmartViewportUpdate,
00108 NoViewportUpdate,
00109 BoundingRectViewportUpdate
00110 };
00111
00112 enum OptimizationFlag {
00113 DontClipPainter = 0x1,
00114 DontSavePainterState = 0x2,
00115 DontAdjustForAntialiasing = 0x4,
00116 IndirectPainting = 0x8
00117 };
00118 Q_DECLARE_FLAGS(OptimizationFlags, OptimizationFlag)
00119
00120 QGraphicsView(QWidget *parent = 0);
00121 QGraphicsView(QGraphicsScene *scene, QWidget *parent = 0);
00122 ~QGraphicsView();
00123
00124 QSize sizeHint() const;
00125
00126 QPainter::RenderHints renderHints() const;
00127 void setRenderHint(QPainter::RenderHint hint, bool enabled = true);
00128 void setRenderHints(QPainter::RenderHints hints);
00129
00130 Qt::Alignment alignment() const;
00131 void setAlignment(Qt::Alignment alignment);
00132
00133 ViewportAnchor transformationAnchor() const;
00134 void setTransformationAnchor(ViewportAnchor anchor);
00135
00136 ViewportAnchor resizeAnchor() const;
00137 void setResizeAnchor(ViewportAnchor anchor);
00138
00139 ViewportUpdateMode viewportUpdateMode() const;
00140 void setViewportUpdateMode(ViewportUpdateMode mode);
00141
00142 OptimizationFlags optimizationFlags() const;
00143 void setOptimizationFlag(OptimizationFlag flag, bool enabled = true);
00144 void setOptimizationFlags(OptimizationFlags flags);
00145
00146 DragMode dragMode() const;
00147 void setDragMode(DragMode mode);
00148
00149 #ifndef QT_NO_RUBBERBAND
00150 Qt::ItemSelectionMode rubberBandSelectionMode() const;
00151 void setRubberBandSelectionMode(Qt::ItemSelectionMode mode);
00152 #endif
00153
00154 CacheMode cacheMode() const;
00155 void setCacheMode(CacheMode mode);
00156 void resetCachedContent();
00157
00158 bool isInteractive() const;
00159 void setInteractive(bool allowed);
00160
00161 QGraphicsScene *scene() const;
00162 void setScene(QGraphicsScene *scene);
00163
00164 QRectF sceneRect() const;
00165 void setSceneRect(const QRectF &rect);
00166 inline void setSceneRect(qreal x, qreal y, qreal w, qreal h);
00167
00168 QMatrix matrix() const;
00169 void setMatrix(const QMatrix &matrix, bool combine = false);
00170 void resetMatrix();
00171 QTransform transform() const;
00172 QTransform viewportTransform() const;
00173 bool isTransformed() const;
00174 void setTransform(const QTransform &matrix, bool combine = false);
00175 void resetTransform();
00176 void rotate(qreal angle);
00177 void scale(qreal sx, qreal sy);
00178 void shear(qreal sh, qreal sv);
00179 void translate(qreal dx, qreal dy);
00180
00181 void centerOn(const QPointF &pos);
00182 inline void centerOn(qreal x, qreal y);
00183 void centerOn(const QGraphicsItem *item);
00184 void ensureVisible(const QRectF &rect, int xmargin = 50, int ymargin = 50);
00185 inline void ensureVisible(qreal x, qreal y, qreal w, qreal h, int xmargin = 50, int ymargin = 50);
00186 void ensureVisible(const QGraphicsItem *item, int xmargin = 50, int ymargin = 50);
00187 void fitInView(const QRectF &rect, Qt::AspectRatioMode aspectRadioMode = Qt::IgnoreAspectRatio);
00188 inline void fitInView(qreal x, qreal y, qreal w, qreal h,
00189 Qt::AspectRatioMode aspectRadioMode = Qt::IgnoreAspectRatio);
00190 void fitInView(const QGraphicsItem *item,
00191 Qt::AspectRatioMode aspectRadioMode = Qt::IgnoreAspectRatio);
00192
00193 void render(QPainter *painter, const QRectF &target = QRectF(), const QRect &source = QRect(),
00194 Qt::AspectRatioMode aspectRatioMode = Qt::KeepAspectRatio);
00195
00196 QList<QGraphicsItem *> items() const;
00197 QList<QGraphicsItem *> items(const QPoint &pos) const;
00198 inline QList<QGraphicsItem *> items(int x, int y) const;
00199 QList<QGraphicsItem *> items(const QRect &rect, Qt::ItemSelectionMode mode = Qt::IntersectsItemShape) const;
00200 inline QList<QGraphicsItem *> items(int x, int y, int w, int h, Qt::ItemSelectionMode mode = Qt::IntersectsItemShape) const;
00201 QList<QGraphicsItem *> items(const QPolygon &polygon, Qt::ItemSelectionMode mode = Qt::IntersectsItemShape) const;
00202 QList<QGraphicsItem *> items(const QPainterPath &path, Qt::ItemSelectionMode mode = Qt::IntersectsItemShape) const;
00203 QGraphicsItem *itemAt(const QPoint &pos) const;
00204 inline QGraphicsItem *itemAt(int x, int y) const;
00205
00206 QPointF mapToScene(const QPoint &point) const;
00207 QPolygonF mapToScene(const QRect &rect) const;
00208 QPolygonF mapToScene(const QPolygon &polygon) const;
00209 QPainterPath mapToScene(const QPainterPath &path) const;
00210 QPoint mapFromScene(const QPointF &point) const;
00211 QPolygon mapFromScene(const QRectF &rect) const;
00212 QPolygon mapFromScene(const QPolygonF &polygon) const;
00213 QPainterPath mapFromScene(const QPainterPath &path) const;
00214 inline QPointF mapToScene(int x, int y) const;
00215 inline QPolygonF mapToScene(int x, int y, int w, int h) const;
00216 inline QPoint mapFromScene(qreal x, qreal y) const;
00217 inline QPolygon mapFromScene(qreal x, qreal y, qreal w, qreal h) const;
00218
00219 QVariant inputMethodQuery(Qt::InputMethodQuery query) const;
00220
00221 QBrush backgroundBrush() const;
00222 void setBackgroundBrush(const QBrush &brush);
00223
00224 QBrush foregroundBrush() const;
00225 void setForegroundBrush(const QBrush &brush);
00226
00227 public Q_SLOTS:
00228 void updateScene(const QList<QRectF> &rects);
00229 void invalidateScene(const QRectF &rect = QRectF(), QGraphicsScene::SceneLayers layers = QGraphicsScene::AllLayers);
00230 void updateSceneRect(const QRectF &rect);
00231
00232 protected Q_SLOTS:
00233 void setupViewport(QWidget *widget);
00234
00235 protected:
00236 QGraphicsView(QGraphicsViewPrivate &, QWidget *parent = 0);
00237 bool event(QEvent *event);
00238 bool viewportEvent(QEvent *event);
00239
00240 #ifndef QT_NO_CONTEXTMENU
00241 void contextMenuEvent(QContextMenuEvent *event);
00242 #endif
00243 void dragEnterEvent(QDragEnterEvent *event);
00244 void dragLeaveEvent(QDragLeaveEvent *event);
00245 void dragMoveEvent(QDragMoveEvent *event);
00246 void dropEvent(QDropEvent *event);
00247 void focusInEvent(QFocusEvent *event);
00248 bool focusNextPrevChild(bool next);
00249 void focusOutEvent(QFocusEvent *event);
00250 void keyPressEvent(QKeyEvent *event);
00251 void keyReleaseEvent(QKeyEvent *event);
00252 void mouseDoubleClickEvent(QMouseEvent *event);
00253 void mousePressEvent(QMouseEvent *event);
00254 void mouseMoveEvent(QMouseEvent *event);
00255 void mouseReleaseEvent(QMouseEvent *event);
00256 #ifndef QT_NO_WHEELEVENT
00257 void wheelEvent(QWheelEvent *event);
00258 #endif
00259 void paintEvent(QPaintEvent *event);
00260 void resizeEvent(QResizeEvent *event);
00261 void scrollContentsBy(int dx, int dy);
00262 void showEvent(QShowEvent *event);
00263 void inputMethodEvent(QInputMethodEvent *event);
00264
00265 virtual void drawBackground(QPainter *painter, const QRectF &rect);
00266 virtual void drawForeground(QPainter *painter, const QRectF &rect);
00267 virtual void drawItems(QPainter *painter, int numItems,
00268 QGraphicsItem *items[],
00269 const QStyleOptionGraphicsItem options[]);
00270
00271 private:
00272 Q_DECLARE_PRIVATE(QGraphicsView)
00273 Q_DISABLE_COPY(QGraphicsView)
00274 #ifndef QT_NO_CURSOR
00275 Q_PRIVATE_SLOT(d_func(), void _q_setViewportCursor(const QCursor &))
00276 Q_PRIVATE_SLOT(d_func(), void _q_unsetViewportCursor())
00277 #endif
00278 friend class QGraphicsSceneWidget;
00279 friend class QGraphicsScene;
00280 friend class QGraphicsScenePrivate;
00281 friend class QGraphicsItemPrivate;
00282 };
00283
00284 Q_DECLARE_OPERATORS_FOR_FLAGS(QGraphicsView::CacheMode)
00285 Q_DECLARE_OPERATORS_FOR_FLAGS(QGraphicsView::OptimizationFlags)
00286
00287 inline void QGraphicsView::setSceneRect(qreal ax, qreal ay, qreal aw, qreal ah)
00288 { setSceneRect(QRectF(ax, ay, aw, ah)); }
00289 inline void QGraphicsView::centerOn(qreal ax, qreal ay)
00290 { centerOn(QPointF(ax, ay)); }
00291 inline void QGraphicsView::ensureVisible(qreal ax, qreal ay, qreal aw, qreal ah, int xmargin, int ymargin)
00292 { ensureVisible(QRectF(ax, ay, aw, ah), xmargin, ymargin); }
00293 inline void QGraphicsView::fitInView(qreal ax, qreal ay, qreal w, qreal h, Qt::AspectRatioMode mode)
00294 { fitInView(QRectF(ax, ay, w, h), mode); }
00295 inline QList<QGraphicsItem *> QGraphicsView::items(int ax, int ay) const
00296 { return items(QPoint(ax, ay)); }
00297 inline QList<QGraphicsItem *> QGraphicsView::items(int ax, int ay, int w, int h, Qt::ItemSelectionMode mode) const
00298 { return items(QRect(ax, ay, w, h), mode); }
00299 inline QGraphicsItem *QGraphicsView::itemAt(int ax, int ay) const
00300 { return itemAt(QPoint(ax, ay)); }
00301 inline QPointF QGraphicsView::mapToScene(int ax, int ay) const
00302 { return mapToScene(QPoint(ax, ay)); }
00303 inline QPolygonF QGraphicsView::mapToScene(int ax, int ay, int w, int h) const
00304 { return mapToScene(QRect(ax, ay, w, h)); }
00305 inline QPoint QGraphicsView::mapFromScene(qreal ax, qreal ay) const
00306 { return mapFromScene(QPointF(ax, ay)); }
00307 inline QPolygon QGraphicsView::mapFromScene(qreal ax, qreal ay, qreal w, qreal h) const
00308 { return mapFromScene(QRectF(ax, ay, w, h)); }
00309
00310 #endif // QT_NO_GRAPHICSVIEW
00311
00312 QT_END_NAMESPACE
00313
00314 QT_END_HEADER
00315
00316 #endif // QGRAPHICSVIEW_H