qgraphicsview.cpp

Absolute File Name:/home/qt/qt5_coco/qt5/qtbase/src/widgets/graphicsview/qgraphicsview.cpp
Source codeSwitch to Preprocessed file
LineSourceCount
1/****************************************************************************-
2**-
3** Copyright (C) 2016 The Qt Company Ltd.-
4** Contact: https://www.qt.io/licensing/-
5**-
6** This file is part of the QtWidgets module of the Qt Toolkit.-
7**-
8** $QT_BEGIN_LICENSE:LGPL$-
9** Commercial License Usage-
10** Licensees holding valid commercial Qt licenses may use this file in-
11** accordance with the commercial license agreement provided with the-
12** Software or, alternatively, in accordance with the terms contained in-
13** a written agreement between you and The Qt Company. For licensing terms-
14** and conditions see https://www.qt.io/terms-conditions. For further-
15** information use the contact form at https://www.qt.io/contact-us.-
16**-
17** GNU Lesser General Public License Usage-
18** Alternatively, this file may be used under the terms of the GNU Lesser-
19** General Public License version 3 as published by the Free Software-
20** Foundation and appearing in the file LICENSE.LGPL3 included in the-
21** packaging of this file. Please review the following information to-
22** ensure the GNU Lesser General Public License version 3 requirements-
23** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.-
24**-
25** GNU General Public License Usage-
26** Alternatively, this file may be used under the terms of the GNU-
27** General Public License version 2.0 or (at your option) the GNU General-
28** Public license version 3 or any later version approved by the KDE Free-
29** Qt Foundation. The licenses are as published by the Free Software-
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3-
31** included in the packaging of this file. Please review the following-
32** information to ensure the GNU General Public License requirements will-
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and-
34** https://www.gnu.org/licenses/gpl-3.0.html.-
35**-
36** $QT_END_LICENSE$-
37**-
38****************************************************************************/-
39-
40static const int QGRAPHICSVIEW_REGION_RECT_THRESHOLD = 50;-
41-
42static const int QGRAPHICSVIEW_PREALLOC_STYLE_OPTIONS = 503; // largest prime < 2^9-
43-
44/*!-
45 \class QGraphicsView-
46 \brief The QGraphicsView class provides a widget for displaying the-
47 contents of a QGraphicsScene.-
48 \since 4.2-
49 \ingroup graphicsview-api-
50 \inmodule QtWidgets-
51-
52 QGraphicsView visualizes the contents of a QGraphicsScene in a scrollable-
53 viewport. To create a scene with geometrical items, see QGraphicsScene's-
54 documentation. QGraphicsView is part of the \l{Graphics View Framework}.-
55-
56 To visualize a scene, you start by constructing a QGraphicsView object,-
57 passing the address of the scene you want to visualize to QGraphicsView's-
58 constructor. Alternatively, you can call setScene() to set the scene at a-
59 later point. After you call show(), the view will by default scroll to the-
60 center of the scene and display any items that are visible at this-
61 point. For example:-
62-
63 \snippet code/src_gui_graphicsview_qgraphicsview.cpp 0-
64-
65 You can explicitly scroll to any position on the scene by using the-
66 scroll bars, or by calling centerOn(). By passing a point to centerOn(),-
67 QGraphicsView will scroll its viewport to ensure that the point is-
68 centered in the view. An overload is provided for scrolling to a-
69 QGraphicsItem, in which case QGraphicsView will see to that the center of-
70 the item is centered in the view. If all you want is to ensure that a-
71 certain area is visible, (but not necessarily centered,) you can call-
72 ensureVisible() instead.-
73-
74 QGraphicsView can be used to visualize a whole scene, or only parts of it.-
75 The visualized area is by default detected automatically when the view is-
76 displayed for the first time (by calling-
77 QGraphicsScene::itemsBoundingRect()). To set the visualized area rectangle-
78 yourself, you can call setSceneRect(). This will adjust the scroll bars'-
79 ranges appropriately. Note that although the scene supports a virtually-
80 unlimited size, the range of the scroll bars will never exceed the range of-
81 an integer (INT_MIN, INT_MAX).-
82-
83 QGraphicsView visualizes the scene by calling render(). By default, the-
84 items are drawn onto the viewport by using a regular QPainter, and using-
85 default render hints. To change the default render hints that-
86 QGraphicsView passes to QPainter when painting items, you can call-
87 setRenderHints().-
88-
89 By default, QGraphicsView provides a regular QWidget for the viewport-
90 widget. You can access this widget by calling viewport(), or you can-
91 replace it by calling setViewport(). To render using OpenGL, simply call-
92 setViewport(new QGLWidget). QGraphicsView takes ownership of the viewport-
93 widget.-
94-
95 QGraphicsView supports affine transformations, using QTransform. You can-
96 either pass a matrix to setTransform(), or you can call one of the-
97 convenience functions rotate(), scale(), translate() or shear(). The most-
98 two common transformations are scaling, which is used to implement-
99 zooming, and rotation. QGraphicsView keeps the center of the view fixed-
100 during a transformation. Because of the scene alignment (setAligment()),-
101 translating the view will have no visual impact.-
102-
103 You can interact with the items on the scene by using the mouse and-
104 keyboard. QGraphicsView translates the mouse and key events into \e scene-
105 events, (events that inherit QGraphicsSceneEvent,), and forward them to-
106 the visualized scene. In the end, it's the individual item that handles-
107 the events and reacts to them. For example, if you click on a selectable-
108 item, the item will typically let the scene know that it has been-
109 selected, and it will also redraw itself to display a selection-
110 rectangle. Similiary, if you click and drag the mouse to move a movable-
111 item, it's the item that handles the mouse moves and moves itself. Item-
112 interaction is enabled by default, and you can toggle it by calling-
113 setInteractive().-
114-
115 You can also provide your own custom scene interaction, by creating a-
116 subclass of QGraphicsView, and reimplementing the mouse and key event-
117 handlers. To simplify how you programmatically interact with items in the-
118 view, QGraphicsView provides the mapping functions mapToScene() and-
119 mapFromScene(), and the item accessors items() and itemAt(). These-
120 functions allow you to map points, rectangles, polygons and paths between-
121 view coordinates and scene coordinates, and to find items on the scene-
122 using view coordinates.-
123-
124 \image graphicsview-view.png-
125-
126 \sa QGraphicsScene, QGraphicsItem, QGraphicsSceneEvent-
127*/-
128-
129/*!-
130 \enum QGraphicsView::ViewportAnchor-
131-
132 This enums describe the possible anchors that QGraphicsView can-
133 use when the user resizes the view or when the view is-
134 transformed.-
135-
136 \value NoAnchor No anchor, i.e. the view leaves the scene's-
137 position unchanged.-
138 \value AnchorViewCenter The scene point at the center of the view-
139 is used as the anchor.-
140 \value AnchorUnderMouse The point under the mouse is used as the anchor.-
141-
142 \sa resizeAnchor, transformationAnchor-
143*/-
144-
145/*!-
146 \enum QGraphicsView::ViewportUpdateMode-
147-
148 \since 4.3-
149-
150 This enum describes how QGraphicsView updates its viewport when the scene-
151 contents change or are exposed.-
152-
153 \value FullViewportUpdate When any visible part of the scene changes or is-
154 reexposed, QGraphicsView will update the entire viewport. This approach is-
155 fastest when QGraphicsView spends more time figuring out what to draw than-
156 it would spend drawing (e.g., when very many small items are repeatedly-
157 updated). This is the preferred update mode for viewports that do not-
158 support partial updates, such as QGLWidget, and for viewports that need to-
159 disable scroll optimization.-
160-
161 \value MinimalViewportUpdate QGraphicsView will determine the minimal-
162 viewport region that requires a redraw, minimizing the time spent drawing-
163 by avoiding a redraw of areas that have not changed. This is-
164 QGraphicsView's default mode. Although this approach provides the best-
165 performance in general, if there are many small visible changes on the-
166 scene, QGraphicsView might end up spending more time finding the minimal-
167 approach than it will spend drawing.-
168-
169 \value SmartViewportUpdate QGraphicsView will attempt to find an optimal-
170 update mode by analyzing the areas that require a redraw.-
171-
172 \value BoundingRectViewportUpdate The bounding rectangle of all changes in-
173 the viewport will be redrawn. This mode has the advantage that-
174 QGraphicsView searches only one region for changes, minimizing time spent-
175 determining what needs redrawing. The disadvantage is that areas that have-
176 not changed also need to be redrawn.-
177-
178 \value NoViewportUpdate QGraphicsView will never update its viewport when-
179 the scene changes; the user is expected to control all updates. This mode-
180 disables all (potentially slow) item visibility testing in QGraphicsView,-
181 and is suitable for scenes that either require a fixed frame rate, or where-
182 the viewport is otherwise updated externally.-
183-
184 \sa viewportUpdateMode-
185*/-
186-
187/*!-
188 \enum QGraphicsView::OptimizationFlag-
189-
190 \since 4.3-
191-
192 This enum describes flags that you can enable to improve rendering-
193 performance in QGraphicsView. By default, none of these flags are set.-
194 Note that setting a flag usually imposes a side effect, and this effect-
195 can vary between paint devices and platforms.-
196-
197 \value DontClipPainter This value is obsolete and has no effect.-
198-
199 \value DontSavePainterState When rendering, QGraphicsView protects the-
200 painter state (see QPainter::save()) when rendering the background or-
201 foreground, and when rendering each item. This allows you to leave the-
202 painter in an altered state (i.e., you can call QPainter::setPen() or-
203 QPainter::setBrush() without restoring the state after painting). However,-
204 if the items consistently do restore the state, you should enable this-
205 flag to prevent QGraphicsView from doing the same.-
206-
207 \value DontAdjustForAntialiasing Disables QGraphicsView's antialiasing-
208 auto-adjustment of exposed areas. Items that render antialiased lines on-
209 the boundaries of their QGraphicsItem::boundingRect() can end up rendering-
210 parts of the line outside. To prevent rendering artifacts, QGraphicsView-
211 expands all exposed regions by 2 pixels in all directions. If you enable-
212 this flag, QGraphicsView will no longer perform these adjustments,-
213 minimizing the areas that require redrawing, which improves performance. A-
214 common side effect is that items that do draw with antialiasing can leave-
215 painting traces behind on the scene as they are moved.-
216-
217 \value IndirectPainting Since Qt 4.6, restore the old painting algorithm-
218 that calls QGraphicsView::drawItems() and QGraphicsScene::drawItems().-
219 To be used only for compatibility with old code.-
220*/-
221-
222/*!-
223 \enum QGraphicsView::CacheModeFlag-
224-
225 This enum describes the flags that you can set for a QGraphicsView's cache-
226 mode.-
227-
228 \value CacheNone All painting is done directly onto the viewport.-
229-
230 \value CacheBackground The background is cached. This affects both custom-
231 backgrounds, and backgrounds based on the backgroundBrush property. When-
232 this flag is enabled, QGraphicsView will allocate one pixmap with the full-
233 size of the viewport.-
234-
235 \sa cacheMode-
236*/-
237-
238/*!-
239 \enum QGraphicsView::DragMode-
240-
241 This enum describes the default action for the view when pressing and-
242 dragging the mouse over the viewport.-
243-
244 \value NoDrag Nothing happens; the mouse event is ignored.-
245-
246 \value ScrollHandDrag The cursor changes into a pointing hand, and-
247 dragging the mouse around will scroll the scrolbars. This mode works both-
248 in \l{QGraphicsView::interactive}{interactive} and non-interactive mode.-
249-
250 \value RubberBandDrag A rubber band will appear. Dragging the mouse will-
251 set the rubber band geometry, and all items covered by the rubber band are-
252 selected. This mode is disabled for non-interactive views.-
253-
254 \sa dragMode, QGraphicsScene::setSelectionArea()-
255*/-
256-
257/*!-
258 \since 5.1-
259-
260 \fn void QGraphicsView::rubberBandChanged(QRect rubberBandRect, QPointF fromScenePoint, QPointF toScenePoint)-
261-
262 This signal is emitted when the rubber band rect is changed. The viewport Rect is specified by \a rubberBandRect.-
263 The drag start position and drag end position are provided in scene points with \a fromScenePoint and \a toScenePoint.-
264-
265 When rubberband selection ends this signal will be emitted with null vales.-
266-
267 \sa rubberBandRect()-
268*/-
269-
270-
271#include "qgraphicsview.h"-
272#include "qgraphicsview_p.h"-
273-
274#ifndef QT_NO_GRAPHICSVIEW-
275-
276#include "qgraphicsitem.h"-
277#include "qgraphicsitem_p.h"-
278#include "qgraphicsscene.h"-
279#include "qgraphicsscene_p.h"-
280#include "qgraphicssceneevent.h"-
281#include "qgraphicswidget.h"-
282-
283#include <QtCore/qdatetime.h>-
284#include <QtCore/qdebug.h>-
285#include <QtCore/qmath.h>-
286#include <QtCore/qscopedvaluerollback.h>-
287#include <QtWidgets/qapplication.h>-
288#include <QtWidgets/qdesktopwidget.h>-
289#include <QtGui/qevent.h>-
290#include <QtWidgets/qlayout.h>-
291#include <QtGui/qtransform.h>-
292#include <QtGui/qmatrix.h>-
293#include <QtGui/qpainter.h>-
294#include <QtWidgets/qscrollbar.h>-
295#include <QtWidgets/qstyleoption.h>-
296-
297#include <private/qevent_p.h>-
298-
299QT_BEGIN_NAMESPACE-
300-
301bool qt_sendSpontaneousEvent(QObject *receiver, QEvent *event);-
302-
303inline int q_round_bound(qreal d) //### (int)(qreal) INT_MAX != INT_MAX for single precision-
304{-
305 if (d <= (qreal) INT_MIN)-
306 return INT_MIN;-
307 else if (d >= (qreal) INT_MAX)-
308 return INT_MAX;-
309 return d >= 0.0 ? int(d + 0.5) : int(d - int(d-1) + 0.5) + int(d-1);-
310}-
311-
312void QGraphicsViewPrivate::translateTouchEvent(QGraphicsViewPrivate *d, QTouchEvent *touchEvent)-
313{-
314 QList<QTouchEvent::TouchPoint> touchPoints = touchEvent->touchPoints();-
315 for (int i = 0; i < touchPoints.count(); ++i) {-
316 QTouchEvent::TouchPoint &touchPoint = touchPoints[i];-
317 // the scene will set the item local pos, startPos, lastPos, and rect before delivering to-
318 // an item, but for now those functions are returning the view's local coordinates-
319 touchPoint.setSceneRect(d->mapToScene(touchPoint.rect()));-
320 touchPoint.setStartScenePos(d->mapToScene(touchPoint.startPos()));-
321 touchPoint.setLastScenePos(d->mapToScene(touchPoint.lastPos()));-
322-
323 // screenPos, startScreenPos, lastScreenPos, and screenRect are already set-
324 }-
325-
326 touchEvent->setTouchPoints(touchPoints);-
327}-
328-
329/*!-
330 \internal-
331*/-
332QGraphicsViewPrivate::QGraphicsViewPrivate()-
333 : renderHints(QPainter::TextAntialiasing),-
334 dragMode(QGraphicsView::NoDrag),-
335 sceneInteractionAllowed(true), hasSceneRect(false),-
336 connectedToScene(false),-
337 useLastMouseEvent(false),-
338 identityMatrix(true),-
339 dirtyScroll(true),-
340 accelerateScrolling(true),-
341 keepLastCenterPoint(true),-
342 transforming(false),-
343 handScrolling(false),-
344 mustAllocateStyleOptions(false),-
345 mustResizeBackgroundPixmap(true),-
346 fullUpdatePending(true),-
347 hasUpdateClip(false),-
348 mousePressButton(Qt::NoButton),-
349 leftIndent(0), topIndent(0),-
350 lastMouseEvent(QEvent::None, QPointF(), QPointF(), QPointF(), Qt::NoButton, 0, 0),-
351 alignment(Qt::AlignCenter),-
352 transformationAnchor(QGraphicsView::AnchorViewCenter), resizeAnchor(QGraphicsView::NoAnchor),-
353 viewportUpdateMode(QGraphicsView::MinimalViewportUpdate),-
354 optimizationFlags(0),-
355 scene(0),-
356#ifndef QT_NO_RUBBERBAND-
357 rubberBanding(false),-
358 rubberBandSelectionMode(Qt::IntersectsItemShape),-
359 rubberBandSelectionOperation(Qt::ReplaceSelection),-
360#endif-
361 handScrollMotions(0), cacheMode(0),-
362#ifndef QT_NO_CURSOR-
363 hasStoredOriginalCursor(false),-
364#endif-
365 lastDragDropEvent(0),-
366 updateSceneSlotReimplementedChecked(false)-
367{-
368 styleOptions.reserve(QGRAPHICSVIEW_PREALLOC_STYLE_OPTIONS);-
369}-
370-
371QGraphicsViewPrivate::~QGraphicsViewPrivate()-
372{-
373}-
374-
375/*!-
376 \internal-
377*/-
378void QGraphicsViewPrivate::recalculateContentSize()-
379{-
380 Q_Q(QGraphicsView);-
381-
382 QSize maxSize = q->maximumViewportSize();-
383 int width = maxSize.width();-
384 int height = maxSize.height();-
385 QRectF viewRect = matrix.mapRect(q->sceneRect());-
386-
387 bool frameOnlyAround = (q->style()->styleHint(QStyle::SH_ScrollView_FrameOnlyAroundContents, 0, q));-
388 if (frameOnlyAround) {-
389 if (hbarpolicy == Qt::ScrollBarAlwaysOn)-
390 height -= frameWidth * 2;-
391 if (vbarpolicy == Qt::ScrollBarAlwaysOn)-
392 width -= frameWidth * 2;-
393 }-
394-
395 // Adjust the maximum width and height of the viewport based on the width-
396 // of visible scroll bars.-
397 int scrollBarExtent = q->style()->pixelMetric(QStyle::PM_ScrollBarExtent, 0, q);-
398 if (frameOnlyAround)-
399 scrollBarExtent += frameWidth * 2;-
400-
401 // We do not need to subtract the width scrollbars whose policy is-
402 // Qt::ScrollBarAlwaysOn, this was already done by maximumViewportSize().-
403 bool useHorizontalScrollBar = (viewRect.width() > width) && hbarpolicy == Qt::ScrollBarAsNeeded;-
404 bool useVerticalScrollBar = (viewRect.height() > height) && vbarpolicy == Qt::ScrollBarAsNeeded;-
405 if (useHorizontalScrollBar && vbarpolicy == Qt::ScrollBarAsNeeded) {-
406 if (viewRect.height() > height - scrollBarExtent)-
407 useVerticalScrollBar = true;-
408 }-
409 if (useVerticalScrollBar && hbarpolicy == Qt::ScrollBarAsNeeded) {-
410 if (viewRect.width() > width - scrollBarExtent)-
411 useHorizontalScrollBar = true;-
412 }-
413 if (useHorizontalScrollBar)-
414 height -= scrollBarExtent;-
415 if (useVerticalScrollBar)-
416 width -= scrollBarExtent;-
417-
418 // Setting the ranges of these scroll bars can/will cause the values to-
419 // change, and scrollContentsBy() will be called correspondingly. This-
420 // will reset the last center point.-
421 QPointF savedLastCenterPoint = lastCenterPoint;-
422-
423 // Remember the former indent settings-
424 qreal oldLeftIndent = leftIndent;-
425 qreal oldTopIndent = topIndent;-
426-
427 // If the whole scene fits horizontally, we center the scene horizontally,-
428 // and ignore the horizontal scroll bars.-
429 int left = q_round_bound(viewRect.left());-
430 int right = q_round_bound(viewRect.right() - width);-
431 if (left >= right) {-
432 hbar->setRange(0, 0);-
433-
434 switch (alignment & Qt::AlignHorizontal_Mask) {-
435 case Qt::AlignLeft:-
436 leftIndent = -viewRect.left();-
437 break;-
438 case Qt::AlignRight:-
439 leftIndent = width - viewRect.width() - viewRect.left() - 1;-
440 break;-
441 case Qt::AlignHCenter:-
442 default:-
443 leftIndent = width / 2 - (viewRect.left() + viewRect.right()) / 2;-
444 break;-
445 }-
446 } else {-
447 hbar->setRange(left, right);-
448 hbar->setPageStep(width);-
449 hbar->setSingleStep(width / 20);-
450 leftIndent = 0;-
451 }-
452-
453 // If the whole scene fits vertically, we center the scene vertically, and-
454 // ignore the vertical scroll bars.-
455 int top = q_round_bound(viewRect.top());-
456 int bottom = q_round_bound(viewRect.bottom() - height);-
457 if (top >= bottom) {-
458 vbar->setRange(0, 0);-
459-
460 switch (alignment & Qt::AlignVertical_Mask) {-
461 case Qt::AlignTop:-
462 topIndent = -viewRect.top();-
463 break;-
464 case Qt::AlignBottom:-
465 topIndent = height - viewRect.height() - viewRect.top() - 1;-
466 break;-
467 case Qt::AlignVCenter:-
468 default:-
469 topIndent = height / 2 - (viewRect.top() + viewRect.bottom()) / 2;-
470 break;-
471 }-
472 } else {-
473 vbar->setRange(top, bottom);-
474 vbar->setPageStep(height);-
475 vbar->setSingleStep(height / 20);-
476 topIndent = 0;-
477 }-
478-
479 // Restorethe center point from before the ranges changed.-
480 lastCenterPoint = savedLastCenterPoint;-
481-
482 // Issue a full update if the indents change.-
483 // ### If the transform is still the same, we can get away with just a-
484 // scroll instead.-
485 if (oldLeftIndent != leftIndent || oldTopIndent != topIndent) {-
486 dirtyScroll = true;-
487 updateAll();-
488 } else if (q->isRightToLeft() && !leftIndent) {-
489 // In reverse mode, the horizontal scroll always changes after the content-
490 // size has changed, as the scroll is calculated by summing the min and-
491 // max values of the range and subtracting the current value. In normal-
492 // mode the scroll remains unchanged unless the indent has changed.-
493 dirtyScroll = true;-
494 }-
495-
496 if (cacheMode & QGraphicsView::CacheBackground) {-
497 // Invalidate the background pixmap-
498 mustResizeBackgroundPixmap = true;-
499 }-
500}-
501-
502/*!-
503 \internal-
504*/-
505void QGraphicsViewPrivate::centerView(QGraphicsView::ViewportAnchor anchor)-
506{-
507 Q_Q(QGraphicsView);-
508 switch (anchor) {-
509 case QGraphicsView::AnchorUnderMouse: {-
510 if (q->underMouse()) {-
511 // Last scene pos: lastMouseMoveScenePoint-
512 // Current mouse pos:-
513 QPointF transformationDiff = q->mapToScene(viewport->rect().center())-
514 - q->mapToScene(viewport->mapFromGlobal(QCursor::pos()));-
515 q->centerOn(lastMouseMoveScenePoint + transformationDiff);-
516 } else {-
517 q->centerOn(lastCenterPoint);-
518 }-
519 break;-
520 }-
521 case QGraphicsView::AnchorViewCenter:-
522 q->centerOn(lastCenterPoint);-
523 break;-
524 case QGraphicsView::NoAnchor:-
525 break;-
526 }-
527}-
528-
529/*!-
530 \internal-
531*/-
532void QGraphicsViewPrivate::updateLastCenterPoint()-
533{-
534 Q_Q(QGraphicsView);-
535 lastCenterPoint = q->mapToScene(viewport->rect().center());-
536}-
537-
538/*!-
539 \internal-
540-
541 Returns the horizontal scroll value (the X value of the left edge of the-
542 viewport).-
543*/-
544qint64 QGraphicsViewPrivate::horizontalScroll() const-
545{-
546 if (dirtyScroll)-
547 const_cast<QGraphicsViewPrivate *>(this)->updateScroll();-
548 return scrollX;-
549}-
550-
551/*!-
552 \internal-
553-
554 Returns the vertical scroll value (the X value of the top edge of the-
555 viewport).-
556*/-
557qint64 QGraphicsViewPrivate::verticalScroll() const-
558{-
559 if (dirtyScroll)-
560 const_cast<QGraphicsViewPrivate *>(this)->updateScroll();-
561 return scrollY;-
562}-
563-
564/*!-
565 \internal-
566-
567 Maps the given rectangle to the scene using QTransform::mapRect()-
568*/-
569QRectF QGraphicsViewPrivate::mapRectToScene(const QRect &rect) const-
570{-
571 if (dirtyScroll)-
572 const_cast<QGraphicsViewPrivate *>(this)->updateScroll();-
573 QRectF scrolled = QRectF(rect.translated(scrollX, scrollY));-
574 return identityMatrix ? scrolled : matrix.inverted().mapRect(scrolled);-
575}-
576-
577-
578/*!-
579 \internal-
580-
581 Maps the given rectangle from the scene using QTransform::mapRect()-
582*/-
583QRectF QGraphicsViewPrivate::mapRectFromScene(const QRectF &rect) const-
584{-
585 if (dirtyScroll)-
586 const_cast<QGraphicsViewPrivate *>(this)->updateScroll();-
587 return (identityMatrix ? rect : matrix.mapRect(rect)).translated(-scrollX, -scrollY);-
588}-
589-
590/*!-
591 \internal-
592*/-
593void QGraphicsViewPrivate::updateScroll()-
594{-
595 Q_Q(QGraphicsView);-
596 scrollX = qint64(-leftIndent);-
597 if (q->isRightToLeft()) {-
598 if (!leftIndent) {-
599 scrollX += hbar->minimum();-
600 scrollX += hbar->maximum();-
601 scrollX -= hbar->value();-
602 }-
603 } else {-
604 scrollX += hbar->value();-
605 }-
606-
607 scrollY = qint64(vbar->value() - topIndent);-
608-
609 dirtyScroll = false;-
610}-
611-
612/*!-
613 \internal-
614*/-
615void QGraphicsViewPrivate::replayLastMouseEvent()-
616{-
617 if (!useLastMouseEvent || !scene)-
618 return;-
619 mouseMoveEventHandler(&lastMouseEvent);-
620}-
621-
622/*!-
623 \internal-
624*/-
625void QGraphicsViewPrivate::storeMouseEvent(QMouseEvent *event)-
626{-
627 useLastMouseEvent = true;-
628 lastMouseEvent = QMouseEvent(QEvent::MouseMove, event->localPos(), event->windowPos(), event->screenPos(),-
629 event->button(), event->buttons(), event->modifiers());-
630}-
631-
632void QGraphicsViewPrivate::mouseMoveEventHandler(QMouseEvent *event)-
633{-
634 Q_Q(QGraphicsView);-
635-
636#ifndef QT_NO_RUBBERBAND-
637 updateRubberBand(event);-
638#endif-
639-
640 storeMouseEvent(event);-
641 lastMouseEvent.setAccepted(false);-
642-
643 if (!sceneInteractionAllowed)-
644 return;-
645 if (handScrolling)-
646 return;-
647 if (!scene)-
648 return;-
649-
650 QGraphicsSceneMouseEvent mouseEvent(QEvent::GraphicsSceneMouseMove);-
651 mouseEvent.setWidget(viewport);-
652 mouseEvent.setButtonDownScenePos(mousePressButton, mousePressScenePoint);-
653 mouseEvent.setButtonDownScreenPos(mousePressButton, mousePressScreenPoint);-
654 mouseEvent.setScenePos(q->mapToScene(event->pos()));-
655 mouseEvent.setScreenPos(event->globalPos());-
656 mouseEvent.setLastScenePos(lastMouseMoveScenePoint);-
657 mouseEvent.setLastScreenPos(lastMouseMoveScreenPoint);-
658 mouseEvent.setButtons(event->buttons());-
659 mouseEvent.setButton(event->button());-
660 mouseEvent.setModifiers(event->modifiers());-
661 mouseEvent.setSource(event->source());-
662 mouseEvent.setFlags(event->flags());-
663 lastMouseMoveScenePoint = mouseEvent.scenePos();-
664 lastMouseMoveScreenPoint = mouseEvent.screenPos();-
665 mouseEvent.setAccepted(false);-
666 if (event->spontaneous())-
667 qt_sendSpontaneousEvent(scene, &mouseEvent);-
668 else-
669 QApplication::sendEvent(scene, &mouseEvent);-
670-
671 // Remember whether the last event was accepted or not.-
672 lastMouseEvent.setAccepted(mouseEvent.isAccepted());-
673-
674 if (mouseEvent.isAccepted() && mouseEvent.buttons() != 0) {-
675 // The event was delivered to a mouse grabber; the press is likely to-
676 // have set a cursor, and we must not change it.-
677 return;-
678 }-
679-
680#ifndef QT_NO_CURSOR-
681 // If all the items ignore hover events, we don't look-up any items-
682 // in QGraphicsScenePrivate::dispatchHoverEvent, hence the-
683 // cachedItemsUnderMouse list will be empty. We therefore do the look-up-
684 // for cursor items here if not all items use the default cursor.-
685 if (scene->d_func()->allItemsIgnoreHoverEvents && !scene->d_func()->allItemsUseDefaultCursor-
686 && scene->d_func()->cachedItemsUnderMouse.isEmpty()) {-
687 scene->d_func()->cachedItemsUnderMouse = scene->d_func()->itemsAtPosition(mouseEvent.screenPos(),-
688 mouseEvent.scenePos(),-
689 mouseEvent.widget());-
690 }-
691 // Find the topmost item under the mouse with a cursor.-
692 foreach (QGraphicsItem *item, scene->d_func()->cachedItemsUnderMouse) {-
693 if (item->hasCursor()) {-
694 _q_setViewportCursor(item->cursor());-
695 return;-
696 }-
697 }-
698-
699 // No items with cursors found; revert to the view cursor.-
700 if (hasStoredOriginalCursor) {-
701 // Restore the original viewport cursor.-
702 hasStoredOriginalCursor = false;-
703 viewport->setCursor(originalCursor);-
704 }-
705#endif-
706}-
707-
708/*!-
709 \internal-
710*/-
711#ifndef QT_NO_RUBBERBAND-
712QRegion QGraphicsViewPrivate::rubberBandRegion(const QWidget *widget, const QRect &rect) const-
713{-
714 QStyleHintReturnMask mask;-
715 QStyleOptionRubberBand option;-
716 option.initFrom(widget);-
717 option.rect = rect;-
718 option.opaque = false;-
719 option.shape = QRubberBand::Rectangle;-
720-
721 QRegion tmp;-
722 tmp += rect;-
723 if (widget->style()->styleHint(QStyle::SH_RubberBand_Mask, &option, widget, &mask))-
724 tmp &= mask.region;-
725 return tmp;-
726}-
727-
728void QGraphicsViewPrivate::updateRubberBand(const QMouseEvent *event)-
729{-
730 Q_Q(QGraphicsView);-
731 if (dragMode != QGraphicsView::RubberBandDrag || !sceneInteractionAllowed || !rubberBanding)-
732 return;-
733 // Check for enough drag distance-
734 if ((mousePressViewPoint - event->pos()).manhattanLength() < QApplication::startDragDistance())-
735 return;-
736-
737 // Update old rubberband-
738 if (viewportUpdateMode != QGraphicsView::NoViewportUpdate && !rubberBandRect.isEmpty()) {-
739 if (viewportUpdateMode != QGraphicsView::FullViewportUpdate)-
740 q->viewport()->update(rubberBandRegion(q->viewport(), rubberBandRect));-
741 else-
742 updateAll();-
743 }-
744-
745 // Stop rubber banding if the user has let go of all buttons (even-
746 // if we didn't get the release events).-
747 if (!event->buttons()) {-
748 rubberBanding = false;-
749 rubberBandSelectionOperation = Qt::ReplaceSelection;-
750 if (!rubberBandRect.isNull()) {-
751 rubberBandRect = QRect();-
752 emit q->rubberBandChanged(rubberBandRect, QPointF(), QPointF());-
753 }-
754 return;-
755 }-
756-
757 QRect oldRubberband = rubberBandRect;-
758-
759 // Update rubberband position-
760 const QPoint mp = q->mapFromScene(mousePressScenePoint);-
761 const QPoint ep = event->pos();-
762 rubberBandRect = QRect(qMin(mp.x(), ep.x()), qMin(mp.y(), ep.y()),-
763 qAbs(mp.x() - ep.x()) + 1, qAbs(mp.y() - ep.y()) + 1);-
764-
765 if (rubberBandRect != oldRubberband || lastRubberbandScenePoint != lastMouseMoveScenePoint) {-
766 lastRubberbandScenePoint = lastMouseMoveScenePoint;-
767 oldRubberband = rubberBandRect;-
768 emit q->rubberBandChanged(rubberBandRect, mousePressScenePoint, lastRubberbandScenePoint);-
769 }-
770-
771 // Update new rubberband-
772 if (viewportUpdateMode != QGraphicsView::NoViewportUpdate) {-
773 if (viewportUpdateMode != QGraphicsView::FullViewportUpdate)-
774 q->viewport()->update(rubberBandRegion(q->viewport(), rubberBandRect));-
775 else-
776 updateAll();-
777 }-
778 // Set the new selection area-
779 QPainterPath selectionArea;-
780 selectionArea.addPolygon(q->mapToScene(rubberBandRect));-
781 selectionArea.closeSubpath();-
782 if (scene)-
783 scene->setSelectionArea(selectionArea, rubberBandSelectionOperation, rubberBandSelectionMode, q->viewportTransform());-
784}-
785#endif-
786-
787/*!-
788 \internal-
789*/-
790#ifndef QT_NO_CURSOR-
791void QGraphicsViewPrivate::_q_setViewportCursor(const QCursor &cursor)-
792{-
793 if (!hasStoredOriginalCursor) {-
794 hasStoredOriginalCursor = true;-
795 originalCursor = viewport->cursor();-
796 }-
797 viewport->setCursor(cursor);-
798}-
799#endif-
800-
801/*!-
802 \internal-
803*/-
804#ifndef QT_NO_CURSOR-
805void QGraphicsViewPrivate::_q_unsetViewportCursor()-
806{-
807 Q_Q(QGraphicsView);-
808 foreach (QGraphicsItem *item,const auto items = q->items(lastMouseEvent.pos()))());-
809 for (QGraphicsItem *item : items) {-
810 if (item->hasCursor()) {
item->hasCursor()Description
TRUEnever evaluated
FALSEnever evaluated
0
811 _q_setViewportCursor(item->cursor());-
812 return;
never executed: return;
0
813 }-
814 }
never executed: end of block
0
815-
816 // Restore the original viewport cursor.-
817 if (hasStoredOriginalCursor) {
hasStoredOriginalCursorDescription
TRUEnever evaluated
FALSEnever evaluated
0
818 hasStoredOriginalCursor = false;-
819 if (dragMode == QGraphicsView::ScrollHandDrag)
dragMode == QG...ScrollHandDragDescription
TRUEnever evaluated
FALSEnever evaluated
0
820 viewport->setCursor(Qt::OpenHandCursor);
never executed: viewport->setCursor(Qt::OpenHandCursor);
0
821 else-
822 viewport->setCursor(originalCursor);
never executed: viewport->setCursor(originalCursor);
0
823 }-
824}
never executed: end of block
0
825#endif-
826-
827/*!-
828 \internal-
829*/-
830void QGraphicsViewPrivate::storeDragDropEvent(const QGraphicsSceneDragDropEvent *event)-
831{-
832 delete lastDragDropEvent;-
833 lastDragDropEvent = new QGraphicsSceneDragDropEvent(event->type());-
834 lastDragDropEvent->setScenePos(event->scenePos());-
835 lastDragDropEvent->setScreenPos(event->screenPos());-
836 lastDragDropEvent->setButtons(event->buttons());-
837 lastDragDropEvent->setModifiers(event->modifiers());-
838 lastDragDropEvent->setPossibleActions(event->possibleActions());-
839 lastDragDropEvent->setProposedAction(event->proposedAction());-
840 lastDragDropEvent->setDropAction(event->dropAction());-
841 lastDragDropEvent->setMimeData(event->mimeData());-
842 lastDragDropEvent->setWidget(event->widget());-
843 lastDragDropEvent->setSource(event->source());-
844}-
845-
846/*!-
847 \internal-
848*/-
849void QGraphicsViewPrivate::populateSceneDragDropEvent(QGraphicsSceneDragDropEvent *dest,-
850 QDropEvent *source)-
851{-
852#ifndef QT_NO_DRAGANDDROP-
853 Q_Q(QGraphicsView);-
854 dest->setScenePos(q->mapToScene(source->pos()));-
855 dest->setScreenPos(q->mapToGlobal(source->pos()));-
856 dest->setButtons(source->mouseButtons());-
857 dest->setModifiers(source->keyboardModifiers());-
858 dest->setPossibleActions(source->possibleActions());-
859 dest->setProposedAction(source->proposedAction());-
860 dest->setDropAction(source->dropAction());-
861 dest->setMimeData(source->mimeData());-
862 dest->setWidget(viewport);-
863 dest->setSource(qobject_cast<QWidget *>(source->source()));-
864#else-
865 Q_UNUSED(dest)-
866 Q_UNUSED(source)-
867#endif-
868}-
869-
870/*!-
871 \internal-
872*/-
873QRect QGraphicsViewPrivate::mapToViewRect(const QGraphicsItem *item, const QRectF &rect) const-
874{-
875 Q_Q(const QGraphicsView);-
876 if (dirtyScroll)-
877 const_cast<QGraphicsViewPrivate *>(this)->updateScroll();-
878-
879 if (item->d_ptr->itemIsUntransformable()) {-
880 QTransform itv = item->deviceTransform(q->viewportTransform());-
881 return itv.mapRect(rect).toAlignedRect();-
882 }-
883-
884 // Translate-only-
885 // COMBINE-
886 QPointF offset;-
887 const QGraphicsItem *parentItem = item;-
888 const QGraphicsItemPrivate *itemd;-
889 do {-
890 itemd = parentItem->d_ptr.data();-
891 if (itemd->transformData)-
892 break;-
893 offset += itemd->pos;-
894 } while ((parentItem = itemd->parent));-
895-
896 QRectF baseRect = rect.translated(offset.x(), offset.y());-
897 if (!parentItem) {-
898 if (identityMatrix) {-
899 baseRect.translate(-scrollX, -scrollY);-
900 return baseRect.toAlignedRect();-
901 }-
902 return matrix.mapRect(baseRect).translated(-scrollX, -scrollY).toAlignedRect();-
903 }-
904-
905 QTransform tr = parentItem->sceneTransform();-
906 if (!identityMatrix)-
907 tr *= matrix;-
908 QRectF r = tr.mapRect(baseRect);-
909 r.translate(-scrollX, -scrollY);-
910 return r.toAlignedRect();-
911}-
912-
913/*!-
914 \internal-
915*/-
916QRegion QGraphicsViewPrivate::mapToViewRegion(const QGraphicsItem *item, const QRectF &rect) const-
917{-
918 Q_Q(const QGraphicsView);-
919 if (dirtyScroll)-
920 const_cast<QGraphicsViewPrivate *>(this)->updateScroll();-
921-
922 // Accurate bounding region-
923 QTransform itv = item->deviceTransform(q->viewportTransform());-
924 return item->boundingRegion(itv) & itv.mapRect(rect).toAlignedRect();-
925}-
926-
927/*!-
928 \internal-
929*/-
930void QGraphicsViewPrivate::processPendingUpdates()-
931{-
932 if (!scene)-
933 return;-
934-
935 if (fullUpdatePending) {-
936 viewport->update();-
937 } else if (viewportUpdateMode == QGraphicsView::BoundingRectViewportUpdate) {-
938 viewport->update(dirtyBoundingRect);-
939 } else {-
940 viewport->update(dirtyRegion); // Already adjusted in updateRect/Region.-
941 }-
942-
943 dirtyBoundingRect = QRect();-
944 dirtyRegion = QRegion();-
945}-
946-
947static inline bool intersectsViewport(const QRect &r, int width, int height)-
948{ return !(r.left() > width) && !(r.right() < 0) && !(r.top() >= height) && !(r.bottom() < 0); }-
949-
950static inline bool containsViewport(const QRect &r, int width, int height)-
951{ return r.left() <= 0 && r.top() <= 0 && r.right() >= width - 1 && r.bottom() >= height - 1; }-
952-
953static inline void QRect_unite(QRect *rect, const QRect &other)-
954{-
955 if (rect->isEmpty()) {-
956 *rect = other;-
957 } else {-
958 rect->setCoords(qMin(rect->left(), other.left()), qMin(rect->top(), other.top()),-
959 qMax(rect->right(), other.right()), qMax(rect->bottom(), other.bottom()));-
960 }-
961}-
962-
963/*-
964 Calling this function results in update rects being clipped to the item's-
965 bounding rect. Note that updates prior to this function call is not clipped.-
966 The clip is removed by passing 0.-
967*/-
968void QGraphicsViewPrivate::setUpdateClip(QGraphicsItem *item)-
969{-
970 Q_Q(QGraphicsView);-
971 // We simply ignore the request if the update mode is either FullViewportUpdate-
972 // or NoViewportUpdate; in that case there's no point in clipping anything.-
973 if (!item || viewportUpdateMode == QGraphicsView::NoViewportUpdate-
974 || viewportUpdateMode == QGraphicsView::FullViewportUpdate) {-
975 hasUpdateClip = false;-
976 return;-
977 }-
978-
979 // Calculate the clip (item's bounding rect in view coordinates).-
980 // Optimized version of:-
981 // QRect clip = item->deviceTransform(q->viewportTransform())-
982 // .mapRect(item->boundingRect()).toAlignedRect();-
983 QRect clip;-
984 if (item->d_ptr->itemIsUntransformable()) {-
985 QTransform xform = item->deviceTransform(q->viewportTransform());-
986 clip = xform.mapRect(item->boundingRect()).toAlignedRect();-
987 } else if (item->d_ptr->sceneTransformTranslateOnly && identityMatrix) {-
988 QRectF r(item->boundingRect());-
989 r.translate(item->d_ptr->sceneTransform.dx() - horizontalScroll(),-
990 item->d_ptr->sceneTransform.dy() - verticalScroll());-
991 clip = r.toAlignedRect();-
992 } else if (!q->isTransformed()) {-
993 clip = item->d_ptr->sceneTransform.mapRect(item->boundingRect()).toAlignedRect();-
994 } else {-
995 QTransform xform = item->d_ptr->sceneTransform;-
996 xform *= q->viewportTransform();-
997 clip = xform.mapRect(item->boundingRect()).toAlignedRect();-
998 }-
999-
1000 if (hasUpdateClip) {-
1001 // Intersect with old clip.-
1002 updateClip &= clip;-
1003 } else {-
1004 updateClip = clip;-
1005 hasUpdateClip = true;-
1006 }-
1007}-
1008-
1009bool QGraphicsViewPrivate::updateRegion(const QRectF &rect, const QTransform &xform)-
1010{-
1011 if (rect.isEmpty())-
1012 return false;-
1013-
1014 if (viewportUpdateMode != QGraphicsView::MinimalViewportUpdate-
1015 && viewportUpdateMode != QGraphicsView::SmartViewportUpdate) {-
1016 // No point in updating with QRegion granularity; use the rect instead.-
1017 return updateRectF(xform.mapRect(rect));-
1018 }-
1019-
1020 // Update mode is either Minimal or Smart, so we have to do a potentially slow operation,-
1021 // which is clearly documented here: QGraphicsItem::setBoundingRegionGranularity.-
1022 const QRegion region = xform.map(QRegion(rect.toAlignedRect()));-
1023 QRect viewRect = region.boundingRect();-
1024 const bool dontAdjustForAntialiasing = optimizationFlags & QGraphicsView::DontAdjustForAntialiasing;-
1025 if (dontAdjustForAntialiasing)-
1026 viewRect.adjust(-1, -1, 1, 1);-
1027 else-
1028 viewRect.adjust(-2, -2, 2, 2);-
1029 if (!intersectsViewport(viewRect, viewport->width(), viewport->height()))-
1030 return false; // Update region for sure outside viewport.-
1031-
1032 const QVector<QRect> &rects = region.rects();-
1033 for (int i = 0; i < rects.size(); ++i) {-
1034 viewRect = rects.at(i);-
1035 if (dontAdjustForAntialiasing)-
1036 viewRect.adjust(-1, -1, 1, 1);-
1037 else-
1038 viewRect.adjust(-2, -2, 2, 2);-
1039 if (hasUpdateClip)-
1040 viewRect &= updateClip;-
1041 dirtyRegion += viewRect;-
1042 }-
1043-
1044 return true;-
1045}-
1046-
1047// NB! Assumes the rect 'r' is already aligned and adjusted for antialiasing.-
1048// For QRectF use updateRectF(const QRectF &) to ensure proper adjustments.-
1049bool QGraphicsViewPrivate::updateRect(const QRect &r)-
1050{-
1051 if (fullUpdatePending || viewportUpdateMode == QGraphicsView::NoViewportUpdate-
1052 || !intersectsViewport(r, viewport->width(), viewport->height())) {-
1053 return false;-
1054 }-
1055-
1056 switch (viewportUpdateMode) {-
1057 case QGraphicsView::FullViewportUpdate:-
1058 fullUpdatePending = true;-
1059 viewport->update();-
1060 break;-
1061 case QGraphicsView::BoundingRectViewportUpdate:-
1062 if (hasUpdateClip)-
1063 QRect_unite(&dirtyBoundingRect, r & updateClip);-
1064 else-
1065 QRect_unite(&dirtyBoundingRect, r);-
1066 if (containsViewport(dirtyBoundingRect, viewport->width(), viewport->height())) {-
1067 fullUpdatePending = true;-
1068 viewport->update();-
1069 }-
1070 break;-
1071 case QGraphicsView::SmartViewportUpdate: // ### DEPRECATE-
1072 case QGraphicsView::MinimalViewportUpdate:-
1073 if (hasUpdateClip)-
1074 dirtyRegion += r & updateClip;-
1075 else-
1076 dirtyRegion += r;-
1077 break;-
1078 default:-
1079 break;-
1080 }-
1081-
1082 return true;-
1083}-
1084-
1085QStyleOptionGraphicsItem *QGraphicsViewPrivate::allocStyleOptionsArray(int numItems)-
1086{-
1087 if (mustAllocateStyleOptions || (numItems > styleOptions.capacity()))-
1088 // too many items, let's allocate on-the-fly-
1089 return new QStyleOptionGraphicsItem[numItems];-
1090-
1091 // expand only whenever necessary-
1092 if (numItems > styleOptions.size())-
1093 styleOptions.resize(numItems);-
1094-
1095 mustAllocateStyleOptions = true;-
1096 return styleOptions.data();-
1097}-
1098-
1099void QGraphicsViewPrivate::freeStyleOptionsArray(QStyleOptionGraphicsItem *array)-
1100{-
1101 mustAllocateStyleOptions = false;-
1102 if (array != styleOptions.data())-
1103 delete [] array;-
1104}-
1105-
1106extern QPainterPath qt_regionToPath(const QRegion &region);-
1107-
1108/*!-
1109 ### Adjustments in findItems: mapToScene(QRect) forces us to adjust the-
1110 input rectangle by (0, 0, 1, 1), because it uses QRect::bottomRight()-
1111 (etc) when mapping the rectangle to a polygon (which is _wrong_). In-
1112 addition, as QGraphicsItem::boundingRect() is defined in logical space,-
1113 but the default pen for QPainter is cosmetic with a width of 0, QPainter-
1114 is at risk of painting 1 pixel outside the bounding rect. Therefore we-
1115 must search for items with an adjustment of (-1, -1, 1, 1).-
1116*/-
1117QList<QGraphicsItem *> QGraphicsViewPrivate::findItems(const QRegion &exposedRegion, bool *allItems,-
1118 const QTransform &viewTransform) const-
1119{-
1120 Q_Q(const QGraphicsView);-
1121-
1122 // Step 1) If all items are contained within the expose region, then-
1123 // return a list of all visible items. ### the scene's growing bounding-
1124 // rect does not take into account untransformable items.-
1125 const QRectF exposedRegionSceneBounds = q->mapToScene(exposedRegion.boundingRect().adjusted(-1, -1, 1, 1))-
1126 .boundingRect();-
1127 if (exposedRegionSceneBounds.contains(scene->sceneRect())) {
exposedRegionS...->sceneRect())Description
TRUEnever evaluated
FALSEnever evaluated
0
1128 Q_ASSERT(allItems);-
1129 *allItems = true;-
1130-
1131 // All items are guaranteed within the exposed region.-
1132 return scene->items(Qt::AscendingOrder);
never executed: return scene->items(Qt::AscendingOrder);
0
1133 }-
1134-
1135 // Step 2) If the expose region is a simple rect and the view is only-
1136 // translated or scaled, search for items using-
1137 // QGraphicsScene::items(QRectF).-
1138 bool simpleRectLookup = exposedRegion.rectCount() == 1 && matrix.type() <= QTransform::TxScale;
exposedRegion.rectCount() == 1Description
TRUEnever evaluated
FALSEnever evaluated
matrix.type() ...sform::TxScaleDescription
TRUEnever evaluated
FALSEnever evaluated
0
1139 if (simpleRectLookup) {
simpleRectLookupDescription
TRUEnever evaluated
FALSEnever evaluated
0
1140 return scene->items(exposedRegionSceneBounds,
never executed: return scene->items(exposedRegionSceneBounds, Qt::IntersectsItemBoundingRect, Qt::AscendingOrder, viewTransform);
0
1141 Qt::IntersectsItemBoundingRect,
never executed: return scene->items(exposedRegionSceneBounds, Qt::IntersectsItemBoundingRect, Qt::AscendingOrder, viewTransform);
0
1142 Qt::AscendingOrder, viewTransform);
never executed: return scene->items(exposedRegionSceneBounds, Qt::IntersectsItemBoundingRect, Qt::AscendingOrder, viewTransform);
0
1143 }-
1144-
1145 // If the region is complex or the view has a complex transform, adjust-
1146 // the expose region, convert it to a path, and then search for items-
1147 // using QGraphicsScene::items(QPainterPath);-
1148 QRegion adjustedRegion;-
1149 foreachconst auto rects = exposedRegion.rects();-
1150 for (const QRect &r , exposedRegion.: rects()))-
1151 adjustedRegion += r.adjusted(-1, -1, 1, 1);
never executed: adjustedRegion += r.adjusted(-1, -1, 1, 1);
0
1152-
1153 const QPainterPath exposedScenePath(q->mapToScene(qt_regionToPath(adjustedRegion)));-
1154 return scene->items(exposedScenePath, Qt::IntersectsItemBoundingRect,
never executed: return scene->items(exposedScenePath, Qt::IntersectsItemBoundingRect, Qt::AscendingOrder, viewTransform);
0
1155 Qt::AscendingOrder, viewTransform);
never executed: return scene->items(exposedScenePath, Qt::IntersectsItemBoundingRect, Qt::AscendingOrder, viewTransform);
0
1156}-
1157-
1158/*!-
1159 \internal-
1160-
1161 Enables input methods for the view if and only if the current focus item of-
1162 the scene accepts input methods. Call function whenever that condition has-
1163 potentially changed.-
1164*/-
1165void QGraphicsViewPrivate::updateInputMethodSensitivity()-
1166{-
1167 Q_Q(QGraphicsView);-
1168 QGraphicsItem *focusItem = 0;-
1169 bool enabled = scene && (focusItem = scene->focusItem())-
1170 && (focusItem->d_ptr->flags & QGraphicsItem::ItemAcceptsInputMethod);-
1171 q->setAttribute(Qt::WA_InputMethodEnabled, enabled);-
1172 q->viewport()->setAttribute(Qt::WA_InputMethodEnabled, enabled);-
1173-
1174 if (!enabled) {-
1175 q->setInputMethodHints(0);-
1176 return;-
1177 }-
1178-
1179 QGraphicsProxyWidget *proxy = focusItem->d_ptr->isWidget && focusItem->d_ptr->isProxyWidget()-
1180 ? static_cast<QGraphicsProxyWidget *>(focusItem) : 0;-
1181 if (!proxy) {-
1182 q->setInputMethodHints(focusItem->inputMethodHints());-
1183 } else if (QWidget *widget = proxy->widget()) {-
1184 if (QWidget *fw = widget->focusWidget())-
1185 widget = fw;-
1186 q->setInputMethodHints(widget->inputMethodHints());-
1187 } else {-
1188 q->setInputMethodHints(0);-
1189 }-
1190}-
1191-
1192/*!-
1193 Constructs a QGraphicsView. \a parent is passed to QWidget's constructor.-
1194*/-
1195QGraphicsView::QGraphicsView(QWidget *parent)-
1196 : QAbstractScrollArea(*new QGraphicsViewPrivate, parent)-
1197{-
1198 setViewport(0);-
1199 setAcceptDrops(true);-
1200 setBackgroundRole(QPalette::Base);-
1201 // Investigate leaving these disabled by default.-
1202 setAttribute(Qt::WA_InputMethodEnabled);-
1203 viewport()->setAttribute(Qt::WA_InputMethodEnabled);-
1204}-
1205-
1206/*!-
1207 Constructs a QGraphicsView and sets the visualized scene to \a-
1208 scene. \a parent is passed to QWidget's constructor.-
1209*/-
1210QGraphicsView::QGraphicsView(QGraphicsScene *scene, QWidget *parent)-
1211 : QAbstractScrollArea(*new QGraphicsViewPrivate, parent)-
1212{-
1213 setScene(scene);-
1214 setViewport(0);-
1215 setAcceptDrops(true);-
1216 setBackgroundRole(QPalette::Base);-
1217 // Investigate leaving these disabled by default.-
1218 setAttribute(Qt::WA_InputMethodEnabled);-
1219 viewport()->setAttribute(Qt::WA_InputMethodEnabled);-
1220}-
1221-
1222/*!-
1223 \internal-
1224 */-
1225QGraphicsView::QGraphicsView(QGraphicsViewPrivate &dd, QWidget *parent)-
1226 : QAbstractScrollArea(dd, parent)-
1227{-
1228 setViewport(0);-
1229 setAcceptDrops(true);-
1230 setBackgroundRole(QPalette::Base);-
1231 // Investigate leaving these disabled by default.-
1232 setAttribute(Qt::WA_InputMethodEnabled);-
1233 viewport()->setAttribute(Qt::WA_InputMethodEnabled);-
1234}-
1235-
1236/*!-
1237 Destructs the QGraphicsView object.-
1238*/-
1239QGraphicsView::~QGraphicsView()-
1240{-
1241 Q_D(QGraphicsView);-
1242 if (d->scene)-
1243 d->scene->d_func()->views.removeAll(this);-
1244 delete d->lastDragDropEvent;-
1245}-
1246-
1247/*!-
1248 \reimp-
1249*/-
1250QSize QGraphicsView::sizeHint() const-
1251{-
1252 Q_D(const QGraphicsView);-
1253 if (d->scene) {-
1254 QSizeF baseSize = d->matrix.mapRect(sceneRect()).size();-
1255 baseSize += QSizeF(d->frameWidth * 2, d->frameWidth * 2);-
1256 return baseSize.boundedTo((3 * QApplication::desktop()->size()) / 4).toSize();-
1257 }-
1258 return QAbstractScrollArea::sizeHint();-
1259}-
1260-
1261/*!-
1262 \property QGraphicsView::renderHints-
1263 \brief the default render hints for the view-
1264-
1265 These hints are-
1266 used to initialize QPainter before each visible item is drawn. QPainter-
1267 uses render hints to toggle rendering features such as antialiasing and-
1268 smooth pixmap transformation.-
1269-
1270 QPainter::TextAntialiasing is enabled by default.-
1271-
1272 Example:-
1273-
1274 \snippet code/src_gui_graphicsview_qgraphicsview.cpp 1-
1275*/-
1276QPainter::RenderHints QGraphicsView::renderHints() const-
1277{-
1278 Q_D(const QGraphicsView);-
1279 return d->renderHints;-
1280}-
1281void QGraphicsView::setRenderHints(QPainter::RenderHints hints)-
1282{-
1283 Q_D(QGraphicsView);-
1284 if (hints == d->renderHints)-
1285 return;-
1286 d->renderHints = hints;-
1287 d->updateAll();-
1288}-
1289-
1290/*!-
1291 If \a enabled is true, the render hint \a hint is enabled; otherwise it-
1292 is disabled.-
1293-
1294 \sa renderHints-
1295*/-
1296void QGraphicsView::setRenderHint(QPainter::RenderHint hint, bool enabled)-
1297{-
1298 Q_D(QGraphicsView);-
1299 QPainter::RenderHints oldHints = d->renderHints;-
if (enabled)d->renderHints|= hint;
1300 elsed->renderHints&= ~.setFlag(hint;, enabled);-
1301 if (oldHints != d->renderHints)
oldHints != d->renderHintsDescription
TRUEnever evaluated
FALSEnever evaluated
0
1302 d->updateAll();
never executed: d->updateAll();
0
1303}
never executed: end of block
0
1304-
1305/*!-
1306 \property QGraphicsView::alignment-
1307 \brief the alignment of the scene in the view when the whole-
1308 scene is visible.-
1309-
1310 If the whole scene is visible in the view, (i.e., there are no visible-
1311 scroll bars,) the view's alignment will decide where the scene will be-
1312 rendered in the view. For example, if the alignment is Qt::AlignCenter,-
1313 which is default, the scene will be centered in the view, and if the-
1314 alignment is (Qt::AlignLeft | Qt::AlignTop), the scene will be rendered in-
1315 the top-left corner of the view.-
1316*/-
1317Qt::Alignment QGraphicsView::alignment() const-
1318{-
1319 Q_D(const QGraphicsView);-
1320 return d->alignment;-
1321}-
1322void QGraphicsView::setAlignment(Qt::Alignment alignment)-
1323{-
1324 Q_D(QGraphicsView);-
1325 if (d->alignment != alignment) {-
1326 d->alignment = alignment;-
1327 d->recalculateContentSize();-
1328 }-
1329}-
1330-
1331/*!-
1332 \property QGraphicsView::transformationAnchor-
1333 \brief how the view should position the scene during transformations.-
1334-
1335 QGraphicsView uses this property to decide how to position the scene in-
1336 the viewport when the transformation matrix changes, and the coordinate-
1337 system of the view is transformed. The default behavior, AnchorViewCenter,-
1338 ensures that the scene point at the center of the view remains unchanged-
1339 during transformations (e.g., when rotating, the scene will appear to-
1340 rotate around the center of the view).-
1341-
1342 Note that the effect of this property is noticeable when only a part of the-
1343 scene is visible (i.e., when there are scroll bars). Otherwise, if the-
1344 whole scene fits in the view, QGraphicsScene uses the view \l alignment to-
1345 position the scene in the view.-
1346-
1347 \sa alignment, resizeAnchor-
1348*/-
1349QGraphicsView::ViewportAnchor QGraphicsView::transformationAnchor() const-
1350{-
1351 Q_D(const QGraphicsView);-
1352 return d->transformationAnchor;-
1353}-
1354void QGraphicsView::setTransformationAnchor(ViewportAnchor anchor)-
1355{-
1356 Q_D(QGraphicsView);-
1357 d->transformationAnchor = anchor;-
1358-
1359 // Ensure mouse tracking is enabled in the case we are using AnchorUnderMouse-
1360 // in order to have up-to-date information for centering the view.-
1361 if (d->transformationAnchor == AnchorUnderMouse)-
1362 d->viewport->setMouseTracking(true);-
1363}-
1364-
1365/*!-
1366 \property QGraphicsView::resizeAnchor-
1367 \brief how the view should position the scene when the view is resized.-
1368-
1369 QGraphicsView uses this property to decide how to position the scene in-
1370 the viewport when the viewport widget's size changes. The default-
1371 behavior, NoAnchor, leaves the scene's position unchanged during a resize;-
1372 the top-left corner of the view will appear to be anchored while resizing.-
1373-
1374 Note that the effect of this property is noticeable when only a part of the-
1375 scene is visible (i.e., when there are scroll bars). Otherwise, if the-
1376 whole scene fits in the view, QGraphicsScene uses the view \l alignment to-
1377 position the scene in the view.-
1378-
1379 \sa alignment, transformationAnchor-
1380*/-
1381QGraphicsView::ViewportAnchor QGraphicsView::resizeAnchor() const-
1382{-
1383 Q_D(const QGraphicsView);-
1384 return d->resizeAnchor;-
1385}-
1386void QGraphicsView::setResizeAnchor(ViewportAnchor anchor)-
1387{-
1388 Q_D(QGraphicsView);-
1389 d->resizeAnchor = anchor;-
1390-
1391 // Ensure mouse tracking is enabled in the case we are using AnchorUnderMouse-
1392 // in order to have up-to-date information for centering the view.-
1393 if (d->resizeAnchor == AnchorUnderMouse)-
1394 d->viewport->setMouseTracking(true);-
1395}-
1396-
1397/*!-
1398 \property QGraphicsView::viewportUpdateMode-
1399 \brief how the viewport should update its contents.-
1400-
1401 \since 4.3-
1402-
1403 QGraphicsView uses this property to decide how to update areas of the-
1404 scene that have been reexposed or changed. Usually you do not need to-
1405 modify this property, but there are some cases where doing so can improve-
1406 rendering performance. See the ViewportUpdateMode documentation for-
1407 specific details.-
1408-
1409 The default value is MinimalViewportUpdate, where QGraphicsView will-
1410 update as small an area of the viewport as possible when the contents-
1411 change.-
1412-
1413 \sa ViewportUpdateMode, cacheMode-
1414*/-
1415QGraphicsView::ViewportUpdateMode QGraphicsView::viewportUpdateMode() const-
1416{-
1417 Q_D(const QGraphicsView);-
1418 return d->viewportUpdateMode;-
1419}-
1420void QGraphicsView::setViewportUpdateMode(ViewportUpdateMode mode)-
1421{-
1422 Q_D(QGraphicsView);-
1423 d->viewportUpdateMode = mode;-
1424}-
1425-
1426/*!-
1427 \property QGraphicsView::optimizationFlags-
1428 \brief flags that can be used to tune QGraphicsView's performance.-
1429-
1430 \since 4.3-
1431-
1432 QGraphicsView uses clipping, extra bounding rect adjustments, and certain-
1433 other aids to improve rendering quality and performance for the common-
1434 case graphics scene. However, depending on the target platform, the scene,-
1435 and the viewport in use, some of these operations can degrade performance.-
1436-
1437 The effect varies from flag to flag; see the OptimizationFlags-
1438 documentation for details.-
1439-
1440 By default, no optimization flags are enabled.-
1441-
1442 \sa setOptimizationFlag()-
1443*/-
1444QGraphicsView::OptimizationFlags QGraphicsView::optimizationFlags() const-
1445{-
1446 Q_D(const QGraphicsView);-
1447 return d->optimizationFlags;-
1448}-
1449void QGraphicsView::setOptimizationFlags(OptimizationFlags flags)-
1450{-
1451 Q_D(QGraphicsView);-
1452 d->optimizationFlags = flags;-
1453}-
1454-
1455/*!-
1456 Enables \a flag if \a enabled is true; otherwise disables \a flag.-
1457-
1458 \sa optimizationFlags-
1459*/-
1460void QGraphicsView::setOptimizationFlag(OptimizationFlag flag, bool enabled)-
1461{-
1462 Q_D(QGraphicsView);-
1463 if (enabled)-
d->optimizationFlags |= flag;
elsed->optimizationFlags&= ~.setFlag(flag;, enabled);
1464}
never executed: end of block
0
1465-
1466/*!-
1467 \property QGraphicsView::dragMode-
1468 \brief the behavior for dragging the mouse over the scene while-
1469 the left mouse button is pressed.-
1470-
1471 This property defines what should happen when the user clicks on the scene-
1472 background and drags the mouse (e.g., scrolling the viewport contents-
1473 using a pointing hand cursor, or selecting multiple items with a rubber-
1474 band). The default value, NoDrag, does nothing.-
1475-
1476 This behavior only affects mouse clicks that are not handled by any item.-
1477 You can define a custom behavior by creating a subclass of QGraphicsView-
1478 and reimplementing mouseMoveEvent().-
1479*/-
1480QGraphicsView::DragMode QGraphicsView::dragMode() const-
1481{-
1482 Q_D(const QGraphicsView);-
1483 return d->dragMode;-
1484}-
1485void QGraphicsView::setDragMode(DragMode mode)-
1486{-
1487 Q_D(QGraphicsView);-
1488 if (d->dragMode == mode)-
1489 return;-
1490-
1491#ifndef QT_NO_CURSOR-
1492 if (d->dragMode == ScrollHandDrag)-
1493 viewport()->unsetCursor();-
1494#endif-
1495-
1496 // If dragMode is unset while dragging, e.g. via a keyEvent, we-
1497 // don't unset the handScrolling state. When enabling scrolling-
1498 // again the mouseMoveEvent will automatically start scrolling,-
1499 // without a mousePress-
1500 if (d->dragMode == ScrollHandDrag && mode == NoDrag && d->handScrolling)-
1501 d->handScrolling = false;-
1502-
1503 d->dragMode = mode;-
1504-
1505#ifndef QT_NO_CURSOR-
1506 if (d->dragMode == ScrollHandDrag) {-
1507 // Forget the stored viewport cursor when we enter scroll hand drag mode.-
1508 d->hasStoredOriginalCursor = false;-
1509 viewport()->setCursor(Qt::OpenHandCursor);-
1510 }-
1511#endif-
1512}-
1513-
1514#ifndef QT_NO_RUBBERBAND-
1515/*!-
1516 \property QGraphicsView::rubberBandSelectionMode-
1517 \brief the behavior for selecting items with a rubber band selection rectangle.-
1518 \since 4.3-
1519-
1520 This property defines how items are selected when using the RubberBandDrag-
1521 drag mode.-
1522-
1523 The default value is Qt::IntersectsItemShape; all items whose shape-
1524 intersects with or is contained by the rubber band are selected.-
1525-
1526 \sa dragMode, items(), rubberBandRect()-
1527*/-
1528Qt::ItemSelectionMode QGraphicsView::rubberBandSelectionMode() const-
1529{-
1530 Q_D(const QGraphicsView);-
1531 return d->rubberBandSelectionMode;-
1532}-
1533void QGraphicsView::setRubberBandSelectionMode(Qt::ItemSelectionMode mode)-
1534{-
1535 Q_D(QGraphicsView);-
1536 d->rubberBandSelectionMode = mode;-
1537}-
1538-
1539/*!-
1540 \since 5.1-
1541 This functions returns the current rubber band area (in viewport coordinates) if the user-
1542 is currently doing an itemselection with rubber band. When the user is not using the-
1543 rubber band this functions returns (a null) QRectF().-
1544-
1545 Notice that part of this QRect can be outise the visual viewport. It can e.g-
1546 contain negative values.-
1547-
1548 \sa rubberBandSelectionMode, rubberBandChanged()-
1549*/-
1550-
1551QRect QGraphicsView::rubberBandRect() const-
1552{-
1553 Q_D(const QGraphicsView);-
1554 if (d->dragMode != QGraphicsView::RubberBandDrag || !d->sceneInteractionAllowed || !d->rubberBanding)-
1555 return QRect();-
1556-
1557 return d->rubberBandRect;-
1558}-
1559#endif-
1560-
1561/*!-
1562 \property QGraphicsView::cacheMode-
1563 \brief which parts of the view are cached-
1564-
1565 QGraphicsView can cache pre-rendered content in a QPixmap, which is then-
1566 drawn onto the viewport. The purpose of such caching is to speed up the-
1567 total rendering time for areas that are slow to render. Texture, gradient-
1568 and alpha blended backgrounds, for example, can be notibly slow to render;-
1569 especially with a transformed view. The CacheBackground flag enables-
1570 caching of the view's background. For example:-
1571-
1572 \snippet code/src_gui_graphicsview_qgraphicsview.cpp 2-
1573-
1574 The cache is invalidated every time the view is transformed. However, when-
1575 scrolling, only partial invalidation is required.-
1576-
1577 By default, nothing is cached.-
1578-
1579 \sa resetCachedContent(), QPixmapCache-
1580*/-
1581QGraphicsView::CacheMode QGraphicsView::cacheMode() const-
1582{-
1583 Q_D(const QGraphicsView);-
1584 return d->cacheMode;-
1585}-
1586void QGraphicsView::setCacheMode(CacheMode mode)-
1587{-
1588 Q_D(QGraphicsView);-
1589 if (mode == d->cacheMode)-
1590 return;-
1591 d->cacheMode = mode;-
1592 resetCachedContent();-
1593}-
1594-
1595/*!-
1596 Resets any cached content. Calling this function will clear-
1597 QGraphicsView's cache. If the current cache mode is \l CacheNone, this-
1598 function does nothing.-
1599-
1600 This function is called automatically for you when the backgroundBrush or-
1601 QGraphicsScene::backgroundBrush properties change; you only need to call-
1602 this function if you have reimplemented QGraphicsScene::drawBackground()-
1603 or QGraphicsView::drawBackground() to draw a custom background, and need-
1604 to trigger a full redraw.-
1605-
1606 \sa cacheMode()-
1607*/-
1608void QGraphicsView::resetCachedContent()-
1609{-
1610 Q_D(QGraphicsView);-
1611 if (d->cacheMode == CacheNone)-
1612 return;-
1613-
1614 if (d->cacheMode & CacheBackground) {-
1615 // Background caching is enabled.-
1616 d->mustResizeBackgroundPixmap = true;-
1617 d->updateAll();-
1618 } else if (d->mustResizeBackgroundPixmap) {-
1619 // Background caching is disabled.-
1620 // Cleanup, free some resources.-
1621 d->mustResizeBackgroundPixmap = false;-
1622 d->backgroundPixmap = QPixmap();-
1623 d->backgroundPixmapExposed = QRegion();-
1624 }-
1625}-
1626-
1627/*!-
1628 Invalidates and schedules a redraw of \a layers inside \a rect. \a rect is-
1629 in scene coordinates. Any cached content for \a layers inside \a rect is-
1630 unconditionally invalidated and redrawn.-
1631-
1632 You can call this function to notify QGraphicsView of changes to the-
1633 background or the foreground of the scene. It is commonly used for scenes-
1634 with tile-based backgrounds to notify changes when QGraphicsView has-
1635 enabled background caching.-
1636-
1637 Note that QGraphicsView currently supports background caching only (see-
1638 QGraphicsView::CacheBackground). This function is equivalent to calling update() if any-
1639 layer but QGraphicsScene::BackgroundLayer is passed.-
1640-
1641 \sa QGraphicsScene::invalidate(), update()-
1642*/-
1643void QGraphicsView::invalidateScene(const QRectF &rect, QGraphicsScene::SceneLayers layers)-
1644{-
1645 Q_D(QGraphicsView);-
1646 if ((layers & QGraphicsScene::BackgroundLayer) && !d->mustResizeBackgroundPixmap) {-
1647 QRect viewRect = mapFromScene(rect).boundingRect();-
1648 if (viewport()->rect().intersects(viewRect)) {-
1649 // The updated background area is exposed; schedule this area for-
1650 // redrawing.-
1651 d->backgroundPixmapExposed += viewRect;-
1652 if (d->scene)-
1653 d->scene->update(rect);-
1654 }-
1655 }-
1656}-
1657-
1658/*!-
1659 \property QGraphicsView::interactive-
1660 \brief whether the view allows scene interaction.-
1661-
1662 If enabled, this view is set to allow scene interaction. Otherwise, this-
1663 view will not allow interaction, and any mouse or key events are ignored-
1664 (i.e., it will act as a read-only view).-
1665-
1666 By default, this property is \c true.-
1667*/-
1668bool QGraphicsView::isInteractive() const-
1669{-
1670 Q_D(const QGraphicsView);-
1671 return d->sceneInteractionAllowed;-
1672}-
1673void QGraphicsView::setInteractive(bool allowed)-
1674{-
1675 Q_D(QGraphicsView);-
1676 d->sceneInteractionAllowed = allowed;-
1677}-
1678-
1679/*!-
1680 Returns a pointer to the scene that is currently visualized in the-
1681 view. If no scene is currently visualized, 0 is returned.-
1682-
1683 \sa setScene()-
1684*/-
1685QGraphicsScene *QGraphicsView::scene() const-
1686{-
1687 Q_D(const QGraphicsView);-
1688 return d->scene;-
1689}-
1690-
1691/*!-
1692 Sets the current scene to \a scene. If \a scene is already being-
1693 viewed, this function does nothing.-
1694-
1695 When a scene is set on a view, the QGraphicsScene::changed() signal-
1696 is automatically connected to this view's updateScene() slot, and the-
1697 view's scroll bars are adjusted to fit the size of the scene.-
1698-
1699 The view does not take ownership of \a scene.-
1700*/-
1701void QGraphicsView::setScene(QGraphicsScene *scene)-
1702{-
1703 Q_D(QGraphicsView);-
1704 if (d->scene == scene)-
1705 return;-
1706-
1707 // Always update the viewport when the scene changes.-
1708 d->updateAll();-
1709-
1710 // Remove the previously assigned scene.-
1711 if (d->scene) {-
1712 disconnect(d->scene, SIGNAL(changed(QList<QRectF>)),-
1713 this, SLOT(updateScene(QList<QRectF>)));-
1714 disconnect(d->scene, SIGNAL(sceneRectChanged(QRectF)),-
1715 this, SLOT(updateSceneRect(QRectF)));-
1716 d->scene->d_func()->removeView(this);-
1717 d->connectedToScene = false;-
1718-
1719 if (isActiveWindow() && isVisible()) {-
1720 QEvent windowDeactivate(QEvent::WindowDeactivate);-
1721 QApplication::sendEvent(d->scene, &windowDeactivate);-
1722 }-
1723 if(hasFocus())-
1724 d->scene->clearFocus();-
1725 }-
1726-
1727 // Assign the new scene and update the contents (scrollbars, etc.)).-
1728 if ((d->scene = scene)) {-
1729 connect(d->scene, SIGNAL(sceneRectChanged(QRectF)),-
1730 this, SLOT(updateSceneRect(QRectF)));-
1731 d->updateSceneSlotReimplementedChecked = false;-
1732 d->scene->d_func()->addView(this);-
1733 d->recalculateContentSize();-
1734 d->lastCenterPoint = sceneRect().center();-
1735 d->keepLastCenterPoint = true;-
1736 // We are only interested in mouse tracking if items accept-
1737 // hover events or use non-default cursors.-
1738 if (!d->scene->d_func()->allItemsIgnoreHoverEvents-
1739 || !d->scene->d_func()->allItemsUseDefaultCursor) {-
1740 d->viewport->setMouseTracking(true);-
1741 }-
1742-
1743 // enable touch events if any items is interested in them-
1744 if (!d->scene->d_func()->allItemsIgnoreTouchEvents)-
1745 d->viewport->setAttribute(Qt::WA_AcceptTouchEvents);-
1746-
1747 if (isActiveWindow() && isVisible()) {-
1748 QEvent windowActivate(QEvent::WindowActivate);-
1749 QApplication::sendEvent(d->scene, &windowActivate);-
1750 }-
1751 } else {-
1752 d->recalculateContentSize();-
1753 }-
1754-
1755 d->updateInputMethodSensitivity();-
1756-
1757 if (d->scene && hasFocus())-
1758 d->scene->setFocus();-
1759}-
1760-
1761/*!-
1762 \property QGraphicsView::sceneRect-
1763 \brief the area of the scene visualized by this view.-
1764-
1765 The scene rectangle defines the extent of the scene, and in the view's case,-
1766 this means the area of the scene that you can navigate using the scroll-
1767 bars.-
1768-
1769 If unset, or if a null QRectF is set, this property has the same value as-
1770 QGraphicsScene::sceneRect, and it changes with-
1771 QGraphicsScene::sceneRect. Otherwise, the view's scene rect is unaffected-
1772 by the scene.-
1773-
1774 Note that, although the scene supports a virtually unlimited size, the-
1775 range of the scroll bars will never exceed the range of an integer-
1776 (INT_MIN, INT_MAX). When the scene is larger than the scroll bars' values,-
1777 you can choose to use translate() to navigate the scene instead.-
1778-
1779 By default, this property contains a rectangle at the origin with zero-
1780 width and height.-
1781-
1782 \sa QGraphicsScene::sceneRect-
1783*/-
1784QRectF QGraphicsView::sceneRect() const-
1785{-
1786 Q_D(const QGraphicsView);-
1787 if (d->hasSceneRect)-
1788 return d->sceneRect;-
1789 if (d->scene)-
1790 return d->scene->sceneRect();-
1791 return QRectF();-
1792}-
1793void QGraphicsView::setSceneRect(const QRectF &rect)-
1794{-
1795 Q_D(QGraphicsView);-
1796 d->hasSceneRect = !rect.isNull();-
1797 d->sceneRect = rect;-
1798 d->recalculateContentSize();-
1799}-
1800-
1801/*!-
1802 Returns the current transformation matrix for the view. If no current-
1803 transformation is set, the identity matrix is returned.-
1804-
1805 \sa setMatrix(), transform(), rotate(), scale(), shear(), translate()-
1806*/-
1807QMatrix QGraphicsView::matrix() const-
1808{-
1809 Q_D(const QGraphicsView);-
1810 return d->matrix.toAffine();-
1811}-
1812-
1813/*!-
1814 Sets the view's current transformation matrix to \a matrix.-
1815-
1816 If \a combine is true, then \a matrix is combined with the current matrix;-
1817 otherwise, \a matrix \e replaces the current matrix. \a combine is false-
1818 by default.-
1819-
1820 The transformation matrix tranforms the scene into view coordinates. Using-
1821 the default transformation, provided by the identity matrix, one pixel in-
1822 the view represents one unit in the scene (e.g., a 10x10 rectangular item-
1823 is drawn using 10x10 pixels in the view). If a 2x2 scaling matrix is-
1824 applied, the scene will be drawn in 1:2 (e.g., a 10x10 rectangular item is-
1825 then drawn using 20x20 pixels in the view).-
1826-
1827 Example:-
1828-
1829 \snippet code/src_gui_graphicsview_qgraphicsview.cpp 3-
1830-
1831 To simplify interation with items using a transformed view, QGraphicsView-
1832 provides mapTo... and mapFrom... functions that can translate between-
1833 scene and view coordinates. For example, you can call mapToScene() to map-
1834 a view coordinate to a floating point scene coordinate, or mapFromScene()-
1835 to map from floating point scene coordinates to view coordinates.-
1836-
1837 \sa matrix(), setTransform(), rotate(), scale(), shear(), translate()-
1838*/-
1839void QGraphicsView::setMatrix(const QMatrix &matrix, bool combine)-
1840{-
1841 setTransform(QTransform(matrix), combine);-
1842}-
1843-
1844/*!-
1845 Resets the view transformation matrix to the identity matrix.-
1846-
1847 \sa resetTransform()-
1848*/-
1849void QGraphicsView::resetMatrix()-
1850{-
1851 resetTransform();-
1852}-
1853-
1854/*!-
1855 Rotates the current view transformation \a angle degrees clockwise.-
1856-
1857 \sa setTransform(), transform(), scale(), shear(), translate()-
1858*/-
1859void QGraphicsView::rotate(qreal angle)-
1860{-
1861 Q_D(QGraphicsView);-
1862 QTransform matrix = d->matrix;-
1863 matrix.rotate(angle);-
1864 setTransform(matrix);-
1865}-
1866-
1867/*!-
1868 Scales the current view transformation by (\a sx, \a sy).-
1869-
1870 \sa setTransform(), transform(), rotate(), shear(), translate()-
1871*/-
1872void QGraphicsView::scale(qreal sx, qreal sy)-
1873{-
1874 Q_D(QGraphicsView);-
1875 QTransform matrix = d->matrix;-
1876 matrix.scale(sx, sy);-
1877 setTransform(matrix);-
1878}-
1879-
1880/*!-
1881 Shears the current view transformation by (\a sh, \a sv).-
1882-
1883 \sa setTransform(), transform(), rotate(), scale(), translate()-
1884*/-
1885void QGraphicsView::shear(qreal sh, qreal sv)-
1886{-
1887 Q_D(QGraphicsView);-
1888 QTransform matrix = d->matrix;-
1889 matrix.shear(sh, sv);-
1890 setTransform(matrix);-
1891}-
1892-
1893/*!-
1894 Translates the current view transformation by (\a dx, \a dy).-
1895-
1896 \sa setTransform(), transform(), rotate(), shear()-
1897*/-
1898void QGraphicsView::translate(qreal dx, qreal dy)-
1899{-
1900 Q_D(QGraphicsView);-
1901 QTransform matrix = d->matrix;-
1902 matrix.translate(dx, dy);-
1903 setTransform(matrix);-
1904}-
1905-
1906/*!-
1907 Scrolls the contents of the viewport to ensure that the scene-
1908 coordinate \a pos, is centered in the view.-
1909-
1910 Because \a pos is a floating point coordinate, and the scroll bars operate-
1911 on integer coordinates, the centering is only an approximation.-
1912-
1913 \note If the item is close to or outside the border, it will be visible-
1914 in the view, but not centered.-
1915-
1916 \sa ensureVisible()-
1917*/-
1918void QGraphicsView::centerOn(const QPointF &pos)-
1919{-
1920 Q_D(QGraphicsView);-
1921 qreal width = viewport()->width();-
1922 qreal height = viewport()->height();-
1923 QPointF viewPoint = d->matrix.map(pos);-
1924 QPointF oldCenterPoint = pos;-
1925-
1926 if (!d->leftIndent) {-
1927 if (isRightToLeft()) {-
1928 qint64 horizontal = 0;-
1929 horizontal += horizontalScrollBar()->minimum();-
1930 horizontal += horizontalScrollBar()->maximum();-
1931 horizontal -= int(viewPoint.x() - width / 2.0);-
1932 horizontalScrollBar()->setValue(horizontal);-
1933 } else {-
1934 horizontalScrollBar()->setValue(int(viewPoint.x() - width / 2.0));-
1935 }-
1936 }-
1937 if (!d->topIndent)-
1938 verticalScrollBar()->setValue(int(viewPoint.y() - height / 2.0));-
1939 d->lastCenterPoint = oldCenterPoint;-
1940}-
1941-
1942/*!-
1943 \fn QGraphicsView::centerOn(qreal x, qreal y)-
1944 \overload-
1945-
1946 This function is provided for convenience. It's equivalent to calling-
1947 centerOn(QPointF(\a x, \a y)).-
1948*/-
1949-
1950/*!-
1951 \overload-
1952-
1953 Scrolls the contents of the viewport to ensure that \a item-
1954 is centered in the view.-
1955-
1956 \sa ensureVisible()-
1957*/-
1958void QGraphicsView::centerOn(const QGraphicsItem *item)-
1959{-
1960 centerOn(item->sceneBoundingRect().center());-
1961}-
1962-
1963/*!-
1964 Scrolls the contents of the viewport so that the scene rectangle \a rect-
1965 is visible, with margins specified in pixels by \a xmargin and \a-
1966 ymargin. If the specified rect cannot be reached, the contents are-
1967 scrolled to the nearest valid position. The default value for both margins-
1968 is 50 pixels.-
1969-
1970 \sa centerOn()-
1971*/-
1972void QGraphicsView::ensureVisible(const QRectF &rect, int xmargin, int ymargin)-
1973{-
1974 Q_D(QGraphicsView);-
1975 qreal width = viewport()->width();-
1976 qreal height = viewport()->height();-
1977 QRectF viewRect = d->matrix.mapRect(rect);-
1978-
1979 qreal left = d->horizontalScroll();-
1980 qreal right = left + width;-
1981 qreal top = d->verticalScroll();-
1982 qreal bottom = top + height;-
1983-
1984 if (viewRect.left() <= left + xmargin) {-
1985 // need to scroll from the left-
1986 if (!d->leftIndent)-
1987 horizontalScrollBar()->setValue(int(viewRect.left() - xmargin - 0.5));-
1988 }-
1989 if (viewRect.right() >= right - xmargin) {-
1990 // need to scroll from the right-
1991 if (!d->leftIndent)-
1992 horizontalScrollBar()->setValue(int(viewRect.right() - width + xmargin + 0.5));-
1993 }-
1994 if (viewRect.top() <= top + ymargin) {-
1995 // need to scroll from the top-
1996 if (!d->topIndent)-
1997 verticalScrollBar()->setValue(int(viewRect.top() - ymargin - 0.5));-
1998 }-
1999 if (viewRect.bottom() >= bottom - ymargin) {-
2000 // need to scroll from the bottom-
2001 if (!d->topIndent)-
2002 verticalScrollBar()->setValue(int(viewRect.bottom() - height + ymargin + 0.5));-
2003 }-
2004}-
2005-
2006/*!-
2007 \fn QGraphicsView::ensureVisible(qreal x, qreal y, qreal w, qreal h,-
2008 int xmargin, int ymargin)-
2009 \overload-
2010-
2011 This function is provided for convenience. It's equivalent to calling-
2012 ensureVisible(QRectF(\a x, \a y, \a w, \a h), \a xmargin, \a ymargin).-
2013*/-
2014-
2015/*!-
2016 \overload-
2017-
2018 Scrolls the contents of the viewport so that the center of item \a item is-
2019 visible, with margins specified in pixels by \a xmargin and \a ymargin. If-
2020 the specified point cannot be reached, the contents are scrolled to the-
2021 nearest valid position. The default value for both margins is 50 pixels.-
2022-
2023 \sa centerOn()-
2024*/-
2025void QGraphicsView::ensureVisible(const QGraphicsItem *item, int xmargin, int ymargin)-
2026{-
2027 ensureVisible(item->sceneBoundingRect(), xmargin, ymargin);-
2028}-
2029-
2030/*!-
2031 Scales the view matrix and scrolls the scroll bars to ensure that the-
2032 scene rectangle \a rect fits inside the viewport. \a rect must be inside-
2033 the scene rect; otherwise, fitInView() cannot guarantee that the whole-
2034 rect is visible.-
2035-
2036 This function keeps the view's rotation, translation, or shear. The view-
2037 is scaled according to \a aspectRatioMode. \a rect will be centered in the-
2038 view if it does not fit tightly.-
2039-
2040 It's common to call fitInView() from inside a reimplementation of-
2041 resizeEvent(), to ensure that the whole scene, or parts of the scene,-
2042 scales automatically to fit the new size of the viewport as the view is-
2043 resized. Note though, that calling fitInView() from inside resizeEvent()-
2044 can lead to unwanted resize recursion, if the new transformation toggles-
2045 the automatic state of the scrollbars. You can toggle the scrollbar-
2046 policies to always on or always off to prevent this (see-
2047 horizontalScrollBarPolicy() and verticalScrollBarPolicy()).-
2048-
2049 If \a rect is empty, or if the viewport is too small, this-
2050 function will do nothing.-
2051-
2052 \sa setTransform(), ensureVisible(), centerOn()-
2053*/-
2054void QGraphicsView::fitInView(const QRectF &rect, Qt::AspectRatioMode aspectRatioMode)-
2055{-
2056 Q_D(QGraphicsView);-
2057 if (!d->scene || rect.isNull())-
2058 return;-
2059-
2060 // Reset the view scale to 1:1.-
2061 QRectF unity = d->matrix.mapRect(QRectF(0, 0, 1, 1));-
2062 if (unity.isEmpty())-
2063 return;-
2064 scale(1 / unity.width(), 1 / unity.height());-
2065-
2066 // Find the ideal x / y scaling ratio to fit \a rect in the view.-
2067 int margin = 2;-
2068 QRectF viewRect = viewport()->rect().adjusted(margin, margin, -margin, -margin);-
2069 if (viewRect.isEmpty())-
2070 return;-
2071 QRectF sceneRect = d->matrix.mapRect(rect);-
2072 if (sceneRect.isEmpty())-
2073 return;-
2074 qreal xratio = viewRect.width() / sceneRect.width();-
2075 qreal yratio = viewRect.height() / sceneRect.height();-
2076-
2077 // Respect the aspect ratio mode.-
2078 switch (aspectRatioMode) {-
2079 case Qt::KeepAspectRatio:-
2080 xratio = yratio = qMin(xratio, yratio);-
2081 break;-
2082 case Qt::KeepAspectRatioByExpanding:-
2083 xratio = yratio = qMax(xratio, yratio);-
2084 break;-
2085 case Qt::IgnoreAspectRatio:-
2086 break;-
2087 }-
2088-
2089 // Scale and center on the center of \a rect.-
2090 scale(xratio, yratio);-
2091 centerOn(rect.center());-
2092}-
2093-
2094/*!-
2095 \fn void QGraphicsView::fitInView(qreal x, qreal y, qreal w, qreal h,-
2096 Qt::AspectRatioMode aspectRatioMode = Qt::IgnoreAspectRatio)-
2097-
2098 \overload-
2099-
2100 This convenience function is equivalent to calling-
2101 fitInView(QRectF(\a x, \a y, \a w, \a h), \a aspectRatioMode).-
2102-
2103 \sa ensureVisible(), centerOn()-
2104*/-
2105-
2106/*!-
2107 \overload-
2108-
2109 Ensures that \a item fits tightly inside the view, scaling the view-
2110 according to \a aspectRatioMode.-
2111-
2112 \sa ensureVisible(), centerOn()-
2113*/-
2114void QGraphicsView::fitInView(const QGraphicsItem *item, Qt::AspectRatioMode aspectRatioMode)-
2115{-
2116 QPainterPath path = item->isClipped() ? item->clipPath() : item->shape();-
2117 if (item->d_ptr->hasTranslateOnlySceneTransform()) {-
2118 path.translate(item->d_ptr->sceneTransform.dx(), item->d_ptr->sceneTransform.dy());-
2119 fitInView(path.boundingRect(), aspectRatioMode);-
2120 } else {-
2121 fitInView(item->d_ptr->sceneTransform.map(path).boundingRect(), aspectRatioMode);-
2122 }-
2123}-
2124-
2125/*!-
2126 Renders the \a source rect, which is in view coordinates, from the scene-
2127 into \a target, which is in paint device coordinates, using \a-
2128 painter. This function is useful for capturing the contents of the view-
2129 onto a paint device, such as a QImage (e.g., to take a screenshot), or for-
2130 printing to QPrinter. For example:-
2131-
2132 \snippet code/src_gui_graphicsview_qgraphicsview.cpp 4-
2133-
2134 If \a source is a null rect, this function will use viewport()->rect() to-
2135 determine what to draw. If \a target is a null rect, the full dimensions-
2136 of \a painter's paint device (e.g., for a QPrinter, the page size) will be-
2137 used.-
2138-
2139 The source rect contents will be transformed according to \a-
2140 aspectRatioMode to fit into the target rect. By default, the aspect ratio-
2141 is kept, and \a source is scaled to fit in \a target.-
2142-
2143 \sa QGraphicsScene::render()-
2144*/-
2145void QGraphicsView::render(QPainter *painter, const QRectF &target, const QRect &source,-
2146 Qt::AspectRatioMode aspectRatioMode)-
2147{-
2148 // ### Switch to using the recursive rendering algorithm instead.-
2149-
2150 Q_D(QGraphicsView);-
2151 if (!d->scene || !(painter && painter->isActive()))-
2152 return;-
2153-
2154 // Default source rect = viewport rect-
2155 QRect sourceRect = source;-
2156 if (source.isNull())-
2157 sourceRect = viewport()->rect();-
2158-
2159 // Default target rect = device rect-
2160 QRectF targetRect = target;-
2161 if (target.isNull()) {-
2162 if (painter->device()->devType() == QInternal::Picture)-
2163 targetRect = sourceRect;-
2164 else-
2165 targetRect.setRect(0, 0, painter->device()->width(), painter->device()->height());-
2166 }-
2167-
2168 // Find the ideal x / y scaling ratio to fit \a source into \a target.-
2169 qreal xratio = targetRect.width() / sourceRect.width();-
2170 qreal yratio = targetRect.height() / sourceRect.height();-
2171-
2172 // Scale according to the aspect ratio mode.-
2173 switch (aspectRatioMode) {-
2174 case Qt::KeepAspectRatio:-
2175 xratio = yratio = qMin(xratio, yratio);-
2176 break;-
2177 case Qt::KeepAspectRatioByExpanding:-
2178 xratio = yratio = qMax(xratio, yratio);-
2179 break;-
2180 case Qt::IgnoreAspectRatio:-
2181 break;-
2182 }-
2183-
2184 // Find all items to draw, and reverse the list (we want to draw-
2185 // in reverse order).-
2186 QPolygonF sourceScenePoly = mapToScene(sourceRect.adjusted(-1, -1, 1, 1));-
2187 QList<QGraphicsItem *> itemList = d->scene->items(sourceScenePoly,-
2188 Qt::IntersectsItemBoundingRect);-
2189 QGraphicsItem **itemArray = new QGraphicsItem *[itemList.size()];-
2190 int numItems = itemList.size();-
2191 for (int i = 0; i < numItems; ++i)-
2192 itemArray[numItems - i - 1] = itemList.at(i);-
2193 itemList.clear();-
2194-
2195 // Setup painter matrix.-
2196 QTransform moveMatrix = QTransform::fromTranslate(-d->horizontalScroll(), -d->verticalScroll());-
2197 QTransform painterMatrix = d->matrix * moveMatrix;-
2198 painterMatrix *= QTransform()-
2199 .translate(targetRect.left(), targetRect.top())-
2200 .scale(xratio, yratio)-
2201 .translate(-sourceRect.left(), -sourceRect.top());-
2202-
2203 // Generate the style options-
2204 QStyleOptionGraphicsItem *styleOptionArray = d->allocStyleOptionsArray(numItems);-
2205 for (int i = 0; i < numItems; ++i)-
2206 itemArray[i]->d_ptr->initStyleOption(&styleOptionArray[i], painterMatrix, targetRect.toRect());-
2207-
2208 painter->save();-
2209-
2210 // Clip in device coordinates to avoid QRegion transformations.-
2211 painter->setClipRect(targetRect);-
2212 QPainterPath path;-
2213 path.addPolygon(sourceScenePoly);-
2214 path.closeSubpath();-
2215 painter->setClipPath(painterMatrix.map(path), Qt::IntersectClip);-
2216-
2217 // Transform the painter.-
2218 painter->setTransform(painterMatrix, true);-
2219-
2220 // Render the scene.-
2221 QRectF sourceSceneRect = sourceScenePoly.boundingRect();-
2222 drawBackground(painter, sourceSceneRect);-
2223 drawItems(painter, numItems, itemArray, styleOptionArray);-
2224 drawForeground(painter, sourceSceneRect);-
2225-
2226 delete [] itemArray;-
2227 d->freeStyleOptionsArray(styleOptionArray);-
2228-
2229 painter->restore();-
2230}-
2231-
2232/*!-
2233 Returns a list of all the items in the associated scene, in descending-
2234 stacking order (i.e., the first item in the returned list is the uppermost-
2235 item).-
2236-
2237 \sa QGraphicsScene::items(), {QGraphicsItem#Sorting}{Sorting}-
2238*/-
2239QList<QGraphicsItem *> QGraphicsView::items() const-
2240{-
2241 Q_D(const QGraphicsView);-
2242 if (!d->scene)-
2243 return QList<QGraphicsItem *>();-
2244 return d->scene->items();-
2245}-
2246-
2247/*!-
2248 Returns a list of all the items at the position \a pos in the view. The-
2249 items are listed in descending stacking order (i.e., the first item in the-
2250 list is the uppermost item, and the last item is the lowermost item). \a-
2251 pos is in viewport coordinates.-
2252-
2253 This function is most commonly called from within mouse event handlers in-
2254 a subclass in QGraphicsView. \a pos is in untransformed viewport-
2255 coordinates, just like QMouseEvent::pos().-
2256-
2257 \snippet code/src_gui_graphicsview_qgraphicsview.cpp 5-
2258-
2259 \sa QGraphicsScene::items(), {QGraphicsItem#Sorting}{Sorting}-
2260*/-
2261QList<QGraphicsItem *> QGraphicsView::items(const QPoint &pos) const-
2262{-
2263 Q_D(const QGraphicsView);-
2264 if (!d->scene)-
2265 return QList<QGraphicsItem *>();-
2266 // ### Unify these two, and use the items(QPointF) version in-
2267 // QGraphicsScene instead. The scene items function could use the viewport-
2268 // transform to map the point to a rect/polygon.-
2269 if ((d->identityMatrix || d->matrix.type() <= QTransform::TxScale)) {-
2270 // Use the rect version-
2271 QTransform xinv = viewportTransform().inverted();-
2272 return d->scene->items(xinv.mapRect(QRectF(pos.x(), pos.y(), 1, 1)),-
2273 Qt::IntersectsItemShape,-
2274 Qt::DescendingOrder,-
2275 viewportTransform());-
2276 }-
2277 // Use the polygon version-
2278 return d->scene->items(mapToScene(pos.x(), pos.y(), 1, 1),-
2279 Qt::IntersectsItemShape,-
2280 Qt::DescendingOrder,-
2281 viewportTransform());-
2282}-
2283-
2284/*!-
2285 \fn QGraphicsView::items(int x, int y) const-
2286-
2287 This function is provided for convenience. It's equivalent to calling-
2288 items(QPoint(\a x, \a y)).-
2289*/-
2290-
2291/*!-
2292 \overload-
2293-
2294 Returns a list of all the items that, depending on \a mode, are either-
2295 contained by or intersect with \a rect. \a rect is in viewport-
2296 coordinates.-
2297-
2298 The default value for \a mode is Qt::IntersectsItemShape; all items whose-
2299 exact shape intersects with or is contained by \a rect are returned.-
2300-
2301 The items are sorted in descending stacking order (i.e., the first item in-
2302 the returned list is the uppermost item).-
2303-
2304 \sa itemAt(), items(), mapToScene(), {QGraphicsItem#Sorting}{Sorting}-
2305*/-
2306QList<QGraphicsItem *> QGraphicsView::items(const QRect &rect, Qt::ItemSelectionMode mode) const-
2307{-
2308 Q_D(const QGraphicsView);-
2309 if (!d->scene)-
2310 return QList<QGraphicsItem *>();-
2311 return d->scene->items(mapToScene(rect), mode, Qt::DescendingOrder, viewportTransform());-
2312}-
2313-
2314/*!-
2315 \fn QList<QGraphicsItem *> QGraphicsView::items(int x, int y, int w, int h, Qt::ItemSelectionMode mode) const-
2316 \since 4.3-
2317-
2318 This convenience function is equivalent to calling items(QRectF(\a x, \a-
2319 y, \a w, \a h), \a mode).-
2320*/-
2321-
2322/*!-
2323 \overload-
2324-
2325 Returns a list of all the items that, depending on \a mode, are either-
2326 contained by or intersect with \a polygon. \a polygon is in viewport-
2327 coordinates.-
2328-
2329 The default value for \a mode is Qt::IntersectsItemShape; all items whose-
2330 exact shape intersects with or is contained by \a polygon are returned.-
2331-
2332 The items are sorted by descending stacking order (i.e., the first item in-
2333 the returned list is the uppermost item).-
2334-
2335 \sa itemAt(), items(), mapToScene(), {QGraphicsItem#Sorting}{Sorting}-
2336*/-
2337QList<QGraphicsItem *> QGraphicsView::items(const QPolygon &polygon, Qt::ItemSelectionMode mode) const-
2338{-
2339 Q_D(const QGraphicsView);-
2340 if (!d->scene)-
2341 return QList<QGraphicsItem *>();-
2342 return d->scene->items(mapToScene(polygon), mode, Qt::DescendingOrder, viewportTransform());-
2343}-
2344-
2345/*!-
2346 \overload-
2347-
2348 Returns a list of all the items that, depending on \a mode, are either-
2349 contained by or intersect with \a path. \a path is in viewport-
2350 coordinates.-
2351-
2352 The default value for \a mode is Qt::IntersectsItemShape; all items whose-
2353 exact shape intersects with or is contained by \a path are returned.-
2354-
2355 \sa itemAt(), items(), mapToScene(), {QGraphicsItem#Sorting}{Sorting}-
2356*/-
2357QList<QGraphicsItem *> QGraphicsView::items(const QPainterPath &path, Qt::ItemSelectionMode mode) const-
2358{-
2359 Q_D(const QGraphicsView);-
2360 if (!d->scene)-
2361 return QList<QGraphicsItem *>();-
2362 return d->scene->items(mapToScene(path), mode, Qt::DescendingOrder, viewportTransform());-
2363}-
2364-
2365/*!-
2366 Returns the item at position \a pos, which is in viewport coordinates.-
2367 If there are several items at this position, this function returns-
2368 the topmost item.-
2369-
2370 Example:-
2371-
2372 \snippet code/src_gui_graphicsview_qgraphicsview.cpp 6-
2373-
2374 \sa items(), {QGraphicsItem#Sorting}{Sorting}-
2375*/-
2376QGraphicsItem *QGraphicsView::itemAt(const QPoint &pos) const-
2377{-
2378 Q_D(const QGraphicsView);-
2379 if (!d->scene)
!d->sceneDescription
TRUEnever evaluated
FALSEnever evaluated
0
2380 return 0;
never executed: return 0;
0
2381 const QList<QGraphicsItem *> itemsAtPos = items(pos);-
2382 return itemsAtPos.isEmpty() ? 0 : itemsAtPos.first();
never executed: return itemsAtPos.isEmpty() ? 0 : itemsAtPos.first();
0
2383}-
2384-
2385/*!-
2386 \overload-
2387 \fn QGraphicsItem *QGraphicsView::itemAt(int x, int y) const-
2388-
2389 This function is provided for convenience. It's equivalent to-
2390 calling itemAt(QPoint(\a x, \a y)).-
2391*/-
2392-
2393/*!-
2394 Returns the viewport coordinate \a point mapped to scene coordinates.-
2395-
2396 Note: It can be useful to map the whole rectangle covered by the pixel at-
2397 \a point instead of the point itself. To do this, you can call-
2398 mapToScene(QRect(\a point, QSize(2, 2))).-
2399-
2400 \sa mapFromScene()-
2401*/-
2402QPointF QGraphicsView::mapToScene(const QPoint &point) const-
2403{-
2404 Q_D(const QGraphicsView);-
2405 QPointF p = point;-
2406 p.rx() += d->horizontalScroll();-
2407 p.ry() += d->verticalScroll();-
2408 return d->identityMatrix ? p : d->matrix.inverted().map(p);-
2409}-
2410-
2411/*!-
2412 \fn QGraphicsView::mapToScene(int x, int y) const-
2413-
2414 This function is provided for convenience. It's equivalent to calling-
2415 mapToScene(QPoint(\a x, \a y)).-
2416*/-
2417-
2418/*!-
2419 Returns the viewport rectangle \a rect mapped to a scene coordinate-
2420 polygon.-
2421-
2422 \sa mapFromScene()-
2423*/-
2424QPolygonF QGraphicsView::mapToScene(const QRect &rect) const-
2425{-
2426 Q_D(const QGraphicsView);-
2427 if (!rect.isValid())-
2428 return QPolygonF();-
2429-
2430 QPointF scrollOffset(d->horizontalScroll(), d->verticalScroll());-
2431 QRect r = rect.adjusted(0, 0, 1, 1);-
2432 QPointF tl = scrollOffset + r.topLeft();-
2433 QPointF tr = scrollOffset + r.topRight();-
2434 QPointF br = scrollOffset + r.bottomRight();-
2435 QPointF bl = scrollOffset + r.bottomLeft();-
2436-
2437 QPolygonF poly(4);-
2438 if (!d->identityMatrix) {-
2439 QTransform x = d->matrix.inverted();-
2440 poly[0] = x.map(tl);-
2441 poly[1] = x.map(tr);-
2442 poly[2] = x.map(br);-
2443 poly[3] = x.map(bl);-
2444 } else {-
2445 poly[0] = tl;-
2446 poly[1] = tr;-
2447 poly[2] = br;-
2448 poly[3] = bl;-
2449 }-
2450 return poly;-
2451}-
2452-
2453/*!-
2454 \fn QGraphicsView::mapToScene(int x, int y, int w, int h) const-
2455-
2456 This function is provided for convenience. It's equivalent to calling-
2457 mapToScene(QRect(\a x, \a y, \a w, \a h)).-
2458*/-
2459-
2460/*!-
2461 Returns the viewport polygon \a polygon mapped to a scene coordinate-
2462 polygon.-
2463-
2464 \sa mapFromScene()-
2465*/-
2466QPolygonF QGraphicsView::mapToScene(const QPolygon &polygon) const-
2467{-
2468 QPolygonF poly;-
2469 poly.reserve(polygon.count());-
2470 foreachfor (const QPoint &point ,: polygon)-
2471 poly << mapToScene(point);
never executed: poly << mapToScene(point);
0
2472 return poly;
never executed: return poly;
0
2473}-
2474-
2475/*!-
2476 Returns the viewport painter path \a path mapped to a scene coordinate-
2477 painter path.-
2478-
2479 \sa mapFromScene()-
2480*/-
2481QPainterPath QGraphicsView::mapToScene(const QPainterPath &path) const-
2482{-
2483 Q_D(const QGraphicsView);-
2484 QTransform matrix = QTransform::fromTranslate(d->horizontalScroll(), d->verticalScroll());-
2485 matrix *= d->matrix.inverted();-
2486 return matrix.map(path);-
2487}-
2488-
2489/*!-
2490 Returns the scene coordinate \a point to viewport coordinates.-
2491-
2492 \sa mapToScene()-
2493*/-
2494QPoint QGraphicsView::mapFromScene(const QPointF &point) const-
2495{-
2496 Q_D(const QGraphicsView);-
2497 QPointF p = d->identityMatrix ? point : d->matrix.map(point);-
2498 p.rx() -= d->horizontalScroll();-
2499 p.ry() -= d->verticalScroll();-
2500 return p.toPoint();-
2501}-
2502-
2503/*!-
2504 \fn QGraphicsView::mapFromScene(qreal x, qreal y) const-
2505-
2506 This function is provided for convenience. It's equivalent to-
2507 calling mapFromScene(QPointF(\a x, \a y)).-
2508*/-
2509-
2510/*!-
2511 Returns the scene rectangle \a rect to a viewport coordinate-
2512 polygon.-
2513-
2514 \sa mapToScene()-
2515*/-
2516QPolygon QGraphicsView::mapFromScene(const QRectF &rect) const-
2517{-
2518 Q_D(const QGraphicsView);-
2519 QPointF tl;-
2520 QPointF tr;-
2521 QPointF br;-
2522 QPointF bl;-
2523 if (!d->identityMatrix) {-
2524 const QTransform &x = d->matrix;-
2525 tl = x.map(rect.topLeft());-
2526 tr = x.map(rect.topRight());-
2527 br = x.map(rect.bottomRight());-
2528 bl = x.map(rect.bottomLeft());-
2529 } else {-
2530 tl = rect.topLeft();-
2531 tr = rect.topRight();-
2532 br = rect.bottomRight();-
2533 bl = rect.bottomLeft();-
2534 }-
2535 QPointF scrollOffset(d->horizontalScroll(), d->verticalScroll());-
2536 tl -= scrollOffset;-
2537 tr -= scrollOffset;-
2538 br -= scrollOffset;-
2539 bl -= scrollOffset;-
2540-
2541 QPolygon poly(4);-
2542 poly[0] = tl.toPoint();-
2543 poly[1] = tr.toPoint();-
2544 poly[2] = br.toPoint();-
2545 poly[3] = bl.toPoint();-
2546 return poly;-
2547}-
2548-
2549/*!-
2550 \fn QGraphicsView::mapFromScene(qreal x, qreal y, qreal w, qreal h) const-
2551-
2552 This function is provided for convenience. It's equivalent to-
2553 calling mapFromScene(QRectF(\a x, \a y, \a w, \a h)).-
2554*/-
2555-
2556/*!-
2557 Returns the scene coordinate polygon \a polygon to a viewport coordinate-
2558 polygon.-
2559-
2560 \sa mapToScene()-
2561*/-
2562QPolygon QGraphicsView::mapFromScene(const QPolygonF &polygon) const-
2563{-
2564 QPolygon poly;-
2565 poly.reserve(polygon.count());-
2566 foreachfor (const QPointF &point ,: polygon)-
2567 poly << mapFromScene(point);
never executed: poly << mapFromScene(point);
0
2568 return poly;
never executed: return poly;
0
2569}-
2570-
2571/*!-
2572 Returns the scene coordinate painter path \a path to a viewport coordinate-
2573 painter path.-
2574-
2575 \sa mapToScene()-
2576*/-
2577QPainterPath QGraphicsView::mapFromScene(const QPainterPath &path) const-
2578{-
2579 Q_D(const QGraphicsView);-
2580 QTransform matrix = d->matrix;-
2581 matrix *= QTransform::fromTranslate(-d->horizontalScroll(), -d->verticalScroll());-
2582 return matrix.map(path);-
2583}-
2584-
2585/*!-
2586 \reimp-
2587*/-
2588QVariant QGraphicsView::inputMethodQuery(Qt::InputMethodQuery query) const-
2589{-
2590 Q_D(const QGraphicsView);-
2591 if (!d->scene)-
2592 return QVariant();-
2593-
2594 QVariant value = d->scene->inputMethodQuery(query);-
2595 if (value.type() == QVariant::RectF)-
2596 value = d->mapRectFromScene(value.toRectF());-
2597 else if (value.type() == QVariant::PointF)-
2598 value = mapFromScene(value.toPointF());-
2599 else if (value.type() == QVariant::Rect)-
2600 value = d->mapRectFromScene(value.toRect()).toRect();-
2601 else if (value.type() == QVariant::Point)-
2602 value = mapFromScene(value.toPoint());-
2603 return value;-
2604}-
2605-
2606/*!-
2607 \property QGraphicsView::backgroundBrush-
2608 \brief the background brush of the scene.-
2609-
2610 This property sets the background brush for the scene in this view. It is-
2611 used to override the scene's own background, and defines the behavior of-
2612 drawBackground(). To provide custom background drawing for this view, you-
2613 can reimplement drawBackground() instead.-
2614-
2615 By default, this property contains a brush with the Qt::NoBrush pattern.-
2616-
2617 \sa QGraphicsScene::backgroundBrush, foregroundBrush-
2618*/-
2619QBrush QGraphicsView::backgroundBrush() const-
2620{-
2621 Q_D(const QGraphicsView);-
2622 return d->backgroundBrush;-
2623}-
2624void QGraphicsView::setBackgroundBrush(const QBrush &brush)-
2625{-
2626 Q_D(QGraphicsView);-
2627 d->backgroundBrush = brush;-
2628 d->updateAll();-
2629-
2630 if (d->cacheMode & CacheBackground) {-
2631 // Invalidate the background pixmap-
2632 d->mustResizeBackgroundPixmap = true;-
2633 }-
2634}-
2635-
2636/*!-
2637 \property QGraphicsView::foregroundBrush-
2638 \brief the foreground brush of the scene.-
2639-
2640 This property sets the foreground brush for the scene in this view. It is-
2641 used to override the scene's own foreground, and defines the behavior of-
2642 drawForeground(). To provide custom foreground drawing for this view, you-
2643 can reimplement drawForeground() instead.-
2644-
2645 By default, this property contains a brush with the Qt::NoBrush pattern.-
2646-
2647 \sa QGraphicsScene::foregroundBrush, backgroundBrush-
2648*/-
2649QBrush QGraphicsView::foregroundBrush() const-
2650{-
2651 Q_D(const QGraphicsView);-
2652 return d->foregroundBrush;-
2653}-
2654void QGraphicsView::setForegroundBrush(const QBrush &brush)-
2655{-
2656 Q_D(QGraphicsView);-
2657 d->foregroundBrush = brush;-
2658 d->updateAll();-
2659}-
2660-
2661/*!-
2662 Schedules an update of the scene rectangles \a rects.-
2663-
2664 \sa QGraphicsScene::changed()-
2665*/-
2666void QGraphicsView::updateScene(const QList<QRectF> &rects)-
2667{-
2668 // ### Note: Since 4.5, this slot is only called if the user explicitly-
2669 // establishes a connection between the scene and the view, as the scene-
2670 // and view are no longer connected. We need to keep it working (basically-
2671 // leave it as it is), but the new delivery path is through-
2672 // QGraphicsScenePrivate::itemUpdate().-
2673 Q_D(QGraphicsView);-
2674 if (d->fullUpdatePending || d->viewportUpdateMode == QGraphicsView::NoViewportUpdate)
d->fullUpdatePendingDescription
TRUEnever evaluated
FALSEnever evaluated
d->viewportUpd...ViewportUpdateDescription
TRUEnever evaluated
FALSEnever evaluated
0
2675 return;
never executed: return;
0
2676-
2677 // Extract and reset dirty scene rect info.-
2678 QVector<QRect> dirtyViewportRects;-
2679 const QVector<QRect> &dirtyRects = d->dirtyRegion.rects();-
2680 const int dirtyRectsCount = dirtyRects.size();-
2681 dirtyViewportRects.reserve(dirtyRectsCount + rects.count());-
2682 for (int i = 0; i < dirtyRectsCount; ++i)
i < dirtyRectsCountDescription
TRUEnever evaluated
FALSEnever evaluated
0
2683 dirtyViewportRects += dirtyRects.at(i);
never executed: dirtyViewportRects += dirtyRects.at(i);
0
2684 d->dirtyRegion = QRegion();-
2685 d->dirtyBoundingRect = QRect();-
2686-
2687 bool fullUpdate = !d->accelerateScrolling || d->viewportUpdateMode == QGraphicsView::FullViewportUpdate;
!d->accelerateScrollingDescription
TRUEnever evaluated
FALSEnever evaluated
d->viewportUpd...ViewportUpdateDescription
TRUEnever evaluated
FALSEnever evaluated
0
2688 bool boundingRectUpdate = (d->viewportUpdateMode == QGraphicsView::BoundingRectViewportUpdate)
(d->viewportUp...iewportUpdate)Description
TRUEnever evaluated
FALSEnever evaluated
0
2689 || (d->viewportUpdateMode == QGraphicsView::SmartViewportUpdate
d->viewportUpd...ViewportUpdateDescription
TRUEnever evaluated
FALSEnever evaluated
0
2690 && ((dirtyViewportRects.size() + rects.size()) >= QGRAPHICSVIEW_REGION_RECT_THRESHOLD));
((dirtyViewpor...ECT_THRESHOLD)Description
TRUEnever evaluated
FALSEnever evaluated
0
2691-
2692 QRegion updateRegion;-
2693 QRect boundingRect;-
2694 QRect viewportRect = viewport()->rect();-
2695 bool redraw = false;-
2696 QTransform transform = viewportTransform();-
2697-
2698 // Convert scene rects to viewport rects.-
2699 foreachfor (const QRectF &rect ,: rects) {-
2700 QRect xrect = transform.mapRect(rect).toAlignedRect();-
2701 if (!(d->optimizationFlags & DontAdjustForAntialiasing))
!(d->optimizat...rAntialiasing)Description
TRUEnever evaluated
FALSEnever evaluated
0
2702 xrect.adjust(-2, -2, 2, 2);
never executed: xrect.adjust(-2, -2, 2, 2);
0
2703 else-
2704 xrect.adjust(-1, -1, 1, 1);
never executed: xrect.adjust(-1, -1, 1, 1);
0
2705 if (!viewportRect.intersects(xrect))
!viewportRect....ersects(xrect)Description
TRUEnever evaluated
FALSEnever evaluated
0
2706 continue;
never executed: continue;
0
2707 dirtyViewportRects << xrect;-
2708 }
never executed: end of block
0
2709-
2710 foreach (const QRect &rect, dirtyViewportRects) {-
2711 // Add the exposed rect to the update region. In rect update-
2712 // mode, we only count the bounding rect of items.-
2713 if (!boundingRectUpdate) {
!boundingRectUpdateDescription
TRUEnever evaluated
FALSEnever evaluated
0
2714 updateRegion += rect;-
2715 } else {
never executed: end of block
0
2716 boundingRect |= rect;-
2717 }
never executed: end of block
0
2718 redraw = true;-
2719 if (fullUpdate) {
fullUpdateDescription
TRUEnever evaluated
FALSEnever evaluated
0
2720 // If fullUpdate is true and we found a visible dirty rect,-
2721 // we're done.-
2722 break;
never executed: break;
0
2723 }-
2724 }
never executed: end of block
0
2725-
2726 if (!redraw)
!redrawDescription
TRUEnever evaluated
FALSEnever evaluated
0
2727 return;
never executed: return;
0
2728-
2729 if (fullUpdate)
fullUpdateDescription
TRUEnever evaluated
FALSEnever evaluated
0
2730 viewport()->update();
never executed: viewport()->update();
0
2731 else if (boundingRectUpdate)
boundingRectUpdateDescription
TRUEnever evaluated
FALSEnever evaluated
0
2732 viewport()->update(boundingRect);
never executed: viewport()->update(boundingRect);
0
2733 else-
2734 viewport()->update(updateRegion);
never executed: viewport()->update(updateRegion);
0
2735}-
2736-
2737/*!-
2738 Notifies QGraphicsView that the scene's scene rect has changed. \a rect-
2739 is the new scene rect. If the view already has an explicitly set scene-
2740 rect, this function does nothing.-
2741-
2742 \sa sceneRect, QGraphicsScene::sceneRectChanged()-
2743*/-
2744void QGraphicsView::updateSceneRect(const QRectF &rect)-
2745{-
2746 Q_D(QGraphicsView);-
2747 if (!d->hasSceneRect) {-
2748 d->sceneRect = rect;-
2749 d->recalculateContentSize();-
2750 }-
2751}-
2752-
2753/*!-
2754 This slot is called by QAbstractScrollArea after setViewport() has been-
2755 called. Reimplement this function in a subclass of QGraphicsView to-
2756 initialize the new viewport \a widget before it is used.-
2757-
2758 \sa setViewport()-
2759*/-
2760void QGraphicsView::setupViewport(QWidget *widget)-
2761{-
2762 Q_D(QGraphicsView);-
2763-
2764 if (!widget) {
!widgetDescription
TRUEnever evaluated
FALSEnever evaluated
0
2765 qWarning("QGraphicsView::setupViewport: cannot initialize null widget");-
2766 return;
never executed: return;
0
2767 }-
2768-
2769 const bool isGLWidget = widget->inherits("QGLWidget") || widget->inherits("QOpenGLWidget");
widget->inherits("QGLWidget")Description
TRUEnever evaluated
FALSEnever evaluated
widget->inheri...OpenGLWidget")Description
TRUEnever evaluated
FALSEnever evaluated
0
2770-
2771 d->accelerateScrolling = !(isGLWidget);-
2772-
2773 widget->setFocusPolicy(Qt::StrongFocus);-
2774-
2775 if (!isGLWidget) {
!isGLWidgetDescription
TRUEnever evaluated
FALSEnever evaluated
0
2776 // autoFillBackground enables scroll acceleration.-
2777 widget->setAutoFillBackground(true);-
2778 }
never executed: end of block
0
2779-
2780 // We are only interested in mouse tracking if items-
2781 // accept hover events or use non-default cursors or if-
2782 // AnchorUnderMouse is used as transformation or resize anchor.-
2783 if ((d->scene && (!d->scene->d_func()->allItemsIgnoreHoverEvents
d->sceneDescription
TRUEnever evaluated
FALSEnever evaluated
!d->scene->d_f...oreHoverEventsDescription
TRUEnever evaluated
FALSEnever evaluated
0
2784 || !d->scene->d_func()->allItemsUseDefaultCursor))
!d->scene->d_f...eDefaultCursorDescription
TRUEnever evaluated
FALSEnever evaluated
0
2785 || d->transformationAnchor == AnchorUnderMouse
d->transformat...chorUnderMouseDescription
TRUEnever evaluated
FALSEnever evaluated
0
2786 || d->resizeAnchor == AnchorUnderMouse) {
d->resizeAncho...chorUnderMouseDescription
TRUEnever evaluated
FALSEnever evaluated
0
2787 widget->setMouseTracking(true);-
2788 }
never executed: end of block
0
2789-
2790 // enable touch events if any items is interested in them-
2791 if (d->scene && !d->scene->d_func()->allItemsIgnoreTouchEvents)
d->sceneDescription
TRUEnever evaluated
FALSEnever evaluated
!d->scene->d_f...oreTouchEventsDescription
TRUEnever evaluated
FALSEnever evaluated
0
2792 widget->setAttribute(Qt::WA_AcceptTouchEvents);
never executed: widget->setAttribute(Qt::WA_AcceptTouchEvents);
0
2793-
2794#ifndef QT_NO_GESTURES-
2795 if (d->scene) {
d->sceneDescription
TRUEnever evaluated
FALSEnever evaluated
0
2796 foreach (Qt::GestureType gesture,const auto gestures = d->scene->d_func()->grabbedGestures.keys())();-
2797 for (Qt::GestureType gesture : gestures)-
2798 widget->grabGesture(gesture);
never executed: widget->grabGesture(gesture);
0
2799 }
never executed: end of block
0
2800#endif-
2801-
2802 widget->setAcceptDrops(acceptDrops());-
2803}
never executed: end of block
0
2804-
2805/*!-
2806 \reimp-
2807*/-
2808bool QGraphicsView::event(QEvent *event)-
2809{-
2810 Q_D(QGraphicsView);-
2811-
2812 if (d->sceneInteractionAllowed) {-
2813 switch (event->type()) {-
2814 case QEvent::ShortcutOverride:-
2815 if (d->scene)-
2816 return QApplication::sendEvent(d->scene, event);-
2817 break;-
2818 case QEvent::KeyPress:-
2819 if (d->scene) {-
2820 QKeyEvent *k = static_cast<QKeyEvent *>(event);-
2821 if (k->key() == Qt::Key_Tab || k->key() == Qt::Key_Backtab) {-
2822 // Send the key events to the scene. This will invoke the-
2823 // scene's tab focus handling, and if the event is-
2824 // accepted, we return (prevent further event delivery),-
2825 // and the base implementation will call QGraphicsView's-
2826 // focusNextPrevChild() function. If the event is ignored,-
2827 // we fall back to standard tab focus handling.-
2828 QApplication::sendEvent(d->scene, event);-
2829 if (event->isAccepted())-
2830 return true;-
2831 // Ensure the event doesn't propagate just because the-
2832 // scene ignored it. If the event propagates, then tab-
2833 // handling will be called twice (this and parent).-
2834 event->accept();-
2835 }-
2836 }-
2837 break;-
2838 default:-
2839 break;-
2840 }-
2841 }-
2842-
2843 return QAbstractScrollArea::event(event);-
2844}-
2845-
2846/*!-
2847 \reimp-
2848*/-
2849bool QGraphicsView::viewportEvent(QEvent *event)-
2850{-
2851 Q_D(QGraphicsView);-
2852 if (!d->scene)
!d->sceneDescription
TRUEnever evaluated
FALSEnever evaluated
0
2853 return QAbstractScrollArea::viewportEvent(event);
never executed: return QAbstractScrollArea::viewportEvent(event);
0
2854-
2855 switch (event->type()) {-
2856 case QEvent::Enter:
never executed: case QEvent::Enter:
0
2857 QApplication::sendEvent(d->scene, event);-
2858 break;
never executed: break;
0
2859 case QEvent::WindowActivate:
never executed: case QEvent::WindowActivate:
0
2860 QApplication::sendEvent(d->scene, event);-
2861 break;
never executed: break;
0
2862 case QEvent::WindowDeactivate:
never executed: case QEvent::WindowDeactivate:
0
2863 // ### This is a temporary fix for until we get proper mouse-
2864 // grab events. mouseGrabberItem should be set to 0 if we lose-
2865 // the mouse grab.-
2866 // Remove all popups when the scene loses focus.-
2867 if (!d->scene->d_func()->popupWidgets.isEmpty())
!d->scene->d_f...gets.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
0
2868 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
2869 QApplication::sendEvent(d->scene, event);-
2870 break;
never executed: break;
0
2871 case QEvent::Show:
never executed: case QEvent::Show:
0
2872 if (d->scene && isActiveWindow()) {
d->sceneDescription
TRUEnever evaluated
FALSEnever evaluated
isActiveWindow()Description
TRUEnever evaluated
FALSEnever evaluated
0
2873 QEvent windowActivate(QEvent::WindowActivate);-
2874 QApplication::sendEvent(d->scene, &windowActivate);-
2875 }
never executed: end of block
0
2876 break;
never executed: break;
0
2877 case QEvent::Hide:
never executed: case QEvent::Hide:
0
2878 // spontaneous event will generate a WindowDeactivate.-
2879 if (!event->spontaneous() && d->scene && isActiveWindow()) {
!event->spontaneous()Description
TRUEnever evaluated
FALSEnever evaluated
d->sceneDescription
TRUEnever evaluated
FALSEnever evaluated
isActiveWindow()Description
TRUEnever evaluated
FALSEnever evaluated
0
2880 QEvent windowDeactivate(QEvent::WindowDeactivate);-
2881 QApplication::sendEvent(d->scene, &windowDeactivate);-
2882 }
never executed: end of block
0
2883 break;
never executed: break;
0
2884 case QEvent::Leave: {
never executed: case QEvent::Leave:
0
2885 // ### This is a temporary fix for until we get proper mouse grab-
2886 // events. activeMouseGrabberItem should be set to 0 if we lose the-
2887 // mouse grab.-
2888 if ((QApplication::activePopupWidget() && QApplication::activePopupWidget() != window())
QApplication::...ePopupWidget()Description
TRUEnever evaluated
FALSEnever evaluated
QApplication::...() != window()Description
TRUEnever evaluated
FALSEnever evaluated
0
2889 || (QApplication::activeModalWidget() && QApplication::activeModalWidget() != window())
QApplication::...eModalWidget()Description
TRUEnever evaluated
FALSEnever evaluated
QApplication::...() != window()Description
TRUEnever evaluated
FALSEnever evaluated
0
2890 || (QApplication::activeWindow() != window())) {
(QApplication:...) != window())Description
TRUEnever evaluated
FALSEnever evaluated
0
2891 if (!d->scene->d_func()->popupWidgets.isEmpty())
!d->scene->d_f...gets.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
0
2892 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
2893 }
never executed: end of block
0
2894 d->useLastMouseEvent = false;-
2895 // a hack to pass a viewport pointer to the scene inside the leave event-
2896 Q_ASSERT(event->d == 0);-
2897 QScopedValueRollback<QEventPrivate *> rb(event->d);-
2898 event->d = reinterpret_cast<QEventPrivate *>(viewport());-
2899 QApplication::sendEvent(d->scene, event);-
2900 break;
never executed: break;
0
2901 }-
2902#ifndef QT_NO_TOOLTIP-
2903 case QEvent::ToolTip: {
never executed: case QEvent::ToolTip:
0
2904 QHelpEvent *toolTip = static_cast<QHelpEvent *>(event);-
2905 QGraphicsSceneHelpEvent helpEvent(QEvent::GraphicsSceneHelp);-
2906 helpEvent.setWidget(viewport());-
2907 helpEvent.setScreenPos(toolTip->globalPos());-
2908 helpEvent.setScenePos(mapToScene(toolTip->pos()));-
2909 QApplication::sendEvent(d->scene, &helpEvent);-
2910 toolTip->setAccepted(helpEvent.isAccepted());-
2911 return true;
never executed: return true;
0
2912 }-
2913#endif-
2914 case QEvent::Paint:
never executed: case QEvent::Paint:
0
2915 // Reset full update-
2916 d->fullUpdatePending = false;-
2917 d->dirtyScrollOffset = QPoint();-
2918 if (d->scene) {
d->sceneDescription
TRUEnever evaluated
FALSEnever evaluated
0
2919 // Check if this view reimplements the updateScene slot; if it-
2920 // does, we can't do direct update delivery and have to fall back-
2921 // to connecting the changed signal.-
2922 if (!d->updateSceneSlotReimplementedChecked) {
!d->updateScen...ementedCheckedDescription
TRUEnever evaluated
FALSEnever evaluated
0
2923 d->updateSceneSlotReimplementedChecked = true;-
2924 const QMetaObject *mo = metaObject();-
2925 if (mo != &QGraphicsView::staticMetaObject) {
mo != &QGraphi...aticMetaObjectDescription
TRUEnever evaluated
FALSEnever evaluated
0
2926 if (mo->indexOfSlot("updateScene(QList<QRectF>)")
mo->indexOfSlo...ist<QRectF>)")Description
TRUEnever evaluated
FALSEnever evaluated
0
2927 != QGraphicsView::staticMetaObject.indexOfSlot("updateScene(QList<QRectF>)")) {
mo->indexOfSlo...ist<QRectF>)")Description
TRUEnever evaluated
FALSEnever evaluated
0
2928 connect(d->scene, SIGNAL(changed(QList<QRectF>)),-
2929 this, SLOT(updateScene(QList<QRectF>)));-
2930 }
never executed: end of block
0
2931 }
never executed: end of block
0
2932 }
never executed: end of block
0
2933 }
never executed: end of block
0
2934 break;
never executed: break;
0
2935 case QEvent::TouchBegin:
never executed: case QEvent::TouchBegin:
0
2936 case QEvent::TouchUpdate:
never executed: case QEvent::TouchUpdate:
0
2937 case QEvent::TouchEnd:
never executed: case QEvent::TouchEnd:
0
2938 {-
2939 if (!isEnabled())
!isEnabled()Description
TRUEnever evaluated
FALSEnever evaluated
0
2940 return false;
never executed: return false;
0
2941-
2942 if (d->scene && d->sceneInteractionAllowed) {
d->sceneDescription
TRUEnever evaluated
FALSEnever evaluated
d->sceneInteractionAllowedDescription
TRUEnever evaluated
FALSEnever evaluated
0
2943 // Convert and deliver the touch event to the scene.-
2944 QTouchEvent *touchEvent = static_cast<QTouchEvent *>(event);-
2945 touchEvent->setTarget(viewport());-
2946 QGraphicsViewPrivate::translateTouchEvent(d, touchEvent);-
2947 (void) QApplication::sendEvent(d->scene, touchEvent);-
2948 } else {
never executed: end of block
0
2949 event->ignore();-
2950 }
never executed: end of block
0
2951-
2952 return true;
never executed: return true;
0
2953 }-
2954#ifndef QT_NO_GESTURES-
2955 case QEvent::Gesture:
never executed: case QEvent::Gesture:
0
2956 case QEvent::GestureOverride:
never executed: case QEvent::GestureOverride:
0
2957 {-
2958 if (!isEnabled())
!isEnabled()Description
TRUEnever evaluated
FALSEnever evaluated
0
2959 return false;
never executed: return false;
0
2960-
2961 if (d->scene && d->sceneInteractionAllowed) {
d->sceneDescription
TRUEnever evaluated
FALSEnever evaluated
d->sceneInteractionAllowedDescription
TRUEnever evaluated
FALSEnever evaluated
0
2962 QGestureEvent *gestureEvent = static_cast<QGestureEvent *>(event);-
2963 gestureEvent->setWidget(viewport());-
2964 (void) QApplication::sendEvent(d->scene, gestureEvent);-
2965 }
never executed: end of block
0
2966 return true;
never executed: return true;
0
2967 }-
2968#endif // QT_NO_GESTURES-
2969 default:
never executed: default:
0
2970 break;
never executed: break;
0
2971 }-
2972-
2973 return QAbstractScrollArea::viewportEvent(event);
never executed: return QAbstractScrollArea::viewportEvent(event);
0
2974}-
2975-
2976#ifndef QT_NO_CONTEXTMENU-
2977/*!-
2978 \reimp-
2979*/-
2980void QGraphicsView::contextMenuEvent(QContextMenuEvent *event)-
2981{-
2982 Q_D(QGraphicsView);-
2983 if (!d->scene || !d->sceneInteractionAllowed)-
2984 return;-
2985-
2986 d->mousePressViewPoint = event->pos();-
2987 d->mousePressScenePoint = mapToScene(d->mousePressViewPoint);-
2988 d->mousePressScreenPoint = event->globalPos();-
2989 d->lastMouseMoveScenePoint = d->mousePressScenePoint;-
2990 d->lastMouseMoveScreenPoint = d->mousePressScreenPoint;-
2991-
2992 QGraphicsSceneContextMenuEvent contextEvent(QEvent::GraphicsSceneContextMenu);-
2993 contextEvent.setWidget(viewport());-
2994 contextEvent.setScenePos(d->mousePressScenePoint);-
2995 contextEvent.setScreenPos(d->mousePressScreenPoint);-
2996 contextEvent.setModifiers(event->modifiers());-
2997 contextEvent.setReason((QGraphicsSceneContextMenuEvent::Reason)(event->reason()));-
2998 contextEvent.setAccepted(event->isAccepted());-
2999 QApplication::sendEvent(d->scene, &contextEvent);-
3000 event->setAccepted(contextEvent.isAccepted());-
3001}-
3002#endif // QT_NO_CONTEXTMENU-
3003-
3004/*!-
3005 \reimp-
3006*/-
3007void QGraphicsView::dropEvent(QDropEvent *event)-
3008{-
3009#ifndef QT_NO_DRAGANDDROP-
3010 Q_D(QGraphicsView);-
3011 if (!d->scene || !d->sceneInteractionAllowed)-
3012 return;-
3013-
3014 // Generate a scene event.-
3015 QGraphicsSceneDragDropEvent sceneEvent(QEvent::GraphicsSceneDrop);-
3016 d->populateSceneDragDropEvent(&sceneEvent, event);-
3017-
3018 // Send it to the scene.-
3019 QApplication::sendEvent(d->scene, &sceneEvent);-
3020-
3021 // Accept the originating event if the scene accepted the scene event.-
3022 event->setAccepted(sceneEvent.isAccepted());-
3023 if (sceneEvent.isAccepted())-
3024 event->setDropAction(sceneEvent.dropAction());-
3025-
3026 delete d->lastDragDropEvent;-
3027 d->lastDragDropEvent = 0;-
3028-
3029#else-
3030 Q_UNUSED(event)-
3031#endif-
3032}-
3033-
3034/*!-
3035 \reimp-
3036*/-
3037void QGraphicsView::dragEnterEvent(QDragEnterEvent *event)-
3038{-
3039#ifndef QT_NO_DRAGANDDROP-
3040 Q_D(QGraphicsView);-
3041 if (!d->scene || !d->sceneInteractionAllowed)-
3042 return;-
3043-
3044 // Disable replaying of mouse move events.-
3045 d->useLastMouseEvent = false;-
3046-
3047 // Generate a scene event.-
3048 QGraphicsSceneDragDropEvent sceneEvent(QEvent::GraphicsSceneDragEnter);-
3049 d->populateSceneDragDropEvent(&sceneEvent, event);-
3050-
3051 // Store it for later use.-
3052 d->storeDragDropEvent(&sceneEvent);-
3053-
3054 // Send it to the scene.-
3055 QApplication::sendEvent(d->scene, &sceneEvent);-
3056-
3057 // Accept the originating event if the scene accepted the scene event.-
3058 if (sceneEvent.isAccepted()) {-
3059 event->setAccepted(true);-
3060 event->setDropAction(sceneEvent.dropAction());-
3061 }-
3062#else-
3063 Q_UNUSED(event)-
3064#endif-
3065}-
3066-
3067/*!-
3068 \reimp-
3069*/-
3070void QGraphicsView::dragLeaveEvent(QDragLeaveEvent *event)-
3071{-
3072#ifndef QT_NO_DRAGANDDROP-
3073 Q_D(QGraphicsView);-
3074 if (!d->scene || !d->sceneInteractionAllowed)-
3075 return;-
3076 if (!d->lastDragDropEvent) {-
3077 qWarning("QGraphicsView::dragLeaveEvent: drag leave received before drag enter");-
3078 return;-
3079 }-
3080-
3081 // Generate a scene event.-
3082 QGraphicsSceneDragDropEvent sceneEvent(QEvent::GraphicsSceneDragLeave);-
3083 sceneEvent.setScenePos(d->lastDragDropEvent->scenePos());-
3084 sceneEvent.setScreenPos(d->lastDragDropEvent->screenPos());-
3085 sceneEvent.setButtons(d->lastDragDropEvent->buttons());-
3086 sceneEvent.setModifiers(d->lastDragDropEvent->modifiers());-
3087 sceneEvent.setPossibleActions(d->lastDragDropEvent->possibleActions());-
3088 sceneEvent.setProposedAction(d->lastDragDropEvent->proposedAction());-
3089 sceneEvent.setDropAction(d->lastDragDropEvent->dropAction());-
3090 sceneEvent.setMimeData(d->lastDragDropEvent->mimeData());-
3091 sceneEvent.setWidget(d->lastDragDropEvent->widget());-
3092 sceneEvent.setSource(d->lastDragDropEvent->source());-
3093 delete d->lastDragDropEvent;-
3094 d->lastDragDropEvent = 0;-
3095-
3096 // Send it to the scene.-
3097 QApplication::sendEvent(d->scene, &sceneEvent);-
3098-
3099 // Accept the originating event if the scene accepted the scene event.-
3100 if (sceneEvent.isAccepted())-
3101 event->setAccepted(true);-
3102#else-
3103 Q_UNUSED(event)-
3104#endif-
3105}-
3106-
3107/*!-
3108 \reimp-
3109*/-
3110void QGraphicsView::dragMoveEvent(QDragMoveEvent *event)-
3111{-
3112#ifndef QT_NO_DRAGANDDROP-
3113 Q_D(QGraphicsView);-
3114 if (!d->scene || !d->sceneInteractionAllowed)-
3115 return;-
3116-
3117 // Generate a scene event.-
3118 QGraphicsSceneDragDropEvent sceneEvent(QEvent::GraphicsSceneDragMove);-
3119 d->populateSceneDragDropEvent(&sceneEvent, event);-
3120-
3121 // Store it for later use.-
3122 d->storeDragDropEvent(&sceneEvent);-
3123-
3124 // Send it to the scene.-
3125 QApplication::sendEvent(d->scene, &sceneEvent);-
3126-
3127 // Ignore the originating event if the scene ignored the scene event.-
3128 event->setAccepted(sceneEvent.isAccepted());-
3129 if (sceneEvent.isAccepted())-
3130 event->setDropAction(sceneEvent.dropAction());-
3131#else-
3132 Q_UNUSED(event)-
3133#endif-
3134}-
3135-
3136/*!-
3137 \reimp-
3138*/-
3139void QGraphicsView::focusInEvent(QFocusEvent *event)-
3140{-
3141 Q_D(QGraphicsView);-
3142 d->updateInputMethodSensitivity();-
3143 QAbstractScrollArea::focusInEvent(event);-
3144 if (d->scene)-
3145 QApplication::sendEvent(d->scene, event);-
3146 // Pass focus on if the scene cannot accept focus.-
3147 if (!d->scene || !event->isAccepted())-
3148 QAbstractScrollArea::focusInEvent(event);-
3149}-
3150-
3151/*!-
3152 \reimp-
3153*/-
3154bool QGraphicsView::focusNextPrevChild(bool next)-
3155{-
3156 return QAbstractScrollArea::focusNextPrevChild(next);-
3157}-
3158-
3159/*!-
3160 \reimp-
3161*/-
3162void QGraphicsView::focusOutEvent(QFocusEvent *event)-
3163{-
3164 Q_D(QGraphicsView);-
3165 QAbstractScrollArea::focusOutEvent(event);-
3166 if (d->scene)-
3167 QApplication::sendEvent(d->scene, event);-
3168}-
3169-
3170/*!-
3171 \reimp-
3172*/-
3173void QGraphicsView::keyPressEvent(QKeyEvent *event)-
3174{-
3175 Q_D(QGraphicsView);-
3176 if (!d->scene || !d->sceneInteractionAllowed) {-
3177 QAbstractScrollArea::keyPressEvent(event);-
3178 return;-
3179 }-
3180 QApplication::sendEvent(d->scene, event);-
3181 if (!event->isAccepted())-
3182 QAbstractScrollArea::keyPressEvent(event);-
3183}-
3184-
3185/*!-
3186 \reimp-
3187*/-
3188void QGraphicsView::keyReleaseEvent(QKeyEvent *event)-
3189{-
3190 Q_D(QGraphicsView);-
3191 if (!d->scene || !d->sceneInteractionAllowed)-
3192 return;-
3193 QApplication::sendEvent(d->scene, event);-
3194 if (!event->isAccepted())-
3195 QAbstractScrollArea::keyReleaseEvent(event);-
3196}-
3197-
3198/*!-
3199 \reimp-
3200*/-
3201void QGraphicsView::mouseDoubleClickEvent(QMouseEvent *event)-
3202{-
3203 Q_D(QGraphicsView);-
3204 if (!d->scene || !d->sceneInteractionAllowed)-
3205 return;-
3206-
3207 d->storeMouseEvent(event);-
3208 d->mousePressViewPoint = event->pos();-
3209 d->mousePressScenePoint = mapToScene(d->mousePressViewPoint);-
3210 d->mousePressScreenPoint = event->globalPos();-
3211 d->lastMouseMoveScenePoint = d->mousePressScenePoint;-
3212 d->lastMouseMoveScreenPoint = d->mousePressScreenPoint;-
3213 d->mousePressButton = event->button();-
3214-
3215 QGraphicsSceneMouseEvent mouseEvent(QEvent::GraphicsSceneMouseDoubleClick);-
3216 mouseEvent.setWidget(viewport());-
3217 mouseEvent.setButtonDownScenePos(d->mousePressButton, d->mousePressScenePoint);-
3218 mouseEvent.setButtonDownScreenPos(d->mousePressButton, d->mousePressScreenPoint);-
3219 mouseEvent.setScenePos(mapToScene(d->mousePressViewPoint));-
3220 mouseEvent.setScreenPos(d->mousePressScreenPoint);-
3221 mouseEvent.setLastScenePos(d->lastMouseMoveScenePoint);-
3222 mouseEvent.setLastScreenPos(d->lastMouseMoveScreenPoint);-
3223 mouseEvent.setButtons(event->buttons());-
3224 mouseEvent.setAccepted(false);-
3225 mouseEvent.setButton(event->button());-
3226 mouseEvent.setModifiers(event->modifiers());-
3227 mouseEvent.setSource(event->source());-
3228 mouseEvent.setFlags(event->flags());-
3229 if (event->spontaneous())-
3230 qt_sendSpontaneousEvent(d->scene, &mouseEvent);-
3231 else-
3232 QApplication::sendEvent(d->scene, &mouseEvent);-
3233-
3234 // Update the original mouse event accepted state.-
3235 const bool isAccepted = mouseEvent.isAccepted();-
3236 event->setAccepted(isAccepted);-
3237-
3238 // Update the last mouse event accepted state.-
3239 d->lastMouseEvent.setAccepted(isAccepted);-
3240}-
3241-
3242/*!-
3243 \reimp-
3244*/-
3245void QGraphicsView::mousePressEvent(QMouseEvent *event)-
3246{-
3247 Q_D(QGraphicsView);-
3248-
3249 // Store this event for replaying, finding deltas, and for-
3250 // scroll-dragging; even in non-interactive mode, scroll hand dragging is-
3251 // allowed, so we store the event at the very top of this function.-
3252 d->storeMouseEvent(event);-
3253 d->lastMouseEvent.setAccepted(false);-
3254-
3255 if (d->sceneInteractionAllowed) {-
3256 // Store some of the event's button-down data.-
3257 d->mousePressViewPoint = event->pos();-
3258 d->mousePressScenePoint = mapToScene(d->mousePressViewPoint);-
3259 d->mousePressScreenPoint = event->globalPos();-
3260 d->lastMouseMoveScenePoint = d->mousePressScenePoint;-
3261 d->lastMouseMoveScreenPoint = d->mousePressScreenPoint;-
3262 d->mousePressButton = event->button();-
3263-
3264 if (d->scene) {-
3265 // Convert and deliver the mouse event to the scene.-
3266 QGraphicsSceneMouseEvent mouseEvent(QEvent::GraphicsSceneMousePress);-
3267 mouseEvent.setWidget(viewport());-
3268 mouseEvent.setButtonDownScenePos(d->mousePressButton, d->mousePressScenePoint);-
3269 mouseEvent.setButtonDownScreenPos(d->mousePressButton, d->mousePressScreenPoint);-
3270 mouseEvent.setScenePos(d->mousePressScenePoint);-
3271 mouseEvent.setScreenPos(d->mousePressScreenPoint);-
3272 mouseEvent.setLastScenePos(d->lastMouseMoveScenePoint);-
3273 mouseEvent.setLastScreenPos(d->lastMouseMoveScreenPoint);-
3274 mouseEvent.setButtons(event->buttons());-
3275 mouseEvent.setButton(event->button());-
3276 mouseEvent.setModifiers(event->modifiers());-
3277 mouseEvent.setSource(event->source());-
3278 mouseEvent.setFlags(event->flags());-
3279 mouseEvent.setAccepted(false);-
3280 if (event->spontaneous())-
3281 qt_sendSpontaneousEvent(d->scene, &mouseEvent);-
3282 else-
3283 QApplication::sendEvent(d->scene, &mouseEvent);-
3284-
3285 // Update the original mouse event accepted state.-
3286 bool isAccepted = mouseEvent.isAccepted();-
3287 event->setAccepted(isAccepted);-
3288-
3289 // Update the last mouse event accepted state.-
3290 d->lastMouseEvent.setAccepted(isAccepted);-
3291-
3292 if (isAccepted)-
3293 return;-
3294 }-
3295 }-
3296-
3297#ifndef QT_NO_RUBBERBAND-
3298 if (d->dragMode == QGraphicsView::RubberBandDrag && !d->rubberBanding) {-
3299 if (d->sceneInteractionAllowed) {-
3300 // Rubberbanding is only allowed in interactive mode.-
3301 event->accept();-
3302 d->rubberBanding = true;-
3303 d->rubberBandRect = QRect();-
3304 if (d->scene) {-
3305 bool extendSelection = (event->modifiers() & Qt::ControlModifier) != 0;-
3306-
3307 if (extendSelection) {-
3308 d->rubberBandSelectionOperation = Qt::AddToSelection;-
3309 } else {-
3310 d->rubberBandSelectionOperation = Qt::ReplaceSelection;-
3311 d->scene->clearSelection();-
3312 }-
3313 }-
3314 }-
3315 } else-
3316#endif-
3317 if (d->dragMode == QGraphicsView::ScrollHandDrag && event->button() == Qt::LeftButton) {-
3318 // Left-button press in scroll hand mode initiates hand scrolling.-
3319 event->accept();-
3320 d->handScrolling = true;-
3321 d->handScrollMotions = 0;-
3322#ifndef QT_NO_CURSOR-
3323 viewport()->setCursor(Qt::ClosedHandCursor);-
3324#endif-
3325 }-
3326}-
3327-
3328/*!-
3329 \reimp-
3330*/-
3331void QGraphicsView::mouseMoveEvent(QMouseEvent *event)-
3332{-
3333 Q_D(QGraphicsView);-
3334-
3335 if (d->dragMode == QGraphicsView::ScrollHandDrag) {-
3336 if (d->handScrolling) {-
3337 QScrollBar *hBar = horizontalScrollBar();-
3338 QScrollBar *vBar = verticalScrollBar();-
3339 QPoint delta = event->pos() - d->lastMouseEvent.pos();-
3340 hBar->setValue(hBar->value() + (isRightToLeft() ? delta.x() : -delta.x()));-
3341 vBar->setValue(vBar->value() - delta.y());-
3342-
3343 // Detect how much we've scrolled to disambiguate scrolling from-
3344 // clicking.-
3345 ++d->handScrollMotions;-
3346 }-
3347 }-
3348-
3349 d->mouseMoveEventHandler(event);-
3350}-
3351-
3352/*!-
3353 \reimp-
3354*/-
3355void QGraphicsView::mouseReleaseEvent(QMouseEvent *event)-
3356{-
3357 Q_D(QGraphicsView);-
3358-
3359#ifndef QT_NO_RUBBERBAND-
3360 if (d->dragMode == QGraphicsView::RubberBandDrag && d->sceneInteractionAllowed && !event->buttons()) {-
3361 if (d->rubberBanding) {-
3362 if (d->viewportUpdateMode != QGraphicsView::NoViewportUpdate){-
3363 if (d->viewportUpdateMode != FullViewportUpdate)-
3364 viewport()->update(d->rubberBandRegion(viewport(), d->rubberBandRect));-
3365 else-
3366 d->updateAll();-
3367 }-
3368 d->rubberBanding = false;-
3369 d->rubberBandSelectionOperation = Qt::ReplaceSelection;-
3370 if (!d->rubberBandRect.isNull()) {-
3371 d->rubberBandRect = QRect();-
3372 emit rubberBandChanged(d->rubberBandRect, QPointF(), QPointF());-
3373 }-
3374 }-
3375 } else-
3376#endif-
3377 if (d->dragMode == QGraphicsView::ScrollHandDrag && event->button() == Qt::LeftButton) {-
3378#ifndef QT_NO_CURSOR-
3379 // Restore the open hand cursor. ### There might be items-
3380 // under the mouse that have a valid cursor at this time, so-
3381 // we could repeat the steps from mouseMoveEvent().-
3382 viewport()->setCursor(Qt::OpenHandCursor);-
3383#endif-
3384 d->handScrolling = false;-
3385-
3386 if (d->scene && d->sceneInteractionAllowed && !d->lastMouseEvent.isAccepted() && d->handScrollMotions <= 6) {-
3387 // If we've detected very little motion during the hand drag, and-
3388 // no item accepted the last event, we'll interpret that as a-
3389 // click to the scene, and reset the selection.-
3390 d->scene->clearSelection();-
3391 }-
3392 }-
3393-
3394 d->storeMouseEvent(event);-
3395-
3396 if (!d->sceneInteractionAllowed)-
3397 return;-
3398-
3399 if (!d->scene)-
3400 return;-
3401-
3402 QGraphicsSceneMouseEvent mouseEvent(QEvent::GraphicsSceneMouseRelease);-
3403 mouseEvent.setWidget(viewport());-
3404 mouseEvent.setButtonDownScenePos(d->mousePressButton, d->mousePressScenePoint);-
3405 mouseEvent.setButtonDownScreenPos(d->mousePressButton, d->mousePressScreenPoint);-
3406 mouseEvent.setScenePos(mapToScene(event->pos()));-
3407 mouseEvent.setScreenPos(event->globalPos());-
3408 mouseEvent.setLastScenePos(d->lastMouseMoveScenePoint);-
3409 mouseEvent.setLastScreenPos(d->lastMouseMoveScreenPoint);-
3410 mouseEvent.setButtons(event->buttons());-
3411 mouseEvent.setButton(event->button());-
3412 mouseEvent.setModifiers(event->modifiers());-
3413 mouseEvent.setSource(event->source());-
3414 mouseEvent.setFlags(event->flags());-
3415 mouseEvent.setAccepted(false);-
3416 if (event->spontaneous())-
3417 qt_sendSpontaneousEvent(d->scene, &mouseEvent);-
3418 else-
3419 QApplication::sendEvent(d->scene, &mouseEvent);-
3420-
3421 // Update the last mouse event selected state.-
3422 d->lastMouseEvent.setAccepted(mouseEvent.isAccepted());-
3423-
3424#ifndef QT_NO_CURSOR-
3425 if (mouseEvent.isAccepted() && mouseEvent.buttons() == 0 && viewport()->testAttribute(Qt::WA_SetCursor)) {-
3426 // The last mouse release on the viewport will trigger clearing the cursor.-
3427 d->_q_unsetViewportCursor();-
3428 }-
3429#endif-
3430}-
3431-
3432#ifndef QT_NO_WHEELEVENT-
3433/*!-
3434 \reimp-
3435*/-
3436void QGraphicsView::wheelEvent(QWheelEvent *event)-
3437{-
3438 Q_D(QGraphicsView);-
3439 if (!d->scene || !d->sceneInteractionAllowed) {-
3440 QAbstractScrollArea::wheelEvent(event);-
3441 return;-
3442 }-
3443-
3444 event->ignore();-
3445-
3446 QGraphicsSceneWheelEvent wheelEvent(QEvent::GraphicsSceneWheel);-
3447 wheelEvent.setWidget(viewport());-
3448 wheelEvent.setScenePos(mapToScene(event->pos()));-
3449 wheelEvent.setScreenPos(event->globalPos());-
3450 wheelEvent.setButtons(event->buttons());-
3451 wheelEvent.setModifiers(event->modifiers());-
3452 wheelEvent.setDelta(event->delta());-
3453 wheelEvent.setOrientation(event->orientation());-
3454 wheelEvent.setAccepted(false);-
3455 QApplication::sendEvent(d->scene, &wheelEvent);-
3456 event->setAccepted(wheelEvent.isAccepted());-
3457 if (!event->isAccepted())-
3458 QAbstractScrollArea::wheelEvent(event);-
3459}-
3460#endif // QT_NO_WHEELEVENT-
3461-
3462/*!-
3463 \reimp-
3464*/-
3465void QGraphicsView::paintEvent(QPaintEvent *event)-
3466{-
3467 Q_D(QGraphicsView);-
3468 if (!d->scene) {-
3469 QAbstractScrollArea::paintEvent(event);-
3470 return;-
3471 }-
3472-
3473 // Set up painter state protection.-
3474 d->scene->d_func()->painterStateProtection = !(d->optimizationFlags & DontSavePainterState);-
3475-
3476 // Determine the exposed region-
3477 d->exposedRegion = event->region();-
3478 QRectF exposedSceneRect = mapToScene(d->exposedRegion.boundingRect()).boundingRect();-
3479-
3480 // Set up the painter-
3481 QPainter painter(viewport());-
3482#ifndef QT_NO_RUBBERBAND-
3483 if (d->rubberBanding && !d->rubberBandRect.isEmpty())-
3484 painter.save();-
3485#endif-
3486 // Set up render hints-
3487 painter.setRenderHints(painter.renderHints(), false);-
3488 painter.setRenderHints(d->renderHints, true);-
3489-
3490 // Set up viewport transform-
3491 const bool viewTransformed = isTransformed();-
3492 if (viewTransformed)-
3493 painter.setWorldTransform(viewportTransform());-
3494 const QTransform viewTransform = painter.worldTransform();-
3495-
3496 // Draw background-
3497 if ((d->cacheMode & CacheBackground)-
3498#ifdef Q_DEAD_CODE_FROM_QT4_X11-
3499 && X11->use_xrender-
3500#endif-
3501 ) {-
3502 // Recreate the background pixmap, and flag the whole background as-
3503 // exposed.-
3504 if (d->mustResizeBackgroundPixmap) {-
3505 d->backgroundPixmap = QPixmap(viewport()->size());-
3506 QBrush bgBrush = viewport()->palette().brush(viewport()->backgroundRole());-
3507 if (!bgBrush.isOpaque())-
3508 d->backgroundPixmap.fill(Qt::transparent);-
3509 QPainter p(&d->backgroundPixmap);-
3510 p.fillRect(0, 0, d->backgroundPixmap.width(), d->backgroundPixmap.height(), bgBrush);-
3511 d->backgroundPixmapExposed = QRegion(viewport()->rect());-
3512 d->mustResizeBackgroundPixmap = false;-
3513 }-
3514-
3515 // Redraw exposed areas-
3516 if (!d->backgroundPixmapExposed.isEmpty()) {-
3517 QPainter backgroundPainter(&d->backgroundPixmap);-
3518 backgroundPainter.setClipRegion(d->backgroundPixmapExposed, Qt::ReplaceClip);-
3519 if (viewTransformed)-
3520 backgroundPainter.setTransform(viewTransform);-
3521 QRectF backgroundExposedSceneRect = mapToScene(d->backgroundPixmapExposed.boundingRect()).boundingRect();-
3522 drawBackground(&backgroundPainter, backgroundExposedSceneRect);-
3523 d->backgroundPixmapExposed = QRegion();-
3524 }-
3525-
3526 // Blit the background from the background pixmap-
3527 if (viewTransformed) {-
3528 painter.setWorldTransform(QTransform());-
3529 painter.drawPixmap(QPoint(), d->backgroundPixmap);-
3530 painter.setWorldTransform(viewTransform);-
3531 } else {-
3532 painter.drawPixmap(QPoint(), d->backgroundPixmap);-
3533 }-
3534 } else {-
3535 if (!(d->optimizationFlags & DontSavePainterState))-
3536 painter.save();-
3537 drawBackground(&painter, exposedSceneRect);-
3538 if (!(d->optimizationFlags & DontSavePainterState))-
3539 painter.restore();-
3540 }-
3541-
3542 // Items-
3543 if (!(d->optimizationFlags & IndirectPainting)) {-
3544 const quint32 oldRectAdjust = d->scene->d_func()->rectAdjust;-
3545 if (d->optimizationFlags & QGraphicsView::DontAdjustForAntialiasing)-
3546 d->scene->d_func()->rectAdjust = 1;-
3547 else-
3548 d->scene->d_func()->rectAdjust = 2;-
3549 d->scene->d_func()->drawItems(&painter, viewTransformed ? &viewTransform : 0,-
3550 &d->exposedRegion, viewport());-
3551 d->scene->d_func()->rectAdjust = oldRectAdjust;-
3552 // Make sure the painter's world transform is restored correctly when-
3553 // drawing without painter state protection (DontSavePainterState).-
3554 // We only change the worldTransform() so there's no need to do a full-blown-
3555 // save() and restore(). Also note that we don't have to do this in case of-
3556 // IndirectPainting (the else branch), because in that case we always save()-
3557 // and restore() in QGraphicsScene::drawItems().-
3558 if (!d->scene->d_func()->painterStateProtection)-
3559 painter.setOpacity(1.0);-
3560 painter.setWorldTransform(viewTransform);-
3561 } else {-
3562 // Make sure we don't have unpolished items before we draw-
3563 if (!d->scene->d_func()->unpolishedItems.isEmpty())-
3564 d->scene->d_func()->_q_polishItems();-
3565 // We reset updateAll here (after we've issued polish events)-
3566 // so that we can discard update requests coming from polishEvent().-
3567 d->scene->d_func()->updateAll = false;-
3568-
3569 // Find all exposed items-
3570 bool allItems = false;-
3571 QList<QGraphicsItem *> itemList = d->findItems(d->exposedRegion, &allItems, viewTransform);-
3572 if (!itemList.isEmpty()) {-
3573 // Generate the style options.-
3574 const int numItems = itemList.size();-
3575 QGraphicsItem **itemArray = &itemList[0]; // Relies on QList internals, but is perfectly valid.-
3576 QStyleOptionGraphicsItem *styleOptionArray = d->allocStyleOptionsArray(numItems);-
3577 QTransform transform(Qt::Uninitialized);-
3578 for (int i = 0; i < numItems; ++i) {-
3579 QGraphicsItem *item = itemArray[i];-
3580 QGraphicsItemPrivate *itemd = item->d_ptr.data();-
3581 itemd->initStyleOption(&styleOptionArray[i], viewTransform, d->exposedRegion, allItems);-
3582 // Cache the item's area in view coordinates.-
3583 // Note that we have to do this here in case the base class implementation-
3584 // (QGraphicsScene::drawItems) is not called. If it is, we'll do this-
3585 // operation twice, but that's the price one has to pay for using indirect-
3586 // painting :-/.-
3587 const QRectF brect = adjustedItemEffectiveBoundingRect(item);-
3588 if (!itemd->itemIsUntransformable()) {-
3589 transform = item->sceneTransform();-
3590 if (viewTransformed)-
3591 transform *= viewTransform;-
3592 } else {-
3593 transform = item->deviceTransform(viewTransform);-
3594 }-
3595 itemd->paintedViewBoundingRects.insert(d->viewport, transform.mapRect(brect).toRect());-
3596 }-
3597 // Draw the items.-
3598 drawItems(&painter, numItems, itemArray, styleOptionArray);-
3599 d->freeStyleOptionsArray(styleOptionArray);-
3600 }-
3601 }-
3602-
3603 // Foreground-
3604 drawForeground(&painter, exposedSceneRect);-
3605-
3606#ifndef QT_NO_RUBBERBAND-
3607 // Rubberband-
3608 if (d->rubberBanding && !d->rubberBandRect.isEmpty()) {-
3609 painter.restore();-
3610 QStyleOptionRubberBand option;-
3611 option.initFrom(viewport());-
3612 option.rect = d->rubberBandRect;-
3613 option.shape = QRubberBand::Rectangle;-
3614-
3615 QStyleHintReturnMask mask;-
3616 if (viewport()->style()->styleHint(QStyle::SH_RubberBand_Mask, &option, viewport(), &mask)) {-
3617 // painter clipping for masked rubberbands-
3618 painter.setClipRegion(mask.region, Qt::IntersectClip);-
3619 }-
3620-
3621 viewport()->style()->drawControl(QStyle::CE_RubberBand, &option, &painter, viewport());-
3622 }-
3623#endif-
3624-
3625 painter.end();-
3626-
3627 // Restore painter state protection.-
3628 d->scene->d_func()->painterStateProtection = true;-
3629}-
3630-
3631/*!-
3632 \reimp-
3633*/-
3634void QGraphicsView::resizeEvent(QResizeEvent *event)-
3635{-
3636 Q_D(QGraphicsView);-
3637 // Save the last center point - the resize may scroll the view, which-
3638 // changes the center point.-
3639 QPointF oldLastCenterPoint = d->lastCenterPoint;-
3640-
3641 QAbstractScrollArea::resizeEvent(event);-
3642 d->recalculateContentSize();-
3643-
3644 // Restore the center point again.-
3645 if (d->resizeAnchor == NoAnchor && !d->keepLastCenterPoint) {-
3646 d->updateLastCenterPoint();-
3647 } else {-
3648 d->lastCenterPoint = oldLastCenterPoint;-
3649 }-
3650 d->centerView(d->resizeAnchor);-
3651 d->keepLastCenterPoint = false;-
3652-
3653 if (d->cacheMode & CacheBackground) {-
3654 // Invalidate the background pixmap-
3655 d->mustResizeBackgroundPixmap = true;-
3656 }-
3657}-
3658-
3659/*!-
3660 \reimp-
3661*/-
3662void QGraphicsView::scrollContentsBy(int dx, int dy)-
3663{-
3664 Q_D(QGraphicsView);-
3665 d->dirtyScroll = true;-
3666 if (d->transforming)-
3667 return;-
3668 if (isRightToLeft())-
3669 dx = -dx;-
3670-
3671 if (d->viewportUpdateMode != QGraphicsView::NoViewportUpdate) {-
3672 if (d->viewportUpdateMode != QGraphicsView::FullViewportUpdate) {-
3673 if (d->accelerateScrolling) {-
3674#ifndef QT_NO_RUBBERBAND-
3675 // Update new and old rubberband regions-
3676 if (!d->rubberBandRect.isEmpty()) {-
3677 QRegion rubberBandRegion(d->rubberBandRegion(viewport(), d->rubberBandRect));-
3678 rubberBandRegion += rubberBandRegion.translated(-dx, -dy);-
3679 viewport()->update(rubberBandRegion);-
3680 }-
3681#endif-
3682 d->dirtyScrollOffset.rx() += dx;-
3683 d->dirtyScrollOffset.ry() += dy;-
3684 d->dirtyRegion.translate(dx, dy);-
3685 viewport()->scroll(dx, dy);-
3686 } else {-
3687 d->updateAll();-
3688 }-
3689 } else {-
3690 d->updateAll();-
3691 }-
3692 }-
3693-
3694 d->updateLastCenterPoint();-
3695-
3696 if ((d->cacheMode & CacheBackground)-
3697#ifdef Q_DEAD_CODE_FROM_QT4_X11-
3698 && X11->use_xrender-
3699#endif-
3700 ) {-
3701 // Scroll the background pixmap-
3702 QRegion exposed;-
3703 if (!d->backgroundPixmap.isNull())-
3704 d->backgroundPixmap.scroll(dx, dy, d->backgroundPixmap.rect(), &exposed);-
3705-
3706 // Invalidate the background pixmap-
3707 d->backgroundPixmapExposed.translate(dx, dy);-
3708 d->backgroundPixmapExposed += exposed;-
3709 }-
3710-
3711 // Always replay on scroll.-
3712 if (d->sceneInteractionAllowed)-
3713 d->replayLastMouseEvent();-
3714}-
3715-
3716/*!-
3717 \reimp-
3718*/-
3719void QGraphicsView::showEvent(QShowEvent *event)-
3720{-
3721 Q_D(QGraphicsView);-
3722 d->recalculateContentSize();-
3723 d->centerView(d->transformationAnchor);-
3724 QAbstractScrollArea::showEvent(event);-
3725}-
3726-
3727/*!-
3728 \reimp-
3729*/-
3730void QGraphicsView::inputMethodEvent(QInputMethodEvent *event)-
3731{-
3732 Q_D(QGraphicsView);-
3733 if (d->scene)-
3734 QApplication::sendEvent(d->scene, event);-
3735}-
3736-
3737/*!-
3738 Draws the background of the scene using \a painter, before any items and-
3739 the foreground are drawn. Reimplement this function to provide a custom-
3740 background for this view.-
3741-
3742 If all you want is to define a color, texture or gradient for the-
3743 background, you can call setBackgroundBrush() instead.-
3744-
3745 All painting is done in \e scene coordinates. \a rect is the exposed-
3746 rectangle.-
3747-
3748 The default implementation fills \a rect using the view's backgroundBrush.-
3749 If no such brush is defined (the default), the scene's drawBackground()-
3750 function is called instead.-
3751-
3752 \sa drawForeground(), QGraphicsScene::drawBackground()-
3753*/-
3754void QGraphicsView::drawBackground(QPainter *painter, const QRectF &rect)-
3755{-
3756 Q_D(QGraphicsView);-
3757 if (d->scene && d->backgroundBrush.style() == Qt::NoBrush) {-
3758 d->scene->drawBackground(painter, rect);-
3759 return;-
3760 }-
3761-
3762 painter->fillRect(rect, d->backgroundBrush);-
3763}-
3764-
3765/*!-
3766 Draws the foreground of the scene using \a painter, after the background-
3767 and all items are drawn. Reimplement this function to provide a custom-
3768 foreground for this view.-
3769-
3770 If all you want is to define a color, texture or gradient for the-
3771 foreground, you can call setForegroundBrush() instead.-
3772-
3773 All painting is done in \e scene coordinates. \a rect is the exposed-
3774 rectangle.-
3775-
3776 The default implementation fills \a rect using the view's foregroundBrush.-
3777 If no such brush is defined (the default), the scene's drawForeground()-
3778 function is called instead.-
3779-
3780 \sa drawBackground(), QGraphicsScene::drawForeground()-
3781*/-
3782void QGraphicsView::drawForeground(QPainter *painter, const QRectF &rect)-
3783{-
3784 Q_D(QGraphicsView);-
3785 if (d->scene && d->foregroundBrush.style() == Qt::NoBrush) {-
3786 d->scene->drawForeground(painter, rect);-
3787 return;-
3788 }-
3789-
3790 painter->fillRect(rect, d->foregroundBrush);-
3791}-
3792-
3793/*!-
3794 \obsolete-
3795-
3796 Draws the items \a items in the scene using \a painter, after the-
3797 background and before the foreground are drawn. \a numItems is the number-
3798 of items in \a items and options in \a options. \a options is a list of-
3799 styleoptions; one for each item. Reimplement this function to provide-
3800 custom item drawing for this view.-
3801-
3802 The default implementation calls the scene's drawItems() function.-
3803-
3804 Since Qt 4.6, this function is not called anymore unless-
3805 the QGraphicsView::IndirectPainting flag is given as an Optimization-
3806 flag.-
3807-
3808 \sa drawForeground(), drawBackground(), QGraphicsScene::drawItems()-
3809*/-
3810void QGraphicsView::drawItems(QPainter *painter, int numItems,-
3811 QGraphicsItem *items[],-
3812 const QStyleOptionGraphicsItem options[])-
3813{-
3814 Q_D(QGraphicsView);-
3815 if (d->scene) {-
3816 QWidget *widget = painter->device() == viewport() ? viewport() : 0;-
3817 d->scene->drawItems(painter, numItems, items, options, widget);-
3818 }-
3819}-
3820-
3821/*!-
3822 Returns the current transformation matrix for the view. If no current-
3823 transformation is set, the identity matrix is returned.-
3824-
3825 \sa setTransform(), rotate(), scale(), shear(), translate()-
3826*/-
3827QTransform QGraphicsView::transform() const-
3828{-
3829 Q_D(const QGraphicsView);-
3830 return d->matrix;-
3831}-
3832-
3833/*!-
3834 Returns a matrix that maps scene coordinates to viewport coordinates.-
3835-
3836 \sa mapToScene(), mapFromScene()-
3837*/-
3838QTransform QGraphicsView::viewportTransform() const-
3839{-
3840 Q_D(const QGraphicsView);-
3841 QTransform moveMatrix = QTransform::fromTranslate(-d->horizontalScroll(), -d->verticalScroll());-
3842 return d->identityMatrix ? moveMatrix : d->matrix * moveMatrix;-
3843}-
3844-
3845/*!-
3846 \since 4.6-
3847-
3848 Returns \c true if the view is transformed (i.e., a non-identity transform-
3849 has been assigned, or the scrollbars are adjusted).-
3850-
3851 \sa setTransform(), horizontalScrollBar(), verticalScrollBar()-
3852*/-
3853bool QGraphicsView::isTransformed() const-
3854{-
3855 Q_D(const QGraphicsView);-
3856 return !d->identityMatrix || d->horizontalScroll() || d->verticalScroll();-
3857}-
3858-
3859/*!-
3860 Sets the view's current transformation matrix to \a matrix.-
3861-
3862 If \a combine is true, then \a matrix is combined with the current matrix;-
3863 otherwise, \a matrix \e replaces the current matrix. \a combine is false-
3864 by default.-
3865-
3866 The transformation matrix tranforms the scene into view coordinates. Using-
3867 the default transformation, provided by the identity matrix, one pixel in-
3868 the view represents one unit in the scene (e.g., a 10x10 rectangular item-
3869 is drawn using 10x10 pixels in the view). If a 2x2 scaling matrix is-
3870 applied, the scene will be drawn in 1:2 (e.g., a 10x10 rectangular item is-
3871 then drawn using 20x20 pixels in the view).-
3872-
3873 Example:-
3874-
3875 \snippet code/src_gui_graphicsview_qgraphicsview.cpp 7-
3876-
3877 To simplify interation with items using a transformed view, QGraphicsView-
3878 provides mapTo... and mapFrom... functions that can translate between-
3879 scene and view coordinates. For example, you can call mapToScene() to map-
3880 a view coordiate to a floating point scene coordinate, or mapFromScene()-
3881 to map from floating point scene coordinates to view coordinates.-
3882-
3883 \sa transform(), rotate(), scale(), shear(), translate()-
3884*/-
3885void QGraphicsView::setTransform(const QTransform &matrix, bool combine )-
3886{-
3887 Q_D(QGraphicsView);-
3888 QTransform oldMatrix = d->matrix;-
3889 if (!combine)-
3890 d->matrix = matrix;-
3891 else-
3892 d->matrix = matrix * d->matrix;-
3893 if (oldMatrix == d->matrix)-
3894 return;-
3895-
3896 d->identityMatrix = d->matrix.isIdentity();-
3897 d->transforming = true;-
3898 if (d->scene) {-
3899 d->recalculateContentSize();-
3900 d->centerView(d->transformationAnchor);-
3901 } else {-
3902 d->updateLastCenterPoint();-
3903 }-
3904-
3905 if (d->sceneInteractionAllowed)-
3906 d->replayLastMouseEvent();-
3907 d->transforming = false;-
3908-
3909 // Any matrix operation requires a full update.-
3910 d->updateAll();-
3911}-
3912-
3913/*!-
3914 Resets the view transformation to the identity matrix.-
3915-
3916 \sa transform(), setTransform()-
3917*/-
3918void QGraphicsView::resetTransform()-
3919{-
3920 setTransform(QTransform());-
3921}-
3922-
3923QPointF QGraphicsViewPrivate::mapToScene(const QPointF &point) const-
3924{-
3925 QPointF p = point;-
3926 p.rx() += horizontalScroll();-
3927 p.ry() += verticalScroll();-
3928 return identityMatrix ? p : matrix.inverted().map(p);-
3929}-
3930-
3931QRectF QGraphicsViewPrivate::mapToScene(const QRectF &rect) const-
3932{-
3933 QPointF scrollOffset(horizontalScroll(), verticalScroll());-
3934 QPointF tl = scrollOffset + rect.topLeft();-
3935 QPointF tr = scrollOffset + rect.topRight();-
3936 QPointF br = scrollOffset + rect.bottomRight();-
3937 QPointF bl = scrollOffset + rect.bottomLeft();-
3938-
3939 QPolygonF poly(4);-
3940 if (!identityMatrix) {-
3941 QTransform x = matrix.inverted();-
3942 poly[0] = x.map(tl);-
3943 poly[1] = x.map(tr);-
3944 poly[2] = x.map(br);-
3945 poly[3] = x.map(bl);-
3946 } else {-
3947 poly[0] = tl;-
3948 poly[1] = tr;-
3949 poly[2] = br;-
3950 poly[3] = bl;-
3951 }-
3952 return poly.boundingRect();-
3953}-
3954-
3955QT_END_NAMESPACE-
3956-
3957#include "moc_qgraphicsview.cpp"-
3958-
3959#endif // QT_NO_GRAPHICSVIEW-
Source codeSwitch to Preprocessed file

Generated by Squish Coco Non-Commercial 4.3.0-BETA-master-30-08-2018-4cb69e9