Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/widgets/graphicsview/qgraphicsview.cpp |
Switch to Source code | Preprocessed file |
Line | Source | Count | ||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | static const int QGRAPHICSVIEW_REGION_RECT_THRESHOLD = 50; | - | ||||||||||||||||||
2 | - | |||||||||||||||||||
3 | static const int QGRAPHICSVIEW_PREALLOC_STYLE_OPTIONS = 503; | - | ||||||||||||||||||
4 | - | |||||||||||||||||||
5 | - | |||||||||||||||||||
6 | - | |||||||||||||||||||
7 | - | |||||||||||||||||||
8 | - | |||||||||||||||||||
9 | - | |||||||||||||||||||
10 | - | |||||||||||||||||||
11 | - | |||||||||||||||||||
12 | - | |||||||||||||||||||
13 | bool qt_sendSpontaneousEvent(QObject *receiver, QEvent *event); | - | ||||||||||||||||||
14 | - | |||||||||||||||||||
15 | inline int q_round_bound(qreal d) | - | ||||||||||||||||||
16 | { | - | ||||||||||||||||||
17 | if (d <= (qreal) (-2147483647 - 1)) | - | ||||||||||||||||||
18 | return (-2147483647 - 1); | - | ||||||||||||||||||
19 | else if (d >= (qreal) 2147483647) | - | ||||||||||||||||||
20 | return 2147483647; | - | ||||||||||||||||||
21 | return d >= 0.0 ? int(d + 0.5) : int(d - int(d-1) + 0.5) + int(d-1); | - | ||||||||||||||||||
22 | } | - | ||||||||||||||||||
23 | - | |||||||||||||||||||
24 | void QGraphicsViewPrivate::translateTouchEvent(QGraphicsViewPrivate *d, QTouchEvent *touchEvent) | - | ||||||||||||||||||
25 | { | - | ||||||||||||||||||
26 | QList<QTouchEvent::TouchPoint> touchPoints = touchEvent->touchPoints(); | - | ||||||||||||||||||
27 | for (int i = 0; i < touchPoints.count(); ++i) { | - | ||||||||||||||||||
28 | QTouchEvent::TouchPoint &touchPoint = touchPoints[i]; | - | ||||||||||||||||||
29 | - | |||||||||||||||||||
30 | - | |||||||||||||||||||
31 | touchPoint.setSceneRect(d->mapToScene(touchPoint.rect())); | - | ||||||||||||||||||
32 | touchPoint.setStartScenePos(d->mapToScene(touchPoint.startPos())); | - | ||||||||||||||||||
33 | touchPoint.setLastScenePos(d->mapToScene(touchPoint.lastPos())); | - | ||||||||||||||||||
34 | - | |||||||||||||||||||
35 | - | |||||||||||||||||||
36 | } | - | ||||||||||||||||||
37 | - | |||||||||||||||||||
38 | touchEvent->setTouchPoints(touchPoints); | - | ||||||||||||||||||
39 | } | - | ||||||||||||||||||
40 | - | |||||||||||||||||||
41 | - | |||||||||||||||||||
42 | - | |||||||||||||||||||
43 | - | |||||||||||||||||||
44 | QGraphicsViewPrivate::QGraphicsViewPrivate() | - | ||||||||||||||||||
45 | : renderHints(QPainter::TextAntialiasing), | - | ||||||||||||||||||
46 | dragMode(QGraphicsView::NoDrag), | - | ||||||||||||||||||
47 | sceneInteractionAllowed(true), hasSceneRect(false), | - | ||||||||||||||||||
48 | connectedToScene(false), | - | ||||||||||||||||||
49 | useLastMouseEvent(false), | - | ||||||||||||||||||
50 | identityMatrix(true), | - | ||||||||||||||||||
51 | dirtyScroll(true), | - | ||||||||||||||||||
52 | accelerateScrolling(true), | - | ||||||||||||||||||
53 | keepLastCenterPoint(true), | - | ||||||||||||||||||
54 | transforming(false), | - | ||||||||||||||||||
55 | handScrolling(false), | - | ||||||||||||||||||
56 | mustAllocateStyleOptions(false), | - | ||||||||||||||||||
57 | mustResizeBackgroundPixmap(true), | - | ||||||||||||||||||
58 | fullUpdatePending(true), | - | ||||||||||||||||||
59 | hasUpdateClip(false), | - | ||||||||||||||||||
60 | mousePressButton(Qt::NoButton), | - | ||||||||||||||||||
61 | leftIndent(0), topIndent(0), | - | ||||||||||||||||||
62 | lastMouseEvent(QEvent::None, QPointF(), QPointF(), QPointF(), Qt::NoButton, 0, 0), | - | ||||||||||||||||||
63 | alignment(Qt::AlignCenter), | - | ||||||||||||||||||
64 | transformationAnchor(QGraphicsView::AnchorViewCenter), resizeAnchor(QGraphicsView::NoAnchor), | - | ||||||||||||||||||
65 | viewportUpdateMode(QGraphicsView::MinimalViewportUpdate), | - | ||||||||||||||||||
66 | optimizationFlags(0), | - | ||||||||||||||||||
67 | scene(0), | - | ||||||||||||||||||
68 | - | |||||||||||||||||||
69 | rubberBanding(false), | - | ||||||||||||||||||
70 | rubberBandSelectionMode(Qt::IntersectsItemShape), | - | ||||||||||||||||||
71 | rubberBandSelectionOperation(Qt::ReplaceSelection), | - | ||||||||||||||||||
72 | - | |||||||||||||||||||
73 | handScrollMotions(0), cacheMode(0), | - | ||||||||||||||||||
74 | - | |||||||||||||||||||
75 | hasStoredOriginalCursor(false), | - | ||||||||||||||||||
76 | - | |||||||||||||||||||
77 | lastDragDropEvent(0), | - | ||||||||||||||||||
78 | updateSceneSlotReimplementedChecked(false) | - | ||||||||||||||||||
79 | { | - | ||||||||||||||||||
80 | styleOptions.reserve(QGRAPHICSVIEW_PREALLOC_STYLE_OPTIONS); | - | ||||||||||||||||||
81 | } | - | ||||||||||||||||||
82 | - | |||||||||||||||||||
83 | QGraphicsViewPrivate::~QGraphicsViewPrivate() | - | ||||||||||||||||||
84 | { | - | ||||||||||||||||||
85 | } | - | ||||||||||||||||||
86 | - | |||||||||||||||||||
87 | - | |||||||||||||||||||
88 | - | |||||||||||||||||||
89 | - | |||||||||||||||||||
90 | void QGraphicsViewPrivate::recalculateContentSize() | - | ||||||||||||||||||
91 | { | - | ||||||||||||||||||
92 | QGraphicsView * const q = q_func(); | - | ||||||||||||||||||
93 | - | |||||||||||||||||||
94 | QSize maxSize = q->maximumViewportSize(); | - | ||||||||||||||||||
95 | int width = maxSize.width(); | - | ||||||||||||||||||
96 | int height = maxSize.height(); | - | ||||||||||||||||||
97 | QRectF viewRect = matrix.mapRect(q->sceneRect()); | - | ||||||||||||||||||
98 | - | |||||||||||||||||||
99 | bool frameOnlyAround = (q->style()->styleHint(QStyle::SH_ScrollView_FrameOnlyAroundContents, 0, q)); | - | ||||||||||||||||||
100 | if (frameOnlyAround) { | - | ||||||||||||||||||
101 | if (hbarpolicy == Qt::ScrollBarAlwaysOn) | - | ||||||||||||||||||
102 | height -= frameWidth * 2; | - | ||||||||||||||||||
103 | if (vbarpolicy == Qt::ScrollBarAlwaysOn) | - | ||||||||||||||||||
104 | width -= frameWidth * 2; | - | ||||||||||||||||||
105 | } | - | ||||||||||||||||||
106 | - | |||||||||||||||||||
107 | - | |||||||||||||||||||
108 | - | |||||||||||||||||||
109 | int scrollBarExtent = q->style()->pixelMetric(QStyle::PM_ScrollBarExtent, 0, q); | - | ||||||||||||||||||
110 | if (frameOnlyAround) | - | ||||||||||||||||||
111 | scrollBarExtent += frameWidth * 2; | - | ||||||||||||||||||
112 | - | |||||||||||||||||||
113 | - | |||||||||||||||||||
114 | - | |||||||||||||||||||
115 | bool useHorizontalScrollBar = (viewRect.width() > width) && hbarpolicy == Qt::ScrollBarAsNeeded; | - | ||||||||||||||||||
116 | bool useVerticalScrollBar = (viewRect.height() > height) && vbarpolicy == Qt::ScrollBarAsNeeded; | - | ||||||||||||||||||
117 | if (useHorizontalScrollBar && vbarpolicy == Qt::ScrollBarAsNeeded) { | - | ||||||||||||||||||
118 | if (viewRect.height() > height - scrollBarExtent) | - | ||||||||||||||||||
119 | useVerticalScrollBar = true; | - | ||||||||||||||||||
120 | } | - | ||||||||||||||||||
121 | if (useVerticalScrollBar && hbarpolicy == Qt::ScrollBarAsNeeded) { | - | ||||||||||||||||||
122 | if (viewRect.width() > width - scrollBarExtent) | - | ||||||||||||||||||
123 | useHorizontalScrollBar = true; | - | ||||||||||||||||||
124 | } | - | ||||||||||||||||||
125 | if (useHorizontalScrollBar) | - | ||||||||||||||||||
126 | height -= scrollBarExtent; | - | ||||||||||||||||||
127 | if (useVerticalScrollBar) | - | ||||||||||||||||||
128 | width -= scrollBarExtent; | - | ||||||||||||||||||
129 | - | |||||||||||||||||||
130 | - | |||||||||||||||||||
131 | - | |||||||||||||||||||
132 | - | |||||||||||||||||||
133 | QPointF savedLastCenterPoint = lastCenterPoint; | - | ||||||||||||||||||
134 | - | |||||||||||||||||||
135 | - | |||||||||||||||||||
136 | qreal oldLeftIndent = leftIndent; | - | ||||||||||||||||||
137 | qreal oldTopIndent = topIndent; | - | ||||||||||||||||||
138 | - | |||||||||||||||||||
139 | - | |||||||||||||||||||
140 | - | |||||||||||||||||||
141 | int left = q_round_bound(viewRect.left()); | - | ||||||||||||||||||
142 | int right = q_round_bound(viewRect.right() - width); | - | ||||||||||||||||||
143 | if (left >= right) { | - | ||||||||||||||||||
144 | hbar->setRange(0, 0); | - | ||||||||||||||||||
145 | - | |||||||||||||||||||
146 | switch (alignment & Qt::AlignHorizontal_Mask) { | - | ||||||||||||||||||
147 | case Qt::AlignLeft: | - | ||||||||||||||||||
148 | leftIndent = -viewRect.left(); | - | ||||||||||||||||||
149 | break; | - | ||||||||||||||||||
150 | case Qt::AlignRight: | - | ||||||||||||||||||
151 | leftIndent = width - viewRect.width() - viewRect.left() - 1; | - | ||||||||||||||||||
152 | break; | - | ||||||||||||||||||
153 | case Qt::AlignHCenter: | - | ||||||||||||||||||
154 | default: | - | ||||||||||||||||||
155 | leftIndent = width / 2 - (viewRect.left() + viewRect.right()) / 2; | - | ||||||||||||||||||
156 | break; | - | ||||||||||||||||||
157 | } | - | ||||||||||||||||||
158 | } else { | - | ||||||||||||||||||
159 | hbar->setRange(left, right); | - | ||||||||||||||||||
160 | hbar->setPageStep(width); | - | ||||||||||||||||||
161 | hbar->setSingleStep(width / 20); | - | ||||||||||||||||||
162 | leftIndent = 0; | - | ||||||||||||||||||
163 | } | - | ||||||||||||||||||
164 | - | |||||||||||||||||||
165 | - | |||||||||||||||||||
166 | - | |||||||||||||||||||
167 | int top = q_round_bound(viewRect.top()); | - | ||||||||||||||||||
168 | int bottom = q_round_bound(viewRect.bottom() - height); | - | ||||||||||||||||||
169 | if (top >= bottom) { | - | ||||||||||||||||||
170 | vbar->setRange(0, 0); | - | ||||||||||||||||||
171 | - | |||||||||||||||||||
172 | switch (alignment & Qt::AlignVertical_Mask) { | - | ||||||||||||||||||
173 | case Qt::AlignTop: | - | ||||||||||||||||||
174 | topIndent = -viewRect.top(); | - | ||||||||||||||||||
175 | break; | - | ||||||||||||||||||
176 | case Qt::AlignBottom: | - | ||||||||||||||||||
177 | topIndent = height - viewRect.height() - viewRect.top() - 1; | - | ||||||||||||||||||
178 | break; | - | ||||||||||||||||||
179 | case Qt::AlignVCenter: | - | ||||||||||||||||||
180 | default: | - | ||||||||||||||||||
181 | topIndent = height / 2 - (viewRect.top() + viewRect.bottom()) / 2; | - | ||||||||||||||||||
182 | break; | - | ||||||||||||||||||
183 | } | - | ||||||||||||||||||
184 | } else { | - | ||||||||||||||||||
185 | vbar->setRange(top, bottom); | - | ||||||||||||||||||
186 | vbar->setPageStep(height); | - | ||||||||||||||||||
187 | vbar->setSingleStep(height / 20); | - | ||||||||||||||||||
188 | topIndent = 0; | - | ||||||||||||||||||
189 | } | - | ||||||||||||||||||
190 | - | |||||||||||||||||||
191 | - | |||||||||||||||||||
192 | lastCenterPoint = savedLastCenterPoint; | - | ||||||||||||||||||
193 | - | |||||||||||||||||||
194 | - | |||||||||||||||||||
195 | - | |||||||||||||||||||
196 | - | |||||||||||||||||||
197 | if (oldLeftIndent != leftIndent || oldTopIndent != topIndent) { | - | ||||||||||||||||||
198 | dirtyScroll = true; | - | ||||||||||||||||||
199 | updateAll(); | - | ||||||||||||||||||
200 | } else if (q->isRightToLeft() && !leftIndent) { | - | ||||||||||||||||||
201 | - | |||||||||||||||||||
202 | - | |||||||||||||||||||
203 | - | |||||||||||||||||||
204 | - | |||||||||||||||||||
205 | dirtyScroll = true; | - | ||||||||||||||||||
206 | } | - | ||||||||||||||||||
207 | - | |||||||||||||||||||
208 | if (cacheMode & QGraphicsView::CacheBackground) { | - | ||||||||||||||||||
209 | - | |||||||||||||||||||
210 | mustResizeBackgroundPixmap = true; | - | ||||||||||||||||||
211 | } | - | ||||||||||||||||||
212 | } | - | ||||||||||||||||||
213 | - | |||||||||||||||||||
214 | - | |||||||||||||||||||
215 | - | |||||||||||||||||||
216 | - | |||||||||||||||||||
217 | void QGraphicsViewPrivate::centerView(QGraphicsView::ViewportAnchor anchor) | - | ||||||||||||||||||
218 | { | - | ||||||||||||||||||
219 | QGraphicsView * const q = q_func(); | - | ||||||||||||||||||
220 | switch (anchor) { | - | ||||||||||||||||||
221 | case QGraphicsView::AnchorUnderMouse: { | - | ||||||||||||||||||
222 | if (q->underMouse()) { | - | ||||||||||||||||||
223 | - | |||||||||||||||||||
224 | - | |||||||||||||||||||
225 | QPointF transformationDiff = q->mapToScene(viewport->rect().center()) | - | ||||||||||||||||||
226 | - q->mapToScene(viewport->mapFromGlobal(QCursor::pos())); | - | ||||||||||||||||||
227 | q->centerOn(lastMouseMoveScenePoint + transformationDiff); | - | ||||||||||||||||||
228 | } else { | - | ||||||||||||||||||
229 | q->centerOn(lastCenterPoint); | - | ||||||||||||||||||
230 | } | - | ||||||||||||||||||
231 | break; | - | ||||||||||||||||||
232 | } | - | ||||||||||||||||||
233 | case QGraphicsView::AnchorViewCenter: | - | ||||||||||||||||||
234 | q->centerOn(lastCenterPoint); | - | ||||||||||||||||||
235 | break; | - | ||||||||||||||||||
236 | case QGraphicsView::NoAnchor: | - | ||||||||||||||||||
237 | break; | - | ||||||||||||||||||
238 | } | - | ||||||||||||||||||
239 | } | - | ||||||||||||||||||
240 | - | |||||||||||||||||||
241 | - | |||||||||||||||||||
242 | - | |||||||||||||||||||
243 | - | |||||||||||||||||||
244 | void QGraphicsViewPrivate::updateLastCenterPoint() | - | ||||||||||||||||||
245 | { | - | ||||||||||||||||||
246 | QGraphicsView * const q = q_func(); | - | ||||||||||||||||||
247 | lastCenterPoint = q->mapToScene(viewport->rect().center()); | - | ||||||||||||||||||
248 | } | - | ||||||||||||||||||
249 | - | |||||||||||||||||||
250 | - | |||||||||||||||||||
251 | - | |||||||||||||||||||
252 | - | |||||||||||||||||||
253 | - | |||||||||||||||||||
254 | - | |||||||||||||||||||
255 | - | |||||||||||||||||||
256 | qint64 QGraphicsViewPrivate::horizontalScroll() const | - | ||||||||||||||||||
257 | { | - | ||||||||||||||||||
258 | if (dirtyScroll) | - | ||||||||||||||||||
259 | const_cast<QGraphicsViewPrivate *>(this)->updateScroll(); | - | ||||||||||||||||||
260 | return scrollX; | - | ||||||||||||||||||
261 | } | - | ||||||||||||||||||
262 | - | |||||||||||||||||||
263 | - | |||||||||||||||||||
264 | - | |||||||||||||||||||
265 | - | |||||||||||||||||||
266 | - | |||||||||||||||||||
267 | - | |||||||||||||||||||
268 | - | |||||||||||||||||||
269 | qint64 QGraphicsViewPrivate::verticalScroll() const | - | ||||||||||||||||||
270 | { | - | ||||||||||||||||||
271 | if (dirtyScroll) | - | ||||||||||||||||||
272 | const_cast<QGraphicsViewPrivate *>(this)->updateScroll(); | - | ||||||||||||||||||
273 | return scrollY; | - | ||||||||||||||||||
274 | } | - | ||||||||||||||||||
275 | - | |||||||||||||||||||
276 | - | |||||||||||||||||||
277 | - | |||||||||||||||||||
278 | - | |||||||||||||||||||
279 | - | |||||||||||||||||||
280 | - | |||||||||||||||||||
281 | QRectF QGraphicsViewPrivate::mapRectToScene(const QRect &rect) const | - | ||||||||||||||||||
282 | { | - | ||||||||||||||||||
283 | if (dirtyScroll) | - | ||||||||||||||||||
284 | const_cast<QGraphicsViewPrivate *>(this)->updateScroll(); | - | ||||||||||||||||||
285 | QRectF scrolled = QRectF(rect.translated(scrollX, scrollY)); | - | ||||||||||||||||||
286 | return identityMatrix ? scrolled : matrix.inverted().mapRect(scrolled); | - | ||||||||||||||||||
287 | } | - | ||||||||||||||||||
288 | - | |||||||||||||||||||
289 | - | |||||||||||||||||||
290 | - | |||||||||||||||||||
291 | - | |||||||||||||||||||
292 | - | |||||||||||||||||||
293 | - | |||||||||||||||||||
294 | - | |||||||||||||||||||
295 | QRectF QGraphicsViewPrivate::mapRectFromScene(const QRectF &rect) const | - | ||||||||||||||||||
296 | { | - | ||||||||||||||||||
297 | if (dirtyScroll) | - | ||||||||||||||||||
298 | const_cast<QGraphicsViewPrivate *>(this)->updateScroll(); | - | ||||||||||||||||||
299 | return (identityMatrix ? rect : matrix.mapRect(rect)).translated(-scrollX, -scrollY); | - | ||||||||||||||||||
300 | } | - | ||||||||||||||||||
301 | - | |||||||||||||||||||
302 | - | |||||||||||||||||||
303 | - | |||||||||||||||||||
304 | - | |||||||||||||||||||
305 | void QGraphicsViewPrivate::updateScroll() | - | ||||||||||||||||||
306 | { | - | ||||||||||||||||||
307 | QGraphicsView * const q = q_func(); | - | ||||||||||||||||||
308 | scrollX = qint64(-leftIndent); | - | ||||||||||||||||||
309 | if (q->isRightToLeft()) { | - | ||||||||||||||||||
310 | if (!leftIndent) { | - | ||||||||||||||||||
311 | scrollX += hbar->minimum(); | - | ||||||||||||||||||
312 | scrollX += hbar->maximum(); | - | ||||||||||||||||||
313 | scrollX -= hbar->value(); | - | ||||||||||||||||||
314 | } | - | ||||||||||||||||||
315 | } else { | - | ||||||||||||||||||
316 | scrollX += hbar->value(); | - | ||||||||||||||||||
317 | } | - | ||||||||||||||||||
318 | - | |||||||||||||||||||
319 | scrollY = qint64(vbar->value() - topIndent); | - | ||||||||||||||||||
320 | - | |||||||||||||||||||
321 | dirtyScroll = false; | - | ||||||||||||||||||
322 | } | - | ||||||||||||||||||
323 | - | |||||||||||||||||||
324 | - | |||||||||||||||||||
325 | - | |||||||||||||||||||
326 | - | |||||||||||||||||||
327 | void QGraphicsViewPrivate::replayLastMouseEvent() | - | ||||||||||||||||||
328 | { | - | ||||||||||||||||||
329 | if (!useLastMouseEvent || !scene) | - | ||||||||||||||||||
330 | return; | - | ||||||||||||||||||
331 | mouseMoveEventHandler(&lastMouseEvent); | - | ||||||||||||||||||
332 | } | - | ||||||||||||||||||
333 | - | |||||||||||||||||||
334 | - | |||||||||||||||||||
335 | - | |||||||||||||||||||
336 | - | |||||||||||||||||||
337 | void QGraphicsViewPrivate::storeMouseEvent(QMouseEvent *event) | - | ||||||||||||||||||
338 | { | - | ||||||||||||||||||
339 | useLastMouseEvent = true; | - | ||||||||||||||||||
340 | lastMouseEvent = QMouseEvent(QEvent::MouseMove, event->localPos(), event->windowPos(), event->screenPos(), | - | ||||||||||||||||||
341 | event->button(), event->buttons(), event->modifiers()); | - | ||||||||||||||||||
342 | } | - | ||||||||||||||||||
343 | - | |||||||||||||||||||
344 | void QGraphicsViewPrivate::mouseMoveEventHandler(QMouseEvent *event) | - | ||||||||||||||||||
345 | { | - | ||||||||||||||||||
346 | QGraphicsView * const q = q_func(); | - | ||||||||||||||||||
347 | - | |||||||||||||||||||
348 | - | |||||||||||||||||||
349 | updateRubberBand(event); | - | ||||||||||||||||||
350 | - | |||||||||||||||||||
351 | - | |||||||||||||||||||
352 | storeMouseEvent(event); | - | ||||||||||||||||||
353 | lastMouseEvent.setAccepted(false); | - | ||||||||||||||||||
354 | - | |||||||||||||||||||
355 | if (!sceneInteractionAllowed) | - | ||||||||||||||||||
356 | return; | - | ||||||||||||||||||
357 | if (handScrolling) | - | ||||||||||||||||||
358 | return; | - | ||||||||||||||||||
359 | if (!scene) | - | ||||||||||||||||||
360 | return; | - | ||||||||||||||||||
361 | - | |||||||||||||||||||
362 | QGraphicsSceneMouseEvent mouseEvent(QEvent::GraphicsSceneMouseMove); | - | ||||||||||||||||||
363 | mouseEvent.setWidget(viewport); | - | ||||||||||||||||||
364 | mouseEvent.setButtonDownScenePos(mousePressButton, mousePressScenePoint); | - | ||||||||||||||||||
365 | mouseEvent.setButtonDownScreenPos(mousePressButton, mousePressScreenPoint); | - | ||||||||||||||||||
366 | mouseEvent.setScenePos(q->mapToScene(event->pos())); | - | ||||||||||||||||||
367 | mouseEvent.setScreenPos(event->globalPos()); | - | ||||||||||||||||||
368 | mouseEvent.setLastScenePos(lastMouseMoveScenePoint); | - | ||||||||||||||||||
369 | mouseEvent.setLastScreenPos(lastMouseMoveScreenPoint); | - | ||||||||||||||||||
370 | mouseEvent.setButtons(event->buttons()); | - | ||||||||||||||||||
371 | mouseEvent.setButton(event->button()); | - | ||||||||||||||||||
372 | mouseEvent.setModifiers(event->modifiers()); | - | ||||||||||||||||||
373 | mouseEvent.setSource(event->source()); | - | ||||||||||||||||||
374 | mouseEvent.setFlags(event->flags()); | - | ||||||||||||||||||
375 | lastMouseMoveScenePoint = mouseEvent.scenePos(); | - | ||||||||||||||||||
376 | lastMouseMoveScreenPoint = mouseEvent.screenPos(); | - | ||||||||||||||||||
377 | mouseEvent.setAccepted(false); | - | ||||||||||||||||||
378 | if (event->spontaneous()) | - | ||||||||||||||||||
379 | qt_sendSpontaneousEvent(scene, &mouseEvent); | - | ||||||||||||||||||
380 | else | - | ||||||||||||||||||
381 | QApplication::sendEvent(scene, &mouseEvent); | - | ||||||||||||||||||
382 | - | |||||||||||||||||||
383 | - | |||||||||||||||||||
384 | lastMouseEvent.setAccepted(mouseEvent.isAccepted()); | - | ||||||||||||||||||
385 | - | |||||||||||||||||||
386 | if (mouseEvent.isAccepted() && mouseEvent.buttons() != 0) { | - | ||||||||||||||||||
387 | - | |||||||||||||||||||
388 | - | |||||||||||||||||||
389 | return; | - | ||||||||||||||||||
390 | } | - | ||||||||||||||||||
391 | - | |||||||||||||||||||
392 | - | |||||||||||||||||||
393 | - | |||||||||||||||||||
394 | - | |||||||||||||||||||
395 | - | |||||||||||||||||||
396 | - | |||||||||||||||||||
397 | if (scene->d_func()->allItemsIgnoreHoverEvents && !scene->d_func()->allItemsUseDefaultCursor | - | ||||||||||||||||||
398 | && scene->d_func()->cachedItemsUnderMouse.isEmpty()) { | - | ||||||||||||||||||
399 | scene->d_func()->cachedItemsUnderMouse = scene->d_func()->itemsAtPosition(mouseEvent.screenPos(), | - | ||||||||||||||||||
400 | mouseEvent.scenePos(), | - | ||||||||||||||||||
401 | mouseEvent.widget()); | - | ||||||||||||||||||
402 | } | - | ||||||||||||||||||
403 | - | |||||||||||||||||||
404 | for (QForeachContainer<typename QtPrivate::remove_reference<decltype(scene->d_func()->cachedItemsUnderMouse)>::type> _container_((scene->d_func()->cachedItemsUnderMouse)); _container_.control && _container_.i != _container_.e; ++_container_.i, _container_.control ^= 1) for (QGraphicsItem *item = *_container_.i; _container_.control; _container_.control = 0) { | - | ||||||||||||||||||
405 | if (item->hasCursor()) { | - | ||||||||||||||||||
406 | _q_setViewportCursor(item->cursor()); | - | ||||||||||||||||||
407 | return; | - | ||||||||||||||||||
408 | } | - | ||||||||||||||||||
409 | } | - | ||||||||||||||||||
410 | - | |||||||||||||||||||
411 | - | |||||||||||||||||||
412 | if (hasStoredOriginalCursor) { | - | ||||||||||||||||||
413 | - | |||||||||||||||||||
414 | hasStoredOriginalCursor = false; | - | ||||||||||||||||||
415 | viewport->setCursor(originalCursor); | - | ||||||||||||||||||
416 | } | - | ||||||||||||||||||
417 | - | |||||||||||||||||||
418 | } | - | ||||||||||||||||||
419 | - | |||||||||||||||||||
420 | - | |||||||||||||||||||
421 | - | |||||||||||||||||||
422 | - | |||||||||||||||||||
423 | - | |||||||||||||||||||
424 | QRegion QGraphicsViewPrivate::rubberBandRegion(const QWidget *widget, const QRect &rect) const | - | ||||||||||||||||||
425 | { | - | ||||||||||||||||||
426 | QStyleHintReturnMask mask; | - | ||||||||||||||||||
427 | QStyleOptionRubberBand option; | - | ||||||||||||||||||
428 | option.initFrom(widget); | - | ||||||||||||||||||
429 | option.rect = rect; | - | ||||||||||||||||||
430 | option.opaque = false; | - | ||||||||||||||||||
431 | option.shape = QRubberBand::Rectangle; | - | ||||||||||||||||||
432 | - | |||||||||||||||||||
433 | QRegion tmp; | - | ||||||||||||||||||
434 | tmp += rect; | - | ||||||||||||||||||
435 | if (widget->style()->styleHint(QStyle::SH_RubberBand_Mask, &option, widget, &mask)) | - | ||||||||||||||||||
436 | tmp &= mask.region; | - | ||||||||||||||||||
437 | return tmp; | - | ||||||||||||||||||
438 | } | - | ||||||||||||||||||
439 | - | |||||||||||||||||||
440 | void QGraphicsViewPrivate::updateRubberBand(const QMouseEvent *event) | - | ||||||||||||||||||
441 | { | - | ||||||||||||||||||
442 | QGraphicsView * const q = q_func(); | - | ||||||||||||||||||
443 | if (dragMode != QGraphicsView::RubberBandDrag || !sceneInteractionAllowed || !rubberBanding) | - | ||||||||||||||||||
444 | return; | - | ||||||||||||||||||
445 | - | |||||||||||||||||||
446 | if ((mousePressViewPoint - event->pos()).manhattanLength() < QApplication::startDragDistance()) | - | ||||||||||||||||||
447 | return; | - | ||||||||||||||||||
448 | - | |||||||||||||||||||
449 | - | |||||||||||||||||||
450 | if (viewportUpdateMode != QGraphicsView::NoViewportUpdate && !rubberBandRect.isEmpty()) { | - | ||||||||||||||||||
451 | if (viewportUpdateMode != QGraphicsView::FullViewportUpdate) | - | ||||||||||||||||||
452 | q->viewport()->update(rubberBandRegion(q->viewport(), rubberBandRect)); | - | ||||||||||||||||||
453 | else | - | ||||||||||||||||||
454 | updateAll(); | - | ||||||||||||||||||
455 | } | - | ||||||||||||||||||
456 | - | |||||||||||||||||||
457 | - | |||||||||||||||||||
458 | - | |||||||||||||||||||
459 | if (!event->buttons()) { | - | ||||||||||||||||||
460 | rubberBanding = false; | - | ||||||||||||||||||
461 | rubberBandSelectionOperation = Qt::ReplaceSelection; | - | ||||||||||||||||||
462 | if (!rubberBandRect.isNull()) { | - | ||||||||||||||||||
463 | rubberBandRect = QRect(); | - | ||||||||||||||||||
464 | q->rubberBandChanged(rubberBandRect, QPointF(), QPointF()); | - | ||||||||||||||||||
465 | } | - | ||||||||||||||||||
466 | return; | - | ||||||||||||||||||
467 | } | - | ||||||||||||||||||
468 | - | |||||||||||||||||||
469 | QRect oldRubberband = rubberBandRect; | - | ||||||||||||||||||
470 | - | |||||||||||||||||||
471 | - | |||||||||||||||||||
472 | const QPoint mp = q->mapFromScene(mousePressScenePoint); | - | ||||||||||||||||||
473 | const QPoint ep = event->pos(); | - | ||||||||||||||||||
474 | rubberBandRect = QRect(qMin(mp.x(), ep.x()), qMin(mp.y(), ep.y()), | - | ||||||||||||||||||
475 | qAbs(mp.x() - ep.x()) + 1, qAbs(mp.y() - ep.y()) + 1); | - | ||||||||||||||||||
476 | - | |||||||||||||||||||
477 | if (rubberBandRect != oldRubberband || lastRubberbandScenePoint != lastMouseMoveScenePoint) { | - | ||||||||||||||||||
478 | lastRubberbandScenePoint = lastMouseMoveScenePoint; | - | ||||||||||||||||||
479 | oldRubberband = rubberBandRect; | - | ||||||||||||||||||
480 | q->rubberBandChanged(rubberBandRect, mousePressScenePoint, lastRubberbandScenePoint); | - | ||||||||||||||||||
481 | } | - | ||||||||||||||||||
482 | - | |||||||||||||||||||
483 | - | |||||||||||||||||||
484 | if (viewportUpdateMode != QGraphicsView::NoViewportUpdate) { | - | ||||||||||||||||||
485 | if (viewportUpdateMode != QGraphicsView::FullViewportUpdate) | - | ||||||||||||||||||
486 | q->viewport()->update(rubberBandRegion(q->viewport(), rubberBandRect)); | - | ||||||||||||||||||
487 | else | - | ||||||||||||||||||
488 | updateAll(); | - | ||||||||||||||||||
489 | } | - | ||||||||||||||||||
490 | - | |||||||||||||||||||
491 | QPainterPath selectionArea; | - | ||||||||||||||||||
492 | selectionArea.addPolygon(q->mapToScene(rubberBandRect)); | - | ||||||||||||||||||
493 | selectionArea.closeSubpath(); | - | ||||||||||||||||||
494 | if (scene) | - | ||||||||||||||||||
495 | scene->setSelectionArea(selectionArea, rubberBandSelectionOperation, rubberBandSelectionMode, q->viewportTransform()); | - | ||||||||||||||||||
496 | } | - | ||||||||||||||||||
497 | - | |||||||||||||||||||
498 | - | |||||||||||||||||||
499 | - | |||||||||||||||||||
500 | - | |||||||||||||||||||
501 | - | |||||||||||||||||||
502 | - | |||||||||||||||||||
503 | void QGraphicsViewPrivate::_q_setViewportCursor(const QCursor &cursor) | - | ||||||||||||||||||
504 | { | - | ||||||||||||||||||
505 | if (!hasStoredOriginalCursor) { | - | ||||||||||||||||||
506 | hasStoredOriginalCursor = true; | - | ||||||||||||||||||
507 | originalCursor = viewport->cursor(); | - | ||||||||||||||||||
508 | } | - | ||||||||||||||||||
509 | viewport->setCursor(cursor); | - | ||||||||||||||||||
510 | } | - | ||||||||||||||||||
511 | - | |||||||||||||||||||
512 | - | |||||||||||||||||||
513 | - | |||||||||||||||||||
514 | - | |||||||||||||||||||
515 | - | |||||||||||||||||||
516 | - | |||||||||||||||||||
517 | void QGraphicsViewPrivate::_q_unsetViewportCursor() | - | ||||||||||||||||||
518 | { | - | ||||||||||||||||||
519 | QGraphicsView * const q = q_func(); | - | ||||||||||||||||||
520 | for (QForeachContainer<typename QtPrivate::remove_reference<decltype(q->const auto items (lastMouseEvent.pos()))>::type> _container_((= q->items(lastMouseEvent.pos()))); _container_.control && _container_.i != _container_.e; ++_container_.i, _container_.control ^= 1)()); | - | ||||||||||||||||||
521 | for (QGraphicsItem *item = *_container_.i; _container_.control; _container_.control = 0: items) { | - | ||||||||||||||||||
522 | if (item->hasCursor()
| 0 | ||||||||||||||||||
523 | _q_setViewportCursor(item->cursor()); | - | ||||||||||||||||||
524 | return; never executed: return; | 0 | ||||||||||||||||||
525 | } | - | ||||||||||||||||||
526 | } never executed: end of block | 0 | ||||||||||||||||||
527 | - | |||||||||||||||||||
528 | - | |||||||||||||||||||
529 | if (hasStoredOriginalCursor
| 0 | ||||||||||||||||||
530 | hasStoredOriginalCursor = false; | - | ||||||||||||||||||
531 | if (dragMode == QGraphicsView::ScrollHandDrag
| 0 | ||||||||||||||||||
532 | viewport->setCursor(Qt::OpenHandCursor); never executed: viewport->setCursor(Qt::OpenHandCursor); | 0 | ||||||||||||||||||
533 | else | - | ||||||||||||||||||
534 | viewport->setCursor(originalCursor); never executed: viewport->setCursor(originalCursor); | 0 | ||||||||||||||||||
535 | } | - | ||||||||||||||||||
536 | } never executed: end of block | 0 | ||||||||||||||||||
537 | - | |||||||||||||||||||
538 | - | |||||||||||||||||||
539 | - | |||||||||||||||||||
540 | - | |||||||||||||||||||
541 | - | |||||||||||||||||||
542 | void QGraphicsViewPrivate::storeDragDropEvent(const QGraphicsSceneDragDropEvent *event) | - | ||||||||||||||||||
543 | { | - | ||||||||||||||||||
544 | delete lastDragDropEvent; | - | ||||||||||||||||||
545 | lastDragDropEvent = new QGraphicsSceneDragDropEvent(event->type()); | - | ||||||||||||||||||
546 | lastDragDropEvent->setScenePos(event->scenePos()); | - | ||||||||||||||||||
547 | lastDragDropEvent->setScreenPos(event->screenPos()); | - | ||||||||||||||||||
548 | lastDragDropEvent->setButtons(event->buttons()); | - | ||||||||||||||||||
549 | lastDragDropEvent->setModifiers(event->modifiers()); | - | ||||||||||||||||||
550 | lastDragDropEvent->setPossibleActions(event->possibleActions()); | - | ||||||||||||||||||
551 | lastDragDropEvent->setProposedAction(event->proposedAction()); | - | ||||||||||||||||||
552 | lastDragDropEvent->setDropAction(event->dropAction()); | - | ||||||||||||||||||
553 | lastDragDropEvent->setMimeData(event->mimeData()); | - | ||||||||||||||||||
554 | lastDragDropEvent->setWidget(event->widget()); | - | ||||||||||||||||||
555 | lastDragDropEvent->setSource(event->source()); | - | ||||||||||||||||||
556 | } | - | ||||||||||||||||||
557 | - | |||||||||||||||||||
558 | - | |||||||||||||||||||
559 | - | |||||||||||||||||||
560 | - | |||||||||||||||||||
561 | void QGraphicsViewPrivate::populateSceneDragDropEvent(QGraphicsSceneDragDropEvent *dest, | - | ||||||||||||||||||
562 | QDropEvent *source) | - | ||||||||||||||||||
563 | { | - | ||||||||||||||||||
564 | - | |||||||||||||||||||
565 | QGraphicsView * const q = q_func(); | - | ||||||||||||||||||
566 | dest->setScenePos(q->mapToScene(source->pos())); | - | ||||||||||||||||||
567 | dest->setScreenPos(q->mapToGlobal(source->pos())); | - | ||||||||||||||||||
568 | dest->setButtons(source->mouseButtons()); | - | ||||||||||||||||||
569 | dest->setModifiers(source->keyboardModifiers()); | - | ||||||||||||||||||
570 | dest->setPossibleActions(source->possibleActions()); | - | ||||||||||||||||||
571 | dest->setProposedAction(source->proposedAction()); | - | ||||||||||||||||||
572 | dest->setDropAction(source->dropAction()); | - | ||||||||||||||||||
573 | dest->setMimeData(source->mimeData()); | - | ||||||||||||||||||
574 | dest->setWidget(viewport); | - | ||||||||||||||||||
575 | dest->setSource(qobject_cast<QWidget *>(source->source())); | - | ||||||||||||||||||
576 | - | |||||||||||||||||||
577 | - | |||||||||||||||||||
578 | - | |||||||||||||||||||
579 | - | |||||||||||||||||||
580 | } | - | ||||||||||||||||||
581 | - | |||||||||||||||||||
582 | - | |||||||||||||||||||
583 | - | |||||||||||||||||||
584 | - | |||||||||||||||||||
585 | QRect QGraphicsViewPrivate::mapToViewRect(const QGraphicsItem *item, const QRectF &rect) const | - | ||||||||||||||||||
586 | { | - | ||||||||||||||||||
587 | const QGraphicsView * const q = q_func(); | - | ||||||||||||||||||
588 | if (dirtyScroll) | - | ||||||||||||||||||
589 | const_cast<QGraphicsViewPrivate *>(this)->updateScroll(); | - | ||||||||||||||||||
590 | - | |||||||||||||||||||
591 | if (item->d_ptr->itemIsUntransformable()) { | - | ||||||||||||||||||
592 | QTransform itv = item->deviceTransform(q->viewportTransform()); | - | ||||||||||||||||||
593 | return itv.mapRect(rect).toAlignedRect(); | - | ||||||||||||||||||
594 | } | - | ||||||||||||||||||
595 | - | |||||||||||||||||||
596 | - | |||||||||||||||||||
597 | - | |||||||||||||||||||
598 | QPointF offset; | - | ||||||||||||||||||
599 | const QGraphicsItem *parentItem = item; | - | ||||||||||||||||||
600 | const QGraphicsItemPrivate *itemd; | - | ||||||||||||||||||
601 | do { | - | ||||||||||||||||||
602 | itemd = parentItem->d_ptr.data(); | - | ||||||||||||||||||
603 | if (itemd->transformData) | - | ||||||||||||||||||
604 | break; | - | ||||||||||||||||||
605 | offset += itemd->pos; | - | ||||||||||||||||||
606 | } while ((parentItem = itemd->parent)); | - | ||||||||||||||||||
607 | - | |||||||||||||||||||
608 | QRectF baseRect = rect.translated(offset.x(), offset.y()); | - | ||||||||||||||||||
609 | if (!parentItem) { | - | ||||||||||||||||||
610 | if (identityMatrix) { | - | ||||||||||||||||||
611 | baseRect.translate(-scrollX, -scrollY); | - | ||||||||||||||||||
612 | return baseRect.toAlignedRect(); | - | ||||||||||||||||||
613 | } | - | ||||||||||||||||||
614 | return matrix.mapRect(baseRect).translated(-scrollX, -scrollY).toAlignedRect(); | - | ||||||||||||||||||
615 | } | - | ||||||||||||||||||
616 | - | |||||||||||||||||||
617 | QTransform tr = parentItem->sceneTransform(); | - | ||||||||||||||||||
618 | if (!identityMatrix) | - | ||||||||||||||||||
619 | tr *= matrix; | - | ||||||||||||||||||
620 | QRectF r = tr.mapRect(baseRect); | - | ||||||||||||||||||
621 | r.translate(-scrollX, -scrollY); | - | ||||||||||||||||||
622 | return r.toAlignedRect(); | - | ||||||||||||||||||
623 | } | - | ||||||||||||||||||
624 | - | |||||||||||||||||||
625 | - | |||||||||||||||||||
626 | - | |||||||||||||||||||
627 | - | |||||||||||||||||||
628 | QRegion QGraphicsViewPrivate::mapToViewRegion(const QGraphicsItem *item, const QRectF &rect) const | - | ||||||||||||||||||
629 | { | - | ||||||||||||||||||
630 | const QGraphicsView * const q = q_func(); | - | ||||||||||||||||||
631 | if (dirtyScroll) | - | ||||||||||||||||||
632 | const_cast<QGraphicsViewPrivate *>(this)->updateScroll(); | - | ||||||||||||||||||
633 | - | |||||||||||||||||||
634 | - | |||||||||||||||||||
635 | QTransform itv = item->deviceTransform(q->viewportTransform()); | - | ||||||||||||||||||
636 | return item->boundingRegion(itv) & itv.mapRect(rect).toAlignedRect(); | - | ||||||||||||||||||
637 | } | - | ||||||||||||||||||
638 | - | |||||||||||||||||||
639 | - | |||||||||||||||||||
640 | - | |||||||||||||||||||
641 | - | |||||||||||||||||||
642 | void QGraphicsViewPrivate::processPendingUpdates() | - | ||||||||||||||||||
643 | { | - | ||||||||||||||||||
644 | if (!scene) | - | ||||||||||||||||||
645 | return; | - | ||||||||||||||||||
646 | - | |||||||||||||||||||
647 | if (fullUpdatePending) { | - | ||||||||||||||||||
648 | viewport->update(); | - | ||||||||||||||||||
649 | } else if (viewportUpdateMode == QGraphicsView::BoundingRectViewportUpdate) { | - | ||||||||||||||||||
650 | viewport->update(dirtyBoundingRect); | - | ||||||||||||||||||
651 | } else { | - | ||||||||||||||||||
652 | viewport->update(dirtyRegion); | - | ||||||||||||||||||
653 | } | - | ||||||||||||||||||
654 | - | |||||||||||||||||||
655 | dirtyBoundingRect = QRect(); | - | ||||||||||||||||||
656 | dirtyRegion = QRegion(); | - | ||||||||||||||||||
657 | } | - | ||||||||||||||||||
658 | - | |||||||||||||||||||
659 | static inline bool intersectsViewport(const QRect &r, int width, int height) | - | ||||||||||||||||||
660 | { return !(r.left() > width) && !(r.right() < 0) && !(r.top() >= height) && !(r.bottom() < 0); } | - | ||||||||||||||||||
661 | - | |||||||||||||||||||
662 | static inline bool containsViewport(const QRect &r, int width, int height) | - | ||||||||||||||||||
663 | { return r.left() <= 0 && r.top() <= 0 && r.right() >= width - 1 && r.bottom() >= height - 1; } | - | ||||||||||||||||||
664 | - | |||||||||||||||||||
665 | static inline void QRect_unite(QRect *rect, const QRect &other) | - | ||||||||||||||||||
666 | { | - | ||||||||||||||||||
667 | if (rect->isEmpty()) { | - | ||||||||||||||||||
668 | *rect = other; | - | ||||||||||||||||||
669 | } else { | - | ||||||||||||||||||
670 | rect->setCoords(qMin(rect->left(), other.left()), qMin(rect->top(), other.top()), | - | ||||||||||||||||||
671 | qMax(rect->right(), other.right()), qMax(rect->bottom(), other.bottom())); | - | ||||||||||||||||||
672 | } | - | ||||||||||||||||||
673 | } | - | ||||||||||||||||||
674 | - | |||||||||||||||||||
675 | - | |||||||||||||||||||
676 | - | |||||||||||||||||||
677 | - | |||||||||||||||||||
678 | - | |||||||||||||||||||
679 | - | |||||||||||||||||||
680 | void QGraphicsViewPrivate::setUpdateClip(QGraphicsItem *item) | - | ||||||||||||||||||
681 | { | - | ||||||||||||||||||
682 | QGraphicsView * const q = q_func(); | - | ||||||||||||||||||
683 | - | |||||||||||||||||||
684 | - | |||||||||||||||||||
685 | if (!item || viewportUpdateMode == QGraphicsView::NoViewportUpdate | - | ||||||||||||||||||
686 | || viewportUpdateMode == QGraphicsView::FullViewportUpdate) { | - | ||||||||||||||||||
687 | hasUpdateClip = false; | - | ||||||||||||||||||
688 | return; | - | ||||||||||||||||||
689 | } | - | ||||||||||||||||||
690 | - | |||||||||||||||||||
691 | - | |||||||||||||||||||
692 | - | |||||||||||||||||||
693 | - | |||||||||||||||||||
694 | - | |||||||||||||||||||
695 | QRect clip; | - | ||||||||||||||||||
696 | if (item->d_ptr->itemIsUntransformable()) { | - | ||||||||||||||||||
697 | QTransform xform = item->deviceTransform(q->viewportTransform()); | - | ||||||||||||||||||
698 | clip = xform.mapRect(item->boundingRect()).toAlignedRect(); | - | ||||||||||||||||||
699 | } else if (item->d_ptr->sceneTransformTranslateOnly && identityMatrix) { | - | ||||||||||||||||||
700 | QRectF r(item->boundingRect()); | - | ||||||||||||||||||
701 | r.translate(item->d_ptr->sceneTransform.dx() - horizontalScroll(), | - | ||||||||||||||||||
702 | item->d_ptr->sceneTransform.dy() - verticalScroll()); | - | ||||||||||||||||||
703 | clip = r.toAlignedRect(); | - | ||||||||||||||||||
704 | } else if (!q->isTransformed()) { | - | ||||||||||||||||||
705 | clip = item->d_ptr->sceneTransform.mapRect(item->boundingRect()).toAlignedRect(); | - | ||||||||||||||||||
706 | } else { | - | ||||||||||||||||||
707 | QTransform xform = item->d_ptr->sceneTransform; | - | ||||||||||||||||||
708 | xform *= q->viewportTransform(); | - | ||||||||||||||||||
709 | clip = xform.mapRect(item->boundingRect()).toAlignedRect(); | - | ||||||||||||||||||
710 | } | - | ||||||||||||||||||
711 | - | |||||||||||||||||||
712 | if (hasUpdateClip) { | - | ||||||||||||||||||
713 | - | |||||||||||||||||||
714 | updateClip &= clip; | - | ||||||||||||||||||
715 | } else { | - | ||||||||||||||||||
716 | updateClip = clip; | - | ||||||||||||||||||
717 | hasUpdateClip = true; | - | ||||||||||||||||||
718 | } | - | ||||||||||||||||||
719 | } | - | ||||||||||||||||||
720 | - | |||||||||||||||||||
721 | bool QGraphicsViewPrivate::updateRegion(const QRectF &rect, const QTransform &xform) | - | ||||||||||||||||||
722 | { | - | ||||||||||||||||||
723 | if (rect.isEmpty()) | - | ||||||||||||||||||
724 | return false; | - | ||||||||||||||||||
725 | - | |||||||||||||||||||
726 | if (viewportUpdateMode != QGraphicsView::MinimalViewportUpdate | - | ||||||||||||||||||
727 | && viewportUpdateMode != QGraphicsView::SmartViewportUpdate) { | - | ||||||||||||||||||
728 | - | |||||||||||||||||||
729 | return updateRectF(xform.mapRect(rect)); | - | ||||||||||||||||||
730 | } | - | ||||||||||||||||||
731 | - | |||||||||||||||||||
732 | - | |||||||||||||||||||
733 | - | |||||||||||||||||||
734 | const QRegion region = xform.map(QRegion(rect.toAlignedRect())); | - | ||||||||||||||||||
735 | QRect viewRect = region.boundingRect(); | - | ||||||||||||||||||
736 | const bool dontAdjustForAntialiasing = optimizationFlags & QGraphicsView::DontAdjustForAntialiasing; | - | ||||||||||||||||||
737 | if (dontAdjustForAntialiasing) | - | ||||||||||||||||||
738 | viewRect.adjust(-1, -1, 1, 1); | - | ||||||||||||||||||
739 | else | - | ||||||||||||||||||
740 | viewRect.adjust(-2, -2, 2, 2); | - | ||||||||||||||||||
741 | if (!intersectsViewport(viewRect, viewport->width(), viewport->height())) | - | ||||||||||||||||||
742 | return false; | - | ||||||||||||||||||
743 | - | |||||||||||||||||||
744 | const QVector<QRect> &rects = region.rects(); | - | ||||||||||||||||||
745 | for (int i = 0; i < rects.size(); ++i) { | - | ||||||||||||||||||
746 | viewRect = rects.at(i); | - | ||||||||||||||||||
747 | if (dontAdjustForAntialiasing) | - | ||||||||||||||||||
748 | viewRect.adjust(-1, -1, 1, 1); | - | ||||||||||||||||||
749 | else | - | ||||||||||||||||||
750 | viewRect.adjust(-2, -2, 2, 2); | - | ||||||||||||||||||
751 | if (hasUpdateClip) | - | ||||||||||||||||||
752 | viewRect &= updateClip; | - | ||||||||||||||||||
753 | dirtyRegion += viewRect; | - | ||||||||||||||||||
754 | } | - | ||||||||||||||||||
755 | - | |||||||||||||||||||
756 | return true; | - | ||||||||||||||||||
757 | } | - | ||||||||||||||||||
758 | - | |||||||||||||||||||
759 | - | |||||||||||||||||||
760 | - | |||||||||||||||||||
761 | bool QGraphicsViewPrivate::updateRect(const QRect &r) | - | ||||||||||||||||||
762 | { | - | ||||||||||||||||||
763 | if (fullUpdatePending || viewportUpdateMode == QGraphicsView::NoViewportUpdate | - | ||||||||||||||||||
764 | || !intersectsViewport(r, viewport->width(), viewport->height())) { | - | ||||||||||||||||||
765 | return false; | - | ||||||||||||||||||
766 | } | - | ||||||||||||||||||
767 | - | |||||||||||||||||||
768 | switch (viewportUpdateMode) { | - | ||||||||||||||||||
769 | case QGraphicsView::FullViewportUpdate: | - | ||||||||||||||||||
770 | fullUpdatePending = true; | - | ||||||||||||||||||
771 | viewport->update(); | - | ||||||||||||||||||
772 | break; | - | ||||||||||||||||||
773 | case QGraphicsView::BoundingRectViewportUpdate: | - | ||||||||||||||||||
774 | if (hasUpdateClip) | - | ||||||||||||||||||
775 | QRect_unite(&dirtyBoundingRect, r & updateClip); | - | ||||||||||||||||||
776 | else | - | ||||||||||||||||||
777 | QRect_unite(&dirtyBoundingRect, r); | - | ||||||||||||||||||
778 | if (containsViewport(dirtyBoundingRect, viewport->width(), viewport->height())) { | - | ||||||||||||||||||
779 | fullUpdatePending = true; | - | ||||||||||||||||||
780 | viewport->update(); | - | ||||||||||||||||||
781 | } | - | ||||||||||||||||||
782 | break; | - | ||||||||||||||||||
783 | case QGraphicsView::SmartViewportUpdate: | - | ||||||||||||||||||
784 | case QGraphicsView::MinimalViewportUpdate: | - | ||||||||||||||||||
785 | if (hasUpdateClip) | - | ||||||||||||||||||
786 | dirtyRegion += r & updateClip; | - | ||||||||||||||||||
787 | else | - | ||||||||||||||||||
788 | dirtyRegion += r; | - | ||||||||||||||||||
789 | break; | - | ||||||||||||||||||
790 | default: | - | ||||||||||||||||||
791 | break; | - | ||||||||||||||||||
792 | } | - | ||||||||||||||||||
793 | - | |||||||||||||||||||
794 | return true; | - | ||||||||||||||||||
795 | } | - | ||||||||||||||||||
796 | - | |||||||||||||||||||
797 | QStyleOptionGraphicsItem *QGraphicsViewPrivate::allocStyleOptionsArray(int numItems) | - | ||||||||||||||||||
798 | { | - | ||||||||||||||||||
799 | if (mustAllocateStyleOptions || (numItems > styleOptions.capacity())) | - | ||||||||||||||||||
800 | - | |||||||||||||||||||
801 | return new QStyleOptionGraphicsItem[numItems]; | - | ||||||||||||||||||
802 | - | |||||||||||||||||||
803 | - | |||||||||||||||||||
804 | if (numItems > styleOptions.size()) | - | ||||||||||||||||||
805 | styleOptions.resize(numItems); | - | ||||||||||||||||||
806 | - | |||||||||||||||||||
807 | mustAllocateStyleOptions = true; | - | ||||||||||||||||||
808 | return styleOptions.data(); | - | ||||||||||||||||||
809 | } | - | ||||||||||||||||||
810 | - | |||||||||||||||||||
811 | void QGraphicsViewPrivate::freeStyleOptionsArray(QStyleOptionGraphicsItem *array) | - | ||||||||||||||||||
812 | { | - | ||||||||||||||||||
813 | mustAllocateStyleOptions = false; | - | ||||||||||||||||||
814 | if (array != styleOptions.data()) | - | ||||||||||||||||||
815 | delete [] array; | - | ||||||||||||||||||
816 | } | - | ||||||||||||||||||
817 | - | |||||||||||||||||||
818 | extern QPainterPath qt_regionToPath(const QRegion ®ion); | - | ||||||||||||||||||
819 | QList<QGraphicsItem *> QGraphicsViewPrivate::findItems(const QRegion &exposedRegion, bool *allItems, | - | ||||||||||||||||||
820 | const QTransform &viewTransform) const | - | ||||||||||||||||||
821 | { | - | ||||||||||||||||||
822 | const QGraphicsView * const q = q_func(); | - | ||||||||||||||||||
823 | - | |||||||||||||||||||
824 | - | |||||||||||||||||||
825 | - | |||||||||||||||||||
826 | - | |||||||||||||||||||
827 | const QRectF exposedRegionSceneBounds = q->mapToScene(exposedRegion.boundingRect().adjusted(-1, -1, 1, 1)) | - | ||||||||||||||||||
828 | .boundingRect(); | - | ||||||||||||||||||
829 | if (exposedRegionSceneBounds.contains(scene->sceneRect())
| 0 | ||||||||||||||||||
830 | ((!(allItems)) ? qt_assert("allItems",__FILE__,11211128) : qt_noop()); | - | ||||||||||||||||||
831 | *allItems = true; | - | ||||||||||||||||||
832 | - | |||||||||||||||||||
833 | - | |||||||||||||||||||
834 | return never executed: scene->items(Qt::AscendingOrder);return scene->items(Qt::AscendingOrder); never executed: return scene->items(Qt::AscendingOrder); | 0 | ||||||||||||||||||
835 | } | - | ||||||||||||||||||
836 | - | |||||||||||||||||||
837 | - | |||||||||||||||||||
838 | - | |||||||||||||||||||
839 | - | |||||||||||||||||||
840 | bool simpleRectLookup = exposedRegion.rectCount() == 1
| 0 | ||||||||||||||||||
841 | if (simpleRectLookup
| 0 | ||||||||||||||||||
842 | return never executed: scene->items(exposedRegionSceneBounds,return scene->items(exposedRegionSceneBounds, Qt::IntersectsItemBoundingRect, Qt::AscendingOrder, viewTransform); never executed: return scene->items(exposedRegionSceneBounds, Qt::IntersectsItemBoundingRect, Qt::AscendingOrder, viewTransform); | 0 | ||||||||||||||||||
843 | Qt::IntersectsItemBoundingRect, never executed: return scene->items(exposedRegionSceneBounds, Qt::IntersectsItemBoundingRect, Qt::AscendingOrder, viewTransform); | 0 | ||||||||||||||||||
844 | Qt::AscendingOrder, viewTransform); never executed: return scene->items(exposedRegionSceneBounds, Qt::IntersectsItemBoundingRect, Qt::AscendingOrder, viewTransform); | 0 | ||||||||||||||||||
845 | } | - | ||||||||||||||||||
846 | - | |||||||||||||||||||
847 | - | |||||||||||||||||||
848 | - | |||||||||||||||||||
849 | - | |||||||||||||||||||
850 | QRegion adjustedRegion; | - | ||||||||||||||||||
851 | for (QForeachContainer<typename QtPrivate::remove_reference<decltype(exposedRegion.const auto rects ())>::type> _container_((= exposedRegion.rects())); _container_.control && _container_.i != _container_.e; ++_container_.i, _container_.control ^= 1)(); | - | ||||||||||||||||||
852 | for (const QRect &r = *_container_.i; _container_.control; _container_.control = 0: rects) | - | ||||||||||||||||||
853 | adjustedRegion += r.adjusted(-1, -1, 1, 1); never executed: adjustedRegion += r.adjusted(-1, -1, 1, 1); | 0 | ||||||||||||||||||
854 | - | |||||||||||||||||||
855 | const QPainterPath exposedScenePath(q->mapToScene(qt_regionToPath(adjustedRegion))); | - | ||||||||||||||||||
856 | return never executed: scene->items(exposedScenePath, Qt::IntersectsItemBoundingRect,return scene->items(exposedScenePath, Qt::IntersectsItemBoundingRect, Qt::AscendingOrder, viewTransform); never executed: return scene->items(exposedScenePath, Qt::IntersectsItemBoundingRect, Qt::AscendingOrder, viewTransform); | 0 | ||||||||||||||||||
857 | Qt::AscendingOrder, viewTransform); never executed: return scene->items(exposedScenePath, Qt::IntersectsItemBoundingRect, Qt::AscendingOrder, viewTransform); | 0 | ||||||||||||||||||
858 | } | - | ||||||||||||||||||
859 | void QGraphicsViewPrivate::updateInputMethodSensitivity() | - | ||||||||||||||||||
860 | { | - | ||||||||||||||||||
861 | QGraphicsView * const q = q_func(); | - | ||||||||||||||||||
862 | QGraphicsItem *focusItem = 0; | - | ||||||||||||||||||
863 | bool enabled = scene && (focusItem = scene->focusItem()) | - | ||||||||||||||||||
864 | && (focusItem->d_ptr->flags & QGraphicsItem::ItemAcceptsInputMethod); | - | ||||||||||||||||||
865 | q->setAttribute(Qt::WA_InputMethodEnabled, enabled); | - | ||||||||||||||||||
866 | q->viewport()->setAttribute(Qt::WA_InputMethodEnabled, enabled); | - | ||||||||||||||||||
867 | - | |||||||||||||||||||
868 | if (!enabled) { | - | ||||||||||||||||||
869 | q->setInputMethodHints(0); | - | ||||||||||||||||||
870 | return; | - | ||||||||||||||||||
871 | } | - | ||||||||||||||||||
872 | - | |||||||||||||||||||
873 | QGraphicsProxyWidget *proxy = focusItem->d_ptr->isWidget && focusItem->d_ptr->isProxyWidget() | - | ||||||||||||||||||
874 | ? static_cast<QGraphicsProxyWidget *>(focusItem) : 0; | - | ||||||||||||||||||
875 | if (!proxy) { | - | ||||||||||||||||||
876 | q->setInputMethodHints(focusItem->inputMethodHints()); | - | ||||||||||||||||||
877 | } else if (QWidget *widget = proxy->widget()) { | - | ||||||||||||||||||
878 | if (QWidget *fw = widget->focusWidget()) | - | ||||||||||||||||||
879 | widget = fw; | - | ||||||||||||||||||
880 | q->setInputMethodHints(widget->inputMethodHints()); | - | ||||||||||||||||||
881 | } else { | - | ||||||||||||||||||
882 | q->setInputMethodHints(0); | - | ||||||||||||||||||
883 | } | - | ||||||||||||||||||
884 | } | - | ||||||||||||||||||
885 | - | |||||||||||||||||||
886 | - | |||||||||||||||||||
887 | - | |||||||||||||||||||
888 | - | |||||||||||||||||||
889 | QGraphicsView::QGraphicsView(QWidget *parent) | - | ||||||||||||||||||
890 | : QAbstractScrollArea(*new QGraphicsViewPrivate, parent) | - | ||||||||||||||||||
891 | { | - | ||||||||||||||||||
892 | setViewport(0); | - | ||||||||||||||||||
893 | setAcceptDrops(true); | - | ||||||||||||||||||
894 | setBackgroundRole(QPalette::Base); | - | ||||||||||||||||||
895 | - | |||||||||||||||||||
896 | setAttribute(Qt::WA_InputMethodEnabled); | - | ||||||||||||||||||
897 | viewport()->setAttribute(Qt::WA_InputMethodEnabled); | - | ||||||||||||||||||
898 | } | - | ||||||||||||||||||
899 | - | |||||||||||||||||||
900 | - | |||||||||||||||||||
901 | - | |||||||||||||||||||
902 | - | |||||||||||||||||||
903 | - | |||||||||||||||||||
904 | QGraphicsView::QGraphicsView(QGraphicsScene *scene, QWidget *parent) | - | ||||||||||||||||||
905 | : QAbstractScrollArea(*new QGraphicsViewPrivate, parent) | - | ||||||||||||||||||
906 | { | - | ||||||||||||||||||
907 | setScene(scene); | - | ||||||||||||||||||
908 | setViewport(0); | - | ||||||||||||||||||
909 | setAcceptDrops(true); | - | ||||||||||||||||||
910 | setBackgroundRole(QPalette::Base); | - | ||||||||||||||||||
911 | - | |||||||||||||||||||
912 | setAttribute(Qt::WA_InputMethodEnabled); | - | ||||||||||||||||||
913 | viewport()->setAttribute(Qt::WA_InputMethodEnabled); | - | ||||||||||||||||||
914 | } | - | ||||||||||||||||||
915 | - | |||||||||||||||||||
916 | - | |||||||||||||||||||
917 | - | |||||||||||||||||||
918 | - | |||||||||||||||||||
919 | QGraphicsView::QGraphicsView(QGraphicsViewPrivate &dd, QWidget *parent) | - | ||||||||||||||||||
920 | : QAbstractScrollArea(dd, parent) | - | ||||||||||||||||||
921 | { | - | ||||||||||||||||||
922 | setViewport(0); | - | ||||||||||||||||||
923 | setAcceptDrops(true); | - | ||||||||||||||||||
924 | setBackgroundRole(QPalette::Base); | - | ||||||||||||||||||
925 | - | |||||||||||||||||||
926 | setAttribute(Qt::WA_InputMethodEnabled); | - | ||||||||||||||||||
927 | viewport()->setAttribute(Qt::WA_InputMethodEnabled); | - | ||||||||||||||||||
928 | } | - | ||||||||||||||||||
929 | - | |||||||||||||||||||
930 | - | |||||||||||||||||||
931 | - | |||||||||||||||||||
932 | - | |||||||||||||||||||
933 | QGraphicsView::~QGraphicsView() | - | ||||||||||||||||||
934 | { | - | ||||||||||||||||||
935 | QGraphicsViewPrivate * const d = d_func(); | - | ||||||||||||||||||
936 | if (d->scene) | - | ||||||||||||||||||
937 | d->scene->d_func()->views.removeAll(this); | - | ||||||||||||||||||
938 | delete d->lastDragDropEvent; | - | ||||||||||||||||||
939 | } | - | ||||||||||||||||||
940 | - | |||||||||||||||||||
941 | - | |||||||||||||||||||
942 | - | |||||||||||||||||||
943 | - | |||||||||||||||||||
944 | QSize QGraphicsView::sizeHint() const | - | ||||||||||||||||||
945 | { | - | ||||||||||||||||||
946 | const QGraphicsViewPrivate * const d = d_func(); | - | ||||||||||||||||||
947 | if (d->scene) { | - | ||||||||||||||||||
948 | QSizeF baseSize = d->matrix.mapRect(sceneRect()).size(); | - | ||||||||||||||||||
949 | baseSize += QSizeF(d->frameWidth * 2, d->frameWidth * 2); | - | ||||||||||||||||||
950 | return baseSize.boundedTo((3 * QApplication::desktop()->size()) / 4).toSize(); | - | ||||||||||||||||||
951 | } | - | ||||||||||||||||||
952 | return QAbstractScrollArea::sizeHint(); | - | ||||||||||||||||||
953 | } | - | ||||||||||||||||||
954 | QPainter::RenderHints QGraphicsView::renderHints() const | - | ||||||||||||||||||
955 | { | - | ||||||||||||||||||
956 | const QGraphicsViewPrivate * const d = d_func(); | - | ||||||||||||||||||
957 | return d->renderHints; | - | ||||||||||||||||||
958 | } | - | ||||||||||||||||||
959 | void QGraphicsView::setRenderHints(QPainter::RenderHints hints) | - | ||||||||||||||||||
960 | { | - | ||||||||||||||||||
961 | QGraphicsViewPrivate * const d = d_func(); | - | ||||||||||||||||||
962 | if (hints == d->renderHints) | - | ||||||||||||||||||
963 | return; | - | ||||||||||||||||||
964 | d->renderHints = hints; | - | ||||||||||||||||||
965 | d->updateAll(); | - | ||||||||||||||||||
966 | } | - | ||||||||||||||||||
967 | - | |||||||||||||||||||
968 | - | |||||||||||||||||||
969 | - | |||||||||||||||||||
970 | - | |||||||||||||||||||
971 | - | |||||||||||||||||||
972 | - | |||||||||||||||||||
973 | - | |||||||||||||||||||
974 | void QGraphicsView::setRenderHint(QPainter::RenderHint hint, bool enabled) | - | ||||||||||||||||||
975 | { | - | ||||||||||||||||||
976 | QGraphicsViewPrivate * const d = d_func(); | - | ||||||||||||||||||
977 | QPainter::RenderHints oldHints = d->renderHints; | - | ||||||||||||||||||
if (enabled)d->renderHints|= hint; | ||||||||||||||||||||
978 | elsed->renderHints&= ~.setFlag(hint;, enabled); | - | ||||||||||||||||||
979 | if (oldHints != d->renderHints
| 0 | ||||||||||||||||||
980 | d->updateAll(); never executed: d->updateAll(); | 0 | ||||||||||||||||||
981 | } never executed: end of block | 0 | ||||||||||||||||||
982 | Qt::Alignment QGraphicsView::alignment() const | - | ||||||||||||||||||
983 | { | - | ||||||||||||||||||
984 | const QGraphicsViewPrivate * const d = d_func(); | - | ||||||||||||||||||
985 | return d->alignment; | - | ||||||||||||||||||
986 | } | - | ||||||||||||||||||
987 | void QGraphicsView::setAlignment(Qt::Alignment alignment) | - | ||||||||||||||||||
988 | { | - | ||||||||||||||||||
989 | QGraphicsViewPrivate * const d = d_func(); | - | ||||||||||||||||||
990 | if (d->alignment != alignment) { | - | ||||||||||||||||||
991 | d->alignment = alignment; | - | ||||||||||||||||||
992 | d->recalculateContentSize(); | - | ||||||||||||||||||
993 | } | - | ||||||||||||||||||
994 | } | - | ||||||||||||||||||
995 | QGraphicsView::ViewportAnchor QGraphicsView::transformationAnchor() const | - | ||||||||||||||||||
996 | { | - | ||||||||||||||||||
997 | const QGraphicsViewPrivate * const d = d_func(); | - | ||||||||||||||||||
998 | return d->transformationAnchor; | - | ||||||||||||||||||
999 | } | - | ||||||||||||||||||
1000 | void QGraphicsView::setTransformationAnchor(ViewportAnchor anchor) | - | ||||||||||||||||||
1001 | { | - | ||||||||||||||||||
1002 | QGraphicsViewPrivate * const d = d_func(); | - | ||||||||||||||||||
1003 | d->transformationAnchor = anchor; | - | ||||||||||||||||||
1004 | - | |||||||||||||||||||
1005 | - | |||||||||||||||||||
1006 | - | |||||||||||||||||||
1007 | if (d->transformationAnchor == AnchorUnderMouse) | - | ||||||||||||||||||
1008 | d->viewport->setMouseTracking(true); | - | ||||||||||||||||||
1009 | } | - | ||||||||||||||||||
1010 | QGraphicsView::ViewportAnchor QGraphicsView::resizeAnchor() const | - | ||||||||||||||||||
1011 | { | - | ||||||||||||||||||
1012 | const QGraphicsViewPrivate * const d = d_func(); | - | ||||||||||||||||||
1013 | return d->resizeAnchor; | - | ||||||||||||||||||
1014 | } | - | ||||||||||||||||||
1015 | void QGraphicsView::setResizeAnchor(ViewportAnchor anchor) | - | ||||||||||||||||||
1016 | { | - | ||||||||||||||||||
1017 | QGraphicsViewPrivate * const d = d_func(); | - | ||||||||||||||||||
1018 | d->resizeAnchor = anchor; | - | ||||||||||||||||||
1019 | - | |||||||||||||||||||
1020 | - | |||||||||||||||||||
1021 | - | |||||||||||||||||||
1022 | if (d->resizeAnchor == AnchorUnderMouse) | - | ||||||||||||||||||
1023 | d->viewport->setMouseTracking(true); | - | ||||||||||||||||||
1024 | } | - | ||||||||||||||||||
1025 | QGraphicsView::ViewportUpdateMode QGraphicsView::viewportUpdateMode() const | - | ||||||||||||||||||
1026 | { | - | ||||||||||||||||||
1027 | const QGraphicsViewPrivate * const d = d_func(); | - | ||||||||||||||||||
1028 | return d->viewportUpdateMode; | - | ||||||||||||||||||
1029 | } | - | ||||||||||||||||||
1030 | void QGraphicsView::setViewportUpdateMode(ViewportUpdateMode mode) | - | ||||||||||||||||||
1031 | { | - | ||||||||||||||||||
1032 | QGraphicsViewPrivate * const d = d_func(); | - | ||||||||||||||||||
1033 | d->viewportUpdateMode = mode; | - | ||||||||||||||||||
1034 | } | - | ||||||||||||||||||
1035 | QGraphicsView::OptimizationFlags QGraphicsView::optimizationFlags() const | - | ||||||||||||||||||
1036 | { | - | ||||||||||||||||||
1037 | const QGraphicsViewPrivate * const d = d_func(); | - | ||||||||||||||||||
1038 | return d->optimizationFlags; | - | ||||||||||||||||||
1039 | } | - | ||||||||||||||||||
1040 | void QGraphicsView::setOptimizationFlags(OptimizationFlags flags) | - | ||||||||||||||||||
1041 | { | - | ||||||||||||||||||
1042 | QGraphicsViewPrivate * const d = d_func(); | - | ||||||||||||||||||
1043 | d->optimizationFlags = flags; | - | ||||||||||||||||||
1044 | } | - | ||||||||||||||||||
1045 | - | |||||||||||||||||||
1046 | - | |||||||||||||||||||
1047 | - | |||||||||||||||||||
1048 | - | |||||||||||||||||||
1049 | - | |||||||||||||||||||
1050 | - | |||||||||||||||||||
1051 | void QGraphicsView::setOptimizationFlag(OptimizationFlag flag, bool enabled) | - | ||||||||||||||||||
1052 | { | - | ||||||||||||||||||
1053 | QGraphicsViewPrivate * const d = d_func(); | - | ||||||||||||||||||
1054 | if (enabled) | - | ||||||||||||||||||
d->optimizationFlags |= flag; | ||||||||||||||||||||
elsed->optimizationFlags&= ~.setFlag(flag;, enabled); | ||||||||||||||||||||
1055 | } never executed: end of block | 0 | ||||||||||||||||||
1056 | QGraphicsView::DragMode QGraphicsView::dragMode() const | - | ||||||||||||||||||
1057 | { | - | ||||||||||||||||||
1058 | const QGraphicsViewPrivate * const d = d_func(); | - | ||||||||||||||||||
1059 | return d->dragMode; | - | ||||||||||||||||||
1060 | } | - | ||||||||||||||||||
1061 | void QGraphicsView::setDragMode(DragMode mode) | - | ||||||||||||||||||
1062 | { | - | ||||||||||||||||||
1063 | QGraphicsViewPrivate * const d = d_func(); | - | ||||||||||||||||||
1064 | if (d->dragMode == mode) | - | ||||||||||||||||||
1065 | return; | - | ||||||||||||||||||
1066 | - | |||||||||||||||||||
1067 | - | |||||||||||||||||||
1068 | if (d->dragMode == ScrollHandDrag) | - | ||||||||||||||||||
1069 | viewport()->unsetCursor(); | - | ||||||||||||||||||
1070 | - | |||||||||||||||||||
1071 | - | |||||||||||||||||||
1072 | - | |||||||||||||||||||
1073 | - | |||||||||||||||||||
1074 | - | |||||||||||||||||||
1075 | - | |||||||||||||||||||
1076 | if (d->dragMode == ScrollHandDrag && mode == NoDrag && d->handScrolling) | - | ||||||||||||||||||
1077 | d->handScrolling = false; | - | ||||||||||||||||||
1078 | - | |||||||||||||||||||
1079 | d->dragMode = mode; | - | ||||||||||||||||||
1080 | - | |||||||||||||||||||
1081 | - | |||||||||||||||||||
1082 | if (d->dragMode == ScrollHandDrag) { | - | ||||||||||||||||||
1083 | - | |||||||||||||||||||
1084 | d->hasStoredOriginalCursor = false; | - | ||||||||||||||||||
1085 | viewport()->setCursor(Qt::OpenHandCursor); | - | ||||||||||||||||||
1086 | } | - | ||||||||||||||||||
1087 | - | |||||||||||||||||||
1088 | } | - | ||||||||||||||||||
1089 | Qt::ItemSelectionMode QGraphicsView::rubberBandSelectionMode() const | - | ||||||||||||||||||
1090 | { | - | ||||||||||||||||||
1091 | const QGraphicsViewPrivate * const d = d_func(); | - | ||||||||||||||||||
1092 | return d->rubberBandSelectionMode; | - | ||||||||||||||||||
1093 | } | - | ||||||||||||||||||
1094 | void QGraphicsView::setRubberBandSelectionMode(Qt::ItemSelectionMode mode) | - | ||||||||||||||||||
1095 | { | - | ||||||||||||||||||
1096 | QGraphicsViewPrivate * const d = d_func(); | - | ||||||||||||||||||
1097 | d->rubberBandSelectionMode = mode; | - | ||||||||||||||||||
1098 | } | - | ||||||||||||||||||
1099 | QRect QGraphicsView::rubberBandRect() const | - | ||||||||||||||||||
1100 | { | - | ||||||||||||||||||
1101 | const QGraphicsViewPrivate * const d = d_func(); | - | ||||||||||||||||||
1102 | if (d->dragMode != QGraphicsView::RubberBandDrag || !d->sceneInteractionAllowed || !d->rubberBanding) | - | ||||||||||||||||||
1103 | return QRect(); | - | ||||||||||||||||||
1104 | - | |||||||||||||||||||
1105 | return d->rubberBandRect; | - | ||||||||||||||||||
1106 | } | - | ||||||||||||||||||
1107 | QGraphicsView::CacheMode QGraphicsView::cacheMode() const | - | ||||||||||||||||||
1108 | { | - | ||||||||||||||||||
1109 | const QGraphicsViewPrivate * const d = d_func(); | - | ||||||||||||||||||
1110 | return d->cacheMode; | - | ||||||||||||||||||
1111 | } | - | ||||||||||||||||||
1112 | void QGraphicsView::setCacheMode(CacheMode mode) | - | ||||||||||||||||||
1113 | { | - | ||||||||||||||||||
1114 | QGraphicsViewPrivate * const d = d_func(); | - | ||||||||||||||||||
1115 | if (mode == d->cacheMode) | - | ||||||||||||||||||
1116 | return; | - | ||||||||||||||||||
1117 | d->cacheMode = mode; | - | ||||||||||||||||||
1118 | resetCachedContent(); | - | ||||||||||||||||||
1119 | } | - | ||||||||||||||||||
1120 | void QGraphicsView::resetCachedContent() | - | ||||||||||||||||||
1121 | { | - | ||||||||||||||||||
1122 | QGraphicsViewPrivate * const d = d_func(); | - | ||||||||||||||||||
1123 | if (d->cacheMode == CacheNone) | - | ||||||||||||||||||
1124 | return; | - | ||||||||||||||||||
1125 | - | |||||||||||||||||||
1126 | if (d->cacheMode & CacheBackground) { | - | ||||||||||||||||||
1127 | - | |||||||||||||||||||
1128 | d->mustResizeBackgroundPixmap = true; | - | ||||||||||||||||||
1129 | d->updateAll(); | - | ||||||||||||||||||
1130 | } else if (d->mustResizeBackgroundPixmap) { | - | ||||||||||||||||||
1131 | - | |||||||||||||||||||
1132 | - | |||||||||||||||||||
1133 | d->mustResizeBackgroundPixmap = false; | - | ||||||||||||||||||
1134 | d->backgroundPixmap = QPixmap(); | - | ||||||||||||||||||
1135 | d->backgroundPixmapExposed = QRegion(); | - | ||||||||||||||||||
1136 | } | - | ||||||||||||||||||
1137 | } | - | ||||||||||||||||||
1138 | void QGraphicsView::invalidateScene(const QRectF &rect, QGraphicsScene::SceneLayers layers) | - | ||||||||||||||||||
1139 | { | - | ||||||||||||||||||
1140 | QGraphicsViewPrivate * const d = d_func(); | - | ||||||||||||||||||
1141 | if ((layers & QGraphicsScene::BackgroundLayer) && !d->mustResizeBackgroundPixmap) { | - | ||||||||||||||||||
1142 | QRect viewRect = mapFromScene(rect).boundingRect(); | - | ||||||||||||||||||
1143 | if (viewport()->rect().intersects(viewRect)) { | - | ||||||||||||||||||
1144 | - | |||||||||||||||||||
1145 | - | |||||||||||||||||||
1146 | d->backgroundPixmapExposed += viewRect; | - | ||||||||||||||||||
1147 | if (d->scene) | - | ||||||||||||||||||
1148 | d->scene->update(rect); | - | ||||||||||||||||||
1149 | } | - | ||||||||||||||||||
1150 | } | - | ||||||||||||||||||
1151 | } | - | ||||||||||||||||||
1152 | bool QGraphicsView::isInteractive() const | - | ||||||||||||||||||
1153 | { | - | ||||||||||||||||||
1154 | const QGraphicsViewPrivate * const d = d_func(); | - | ||||||||||||||||||
1155 | return d->sceneInteractionAllowed; | - | ||||||||||||||||||
1156 | } | - | ||||||||||||||||||
1157 | void QGraphicsView::setInteractive(bool allowed) | - | ||||||||||||||||||
1158 | { | - | ||||||||||||||||||
1159 | QGraphicsViewPrivate * const d = d_func(); | - | ||||||||||||||||||
1160 | d->sceneInteractionAllowed = allowed; | - | ||||||||||||||||||
1161 | } | - | ||||||||||||||||||
1162 | - | |||||||||||||||||||
1163 | - | |||||||||||||||||||
1164 | - | |||||||||||||||||||
1165 | - | |||||||||||||||||||
1166 | - | |||||||||||||||||||
1167 | - | |||||||||||||||||||
1168 | - | |||||||||||||||||||
1169 | QGraphicsScene *QGraphicsView::scene() const | - | ||||||||||||||||||
1170 | { | - | ||||||||||||||||||
1171 | const QGraphicsViewPrivate * const d = d_func(); | - | ||||||||||||||||||
1172 | return d->scene; | - | ||||||||||||||||||
1173 | } | - | ||||||||||||||||||
1174 | void QGraphicsView::setScene(QGraphicsScene *scene) | - | ||||||||||||||||||
1175 | { | - | ||||||||||||||||||
1176 | QGraphicsViewPrivate * const d = d_func(); | - | ||||||||||||||||||
1177 | if (d->scene == scene) | - | ||||||||||||||||||
1178 | return; | - | ||||||||||||||||||
1179 | - | |||||||||||||||||||
1180 | - | |||||||||||||||||||
1181 | d->updateAll(); | - | ||||||||||||||||||
1182 | - | |||||||||||||||||||
1183 | - | |||||||||||||||||||
1184 | if (d->scene) { | - | ||||||||||||||||||
1185 | disconnect(d->scene, qFlagLocation("2""changed(QList<QRectF>)" "\0" __FILE__ ":" "1710""1712"), | - | ||||||||||||||||||
1186 | this, qFlagLocation("1""updateScene(QList<QRectF>)" "\0" __FILE__ ":" "1711""1713")); | - | ||||||||||||||||||
1187 | disconnect(d->scene, qFlagLocation("2""sceneRectChanged(QRectF)" "\0" __FILE__ ":" "1712""1714"), | - | ||||||||||||||||||
1188 | this, qFlagLocation("1""updateSceneRect(QRectF)" "\0" __FILE__ ":" "1713""1715")); | - | ||||||||||||||||||
1189 | d->scene->d_func()->removeView(this); | - | ||||||||||||||||||
1190 | d->connectedToScene = false; | - | ||||||||||||||||||
1191 | - | |||||||||||||||||||
1192 | if (isActiveWindow() && isVisible()) { | - | ||||||||||||||||||
1193 | QEvent windowDeactivate(QEvent::WindowDeactivate); | - | ||||||||||||||||||
1194 | QApplication::sendEvent(d->scene, &windowDeactivate); | - | ||||||||||||||||||
1195 | } | - | ||||||||||||||||||
1196 | if(hasFocus()) | - | ||||||||||||||||||
1197 | d->scene->clearFocus(); | - | ||||||||||||||||||
1198 | } | - | ||||||||||||||||||
1199 | - | |||||||||||||||||||
1200 | - | |||||||||||||||||||
1201 | if ((d->scene = scene)) { | - | ||||||||||||||||||
1202 | connect(d->scene, qFlagLocation("2""sceneRectChanged(QRectF)" "\0" __FILE__ ":" "1727""1729"), | - | ||||||||||||||||||
1203 | this, qFlagLocation("1""updateSceneRect(QRectF)" "\0" __FILE__ ":" "1728""1730")); | - | ||||||||||||||||||
1204 | d->updateSceneSlotReimplementedChecked = false; | - | ||||||||||||||||||
1205 | d->scene->d_func()->addView(this); | - | ||||||||||||||||||
1206 | d->recalculateContentSize(); | - | ||||||||||||||||||
1207 | d->lastCenterPoint = sceneRect().center(); | - | ||||||||||||||||||
1208 | d->keepLastCenterPoint = true; | - | ||||||||||||||||||
1209 | - | |||||||||||||||||||
1210 | - | |||||||||||||||||||
1211 | if (!d->scene->d_func()->allItemsIgnoreHoverEvents | - | ||||||||||||||||||
1212 | || !d->scene->d_func()->allItemsUseDefaultCursor) { | - | ||||||||||||||||||
1213 | d->viewport->setMouseTracking(true); | - | ||||||||||||||||||
1214 | } | - | ||||||||||||||||||
1215 | - | |||||||||||||||||||
1216 | - | |||||||||||||||||||
1217 | if (!d->scene->d_func()->allItemsIgnoreTouchEvents) | - | ||||||||||||||||||
1218 | d->viewport->setAttribute(Qt::WA_AcceptTouchEvents); | - | ||||||||||||||||||
1219 | - | |||||||||||||||||||
1220 | if (isActiveWindow() && isVisible()) { | - | ||||||||||||||||||
1221 | QEvent windowActivate(QEvent::WindowActivate); | - | ||||||||||||||||||
1222 | QApplication::sendEvent(d->scene, &windowActivate); | - | ||||||||||||||||||
1223 | } | - | ||||||||||||||||||
1224 | } else { | - | ||||||||||||||||||
1225 | d->recalculateContentSize(); | - | ||||||||||||||||||
1226 | } | - | ||||||||||||||||||
1227 | - | |||||||||||||||||||
1228 | d->updateInputMethodSensitivity(); | - | ||||||||||||||||||
1229 | - | |||||||||||||||||||
1230 | if (d->scene && hasFocus()) | - | ||||||||||||||||||
1231 | d->scene->setFocus(); | - | ||||||||||||||||||
1232 | } | - | ||||||||||||||||||
1233 | QRectF QGraphicsView::sceneRect() const | - | ||||||||||||||||||
1234 | { | - | ||||||||||||||||||
1235 | const QGraphicsViewPrivate * const d = d_func(); | - | ||||||||||||||||||
1236 | if (d->hasSceneRect) | - | ||||||||||||||||||
1237 | return d->sceneRect; | - | ||||||||||||||||||
1238 | if (d->scene) | - | ||||||||||||||||||
1239 | return d->scene->sceneRect(); | - | ||||||||||||||||||
1240 | return QRectF(); | - | ||||||||||||||||||
1241 | } | - | ||||||||||||||||||
1242 | void QGraphicsView::setSceneRect(const QRectF &rect) | - | ||||||||||||||||||
1243 | { | - | ||||||||||||||||||
1244 | QGraphicsViewPrivate * const d = d_func(); | - | ||||||||||||||||||
1245 | d->hasSceneRect = !rect.isNull(); | - | ||||||||||||||||||
1246 | d->sceneRect = rect; | - | ||||||||||||||||||
1247 | d->recalculateContentSize(); | - | ||||||||||||||||||
1248 | } | - | ||||||||||||||||||
1249 | - | |||||||||||||||||||
1250 | - | |||||||||||||||||||
1251 | - | |||||||||||||||||||
1252 | - | |||||||||||||||||||
1253 | - | |||||||||||||||||||
1254 | - | |||||||||||||||||||
1255 | - | |||||||||||||||||||
1256 | QMatrix QGraphicsView::matrix() const | - | ||||||||||||||||||
1257 | { | - | ||||||||||||||||||
1258 | const QGraphicsViewPrivate * const d = d_func(); | - | ||||||||||||||||||
1259 | return d->matrix.toAffine(); | - | ||||||||||||||||||
1260 | } | - | ||||||||||||||||||
1261 | void QGraphicsView::setMatrix(const QMatrix &matrix, bool combine) | - | ||||||||||||||||||
1262 | { | - | ||||||||||||||||||
1263 | setTransform(QTransform(matrix), combine); | - | ||||||||||||||||||
1264 | } | - | ||||||||||||||||||
1265 | - | |||||||||||||||||||
1266 | - | |||||||||||||||||||
1267 | - | |||||||||||||||||||
1268 | - | |||||||||||||||||||
1269 | - | |||||||||||||||||||
1270 | - | |||||||||||||||||||
1271 | void QGraphicsView::resetMatrix() | - | ||||||||||||||||||
1272 | { | - | ||||||||||||||||||
1273 | resetTransform(); | - | ||||||||||||||||||
1274 | } | - | ||||||||||||||||||
1275 | - | |||||||||||||||||||
1276 | - | |||||||||||||||||||
1277 | - | |||||||||||||||||||
1278 | - | |||||||||||||||||||
1279 | - | |||||||||||||||||||
1280 | - | |||||||||||||||||||
1281 | void QGraphicsView::rotate(qreal angle) | - | ||||||||||||||||||
1282 | { | - | ||||||||||||||||||
1283 | QGraphicsViewPrivate * const d = d_func(); | - | ||||||||||||||||||
1284 | QTransform matrix = d->matrix; | - | ||||||||||||||||||
1285 | matrix.rotate(angle); | - | ||||||||||||||||||
1286 | setTransform(matrix); | - | ||||||||||||||||||
1287 | } | - | ||||||||||||||||||
1288 | - | |||||||||||||||||||
1289 | - | |||||||||||||||||||
1290 | - | |||||||||||||||||||
1291 | - | |||||||||||||||||||
1292 | - | |||||||||||||||||||
1293 | - | |||||||||||||||||||
1294 | void QGraphicsView::scale(qreal sx, qreal sy) | - | ||||||||||||||||||
1295 | { | - | ||||||||||||||||||
1296 | QGraphicsViewPrivate * const d = d_func(); | - | ||||||||||||||||||
1297 | QTransform matrix = d->matrix; | - | ||||||||||||||||||
1298 | matrix.scale(sx, sy); | - | ||||||||||||||||||
1299 | setTransform(matrix); | - | ||||||||||||||||||
1300 | } | - | ||||||||||||||||||
1301 | - | |||||||||||||||||||
1302 | - | |||||||||||||||||||
1303 | - | |||||||||||||||||||
1304 | - | |||||||||||||||||||
1305 | - | |||||||||||||||||||
1306 | - | |||||||||||||||||||
1307 | void QGraphicsView::shear(qreal sh, qreal sv) | - | ||||||||||||||||||
1308 | { | - | ||||||||||||||||||
1309 | QGraphicsViewPrivate * const d = d_func(); | - | ||||||||||||||||||
1310 | QTransform matrix = d->matrix; | - | ||||||||||||||||||
1311 | matrix.shear(sh, sv); | - | ||||||||||||||||||
1312 | setTransform(matrix); | - | ||||||||||||||||||
1313 | } | - | ||||||||||||||||||
1314 | - | |||||||||||||||||||
1315 | - | |||||||||||||||||||
1316 | - | |||||||||||||||||||
1317 | - | |||||||||||||||||||
1318 | - | |||||||||||||||||||
1319 | - | |||||||||||||||||||
1320 | void QGraphicsView::translate(qreal dx, qreal dy) | - | ||||||||||||||||||
1321 | { | - | ||||||||||||||||||
1322 | QGraphicsViewPrivate * const d = d_func(); | - | ||||||||||||||||||
1323 | QTransform matrix = d->matrix; | - | ||||||||||||||||||
1324 | matrix.translate(dx, dy); | - | ||||||||||||||||||
1325 | setTransform(matrix); | - | ||||||||||||||||||
1326 | } | - | ||||||||||||||||||
1327 | void QGraphicsView::centerOn(const QPointF &pos) | - | ||||||||||||||||||
1328 | { | - | ||||||||||||||||||
1329 | QGraphicsViewPrivate * const d = d_func(); | - | ||||||||||||||||||
1330 | qreal width = viewport()->width(); | - | ||||||||||||||||||
1331 | qreal height = viewport()->height(); | - | ||||||||||||||||||
1332 | QPointF viewPoint = d->matrix.map(pos); | - | ||||||||||||||||||
1333 | QPointF oldCenterPoint = pos; | - | ||||||||||||||||||
1334 | - | |||||||||||||||||||
1335 | if (!d->leftIndent) { | - | ||||||||||||||||||
1336 | if (isRightToLeft()) { | - | ||||||||||||||||||
1337 | qint64 horizontal = 0; | - | ||||||||||||||||||
1338 | horizontal += horizontalScrollBar()->minimum(); | - | ||||||||||||||||||
1339 | horizontal += horizontalScrollBar()->maximum(); | - | ||||||||||||||||||
1340 | horizontal -= int(viewPoint.x() - width / 2.0); | - | ||||||||||||||||||
1341 | horizontalScrollBar()->setValue(horizontal); | - | ||||||||||||||||||
1342 | } else { | - | ||||||||||||||||||
1343 | horizontalScrollBar()->setValue(int(viewPoint.x() - width / 2.0)); | - | ||||||||||||||||||
1344 | } | - | ||||||||||||||||||
1345 | } | - | ||||||||||||||||||
1346 | if (!d->topIndent) | - | ||||||||||||||||||
1347 | verticalScrollBar()->setValue(int(viewPoint.y() - height / 2.0)); | - | ||||||||||||||||||
1348 | d->lastCenterPoint = oldCenterPoint; | - | ||||||||||||||||||
1349 | } | - | ||||||||||||||||||
1350 | void QGraphicsView::centerOn(const QGraphicsItem *item) | - | ||||||||||||||||||
1351 | { | - | ||||||||||||||||||
1352 | centerOn(item->sceneBoundingRect().center()); | - | ||||||||||||||||||
1353 | } | - | ||||||||||||||||||
1354 | void QGraphicsView::ensureVisible(const QRectF &rect, int xmargin, int ymargin) | - | ||||||||||||||||||
1355 | { | - | ||||||||||||||||||
1356 | QGraphicsViewPrivate * const d = d_func(); | - | ||||||||||||||||||
1357 | qreal width = viewport()->width(); | - | ||||||||||||||||||
1358 | qreal height = viewport()->height(); | - | ||||||||||||||||||
1359 | QRectF viewRect = d->matrix.mapRect(rect); | - | ||||||||||||||||||
1360 | - | |||||||||||||||||||
1361 | qreal left = d->horizontalScroll(); | - | ||||||||||||||||||
1362 | qreal right = left + width; | - | ||||||||||||||||||
1363 | qreal top = d->verticalScroll(); | - | ||||||||||||||||||
1364 | qreal bottom = top + height; | - | ||||||||||||||||||
1365 | - | |||||||||||||||||||
1366 | if (viewRect.left() <= left + xmargin) { | - | ||||||||||||||||||
1367 | - | |||||||||||||||||||
1368 | if (!d->leftIndent) | - | ||||||||||||||||||
1369 | horizontalScrollBar()->setValue(int(viewRect.left() - xmargin - 0.5)); | - | ||||||||||||||||||
1370 | } | - | ||||||||||||||||||
1371 | if (viewRect.right() >= right - xmargin) { | - | ||||||||||||||||||
1372 | - | |||||||||||||||||||
1373 | if (!d->leftIndent) | - | ||||||||||||||||||
1374 | horizontalScrollBar()->setValue(int(viewRect.right() - width + xmargin + 0.5)); | - | ||||||||||||||||||
1375 | } | - | ||||||||||||||||||
1376 | if (viewRect.top() <= top + ymargin) { | - | ||||||||||||||||||
1377 | - | |||||||||||||||||||
1378 | if (!d->topIndent) | - | ||||||||||||||||||
1379 | verticalScrollBar()->setValue(int(viewRect.top() - ymargin - 0.5)); | - | ||||||||||||||||||
1380 | } | - | ||||||||||||||||||
1381 | if (viewRect.bottom() >= bottom - ymargin) { | - | ||||||||||||||||||
1382 | - | |||||||||||||||||||
1383 | if (!d->topIndent) | - | ||||||||||||||||||
1384 | verticalScrollBar()->setValue(int(viewRect.bottom() - height + ymargin + 0.5)); | - | ||||||||||||||||||
1385 | } | - | ||||||||||||||||||
1386 | } | - | ||||||||||||||||||
1387 | void QGraphicsView::ensureVisible(const QGraphicsItem *item, int xmargin, int ymargin) | - | ||||||||||||||||||
1388 | { | - | ||||||||||||||||||
1389 | ensureVisible(item->sceneBoundingRect(), xmargin, ymargin); | - | ||||||||||||||||||
1390 | } | - | ||||||||||||||||||
1391 | void QGraphicsView::fitInView(const QRectF &rect, Qt::AspectRatioMode aspectRatioMode) | - | ||||||||||||||||||
1392 | { | - | ||||||||||||||||||
1393 | QGraphicsViewPrivate * const d = d_func(); | - | ||||||||||||||||||
1394 | if (!d->scene || rect.isNull()) | - | ||||||||||||||||||
1395 | return; | - | ||||||||||||||||||
1396 | - | |||||||||||||||||||
1397 | - | |||||||||||||||||||
1398 | QRectF unity = d->matrix.mapRect(QRectF(0, 0, 1, 1)); | - | ||||||||||||||||||
1399 | if (unity.isEmpty()) | - | ||||||||||||||||||
1400 | return; | - | ||||||||||||||||||
1401 | scale(1 / unity.width(), 1 / unity.height()); | - | ||||||||||||||||||
1402 | - | |||||||||||||||||||
1403 | - | |||||||||||||||||||
1404 | int margin = 2; | - | ||||||||||||||||||
1405 | QRectF viewRect = viewport()->rect().adjusted(margin, margin, -margin, -margin); | - | ||||||||||||||||||
1406 | if (viewRect.isEmpty()) | - | ||||||||||||||||||
1407 | return; | - | ||||||||||||||||||
1408 | QRectF sceneRect = d->matrix.mapRect(rect); | - | ||||||||||||||||||
1409 | if (sceneRect.isEmpty()) | - | ||||||||||||||||||
1410 | return; | - | ||||||||||||||||||
1411 | qreal xratio = viewRect.width() / sceneRect.width(); | - | ||||||||||||||||||
1412 | qreal yratio = viewRect.height() / sceneRect.height(); | - | ||||||||||||||||||
1413 | - | |||||||||||||||||||
1414 | - | |||||||||||||||||||
1415 | switch (aspectRatioMode) { | - | ||||||||||||||||||
1416 | case Qt::KeepAspectRatio: | - | ||||||||||||||||||
1417 | xratio = yratio = qMin(xratio, yratio); | - | ||||||||||||||||||
1418 | break; | - | ||||||||||||||||||
1419 | case Qt::KeepAspectRatioByExpanding: | - | ||||||||||||||||||
1420 | xratio = yratio = qMax(xratio, yratio); | - | ||||||||||||||||||
1421 | break; | - | ||||||||||||||||||
1422 | case Qt::IgnoreAspectRatio: | - | ||||||||||||||||||
1423 | break; | - | ||||||||||||||||||
1424 | } | - | ||||||||||||||||||
1425 | - | |||||||||||||||||||
1426 | - | |||||||||||||||||||
1427 | scale(xratio, yratio); | - | ||||||||||||||||||
1428 | centerOn(rect.center()); | - | ||||||||||||||||||
1429 | } | - | ||||||||||||||||||
1430 | void QGraphicsView::fitInView(const QGraphicsItem *item, Qt::AspectRatioMode aspectRatioMode) | - | ||||||||||||||||||
1431 | { | - | ||||||||||||||||||
1432 | QPainterPath path = item->isClipped() ? item->clipPath() : item->shape(); | - | ||||||||||||||||||
1433 | if (item->d_ptr->hasTranslateOnlySceneTransform()) { | - | ||||||||||||||||||
1434 | path.translate(item->d_ptr->sceneTransform.dx(), item->d_ptr->sceneTransform.dy()); | - | ||||||||||||||||||
1435 | fitInView(path.boundingRect(), aspectRatioMode); | - | ||||||||||||||||||
1436 | } else { | - | ||||||||||||||||||
1437 | fitInView(item->d_ptr->sceneTransform.map(path).boundingRect(), aspectRatioMode); | - | ||||||||||||||||||
1438 | } | - | ||||||||||||||||||
1439 | } | - | ||||||||||||||||||
1440 | void QGraphicsView::render(QPainter *painter, const QRectF &target, const QRect &source, | - | ||||||||||||||||||
1441 | Qt::AspectRatioMode aspectRatioMode) | - | ||||||||||||||||||
1442 | { | - | ||||||||||||||||||
1443 | - | |||||||||||||||||||
1444 | - | |||||||||||||||||||
1445 | QGraphicsViewPrivate * const d = d_func(); | - | ||||||||||||||||||
1446 | if (!d->scene || !(painter && painter->isActive())) | - | ||||||||||||||||||
1447 | return; | - | ||||||||||||||||||
1448 | - | |||||||||||||||||||
1449 | - | |||||||||||||||||||
1450 | QRect sourceRect = source; | - | ||||||||||||||||||
1451 | if (source.isNull()) | - | ||||||||||||||||||
1452 | sourceRect = viewport()->rect(); | - | ||||||||||||||||||
1453 | - | |||||||||||||||||||
1454 | - | |||||||||||||||||||
1455 | QRectF targetRect = target; | - | ||||||||||||||||||
1456 | if (target.isNull()) { | - | ||||||||||||||||||
1457 | if (painter->device()->devType() == QInternal::Picture) | - | ||||||||||||||||||
1458 | targetRect = sourceRect; | - | ||||||||||||||||||
1459 | else | - | ||||||||||||||||||
1460 | targetRect.setRect(0, 0, painter->device()->width(), painter->device()->height()); | - | ||||||||||||||||||
1461 | } | - | ||||||||||||||||||
1462 | - | |||||||||||||||||||
1463 | - | |||||||||||||||||||
1464 | qreal xratio = targetRect.width() / sourceRect.width(); | - | ||||||||||||||||||
1465 | qreal yratio = targetRect.height() / sourceRect.height(); | - | ||||||||||||||||||
1466 | - | |||||||||||||||||||
1467 | - | |||||||||||||||||||
1468 | switch (aspectRatioMode) { | - | ||||||||||||||||||
1469 | case Qt::KeepAspectRatio: | - | ||||||||||||||||||
1470 | xratio = yratio = qMin(xratio, yratio); | - | ||||||||||||||||||
1471 | break; | - | ||||||||||||||||||
1472 | case Qt::KeepAspectRatioByExpanding: | - | ||||||||||||||||||
1473 | xratio = yratio = qMax(xratio, yratio); | - | ||||||||||||||||||
1474 | break; | - | ||||||||||||||||||
1475 | case Qt::IgnoreAspectRatio: | - | ||||||||||||||||||
1476 | break; | - | ||||||||||||||||||
1477 | } | - | ||||||||||||||||||
1478 | - | |||||||||||||||||||
1479 | - | |||||||||||||||||||
1480 | - | |||||||||||||||||||
1481 | QPolygonF sourceScenePoly = mapToScene(sourceRect.adjusted(-1, -1, 1, 1)); | - | ||||||||||||||||||
1482 | QList<QGraphicsItem *> itemList = d->scene->items(sourceScenePoly, | - | ||||||||||||||||||
1483 | Qt::IntersectsItemBoundingRect); | - | ||||||||||||||||||
1484 | QGraphicsItem **itemArray = new QGraphicsItem *[itemList.size()]; | - | ||||||||||||||||||
1485 | int numItems = itemList.size(); | - | ||||||||||||||||||
1486 | for (int i = 0; i < numItems; ++i) | - | ||||||||||||||||||
1487 | itemArray[numItems - i - 1] = itemList.at(i); | - | ||||||||||||||||||
1488 | itemList.clear(); | - | ||||||||||||||||||
1489 | - | |||||||||||||||||||
1490 | - | |||||||||||||||||||
1491 | QTransform moveMatrix = QTransform::fromTranslate(-d->horizontalScroll(), -d->verticalScroll()); | - | ||||||||||||||||||
1492 | QTransform painterMatrix = d->matrix * moveMatrix; | - | ||||||||||||||||||
1493 | painterMatrix *= QTransform() | - | ||||||||||||||||||
1494 | .translate(targetRect.left(), targetRect.top()) | - | ||||||||||||||||||
1495 | .scale(xratio, yratio) | - | ||||||||||||||||||
1496 | .translate(-sourceRect.left(), -sourceRect.top()); | - | ||||||||||||||||||
1497 | - | |||||||||||||||||||
1498 | - | |||||||||||||||||||
1499 | QStyleOptionGraphicsItem *styleOptionArray = d->allocStyleOptionsArray(numItems); | - | ||||||||||||||||||
1500 | for (int i = 0; i < numItems; ++i) | - | ||||||||||||||||||
1501 | itemArray[i]->d_ptr->initStyleOption(&styleOptionArray[i], painterMatrix, targetRect.toRect()); | - | ||||||||||||||||||
1502 | - | |||||||||||||||||||
1503 | painter->save(); | - | ||||||||||||||||||
1504 | - | |||||||||||||||||||
1505 | - | |||||||||||||||||||
1506 | painter->setClipRect(targetRect); | - | ||||||||||||||||||
1507 | QPainterPath path; | - | ||||||||||||||||||
1508 | path.addPolygon(sourceScenePoly); | - | ||||||||||||||||||
1509 | path.closeSubpath(); | - | ||||||||||||||||||
1510 | painter->setClipPath(painterMatrix.map(path), Qt::IntersectClip); | - | ||||||||||||||||||
1511 | - | |||||||||||||||||||
1512 | - | |||||||||||||||||||
1513 | painter->setTransform(painterMatrix, true); | - | ||||||||||||||||||
1514 | - | |||||||||||||||||||
1515 | - | |||||||||||||||||||
1516 | QRectF sourceSceneRect = sourceScenePoly.boundingRect(); | - | ||||||||||||||||||
1517 | drawBackground(painter, sourceSceneRect); | - | ||||||||||||||||||
1518 | drawItems(painter, numItems, itemArray, styleOptionArray); | - | ||||||||||||||||||
1519 | drawForeground(painter, sourceSceneRect); | - | ||||||||||||||||||
1520 | - | |||||||||||||||||||
1521 | delete [] itemArray; | - | ||||||||||||||||||
1522 | d->freeStyleOptionsArray(styleOptionArray); | - | ||||||||||||||||||
1523 | - | |||||||||||||||||||
1524 | painter->restore(); | - | ||||||||||||||||||
1525 | } | - | ||||||||||||||||||
1526 | QList<QGraphicsItem *> QGraphicsView::items() const | - | ||||||||||||||||||
1527 | { | - | ||||||||||||||||||
1528 | const QGraphicsViewPrivate * const d = d_func(); | - | ||||||||||||||||||
1529 | if (!d->scene) | - | ||||||||||||||||||
1530 | return QList<QGraphicsItem *>(); | - | ||||||||||||||||||
1531 | return d->scene->items(); | - | ||||||||||||||||||
1532 | } | - | ||||||||||||||||||
1533 | QList<QGraphicsItem *> QGraphicsView::items(const QPoint &pos) const | - | ||||||||||||||||||
1534 | { | - | ||||||||||||||||||
1535 | const QGraphicsViewPrivate * const d = d_func(); | - | ||||||||||||||||||
1536 | if (!d->scene) | - | ||||||||||||||||||
1537 | return QList<QGraphicsItem *>(); | - | ||||||||||||||||||
1538 | - | |||||||||||||||||||
1539 | - | |||||||||||||||||||
1540 | - | |||||||||||||||||||
1541 | if ((d->identityMatrix || d->matrix.type() <= QTransform::TxScale)) { | - | ||||||||||||||||||
1542 | - | |||||||||||||||||||
1543 | QTransform xinv = viewportTransform().inverted(); | - | ||||||||||||||||||
1544 | return d->scene->items(xinv.mapRect(QRectF(pos.x(), pos.y(), 1, 1)), | - | ||||||||||||||||||
1545 | Qt::IntersectsItemShape, | - | ||||||||||||||||||
1546 | Qt::DescendingOrder, | - | ||||||||||||||||||
1547 | viewportTransform()); | - | ||||||||||||||||||
1548 | } | - | ||||||||||||||||||
1549 | - | |||||||||||||||||||
1550 | return d->scene->items(mapToScene(pos.x(), pos.y(), 1, 1), | - | ||||||||||||||||||
1551 | Qt::IntersectsItemShape, | - | ||||||||||||||||||
1552 | Qt::DescendingOrder, | - | ||||||||||||||||||
1553 | viewportTransform()); | - | ||||||||||||||||||
1554 | } | - | ||||||||||||||||||
1555 | QList<QGraphicsItem *> QGraphicsView::items(const QRect &rect, Qt::ItemSelectionMode mode) const | - | ||||||||||||||||||
1556 | { | - | ||||||||||||||||||
1557 | const QGraphicsViewPrivate * const d = d_func(); | - | ||||||||||||||||||
1558 | if (!d->scene) | - | ||||||||||||||||||
1559 | return QList<QGraphicsItem *>(); | - | ||||||||||||||||||
1560 | return d->scene->items(mapToScene(rect), mode, Qt::DescendingOrder, viewportTransform()); | - | ||||||||||||||||||
1561 | } | - | ||||||||||||||||||
1562 | QList<QGraphicsItem *> QGraphicsView::items(const QPolygon &polygon, Qt::ItemSelectionMode mode) const | - | ||||||||||||||||||
1563 | { | - | ||||||||||||||||||
1564 | const QGraphicsViewPrivate * const d = d_func(); | - | ||||||||||||||||||
1565 | if (!d->scene) | - | ||||||||||||||||||
1566 | return QList<QGraphicsItem *>(); | - | ||||||||||||||||||
1567 | return d->scene->items(mapToScene(polygon), mode, Qt::DescendingOrder, viewportTransform()); | - | ||||||||||||||||||
1568 | } | - | ||||||||||||||||||
1569 | QList<QGraphicsItem *> QGraphicsView::items(const QPainterPath &path, Qt::ItemSelectionMode mode) const | - | ||||||||||||||||||
1570 | { | - | ||||||||||||||||||
1571 | const QGraphicsViewPrivate * const d = d_func(); | - | ||||||||||||||||||
1572 | if (!d->scene) | - | ||||||||||||||||||
1573 | return QList<QGraphicsItem *>(); | - | ||||||||||||||||||
1574 | return d->scene->items(mapToScene(path), mode, Qt::DescendingOrder, viewportTransform()); | - | ||||||||||||||||||
1575 | } | - | ||||||||||||||||||
1576 | QGraphicsItem *QGraphicsView::itemAt(const QPoint &pos) const | - | ||||||||||||||||||
1577 | { | - | ||||||||||||||||||
1578 | const QGraphicsViewPrivate * const d = d_func(); | - | ||||||||||||||||||
1579 | if (!d->scene
| 0 | ||||||||||||||||||
1580 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||||||||||||||
1581 | const QList<QGraphicsItem *> itemsAtPos = items(pos); | - | ||||||||||||||||||
1582 | return never executed: itemsAtPos.isEmpty() ? 0 : itemsAtPos.first();return itemsAtPos.isEmpty() ? 0 : itemsAtPos.first(); never executed: return itemsAtPos.isEmpty() ? 0 : itemsAtPos.first(); | 0 | ||||||||||||||||||
1583 | } | - | ||||||||||||||||||
1584 | QPointF QGraphicsView::mapToScene(const QPoint &point) const | - | ||||||||||||||||||
1585 | { | - | ||||||||||||||||||
1586 | const QGraphicsViewPrivate * const d = d_func(); | - | ||||||||||||||||||
1587 | QPointF p = point; | - | ||||||||||||||||||
1588 | p.rx() += d->horizontalScroll(); | - | ||||||||||||||||||
1589 | p.ry() += d->verticalScroll(); | - | ||||||||||||||||||
1590 | return d->identityMatrix ? p : d->matrix.inverted().map(p); | - | ||||||||||||||||||
1591 | } | - | ||||||||||||||||||
1592 | QPolygonF QGraphicsView::mapToScene(const QRect &rect) const | - | ||||||||||||||||||
1593 | { | - | ||||||||||||||||||
1594 | const QGraphicsViewPrivate * const d = d_func(); | - | ||||||||||||||||||
1595 | if (!rect.isValid()) | - | ||||||||||||||||||
1596 | return QPolygonF(); | - | ||||||||||||||||||
1597 | - | |||||||||||||||||||
1598 | QPointF scrollOffset(d->horizontalScroll(), d->verticalScroll()); | - | ||||||||||||||||||
1599 | QRect r = rect.adjusted(0, 0, 1, 1); | - | ||||||||||||||||||
1600 | QPointF tl = scrollOffset + r.topLeft(); | - | ||||||||||||||||||
1601 | QPointF tr = scrollOffset + r.topRight(); | - | ||||||||||||||||||
1602 | QPointF br = scrollOffset + r.bottomRight(); | - | ||||||||||||||||||
1603 | QPointF bl = scrollOffset + r.bottomLeft(); | - | ||||||||||||||||||
1604 | - | |||||||||||||||||||
1605 | QPolygonF poly(4); | - | ||||||||||||||||||
1606 | if (!d->identityMatrix) { | - | ||||||||||||||||||
1607 | QTransform x = d->matrix.inverted(); | - | ||||||||||||||||||
1608 | poly[0] = x.map(tl); | - | ||||||||||||||||||
1609 | poly[1] = x.map(tr); | - | ||||||||||||||||||
1610 | poly[2] = x.map(br); | - | ||||||||||||||||||
1611 | poly[3] = x.map(bl); | - | ||||||||||||||||||
1612 | } else { | - | ||||||||||||||||||
1613 | poly[0] = tl; | - | ||||||||||||||||||
1614 | poly[1] = tr; | - | ||||||||||||||||||
1615 | poly[2] = br; | - | ||||||||||||||||||
1616 | poly[3] = bl; | - | ||||||||||||||||||
1617 | } | - | ||||||||||||||||||
1618 | return poly; | - | ||||||||||||||||||
1619 | } | - | ||||||||||||||||||
1620 | QPolygonF QGraphicsView::mapToScene(const QPolygon &polygon) const | - | ||||||||||||||||||
1621 | { | - | ||||||||||||||||||
1622 | QPolygonF poly; | - | ||||||||||||||||||
1623 | poly.reserve(polygon.count()); | - | ||||||||||||||||||
1624 | for (QForeachContainer<typename QtPrivate::remove_reference<decltype(polygon)>::type> _container_((polygon)); _container_.control && _container_.i != _container_.e; ++_container_.i, _container_.control ^= 1)for (const QPoint &point = *_container_.i; _container_.control; _container_.control = 0: polygon) | - | ||||||||||||||||||
1625 | poly << mapToScene(point); never executed: poly << mapToScene(point); | 0 | ||||||||||||||||||
1626 | return never executed: poly;return poly; never executed: return poly; | 0 | ||||||||||||||||||
1627 | } | - | ||||||||||||||||||
1628 | - | |||||||||||||||||||
1629 | - | |||||||||||||||||||
1630 | - | |||||||||||||||||||
1631 | - | |||||||||||||||||||
1632 | - | |||||||||||||||||||
1633 | - | |||||||||||||||||||
1634 | - | |||||||||||||||||||
1635 | QPainterPath QGraphicsView::mapToScene(const QPainterPath &path) const | - | ||||||||||||||||||
1636 | { | - | ||||||||||||||||||
1637 | const QGraphicsViewPrivate * const d = d_func(); | - | ||||||||||||||||||
1638 | QTransform matrix = QTransform::fromTranslate(d->horizontalScroll(), d->verticalScroll()); | - | ||||||||||||||||||
1639 | matrix *= d->matrix.inverted(); | - | ||||||||||||||||||
1640 | return matrix.map(path); | - | ||||||||||||||||||
1641 | } | - | ||||||||||||||||||
1642 | - | |||||||||||||||||||
1643 | - | |||||||||||||||||||
1644 | - | |||||||||||||||||||
1645 | - | |||||||||||||||||||
1646 | - | |||||||||||||||||||
1647 | - | |||||||||||||||||||
1648 | QPoint QGraphicsView::mapFromScene(const QPointF &point) const | - | ||||||||||||||||||
1649 | { | - | ||||||||||||||||||
1650 | const QGraphicsViewPrivate * const d = d_func(); | - | ||||||||||||||||||
1651 | QPointF p = d->identityMatrix ? point : d->matrix.map(point); | - | ||||||||||||||||||
1652 | p.rx() -= d->horizontalScroll(); | - | ||||||||||||||||||
1653 | p.ry() -= d->verticalScroll(); | - | ||||||||||||||||||
1654 | return p.toPoint(); | - | ||||||||||||||||||
1655 | } | - | ||||||||||||||||||
1656 | QPolygon QGraphicsView::mapFromScene(const QRectF &rect) const | - | ||||||||||||||||||
1657 | { | - | ||||||||||||||||||
1658 | const QGraphicsViewPrivate * const d = d_func(); | - | ||||||||||||||||||
1659 | QPointF tl; | - | ||||||||||||||||||
1660 | QPointF tr; | - | ||||||||||||||||||
1661 | QPointF br; | - | ||||||||||||||||||
1662 | QPointF bl; | - | ||||||||||||||||||
1663 | if (!d->identityMatrix) { | - | ||||||||||||||||||
1664 | const QTransform &x = d->matrix; | - | ||||||||||||||||||
1665 | tl = x.map(rect.topLeft()); | - | ||||||||||||||||||
1666 | tr = x.map(rect.topRight()); | - | ||||||||||||||||||
1667 | br = x.map(rect.bottomRight()); | - | ||||||||||||||||||
1668 | bl = x.map(rect.bottomLeft()); | - | ||||||||||||||||||
1669 | } else { | - | ||||||||||||||||||
1670 | tl = rect.topLeft(); | - | ||||||||||||||||||
1671 | tr = rect.topRight(); | - | ||||||||||||||||||
1672 | br = rect.bottomRight(); | - | ||||||||||||||||||
1673 | bl = rect.bottomLeft(); | - | ||||||||||||||||||
1674 | } | - | ||||||||||||||||||
1675 | QPointF scrollOffset(d->horizontalScroll(), d->verticalScroll()); | - | ||||||||||||||||||
1676 | tl -= scrollOffset; | - | ||||||||||||||||||
1677 | tr -= scrollOffset; | - | ||||||||||||||||||
1678 | br -= scrollOffset; | - | ||||||||||||||||||
1679 | bl -= scrollOffset; | - | ||||||||||||||||||
1680 | - | |||||||||||||||||||
1681 | QPolygon poly(4); | - | ||||||||||||||||||
1682 | poly[0] = tl.toPoint(); | - | ||||||||||||||||||
1683 | poly[1] = tr.toPoint(); | - | ||||||||||||||||||
1684 | poly[2] = br.toPoint(); | - | ||||||||||||||||||
1685 | poly[3] = bl.toPoint(); | - | ||||||||||||||||||
1686 | return poly; | - | ||||||||||||||||||
1687 | } | - | ||||||||||||||||||
1688 | QPolygon QGraphicsView::mapFromScene(const QPolygonF &polygon) const | - | ||||||||||||||||||
1689 | { | - | ||||||||||||||||||
1690 | QPolygon poly; | - | ||||||||||||||||||
1691 | poly.reserve(polygon.count()); | - | ||||||||||||||||||
1692 | for (QForeachContainer<typename QtPrivate::remove_reference<decltype(polygon)>::type> _container_((polygon)); _container_.control && _container_.i != _container_.e; ++_container_.i, _container_.control ^= 1)for (const QPointF &point = *_container_.i; _container_.control; _container_.control = 0: polygon) | - | ||||||||||||||||||
1693 | poly << mapFromScene(point); never executed: poly << mapFromScene(point); | 0 | ||||||||||||||||||
1694 | return never executed: poly;return poly; never executed: return poly; | 0 | ||||||||||||||||||
1695 | } | - | ||||||||||||||||||
1696 | - | |||||||||||||||||||
1697 | - | |||||||||||||||||||
1698 | - | |||||||||||||||||||
1699 | - | |||||||||||||||||||
1700 | - | |||||||||||||||||||
1701 | - | |||||||||||||||||||
1702 | - | |||||||||||||||||||
1703 | QPainterPath QGraphicsView::mapFromScene(const QPainterPath &path) const | - | ||||||||||||||||||
1704 | { | - | ||||||||||||||||||
1705 | const QGraphicsViewPrivate * const d = d_func(); | - | ||||||||||||||||||
1706 | QTransform matrix = d->matrix; | - | ||||||||||||||||||
1707 | matrix *= QTransform::fromTranslate(-d->horizontalScroll(), -d->verticalScroll()); | - | ||||||||||||||||||
1708 | return matrix.map(path); | - | ||||||||||||||||||
1709 | } | - | ||||||||||||||||||
1710 | - | |||||||||||||||||||
1711 | - | |||||||||||||||||||
1712 | - | |||||||||||||||||||
1713 | - | |||||||||||||||||||
1714 | QVariant QGraphicsView::inputMethodQuery(Qt::InputMethodQuery query) const | - | ||||||||||||||||||
1715 | { | - | ||||||||||||||||||
1716 | const QGraphicsViewPrivate * const d = d_func(); | - | ||||||||||||||||||
1717 | if (!d->scene) | - | ||||||||||||||||||
1718 | return QVariant(); | - | ||||||||||||||||||
1719 | - | |||||||||||||||||||
1720 | QVariant value = d->scene->inputMethodQuery(query); | - | ||||||||||||||||||
1721 | if (value.type() == QVariant::RectF) | - | ||||||||||||||||||
1722 | value = d->mapRectFromScene(value.toRectF()); | - | ||||||||||||||||||
1723 | else if (value.type() == QVariant::PointF) | - | ||||||||||||||||||
1724 | value = mapFromScene(value.toPointF()); | - | ||||||||||||||||||
1725 | else if (value.type() == QVariant::Rect) | - | ||||||||||||||||||
1726 | value = d->mapRectFromScene(value.toRect()).toRect(); | - | ||||||||||||||||||
1727 | else if (value.type() == QVariant::Point) | - | ||||||||||||||||||
1728 | value = mapFromScene(value.toPoint()); | - | ||||||||||||||||||
1729 | return value; | - | ||||||||||||||||||
1730 | } | - | ||||||||||||||||||
1731 | QBrush QGraphicsView::backgroundBrush() const | - | ||||||||||||||||||
1732 | { | - | ||||||||||||||||||
1733 | const QGraphicsViewPrivate * const d = d_func(); | - | ||||||||||||||||||
1734 | return d->backgroundBrush; | - | ||||||||||||||||||
1735 | } | - | ||||||||||||||||||
1736 | void QGraphicsView::setBackgroundBrush(const QBrush &brush) | - | ||||||||||||||||||
1737 | { | - | ||||||||||||||||||
1738 | QGraphicsViewPrivate * const d = d_func(); | - | ||||||||||||||||||
1739 | d->backgroundBrush = brush; | - | ||||||||||||||||||
1740 | d->updateAll(); | - | ||||||||||||||||||
1741 | - | |||||||||||||||||||
1742 | if (d->cacheMode & CacheBackground) { | - | ||||||||||||||||||
1743 | - | |||||||||||||||||||
1744 | d->mustResizeBackgroundPixmap = true; | - | ||||||||||||||||||
1745 | } | - | ||||||||||||||||||
1746 | } | - | ||||||||||||||||||
1747 | QBrush QGraphicsView::foregroundBrush() const | - | ||||||||||||||||||
1748 | { | - | ||||||||||||||||||
1749 | const QGraphicsViewPrivate * const d = d_func(); | - | ||||||||||||||||||
1750 | return d->foregroundBrush; | - | ||||||||||||||||||
1751 | } | - | ||||||||||||||||||
1752 | void QGraphicsView::setForegroundBrush(const QBrush &brush) | - | ||||||||||||||||||
1753 | { | - | ||||||||||||||||||
1754 | QGraphicsViewPrivate * const d = d_func(); | - | ||||||||||||||||||
1755 | d->foregroundBrush = brush; | - | ||||||||||||||||||
1756 | d->updateAll(); | - | ||||||||||||||||||
1757 | } | - | ||||||||||||||||||
1758 | - | |||||||||||||||||||
1759 | - | |||||||||||||||||||
1760 | - | |||||||||||||||||||
1761 | - | |||||||||||||||||||
1762 | - | |||||||||||||||||||
1763 | - | |||||||||||||||||||
1764 | void QGraphicsView::updateScene(const QList<QRectF> &rects) | - | ||||||||||||||||||
1765 | { | - | ||||||||||||||||||
1766 | - | |||||||||||||||||||
1767 | - | |||||||||||||||||||
1768 | - | |||||||||||||||||||
1769 | - | |||||||||||||||||||
1770 | - | |||||||||||||||||||
1771 | QGraphicsViewPrivate * const d = d_func(); | - | ||||||||||||||||||
1772 | if (d->fullUpdatePending
| 0 | ||||||||||||||||||
1773 | return; never executed: return; | 0 | ||||||||||||||||||
1774 | - | |||||||||||||||||||
1775 | - | |||||||||||||||||||
1776 | QVector<QRect> dirtyViewportRects; | - | ||||||||||||||||||
1777 | const QVector<QRect> &dirtyRects = d->dirtyRegion.rects(); | - | ||||||||||||||||||
1778 | const int dirtyRectsCount = dirtyRects.size(); | - | ||||||||||||||||||
1779 | dirtyViewportRects.reserve(dirtyRectsCount + rects.count()); | - | ||||||||||||||||||
1780 | for (int i = 0; i < dirtyRectsCount
| 0 | ||||||||||||||||||
1781 | dirtyViewportRects += dirtyRects.at(i); never executed: dirtyViewportRects += dirtyRects.at(i); | 0 | ||||||||||||||||||
1782 | d->dirtyRegion = QRegion(); | - | ||||||||||||||||||
1783 | d->dirtyBoundingRect = QRect(); | - | ||||||||||||||||||
1784 | - | |||||||||||||||||||
1785 | bool fullUpdate = !d->accelerateScrolling
| 0 | ||||||||||||||||||
1786 | bool boundingRectUpdate = (
| 0 | ||||||||||||||||||
1787 | || (d->viewportUpdateMode == QGraphicsView::SmartViewportUpdate
| 0 | ||||||||||||||||||
1788 | && ((
| 0 | ||||||||||||||||||
1789 | - | |||||||||||||||||||
1790 | QRegion updateRegion; | - | ||||||||||||||||||
1791 | QRect boundingRect; | - | ||||||||||||||||||
1792 | QRect viewportRect = viewport()->rect(); | - | ||||||||||||||||||
1793 | bool redraw = false; | - | ||||||||||||||||||
1794 | QTransform transform = viewportTransform(); | - | ||||||||||||||||||
1795 | - | |||||||||||||||||||
1796 | - | |||||||||||||||||||
1797 | for (QForeachContainer<typename QtPrivate::remove_reference<decltype(rects)>::type> _container_((rects)); _container_.control && _container_.i != _container_.e; ++_container_.i, _container_.control ^= 1)for (const QRectF &rect = *_container_.i; _container_.control; _container_.control = 0: rects) { | - | ||||||||||||||||||
1798 | QRect xrect = transform.mapRect(rect).toAlignedRect(); | - | ||||||||||||||||||
1799 | if (!(d->optimizationFlags & DontAdjustForAntialiasing)
| 0 | ||||||||||||||||||
1800 | xrect.adjust(-2, -2, 2, 2); never executed: xrect.adjust(-2, -2, 2, 2); | 0 | ||||||||||||||||||
1801 | else | - | ||||||||||||||||||
1802 | xrect.adjust(-1, -1, 1, 1); never executed: xrect.adjust(-1, -1, 1, 1); | 0 | ||||||||||||||||||
1803 | if (!viewportRect.intersects(xrect)
| 0 | ||||||||||||||||||
1804 | continue; never executed: continue; | 0 | ||||||||||||||||||
1805 | dirtyViewportRects << xrect; | - | ||||||||||||||||||
1806 | } never executed: end of block | 0 | ||||||||||||||||||
1807 | - | |||||||||||||||||||
1808 | for (QForeachContainer<typename QtPrivate::remove_reference<decltype(dirtyViewportRects)>::type> _container_((dirtyViewportRects)); _container_.control && _container_.i != _container_.e; ++_container_.i, _container_.control ^= 1) for (const QRect &rect = *_container_.i; _container_.control; _container_.control = 0) { | - | ||||||||||||||||||
1809 | - | |||||||||||||||||||
1810 | - | |||||||||||||||||||
1811 | if (!boundingRectUpdate
| 0 | ||||||||||||||||||
1812 | updateRegion += rect; | - | ||||||||||||||||||
1813 | } never executed: else {end of block | 0 | ||||||||||||||||||
1814 | boundingRect |= rect; | - | ||||||||||||||||||
1815 | } never executed: end of block | 0 | ||||||||||||||||||
1816 | redraw = true; | - | ||||||||||||||||||
1817 | if (fullUpdate
| 0 | ||||||||||||||||||
1818 | - | |||||||||||||||||||
1819 | - | |||||||||||||||||||
1820 | break; never executed: break; | 0 | ||||||||||||||||||
1821 | } | - | ||||||||||||||||||
1822 | } never executed: end of block | 0 | ||||||||||||||||||
1823 | - | |||||||||||||||||||
1824 | if (!redraw
| 0 | ||||||||||||||||||
1825 | return; never executed: return; | 0 | ||||||||||||||||||
1826 | - | |||||||||||||||||||
1827 | if (fullUpdate
| 0 | ||||||||||||||||||
1828 | viewport()->update(); never executed: viewport()->update(); | 0 | ||||||||||||||||||
1829 | else if (boundingRectUpdate
| 0 | ||||||||||||||||||
1830 | viewport()->update(boundingRect); never executed: viewport()->update(boundingRect); | 0 | ||||||||||||||||||
1831 | else | - | ||||||||||||||||||
1832 | viewport()->update(updateRegion); never executed: viewport()->update(updateRegion); | 0 | ||||||||||||||||||
1833 | } | - | ||||||||||||||||||
1834 | void QGraphicsView::updateSceneRect(const QRectF &rect) | - | ||||||||||||||||||
1835 | { | - | ||||||||||||||||||
1836 | QGraphicsViewPrivate * const d = d_func(); | - | ||||||||||||||||||
1837 | if (!d->hasSceneRect) { | - | ||||||||||||||||||
1838 | d->sceneRect = rect; | - | ||||||||||||||||||
1839 | d->recalculateContentSize(); | - | ||||||||||||||||||
1840 | } | - | ||||||||||||||||||
1841 | } | - | ||||||||||||||||||
1842 | void QGraphicsView::setupViewport(QWidget *widget) | - | ||||||||||||||||||
1843 | { | - | ||||||||||||||||||
1844 | QGraphicsViewPrivate * const d = d_func(); | - | ||||||||||||||||||
1845 | - | |||||||||||||||||||
1846 | if (!widget
| 0 | ||||||||||||||||||
1847 | QMessageLogger(__FILE__, 27632765, __PRETTY_FUNCTION__).warning("QGraphicsView::setupViewport: cannot initialize null widget"); | - | ||||||||||||||||||
1848 | return; never executed: return; | 0 | ||||||||||||||||||
1849 | } | - | ||||||||||||||||||
1850 | - | |||||||||||||||||||
1851 | const bool isGLWidget = widget->inherits("QGLWidget")
| 0 | ||||||||||||||||||
1852 | - | |||||||||||||||||||
1853 | d->accelerateScrolling = !(isGLWidget); | - | ||||||||||||||||||
1854 | - | |||||||||||||||||||
1855 | widget->setFocusPolicy(Qt::StrongFocus); | - | ||||||||||||||||||
1856 | - | |||||||||||||||||||
1857 | if (!isGLWidget
| 0 | ||||||||||||||||||
1858 | - | |||||||||||||||||||
1859 | widget->setAutoFillBackground(true); | - | ||||||||||||||||||
1860 | } never executed: end of block | 0 | ||||||||||||||||||
1861 | - | |||||||||||||||||||
1862 | - | |||||||||||||||||||
1863 | - | |||||||||||||||||||
1864 | - | |||||||||||||||||||
1865 | if ((d->scene
| 0 | ||||||||||||||||||
1866 | || !d->scene->d_func()->allItemsUseDefaultCursor
| 0 | ||||||||||||||||||
1867 | || d->transformationAnchor == AnchorUnderMouse
| 0 | ||||||||||||||||||
1868 | || d->resizeAnchor == AnchorUnderMouse
| 0 | ||||||||||||||||||
1869 | widget->setMouseTracking(true); | - | ||||||||||||||||||
1870 | } never executed: end of block | 0 | ||||||||||||||||||
1871 | - | |||||||||||||||||||
1872 | - | |||||||||||||||||||
1873 | if (d->scene
| 0 | ||||||||||||||||||
1874 | widget->setAttribute(Qt::WA_AcceptTouchEvents); never executed: widget->setAttribute(Qt::WA_AcceptTouchEvents); | 0 | ||||||||||||||||||
1875 | - | |||||||||||||||||||
1876 | - | |||||||||||||||||||
1877 | if (d->scene
| 0 | ||||||||||||||||||
1878 | for (QForeachContainer<typename QtPrivate::remove_reference<decltype(d->scene->d_func()->grabbedGestures.keys())>::type> _container_((const auto gestures = d->scene->d_func()->grabbedGestures.keys())); _container_.control && _container_.i != _container_.e; ++_container_.i, _container_.control ^= 1)(); | - | ||||||||||||||||||
1879 | for (Qt::GestureType gesture = *_container_.i; _container_.control; _container_.control = 0: gestures) | - | ||||||||||||||||||
1880 | widget->grabGesture(gesture); never executed: widget->grabGesture(gesture); | 0 | ||||||||||||||||||
1881 | } never executed: end of block | 0 | ||||||||||||||||||
1882 | - | |||||||||||||||||||
1883 | - | |||||||||||||||||||
1884 | widget->setAcceptDrops(acceptDrops()); | - | ||||||||||||||||||
1885 | } never executed: end of block | 0 | ||||||||||||||||||
1886 | - | |||||||||||||||||||
1887 | - | |||||||||||||||||||
1888 | - | |||||||||||||||||||
1889 | - | |||||||||||||||||||
1890 | bool QGraphicsView::event(QEvent *event) | - | ||||||||||||||||||
1891 | { | - | ||||||||||||||||||
1892 | QGraphicsViewPrivate * const d = d_func(); | - | ||||||||||||||||||
1893 | - | |||||||||||||||||||
1894 | if (d->sceneInteractionAllowed) { | - | ||||||||||||||||||
1895 | switch (event->type()) { | - | ||||||||||||||||||
1896 | case QEvent::ShortcutOverride: | - | ||||||||||||||||||
1897 | if (d->scene) | - | ||||||||||||||||||
1898 | return QApplication::sendEvent(d->scene, event); | - | ||||||||||||||||||
1899 | break; | - | ||||||||||||||||||
1900 | case QEvent::KeyPress: | - | ||||||||||||||||||
1901 | if (d->scene) { | - | ||||||||||||||||||
1902 | QKeyEvent *k = static_cast<QKeyEvent *>(event); | - | ||||||||||||||||||
1903 | if (k->key() == Qt::Key_Tab || k->key() == Qt::Key_Backtab) { | - | ||||||||||||||||||
1904 | - | |||||||||||||||||||
1905 | - | |||||||||||||||||||
1906 | - | |||||||||||||||||||
1907 | - | |||||||||||||||||||
1908 | - | |||||||||||||||||||
1909 | - | |||||||||||||||||||
1910 | QApplication::sendEvent(d->scene, event); | - | ||||||||||||||||||
1911 | if (event->isAccepted()) | - | ||||||||||||||||||
1912 | return true; | - | ||||||||||||||||||
1913 | - | |||||||||||||||||||
1914 | - | |||||||||||||||||||
1915 | - | |||||||||||||||||||
1916 | event->accept(); | - | ||||||||||||||||||
1917 | } | - | ||||||||||||||||||
1918 | } | - | ||||||||||||||||||
1919 | break; | - | ||||||||||||||||||
1920 | default: | - | ||||||||||||||||||
1921 | break; | - | ||||||||||||||||||
1922 | } | - | ||||||||||||||||||
1923 | } | - | ||||||||||||||||||
1924 | - | |||||||||||||||||||
1925 | return QAbstractScrollArea::event(event); | - | ||||||||||||||||||
1926 | } | - | ||||||||||||||||||
1927 | - | |||||||||||||||||||
1928 | - | |||||||||||||||||||
1929 | - | |||||||||||||||||||
1930 | - | |||||||||||||||||||
1931 | bool QGraphicsView::viewportEvent(QEvent *event) | - | ||||||||||||||||||
1932 | { | - | ||||||||||||||||||
1933 | QGraphicsViewPrivate * const d = d_func(); | - | ||||||||||||||||||
1934 | if (!d->scene
| 0 | ||||||||||||||||||
1935 | return never executed: QAbstractScrollArea::viewportEvent(event);return QAbstractScrollArea::viewportEvent(event); never executed: return QAbstractScrollArea::viewportEvent(event); | 0 | ||||||||||||||||||
1936 | - | |||||||||||||||||||
1937 | switch (event->type()) { | - | ||||||||||||||||||
1938 | case never executed: QEvent::Enter:case QEvent::Enter: never executed: case QEvent::Enter: | 0 | ||||||||||||||||||
1939 | QApplication::sendEvent(d->scene, event); | - | ||||||||||||||||||
1940 | break; never executed: break; | 0 | ||||||||||||||||||
1941 | case never executed: QEvent::WindowActivate:case QEvent::WindowActivate: never executed: case QEvent::WindowActivate: | 0 | ||||||||||||||||||
1942 | QApplication::sendEvent(d->scene, event); | - | ||||||||||||||||||
1943 | break; never executed: break; | 0 | ||||||||||||||||||
1944 | case never executed: QEvent::WindowDeactivate:case QEvent::WindowDeactivate: never executed: case QEvent::WindowDeactivate: | 0 | ||||||||||||||||||
1945 | - | |||||||||||||||||||
1946 | - | |||||||||||||||||||
1947 | - | |||||||||||||||||||
1948 | - | |||||||||||||||||||
1949 | if (!d->scene->d_func()->popupWidgets.isEmpty()
| 0 | ||||||||||||||||||
1950 | d->scene->d_func()->removePopup(d->scene->d_func()->popupWidgets.firstconstFirst()); never executed: d->scene->d_func()->removePopup(d->scene->d_func()->popupWidgets.constFirst()); | 0 | ||||||||||||||||||
1951 | QApplication::sendEvent(d->scene, event); | - | ||||||||||||||||||
1952 | break; never executed: break; | 0 | ||||||||||||||||||
1953 | case never executed: QEvent::Show:case QEvent::Show: never executed: case QEvent::Show: | 0 | ||||||||||||||||||
1954 | if (d->scene
| 0 | ||||||||||||||||||
1955 | QEvent windowActivate(QEvent::WindowActivate); | - | ||||||||||||||||||
1956 | QApplication::sendEvent(d->scene, &windowActivate); | - | ||||||||||||||||||
1957 | } never executed: end of block | 0 | ||||||||||||||||||
1958 | break; never executed: break; | 0 | ||||||||||||||||||
1959 | case never executed: QEvent::Hide:case QEvent::Hide: never executed: case QEvent::Hide: | 0 | ||||||||||||||||||
1960 | - | |||||||||||||||||||
1961 | if (!event->spontaneous()
| 0 | ||||||||||||||||||
1962 | QEvent windowDeactivate(QEvent::WindowDeactivate); | - | ||||||||||||||||||
1963 | QApplication::sendEvent(d->scene, &windowDeactivate); | - | ||||||||||||||||||
1964 | } never executed: end of block | 0 | ||||||||||||||||||
1965 | break; never executed: break; | 0 | ||||||||||||||||||
1966 | case never executed: QEvent::Leave:case QEvent::Leave: never executed: {case QEvent::Leave: | 0 | ||||||||||||||||||
1967 | - | |||||||||||||||||||
1968 | - | |||||||||||||||||||
1969 | - | |||||||||||||||||||
1970 | if ((QApplication::activePopupWidget()
| 0 | ||||||||||||||||||
1971 | || (QApplication::activeModalWidget()
| 0 | ||||||||||||||||||
1972 | || (
| 0 | ||||||||||||||||||
1973 | if (!d->scene->d_func()->popupWidgets.isEmpty()
| 0 | ||||||||||||||||||
1974 | d->scene->d_func()->removePopup(d->scene->d_func()->popupWidgets.firstconstFirst()); never executed: d->scene->d_func()->removePopup(d->scene->d_func()->popupWidgets.constFirst()); | 0 | ||||||||||||||||||
1975 | } never executed: end of block | 0 | ||||||||||||||||||
1976 | d->useLastMouseEvent = false; | - | ||||||||||||||||||
1977 | - | |||||||||||||||||||
1978 | ((!(event->d == 0)) ? qt_assert("event->d == 0",__FILE__,28932896) : qt_noop()); | - | ||||||||||||||||||
1979 | QScopedValueRollback<QEventPrivate *> rb(event->d); | - | ||||||||||||||||||
1980 | event->d = reinterpret_cast<QEventPrivate *>(viewport()); | - | ||||||||||||||||||
1981 | QApplication::sendEvent(d->scene, event); | - | ||||||||||||||||||
1982 | break; never executed: break; | 0 | ||||||||||||||||||
1983 | } | - | ||||||||||||||||||
1984 | - | |||||||||||||||||||
1985 | case never executed: QEvent::ToolTip:case QEvent::ToolTip: never executed: {case QEvent::ToolTip: | 0 | ||||||||||||||||||
1986 | QHelpEvent *toolTip = static_cast<QHelpEvent *>(event); | - | ||||||||||||||||||
1987 | QGraphicsSceneHelpEvent helpEvent(QEvent::GraphicsSceneHelp); | - | ||||||||||||||||||
1988 | helpEvent.setWidget(viewport()); | - | ||||||||||||||||||
1989 | helpEvent.setScreenPos(toolTip->globalPos()); | - | ||||||||||||||||||
1990 | helpEvent.setScenePos(mapToScene(toolTip->pos())); | - | ||||||||||||||||||
1991 | QApplication::sendEvent(d->scene, &helpEvent); | - | ||||||||||||||||||
1992 | toolTip->setAccepted(helpEvent.isAccepted()); | - | ||||||||||||||||||
1993 | return never executed: true;return true; never executed: return true; | 0 | ||||||||||||||||||
1994 | } | - | ||||||||||||||||||
1995 | - | |||||||||||||||||||
1996 | case never executed: QEvent::Paint:case QEvent::Paint: never executed: case QEvent::Paint: | 0 | ||||||||||||||||||
1997 | - | |||||||||||||||||||
1998 | d->fullUpdatePending = false; | - | ||||||||||||||||||
1999 | d->dirtyScrollOffset = QPoint(); | - | ||||||||||||||||||
2000 | if (d->scene
| 0 | ||||||||||||||||||
2001 | - | |||||||||||||||||||
2002 | - | |||||||||||||||||||
2003 | - | |||||||||||||||||||
2004 | if (!d->updateSceneSlotReimplementedChecked
| 0 | ||||||||||||||||||
2005 | d->updateSceneSlotReimplementedChecked = true; | - | ||||||||||||||||||
2006 | const QMetaObject *mo = metaObject(); | - | ||||||||||||||||||
2007 | if (mo != &QGraphicsView::staticMetaObject
| 0 | ||||||||||||||||||
2008 | if (mo->indexOfSlot("updateScene(QList<QRectF>)")
| 0 | ||||||||||||||||||
2009 | != QGraphicsView::staticMetaObject.indexOfSlot("updateScene(QList<QRectF>)")
| 0 | ||||||||||||||||||
2010 | connect(d->scene, qFlagLocation("2""changed(QList<QRectF>)" "\0" __FILE__ ":" "2925""2928"), | - | ||||||||||||||||||
2011 | this, qFlagLocation("1""updateScene(QList<QRectF>)" "\0" __FILE__ ":" "2926""2929")); | - | ||||||||||||||||||
2012 | } never executed: end of block | 0 | ||||||||||||||||||
2013 | } never executed: end of block | 0 | ||||||||||||||||||
2014 | } never executed: end of block | 0 | ||||||||||||||||||
2015 | } never executed: end of block | 0 | ||||||||||||||||||
2016 | break; never executed: break; | 0 | ||||||||||||||||||
2017 | case never executed: QEvent::TouchBegin:case QEvent::TouchBegin: never executed: case QEvent::TouchBegin: | 0 | ||||||||||||||||||
2018 | case never executed: QEvent::TouchUpdate:case QEvent::TouchUpdate: never executed: case QEvent::TouchUpdate: | 0 | ||||||||||||||||||
2019 | case never executed: QEvent::TouchEnd:case QEvent::TouchEnd: never executed: case QEvent::TouchEnd: | 0 | ||||||||||||||||||
2020 | { | - | ||||||||||||||||||
2021 | if (!isEnabled()
| 0 | ||||||||||||||||||
2022 | return never executed: false;return false; never executed: return false; | 0 | ||||||||||||||||||
2023 | - | |||||||||||||||||||
2024 | if (d->scene
| 0 | ||||||||||||||||||
2025 | - | |||||||||||||||||||
2026 | QTouchEvent *touchEvent = static_cast<QTouchEvent *>(event); | - | ||||||||||||||||||
2027 | touchEvent->setTarget(viewport()); | - | ||||||||||||||||||
2028 | QGraphicsViewPrivate::translateTouchEvent(d, touchEvent); | - | ||||||||||||||||||
2029 | (void) QApplication::sendEvent(d->scene, touchEvent); | - | ||||||||||||||||||
2030 | } never executed: else {end of block | 0 | ||||||||||||||||||
2031 | event->ignore(); | - | ||||||||||||||||||
2032 | } never executed: end of block | 0 | ||||||||||||||||||
2033 | - | |||||||||||||||||||
2034 | return never executed: true;return true; never executed: return true; | 0 | ||||||||||||||||||
2035 | } | - | ||||||||||||||||||
2036 | - | |||||||||||||||||||
2037 | case never executed: QEvent::Gesture:case QEvent::Gesture: never executed: case QEvent::Gesture: | 0 | ||||||||||||||||||
2038 | case never executed: QEvent::GestureOverride:case QEvent::GestureOverride: never executed: case QEvent::GestureOverride: | 0 | ||||||||||||||||||
2039 | { | - | ||||||||||||||||||
2040 | if (!isEnabled()
| 0 | ||||||||||||||||||
2041 | return never executed: false;return false; never executed: return false; | 0 | ||||||||||||||||||
2042 | - | |||||||||||||||||||
2043 | if (d->scene
| 0 | ||||||||||||||||||
2044 | QGestureEvent *gestureEvent = static_cast<QGestureEvent *>(event); | - | ||||||||||||||||||
2045 | gestureEvent->setWidget(viewport()); | - | ||||||||||||||||||
2046 | (void) QApplication::sendEvent(d->scene, gestureEvent); | - | ||||||||||||||||||
2047 | } never executed: end of block | 0 | ||||||||||||||||||
2048 | return never executed: true;return true; never executed: return true; | 0 | ||||||||||||||||||
2049 | } | - | ||||||||||||||||||
2050 | - | |||||||||||||||||||
2051 | default never executed: :default: never executed: default: | 0 | ||||||||||||||||||
2052 | break; never executed: break; | 0 | ||||||||||||||||||
2053 | } | - | ||||||||||||||||||
2054 | - | |||||||||||||||||||
2055 | return never executed: QAbstractScrollArea::viewportEvent(event);return QAbstractScrollArea::viewportEvent(event); never executed: return QAbstractScrollArea::viewportEvent(event); | 0 | ||||||||||||||||||
2056 | } | - | ||||||||||||||||||
2057 | - | |||||||||||||||||||
2058 | - | |||||||||||||||||||
2059 | - | |||||||||||||||||||
2060 | - | |||||||||||||||||||
2061 | - | |||||||||||||||||||
2062 | void QGraphicsView::contextMenuEvent(QContextMenuEvent *event) | - | ||||||||||||||||||
2063 | { | - | ||||||||||||||||||
2064 | QGraphicsViewPrivate * const d = d_func(); | - | ||||||||||||||||||
2065 | if (!d->scene || !d->sceneInteractionAllowed) | - | ||||||||||||||||||
2066 | return; | - | ||||||||||||||||||
2067 | - | |||||||||||||||||||
2068 | d->mousePressViewPoint = event->pos(); | - | ||||||||||||||||||
2069 | d->mousePressScenePoint = mapToScene(d->mousePressViewPoint); | - | ||||||||||||||||||
2070 | d->mousePressScreenPoint = event->globalPos(); | - | ||||||||||||||||||
2071 | d->lastMouseMoveScenePoint = d->mousePressScenePoint; | - | ||||||||||||||||||
2072 | d->lastMouseMoveScreenPoint = d->mousePressScreenPoint; | - | ||||||||||||||||||
2073 | - | |||||||||||||||||||
2074 | QGraphicsSceneContextMenuEvent contextEvent(QEvent::GraphicsSceneContextMenu); | - | ||||||||||||||||||
2075 | contextEvent.setWidget(viewport()); | - | ||||||||||||||||||
2076 | contextEvent.setScenePos(d->mousePressScenePoint); | - | ||||||||||||||||||
2077 | contextEvent.setScreenPos(d->mousePressScreenPoint); | - | ||||||||||||||||||
2078 | contextEvent.setModifiers(event->modifiers()); | - | ||||||||||||||||||
2079 | contextEvent.setReason((QGraphicsSceneContextMenuEvent::Reason)(event->reason())); | - | ||||||||||||||||||
2080 | contextEvent.setAccepted(event->isAccepted()); | - | ||||||||||||||||||
2081 | QApplication::sendEvent(d->scene, &contextEvent); | - | ||||||||||||||||||
2082 | event->setAccepted(contextEvent.isAccepted()); | - | ||||||||||||||||||
2083 | } | - | ||||||||||||||||||
2084 | - | |||||||||||||||||||
2085 | - | |||||||||||||||||||
2086 | - | |||||||||||||||||||
2087 | - | |||||||||||||||||||
2088 | - | |||||||||||||||||||
2089 | void QGraphicsView::dropEvent(QDropEvent *event) | - | ||||||||||||||||||
2090 | { | - | ||||||||||||||||||
2091 | - | |||||||||||||||||||
2092 | QGraphicsViewPrivate * const d = d_func(); | - | ||||||||||||||||||
2093 | if (!d->scene || !d->sceneInteractionAllowed) | - | ||||||||||||||||||
2094 | return; | - | ||||||||||||||||||
2095 | - | |||||||||||||||||||
2096 | - | |||||||||||||||||||
2097 | QGraphicsSceneDragDropEvent sceneEvent(QEvent::GraphicsSceneDrop); | - | ||||||||||||||||||
2098 | d->populateSceneDragDropEvent(&sceneEvent, event); | - | ||||||||||||||||||
2099 | - | |||||||||||||||||||
2100 | - | |||||||||||||||||||
2101 | QApplication::sendEvent(d->scene, &sceneEvent); | - | ||||||||||||||||||
2102 | - | |||||||||||||||||||
2103 | - | |||||||||||||||||||
2104 | event->setAccepted(sceneEvent.isAccepted()); | - | ||||||||||||||||||
2105 | if (sceneEvent.isAccepted()) | - | ||||||||||||||||||
2106 | event->setDropAction(sceneEvent.dropAction()); | - | ||||||||||||||||||
2107 | - | |||||||||||||||||||
2108 | delete d->lastDragDropEvent; | - | ||||||||||||||||||
2109 | d->lastDragDropEvent = 0; | - | ||||||||||||||||||
2110 | - | |||||||||||||||||||
2111 | - | |||||||||||||||||||
2112 | - | |||||||||||||||||||
2113 | - | |||||||||||||||||||
2114 | } | - | ||||||||||||||||||
2115 | - | |||||||||||||||||||
2116 | - | |||||||||||||||||||
2117 | - | |||||||||||||||||||
2118 | - | |||||||||||||||||||
2119 | void QGraphicsView::dragEnterEvent(QDragEnterEvent *event) | - | ||||||||||||||||||
2120 | { | - | ||||||||||||||||||
2121 | - | |||||||||||||||||||
2122 | QGraphicsViewPrivate * const d = d_func(); | - | ||||||||||||||||||
2123 | if (!d->scene || !d->sceneInteractionAllowed) | - | ||||||||||||||||||
2124 | return; | - | ||||||||||||||||||
2125 | - | |||||||||||||||||||
2126 | - | |||||||||||||||||||
2127 | d->useLastMouseEvent = false; | - | ||||||||||||||||||
2128 | - | |||||||||||||||||||
2129 | - | |||||||||||||||||||
2130 | QGraphicsSceneDragDropEvent sceneEvent(QEvent::GraphicsSceneDragEnter); | - | ||||||||||||||||||
2131 | d->populateSceneDragDropEvent(&sceneEvent, event); | - | ||||||||||||||||||
2132 | - | |||||||||||||||||||
2133 | - | |||||||||||||||||||
2134 | d->storeDragDropEvent(&sceneEvent); | - | ||||||||||||||||||
2135 | - | |||||||||||||||||||
2136 | - | |||||||||||||||||||
2137 | QApplication::sendEvent(d->scene, &sceneEvent); | - | ||||||||||||||||||
2138 | - | |||||||||||||||||||
2139 | - | |||||||||||||||||||
2140 | if (sceneEvent.isAccepted()) { | - | ||||||||||||||||||
2141 | event->setAccepted(true); | - | ||||||||||||||||||
2142 | event->setDropAction(sceneEvent.dropAction()); | - | ||||||||||||||||||
2143 | } | - | ||||||||||||||||||
2144 | - | |||||||||||||||||||
2145 | - | |||||||||||||||||||
2146 | - | |||||||||||||||||||
2147 | } | - | ||||||||||||||||||
2148 | - | |||||||||||||||||||
2149 | - | |||||||||||||||||||
2150 | - | |||||||||||||||||||
2151 | - | |||||||||||||||||||
2152 | void QGraphicsView::dragLeaveEvent(QDragLeaveEvent *event) | - | ||||||||||||||||||
2153 | { | - | ||||||||||||||||||
2154 | - | |||||||||||||||||||
2155 | QGraphicsViewPrivate * const d = d_func(); | - | ||||||||||||||||||
2156 | if (!d->scene || !d->sceneInteractionAllowed) | - | ||||||||||||||||||
2157 | return; | - | ||||||||||||||||||
2158 | if (!d->lastDragDropEvent) { | - | ||||||||||||||||||
2159 | QMessageLogger(__FILE__, 30743077, __PRETTY_FUNCTION__).warning("QGraphicsView::dragLeaveEvent: drag leave received before drag enter"); | - | ||||||||||||||||||
2160 | return; | - | ||||||||||||||||||
2161 | } | - | ||||||||||||||||||
2162 | - | |||||||||||||||||||
2163 | - | |||||||||||||||||||
2164 | QGraphicsSceneDragDropEvent sceneEvent(QEvent::GraphicsSceneDragLeave); | - | ||||||||||||||||||
2165 | sceneEvent.setScenePos(d->lastDragDropEvent->scenePos()); | - | ||||||||||||||||||
2166 | sceneEvent.setScreenPos(d->lastDragDropEvent->screenPos()); | - | ||||||||||||||||||
2167 | sceneEvent.setButtons(d->lastDragDropEvent->buttons()); | - | ||||||||||||||||||
2168 | sceneEvent.setModifiers(d->lastDragDropEvent->modifiers()); | - | ||||||||||||||||||
2169 | sceneEvent.setPossibleActions(d->lastDragDropEvent->possibleActions()); | - | ||||||||||||||||||
2170 | sceneEvent.setProposedAction(d->lastDragDropEvent->proposedAction()); | - | ||||||||||||||||||
2171 | sceneEvent.setDropAction(d->lastDragDropEvent->dropAction()); | - | ||||||||||||||||||
2172 | sceneEvent.setMimeData(d->lastDragDropEvent->mimeData()); | - | ||||||||||||||||||
2173 | sceneEvent.setWidget(d->lastDragDropEvent->widget()); | - | ||||||||||||||||||
2174 | sceneEvent.setSource(d->lastDragDropEvent->source()); | - | ||||||||||||||||||
2175 | delete d->lastDragDropEvent; | - | ||||||||||||||||||
2176 | d->lastDragDropEvent = 0; | - | ||||||||||||||||||
2177 | - | |||||||||||||||||||
2178 | - | |||||||||||||||||||
2179 | QApplication::sendEvent(d->scene, &sceneEvent); | - | ||||||||||||||||||
2180 | - | |||||||||||||||||||
2181 | - | |||||||||||||||||||
2182 | if (sceneEvent.isAccepted()) | - | ||||||||||||||||||
2183 | event->setAccepted(true); | - | ||||||||||||||||||
2184 | - | |||||||||||||||||||
2185 | - | |||||||||||||||||||
2186 | - | |||||||||||||||||||
2187 | } | - | ||||||||||||||||||
2188 | - | |||||||||||||||||||
2189 | - | |||||||||||||||||||
2190 | - | |||||||||||||||||||
2191 | - | |||||||||||||||||||
2192 | void QGraphicsView::dragMoveEvent(QDragMoveEvent *event) | - | ||||||||||||||||||
2193 | { | - | ||||||||||||||||||
2194 | - | |||||||||||||||||||
2195 | QGraphicsViewPrivate * const d = d_func(); | - | ||||||||||||||||||
2196 | if (!d->scene || !d->sceneInteractionAllowed) | - | ||||||||||||||||||
2197 | return; | - | ||||||||||||||||||
2198 | - | |||||||||||||||||||
2199 | - | |||||||||||||||||||
2200 | QGraphicsSceneDragDropEvent sceneEvent(QEvent::GraphicsSceneDragMove); | - | ||||||||||||||||||
2201 | d->populateSceneDragDropEvent(&sceneEvent, event); | - | ||||||||||||||||||
2202 | - | |||||||||||||||||||
2203 | - | |||||||||||||||||||
2204 | d->storeDragDropEvent(&sceneEvent); | - | ||||||||||||||||||
2205 | - | |||||||||||||||||||
2206 | - | |||||||||||||||||||
2207 | QApplication::sendEvent(d->scene, &sceneEvent); | - | ||||||||||||||||||
2208 | - | |||||||||||||||||||
2209 | - | |||||||||||||||||||
2210 | event->setAccepted(sceneEvent.isAccepted()); | - | ||||||||||||||||||
2211 | if (sceneEvent.isAccepted()) | - | ||||||||||||||||||
2212 | event->setDropAction(sceneEvent.dropAction()); | - | ||||||||||||||||||
2213 | - | |||||||||||||||||||
2214 | - | |||||||||||||||||||
2215 | - | |||||||||||||||||||
2216 | } | - | ||||||||||||||||||
2217 | - | |||||||||||||||||||
2218 | - | |||||||||||||||||||
2219 | - | |||||||||||||||||||
2220 | - | |||||||||||||||||||
2221 | void QGraphicsView::focusInEvent(QFocusEvent *event) | - | ||||||||||||||||||
2222 | { | - | ||||||||||||||||||
2223 | QGraphicsViewPrivate * const d = d_func(); | - | ||||||||||||||||||
2224 | d->updateInputMethodSensitivity(); | - | ||||||||||||||||||
2225 | QAbstractScrollArea::focusInEvent(event); | - | ||||||||||||||||||
2226 | if (d->scene) | - | ||||||||||||||||||
2227 | QApplication::sendEvent(d->scene, event); | - | ||||||||||||||||||
2228 | - | |||||||||||||||||||
2229 | if (!d->scene || !event->isAccepted()) | - | ||||||||||||||||||
2230 | QAbstractScrollArea::focusInEvent(event); | - | ||||||||||||||||||
2231 | } | - | ||||||||||||||||||
2232 | - | |||||||||||||||||||
2233 | - | |||||||||||||||||||
2234 | - | |||||||||||||||||||
2235 | - | |||||||||||||||||||
2236 | bool QGraphicsView::focusNextPrevChild(bool next) | - | ||||||||||||||||||
2237 | { | - | ||||||||||||||||||
2238 | return QAbstractScrollArea::focusNextPrevChild(next); | - | ||||||||||||||||||
2239 | } | - | ||||||||||||||||||
2240 | - | |||||||||||||||||||
2241 | - | |||||||||||||||||||
2242 | - | |||||||||||||||||||
2243 | - | |||||||||||||||||||
2244 | void QGraphicsView::focusOutEvent(QFocusEvent *event) | - | ||||||||||||||||||
2245 | { | - | ||||||||||||||||||
2246 | QGraphicsViewPrivate * const d = d_func(); | - | ||||||||||||||||||
2247 | QAbstractScrollArea::focusOutEvent(event); | - | ||||||||||||||||||
2248 | if (d->scene) | - | ||||||||||||||||||
2249 | QApplication::sendEvent(d->scene, event); | - | ||||||||||||||||||
2250 | } | - | ||||||||||||||||||
2251 | - | |||||||||||||||||||
2252 | - | |||||||||||||||||||
2253 | - | |||||||||||||||||||
2254 | - | |||||||||||||||||||
2255 | void QGraphicsView::keyPressEvent(QKeyEvent *event) | - | ||||||||||||||||||
2256 | { | - | ||||||||||||||||||
2257 | QGraphicsViewPrivate * const d = d_func(); | - | ||||||||||||||||||
2258 | if (!d->scene || !d->sceneInteractionAllowed) { | - | ||||||||||||||||||
2259 | QAbstractScrollArea::keyPressEvent(event); | - | ||||||||||||||||||
2260 | return; | - | ||||||||||||||||||
2261 | } | - | ||||||||||||||||||
2262 | QApplication::sendEvent(d->scene, event); | - | ||||||||||||||||||
2263 | if (!event->isAccepted()) | - | ||||||||||||||||||
2264 | QAbstractScrollArea::keyPressEvent(event); | - | ||||||||||||||||||
2265 | } | - | ||||||||||||||||||
2266 | - | |||||||||||||||||||
2267 | - | |||||||||||||||||||
2268 | - | |||||||||||||||||||
2269 | - | |||||||||||||||||||
2270 | void QGraphicsView::keyReleaseEvent(QKeyEvent *event) | - | ||||||||||||||||||
2271 | { | - | ||||||||||||||||||
2272 | QGraphicsViewPrivate * const d = d_func(); | - | ||||||||||||||||||
2273 | if (!d->scene || !d->sceneInteractionAllowed) | - | ||||||||||||||||||
2274 | return; | - | ||||||||||||||||||
2275 | QApplication::sendEvent(d->scene, event); | - | ||||||||||||||||||
2276 | if (!event->isAccepted()) | - | ||||||||||||||||||
2277 | QAbstractScrollArea::keyReleaseEvent(event); | - | ||||||||||||||||||
2278 | } | - | ||||||||||||||||||
2279 | - | |||||||||||||||||||
2280 | - | |||||||||||||||||||
2281 | - | |||||||||||||||||||
2282 | - | |||||||||||||||||||
2283 | void QGraphicsView::mouseDoubleClickEvent(QMouseEvent *event) | - | ||||||||||||||||||
2284 | { | - | ||||||||||||||||||
2285 | QGraphicsViewPrivate * const d = d_func(); | - | ||||||||||||||||||
2286 | if (!d->scene || !d->sceneInteractionAllowed) | - | ||||||||||||||||||
2287 | return; | - | ||||||||||||||||||
2288 | - | |||||||||||||||||||
2289 | d->storeMouseEvent(event); | - | ||||||||||||||||||
2290 | d->mousePressViewPoint = event->pos(); | - | ||||||||||||||||||
2291 | d->mousePressScenePoint = mapToScene(d->mousePressViewPoint); | - | ||||||||||||||||||
2292 | d->mousePressScreenPoint = event->globalPos(); | - | ||||||||||||||||||
2293 | d->lastMouseMoveScenePoint = d->mousePressScenePoint; | - | ||||||||||||||||||
2294 | d->lastMouseMoveScreenPoint = d->mousePressScreenPoint; | - | ||||||||||||||||||
2295 | d->mousePressButton = event->button(); | - | ||||||||||||||||||
2296 | - | |||||||||||||||||||
2297 | QGraphicsSceneMouseEvent mouseEvent(QEvent::GraphicsSceneMouseDoubleClick); | - | ||||||||||||||||||
2298 | mouseEvent.setWidget(viewport()); | - | ||||||||||||||||||
2299 | mouseEvent.setButtonDownScenePos(d->mousePressButton, d->mousePressScenePoint); | - | ||||||||||||||||||
2300 | mouseEvent.setButtonDownScreenPos(d->mousePressButton, d->mousePressScreenPoint); | - | ||||||||||||||||||
2301 | mouseEvent.setScenePos(mapToScene(d->mousePressViewPoint)); | - | ||||||||||||||||||
2302 | mouseEvent.setScreenPos(d->mousePressScreenPoint); | - | ||||||||||||||||||
2303 | mouseEvent.setLastScenePos(d->lastMouseMoveScenePoint); | - | ||||||||||||||||||
2304 | mouseEvent.setLastScreenPos(d->lastMouseMoveScreenPoint); | - | ||||||||||||||||||
2305 | mouseEvent.setButtons(event->buttons()); | - | ||||||||||||||||||
2306 | mouseEvent.setAccepted(false); | - | ||||||||||||||||||
2307 | mouseEvent.setButton(event->button()); | - | ||||||||||||||||||
2308 | mouseEvent.setModifiers(event->modifiers()); | - | ||||||||||||||||||
2309 | mouseEvent.setSource(event->source()); | - | ||||||||||||||||||
2310 | mouseEvent.setFlags(event->flags()); | - | ||||||||||||||||||
2311 | if (event->spontaneous()) | - | ||||||||||||||||||
2312 | qt_sendSpontaneousEvent(d->scene, &mouseEvent); | - | ||||||||||||||||||
2313 | else | - | ||||||||||||||||||
2314 | QApplication::sendEvent(d->scene, &mouseEvent); | - | ||||||||||||||||||
2315 | - | |||||||||||||||||||
2316 | - | |||||||||||||||||||
2317 | const bool isAccepted = mouseEvent.isAccepted(); | - | ||||||||||||||||||
2318 | event->setAccepted(isAccepted); | - | ||||||||||||||||||
2319 | - | |||||||||||||||||||
2320 | - | |||||||||||||||||||
2321 | d->lastMouseEvent.setAccepted(isAccepted); | - | ||||||||||||||||||
2322 | } | - | ||||||||||||||||||
2323 | - | |||||||||||||||||||
2324 | - | |||||||||||||||||||
2325 | - | |||||||||||||||||||
2326 | - | |||||||||||||||||||
2327 | void QGraphicsView::mousePressEvent(QMouseEvent *event) | - | ||||||||||||||||||
2328 | { | - | ||||||||||||||||||
2329 | QGraphicsViewPrivate * const d = d_func(); | - | ||||||||||||||||||
2330 | - | |||||||||||||||||||
2331 | - | |||||||||||||||||||
2332 | - | |||||||||||||||||||
2333 | - | |||||||||||||||||||
2334 | d->storeMouseEvent(event); | - | ||||||||||||||||||
2335 | d->lastMouseEvent.setAccepted(false); | - | ||||||||||||||||||
2336 | - | |||||||||||||||||||
2337 | if (d->sceneInteractionAllowed) { | - | ||||||||||||||||||
2338 | - | |||||||||||||||||||
2339 | d->mousePressViewPoint = event->pos(); | - | ||||||||||||||||||
2340 | d->mousePressScenePoint = mapToScene(d->mousePressViewPoint); | - | ||||||||||||||||||
2341 | d->mousePressScreenPoint = event->globalPos(); | - | ||||||||||||||||||
2342 | d->lastMouseMoveScenePoint = d->mousePressScenePoint; | - | ||||||||||||||||||
2343 | d->lastMouseMoveScreenPoint = d->mousePressScreenPoint; | - | ||||||||||||||||||
2344 | d->mousePressButton = event->button(); | - | ||||||||||||||||||
2345 | - | |||||||||||||||||||
2346 | if (d->scene) { | - | ||||||||||||||||||
2347 | - | |||||||||||||||||||
2348 | QGraphicsSceneMouseEvent mouseEvent(QEvent::GraphicsSceneMousePress); | - | ||||||||||||||||||
2349 | mouseEvent.setWidget(viewport()); | - | ||||||||||||||||||
2350 | mouseEvent.setButtonDownScenePos(d->mousePressButton, d->mousePressScenePoint); | - | ||||||||||||||||||
2351 | mouseEvent.setButtonDownScreenPos(d->mousePressButton, d->mousePressScreenPoint); | - | ||||||||||||||||||
2352 | mouseEvent.setScenePos(d->mousePressScenePoint); | - | ||||||||||||||||||
2353 | mouseEvent.setScreenPos(d->mousePressScreenPoint); | - | ||||||||||||||||||
2354 | mouseEvent.setLastScenePos(d->lastMouseMoveScenePoint); | - | ||||||||||||||||||
2355 | mouseEvent.setLastScreenPos(d->lastMouseMoveScreenPoint); | - | ||||||||||||||||||
2356 | mouseEvent.setButtons(event->buttons()); | - | ||||||||||||||||||
2357 | mouseEvent.setButton(event->button()); | - | ||||||||||||||||||
2358 | mouseEvent.setModifiers(event->modifiers()); | - | ||||||||||||||||||
2359 | mouseEvent.setSource(event->source()); | - | ||||||||||||||||||
2360 | mouseEvent.setFlags(event->flags()); | - | ||||||||||||||||||
2361 | mouseEvent.setAccepted(false); | - | ||||||||||||||||||
2362 | if (event->spontaneous()) | - | ||||||||||||||||||
2363 | qt_sendSpontaneousEvent(d->scene, &mouseEvent); | - | ||||||||||||||||||
2364 | else | - | ||||||||||||||||||
2365 | QApplication::sendEvent(d->scene, &mouseEvent); | - | ||||||||||||||||||
2366 | - | |||||||||||||||||||
2367 | - | |||||||||||||||||||
2368 | bool isAccepted = mouseEvent.isAccepted(); | - | ||||||||||||||||||
2369 | event->setAccepted(isAccepted); | - | ||||||||||||||||||
2370 | - | |||||||||||||||||||
2371 | - | |||||||||||||||||||
2372 | d->lastMouseEvent.setAccepted(isAccepted); | - | ||||||||||||||||||
2373 | - | |||||||||||||||||||
2374 | if (isAccepted) | - | ||||||||||||||||||
2375 | return; | - | ||||||||||||||||||
2376 | } | - | ||||||||||||||||||
2377 | } | - | ||||||||||||||||||
2378 | - | |||||||||||||||||||
2379 | - | |||||||||||||||||||
2380 | if (d->dragMode == QGraphicsView::RubberBandDrag && !d->rubberBanding) { | - | ||||||||||||||||||
2381 | if (d->sceneInteractionAllowed) { | - | ||||||||||||||||||
2382 | - | |||||||||||||||||||
2383 | event->accept(); | - | ||||||||||||||||||
2384 | d->rubberBanding = true; | - | ||||||||||||||||||
2385 | d->rubberBandRect = QRect(); | - | ||||||||||||||||||
2386 | if (d->scene) { | - | ||||||||||||||||||
2387 | bool extendSelection = (event->modifiers() & Qt::ControlModifier) != 0; | - | ||||||||||||||||||
2388 | - | |||||||||||||||||||
2389 | if (extendSelection) { | - | ||||||||||||||||||
2390 | d->rubberBandSelectionOperation = Qt::AddToSelection; | - | ||||||||||||||||||
2391 | } else { | - | ||||||||||||||||||
2392 | d->rubberBandSelectionOperation = Qt::ReplaceSelection; | - | ||||||||||||||||||
2393 | d->scene->clearSelection(); | - | ||||||||||||||||||
2394 | } | - | ||||||||||||||||||
2395 | } | - | ||||||||||||||||||
2396 | } | - | ||||||||||||||||||
2397 | } else | - | ||||||||||||||||||
2398 | - | |||||||||||||||||||
2399 | if (d->dragMode == QGraphicsView::ScrollHandDrag && event->button() == Qt::LeftButton) { | - | ||||||||||||||||||
2400 | - | |||||||||||||||||||
2401 | event->accept(); | - | ||||||||||||||||||
2402 | d->handScrolling = true; | - | ||||||||||||||||||
2403 | d->handScrollMotions = 0; | - | ||||||||||||||||||
2404 | - | |||||||||||||||||||
2405 | viewport()->setCursor(Qt::ClosedHandCursor); | - | ||||||||||||||||||
2406 | - | |||||||||||||||||||
2407 | } | - | ||||||||||||||||||
2408 | } | - | ||||||||||||||||||
2409 | - | |||||||||||||||||||
2410 | - | |||||||||||||||||||
2411 | - | |||||||||||||||||||
2412 | - | |||||||||||||||||||
2413 | void QGraphicsView::mouseMoveEvent(QMouseEvent *event) | - | ||||||||||||||||||
2414 | { | - | ||||||||||||||||||
2415 | QGraphicsViewPrivate * const d = d_func(); | - | ||||||||||||||||||
2416 | - | |||||||||||||||||||
2417 | if (d->dragMode == QGraphicsView::ScrollHandDrag) { | - | ||||||||||||||||||
2418 | if (d->handScrolling) { | - | ||||||||||||||||||
2419 | QScrollBar *hBar = horizontalScrollBar(); | - | ||||||||||||||||||
2420 | QScrollBar *vBar = verticalScrollBar(); | - | ||||||||||||||||||
2421 | QPoint delta = event->pos() - d->lastMouseEvent.pos(); | - | ||||||||||||||||||
2422 | hBar->setValue(hBar->value() + (isRightToLeft() ? delta.x() : -delta.x())); | - | ||||||||||||||||||
2423 | vBar->setValue(vBar->value() - delta.y()); | - | ||||||||||||||||||
2424 | - | |||||||||||||||||||
2425 | - | |||||||||||||||||||
2426 | - | |||||||||||||||||||
2427 | ++d->handScrollMotions; | - | ||||||||||||||||||
2428 | } | - | ||||||||||||||||||
2429 | } | - | ||||||||||||||||||
2430 | - | |||||||||||||||||||
2431 | d->mouseMoveEventHandler(event); | - | ||||||||||||||||||
2432 | } | - | ||||||||||||||||||
2433 | - | |||||||||||||||||||
2434 | - | |||||||||||||||||||
2435 | - | |||||||||||||||||||
2436 | - | |||||||||||||||||||
2437 | void QGraphicsView::mouseReleaseEvent(QMouseEvent *event) | - | ||||||||||||||||||
2438 | { | - | ||||||||||||||||||
2439 | QGraphicsViewPrivate * const d = d_func(); | - | ||||||||||||||||||
2440 | - | |||||||||||||||||||
2441 | - | |||||||||||||||||||
2442 | if (d->dragMode == QGraphicsView::RubberBandDrag && d->sceneInteractionAllowed && !event->buttons()) { | - | ||||||||||||||||||
2443 | if (d->rubberBanding) { | - | ||||||||||||||||||
2444 | if (d->viewportUpdateMode != QGraphicsView::NoViewportUpdate){ | - | ||||||||||||||||||
2445 | if (d->viewportUpdateMode != FullViewportUpdate) | - | ||||||||||||||||||
2446 | viewport()->update(d->rubberBandRegion(viewport(), d->rubberBandRect)); | - | ||||||||||||||||||
2447 | else | - | ||||||||||||||||||
2448 | d->updateAll(); | - | ||||||||||||||||||
2449 | } | - | ||||||||||||||||||
2450 | d->rubberBanding = false; | - | ||||||||||||||||||
2451 | d->rubberBandSelectionOperation = Qt::ReplaceSelection; | - | ||||||||||||||||||
2452 | if (!d->rubberBandRect.isNull()) { | - | ||||||||||||||||||
2453 | d->rubberBandRect = QRect(); | - | ||||||||||||||||||
2454 | rubberBandChanged(d->rubberBandRect, QPointF(), QPointF()); | - | ||||||||||||||||||
2455 | } | - | ||||||||||||||||||
2456 | } | - | ||||||||||||||||||
2457 | } else | - | ||||||||||||||||||
2458 | - | |||||||||||||||||||
2459 | if (d->dragMode == QGraphicsView::ScrollHandDrag && event->button() == Qt::LeftButton) { | - | ||||||||||||||||||
2460 | - | |||||||||||||||||||
2461 | - | |||||||||||||||||||
2462 | - | |||||||||||||||||||
2463 | - | |||||||||||||||||||
2464 | viewport()->setCursor(Qt::OpenHandCursor); | - | ||||||||||||||||||
2465 | - | |||||||||||||||||||
2466 | d->handScrolling = false; | - | ||||||||||||||||||
2467 | - | |||||||||||||||||||
2468 | if (d->scene && d->sceneInteractionAllowed && !d->lastMouseEvent.isAccepted() && d->handScrollMotions <= 6) { | - | ||||||||||||||||||
2469 | - | |||||||||||||||||||
2470 | - | |||||||||||||||||||
2471 | - | |||||||||||||||||||
2472 | d->scene->clearSelection(); | - | ||||||||||||||||||
2473 | } | - | ||||||||||||||||||
2474 | } | - | ||||||||||||||||||
2475 | - | |||||||||||||||||||
2476 | d->storeMouseEvent(event); | - | ||||||||||||||||||
2477 | - | |||||||||||||||||||
2478 | if (!d->sceneInteractionAllowed) | - | ||||||||||||||||||
2479 | return; | - | ||||||||||||||||||
2480 | - | |||||||||||||||||||
2481 | if (!d->scene) | - | ||||||||||||||||||
2482 | return; | - | ||||||||||||||||||
2483 | - | |||||||||||||||||||
2484 | QGraphicsSceneMouseEvent mouseEvent(QEvent::GraphicsSceneMouseRelease); | - | ||||||||||||||||||
2485 | mouseEvent.setWidget(viewport()); | - | ||||||||||||||||||
2486 | mouseEvent.setButtonDownScenePos(d->mousePressButton, d->mousePressScenePoint); | - | ||||||||||||||||||
2487 | mouseEvent.setButtonDownScreenPos(d->mousePressButton, d->mousePressScreenPoint); | - | ||||||||||||||||||
2488 | mouseEvent.setScenePos(mapToScene(event->pos())); | - | ||||||||||||||||||
2489 | mouseEvent.setScreenPos(event->globalPos()); | - | ||||||||||||||||||
2490 | mouseEvent.setLastScenePos(d->lastMouseMoveScenePoint); | - | ||||||||||||||||||
2491 | mouseEvent.setLastScreenPos(d->lastMouseMoveScreenPoint); | - | ||||||||||||||||||
2492 | mouseEvent.setButtons(event->buttons()); | - | ||||||||||||||||||
2493 | mouseEvent.setButton(event->button()); | - | ||||||||||||||||||
2494 | mouseEvent.setModifiers(event->modifiers()); | - | ||||||||||||||||||
2495 | mouseEvent.setSource(event->source()); | - | ||||||||||||||||||
2496 | mouseEvent.setFlags(event->flags()); | - | ||||||||||||||||||
2497 | mouseEvent.setAccepted(false); | - | ||||||||||||||||||
2498 | if (event->spontaneous()) | - | ||||||||||||||||||
2499 | qt_sendSpontaneousEvent(d->scene, &mouseEvent); | - | ||||||||||||||||||
2500 | else | - | ||||||||||||||||||
2501 | QApplication::sendEvent(d->scene, &mouseEvent); | - | ||||||||||||||||||
2502 | - | |||||||||||||||||||
2503 | - | |||||||||||||||||||
2504 | d->lastMouseEvent.setAccepted(mouseEvent.isAccepted()); | - | ||||||||||||||||||
2505 | - | |||||||||||||||||||
2506 | - | |||||||||||||||||||
2507 | if (mouseEvent.isAccepted() && mouseEvent.buttons() == 0 && viewport()->testAttribute(Qt::WA_SetCursor)) { | - | ||||||||||||||||||
2508 | - | |||||||||||||||||||
2509 | d->_q_unsetViewportCursor(); | - | ||||||||||||||||||
2510 | } | - | ||||||||||||||||||
2511 | - | |||||||||||||||||||
2512 | } | - | ||||||||||||||||||
2513 | - | |||||||||||||||||||
2514 | - | |||||||||||||||||||
2515 | - | |||||||||||||||||||
2516 | - | |||||||||||||||||||
2517 | - | |||||||||||||||||||
2518 | void QGraphicsView::wheelEvent(QWheelEvent *event) | - | ||||||||||||||||||
2519 | { | - | ||||||||||||||||||
2520 | QGraphicsViewPrivate * const d = d_func(); | - | ||||||||||||||||||
2521 | if (!d->scene || !d->sceneInteractionAllowed) { | - | ||||||||||||||||||
2522 | QAbstractScrollArea::wheelEvent(event); | - | ||||||||||||||||||
2523 | return; | - | ||||||||||||||||||
2524 | } | - | ||||||||||||||||||
2525 | - | |||||||||||||||||||
2526 | event->ignore(); | - | ||||||||||||||||||
2527 | - | |||||||||||||||||||
2528 | QGraphicsSceneWheelEvent wheelEvent(QEvent::GraphicsSceneWheel); | - | ||||||||||||||||||
2529 | wheelEvent.setWidget(viewport()); | - | ||||||||||||||||||
2530 | wheelEvent.setScenePos(mapToScene(event->pos())); | - | ||||||||||||||||||
2531 | wheelEvent.setScreenPos(event->globalPos()); | - | ||||||||||||||||||
2532 | wheelEvent.setButtons(event->buttons()); | - | ||||||||||||||||||
2533 | wheelEvent.setModifiers(event->modifiers()); | - | ||||||||||||||||||
2534 | wheelEvent.setDelta(event->delta()); | - | ||||||||||||||||||
2535 | wheelEvent.setOrientation(event->orientation()); | - | ||||||||||||||||||
2536 | wheelEvent.setAccepted(false); | - | ||||||||||||||||||
2537 | QApplication::sendEvent(d->scene, &wheelEvent); | - | ||||||||||||||||||
2538 | event->setAccepted(wheelEvent.isAccepted()); | - | ||||||||||||||||||
2539 | if (!event->isAccepted()) | - | ||||||||||||||||||
2540 | QAbstractScrollArea::wheelEvent(event); | - | ||||||||||||||||||
2541 | } | - | ||||||||||||||||||
2542 | - | |||||||||||||||||||
2543 | - | |||||||||||||||||||
2544 | - | |||||||||||||||||||
2545 | - | |||||||||||||||||||
2546 | - | |||||||||||||||||||
2547 | void QGraphicsView::paintEvent(QPaintEvent *event) | - | ||||||||||||||||||
2548 | { | - | ||||||||||||||||||
2549 | QGraphicsViewPrivate * const d = d_func(); | - | ||||||||||||||||||
2550 | if (!d->scene) { | - | ||||||||||||||||||
2551 | QAbstractScrollArea::paintEvent(event); | - | ||||||||||||||||||
2552 | return; | - | ||||||||||||||||||
2553 | } | - | ||||||||||||||||||
2554 | - | |||||||||||||||||||
2555 | - | |||||||||||||||||||
2556 | d->scene->d_func()->painterStateProtection = !(d->optimizationFlags & DontSavePainterState); | - | ||||||||||||||||||
2557 | - | |||||||||||||||||||
2558 | - | |||||||||||||||||||
2559 | d->exposedRegion = event->region(); | - | ||||||||||||||||||
2560 | QRectF exposedSceneRect = mapToScene(d->exposedRegion.boundingRect()).boundingRect(); | - | ||||||||||||||||||
2561 | - | |||||||||||||||||||
2562 | - | |||||||||||||||||||
2563 | QPainter painter(viewport()); | - | ||||||||||||||||||
2564 | - | |||||||||||||||||||
2565 | if (d->rubberBanding && !d->rubberBandRect.isEmpty()) | - | ||||||||||||||||||
2566 | painter.save(); | - | ||||||||||||||||||
2567 | - | |||||||||||||||||||
2568 | - | |||||||||||||||||||
2569 | painter.setRenderHints(painter.renderHints(), false); | - | ||||||||||||||||||
2570 | painter.setRenderHints(d->renderHints, true); | - | ||||||||||||||||||
2571 | - | |||||||||||||||||||
2572 | - | |||||||||||||||||||
2573 | const bool viewTransformed = isTransformed(); | - | ||||||||||||||||||
2574 | if (viewTransformed) | - | ||||||||||||||||||
2575 | painter.setWorldTransform(viewportTransform()); | - | ||||||||||||||||||
2576 | const QTransform viewTransform = painter.worldTransform(); | - | ||||||||||||||||||
2577 | - | |||||||||||||||||||
2578 | - | |||||||||||||||||||
2579 | if ((d->cacheMode & CacheBackground) | - | ||||||||||||||||||
2580 | - | |||||||||||||||||||
2581 | - | |||||||||||||||||||
2582 | - | |||||||||||||||||||
2583 | ) { | - | ||||||||||||||||||
2584 | - | |||||||||||||||||||
2585 | - | |||||||||||||||||||
2586 | if (d->mustResizeBackgroundPixmap) { | - | ||||||||||||||||||
2587 | d->backgroundPixmap = QPixmap(viewport()->size()); | - | ||||||||||||||||||
2588 | QBrush bgBrush = viewport()->palette().brush(viewport()->backgroundRole()); | - | ||||||||||||||||||
2589 | if (!bgBrush.isOpaque()) | - | ||||||||||||||||||
2590 | d->backgroundPixmap.fill(Qt::transparent); | - | ||||||||||||||||||
2591 | QPainter p(&d->backgroundPixmap); | - | ||||||||||||||||||
2592 | p.fillRect(0, 0, d->backgroundPixmap.width(), d->backgroundPixmap.height(), bgBrush); | - | ||||||||||||||||||
2593 | d->backgroundPixmapExposed = QRegion(viewport()->rect()); | - | ||||||||||||||||||
2594 | d->mustResizeBackgroundPixmap = false; | - | ||||||||||||||||||
2595 | } | - | ||||||||||||||||||
2596 | - | |||||||||||||||||||
2597 | - | |||||||||||||||||||
2598 | if (!d->backgroundPixmapExposed.isEmpty()) { | - | ||||||||||||||||||
2599 | QPainter backgroundPainter(&d->backgroundPixmap); | - | ||||||||||||||||||
2600 | backgroundPainter.setClipRegion(d->backgroundPixmapExposed, Qt::ReplaceClip); | - | ||||||||||||||||||
2601 | if (viewTransformed) | - | ||||||||||||||||||
2602 | backgroundPainter.setTransform(viewTransform); | - | ||||||||||||||||||
2603 | QRectF backgroundExposedSceneRect = mapToScene(d->backgroundPixmapExposed.boundingRect()).boundingRect(); | - | ||||||||||||||||||
2604 | drawBackground(&backgroundPainter, backgroundExposedSceneRect); | - | ||||||||||||||||||
2605 | d->backgroundPixmapExposed = QRegion(); | - | ||||||||||||||||||
2606 | } | - | ||||||||||||||||||
2607 | - | |||||||||||||||||||
2608 | - | |||||||||||||||||||
2609 | if (viewTransformed) { | - | ||||||||||||||||||
2610 | painter.setWorldTransform(QTransform()); | - | ||||||||||||||||||
2611 | painter.drawPixmap(QPoint(), d->backgroundPixmap); | - | ||||||||||||||||||
2612 | painter.setWorldTransform(viewTransform); | - | ||||||||||||||||||
2613 | } else { | - | ||||||||||||||||||
2614 | painter.drawPixmap(QPoint(), d->backgroundPixmap); | - | ||||||||||||||||||
2615 | } | - | ||||||||||||||||||
2616 | } else { | - | ||||||||||||||||||
2617 | if (!(d->optimizationFlags & DontSavePainterState)) | - | ||||||||||||||||||
2618 | painter.save(); | - | ||||||||||||||||||
2619 | drawBackground(&painter, exposedSceneRect); | - | ||||||||||||||||||
2620 | if (!(d->optimizationFlags & DontSavePainterState)) | - | ||||||||||||||||||
2621 | painter.restore(); | - | ||||||||||||||||||
2622 | } | - | ||||||||||||||||||
2623 | - | |||||||||||||||||||
2624 | - | |||||||||||||||||||
2625 | if (!(d->optimizationFlags & IndirectPainting)) { | - | ||||||||||||||||||
2626 | const quint32 oldRectAdjust = d->scene->d_func()->rectAdjust; | - | ||||||||||||||||||
2627 | if (d->optimizationFlags & QGraphicsView::DontAdjustForAntialiasing) | - | ||||||||||||||||||
2628 | d->scene->d_func()->rectAdjust = 1; | - | ||||||||||||||||||
2629 | else | - | ||||||||||||||||||
2630 | d->scene->d_func()->rectAdjust = 2; | - | ||||||||||||||||||
2631 | d->scene->d_func()->drawItems(&painter, viewTransformed ? &viewTransform : 0, | - | ||||||||||||||||||
2632 | &d->exposedRegion, viewport()); | - | ||||||||||||||||||
2633 | d->scene->d_func()->rectAdjust = oldRectAdjust; | - | ||||||||||||||||||
2634 | - | |||||||||||||||||||
2635 | - | |||||||||||||||||||
2636 | - | |||||||||||||||||||
2637 | - | |||||||||||||||||||
2638 | - | |||||||||||||||||||
2639 | - | |||||||||||||||||||
2640 | if (!d->scene->d_func()->painterStateProtection) | - | ||||||||||||||||||
2641 | painter.setOpacity(1.0); | - | ||||||||||||||||||
2642 | painter.setWorldTransform(viewTransform); | - | ||||||||||||||||||
2643 | } else { | - | ||||||||||||||||||
2644 | - | |||||||||||||||||||
2645 | if (!d->scene->d_func()->unpolishedItems.isEmpty()) | - | ||||||||||||||||||
2646 | d->scene->d_func()->_q_polishItems(); | - | ||||||||||||||||||
2647 | - | |||||||||||||||||||
2648 | - | |||||||||||||||||||
2649 | d->scene->d_func()->updateAll = false; | - | ||||||||||||||||||
2650 | - | |||||||||||||||||||
2651 | - | |||||||||||||||||||
2652 | bool allItems = false; | - | ||||||||||||||||||
2653 | QList<QGraphicsItem *> itemList = d->findItems(d->exposedRegion, &allItems, viewTransform); | - | ||||||||||||||||||
2654 | if (!itemList.isEmpty()) { | - | ||||||||||||||||||
2655 | - | |||||||||||||||||||
2656 | const int numItems = itemList.size(); | - | ||||||||||||||||||
2657 | QGraphicsItem **itemArray = &itemList[0]; | - | ||||||||||||||||||
2658 | QStyleOptionGraphicsItem *styleOptionArray = d->allocStyleOptionsArray(numItems); | - | ||||||||||||||||||
2659 | QTransform transform(Qt::Uninitialized); | - | ||||||||||||||||||
2660 | for (int i = 0; i < numItems; ++i) { | - | ||||||||||||||||||
2661 | QGraphicsItem *item = itemArray[i]; | - | ||||||||||||||||||
2662 | QGraphicsItemPrivate *itemd = item->d_ptr.data(); | - | ||||||||||||||||||
2663 | itemd->initStyleOption(&styleOptionArray[i], viewTransform, d->exposedRegion, allItems); | - | ||||||||||||||||||
2664 | - | |||||||||||||||||||
2665 | - | |||||||||||||||||||
2666 | - | |||||||||||||||||||
2667 | - | |||||||||||||||||||
2668 | - | |||||||||||||||||||
2669 | const QRectF brect = adjustedItemEffectiveBoundingRect(item); | - | ||||||||||||||||||
2670 | if (!itemd->itemIsUntransformable()) { | - | ||||||||||||||||||
2671 | transform = item->sceneTransform(); | - | ||||||||||||||||||
2672 | if (viewTransformed) | - | ||||||||||||||||||
2673 | transform *= viewTransform; | - | ||||||||||||||||||
2674 | } else { | - | ||||||||||||||||||
2675 | transform = item->deviceTransform(viewTransform); | - | ||||||||||||||||||
2676 | } | - | ||||||||||||||||||
2677 | itemd->paintedViewBoundingRects.insert(d->viewport, transform.mapRect(brect).toRect()); | - | ||||||||||||||||||
2678 | } | - | ||||||||||||||||||
2679 | - | |||||||||||||||||||
2680 | drawItems(&painter, numItems, itemArray, styleOptionArray); | - | ||||||||||||||||||
2681 | d->freeStyleOptionsArray(styleOptionArray); | - | ||||||||||||||||||
2682 | } | - | ||||||||||||||||||
2683 | } | - | ||||||||||||||||||
2684 | - | |||||||||||||||||||
2685 | - | |||||||||||||||||||
2686 | drawForeground(&painter, exposedSceneRect); | - | ||||||||||||||||||
2687 | - | |||||||||||||||||||
2688 | - | |||||||||||||||||||
2689 | - | |||||||||||||||||||
2690 | if (d->rubberBanding && !d->rubberBandRect.isEmpty()) { | - | ||||||||||||||||||
2691 | painter.restore(); | - | ||||||||||||||||||
2692 | QStyleOptionRubberBand option; | - | ||||||||||||||||||
2693 | option.initFrom(viewport()); | - | ||||||||||||||||||
2694 | option.rect = d->rubberBandRect; | - | ||||||||||||||||||
2695 | option.shape = QRubberBand::Rectangle; | - | ||||||||||||||||||
2696 | - | |||||||||||||||||||
2697 | QStyleHintReturnMask mask; | - | ||||||||||||||||||
2698 | if (viewport()->style()->styleHint(QStyle::SH_RubberBand_Mask, &option, viewport(), &mask)) { | - | ||||||||||||||||||
2699 | - | |||||||||||||||||||
2700 | painter.setClipRegion(mask.region, Qt::IntersectClip); | - | ||||||||||||||||||
2701 | } | - | ||||||||||||||||||
2702 | - | |||||||||||||||||||
2703 | viewport()->style()->drawControl(QStyle::CE_RubberBand, &option, &painter, viewport()); | - | ||||||||||||||||||
2704 | } | - | ||||||||||||||||||
2705 | - | |||||||||||||||||||
2706 | - | |||||||||||||||||||
2707 | painter.end(); | - | ||||||||||||||||||
2708 | - | |||||||||||||||||||
2709 | - | |||||||||||||||||||
2710 | d->scene->d_func()->painterStateProtection = true; | - | ||||||||||||||||||
2711 | } | - | ||||||||||||||||||
2712 | - | |||||||||||||||||||
2713 | - | |||||||||||||||||||
2714 | - | |||||||||||||||||||
2715 | - | |||||||||||||||||||
2716 | void QGraphicsView::resizeEvent(QResizeEvent *event) | - | ||||||||||||||||||
2717 | { | - | ||||||||||||||||||
2718 | QGraphicsViewPrivate * const d = d_func(); | - | ||||||||||||||||||
2719 | - | |||||||||||||||||||
2720 | - | |||||||||||||||||||
2721 | QPointF oldLastCenterPoint = d->lastCenterPoint; | - | ||||||||||||||||||
2722 | - | |||||||||||||||||||
2723 | QAbstractScrollArea::resizeEvent(event); | - | ||||||||||||||||||
2724 | d->recalculateContentSize(); | - | ||||||||||||||||||
2725 | - | |||||||||||||||||||
2726 | - | |||||||||||||||||||
2727 | if (d->resizeAnchor == NoAnchor && !d->keepLastCenterPoint) { | - | ||||||||||||||||||
2728 | d->updateLastCenterPoint(); | - | ||||||||||||||||||
2729 | } else { | - | ||||||||||||||||||
2730 | d->lastCenterPoint = oldLastCenterPoint; | - | ||||||||||||||||||
2731 | } | - | ||||||||||||||||||
2732 | d->centerView(d->resizeAnchor); | - | ||||||||||||||||||
2733 | d->keepLastCenterPoint = false; | - | ||||||||||||||||||
2734 | - | |||||||||||||||||||
2735 | if (d->cacheMode & CacheBackground) { | - | ||||||||||||||||||
2736 | - | |||||||||||||||||||
2737 | d->mustResizeBackgroundPixmap = true; | - | ||||||||||||||||||
2738 | } | - | ||||||||||||||||||
2739 | } | - | ||||||||||||||||||
2740 | - | |||||||||||||||||||
2741 | - | |||||||||||||||||||
2742 | - | |||||||||||||||||||
2743 | - | |||||||||||||||||||
2744 | void QGraphicsView::scrollContentsBy(int dx, int dy) | - | ||||||||||||||||||
2745 | { | - | ||||||||||||||||||
2746 | QGraphicsViewPrivate * const d = d_func(); | - | ||||||||||||||||||
2747 | d->dirtyScroll = true; | - | ||||||||||||||||||
2748 | if (d->transforming) | - | ||||||||||||||||||
2749 | return; | - | ||||||||||||||||||
2750 | if (isRightToLeft()) | - | ||||||||||||||||||
2751 | dx = -dx; | - | ||||||||||||||||||
2752 | - | |||||||||||||||||||
2753 | if (d->viewportUpdateMode != QGraphicsView::NoViewportUpdate) { | - | ||||||||||||||||||
2754 | if (d->viewportUpdateMode != QGraphicsView::FullViewportUpdate) { | - | ||||||||||||||||||
2755 | if (d->accelerateScrolling) { | - | ||||||||||||||||||
2756 | - | |||||||||||||||||||
2757 | - | |||||||||||||||||||
2758 | if (!d->rubberBandRect.isEmpty()) { | - | ||||||||||||||||||
2759 | QRegion rubberBandRegion(d->rubberBandRegion(viewport(), d->rubberBandRect)); | - | ||||||||||||||||||
2760 | rubberBandRegion += rubberBandRegion.translated(-dx, -dy); | - | ||||||||||||||||||
2761 | viewport()->update(rubberBandRegion); | - | ||||||||||||||||||
2762 | } | - | ||||||||||||||||||
2763 | - | |||||||||||||||||||
2764 | d->dirtyScrollOffset.rx() += dx; | - | ||||||||||||||||||
2765 | d->dirtyScrollOffset.ry() += dy; | - | ||||||||||||||||||
2766 | d->dirtyRegion.translate(dx, dy); | - | ||||||||||||||||||
2767 | viewport()->scroll(dx, dy); | - | ||||||||||||||||||
2768 | } else { | - | ||||||||||||||||||
2769 | d->updateAll(); | - | ||||||||||||||||||
2770 | } | - | ||||||||||||||||||
2771 | } else { | - | ||||||||||||||||||
2772 | d->updateAll(); | - | ||||||||||||||||||
2773 | } | - | ||||||||||||||||||
2774 | } | - | ||||||||||||||||||
2775 | - | |||||||||||||||||||
2776 | d->updateLastCenterPoint(); | - | ||||||||||||||||||
2777 | - | |||||||||||||||||||
2778 | if ((d->cacheMode & CacheBackground) | - | ||||||||||||||||||
2779 | - | |||||||||||||||||||
2780 | - | |||||||||||||||||||
2781 | - | |||||||||||||||||||
2782 | ) { | - | ||||||||||||||||||
2783 | - | |||||||||||||||||||
2784 | QRegion exposed; | - | ||||||||||||||||||
2785 | if (!d->backgroundPixmap.isNull()) | - | ||||||||||||||||||
2786 | d->backgroundPixmap.scroll(dx, dy, d->backgroundPixmap.rect(), &exposed); | - | ||||||||||||||||||
2787 | - | |||||||||||||||||||
2788 | - | |||||||||||||||||||
2789 | d->backgroundPixmapExposed.translate(dx, dy); | - | ||||||||||||||||||
2790 | d->backgroundPixmapExposed += exposed; | - | ||||||||||||||||||
2791 | } | - | ||||||||||||||||||
2792 | - | |||||||||||||||||||
2793 | - | |||||||||||||||||||
2794 | if (d->sceneInteractionAllowed) | - | ||||||||||||||||||
2795 | d->replayLastMouseEvent(); | - | ||||||||||||||||||
2796 | } | - | ||||||||||||||||||
2797 | - | |||||||||||||||||||
2798 | - | |||||||||||||||||||
2799 | - | |||||||||||||||||||
2800 | - | |||||||||||||||||||
2801 | void QGraphicsView::showEvent(QShowEvent *event) | - | ||||||||||||||||||
2802 | { | - | ||||||||||||||||||
2803 | QGraphicsViewPrivate * const d = d_func(); | - | ||||||||||||||||||
2804 | d->recalculateContentSize(); | - | ||||||||||||||||||
2805 | d->centerView(d->transformationAnchor); | - | ||||||||||||||||||
2806 | QAbstractScrollArea::showEvent(event); | - | ||||||||||||||||||
2807 | } | - | ||||||||||||||||||
2808 | - | |||||||||||||||||||
2809 | - | |||||||||||||||||||
2810 | - | |||||||||||||||||||
2811 | - | |||||||||||||||||||
2812 | void QGraphicsView::inputMethodEvent(QInputMethodEvent *event) | - | ||||||||||||||||||
2813 | { | - | ||||||||||||||||||
2814 | QGraphicsViewPrivate * const d = d_func(); | - | ||||||||||||||||||
2815 | if (d->scene) | - | ||||||||||||||||||
2816 | QApplication::sendEvent(d->scene, event); | - | ||||||||||||||||||
2817 | } | - | ||||||||||||||||||
2818 | void QGraphicsView::drawBackground(QPainter *painter, const QRectF &rect) | - | ||||||||||||||||||
2819 | { | - | ||||||||||||||||||
2820 | QGraphicsViewPrivate * const d = d_func(); | - | ||||||||||||||||||
2821 | if (d->scene && d->backgroundBrush.style() == Qt::NoBrush) { | - | ||||||||||||||||||
2822 | d->scene->drawBackground(painter, rect); | - | ||||||||||||||||||
2823 | return; | - | ||||||||||||||||||
2824 | } | - | ||||||||||||||||||
2825 | - | |||||||||||||||||||
2826 | painter->fillRect(rect, d->backgroundBrush); | - | ||||||||||||||||||
2827 | } | - | ||||||||||||||||||
2828 | void QGraphicsView::drawForeground(QPainter *painter, const QRectF &rect) | - | ||||||||||||||||||
2829 | { | - | ||||||||||||||||||
2830 | QGraphicsViewPrivate * const d = d_func(); | - | ||||||||||||||||||
2831 | if (d->scene && d->foregroundBrush.style() == Qt::NoBrush) { | - | ||||||||||||||||||
2832 | d->scene->drawForeground(painter, rect); | - | ||||||||||||||||||
2833 | return; | - | ||||||||||||||||||
2834 | } | - | ||||||||||||||||||
2835 | - | |||||||||||||||||||
2836 | painter->fillRect(rect, d->foregroundBrush); | - | ||||||||||||||||||
2837 | } | - | ||||||||||||||||||
2838 | void QGraphicsView::drawItems(QPainter *painter, int numItems, | - | ||||||||||||||||||
2839 | QGraphicsItem *items[], | - | ||||||||||||||||||
2840 | const QStyleOptionGraphicsItem options[]) | - | ||||||||||||||||||
2841 | { | - | ||||||||||||||||||
2842 | QGraphicsViewPrivate * const d = d_func(); | - | ||||||||||||||||||
2843 | if (d->scene) { | - | ||||||||||||||||||
2844 | QWidget *widget = painter->device() == viewport() ? viewport() : 0; | - | ||||||||||||||||||
2845 | d->scene->drawItems(painter, numItems, items, options, widget); | - | ||||||||||||||||||
2846 | } | - | ||||||||||||||||||
2847 | } | - | ||||||||||||||||||
2848 | - | |||||||||||||||||||
2849 | - | |||||||||||||||||||
2850 | - | |||||||||||||||||||
2851 | - | |||||||||||||||||||
2852 | - | |||||||||||||||||||
2853 | - | |||||||||||||||||||
2854 | - | |||||||||||||||||||
2855 | QTransform QGraphicsView::transform() const | - | ||||||||||||||||||
2856 | { | - | ||||||||||||||||||
2857 | const QGraphicsViewPrivate * const d = d_func(); | - | ||||||||||||||||||
2858 | return d->matrix; | - | ||||||||||||||||||
2859 | } | - | ||||||||||||||||||
2860 | - | |||||||||||||||||||
2861 | - | |||||||||||||||||||
2862 | - | |||||||||||||||||||
2863 | - | |||||||||||||||||||
2864 | - | |||||||||||||||||||
2865 | - | |||||||||||||||||||
2866 | QTransform QGraphicsView::viewportTransform() const | - | ||||||||||||||||||
2867 | { | - | ||||||||||||||||||
2868 | const QGraphicsViewPrivate * const d = d_func(); | - | ||||||||||||||||||
2869 | QTransform moveMatrix = QTransform::fromTranslate(-d->horizontalScroll(), -d->verticalScroll()); | - | ||||||||||||||||||
2870 | return d->identityMatrix ? moveMatrix : d->matrix * moveMatrix; | - | ||||||||||||||||||
2871 | } | - | ||||||||||||||||||
2872 | bool QGraphicsView::isTransformed() const | - | ||||||||||||||||||
2873 | { | - | ||||||||||||||||||
2874 | const QGraphicsViewPrivate * const d = d_func(); | - | ||||||||||||||||||
2875 | return !d->identityMatrix || d->horizontalScroll() || d->verticalScroll(); | - | ||||||||||||||||||
2876 | } | - | ||||||||||||||||||
2877 | void QGraphicsView::setTransform(const QTransform &matrix, bool combine ) | - | ||||||||||||||||||
2878 | { | - | ||||||||||||||||||
2879 | QGraphicsViewPrivate * const d = d_func(); | - | ||||||||||||||||||
2880 | QTransform oldMatrix = d->matrix; | - | ||||||||||||||||||
2881 | if (!combine) | - | ||||||||||||||||||
2882 | d->matrix = matrix; | - | ||||||||||||||||||
2883 | else | - | ||||||||||||||||||
2884 | d->matrix = matrix * d->matrix; | - | ||||||||||||||||||
2885 | if (oldMatrix == d->matrix) | - | ||||||||||||||||||
2886 | return; | - | ||||||||||||||||||
2887 | - | |||||||||||||||||||
2888 | d->identityMatrix = d->matrix.isIdentity(); | - | ||||||||||||||||||
2889 | d->transforming = true; | - | ||||||||||||||||||
2890 | if (d->scene) { | - | ||||||||||||||||||
2891 | d->recalculateContentSize(); | - | ||||||||||||||||||
2892 | d->centerView(d->transformationAnchor); | - | ||||||||||||||||||
2893 | } else { | - | ||||||||||||||||||
2894 | d->updateLastCenterPoint(); | - | ||||||||||||||||||
2895 | } | - | ||||||||||||||||||
2896 | - | |||||||||||||||||||
2897 | if (d->sceneInteractionAllowed) | - | ||||||||||||||||||
2898 | d->replayLastMouseEvent(); | - | ||||||||||||||||||
2899 | d->transforming = false; | - | ||||||||||||||||||
2900 | - | |||||||||||||||||||
2901 | - | |||||||||||||||||||
2902 | d->updateAll(); | - | ||||||||||||||||||
2903 | } | - | ||||||||||||||||||
2904 | - | |||||||||||||||||||
2905 | - | |||||||||||||||||||
2906 | - | |||||||||||||||||||
2907 | - | |||||||||||||||||||
2908 | - | |||||||||||||||||||
2909 | - | |||||||||||||||||||
2910 | void QGraphicsView::resetTransform() | - | ||||||||||||||||||
2911 | { | - | ||||||||||||||||||
2912 | setTransform(QTransform()); | - | ||||||||||||||||||
2913 | } | - | ||||||||||||||||||
2914 | - | |||||||||||||||||||
2915 | QPointF QGraphicsViewPrivate::mapToScene(const QPointF &point) const | - | ||||||||||||||||||
2916 | { | - | ||||||||||||||||||
2917 | QPointF p = point; | - | ||||||||||||||||||
2918 | p.rx() += horizontalScroll(); | - | ||||||||||||||||||
2919 | p.ry() += verticalScroll(); | - | ||||||||||||||||||
2920 | return identityMatrix ? p : matrix.inverted().map(p); | - | ||||||||||||||||||
2921 | } | - | ||||||||||||||||||
2922 | - | |||||||||||||||||||
2923 | QRectF QGraphicsViewPrivate::mapToScene(const QRectF &rect) const | - | ||||||||||||||||||
2924 | { | - | ||||||||||||||||||
2925 | QPointF scrollOffset(horizontalScroll(), verticalScroll()); | - | ||||||||||||||||||
2926 | QPointF tl = scrollOffset + rect.topLeft(); | - | ||||||||||||||||||
2927 | QPointF tr = scrollOffset + rect.topRight(); | - | ||||||||||||||||||
2928 | QPointF br = scrollOffset + rect.bottomRight(); | - | ||||||||||||||||||
2929 | QPointF bl = scrollOffset + rect.bottomLeft(); | - | ||||||||||||||||||
2930 | - | |||||||||||||||||||
2931 | QPolygonF poly(4); | - | ||||||||||||||||||
2932 | if (!identityMatrix) { | - | ||||||||||||||||||
2933 | QTransform x = matrix.inverted(); | - | ||||||||||||||||||
2934 | poly[0] = x.map(tl); | - | ||||||||||||||||||
2935 | poly[1] = x.map(tr); | - | ||||||||||||||||||
2936 | poly[2] = x.map(br); | - | ||||||||||||||||||
2937 | poly[3] = x.map(bl); | - | ||||||||||||||||||
2938 | } else { | - | ||||||||||||||||||
2939 | poly[0] = tl; | - | ||||||||||||||||||
2940 | poly[1] = tr; | - | ||||||||||||||||||
2941 | poly[2] = br; | - | ||||||||||||||||||
2942 | poly[3] = bl; | - | ||||||||||||||||||
2943 | } | - | ||||||||||||||||||
2944 | return poly.boundingRect(); | - | ||||||||||||||||||
2945 | } | - | ||||||||||||||||||
2946 | - | |||||||||||||||||||
2947 | - | |||||||||||||||||||
2948 | - | |||||||||||||||||||
Switch to Source code | Preprocessed file |