Qt 6.x
The Qt SDK
Loading...
Searching...
No Matches
qgraphicsview.cpp
Go to the documentation of this file.
1// Copyright (C) 2021 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
5
6static const int QGRAPHICSVIEW_PREALLOC_STYLE_OPTIONS = 503; // largest prime < 2^9
7
247#include "qgraphicsview.h"
248#include "qgraphicsview_p.h"
249
250#include "qgraphicsitem.h"
251#include "qgraphicsitem_p.h"
252#include "qgraphicsscene.h"
253#include "qgraphicsscene_p.h"
254#include "qgraphicssceneevent.h"
255#include "qgraphicswidget.h"
256
257#include <QtCore/qdatetime.h>
258#include <QtCore/qdebug.h>
259#include <QtCore/qmath.h>
260#include <QtCore/qscopedvaluerollback.h>
261#include <QtWidgets/qapplication.h>
262#include <QtGui/qevent.h>
263#include <QtWidgets/qlayout.h>
264#include <QtGui/qtransform.h>
265#include <QtGui/qpainter.h>
266#include <QtGui/qpainterpath.h>
267#include <QtWidgets/qscrollbar.h>
268#include <QtWidgets/qstyleoption.h>
269
270#include <private/qevent_p.h>
271#include <QtGui/private/qeventpoint_p.h>
272
274
276
277inline int q_round_bound(qreal d) //### (int)(qreal) INT_MAX != INT_MAX for single precision
278{
279 if (d <= (qreal) INT_MIN)
280 return INT_MIN;
281 else if (d >= (qreal) INT_MAX)
282 return INT_MAX;
283 return d >= 0.0 ? int(d + 0.5) : int(d - int(d-1) + 0.5) + int(d-1);
284}
285
287{
288 for (int i = 0; i < touchEvent->pointCount(); ++i) {
289 auto &pt = touchEvent->point(i);
290 // the scene will set the item local pos, startPos, lastPos, and rect before delivering to
291 // an item, but for now those functions are returning the view's local coordinates
292 QMutableEventPoint::setScenePosition(pt, d->mapToScene(pt.position()));
293 // screenPos, startScreenPos, and lastScreenPos are already set
294 }
295}
296
301 : renderHints(QPainter::TextAntialiasing),
302 dragMode(QGraphicsView::NoDrag),
303 sceneInteractionAllowed(true), hasSceneRect(false),
304 connectedToScene(false),
305 useLastMouseEvent(false),
306 identityMatrix(true),
307 dirtyScroll(true),
308 accelerateScrolling(true),
309 keepLastCenterPoint(true),
310 transforming(false),
311 handScrolling(false),
312 mustAllocateStyleOptions(false),
313 mustResizeBackgroundPixmap(true),
314 fullUpdatePending(true),
315 hasUpdateClip(false),
316 mousePressButton(Qt::NoButton),
317 leftIndent(0), topIndent(0),
318 alignment(Qt::AlignCenter),
319 transformationAnchor(QGraphicsView::AnchorViewCenter), resizeAnchor(QGraphicsView::NoAnchor),
320 viewportUpdateMode(QGraphicsView::MinimalViewportUpdate),
321 scene(nullptr),
322#if QT_CONFIG(rubberband)
323 rubberBanding(false),
324 rubberBandSelectionMode(Qt::IntersectsItemShape),
325 rubberBandSelectionOperation(Qt::ReplaceSelection),
326#endif
327 handScrollMotions(0),
328#ifndef QT_NO_CURSOR
329 hasStoredOriginalCursor(false),
330#endif
331 lastDragDropEvent(nullptr),
332 updateSceneSlotReimplementedChecked(false)
333{
335}
336
338{
339}
340
345{
346 Q_Q(QGraphicsView);
347
348 const QSize maxSize = q->maximumViewportSize();
349 int width = maxSize.width();
350 int height = maxSize.height();
351 const QRectF viewRect = matrix.mapRect(q->sceneRect());
352
353 bool frameOnlyAround = (q->style()->styleHint(QStyle::SH_ScrollView_FrameOnlyAroundContents, nullptr, q));
354 if (frameOnlyAround) {
355 if (hbarpolicy == Qt::ScrollBarAlwaysOn)
356 height -= frameWidth * 2;
357 if (vbarpolicy == Qt::ScrollBarAlwaysOn)
358 width -= frameWidth * 2;
359 }
360
361 // Adjust the maximum width and height of the viewport based on the width
362 // of visible scroll bars.
363 const int scrollBarExtent = q->style()->pixelMetric(QStyle::PM_ScrollBarExtent, nullptr, q)
364 + (frameOnlyAround ? frameWidth * 2 : 0);
365
366 // We do not need to subtract the width scrollbars whose policy is
367 // Qt::ScrollBarAlwaysOn, this was already done by maximumViewportSize().
368 bool useHorizontalScrollBar = (viewRect.width() > width) && hbarpolicy == Qt::ScrollBarAsNeeded;
369 bool useVerticalScrollBar = (viewRect.height() > height) && vbarpolicy == Qt::ScrollBarAsNeeded;
370 if (useHorizontalScrollBar && vbarpolicy == Qt::ScrollBarAsNeeded) {
371 if (viewRect.height() > height - scrollBarExtent)
372 useVerticalScrollBar = true;
373 }
374 if (useVerticalScrollBar && hbarpolicy == Qt::ScrollBarAsNeeded) {
375 if (viewRect.width() > width - scrollBarExtent)
376 useHorizontalScrollBar = true;
377 }
378 if (useHorizontalScrollBar)
379 height -= scrollBarExtent;
380 if (useVerticalScrollBar)
381 width -= scrollBarExtent;
382
383 // Setting the ranges of these scroll bars can/will cause the values to
384 // change, and scrollContentsBy() will be called correspondingly. This
385 // will reset the last center point.
386 const QPointF savedLastCenterPoint = lastCenterPoint;
387
388 // Remember the former indent settings
389 const qreal oldLeftIndent = leftIndent;
390 const qreal oldTopIndent = topIndent;
391
392 // If the whole scene fits horizontally, we center the scene horizontally,
393 // and ignore the horizontal scroll bars.
394 const int left = q_round_bound(viewRect.left());
395 const int right = q_round_bound(viewRect.right() - width);
396 if (left >= right) {
398 case Qt::AlignLeft:
399 leftIndent = -viewRect.left();
400 break;
401 case Qt::AlignRight:
402 leftIndent = maxSize.width() - viewRect.width() - viewRect.left() - 1;
403 break;
404 case Qt::AlignHCenter:
405 default:
406 leftIndent = maxSize.width() / 2 - (viewRect.left() + viewRect.right()) / 2;
407 break;
408 }
409
410 hbar->setRange(0, 0);
411 } else {
412 leftIndent = 0;
413
414 hbar->setRange(left, right);
415 hbar->setPageStep(width);
416 hbar->setSingleStep(width / 20);
417
418 if (oldLeftIndent != 0)
419 hbar->setValue(-oldLeftIndent);
420 }
421
422 // If the whole scene fits vertically, we center the scene vertically, and
423 // ignore the vertical scroll bars.
424 const int top = q_round_bound(viewRect.top());
425 const int bottom = q_round_bound(viewRect.bottom() - height);
426 if (top >= bottom) {
428 case Qt::AlignTop:
429 topIndent = -viewRect.top();
430 break;
431 case Qt::AlignBottom:
432 topIndent = maxSize.height() - viewRect.height() - viewRect.top() - 1;
433 break;
434 case Qt::AlignVCenter:
435 default:
436 topIndent = maxSize.height() / 2 - (viewRect.top() + viewRect.bottom()) / 2;
437 break;
438 }
439
440 vbar->setRange(0, 0);
441 } else {
442 topIndent = 0;
443
444 vbar->setRange(top, bottom);
445 vbar->setPageStep(height);
446 vbar->setSingleStep(height / 20);
447
448 if (oldTopIndent != 0)
449 vbar->setValue(-oldTopIndent);
450 }
451
452 // Restorethe center point from before the ranges changed.
453 lastCenterPoint = savedLastCenterPoint;
454
455 // Issue a full update if the indents change.
456 // ### If the transform is still the same, we can get away with just a
457 // scroll instead.
458 if (oldLeftIndent != leftIndent || oldTopIndent != topIndent) {
459 dirtyScroll = true;
460 updateAll();
461 } else if (q->isRightToLeft() && !leftIndent) {
462 // In reverse mode, the horizontal scroll always changes after the content
463 // size has changed, as the scroll is calculated by summing the min and
464 // max values of the range and subtracting the current value. In normal
465 // mode the scroll remains unchanged unless the indent has changed.
466 dirtyScroll = true;
467 }
468
470 // Invalidate the background pixmap
472 }
473}
474
479{
480 Q_Q(QGraphicsView);
481 switch (anchor) {
483 if (q->underMouse()) {
484 // Last scene pos: lastMouseMoveScenePoint
485 // Current mouse pos:
486 QPointF transformationDiff = q->mapToScene(viewport->rect().center())
487 - q->mapToScene(viewport->mapFromGlobal(QCursor::pos()));
488 q->centerOn(lastMouseMoveScenePoint + transformationDiff);
489 } else {
490 q->centerOn(lastCenterPoint);
491 }
492 break;
493 }
495 q->centerOn(lastCenterPoint);
496 break;
498 break;
499 }
500}
501
506{
507 Q_Q(QGraphicsView);
508 lastCenterPoint = q->mapToScene(viewport->rect().center());
509}
510
518{
519 if (dirtyScroll)
520 const_cast<QGraphicsViewPrivate *>(this)->updateScroll();
521 return scrollX;
522}
523
531{
532 if (dirtyScroll)
533 const_cast<QGraphicsViewPrivate *>(this)->updateScroll();
534 return scrollY;
535}
536
543{
544 if (dirtyScroll)
545 const_cast<QGraphicsViewPrivate *>(this)->updateScroll();
546 QRectF scrolled = QRectF(rect.translated(scrollX, scrollY));
547 return identityMatrix ? scrolled : matrix.inverted().mapRect(scrolled);
548}
549
550
557{
558 if (dirtyScroll)
559 const_cast<QGraphicsViewPrivate *>(this)->updateScroll();
560 return (identityMatrix ? rect : matrix.mapRect(rect)).translated(-scrollX, -scrollY);
561}
562
567{
568 Q_Q(QGraphicsView);
570 if (q->isRightToLeft()) {
571 if (!leftIndent) {
572 scrollX += hbar->minimum();
573 scrollX += hbar->maximum();
574 scrollX -= hbar->value();
575 }
576 } else {
577 scrollX += hbar->value();
578 }
579
580 scrollY = qint64(vbar->value() - topIndent);
581
582 dirtyScroll = false;
583}
584
592{
593 Q_Q(const QGraphicsView);
594 if (q->dragMode() != QGraphicsView::NoDrag)
595 return false;
596
597 const QGraphicsItem *childItem = q->itemAt(startPos);
598
599 if (!startPos.isNull() && childItem && (childItem->flags() & QGraphicsItem::ItemIsMovable))
600 return false;
601
602 return QAbstractScrollAreaPrivate::canStartScrollingAt(startPos);
603}
604
609{
610 if (!useLastMouseEvent || !scene)
611 return;
612 QSinglePointEvent *spe = static_cast<QSinglePointEvent *>(&lastMouseEvent);
613 mouseMoveEventHandler(static_cast<QMouseEvent *>(spe));
614}
615
620{
621 useLastMouseEvent = true;
623}
624
626{
627 Q_Q(QGraphicsView);
628
629#if QT_CONFIG(rubberband)
630 updateRubberBand(event);
631#endif
632
635
637 return;
638 if (handScrolling)
639 return;
640 if (!scene)
641 return;
642
644 mouseEvent.setWidget(viewport);
647 mouseEvent.setScenePos(q->mapToScene(event->position().toPoint()));
648 mouseEvent.setScreenPos(event->globalPosition().toPoint());
651 mouseEvent.setButtons(event->buttons());
652 mouseEvent.setButton(event->button());
653 mouseEvent.setModifiers(event->modifiers());
654 mouseEvent.setSource(event->source());
655 mouseEvent.setFlags(event->flags());
656 mouseEvent.setTimestamp(event->timestamp());
657 lastMouseMoveScenePoint = mouseEvent.scenePos();
658 lastMouseMoveScreenPoint = mouseEvent.screenPos();
659 mouseEvent.setAccepted(false);
660 if (event->spontaneous())
661 qt_sendSpontaneousEvent(scene, &mouseEvent);
662 else
664
665 // Remember whether the last event was accepted or not.
667
668 if (mouseEvent.isAccepted() && mouseEvent.buttons() != 0) {
669 // The event was delivered to a mouse grabber; the press is likely to
670 // have set a cursor, and we must not change it.
671 return;
672 }
673
674#ifndef QT_NO_CURSOR
675 // If all the items ignore hover events, we don't look-up any items
676 // in QGraphicsScenePrivate::dispatchHoverEvent, hence the
677 // cachedItemsUnderMouse list will be empty. We therefore do the look-up
678 // for cursor items here if not all items use the default cursor.
679 if (scene->d_func()->allItemsIgnoreHoverEvents && !scene->d_func()->allItemsUseDefaultCursor
680 && scene->d_func()->cachedItemsUnderMouse.isEmpty()) {
681 scene->d_func()->cachedItemsUnderMouse = scene->d_func()->itemsAtPosition(mouseEvent.screenPos(),
682 mouseEvent.scenePos(),
683 mouseEvent.widget());
684 }
685 // Find the topmost item under the mouse with a cursor.
686 for (QGraphicsItem *item : std::as_const(scene->d_func()->cachedItemsUnderMouse)) {
687 if (item->isEnabled() && item->hasCursor()) {
689 return;
690 }
691 }
692
693 // No items with cursors found; revert to the view cursor.
695 // Restore the original viewport cursor.
697 viewport->setCursor(originalCursor);
698 }
699#endif
700}
701
705#if QT_CONFIG(rubberband)
706QRegion QGraphicsViewPrivate::rubberBandRegion(const QWidget *widget, const QRect &rect) const
707{
709 QStyleOptionRubberBand option;
710 option.initFrom(widget);
711 option.rect = rect;
712 option.opaque = false;
714
715 QRegion tmp;
716 tmp += rect.adjusted(-1, -1, 1, 1);
718 tmp &= mask.region;
719 return tmp;
720}
721
722void QGraphicsViewPrivate::updateRubberBand(const QMouseEvent *event)
723{
724 Q_Q(QGraphicsView);
726 return;
727 // Check for enough drag distance
728 if ((mousePressViewPoint - event->position().toPoint()).manhattanLength() < QApplication::startDragDistance())
729 return;
730
731 // Update old rubberband
732 if (viewportUpdateMode != QGraphicsView::NoViewportUpdate && !rubberBandRect.isEmpty()) {
734 q->viewport()->update(rubberBandRegion(q->viewport(), rubberBandRect));
735 else
736 updateAll();
737 }
738
739 // Stop rubber banding if the user has let go of all buttons (even
740 // if we didn't get the release events).
741 if (!event->buttons()) {
742 rubberBanding = false;
743 rubberBandSelectionOperation = Qt::ReplaceSelection;
744 if (!rubberBandRect.isNull()) {
745 rubberBandRect = QRect();
746 emit q->rubberBandChanged(rubberBandRect, QPointF(), QPointF());
747 }
748 return;
749 }
750
751 QRect oldRubberband = rubberBandRect;
752
753 // Update rubberband position
754 const QPoint mp = q->mapFromScene(mousePressScenePoint);
755 const QPoint ep = event->position().toPoint();
756 rubberBandRect = QRect(qMin(mp.x(), ep.x()), qMin(mp.y(), ep.y()),
757 qAbs(mp.x() - ep.x()) + 1, qAbs(mp.y() - ep.y()) + 1);
758
759 if (rubberBandRect != oldRubberband || lastRubberbandScenePoint != lastMouseMoveScenePoint) {
761 oldRubberband = rubberBandRect;
762 emit q->rubberBandChanged(rubberBandRect, mousePressScenePoint, lastRubberbandScenePoint);
763 }
764
765 // Update new rubberband
768 q->viewport()->update(rubberBandRegion(q->viewport(), rubberBandRect));
769 else
770 updateAll();
771 }
772 // Set the new selection area
773 QPainterPath selectionArea;
774 selectionArea.addPolygon(q->mapToScene(rubberBandRect));
775 selectionArea.closeSubpath();
776 if (scene)
777 scene->setSelectionArea(selectionArea, rubberBandSelectionOperation, rubberBandSelectionMode, q->viewportTransform());
778}
779
780void QGraphicsViewPrivate::clearRubberBand()
781{
782 Q_Q(QGraphicsView);
784 return;
785
788 q->viewport()->update(rubberBandRegion(q->viewport(), rubberBandRect));
789 else
790 updateAll();
791 }
792
793 rubberBanding = false;
794 rubberBandSelectionOperation = Qt::ReplaceSelection;
795 if (!rubberBandRect.isNull()) {
796 rubberBandRect = QRect();
797 emit q->rubberBandChanged(rubberBandRect, QPointF(), QPointF());
798 }
799}
800#endif
801
805#ifndef QT_NO_CURSOR
807{
810 originalCursor = viewport->cursor();
811 }
812 viewport->setCursor(cursor);
813}
814#endif
815
819#ifndef QT_NO_CURSOR
821{
822 Q_Q(QGraphicsView);
823 const auto items = q->items(lastMouseEvent.position().toPoint());
824 for (QGraphicsItem *item : items) {
825 if (item->isEnabled() && item->hasCursor()) {
827 return;
828 }
829 }
830
831 // Restore the original viewport cursor.
835 viewport->setCursor(Qt::OpenHandCursor);
836 else
837 viewport->setCursor(originalCursor);
838 }
839}
840#endif
841
846{
847 delete lastDragDropEvent;
849 lastDragDropEvent->setScenePos(event->scenePos());
850 lastDragDropEvent->setScreenPos(event->screenPos());
852 lastDragDropEvent->setModifiers(event->modifiers());
853 lastDragDropEvent->setPossibleActions(event->possibleActions());
854 lastDragDropEvent->setProposedAction(event->proposedAction());
855 lastDragDropEvent->setDropAction(event->dropAction());
856 lastDragDropEvent->setMimeData(event->mimeData());
859 lastDragDropEvent->setTimestamp(event->timestamp());
860}
861
866 QDropEvent *source)
867{
868#if QT_CONFIG(draganddrop)
869 Q_Q(QGraphicsView);
870 dest->setScenePos(q->mapToScene(source->position().toPoint()));
871 dest->setScreenPos(q->mapToGlobal(source->position().toPoint()));
872 dest->setButtons(source->buttons());
873 dest->setModifiers(source->modifiers());
874 dest->setPossibleActions(source->possibleActions());
875 dest->setProposedAction(source->proposedAction());
876 dest->setDropAction(source->dropAction());
877 dest->setMimeData(source->mimeData());
878 dest->setWidget(viewport);
879 dest->setSource(qobject_cast<QWidget *>(source->source()));
880#else
881 Q_UNUSED(dest);
883#endif
884}
885
890{
891 Q_Q(const QGraphicsView);
892 if (dirtyScroll)
893 const_cast<QGraphicsViewPrivate *>(this)->updateScroll();
894
896 QTransform itv = item->deviceTransform(q->viewportTransform());
897 return itv.mapRect(rect).toAlignedRect();
898 }
899
900 // Translate-only
901 // COMBINE
903 const QGraphicsItem *parentItem = item;
904 const QGraphicsItemPrivate *itemd;
905 do {
906 itemd = parentItem->d_ptr.data();
907 if (itemd->transformData)
908 break;
909 offset += itemd->pos;
910 } while ((parentItem = itemd->parent));
911
912 QRectF baseRect = rect.translated(offset.x(), offset.y());
913 if (!parentItem) {
914 if (identityMatrix) {
915 baseRect.translate(-scrollX, -scrollY);
916 return baseRect.toAlignedRect();
917 }
918 return matrix.mapRect(baseRect).translated(-scrollX, -scrollY).toAlignedRect();
919 }
920
921 QTransform tr = parentItem->sceneTransform();
922 if (!identityMatrix)
923 tr *= matrix;
924 QRectF r = tr.mapRect(baseRect);
925 r.translate(-scrollX, -scrollY);
926 return r.toAlignedRect();
927}
928
933{
934 Q_Q(const QGraphicsView);
935 if (dirtyScroll)
936 const_cast<QGraphicsViewPrivate *>(this)->updateScroll();
937
938 // Accurate bounding region
939 QTransform itv = item->deviceTransform(q->viewportTransform());
940 return item->boundingRegion(itv) & itv.mapRect(rect).toAlignedRect();
941}
942
947{
948 if (!scene)
949 return;
950
951 if (fullUpdatePending) {
952 viewport->update();
955 } else {
956 viewport->update(dirtyRegion); // Already adjusted in updateRect/Region.
957 }
958
961}
962
963static inline bool intersectsViewport(const QRect &r, int width, int height)
964{ return !(r.left() > width) && !(r.right() < 0) && !(r.top() >= height) && !(r.bottom() < 0); }
965
966static inline bool containsViewport(const QRect &r, int width, int height)
967{ return r.left() <= 0 && r.top() <= 0 && r.right() >= width - 1 && r.bottom() >= height - 1; }
968
969static inline void QRect_unite(QRect *rect, const QRect &other)
970{
971 if (rect->isEmpty()) {
972 *rect = other;
973 } else {
974 rect->setCoords(qMin(rect->left(), other.left()), qMin(rect->top(), other.top()),
975 qMax(rect->right(), other.right()), qMax(rect->bottom(), other.bottom()));
976 }
977}
978
979/*
980 Calling this function results in update rects being clipped to the item's
981 bounding rect. Note that updates prior to this function call is not clipped.
982 The clip is removed by passing \nullptr.
983*/
985{
986 Q_Q(QGraphicsView);
987 // We simply ignore the request if the update mode is either FullViewportUpdate
988 // or NoViewportUpdate; in that case there's no point in clipping anything.
991 hasUpdateClip = false;
992 return;
993 }
994
995 // Calculate the clip (item's bounding rect in view coordinates).
996 // Optimized version of:
997 // QRect clip = item->deviceTransform(q->viewportTransform())
998 // .mapRect(item->boundingRect()).toAlignedRect();
999 QRect clip;
1001 QTransform xform = item->deviceTransform(q->viewportTransform());
1002 clip = xform.mapRect(item->boundingRect()).toAlignedRect();
1005 r.translate(item->d_ptr->sceneTransform.dx() - horizontalScroll(),
1007 clip = r.toAlignedRect();
1008 } else if (!q->isTransformed()) {
1009 clip = item->d_ptr->sceneTransform.mapRect(item->boundingRect()).toAlignedRect();
1010 } else {
1012 xform *= q->viewportTransform();
1013 clip = xform.mapRect(item->boundingRect()).toAlignedRect();
1014 }
1015
1016 if (hasUpdateClip) {
1017 // Intersect with old clip.
1018 updateClip &= clip;
1019 } else {
1020 updateClip = clip;
1021 hasUpdateClip = true;
1022 }
1023}
1024
1026{
1027 if (rect.isEmpty())
1028 return false;
1029
1032 // No point in updating with QRegion granularity; use the rect instead.
1033 return updateRectF(xform.mapRect(rect));
1034 }
1035
1036 // Update mode is either Minimal or Smart, so we have to do a potentially slow operation,
1037 // which is clearly documented here: QGraphicsItem::setBoundingRegionGranularity.
1038 const QRegion region = xform.map(QRegion(rect.toAlignedRect()));
1039 QRect viewRect = region.boundingRect();
1040 const bool dontAdjustForAntialiasing = optimizationFlags & QGraphicsView::DontAdjustForAntialiasing;
1041 if (dontAdjustForAntialiasing)
1042 viewRect.adjust(-1, -1, 1, 1);
1043 else
1044 viewRect.adjust(-2, -2, 2, 2);
1045 if (!intersectsViewport(viewRect, viewport->width(), viewport->height()))
1046 return false; // Update region for sure outside viewport.
1047
1048 for (QRect viewRect : region) {
1049 if (dontAdjustForAntialiasing)
1050 viewRect.adjust(-1, -1, 1, 1);
1051 else
1052 viewRect.adjust(-2, -2, 2, 2);
1053 if (hasUpdateClip)
1054 viewRect &= updateClip;
1055 dirtyRegion += viewRect;
1056 }
1057
1058 return true;
1059}
1060
1061// NB! Assumes the rect 'r' is already aligned and adjusted for antialiasing.
1062// For QRectF use updateRectF(const QRectF &) to ensure proper adjustments.
1064{
1066 || !intersectsViewport(r, viewport->width(), viewport->height())) {
1067 return false;
1068 }
1069
1070 switch (viewportUpdateMode) {
1072 fullUpdatePending = true;
1073 viewport->update();
1074 break;
1076 if (hasUpdateClip)
1078 else
1080 if (containsViewport(dirtyBoundingRect, viewport->width(), viewport->height())) {
1081 fullUpdatePending = true;
1082 viewport->update();
1083 }
1084 break;
1085 case QGraphicsView::SmartViewportUpdate: // ### DEPRECATE
1087 if (hasUpdateClip)
1089 else
1090 dirtyRegion += r;
1091 break;
1092 default:
1093 break;
1094 }
1095
1096 return true;
1097}
1098
1100{
1101 if (mustAllocateStyleOptions || (numItems > styleOptions.capacity()))
1102 // too many items, let's allocate on-the-fly
1103 return new QStyleOptionGraphicsItem[numItems];
1104
1105 // expand only whenever necessary
1106 if (numItems > styleOptions.size())
1107 styleOptions.resize(numItems);
1108
1110 return styleOptions.data();
1111}
1112
1114{
1116 if (array != styleOptions.data())
1117 delete [] array;
1118}
1119
1120extern QPainterPath qt_regionToPath(const QRegion &region);
1121
1132 const QTransform &viewTransform) const
1133{
1134 Q_Q(const QGraphicsView);
1135
1136 // Step 1) If all items are contained within the expose region, then
1137 // return a list of all visible items. ### the scene's growing bounding
1138 // rect does not take into account untransformable items.
1139 const QRectF exposedRegionSceneBounds = q->mapToScene(exposedRegion.boundingRect().adjusted(-1, -1, 1, 1))
1140 .boundingRect();
1141 if (exposedRegionSceneBounds.contains(scene->sceneRect())) {
1142 Q_ASSERT(allItems);
1143 *allItems = true;
1144
1145 // All items are guaranteed within the exposed region.
1147 }
1148
1149 // Step 2) If the expose region is a simple rect and the view is only
1150 // translated or scaled, search for items using
1151 // QGraphicsScene::items(QRectF).
1152 bool simpleRectLookup = exposedRegion.rectCount() == 1 && matrix.type() <= QTransform::TxScale;
1153 if (simpleRectLookup) {
1154 return scene->items(exposedRegionSceneBounds,
1156 Qt::AscendingOrder, viewTransform);
1157 }
1158
1159 // If the region is complex or the view has a complex transform, adjust
1160 // the expose region, convert it to a path, and then search for items
1161 // using QGraphicsScene::items(QPainterPath);
1162 QRegion adjustedRegion;
1163 for (const QRect &r : exposedRegion)
1164 adjustedRegion += r.adjusted(-1, -1, 1, 1);
1165
1166 const QPainterPath exposedScenePath(q->mapToScene(qt_regionToPath(adjustedRegion)));
1167 return scene->items(exposedScenePath, Qt::IntersectsItemBoundingRect,
1168 Qt::AscendingOrder, viewTransform);
1169}
1170
1179{
1180 Q_Q(QGraphicsView);
1181 QGraphicsItem *focusItem = nullptr;
1182 bool enabled = scene && (focusItem = scene->focusItem())
1184 q->setAttribute(Qt::WA_InputMethodEnabled, enabled);
1185 q->viewport()->setAttribute(Qt::WA_InputMethodEnabled, enabled);
1186
1187 if (!enabled) {
1188 q->setInputMethodHints({ });
1189 return;
1190 }
1191
1192 QGraphicsProxyWidget *proxy = focusItem->d_ptr->isWidget && focusItem->d_ptr->isProxyWidget()
1193 ? static_cast<QGraphicsProxyWidget *>(focusItem) : nullptr;
1194 if (!proxy) {
1195 q->setInputMethodHints(focusItem->inputMethodHints());
1196 } else if (QWidget *widget = proxy->widget()) {
1197 if (QWidget *fw = widget->focusWidget())
1198 widget = fw;
1200 } else {
1201 q->setInputMethodHints({ });
1202 }
1203}
1204
1209 : QAbstractScrollArea(*new QGraphicsViewPrivate, parent)
1210{
1211 setViewport(nullptr);
1212 setAcceptDrops(true);
1214 // Investigate leaving these disabled by default.
1216 viewport()->setAttribute(Qt::WA_InputMethodEnabled);
1217}
1218
1224 : QAbstractScrollArea(*new QGraphicsViewPrivate, parent)
1225{
1226 setScene(scene);
1227 setViewport(nullptr);
1228 setAcceptDrops(true);
1230 // Investigate leaving these disabled by default.
1232 viewport()->setAttribute(Qt::WA_InputMethodEnabled);
1233}
1234
1239 : QAbstractScrollArea(dd, parent)
1240{
1241 setViewport(nullptr);
1242 setAcceptDrops(true);
1244 // Investigate leaving these disabled by default.
1246 viewport()->setAttribute(Qt::WA_InputMethodEnabled);
1247}
1248
1253{
1254 Q_D(QGraphicsView);
1255 if (d->scene)
1256 d->scene->d_func()->views.removeAll(this);
1257 delete d->lastDragDropEvent;
1258}
1259
1264{
1265 Q_D(const QGraphicsView);
1266 if (d->scene) {
1267 QSizeF baseSize = d->matrix.mapRect(sceneRect()).size();
1268 baseSize += QSizeF(d->frameWidth * 2, d->frameWidth * 2);
1269 return baseSize.boundedTo((3 * QGuiApplication::primaryScreen()->virtualSize()) / 4).toSize();
1270 }
1271 return QAbstractScrollArea::sizeHint();
1272}
1273
1289QPainter::RenderHints QGraphicsView::renderHints() const
1290{
1291 Q_D(const QGraphicsView);
1292 return d->renderHints;
1293}
1294void QGraphicsView::setRenderHints(QPainter::RenderHints hints)
1295{
1296 Q_D(QGraphicsView);
1297 if (hints == d->renderHints)
1298 return;
1299 d->renderHints = hints;
1300 d->updateAll();
1301}
1302
1310{
1311 Q_D(QGraphicsView);
1312 QPainter::RenderHints oldHints = d->renderHints;
1313 d->renderHints.setFlag(hint, enabled);
1314 if (oldHints != d->renderHints)
1315 d->updateAll();
1316}
1317
1330Qt::Alignment QGraphicsView::alignment() const
1331{
1332 Q_D(const QGraphicsView);
1333 return d->alignment;
1334}
1336{
1337 Q_D(QGraphicsView);
1338 if (d->alignment != alignment) {
1339 d->alignment = alignment;
1340 d->recalculateContentSize();
1341 }
1342}
1343
1363{
1364 Q_D(const QGraphicsView);
1365 return d->transformationAnchor;
1366}
1368{
1369 Q_D(QGraphicsView);
1370 d->transformationAnchor = anchor;
1371
1372 // Ensure mouse tracking is enabled in the case we are using AnchorUnderMouse
1373 // in order to have up-to-date information for centering the view.
1374 if (d->transformationAnchor == AnchorUnderMouse)
1375 d->viewport->setMouseTracking(true);
1376}
1377
1395{
1396 Q_D(const QGraphicsView);
1397 return d->resizeAnchor;
1398}
1400{
1401 Q_D(QGraphicsView);
1402 d->resizeAnchor = anchor;
1403
1404 // Ensure mouse tracking is enabled in the case we are using AnchorUnderMouse
1405 // in order to have up-to-date information for centering the view.
1406 if (d->resizeAnchor == AnchorUnderMouse)
1407 d->viewport->setMouseTracking(true);
1408}
1409
1429{
1430 Q_D(const QGraphicsView);
1431 return d->viewportUpdateMode;
1432}
1434{
1435 Q_D(QGraphicsView);
1436 d->viewportUpdateMode = mode;
1437}
1438
1457QGraphicsView::OptimizationFlags QGraphicsView::optimizationFlags() const
1458{
1459 Q_D(const QGraphicsView);
1460 return d->optimizationFlags;
1461}
1463{
1464 Q_D(QGraphicsView);
1465 d->optimizationFlags = flags;
1466}
1467
1474{
1475 Q_D(QGraphicsView);
1476 d->optimizationFlags.setFlag(flag, enabled);
1477}
1478
1494{
1495 Q_D(const QGraphicsView);
1496 return d->dragMode;
1497}
1499{
1500 Q_D(QGraphicsView);
1501 if (d->dragMode == mode)
1502 return;
1503
1504#if QT_CONFIG(rubberband)
1505 d->clearRubberBand();
1506#endif
1507
1508#ifndef QT_NO_CURSOR
1509 if (d->dragMode == ScrollHandDrag)
1510 viewport()->unsetCursor();
1511#endif
1512
1513 // If dragMode is unset while dragging, e.g. via a keyEvent, we
1514 // don't unset the handScrolling state. When enabling scrolling
1515 // again the mouseMoveEvent will automatically start scrolling,
1516 // without a mousePress
1517 if (d->dragMode == ScrollHandDrag && mode == NoDrag && d->handScrolling)
1518 d->handScrolling = false;
1519
1520 d->dragMode = mode;
1521
1522#ifndef QT_NO_CURSOR
1523 if (d->dragMode == ScrollHandDrag) {
1524 // Forget the stored viewport cursor when we enter scroll hand drag mode.
1525 d->hasStoredOriginalCursor = false;
1526 viewport()->setCursor(Qt::OpenHandCursor);
1527 }
1528#endif
1529}
1530
1531#if QT_CONFIG(rubberband)
1545Qt::ItemSelectionMode QGraphicsView::rubberBandSelectionMode() const
1546{
1547 Q_D(const QGraphicsView);
1548 return d->rubberBandSelectionMode;
1549}
1550void QGraphicsView::setRubberBandSelectionMode(Qt::ItemSelectionMode mode)
1551{
1552 Q_D(QGraphicsView);
1553 d->rubberBandSelectionMode = mode;
1554}
1555
1568QRect QGraphicsView::rubberBandRect() const
1569{
1570 Q_D(const QGraphicsView);
1571 if (d->dragMode != QGraphicsView::RubberBandDrag || !d->sceneInteractionAllowed || !d->rubberBanding)
1572 return QRect();
1573
1574 return d->rubberBandRect;
1575}
1576#endif
1577
1598QGraphicsView::CacheMode QGraphicsView::cacheMode() const
1599{
1600 Q_D(const QGraphicsView);
1601 return d->cacheMode;
1602}
1604{
1605 Q_D(QGraphicsView);
1606 if (mode == d->cacheMode)
1607 return;
1608 d->cacheMode = mode;
1610}
1611
1626{
1627 Q_D(QGraphicsView);
1628 if (d->cacheMode == CacheNone)
1629 return;
1630
1631 if (d->cacheMode & CacheBackground) {
1632 // Background caching is enabled.
1633 d->mustResizeBackgroundPixmap = true;
1634 d->updateAll();
1635 } else if (d->mustResizeBackgroundPixmap) {
1636 // Background caching is disabled.
1637 // Cleanup, free some resources.
1638 d->mustResizeBackgroundPixmap = false;
1639 d->backgroundPixmap = QPixmap();
1640 d->backgroundPixmapExposed = QRegion();
1641 }
1642}
1643
1660void QGraphicsView::invalidateScene(const QRectF &rect, QGraphicsScene::SceneLayers layers)
1661{
1662 Q_D(QGraphicsView);
1663 if ((layers & QGraphicsScene::BackgroundLayer) && !d->mustResizeBackgroundPixmap) {
1664 QRect viewRect = mapFromScene(rect).boundingRect();
1665 if (viewport()->rect().intersects(viewRect)) {
1666 // The updated background area is exposed; schedule this area for
1667 // redrawing.
1668 d->backgroundPixmapExposed += viewRect;
1669 if (d->scene)
1670 d->scene->update(rect);
1671 }
1672 }
1673}
1674
1686{
1687 Q_D(const QGraphicsView);
1688 return d->sceneInteractionAllowed;
1689}
1691{
1692 Q_D(QGraphicsView);
1693 d->sceneInteractionAllowed = allowed;
1694}
1695
1703{
1704 Q_D(const QGraphicsView);
1705 return d->scene;
1706}
1707
1719{
1720 Q_D(QGraphicsView);
1721 if (d->scene == scene)
1722 return;
1723
1724 // Always update the viewport when the scene changes.
1725 d->updateAll();
1726
1727 // Remove the previously assigned scene.
1728 if (d->scene) {
1729 disconnect(d->scene, SIGNAL(changed(QList<QRectF>)),
1731 disconnect(d->scene, SIGNAL(sceneRectChanged(QRectF)),
1732 this, SLOT(updateSceneRect(QRectF)));
1733 d->scene->d_func()->removeView(this);
1734 d->connectedToScene = false;
1735
1736 if (isActiveWindow() && isVisible()) {
1737 QEvent windowDeactivate(QEvent::WindowDeactivate);
1738 QCoreApplication::sendEvent(d->scene, &windowDeactivate);
1739 }
1740 if (hasFocus())
1741 d->scene->clearFocus();
1742 }
1743
1744 // Assign the new scene and update the contents (scrollbars, etc.)).
1745 if ((d->scene = scene)) {
1746 connect(d->scene, SIGNAL(sceneRectChanged(QRectF)),
1747 this, SLOT(updateSceneRect(QRectF)));
1748 d->updateSceneSlotReimplementedChecked = false;
1749 d->scene->d_func()->addView(this);
1750 d->recalculateContentSize();
1751 d->lastCenterPoint = sceneRect().center();
1752 d->keepLastCenterPoint = true;
1753 // We are only interested in mouse tracking if items accept
1754 // hover events or use non-default cursors.
1755 if (!d->scene->d_func()->allItemsIgnoreHoverEvents
1756 || !d->scene->d_func()->allItemsUseDefaultCursor) {
1757 d->viewport->setMouseTracking(true);
1758 }
1759
1760 // enable touch events if any items is interested in them
1761 if (!d->scene->d_func()->allItemsIgnoreTouchEvents)
1762 d->viewport->setAttribute(Qt::WA_AcceptTouchEvents);
1763
1764 if (isActiveWindow() && isVisible()) {
1765 QEvent windowActivate(QEvent::WindowActivate);
1766 QCoreApplication::sendEvent(d->scene, &windowActivate);
1767 }
1768 } else {
1769 d->recalculateContentSize();
1770 }
1771
1772 d->updateInputMethodSensitivity();
1773
1774 if (d->scene && hasFocus())
1775 d->scene->setFocus();
1776}
1777
1802{
1803 Q_D(const QGraphicsView);
1804 if (d->hasSceneRect)
1805 return d->sceneRect;
1806 if (d->scene)
1807 return d->scene->sceneRect();
1808 return QRectF();
1809}
1811{
1812 Q_D(QGraphicsView);
1813 d->hasSceneRect = !rect.isNull();
1814 d->sceneRect = rect;
1815 d->recalculateContentSize();
1816}
1817
1824{
1825 Q_D(QGraphicsView);
1826 QTransform matrix = d->matrix;
1827 matrix.rotate(angle);
1829}
1830
1837{
1838 Q_D(QGraphicsView);
1839 QTransform matrix = d->matrix;
1840 matrix.scale(sx, sy);
1842}
1843
1850{
1851 Q_D(QGraphicsView);
1852 QTransform matrix = d->matrix;
1853 matrix.shear(sh, sv);
1855}
1856
1863{
1864 Q_D(QGraphicsView);
1865 QTransform matrix = d->matrix;
1866 matrix.translate(dx, dy);
1868}
1869
1883{
1884 Q_D(QGraphicsView);
1885 qreal width = viewport()->width();
1886 qreal height = viewport()->height();
1887 QPointF viewPoint = d->matrix.map(pos);
1888 QPointF oldCenterPoint = pos;
1889
1890 if (!d->leftIndent) {
1891 if (isRightToLeft()) {
1892 qint64 horizontal = 0;
1893 horizontal += horizontalScrollBar()->minimum();
1894 horizontal += horizontalScrollBar()->maximum();
1895 horizontal -= int(viewPoint.x() - width / 2.0);
1896 horizontalScrollBar()->setValue(horizontal);
1897 } else {
1898 horizontalScrollBar()->setValue(int(viewPoint.x() - width / 2.0));
1899 }
1900 }
1901 if (!d->topIndent)
1902 verticalScrollBar()->setValue(int(viewPoint.y() - height / 2.0));
1903 d->lastCenterPoint = oldCenterPoint;
1904}
1905
1923{
1925}
1926
1936void QGraphicsView::ensureVisible(const QRectF &rect, int xmargin, int ymargin)
1937{
1938 Q_D(QGraphicsView);
1939 qreal width = viewport()->width();
1940 qreal height = viewport()->height();
1941 QRectF viewRect = d->matrix.mapRect(rect);
1942
1943 qreal left = d->horizontalScroll();
1944 qreal right = left + width;
1945 qreal top = d->verticalScroll();
1946 qreal bottom = top + height;
1947
1948 if (viewRect.left() <= left + xmargin) {
1949 // need to scroll from the left
1950 if (!d->leftIndent)
1951 horizontalScrollBar()->setValue(int(viewRect.left() - xmargin - 0.5));
1952 }
1953 if (viewRect.right() >= right - xmargin) {
1954 // need to scroll from the right
1955 if (!d->leftIndent)
1956 horizontalScrollBar()->setValue(int(viewRect.right() - width + xmargin + 0.5));
1957 }
1958 if (viewRect.top() <= top + ymargin) {
1959 // need to scroll from the top
1960 if (!d->topIndent)
1961 verticalScrollBar()->setValue(int(viewRect.top() - ymargin - 0.5));
1962 }
1963 if (viewRect.bottom() >= bottom - ymargin) {
1964 // need to scroll from the bottom
1965 if (!d->topIndent)
1966 verticalScrollBar()->setValue(int(viewRect.bottom() - height + ymargin + 0.5));
1967 }
1968}
1969
1989void QGraphicsView::ensureVisible(const QGraphicsItem *item, int xmargin, int ymargin)
1990{
1991 ensureVisible(item->sceneBoundingRect(), xmargin, ymargin);
1992}
1993
2019{
2020 Q_D(QGraphicsView);
2021 if (!d->scene || rect.isNull())
2022 return;
2023
2024 // Reset the view scale to 1:1.
2025 QRectF unity = d->matrix.mapRect(QRectF(0, 0, 1, 1));
2026 if (unity.isEmpty())
2027 return;
2028 scale(1 / unity.width(), 1 / unity.height());
2029
2030 // Find the ideal x / y scaling ratio to fit \a rect in the view.
2031 int margin = 2;
2032 QRectF viewRect = viewport()->rect().adjusted(margin, margin, -margin, -margin);
2033 if (viewRect.isEmpty())
2034 return;
2035 QRectF sceneRect = d->matrix.mapRect(rect);
2036 if (sceneRect.isEmpty())
2037 return;
2038 qreal xratio = viewRect.width() / sceneRect.width();
2039 qreal yratio = viewRect.height() / sceneRect.height();
2040
2041 // Respect the aspect ratio mode.
2042 switch (aspectRatioMode) {
2044 xratio = yratio = qMin(xratio, yratio);
2045 break;
2047 xratio = yratio = qMax(xratio, yratio);
2048 break;
2050 break;
2051 }
2052
2053 // Scale and center on the center of \a rect.
2054 scale(xratio, yratio);
2055 centerOn(rect.center());
2056}
2057
2079{
2083 fitInView(path.boundingRect(), aspectRatioMode);
2084 } else {
2085 fitInView(item->d_ptr->sceneTransform.map(path).boundingRect(), aspectRatioMode);
2086 }
2087}
2088
2110 Qt::AspectRatioMode aspectRatioMode)
2111{
2112 // ### Switch to using the recursive rendering algorithm instead.
2113
2114 Q_D(QGraphicsView);
2115 if (!d->scene || !(painter && painter->isActive()))
2116 return;
2117
2118 // Default source rect = viewport rect
2119 QRect sourceRect = source;
2120 if (source.isNull())
2121 sourceRect = viewport()->rect();
2122
2123 // Default target rect = device rect
2124 QRectF targetRect = target;
2125 if (target.isNull()) {
2127 targetRect = sourceRect;
2128 else
2129 targetRect.setRect(0, 0, painter->device()->width(), painter->device()->height());
2130 }
2131
2132 // Find the ideal x / y scaling ratio to fit \a source into \a target.
2133 qreal xratio = targetRect.width() / sourceRect.width();
2134 qreal yratio = targetRect.height() / sourceRect.height();
2135
2136 // Scale according to the aspect ratio mode.
2137 switch (aspectRatioMode) {
2139 xratio = yratio = qMin(xratio, yratio);
2140 break;
2142 xratio = yratio = qMax(xratio, yratio);
2143 break;
2145 break;
2146 }
2147
2148 // Find all items to draw, and reverse the list (we want to draw
2149 // in reverse order).
2150 QPolygonF sourceScenePoly = mapToScene(sourceRect.adjusted(-1, -1, 1, 1));
2151 QList<QGraphicsItem *> itemList = d->scene->items(sourceScenePoly,
2153 QGraphicsItem **itemArray = new QGraphicsItem *[itemList.size()];
2154 int numItems = itemList.size();
2155 for (int i = 0; i < numItems; ++i)
2156 itemArray[numItems - i - 1] = itemList.at(i);
2157 itemList.clear();
2158
2159 // Setup painter matrix.
2160 QTransform moveMatrix = QTransform::fromTranslate(-d->horizontalScroll(), -d->verticalScroll());
2161 QTransform painterMatrix = d->matrix * moveMatrix;
2162 painterMatrix *= QTransform()
2163 .translate(targetRect.left(), targetRect.top())
2164 .scale(xratio, yratio)
2165 .translate(-sourceRect.left(), -sourceRect.top());
2166
2167 // Generate the style options
2168 QStyleOptionGraphicsItem *styleOptionArray = d->allocStyleOptionsArray(numItems);
2169 for (int i = 0; i < numItems; ++i)
2170 itemArray[i]->d_ptr->initStyleOption(&styleOptionArray[i], painterMatrix, targetRect.toRect());
2171
2172 painter->save();
2173
2174 // Clip in device coordinates to avoid QRegion transformations.
2175 painter->setClipRect(targetRect);
2177 path.addPolygon(sourceScenePoly);
2178 path.closeSubpath();
2179 painter->setClipPath(painterMatrix.map(path), Qt::IntersectClip);
2180
2181 // Transform the painter.
2182 painter->setTransform(painterMatrix, true);
2183
2184 // Render the scene.
2185 QRectF sourceSceneRect = sourceScenePoly.boundingRect();
2186 drawBackground(painter, sourceSceneRect);
2187 drawItems(painter, numItems, itemArray, styleOptionArray);
2188 drawForeground(painter, sourceSceneRect);
2189
2190 delete [] itemArray;
2191 d->freeStyleOptionsArray(styleOptionArray);
2192
2193 painter->restore();
2194}
2195
2204{
2205 Q_D(const QGraphicsView);
2206 if (!d->scene)
2207 return QList<QGraphicsItem *>();
2208 return d->scene->items();
2209}
2210
2226{
2227 Q_D(const QGraphicsView);
2228 if (!d->scene)
2229 return QList<QGraphicsItem *>();
2230 // ### Unify these two, and use the items(QPointF) version in
2231 // QGraphicsScene instead. The scene items function could use the viewport
2232 // transform to map the point to a rect/polygon.
2233 if ((d->identityMatrix || d->matrix.type() <= QTransform::TxScale)) {
2234 // Use the rect version
2236 return d->scene->items(xinv.mapRect(QRectF(pos.x(), pos.y(), 1, 1)),
2240 }
2241 // Use the polygon version
2242 return d->scene->items(mapToScene(pos.x(), pos.y(), 1, 1),
2246}
2247
2271{
2272 Q_D(const QGraphicsView);
2273 if (!d->scene)
2274 return QList<QGraphicsItem *>();
2275 return d->scene->items(mapToScene(rect), mode, Qt::DescendingOrder, viewportTransform());
2276}
2277
2302{
2303 Q_D(const QGraphicsView);
2304 if (!d->scene)
2305 return QList<QGraphicsItem *>();
2306 return d->scene->items(mapToScene(polygon), mode, Qt::DescendingOrder, viewportTransform());
2307}
2308
2322{
2323 Q_D(const QGraphicsView);
2324 if (!d->scene)
2325 return QList<QGraphicsItem *>();
2326 return d->scene->items(mapToScene(path), mode, Qt::DescendingOrder, viewportTransform());
2327}
2328
2341{
2342 Q_D(const QGraphicsView);
2343 if (!d->scene)
2344 return nullptr;
2345 const QList<QGraphicsItem *> itemsAtPos = items(pos);
2346 return itemsAtPos.isEmpty() ? 0 : itemsAtPos.first();
2347}
2348
2367{
2368 Q_D(const QGraphicsView);
2369 QPointF p = point;
2370 p.rx() += d->horizontalScroll();
2371 p.ry() += d->verticalScroll();
2372 return d->identityMatrix ? p : d->matrix.inverted().map(p);
2373}
2374
2389{
2390 Q_D(const QGraphicsView);
2391 if (!rect.isValid())
2392 return QPolygonF();
2393
2394 QPointF scrollOffset(d->horizontalScroll(), d->verticalScroll());
2395 QRect r = rect.adjusted(0, 0, 1, 1);
2396 QPointF tl = scrollOffset + r.topLeft();
2397 QPointF tr = scrollOffset + r.topRight();
2398 QPointF br = scrollOffset + r.bottomRight();
2399 QPointF bl = scrollOffset + r.bottomLeft();
2400
2401 QPolygonF poly(4);
2402 if (!d->identityMatrix) {
2403 QTransform x = d->matrix.inverted();
2404 poly[0] = x.map(tl);
2405 poly[1] = x.map(tr);
2406 poly[2] = x.map(br);
2407 poly[3] = x.map(bl);
2408 } else {
2409 poly[0] = tl;
2410 poly[1] = tr;
2411 poly[2] = br;
2412 poly[3] = bl;
2413 }
2414 return poly;
2415}
2416
2431{
2432 QPolygonF poly;
2433 poly.reserve(polygon.size());
2434 for (const QPoint &point : polygon)
2435 poly << mapToScene(point);
2436 return poly;
2437}
2438
2446{
2447 Q_D(const QGraphicsView);
2448 QTransform matrix = QTransform::fromTranslate(d->horizontalScroll(), d->verticalScroll());
2449 matrix *= d->matrix.inverted();
2450 return matrix.map(path);
2451}
2452
2459{
2460 Q_D(const QGraphicsView);
2461 QPointF p = d->identityMatrix ? point : d->matrix.map(point);
2462 p.rx() -= d->horizontalScroll();
2463 p.ry() -= d->verticalScroll();
2464 return p.toPoint();
2465}
2466
2481{
2482 Q_D(const QGraphicsView);
2483 QPointF tl;
2484 QPointF tr;
2485 QPointF br;
2486 QPointF bl;
2487 if (!d->identityMatrix) {
2488 const QTransform &x = d->matrix;
2489 tl = x.map(rect.topLeft());
2490 tr = x.map(rect.topRight());
2491 br = x.map(rect.bottomRight());
2492 bl = x.map(rect.bottomLeft());
2493 } else {
2494 tl = rect.topLeft();
2495 tr = rect.topRight();
2496 br = rect.bottomRight();
2497 bl = rect.bottomLeft();
2498 }
2499 QPointF scrollOffset(d->horizontalScroll(), d->verticalScroll());
2500 tl -= scrollOffset;
2501 tr -= scrollOffset;
2502 br -= scrollOffset;
2503 bl -= scrollOffset;
2504
2505 QPolygon poly(4);
2506 poly[0] = tl.toPoint();
2507 poly[1] = tr.toPoint();
2508 poly[2] = br.toPoint();
2509 poly[3] = bl.toPoint();
2510 return poly;
2511}
2512
2527{
2528 QPolygon poly;
2529 poly.reserve(polygon.size());
2530 for (const QPointF &point : polygon)
2531 poly << mapFromScene(point);
2532 return poly;
2533}
2534
2542{
2543 Q_D(const QGraphicsView);
2544 QTransform matrix = d->matrix;
2545 matrix *= QTransform::fromTranslate(-d->horizontalScroll(), -d->verticalScroll());
2546 return matrix.map(path);
2547}
2548
2553{
2554 Q_D(const QGraphicsView);
2555 if (!d->scene)
2556 return QVariant();
2557
2558 QVariant value = d->scene->inputMethodQuery(query);
2559 if (value.userType() == QMetaType::QRectF)
2560 value = d->mapRectFromScene(value.toRectF());
2561 else if (value.userType() == QMetaType::QPointF)
2562 value = mapFromScene(value.toPointF());
2563 else if (value.userType() == QMetaType::QRect)
2564 value = d->mapRectFromScene(value.toRect()).toRect();
2565 else if (value.userType() == QMetaType::QPoint)
2566 value = mapFromScene(value.toPoint());
2567 return value;
2568}
2569
2584{
2585 Q_D(const QGraphicsView);
2586 return d->backgroundBrush;
2587}
2589{
2590 Q_D(QGraphicsView);
2591 d->backgroundBrush = brush;
2592 d->updateAll();
2593
2594 if (d->cacheMode & CacheBackground) {
2595 // Invalidate the background pixmap
2596 d->mustResizeBackgroundPixmap = true;
2597 }
2598}
2599
2614{
2615 Q_D(const QGraphicsView);
2616 return d->foregroundBrush;
2617}
2619{
2620 Q_D(QGraphicsView);
2621 d->foregroundBrush = brush;
2622 d->updateAll();
2623}
2624
2631{
2632 // ### Note: Since 4.5, this slot is only called if the user explicitly
2633 // establishes a connection between the scene and the view, as the scene
2634 // and view are no longer connected. We need to keep it working (basically
2635 // leave it as it is), but the new delivery path is through
2636 // QGraphicsScenePrivate::itemUpdate().
2637 Q_D(QGraphicsView);
2638 if (d->fullUpdatePending || d->viewportUpdateMode == QGraphicsView::NoViewportUpdate)
2639 return;
2640
2641 // Extract and reset dirty scene rect info.
2642 QList<QRect> dirtyViewportRects;
2643 dirtyViewportRects.reserve(d->dirtyRegion.rectCount() + rects.size());
2644 for (const QRect &dirtyRect : d->dirtyRegion)
2645 dirtyViewportRects += dirtyRect;
2646 d->dirtyRegion = QRegion();
2647 d->dirtyBoundingRect = QRect();
2648
2649 bool fullUpdate = !d->accelerateScrolling || d->viewportUpdateMode == QGraphicsView::FullViewportUpdate;
2650 bool boundingRectUpdate = (d->viewportUpdateMode == QGraphicsView::BoundingRectViewportUpdate)
2651 || (d->viewportUpdateMode == QGraphicsView::SmartViewportUpdate
2652 && ((dirtyViewportRects.size() + rects.size()) >= QGRAPHICSVIEW_REGION_RECT_THRESHOLD));
2653
2654 QRegion updateRegion;
2656 QRect viewportRect = viewport()->rect();
2657 bool redraw = false;
2659
2660 // Convert scene rects to viewport rects.
2661 for (const QRectF &rect : rects) {
2662 QRect xrect = transform.mapRect(rect).toAlignedRect();
2663 if (!(d->optimizationFlags & DontAdjustForAntialiasing))
2664 xrect.adjust(-2, -2, 2, 2);
2665 else
2666 xrect.adjust(-1, -1, 1, 1);
2667 if (!viewportRect.intersects(xrect))
2668 continue;
2669 dirtyViewportRects << xrect;
2670 }
2671
2672 for (const QRect &rect : std::as_const(dirtyViewportRects)) {
2673 // Add the exposed rect to the update region. In rect update
2674 // mode, we only count the bounding rect of items.
2675 if (!boundingRectUpdate) {
2676 updateRegion += rect;
2677 } else {
2678 boundingRect |= rect;
2679 }
2680 redraw = true;
2681 if (fullUpdate) {
2682 // If fullUpdate is true and we found a visible dirty rect,
2683 // we're done.
2684 break;
2685 }
2686 }
2687
2688 if (!redraw)
2689 return;
2690
2691 if (fullUpdate)
2692 viewport()->update();
2693 else if (boundingRectUpdate)
2694 viewport()->update(boundingRect);
2695 else
2696 viewport()->update(updateRegion);
2697}
2698
2707{
2708 Q_D(QGraphicsView);
2709 if (!d->hasSceneRect) {
2710 d->sceneRect = rect;
2711 d->recalculateContentSize();
2712 }
2713}
2714
2723{
2724 Q_D(QGraphicsView);
2725
2726 if (!widget) {
2727 qWarning("QGraphicsView::setupViewport: cannot initialize null widget");
2728 return;
2729 }
2730
2731 const bool isGLWidget = widget->inherits("QOpenGLWidget");
2732
2733 d->accelerateScrolling = !(isGLWidget);
2734
2736
2737 if (isGLWidget)
2738 d->stereoEnabled = QWidgetPrivate::get(widget)->isStereoEnabled();
2739
2740 if (!isGLWidget) {
2741 // autoFillBackground enables scroll acceleration.
2743 }
2744
2745 // We are only interested in mouse tracking if items
2746 // accept hover events or use non-default cursors or if
2747 // AnchorUnderMouse is used as transformation or resize anchor.
2748 if ((d->scene && (!d->scene->d_func()->allItemsIgnoreHoverEvents
2749 || !d->scene->d_func()->allItemsUseDefaultCursor))
2750 || d->transformationAnchor == AnchorUnderMouse
2751 || d->resizeAnchor == AnchorUnderMouse) {
2752 widget->setMouseTracking(true);
2753 }
2754
2755 // enable touch events if any items is interested in them
2756 if (d->scene && !d->scene->d_func()->allItemsIgnoreTouchEvents)
2758
2759#ifndef QT_NO_GESTURES
2760 if (d->scene) {
2761 const auto gestures = d->scene->d_func()->grabbedGestures.keys();
2762 for (Qt::GestureType gesture : gestures)
2763 widget->grabGesture(gesture);
2764 }
2765#endif
2766
2767 widget->setAcceptDrops(acceptDrops());
2768}
2769
2774{
2775 Q_D(QGraphicsView);
2776
2777 if (d->sceneInteractionAllowed) {
2778 switch (event->type()) {
2780 if (d->scene)
2781 return QCoreApplication::sendEvent(d->scene, event);
2782 break;
2783 case QEvent::KeyPress:
2784 if (d->scene) {
2785 QKeyEvent *k = static_cast<QKeyEvent *>(event);
2786 if (k->key() == Qt::Key_Tab || k->key() == Qt::Key_Backtab) {
2787 // Send the key events to the scene. This will invoke the
2788 // scene's tab focus handling, and if the event is
2789 // accepted, we return (prevent further event delivery),
2790 // and the base implementation will call QGraphicsView's
2791 // focusNextPrevChild() function. If the event is ignored,
2792 // we fall back to standard tab focus handling.
2794 if (event->isAccepted())
2795 return true;
2796 // Ensure the event doesn't propagate just because the
2797 // scene ignored it. If the event propagates, then tab
2798 // handling will be called twice (this and parent).
2799 event->accept();
2800 }
2801 }
2802 break;
2803 default:
2804 break;
2805 }
2806 }
2807
2808 return QAbstractScrollArea::event(event);
2809}
2810
2815{
2816 Q_D(QGraphicsView);
2817 if (!d->scene)
2818 return QAbstractScrollArea::viewportEvent(event);
2819
2820 switch (event->type()) {
2821 case QEvent::Enter:
2823 break;
2826 break;
2828 // ### This is a temporary fix for until we get proper mouse
2829 // grab events. mouseGrabberItem should be set to 0 if we lose
2830 // the mouse grab.
2831 // Remove all popups when the scene loses focus.
2832 if (!d->scene->d_func()->popupWidgets.isEmpty())
2833 d->scene->d_func()->removePopup(d->scene->d_func()->popupWidgets.constFirst());
2835 break;
2836 case QEvent::Show:
2837 if (d->scene && isActiveWindow()) {
2838 QEvent windowActivate(QEvent::WindowActivate);
2839 QCoreApplication::sendEvent(d->scene, &windowActivate);
2840 }
2841 break;
2842 case QEvent::Hide:
2843 // spontaneous event will generate a WindowDeactivate.
2844 if (!event->spontaneous() && d->scene && isActiveWindow()) {
2845 QEvent windowDeactivate(QEvent::WindowDeactivate);
2846 QCoreApplication::sendEvent(d->scene, &windowDeactivate);
2847 }
2848 break;
2849 case QEvent::Leave: {
2850 // ### This is a temporary fix for until we get proper mouse grab
2851 // events. activeMouseGrabberItem should be set to 0 if we lose the
2852 // mouse grab.
2855 || (QApplication::activeWindow() != window())) {
2856 if (!d->scene->d_func()->popupWidgets.isEmpty())
2857 d->scene->d_func()->removePopup(d->scene->d_func()->popupWidgets.constFirst());
2858 }
2859 d->useLastMouseEvent = false;
2861 leaveEvent.setWidget(viewport());
2862 QCoreApplication::sendEvent(d->scene, &leaveEvent);
2863 event->setAccepted(leaveEvent.isAccepted());
2864 break;
2865 }
2866#if QT_CONFIG(tooltip)
2867 case QEvent::ToolTip: {
2868 QHelpEvent *toolTip = static_cast<QHelpEvent *>(event);
2870 helpEvent.setWidget(viewport());
2871 helpEvent.setScreenPos(toolTip->globalPos());
2872 helpEvent.setScenePos(mapToScene(toolTip->pos()));
2873 QCoreApplication::sendEvent(d->scene, &helpEvent);
2874 toolTip->setAccepted(helpEvent.isAccepted());
2875 return true;
2876 }
2877#endif
2878 case QEvent::Paint:
2879 // Reset full update
2880 d->fullUpdatePending = false;
2881 d->dirtyScrollOffset = QPoint();
2882 if (d->scene) {
2883 // Check if this view reimplements the updateScene slot; if it
2884 // does, we can't do direct update delivery and have to fall back
2885 // to connecting the changed signal.
2886 if (!d->updateSceneSlotReimplementedChecked) {
2887 d->updateSceneSlotReimplementedChecked = true;
2888 const QMetaObject *mo = metaObject();
2889 if (mo != &QGraphicsView::staticMetaObject) {
2890 if (mo->indexOfSlot("updateScene(QList<QRectF>)")
2891 != QGraphicsView::staticMetaObject.indexOfSlot("updateScene(QList<QRectF>)")) {
2892 connect(d->scene, SIGNAL(changed(QList<QRectF>)),
2894 }
2895 }
2896 }
2897 }
2898 break;
2899 case QEvent::TouchBegin:
2901 case QEvent::TouchEnd:
2902 {
2903 if (!isEnabled())
2904 return false;
2905
2906 if (d->scene && d->sceneInteractionAllowed) {
2907 // Convert and deliver the touch event to the scene.
2908 QTouchEvent *touchEvent = static_cast<QTouchEvent *>(event);
2911 QCoreApplication::sendEvent(d->scene, touchEvent);
2912 } else {
2913 event->ignore();
2914 }
2915
2916 return true;
2917 }
2918#ifndef QT_NO_GESTURES
2919 case QEvent::Gesture:
2921 {
2922 if (!isEnabled())
2923 return false;
2924
2925 if (d->scene && d->sceneInteractionAllowed) {
2926 QGestureEvent *gestureEvent = static_cast<QGestureEvent *>(event);
2927 gestureEvent->setWidget(viewport());
2928 QCoreApplication::sendEvent(d->scene, gestureEvent);
2929 }
2930 return true;
2931 }
2932#endif // QT_NO_GESTURES
2933 default:
2934 break;
2935 }
2936
2937 return QAbstractScrollArea::viewportEvent(event);
2938}
2939
2940#ifndef QT_NO_CONTEXTMENU
2945{
2946 Q_D(QGraphicsView);
2947 if (!d->scene || !d->sceneInteractionAllowed)
2948 return;
2949
2950 d->mousePressViewPoint = event->pos();
2951 d->mousePressScenePoint = mapToScene(d->mousePressViewPoint);
2952 d->mousePressScreenPoint = event->globalPos();
2953 d->lastMouseMoveScenePoint = d->mousePressScenePoint;
2954 d->lastMouseMoveScreenPoint = d->mousePressScreenPoint;
2955
2957 contextEvent.setWidget(viewport());
2958 contextEvent.setScenePos(d->mousePressScenePoint);
2959 contextEvent.setScreenPos(d->mousePressScreenPoint);
2960 contextEvent.setModifiers(event->modifiers());
2961 contextEvent.setReason((QGraphicsSceneContextMenuEvent::Reason)(event->reason()));
2962 contextEvent.setAccepted(event->isAccepted());
2963 contextEvent.setTimestamp(event->timestamp());
2964 QCoreApplication::sendEvent(d->scene, &contextEvent);
2965 event->setAccepted(contextEvent.isAccepted());
2966}
2967#endif // QT_NO_CONTEXTMENU
2968
2969#if QT_CONFIG(draganddrop)
2973void QGraphicsView::dropEvent(QDropEvent *event)
2974{
2975 Q_D(QGraphicsView);
2976 if (!d->scene || !d->sceneInteractionAllowed)
2977 return;
2978
2979 // Generate a scene event.
2981 d->populateSceneDragDropEvent(&sceneEvent, event);
2982
2983 // Send it to the scene.
2984 QCoreApplication::sendEvent(d->scene, &sceneEvent);
2985
2986 // Accept the originating event if the scene accepted the scene event.
2987 event->setAccepted(sceneEvent.isAccepted());
2988 if (sceneEvent.isAccepted())
2989 event->setDropAction(sceneEvent.dropAction());
2990
2991 delete d->lastDragDropEvent;
2992 d->lastDragDropEvent = nullptr;
2993}
2994
2998void QGraphicsView::dragEnterEvent(QDragEnterEvent *event)
2999{
3000 Q_D(QGraphicsView);
3001 if (!d->scene || !d->sceneInteractionAllowed)
3002 return;
3003
3004 // Disable replaying of mouse move events.
3005 d->useLastMouseEvent = false;
3006
3007 // Generate a scene event.
3009 d->populateSceneDragDropEvent(&sceneEvent, event);
3010
3011 // Store it for later use.
3012 d->storeDragDropEvent(&sceneEvent);
3013
3014 // Send it to the scene.
3015 QCoreApplication::sendEvent(d->scene, &sceneEvent);
3016
3017 // Accept the originating event if the scene accepted the scene event.
3018 if (sceneEvent.isAccepted()) {
3019 event->setAccepted(true);
3020 event->setDropAction(sceneEvent.dropAction());
3021 }
3022}
3023
3027void QGraphicsView::dragLeaveEvent(QDragLeaveEvent *event)
3028{
3029 Q_D(QGraphicsView);
3030 if (!d->scene || !d->sceneInteractionAllowed)
3031 return;
3032 if (!d->lastDragDropEvent) {
3033 qWarning("QGraphicsView::dragLeaveEvent: drag leave received before drag enter");
3034 return;
3035 }
3036
3037 // Generate a scene event.
3039 sceneEvent.setScenePos(d->lastDragDropEvent->scenePos());
3040 sceneEvent.setScreenPos(d->lastDragDropEvent->screenPos());
3041 sceneEvent.setButtons(d->lastDragDropEvent->buttons());
3042 sceneEvent.setModifiers(d->lastDragDropEvent->modifiers());
3043 sceneEvent.setPossibleActions(d->lastDragDropEvent->possibleActions());
3044 sceneEvent.setProposedAction(d->lastDragDropEvent->proposedAction());
3045 sceneEvent.setDropAction(d->lastDragDropEvent->dropAction());
3046 sceneEvent.setMimeData(d->lastDragDropEvent->mimeData());
3047 sceneEvent.setWidget(d->lastDragDropEvent->widget());
3048 sceneEvent.setSource(d->lastDragDropEvent->source());
3049 delete d->lastDragDropEvent;
3050 d->lastDragDropEvent = nullptr;
3051
3052 // Send it to the scene.
3053 QCoreApplication::sendEvent(d->scene, &sceneEvent);
3054
3055 // Accept the originating event if the scene accepted the scene event.
3056 if (sceneEvent.isAccepted())
3057 event->setAccepted(true);
3058}
3059
3063void QGraphicsView::dragMoveEvent(QDragMoveEvent *event)
3064{
3065 Q_D(QGraphicsView);
3066 if (!d->scene || !d->sceneInteractionAllowed)
3067 return;
3068
3069 // Generate a scene event.
3071 d->populateSceneDragDropEvent(&sceneEvent, event);
3072
3073 // Store it for later use.
3074 d->storeDragDropEvent(&sceneEvent);
3075
3076 // Send it to the scene.
3077 QCoreApplication::sendEvent(d->scene, &sceneEvent);
3078
3079 // Ignore the originating event if the scene ignored the scene event.
3080 event->setAccepted(sceneEvent.isAccepted());
3081 if (sceneEvent.isAccepted())
3082 event->setDropAction(sceneEvent.dropAction());
3083}
3084#endif // QT_CONFIG(draganddrop)
3085
3090{
3091 Q_D(QGraphicsView);
3092 d->updateInputMethodSensitivity();
3093 QAbstractScrollArea::focusInEvent(event);
3094 if (d->scene)
3096 // Pass focus on if the scene cannot accept focus.
3097 if (!d->scene || !event->isAccepted())
3098 QAbstractScrollArea::focusInEvent(event);
3099}
3100
3105{
3106 return QAbstractScrollArea::focusNextPrevChild(next);
3107}
3108
3113{
3114 Q_D(QGraphicsView);
3115 QAbstractScrollArea::focusOutEvent(event);
3116 if (d->scene)
3118}
3119
3124{
3125 Q_D(QGraphicsView);
3126 if (!d->scene || !d->sceneInteractionAllowed) {
3127 QAbstractScrollArea::keyPressEvent(event);
3128 return;
3129 }
3131 if (!event->isAccepted())
3132 QAbstractScrollArea::keyPressEvent(event);
3133}
3134
3139{
3140 Q_D(QGraphicsView);
3141 if (!d->scene || !d->sceneInteractionAllowed)
3142 return;
3144 if (!event->isAccepted())
3145 QAbstractScrollArea::keyReleaseEvent(event);
3146}
3147
3152{
3153 Q_D(QGraphicsView);
3154 if (!d->scene || !d->sceneInteractionAllowed)
3155 return;
3156
3157 d->storeMouseEvent(event);
3158 d->mousePressViewPoint = event->position().toPoint();
3159 d->mousePressScenePoint = mapToScene(d->mousePressViewPoint);
3160 d->mousePressScreenPoint = event->globalPosition().toPoint();
3161 d->lastMouseMoveScenePoint = d->mousePressScenePoint;
3162 d->lastMouseMoveScreenPoint = d->mousePressScreenPoint;
3163 d->mousePressButton = event->button();
3164
3166 mouseEvent.setWidget(viewport());
3167 mouseEvent.setButtonDownScenePos(d->mousePressButton, d->mousePressScenePoint);
3168 mouseEvent.setButtonDownScreenPos(d->mousePressButton, d->mousePressScreenPoint);
3169 mouseEvent.setScenePos(mapToScene(d->mousePressViewPoint));
3170 mouseEvent.setScreenPos(d->mousePressScreenPoint);
3171 mouseEvent.setLastScenePos(d->lastMouseMoveScenePoint);
3172 mouseEvent.setLastScreenPos(d->lastMouseMoveScreenPoint);
3173 mouseEvent.setButtons(event->buttons());
3174 mouseEvent.setAccepted(false);
3175 mouseEvent.setButton(event->button());
3176 mouseEvent.setModifiers(event->modifiers());
3177 mouseEvent.setSource(event->source());
3178 mouseEvent.setFlags(event->flags());
3179 mouseEvent.setTimestamp(event->timestamp());
3180 if (event->spontaneous())
3181 qt_sendSpontaneousEvent(d->scene, &mouseEvent);
3182 else
3183 QCoreApplication::sendEvent(d->scene, &mouseEvent);
3184
3185 // Update the original mouse event accepted state.
3186 const bool isAccepted = mouseEvent.isAccepted();
3187 event->setAccepted(isAccepted);
3188
3189 // Update the last mouse event accepted state.
3190 d->lastMouseEvent.setAccepted(isAccepted);
3191}
3192
3197{
3198 Q_D(QGraphicsView);
3199
3200 // Store this event for replaying, finding deltas, and for
3201 // scroll-dragging; even in non-interactive mode, scroll hand dragging is
3202 // allowed, so we store the event at the very top of this function.
3203 d->storeMouseEvent(event);
3204 d->lastMouseEvent.setAccepted(false);
3205
3206 if (d->sceneInteractionAllowed) {
3207 // Store some of the event's button-down data.
3208 d->mousePressViewPoint = event->position().toPoint();
3209 d->mousePressScenePoint = mapToScene(d->mousePressViewPoint);
3210 d->mousePressScreenPoint = event->globalPosition().toPoint();
3211 d->lastMouseMoveScenePoint = d->mousePressScenePoint;
3212 d->lastMouseMoveScreenPoint = d->mousePressScreenPoint;
3213 d->mousePressButton = event->button();
3214
3215 if (d->scene) {
3216 // Convert and deliver the mouse event to the scene.
3218 mouseEvent.setWidget(viewport());
3219 mouseEvent.setButtonDownScenePos(d->mousePressButton, d->mousePressScenePoint);
3220 mouseEvent.setButtonDownScreenPos(d->mousePressButton, d->mousePressScreenPoint);
3221 mouseEvent.setScenePos(d->mousePressScenePoint);
3222 mouseEvent.setScreenPos(d->mousePressScreenPoint);
3223 mouseEvent.setLastScenePos(d->lastMouseMoveScenePoint);
3224 mouseEvent.setLastScreenPos(d->lastMouseMoveScreenPoint);
3225 mouseEvent.setButtons(event->buttons());
3226 mouseEvent.setButton(event->button());
3227 mouseEvent.setModifiers(event->modifiers());
3228 mouseEvent.setSource(event->source());
3229 mouseEvent.setFlags(event->flags());
3230 mouseEvent.setAccepted(false);
3231 mouseEvent.setTimestamp(event->timestamp());
3232 if (event->spontaneous())
3233 qt_sendSpontaneousEvent(d->scene, &mouseEvent);
3234 else
3235 QCoreApplication::sendEvent(d->scene, &mouseEvent);
3236
3237 // Update the original mouse event accepted state.
3238 bool isAccepted = mouseEvent.isAccepted();
3239 event->setAccepted(isAccepted);
3240
3241 // Update the last mouse event accepted state.
3242 d->lastMouseEvent.setAccepted(isAccepted);
3243
3244 if (isAccepted)
3245 return;
3246 }
3247 }
3248
3249#if QT_CONFIG(rubberband)
3250 if (d->dragMode == QGraphicsView::RubberBandDrag && !d->rubberBanding) {
3251 if (d->sceneInteractionAllowed) {
3252 // Rubberbanding is only allowed in interactive mode.
3253 event->accept();
3254 d->rubberBanding = true;
3255 d->rubberBandRect = QRect();
3256 if (d->scene) {
3257 bool extendSelection = (event->modifiers() & Qt::ControlModifier) != 0;
3258
3259 if (extendSelection) {
3260 d->rubberBandSelectionOperation = Qt::AddToSelection;
3261 } else {
3262 d->rubberBandSelectionOperation = Qt::ReplaceSelection;
3263 d->scene->clearSelection();
3264 }
3265 }
3266 }
3267 } else
3268#endif
3269 if (d->dragMode == QGraphicsView::ScrollHandDrag && event->button() == Qt::LeftButton) {
3270 // Left-button press in scroll hand mode initiates hand scrolling.
3271 event->accept();
3272 d->handScrolling = true;
3273 d->handScrollMotions = 0;
3274#ifndef QT_NO_CURSOR
3275 viewport()->setCursor(Qt::ClosedHandCursor);
3276#endif
3277 }
3278}
3279
3284{
3285 Q_D(QGraphicsView);
3286
3287 if (d->dragMode == QGraphicsView::ScrollHandDrag) {
3288 if (d->handScrolling) {
3289 QScrollBar *hBar = horizontalScrollBar();
3290 QScrollBar *vBar = verticalScrollBar();
3291 QPoint delta = event->position().toPoint() - d->lastMouseEvent.position().toPoint();
3292 hBar->setValue(hBar->value() + (isRightToLeft() ? delta.x() : -delta.x()));
3293 vBar->setValue(vBar->value() - delta.y());
3294
3295 // Detect how much we've scrolled to disambiguate scrolling from
3296 // clicking.
3297 ++d->handScrollMotions;
3298 }
3299 }
3300
3301 d->mouseMoveEventHandler(event);
3302}
3303
3308{
3309 Q_D(QGraphicsView);
3310
3311#if QT_CONFIG(rubberband)
3312 if (d->dragMode == QGraphicsView::RubberBandDrag && d->sceneInteractionAllowed && !event->buttons()) {
3313 d->clearRubberBand();
3314 } else
3315#endif
3316 if (d->dragMode == QGraphicsView::ScrollHandDrag && event->button() == Qt::LeftButton) {
3317#ifndef QT_NO_CURSOR
3318 // Restore the open hand cursor. ### There might be items
3319 // under the mouse that have a valid cursor at this time, so
3320 // we could repeat the steps from mouseMoveEvent().
3321 viewport()->setCursor(Qt::OpenHandCursor);
3322#endif
3323 d->handScrolling = false;
3324
3325 if (d->scene && d->sceneInteractionAllowed && !d->lastMouseEvent.isAccepted() && d->handScrollMotions <= 6) {
3326 // If we've detected very little motion during the hand drag, and
3327 // no item accepted the last event, we'll interpret that as a
3328 // click to the scene, and reset the selection.
3329 d->scene->clearSelection();
3330 }
3331 }
3332
3333 d->storeMouseEvent(event);
3334
3335 if (!d->sceneInteractionAllowed)
3336 return;
3337
3338 if (!d->scene)
3339 return;
3340
3342 mouseEvent.setWidget(viewport());
3343 mouseEvent.setButtonDownScenePos(d->mousePressButton, d->mousePressScenePoint);
3344 mouseEvent.setButtonDownScreenPos(d->mousePressButton, d->mousePressScreenPoint);
3345 mouseEvent.setScenePos(mapToScene(event->position().toPoint()));
3346 mouseEvent.setScreenPos(event->globalPosition().toPoint());
3347 mouseEvent.setLastScenePos(d->lastMouseMoveScenePoint);
3348 mouseEvent.setLastScreenPos(d->lastMouseMoveScreenPoint);
3349 mouseEvent.setButtons(event->buttons());
3350 mouseEvent.setButton(event->button());
3351 mouseEvent.setModifiers(event->modifiers());
3352 mouseEvent.setSource(event->source());
3353 mouseEvent.setFlags(event->flags());
3354 mouseEvent.setAccepted(false);
3355 mouseEvent.setTimestamp(event->timestamp());
3356 if (event->spontaneous())
3357 qt_sendSpontaneousEvent(d->scene, &mouseEvent);
3358 else
3359 QCoreApplication::sendEvent(d->scene, &mouseEvent);
3360
3361 // Update the last mouse event selected state.
3362 d->lastMouseEvent.setAccepted(mouseEvent.isAccepted());
3363
3364#ifndef QT_NO_CURSOR
3365 if (mouseEvent.isAccepted() && mouseEvent.buttons() == 0 && viewport()->testAttribute(Qt::WA_SetCursor)) {
3366 // The last mouse release on the viewport will trigger clearing the cursor.
3367 d->_q_unsetViewportCursor();
3368 }
3369#endif
3370}
3371
3372#if QT_CONFIG(wheelevent)
3376void QGraphicsView::wheelEvent(QWheelEvent *event)
3377{
3378 Q_D(QGraphicsView);
3379 if (!d->scene || !d->sceneInteractionAllowed) {
3380 QAbstractScrollArea::wheelEvent(event);
3381 return;
3382 }
3383
3384 event->ignore();
3385
3387 wheelEvent.setWidget(viewport());
3388 wheelEvent.setScenePos(mapToScene(event->position().toPoint()));
3389 wheelEvent.setScreenPos(event->globalPosition().toPoint());
3390 wheelEvent.setButtons(event->buttons());
3391 wheelEvent.setModifiers(event->modifiers());
3392 const bool horizontal = qAbs(event->angleDelta().x()) > qAbs(event->angleDelta().y());
3393 wheelEvent.setDelta(horizontal ? event->angleDelta().x() : event->angleDelta().y());
3394 wheelEvent.setPixelDelta(event->pixelDelta());
3395 wheelEvent.setPhase(event->phase());
3396 wheelEvent.setInverted(event->isInverted());
3397 wheelEvent.setOrientation(horizontal ? Qt::Horizontal : Qt::Vertical);
3398 wheelEvent.setAccepted(false);
3399 wheelEvent.setTimestamp(event->timestamp());
3400 QCoreApplication::sendEvent(d->scene, &wheelEvent);
3401 event->setAccepted(wheelEvent.isAccepted());
3402 if (!event->isAccepted())
3403 QAbstractScrollArea::wheelEvent(event);
3404}
3405#endif // QT_CONFIG(wheelevent)
3406
3411{
3412 Q_D(QGraphicsView);
3413 if (!d->scene) {
3414 QAbstractScrollArea::paintEvent(event);
3415 return;
3416 }
3417
3418 // Set up painter state protection.
3419 d->scene->d_func()->painterStateProtection = !(d->optimizationFlags & DontSavePainterState);
3420
3421 // Determine the exposed region
3422 d->exposedRegion = event->region();
3423 QRectF exposedSceneRect = mapToScene(d->exposedRegion.boundingRect()).boundingRect();
3424
3425 // Set up the painter
3427#if QT_CONFIG(rubberband)
3428 if (d->rubberBanding && !d->rubberBandRect.isEmpty())
3429 painter.save();
3430#endif
3431 // Set up render hints
3433 painter.setRenderHints(d->renderHints, true);
3434
3435 // Set up viewport transform
3436 const bool viewTransformed = isTransformed();
3437 if (viewTransformed)
3439 const QTransform viewTransform = painter.worldTransform();
3440
3441 const auto actuallyDraw = [&]() {
3442 // Draw background
3443 if (d->cacheMode & CacheBackground) {
3444 // Recreate the background pixmap, and flag the whole background as
3445 // exposed.
3446 if (d->mustResizeBackgroundPixmap) {
3447 const qreal dpr = d->viewport->devicePixelRatio();
3448 d->backgroundPixmap = QPixmap(viewport()->size() * dpr);
3449 d->backgroundPixmap.setDevicePixelRatio(dpr);
3450 QBrush bgBrush = viewport()->palette().brush(viewport()->backgroundRole());
3451 if (!bgBrush.isOpaque())
3452 d->backgroundPixmap.fill(Qt::transparent);
3453 QPainter p(&d->backgroundPixmap);
3454 p.fillRect(0, 0, d->backgroundPixmap.width(), d->backgroundPixmap.height(), bgBrush);
3455 d->backgroundPixmapExposed = QRegion(viewport()->rect());
3456 d->mustResizeBackgroundPixmap = false;
3457 }
3458
3459 // Redraw exposed areas
3460 if (!d->backgroundPixmapExposed.isEmpty()) {
3461 QPainter backgroundPainter(&d->backgroundPixmap);
3462 backgroundPainter.setClipRegion(d->backgroundPixmapExposed, Qt::ReplaceClip);
3463 if (viewTransformed)
3464 backgroundPainter.setTransform(viewTransform);
3465 QRectF backgroundExposedSceneRect = mapToScene(d->backgroundPixmapExposed.boundingRect()).boundingRect();
3466 drawBackground(&backgroundPainter, backgroundExposedSceneRect);
3467 d->backgroundPixmapExposed = QRegion();
3468 }
3469
3470 // Blit the background from the background pixmap
3471 if (viewTransformed) {
3473 painter.drawPixmap(QPoint(), d->backgroundPixmap);
3474 painter.setWorldTransform(viewTransform);
3475 } else {
3476 painter.drawPixmap(QPoint(), d->backgroundPixmap);
3477 }
3478 } else {
3479 if (!(d->optimizationFlags & DontSavePainterState))
3480 painter.save();
3481
3482 drawBackground(&painter, exposedSceneRect);
3483 if (!(d->optimizationFlags & DontSavePainterState))
3484 painter.restore();
3485 }
3486
3487 // Items
3488 if (!(d->optimizationFlags & IndirectPainting)) {
3489 const quint32 oldRectAdjust = d->scene->d_func()->rectAdjust;
3490 if (d->optimizationFlags & QGraphicsView::DontAdjustForAntialiasing)
3491 d->scene->d_func()->rectAdjust = 1;
3492 else
3493 d->scene->d_func()->rectAdjust = 2;
3494 d->scene->d_func()->drawItems(&painter, viewTransformed ? &viewTransform : nullptr,
3495 &d->exposedRegion, viewport());
3496 d->scene->d_func()->rectAdjust = oldRectAdjust;
3497 // Make sure the painter's world transform is restored correctly when
3498 // drawing without painter state protection (DontSavePainterState).
3499 // We only change the worldTransform() so there's no need to do a full-blown
3500 // save() and restore(). Also note that we don't have to do this in case of
3501 // IndirectPainting (the else branch), because in that case we always save()
3502 // and restore() in QGraphicsScene::drawItems().
3503 if (!d->scene->d_func()->painterStateProtection)
3504 painter.setOpacity(1.0);
3505 painter.setWorldTransform(viewTransform);
3506 } else {
3507 // Make sure we don't have unpolished items before we draw
3508 if (!d->scene->d_func()->unpolishedItems.isEmpty())
3509 d->scene->d_func()->_q_polishItems();
3510 // We reset updateAll here (after we've issued polish events)
3511 // so that we can discard update requests coming from polishEvent().
3512 d->scene->d_func()->updateAll = false;
3513
3514 // Find all exposed items
3515 bool allItems = false;
3516 QList<QGraphicsItem *> itemList = d->findItems(d->exposedRegion, &allItems, viewTransform);
3517 if (!itemList.isEmpty()) {
3518 // Generate the style options.
3519 const int numItems = itemList.size();
3520 QGraphicsItem **itemArray = &itemList[0]; // Relies on QList internals, but is perfectly valid.
3521 QStyleOptionGraphicsItem *styleOptionArray = d->allocStyleOptionsArray(numItems);
3523 for (int i = 0; i < numItems; ++i) {
3524 QGraphicsItem *item = itemArray[i];
3525 QGraphicsItemPrivate *itemd = item->d_ptr.data();
3526 itemd->initStyleOption(&styleOptionArray[i], viewTransform, d->exposedRegion, allItems);
3527 // Cache the item's area in view coordinates.
3528 // Note that we have to do this here in case the base class implementation
3529 // (QGraphicsScene::drawItems) is not called. If it is, we'll do this
3530 // operation twice, but that's the price one has to pay for using indirect
3531 // painting :-/.
3533 if (!itemd->itemIsUntransformable()) {
3535 if (viewTransformed)
3536 transform *= viewTransform;
3537 } else {
3538 transform = item->deviceTransform(viewTransform);
3539 }
3540 itemd->paintedViewBoundingRects.insert(d->viewport, transform.mapRect(brect).toRect());
3541 }
3542 // Draw the items.
3543 drawItems(&painter, numItems, itemArray, styleOptionArray);
3544 d->freeStyleOptionsArray(styleOptionArray);
3545 }
3546 }
3547
3548 // Foreground
3549 drawForeground(&painter, exposedSceneRect);
3550
3551 #if QT_CONFIG(rubberband)
3552 // Rubberband
3553 if (d->rubberBanding && !d->rubberBandRect.isEmpty()) {
3554 painter.restore();
3555 QStyleOptionRubberBand option;
3556 option.initFrom(viewport());
3557 option.rect = d->rubberBandRect;
3559
3561 if (viewport()->style()->styleHint(QStyle::SH_RubberBand_Mask, &option, viewport(), &mask)) {
3562 // painter clipping for masked rubberbands
3564 }
3565
3566 viewport()->style()->drawControl(QStyle::CE_RubberBand, &option, &painter, viewport());
3567 }
3568 #endif
3569 };
3570
3571 actuallyDraw();
3572
3573 // For stereo we want to draw everything twice, once to each buffer
3574 if (d->stereoEnabled) {
3576 if (w->toggleStereoTargetBuffer()) {
3577 actuallyDraw();
3578 w->toggleStereoTargetBuffer();
3579 }
3580 }
3581
3582 painter.end();
3583
3584 // Restore painter state protection.
3585 d->scene->d_func()->painterStateProtection = true;
3586}
3587
3592{
3593 Q_D(QGraphicsView);
3594 // Save the last center point - the resize may scroll the view, which
3595 // changes the center point.
3596 QPointF oldLastCenterPoint = d->lastCenterPoint;
3597
3598 QAbstractScrollArea::resizeEvent(event);
3599 d->recalculateContentSize();
3600
3601 // Restore the center point again.
3602 if (d->resizeAnchor == NoAnchor && !d->keepLastCenterPoint) {
3603 d->updateLastCenterPoint();
3604 } else {
3605 d->lastCenterPoint = oldLastCenterPoint;
3606 }
3607 d->centerView(d->resizeAnchor);
3608 d->keepLastCenterPoint = false;
3609
3610 if (d->cacheMode & CacheBackground) {
3611 // Invalidate the background pixmap
3612 d->mustResizeBackgroundPixmap = true;
3613 }
3614}
3615
3620{
3621 Q_D(QGraphicsView);
3622 d->dirtyScroll = true;
3623 if (d->transforming)
3624 return;
3625 if (isRightToLeft())
3626 dx = -dx;
3627
3628 if (d->viewportUpdateMode != QGraphicsView::NoViewportUpdate) {
3629 if (d->viewportUpdateMode != QGraphicsView::FullViewportUpdate) {
3630 if (d->accelerateScrolling) {
3631#if QT_CONFIG(rubberband)
3632 // Update new and old rubberband regions
3633 if (!d->rubberBandRect.isEmpty()) {
3634 QRegion rubberBandRegion(d->rubberBandRegion(viewport(), d->rubberBandRect));
3635 rubberBandRegion += rubberBandRegion.translated(-dx, -dy);
3636 viewport()->update(rubberBandRegion);
3637 }
3638#endif
3639 d->dirtyScrollOffset.rx() += dx;
3640 d->dirtyScrollOffset.ry() += dy;
3641 d->dirtyRegion.translate(dx, dy);
3642 viewport()->scroll(dx, dy);
3643 } else {
3644 d->updateAll();
3645 }
3646 } else {
3647 d->updateAll();
3648 }
3649 }
3650
3651 d->updateLastCenterPoint();
3652
3653 if (d->cacheMode & CacheBackground) {
3654 // Below, QPixmap::scroll() works in device pixels, while the delta values
3655 // and backgroundPixmapExposed are in device independent pixels.
3656 const qreal dpr = d->backgroundPixmap.devicePixelRatio();
3657 const qreal inverseDpr = qreal(1) / dpr;
3658
3659 // Scroll the background pixmap
3660 QRegion exposed;
3661 if (!d->backgroundPixmap.isNull())
3662 d->backgroundPixmap.scroll(dx * dpr, dy * dpr, d->backgroundPixmap.rect(), &exposed);
3663
3664 // Invalidate the background pixmap
3665 d->backgroundPixmapExposed.translate(dx, dy);
3666 const QRegion exposedScaled = QTransform::fromScale(inverseDpr, inverseDpr).map(exposed);
3667 d->backgroundPixmapExposed += exposedScaled;
3668 }
3669
3670 // Always replay on scroll.
3671 if (d->sceneInteractionAllowed)
3672 d->replayLastMouseEvent();
3673}
3674
3679{
3680 Q_D(QGraphicsView);
3681 d->recalculateContentSize();
3682 d->centerView(d->transformationAnchor);
3683 QAbstractScrollArea::showEvent(event);
3684}
3685
3690{
3691 Q_D(QGraphicsView);
3692 if (d->scene)
3694}
3695
3714{
3715 Q_D(QGraphicsView);
3716 if (d->scene && d->backgroundBrush.style() == Qt::NoBrush) {
3717 d->scene->drawBackground(painter, rect);
3718 return;
3719 }
3720
3721 const bool wasAa = painter->testRenderHint(QPainter::Antialiasing);
3722 if (wasAa)
3724 painter->fillRect(rect, d->backgroundBrush);
3725 if (wasAa)
3727}
3728
3747{
3748 Q_D(QGraphicsView);
3749 if (d->scene && d->foregroundBrush.style() == Qt::NoBrush) {
3750 d->scene->drawForeground(painter, rect);
3751 return;
3752 }
3753
3754 painter->fillRect(rect, d->foregroundBrush);
3755}
3756
3776 const QStyleOptionGraphicsItem options[])
3777{
3778 Q_D(QGraphicsView);
3779 if (d->scene) {
3780 QWidget *widget = painter->device() == viewport() ? viewport() : nullptr;
3781 d->scene->drawItems(painter, numItems, items, options, widget);
3782 }
3783}
3784
3792{
3793 Q_D(const QGraphicsView);
3794 return d->matrix;
3795}
3796
3803{
3804 Q_D(const QGraphicsView);
3805 QTransform moveMatrix = QTransform::fromTranslate(-d->horizontalScroll(), -d->verticalScroll());
3806 return d->identityMatrix ? moveMatrix : d->matrix * moveMatrix;
3807}
3808
3818{
3819 Q_D(const QGraphicsView);
3820 return !d->identityMatrix || d->horizontalScroll() || d->verticalScroll();
3821}
3822
3850{
3851 Q_D(QGraphicsView);
3852 QTransform oldMatrix = d->matrix;
3853 if (!combine)
3854 d->matrix = matrix;
3855 else
3856 d->matrix = matrix * d->matrix;
3857 if (oldMatrix == d->matrix)
3858 return;
3859
3860 d->identityMatrix = d->matrix.isIdentity();
3861 d->transforming = true;
3862 if (d->scene) {
3863 d->recalculateContentSize();
3864 d->centerView(d->transformationAnchor);
3865 } else {
3866 d->updateLastCenterPoint();
3867 }
3868
3869 if (d->sceneInteractionAllowed)
3870 d->replayLastMouseEvent();
3871 d->transforming = false;
3872
3873 // Any matrix operation requires a full update.
3874 d->updateAll();
3875}
3876
3883{
3885}
3886
3888{
3889 QPointF p = point;
3890 p.rx() += horizontalScroll();
3891 p.ry() += verticalScroll();
3892 return identityMatrix ? p : matrix.inverted().map(p);
3893}
3894
3896{
3897 QPointF scrollOffset(horizontalScroll(), verticalScroll());
3898 QPointF tl = scrollOffset + rect.topLeft();
3899 QPointF tr = scrollOffset + rect.topRight();
3900 QPointF br = scrollOffset + rect.bottomRight();
3901 QPointF bl = scrollOffset + rect.bottomLeft();
3902
3903 QPolygonF poly(4);
3904 if (!identityMatrix) {
3906 poly[0] = x.map(tl);
3907 poly[1] = x.map(tr);
3908 poly[2] = x.map(br);
3909 poly[3] = x.map(bl);
3910 } else {
3911 poly[0] = tl;
3912 poly[1] = tr;
3913 poly[2] = br;
3914 poly[3] = bl;
3915 }
3916 return poly.boundingRect();
3917}
3918
3920
3921#include "moc_qgraphicsview.cpp"
int value
the slider's current value
static QWidget * activeModalWidget()
Returns the active modal widget.
static QWidget * activePopupWidget()
Returns the active popup widget.
int startDragDistance
the minimum distance required for a drag and drop operation to start.
static QWidget * activeWindow()
Returns the application top-level window that has the keyboard input focus, or \nullptr if no applica...
\inmodule QtGui
Definition qbrush.h:30
bool isOpaque() const
Returns true if the brush is fully opaque otherwise false.
Definition qbrush.cpp:830
The QContextMenuEvent class contains parameters that describe a context menu event.
Definition qevent.h:593
static bool sendEvent(QObject *receiver, QEvent *event)
Sends event event directly to receiver receiver, using the notify() function.
The QCursor class provides a mouse cursor with an arbitrary shape.
Definition qcursor.h:45
static QPoint pos()
Returns the position of the cursor (hot spot) of the primary screen in global screen coordinates.
Definition qcursor.cpp:188
\inmodule QtCore
Definition qcoreevent.h:45
virtual void setAccepted(bool accepted)
Definition qcoreevent.h:302
@ GraphicsSceneDragLeave
Definition qcoreevent.h:200
@ GraphicsSceneMouseMove
Definition qcoreevent.h:189
@ GestureOverride
Definition qcoreevent.h:254
@ GraphicsSceneContextMenu
Definition qcoreevent.h:193
@ GraphicsSceneMouseRelease
Definition qcoreevent.h:191
@ GraphicsSceneDragEnter
Definition qcoreevent.h:198
@ GraphicsSceneDragMove
Definition qcoreevent.h:199
@ ShortcutOverride
Definition qcoreevent.h:158
@ GraphicsSceneMousePress
Definition qcoreevent.h:190
@ KeyPress
Definition qcoreevent.h:64
@ TouchUpdate
Definition qcoreevent.h:242
@ TouchBegin
Definition qcoreevent.h:241
@ WindowActivate
Definition qcoreevent.h:83
@ GraphicsSceneMouseDoubleClick
Definition qcoreevent.h:192
@ GraphicsSceneWheel
Definition qcoreevent.h:202
@ GraphicsSceneDrop
Definition qcoreevent.h:201
@ GraphicsSceneHelp
Definition qcoreevent.h:197
@ WindowDeactivate
Definition qcoreevent.h:84
@ GraphicsSceneLeave
Definition qcoreevent.h:203
bool isAccepted() const
Definition qcoreevent.h:303
The QFocusEvent class contains event parameters for widget focus events.
Definition qevent.h:469
The QGestureEvent class provides the description of triggered gestures.
Definition qgesture.h:244
void setWidget(QWidget *widget)
void initStyleOption(QStyleOptionGraphicsItem *option, const QTransform &worldTransform, const QRegion &exposedRegion, bool allItems=false) const
bool itemIsUntransformable() const
QGraphicsItem * parent
TransformData * transformData
QHash< QWidget *, QRect > paintedViewBoundingRects
virtual bool isProxyWidget() const
The QGraphicsItem class is the base class for all graphical items in a QGraphicsScene.
QTransform deviceTransform(const QTransform &viewportTransform) const
QScopedPointer< QGraphicsItemPrivate > d_ptr
QPainterPath clipPath() const
virtual QPainterPath shape() const
Returns the shape of this item as a QPainterPath in local coordinates.
QRectF sceneBoundingRect() const
Returns the bounding rect of this item in scene coordinates, by combining sceneTransform() with bound...
virtual QRectF boundingRect() const =0
This pure virtual function defines the outer bounds of the item as a rectangle; all painting must be ...
QCursor cursor() const
Returns the current cursor shape for the item.
bool isEnabled() const
Returns true if the item is enabled; otherwise, false is returned.
bool isClipped() const
Returns true if this item is clipped.
bool hasCursor() const
Returns true if this item has a cursor set; otherwise, false is returned.
QTransform sceneTransform() const
QRegion boundingRegion(const QTransform &itemToDeviceTransform) const
Qt::InputMethodHints inputMethodHints() const
Returns the current input method hints of this item.
GraphicsItemFlags flags() const
Returns this item's flags.
The QGraphicsProxyWidget class provides a proxy layer for embedding a QWidget in a QGraphicsScene.
The QGraphicsSceneContextMenuEvent class provides context menu events in the graphics view framework.
void setModifiers(Qt::KeyboardModifiers modifiers)
void setScenePos(const QPointF &pos)
Reason
This enum describes the reason why the context event was sent.
The QGraphicsSceneDragDropEvent class provides events for drag and drop in the graphics view framewor...
void setButtons(Qt::MouseButtons buttons)
void setMimeData(const QMimeData *data)
void setPossibleActions(Qt::DropActions actions)
void setProposedAction(Qt::DropAction action)
void setModifiers(Qt::KeyboardModifiers modifiers)
void setDropAction(Qt::DropAction action)
This function lets the receiver of the drop set the drop action that was performed to action,...
void setScreenPos(const QPoint &pos)
void setScenePos(const QPointF &pos)
The QGraphicsSceneEvent class provides a base class for all graphics view related events.
void setWidget(QWidget *widget)
void setTimestamp(quint64 ts)
QWidget * widget() const
Returns the widget where the event originated, or \nullptr if the event originates from another appli...
The QGraphicsSceneHelpEvent class provides events when a tooltip is requested.
void setScenePos(const QPointF &pos)
void setScreenPos(const QPoint &pos)
The QGraphicsSceneMouseEvent class provides mouse events in the graphics view framework.
void setFlags(Qt::MouseEventFlags)
void setLastScenePos(const QPointF &pos)
void setButton(Qt::MouseButton button)
void setScenePos(const QPointF &pos)
QPoint screenPos() const
Returns the mouse cursor position in screen coordinates.
Qt::MouseButtons buttons() const
Returns the combination of mouse buttons that were pressed at the time the event was sent.
void setButtonDownScenePos(Qt::MouseButton button, const QPointF &pos)
void setButtons(Qt::MouseButtons buttons)
QPointF scenePos() const
Returns the mouse cursor position in scene coordinates.
void setModifiers(Qt::KeyboardModifiers modifiers)
void setButtonDownScreenPos(Qt::MouseButton button, const QPoint &pos)
void setLastScreenPos(const QPoint &pos)
void setSource(Qt::MouseEventSource source)
void setScreenPos(const QPoint &pos)
The QGraphicsSceneWheelEvent class provides wheel events in the graphics view framework.
The QGraphicsScene class provides a surface for managing a large number of 2D graphical items.
QList< QGraphicsItem * > items(Qt::SortOrder order=Qt::DescendingOrder) const
Returns an ordered list of all items on the scene.
QRectF sceneRect
the scene rectangle; the bounding rectangle of the scene
void setSelectionArea(const QPainterPath &path, const QTransform &deviceTransform)
QGraphicsItem * focusItem() const
When the scene is active, this functions returns the scene's current focus item, or \nullptr if no it...
QRect mapToViewRect(const QGraphicsItem *item, const QRectF &rect) const
void storeDragDropEvent(const QGraphicsSceneDragDropEvent *event)
QMutableSinglePointEvent lastMouseEvent
Qt::Alignment alignment
void freeStyleOptionsArray(QStyleOptionGraphicsItem *array)
QPointer< QGraphicsScene > scene
bool updateRegion(const QRectF &rect, const QTransform &xform)
QGraphicsView::DragMode dragMode
bool updateRect(const QRect &rect)
void _q_setViewportCursor(const QCursor &cursor)
qint64 horizontalScroll() const
bool updateRectF(const QRectF &rect)
QGraphicsView::ViewportUpdateMode viewportUpdateMode
static void translateTouchEvent(QGraphicsViewPrivate *d, QTouchEvent *touchEvent)
QGraphicsView::OptimizationFlags optimizationFlags
qint64 verticalScroll() const
QRectF mapRectToScene(const QRect &rect) const
QList< QStyleOptionGraphicsItem > styleOptions
QList< QGraphicsItem * > findItems(const QRegion &exposedRegion, bool *allItems, const QTransform &viewTransform) const
QRectF mapRectFromScene(const QRectF &rect) const
void populateSceneDragDropEvent(QGraphicsSceneDragDropEvent *dest, QDropEvent *source)
QPointF mapToScene(const QPointF &point) const
void mouseMoveEventHandler(QMouseEvent *event)
QStyleOptionGraphicsItem * allocStyleOptionsArray(int numItems)
QGraphicsSceneDragDropEvent * lastDragDropEvent
void centerView(QGraphicsView::ViewportAnchor anchor)
bool canStartScrollingAt(const QPoint &startPos) const override
QRegion mapToViewRegion(const QGraphicsItem *item, const QRectF &rect) const
void storeMouseEvent(QMouseEvent *event)
Qt::MouseButton mousePressButton
void setUpdateClip(QGraphicsItem *)
QGraphicsView::CacheMode cacheMode
The QGraphicsView class provides a widget for displaying the contents of a QGraphicsScene.
QPainter::RenderHints renderHints
the default render hints for the view
void mousePressEvent(QMouseEvent *event) override
\reimp
void setInteractive(bool allowed)
void shear(qreal sh, qreal sv)
Shears the current view transformation by (sh, sv).
QPointF mapToScene(const QPoint &point) const
Returns the viewport coordinate point mapped to scene coordinates.
void mouseMoveEvent(QMouseEvent *event) override
\reimp
QSize sizeHint() const override
\reimp
QList< QGraphicsItem * > items() const
Returns a list of all the items in the associated scene, in descending stacking order (i....
void setResizeAnchor(ViewportAnchor anchor)
void updateScene(const QList< QRectF > &rects)
Schedules an update of the scene rectangles rects.
void centerOn(const QPointF &pos)
Scrolls the contents of the viewport to ensure that the scene coordinate pos, is centered in the view...
void focusInEvent(QFocusEvent *event) override
\reimp
void updateSceneRect(const QRectF &rect)
Notifies QGraphicsView that the scene's scene rect has changed.
void setForegroundBrush(const QBrush &brush)
ViewportUpdateMode viewportUpdateMode
how the viewport should update its contents.
void setTransform(const QTransform &matrix, bool combine=false)
Sets the view's current transformation matrix to matrix.
bool isInteractive() const
void resetCachedContent()
Resets any cached content.
void setDragMode(DragMode mode)
QBrush backgroundBrush
the background brush of the scene.
void setRenderHints(QPainter::RenderHints hints)
void contextMenuEvent(QContextMenuEvent *event) override
\reimp
void setBackgroundBrush(const QBrush &brush)
void translate(qreal dx, qreal dy)
Translates the current view transformation by (dx, dy).
void setOptimizationFlag(OptimizationFlag flag, bool enabled=true)
Enables flag if enabled is true; otherwise disables flag.
Qt::Alignment alignment
the alignment of the scene in the view when the whole scene is visible.
bool isTransformed() const
void setupViewport(QWidget *widget) override
This slot is called by QAbstractScrollArea after setViewport() has been called.
QTransform transform() const
Returns the current transformation matrix for the view.
void resetTransform()
Resets the view transformation to the identity matrix.
bool viewportEvent(QEvent *event) override
\reimp
bool event(QEvent *event) override
\reimp
void scrollContentsBy(int dx, int dy) override
\reimp
void ensureVisible(const QRectF &rect, int xmargin=50, int ymargin=50)
Scrolls the contents of the viewport so that the scene rectangle rect is visible, with margins specif...
OptimizationFlags optimizationFlags
flags that can be used to tune QGraphicsView's performance.
bool focusNextPrevChild(bool next) override
\reimp
virtual void drawItems(QPainter *painter, int numItems, QGraphicsItem *items[], const QStyleOptionGraphicsItem options[])
QVariant inputMethodQuery(Qt::InputMethodQuery query) const override
\reimp
void mouseDoubleClickEvent(QMouseEvent *event) override
\reimp
void paintEvent(QPaintEvent *event) override
\reimp
void inputMethodEvent(QInputMethodEvent *event) override
\reimp
QRectF sceneRect
the area of the scene visualized by this view.
void mouseReleaseEvent(QMouseEvent *event) override
\reimp
virtual void drawForeground(QPainter *painter, const QRectF &rect)
Draws the foreground of the scene using painter, after the background and all items are drawn.
void scale(qreal sx, qreal sy)
Scales the current view transformation by (sx, sy).
virtual void drawBackground(QPainter *painter, const QRectF &rect)
Draws the background of the scene using painter, before any items and the foreground are drawn.
void focusOutEvent(QFocusEvent *event) override
\reimp
void invalidateScene(const QRectF &rect=QRectF(), QGraphicsScene::SceneLayers layers=QGraphicsScene::AllLayers)
Invalidates and schedules a redraw of layers inside rect.
ViewportAnchor
This enums describe the possible anchors that QGraphicsView can use when the user resizes the view or...
void fitInView(const QRectF &rect, Qt::AspectRatioMode aspectRadioMode=Qt::IgnoreAspectRatio)
Scales the view matrix and scrolls the scroll bars to ensure that the scene rectangle rect fits insid...
void setCacheMode(CacheMode mode)
QTransform viewportTransform() const
Returns a matrix that maps scene coordinates to viewport coordinates.
ViewportAnchor transformationAnchor
how the view should position the scene during transformations.
void resizeEvent(QResizeEvent *event) override
\reimp
DragMode dragMode
the behavior for dragging the mouse over the scene while the left mouse button is pressed.
DragMode
This enum describes the default action for the view when pressing and dragging the mouse over the vie...
void setRenderHint(QPainter::RenderHint hint, bool enabled=true)
If enabled is true, the render hint hint is enabled; otherwise it is disabled.
~QGraphicsView()
Destructs the QGraphicsView object.
QGraphicsItem * itemAt(const QPoint &pos) const
Returns the item at position pos, which is in viewport coordinates.
void keyPressEvent(QKeyEvent *event) override
\reimp
void render(QPainter *painter, const QRectF &target=QRectF(), const QRect &source=QRect(), Qt::AspectRatioMode aspectRatioMode=Qt::KeepAspectRatio)
Renders the source rect, which is in view coordinates, from the scene into target,...
void setScene(QGraphicsScene *scene)
Sets the current scene to scene.
void keyReleaseEvent(QKeyEvent *event) override
\reimp
void showEvent(QShowEvent *event) override
\reimp
QGraphicsView(QWidget *parent=nullptr)
Constructs a QGraphicsView.
ViewportAnchor resizeAnchor
how the view should position the scene when the view is resized.
QPoint mapFromScene(const QPointF &point) const
Returns the scene coordinate point to viewport coordinates.
void setTransformationAnchor(ViewportAnchor anchor)
QGraphicsScene * scene() const
Returns a pointer to the scene that is currently visualized in the view.
void setOptimizationFlags(OptimizationFlags flags)
void rotate(qreal angle)
Rotates the current view transformation angle degrees clockwise.
void setSceneRect(const QRectF &rect)
void setViewportUpdateMode(ViewportUpdateMode mode)
QBrush foregroundBrush
the foreground brush of the scene.
CacheMode cacheMode
which parts of the view are cached
void setAlignment(Qt::Alignment alignment)
QScreen * primaryScreen
the primary (or default) screen of the application.
iterator insert(const Key &key, const T &value)
Inserts a new item with the key and a value of value.
Definition qhash.h:1283
The QHelpEvent class provides an event that is used to request helpful information about a particular...
Definition qevent.h:787
const QPoint & globalPos() const
Returns the mouse cursor position when the event was generated in global coordinates.
Definition qevent.h:798
const QPoint & pos() const
Returns the mouse cursor position when the event was generated, relative to the widget to which the e...
Definition qevent.h:797
The QInputMethodEvent class provides parameters for input method events.
Definition qevent.h:624
The QKeyEvent class describes a key event.
Definition qevent.h:423
int key() const
Returns the code of the key that was pressed or released.
Definition qevent.h:433
Definition qlist.h:74
qsizetype size() const noexcept
Definition qlist.h:386
bool isEmpty() const noexcept
Definition qlist.h:390
T & first()
Definition qlist.h:628
qsizetype capacity() const
Definition qlist.h:405
const_reference at(qsizetype i) const noexcept
Definition qlist.h:429
void reserve(qsizetype size)
Definition qlist.h:746
pointer data()
Definition qlist.h:414
void resize(qsizetype size)
Definition qlist.h:392
void clear()
Definition qlist.h:417
\inmodule QtGui
Definition qevent.h:195
static QMutableTouchEvent * from(QTouchEvent *e)
Definition qevent_p.h:37
void setTarget(QObject *target)
Definition qevent_p.h:41
\inmodule QtCore
Definition qobject.h:90
bool inherits(const char *classname) const
Returns true if this object is an instance of a class that inherits className or a QObject subclass t...
Definition qobject.h:313
virtual int devType() const
int width() const
int height() const
The QPaintEvent class contains event parameters for paint events.
Definition qevent.h:485
\inmodule QtGui
void translate(qreal dx, qreal dy)
Translates all elements in the path by ({dx}, {dy}).
void addPolygon(const QPolygonF &polygon)
Adds the given polygon to the path as an (unclosed) subpath.
void closeSubpath()
Closes the current subpath by drawing a line to the beginning of the subpath, automatically starting ...
The QPainter class performs low-level painting on widgets and other paint devices.
Definition qpainter.h:46
RenderHints renderHints() const
Returns a flag that specifies the rendering hints that are set for this painter.
QPaintDevice * device() const
Returns the paint device on which this painter is currently painting, or \nullptr if the painter is n...
void setClipRect(const QRectF &, Qt::ClipOperation op=Qt::ReplaceClip)
Enables clipping, and sets the clip region to the given rectangle using the given clip operation.
void setClipPath(const QPainterPath &path, Qt::ClipOperation op=Qt::ReplaceClip)
Enables clipping, and sets the clip path for the painter to the given path, with the clip operation.
void restore()
Restores the current painter state (pops a saved state off the stack).
const QTransform & worldTransform() const
Returns the world transformation matrix.
void setOpacity(qreal opacity)
void save()
Saves the current painter state (pushes the state onto a stack).
void setWorldTransform(const QTransform &matrix, bool combine=false)
Sets the world transformation matrix.
void drawPixmap(const QRectF &targetRect, const QPixmap &pixmap, const QRectF &sourceRect)
Draws the rectangular portion source of the given pixmap into the given target in the paint device.
RenderHint
Renderhints are used to specify flags to QPainter that may or may not be respected by any given engin...
Definition qpainter.h:51
@ Antialiasing
Definition qpainter.h:52
bool end()
Ends painting.
bool isActive() const
Returns true if begin() has been called and end() has not yet been called; otherwise returns false.
void setRenderHints(RenderHints hints, bool on=true)
void fillRect(const QRectF &, const QBrush &)
Fills the given rectangle with the brush specified.
void setClipRegion(const QRegion &, Qt::ClipOperation op=Qt::ReplaceClip)
Sets the clip region to the given region using the specified clip operation.
void setTransform(const QTransform &transform, bool combine=false)
bool testRenderHint(RenderHint hint) const
Definition qpainter.h:407
Returns a copy of the pixmap that is transformed using the given transformation transform and transfo...
Definition qpixmap.h:27
\inmodule QtCore\reentrant
Definition qpoint.h:214
constexpr qreal x() const noexcept
Returns the x coordinate of this point.
Definition qpoint.h:333
constexpr qreal y() const noexcept
Returns the y coordinate of this point.
Definition qpoint.h:338
constexpr qreal & rx() noexcept
Returns a reference to the x coordinate of this point.
Definition qpoint.h:353
constexpr QPoint toPoint() const
Rounds the coordinates of this point to the nearest integer, and returns a QPoint object with the rou...
Definition qpoint.h:394
\inmodule QtCore\reentrant
Definition qpoint.h:23
constexpr bool isNull() const noexcept
Returns true if both the x and y coordinates are set to 0, otherwise returns false.
Definition qpoint.h:122
constexpr int & rx() noexcept
Returns a reference to the x coordinate of this point.
Definition qpoint.h:152
constexpr int x() const noexcept
Returns the x coordinate of this point.
Definition qpoint.h:127
constexpr int y() const noexcept
Returns the y coordinate of this point.
Definition qpoint.h:132
virtual void setAccepted(bool accepted) override
\reimp
Definition qevent.cpp:315
The QPolygonF class provides a list of points using floating point precision.
Definition qpolygon.h:96
QRectF Q_GUI_EXPORT boundingRect() const
Returns the bounding rectangle of the polygon, or QRectF(0,0,0,0) if the polygon is empty.
Definition qpolygon.cpp:588
The QPolygon class provides a list of points using integer precision.
Definition qpolygon.h:23
\inmodule QtCore\reentrant
Definition qrect.h:483
constexpr bool isEmpty() const noexcept
Returns true if the rectangle is empty, otherwise returns false.
Definition qrect.h:647
constexpr qreal bottom() const noexcept
Returns the y-coordinate of the rectangle's bottom edge.
Definition qrect.h:499
QRect toAlignedRect() const noexcept
Definition qrect.cpp:2330
constexpr qreal height() const noexcept
Returns the height of the rectangle.
Definition qrect.h:718
constexpr qreal width() const noexcept
Returns the width of the rectangle.
Definition qrect.h:715
bool contains(const QRectF &r) const noexcept
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition qrect.cpp:1985
constexpr qreal left() const noexcept
Returns the x-coordinate of the rectangle's left edge.
Definition qrect.h:496
constexpr QPointF center() const noexcept
Returns the center point of the rectangle.
Definition qrect.h:685
constexpr QRect toRect() const noexcept
Returns a QRect based on the values of this rectangle.
Definition qrect.h:845
constexpr void translate(qreal dx, qreal dy) noexcept
Moves the rectangle dx along the x-axis and dy along the y-axis, relative to the current position.
Definition qrect.h:724
constexpr qreal top() const noexcept
Returns the y-coordinate of the rectangle's top edge.
Definition qrect.h:497
constexpr qreal right() const noexcept
Returns the x-coordinate of the rectangle's right edge.
Definition qrect.h:498
constexpr void setRect(qreal x, qreal y, qreal w, qreal h) noexcept
Sets the coordinates of the rectangle's top-left corner to (x, y), and its size to the given width an...
Definition qrect.h:767
\inmodule QtCore\reentrant
Definition qrect.h:30
bool intersects(const QRect &r) const noexcept
Returns true if this rectangle intersects with the given rectangle (i.e., there is at least one pixel...
Definition qrect.cpp:1065
constexpr void adjust(int x1, int y1, int x2, int y2) noexcept
Adds dx1, dy1, dx2 and dy2 respectively to the existing coordinates of the rectangle.
Definition qrect.h:372
constexpr int height() const noexcept
Returns the height of the rectangle.
Definition qrect.h:238
constexpr QRect adjusted(int x1, int y1, int x2, int y2) const noexcept
Returns a new rectangle with dx1, dy1, dx2 and dy2 added respectively to the existing coordinates of ...
Definition qrect.h:369
constexpr int top() const noexcept
Returns the y-coordinate of the rectangle's top edge.
Definition qrect.h:175
constexpr int left() const noexcept
Returns the x-coordinate of the rectangle's left edge.
Definition qrect.h:172
constexpr int width() const noexcept
Returns the width of the rectangle.
Definition qrect.h:235
constexpr QRect translated(int dx, int dy) const noexcept
Returns a copy of the rectangle that is translated dx along the x axis and dy along the y axis,...
Definition qrect.h:260
The QRegion class specifies a clip region for a painter.
Definition qregion.h:27
QRect boundingRect() const noexcept
Returns the bounding rectangle of this region.
int rectCount() const noexcept
QRegion translated(int dx, int dy) const
Definition qregion.cpp:593
The QResizeEvent class contains event parameters for resize events.
Definition qevent.h:547
T * data() const noexcept
Returns the value of the pointer referenced by this object.
The QScrollBar widget provides a vertical or horizontal scroll bar.
Definition qscrollbar.h:20
The QShowEvent class provides an event that is sent when a widget is shown.
Definition qevent.h:577
A base class for pointer events containing a single point, such as mouse events.
Definition qevent.h:108
QPointF position() const
Returns the position of the point in this event, relative to the widget or item that received the eve...
Definition qevent.h:118
\inmodule QtCore
Definition qsize.h:207
constexpr QSize toSize() const noexcept
Returns an integer based copy of this size.
Definition qsize.h:390
constexpr QSizeF boundedTo(const QSizeF &) const noexcept
Returns a size holding the minimum width and height of this size and the given otherSize.
Definition qsize.h:385
\inmodule QtCore
Definition qsize.h:25
constexpr int height() const noexcept
Returns the height.
Definition qsize.h:132
constexpr int width() const noexcept
Returns the width.
Definition qsize.h:129
The QStyleHintReturnMask class provides style hints that return a QRegion.
The QStyleOptionGraphicsItem class is used to describe the parameters needed to draw a QGraphicsItem.
@ SH_ScrollView_FrameOnlyAroundContents
Definition qstyle.h:600
@ SH_RubberBand_Mask
Definition qstyle.h:637
virtual int styleHint(StyleHint stylehint, const QStyleOption *opt=nullptr, const QWidget *widget=nullptr, QStyleHintReturn *returnData=nullptr) const =0
Returns an integer representing the specified style hint for the given widget described by the provid...
@ CE_RubberBand
Definition qstyle.h:209
@ PM_ScrollBarExtent
Definition qstyle.h:426
QEventPoint & point(int touchId)
The QTouchEvent class contains parameters that describe a touch event.
Definition qevent.h:916
The QTransform class specifies 2D transformations of a coordinate system.
Definition qtransform.h:20
static QTransform fromScale(qreal dx, qreal dy)
Creates a matrix which corresponds to a scaling of sx horizontally and sy vertically.
QTransform & scale(qreal sx, qreal sy)
Scales the coordinate system by sx horizontally and sy vertically, and returns a reference to the mat...
qreal dx() const
Returns the horizontal translation factor.
Definition qtransform.h:235
QPoint map(const QPoint &p) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
static QTransform fromTranslate(qreal dx, qreal dy)
Creates a matrix which corresponds to a translation of dx along the x axis and dy along the y axis.
QTransform inverted(bool *invertible=nullptr) const
Returns an inverted copy of this matrix.
QTransform & translate(qreal dx, qreal dy)
Moves the coordinate system dx along the x axis and dy along the y axis, and returns a reference to t...
QRect mapRect(const QRect &) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
qreal dy() const
Returns the vertical translation factor.
Definition qtransform.h:239
\inmodule QtCore
Definition qvariant.h:64
virtual bool isStereoEnabled()
Definition qwidget_p.h:630
static QWidgetPrivate * get(QWidget *w)
Definition qwidget_p.h:211
The QWidget class is the base class of all user interface objects.
Definition qwidget.h:99
void setAutoFillBackground(bool enabled)
Definition qwidget.cpp:319
void setAttribute(Qt::WidgetAttribute, bool on=true)
Sets the attribute attribute on this widget if on is true; otherwise clears the attribute.
void setMouseTracking(bool enable)
Definition qwidget.h:853
QWidget * focusWidget() const
Returns the last child of this widget that setFocus had been called on.
Definition qwidget.cpp:6851
void setAcceptDrops(bool on)
Definition qwidget.cpp:3443
void setFocusPolicy(Qt::FocusPolicy policy)
Definition qwidget.cpp:7904
void grabGesture(Qt::GestureType type, Qt::GestureFlags flags=Qt::GestureFlags())
Subscribes the widget to a given gesture with specific flags.
Qt::InputMethodHints inputMethodHints
What input method specific hints the widget has.
Definition qwidget.h:178
QStyle * style() const
Definition qwidget.cpp:2607
void setInputMethodHints(Qt::InputMethodHints hints)
QOpenGLWidget * widget
[1]
QCursor cursor
auto mo
[7]
rect
[4]
uint alignment
short next
Definition keywords.cpp:445
Combined button and popup list for selecting options.
InputMethodQuery
@ AlignRight
Definition qnamespace.h:145
@ AlignBottom
Definition qnamespace.h:153
@ AlignVCenter
Definition qnamespace.h:154
@ AlignTop
Definition qnamespace.h:152
@ AlignHCenter
Definition qnamespace.h:147
@ AlignHorizontal_Mask
Definition qnamespace.h:150
@ AlignVertical_Mask
Definition qnamespace.h:160
@ AlignLeft
Definition qnamespace.h:143
@ LeftButton
Definition qnamespace.h:57
@ WA_AcceptTouchEvents
Definition qnamespace.h:403
@ WA_SetCursor
Definition qnamespace.h:304
@ WA_InputMethodEnabled
Definition qnamespace.h:294
@ ReplaceClip
@ IntersectClip
AspectRatioMode
@ KeepAspectRatioByExpanding
@ KeepAspectRatio
@ IgnoreAspectRatio
@ StrongFocus
Definition qnamespace.h:109
@ Horizontal
Definition qnamespace.h:98
@ Vertical
Definition qnamespace.h:99
@ AddToSelection
@ ReplaceSelection
@ OpenHandCursor
@ ClosedHandCursor
@ transparent
Definition qnamespace.h:46
@ Key_Tab
Definition qnamespace.h:659
@ Key_Backtab
Definition qnamespace.h:660
@ ScrollBarAlwaysOn
@ ScrollBarAsNeeded
@ DescendingOrder
Definition qnamespace.h:122
@ AscendingOrder
Definition qnamespace.h:121
@ ControlModifier
ItemSelectionMode
@ IntersectsItemShape
@ IntersectsItemBoundingRect
@ NoBrush
GestureType
constexpr Initialization Uninitialized
Definition brush.cpp:5
EGLOutputLayerEXT EGLint EGLAttrib value
[5]
const EGLAttrib EGLOutputLayerEXT * layers
static QRectF adjustedItemEffectiveBoundingRect(const QGraphicsItem *item)
static bool intersectsViewport(const QRect &r, int width, int height)
static bool containsViewport(const QRect &r, int width, int height)
static void QRect_unite(QRect *rect, const QRect &other)
static const int QGRAPHICSVIEW_REGION_RECT_THRESHOLD
QPainterPath qt_regionToPath(const QRegion &region)
Definition qregion.cpp:1007
QT_BEGIN_NAMESPACE bool qt_sendSpontaneousEvent(QObject *receiver, QEvent *event)
int q_round_bound(qreal d)
static const int QGRAPHICSVIEW_PREALLOC_STYLE_OPTIONS
bool qt_sendSpontaneousEvent(QObject *receiver, QEvent *event)
#define qWarning
Definition qlogging.h:162
constexpr const T & qMin(const T &a, const T &b)
Definition qminmax.h:40
constexpr const T & qMax(const T &a, const T &b)
Definition qminmax.h:42
constexpr T qAbs(const T &t)
Definition qnumeric.h:328
#define SLOT(a)
Definition qobjectdefs.h:51
#define SIGNAL(a)
Definition qobjectdefs.h:52
GLint GLint GLint GLint GLint x
[0]
GLenum mode
GLfloat GLfloat GLfloat w
[0]
GLint GLsizei GLsizei height
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLboolean r
[2]
GLdouble GLdouble GLdouble GLdouble top
GLdouble GLdouble right
GLenum GLenum GLsizei const GLuint GLboolean enabled
GLint GLsizei width
GLint left
GLint GLint bottom
GLfloat angle
GLenum target
GLbitfield flags
GLenum GLuint GLintptr offset
GLint GLint GLint GLint GLint GLint GLint GLbitfield mask
GLint y
GLsizei GLsizei GLchar * source
struct _cl_event * event
GLuint GLenum GLenum transform
GLenum query
GLenum array
GLuint GLenum matrix
GLdouble GLdouble GLdouble GLdouble q
Definition qopenglext.h:259
GLsizei const GLchar *const * path
GLfloat GLfloat p
[1]
GLuint GLenum option
GLenum GLenum GLenum GLenum GLenum scale
static const QRectF boundingRect(const QPointF *points, int pointCount)
QPainterPath qt_regionToPath(const QRegion &region)
Definition qregion.cpp:1007
static QT_BEGIN_NAMESPACE qreal dpr(const QWindow *w)
#define Q_ASSERT(cond)
Definition qrandom.cpp:47
static QT_BEGIN_NAMESPACE QVariant hint(QPlatformIntegration::StyleHint h)
#define QT_CONFIG(feature)
#define tr(X)
#define emit
#define Q_UNUSED(x)
unsigned int quint32
Definition qtypes.h:45
long long qint64
Definition qtypes.h:55
double qreal
Definition qtypes.h:92
QWidget * qobject_cast< QWidget * >(QObject *o)
Definition qwidget.h:786
if(qFloatDistance(a, b)<(1<< 7))
[0]
connect(quitButton, &QPushButton::clicked, &app, &QCoreApplication::quit, Qt::QueuedConnection)
obj metaObject() -> className()
QObject::connect nullptr
myObject disconnect()
[26]
QSharedPointer< T > other(t)
[5]
QGraphicsScene scene
[0]
QGraphicsItem * item
view viewport() -> scroll(dx, dy, deviceRect)
edit isVisible()
QList< QTreeWidgetItem * > items
app setAttribute(Qt::AA_DontShowIconsInMenus)
QPainter painter(this)
[7]
aWidget window() -> setWindowTitle("New Window Title")
[2]
scrollArea setBackgroundRole(QPalette::Dark)
QNetworkProxy proxy
[0]
\inmodule QtCore
IUIAutomationTreeWalker __RPC__deref_out_opt IUIAutomationElement ** parent