Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/widgets/graphicsview/qgraphicsview.cpp |
Source code | Switch to Preprocessed file |
Line | Source | Count | ||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | /**************************************************************************** | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3 | ** Copyright (C) 2015 The Qt Company Ltd. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
4 | ** Contact: http://www.qt.io/licensing/ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
5 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||
6 | ** This file is part of the QtWidgets module of the Qt Toolkit. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
7 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||
8 | ** $QT_BEGIN_LICENSE:LGPL21$ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
9 | ** Commercial License Usage | - | ||||||||||||||||||||||||||||||||||||||||||||||||
10 | ** Licensees holding valid commercial Qt licenses may use this file in | - | ||||||||||||||||||||||||||||||||||||||||||||||||
11 | ** accordance with the commercial license agreement provided with the | - | ||||||||||||||||||||||||||||||||||||||||||||||||
12 | ** Software or, alternatively, in accordance with the terms contained in | - | ||||||||||||||||||||||||||||||||||||||||||||||||
13 | ** a written agreement between you and The Qt Company. For licensing terms | - | ||||||||||||||||||||||||||||||||||||||||||||||||
14 | ** and conditions see http://www.qt.io/terms-conditions. For further | - | ||||||||||||||||||||||||||||||||||||||||||||||||
15 | ** information use the contact form at http://www.qt.io/contact-us. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
16 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||
17 | ** GNU Lesser General Public License Usage | - | ||||||||||||||||||||||||||||||||||||||||||||||||
18 | ** Alternatively, this file may be used under the terms of the GNU Lesser | - | ||||||||||||||||||||||||||||||||||||||||||||||||
19 | ** General Public License version 2.1 or version 3 as published by the Free | - | ||||||||||||||||||||||||||||||||||||||||||||||||
20 | ** Software Foundation and appearing in the file LICENSE.LGPLv21 and | - | ||||||||||||||||||||||||||||||||||||||||||||||||
21 | ** LICENSE.LGPLv3 included in the packaging of this file. Please review the | - | ||||||||||||||||||||||||||||||||||||||||||||||||
22 | ** following information to ensure the GNU Lesser General Public License | - | ||||||||||||||||||||||||||||||||||||||||||||||||
23 | ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and | - | ||||||||||||||||||||||||||||||||||||||||||||||||
24 | ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
25 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||
26 | ** As a special exception, The Qt Company gives you certain additional | - | ||||||||||||||||||||||||||||||||||||||||||||||||
27 | ** rights. These rights are described in The Qt Company LGPL Exception | - | ||||||||||||||||||||||||||||||||||||||||||||||||
28 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
29 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||
30 | ** $QT_END_LICENSE$ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
31 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||
32 | ****************************************************************************/ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
33 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
34 | static const int QGRAPHICSVIEW_REGION_RECT_THRESHOLD = 50; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
35 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
36 | static const int QGRAPHICSVIEW_PREALLOC_STYLE_OPTIONS = 503; // largest prime < 2^9 | - | ||||||||||||||||||||||||||||||||||||||||||||||||
37 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
38 | /*! | - | ||||||||||||||||||||||||||||||||||||||||||||||||
39 | \class QGraphicsView | - | ||||||||||||||||||||||||||||||||||||||||||||||||
40 | \brief The QGraphicsView class provides a widget for displaying the | - | ||||||||||||||||||||||||||||||||||||||||||||||||
41 | contents of a QGraphicsScene. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
42 | \since 4.2 | - | ||||||||||||||||||||||||||||||||||||||||||||||||
43 | \ingroup graphicsview-api | - | ||||||||||||||||||||||||||||||||||||||||||||||||
44 | \inmodule QtWidgets | - | ||||||||||||||||||||||||||||||||||||||||||||||||
45 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
46 | QGraphicsView visualizes the contents of a QGraphicsScene in a scrollable | - | ||||||||||||||||||||||||||||||||||||||||||||||||
47 | viewport. To create a scene with geometrical items, see QGraphicsScene's | - | ||||||||||||||||||||||||||||||||||||||||||||||||
48 | documentation. QGraphicsView is part of the \l{Graphics View Framework}. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
49 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
50 | To visualize a scene, you start by constructing a QGraphicsView object, | - | ||||||||||||||||||||||||||||||||||||||||||||||||
51 | passing the address of the scene you want to visualize to QGraphicsView's | - | ||||||||||||||||||||||||||||||||||||||||||||||||
52 | constructor. Alternatively, you can call setScene() to set the scene at a | - | ||||||||||||||||||||||||||||||||||||||||||||||||
53 | later point. After you call show(), the view will by default scroll to the | - | ||||||||||||||||||||||||||||||||||||||||||||||||
54 | center of the scene and display any items that are visible at this | - | ||||||||||||||||||||||||||||||||||||||||||||||||
55 | point. For example: | - | ||||||||||||||||||||||||||||||||||||||||||||||||
56 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
57 | \snippet code/src_gui_graphicsview_qgraphicsview.cpp 0 | - | ||||||||||||||||||||||||||||||||||||||||||||||||
58 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
59 | You can explicitly scroll to any position on the scene by using the | - | ||||||||||||||||||||||||||||||||||||||||||||||||
60 | scroll bars, or by calling centerOn(). By passing a point to centerOn(), | - | ||||||||||||||||||||||||||||||||||||||||||||||||
61 | QGraphicsView will scroll its viewport to ensure that the point is | - | ||||||||||||||||||||||||||||||||||||||||||||||||
62 | centered in the view. An overload is provided for scrolling to a | - | ||||||||||||||||||||||||||||||||||||||||||||||||
63 | QGraphicsItem, in which case QGraphicsView will see to that the center of | - | ||||||||||||||||||||||||||||||||||||||||||||||||
64 | the item is centered in the view. If all you want is to ensure that a | - | ||||||||||||||||||||||||||||||||||||||||||||||||
65 | certain area is visible, (but not necessarily centered,) you can call | - | ||||||||||||||||||||||||||||||||||||||||||||||||
66 | ensureVisible() instead. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
67 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
68 | QGraphicsView can be used to visualize a whole scene, or only parts of it. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
69 | The visualized area is by default detected automatically when the view is | - | ||||||||||||||||||||||||||||||||||||||||||||||||
70 | displayed for the first time (by calling | - | ||||||||||||||||||||||||||||||||||||||||||||||||
71 | QGraphicsScene::itemsBoundingRect()). To set the visualized area rectangle | - | ||||||||||||||||||||||||||||||||||||||||||||||||
72 | yourself, you can call setSceneRect(). This will adjust the scroll bars' | - | ||||||||||||||||||||||||||||||||||||||||||||||||
73 | ranges appropriately. Note that although the scene supports a virtually | - | ||||||||||||||||||||||||||||||||||||||||||||||||
74 | unlimited size, the range of the scroll bars will never exceed the range of | - | ||||||||||||||||||||||||||||||||||||||||||||||||
75 | an integer (INT_MIN, INT_MAX). | - | ||||||||||||||||||||||||||||||||||||||||||||||||
76 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
77 | QGraphicsView visualizes the scene by calling render(). By default, the | - | ||||||||||||||||||||||||||||||||||||||||||||||||
78 | items are drawn onto the viewport by using a regular QPainter, and using | - | ||||||||||||||||||||||||||||||||||||||||||||||||
79 | default render hints. To change the default render hints that | - | ||||||||||||||||||||||||||||||||||||||||||||||||
80 | QGraphicsView passes to QPainter when painting items, you can call | - | ||||||||||||||||||||||||||||||||||||||||||||||||
81 | setRenderHints(). | - | ||||||||||||||||||||||||||||||||||||||||||||||||
82 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
83 | By default, QGraphicsView provides a regular QWidget for the viewport | - | ||||||||||||||||||||||||||||||||||||||||||||||||
84 | widget. You can access this widget by calling viewport(), or you can | - | ||||||||||||||||||||||||||||||||||||||||||||||||
85 | replace it by calling setViewport(). To render using OpenGL, simply call | - | ||||||||||||||||||||||||||||||||||||||||||||||||
86 | setViewport(new QGLWidget). QGraphicsView takes ownership of the viewport | - | ||||||||||||||||||||||||||||||||||||||||||||||||
87 | widget. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
88 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
89 | QGraphicsView supports affine transformations, using QTransform. You can | - | ||||||||||||||||||||||||||||||||||||||||||||||||
90 | either pass a matrix to setTransform(), or you can call one of the | - | ||||||||||||||||||||||||||||||||||||||||||||||||
91 | convenience functions rotate(), scale(), translate() or shear(). The most | - | ||||||||||||||||||||||||||||||||||||||||||||||||
92 | two common transformations are scaling, which is used to implement | - | ||||||||||||||||||||||||||||||||||||||||||||||||
93 | zooming, and rotation. QGraphicsView keeps the center of the view fixed | - | ||||||||||||||||||||||||||||||||||||||||||||||||
94 | during a transformation. Because of the scene alignment (setAligment()), | - | ||||||||||||||||||||||||||||||||||||||||||||||||
95 | translating the view will have no visual impact. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
96 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
97 | You can interact with the items on the scene by using the mouse and | - | ||||||||||||||||||||||||||||||||||||||||||||||||
98 | keyboard. QGraphicsView translates the mouse and key events into \e scene | - | ||||||||||||||||||||||||||||||||||||||||||||||||
99 | events, (events that inherit QGraphicsSceneEvent,), and forward them to | - | ||||||||||||||||||||||||||||||||||||||||||||||||
100 | the visualized scene. In the end, it's the individual item that handles | - | ||||||||||||||||||||||||||||||||||||||||||||||||
101 | the events and reacts to them. For example, if you click on a selectable | - | ||||||||||||||||||||||||||||||||||||||||||||||||
102 | item, the item will typically let the scene know that it has been | - | ||||||||||||||||||||||||||||||||||||||||||||||||
103 | selected, and it will also redraw itself to display a selection | - | ||||||||||||||||||||||||||||||||||||||||||||||||
104 | rectangle. Similiary, if you click and drag the mouse to move a movable | - | ||||||||||||||||||||||||||||||||||||||||||||||||
105 | item, it's the item that handles the mouse moves and moves itself. Item | - | ||||||||||||||||||||||||||||||||||||||||||||||||
106 | interaction is enabled by default, and you can toggle it by calling | - | ||||||||||||||||||||||||||||||||||||||||||||||||
107 | setInteractive(). | - | ||||||||||||||||||||||||||||||||||||||||||||||||
108 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
109 | You can also provide your own custom scene interaction, by creating a | - | ||||||||||||||||||||||||||||||||||||||||||||||||
110 | subclass of QGraphicsView, and reimplementing the mouse and key event | - | ||||||||||||||||||||||||||||||||||||||||||||||||
111 | handlers. To simplify how you programmatically interact with items in the | - | ||||||||||||||||||||||||||||||||||||||||||||||||
112 | view, QGraphicsView provides the mapping functions mapToScene() and | - | ||||||||||||||||||||||||||||||||||||||||||||||||
113 | mapFromScene(), and the item accessors items() and itemAt(). These | - | ||||||||||||||||||||||||||||||||||||||||||||||||
114 | functions allow you to map points, rectangles, polygons and paths between | - | ||||||||||||||||||||||||||||||||||||||||||||||||
115 | view coordinates and scene coordinates, and to find items on the scene | - | ||||||||||||||||||||||||||||||||||||||||||||||||
116 | using view coordinates. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
117 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
118 | \image graphicsview-view.png | - | ||||||||||||||||||||||||||||||||||||||||||||||||
119 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
120 | \sa QGraphicsScene, QGraphicsItem, QGraphicsSceneEvent | - | ||||||||||||||||||||||||||||||||||||||||||||||||
121 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
122 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
123 | /*! | - | ||||||||||||||||||||||||||||||||||||||||||||||||
124 | \enum QGraphicsView::ViewportAnchor | - | ||||||||||||||||||||||||||||||||||||||||||||||||
125 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
126 | This enums describe the possible anchors that QGraphicsView can | - | ||||||||||||||||||||||||||||||||||||||||||||||||
127 | use when the user resizes the view or when the view is | - | ||||||||||||||||||||||||||||||||||||||||||||||||
128 | transformed. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
129 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
130 | \value NoAnchor No anchor, i.e. the view leaves the scene's | - | ||||||||||||||||||||||||||||||||||||||||||||||||
131 | position unchanged. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
132 | \value AnchorViewCenter The scene point at the center of the view | - | ||||||||||||||||||||||||||||||||||||||||||||||||
133 | is used as the anchor. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
134 | \value AnchorUnderMouse The point under the mouse is used as the anchor. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
135 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
136 | \sa resizeAnchor, transformationAnchor | - | ||||||||||||||||||||||||||||||||||||||||||||||||
137 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
138 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
139 | /*! | - | ||||||||||||||||||||||||||||||||||||||||||||||||
140 | \enum QGraphicsView::ViewportUpdateMode | - | ||||||||||||||||||||||||||||||||||||||||||||||||
141 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
142 | \since 4.3 | - | ||||||||||||||||||||||||||||||||||||||||||||||||
143 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
144 | This enum describes how QGraphicsView updates its viewport when the scene | - | ||||||||||||||||||||||||||||||||||||||||||||||||
145 | contents change or are exposed. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
146 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
147 | \value FullViewportUpdate When any visible part of the scene changes or is | - | ||||||||||||||||||||||||||||||||||||||||||||||||
148 | reexposed, QGraphicsView will update the entire viewport. This approach is | - | ||||||||||||||||||||||||||||||||||||||||||||||||
149 | fastest when QGraphicsView spends more time figuring out what to draw than | - | ||||||||||||||||||||||||||||||||||||||||||||||||
150 | it would spend drawing (e.g., when very many small items are repeatedly | - | ||||||||||||||||||||||||||||||||||||||||||||||||
151 | updated). This is the preferred update mode for viewports that do not | - | ||||||||||||||||||||||||||||||||||||||||||||||||
152 | support partial updates, such as QGLWidget, and for viewports that need to | - | ||||||||||||||||||||||||||||||||||||||||||||||||
153 | disable scroll optimization. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
154 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
155 | \value MinimalViewportUpdate QGraphicsView will determine the minimal | - | ||||||||||||||||||||||||||||||||||||||||||||||||
156 | viewport region that requires a redraw, minimizing the time spent drawing | - | ||||||||||||||||||||||||||||||||||||||||||||||||
157 | by avoiding a redraw of areas that have not changed. This is | - | ||||||||||||||||||||||||||||||||||||||||||||||||
158 | QGraphicsView's default mode. Although this approach provides the best | - | ||||||||||||||||||||||||||||||||||||||||||||||||
159 | performance in general, if there are many small visible changes on the | - | ||||||||||||||||||||||||||||||||||||||||||||||||
160 | scene, QGraphicsView might end up spending more time finding the minimal | - | ||||||||||||||||||||||||||||||||||||||||||||||||
161 | approach than it will spend drawing. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
162 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
163 | \value SmartViewportUpdate QGraphicsView will attempt to find an optimal | - | ||||||||||||||||||||||||||||||||||||||||||||||||
164 | update mode by analyzing the areas that require a redraw. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
165 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
166 | \value BoundingRectViewportUpdate The bounding rectangle of all changes in | - | ||||||||||||||||||||||||||||||||||||||||||||||||
167 | the viewport will be redrawn. This mode has the advantage that | - | ||||||||||||||||||||||||||||||||||||||||||||||||
168 | QGraphicsView searches only one region for changes, minimizing time spent | - | ||||||||||||||||||||||||||||||||||||||||||||||||
169 | determining what needs redrawing. The disadvantage is that areas that have | - | ||||||||||||||||||||||||||||||||||||||||||||||||
170 | not changed also need to be redrawn. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
171 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
172 | \value NoViewportUpdate QGraphicsView will never update its viewport when | - | ||||||||||||||||||||||||||||||||||||||||||||||||
173 | the scene changes; the user is expected to control all updates. This mode | - | ||||||||||||||||||||||||||||||||||||||||||||||||
174 | disables all (potentially slow) item visibility testing in QGraphicsView, | - | ||||||||||||||||||||||||||||||||||||||||||||||||
175 | and is suitable for scenes that either require a fixed frame rate, or where | - | ||||||||||||||||||||||||||||||||||||||||||||||||
176 | the viewport is otherwise updated externally. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
177 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
178 | \sa viewportUpdateMode | - | ||||||||||||||||||||||||||||||||||||||||||||||||
179 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
180 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
181 | /*! | - | ||||||||||||||||||||||||||||||||||||||||||||||||
182 | \enum QGraphicsView::OptimizationFlag | - | ||||||||||||||||||||||||||||||||||||||||||||||||
183 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
184 | \since 4.3 | - | ||||||||||||||||||||||||||||||||||||||||||||||||
185 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
186 | This enum describes flags that you can enable to improve rendering | - | ||||||||||||||||||||||||||||||||||||||||||||||||
187 | performance in QGraphicsView. By default, none of these flags are set. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
188 | Note that setting a flag usually imposes a side effect, and this effect | - | ||||||||||||||||||||||||||||||||||||||||||||||||
189 | can vary between paint devices and platforms. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
190 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
191 | \value DontClipPainter This value is obsolete and has no effect. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
192 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
193 | \value DontSavePainterState When rendering, QGraphicsView protects the | - | ||||||||||||||||||||||||||||||||||||||||||||||||
194 | painter state (see QPainter::save()) when rendering the background or | - | ||||||||||||||||||||||||||||||||||||||||||||||||
195 | foreground, and when rendering each item. This allows you to leave the | - | ||||||||||||||||||||||||||||||||||||||||||||||||
196 | painter in an altered state (i.e., you can call QPainter::setPen() or | - | ||||||||||||||||||||||||||||||||||||||||||||||||
197 | QPainter::setBrush() without restoring the state after painting). However, | - | ||||||||||||||||||||||||||||||||||||||||||||||||
198 | if the items consistently do restore the state, you should enable this | - | ||||||||||||||||||||||||||||||||||||||||||||||||
199 | flag to prevent QGraphicsView from doing the same. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
200 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
201 | \value DontAdjustForAntialiasing Disables QGraphicsView's antialiasing | - | ||||||||||||||||||||||||||||||||||||||||||||||||
202 | auto-adjustment of exposed areas. Items that render antialiased lines on | - | ||||||||||||||||||||||||||||||||||||||||||||||||
203 | the boundaries of their QGraphicsItem::boundingRect() can end up rendering | - | ||||||||||||||||||||||||||||||||||||||||||||||||
204 | parts of the line outside. To prevent rendering artifacts, QGraphicsView | - | ||||||||||||||||||||||||||||||||||||||||||||||||
205 | expands all exposed regions by 2 pixels in all directions. If you enable | - | ||||||||||||||||||||||||||||||||||||||||||||||||
206 | this flag, QGraphicsView will no longer perform these adjustments, | - | ||||||||||||||||||||||||||||||||||||||||||||||||
207 | minimizing the areas that require redrawing, which improves performance. A | - | ||||||||||||||||||||||||||||||||||||||||||||||||
208 | common side effect is that items that do draw with antialiasing can leave | - | ||||||||||||||||||||||||||||||||||||||||||||||||
209 | painting traces behind on the scene as they are moved. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
210 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
211 | \value IndirectPainting Since Qt 4.6, restore the old painting algorithm | - | ||||||||||||||||||||||||||||||||||||||||||||||||
212 | that calls QGraphicsView::drawItems() and QGraphicsScene::drawItems(). | - | ||||||||||||||||||||||||||||||||||||||||||||||||
213 | To be used only for compatibility with old code. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
214 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
215 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
216 | /*! | - | ||||||||||||||||||||||||||||||||||||||||||||||||
217 | \enum QGraphicsView::CacheModeFlag | - | ||||||||||||||||||||||||||||||||||||||||||||||||
218 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
219 | This enum describes the flags that you can set for a QGraphicsView's cache | - | ||||||||||||||||||||||||||||||||||||||||||||||||
220 | mode. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
221 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
222 | \value CacheNone All painting is done directly onto the viewport. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
223 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
224 | \value CacheBackground The background is cached. This affects both custom | - | ||||||||||||||||||||||||||||||||||||||||||||||||
225 | backgrounds, and backgrounds based on the backgroundBrush property. When | - | ||||||||||||||||||||||||||||||||||||||||||||||||
226 | this flag is enabled, QGraphicsView will allocate one pixmap with the full | - | ||||||||||||||||||||||||||||||||||||||||||||||||
227 | size of the viewport. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
228 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
229 | \sa cacheMode | - | ||||||||||||||||||||||||||||||||||||||||||||||||
230 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
231 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
232 | /*! | - | ||||||||||||||||||||||||||||||||||||||||||||||||
233 | \enum QGraphicsView::DragMode | - | ||||||||||||||||||||||||||||||||||||||||||||||||
234 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
235 | This enum describes the default action for the view when pressing and | - | ||||||||||||||||||||||||||||||||||||||||||||||||
236 | dragging the mouse over the viewport. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
237 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
238 | \value NoDrag Nothing happens; the mouse event is ignored. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
239 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
240 | \value ScrollHandDrag The cursor changes into a pointing hand, and | - | ||||||||||||||||||||||||||||||||||||||||||||||||
241 | dragging the mouse around will scroll the scrolbars. This mode works both | - | ||||||||||||||||||||||||||||||||||||||||||||||||
242 | in \l{QGraphicsView::interactive}{interactive} and non-interactive mode. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
243 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
244 | \value RubberBandDrag A rubber band will appear. Dragging the mouse will | - | ||||||||||||||||||||||||||||||||||||||||||||||||
245 | set the rubber band geometry, and all items covered by the rubber band are | - | ||||||||||||||||||||||||||||||||||||||||||||||||
246 | selected. This mode is disabled for non-interactive views. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
247 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
248 | \sa dragMode, QGraphicsScene::setSelectionArea() | - | ||||||||||||||||||||||||||||||||||||||||||||||||
249 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
250 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
251 | /*! | - | ||||||||||||||||||||||||||||||||||||||||||||||||
252 | \since 5.1 | - | ||||||||||||||||||||||||||||||||||||||||||||||||
253 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
254 | \fn void QGraphicsView::rubberBandChanged(QRect rubberBandRect, QPointF fromScenePoint, QPointF toScenePoint) | - | ||||||||||||||||||||||||||||||||||||||||||||||||
255 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
256 | This signal is emitted when the rubber band rect is changed. The viewport Rect is specified by \a rubberBandRect. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
257 | The drag start position and drag end position are provided in scene points with \a fromScenePoint and \a toScenePoint. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
258 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
259 | When rubberband selection ends this signal will be emitted with null vales. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
260 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
261 | \sa rubberBandRect() | - | ||||||||||||||||||||||||||||||||||||||||||||||||
262 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
263 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
264 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
265 | #include "qgraphicsview.h" | - | ||||||||||||||||||||||||||||||||||||||||||||||||
266 | #include "qgraphicsview_p.h" | - | ||||||||||||||||||||||||||||||||||||||||||||||||
267 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
268 | #ifndef QT_NO_GRAPHICSVIEW | - | ||||||||||||||||||||||||||||||||||||||||||||||||
269 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
270 | #include "qgraphicsitem.h" | - | ||||||||||||||||||||||||||||||||||||||||||||||||
271 | #include "qgraphicsitem_p.h" | - | ||||||||||||||||||||||||||||||||||||||||||||||||
272 | #include "qgraphicsscene.h" | - | ||||||||||||||||||||||||||||||||||||||||||||||||
273 | #include "qgraphicsscene_p.h" | - | ||||||||||||||||||||||||||||||||||||||||||||||||
274 | #include "qgraphicssceneevent.h" | - | ||||||||||||||||||||||||||||||||||||||||||||||||
275 | #include "qgraphicswidget.h" | - | ||||||||||||||||||||||||||||||||||||||||||||||||
276 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
277 | #include <QtCore/qdatetime.h> | - | ||||||||||||||||||||||||||||||||||||||||||||||||
278 | #include <QtCore/qdebug.h> | - | ||||||||||||||||||||||||||||||||||||||||||||||||
279 | #include <QtCore/qmath.h> | - | ||||||||||||||||||||||||||||||||||||||||||||||||
280 | #include <QtCore/qscopedvaluerollback.h> | - | ||||||||||||||||||||||||||||||||||||||||||||||||
281 | #include <QtWidgets/qapplication.h> | - | ||||||||||||||||||||||||||||||||||||||||||||||||
282 | #include <QtWidgets/qdesktopwidget.h> | - | ||||||||||||||||||||||||||||||||||||||||||||||||
283 | #include <QtGui/qevent.h> | - | ||||||||||||||||||||||||||||||||||||||||||||||||
284 | #include <QtWidgets/qlayout.h> | - | ||||||||||||||||||||||||||||||||||||||||||||||||
285 | #include <QtGui/qtransform.h> | - | ||||||||||||||||||||||||||||||||||||||||||||||||
286 | #include <QtGui/qmatrix.h> | - | ||||||||||||||||||||||||||||||||||||||||||||||||
287 | #include <QtGui/qpainter.h> | - | ||||||||||||||||||||||||||||||||||||||||||||||||
288 | #include <QtWidgets/qscrollbar.h> | - | ||||||||||||||||||||||||||||||||||||||||||||||||
289 | #include <QtWidgets/qstyleoption.h> | - | ||||||||||||||||||||||||||||||||||||||||||||||||
290 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
291 | #include <private/qevent_p.h> | - | ||||||||||||||||||||||||||||||||||||||||||||||||
292 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
293 | QT_BEGIN_NAMESPACE | - | ||||||||||||||||||||||||||||||||||||||||||||||||
294 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
295 | bool qt_sendSpontaneousEvent(QObject *receiver, QEvent *event); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
296 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
297 | inline int q_round_bound(qreal d) //### (int)(qreal) INT_MAX != INT_MAX for single precision | - | ||||||||||||||||||||||||||||||||||||||||||||||||
298 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
299 | if (d <= (qreal) INT_MIN)
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
300 | return INT_MIN; never executed: return (-2147483647 - 1); | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
301 | else if (d >= (qreal) INT_MAX)
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
302 | return INT_MAX; never executed: return 2147483647; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
303 | return d >= 0.0 ? int(d + 0.5) : int(d - int(d-1) + 0.5) + int(d-1); never executed: return d >= 0.0 ? int(d + 0.5) : int(d - int(d-1) + 0.5) + int(d-1);
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
304 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||
305 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
306 | void QGraphicsViewPrivate::translateTouchEvent(QGraphicsViewPrivate *d, QTouchEvent *touchEvent) | - | ||||||||||||||||||||||||||||||||||||||||||||||||
307 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
308 | QList<QTouchEvent::TouchPoint> touchPoints = touchEvent->touchPoints(); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
309 | for (int i = 0; i < touchPoints.count(); ++i) {
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
310 | QTouchEvent::TouchPoint &touchPoint = touchPoints[i]; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
311 | // the scene will set the item local pos, startPos, lastPos, and rect before delivering to | - | ||||||||||||||||||||||||||||||||||||||||||||||||
312 | // an item, but for now those functions are returning the view's local coordinates | - | ||||||||||||||||||||||||||||||||||||||||||||||||
313 | touchPoint.setSceneRect(d->mapToScene(touchPoint.rect())); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
314 | touchPoint.setStartScenePos(d->mapToScene(touchPoint.startPos())); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
315 | touchPoint.setLastScenePos(d->mapToScene(touchPoint.lastPos())); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
316 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
317 | // screenPos, startScreenPos, lastScreenPos, and screenRect are already set | - | ||||||||||||||||||||||||||||||||||||||||||||||||
318 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
319 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
320 | touchEvent->setTouchPoints(touchPoints); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
321 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
322 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
323 | /*! | - | ||||||||||||||||||||||||||||||||||||||||||||||||
324 | \internal | - | ||||||||||||||||||||||||||||||||||||||||||||||||
325 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
326 | QGraphicsViewPrivate::QGraphicsViewPrivate() | - | ||||||||||||||||||||||||||||||||||||||||||||||||
327 | : renderHints(QPainter::TextAntialiasing), | - | ||||||||||||||||||||||||||||||||||||||||||||||||
328 | dragMode(QGraphicsView::NoDrag), | - | ||||||||||||||||||||||||||||||||||||||||||||||||
329 | sceneInteractionAllowed(true), hasSceneRect(false), | - | ||||||||||||||||||||||||||||||||||||||||||||||||
330 | connectedToScene(false), | - | ||||||||||||||||||||||||||||||||||||||||||||||||
331 | useLastMouseEvent(false), | - | ||||||||||||||||||||||||||||||||||||||||||||||||
332 | identityMatrix(true), | - | ||||||||||||||||||||||||||||||||||||||||||||||||
333 | dirtyScroll(true), | - | ||||||||||||||||||||||||||||||||||||||||||||||||
334 | accelerateScrolling(true), | - | ||||||||||||||||||||||||||||||||||||||||||||||||
335 | keepLastCenterPoint(true), | - | ||||||||||||||||||||||||||||||||||||||||||||||||
336 | transforming(false), | - | ||||||||||||||||||||||||||||||||||||||||||||||||
337 | handScrolling(false), | - | ||||||||||||||||||||||||||||||||||||||||||||||||
338 | mustAllocateStyleOptions(false), | - | ||||||||||||||||||||||||||||||||||||||||||||||||
339 | mustResizeBackgroundPixmap(true), | - | ||||||||||||||||||||||||||||||||||||||||||||||||
340 | fullUpdatePending(true), | - | ||||||||||||||||||||||||||||||||||||||||||||||||
341 | hasUpdateClip(false), | - | ||||||||||||||||||||||||||||||||||||||||||||||||
342 | mousePressButton(Qt::NoButton), | - | ||||||||||||||||||||||||||||||||||||||||||||||||
343 | leftIndent(0), topIndent(0), | - | ||||||||||||||||||||||||||||||||||||||||||||||||
344 | lastMouseEvent(QEvent::None, QPointF(), QPointF(), QPointF(), Qt::NoButton, 0, 0), | - | ||||||||||||||||||||||||||||||||||||||||||||||||
345 | alignment(Qt::AlignCenter), | - | ||||||||||||||||||||||||||||||||||||||||||||||||
346 | transformationAnchor(QGraphicsView::AnchorViewCenter), resizeAnchor(QGraphicsView::NoAnchor), | - | ||||||||||||||||||||||||||||||||||||||||||||||||
347 | viewportUpdateMode(QGraphicsView::MinimalViewportUpdate), | - | ||||||||||||||||||||||||||||||||||||||||||||||||
348 | optimizationFlags(0), | - | ||||||||||||||||||||||||||||||||||||||||||||||||
349 | scene(0), | - | ||||||||||||||||||||||||||||||||||||||||||||||||
350 | #ifndef QT_NO_RUBBERBAND | - | ||||||||||||||||||||||||||||||||||||||||||||||||
351 | rubberBanding(false), | - | ||||||||||||||||||||||||||||||||||||||||||||||||
352 | rubberBandSelectionMode(Qt::IntersectsItemShape), | - | ||||||||||||||||||||||||||||||||||||||||||||||||
353 | rubberBandSelectionOperation(Qt::ReplaceSelection), | - | ||||||||||||||||||||||||||||||||||||||||||||||||
354 | #endif | - | ||||||||||||||||||||||||||||||||||||||||||||||||
355 | handScrollMotions(0), cacheMode(0), | - | ||||||||||||||||||||||||||||||||||||||||||||||||
356 | #ifndef QT_NO_CURSOR | - | ||||||||||||||||||||||||||||||||||||||||||||||||
357 | hasStoredOriginalCursor(false), | - | ||||||||||||||||||||||||||||||||||||||||||||||||
358 | #endif | - | ||||||||||||||||||||||||||||||||||||||||||||||||
359 | lastDragDropEvent(0), | - | ||||||||||||||||||||||||||||||||||||||||||||||||
360 | updateSceneSlotReimplementedChecked(false) | - | ||||||||||||||||||||||||||||||||||||||||||||||||
361 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
362 | styleOptions.reserve(QGRAPHICSVIEW_PREALLOC_STYLE_OPTIONS); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
363 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
364 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
365 | QGraphicsViewPrivate::~QGraphicsViewPrivate() | - | ||||||||||||||||||||||||||||||||||||||||||||||||
366 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
367 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||
368 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
369 | /*! | - | ||||||||||||||||||||||||||||||||||||||||||||||||
370 | \internal | - | ||||||||||||||||||||||||||||||||||||||||||||||||
371 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
372 | void QGraphicsViewPrivate::recalculateContentSize() | - | ||||||||||||||||||||||||||||||||||||||||||||||||
373 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
374 | Q_Q(QGraphicsView); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
375 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
376 | QSize maxSize = q->maximumViewportSize(); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
377 | int width = maxSize.width(); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
378 | int height = maxSize.height(); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
379 | QRectF viewRect = matrix.mapRect(q->sceneRect()); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
380 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
381 | bool frameOnlyAround = (q->style()->styleHint(QStyle::SH_ScrollView_FrameOnlyAroundContents, 0, q)); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
382 | if (frameOnlyAround) {
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
383 | if (hbarpolicy == Qt::ScrollBarAlwaysOn)
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
384 | height -= frameWidth * 2; never executed: height -= frameWidth * 2; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
385 | if (vbarpolicy == Qt::ScrollBarAlwaysOn)
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
386 | width -= frameWidth * 2; never executed: width -= frameWidth * 2; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
387 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
388 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
389 | // Adjust the maximum width and height of the viewport based on the width | - | ||||||||||||||||||||||||||||||||||||||||||||||||
390 | // of visible scroll bars. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
391 | int scrollBarExtent = q->style()->pixelMetric(QStyle::PM_ScrollBarExtent, 0, q); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
392 | if (frameOnlyAround)
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
393 | scrollBarExtent += frameWidth * 2; never executed: scrollBarExtent += frameWidth * 2; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
394 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
395 | // We do not need to subtract the width scrollbars whose policy is | - | ||||||||||||||||||||||||||||||||||||||||||||||||
396 | // Qt::ScrollBarAlwaysOn, this was already done by maximumViewportSize(). | - | ||||||||||||||||||||||||||||||||||||||||||||||||
397 | bool useHorizontalScrollBar = (viewRect.width() > width) && hbarpolicy == Qt::ScrollBarAsNeeded;
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
398 | bool useVerticalScrollBar = (viewRect.height() > height) && vbarpolicy == Qt::ScrollBarAsNeeded;
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
399 | if (useHorizontalScrollBar && vbarpolicy == Qt::ScrollBarAsNeeded) {
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
400 | if (viewRect.height() > height - scrollBarExtent)
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
401 | useVerticalScrollBar = true; never executed: useVerticalScrollBar = true; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
402 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
403 | if (useVerticalScrollBar && hbarpolicy == Qt::ScrollBarAsNeeded) {
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
404 | if (viewRect.width() > width - scrollBarExtent)
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
405 | useHorizontalScrollBar = true; never executed: useHorizontalScrollBar = true; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
406 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
407 | if (useHorizontalScrollBar)
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
408 | height -= scrollBarExtent; never executed: height -= scrollBarExtent; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
409 | if (useVerticalScrollBar)
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
410 | width -= scrollBarExtent; never executed: width -= scrollBarExtent; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
411 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
412 | // Setting the ranges of these scroll bars can/will cause the values to | - | ||||||||||||||||||||||||||||||||||||||||||||||||
413 | // change, and scrollContentsBy() will be called correspondingly. This | - | ||||||||||||||||||||||||||||||||||||||||||||||||
414 | // will reset the last center point. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
415 | QPointF savedLastCenterPoint = lastCenterPoint; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
416 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
417 | // Remember the former indent settings | - | ||||||||||||||||||||||||||||||||||||||||||||||||
418 | qreal oldLeftIndent = leftIndent; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
419 | qreal oldTopIndent = topIndent; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
420 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
421 | // If the whole scene fits horizontally, we center the scene horizontally, | - | ||||||||||||||||||||||||||||||||||||||||||||||||
422 | // and ignore the horizontal scroll bars. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
423 | int left = q_round_bound(viewRect.left()); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
424 | int right = q_round_bound(viewRect.right() - width); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
425 | if (left >= right) {
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
426 | hbar->setRange(0, 0); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
427 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
428 | switch (alignment & Qt::AlignHorizontal_Mask) { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
429 | case Qt::AlignLeft: never executed: case Qt::AlignLeft: | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
430 | leftIndent = -viewRect.left(); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
431 | break; never executed: break; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
432 | case Qt::AlignRight: never executed: case Qt::AlignRight: | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
433 | leftIndent = width - viewRect.width() - viewRect.left() - 1; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
434 | break; never executed: break; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
435 | case Qt::AlignHCenter: never executed: case Qt::AlignHCenter: | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
436 | default: never executed: default: | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
437 | leftIndent = width / 2 - (viewRect.left() + viewRect.right()) / 2; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
438 | break; never executed: break; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
439 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||
440 | } else { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
441 | hbar->setRange(left, right); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
442 | hbar->setPageStep(width); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
443 | hbar->setSingleStep(width / 20); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
444 | leftIndent = 0; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
445 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
446 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
447 | // If the whole scene fits vertically, we center the scene vertically, and | - | ||||||||||||||||||||||||||||||||||||||||||||||||
448 | // ignore the vertical scroll bars. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
449 | int top = q_round_bound(viewRect.top()); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
450 | int bottom = q_round_bound(viewRect.bottom() - height); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
451 | if (top >= bottom) {
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
452 | vbar->setRange(0, 0); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
453 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
454 | switch (alignment & Qt::AlignVertical_Mask) { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
455 | case Qt::AlignTop: never executed: case Qt::AlignTop: | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
456 | topIndent = -viewRect.top(); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
457 | break; never executed: break; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
458 | case Qt::AlignBottom: never executed: case Qt::AlignBottom: | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
459 | topIndent = height - viewRect.height() - viewRect.top() - 1; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
460 | break; never executed: break; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
461 | case Qt::AlignVCenter: never executed: case Qt::AlignVCenter: | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
462 | default: never executed: default: | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
463 | topIndent = height / 2 - (viewRect.top() + viewRect.bottom()) / 2; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
464 | break; never executed: break; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
465 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||
466 | } else { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
467 | vbar->setRange(top, bottom); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
468 | vbar->setPageStep(height); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
469 | vbar->setSingleStep(height / 20); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
470 | topIndent = 0; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
471 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
472 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
473 | // Restorethe center point from before the ranges changed. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
474 | lastCenterPoint = savedLastCenterPoint; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
475 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
476 | // Issue a full update if the indents change. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
477 | // ### If the transform is still the same, we can get away with just a | - | ||||||||||||||||||||||||||||||||||||||||||||||||
478 | // scroll instead. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
479 | if (oldLeftIndent != leftIndent || oldTopIndent != topIndent) {
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
480 | dirtyScroll = true; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
481 | updateAll(); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
482 | } else if (q->isRightToLeft() && !leftIndent) { never executed: end of block
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
483 | // In reverse mode, the horizontal scroll always changes after the content | - | ||||||||||||||||||||||||||||||||||||||||||||||||
484 | // size has changed, as the scroll is calculated by summing the min and | - | ||||||||||||||||||||||||||||||||||||||||||||||||
485 | // max values of the range and subtracting the current value. In normal | - | ||||||||||||||||||||||||||||||||||||||||||||||||
486 | // mode the scroll remains unchanged unless the indent has changed. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
487 | dirtyScroll = true; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
488 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
489 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
490 | if (cacheMode & QGraphicsView::CacheBackground) {
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
491 | // Invalidate the background pixmap | - | ||||||||||||||||||||||||||||||||||||||||||||||||
492 | mustResizeBackgroundPixmap = true; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
493 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
494 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
495 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
496 | /*! | - | ||||||||||||||||||||||||||||||||||||||||||||||||
497 | \internal | - | ||||||||||||||||||||||||||||||||||||||||||||||||
498 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
499 | void QGraphicsViewPrivate::centerView(QGraphicsView::ViewportAnchor anchor) | - | ||||||||||||||||||||||||||||||||||||||||||||||||
500 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
501 | Q_Q(QGraphicsView); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
502 | switch (anchor) { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
503 | case QGraphicsView::AnchorUnderMouse: { never executed: case QGraphicsView::AnchorUnderMouse: | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
504 | if (q->underMouse()) {
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
505 | // Last scene pos: lastMouseMoveScenePoint | - | ||||||||||||||||||||||||||||||||||||||||||||||||
506 | // Current mouse pos: | - | ||||||||||||||||||||||||||||||||||||||||||||||||
507 | QPointF transformationDiff = q->mapToScene(viewport->rect().center()) | - | ||||||||||||||||||||||||||||||||||||||||||||||||
508 | - q->mapToScene(viewport->mapFromGlobal(QCursor::pos())); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
509 | q->centerOn(lastMouseMoveScenePoint + transformationDiff); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
510 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
511 | q->centerOn(lastCenterPoint); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
512 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
513 | break; never executed: break; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
514 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||
515 | case QGraphicsView::AnchorViewCenter: never executed: case QGraphicsView::AnchorViewCenter: | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
516 | q->centerOn(lastCenterPoint); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
517 | break; never executed: break; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
518 | case QGraphicsView::NoAnchor: never executed: case QGraphicsView::NoAnchor: | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
519 | break; never executed: break; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
520 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||
521 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
522 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
523 | /*! | - | ||||||||||||||||||||||||||||||||||||||||||||||||
524 | \internal | - | ||||||||||||||||||||||||||||||||||||||||||||||||
525 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
526 | void QGraphicsViewPrivate::updateLastCenterPoint() | - | ||||||||||||||||||||||||||||||||||||||||||||||||
527 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
528 | Q_Q(QGraphicsView); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
529 | lastCenterPoint = q->mapToScene(viewport->rect().center()); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
530 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
531 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
532 | /*! | - | ||||||||||||||||||||||||||||||||||||||||||||||||
533 | \internal | - | ||||||||||||||||||||||||||||||||||||||||||||||||
534 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
535 | Returns the horizontal scroll value (the X value of the left edge of the | - | ||||||||||||||||||||||||||||||||||||||||||||||||
536 | viewport). | - | ||||||||||||||||||||||||||||||||||||||||||||||||
537 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
538 | qint64 QGraphicsViewPrivate::horizontalScroll() const | - | ||||||||||||||||||||||||||||||||||||||||||||||||
539 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
540 | if (dirtyScroll)
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
541 | const_cast<QGraphicsViewPrivate *>(this)->updateScroll(); never executed: const_cast<QGraphicsViewPrivate *>(this)->updateScroll(); | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
542 | return scrollX; never executed: return scrollX; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
543 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||
544 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
545 | /*! | - | ||||||||||||||||||||||||||||||||||||||||||||||||
546 | \internal | - | ||||||||||||||||||||||||||||||||||||||||||||||||
547 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
548 | Returns the vertical scroll value (the X value of the top edge of the | - | ||||||||||||||||||||||||||||||||||||||||||||||||
549 | viewport). | - | ||||||||||||||||||||||||||||||||||||||||||||||||
550 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
551 | qint64 QGraphicsViewPrivate::verticalScroll() const | - | ||||||||||||||||||||||||||||||||||||||||||||||||
552 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
553 | if (dirtyScroll)
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
554 | const_cast<QGraphicsViewPrivate *>(this)->updateScroll(); never executed: const_cast<QGraphicsViewPrivate *>(this)->updateScroll(); | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
555 | return scrollY; never executed: return scrollY; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
556 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||
557 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
558 | /*! | - | ||||||||||||||||||||||||||||||||||||||||||||||||
559 | \internal | - | ||||||||||||||||||||||||||||||||||||||||||||||||
560 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
561 | Maps the given rectangle to the scene using QTransform::mapRect() | - | ||||||||||||||||||||||||||||||||||||||||||||||||
562 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
563 | QRectF QGraphicsViewPrivate::mapRectToScene(const QRect &rect) const | - | ||||||||||||||||||||||||||||||||||||||||||||||||
564 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
565 | if (dirtyScroll)
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
566 | const_cast<QGraphicsViewPrivate *>(this)->updateScroll(); never executed: const_cast<QGraphicsViewPrivate *>(this)->updateScroll(); | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
567 | QRectF scrolled = QRectF(rect.translated(scrollX, scrollY)); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
568 | return identityMatrix ? scrolled : matrix.inverted().mapRect(scrolled); never executed: return identityMatrix ? scrolled : matrix.inverted().mapRect(scrolled);
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
569 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||
570 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
571 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
572 | /*! | - | ||||||||||||||||||||||||||||||||||||||||||||||||
573 | \internal | - | ||||||||||||||||||||||||||||||||||||||||||||||||
574 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
575 | Maps the given rectangle from the scene using QTransform::mapRect() | - | ||||||||||||||||||||||||||||||||||||||||||||||||
576 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
577 | QRectF QGraphicsViewPrivate::mapRectFromScene(const QRectF &rect) const | - | ||||||||||||||||||||||||||||||||||||||||||||||||
578 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
579 | if (dirtyScroll)
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
580 | const_cast<QGraphicsViewPrivate *>(this)->updateScroll(); never executed: const_cast<QGraphicsViewPrivate *>(this)->updateScroll(); | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
581 | return (identityMatrix ? rect : matrix.mapRect(rect)).translated(-scrollX, -scrollY); never executed: return (identityMatrix ? rect : matrix.mapRect(rect)).translated(-scrollX, -scrollY);
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
582 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||
583 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
584 | /*! | - | ||||||||||||||||||||||||||||||||||||||||||||||||
585 | \internal | - | ||||||||||||||||||||||||||||||||||||||||||||||||
586 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
587 | void QGraphicsViewPrivate::updateScroll() | - | ||||||||||||||||||||||||||||||||||||||||||||||||
588 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
589 | Q_Q(QGraphicsView); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
590 | scrollX = qint64(-leftIndent); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
591 | if (q->isRightToLeft()) {
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
592 | if (!leftIndent) {
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
593 | scrollX += hbar->minimum(); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
594 | scrollX += hbar->maximum(); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
595 | scrollX -= hbar->value(); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
596 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
597 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
598 | scrollX += hbar->value(); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
599 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
600 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
601 | scrollY = qint64(vbar->value() - topIndent); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
602 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
603 | dirtyScroll = false; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
604 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
605 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
606 | /*! | - | ||||||||||||||||||||||||||||||||||||||||||||||||
607 | \internal | - | ||||||||||||||||||||||||||||||||||||||||||||||||
608 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
609 | void QGraphicsViewPrivate::replayLastMouseEvent() | - | ||||||||||||||||||||||||||||||||||||||||||||||||
610 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
611 | if (!useLastMouseEvent || !scene)
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
612 | return; never executed: return; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
613 | mouseMoveEventHandler(&lastMouseEvent); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
614 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
615 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
616 | /*! | - | ||||||||||||||||||||||||||||||||||||||||||||||||
617 | \internal | - | ||||||||||||||||||||||||||||||||||||||||||||||||
618 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
619 | void QGraphicsViewPrivate::storeMouseEvent(QMouseEvent *event) | - | ||||||||||||||||||||||||||||||||||||||||||||||||
620 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
621 | useLastMouseEvent = true; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
622 | lastMouseEvent = QMouseEvent(QEvent::MouseMove, event->localPos(), event->windowPos(), event->screenPos(), | - | ||||||||||||||||||||||||||||||||||||||||||||||||
623 | event->button(), event->buttons(), event->modifiers()); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
624 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
625 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
626 | void QGraphicsViewPrivate::mouseMoveEventHandler(QMouseEvent *event) | - | ||||||||||||||||||||||||||||||||||||||||||||||||
627 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
628 | Q_Q(QGraphicsView); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
629 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
630 | #ifndef QT_NO_RUBBERBAND | - | ||||||||||||||||||||||||||||||||||||||||||||||||
631 | updateRubberBand(event); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
632 | #endif | - | ||||||||||||||||||||||||||||||||||||||||||||||||
633 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
634 | storeMouseEvent(event); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
635 | lastMouseEvent.setAccepted(false); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
636 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
637 | if (!sceneInteractionAllowed)
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
638 | return; never executed: return; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
639 | if (handScrolling)
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
640 | return; never executed: return; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
641 | if (!scene)
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
642 | return; never executed: return; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
643 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
644 | QGraphicsSceneMouseEvent mouseEvent(QEvent::GraphicsSceneMouseMove); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
645 | mouseEvent.setWidget(viewport); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
646 | mouseEvent.setButtonDownScenePos(mousePressButton, mousePressScenePoint); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
647 | mouseEvent.setButtonDownScreenPos(mousePressButton, mousePressScreenPoint); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
648 | mouseEvent.setScenePos(q->mapToScene(event->pos())); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
649 | mouseEvent.setScreenPos(event->globalPos()); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
650 | mouseEvent.setLastScenePos(lastMouseMoveScenePoint); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
651 | mouseEvent.setLastScreenPos(lastMouseMoveScreenPoint); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
652 | mouseEvent.setButtons(event->buttons()); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
653 | mouseEvent.setButton(event->button()); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
654 | mouseEvent.setModifiers(event->modifiers()); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
655 | mouseEvent.setSource(event->source()); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
656 | mouseEvent.setFlags(event->flags()); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
657 | lastMouseMoveScenePoint = mouseEvent.scenePos(); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
658 | lastMouseMoveScreenPoint = mouseEvent.screenPos(); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
659 | mouseEvent.setAccepted(false); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
660 | if (event->spontaneous())
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
661 | qt_sendSpontaneousEvent(scene, &mouseEvent); never executed: qt_sendSpontaneousEvent(scene, &mouseEvent); | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
662 | else | - | ||||||||||||||||||||||||||||||||||||||||||||||||
663 | QApplication::sendEvent(scene, &mouseEvent); never executed: QApplication::sendEvent(scene, &mouseEvent); | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
664 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
665 | // Remember whether the last event was accepted or not. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
666 | lastMouseEvent.setAccepted(mouseEvent.isAccepted()); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
667 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
668 | if (mouseEvent.isAccepted() && mouseEvent.buttons() != 0) {
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
669 | // The event was delivered to a mouse grabber; the press is likely to | - | ||||||||||||||||||||||||||||||||||||||||||||||||
670 | // have set a cursor, and we must not change it. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
671 | return; never executed: return; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
672 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||
673 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
674 | #ifndef QT_NO_CURSOR | - | ||||||||||||||||||||||||||||||||||||||||||||||||
675 | // If all the items ignore hover events, we don't look-up any items | - | ||||||||||||||||||||||||||||||||||||||||||||||||
676 | // in QGraphicsScenePrivate::dispatchHoverEvent, hence the | - | ||||||||||||||||||||||||||||||||||||||||||||||||
677 | // cachedItemsUnderMouse list will be empty. We therefore do the look-up | - | ||||||||||||||||||||||||||||||||||||||||||||||||
678 | // for cursor items here if not all items use the default cursor. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
679 | if (scene->d_func()->allItemsIgnoreHoverEvents && !scene->d_func()->allItemsUseDefaultCursor
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
680 | && scene->d_func()->cachedItemsUnderMouse.isEmpty()) {
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
681 | scene->d_func()->cachedItemsUnderMouse = scene->d_func()->itemsAtPosition(mouseEvent.screenPos(), | - | ||||||||||||||||||||||||||||||||||||||||||||||||
682 | mouseEvent.scenePos(), | - | ||||||||||||||||||||||||||||||||||||||||||||||||
683 | mouseEvent.widget()); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
684 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
685 | // Find the topmost item under the mouse with a cursor. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
686 | foreach (QGraphicsItem *item, scene->d_func()->cachedItemsUnderMouse) { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
687 | if (item->hasCursor()) {
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
688 | _q_setViewportCursor(item->cursor()); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
689 | return; never executed: return; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
690 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||
691 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
692 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
693 | // No items with cursors found; revert to the view cursor. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
694 | if (hasStoredOriginalCursor) {
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
695 | // Restore the original viewport cursor. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
696 | hasStoredOriginalCursor = false; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
697 | viewport->setCursor(originalCursor); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
698 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
699 | #endif | - | ||||||||||||||||||||||||||||||||||||||||||||||||
700 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
701 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
702 | /*! | - | ||||||||||||||||||||||||||||||||||||||||||||||||
703 | \internal | - | ||||||||||||||||||||||||||||||||||||||||||||||||
704 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
705 | #ifndef QT_NO_RUBBERBAND | - | ||||||||||||||||||||||||||||||||||||||||||||||||
706 | QRegion QGraphicsViewPrivate::rubberBandRegion(const QWidget *widget, const QRect &rect) const | - | ||||||||||||||||||||||||||||||||||||||||||||||||
707 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
708 | QStyleHintReturnMask mask; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
709 | QStyleOptionRubberBand option; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
710 | option.initFrom(widget); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
711 | option.rect = rect; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
712 | option.opaque = false; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
713 | option.shape = QRubberBand::Rectangle; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
714 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
715 | QRegion tmp; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
716 | tmp += rect; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
717 | if (widget->style()->styleHint(QStyle::SH_RubberBand_Mask, &option, widget, &mask))
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
718 | tmp &= mask.region; never executed: tmp &= mask.region; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
719 | return tmp; never executed: return tmp; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
720 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||
721 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
722 | void QGraphicsViewPrivate::updateRubberBand(const QMouseEvent *event) | - | ||||||||||||||||||||||||||||||||||||||||||||||||
723 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
724 | Q_Q(QGraphicsView); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
725 | if (dragMode != QGraphicsView::RubberBandDrag || !sceneInteractionAllowed || !rubberBanding)
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
726 | return; never executed: return; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
727 | // Check for enough drag distance | - | ||||||||||||||||||||||||||||||||||||||||||||||||
728 | if ((mousePressViewPoint - event->pos()).manhattanLength() < QApplication::startDragDistance())
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
729 | return; never executed: return; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
730 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
731 | // Update old rubberband | - | ||||||||||||||||||||||||||||||||||||||||||||||||
732 | if (viewportUpdateMode != QGraphicsView::NoViewportUpdate && !rubberBandRect.isEmpty()) {
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
733 | if (viewportUpdateMode != QGraphicsView::FullViewportUpdate)
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
734 | q->viewport()->update(rubberBandRegion(q->viewport(), rubberBandRect)); never executed: q->viewport()->update(rubberBandRegion(q->viewport(), rubberBandRect)); | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
735 | else | - | ||||||||||||||||||||||||||||||||||||||||||||||||
736 | updateAll(); never executed: updateAll(); | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
737 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||
738 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
739 | // Stop rubber banding if the user has let go of all buttons (even | - | ||||||||||||||||||||||||||||||||||||||||||||||||
740 | // if we didn't get the release events). | - | ||||||||||||||||||||||||||||||||||||||||||||||||
741 | if (!event->buttons()) {
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
742 | rubberBanding = false; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
743 | rubberBandSelectionOperation = Qt::ReplaceSelection; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
744 | if (!rubberBandRect.isNull()) {
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
745 | rubberBandRect = QRect(); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
746 | emit q->rubberBandChanged(rubberBandRect, QPointF(), QPointF()); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
747 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
748 | return; never executed: return; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
749 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||
750 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
751 | QRect oldRubberband = rubberBandRect; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
752 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
753 | // Update rubberband position | - | ||||||||||||||||||||||||||||||||||||||||||||||||
754 | const QPoint mp = q->mapFromScene(mousePressScenePoint); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
755 | const QPoint ep = event->pos(); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
756 | rubberBandRect = QRect(qMin(mp.x(), ep.x()), qMin(mp.y(), ep.y()), | - | ||||||||||||||||||||||||||||||||||||||||||||||||
757 | qAbs(mp.x() - ep.x()) + 1, qAbs(mp.y() - ep.y()) + 1); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
758 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
759 | if (rubberBandRect != oldRubberband || lastRubberbandScenePoint != lastMouseMoveScenePoint) {
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
760 | lastRubberbandScenePoint = lastMouseMoveScenePoint; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
761 | oldRubberband = rubberBandRect; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
762 | emit q->rubberBandChanged(rubberBandRect, mousePressScenePoint, lastRubberbandScenePoint); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
763 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
764 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
765 | // Update new rubberband | - | ||||||||||||||||||||||||||||||||||||||||||||||||
766 | if (viewportUpdateMode != QGraphicsView::NoViewportUpdate) {
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
767 | if (viewportUpdateMode != QGraphicsView::FullViewportUpdate)
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
768 | q->viewport()->update(rubberBandRegion(q->viewport(), rubberBandRect)); never executed: q->viewport()->update(rubberBandRegion(q->viewport(), rubberBandRect)); | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
769 | else | - | ||||||||||||||||||||||||||||||||||||||||||||||||
770 | updateAll(); never executed: updateAll(); | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
771 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||
772 | // Set the new selection area | - | ||||||||||||||||||||||||||||||||||||||||||||||||
773 | QPainterPath selectionArea; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
774 | selectionArea.addPolygon(q->mapToScene(rubberBandRect)); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
775 | selectionArea.closeSubpath(); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
776 | if (scene)
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
777 | scene->setSelectionArea(selectionArea, rubberBandSelectionOperation, rubberBandSelectionMode, q->viewportTransform()); never executed: scene->setSelectionArea(selectionArea, rubberBandSelectionOperation, rubberBandSelectionMode, q->viewportTransform()); | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
778 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
779 | #endif | - | ||||||||||||||||||||||||||||||||||||||||||||||||
780 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
781 | /*! | - | ||||||||||||||||||||||||||||||||||||||||||||||||
782 | \internal | - | ||||||||||||||||||||||||||||||||||||||||||||||||
783 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
784 | #ifndef QT_NO_CURSOR | - | ||||||||||||||||||||||||||||||||||||||||||||||||
785 | void QGraphicsViewPrivate::_q_setViewportCursor(const QCursor &cursor) | - | ||||||||||||||||||||||||||||||||||||||||||||||||
786 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
787 | if (!hasStoredOriginalCursor) {
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
788 | hasStoredOriginalCursor = true; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
789 | originalCursor = viewport->cursor(); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
790 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
791 | viewport->setCursor(cursor); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
792 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
793 | #endif | - | ||||||||||||||||||||||||||||||||||||||||||||||||
794 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
795 | /*! | - | ||||||||||||||||||||||||||||||||||||||||||||||||
796 | \internal | - | ||||||||||||||||||||||||||||||||||||||||||||||||
797 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
798 | #ifndef QT_NO_CURSOR | - | ||||||||||||||||||||||||||||||||||||||||||||||||
799 | void QGraphicsViewPrivate::_q_unsetViewportCursor() | - | ||||||||||||||||||||||||||||||||||||||||||||||||
800 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
801 | Q_Q(QGraphicsView); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
802 | foreach (QGraphicsItem *item, q->items(lastMouseEvent.pos())) { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
803 | if (item->hasCursor()) {
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
804 | _q_setViewportCursor(item->cursor()); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
805 | return; never executed: return; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
806 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||
807 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
808 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
809 | // Restore the original viewport cursor. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
810 | if (hasStoredOriginalCursor) {
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
811 | hasStoredOriginalCursor = false; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
812 | if (dragMode == QGraphicsView::ScrollHandDrag)
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
813 | viewport->setCursor(Qt::OpenHandCursor); never executed: viewport->setCursor(Qt::OpenHandCursor); | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
814 | else | - | ||||||||||||||||||||||||||||||||||||||||||||||||
815 | viewport->setCursor(originalCursor); never executed: viewport->setCursor(originalCursor); | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
816 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||
817 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
818 | #endif | - | ||||||||||||||||||||||||||||||||||||||||||||||||
819 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
820 | /*! | - | ||||||||||||||||||||||||||||||||||||||||||||||||
821 | \internal | - | ||||||||||||||||||||||||||||||||||||||||||||||||
822 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
823 | void QGraphicsViewPrivate::storeDragDropEvent(const QGraphicsSceneDragDropEvent *event) | - | ||||||||||||||||||||||||||||||||||||||||||||||||
824 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
825 | delete lastDragDropEvent; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
826 | lastDragDropEvent = new QGraphicsSceneDragDropEvent(event->type()); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
827 | lastDragDropEvent->setScenePos(event->scenePos()); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
828 | lastDragDropEvent->setScreenPos(event->screenPos()); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
829 | lastDragDropEvent->setButtons(event->buttons()); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
830 | lastDragDropEvent->setModifiers(event->modifiers()); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
831 | lastDragDropEvent->setPossibleActions(event->possibleActions()); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
832 | lastDragDropEvent->setProposedAction(event->proposedAction()); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
833 | lastDragDropEvent->setDropAction(event->dropAction()); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
834 | lastDragDropEvent->setMimeData(event->mimeData()); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
835 | lastDragDropEvent->setWidget(event->widget()); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
836 | lastDragDropEvent->setSource(event->source()); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
837 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
838 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
839 | /*! | - | ||||||||||||||||||||||||||||||||||||||||||||||||
840 | \internal | - | ||||||||||||||||||||||||||||||||||||||||||||||||
841 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
842 | void QGraphicsViewPrivate::populateSceneDragDropEvent(QGraphicsSceneDragDropEvent *dest, | - | ||||||||||||||||||||||||||||||||||||||||||||||||
843 | QDropEvent *source) | - | ||||||||||||||||||||||||||||||||||||||||||||||||
844 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
845 | #ifndef QT_NO_DRAGANDDROP | - | ||||||||||||||||||||||||||||||||||||||||||||||||
846 | Q_Q(QGraphicsView); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
847 | dest->setScenePos(q->mapToScene(source->pos())); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
848 | dest->setScreenPos(q->mapToGlobal(source->pos())); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
849 | dest->setButtons(source->mouseButtons()); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
850 | dest->setModifiers(source->keyboardModifiers()); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
851 | dest->setPossibleActions(source->possibleActions()); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
852 | dest->setProposedAction(source->proposedAction()); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
853 | dest->setDropAction(source->dropAction()); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
854 | dest->setMimeData(source->mimeData()); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
855 | dest->setWidget(viewport); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
856 | dest->setSource(qobject_cast<QWidget *>(source->source())); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
857 | #else | - | ||||||||||||||||||||||||||||||||||||||||||||||||
858 | Q_UNUSED(dest) | - | ||||||||||||||||||||||||||||||||||||||||||||||||
859 | Q_UNUSED(source) | - | ||||||||||||||||||||||||||||||||||||||||||||||||
860 | #endif | - | ||||||||||||||||||||||||||||||||||||||||||||||||
861 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
862 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
863 | /*! | - | ||||||||||||||||||||||||||||||||||||||||||||||||
864 | \internal | - | ||||||||||||||||||||||||||||||||||||||||||||||||
865 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
866 | QRect QGraphicsViewPrivate::mapToViewRect(const QGraphicsItem *item, const QRectF &rect) const | - | ||||||||||||||||||||||||||||||||||||||||||||||||
867 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
868 | Q_Q(const QGraphicsView); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
869 | if (dirtyScroll)
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
870 | const_cast<QGraphicsViewPrivate *>(this)->updateScroll(); never executed: const_cast<QGraphicsViewPrivate *>(this)->updateScroll(); | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
871 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
872 | if (item->d_ptr->itemIsUntransformable()) {
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
873 | QTransform itv = item->deviceTransform(q->viewportTransform()); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
874 | return itv.mapRect(rect).toAlignedRect(); never executed: return itv.mapRect(rect).toAlignedRect(); | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
875 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||
876 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
877 | // Translate-only | - | ||||||||||||||||||||||||||||||||||||||||||||||||
878 | // COMBINE | - | ||||||||||||||||||||||||||||||||||||||||||||||||
879 | QPointF offset; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
880 | const QGraphicsItem *parentItem = item; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
881 | const QGraphicsItemPrivate *itemd; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
882 | do { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
883 | itemd = parentItem->d_ptr.data(); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
884 | if (itemd->transformData)
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
885 | break; never executed: break; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
886 | offset += itemd->pos; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
887 | } while ((parentItem = itemd->parent)); never executed: end of block
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
888 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
889 | QRectF baseRect = rect.translated(offset.x(), offset.y()); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
890 | if (!parentItem) {
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
891 | if (identityMatrix) {
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
892 | baseRect.translate(-scrollX, -scrollY); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
893 | return baseRect.toAlignedRect(); never executed: return baseRect.toAlignedRect(); | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
894 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||
895 | return matrix.mapRect(baseRect).translated(-scrollX, -scrollY).toAlignedRect(); never executed: return matrix.mapRect(baseRect).translated(-scrollX, -scrollY).toAlignedRect(); | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
896 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||
897 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
898 | QTransform tr = parentItem->sceneTransform(); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
899 | if (!identityMatrix)
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
900 | tr *= matrix; never executed: tr *= matrix; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
901 | QRectF r = tr.mapRect(baseRect); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
902 | r.translate(-scrollX, -scrollY); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
903 | return r.toAlignedRect(); never executed: return r.toAlignedRect(); | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
904 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||
905 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
906 | /*! | - | ||||||||||||||||||||||||||||||||||||||||||||||||
907 | \internal | - | ||||||||||||||||||||||||||||||||||||||||||||||||
908 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
909 | QRegion QGraphicsViewPrivate::mapToViewRegion(const QGraphicsItem *item, const QRectF &rect) const | - | ||||||||||||||||||||||||||||||||||||||||||||||||
910 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
911 | Q_Q(const QGraphicsView); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
912 | if (dirtyScroll)
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
913 | const_cast<QGraphicsViewPrivate *>(this)->updateScroll(); never executed: const_cast<QGraphicsViewPrivate *>(this)->updateScroll(); | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
914 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
915 | // Accurate bounding region | - | ||||||||||||||||||||||||||||||||||||||||||||||||
916 | QTransform itv = item->deviceTransform(q->viewportTransform()); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
917 | return item->boundingRegion(itv) & itv.mapRect(rect).toAlignedRect(); never executed: return item->boundingRegion(itv) & itv.mapRect(rect).toAlignedRect(); | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
918 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||
919 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
920 | /*! | - | ||||||||||||||||||||||||||||||||||||||||||||||||
921 | \internal | - | ||||||||||||||||||||||||||||||||||||||||||||||||
922 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
923 | void QGraphicsViewPrivate::processPendingUpdates() | - | ||||||||||||||||||||||||||||||||||||||||||||||||
924 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
925 | if (!scene)
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
926 | return; never executed: return; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
927 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
928 | if (fullUpdatePending) {
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
929 | viewport->update(); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
930 | } else if (viewportUpdateMode == QGraphicsView::BoundingRectViewportUpdate) { never executed: end of block
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
931 | viewport->update(dirtyBoundingRect); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
932 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
933 | viewport->update(dirtyRegion); // Already adjusted in updateRect/Region. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
934 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
935 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
936 | dirtyBoundingRect = QRect(); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
937 | dirtyRegion = QRegion(); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
938 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
939 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
940 | static inline bool intersectsViewport(const QRect &r, int width, int height) | - | ||||||||||||||||||||||||||||||||||||||||||||||||
941 | { never executed: return !(r.left() > width) && !(r.right() < 0) && !(r.top() >= height) && !(r.bottom() < 0);
never executed: return !(r.left() > width) && !(r.right() < 0) && !(r.top() >= height) && !(r.bottom() < 0);
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
942 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
943 | static inline bool containsViewport(const QRect &r, int width, int height) | - | ||||||||||||||||||||||||||||||||||||||||||||||||
944 | { never executed: return r.left() <= 0 && r.top() <= 0 && r.right() >= width - 1 && r.bottom() >= height - 1;
never executed: return r.left() <= 0 && r.top() <= 0 && r.right() >= width - 1 && r.bottom() >= height - 1;
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
945 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
946 | static inline void QRect_unite(QRect *rect, const QRect &other) | - | ||||||||||||||||||||||||||||||||||||||||||||||||
947 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
948 | if (rect->isEmpty()) {
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
949 | *rect = other; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
950 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
951 | rect->setCoords(qMin(rect->left(), other.left()), qMin(rect->top(), other.top()), | - | ||||||||||||||||||||||||||||||||||||||||||||||||
952 | qMax(rect->right(), other.right()), qMax(rect->bottom(), other.bottom())); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
953 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
954 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||
955 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
956 | /* | - | ||||||||||||||||||||||||||||||||||||||||||||||||
957 | Calling this function results in update rects being clipped to the item's | - | ||||||||||||||||||||||||||||||||||||||||||||||||
958 | bounding rect. Note that updates prior to this function call is not clipped. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
959 | The clip is removed by passing 0. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
960 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
961 | void QGraphicsViewPrivate::setUpdateClip(QGraphicsItem *item) | - | ||||||||||||||||||||||||||||||||||||||||||||||||
962 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
963 | Q_Q(QGraphicsView); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
964 | // We simply ignore the request if the update mode is either FullViewportUpdate | - | ||||||||||||||||||||||||||||||||||||||||||||||||
965 | // or NoViewportUpdate; in that case there's no point in clipping anything. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
966 | if (!item || viewportUpdateMode == QGraphicsView::NoViewportUpdate
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
967 | || viewportUpdateMode == QGraphicsView::FullViewportUpdate) {
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
968 | hasUpdateClip = false; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
969 | return; never executed: return; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
970 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||
971 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
972 | // Calculate the clip (item's bounding rect in view coordinates). | - | ||||||||||||||||||||||||||||||||||||||||||||||||
973 | // Optimized version of: | - | ||||||||||||||||||||||||||||||||||||||||||||||||
974 | // QRect clip = item->deviceTransform(q->viewportTransform()) | - | ||||||||||||||||||||||||||||||||||||||||||||||||
975 | // .mapRect(item->boundingRect()).toAlignedRect(); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
976 | QRect clip; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
977 | if (item->d_ptr->itemIsUntransformable()) {
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
978 | QTransform xform = item->deviceTransform(q->viewportTransform()); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
979 | clip = xform.mapRect(item->boundingRect()).toAlignedRect(); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
980 | } else if (item->d_ptr->sceneTransformTranslateOnly && identityMatrix) { never executed: end of block
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
981 | QRectF r(item->boundingRect()); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
982 | r.translate(item->d_ptr->sceneTransform.dx() - horizontalScroll(), | - | ||||||||||||||||||||||||||||||||||||||||||||||||
983 | item->d_ptr->sceneTransform.dy() - verticalScroll()); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
984 | clip = r.toAlignedRect(); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
985 | } else if (!q->isTransformed()) { never executed: end of block
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
986 | clip = item->d_ptr->sceneTransform.mapRect(item->boundingRect()).toAlignedRect(); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
987 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
988 | QTransform xform = item->d_ptr->sceneTransform; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
989 | xform *= q->viewportTransform(); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
990 | clip = xform.mapRect(item->boundingRect()).toAlignedRect(); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
991 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
992 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
993 | if (hasUpdateClip) {
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
994 | // Intersect with old clip. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
995 | updateClip &= clip; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
996 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
997 | updateClip = clip; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
998 | hasUpdateClip = true; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
999 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
1000 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1001 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
1002 | bool QGraphicsViewPrivate::updateRegion(const QRectF &rect, const QTransform &xform) | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1003 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1004 | if (rect.isEmpty())
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
1005 | return false; never executed: return false; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
1006 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
1007 | if (viewportUpdateMode != QGraphicsView::MinimalViewportUpdate
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
1008 | && viewportUpdateMode != QGraphicsView::SmartViewportUpdate) {
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
1009 | // No point in updating with QRegion granularity; use the rect instead. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1010 | return updateRectF(xform.mapRect(rect)); never executed: return updateRectF(xform.mapRect(rect)); | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
1011 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1012 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
1013 | // Update mode is either Minimal or Smart, so we have to do a potentially slow operation, | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1014 | // which is clearly documented here: QGraphicsItem::setBoundingRegionGranularity. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1015 | const QRegion region = xform.map(QRegion(rect.toAlignedRect())); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1016 | QRect viewRect = region.boundingRect(); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1017 | const bool dontAdjustForAntialiasing = optimizationFlags & QGraphicsView::DontAdjustForAntialiasing; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1018 | if (dontAdjustForAntialiasing)
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
1019 | viewRect.adjust(-1, -1, 1, 1); never executed: viewRect.adjust(-1, -1, 1, 1); | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
1020 | else | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1021 | viewRect.adjust(-2, -2, 2, 2); never executed: viewRect.adjust(-2, -2, 2, 2); | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
1022 | if (!intersectsViewport(viewRect, viewport->width(), viewport->height()))
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
1023 | return false; // Update region for sure outside viewport. never executed: return false; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
1024 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
1025 | const QVector<QRect> &rects = region.rects(); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1026 | for (int i = 0; i < rects.size(); ++i) {
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
1027 | viewRect = rects.at(i); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1028 | if (dontAdjustForAntialiasing)
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
1029 | viewRect.adjust(-1, -1, 1, 1); never executed: viewRect.adjust(-1, -1, 1, 1); | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
1030 | else | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1031 | viewRect.adjust(-2, -2, 2, 2); never executed: viewRect.adjust(-2, -2, 2, 2); | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
1032 | if (hasUpdateClip)
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
1033 | viewRect &= updateClip; never executed: viewRect &= updateClip; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
1034 | dirtyRegion += viewRect; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1035 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
1036 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
1037 | return true; never executed: return true; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
1038 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1039 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
1040 | // NB! Assumes the rect 'r' is already aligned and adjusted for antialiasing. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1041 | // For QRectF use updateRectF(const QRectF &) to ensure proper adjustments. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1042 | bool QGraphicsViewPrivate::updateRect(const QRect &r) | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1043 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1044 | if (fullUpdatePending || viewportUpdateMode == QGraphicsView::NoViewportUpdate
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
1045 | || !intersectsViewport(r, viewport->width(), viewport->height())) {
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
1046 | return false; never executed: return false; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
1047 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1048 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
1049 | switch (viewportUpdateMode) { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1050 | case QGraphicsView::FullViewportUpdate: never executed: case QGraphicsView::FullViewportUpdate: | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
1051 | fullUpdatePending = true; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1052 | viewport->update(); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1053 | break; never executed: break; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
1054 | case QGraphicsView::BoundingRectViewportUpdate: never executed: case QGraphicsView::BoundingRectViewportUpdate: | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
1055 | if (hasUpdateClip)
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
1056 | QRect_unite(&dirtyBoundingRect, r & updateClip); never executed: QRect_unite(&dirtyBoundingRect, r & updateClip); | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
1057 | else | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1058 | QRect_unite(&dirtyBoundingRect, r); never executed: QRect_unite(&dirtyBoundingRect, r); | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
1059 | if (containsViewport(dirtyBoundingRect, viewport->width(), viewport->height())) {
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
1060 | fullUpdatePending = true; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1061 | viewport->update(); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1062 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
1063 | break; never executed: break; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
1064 | case QGraphicsView::SmartViewportUpdate: // ### DEPRECATE never executed: case QGraphicsView::SmartViewportUpdate: | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
1065 | case QGraphicsView::MinimalViewportUpdate: never executed: case QGraphicsView::MinimalViewportUpdate: | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
1066 | if (hasUpdateClip)
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
1067 | dirtyRegion += r & updateClip; never executed: dirtyRegion += r & updateClip; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
1068 | else | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1069 | dirtyRegion += r; never executed: dirtyRegion += r; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
1070 | break; never executed: break; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
1071 | default: never executed: default: | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
1072 | break; never executed: break; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
1073 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1074 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
1075 | return true; never executed: return true; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
1076 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1077 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
1078 | QStyleOptionGraphicsItem *QGraphicsViewPrivate::allocStyleOptionsArray(int numItems) | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1079 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1080 | if (mustAllocateStyleOptions || (numItems > styleOptions.capacity()))
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
1081 | // too many items, let's allocate on-the-fly | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1082 | return new QStyleOptionGraphicsItem[numItems]; never executed: return new QStyleOptionGraphicsItem[numItems]; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
1083 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
1084 | // expand only whenever necessary | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1085 | if (numItems > styleOptions.size())
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
1086 | styleOptions.resize(numItems); never executed: styleOptions.resize(numItems); | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
1087 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
1088 | mustAllocateStyleOptions = true; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1089 | return styleOptions.data(); never executed: return styleOptions.data(); | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
1090 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1091 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
1092 | void QGraphicsViewPrivate::freeStyleOptionsArray(QStyleOptionGraphicsItem *array) | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1093 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1094 | mustAllocateStyleOptions = false; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1095 | if (array != styleOptions.data())
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
1096 | delete [] array; never executed: delete [] array; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
1097 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
1098 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
1099 | extern QPainterPath qt_regionToPath(const QRegion ®ion); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1100 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
1101 | /*! | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1102 | ### Adjustments in findItems: mapToScene(QRect) forces us to adjust the | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1103 | input rectangle by (0, 0, 1, 1), because it uses QRect::bottomRight() | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1104 | (etc) when mapping the rectangle to a polygon (which is _wrong_). In | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1105 | addition, as QGraphicsItem::boundingRect() is defined in logical space, | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1106 | but the default pen for QPainter is cosmetic with a width of 0, QPainter | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1107 | is at risk of painting 1 pixel outside the bounding rect. Therefore we | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1108 | must search for items with an adjustment of (-1, -1, 1, 1). | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1109 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1110 | QList<QGraphicsItem *> QGraphicsViewPrivate::findItems(const QRegion &exposedRegion, bool *allItems, | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1111 | const QTransform &viewTransform) const | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1112 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1113 | Q_Q(const QGraphicsView); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1114 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
1115 | // Step 1) If all items are contained within the expose region, then | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1116 | // return a list of all visible items. ### the scene's growing bounding | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1117 | // rect does not take into account untransformable items. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1118 | const QRectF exposedRegionSceneBounds = q->mapToScene(exposedRegion.boundingRect().adjusted(-1, -1, 1, 1)) | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1119 | .boundingRect(); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1120 | if (exposedRegionSceneBounds.contains(scene->sceneRect())) {
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
1121 | Q_ASSERT(allItems); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1122 | *allItems = true; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1123 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
1124 | // All items are guaranteed within the exposed region. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1125 | return scene->items(Qt::AscendingOrder); never executed: return scene->items(Qt::AscendingOrder); | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
1126 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1127 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
1128 | // Step 2) If the expose region is a simple rect and the view is only | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1129 | // translated or scaled, search for items using | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1130 | // QGraphicsScene::items(QRectF). | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1131 | bool simpleRectLookup = exposedRegion.rectCount() == 1 && matrix.type() <= QTransform::TxScale;
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
1132 | if (simpleRectLookup) {
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
1133 | return scene->items(exposedRegionSceneBounds, never executed: return scene->items(exposedRegionSceneBounds, Qt::IntersectsItemBoundingRect, Qt::AscendingOrder, viewTransform); | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
1134 | Qt::IntersectsItemBoundingRect, never executed: return scene->items(exposedRegionSceneBounds, Qt::IntersectsItemBoundingRect, Qt::AscendingOrder, viewTransform); | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
1135 | Qt::AscendingOrder, viewTransform); never executed: return scene->items(exposedRegionSceneBounds, Qt::IntersectsItemBoundingRect, Qt::AscendingOrder, viewTransform); | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
1136 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1137 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
1138 | // If the region is complex or the view has a complex transform, adjust | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1139 | // the expose region, convert it to a path, and then search for items | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1140 | // using QGraphicsScene::items(QPainterPath); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1141 | QRegion adjustedRegion; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1142 | foreach (const QRect &r, exposedRegion.rects()) | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1143 | adjustedRegion += r.adjusted(-1, -1, 1, 1); never executed: adjustedRegion += r.adjusted(-1, -1, 1, 1); | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
1144 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
1145 | const QPainterPath exposedScenePath(q->mapToScene(qt_regionToPath(adjustedRegion))); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1146 | return scene->items(exposedScenePath, Qt::IntersectsItemBoundingRect, never executed: return scene->items(exposedScenePath, Qt::IntersectsItemBoundingRect, Qt::AscendingOrder, viewTransform); | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
1147 | Qt::AscendingOrder, viewTransform); never executed: return scene->items(exposedScenePath, Qt::IntersectsItemBoundingRect, Qt::AscendingOrder, viewTransform); | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
1148 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1149 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
1150 | /*! | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1151 | \internal | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1152 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
1153 | Enables input methods for the view if and only if the current focus item of | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1154 | the scene accepts input methods. Call function whenever that condition has | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1155 | potentially changed. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1156 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1157 | void QGraphicsViewPrivate::updateInputMethodSensitivity() | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1158 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1159 | Q_Q(QGraphicsView); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1160 | QGraphicsItem *focusItem = 0; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1161 | bool enabled = scene && (focusItem = scene->focusItem())
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
1162 | && (focusItem->d_ptr->flags & QGraphicsItem::ItemAcceptsInputMethod);
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
1163 | q->setAttribute(Qt::WA_InputMethodEnabled, enabled); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1164 | q->viewport()->setAttribute(Qt::WA_InputMethodEnabled, enabled); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1165 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
1166 | if (!enabled) {
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
1167 | q->setInputMethodHints(0); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1168 | return; never executed: return; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
1169 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1170 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
1171 | QGraphicsProxyWidget *proxy = focusItem->d_ptr->isWidget && focusItem->d_ptr->isProxyWidget()
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
1172 | ? static_cast<QGraphicsProxyWidget *>(focusItem) : 0; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1173 | if (!proxy) {
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
1174 | q->setInputMethodHints(focusItem->inputMethodHints()); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1175 | } else if (QWidget *widget = proxy->widget()) { never executed: end of block
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
1176 | if (QWidget *fw = widget->focusWidget())
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
1177 | widget = fw; never executed: widget = fw; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
1178 | q->setInputMethodHints(widget->inputMethodHints()); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1179 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
1180 | q->setInputMethodHints(0); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1181 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
1182 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1183 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
1184 | /*! | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1185 | Constructs a QGraphicsView. \a parent is passed to QWidget's constructor. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1186 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1187 | QGraphicsView::QGraphicsView(QWidget *parent) | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1188 | : QAbstractScrollArea(*new QGraphicsViewPrivate, parent) | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1189 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1190 | setViewport(0); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1191 | setAcceptDrops(true); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1192 | setBackgroundRole(QPalette::Base); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1193 | // Investigate leaving these disabled by default. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1194 | setAttribute(Qt::WA_InputMethodEnabled); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1195 | viewport()->setAttribute(Qt::WA_InputMethodEnabled); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1196 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
1197 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
1198 | /*! | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1199 | Constructs a QGraphicsView and sets the visualized scene to \a | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1200 | scene. \a parent is passed to QWidget's constructor. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1201 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1202 | QGraphicsView::QGraphicsView(QGraphicsScene *scene, QWidget *parent) | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1203 | : QAbstractScrollArea(*new QGraphicsViewPrivate, parent) | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1204 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1205 | setScene(scene); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1206 | setViewport(0); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1207 | setAcceptDrops(true); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1208 | setBackgroundRole(QPalette::Base); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1209 | // Investigate leaving these disabled by default. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1210 | setAttribute(Qt::WA_InputMethodEnabled); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1211 | viewport()->setAttribute(Qt::WA_InputMethodEnabled); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1212 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
1213 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
1214 | /*! | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1215 | \internal | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1216 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1217 | QGraphicsView::QGraphicsView(QGraphicsViewPrivate &dd, QWidget *parent) | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1218 | : QAbstractScrollArea(dd, parent) | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1219 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1220 | setViewport(0); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1221 | setAcceptDrops(true); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1222 | setBackgroundRole(QPalette::Base); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1223 | // Investigate leaving these disabled by default. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1224 | setAttribute(Qt::WA_InputMethodEnabled); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1225 | viewport()->setAttribute(Qt::WA_InputMethodEnabled); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1226 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
1227 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
1228 | /*! | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1229 | Destructs the QGraphicsView object. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1230 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1231 | QGraphicsView::~QGraphicsView() | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1232 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1233 | Q_D(QGraphicsView); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1234 | if (d->scene)
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
1235 | d->scene->d_func()->views.removeAll(this); never executed: d->scene->d_func()->views.removeAll(this); | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
1236 | delete d->lastDragDropEvent; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1237 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
1238 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
1239 | /*! | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1240 | \reimp | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1241 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1242 | QSize QGraphicsView::sizeHint() const | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1243 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1244 | Q_D(const QGraphicsView); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1245 | if (d->scene) {
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
1246 | QSizeF baseSize = d->matrix.mapRect(sceneRect()).size(); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1247 | baseSize += QSizeF(d->frameWidth * 2, d->frameWidth * 2); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1248 | return baseSize.boundedTo((3 * QApplication::desktop()->size()) / 4).toSize(); never executed: return baseSize.boundedTo((3 * QApplication::desktop()->size()) / 4).toSize(); | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
1249 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1250 | return QAbstractScrollArea::sizeHint(); never executed: return QAbstractScrollArea::sizeHint(); | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
1251 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1252 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
1253 | /*! | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1254 | \property QGraphicsView::renderHints | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1255 | \brief the default render hints for the view | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1256 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
1257 | These hints are | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1258 | used to initialize QPainter before each visible item is drawn. QPainter | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1259 | uses render hints to toggle rendering features such as antialiasing and | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1260 | smooth pixmap transformation. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1261 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
1262 | QPainter::TextAntialiasing is enabled by default. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1263 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
1264 | Example: | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1265 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
1266 | \snippet code/src_gui_graphicsview_qgraphicsview.cpp 1 | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1267 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1268 | QPainter::RenderHints QGraphicsView::renderHints() const | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1269 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1270 | Q_D(const QGraphicsView); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1271 | return d->renderHints; never executed: return d->renderHints; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
1272 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1273 | void QGraphicsView::setRenderHints(QPainter::RenderHints hints) | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1274 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1275 | Q_D(QGraphicsView); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1276 | if (hints == d->renderHints)
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
1277 | return; never executed: return; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
1278 | d->renderHints = hints; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1279 | d->updateAll(); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1280 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
1281 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
1282 | /*! | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1283 | If \a enabled is true, the render hint \a hint is enabled; otherwise it | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1284 | is disabled. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1285 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
1286 | \sa renderHints | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1287 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1288 | void QGraphicsView::setRenderHint(QPainter::RenderHint hint, bool enabled) | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1289 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1290 | Q_D(QGraphicsView); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1291 | QPainter::RenderHints oldHints = d->renderHints; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1292 | if (enabled)
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
1293 | d->renderHints |= hint; never executed: d->renderHints |= hint; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
1294 | else | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1295 | d->renderHints &= ~hint; never executed: d->renderHints &= ~hint; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
1296 | if (oldHints != d->renderHints)
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
1297 | d->updateAll(); never executed: d->updateAll(); | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
1298 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
1299 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
1300 | /*! | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1301 | \property QGraphicsView::alignment | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1302 | \brief the alignment of the scene in the view when the whole | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1303 | scene is visible. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1304 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
1305 | If the whole scene is visible in the view, (i.e., there are no visible | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1306 | scroll bars,) the view's alignment will decide where the scene will be | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1307 | rendered in the view. For example, if the alignment is Qt::AlignCenter, | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1308 | which is default, the scene will be centered in the view, and if the | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1309 | alignment is (Qt::AlignLeft | Qt::AlignTop), the scene will be rendered in | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1310 | the top-left corner of the view. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1311 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1312 | Qt::Alignment QGraphicsView::alignment() const | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1313 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1314 | Q_D(const QGraphicsView); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1315 | return d->alignment; never executed: return d->alignment; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
1316 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1317 | void QGraphicsView::setAlignment(Qt::Alignment alignment) | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1318 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1319 | Q_D(QGraphicsView); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1320 | if (d->alignment != alignment) {
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
1321 | d->alignment = alignment; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1322 | d->recalculateContentSize(); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1323 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
1324 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
1325 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
1326 | /*! | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1327 | \property QGraphicsView::transformationAnchor | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1328 | \brief how the view should position the scene during transformations. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1329 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
1330 | QGraphicsView uses this property to decide how to position the scene in | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1331 | the viewport when the transformation matrix changes, and the coordinate | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1332 | system of the view is transformed. The default behavior, AnchorViewCenter, | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1333 | ensures that the scene point at the center of the view remains unchanged | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1334 | during transformations (e.g., when rotating, the scene will appear to | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1335 | rotate around the center of the view). | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1336 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
1337 | Note that the effect of this property is noticeable when only a part of the | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1338 | scene is visible (i.e., when there are scroll bars). Otherwise, if the | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1339 | whole scene fits in the view, QGraphicsScene uses the view \l alignment to | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1340 | position the scene in the view. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1341 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
1342 | \sa alignment, resizeAnchor | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1343 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1344 | QGraphicsView::ViewportAnchor QGraphicsView::transformationAnchor() const | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1345 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1346 | Q_D(const QGraphicsView); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1347 | return d->transformationAnchor; never executed: return d->transformationAnchor; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
1348 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1349 | void QGraphicsView::setTransformationAnchor(ViewportAnchor anchor) | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1350 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1351 | Q_D(QGraphicsView); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1352 | d->transformationAnchor = anchor; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1353 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
1354 | // Ensure mouse tracking is enabled in the case we are using AnchorUnderMouse | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1355 | // in order to have up-to-date information for centering the view. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1356 | if (d->transformationAnchor == AnchorUnderMouse)
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
1357 | d->viewport->setMouseTracking(true); never executed: d->viewport->setMouseTracking(true); | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
1358 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
1359 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
1360 | /*! | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1361 | \property QGraphicsView::resizeAnchor | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1362 | \brief how the view should position the scene when the view is resized. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1363 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
1364 | QGraphicsView uses this property to decide how to position the scene in | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1365 | the viewport when the viewport widget's size changes. The default | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1366 | behavior, NoAnchor, leaves the scene's position unchanged during a resize; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1367 | the top-left corner of the view will appear to be anchored while resizing. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1368 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
1369 | Note that the effect of this property is noticeable when only a part of the | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1370 | scene is visible (i.e., when there are scroll bars). Otherwise, if the | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1371 | whole scene fits in the view, QGraphicsScene uses the view \l alignment to | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1372 | position the scene in the view. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1373 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
1374 | \sa alignment, transformationAnchor | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1375 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1376 | QGraphicsView::ViewportAnchor QGraphicsView::resizeAnchor() const | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1377 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1378 | Q_D(const QGraphicsView); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1379 | return d->resizeAnchor; never executed: return d->resizeAnchor; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
1380 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1381 | void QGraphicsView::setResizeAnchor(ViewportAnchor anchor) | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1382 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1383 | Q_D(QGraphicsView); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1384 | d->resizeAnchor = anchor; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1385 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
1386 | // Ensure mouse tracking is enabled in the case we are using AnchorUnderMouse | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1387 | // in order to have up-to-date information for centering the view. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1388 | if (d->resizeAnchor == AnchorUnderMouse)
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
1389 | d->viewport->setMouseTracking(true); never executed: d->viewport->setMouseTracking(true); | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
1390 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
1391 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
1392 | /*! | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1393 | \property QGraphicsView::viewportUpdateMode | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1394 | \brief how the viewport should update its contents. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1395 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
1396 | \since 4.3 | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1397 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
1398 | QGraphicsView uses this property to decide how to update areas of the | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1399 | scene that have been reexposed or changed. Usually you do not need to | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1400 | modify this property, but there are some cases where doing so can improve | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1401 | rendering performance. See the ViewportUpdateMode documentation for | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1402 | specific details. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1403 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
1404 | The default value is MinimalViewportUpdate, where QGraphicsView will | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1405 | update as small an area of the viewport as possible when the contents | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1406 | change. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1407 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
1408 | \sa ViewportUpdateMode, cacheMode | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1409 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1410 | QGraphicsView::ViewportUpdateMode QGraphicsView::viewportUpdateMode() const | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1411 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1412 | Q_D(const QGraphicsView); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1413 | return d->viewportUpdateMode; never executed: return d->viewportUpdateMode; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
1414 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1415 | void QGraphicsView::setViewportUpdateMode(ViewportUpdateMode mode) | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1416 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1417 | Q_D(QGraphicsView); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1418 | d->viewportUpdateMode = mode; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1419 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
1420 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
1421 | /*! | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1422 | \property QGraphicsView::optimizationFlags | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1423 | \brief flags that can be used to tune QGraphicsView's performance. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1424 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
1425 | \since 4.3 | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1426 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
1427 | QGraphicsView uses clipping, extra bounding rect adjustments, and certain | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1428 | other aids to improve rendering quality and performance for the common | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1429 | case graphics scene. However, depending on the target platform, the scene, | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1430 | and the viewport in use, some of these operations can degrade performance. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1431 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
1432 | The effect varies from flag to flag; see the OptimizationFlags | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1433 | documentation for details. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1434 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
1435 | By default, no optimization flags are enabled. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1436 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
1437 | \sa setOptimizationFlag() | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1438 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1439 | QGraphicsView::OptimizationFlags QGraphicsView::optimizationFlags() const | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1440 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1441 | Q_D(const QGraphicsView); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1442 | return d->optimizationFlags; never executed: return d->optimizationFlags; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
1443 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1444 | void QGraphicsView::setOptimizationFlags(OptimizationFlags flags) | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1445 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1446 | Q_D(QGraphicsView); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1447 | d->optimizationFlags = flags; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1448 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
1449 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
1450 | /*! | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1451 | Enables \a flag if \a enabled is true; otherwise disables \a flag. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1452 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
1453 | \sa optimizationFlags | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1454 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1455 | void QGraphicsView::setOptimizationFlag(OptimizationFlag flag, bool enabled) | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1456 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1457 | Q_D(QGraphicsView); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1458 | if (enabled)
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
1459 | d->optimizationFlags |= flag; never executed: d->optimizationFlags |= flag; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
1460 | else | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1461 | d->optimizationFlags &= ~flag; never executed: d->optimizationFlags &= ~flag; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
1462 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1463 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
1464 | /*! | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1465 | \property QGraphicsView::dragMode | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1466 | \brief the behavior for dragging the mouse over the scene while | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1467 | the left mouse button is pressed. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1468 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
1469 | This property defines what should happen when the user clicks on the scene | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1470 | background and drags the mouse (e.g., scrolling the viewport contents | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1471 | using a pointing hand cursor, or selecting multiple items with a rubber | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1472 | band). The default value, NoDrag, does nothing. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1473 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
1474 | This behavior only affects mouse clicks that are not handled by any item. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1475 | You can define a custom behavior by creating a subclass of QGraphicsView | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1476 | and reimplementing mouseMoveEvent(). | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1477 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1478 | QGraphicsView::DragMode QGraphicsView::dragMode() const | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1479 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1480 | Q_D(const QGraphicsView); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1481 | return d->dragMode; never executed: return d->dragMode; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
1482 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1483 | void QGraphicsView::setDragMode(DragMode mode) | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1484 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1485 | Q_D(QGraphicsView); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1486 | if (d->dragMode == mode)
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
1487 | return; never executed: return; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
1488 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
1489 | #ifndef QT_NO_CURSOR | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1490 | if (d->dragMode == ScrollHandDrag)
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
1491 | viewport()->unsetCursor(); never executed: viewport()->unsetCursor(); | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
1492 | #endif | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1493 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
1494 | // If dragMode is unset while dragging, e.g. via a keyEvent, we | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1495 | // don't unset the handScrolling state. When enabling scrolling | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1496 | // again the mouseMoveEvent will automatically start scrolling, | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1497 | // without a mousePress | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1498 | if (d->dragMode == ScrollHandDrag && mode == NoDrag && d->handScrolling)
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
1499 | d->handScrolling = false; never executed: d->handScrolling = false; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
1500 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
1501 | d->dragMode = mode; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1502 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
1503 | #ifndef QT_NO_CURSOR | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1504 | if (d->dragMode == ScrollHandDrag) {
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
1505 | // Forget the stored viewport cursor when we enter scroll hand drag mode. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1506 | d->hasStoredOriginalCursor = false; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1507 | viewport()->setCursor(Qt::OpenHandCursor); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1508 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
1509 | #endif | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1510 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
1511 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
1512 | #ifndef QT_NO_RUBBERBAND | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1513 | /*! | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1514 | \property QGraphicsView::rubberBandSelectionMode | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1515 | \brief the behavior for selecting items with a rubber band selection rectangle. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1516 | \since 4.3 | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1517 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
1518 | This property defines how items are selected when using the RubberBandDrag | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1519 | drag mode. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1520 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
1521 | The default value is Qt::IntersectsItemShape; all items whose shape | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1522 | intersects with or is contained by the rubber band are selected. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1523 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
1524 | \sa dragMode, items(), rubberBandRect() | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1525 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1526 | Qt::ItemSelectionMode QGraphicsView::rubberBandSelectionMode() const | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1527 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1528 | Q_D(const QGraphicsView); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1529 | return d->rubberBandSelectionMode; never executed: return d->rubberBandSelectionMode; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
1530 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1531 | void QGraphicsView::setRubberBandSelectionMode(Qt::ItemSelectionMode mode) | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1532 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1533 | Q_D(QGraphicsView); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1534 | d->rubberBandSelectionMode = mode; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1535 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
1536 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
1537 | /*! | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1538 | \since 5.1 | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1539 | This functions returns the current rubber band area (in viewport coordinates) if the user | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1540 | is currently doing an itemselection with rubber band. When the user is not using the | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1541 | rubber band this functions returns (a null) QRectF(). | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1542 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
1543 | Notice that part of this QRect can be outise the visual viewport. It can e.g | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1544 | contain negative values. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1545 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
1546 | \sa rubberBandSelectionMode, rubberBandChanged() | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1547 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1548 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
1549 | QRect QGraphicsView::rubberBandRect() const | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1550 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1551 | Q_D(const QGraphicsView); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1552 | if (d->dragMode != QGraphicsView::RubberBandDrag || !d->sceneInteractionAllowed || !d->rubberBanding)
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
1553 | return QRect(); never executed: return QRect(); | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
1554 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
1555 | return d->rubberBandRect; never executed: return d->rubberBandRect; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
1556 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1557 | #endif | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1558 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
1559 | /*! | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1560 | \property QGraphicsView::cacheMode | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1561 | \brief which parts of the view are cached | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1562 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
1563 | QGraphicsView can cache pre-rendered content in a QPixmap, which is then | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1564 | drawn onto the viewport. The purpose of such caching is to speed up the | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1565 | total rendering time for areas that are slow to render. Texture, gradient | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1566 | and alpha blended backgrounds, for example, can be notibly slow to render; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1567 | especially with a transformed view. The CacheBackground flag enables | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1568 | caching of the view's background. For example: | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1569 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
1570 | \snippet code/src_gui_graphicsview_qgraphicsview.cpp 2 | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1571 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
1572 | The cache is invalidated every time the view is transformed. However, when | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1573 | scrolling, only partial invalidation is required. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1574 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
1575 | By default, nothing is cached. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1576 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
1577 | \sa resetCachedContent(), QPixmapCache | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1578 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1579 | QGraphicsView::CacheMode QGraphicsView::cacheMode() const | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1580 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1581 | Q_D(const QGraphicsView); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1582 | return d->cacheMode; never executed: return d->cacheMode; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
1583 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1584 | void QGraphicsView::setCacheMode(CacheMode mode) | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1585 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1586 | Q_D(QGraphicsView); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1587 | if (mode == d->cacheMode)
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
1588 | return; never executed: return; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
1589 | d->cacheMode = mode; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1590 | resetCachedContent(); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1591 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
1592 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
1593 | /*! | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1594 | Resets any cached content. Calling this function will clear | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1595 | QGraphicsView's cache. If the current cache mode is \l CacheNone, this | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1596 | function does nothing. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1597 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
1598 | This function is called automatically for you when the backgroundBrush or | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1599 | QGraphicsScene::backgroundBrush properties change; you only need to call | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1600 | this function if you have reimplemented QGraphicsScene::drawBackground() | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1601 | or QGraphicsView::drawBackground() to draw a custom background, and need | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1602 | to trigger a full redraw. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1603 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
1604 | \sa cacheMode() | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1605 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1606 | void QGraphicsView::resetCachedContent() | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1607 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1608 | Q_D(QGraphicsView); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1609 | if (d->cacheMode == CacheNone)
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
1610 | return; never executed: return; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
1611 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
1612 | if (d->cacheMode & CacheBackground) {
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
1613 | // Background caching is enabled. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1614 | d->mustResizeBackgroundPixmap = true; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1615 | d->updateAll(); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1616 | } else if (d->mustResizeBackgroundPixmap) { never executed: end of block
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
1617 | // Background caching is disabled. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1618 | // Cleanup, free some resources. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1619 | d->mustResizeBackgroundPixmap = false; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1620 | d->backgroundPixmap = QPixmap(); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1621 | d->backgroundPixmapExposed = QRegion(); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1622 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
1623 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
1624 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
1625 | /*! | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1626 | Invalidates and schedules a redraw of \a layers inside \a rect. \a rect is | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1627 | in scene coordinates. Any cached content for \a layers inside \a rect is | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1628 | unconditionally invalidated and redrawn. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1629 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
1630 | You can call this function to notify QGraphicsView of changes to the | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1631 | background or the foreground of the scene. It is commonly used for scenes | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1632 | with tile-based backgrounds to notify changes when QGraphicsView has | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1633 | enabled background caching. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1634 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
1635 | Note that QGraphicsView currently supports background caching only (see | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1636 | QGraphicsView::CacheBackground). This function is equivalent to calling update() if any | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1637 | layer but QGraphicsScene::BackgroundLayer is passed. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1638 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
1639 | \sa QGraphicsScene::invalidate(), update() | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1640 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1641 | void QGraphicsView::invalidateScene(const QRectF &rect, QGraphicsScene::SceneLayers layers) | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1642 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1643 | Q_D(QGraphicsView); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1644 | if ((layers & QGraphicsScene::BackgroundLayer) && !d->mustResizeBackgroundPixmap) {
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
1645 | QRect viewRect = mapFromScene(rect).boundingRect(); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1646 | if (viewport()->rect().intersects(viewRect)) {
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
1647 | // The updated background area is exposed; schedule this area for | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1648 | // redrawing. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1649 | d->backgroundPixmapExposed += viewRect; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1650 | if (d->scene)
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
1651 | d->scene->update(rect); never executed: d->scene->update(rect); | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
1652 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
1653 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
1654 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
1655 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
1656 | /*! | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1657 | \property QGraphicsView::interactive | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1658 | \brief whether the view allows scene interaction. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1659 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
1660 | If enabled, this view is set to allow scene interaction. Otherwise, this | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1661 | view will not allow interaction, and any mouse or key events are ignored | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1662 | (i.e., it will act as a read-only view). | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1663 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
1664 | By default, this property is \c true. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1665 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1666 | bool QGraphicsView::isInteractive() const | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1667 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1668 | Q_D(const QGraphicsView); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1669 | return d->sceneInteractionAllowed; never executed: return d->sceneInteractionAllowed; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
1670 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1671 | void QGraphicsView::setInteractive(bool allowed) | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1672 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1673 | Q_D(QGraphicsView); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1674 | d->sceneInteractionAllowed = allowed; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1675 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
1676 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
1677 | /*! | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1678 | Returns a pointer to the scene that is currently visualized in the | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1679 | view. If no scene is currently visualized, 0 is returned. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1680 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
1681 | \sa setScene() | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1682 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1683 | QGraphicsScene *QGraphicsView::scene() const | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1684 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1685 | Q_D(const QGraphicsView); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1686 | return d->scene; never executed: return d->scene; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
1687 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1688 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
1689 | /*! | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1690 | Sets the current scene to \a scene. If \a scene is already being | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1691 | viewed, this function does nothing. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1692 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
1693 | When a scene is set on a view, the QGraphicsScene::changed() signal | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1694 | is automatically connected to this view's updateScene() slot, and the | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1695 | view's scroll bars are adjusted to fit the size of the scene. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1696 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
1697 | The view does not take ownership of \a scene. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1698 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1699 | void QGraphicsView::setScene(QGraphicsScene *scene) | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1700 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1701 | Q_D(QGraphicsView); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1702 | if (d->scene == scene)
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
1703 | return; never executed: return; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
1704 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
1705 | // Always update the viewport when the scene changes. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1706 | d->updateAll(); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1707 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
1708 | // Remove the previously assigned scene. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1709 | if (d->scene) {
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
1710 | disconnect(d->scene, SIGNAL(changed(QList<QRectF>)), | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1711 | this, SLOT(updateScene(QList<QRectF>))); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1712 | disconnect(d->scene, SIGNAL(sceneRectChanged(QRectF)), | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1713 | this, SLOT(updateSceneRect(QRectF))); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1714 | d->scene->d_func()->removeView(this); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1715 | d->connectedToScene = false; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1716 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
1717 | if (isActiveWindow() && isVisible()) {
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
1718 | QEvent windowDeactivate(QEvent::WindowDeactivate); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1719 | QApplication::sendEvent(d->scene, &windowDeactivate); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1720 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
1721 | if(hasFocus())
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
1722 | d->scene->clearFocus(); never executed: d->scene->clearFocus(); | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
1723 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
1724 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
1725 | // Assign the new scene and update the contents (scrollbars, etc.)). | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1726 | if ((d->scene = scene)) {
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
1727 | connect(d->scene, SIGNAL(sceneRectChanged(QRectF)), | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1728 | this, SLOT(updateSceneRect(QRectF))); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1729 | d->updateSceneSlotReimplementedChecked = false; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1730 | d->scene->d_func()->addView(this); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1731 | d->recalculateContentSize(); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1732 | d->lastCenterPoint = sceneRect().center(); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1733 | d->keepLastCenterPoint = true; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1734 | // We are only interested in mouse tracking if items accept | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1735 | // hover events or use non-default cursors. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1736 | if (!d->scene->d_func()->allItemsIgnoreHoverEvents
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
1737 | || !d->scene->d_func()->allItemsUseDefaultCursor) {
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
1738 | d->viewport->setMouseTracking(true); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1739 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
1740 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
1741 | // enable touch events if any items is interested in them | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1742 | if (!d->scene->d_func()->allItemsIgnoreTouchEvents)
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
1743 | d->viewport->setAttribute(Qt::WA_AcceptTouchEvents); never executed: d->viewport->setAttribute(Qt::WA_AcceptTouchEvents); | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
1744 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
1745 | if (isActiveWindow() && isVisible()) {
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
1746 | QEvent windowActivate(QEvent::WindowActivate); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1747 | QApplication::sendEvent(d->scene, &windowActivate); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1748 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
1749 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
1750 | d->recalculateContentSize(); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1751 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
1752 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
1753 | d->updateInputMethodSensitivity(); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1754 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
1755 | if (d->scene && hasFocus())
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
1756 | d->scene->setFocus(); never executed: d->scene->setFocus(); | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
1757 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
1758 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
1759 | /*! | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1760 | \property QGraphicsView::sceneRect | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1761 | \brief the area of the scene visualized by this view. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1762 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
1763 | The scene rectangle defines the extent of the scene, and in the view's case, | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1764 | this means the area of the scene that you can navigate using the scroll | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1765 | bars. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1766 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
1767 | If unset, or if a null QRectF is set, this property has the same value as | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1768 | QGraphicsScene::sceneRect, and it changes with | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1769 | QGraphicsScene::sceneRect. Otherwise, the view's scene rect is unaffected | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1770 | by the scene. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1771 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
1772 | Note that, although the scene supports a virtually unlimited size, the | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1773 | range of the scroll bars will never exceed the range of an integer | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1774 | (INT_MIN, INT_MAX). When the scene is larger than the scroll bars' values, | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1775 | you can choose to use translate() to navigate the scene instead. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1776 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
1777 | By default, this property contains a rectangle at the origin with zero | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1778 | width and height. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1779 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
1780 | \sa QGraphicsScene::sceneRect | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1781 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1782 | QRectF QGraphicsView::sceneRect() const | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1783 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1784 | Q_D(const QGraphicsView); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1785 | if (d->hasSceneRect)
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
1786 | return d->sceneRect; never executed: return d->sceneRect; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
1787 | if (d->scene)
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
1788 | return d->scene->sceneRect(); never executed: return d->scene->sceneRect(); | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
1789 | return QRectF(); never executed: return QRectF(); | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
1790 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1791 | void QGraphicsView::setSceneRect(const QRectF &rect) | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1792 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1793 | Q_D(QGraphicsView); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1794 | d->hasSceneRect = !rect.isNull(); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1795 | d->sceneRect = rect; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1796 | d->recalculateContentSize(); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1797 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
1798 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
1799 | /*! | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1800 | Returns the current transformation matrix for the view. If no current | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1801 | transformation is set, the identity matrix is returned. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1802 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
1803 | \sa setMatrix(), transform(), rotate(), scale(), shear(), translate() | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1804 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1805 | QMatrix QGraphicsView::matrix() const | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1806 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1807 | Q_D(const QGraphicsView); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1808 | return d->matrix.toAffine(); never executed: return d->matrix.toAffine(); | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
1809 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1810 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
1811 | /*! | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1812 | Sets the view's current transformation matrix to \a matrix. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1813 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
1814 | If \a combine is true, then \a matrix is combined with the current matrix; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1815 | otherwise, \a matrix \e replaces the current matrix. \a combine is false | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1816 | by default. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1817 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
1818 | The transformation matrix tranforms the scene into view coordinates. Using | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1819 | the default transformation, provided by the identity matrix, one pixel in | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1820 | the view represents one unit in the scene (e.g., a 10x10 rectangular item | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1821 | is drawn using 10x10 pixels in the view). If a 2x2 scaling matrix is | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1822 | applied, the scene will be drawn in 1:2 (e.g., a 10x10 rectangular item is | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1823 | then drawn using 20x20 pixels in the view). | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1824 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
1825 | Example: | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1826 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
1827 | \snippet code/src_gui_graphicsview_qgraphicsview.cpp 3 | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1828 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
1829 | To simplify interation with items using a transformed view, QGraphicsView | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1830 | provides mapTo... and mapFrom... functions that can translate between | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1831 | scene and view coordinates. For example, you can call mapToScene() to map | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1832 | a view coordinate to a floating point scene coordinate, or mapFromScene() | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1833 | to map from floating point scene coordinates to view coordinates. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1834 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
1835 | \sa matrix(), setTransform(), rotate(), scale(), shear(), translate() | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1836 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1837 | void QGraphicsView::setMatrix(const QMatrix &matrix, bool combine) | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1838 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1839 | setTransform(QTransform(matrix), combine); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1840 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
1841 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
1842 | /*! | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1843 | Resets the view transformation matrix to the identity matrix. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1844 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
1845 | \sa resetTransform() | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1846 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1847 | void QGraphicsView::resetMatrix() | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1848 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1849 | resetTransform(); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1850 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
1851 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
1852 | /*! | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1853 | Rotates the current view transformation \a angle degrees clockwise. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1854 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
1855 | \sa setTransform(), transform(), scale(), shear(), translate() | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1856 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1857 | void QGraphicsView::rotate(qreal angle) | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1858 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1859 | Q_D(QGraphicsView); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1860 | QTransform matrix = d->matrix; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1861 | matrix.rotate(angle); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1862 | setTransform(matrix); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1863 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
1864 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
1865 | /*! | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1866 | Scales the current view transformation by (\a sx, \a sy). | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1867 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
1868 | \sa setTransform(), transform(), rotate(), shear(), translate() | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1869 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1870 | void QGraphicsView::scale(qreal sx, qreal sy) | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1871 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1872 | Q_D(QGraphicsView); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1873 | QTransform matrix = d->matrix; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1874 | matrix.scale(sx, sy); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1875 | setTransform(matrix); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1876 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
1877 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
1878 | /*! | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1879 | Shears the current view transformation by (\a sh, \a sv). | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1880 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
1881 | \sa setTransform(), transform(), rotate(), scale(), translate() | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1882 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1883 | void QGraphicsView::shear(qreal sh, qreal sv) | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1884 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1885 | Q_D(QGraphicsView); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1886 | QTransform matrix = d->matrix; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1887 | matrix.shear(sh, sv); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1888 | setTransform(matrix); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1889 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
1890 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
1891 | /*! | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1892 | Translates the current view transformation by (\a dx, \a dy). | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1893 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
1894 | \sa setTransform(), transform(), rotate(), shear() | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1895 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1896 | void QGraphicsView::translate(qreal dx, qreal dy) | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1897 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1898 | Q_D(QGraphicsView); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1899 | QTransform matrix = d->matrix; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1900 | matrix.translate(dx, dy); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1901 | setTransform(matrix); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1902 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
1903 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
1904 | /*! | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1905 | Scrolls the contents of the viewport to ensure that the scene | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1906 | coordinate \a pos, is centered in the view. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1907 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
1908 | Because \a pos is a floating point coordinate, and the scroll bars operate | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1909 | on integer coordinates, the centering is only an approximation. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1910 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
1911 | \note If the item is close to or outside the border, it will be visible | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1912 | in the view, but not centered. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1913 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
1914 | \sa ensureVisible() | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1915 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1916 | void QGraphicsView::centerOn(const QPointF &pos) | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1917 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1918 | Q_D(QGraphicsView); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1919 | qreal width = viewport()->width(); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1920 | qreal height = viewport()->height(); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1921 | QPointF viewPoint = d->matrix.map(pos); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1922 | QPointF oldCenterPoint = pos; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1923 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
1924 | if (!d->leftIndent) {
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
1925 | if (isRightToLeft()) {
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
1926 | qint64 horizontal = 0; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1927 | horizontal += horizontalScrollBar()->minimum(); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1928 | horizontal += horizontalScrollBar()->maximum(); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1929 | horizontal -= int(viewPoint.x() - width / 2.0); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1930 | horizontalScrollBar()->setValue(horizontal); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1931 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
1932 | horizontalScrollBar()->setValue(int(viewPoint.x() - width / 2.0)); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1933 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
1934 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1935 | if (!d->topIndent)
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
1936 | verticalScrollBar()->setValue(int(viewPoint.y() - height / 2.0)); never executed: verticalScrollBar()->setValue(int(viewPoint.y() - height / 2.0)); | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
1937 | d->lastCenterPoint = oldCenterPoint; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1938 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
1939 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
1940 | /*! | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1941 | \fn QGraphicsView::centerOn(qreal x, qreal y) | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1942 | \overload | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1943 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
1944 | This function is provided for convenience. It's equivalent to calling | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1945 | centerOn(QPointF(\a x, \a y)). | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1946 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1947 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
1948 | /*! | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1949 | \overload | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1950 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
1951 | Scrolls the contents of the viewport to ensure that \a item | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1952 | is centered in the view. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1953 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
1954 | \sa ensureVisible() | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1955 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1956 | void QGraphicsView::centerOn(const QGraphicsItem *item) | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1957 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1958 | centerOn(item->sceneBoundingRect().center()); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1959 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
1960 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
1961 | /*! | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1962 | Scrolls the contents of the viewport so that the scene rectangle \a rect | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1963 | is visible, with margins specified in pixels by \a xmargin and \a | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1964 | ymargin. If the specified rect cannot be reached, the contents are | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1965 | scrolled to the nearest valid position. The default value for both margins | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1966 | is 50 pixels. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1967 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
1968 | \sa centerOn() | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1969 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1970 | void QGraphicsView::ensureVisible(const QRectF &rect, int xmargin, int ymargin) | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1971 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1972 | Q_D(QGraphicsView); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1973 | qreal width = viewport()->width(); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1974 | qreal height = viewport()->height(); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1975 | QRectF viewRect = d->matrix.mapRect(rect); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1976 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
1977 | qreal left = d->horizontalScroll(); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1978 | qreal right = left + width; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1979 | qreal top = d->verticalScroll(); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1980 | qreal bottom = top + height; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1981 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
1982 | if (viewRect.left() <= left + xmargin) {
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
1983 | // need to scroll from the left | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1984 | if (!d->leftIndent)
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
1985 | horizontalScrollBar()->setValue(int(viewRect.left() - xmargin - 0.5)); never executed: horizontalScrollBar()->setValue(int(viewRect.left() - xmargin - 0.5)); | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
1986 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
1987 | if (viewRect.right() >= right - xmargin) {
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
1988 | // need to scroll from the right | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1989 | if (!d->leftIndent)
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
1990 | horizontalScrollBar()->setValue(int(viewRect.right() - width + xmargin + 0.5)); never executed: horizontalScrollBar()->setValue(int(viewRect.right() - width + xmargin + 0.5)); | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
1991 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
1992 | if (viewRect.top() <= top + ymargin) {
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
1993 | // need to scroll from the top | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1994 | if (!d->topIndent)
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
1995 | verticalScrollBar()->setValue(int(viewRect.top() - ymargin - 0.5)); never executed: verticalScrollBar()->setValue(int(viewRect.top() - ymargin - 0.5)); | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
1996 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
1997 | if (viewRect.bottom() >= bottom - ymargin) {
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
1998 | // need to scroll from the bottom | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1999 | if (!d->topIndent)
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
2000 | verticalScrollBar()->setValue(int(viewRect.bottom() - height + ymargin + 0.5)); never executed: verticalScrollBar()->setValue(int(viewRect.bottom() - height + ymargin + 0.5)); | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
2001 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
2002 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
2003 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
2004 | /*! | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2005 | \fn QGraphicsView::ensureVisible(qreal x, qreal y, qreal w, qreal h, | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2006 | int xmargin, int ymargin) | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2007 | \overload | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2008 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
2009 | This function is provided for convenience. It's equivalent to calling | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2010 | ensureVisible(QRectF(\a x, \a y, \a w, \a h), \a xmargin, \a ymargin). | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2011 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2012 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
2013 | /*! | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2014 | \overload | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2015 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
2016 | Scrolls the contents of the viewport so that the center of item \a item is | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2017 | visible, with margins specified in pixels by \a xmargin and \a ymargin. If | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2018 | the specified point cannot be reached, the contents are scrolled to the | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2019 | nearest valid position. The default value for both margins is 50 pixels. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2020 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
2021 | \sa centerOn() | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2022 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2023 | void QGraphicsView::ensureVisible(const QGraphicsItem *item, int xmargin, int ymargin) | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2024 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2025 | ensureVisible(item->sceneBoundingRect(), xmargin, ymargin); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2026 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
2027 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
2028 | /*! | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2029 | Scales the view matrix and scrolls the scroll bars to ensure that the | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2030 | scene rectangle \a rect fits inside the viewport. \a rect must be inside | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2031 | the scene rect; otherwise, fitInView() cannot guarantee that the whole | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2032 | rect is visible. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2033 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
2034 | This function keeps the view's rotation, translation, or shear. The view | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2035 | is scaled according to \a aspectRatioMode. \a rect will be centered in the | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2036 | view if it does not fit tightly. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2037 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
2038 | It's common to call fitInView() from inside a reimplementation of | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2039 | resizeEvent(), to ensure that the whole scene, or parts of the scene, | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2040 | scales automatically to fit the new size of the viewport as the view is | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2041 | resized. Note though, that calling fitInView() from inside resizeEvent() | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2042 | can lead to unwanted resize recursion, if the new transformation toggles | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2043 | the automatic state of the scrollbars. You can toggle the scrollbar | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2044 | policies to always on or always off to prevent this (see | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2045 | horizontalScrollBarPolicy() and verticalScrollBarPolicy()). | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2046 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
2047 | If \a rect is empty, or if the viewport is too small, this | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2048 | function will do nothing. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2049 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
2050 | \sa setTransform(), ensureVisible(), centerOn() | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2051 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2052 | void QGraphicsView::fitInView(const QRectF &rect, Qt::AspectRatioMode aspectRatioMode) | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2053 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2054 | Q_D(QGraphicsView); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2055 | if (!d->scene || rect.isNull())
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
2056 | return; never executed: return; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
2057 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
2058 | // Reset the view scale to 1:1. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2059 | QRectF unity = d->matrix.mapRect(QRectF(0, 0, 1, 1)); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2060 | if (unity.isEmpty())
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
2061 | return; never executed: return; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
2062 | scale(1 / unity.width(), 1 / unity.height()); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2063 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
2064 | // Find the ideal x / y scaling ratio to fit \a rect in the view. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2065 | int margin = 2; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2066 | QRectF viewRect = viewport()->rect().adjusted(margin, margin, -margin, -margin); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2067 | if (viewRect.isEmpty())
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
2068 | return; never executed: return; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
2069 | QRectF sceneRect = d->matrix.mapRect(rect); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2070 | if (sceneRect.isEmpty())
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
2071 | return; never executed: return; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
2072 | qreal xratio = viewRect.width() / sceneRect.width(); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2073 | qreal yratio = viewRect.height() / sceneRect.height(); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2074 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
2075 | // Respect the aspect ratio mode. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2076 | switch (aspectRatioMode) { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2077 | case Qt::KeepAspectRatio: never executed: case Qt::KeepAspectRatio: | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
2078 | xratio = yratio = qMin(xratio, yratio); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2079 | break; never executed: break; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
2080 | case Qt::KeepAspectRatioByExpanding: never executed: case Qt::KeepAspectRatioByExpanding: | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
2081 | xratio = yratio = qMax(xratio, yratio); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2082 | break; never executed: break; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
2083 | case Qt::IgnoreAspectRatio: never executed: case Qt::IgnoreAspectRatio: | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
2084 | break; never executed: break; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
2085 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2086 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
2087 | // Scale and center on the center of \a rect. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2088 | scale(xratio, yratio); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2089 | centerOn(rect.center()); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2090 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
2091 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
2092 | /*! | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2093 | \fn void QGraphicsView::fitInView(qreal x, qreal y, qreal w, qreal h, | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2094 | Qt::AspectRatioMode aspectRatioMode = Qt::IgnoreAspectRatio) | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2095 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
2096 | \overload | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2097 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
2098 | This convenience function is equivalent to calling | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2099 | fitInView(QRectF(\a x, \a y, \a w, \a h), \a aspectRatioMode). | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2100 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
2101 | \sa ensureVisible(), centerOn() | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2102 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2103 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
2104 | /*! | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2105 | \overload | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2106 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
2107 | Ensures that \a item fits tightly inside the view, scaling the view | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2108 | according to \a aspectRatioMode. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2109 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
2110 | \sa ensureVisible(), centerOn() | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2111 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2112 | void QGraphicsView::fitInView(const QGraphicsItem *item, Qt::AspectRatioMode aspectRatioMode) | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2113 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2114 | QPainterPath path = item->isClipped() ? item->clipPath() : item->shape();
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
2115 | if (item->d_ptr->hasTranslateOnlySceneTransform()) {
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
2116 | path.translate(item->d_ptr->sceneTransform.dx(), item->d_ptr->sceneTransform.dy()); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2117 | fitInView(path.boundingRect(), aspectRatioMode); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2118 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
2119 | fitInView(item->d_ptr->sceneTransform.map(path).boundingRect(), aspectRatioMode); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2120 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
2121 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2122 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
2123 | /*! | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2124 | Renders the \a source rect, which is in view coordinates, from the scene | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2125 | into \a target, which is in paint device coordinates, using \a | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2126 | painter. This function is useful for capturing the contents of the view | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2127 | onto a paint device, such as a QImage (e.g., to take a screenshot), or for | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2128 | printing to QPrinter. For example: | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2129 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
2130 | \snippet code/src_gui_graphicsview_qgraphicsview.cpp 4 | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2131 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
2132 | If \a source is a null rect, this function will use viewport()->rect() to | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2133 | determine what to draw. If \a target is a null rect, the full dimensions | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2134 | of \a painter's paint device (e.g., for a QPrinter, the page size) will be | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2135 | used. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2136 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
2137 | The source rect contents will be transformed according to \a | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2138 | aspectRatioMode to fit into the target rect. By default, the aspect ratio | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2139 | is kept, and \a source is scaled to fit in \a target. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2140 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
2141 | \sa QGraphicsScene::render() | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2142 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2143 | void QGraphicsView::render(QPainter *painter, const QRectF &target, const QRect &source, | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2144 | Qt::AspectRatioMode aspectRatioMode) | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2145 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2146 | // ### Switch to using the recursive rendering algorithm instead. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2147 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
2148 | Q_D(QGraphicsView); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2149 | if (!d->scene || !(painter && painter->isActive()))
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
2150 | return; never executed: return; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
2151 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
2152 | // Default source rect = viewport rect | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2153 | QRect sourceRect = source; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2154 | if (source.isNull())
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
2155 | sourceRect = viewport()->rect(); never executed: sourceRect = viewport()->rect(); | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
2156 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
2157 | // Default target rect = device rect | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2158 | QRectF targetRect = target; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2159 | if (target.isNull()) {
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
2160 | if (painter->device()->devType() == QInternal::Picture)
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
2161 | targetRect = sourceRect; never executed: targetRect = sourceRect; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
2162 | else | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2163 | targetRect.setRect(0, 0, painter->device()->width(), painter->device()->height()); never executed: targetRect.setRect(0, 0, painter->device()->width(), painter->device()->height()); | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
2164 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2165 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
2166 | // Find the ideal x / y scaling ratio to fit \a source into \a target. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2167 | qreal xratio = targetRect.width() / sourceRect.width(); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2168 | qreal yratio = targetRect.height() / sourceRect.height(); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2169 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
2170 | // Scale according to the aspect ratio mode. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2171 | switch (aspectRatioMode) { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2172 | case Qt::KeepAspectRatio: never executed: case Qt::KeepAspectRatio: | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
2173 | xratio = yratio = qMin(xratio, yratio); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2174 | break; never executed: break; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
2175 | case Qt::KeepAspectRatioByExpanding: never executed: case Qt::KeepAspectRatioByExpanding: | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
2176 | xratio = yratio = qMax(xratio, yratio); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2177 | break; never executed: break; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
2178 | case Qt::IgnoreAspectRatio: never executed: case Qt::IgnoreAspectRatio: | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
2179 | break; never executed: break; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
2180 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2181 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
2182 | // Find all items to draw, and reverse the list (we want to draw | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2183 | // in reverse order). | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2184 | QPolygonF sourceScenePoly = mapToScene(sourceRect.adjusted(-1, -1, 1, 1)); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2185 | QList<QGraphicsItem *> itemList = d->scene->items(sourceScenePoly, | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2186 | Qt::IntersectsItemBoundingRect); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2187 | QGraphicsItem **itemArray = new QGraphicsItem *[itemList.size()]; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2188 | int numItems = itemList.size(); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2189 | for (int i = 0; i < numItems; ++i)
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
2190 | itemArray[numItems - i - 1] = itemList.at(i); never executed: itemArray[numItems - i - 1] = itemList.at(i); | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
2191 | itemList.clear(); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2192 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
2193 | // Setup painter matrix. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2194 | QTransform moveMatrix = QTransform::fromTranslate(-d->horizontalScroll(), -d->verticalScroll()); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2195 | QTransform painterMatrix = d->matrix * moveMatrix; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2196 | painterMatrix *= QTransform() | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2197 | .translate(targetRect.left(), targetRect.top()) | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2198 | .scale(xratio, yratio) | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2199 | .translate(-sourceRect.left(), -sourceRect.top()); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2200 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
2201 | // Generate the style options | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2202 | QStyleOptionGraphicsItem *styleOptionArray = d->allocStyleOptionsArray(numItems); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2203 | for (int i = 0; i < numItems; ++i)
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
2204 | itemArray[i]->d_ptr->initStyleOption(&styleOptionArray[i], painterMatrix, targetRect.toRect()); never executed: itemArray[i]->d_ptr->initStyleOption(&styleOptionArray[i], painterMatrix, targetRect.toRect()); | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
2205 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
2206 | painter->save(); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2207 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
2208 | // Clip in device coordinates to avoid QRegion transformations. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2209 | painter->setClipRect(targetRect); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2210 | QPainterPath path; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2211 | path.addPolygon(sourceScenePoly); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2212 | path.closeSubpath(); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2213 | painter->setClipPath(painterMatrix.map(path), Qt::IntersectClip); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2214 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
2215 | // Transform the painter. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2216 | painter->setTransform(painterMatrix, true); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2217 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
2218 | // Render the scene. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2219 | QRectF sourceSceneRect = sourceScenePoly.boundingRect(); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2220 | drawBackground(painter, sourceSceneRect); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2221 | drawItems(painter, numItems, itemArray, styleOptionArray); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2222 | drawForeground(painter, sourceSceneRect); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2223 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
2224 | delete [] itemArray; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2225 | d->freeStyleOptionsArray(styleOptionArray); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2226 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
2227 | painter->restore(); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2228 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
2229 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
2230 | /*! | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2231 | Returns a list of all the items in the associated scene, in descending | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2232 | stacking order (i.e., the first item in the returned list is the uppermost | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2233 | item). | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2234 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
2235 | \sa QGraphicsScene::items(), {QGraphicsItem#Sorting}{Sorting} | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2236 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2237 | QList<QGraphicsItem *> QGraphicsView::items() const | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2238 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2239 | Q_D(const QGraphicsView); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2240 | if (!d->scene)
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
2241 | return QList<QGraphicsItem *>(); never executed: return QList<QGraphicsItem *>(); | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
2242 | return d->scene->items(); never executed: return d->scene->items(); | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
2243 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2244 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
2245 | /*! | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2246 | Returns a list of all the items at the position \a pos in the view. The | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2247 | items are listed in descending stacking order (i.e., the first item in the | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2248 | list is the uppermost item, and the last item is the lowermost item). \a | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2249 | pos is in viewport coordinates. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2250 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
2251 | This function is most commonly called from within mouse event handlers in | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2252 | a subclass in QGraphicsView. \a pos is in untransformed viewport | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2253 | coordinates, just like QMouseEvent::pos(). | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2254 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
2255 | \snippet code/src_gui_graphicsview_qgraphicsview.cpp 5 | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2256 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
2257 | \sa QGraphicsScene::items(), {QGraphicsItem#Sorting}{Sorting} | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2258 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2259 | QList<QGraphicsItem *> QGraphicsView::items(const QPoint &pos) const | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2260 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2261 | Q_D(const QGraphicsView); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2262 | if (!d->scene)
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
2263 | return QList<QGraphicsItem *>(); never executed: return QList<QGraphicsItem *>(); | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
2264 | // ### Unify these two, and use the items(QPointF) version in | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2265 | // QGraphicsScene instead. The scene items function could use the viewport | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2266 | // transform to map the point to a rect/polygon. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2267 | if ((d->identityMatrix || d->matrix.type() <= QTransform::TxScale)) {
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
2268 | // Use the rect version | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2269 | QTransform xinv = viewportTransform().inverted(); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2270 | return d->scene->items(xinv.mapRect(QRectF(pos.x(), pos.y(), 1, 1)), never executed: return d->scene->items(xinv.mapRect(QRectF(pos.x(), pos.y(), 1, 1)), Qt::IntersectsItemShape, Qt::DescendingOrder, viewportTransform()); | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
2271 | Qt::IntersectsItemShape, never executed: return d->scene->items(xinv.mapRect(QRectF(pos.x(), pos.y(), 1, 1)), Qt::IntersectsItemShape, Qt::DescendingOrder, viewportTransform()); | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
2272 | Qt::DescendingOrder, never executed: return d->scene->items(xinv.mapRect(QRectF(pos.x(), pos.y(), 1, 1)), Qt::IntersectsItemShape, Qt::DescendingOrder, viewportTransform()); | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
2273 | viewportTransform()); never executed: return d->scene->items(xinv.mapRect(QRectF(pos.x(), pos.y(), 1, 1)), Qt::IntersectsItemShape, Qt::DescendingOrder, viewportTransform()); | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
2274 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2275 | // Use the polygon version | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2276 | return d->scene->items(mapToScene(pos.x(), pos.y(), 1, 1), never executed: return d->scene->items(mapToScene(pos.x(), pos.y(), 1, 1), Qt::IntersectsItemShape, Qt::DescendingOrder, viewportTransform()); | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
2277 | Qt::IntersectsItemShape, never executed: return d->scene->items(mapToScene(pos.x(), pos.y(), 1, 1), Qt::IntersectsItemShape, Qt::DescendingOrder, viewportTransform()); | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
2278 | Qt::DescendingOrder, never executed: return d->scene->items(mapToScene(pos.x(), pos.y(), 1, 1), Qt::IntersectsItemShape, Qt::DescendingOrder, viewportTransform()); | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
2279 | viewportTransform()); never executed: return d->scene->items(mapToScene(pos.x(), pos.y(), 1, 1), Qt::IntersectsItemShape, Qt::DescendingOrder, viewportTransform()); | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
2280 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2281 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
2282 | /*! | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2283 | \fn QGraphicsView::items(int x, int y) const | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2284 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
2285 | This function is provided for convenience. It's equivalent to calling | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2286 | items(QPoint(\a x, \a y)). | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2287 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2288 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
2289 | /*! | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2290 | \overload | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2291 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
2292 | Returns a list of all the items that, depending on \a mode, are either | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2293 | contained by or intersect with \a rect. \a rect is in viewport | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2294 | coordinates. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2295 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
2296 | The default value for \a mode is Qt::IntersectsItemShape; all items whose | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2297 | exact shape intersects with or is contained by \a rect are returned. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2298 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
2299 | The items are sorted in descending stacking order (i.e., the first item in | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2300 | the returned list is the uppermost item). | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2301 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
2302 | \sa itemAt(), items(), mapToScene(), {QGraphicsItem#Sorting}{Sorting} | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2303 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2304 | QList<QGraphicsItem *> QGraphicsView::items(const QRect &rect, Qt::ItemSelectionMode mode) const | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2305 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2306 | Q_D(const QGraphicsView); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2307 | if (!d->scene)
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
2308 | return QList<QGraphicsItem *>(); never executed: return QList<QGraphicsItem *>(); | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
2309 | return d->scene->items(mapToScene(rect), mode, Qt::DescendingOrder, viewportTransform()); never executed: return d->scene->items(mapToScene(rect), mode, Qt::DescendingOrder, viewportTransform()); | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
2310 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2311 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
2312 | /*! | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2313 | \fn QList<QGraphicsItem *> QGraphicsView::items(int x, int y, int w, int h, Qt::ItemSelectionMode mode) const | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2314 | \since 4.3 | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2315 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
2316 | This convenience function is equivalent to calling items(QRectF(\a x, \a | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2317 | y, \a w, \a h), \a mode). | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2318 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2319 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
2320 | /*! | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2321 | \overload | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2322 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
2323 | Returns a list of all the items that, depending on \a mode, are either | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2324 | contained by or intersect with \a polygon. \a polygon is in viewport | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2325 | coordinates. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2326 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
2327 | The default value for \a mode is Qt::IntersectsItemShape; all items whose | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2328 | exact shape intersects with or is contained by \a polygon are returned. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2329 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
2330 | The items are sorted by descending stacking order (i.e., the first item in | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2331 | the returned list is the uppermost item). | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2332 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
2333 | \sa itemAt(), items(), mapToScene(), {QGraphicsItem#Sorting}{Sorting} | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2334 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2335 | QList<QGraphicsItem *> QGraphicsView::items(const QPolygon &polygon, Qt::ItemSelectionMode mode) const | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2336 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2337 | Q_D(const QGraphicsView); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2338 | if (!d->scene)
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
2339 | return QList<QGraphicsItem *>(); never executed: return QList<QGraphicsItem *>(); | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
2340 | return d->scene->items(mapToScene(polygon), mode, Qt::DescendingOrder, viewportTransform()); never executed: return d->scene->items(mapToScene(polygon), mode, Qt::DescendingOrder, viewportTransform()); | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
2341 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2342 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
2343 | /*! | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2344 | \overload | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2345 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
2346 | Returns a list of all the items that, depending on \a mode, are either | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2347 | contained by or intersect with \a path. \a path is in viewport | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2348 | coordinates. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2349 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
2350 | The default value for \a mode is Qt::IntersectsItemShape; all items whose | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2351 | exact shape intersects with or is contained by \a path are returned. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2352 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
2353 | \sa itemAt(), items(), mapToScene(), {QGraphicsItem#Sorting}{Sorting} | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2354 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2355 | QList<QGraphicsItem *> QGraphicsView::items(const QPainterPath &path, Qt::ItemSelectionMode mode) const | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2356 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2357 | Q_D(const QGraphicsView); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2358 | if (!d->scene)
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
2359 | return QList<QGraphicsItem *>(); never executed: return QList<QGraphicsItem *>(); | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
2360 | return d->scene->items(mapToScene(path), mode, Qt::DescendingOrder, viewportTransform()); never executed: return d->scene->items(mapToScene(path), mode, Qt::DescendingOrder, viewportTransform()); | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
2361 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2362 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
2363 | /*! | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2364 | Returns the item at position \a pos, which is in viewport coordinates. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2365 | If there are several items at this position, this function returns | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2366 | the topmost item. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2367 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
2368 | Example: | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2369 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
2370 | \snippet code/src_gui_graphicsview_qgraphicsview.cpp 6 | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2371 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
2372 | \sa items(), {QGraphicsItem#Sorting}{Sorting} | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2373 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2374 | QGraphicsItem *QGraphicsView::itemAt(const QPoint &pos) const | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2375 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2376 | Q_D(const QGraphicsView); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2377 | if (!d->scene)
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
2378 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
2379 | QList<QGraphicsItem *> itemsAtPos = items(pos); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2380 | return itemsAtPos.isEmpty() ? 0 : itemsAtPos.first(); never executed: return itemsAtPos.isEmpty() ? 0 : itemsAtPos.first();
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
2381 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2382 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
2383 | /*! | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2384 | \overload | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2385 | \fn QGraphicsItem *QGraphicsView::itemAt(int x, int y) const | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2386 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
2387 | This function is provided for convenience. It's equivalent to | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2388 | calling itemAt(QPoint(\a x, \a y)). | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2389 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2390 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
2391 | /*! | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2392 | Returns the viewport coordinate \a point mapped to scene coordinates. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2393 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
2394 | Note: It can be useful to map the whole rectangle covered by the pixel at | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2395 | \a point instead of the point itself. To do this, you can call | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2396 | mapToScene(QRect(\a point, QSize(2, 2))). | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2397 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
2398 | \sa mapFromScene() | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2399 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2400 | QPointF QGraphicsView::mapToScene(const QPoint &point) const | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2401 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2402 | Q_D(const QGraphicsView); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2403 | QPointF p = point; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2404 | p.rx() += d->horizontalScroll(); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2405 | p.ry() += d->verticalScroll(); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2406 | return d->identityMatrix ? p : d->matrix.inverted().map(p); never executed: return d->identityMatrix ? p : d->matrix.inverted().map(p);
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
2407 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2408 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
2409 | /*! | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2410 | \fn QGraphicsView::mapToScene(int x, int y) const | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2411 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
2412 | This function is provided for convenience. It's equivalent to calling | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2413 | mapToScene(QPoint(\a x, \a y)). | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2414 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2415 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
2416 | /*! | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2417 | Returns the viewport rectangle \a rect mapped to a scene coordinate | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2418 | polygon. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2419 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
2420 | \sa mapFromScene() | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2421 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2422 | QPolygonF QGraphicsView::mapToScene(const QRect &rect) const | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2423 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2424 | Q_D(const QGraphicsView); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2425 | if (!rect.isValid())
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
2426 | return QPolygonF(); never executed: return QPolygonF(); | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
2427 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
2428 | QPointF scrollOffset(d->horizontalScroll(), d->verticalScroll()); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2429 | QRect r = rect.adjusted(0, 0, 1, 1); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2430 | QPointF tl = scrollOffset + r.topLeft(); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2431 | QPointF tr = scrollOffset + r.topRight(); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2432 | QPointF br = scrollOffset + r.bottomRight(); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2433 | QPointF bl = scrollOffset + r.bottomLeft(); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2434 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
2435 | QPolygonF poly(4); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2436 | if (!d->identityMatrix) {
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
2437 | QTransform x = d->matrix.inverted(); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2438 | poly[0] = x.map(tl); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2439 | poly[1] = x.map(tr); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2440 | poly[2] = x.map(br); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2441 | poly[3] = x.map(bl); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2442 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
2443 | poly[0] = tl; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2444 | poly[1] = tr; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2445 | poly[2] = br; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2446 | poly[3] = bl; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2447 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
2448 | return poly; never executed: return poly; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
2449 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2450 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
2451 | /*! | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2452 | \fn QGraphicsView::mapToScene(int x, int y, int w, int h) const | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2453 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
2454 | This function is provided for convenience. It's equivalent to calling | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2455 | mapToScene(QRect(\a x, \a y, \a w, \a h)). | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2456 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2457 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
2458 | /*! | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2459 | Returns the viewport polygon \a polygon mapped to a scene coordinate | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2460 | polygon. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2461 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
2462 | \sa mapFromScene() | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2463 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2464 | QPolygonF QGraphicsView::mapToScene(const QPolygon &polygon) const | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2465 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2466 | QPolygonF poly; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2467 | poly.reserve(polygon.count()); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2468 | foreach (const QPoint &point, polygon) | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2469 | poly << mapToScene(point); never executed: poly << mapToScene(point); | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
2470 | return poly; never executed: return poly; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
2471 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2472 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
2473 | /*! | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2474 | Returns the viewport painter path \a path mapped to a scene coordinate | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2475 | painter path. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2476 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
2477 | \sa mapFromScene() | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2478 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2479 | QPainterPath QGraphicsView::mapToScene(const QPainterPath &path) const | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2480 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2481 | Q_D(const QGraphicsView); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2482 | QTransform matrix = QTransform::fromTranslate(d->horizontalScroll(), d->verticalScroll()); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2483 | matrix *= d->matrix.inverted(); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2484 | return matrix.map(path); never executed: return matrix.map(path); | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
2485 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2486 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
2487 | /*! | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2488 | Returns the scene coordinate \a point to viewport coordinates. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2489 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
2490 | \sa mapToScene() | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2491 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2492 | QPoint QGraphicsView::mapFromScene(const QPointF &point) const | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2493 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2494 | Q_D(const QGraphicsView); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2495 | QPointF p = d->identityMatrix ? point : d->matrix.map(point);
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
2496 | p.rx() -= d->horizontalScroll(); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2497 | p.ry() -= d->verticalScroll(); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2498 | return p.toPoint(); never executed: return p.toPoint(); | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
2499 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2500 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
2501 | /*! | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2502 | \fn QGraphicsView::mapFromScene(qreal x, qreal y) const | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2503 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
2504 | This function is provided for convenience. It's equivalent to | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2505 | calling mapFromScene(QPointF(\a x, \a y)). | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2506 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2507 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
2508 | /*! | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2509 | Returns the scene rectangle \a rect to a viewport coordinate | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2510 | polygon. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2511 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
2512 | \sa mapToScene() | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2513 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2514 | QPolygon QGraphicsView::mapFromScene(const QRectF &rect) const | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2515 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2516 | Q_D(const QGraphicsView); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2517 | QPointF tl; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2518 | QPointF tr; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2519 | QPointF br; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2520 | QPointF bl; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2521 | if (!d->identityMatrix) {
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
2522 | const QTransform &x = d->matrix; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2523 | tl = x.map(rect.topLeft()); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2524 | tr = x.map(rect.topRight()); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2525 | br = x.map(rect.bottomRight()); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2526 | bl = x.map(rect.bottomLeft()); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2527 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
2528 | tl = rect.topLeft(); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2529 | tr = rect.topRight(); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2530 | br = rect.bottomRight(); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2531 | bl = rect.bottomLeft(); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2532 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
2533 | QPointF scrollOffset(d->horizontalScroll(), d->verticalScroll()); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2534 | tl -= scrollOffset; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2535 | tr -= scrollOffset; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2536 | br -= scrollOffset; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2537 | bl -= scrollOffset; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2538 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
2539 | QPolygon poly(4); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2540 | poly[0] = tl.toPoint(); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2541 | poly[1] = tr.toPoint(); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2542 | poly[2] = br.toPoint(); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2543 | poly[3] = bl.toPoint(); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2544 | return poly; never executed: return poly; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
2545 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2546 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
2547 | /*! | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2548 | \fn QGraphicsView::mapFromScene(qreal x, qreal y, qreal w, qreal h) const | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2549 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
2550 | This function is provided for convenience. It's equivalent to | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2551 | calling mapFromScene(QRectF(\a x, \a y, \a w, \a h)). | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2552 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2553 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
2554 | /*! | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2555 | Returns the scene coordinate polygon \a polygon to a viewport coordinate | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2556 | polygon. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2557 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
2558 | \sa mapToScene() | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2559 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2560 | QPolygon QGraphicsView::mapFromScene(const QPolygonF &polygon) const | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2561 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2562 | QPolygon poly; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2563 | poly.reserve(polygon.count()); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2564 | foreach (const QPointF &point, polygon) | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2565 | poly << mapFromScene(point); never executed: poly << mapFromScene(point); | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
2566 | return poly; never executed: return poly; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
2567 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2568 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
2569 | /*! | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2570 | Returns the scene coordinate painter path \a path to a viewport coordinate | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2571 | painter path. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2572 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
2573 | \sa mapToScene() | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2574 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2575 | QPainterPath QGraphicsView::mapFromScene(const QPainterPath &path) const | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2576 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2577 | Q_D(const QGraphicsView); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2578 | QTransform matrix = d->matrix; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2579 | matrix *= QTransform::fromTranslate(-d->horizontalScroll(), -d->verticalScroll()); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2580 | return matrix.map(path); never executed: return matrix.map(path); | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
2581 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2582 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
2583 | /*! | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2584 | \reimp | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2585 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2586 | QVariant QGraphicsView::inputMethodQuery(Qt::InputMethodQuery query) const | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2587 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2588 | Q_D(const QGraphicsView); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2589 | if (!d->scene)
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
2590 | return QVariant(); never executed: return QVariant(); | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
2591 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
2592 | QVariant value = d->scene->inputMethodQuery(query); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2593 | if (value.type() == QVariant::RectF)
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
2594 | value = d->mapRectFromScene(value.toRectF()); never executed: value = d->mapRectFromScene(value.toRectF()); | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
2595 | else if (value.type() == QVariant::PointF)
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
2596 | value = mapFromScene(value.toPointF()); never executed: value = mapFromScene(value.toPointF()); | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
2597 | else if (value.type() == QVariant::Rect)
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
2598 | value = d->mapRectFromScene(value.toRect()).toRect(); never executed: value = d->mapRectFromScene(value.toRect()).toRect(); | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
2599 | else if (value.type() == QVariant::Point)
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
2600 | value = mapFromScene(value.toPoint()); never executed: value = mapFromScene(value.toPoint()); | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
2601 | return value; never executed: return value; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
2602 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2603 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
2604 | /*! | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2605 | \property QGraphicsView::backgroundBrush | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2606 | \brief the background brush of the scene. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2607 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
2608 | This property sets the background brush for the scene in this view. It is | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2609 | used to override the scene's own background, and defines the behavior of | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2610 | drawBackground(). To provide custom background drawing for this view, you | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2611 | can reimplement drawBackground() instead. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2612 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
2613 | By default, this property contains a brush with the Qt::NoBrush pattern. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2614 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
2615 | \sa QGraphicsScene::backgroundBrush, foregroundBrush | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2616 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2617 | QBrush QGraphicsView::backgroundBrush() const | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2618 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2619 | Q_D(const QGraphicsView); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2620 | return d->backgroundBrush; never executed: return d->backgroundBrush; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
2621 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2622 | void QGraphicsView::setBackgroundBrush(const QBrush &brush) | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2623 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2624 | Q_D(QGraphicsView); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2625 | d->backgroundBrush = brush; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2626 | d->updateAll(); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2627 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
2628 | if (d->cacheMode & CacheBackground) {
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
2629 | // Invalidate the background pixmap | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2630 | d->mustResizeBackgroundPixmap = true; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2631 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
2632 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
2633 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
2634 | /*! | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2635 | \property QGraphicsView::foregroundBrush | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2636 | \brief the foreground brush of the scene. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2637 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
2638 | This property sets the foreground brush for the scene in this view. It is | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2639 | used to override the scene's own foreground, and defines the behavior of | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2640 | drawForeground(). To provide custom foreground drawing for this view, you | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2641 | can reimplement drawForeground() instead. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2642 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
2643 | By default, this property contains a brush with the Qt::NoBrush pattern. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2644 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
2645 | \sa QGraphicsScene::foregroundBrush, backgroundBrush | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2646 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2647 | QBrush QGraphicsView::foregroundBrush() const | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2648 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2649 | Q_D(const QGraphicsView); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2650 | return d->foregroundBrush; never executed: return d->foregroundBrush; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
2651 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2652 | void QGraphicsView::setForegroundBrush(const QBrush &brush) | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2653 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2654 | Q_D(QGraphicsView); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2655 | d->foregroundBrush = brush; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2656 | d->updateAll(); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2657 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
2658 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
2659 | /*! | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2660 | Schedules an update of the scene rectangles \a rects. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2661 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
2662 | \sa QGraphicsScene::changed() | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2663 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2664 | void QGraphicsView::updateScene(const QList<QRectF> &rects) | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2665 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2666 | // ### Note: Since 4.5, this slot is only called if the user explicitly | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2667 | // establishes a connection between the scene and the view, as the scene | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2668 | // and view are no longer connected. We need to keep it working (basically | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2669 | // leave it as it is), but the new delivery path is through | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2670 | // QGraphicsScenePrivate::itemUpdate(). | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2671 | Q_D(QGraphicsView); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2672 | if (d->fullUpdatePending || d->viewportUpdateMode == QGraphicsView::NoViewportUpdate)
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
2673 | return; never executed: return; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
2674 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
2675 | // Extract and reset dirty scene rect info. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2676 | QVector<QRect> dirtyViewportRects; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2677 | const QVector<QRect> &dirtyRects = d->dirtyRegion.rects(); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2678 | const int dirtyRectsCount = dirtyRects.size(); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2679 | dirtyViewportRects.reserve(dirtyRectsCount + rects.count()); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2680 | for (int i = 0; i < dirtyRectsCount; ++i)
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
2681 | dirtyViewportRects += dirtyRects.at(i); never executed: dirtyViewportRects += dirtyRects.at(i); | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
2682 | d->dirtyRegion = QRegion(); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2683 | d->dirtyBoundingRect = QRect(); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2684 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
2685 | bool fullUpdate = !d->accelerateScrolling || d->viewportUpdateMode == QGraphicsView::FullViewportUpdate;
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
2686 | bool boundingRectUpdate = (d->viewportUpdateMode == QGraphicsView::BoundingRectViewportUpdate)
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
2687 | || (d->viewportUpdateMode == QGraphicsView::SmartViewportUpdate
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
2688 | && ((dirtyViewportRects.size() + rects.size()) >= QGRAPHICSVIEW_REGION_RECT_THRESHOLD));
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
2689 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
2690 | QRegion updateRegion; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2691 | QRect boundingRect; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2692 | QRect viewportRect = viewport()->rect(); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2693 | bool redraw = false; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2694 | QTransform transform = viewportTransform(); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2695 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
2696 | // Convert scene rects to viewport rects. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2697 | foreach (const QRectF &rect, rects) { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2698 | QRect xrect = transform.mapRect(rect).toAlignedRect(); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2699 | if (!(d->optimizationFlags & DontAdjustForAntialiasing))
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
2700 | xrect.adjust(-2, -2, 2, 2); never executed: xrect.adjust(-2, -2, 2, 2); | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
2701 | else | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2702 | xrect.adjust(-1, -1, 1, 1); never executed: xrect.adjust(-1, -1, 1, 1); | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
2703 | if (!viewportRect.intersects(xrect))
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
2704 | continue; never executed: continue; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
2705 | dirtyViewportRects << xrect; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2706 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
2707 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
2708 | foreach (const QRect &rect, dirtyViewportRects) { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2709 | // Add the exposed rect to the update region. In rect update | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2710 | // mode, we only count the bounding rect of items. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2711 | if (!boundingRectUpdate) {
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
2712 | updateRegion += rect; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2713 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
2714 | boundingRect |= rect; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2715 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
2716 | redraw = true; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2717 | if (fullUpdate) {
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
2718 | // If fullUpdate is true and we found a visible dirty rect, | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2719 | // we're done. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2720 | break; never executed: break; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
2721 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2722 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
2723 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
2724 | if (!redraw)
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
2725 | return; never executed: return; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
2726 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
2727 | if (fullUpdate)
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
2728 | viewport()->update(); never executed: viewport()->update(); | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
2729 | else if (boundingRectUpdate)
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
2730 | viewport()->update(boundingRect); never executed: viewport()->update(boundingRect); | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
2731 | else | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2732 | viewport()->update(updateRegion); never executed: viewport()->update(updateRegion); | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
2733 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2734 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
2735 | /*! | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2736 | Notifies QGraphicsView that the scene's scene rect has changed. \a rect | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2737 | is the new scene rect. If the view already has an explicitly set scene | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2738 | rect, this function does nothing. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2739 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
2740 | \sa sceneRect, QGraphicsScene::sceneRectChanged() | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2741 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2742 | void QGraphicsView::updateSceneRect(const QRectF &rect) | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2743 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2744 | Q_D(QGraphicsView); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2745 | if (!d->hasSceneRect) {
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
2746 | d->sceneRect = rect; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2747 | d->recalculateContentSize(); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2748 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
2749 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
2750 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
2751 | /*! | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2752 | This slot is called by QAbstractScrollArea after setViewport() has been | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2753 | called. Reimplement this function in a subclass of QGraphicsView to | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2754 | initialize the new viewport \a widget before it is used. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2755 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
2756 | \sa setViewport() | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2757 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2758 | void QGraphicsView::setupViewport(QWidget *widget) | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2759 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2760 | Q_D(QGraphicsView); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2761 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
2762 | if (!widget) {
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
2763 | qWarning("QGraphicsView::setupViewport: cannot initialize null widget"); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2764 | return; never executed: return; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
2765 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2766 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
2767 | const bool isGLWidget = widget->inherits("QGLWidget") || widget->inherits("QOpenGLWidget");
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
2768 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
2769 | d->accelerateScrolling = !(isGLWidget); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2770 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
2771 | widget->setFocusPolicy(Qt::StrongFocus); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2772 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
2773 | if (!isGLWidget) {
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
2774 | // autoFillBackground enables scroll acceleration. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2775 | widget->setAutoFillBackground(true); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2776 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
2777 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
2778 | // We are only interested in mouse tracking if items | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2779 | // accept hover events or use non-default cursors or if | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2780 | // AnchorUnderMouse is used as transformation or resize anchor. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2781 | if ((d->scene && (!d->scene->d_func()->allItemsIgnoreHoverEvents
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
2782 | || !d->scene->d_func()->allItemsUseDefaultCursor))
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
2783 | || d->transformationAnchor == AnchorUnderMouse
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
2784 | || d->resizeAnchor == AnchorUnderMouse) {
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
2785 | widget->setMouseTracking(true); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2786 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
2787 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
2788 | // enable touch events if any items is interested in them | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2789 | if (d->scene && !d->scene->d_func()->allItemsIgnoreTouchEvents)
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
2790 | widget->setAttribute(Qt::WA_AcceptTouchEvents); never executed: widget->setAttribute(Qt::WA_AcceptTouchEvents); | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
2791 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
2792 | #ifndef QT_NO_GESTURES | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2793 | if (d->scene) {
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
2794 | foreach (Qt::GestureType gesture, d->scene->d_func()->grabbedGestures.keys()) | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2795 | widget->grabGesture(gesture); never executed: widget->grabGesture(gesture); | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
2796 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
2797 | #endif | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2798 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
2799 | widget->setAcceptDrops(acceptDrops()); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2800 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
2801 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
2802 | /*! | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2803 | \reimp | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2804 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2805 | bool QGraphicsView::event(QEvent *event) | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2806 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2807 | Q_D(QGraphicsView); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2808 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
2809 | if (d->sceneInteractionAllowed) {
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
2810 | switch (event->type()) { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2811 | case QEvent::ShortcutOverride: never executed: case QEvent::ShortcutOverride: | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
2812 | if (d->scene)
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
2813 | return QApplication::sendEvent(d->scene, event); never executed: return QApplication::sendEvent(d->scene, event); | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
2814 | break; never executed: break; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
2815 | case QEvent::KeyPress: never executed: case QEvent::KeyPress: | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
2816 | if (d->scene) {
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
2817 | QKeyEvent *k = static_cast<QKeyEvent *>(event); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2818 | if (k->key() == Qt::Key_Tab || k->key() == Qt::Key_Backtab) {
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
2819 | // Send the key events to the scene. This will invoke the | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2820 | // scene's tab focus handling, and if the event is | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2821 | // accepted, we return (prevent further event delivery), | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2822 | // and the base implementation will call QGraphicsView's | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2823 | // focusNextPrevChild() function. If the event is ignored, | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2824 | // we fall back to standard tab focus handling. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2825 | QApplication::sendEvent(d->scene, event); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2826 | if (event->isAccepted())
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
2827 | return true; never executed: return true; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
2828 | // Ensure the event doesn't propagate just because the | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2829 | // scene ignored it. If the event propagates, then tab | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2830 | // handling will be called twice (this and parent). | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2831 | event->accept(); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2832 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
2833 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
2834 | break; never executed: break; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
2835 | default: never executed: default: | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
2836 | break; never executed: break; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
2837 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2838 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2839 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
2840 | return QAbstractScrollArea::event(event); never executed: return QAbstractScrollArea::event(event); | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
2841 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2842 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
2843 | /*! | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2844 | \reimp | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2845 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2846 | bool QGraphicsView::viewportEvent(QEvent *event) | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2847 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2848 | Q_D(QGraphicsView); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2849 | if (!d->scene)
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
2850 | return QAbstractScrollArea::viewportEvent(event); never executed: return QAbstractScrollArea::viewportEvent(event); | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
2851 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
2852 | switch (event->type()) { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2853 | case QEvent::Enter: never executed: case QEvent::Enter: | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
2854 | QApplication::sendEvent(d->scene, event); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2855 | break; never executed: break; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
2856 | case QEvent::WindowActivate: never executed: case QEvent::WindowActivate: | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
2857 | QApplication::sendEvent(d->scene, event); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2858 | break; never executed: break; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
2859 | case QEvent::WindowDeactivate: never executed: case QEvent::WindowDeactivate: | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
2860 | // ### This is a temporary fix for until we get proper mouse | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2861 | // grab events. mouseGrabberItem should be set to 0 if we lose | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2862 | // the mouse grab. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2863 | // Remove all popups when the scene loses focus. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2864 | if (!d->scene->d_func()->popupWidgets.isEmpty())
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
2865 | d->scene->d_func()->removePopup(d->scene->d_func()->popupWidgets.first()); never executed: d->scene->d_func()->removePopup(d->scene->d_func()->popupWidgets.first()); | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
2866 | QApplication::sendEvent(d->scene, event); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2867 | break; never executed: break; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
2868 | case QEvent::Show: never executed: case QEvent::Show: | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
2869 | if (d->scene && isActiveWindow()) {
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
2870 | QEvent windowActivate(QEvent::WindowActivate); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2871 | QApplication::sendEvent(d->scene, &windowActivate); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2872 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
2873 | break; never executed: break; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
2874 | case QEvent::Hide: never executed: case QEvent::Hide: | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
2875 | // spontaneous event will generate a WindowDeactivate. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2876 | if (!event->spontaneous() && d->scene && isActiveWindow()) {
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
2877 | QEvent windowDeactivate(QEvent::WindowDeactivate); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2878 | QApplication::sendEvent(d->scene, &windowDeactivate); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2879 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
2880 | break; never executed: break; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
2881 | case QEvent::Leave: { never executed: case QEvent::Leave: | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
2882 | // ### This is a temporary fix for until we get proper mouse grab | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2883 | // events. activeMouseGrabberItem should be set to 0 if we lose the | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2884 | // mouse grab. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2885 | if ((QApplication::activePopupWidget() && QApplication::activePopupWidget() != window())
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
2886 | || (QApplication::activeModalWidget() && QApplication::activeModalWidget() != window())
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
2887 | || (QApplication::activeWindow() != window())) {
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
2888 | if (!d->scene->d_func()->popupWidgets.isEmpty())
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
2889 | d->scene->d_func()->removePopup(d->scene->d_func()->popupWidgets.first()); never executed: d->scene->d_func()->removePopup(d->scene->d_func()->popupWidgets.first()); | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
2890 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
2891 | d->useLastMouseEvent = false; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2892 | // a hack to pass a viewport pointer to the scene inside the leave event | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2893 | Q_ASSERT(event->d == 0); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2894 | QScopedValueRollback<QEventPrivate *> rb(event->d); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2895 | event->d = reinterpret_cast<QEventPrivate *>(viewport()); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2896 | QApplication::sendEvent(d->scene, event); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2897 | break; never executed: break; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
2898 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2899 | #ifndef QT_NO_TOOLTIP | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2900 | case QEvent::ToolTip: { never executed: case QEvent::ToolTip: | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
2901 | QHelpEvent *toolTip = static_cast<QHelpEvent *>(event); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2902 | QGraphicsSceneHelpEvent helpEvent(QEvent::GraphicsSceneHelp); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2903 | helpEvent.setWidget(viewport()); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2904 | helpEvent.setScreenPos(toolTip->globalPos()); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2905 | helpEvent.setScenePos(mapToScene(toolTip->pos())); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2906 | QApplication::sendEvent(d->scene, &helpEvent); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2907 | toolTip->setAccepted(helpEvent.isAccepted()); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2908 | return true; never executed: return true; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
2909 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2910 | #endif | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2911 | case QEvent::Paint: never executed: case QEvent::Paint: | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
2912 | // Reset full update | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2913 | d->fullUpdatePending = false; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2914 | d->dirtyScrollOffset = QPoint(); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2915 | if (d->scene) {
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
2916 | // Check if this view reimplements the updateScene slot; if it | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2917 | // does, we can't do direct update delivery and have to fall back | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2918 | // to connecting the changed signal. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2919 | if (!d->updateSceneSlotReimplementedChecked) {
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
2920 | d->updateSceneSlotReimplementedChecked = true; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2921 | const QMetaObject *mo = metaObject(); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2922 | if (mo != &QGraphicsView::staticMetaObject) {
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
2923 | if (mo->indexOfSlot("updateScene(QList<QRectF>)")
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
2924 | != QGraphicsView::staticMetaObject.indexOfSlot("updateScene(QList<QRectF>)")) {
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
2925 | connect(d->scene, SIGNAL(changed(QList<QRectF>)), | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2926 | this, SLOT(updateScene(QList<QRectF>))); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2927 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
2928 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
2929 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
2930 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
2931 | break; never executed: break; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
2932 | case QEvent::TouchBegin: never executed: case QEvent::TouchBegin: | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
2933 | case QEvent::TouchUpdate: never executed: case QEvent::TouchUpdate: | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
2934 | case QEvent::TouchEnd: never executed: case QEvent::TouchEnd: | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
2935 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2936 | if (!isEnabled())
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
2937 | return false; never executed: return false; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
2938 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
2939 | if (d->scene && d->sceneInteractionAllowed) {
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
2940 | // Convert and deliver the touch event to the scene. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2941 | QTouchEvent *touchEvent = static_cast<QTouchEvent *>(event); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2942 | touchEvent->setTarget(viewport()); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2943 | QGraphicsViewPrivate::translateTouchEvent(d, touchEvent); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2944 | (void) QApplication::sendEvent(d->scene, touchEvent); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2945 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
2946 | event->ignore(); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2947 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
2948 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
2949 | return true; never executed: return true; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
2950 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2951 | #ifndef QT_NO_GESTURES | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2952 | case QEvent::Gesture: never executed: case QEvent::Gesture: | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
2953 | case QEvent::GestureOverride: never executed: case QEvent::GestureOverride: | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
2954 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2955 | if (!isEnabled())
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
2956 | return false; never executed: return false; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
2957 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
2958 | if (d->scene && d->sceneInteractionAllowed) {
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
2959 | QGestureEvent *gestureEvent = static_cast<QGestureEvent *>(event); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2960 | gestureEvent->setWidget(viewport()); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2961 | (void) QApplication::sendEvent(d->scene, gestureEvent); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2962 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
2963 | return true; never executed: return true; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
2964 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2965 | #endif // QT_NO_GESTURES | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2966 | default: never executed: default: | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
2967 | break; never executed: break; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
2968 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2969 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
2970 | return QAbstractScrollArea::viewportEvent(event); never executed: return QAbstractScrollArea::viewportEvent(event); | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
2971 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2972 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
2973 | #ifndef QT_NO_CONTEXTMENU | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2974 | /*! | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2975 | \reimp | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2976 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2977 | void QGraphicsView::contextMenuEvent(QContextMenuEvent *event) | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2978 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2979 | Q_D(QGraphicsView); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2980 | if (!d->scene || !d->sceneInteractionAllowed)
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
2981 | return; never executed: return; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
2982 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
2983 | d->mousePressViewPoint = event->pos(); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2984 | d->mousePressScenePoint = mapToScene(d->mousePressViewPoint); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2985 | d->mousePressScreenPoint = event->globalPos(); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2986 | d->lastMouseMoveScenePoint = d->mousePressScenePoint; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2987 | d->lastMouseMoveScreenPoint = d->mousePressScreenPoint; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2988 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
2989 | QGraphicsSceneContextMenuEvent contextEvent(QEvent::GraphicsSceneContextMenu); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2990 | contextEvent.setWidget(viewport()); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2991 | contextEvent.setScenePos(d->mousePressScenePoint); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2992 | contextEvent.setScreenPos(d->mousePressScreenPoint); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2993 | contextEvent.setModifiers(event->modifiers()); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2994 | contextEvent.setReason((QGraphicsSceneContextMenuEvent::Reason)(event->reason())); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2995 | contextEvent.setAccepted(event->isAccepted()); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2996 | QApplication::sendEvent(d->scene, &contextEvent); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2997 | event->setAccepted(contextEvent.isAccepted()); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2998 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
2999 | #endif // QT_NO_CONTEXTMENU | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3000 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
3001 | /*! | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3002 | \reimp | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3003 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3004 | void QGraphicsView::dropEvent(QDropEvent *event) | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3005 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3006 | #ifndef QT_NO_DRAGANDDROP | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3007 | Q_D(QGraphicsView); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3008 | if (!d->scene || !d->sceneInteractionAllowed)
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
3009 | return; never executed: return; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
3010 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
3011 | // Generate a scene event. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3012 | QGraphicsSceneDragDropEvent sceneEvent(QEvent::GraphicsSceneDrop); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3013 | d->populateSceneDragDropEvent(&sceneEvent, event); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3014 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
3015 | // Send it to the scene. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3016 | QApplication::sendEvent(d->scene, &sceneEvent); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3017 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
3018 | // Accept the originating event if the scene accepted the scene event. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3019 | event->setAccepted(sceneEvent.isAccepted()); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3020 | if (sceneEvent.isAccepted())
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
3021 | event->setDropAction(sceneEvent.dropAction()); never executed: event->setDropAction(sceneEvent.dropAction()); | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
3022 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
3023 | delete d->lastDragDropEvent; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3024 | d->lastDragDropEvent = 0; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3025 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
3026 | #else | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3027 | Q_UNUSED(event) | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3028 | #endif | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3029 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
3030 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
3031 | /*! | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3032 | \reimp | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3033 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3034 | void QGraphicsView::dragEnterEvent(QDragEnterEvent *event) | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3035 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3036 | #ifndef QT_NO_DRAGANDDROP | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3037 | Q_D(QGraphicsView); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3038 | if (!d->scene || !d->sceneInteractionAllowed)
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
3039 | return; never executed: return; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
3040 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
3041 | // Disable replaying of mouse move events. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3042 | d->useLastMouseEvent = false; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3043 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
3044 | // Generate a scene event. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3045 | QGraphicsSceneDragDropEvent sceneEvent(QEvent::GraphicsSceneDragEnter); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3046 | d->populateSceneDragDropEvent(&sceneEvent, event); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3047 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
3048 | // Store it for later use. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3049 | d->storeDragDropEvent(&sceneEvent); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3050 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
3051 | // Send it to the scene. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3052 | QApplication::sendEvent(d->scene, &sceneEvent); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3053 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
3054 | // Accept the originating event if the scene accepted the scene event. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3055 | if (sceneEvent.isAccepted()) {
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
3056 | event->setAccepted(true); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3057 | event->setDropAction(sceneEvent.dropAction()); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3058 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
3059 | #else | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3060 | Q_UNUSED(event) | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3061 | #endif | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3062 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
3063 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
3064 | /*! | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3065 | \reimp | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3066 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3067 | void QGraphicsView::dragLeaveEvent(QDragLeaveEvent *event) | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3068 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3069 | #ifndef QT_NO_DRAGANDDROP | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3070 | Q_D(QGraphicsView); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3071 | if (!d->scene || !d->sceneInteractionAllowed)
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
3072 | return; never executed: return; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
3073 | if (!d->lastDragDropEvent) {
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
3074 | qWarning("QGraphicsView::dragLeaveEvent: drag leave received before drag enter"); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3075 | return; never executed: return; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
3076 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3077 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
3078 | // Generate a scene event. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3079 | QGraphicsSceneDragDropEvent sceneEvent(QEvent::GraphicsSceneDragLeave); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3080 | sceneEvent.setScenePos(d->lastDragDropEvent->scenePos()); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3081 | sceneEvent.setScreenPos(d->lastDragDropEvent->screenPos()); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3082 | sceneEvent.setButtons(d->lastDragDropEvent->buttons()); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3083 | sceneEvent.setModifiers(d->lastDragDropEvent->modifiers()); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3084 | sceneEvent.setPossibleActions(d->lastDragDropEvent->possibleActions()); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3085 | sceneEvent.setProposedAction(d->lastDragDropEvent->proposedAction()); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3086 | sceneEvent.setDropAction(d->lastDragDropEvent->dropAction()); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3087 | sceneEvent.setMimeData(d->lastDragDropEvent->mimeData()); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3088 | sceneEvent.setWidget(d->lastDragDropEvent->widget()); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3089 | sceneEvent.setSource(d->lastDragDropEvent->source()); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3090 | delete d->lastDragDropEvent; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3091 | d->lastDragDropEvent = 0; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3092 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
3093 | // Send it to the scene. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3094 | QApplication::sendEvent(d->scene, &sceneEvent); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3095 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
3096 | // Accept the originating event if the scene accepted the scene event. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3097 | if (sceneEvent.isAccepted())
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
3098 | event->setAccepted(true); never executed: event->setAccepted(true); | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
3099 | #else | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3100 | Q_UNUSED(event) | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3101 | #endif | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3102 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
3103 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
3104 | /*! | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3105 | \reimp | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3106 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3107 | void QGraphicsView::dragMoveEvent(QDragMoveEvent *event) | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3108 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3109 | #ifndef QT_NO_DRAGANDDROP | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3110 | Q_D(QGraphicsView); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3111 | if (!d->scene || !d->sceneInteractionAllowed)
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
3112 | return; never executed: return; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
3113 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
3114 | // Generate a scene event. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3115 | QGraphicsSceneDragDropEvent sceneEvent(QEvent::GraphicsSceneDragMove); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3116 | d->populateSceneDragDropEvent(&sceneEvent, event); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3117 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
3118 | // Store it for later use. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3119 | d->storeDragDropEvent(&sceneEvent); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3120 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
3121 | // Send it to the scene. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3122 | QApplication::sendEvent(d->scene, &sceneEvent); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3123 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
3124 | // Ignore the originating event if the scene ignored the scene event. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3125 | event->setAccepted(sceneEvent.isAccepted()); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3126 | if (sceneEvent.isAccepted())
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
3127 | event->setDropAction(sceneEvent.dropAction()); never executed: event->setDropAction(sceneEvent.dropAction()); | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
3128 | #else | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3129 | Q_UNUSED(event) | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3130 | #endif | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3131 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
3132 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
3133 | /*! | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3134 | \reimp | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3135 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3136 | void QGraphicsView::focusInEvent(QFocusEvent *event) | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3137 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3138 | Q_D(QGraphicsView); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3139 | d->updateInputMethodSensitivity(); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3140 | QAbstractScrollArea::focusInEvent(event); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3141 | if (d->scene)
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
3142 | QApplication::sendEvent(d->scene, event); never executed: QApplication::sendEvent(d->scene, event); | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
3143 | // Pass focus on if the scene cannot accept focus. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3144 | if (!d->scene || !event->isAccepted())
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
3145 | QAbstractScrollArea::focusInEvent(event); never executed: QAbstractScrollArea::focusInEvent(event); | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
3146 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
3147 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
3148 | /*! | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3149 | \reimp | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3150 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3151 | bool QGraphicsView::focusNextPrevChild(bool next) | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3152 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3153 | return QAbstractScrollArea::focusNextPrevChild(next); never executed: return QAbstractScrollArea::focusNextPrevChild(next); | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
3154 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3155 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
3156 | /*! | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3157 | \reimp | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3158 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3159 | void QGraphicsView::focusOutEvent(QFocusEvent *event) | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3160 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3161 | Q_D(QGraphicsView); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3162 | QAbstractScrollArea::focusOutEvent(event); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3163 | if (d->scene)
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
3164 | QApplication::sendEvent(d->scene, event); never executed: QApplication::sendEvent(d->scene, event); | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
3165 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
3166 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
3167 | /*! | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3168 | \reimp | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3169 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3170 | void QGraphicsView::keyPressEvent(QKeyEvent *event) | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3171 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3172 | Q_D(QGraphicsView); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3173 | if (!d->scene || !d->sceneInteractionAllowed) {
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
3174 | QAbstractScrollArea::keyPressEvent(event); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3175 | return; never executed: return; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
3176 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3177 | QApplication::sendEvent(d->scene, event); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3178 | if (!event->isAccepted())
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
3179 | QAbstractScrollArea::keyPressEvent(event); never executed: QAbstractScrollArea::keyPressEvent(event); | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
3180 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
3181 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
3182 | /*! | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3183 | \reimp | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3184 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3185 | void QGraphicsView::keyReleaseEvent(QKeyEvent *event) | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3186 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3187 | Q_D(QGraphicsView); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3188 | if (!d->scene || !d->sceneInteractionAllowed)
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
3189 | return; never executed: return; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
3190 | QApplication::sendEvent(d->scene, event); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3191 | if (!event->isAccepted())
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
3192 | QAbstractScrollArea::keyReleaseEvent(event); never executed: QAbstractScrollArea::keyReleaseEvent(event); | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
3193 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
3194 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
3195 | /*! | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3196 | \reimp | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3197 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3198 | void QGraphicsView::mouseDoubleClickEvent(QMouseEvent *event) | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3199 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3200 | Q_D(QGraphicsView); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3201 | if (!d->scene || !d->sceneInteractionAllowed)
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
3202 | return; never executed: return; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
3203 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
3204 | d->storeMouseEvent(event); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3205 | d->mousePressViewPoint = event->pos(); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3206 | d->mousePressScenePoint = mapToScene(d->mousePressViewPoint); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3207 | d->mousePressScreenPoint = event->globalPos(); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3208 | d->lastMouseMoveScenePoint = d->mousePressScenePoint; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3209 | d->lastMouseMoveScreenPoint = d->mousePressScreenPoint; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3210 | d->mousePressButton = event->button(); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3211 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
3212 | QGraphicsSceneMouseEvent mouseEvent(QEvent::GraphicsSceneMouseDoubleClick); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3213 | mouseEvent.setWidget(viewport()); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3214 | mouseEvent.setButtonDownScenePos(d->mousePressButton, d->mousePressScenePoint); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3215 | mouseEvent.setButtonDownScreenPos(d->mousePressButton, d->mousePressScreenPoint); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3216 | mouseEvent.setScenePos(mapToScene(d->mousePressViewPoint)); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3217 | mouseEvent.setScreenPos(d->mousePressScreenPoint); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3218 | mouseEvent.setLastScenePos(d->lastMouseMoveScenePoint); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3219 | mouseEvent.setLastScreenPos(d->lastMouseMoveScreenPoint); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3220 | mouseEvent.setButtons(event->buttons()); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3221 | mouseEvent.setAccepted(false); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3222 | mouseEvent.setButton(event->button()); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3223 | mouseEvent.setModifiers(event->modifiers()); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3224 | mouseEvent.setSource(event->source()); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3225 | mouseEvent.setFlags(event->flags()); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3226 | if (event->spontaneous())
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
3227 | qt_sendSpontaneousEvent(d->scene, &mouseEvent); never executed: qt_sendSpontaneousEvent(d->scene, &mouseEvent); | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
3228 | else | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3229 | QApplication::sendEvent(d->scene, &mouseEvent); never executed: QApplication::sendEvent(d->scene, &mouseEvent); | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
3230 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
3231 | // Update the original mouse event accepted state. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3232 | const bool isAccepted = mouseEvent.isAccepted(); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3233 | event->setAccepted(isAccepted); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3234 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
3235 | // Update the last mouse event accepted state. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3236 | d->lastMouseEvent.setAccepted(isAccepted); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3237 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
3238 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
3239 | /*! | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3240 | \reimp | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3241 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3242 | void QGraphicsView::mousePressEvent(QMouseEvent *event) | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3243 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3244 | Q_D(QGraphicsView); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3245 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
3246 | // Store this event for replaying, finding deltas, and for | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3247 | // scroll-dragging; even in non-interactive mode, scroll hand dragging is | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3248 | // allowed, so we store the event at the very top of this function. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3249 | d->storeMouseEvent(event); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3250 | d->lastMouseEvent.setAccepted(false); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3251 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
3252 | if (d->sceneInteractionAllowed) {
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
3253 | // Store some of the event's button-down data. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3254 | d->mousePressViewPoint = event->pos(); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3255 | d->mousePressScenePoint = mapToScene(d->mousePressViewPoint); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3256 | d->mousePressScreenPoint = event->globalPos(); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3257 | d->lastMouseMoveScenePoint = d->mousePressScenePoint; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3258 | d->lastMouseMoveScreenPoint = d->mousePressScreenPoint; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3259 | d->mousePressButton = event->button(); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3260 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
3261 | if (d->scene) {
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
3262 | // Convert and deliver the mouse event to the scene. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3263 | QGraphicsSceneMouseEvent mouseEvent(QEvent::GraphicsSceneMousePress); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3264 | mouseEvent.setWidget(viewport()); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3265 | mouseEvent.setButtonDownScenePos(d->mousePressButton, d->mousePressScenePoint); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3266 | mouseEvent.setButtonDownScreenPos(d->mousePressButton, d->mousePressScreenPoint); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3267 | mouseEvent.setScenePos(d->mousePressScenePoint); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3268 | mouseEvent.setScreenPos(d->mousePressScreenPoint); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3269 | mouseEvent.setLastScenePos(d->lastMouseMoveScenePoint); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3270 | mouseEvent.setLastScreenPos(d->lastMouseMoveScreenPoint); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3271 | mouseEvent.setButtons(event->buttons()); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3272 | mouseEvent.setButton(event->button()); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3273 | mouseEvent.setModifiers(event->modifiers()); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3274 | mouseEvent.setSource(event->source()); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3275 | mouseEvent.setFlags(event->flags()); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3276 | mouseEvent.setAccepted(false); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3277 | if (event->spontaneous())
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
3278 | qt_sendSpontaneousEvent(d->scene, &mouseEvent); never executed: qt_sendSpontaneousEvent(d->scene, &mouseEvent); | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
3279 | else | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3280 | QApplication::sendEvent(d->scene, &mouseEvent); never executed: QApplication::sendEvent(d->scene, &mouseEvent); | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
3281 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
3282 | // Update the original mouse event accepted state. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3283 | bool isAccepted = mouseEvent.isAccepted(); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3284 | event->setAccepted(isAccepted); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3285 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
3286 | // Update the last mouse event accepted state. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3287 | d->lastMouseEvent.setAccepted(isAccepted); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3288 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
3289 | if (isAccepted)
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
3290 | return; never executed: return; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
3291 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
3292 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
3293 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
3294 | #ifndef QT_NO_RUBBERBAND | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3295 | if (d->dragMode == QGraphicsView::RubberBandDrag && !d->rubberBanding) {
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
3296 | if (d->sceneInteractionAllowed) {
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
3297 | // Rubberbanding is only allowed in interactive mode. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3298 | event->accept(); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3299 | d->rubberBanding = true; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3300 | d->rubberBandRect = QRect(); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3301 | if (d->scene) {
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
3302 | bool extendSelection = (event->modifiers() & Qt::ControlModifier) != 0; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3303 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
3304 | if (extendSelection) {
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
3305 | d->rubberBandSelectionOperation = Qt::AddToSelection; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3306 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
3307 | d->rubberBandSelectionOperation = Qt::ReplaceSelection; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3308 | d->scene->clearSelection(); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3309 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
3310 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3311 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
3312 | } else never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
3313 | #endif | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3314 | if (d->dragMode == QGraphicsView::ScrollHandDrag && event->button() == Qt::LeftButton) {
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
3315 | // Left-button press in scroll hand mode initiates hand scrolling. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3316 | event->accept(); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3317 | d->handScrolling = true; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3318 | d->handScrollMotions = 0; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3319 | #ifndef QT_NO_CURSOR | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3320 | viewport()->setCursor(Qt::ClosedHandCursor); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3321 | #endif | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3322 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
3323 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
3324 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
3325 | /*! | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3326 | \reimp | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3327 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3328 | void QGraphicsView::mouseMoveEvent(QMouseEvent *event) | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3329 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3330 | Q_D(QGraphicsView); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3331 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
3332 | if (d->dragMode == QGraphicsView::ScrollHandDrag) {
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
3333 | if (d->handScrolling) {
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
3334 | QScrollBar *hBar = horizontalScrollBar(); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3335 | QScrollBar *vBar = verticalScrollBar(); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3336 | QPoint delta = event->pos() - d->lastMouseEvent.pos(); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3337 | hBar->setValue(hBar->value() + (isRightToLeft() ? delta.x() : -delta.x())); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3338 | vBar->setValue(vBar->value() - delta.y()); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3339 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
3340 | // Detect how much we've scrolled to disambiguate scrolling from | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3341 | // clicking. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3342 | ++d->handScrollMotions; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3343 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
3344 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
3345 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
3346 | d->mouseMoveEventHandler(event); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3347 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
3348 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
3349 | /*! | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3350 | \reimp | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3351 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3352 | void QGraphicsView::mouseReleaseEvent(QMouseEvent *event) | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3353 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3354 | Q_D(QGraphicsView); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3355 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
3356 | #ifndef QT_NO_RUBBERBAND | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3357 | if (d->dragMode == QGraphicsView::RubberBandDrag && d->sceneInteractionAllowed && !event->buttons()) {
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
3358 | if (d->rubberBanding) {
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
3359 | if (d->viewportUpdateMode != QGraphicsView::NoViewportUpdate){
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
3360 | if (d->viewportUpdateMode != FullViewportUpdate)
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
3361 | viewport()->update(d->rubberBandRegion(viewport(), d->rubberBandRect)); never executed: viewport()->update(d->rubberBandRegion(viewport(), d->rubberBandRect)); | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
3362 | else | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3363 | d->updateAll(); never executed: d->updateAll(); | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
3364 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3365 | d->rubberBanding = false; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3366 | d->rubberBandSelectionOperation = Qt::ReplaceSelection; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3367 | if (!d->rubberBandRect.isNull()) {
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
3368 | d->rubberBandRect = QRect(); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3369 | emit rubberBandChanged(d->rubberBandRect, QPointF(), QPointF()); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3370 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
3371 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
3372 | } else never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
3373 | #endif | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3374 | if (d->dragMode == QGraphicsView::ScrollHandDrag && event->button() == Qt::LeftButton) {
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
3375 | #ifndef QT_NO_CURSOR | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3376 | // Restore the open hand cursor. ### There might be items | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3377 | // under the mouse that have a valid cursor at this time, so | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3378 | // we could repeat the steps from mouseMoveEvent(). | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3379 | viewport()->setCursor(Qt::OpenHandCursor); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3380 | #endif | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3381 | d->handScrolling = false; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3382 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
3383 | if (d->scene && d->sceneInteractionAllowed && !d->lastMouseEvent.isAccepted() && d->handScrollMotions <= 6) {
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
3384 | // If we've detected very little motion during the hand drag, and | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3385 | // no item accepted the last event, we'll interpret that as a | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3386 | // click to the scene, and reset the selection. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3387 | d->scene->clearSelection(); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3388 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
3389 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
3390 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
3391 | d->storeMouseEvent(event); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3392 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
3393 | if (!d->sceneInteractionAllowed)
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
3394 | return; never executed: return; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
3395 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
3396 | if (!d->scene)
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
3397 | return; never executed: return; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
3398 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
3399 | QGraphicsSceneMouseEvent mouseEvent(QEvent::GraphicsSceneMouseRelease); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3400 | mouseEvent.setWidget(viewport()); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3401 | mouseEvent.setButtonDownScenePos(d->mousePressButton, d->mousePressScenePoint); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3402 | mouseEvent.setButtonDownScreenPos(d->mousePressButton, d->mousePressScreenPoint); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3403 | mouseEvent.setScenePos(mapToScene(event->pos())); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3404 | mouseEvent.setScreenPos(event->globalPos()); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3405 | mouseEvent.setLastScenePos(d->lastMouseMoveScenePoint); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3406 | mouseEvent.setLastScreenPos(d->lastMouseMoveScreenPoint); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3407 | mouseEvent.setButtons(event->buttons()); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3408 | mouseEvent.setButton(event->button()); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3409 | mouseEvent.setModifiers(event->modifiers()); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3410 | mouseEvent.setSource(event->source()); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3411 | mouseEvent.setFlags(event->flags()); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3412 | mouseEvent.setAccepted(false); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3413 | if (event->spontaneous())
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
3414 | qt_sendSpontaneousEvent(d->scene, &mouseEvent); never executed: qt_sendSpontaneousEvent(d->scene, &mouseEvent); | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
3415 | else | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3416 | QApplication::sendEvent(d->scene, &mouseEvent); never executed: QApplication::sendEvent(d->scene, &mouseEvent); | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
3417 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
3418 | // Update the last mouse event selected state. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3419 | d->lastMouseEvent.setAccepted(mouseEvent.isAccepted()); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3420 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
3421 | #ifndef QT_NO_CURSOR | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3422 | if (mouseEvent.isAccepted() && mouseEvent.buttons() == 0 && viewport()->testAttribute(Qt::WA_SetCursor)) {
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
3423 | // The last mouse release on the viewport will trigger clearing the cursor. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3424 | d->_q_unsetViewportCursor(); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3425 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
3426 | #endif | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3427 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
3428 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
3429 | #ifndef QT_NO_WHEELEVENT | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3430 | /*! | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3431 | \reimp | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3432 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3433 | void QGraphicsView::wheelEvent(QWheelEvent *event) | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3434 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3435 | Q_D(QGraphicsView); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3436 | if (!d->scene || !d->sceneInteractionAllowed) {
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
3437 | QAbstractScrollArea::wheelEvent(event); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3438 | return; never executed: return; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
3439 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3440 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
3441 | event->ignore(); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3442 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
3443 | QGraphicsSceneWheelEvent wheelEvent(QEvent::GraphicsSceneWheel); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3444 | wheelEvent.setWidget(viewport()); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3445 | wheelEvent.setScenePos(mapToScene(event->pos())); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3446 | wheelEvent.setScreenPos(event->globalPos()); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3447 | wheelEvent.setButtons(event->buttons()); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3448 | wheelEvent.setModifiers(event->modifiers()); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3449 | wheelEvent.setDelta(event->delta()); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3450 | wheelEvent.setOrientation(event->orientation()); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3451 | wheelEvent.setAccepted(false); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3452 | QApplication::sendEvent(d->scene, &wheelEvent); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3453 | event->setAccepted(wheelEvent.isAccepted()); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3454 | if (!event->isAccepted())
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
3455 | QAbstractScrollArea::wheelEvent(event); never executed: QAbstractScrollArea::wheelEvent(event); | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
3456 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
3457 | #endif // QT_NO_WHEELEVENT | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3458 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
3459 | /*! | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3460 | \reimp | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3461 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3462 | void QGraphicsView::paintEvent(QPaintEvent *event) | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3463 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3464 | Q_D(QGraphicsView); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3465 | if (!d->scene) {
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
3466 | QAbstractScrollArea::paintEvent(event); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3467 | return; never executed: return; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
3468 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3469 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
3470 | // Set up painter state protection. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3471 | d->scene->d_func()->painterStateProtection = !(d->optimizationFlags & DontSavePainterState); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3472 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
3473 | // Determine the exposed region | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3474 | d->exposedRegion = event->region(); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3475 | QRectF exposedSceneRect = mapToScene(d->exposedRegion.boundingRect()).boundingRect(); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3476 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
3477 | // Set up the painter | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3478 | QPainter painter(viewport()); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3479 | #ifndef QT_NO_RUBBERBAND | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3480 | if (d->rubberBanding && !d->rubberBandRect.isEmpty())
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
3481 | painter.save(); never executed: painter.save(); | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
3482 | #endif | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3483 | // Set up render hints | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3484 | painter.setRenderHints(painter.renderHints(), false); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3485 | painter.setRenderHints(d->renderHints, true); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3486 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
3487 | // Set up viewport transform | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3488 | const bool viewTransformed = isTransformed(); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3489 | if (viewTransformed)
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
3490 | painter.setWorldTransform(viewportTransform()); never executed: painter.setWorldTransform(viewportTransform()); | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
3491 | const QTransform viewTransform = painter.worldTransform(); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3492 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
3493 | // Draw background | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3494 | if ((d->cacheMode & CacheBackground)
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
3495 | #ifdef Q_DEAD_CODE_FROM_QT4_X11 | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3496 | && X11->use_xrender | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3497 | #endif | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3498 | ) { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3499 | // Recreate the background pixmap, and flag the whole background as | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3500 | // exposed. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3501 | if (d->mustResizeBackgroundPixmap) {
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
3502 | d->backgroundPixmap = QPixmap(viewport()->size()); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3503 | QBrush bgBrush = viewport()->palette().brush(viewport()->backgroundRole()); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3504 | if (!bgBrush.isOpaque())
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
3505 | d->backgroundPixmap.fill(Qt::transparent); never executed: d->backgroundPixmap.fill(Qt::transparent); | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
3506 | QPainter p(&d->backgroundPixmap); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3507 | p.fillRect(0, 0, d->backgroundPixmap.width(), d->backgroundPixmap.height(), bgBrush); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3508 | d->backgroundPixmapExposed = QRegion(viewport()->rect()); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3509 | d->mustResizeBackgroundPixmap = false; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3510 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
3511 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
3512 | // Redraw exposed areas | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3513 | if (!d->backgroundPixmapExposed.isEmpty()) {
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
3514 | QPainter backgroundPainter(&d->backgroundPixmap); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3515 | backgroundPainter.setClipRegion(d->backgroundPixmapExposed, Qt::ReplaceClip); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3516 | if (viewTransformed)
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
3517 | backgroundPainter.setTransform(viewTransform); never executed: backgroundPainter.setTransform(viewTransform); | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
3518 | QRectF backgroundExposedSceneRect = mapToScene(d->backgroundPixmapExposed.boundingRect()).boundingRect(); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3519 | drawBackground(&backgroundPainter, backgroundExposedSceneRect); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3520 | d->backgroundPixmapExposed = QRegion(); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3521 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
3522 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
3523 | // Blit the background from the background pixmap | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3524 | if (viewTransformed) {
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
3525 | painter.setWorldTransform(QTransform()); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3526 | painter.drawPixmap(QPoint(), d->backgroundPixmap); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3527 | painter.setWorldTransform(viewTransform); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3528 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
3529 | painter.drawPixmap(QPoint(), d->backgroundPixmap); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3530 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
3531 | } else { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3532 | if (!(d->optimizationFlags & DontSavePainterState))
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
3533 | painter.save(); never executed: painter.save(); | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
3534 | drawBackground(&painter, exposedSceneRect); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3535 | if (!(d->optimizationFlags & DontSavePainterState))
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
3536 | painter.restore(); never executed: painter.restore(); | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
3537 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
3538 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
3539 | // Items | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3540 | if (!(d->optimizationFlags & IndirectPainting)) {
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
3541 | const quint32 oldRectAdjust = d->scene->d_func()->rectAdjust; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3542 | if (d->optimizationFlags & QGraphicsView::DontAdjustForAntialiasing)
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
3543 | d->scene->d_func()->rectAdjust = 1; never executed: d->scene->d_func()->rectAdjust = 1; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
3544 | else | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3545 | d->scene->d_func()->rectAdjust = 2; never executed: d->scene->d_func()->rectAdjust = 2; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
3546 | d->scene->d_func()->drawItems(&painter, viewTransformed ? &viewTransform : 0, | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3547 | &d->exposedRegion, viewport()); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3548 | d->scene->d_func()->rectAdjust = oldRectAdjust; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3549 | // Make sure the painter's world transform is restored correctly when | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3550 | // drawing without painter state protection (DontSavePainterState). | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3551 | // We only change the worldTransform() so there's no need to do a full-blown | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3552 | // save() and restore(). Also note that we don't have to do this in case of | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3553 | // IndirectPainting (the else branch), because in that case we always save() | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3554 | // and restore() in QGraphicsScene::drawItems(). | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3555 | if (!d->scene->d_func()->painterStateProtection)
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
3556 | painter.setOpacity(1.0); never executed: painter.setOpacity(1.0); | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
3557 | painter.setWorldTransform(viewTransform); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3558 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
3559 | // Make sure we don't have unpolished items before we draw | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3560 | if (!d->scene->d_func()->unpolishedItems.isEmpty())
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
3561 | d->scene->d_func()->_q_polishItems(); never executed: d->scene->d_func()->_q_polishItems(); | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
3562 | // We reset updateAll here (after we've issued polish events) | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3563 | // so that we can discard update requests coming from polishEvent(). | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3564 | d->scene->d_func()->updateAll = false; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3565 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
3566 | // Find all exposed items | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3567 | bool allItems = false; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3568 | QList<QGraphicsItem *> itemList = d->findItems(d->exposedRegion, &allItems, viewTransform); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3569 | if (!itemList.isEmpty()) {
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
3570 | // Generate the style options. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3571 | const int numItems = itemList.size(); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3572 | QGraphicsItem **itemArray = &itemList[0]; // Relies on QList internals, but is perfectly valid. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3573 | QStyleOptionGraphicsItem *styleOptionArray = d->allocStyleOptionsArray(numItems); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3574 | QTransform transform(Qt::Uninitialized); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3575 | for (int i = 0; i < numItems; ++i) {
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
3576 | QGraphicsItem *item = itemArray[i]; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3577 | QGraphicsItemPrivate *itemd = item->d_ptr.data(); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3578 | itemd->initStyleOption(&styleOptionArray[i], viewTransform, d->exposedRegion, allItems); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3579 | // Cache the item's area in view coordinates. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3580 | // Note that we have to do this here in case the base class implementation | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3581 | // (QGraphicsScene::drawItems) is not called. If it is, we'll do this | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3582 | // operation twice, but that's the price one has to pay for using indirect | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3583 | // painting :-/. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3584 | const QRectF brect = adjustedItemEffectiveBoundingRect(item); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3585 | if (!itemd->itemIsUntransformable()) {
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
3586 | transform = item->sceneTransform(); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3587 | if (viewTransformed)
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
3588 | transform *= viewTransform; never executed: transform *= viewTransform; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
3589 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
3590 | transform = item->deviceTransform(viewTransform); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3591 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
3592 | itemd->paintedViewBoundingRects.insert(d->viewport, transform.mapRect(brect).toRect()); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3593 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
3594 | // Draw the items. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3595 | drawItems(&painter, numItems, itemArray, styleOptionArray); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3596 | d->freeStyleOptionsArray(styleOptionArray); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3597 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
3598 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
3599 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
3600 | // Foreground | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3601 | drawForeground(&painter, exposedSceneRect); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3602 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
3603 | #ifndef QT_NO_RUBBERBAND | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3604 | // Rubberband | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3605 | if (d->rubberBanding && !d->rubberBandRect.isEmpty()) {
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
3606 | painter.restore(); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3607 | QStyleOptionRubberBand option; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3608 | option.initFrom(viewport()); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3609 | option.rect = d->rubberBandRect; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3610 | option.shape = QRubberBand::Rectangle; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3611 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
3612 | QStyleHintReturnMask mask; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3613 | if (viewport()->style()->styleHint(QStyle::SH_RubberBand_Mask, &option, viewport(), &mask)) {
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
3614 | // painter clipping for masked rubberbands | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3615 | painter.setClipRegion(mask.region, Qt::IntersectClip); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3616 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
3617 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
3618 | viewport()->style()->drawControl(QStyle::CE_RubberBand, &option, &painter, viewport()); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3619 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
3620 | #endif | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3621 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
3622 | painter.end(); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3623 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
3624 | // Restore painter state protection. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3625 | d->scene->d_func()->painterStateProtection = true; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3626 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
3627 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
3628 | /*! | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3629 | \reimp | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3630 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3631 | void QGraphicsView::resizeEvent(QResizeEvent *event) | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3632 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3633 | Q_D(QGraphicsView); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3634 | // Save the last center point - the resize may scroll the view, which | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3635 | // changes the center point. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3636 | QPointF oldLastCenterPoint = d->lastCenterPoint; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3637 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
3638 | QAbstractScrollArea::resizeEvent(event); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3639 | d->recalculateContentSize(); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3640 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
3641 | // Restore the center point again. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3642 | if (d->resizeAnchor == NoAnchor && !d->keepLastCenterPoint) {
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
3643 | d->updateLastCenterPoint(); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3644 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
3645 | d->lastCenterPoint = oldLastCenterPoint; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3646 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
3647 | d->centerView(d->resizeAnchor); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3648 | d->keepLastCenterPoint = false; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3649 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
3650 | if (d->cacheMode & CacheBackground) {
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
3651 | // Invalidate the background pixmap | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3652 | d->mustResizeBackgroundPixmap = true; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3653 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
3654 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
3655 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
3656 | /*! | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3657 | \reimp | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3658 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3659 | void QGraphicsView::scrollContentsBy(int dx, int dy) | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3660 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3661 | Q_D(QGraphicsView); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3662 | d->dirtyScroll = true; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3663 | if (d->transforming)
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
3664 | return; never executed: return; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
3665 | if (isRightToLeft())
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
3666 | dx = -dx; never executed: dx = -dx; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
3667 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
3668 | if (d->viewportUpdateMode != QGraphicsView::NoViewportUpdate) {
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
3669 | if (d->viewportUpdateMode != QGraphicsView::FullViewportUpdate) {
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
3670 | if (d->accelerateScrolling) {
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
3671 | #ifndef QT_NO_RUBBERBAND | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3672 | // Update new and old rubberband regions | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3673 | if (!d->rubberBandRect.isEmpty()) {
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
3674 | QRegion rubberBandRegion(d->rubberBandRegion(viewport(), d->rubberBandRect)); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3675 | rubberBandRegion += rubberBandRegion.translated(-dx, -dy); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3676 | viewport()->update(rubberBandRegion); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3677 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
3678 | #endif | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3679 | d->dirtyScrollOffset.rx() += dx; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3680 | d->dirtyScrollOffset.ry() += dy; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3681 | d->dirtyRegion.translate(dx, dy); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3682 | viewport()->scroll(dx, dy); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3683 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
3684 | d->updateAll(); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3685 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
3686 | } else { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3687 | d->updateAll(); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3688 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
3689 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3690 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
3691 | d->updateLastCenterPoint(); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3692 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
3693 | if ((d->cacheMode & CacheBackground)
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
3694 | #ifdef Q_DEAD_CODE_FROM_QT4_X11 | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3695 | && X11->use_xrender | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3696 | #endif | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3697 | ) { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3698 | // Scroll the background pixmap | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3699 | QRegion exposed; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3700 | if (!d->backgroundPixmap.isNull())
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
3701 | d->backgroundPixmap.scroll(dx, dy, d->backgroundPixmap.rect(), &exposed); never executed: d->backgroundPixmap.scroll(dx, dy, d->backgroundPixmap.rect(), &exposed); | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
3702 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
3703 | // Invalidate the background pixmap | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3704 | d->backgroundPixmapExposed.translate(dx, dy); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3705 | d->backgroundPixmapExposed += exposed; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3706 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
3707 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
3708 | // Always replay on scroll. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3709 | if (d->sceneInteractionAllowed)
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
3710 | d->replayLastMouseEvent(); never executed: d->replayLastMouseEvent(); | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
3711 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
3712 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
3713 | /*! | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3714 | \reimp | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3715 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3716 | void QGraphicsView::showEvent(QShowEvent *event) | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3717 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3718 | Q_D(QGraphicsView); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3719 | d->recalculateContentSize(); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3720 | d->centerView(d->transformationAnchor); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3721 | QAbstractScrollArea::showEvent(event); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3722 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
3723 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
3724 | /*! | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3725 | \reimp | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3726 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3727 | void QGraphicsView::inputMethodEvent(QInputMethodEvent *event) | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3728 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3729 | Q_D(QGraphicsView); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3730 | if (d->scene)
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
3731 | QApplication::sendEvent(d->scene, event); never executed: QApplication::sendEvent(d->scene, event); | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
3732 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
3733 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
3734 | /*! | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3735 | Draws the background of the scene using \a painter, before any items and | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3736 | the foreground are drawn. Reimplement this function to provide a custom | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3737 | background for this view. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3738 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
3739 | If all you want is to define a color, texture or gradient for the | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3740 | background, you can call setBackgroundBrush() instead. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3741 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
3742 | All painting is done in \e scene coordinates. \a rect is the exposed | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3743 | rectangle. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3744 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
3745 | The default implementation fills \a rect using the view's backgroundBrush. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3746 | If no such brush is defined (the default), the scene's drawBackground() | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3747 | function is called instead. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3748 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
3749 | \sa drawForeground(), QGraphicsScene::drawBackground() | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3750 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3751 | void QGraphicsView::drawBackground(QPainter *painter, const QRectF &rect) | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3752 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3753 | Q_D(QGraphicsView); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3754 | if (d->scene && d->backgroundBrush.style() == Qt::NoBrush) {
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
3755 | d->scene->drawBackground(painter, rect); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3756 | return; never executed: return; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
3757 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3758 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
3759 | painter->fillRect(rect, d->backgroundBrush); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3760 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
3761 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
3762 | /*! | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3763 | Draws the foreground of the scene using \a painter, after the background | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3764 | and all items are drawn. Reimplement this function to provide a custom | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3765 | foreground for this view. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3766 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
3767 | If all you want is to define a color, texture or gradient for the | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3768 | foreground, you can call setForegroundBrush() instead. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3769 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
3770 | All painting is done in \e scene coordinates. \a rect is the exposed | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3771 | rectangle. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3772 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
3773 | The default implementation fills \a rect using the view's foregroundBrush. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3774 | If no such brush is defined (the default), the scene's drawForeground() | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3775 | function is called instead. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3776 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
3777 | \sa drawBackground(), QGraphicsScene::drawForeground() | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3778 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3779 | void QGraphicsView::drawForeground(QPainter *painter, const QRectF &rect) | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3780 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3781 | Q_D(QGraphicsView); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3782 | if (d->scene && d->foregroundBrush.style() == Qt::NoBrush) {
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
3783 | d->scene->drawForeground(painter, rect); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3784 | return; never executed: return; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
3785 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3786 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
3787 | painter->fillRect(rect, d->foregroundBrush); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3788 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
3789 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
3790 | /*! | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3791 | \obsolete | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3792 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
3793 | Draws the items \a items in the scene using \a painter, after the | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3794 | background and before the foreground are drawn. \a numItems is the number | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3795 | of items in \a items and options in \a options. \a options is a list of | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3796 | styleoptions; one for each item. Reimplement this function to provide | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3797 | custom item drawing for this view. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3798 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
3799 | The default implementation calls the scene's drawItems() function. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3800 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
3801 | Since Qt 4.6, this function is not called anymore unless | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3802 | the QGraphicsView::IndirectPainting flag is given as an Optimization | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3803 | flag. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3804 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
3805 | \sa drawForeground(), drawBackground(), QGraphicsScene::drawItems() | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3806 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3807 | void QGraphicsView::drawItems(QPainter *painter, int numItems, | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3808 | QGraphicsItem *items[], | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3809 | const QStyleOptionGraphicsItem options[]) | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3810 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3811 | Q_D(QGraphicsView); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3812 | if (d->scene) {
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
3813 | QWidget *widget = painter->device() == viewport() ? viewport() : 0;
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
3814 | d->scene->drawItems(painter, numItems, items, options, widget); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3815 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
3816 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
3817 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
3818 | /*! | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3819 | Returns the current transformation matrix for the view. If no current | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3820 | transformation is set, the identity matrix is returned. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3821 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
3822 | \sa setTransform(), rotate(), scale(), shear(), translate() | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3823 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3824 | QTransform QGraphicsView::transform() const | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3825 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3826 | Q_D(const QGraphicsView); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3827 | return d->matrix; never executed: return d->matrix; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
3828 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3829 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
3830 | /*! | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3831 | Returns a matrix that maps scene coordinates to viewport coordinates. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3832 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
3833 | \sa mapToScene(), mapFromScene() | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3834 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3835 | QTransform QGraphicsView::viewportTransform() const | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3836 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3837 | Q_D(const QGraphicsView); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3838 | QTransform moveMatrix = QTransform::fromTranslate(-d->horizontalScroll(), -d->verticalScroll()); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3839 | return d->identityMatrix ? moveMatrix : d->matrix * moveMatrix; never executed: return d->identityMatrix ? moveMatrix : d->matrix * moveMatrix;
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
3840 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3841 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
3842 | /*! | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3843 | \since 4.6 | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3844 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
3845 | Returns \c true if the view is transformed (i.e., a non-identity transform | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3846 | has been assigned, or the scrollbars are adjusted). | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3847 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
3848 | \sa setTransform(), horizontalScrollBar(), verticalScrollBar() | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3849 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3850 | bool QGraphicsView::isTransformed() const | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3851 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3852 | Q_D(const QGraphicsView); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3853 | return !d->identityMatrix || d->horizontalScroll() || d->verticalScroll(); never executed: return !d->identityMatrix || d->horizontalScroll() || d->verticalScroll();
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
3854 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3855 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
3856 | /*! | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3857 | Sets the view's current transformation matrix to \a matrix. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3858 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
3859 | If \a combine is true, then \a matrix is combined with the current matrix; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3860 | otherwise, \a matrix \e replaces the current matrix. \a combine is false | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3861 | by default. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3862 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
3863 | The transformation matrix tranforms the scene into view coordinates. Using | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3864 | the default transformation, provided by the identity matrix, one pixel in | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3865 | the view represents one unit in the scene (e.g., a 10x10 rectangular item | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3866 | is drawn using 10x10 pixels in the view). If a 2x2 scaling matrix is | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3867 | applied, the scene will be drawn in 1:2 (e.g., a 10x10 rectangular item is | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3868 | then drawn using 20x20 pixels in the view). | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3869 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
3870 | Example: | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3871 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
3872 | \snippet code/src_gui_graphicsview_qgraphicsview.cpp 7 | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3873 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
3874 | To simplify interation with items using a transformed view, QGraphicsView | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3875 | provides mapTo... and mapFrom... functions that can translate between | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3876 | scene and view coordinates. For example, you can call mapToScene() to map | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3877 | a view coordiate to a floating point scene coordinate, or mapFromScene() | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3878 | to map from floating point scene coordinates to view coordinates. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3879 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
3880 | \sa transform(), rotate(), scale(), shear(), translate() | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3881 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3882 | void QGraphicsView::setTransform(const QTransform &matrix, bool combine ) | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3883 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3884 | Q_D(QGraphicsView); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3885 | QTransform oldMatrix = d->matrix; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3886 | if (!combine)
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
3887 | d->matrix = matrix; never executed: d->matrix = matrix; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
3888 | else | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3889 | d->matrix = matrix * d->matrix; never executed: d->matrix = matrix * d->matrix; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
3890 | if (oldMatrix == d->matrix)
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
3891 | return; never executed: return; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
3892 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
3893 | d->identityMatrix = d->matrix.isIdentity(); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3894 | d->transforming = true; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3895 | if (d->scene) {
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
3896 | d->recalculateContentSize(); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3897 | d->centerView(d->transformationAnchor); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3898 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
3899 | d->updateLastCenterPoint(); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3900 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
3901 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
3902 | if (d->sceneInteractionAllowed)
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
3903 | d->replayLastMouseEvent(); never executed: d->replayLastMouseEvent(); | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
3904 | d->transforming = false; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3905 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
3906 | // Any matrix operation requires a full update. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3907 | d->updateAll(); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3908 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
3909 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
3910 | /*! | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3911 | Resets the view transformation to the identity matrix. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3912 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
3913 | \sa transform(), setTransform() | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3914 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3915 | void QGraphicsView::resetTransform() | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3916 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3917 | setTransform(QTransform()); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3918 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
3919 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
3920 | QPointF QGraphicsViewPrivate::mapToScene(const QPointF &point) const | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3921 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3922 | QPointF p = point; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3923 | p.rx() += horizontalScroll(); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3924 | p.ry() += verticalScroll(); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3925 | return identityMatrix ? p : matrix.inverted().map(p); never executed: return identityMatrix ? p : matrix.inverted().map(p);
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
3926 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3927 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
3928 | QRectF QGraphicsViewPrivate::mapToScene(const QRectF &rect) const | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3929 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3930 | QPointF scrollOffset(horizontalScroll(), verticalScroll()); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3931 | QPointF tl = scrollOffset + rect.topLeft(); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3932 | QPointF tr = scrollOffset + rect.topRight(); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3933 | QPointF br = scrollOffset + rect.bottomRight(); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3934 | QPointF bl = scrollOffset + rect.bottomLeft(); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3935 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
3936 | QPolygonF poly(4); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3937 | if (!identityMatrix) {
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
3938 | QTransform x = matrix.inverted(); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3939 | poly[0] = x.map(tl); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3940 | poly[1] = x.map(tr); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3941 | poly[2] = x.map(br); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3942 | poly[3] = x.map(bl); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3943 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
3944 | poly[0] = tl; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3945 | poly[1] = tr; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3946 | poly[2] = br; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3947 | poly[3] = bl; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3948 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
3949 | return poly.boundingRect(); never executed: return poly.boundingRect(); | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
3950 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3951 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
3952 | QT_END_NAMESPACE | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3953 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
3954 | #include "moc_qgraphicsview.cpp" | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3955 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
3956 | #endif // QT_NO_GRAPHICSVIEW | - | ||||||||||||||||||||||||||||||||||||||||||||||||
Source code | Switch to Preprocessed file |