Qt 4.8
qgraphicsview.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the QtGui module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 
43 
44 static const int QGRAPHICSVIEW_PREALLOC_STYLE_OPTIONS = 503; // largest prime < 2^9
45 
277 #include "qgraphicsview.h"
278 #include "qgraphicsview_p.h"
279 
280 #ifndef QT_NO_GRAPHICSVIEW
281 
282 #include "qgraphicsitem.h"
283 #include "qgraphicsitem_p.h"
284 #include "qgraphicsscene.h"
285 #include "qgraphicsscene_p.h"
286 #include "qgraphicssceneevent.h"
287 #include "qgraphicswidget.h"
288 
289 #include <QtCore/qdatetime.h>
290 #include <QtCore/qdebug.h>
291 #include <QtCore/qmath.h>
292 #include <QtGui/qapplication.h>
293 #include <QtGui/qdesktopwidget.h>
294 #include <QtGui/qevent.h>
295 #include <QtGui/qlayout.h>
296 #include <QtGui/qtransform.h>
297 #include <QtGui/qmatrix.h>
298 #include <QtGui/qpainter.h>
299 #include <QtGui/qscrollbar.h>
300 #include <QtGui/qstyleoption.h>
301 #include <QtGui/qinputcontext.h>
302 #ifdef Q_WS_X11
303 #include <QtGui/qpaintengine.h>
304 #include <private/qt_x11_p.h>
305 #endif
306 
307 #include <private/qevent_p.h>
308 
310 
311 bool qt_sendSpontaneousEvent(QObject *receiver, QEvent *event);
312 
313 inline int q_round_bound(qreal d) //### (int)(qreal) INT_MAX != INT_MAX for single precision
314 {
315  if (d <= (qreal) INT_MIN)
316  return INT_MIN;
317  else if (d >= (qreal) INT_MAX)
318  return INT_MAX;
319  return d >= 0.0 ? int(d + qreal(0.5)) : int(d - int(d-1) + qreal(0.5)) + int(d-1);
320 }
321 
323 {
324  QList<QTouchEvent::TouchPoint> touchPoints = touchEvent->touchPoints();
325  for (int i = 0; i < touchPoints.count(); ++i) {
326  QTouchEvent::TouchPoint &touchPoint = touchPoints[i];
327  // the scene will set the item local pos, startPos, lastPos, and rect before delivering to
328  // an item, but for now those functions are returning the view's local coordinates
329  touchPoint.setSceneRect(d->mapToScene(touchPoint.rect()));
330  touchPoint.setStartScenePos(d->mapToScene(touchPoint.startPos()));
331  touchPoint.setLastScenePos(d->mapToScene(touchPoint.lastPos()));
332 
333  // screenPos, startScreenPos, lastScreenPos, and screenRect are already set
334  }
335 
336  touchEvent->setTouchPoints(touchPoints);
337 }
338 
343  : renderHints(QPainter::TextAntialiasing),
344  dragMode(QGraphicsView::NoDrag),
346  connectedToScene(false),
347  useLastMouseEvent(false),
348  identityMatrix(true),
349  dirtyScroll(true),
350  accelerateScrolling(true),
351  keepLastCenterPoint(true),
352  transforming(false),
353  handScrolling(false),
356  fullUpdatePending(true),
357  hasUpdateClip(false),
359  leftIndent(0), topIndent(0),
362  transformationAnchor(QGraphicsView::AnchorViewCenter), resizeAnchor(QGraphicsView::NoAnchor),
363  viewportUpdateMode(QGraphicsView::MinimalViewportUpdate),
365  scene(0),
366 #ifndef QT_NO_RUBBERBAND
367  rubberBanding(false),
369 #endif
371 #ifndef QT_NO_CURSOR
373 #endif
376 {
378 }
379 
384 {
386 
387  QSize maxSize = q->maximumViewportSize();
388  int width = maxSize.width();
389  int height = maxSize.height();
390  QRectF viewRect = matrix.mapRect(q->sceneRect());
391 
392  bool frameOnlyAround = (q->style()->styleHint(QStyle::SH_ScrollView_FrameOnlyAroundContents, 0, q));
393  if (frameOnlyAround) {
395  height -= frameWidth * 2;
397  width -= frameWidth * 2;
398  }
399 
400  // Adjust the maximum width and height of the viewport based on the width
401  // of visible scroll bars.
402  int scrollBarExtent = q->style()->pixelMetric(QStyle::PM_ScrollBarExtent, 0, q);
403  if (frameOnlyAround)
404  scrollBarExtent += frameWidth * 2;
405 
406  bool useHorizontalScrollBar = (viewRect.width() > width) && hbarpolicy != Qt::ScrollBarAlwaysOff;
407  bool useVerticalScrollBar = (viewRect.height() > height) && vbarpolicy != Qt::ScrollBarAlwaysOff;
408  if (useHorizontalScrollBar && !useVerticalScrollBar) {
409  if (viewRect.height() > height - scrollBarExtent)
410  useVerticalScrollBar = true;
411  }
412  if (useVerticalScrollBar && !useHorizontalScrollBar) {
413  if (viewRect.width() > width - scrollBarExtent)
414  useHorizontalScrollBar = true;
415  }
416  if (useHorizontalScrollBar && hbarpolicy != Qt::ScrollBarAlwaysOn)
417  height -= scrollBarExtent;
418  if (useVerticalScrollBar && vbarpolicy != Qt::ScrollBarAlwaysOn)
419  width -= scrollBarExtent;
420 
421  // Setting the ranges of these scroll bars can/will cause the values to
422  // change, and scrollContentsBy() will be called correspondingly. This
423  // will reset the last center point.
424  QPointF savedLastCenterPoint = lastCenterPoint;
425 
426  // Remember the former indent settings
427  qreal oldLeftIndent = leftIndent;
428  qreal oldTopIndent = topIndent;
429 
430  // If the whole scene fits horizontally, we center the scene horizontally,
431  // and ignore the horizontal scroll bars.
432  int left = q_round_bound(viewRect.left());
433  int right = q_round_bound(viewRect.right() - width);
434  if (left >= right) {
435  hbar->setRange(0, 0);
436 
438  case Qt::AlignLeft:
439  leftIndent = -viewRect.left();
440  break;
441  case Qt::AlignRight:
442  leftIndent = width - viewRect.width() - viewRect.left() - 1;
443  break;
444  case Qt::AlignHCenter:
445  default:
446  leftIndent = width / 2 - (viewRect.left() + viewRect.right()) / 2;
447  break;
448  }
449  } else {
450  hbar->setRange(left, right);
451  hbar->setPageStep(width);
452  hbar->setSingleStep(width / 20);
453  leftIndent = 0;
454  }
455 
456  // If the whole scene fits vertically, we center the scene vertically, and
457  // ignore the vertical scroll bars.
458  int top = q_round_bound(viewRect.top());
459  int bottom = q_round_bound(viewRect.bottom() - height);
460  if (top >= bottom) {
461  vbar->setRange(0, 0);
462 
463  switch (alignment & Qt::AlignVertical_Mask) {
464  case Qt::AlignTop:
465  topIndent = -viewRect.top();
466  break;
467  case Qt::AlignBottom:
468  topIndent = height - viewRect.height() - viewRect.top() - 1;
469  break;
470  case Qt::AlignVCenter:
471  default:
472  topIndent = height / 2 - (viewRect.top() + viewRect.bottom()) / 2;
473  break;
474  }
475  } else {
476  vbar->setRange(top, bottom);
477  vbar->setPageStep(height);
478  vbar->setSingleStep(height / 20);
479  topIndent = 0;
480  }
481 
482  // Restorethe center point from before the ranges changed.
483  lastCenterPoint = savedLastCenterPoint;
484 
485  // Issue a full update if the indents change.
486  // ### If the transform is still the same, we can get away with just a
487  // scroll instead.
488  if (oldLeftIndent != leftIndent || oldTopIndent != topIndent) {
489  dirtyScroll = true;
490  updateAll();
491  } else if (q->isRightToLeft() && !leftIndent) {
492  // In reverse mode, the horizontal scroll always changes after the content
493  // size has changed, as the scroll is calculated by summing the min and
494  // max values of the range and subtracting the current value. In normal
495  // mode the scroll remains unchanged unless the indent has changed.
496  dirtyScroll = true;
497  }
498 
500  // Invalidate the background pixmap
502  }
503 }
504 
509 {
511  switch (anchor) {
513  if (q->underMouse()) {
514  // Last scene pos: lastMouseMoveScenePoint
515  // Current mouse pos:
516  QPointF transformationDiff = q->mapToScene(viewport->rect().center())
517  - q->mapToScene(viewport->mapFromGlobal(QCursor::pos()));
518  q->centerOn(lastMouseMoveScenePoint + transformationDiff);
519  } else {
520  q->centerOn(lastCenterPoint);
521  }
522  break;
523  }
525  q->centerOn(lastCenterPoint);
526  break;
528  break;
529  }
530 }
531 
536 {
538  lastCenterPoint = q->mapToScene(viewport->rect().center());
539 }
540 
551 {
552  if (dirtyScroll)
553  const_cast<QGraphicsViewPrivate *>(this)->updateScroll();
554  return scrollX;
555 }
556 
567 {
568  if (dirtyScroll)
569  const_cast<QGraphicsViewPrivate *>(this)->updateScroll();
570  return scrollY;
571 }
572 
579 {
580  if (dirtyScroll)
581  const_cast<QGraphicsViewPrivate *>(this)->updateScroll();
582  QRectF scrolled = QRectF(rect.translated(scrollX, scrollY));
583  return identityMatrix ? scrolled : matrix.inverted().mapRect(scrolled);
584 }
585 
586 
593 {
594  if (dirtyScroll)
595  const_cast<QGraphicsViewPrivate *>(this)->updateScroll();
596  return (identityMatrix ? rect : matrix.mapRect(rect)).translated(-scrollX, -scrollY);
597 }
598 
603 {
606  if (q->isRightToLeft()) {
607  if (!leftIndent) {
608  scrollX += hbar->minimum();
609  scrollX += hbar->maximum();
610  scrollX -= hbar->value();
611  }
612  } else {
613  scrollX += hbar->value();
614  }
615 
617 
618  dirtyScroll = false;
619 }
620 
625 {
626  if (!useLastMouseEvent || !scene)
627  return;
629 }
630 
635 {
636  useLastMouseEvent = true;
637  lastMouseEvent = QMouseEvent(QEvent::MouseMove, event->pos(), event->globalPos(),
638  event->button(), event->buttons(), event->modifiers());
639 }
640 
642 {
644 
645  storeMouseEvent(event);
647 
649  return;
650  if (handScrolling)
651  return;
652  if (!scene)
653  return;
654 
656  mouseEvent.setWidget(viewport);
659  mouseEvent.setScenePos(q->mapToScene(event->pos()));
660  mouseEvent.setScreenPos(event->globalPos());
663  mouseEvent.setButtons(event->buttons());
664  mouseEvent.setButton(event->button());
665  mouseEvent.setModifiers(event->modifiers());
666  lastMouseMoveScenePoint = mouseEvent.scenePos();
667  lastMouseMoveScreenPoint = mouseEvent.screenPos();
668  mouseEvent.setAccepted(false);
669  if (event->spontaneous())
670  qt_sendSpontaneousEvent(scene, &mouseEvent);
671  else
672  QApplication::sendEvent(scene, &mouseEvent);
673 
674  // Remember whether the last event was accepted or not.
675  lastMouseEvent.setAccepted(mouseEvent.isAccepted());
676 
677  if (mouseEvent.isAccepted() && mouseEvent.buttons() != 0) {
678  // The event was delivered to a mouse grabber; the press is likely to
679  // have set a cursor, and we must not change it.
680  return;
681  }
682 
683 #ifndef QT_NO_CURSOR
684  // If all the items ignore hover events, we don't look-up any items
685  // in QGraphicsScenePrivate::dispatchHoverEvent, hence the
686  // cachedItemsUnderMouse list will be empty. We therefore do the look-up
687  // for cursor items here if not all items use the default cursor.
688  if (scene->d_func()->allItemsIgnoreHoverEvents && !scene->d_func()->allItemsUseDefaultCursor
689  && scene->d_func()->cachedItemsUnderMouse.isEmpty()) {
690  scene->d_func()->cachedItemsUnderMouse = scene->d_func()->itemsAtPosition(mouseEvent.screenPos(),
691  mouseEvent.scenePos(),
692  mouseEvent.widget());
693  }
694  // Find the topmost item under the mouse with a cursor.
695  foreach (QGraphicsItem *item, scene->d_func()->cachedItemsUnderMouse) {
696  if (item->hasCursor()) {
697  _q_setViewportCursor(item->cursor());
698  return;
699  }
700  }
701 
702  // No items with cursors found; revert to the view cursor.
704  // Restore the original viewport cursor.
705  hasStoredOriginalCursor = false;
707  }
708 #endif
709 }
710 
714 #ifndef QT_NO_RUBBERBAND
716 {
718  QStyleOptionRubberBand option;
719  option.initFrom(widget);
720  option.rect = rect;
721  option.opaque = false;
722  option.shape = QRubberBand::Rectangle;
723 
724  QRegion tmp;
725  tmp += rect;
726  if (widget->style()->styleHint(QStyle::SH_RubberBand_Mask, &option, widget, &mask))
727  tmp &= mask.region;
728  return tmp;
729 }
730 #endif
731 
735 #ifndef QT_NO_CURSOR
737 {
741  }
742  viewport->setCursor(cursor);
743 }
744 #endif
745 
749 #ifndef QT_NO_CURSOR
751 {
753  foreach (QGraphicsItem *item, q->items(lastMouseEvent.pos())) {
754  if (item->hasCursor()) {
755  _q_setViewportCursor(item->cursor());
756  return;
757  }
758  }
759 
760  // Restore the original viewport cursor.
762  hasStoredOriginalCursor = false;
765  else
767  }
768 }
769 #endif
770 
775 {
776  delete lastDragDropEvent;
788 }
789 
794  QDropEvent *source)
795 {
796 #ifndef QT_NO_DRAGANDDROP
798  dest->setScenePos(q->mapToScene(source->pos()));
799  dest->setScreenPos(q->mapToGlobal(source->pos()));
800  dest->setButtons(source->mouseButtons());
801  dest->setModifiers(source->keyboardModifiers());
802  dest->setPossibleActions(source->possibleActions());
803  dest->setProposedAction(source->proposedAction());
804  dest->setDropAction(source->dropAction());
805  dest->setMimeData(source->mimeData());
806  dest->setWidget(viewport);
807  dest->setSource(source->source());
808 #else
809  Q_UNUSED(dest)
810  Q_UNUSED(source)
811 #endif
812 }
813 
818 {
819  Q_Q(const QGraphicsView);
820  if (dirtyScroll)
821  const_cast<QGraphicsViewPrivate *>(this)->updateScroll();
822 
823  if (item->d_ptr->itemIsUntransformable()) {
824  QTransform itv = item->deviceTransform(q->viewportTransform());
825  return itv.mapRect(rect).toAlignedRect();
826  }
827 
828  // Translate-only
829  // COMBINE
830  QPointF offset;
831  const QGraphicsItem *parentItem = item;
832  const QGraphicsItemPrivate *itemd;
833  do {
834  itemd = parentItem->d_ptr.data();
835  if (itemd->transformData)
836  break;
837  offset += itemd->pos;
838  } while ((parentItem = itemd->parent));
839 
840  QRectF baseRect = rect.translated(offset.x(), offset.y());
841  if (!parentItem) {
842  if (identityMatrix) {
843  baseRect.translate(-scrollX, -scrollY);
844  return baseRect.toAlignedRect();
845  }
846  return matrix.mapRect(baseRect).translated(-scrollX, -scrollY).toAlignedRect();
847  }
848 
849  QTransform tr = parentItem->sceneTransform();
850  if (!identityMatrix)
851  tr *= matrix;
852  QRectF r = tr.mapRect(baseRect);
853  r.translate(-scrollX, -scrollY);
854  return r.toAlignedRect();
855 }
856 
861 {
862  Q_Q(const QGraphicsView);
863  if (dirtyScroll)
864  const_cast<QGraphicsViewPrivate *>(this)->updateScroll();
865 
866  // Accurate bounding region
867  QTransform itv = item->deviceTransform(q->viewportTransform());
868  return item->boundingRegion(itv) & itv.mapRect(rect).toAlignedRect();
869 }
870 
875 {
876  if (!scene)
877  return;
878 
879  if (fullUpdatePending) {
880  viewport->update();
883  } else {
884  viewport->update(dirtyRegion); // Already adjusted in updateRect/Region.
885  }
886 
888  dirtyRegion = QRegion();
889 }
890 
891 static inline bool intersectsViewport(const QRect &r, int width, int height)
892 { return !(r.left() > width) && !(r.right() < 0) && !(r.top() >= height) && !(r.bottom() < 0); }
893 
894 static inline bool containsViewport(const QRect &r, int width, int height)
895 { return r.left() <= 0 && r.top() <= 0 && r.right() >= width - 1 && r.bottom() >= height - 1; }
896 
897 static inline void QRect_unite(QRect *rect, const QRect &other)
898 {
899  if (rect->isEmpty()) {
900  *rect = other;
901  } else {
902  rect->setCoords(qMin(rect->left(), other.left()), qMin(rect->top(), other.top()),
903  qMax(rect->right(), other.right()), qMax(rect->bottom(), other.bottom()));
904  }
905 }
906 
907 /*
908  Calling this function results in update rects being clipped to the item's
909  bounding rect. Note that updates prior to this function call is not clipped.
910  The clip is removed by passing 0.
911 */
913 {
915  // We simply ignore the request if the update mode is either FullViewportUpdate
916  // or NoViewportUpdate; in that case there's no point in clipping anything.
919  hasUpdateClip = false;
920  return;
921  }
922 
923  // Calculate the clip (item's bounding rect in view coordinates).
924  // Optimized version of:
925  // QRect clip = item->deviceTransform(q->viewportTransform())
926  // .mapRect(item->boundingRect()).toAlignedRect();
927  QRect clip;
928  if (item->d_ptr->itemIsUntransformable()) {
929  QTransform xform = item->deviceTransform(q->viewportTransform());
930  clip = xform.mapRect(item->boundingRect()).toAlignedRect();
931  } else if (item->d_ptr->sceneTransformTranslateOnly && identityMatrix) {
932  QRectF r(item->boundingRect());
934  item->d_ptr->sceneTransform.dy() - verticalScroll());
935  clip = r.toAlignedRect();
936  } else if (!q->isTransformed()) {
937  clip = item->d_ptr->sceneTransform.mapRect(item->boundingRect()).toAlignedRect();
938  } else {
939  QTransform xform = item->d_ptr->sceneTransform;
940  xform *= q->viewportTransform();
941  clip = xform.mapRect(item->boundingRect()).toAlignedRect();
942  }
943 
944  if (hasUpdateClip) {
945  // Intersect with old clip.
946  updateClip &= clip;
947  } else {
948  updateClip = clip;
949  hasUpdateClip = true;
950  }
951 }
952 
953 bool QGraphicsViewPrivate::updateRegion(const QRectF &rect, const QTransform &xform)
954 {
955  if (rect.isEmpty())
956  return false;
957 
960  // No point in updating with QRegion granularity; use the rect instead.
961  return updateRectF(xform.mapRect(rect));
962  }
963 
964  // Update mode is either Minimal or Smart, so we have to do a potentially slow operation,
965  // which is clearly documented here: QGraphicsItem::setBoundingRegionGranularity.
966  const QRegion region = xform.map(QRegion(rect.toAlignedRect()));
967  QRect viewRect = region.boundingRect();
968  const bool dontAdjustForAntialiasing = optimizationFlags & QGraphicsView::DontAdjustForAntialiasing;
969  if (dontAdjustForAntialiasing)
970  viewRect.adjust(-1, -1, 1, 1);
971  else
972  viewRect.adjust(-2, -2, 2, 2);
973  if (!intersectsViewport(viewRect, viewport->width(), viewport->height()))
974  return false; // Update region for sure outside viewport.
975 
976  const QVector<QRect> &rects = region.rects();
977  for (int i = 0; i < rects.size(); ++i) {
978  viewRect = rects.at(i);
979  if (dontAdjustForAntialiasing)
980  viewRect.adjust(-1, -1, 1, 1);
981  else
982  viewRect.adjust(-2, -2, 2, 2);
983  if (hasUpdateClip)
984  viewRect &= updateClip;
985  dirtyRegion += viewRect;
986  }
987 
988  return true;
989 }
990 
991 // NB! Assumes the rect 'r' is already aligned and adjusted for antialiasing.
992 // For QRectF use updateRectF(const QRectF &) to ensure proper adjustments.
994 {
997  return false;
998  }
999 
1000  switch (viewportUpdateMode) {
1002  fullUpdatePending = true;
1003  viewport->update();
1004  break;
1006  if (hasUpdateClip)
1008  else
1011  fullUpdatePending = true;
1012  viewport->update();
1013  }
1014  break;
1015  case QGraphicsView::SmartViewportUpdate: // ### DEPRECATE
1017  if (hasUpdateClip)
1018  dirtyRegion += r & updateClip;
1019  else
1020  dirtyRegion += r;
1021  break;
1022  default:
1023  break;
1024  }
1025 
1026  return true;
1027 }
1028 
1030 {
1031  if (mustAllocateStyleOptions || (numItems > styleOptions.capacity()))
1032  // too many items, let's allocate on-the-fly
1033  return new QStyleOptionGraphicsItem[numItems];
1034 
1035  // expand only whenever necessary
1036  if (numItems > styleOptions.size())
1037  styleOptions.resize(numItems);
1038 
1039  mustAllocateStyleOptions = true;
1040  return styleOptions.data();
1041 }
1042 
1044 {
1045  mustAllocateStyleOptions = false;
1046  if (array != styleOptions.data())
1047  delete [] array;
1048 }
1049 
1051 
1062  const QTransform &viewTransform) const
1063 {
1064  Q_Q(const QGraphicsView);
1065 
1066  // Step 1) If all items are contained within the expose region, then
1067  // return a list of all visible items. ### the scene's growing bounding
1068  // rect does not take into account untransformable items.
1069  const QRectF exposedRegionSceneBounds = q->mapToScene(exposedRegion.boundingRect().adjusted(-1, -1, 1, 1))
1070  .boundingRect();
1071  if (exposedRegionSceneBounds.contains(scene->sceneRect())) {
1072  Q_ASSERT(allItems);
1073  *allItems = true;
1074 
1075  // All items are guaranteed within the exposed region.
1076  return scene->items(Qt::AscendingOrder);
1077  }
1078 
1079  // Step 2) If the expose region is a simple rect and the view is only
1080  // translated or scaled, search for items using
1081  // QGraphicsScene::items(QRectF).
1082  bool simpleRectLookup = exposedRegion.rectCount() == 1 && matrix.type() <= QTransform::TxScale;
1083  if (simpleRectLookup) {
1084  return scene->items(exposedRegionSceneBounds,
1086  Qt::AscendingOrder, viewTransform);
1087  }
1088 
1089  // If the region is complex or the view has a complex transform, adjust
1090  // the expose region, convert it to a path, and then search for items
1091  // using QGraphicsScene::items(QPainterPath);
1092  QRegion adjustedRegion;
1093  foreach (const QRect &r, exposedRegion.rects())
1094  adjustedRegion += r.adjusted(-1, -1, 1, 1);
1095 
1096  const QPainterPath exposedScenePath(q->mapToScene(qt_regionToPath(adjustedRegion)));
1097  return scene->items(exposedScenePath, Qt::IntersectsItemBoundingRect,
1098  Qt::AscendingOrder, viewTransform);
1099 }
1100 
1112 {
1113  Q_Q(QGraphicsView);
1114  QGraphicsItem *focusItem = 0;
1115  bool enabled = scene && (focusItem = scene->focusItem())
1116  && (focusItem->d_ptr->flags & QGraphicsItem::ItemAcceptsInputMethod);
1117  q->setAttribute(Qt::WA_InputMethodEnabled, enabled);
1118  q->viewport()->setAttribute(Qt::WA_InputMethodEnabled, enabled);
1119 
1120  if (!enabled) {
1121  q->setInputMethodHints(0);
1122  return;
1123  }
1124 
1125  QGraphicsProxyWidget *proxy = focusItem->d_ptr->isWidget && focusItem->d_ptr->isProxyWidget()
1126  ? static_cast<QGraphicsProxyWidget *>(focusItem) : 0;
1127  if (!proxy) {
1128  q->setInputMethodHints(focusItem->inputMethodHints());
1129  } else if (QWidget *widget = proxy->widget()) {
1130  if (QWidget *fw = widget->focusWidget())
1131  widget = fw;
1133  } else {
1134  q->setInputMethodHints(0);
1135  }
1136 }
1137 
1143 {
1144  setViewport(0);
1145  setAcceptDrops(true);
1147  // Investigate leaving these disabled by default.
1150 }
1151 
1158 {
1159  setScene(scene);
1160  setViewport(0);
1161  setAcceptDrops(true);
1163  // Investigate leaving these disabled by default.
1166 }
1167 
1172  : QAbstractScrollArea(dd, parent)
1173 {
1174  setViewport(0);
1175  setAcceptDrops(true);
1177  // Investigate leaving these disabled by default.
1180 }
1181 
1186 {
1187  Q_D(QGraphicsView);
1188  if (d->scene)
1189  d->scene->d_func()->views.removeAll(this);
1190  delete d->lastDragDropEvent;
1191 }
1192 
1197 {
1198  Q_D(const QGraphicsView);
1199  if (d->scene) {
1200  QSizeF baseSize = d->matrix.mapRect(sceneRect()).size();
1201  baseSize += QSizeF(d->frameWidth * 2, d->frameWidth * 2);
1202  return baseSize.boundedTo((3 * QApplication::desktop()->size()) / 4).toSize();
1203  }
1205 }
1206 
1225 QPainter::RenderHints QGraphicsView::renderHints() const
1226 {
1227  Q_D(const QGraphicsView);
1228  return d->renderHints;
1229 }
1230 void QGraphicsView::setRenderHints(QPainter::RenderHints hints)
1231 {
1232  Q_D(QGraphicsView);
1233  if (hints == d->renderHints)
1234  return;
1235  d->renderHints = hints;
1236  d->updateAll();
1237 }
1238 
1246 {
1247  Q_D(QGraphicsView);
1248  QPainter::RenderHints oldHints = d->renderHints;
1249  if (enabled)
1250  d->renderHints |= hint;
1251  else
1252  d->renderHints &= ~hint;
1253  if (oldHints != d->renderHints)
1254  d->updateAll();
1255 }
1256 
1272 Qt::Alignment QGraphicsView::alignment() const
1273 {
1274  Q_D(const QGraphicsView);
1275  return d->alignment;
1276 }
1278 {
1279  Q_D(QGraphicsView);
1280  if (d->alignment != alignment) {
1281  d->alignment = alignment;
1282  d->recalculateContentSize();
1283  }
1284 }
1285 
1308 {
1309  Q_D(const QGraphicsView);
1310  return d->transformationAnchor;
1311 }
1313 {
1314  Q_D(QGraphicsView);
1315  d->transformationAnchor = anchor;
1316 
1317  // Ensure mouse tracking is enabled in the case we are using AnchorUnderMouse
1318  // in order to have up-to-date information for centering the view.
1319  if (d->transformationAnchor == AnchorUnderMouse)
1320  d->viewport->setMouseTracking(true);
1321 }
1322 
1343 {
1344  Q_D(const QGraphicsView);
1345  return d->resizeAnchor;
1346 }
1348 {
1349  Q_D(QGraphicsView);
1350  d->resizeAnchor = anchor;
1351 
1352  // Ensure mouse tracking is enabled in the case we are using AnchorUnderMouse
1353  // in order to have up-to-date information for centering the view.
1354  if (d->resizeAnchor == AnchorUnderMouse)
1355  d->viewport->setMouseTracking(true);
1356 }
1357 
1380 {
1381  Q_D(const QGraphicsView);
1382  return d->viewportUpdateMode;
1383 }
1385 {
1386  Q_D(QGraphicsView);
1387  d->viewportUpdateMode = mode;
1388 }
1389 
1411 QGraphicsView::OptimizationFlags QGraphicsView::optimizationFlags() const
1412 {
1413  Q_D(const QGraphicsView);
1414  return d->optimizationFlags;
1415 }
1416 void QGraphicsView::setOptimizationFlags(OptimizationFlags flags)
1417 {
1418  Q_D(QGraphicsView);
1419  d->optimizationFlags = flags;
1420 }
1421 
1428 {
1429  Q_D(QGraphicsView);
1430  if (enabled)
1431  d->optimizationFlags |= flag;
1432  else
1433  d->optimizationFlags &= ~flag;
1434 }
1435 
1454 {
1455  Q_D(const QGraphicsView);
1456  return d->dragMode;
1457 }
1459 {
1460  Q_D(QGraphicsView);
1461  if (d->dragMode == mode)
1462  return;
1463 
1464 #ifndef QT_NO_CURSOR
1465  if (d->dragMode == ScrollHandDrag)
1466  viewport()->unsetCursor();
1467 #endif
1468 
1469  // If dragMode is unset while dragging, e.g. via a keyEvent, we
1470  // don't unset the handScrolling state. When enabling scrolling
1471  // again the mouseMoveEvent will automatically start scrolling,
1472  // without a mousePress
1473  if (d->dragMode == ScrollHandDrag && mode == NoDrag && d->handScrolling)
1474  d->handScrolling = false;
1475 
1476  d->dragMode = mode;
1477 
1478 #ifndef QT_NO_CURSOR
1479  if (d->dragMode == ScrollHandDrag) {
1480  // Forget the stored viewport cursor when we enter scroll hand drag mode.
1481  d->hasStoredOriginalCursor = false;
1483  }
1484 #endif
1485 }
1486 
1487 #ifndef QT_NO_RUBBERBAND
1488 
1505 {
1506  Q_D(const QGraphicsView);
1507  return d->rubberBandSelectionMode;
1508 }
1510 {
1511  Q_D(QGraphicsView);
1512  d->rubberBandSelectionMode = mode;
1513 }
1514 #endif
1515 
1539 QGraphicsView::CacheMode QGraphicsView::cacheMode() const
1540 {
1541  Q_D(const QGraphicsView);
1542  return d->cacheMode;
1543 }
1544 void QGraphicsView::setCacheMode(CacheMode mode)
1545 {
1546  Q_D(QGraphicsView);
1547  if (mode == d->cacheMode)
1548  return;
1549  d->cacheMode = mode;
1551 }
1552 
1567 {
1568  Q_D(QGraphicsView);
1569  if (d->cacheMode == CacheNone)
1570  return;
1571 
1572  if (d->cacheMode & CacheBackground) {
1573  // Background caching is enabled.
1574  d->mustResizeBackgroundPixmap = true;
1575  d->updateAll();
1576  } else if (d->mustResizeBackgroundPixmap) {
1577  // Background caching is disabled.
1578  // Cleanup, free some resources.
1579  d->mustResizeBackgroundPixmap = false;
1580  d->backgroundPixmap = QPixmap();
1581  d->backgroundPixmapExposed = QRegion();
1582  }
1583 }
1584 
1601 void QGraphicsView::invalidateScene(const QRectF &rect, QGraphicsScene::SceneLayers layers)
1602 {
1603  Q_D(QGraphicsView);
1604  if ((layers & QGraphicsScene::BackgroundLayer) && !d->mustResizeBackgroundPixmap) {
1605  QRect viewRect = mapFromScene(rect).boundingRect();
1606  if (viewport()->rect().intersects(viewRect)) {
1607  // The updated background area is exposed; schedule this area for
1608  // redrawing.
1609  d->backgroundPixmapExposed += viewRect;
1610  if (d->scene)
1611  d->scene->update(rect);
1612  }
1613  }
1614 }
1615 
1630 {
1631  Q_D(const QGraphicsView);
1632  return d->sceneInteractionAllowed;
1633 }
1635 {
1636  Q_D(QGraphicsView);
1637  d->sceneInteractionAllowed = allowed;
1638 }
1639 
1647 {
1648  Q_D(const QGraphicsView);
1649  return d->scene;
1650 }
1651 
1661 {
1662  Q_D(QGraphicsView);
1663  if (d->scene == scene)
1664  return;
1665 
1666  // Always update the viewport when the scene changes.
1667  d->updateAll();
1668 
1669  // Remove the previously assigned scene.
1670  if (d->scene) {
1671  disconnect(d->scene, SIGNAL(changed(QList<QRectF>)),
1672  this, SLOT(updateScene(QList<QRectF>)));
1673  disconnect(d->scene, SIGNAL(sceneRectChanged(QRectF)),
1674  this, SLOT(updateSceneRect(QRectF)));
1675  d->scene->d_func()->removeView(this);
1676  d->connectedToScene = false;
1677 
1678  if (isActiveWindow() && isVisible()) {
1679  QEvent windowDeactivate(QEvent::WindowDeactivate);
1680  QApplication::sendEvent(d->scene, &windowDeactivate);
1681  }
1682  if(hasFocus())
1683  d->scene->clearFocus();
1684  }
1685 
1686  // Assign the new scene and update the contents (scrollbars, etc.)).
1687  if ((d->scene = scene)) {
1688  connect(d->scene, SIGNAL(sceneRectChanged(QRectF)),
1689  this, SLOT(updateSceneRect(QRectF)));
1690  d->updateSceneSlotReimplementedChecked = false;
1691  d->scene->d_func()->addView(this);
1692  d->recalculateContentSize();
1693  d->lastCenterPoint = sceneRect().center();
1694  d->keepLastCenterPoint = true;
1695  // We are only interested in mouse tracking if items accept
1696  // hover events or use non-default cursors.
1697  if (!d->scene->d_func()->allItemsIgnoreHoverEvents
1698  || !d->scene->d_func()->allItemsUseDefaultCursor) {
1699  d->viewport->setMouseTracking(true);
1700  }
1701 
1702  // enable touch events if any items is interested in them
1703  if (!d->scene->d_func()->allItemsIgnoreTouchEvents)
1704  d->viewport->setAttribute(Qt::WA_AcceptTouchEvents);
1705 
1706  if (isActiveWindow() && isVisible()) {
1707  QEvent windowActivate(QEvent::WindowActivate);
1708  QApplication::sendEvent(d->scene, &windowActivate);
1709  }
1710  } else {
1711  d->recalculateContentSize();
1712  }
1713 
1714  d->updateInputMethodSensitivity();
1715 
1716  if (d->scene && hasFocus())
1717  d->scene->setFocus();
1718 }
1719 
1747 {
1748  Q_D(const QGraphicsView);
1749  if (d->hasSceneRect)
1750  return d->sceneRect;
1751  if (d->scene)
1752  return d->scene->sceneRect();
1753  return QRectF();
1754 }
1756 {
1757  Q_D(QGraphicsView);
1758  d->hasSceneRect = !rect.isNull();
1759  d->sceneRect = rect;
1760  d->recalculateContentSize();
1761 }
1762 
1770 {
1771  Q_D(const QGraphicsView);
1772  return d->matrix.toAffine();
1773 }
1774 
1801 void QGraphicsView::setMatrix(const QMatrix &matrix, bool combine)
1802 {
1803  setTransform(QTransform(matrix), combine);
1804 }
1805 
1812 {
1813  resetTransform();
1814 }
1815 
1822 {
1823  Q_D(QGraphicsView);
1824  QTransform matrix = d->matrix;
1825  matrix.rotate(angle);
1826  setTransform(matrix);
1827 }
1828 
1835 {
1836  Q_D(QGraphicsView);
1837  QTransform matrix = d->matrix;
1838  matrix.scale(sx, sy);
1839  setTransform(matrix);
1840 }
1841 
1848 {
1849  Q_D(QGraphicsView);
1850  QTransform matrix = d->matrix;
1851  matrix.shear(sh, sv);
1852  setTransform(matrix);
1853 }
1854 
1861 {
1862  Q_D(QGraphicsView);
1863  QTransform matrix = d->matrix;
1864  matrix.translate(dx, dy);
1865  setTransform(matrix);
1866 }
1867 
1881 {
1882  Q_D(QGraphicsView);
1883  qreal width = viewport()->width();
1884  qreal height = viewport()->height();
1885  QPointF viewPoint = d->matrix.map(pos);
1886  QPointF oldCenterPoint = pos;
1887 
1888  if (!d->leftIndent) {
1889  if (isRightToLeft()) {
1890  qint64 horizontal = 0;
1891  horizontal += horizontalScrollBar()->minimum();
1892  horizontal += horizontalScrollBar()->maximum();
1893  horizontal -= int(viewPoint.x() - width / qreal(2.0));
1894  horizontalScrollBar()->setValue(horizontal);
1895  } else {
1896  horizontalScrollBar()->setValue(int(viewPoint.x() - width / qreal(2.0)));
1897  }
1898  }
1899  if (!d->topIndent)
1900  verticalScrollBar()->setValue(int(viewPoint.y() - height / qreal(2.0)));
1901  d->lastCenterPoint = oldCenterPoint;
1902 }
1903 
1927 {
1928  centerOn(item->sceneBoundingRect().center());
1929 }
1930 
1940 void QGraphicsView::ensureVisible(const QRectF &rect, int xmargin, int ymargin)
1941 {
1942  Q_D(QGraphicsView);
1943  qreal width = viewport()->width();
1944  qreal height = viewport()->height();
1945  QRectF viewRect = d->matrix.mapRect(rect);
1946 
1947  qreal left = d->horizontalScroll();
1948  qreal right = left + width;
1949  qreal top = d->verticalScroll();
1950  qreal bottom = top + height;
1951 
1952  if (viewRect.left() <= left + xmargin) {
1953  // need to scroll from the left
1954  if (!d->leftIndent)
1955  horizontalScrollBar()->setValue(int(viewRect.left() - xmargin - qreal(0.5)));
1956  }
1957  if (viewRect.right() >= right - xmargin) {
1958  // need to scroll from the right
1959  if (!d->leftIndent)
1960  horizontalScrollBar()->setValue(int(viewRect.right() - width + xmargin + qreal(0.5)));
1961  }
1962  if (viewRect.top() <= top + ymargin) {
1963  // need to scroll from the top
1964  if (!d->topIndent)
1965  verticalScrollBar()->setValue(int(viewRect.top() - ymargin - qreal(0.5)));
1966  }
1967  if (viewRect.bottom() >= bottom - ymargin) {
1968  // need to scroll from the bottom
1969  if (!d->topIndent)
1970  verticalScrollBar()->setValue(int(viewRect.bottom() - height + ymargin + qreal(0.5)));
1971  }
1972 }
1973 
1999 void QGraphicsView::ensureVisible(const QGraphicsItem *item, int xmargin, int ymargin)
2000 {
2001  ensureVisible(item->sceneBoundingRect(), xmargin, ymargin);
2002 }
2003 
2029 {
2030  Q_D(QGraphicsView);
2031  if (!d->scene || rect.isNull())
2032  return;
2033 
2034  // Reset the view scale to 1:1.
2035  QRectF unity = d->matrix.mapRect(QRectF(0, 0, 1, 1));
2036  if (unity.isEmpty())
2037  return;
2038  scale(1 / unity.width(), 1 / unity.height());
2039 
2040  // Find the ideal x / y scaling ratio to fit \a rect in the view.
2041  int margin = 2;
2042  QRectF viewRect = viewport()->rect().adjusted(margin, margin, -margin, -margin);
2043  if (viewRect.isEmpty())
2044  return;
2045  QRectF sceneRect = d->matrix.mapRect(rect);
2046  if (sceneRect.isEmpty())
2047  return;
2048  qreal xratio = viewRect.width() / sceneRect.width();
2049  qreal yratio = viewRect.height() / sceneRect.height();
2050 
2051  // Respect the aspect ratio mode.
2052  switch (aspectRatioMode) {
2053  case Qt::KeepAspectRatio:
2054  xratio = yratio = qMin(xratio, yratio);
2055  break;
2057  xratio = yratio = qMax(xratio, yratio);
2058  break;
2059  case Qt::IgnoreAspectRatio:
2060  break;
2061  }
2062 
2063  // Scale and center on the center of \a rect.
2064  scale(xratio, yratio);
2065  centerOn(rect.center());
2066 }
2067 
2095 {
2096  QPainterPath path = item->isClipped() ? item->clipPath() : item->shape();
2097  if (item->d_ptr->hasTranslateOnlySceneTransform()) {
2098  path.translate(item->d_ptr->sceneTransform.dx(), item->d_ptr->sceneTransform.dy());
2099  fitInView(path.boundingRect(), aspectRatioMode);
2100  } else {
2101  fitInView(item->d_ptr->sceneTransform.map(path).boundingRect(), aspectRatioMode);
2102  }
2103 }
2104 
2125 void QGraphicsView::render(QPainter *painter, const QRectF &target, const QRect &source,
2126  Qt::AspectRatioMode aspectRatioMode)
2127 {
2128  // ### Switch to using the recursive rendering algorithm instead.
2129 
2130  Q_D(QGraphicsView);
2131  if (!d->scene || !(painter && painter->isActive()))
2132  return;
2133 
2134  // Default source rect = viewport rect
2135  QRect sourceRect = source;
2136  if (source.isNull())
2137  sourceRect = viewport()->rect();
2138 
2139  // Default target rect = device rect
2140  QRectF targetRect = target;
2141  if (target.isNull()) {
2142  if (painter->device()->devType() == QInternal::Picture)
2143  targetRect = sourceRect;
2144  else
2145  targetRect.setRect(0, 0, painter->device()->width(), painter->device()->height());
2146  }
2147 
2148  // Find the ideal x / y scaling ratio to fit \a source into \a target.
2149  qreal xratio = targetRect.width() / sourceRect.width();
2150  qreal yratio = targetRect.height() / sourceRect.height();
2151 
2152  // Scale according to the aspect ratio mode.
2153  switch (aspectRatioMode) {
2154  case Qt::KeepAspectRatio:
2155  xratio = yratio = qMin(xratio, yratio);
2156  break;
2158  xratio = yratio = qMax(xratio, yratio);
2159  break;
2160  case Qt::IgnoreAspectRatio:
2161  break;
2162  }
2163 
2164  // Find all items to draw, and reverse the list (we want to draw
2165  // in reverse order).
2166  QPolygonF sourceScenePoly = mapToScene(sourceRect.adjusted(-1, -1, 1, 1));
2167  QList<QGraphicsItem *> itemList = d->scene->items(sourceScenePoly,
2169  QGraphicsItem **itemArray = new QGraphicsItem *[itemList.size()];
2170  int numItems = itemList.size();
2171  for (int i = 0; i < numItems; ++i)
2172  itemArray[numItems - i - 1] = itemList.at(i);
2173  itemList.clear();
2174 
2175  // Setup painter matrix.
2176  QTransform moveMatrix = QTransform::fromTranslate(-d->horizontalScroll(), -d->verticalScroll());
2177  QTransform painterMatrix = d->matrix * moveMatrix;
2178  painterMatrix *= QTransform()
2179  .translate(targetRect.left(), targetRect.top())
2180  .scale(xratio, yratio)
2181  .translate(-sourceRect.left(), -sourceRect.top());
2182 
2183  // Generate the style options
2184  QStyleOptionGraphicsItem *styleOptionArray = d->allocStyleOptionsArray(numItems);
2185  for (int i = 0; i < numItems; ++i)
2186  itemArray[i]->d_ptr->initStyleOption(&styleOptionArray[i], painterMatrix, targetRect.toRect());
2187 
2188  painter->save();
2189 
2190  // Clip in device coordinates to avoid QRegion transformations.
2191  painter->setClipRect(targetRect);
2192  QPainterPath path;
2193  path.addPolygon(sourceScenePoly);
2194  path.closeSubpath();
2195  painter->setClipPath(painterMatrix.map(path), Qt::IntersectClip);
2196 
2197  // Transform the painter.
2198  painter->setTransform(painterMatrix, true);
2199 
2200  // Render the scene.
2201  QRectF sourceSceneRect = sourceScenePoly.boundingRect();
2202  drawBackground(painter, sourceSceneRect);
2203  drawItems(painter, numItems, itemArray, styleOptionArray);
2204  drawForeground(painter, sourceSceneRect);
2205 
2206  delete [] itemArray;
2207  d->freeStyleOptionsArray(styleOptionArray);
2208 
2209  painter->restore();
2210 }
2211 
2220 {
2221  Q_D(const QGraphicsView);
2222  if (!d->scene)
2223  return QList<QGraphicsItem *>();
2224  return d->scene->items();
2225 }
2226 
2242 {
2243  Q_D(const QGraphicsView);
2244  if (!d->scene)
2245  return QList<QGraphicsItem *>();
2246  // ### Unify these two, and use the items(QPointF) version in
2247  // QGraphicsScene instead. The scene items function could use the viewport
2248  // transform to map the point to a rect/polygon.
2249  if ((d->identityMatrix || d->matrix.type() <= QTransform::TxScale)) {
2250  // Use the rect version
2252  return d->scene->items(xinv.mapRect(QRectF(pos.x(), pos.y(), 1, 1)),
2255  viewportTransform());
2256  }
2257  // Use the polygon version
2258  return d->scene->items(mapToScene(pos.x(), pos.y(), 1, 1),
2261  viewportTransform());
2262 }
2263 
2293 {
2294  Q_D(const QGraphicsView);
2295  if (!d->scene)
2296  return QList<QGraphicsItem *>();
2297  return d->scene->items(mapToScene(rect), mode, Qt::DescendingOrder, viewportTransform());
2298 }
2299 
2327 {
2328  Q_D(const QGraphicsView);
2329  if (!d->scene)
2330  return QList<QGraphicsItem *>();
2331  return d->scene->items(mapToScene(polygon), mode, Qt::DescendingOrder, viewportTransform());
2332 }
2333 
2350 {
2351  Q_D(const QGraphicsView);
2352  if (!d->scene)
2353  return QList<QGraphicsItem *>();
2354  return d->scene->items(mapToScene(path), mode, Qt::DescendingOrder, viewportTransform());
2355 }
2356 
2369 {
2370  Q_D(const QGraphicsView);
2371  if (!d->scene)
2372  return 0;
2373  QList<QGraphicsItem *> itemsAtPos = items(pos);
2374  return itemsAtPos.isEmpty() ? 0 : itemsAtPos.first();
2375 }
2376 
2395 {
2396  Q_D(const QGraphicsView);
2397  QPointF p = point;
2398  p.rx() += d->horizontalScroll();
2399  p.ry() += d->verticalScroll();
2400  return d->identityMatrix ? p : d->matrix.inverted().map(p);
2401 }
2402 
2420 {
2421  Q_D(const QGraphicsView);
2422  if (!rect.isValid())
2423  return QPolygonF();
2424 
2425  QPointF scrollOffset(d->horizontalScroll(), d->verticalScroll());
2426  QRect r = rect.adjusted(0, 0, 1, 1);
2427  QPointF tl = scrollOffset + r.topLeft();
2428  QPointF tr = scrollOffset + r.topRight();
2429  QPointF br = scrollOffset + r.bottomRight();
2430  QPointF bl = scrollOffset + r.bottomLeft();
2431 
2432  QPolygonF poly(4);
2433  if (!d->identityMatrix) {
2434  QTransform x = d->matrix.inverted();
2435  poly[0] = x.map(tl);
2436  poly[1] = x.map(tr);
2437  poly[2] = x.map(br);
2438  poly[3] = x.map(bl);
2439  } else {
2440  poly[0] = tl;
2441  poly[1] = tr;
2442  poly[2] = br;
2443  poly[3] = bl;
2444  }
2445  return poly;
2446 }
2447 
2465 {
2466  QPolygonF poly;
2467  foreach (const QPoint &point, polygon)
2468  poly << mapToScene(point);
2469  return poly;
2470 }
2471 
2479 {
2480  Q_D(const QGraphicsView);
2481  QTransform matrix = QTransform::fromTranslate(d->horizontalScroll(), d->verticalScroll());
2482  matrix *= d->matrix.inverted();
2483  return matrix.map(path);
2484 }
2485 
2492 {
2493  Q_D(const QGraphicsView);
2494  QPointF p = d->identityMatrix ? point : d->matrix.map(point);
2495  p.rx() -= d->horizontalScroll();
2496  p.ry() -= d->verticalScroll();
2497  return p.toPoint();
2498 }
2499 
2517 {
2518  Q_D(const QGraphicsView);
2519  QPointF tl;
2520  QPointF tr;
2521  QPointF br;
2522  QPointF bl;
2523  if (!d->identityMatrix) {
2524  const QTransform &x = d->matrix;
2525  tl = x.map(rect.topLeft());
2526  tr = x.map(rect.topRight());
2527  br = x.map(rect.bottomRight());
2528  bl = x.map(rect.bottomLeft());
2529  } else {
2530  tl = rect.topLeft();
2531  tr = rect.topRight();
2532  br = rect.bottomRight();
2533  bl = rect.bottomLeft();
2534  }
2535  QPointF scrollOffset(d->horizontalScroll(), d->verticalScroll());
2536  tl -= scrollOffset;
2537  tr -= scrollOffset;
2538  br -= scrollOffset;
2539  bl -= scrollOffset;
2540 
2541  QPolygon poly(4);
2542  poly[0] = tl.toPoint();
2543  poly[1] = tr.toPoint();
2544  poly[2] = br.toPoint();
2545  poly[3] = bl.toPoint();
2546  return poly;
2547 }
2548 
2566 {
2567  QPolygon poly;
2568  foreach (const QPointF &point, polygon)
2569  poly << mapFromScene(point);
2570  return poly;
2571 }
2572 
2580 {
2581  Q_D(const QGraphicsView);
2582  QTransform matrix = d->matrix;
2583  matrix *= QTransform::fromTranslate(-d->horizontalScroll(), -d->verticalScroll());
2584  return matrix.map(path);
2585 }
2586 
2591 {
2592  Q_D(const QGraphicsView);
2593  if (!d->scene)
2594  return QVariant();
2595 
2596  QVariant value = d->scene->inputMethodQuery(query);
2597  if (value.type() == QVariant::RectF)
2598  value = d->mapRectFromScene(value.toRectF());
2599  else if (value.type() == QVariant::PointF)
2600  value = mapFromScene(value.toPointF());
2601  else if (value.type() == QVariant::Rect)
2602  value = d->mapRectFromScene(value.toRect()).toRect();
2603  else if (value.type() == QVariant::Point)
2604  value = mapFromScene(value.toPoint());
2605  return value;
2606 }
2607 
2625 {
2626  Q_D(const QGraphicsView);
2627  return d->backgroundBrush;
2628 }
2630 {
2631  Q_D(QGraphicsView);
2632  d->backgroundBrush = brush;
2633  d->updateAll();
2634 
2635  if (d->cacheMode & CacheBackground) {
2636  // Invalidate the background pixmap
2637  d->mustResizeBackgroundPixmap = true;
2638  }
2639 }
2640 
2658 {
2659  Q_D(const QGraphicsView);
2660  return d->foregroundBrush;
2661 }
2663 {
2664  Q_D(QGraphicsView);
2665  d->foregroundBrush = brush;
2666  d->updateAll();
2667 }
2668 
2675 {
2676  // ### Note: Since 4.5, this slot is only called if the user explicitly
2677  // establishes a connection between the scene and the view, as the scene
2678  // and view are no longer connected. We need to keep it working (basically
2679  // leave it as it is), but the new delivery path is through
2680  // QGraphicsScenePrivate::itemUpdate().
2681  Q_D(QGraphicsView);
2682  if (d->fullUpdatePending || d->viewportUpdateMode == QGraphicsView::NoViewportUpdate)
2683  return;
2684 
2685  // Extract and reset dirty scene rect info.
2686  QVector<QRect> dirtyViewportRects;
2687  const QVector<QRect> &dirtyRects = d->dirtyRegion.rects();
2688  for (int i = 0; i < dirtyRects.size(); ++i)
2689  dirtyViewportRects += dirtyRects.at(i);
2690  d->dirtyRegion = QRegion();
2691  d->dirtyBoundingRect = QRect();
2692 
2693  bool fullUpdate = !d->accelerateScrolling || d->viewportUpdateMode == QGraphicsView::FullViewportUpdate;
2694  bool boundingRectUpdate = (d->viewportUpdateMode == QGraphicsView::BoundingRectViewportUpdate)
2695  || (d->viewportUpdateMode == QGraphicsView::SmartViewportUpdate
2696  && ((dirtyViewportRects.size() + rects.size()) >= QGRAPHICSVIEW_REGION_RECT_THRESHOLD));
2697 
2698  QRegion updateRegion;
2700  QRect viewportRect = viewport()->rect();
2701  bool redraw = false;
2703 
2704  // Convert scene rects to viewport rects.
2705  foreach (const QRectF &rect, rects) {
2706  QRect xrect = transform.mapRect(rect).toAlignedRect();
2707  if (!(d->optimizationFlags & DontAdjustForAntialiasing))
2708  xrect.adjust(-2, -2, 2, 2);
2709  else
2710  xrect.adjust(-1, -1, 1, 1);
2711  if (!viewportRect.intersects(xrect))
2712  continue;
2713  dirtyViewportRects << xrect;
2714  }
2715 
2716  foreach (const QRect &rect, dirtyViewportRects) {
2717  // Add the exposed rect to the update region. In rect update
2718  // mode, we only count the bounding rect of items.
2719  if (!boundingRectUpdate) {
2720  updateRegion += rect;
2721  } else {
2722  boundingRect |= rect;
2723  }
2724  redraw = true;
2725  if (fullUpdate) {
2726  // If fullUpdate is true and we found a visible dirty rect,
2727  // we're done.
2728  break;
2729  }
2730  }
2731 
2732  if (!redraw)
2733  return;
2734 
2735  if (fullUpdate)
2736  viewport()->update();
2737  else if (boundingRectUpdate)
2738  viewport()->update(boundingRect);
2739  else
2740  viewport()->update(updateRegion);
2741 }
2742 
2751 {
2752  Q_D(QGraphicsView);
2753  if (!d->hasSceneRect) {
2754  d->sceneRect = rect;
2755  d->recalculateContentSize();
2756  }
2757 }
2758 
2767 {
2768  Q_D(QGraphicsView);
2769 
2770  if (!widget) {
2771  qWarning("QGraphicsView::setupViewport: cannot initialize null widget");
2772  return;
2773  }
2774 
2775  const bool isGLWidget = widget->inherits("QGLWidget");
2776 
2777  d->accelerateScrolling = !(isGLWidget);
2778 
2780 
2781  if (!isGLWidget) {
2782  // autoFillBackground enables scroll acceleration.
2783  widget->setAutoFillBackground(true);
2784  }
2785 
2786  // We are only interested in mouse tracking if items
2787  // accept hover events or use non-default cursors or if
2788  // AnchorUnderMouse is used as transformation or resize anchor.
2789  if ((d->scene && (!d->scene->d_func()->allItemsIgnoreHoverEvents
2790  || !d->scene->d_func()->allItemsUseDefaultCursor))
2791  || d->transformationAnchor == AnchorUnderMouse
2792  || d->resizeAnchor == AnchorUnderMouse) {
2793  widget->setMouseTracking(true);
2794  }
2795 
2796  // enable touch events if any items is interested in them
2797  if (d->scene && !d->scene->d_func()->allItemsIgnoreTouchEvents)
2799 
2800 #ifndef QT_NO_GESTURES
2801  if (d->scene) {
2802  foreach (Qt::GestureType gesture, d->scene->d_func()->grabbedGestures.keys())
2803  widget->grabGesture(gesture);
2804  }
2805 #endif
2806 
2807  widget->setAcceptDrops(acceptDrops());
2808 }
2809 
2814 {
2815  Q_D(QGraphicsView);
2816 
2817  if (d->sceneInteractionAllowed) {
2818  switch (event->type()) {
2820  if (d->scene)
2821  return QApplication::sendEvent(d->scene, event);
2822  break;
2823  case QEvent::KeyPress:
2824  if (d->scene) {
2825  QKeyEvent *k = static_cast<QKeyEvent *>(event);
2826  if (k->key() == Qt::Key_Tab || k->key() == Qt::Key_Backtab) {
2827  // Send the key events to the scene. This will invoke the
2828  // scene's tab focus handling, and if the event is
2829  // accepted, we return (prevent further event delivery),
2830  // and the base implementation will call QGraphicsView's
2831  // focusNextPrevChild() function. If the event is ignored,
2832  // we fall back to standard tab focus handling.
2833  QApplication::sendEvent(d->scene, event);
2834  if (event->isAccepted())
2835  return true;
2836  // Ensure the event doesn't propagate just because the
2837  // scene ignored it. If the event propagates, then tab
2838  // handling will be called twice (this and parent).
2839  event->accept();
2840  }
2841  }
2842  break;
2843  default:
2844  break;
2845  }
2846  }
2847 
2848  return QAbstractScrollArea::event(event);
2849 }
2850 
2855 {
2856  Q_D(QGraphicsView);
2857  if (!d->scene)
2858  return QAbstractScrollArea::viewportEvent(event);
2859 
2860  switch (event->type()) {
2861  case QEvent::Enter:
2862  QApplication::sendEvent(d->scene, event);
2863  break;
2865  QApplication::sendEvent(d->scene, event);
2866  break;
2868  // ### This is a temporary fix for until we get proper mouse
2869  // grab events. mouseGrabberItem should be set to 0 if we lose
2870  // the mouse grab.
2871  // Remove all popups when the scene loses focus.
2872  if (!d->scene->d_func()->popupWidgets.isEmpty())
2873  d->scene->d_func()->removePopup(d->scene->d_func()->popupWidgets.first());
2874  QApplication::sendEvent(d->scene, event);
2875  break;
2876  case QEvent::Show:
2877  if (d->scene && isActiveWindow()) {
2878  QEvent windowActivate(QEvent::WindowActivate);
2879  QApplication::sendEvent(d->scene, &windowActivate);
2880  }
2881  break;
2882  case QEvent::Hide:
2883  // spontaneous event will generate a WindowDeactivate.
2884  if (!event->spontaneous() && d->scene && isActiveWindow()) {
2885  QEvent windowDeactivate(QEvent::WindowDeactivate);
2886  QApplication::sendEvent(d->scene, &windowDeactivate);
2887  }
2888  break;
2889  case QEvent::Leave:
2890  // ### This is a temporary fix for until we get proper mouse grab
2891  // events. activeMouseGrabberItem should be set to 0 if we lose the
2892  // mouse grab.
2895  || (QApplication::activeWindow() != window())) {
2896  if (!d->scene->d_func()->popupWidgets.isEmpty())
2897  d->scene->d_func()->removePopup(d->scene->d_func()->popupWidgets.first());
2898  }
2899  d->useLastMouseEvent = false;
2900  // a hack to pass a viewport pointer to the scene inside the leave event
2901  Q_ASSERT(event->d == 0);
2902  event->d = reinterpret_cast<QEventPrivate *>(viewport());
2903  QApplication::sendEvent(d->scene, event);
2904  break;
2905 #ifndef QT_NO_TOOLTIP
2906  case QEvent::ToolTip: {
2907  QHelpEvent *toolTip = static_cast<QHelpEvent *>(event);
2909  helpEvent.setWidget(viewport());
2910  helpEvent.setScreenPos(toolTip->globalPos());
2911  helpEvent.setScenePos(mapToScene(toolTip->pos()));
2912  QApplication::sendEvent(d->scene, &helpEvent);
2913  toolTip->setAccepted(helpEvent.isAccepted());
2914  return true;
2915  }
2916 #endif
2917  case QEvent::Paint:
2918  // Reset full update
2919  d->fullUpdatePending = false;
2920  d->dirtyScrollOffset = QPoint();
2921  if (d->scene) {
2922  // Check if this view reimplements the updateScene slot; if it
2923  // does, we can't do direct update delivery and have to fall back
2924  // to connecting the changed signal.
2925  if (!d->updateSceneSlotReimplementedChecked) {
2926  d->updateSceneSlotReimplementedChecked = true;
2927  const QMetaObject *mo = metaObject();
2928  if (mo != &QGraphicsView::staticMetaObject) {
2929  if (mo->indexOfSlot("updateScene(QList<QRectF>)")
2930  != QGraphicsView::staticMetaObject.indexOfSlot("updateScene(QList<QRectF>)")) {
2931  connect(d->scene, SIGNAL(changed(QList<QRectF>)),
2932  this, SLOT(updateScene(QList<QRectF>)));
2933  }
2934  }
2935  }
2936  }
2937  break;
2938  case QEvent::TouchBegin:
2939  case QEvent::TouchUpdate:
2940  case QEvent::TouchEnd:
2941  {
2942  if (!isEnabled())
2943  return false;
2944 
2945  if (d->scene && d->sceneInteractionAllowed) {
2946  // Convert and deliver the touch event to the scene.
2947  QTouchEvent *touchEvent = static_cast<QTouchEvent *>(event);
2948  touchEvent->setWidget(viewport());
2950  (void) QApplication::sendEvent(d->scene, touchEvent);
2951  }
2952 
2953  return true;
2954  }
2955 #ifndef QT_NO_GESTURES
2956  case QEvent::Gesture:
2958  {
2959  if (!isEnabled())
2960  return false;
2961 
2962  if (d->scene && d->sceneInteractionAllowed) {
2963  QGestureEvent *gestureEvent = static_cast<QGestureEvent *>(event);
2964  gestureEvent->setWidget(viewport());
2965  (void) QApplication::sendEvent(d->scene, gestureEvent);
2966  }
2967  return true;
2968  }
2969 #endif // QT_NO_GESTURES
2970  default:
2971  break;
2972  }
2973 
2974  return QAbstractScrollArea::viewportEvent(event);
2975 }
2976 
2977 #ifndef QT_NO_CONTEXTMENU
2978 
2982 {
2983  Q_D(QGraphicsView);
2984  if (!d->scene || !d->sceneInteractionAllowed)
2985  return;
2986 
2987  d->mousePressViewPoint = event->pos();
2988  d->mousePressScenePoint = mapToScene(d->mousePressViewPoint);
2989  d->mousePressScreenPoint = event->globalPos();
2990  d->lastMouseMoveScenePoint = d->mousePressScenePoint;
2991  d->lastMouseMoveScreenPoint = d->mousePressScreenPoint;
2992 
2994  contextEvent.setWidget(viewport());
2995  contextEvent.setScenePos(d->mousePressScenePoint);
2996  contextEvent.setScreenPos(d->mousePressScreenPoint);
2997  contextEvent.setModifiers(event->modifiers());
2998  contextEvent.setReason((QGraphicsSceneContextMenuEvent::Reason)(event->reason()));
2999  contextEvent.setAccepted(event->isAccepted());
3000  QApplication::sendEvent(d->scene, &contextEvent);
3001  event->setAccepted(contextEvent.isAccepted());
3002 }
3003 #endif // QT_NO_CONTEXTMENU
3004 
3009 {
3010 #ifndef QT_NO_DRAGANDDROP
3011  Q_D(QGraphicsView);
3012  if (!d->scene || !d->sceneInteractionAllowed)
3013  return;
3014 
3015  // Generate a scene event.
3017  d->populateSceneDragDropEvent(&sceneEvent, event);
3018 
3019  // Send it to the scene.
3020  QApplication::sendEvent(d->scene, &sceneEvent);
3021 
3022  // Accept the originating event if the scene accepted the scene event.
3023  event->setAccepted(sceneEvent.isAccepted());
3024  if (sceneEvent.isAccepted())
3025  event->setDropAction(sceneEvent.dropAction());
3026 
3027  delete d->lastDragDropEvent;
3028  d->lastDragDropEvent = 0;
3029 
3030 #else
3031  Q_UNUSED(event)
3032 #endif
3033 }
3034 
3039 {
3040 #ifndef QT_NO_DRAGANDDROP
3041  Q_D(QGraphicsView);
3042  if (!d->scene || !d->sceneInteractionAllowed)
3043  return;
3044 
3045  // Disable replaying of mouse move events.
3046  d->useLastMouseEvent = false;
3047 
3048  // Generate a scene event.
3050  d->populateSceneDragDropEvent(&sceneEvent, event);
3051 
3052  // Store it for later use.
3053  d->storeDragDropEvent(&sceneEvent);
3054 
3055  // Send it to the scene.
3056  QApplication::sendEvent(d->scene, &sceneEvent);
3057 
3058  // Accept the originating event if the scene accepted the scene event.
3059  if (sceneEvent.isAccepted()) {
3060  event->setAccepted(true);
3061  event->setDropAction(sceneEvent.dropAction());
3062  }
3063 #else
3064  Q_UNUSED(event)
3065 #endif
3066 }
3067 
3072 {
3073 #ifndef QT_NO_DRAGANDDROP
3074  Q_D(QGraphicsView);
3075  if (!d->scene || !d->sceneInteractionAllowed)
3076  return;
3077  if (!d->lastDragDropEvent) {
3078  qWarning("QGraphicsView::dragLeaveEvent: drag leave received before drag enter");
3079  return;
3080  }
3081 
3082  // Generate a scene event.
3084  sceneEvent.setScenePos(d->lastDragDropEvent->scenePos());
3085  sceneEvent.setScreenPos(d->lastDragDropEvent->screenPos());
3086  sceneEvent.setButtons(d->lastDragDropEvent->buttons());
3087  sceneEvent.setModifiers(d->lastDragDropEvent->modifiers());
3088  sceneEvent.setPossibleActions(d->lastDragDropEvent->possibleActions());
3089  sceneEvent.setProposedAction(d->lastDragDropEvent->proposedAction());
3090  sceneEvent.setDropAction(d->lastDragDropEvent->dropAction());
3091  sceneEvent.setMimeData(d->lastDragDropEvent->mimeData());
3092  sceneEvent.setWidget(d->lastDragDropEvent->widget());
3093  sceneEvent.setSource(d->lastDragDropEvent->source());
3094  delete d->lastDragDropEvent;
3095  d->lastDragDropEvent = 0;
3096 
3097  // Send it to the scene.
3098  QApplication::sendEvent(d->scene, &sceneEvent);
3099 
3100  // Accept the originating event if the scene accepted the scene event.
3101  if (sceneEvent.isAccepted())
3102  event->setAccepted(true);
3103 #else
3104  Q_UNUSED(event)
3105 #endif
3106 }
3107 
3112 {
3113 #ifndef QT_NO_DRAGANDDROP
3114  Q_D(QGraphicsView);
3115  if (!d->scene || !d->sceneInteractionAllowed)
3116  return;
3117 
3118  // Generate a scene event.
3120  d->populateSceneDragDropEvent(&sceneEvent, event);
3121 
3122  // Store it for later use.
3123  d->storeDragDropEvent(&sceneEvent);
3124 
3125  // Send it to the scene.
3126  QApplication::sendEvent(d->scene, &sceneEvent);
3127 
3128  // Ignore the originating event if the scene ignored the scene event.
3129  event->setAccepted(sceneEvent.isAccepted());
3130  if (sceneEvent.isAccepted())
3131  event->setDropAction(sceneEvent.dropAction());
3132 #else
3133  Q_UNUSED(event)
3134 #endif
3135 }
3136 
3141 {
3142  Q_D(QGraphicsView);
3143  d->updateInputMethodSensitivity();
3145  if (d->scene)
3146  QApplication::sendEvent(d->scene, event);
3147  // Pass focus on if the scene cannot accept focus.
3148  if (!d->scene || !event->isAccepted())
3150 }
3151 
3156 {
3158 }
3159 
3164 {
3165  Q_D(QGraphicsView);
3167  if (d->scene)
3168  QApplication::sendEvent(d->scene, event);
3169 }
3170 
3175 {
3176  Q_D(QGraphicsView);
3177  if (!d->scene || !d->sceneInteractionAllowed) {
3179  return;
3180  }
3181  QApplication::sendEvent(d->scene, event);
3182  if (!event->isAccepted())
3184 }
3185 
3190 {
3191  Q_D(QGraphicsView);
3192  if (!d->scene || !d->sceneInteractionAllowed)
3193  return;
3194  QApplication::sendEvent(d->scene, event);
3195  if (!event->isAccepted())
3197 }
3198 
3203 {
3204  Q_D(QGraphicsView);
3205  if (!d->scene || !d->sceneInteractionAllowed)
3206  return;
3207 
3208  d->storeMouseEvent(event);
3209  d->mousePressViewPoint = event->pos();
3210  d->mousePressScenePoint = mapToScene(d->mousePressViewPoint);
3211  d->mousePressScreenPoint = event->globalPos();
3212  d->lastMouseMoveScenePoint = d->mousePressScenePoint;
3213  d->lastMouseMoveScreenPoint = d->mousePressScreenPoint;
3214  d->mousePressButton = event->button();
3215 
3217  mouseEvent.setWidget(viewport());
3218  mouseEvent.setButtonDownScenePos(d->mousePressButton, d->mousePressScenePoint);
3219  mouseEvent.setButtonDownScreenPos(d->mousePressButton, d->mousePressScreenPoint);
3220  mouseEvent.setScenePos(mapToScene(d->mousePressViewPoint));
3221  mouseEvent.setScreenPos(d->mousePressScreenPoint);
3222  mouseEvent.setLastScenePos(d->lastMouseMoveScenePoint);
3223  mouseEvent.setLastScreenPos(d->lastMouseMoveScreenPoint);
3224  mouseEvent.setButtons(event->buttons());
3225  mouseEvent.setButtons(event->buttons());
3226  mouseEvent.setAccepted(false);
3227  mouseEvent.setButton(event->button());
3228  mouseEvent.setModifiers(event->modifiers());
3229  if (event->spontaneous())
3230  qt_sendSpontaneousEvent(d->scene, &mouseEvent);
3231  else
3232  QApplication::sendEvent(d->scene, &mouseEvent);
3233 }
3234 
3239 {
3240  Q_D(QGraphicsView);
3241 
3242  // Store this event for replaying, finding deltas, and for
3243  // scroll-dragging; even in non-interactive mode, scroll hand dragging is
3244  // allowed, so we store the event at the very top of this function.
3245  d->storeMouseEvent(event);
3246  d->lastMouseEvent.setAccepted(false);
3247 
3248  if (d->sceneInteractionAllowed) {
3249  // Store some of the event's button-down data.
3250  d->mousePressViewPoint = event->pos();
3251  d->mousePressScenePoint = mapToScene(d->mousePressViewPoint);
3252  d->mousePressScreenPoint = event->globalPos();
3253  d->lastMouseMoveScenePoint = d->mousePressScenePoint;
3254  d->lastMouseMoveScreenPoint = d->mousePressScreenPoint;
3255  d->mousePressButton = event->button();
3256 
3257  if (d->scene) {
3258  // Convert and deliver the mouse event to the scene.
3260  mouseEvent.setWidget(viewport());
3261  mouseEvent.setButtonDownScenePos(d->mousePressButton, d->mousePressScenePoint);
3262  mouseEvent.setButtonDownScreenPos(d->mousePressButton, d->mousePressScreenPoint);
3263  mouseEvent.setScenePos(d->mousePressScenePoint);
3264  mouseEvent.setScreenPos(d->mousePressScreenPoint);
3265  mouseEvent.setLastScenePos(d->lastMouseMoveScenePoint);
3266  mouseEvent.setLastScreenPos(d->lastMouseMoveScreenPoint);
3267  mouseEvent.setButtons(event->buttons());
3268  mouseEvent.setButton(event->button());
3269  mouseEvent.setModifiers(event->modifiers());
3270  mouseEvent.setAccepted(false);
3271  if (event->spontaneous())
3272  qt_sendSpontaneousEvent(d->scene, &mouseEvent);
3273  else
3274  QApplication::sendEvent(d->scene, &mouseEvent);
3275 
3276  // Update the original mouse event accepted state.
3277  bool isAccepted = mouseEvent.isAccepted();
3278  event->setAccepted(isAccepted);
3279 
3280  // Update the last mouse event accepted state.
3281  d->lastMouseEvent.setAccepted(isAccepted);
3282 
3283  if (isAccepted)
3284  return;
3285  }
3286  }
3287 
3288 #ifndef QT_NO_RUBBERBAND
3289  if (d->dragMode == QGraphicsView::RubberBandDrag && !d->rubberBanding) {
3290  if (d->sceneInteractionAllowed) {
3291  // Rubberbanding is only allowed in interactive mode.
3292  event->accept();
3293  d->rubberBanding = true;
3294  d->rubberBandRect = QRect();
3295  if (d->scene) {
3296  // Initiating a rubber band always clears the selection.
3297  d->scene->clearSelection();
3298  }
3299  }
3300  } else
3301 #endif
3302  if (d->dragMode == QGraphicsView::ScrollHandDrag && event->button() == Qt::LeftButton) {
3303  // Left-button press in scroll hand mode initiates hand scrolling.
3304  event->accept();
3305  d->handScrolling = true;
3306  d->handScrollMotions = 0;
3307 #ifndef QT_NO_CURSOR
3309 #endif
3310  }
3311 }
3312 
3317 {
3318  Q_D(QGraphicsView);
3319 
3320 #ifndef QT_NO_RUBBERBAND
3321  if (d->dragMode == QGraphicsView::RubberBandDrag && d->sceneInteractionAllowed) {
3322  d->storeMouseEvent(event);
3323  if (d->rubberBanding) {
3324  // Check for enough drag distance
3325  if ((d->mousePressViewPoint - event->pos()).manhattanLength()
3327  return;
3328  }
3329 
3330  // Update old rubberband
3331  if (d->viewportUpdateMode != QGraphicsView::NoViewportUpdate && !d->rubberBandRect.isEmpty()) {
3332  if (d->viewportUpdateMode != FullViewportUpdate)
3333  viewport()->update(d->rubberBandRegion(viewport(), d->rubberBandRect));
3334  else
3335  d->updateAll();
3336  }
3337 
3338  // Stop rubber banding if the user has let go of all buttons (even
3339  // if we didn't get the release events).
3340  if (!event->buttons()) {
3341  d->rubberBanding = false;
3342  d->rubberBandRect = QRect();
3343  return;
3344  }
3345 
3346  // Update rubberband position
3347  const QPoint &mp = d->mousePressViewPoint;
3348  QPoint ep = event->pos();
3349  d->rubberBandRect = QRect(qMin(mp.x(), ep.x()), qMin(mp.y(), ep.y()),
3350  qAbs(mp.x() - ep.x()) + 1, qAbs(mp.y() - ep.y()) + 1);
3351 
3352  // Update new rubberband
3353  if (d->viewportUpdateMode != QGraphicsView::NoViewportUpdate){
3354  if (d->viewportUpdateMode != FullViewportUpdate)
3355  viewport()->update(d->rubberBandRegion(viewport(), d->rubberBandRect));
3356  else
3357  d->updateAll();
3358  }
3359  // Set the new selection area
3360  QPainterPath selectionArea;
3361  selectionArea.addPolygon(mapToScene(d->rubberBandRect));
3362  selectionArea.closeSubpath();
3363  if (d->scene)
3364  d->scene->setSelectionArea(selectionArea, d->rubberBandSelectionMode,
3365  viewportTransform());
3366  return;
3367  }
3368  } else
3369 #endif // QT_NO_RUBBERBAND
3370  if (d->dragMode == QGraphicsView::ScrollHandDrag) {
3371  if (d->handScrolling) {
3372  QScrollBar *hBar = horizontalScrollBar();
3373  QScrollBar *vBar = verticalScrollBar();
3374  QPoint delta = event->pos() - d->lastMouseEvent.pos();
3375  hBar->setValue(hBar->value() + (isRightToLeft() ? delta.x() : -delta.x()));
3376  vBar->setValue(vBar->value() - delta.y());
3377 
3378  // Detect how much we've scrolled to disambiguate scrolling from
3379  // clicking.
3380  ++d->handScrollMotions;
3381  }
3382  }
3383 
3384  d->mouseMoveEventHandler(event);
3385 }
3386 
3391 {
3392  Q_D(QGraphicsView);
3393 
3394 #ifndef QT_NO_RUBBERBAND
3395  if (d->dragMode == QGraphicsView::RubberBandDrag && d->sceneInteractionAllowed && !event->buttons()) {
3396  if (d->rubberBanding) {
3397  if (d->viewportUpdateMode != QGraphicsView::NoViewportUpdate){
3398  if (d->viewportUpdateMode != FullViewportUpdate)
3399  viewport()->update(d->rubberBandRegion(viewport(), d->rubberBandRect));
3400  else
3401  d->updateAll();
3402  }
3403  d->rubberBanding = false;
3404  d->rubberBandRect = QRect();
3405  }
3406  } else
3407 #endif
3408  if (d->dragMode == QGraphicsView::ScrollHandDrag && event->button() == Qt::LeftButton) {
3409 #ifndef QT_NO_CURSOR
3410  // Restore the open hand cursor. ### There might be items
3411  // under the mouse that have a valid cursor at this time, so
3412  // we could repeat the steps from mouseMoveEvent().
3414 #endif
3415  d->handScrolling = false;
3416 
3417  if (d->scene && d->sceneInteractionAllowed && !d->lastMouseEvent.isAccepted() && d->handScrollMotions <= 6) {
3418  // If we've detected very little motion during the hand drag, and
3419  // no item accepted the last event, we'll interpret that as a
3420  // click to the scene, and reset the selection.
3421  d->scene->clearSelection();
3422  }
3423  }
3424 
3425  d->storeMouseEvent(event);
3426 
3427  if (!d->sceneInteractionAllowed)
3428  return;
3429 
3430  if (!d->scene)
3431  return;
3432 
3434  mouseEvent.setWidget(viewport());
3435  mouseEvent.setButtonDownScenePos(d->mousePressButton, d->mousePressScenePoint);
3436  mouseEvent.setButtonDownScreenPos(d->mousePressButton, d->mousePressScreenPoint);
3437  mouseEvent.setScenePos(mapToScene(event->pos()));
3438  mouseEvent.setScreenPos(event->globalPos());
3439  mouseEvent.setLastScenePos(d->lastMouseMoveScenePoint);
3440  mouseEvent.setLastScreenPos(d->lastMouseMoveScreenPoint);
3441  mouseEvent.setButtons(event->buttons());
3442  mouseEvent.setButton(event->button());
3443  mouseEvent.setModifiers(event->modifiers());
3444  mouseEvent.setAccepted(false);
3445  if (event->spontaneous())
3446  qt_sendSpontaneousEvent(d->scene, &mouseEvent);
3447  else
3448  QApplication::sendEvent(d->scene, &mouseEvent);
3449 
3450  // Update the last mouse event selected state.
3451  d->lastMouseEvent.setAccepted(mouseEvent.isAccepted());
3452 
3453 #ifndef QT_NO_CURSOR
3454  if (mouseEvent.isAccepted() && mouseEvent.buttons() == 0 && viewport()->testAttribute(Qt::WA_SetCursor)) {
3455  // The last mouse release on the viewport will trigger clearing the cursor.
3456  d->_q_unsetViewportCursor();
3457  }
3458 #endif
3459 }
3460 
3461 #ifndef QT_NO_WHEELEVENT
3462 
3466 {
3467  Q_D(QGraphicsView);
3468  if (!d->scene || !d->sceneInteractionAllowed) {
3470  return;
3471  }
3472 
3473  event->ignore();
3474 
3476  wheelEvent.setWidget(viewport());
3477  wheelEvent.setScenePos(mapToScene(event->pos()));
3478  wheelEvent.setScreenPos(event->globalPos());
3479  wheelEvent.setButtons(event->buttons());
3480  wheelEvent.setModifiers(event->modifiers());
3481  wheelEvent.setDelta(event->delta());
3482  wheelEvent.setOrientation(event->orientation());
3483  wheelEvent.setAccepted(false);
3484  QApplication::sendEvent(d->scene, &wheelEvent);
3485  event->setAccepted(wheelEvent.isAccepted());
3486  if (!event->isAccepted())
3488 }
3489 #endif // QT_NO_WHEELEVENT
3490 
3495 {
3496  Q_D(QGraphicsView);
3497  if (!d->scene) {
3499  return;
3500  }
3501 
3502  // Set up painter state protection.
3503  d->scene->d_func()->painterStateProtection = !(d->optimizationFlags & DontSavePainterState);
3504 
3505  // Determine the exposed region
3506  d->exposedRegion = event->region();
3507  QRectF exposedSceneRect = mapToScene(d->exposedRegion.boundingRect()).boundingRect();
3508 
3509  // Set up the painter
3510  QPainter painter(viewport());
3511 #ifndef QT_NO_RUBBERBAND
3512  if (d->rubberBanding && !d->rubberBandRect.isEmpty())
3513  painter.save();
3514 #endif
3515  // Set up render hints
3516  painter.setRenderHints(painter.renderHints(), false);
3517  painter.setRenderHints(d->renderHints, true);
3518 
3519  // Set up viewport transform
3520  const bool viewTransformed = isTransformed();
3521  if (viewTransformed)
3523  const QTransform viewTransform = painter.worldTransform();
3524 
3525  // Draw background
3526  if ((d->cacheMode & CacheBackground)
3527 #ifdef Q_WS_X11
3528  && X11->use_xrender
3529 #endif
3530  ) {
3531  // Recreate the background pixmap, and flag the whole background as
3532  // exposed.
3533  if (d->mustResizeBackgroundPixmap) {
3534  d->backgroundPixmap = QPixmap(viewport()->size());
3535  QBrush bgBrush = viewport()->palette().brush(viewport()->backgroundRole());
3536  if (!bgBrush.isOpaque())
3537  d->backgroundPixmap.fill(Qt::transparent);
3538  QPainter p(&d->backgroundPixmap);
3539  p.fillRect(0, 0, d->backgroundPixmap.width(), d->backgroundPixmap.height(), bgBrush);
3540  d->backgroundPixmapExposed = QRegion(viewport()->rect());
3541  d->mustResizeBackgroundPixmap = false;
3542  }
3543 
3544  // Redraw exposed areas
3545  if (!d->backgroundPixmapExposed.isEmpty()) {
3546  QPainter backgroundPainter(&d->backgroundPixmap);
3547  backgroundPainter.setClipRegion(d->backgroundPixmapExposed, Qt::ReplaceClip);
3548  if (viewTransformed)
3549  backgroundPainter.setTransform(viewTransform);
3550  QRectF backgroundExposedSceneRect = mapToScene(d->backgroundPixmapExposed.boundingRect()).boundingRect();
3551  drawBackground(&backgroundPainter, backgroundExposedSceneRect);
3552  d->backgroundPixmapExposed = QRegion();
3553  }
3554 
3555  // Blit the background from the background pixmap
3556  if (viewTransformed) {
3557  painter.setWorldTransform(QTransform());
3558  painter.drawPixmap(QPoint(), d->backgroundPixmap);
3559  painter.setWorldTransform(viewTransform);
3560  } else {
3561  painter.drawPixmap(QPoint(), d->backgroundPixmap);
3562  }
3563  } else {
3564  if (!(d->optimizationFlags & DontSavePainterState))
3565  painter.save();
3566  drawBackground(&painter, exposedSceneRect);
3567  if (!(d->optimizationFlags & DontSavePainterState))
3568  painter.restore();
3569  }
3570 
3571  // Items
3572  if (!(d->optimizationFlags & IndirectPainting)) {
3573  const quint32 oldRectAdjust = d->scene->d_func()->rectAdjust;
3574  if (d->optimizationFlags & QGraphicsView::DontAdjustForAntialiasing)
3575  d->scene->d_func()->rectAdjust = 1;
3576  else
3577  d->scene->d_func()->rectAdjust = 2;
3578  d->scene->d_func()->drawItems(&painter, viewTransformed ? &viewTransform : 0,
3579  &d->exposedRegion, viewport());
3580  d->scene->d_func()->rectAdjust = oldRectAdjust;
3581  // Make sure the painter's world transform is restored correctly when
3582  // drawing without painter state protection (DontSavePainterState).
3583  // We only change the worldTransform() so there's no need to do a full-blown
3584  // save() and restore(). Also note that we don't have to do this in case of
3585  // IndirectPainting (the else branch), because in that case we always save()
3586  // and restore() in QGraphicsScene::drawItems().
3587  if (!d->scene->d_func()->painterStateProtection)
3588  painter.setOpacity(1.0);
3589  painter.setWorldTransform(viewTransform);
3590  } else {
3591  // Make sure we don't have unpolished items before we draw
3592  if (!d->scene->d_func()->unpolishedItems.isEmpty())
3593  d->scene->d_func()->_q_polishItems();
3594  // We reset updateAll here (after we've issued polish events)
3595  // so that we can discard update requests coming from polishEvent().
3596  d->scene->d_func()->updateAll = false;
3597 
3598  // Find all exposed items
3599  bool allItems = false;
3600  QList<QGraphicsItem *> itemList = d->findItems(d->exposedRegion, &allItems, viewTransform);
3601  if (!itemList.isEmpty()) {
3602  // Generate the style options.
3603  const int numItems = itemList.size();
3604  QGraphicsItem **itemArray = &itemList[0]; // Relies on QList internals, but is perfectly valid.
3605  QStyleOptionGraphicsItem *styleOptionArray = d->allocStyleOptionsArray(numItems);
3607  for (int i = 0; i < numItems; ++i) {
3608  QGraphicsItem *item = itemArray[i];
3609  QGraphicsItemPrivate *itemd = item->d_ptr.data();
3610  itemd->initStyleOption(&styleOptionArray[i], viewTransform, d->exposedRegion, allItems);
3611  // Cache the item's area in view coordinates.
3612  // Note that we have to do this here in case the base class implementation
3613  // (QGraphicsScene::drawItems) is not called. If it is, we'll do this
3614  // operation twice, but that's the price one has to pay for using indirect
3615  // painting :-/.
3616  const QRectF brect = adjustedItemEffectiveBoundingRect(item);
3617  if (!itemd->itemIsUntransformable()) {
3618  transform = item->sceneTransform();
3619  if (viewTransformed)
3620  transform *= viewTransform;
3621  } else {
3622  transform = item->deviceTransform(viewTransform);
3623  }
3624  itemd->paintedViewBoundingRects.insert(d->viewport, transform.mapRect(brect).toRect());
3625  }
3626  // Draw the items.
3627  drawItems(&painter, numItems, itemArray, styleOptionArray);
3628  d->freeStyleOptionsArray(styleOptionArray);
3629  }
3630  }
3631 
3632  // Foreground
3633  drawForeground(&painter, exposedSceneRect);
3634 
3635 #ifndef QT_NO_RUBBERBAND
3636  // Rubberband
3637  if (d->rubberBanding && !d->rubberBandRect.isEmpty()) {
3638  painter.restore();
3639  QStyleOptionRubberBand option;
3640  option.initFrom(viewport());
3641  option.rect = d->rubberBandRect;
3642  option.shape = QRubberBand::Rectangle;
3643 
3645  if (viewport()->style()->styleHint(QStyle::SH_RubberBand_Mask, &option, viewport(), &mask)) {
3646  // painter clipping for masked rubberbands
3647  painter.setClipRegion(mask.region, Qt::IntersectClip);
3648  }
3649 
3650  viewport()->style()->drawControl(QStyle::CE_RubberBand, &option, &painter, viewport());
3651  }
3652 #endif
3653 
3654  painter.end();
3655 
3656  // Restore painter state protection.
3657  d->scene->d_func()->painterStateProtection = true;
3658 }
3659 
3664 {
3665  Q_D(QGraphicsView);
3666  // Save the last center point - the resize may scroll the view, which
3667  // changes the center point.
3668  QPointF oldLastCenterPoint = d->lastCenterPoint;
3669 
3671  d->recalculateContentSize();
3672 
3673  // Restore the center point again.
3674  if (d->resizeAnchor == NoAnchor && !d->keepLastCenterPoint) {
3675  d->updateLastCenterPoint();
3676  } else {
3677  d->lastCenterPoint = oldLastCenterPoint;
3678  }
3679  d->centerView(d->resizeAnchor);
3680  d->keepLastCenterPoint = false;
3681 
3682  if (d->cacheMode & CacheBackground) {
3683  // Invalidate the background pixmap
3684  d->mustResizeBackgroundPixmap = true;
3685  }
3686 }
3687 
3692 {
3693  Q_D(QGraphicsView);
3694  d->dirtyScroll = true;
3695  if (d->transforming)
3696  return;
3697  if (isRightToLeft())
3698  dx = -dx;
3699 
3700  if (d->viewportUpdateMode != QGraphicsView::NoViewportUpdate) {
3701  if (d->viewportUpdateMode != QGraphicsView::FullViewportUpdate) {
3702  if (d->accelerateScrolling) {
3703 #ifndef QT_NO_RUBBERBAND
3704  // Update new and old rubberband regions
3705  if (!d->rubberBandRect.isEmpty()) {
3706  QRegion rubberBandRegion(d->rubberBandRegion(viewport(), d->rubberBandRect));
3707  rubberBandRegion += rubberBandRegion.translated(-dx, -dy);
3708  viewport()->update(rubberBandRegion);
3709  }
3710 #endif
3711  d->dirtyScrollOffset.rx() += dx;
3712  d->dirtyScrollOffset.ry() += dy;
3713  d->dirtyRegion.translate(dx, dy);
3714  viewport()->scroll(dx, dy);
3715  } else {
3716  d->updateAll();
3717  }
3718  } else {
3719  d->updateAll();
3720  }
3721  }
3722 
3723  d->updateLastCenterPoint();
3724 
3725  if ((d->cacheMode & CacheBackground)
3726 #ifdef Q_WS_X11
3727  && X11->use_xrender
3728 #endif
3729  ) {
3730  // Scroll the background pixmap
3731  QRegion exposed;
3732  if (!d->backgroundPixmap.isNull())
3733  d->backgroundPixmap.scroll(dx, dy, d->backgroundPixmap.rect(), &exposed);
3734 
3735  // Invalidate the background pixmap
3736  d->backgroundPixmapExposed.translate(dx, dy);
3737  d->backgroundPixmapExposed += exposed;
3738  }
3739 
3740  // Always replay on scroll.
3741  if (d->sceneInteractionAllowed)
3742  d->replayLastMouseEvent();
3743 }
3744 
3749 {
3750  Q_D(QGraphicsView);
3751  d->recalculateContentSize();
3752  d->centerView(d->transformationAnchor);
3754 }
3755 
3760 {
3761  Q_D(QGraphicsView);
3762  if (d->scene)
3763  QApplication::sendEvent(d->scene, event);
3764 }
3765 
3784 {
3785  Q_D(QGraphicsView);
3786  if (d->scene && d->backgroundBrush.style() == Qt::NoBrush) {
3787  d->scene->drawBackground(painter, rect);
3788  return;
3789  }
3790 
3791  painter->fillRect(rect, d->backgroundBrush);
3792 }
3793 
3812 {
3813  Q_D(QGraphicsView);
3814  if (d->scene && d->foregroundBrush.style() == Qt::NoBrush) {
3815  d->scene->drawForeground(painter, rect);
3816  return;
3817  }
3818 
3819  painter->fillRect(rect, d->foregroundBrush);
3820 }
3821 
3842 void QGraphicsView::drawItems(QPainter *painter, int numItems,
3843  QGraphicsItem *items[],
3844  const QStyleOptionGraphicsItem options[])
3845 {
3846  Q_D(QGraphicsView);
3847  if (d->scene) {
3848  QWidget *widget = painter->device() == viewport() ? viewport() : 0;
3849  d->scene->drawItems(painter, numItems, items, options, widget);
3850  }
3851 }
3852 
3860 {
3861  Q_D(const QGraphicsView);
3862  return d->matrix;
3863 }
3864 
3871 {
3872  Q_D(const QGraphicsView);
3873  QTransform moveMatrix = QTransform::fromTranslate(-d->horizontalScroll(), -d->verticalScroll());
3874  return d->identityMatrix ? moveMatrix : d->matrix * moveMatrix;
3875 }
3876 
3889 {
3890  Q_D(const QGraphicsView);
3891  return !d->identityMatrix || d->horizontalScroll() || d->verticalScroll();
3892 }
3893 
3920 void QGraphicsView::setTransform(const QTransform &matrix, bool combine )
3921 {
3922  Q_D(QGraphicsView);
3923  QTransform oldMatrix = d->matrix;
3924  if (!combine)
3925  d->matrix = matrix;
3926  else
3927  d->matrix = matrix * d->matrix;
3928  if (oldMatrix == d->matrix)
3929  return;
3930 
3931  d->identityMatrix = d->matrix.isIdentity();
3932  d->transforming = true;
3933  if (d->scene) {
3934  d->recalculateContentSize();
3935  d->centerView(d->transformationAnchor);
3936  } else {
3937  d->updateLastCenterPoint();
3938  }
3939 
3940  if (d->sceneInteractionAllowed)
3941  d->replayLastMouseEvent();
3942  d->transforming = false;
3943 
3944  // Any matrix operation requires a full update.
3945  d->updateAll();
3946 }
3947 
3954 {
3956 }
3957 
3959 {
3960  QPointF p = point;
3961  p.rx() += horizontalScroll();
3962  p.ry() += verticalScroll();
3963  return identityMatrix ? p : matrix.inverted().map(p);
3964 }
3965 
3967 {
3968  QPointF scrollOffset(horizontalScroll(), verticalScroll());
3969  QPointF tl = scrollOffset + rect.topLeft();
3970  QPointF tr = scrollOffset + rect.topRight();
3971  QPointF br = scrollOffset + rect.bottomRight();
3972  QPointF bl = scrollOffset + rect.bottomLeft();
3973 
3974  QPolygonF poly(4);
3975  if (!identityMatrix) {
3977  poly[0] = x.map(tl);
3978  poly[1] = x.map(tr);
3979  poly[2] = x.map(br);
3980  poly[3] = x.map(bl);
3981  } else {
3982  poly[0] = tl;
3983  poly[1] = tr;
3984  poly[2] = br;
3985  poly[3] = bl;
3986  }
3987  return poly.boundingRect();
3988 }
3989 
3991 
3992 #include "moc_qgraphicsview.cpp"
3993 
3994 #endif // QT_NO_GRAPHICSVIEW
void scroll(int dx, int dy)
Scrolls the widget including its children dx pixels to the right and dy downward. ...
Definition: qwidget.cpp:10684
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
QPoint pos() const
void setTransform(const QTransform &transform, bool combine=false)
Sets the world transformation matrix.
Definition: qpainter.cpp:9547
QSize baseSize() const
Qt::DropAction dropAction() const
Returns the action that was performed in this drag and drop.
const QMimeData * mimeData() const
This function returns the MIME data of the event.
The QPainter class performs low-level painting on widgets and other paint devices.
Definition: qpainter.h:86
ViewportAnchor resizeAnchor() const
QPaintDevice * device() const
Returns the paint device on which this painter is currently painting, or 0 if the painter is not acti...
Definition: qpainter.cpp:1530
void updateScene(const QList< QRectF > &rects)
Schedules an update of the scene rectangles rects.
void setModifiers(Qt::KeyboardModifiers modifiers)
double d
Definition: qnumeric_p.h:62
QRect toAlignedRect() const
Returns a QRect based on the values of this rectangle that is the smallest possible integer rectangle...
Definition: qrect.cpp:2817
QPointF bottomRight() const
Returns the position of the rectangle&#39;s bottom-right corner.
Definition: qrect.h:540
bool isClipped() const
Returns true if this item is clipped.
void setSource(QWidget *source)
This function set the source widget, i.
bool focusNextPrevChild(bool next)
Reimplemented Function
The QMetaObject class contains meta-information about Qt objects.
Definition: qobjectdefs.h:304
void setScenePos(const QPointF &pos)
Sets the scene position of the mouse to pos.
bool enabled
whether the widget is enabled
Definition: qwidget.h:157
bool updateRectF(const QRectF &rect)
QPalette palette
the widget&#39;s palette
Definition: qwidget.h:180
void storeDragDropEvent(const QGraphicsSceneDragDropEvent *event)
The QGraphicsScene class provides a surface for managing a large number of 2D graphical items...
DragMode
This enum describes the default action for the view when pressing and dragging the mouse over the vie...
Definition: qgraphicsview.h:98
qreal dy() const
Returns the vertical translation factor.
Definition: qtransform.h:277
void setResizeAnchor(ViewportAnchor anchor)
QGraphicsItem * parent
qreal right() const
Returns the x-coordinate of the rectangle&#39;s right edge.
Definition: qrect.h:527
The QKeyEvent class describes a key event.
Definition: qevent.h:224
QWidget * focusWidget() const
Returns the last child of this widget that setFocus had been called on.
Definition: qwidget.cpp:6863
QPoint screenPos() const
Returns the mouse cursor position in screen coordinates.
void focusInEvent(QFocusEvent *event)
Reimplemented Function
QRect adjusted(int x1, int y1, int x2, int y2) const
Returns a new rectangle with dx1, dy1, dx2 and dy2 added respectively to the existing coordinates of ...
Definition: qrect.h:431
bool isNull() const
Returns true if the rectangle is a null rectangle, otherwise returns false.
Definition: qrect.h:231
void setInputMethodHints(Qt::InputMethodHints hints)
Definition: qwidget.cpp:9736
virtual void showEvent(QShowEvent *)
This event handler can be reimplemented in a subclass to receive widget show events which are passed ...
Definition: qwidget.cpp:9842
OptimizationFlags optimizationFlags() const
double qreal
Definition: qglobal.h:1193
The QCursor class provides a mouse cursor with an arbitrary shape.
Definition: qcursor.h:89
static QRectF adjustedItemEffectiveBoundingRect(const QGraphicsItem *item)
QSize sizeHint() const
Reimplemented Function
void setAlignment(Qt::Alignment alignment)
Q_DECL_CONSTEXPR const T & qMin(const T &a, const T &b)
Definition: qglobal.h:1215
QPointF mapToScene(const QPoint &point) const
Returns the viewport coordinate point mapped to scene coordinates.
OptimizationFlag
This enum describes flags that you can enable to improve rendering performance in QGraphicsView...
bool isTransformed() const
Returns true if the view is transformed (i.
void storeMouseEvent(QMouseEvent *event)
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
QGraphicsView::CacheMode cacheMode
QMatrix matrix() const
Returns the current transformation matrix for the view.
QPointF toPointF() const
Returns the variant as a QPointF if the variant has type() Point or PointF ; otherwise returns a null...
Definition: qvariant.cpp:2509
void setModifiers(Qt::KeyboardModifiers modifiers)
QSize size() const
EventRef event
QScopedPointer< QGraphicsLayoutItemPrivate > d_ptr
QPointer< QWidget > widget
void setScenePos(const QPointF &pos)
Sets the position associated with the context menu to the given point in scene coordinates.
void translate(qreal dx, qreal dy)
Translates all elements in the path by ({dx}, {dy}).
void rotate(qreal angle)
Rotates the current view transformation angle degrees clockwise.
QScopedPointer< QGraphicsItemPrivate > d_ptr
int width
the width of the widget excluding any window frame
Definition: qwidget.h:166
static const int QGRAPHICSVIEW_PREALLOC_STYLE_OPTIONS
void unsetCursor()
Definition: qwidget.cpp:5311
void keyPressEvent(QKeyEvent *event)
Reimplemented Function
bool acceptDrops() const
T * data() const
Returns the value of the pointer referenced by this object.
bool hasTranslateOnlySceneTransform()
The QMatrix class specifies 2D transformations of a coordinate system.
Definition: qmatrix.h:61
void contextMenuEvent(QContextMenuEvent *event)
Reimplemented Function
QTransform sceneTransform() const
Returns this item&#39;s scene transformation matrix.
QSize toSize() const
Returns an integer based copy of this size.
Definition: qsize.h:355
Qt::DropActions possibleActions() const
Returns an OR-combination of possible drop actions.
Definition: qevent.h:490
The QPainterPath class provides a container for painting operations, enabling graphical shapes to be ...
Definition: qpainterpath.h:67
int minimum() const
void setButtonDownScenePos(Qt::MouseButton button, const QPointF &pos)
The QWheelEvent class contains parameters that describe a wheel event.
Definition: qevent.h:139
The QContextMenuEvent class contains parameters that describe a context menu event.
Definition: qevent.h:396
void setScreenPos(const QPoint &pos)
bool isVisible() const
Definition: qwidget.h:1005
QTransform & shear(qreal sh, qreal sv)
Shears the coordinate system by sh horizontally and sv vertically, and returns a reference to the mat...
Definition: qtransform.cpp:551
QRectF rect() const
Returns the rect for this touch point, relative to the widget or QGraphicsItem that received the even...
Definition: qevent.cpp:4624
virtual QRectF boundingRect() const =0
This pure virtual function defines the outer bounds of the item as a rectangle; all painting must be ...
void setMimeData(const QMimeData *data)
This function sets the MIME data for the event.
int height() const
Definition: qpaintdevice.h:92
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...
Definition: qpainter.cpp:2801
static bool containsViewport(const QRect &r, int width, int height)
void setStartScenePos(const QPointF &startScenePos)
Definition: qevent.cpp:4719
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, which is in paint device coordinates, using painter.
void setScenePos(const QPointF &pos)
static QWidget * activeWindow()
Returns the application top-level window that has the keyboard input focus, or 0 if no application wi...
void setAccepted(bool accepted)
Definition: qcoreevent.h:306
QBrush foregroundBrush() const
#define SLOT(a)
Definition: qobjectdefs.h:226
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214
The QGraphicsItem class is the base class for all graphical items in a QGraphicsScene.
Definition: qgraphicsitem.h:89
The QGraphicsSceneMouseEvent class provides mouse events in the graphics view framework.
void closeSubpath()
Closes the current subpath by drawing a line to the beginning of the subpath, automatically starting ...
qreal left() const
Returns the x-coordinate of the rectangle&#39;s left edge.
Definition: qrect.h:525
void restore()
Restores the current painter state (pops a saved state off the stack).
Definition: qpainter.cpp:1620
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
void setDropAction(Qt::DropAction action)
Sets the action to be performed on the data by the target.
Definition: qevent.cpp:2746
Qt::DropAction dropAction() const
Returns the action to be performed on the data by the target.
Definition: qevent.h:494
QPointF mapToScene(const QPointF &point) const
virtual int styleHint(StyleHint stylehint, const QStyleOption *opt=0, const QWidget *widget=0, QStyleHintReturn *returnData=0) const =0
Returns an integer representing the specified style hint for the given widget described by the provid...
void dragEnterEvent(QDragEnterEvent *event)
Reimplemented Function
QPainter::RenderHints renderHints() const
QMouseEvent lastMouseEvent
QPointF topLeft() const
Returns the position of the rectangle&#39;s top-left corner.
Definition: qrect.h:539
int left() const
Returns the x-coordinate of the rectangle&#39;s left edge.
Definition: qrect.h:240
QRect translated(int dx, int dy) const
Returns a copy of the rectangle that is translated dx along the x axis and dy along the y axis...
Definition: qrect.h:328
Qt::MouseButtons buttons() const
Returns a Qt::MouseButtons value indicating which buttons were pressed on the mouse when this mouse e...
static const QMetaObject staticMetaObject
This variable stores the meta-object for the class.
Definition: qobject.h:128
int width() const
Returns the width of the rectangle.
Definition: qrect.h:303
QPalette::ColorRole backgroundRole() const
Returns the background role of the widget.
Definition: qwidget.cpp:4677
QScrollBar * verticalScrollBar() const
Returns the vertical scroll bar.
static QString tr(const char *sourceText, const char *comment=0, int n=-1)
QList< QGraphicsItem * > items() const
Returns a list of all items in the scene in descending stacking order.
void mouseDoubleClickEvent(QMouseEvent *event)
Reimplemented Function
virtual void keyReleaseEvent(QKeyEvent *)
This event handler, for event event, can be reimplemented in a subclass to receive key release events...
Definition: qwidget.cpp:9407
QWidget * widget() const
Returns the widget where the event originated, or 0 if the event originates from another application...
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
Qt::KeyboardModifiers modifiers() const
Returns the keyboard modifiers that were pressed when the drag and drop event was created...
ItemSelectionMode
Definition: qnamespace.h:1503
QRect boundingRect() const
Returns the bounding rectangle of this region.
Definition: qregion.cpp:4363
The QAbstractScrollArea widget provides a scrolling area with on-demand scroll bars.
QPointF bottomLeft() const
Returns the position of the rectangle&#39;s bottom-left corner.
Definition: qrect.h:542
void setButtons(Qt::MouseButtons buttons)
The QPolygon class provides a vector of points using integer precision.
Definition: qpolygon.h:60
void addPolygon(const QPolygonF &polygon)
Adds the given polygon to the path as an (unclosed) subpath.
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...
Definition: qtransform.cpp:417
void setScenePos(const QPointF &pos)
void setWidget(QWidget *widget)
Sets the widget related to this event.
QBrush backgroundBrush() const
int height() const
Returns the height of the rectangle.
Definition: qrect.h:306
void inputMethodEvent(QInputMethodEvent *event)
Reimplemented Function
int q_round_bound(qreal d)
bool isActiveWindow() const
void populateSceneDragDropEvent(QGraphicsSceneDragDropEvent *dest, QDropEvent *source)
int bottom() const
Returns the y-coordinate of the rectangle&#39;s bottom edge.
Definition: qrect.h:249
bool hasFocus() const
Definition: qwidget.cpp:6583
QRectF toRectF() const
Returns the variant as a QRectF if the variant has type() Rect or RectF ; otherwise returns an invali...
Definition: qvariant.cpp:2463
DragMode dragMode() const
The QDragMoveEvent class provides an event which is sent while a drag and drop action is in progress...
Definition: qevent.h:530
qint64 horizontalScroll() const
Returns the horizontal scroll value (the X value of the left edge of the viewport).
bool updateSceneSlotReimplementedChecked
Q_DECL_CONSTEXPR T qAbs(const T &t)
Definition: qglobal.h:1201
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
QRectF boundingRect() const
Returns the bounding rectangle of the polygon, or QRectF(0,0,0,0) if the polygon is empty...
Definition: qpolygon.cpp:742
The QObject class is the base class of all Qt objects.
Definition: qobject.h:111
void invalidateScene(const QRectF &rect=QRectF(), QGraphicsScene::SceneLayers layers=QGraphicsScene::AllLayers)
Invalidates and schedules a redraw of layers inside rect.
TransformationType type() const
Returns the transformation type of this matrix.
#define X11
Definition: qt_x11_p.h:724
QVector< QStyleOptionGraphicsItem > styleOptions
#define Q_D(Class)
Definition: qglobal.h:2482
QRectF mapRectFromScene(const QRectF &rect) const
Qt::KeyboardModifiers keyboardModifiers() const
Returns the modifier keys that are pressed.
Definition: qevent.h:488
void focusOutEvent(QFocusEvent *event)
Reimplemented Function
QPainter::RenderHints renderHints
int height() const
virtual int devType() const
Definition: qpaintdevice.h:167
The QSizeF class defines the size of a two-dimensional object using floating point precision...
Definition: qsize.h:202
virtual QPainterPath shape() const
Returns the shape of this item as a QPainterPath in local coordinates.
int rectCount() const
Returns the number of rectangles that will be returned in rects().
Definition: qregion.cpp:4461
Q_CORE_EXPORT QTextStream & right(QTextStream &s)
void setupViewport(QWidget *widget)
This slot is called by QAbstractScrollArea after setViewport() has been called.
void save()
Saves the current painter state (pushes the state onto a stack).
Definition: qpainter.cpp:1590
QGraphicsView::ViewportAnchor transformationAnchor
virtual void focusOutEvent(QFocusEvent *)
This event handler can be reimplemented in a subclass to receive keyboard focus events (focus lost) f...
Definition: qwidget.cpp:9457
CacheMode cacheMode() const
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
Definition: qglobal.h:1217
void setRange(int min, int max)
Sets the slider&#39;s minimum to min and its maximum to max.
QTransform inverted(bool *invertible=0) const
Returns an inverted copy of this matrix.
Definition: qtransform.cpp:364
const QPoint & pos() const
Returns the position of the mouse cursor, relative to the widget that received the event...
Definition: qevent.h:95
void grabGesture(Qt::GestureType type, Qt::GestureFlags flags=Qt::GestureFlags())
Subscribes the widget to a given gesture with specific flags.
Definition: qwidget.cpp:12964
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...
bool isEmpty() const
Returns true if the list contains no items; otherwise returns false.
Definition: qlist.h:152
qreal x() const
Returns the x-coordinate of this point.
Definition: qpoint.h:282
void resize(int size)
Sets the size of the vector to size.
Definition: qvector.h:342
QStyle * style() const
Definition: qwidget.cpp:2742
#define Q_Q(Class)
Definition: qglobal.h:2483
void setButtons(Qt::MouseButtons buttons)
QRectF boundingRect() const
Returns the bounding rectangle of this painter path as a rectangle with floating point precision...
QTransform viewportTransform() const
Returns a matrix that maps viewport coordinates to scene coordinates.
void resetTransform()
Resets the view transformation to the identity matrix.
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...
QCursor cursor() const
Returns the current cursor shape for the item.
void update()
Updates the widget unless updates are disabled or the widget is hidden.
Definition: qwidget.cpp:10883
static const QRectF boundingRect(const QPointF *points, int pointCount)
void wheelEvent(QWheelEvent *)
This event handler can be reimplemented in a subclass to receive wheel events for the viewport() widg...
QWidget * viewport() const
Returns the viewport widget.
bool contains(const QPointF &p) const
Returns true if the given point is inside or on the edge of the rectangle; otherwise returns false...
Definition: qrect.cpp:2349
Qt::Alignment alignment() const
int key() const
Returns the code of the key that was pressed or released.
Definition: qevent.h:231
void resizeEvent(QResizeEvent *)
This event handler can be reimplemented in a subclass to receive resize events (passed in event)...
#define SIGNAL(a)
Definition: qobjectdefs.h:227
void keyReleaseEvent(QKeyEvent *event)
Reimplemented Function
int width() const
Returns the width.
Definition: qsize.h:126
static QWidget * activeModalWidget()
Returns the active modal widget.
QWidget * source() const
This function returns the QGraphicsView that created the QGraphicsSceneDragDropEvent.
QRect mapRect(const QRect &) const
Creates and returns a QRect object that is a copy of the given rectangle, mapped into the coordinate ...
The QScrollBar widget provides a vertical or horizontal scroll bar.
Definition: qscrollbar.h:59
void setBackgroundRole(QPalette::ColorRole)
Sets the background role of the widget to role.
Definition: qwidget.cpp:4708
void setScene(QGraphicsScene *scene)
Sets the current scene to scene.
bool isInteractive() const
int value() const
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
qreal & rx()
Returns a reference to the x coordinate of this point.
Definition: qpoint.h:302
int width() const
Definition: qpaintdevice.h:91
The QGestureEvent class provides the description of triggered gestures.
Definition: qevent.h:841
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511
static bool intersectsViewport(const QRect &r, int width, int height)
bool isAccepted() const
Definition: qcoreevent.h:307
short frameWidth
Definition: qframe_p.h:74
QGraphicsItem * focusItem() const
When the scene is active, this functions returns the scene&#39;s current focus item, or 0 if no item curr...
void setTransform(const QTransform &matrix, bool combine=false)
Sets the view&#39;s current transformation matrix to matrix.
void updateInputMethodSensitivity()
Enables input methods for the view if and only if the current focus item of the scene accepts input m...
void dragLeaveEvent(QDragLeaveEvent *event)
Reimplemented Function
void setModifiers(Qt::KeyboardModifiers modifiers)
Sets the keyboard modifiers associated with the context menu to the modifiers specified.
void setPossibleActions(Qt::DropActions actions)
Sets the possible drop actions that the drag can result in to actions.
QGraphicsView::ViewportUpdateMode viewportUpdateMode
friend class QPixmap
Definition: qwidget.h:748
void resizeEvent(QResizeEvent *event)
Reimplemented Function
void setScreenPos(const QPoint &pos)
Sets the position associated with the context menu to the given point in screen coordinates.
void paintEvent(QPaintEvent *)
This event handler can be reimplemented in a subclass to receive paint events (passed in event)...
int height
the height of the widget excluding any window frame
Definition: qwidget.h:167
bool testAttribute(Qt::WidgetAttribute) const
Returns true if attribute attribute is set on this widget; otherwise returns false.
Definition: qwidget.h:1041
static bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
Creates a connection of the given type from the signal in the sender object to the method in the rece...
Definition: qobject.cpp:2580
QPointF lastPos() const
Returns the position of this touch point from the previous touch event, relative to the widget or QGr...
Definition: qevent.cpp:4571
void setDropAction(Qt::DropAction action)
This function lets the receiver of the drop set the drop action that was performed to action...
void freeStyleOptionsArray(QStyleOptionGraphicsItem *array)
QRectF sceneRect() const
bool itemIsUntransformable() const
int width() const
void initFrom(const QWidget *w)
Definition: qstyleoption.h:99
void initStyleOption(QStyleOptionGraphicsItem *option, const QTransform &worldTransform, const QRegion &exposedRegion, bool allItems=false) const
static void QRect_unite(QRect *rect, const QRect &other)
void resetCachedContent()
Resets any cached content.
quint32 sceneTransformTranslateOnly
qreal height() const
Returns the height of the rectangle.
Definition: qrect.h:710
QRegion rubberBandRegion(const QWidget *widget, const QRect &rect) const
bool isActive() const
Returns true if begin() has been called and end() has not yet been called; otherwise returns false...
Definition: qpainter.cpp:1545
QTransform & rotate(qreal a, Qt::Axis axis=Qt::ZAxis)
Rotates the coordinate system counterclockwise by the given angle about the specified axis and return...
Definition: qtransform.cpp:615
void adjust(int x1, int y1, int x2, int y2)
Adds dx1, dy1, dx2 and dy2 respectively to the existing coordinates of the rectangle.
Definition: qrect.h:434
bool spontaneous() const
Returns true if the event originated outside the application (a system event); otherwise returns fals...
Definition: qcoreevent.h:304
The QPolygonF class provides a vector of points using floating point precision.
Definition: qpolygon.h:134
void dragMoveEvent(QDragMoveEvent *event)
Reimplemented Function
static const int QGRAPHICSVIEW_REGION_RECT_THRESHOLD
The QResizeEvent class contains event parameters for resize events.
Definition: qevent.h:349
QRegion mapToViewRegion(const QGraphicsItem *item, const QRectF &rect) const
const char * styleHint(const QFontDef &request)
QGraphicsItem * itemAt(const QPoint &pos) const
Returns the item at position pos, which is in viewport coordinates.
QPoint screenPos() const
Returns the position of the mouse relative to the screen.
Q_CORE_EXPORT void qWarning(const char *,...)
QPoint map(const QPoint &p) const
Creates and returns a QPoint object that is a copy of the given point, mapped into the coordinate sys...
int delta() const
Returns the distance that the wheel is rotated, in eighths of a degree.
Definition: qevent.h:150
void _q_setViewportCursor(const QCursor &cursor)
void setUpdateClip(QGraphicsItem *)
QRectF mapRectToScene(const QRect &rect) const
void mouseMoveEventHandler(QMouseEvent *event)
Qt::MouseButtons buttons() const
Returns the mouse state when the event occurred.
Definition: qevent.h:158
void setSceneRect(const QRectF &sceneRect)
Definition: qevent.cpp:4783
RenderHint
Renderhints are used to specify flags to QPainter that may or may not be respected by any given engin...
Definition: qpainter.h:93
void translate(qreal dx, qreal dy)
Translates the current view transformation by (dx, dy).
qreal width() const
Returns the width of the rectangle.
Definition: qrect.h:707
QTransform transform() const
Returns the current transformation matrix for the view.
static bool sendEvent(QObject *receiver, QEvent *event)
Sends event event directly to receiver receiver, using the notify() function.
void setCursor(const QCursor &)
Definition: qwidget.cpp:5290
QRectF sceneRect
the scene rectangle; the bounding rectangle of the scene
void setRect(qreal x, qreal y, qreal w, qreal h)
Sets the coordinates of the rectangle&#39;s top-left corner to (x, y), and its size to the given width an...
Definition: qrect.h:754
The QDragLeaveEvent class provides an event that is sent to a widget when a drag and drop action leav...
Definition: qevent.h:577
The QRegion class specifies a clip region for a painter.
Definition: qregion.h:68
int indexOfSlot(const char *slot) const
Finds slot and returns its index; otherwise returns -1.
#define QT_NO_CURSOR
QCursor cursor
the cursor shape for this widget
Definition: qwidget.h:183
static int startDragDistance()
__int64 qint64
Definition: qglobal.h:942
void showEvent(QShowEvent *event)
Reimplemented Function
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 setCoords(int x1, int y1, int x2, int y2)
Sets the coordinates of the rectangle&#39;s top-left corner to (x1, y1), and the coordinates of its botto...
Definition: qrect.h:416
bool isOpaque() const
Returns true if the brush is fully opaque otherwise false.
Definition: qbrush.cpp:910
The QShowEvent class provides an event that is sent when a widget is shown.
Definition: qevent.h:380
bool opaque
whether the rubber band is required to be drawn in an opaque style
Definition: qstyleoption.h:676
void setOptimizationFlag(OptimizationFlag flag, bool enabled=true)
Enables flag if enabled is true; otherwise disables flag.
Qt::DropAction proposedAction() const
Returns the proposed drop action.
Definition: qevent.h:491
Qt::Orientation orientation() const
Returns the wheel&#39;s orientation.
Definition: qevent.h:159
The QStyleOptionRubberBand class is used to describe the parameters needed for drawing a rubber band...
Definition: qstyleoption.h:669
void setLastScenePos(const QPointF &pos)
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:275
void translate(qreal dx, qreal dy)
Moves the rectangle dx along the x-axis and dy along the y-axis, relative to the current position...
Definition: qrect.h:716
Qt::MouseButton button() const
Returns the button that caused the event.
Definition: qevent.h:101
void setInteractive(bool allowed)
GestureType
Definition: qnamespace.h:1759
QRect toRect() const
Returns a QRect based on the values of this rectangle.
Definition: qrect.h:845
QRect rect() const
QRegion mask() const
Returns the mask currently set on a widget.
Definition: qwidget.cpp:10058
Q_AUTOTEST_EXPORT QPainterPath qt_regionToPath(const QRegion &region)
Definition: qregion.cpp:1160
void scrollContentsBy(int dx, int dy)
Reimplemented Function
QGraphicsView(QWidget *parent=0)
Constructs a QGraphicsView.
bool isEnabled() const
Definition: qwidget.h:948
#define None
const QBrush & brush(ColorGroup cg, ColorRole cr) const
Returns the brush in the specified color group, used for the given color role.
Definition: qpalette.cpp:874
const T & at(int i) const
Returns the item at index position i in the vector.
Definition: qvector.h:350
void shear(qreal sh, qreal sv)
Shears the current view transformation by (sh, sv).
The QGraphicsProxyWidget class provides a proxy layer for embedding a QWidget in a QGraphicsScene...
Reason reason() const
Returns the reason for this context event.
Definition: qevent.h:415
void setBackgroundBrush(const QBrush &brush)
void setMouseTracking(bool enable)
Definition: qwidget.h:990
The QMouseEvent class contains parameters that describe a mouse event.
Definition: qevent.h:85
Qt::DropAction proposedAction() const
Returns the drop action that is proposed, i.e., preferred.
static QDesktopWidget * desktop()
Returns the desktop widget (also called the root window).
QTransform deviceTransform(const QTransform &viewportTransform) const
Returns this item&#39;s device transformation matrix, using viewportTransform to map from scene to device...
void setAutoFillBackground(bool enabled)
Definition: qwidget.cpp:631
const QPoint & pos() const
Returns the position of the mouse cursor relative to the widget that received the event...
Definition: qevent.h:151
T & first()
Returns a reference to the first item in the list.
Definition: qlist.h:282
QEventPrivate * d
Definition: qcoreevent.h:315
void setMatrix(const QMatrix &matrix, bool combine=false)
Sets the view&#39;s current transformation matrix to matrix.
bool isEmpty() const
Returns true if the rectangle is empty, otherwise returns false.
Definition: qrect.h:234
virtual bool viewportEvent(QEvent *)
The main event handler for the scrolling area (the viewport() widget).
InputMethodQuery
Definition: qnamespace.h:1541
void setRenderHints(RenderHints hints, bool on=true)
Sets the given render hints on the painter if on is true; otherwise clears the render hints...
Definition: qpainter.cpp:7649
The QBrush class defines the fill pattern of shapes drawn by QPainter.
Definition: qbrush.h:76
The QInputMethodEvent class provides parameters for input method events.
Definition: qevent.h:431
static bool disconnect(const QObject *sender, const char *signal, const QObject *receiver, const char *member)
Disconnects signal in object sender from method in object receiver.
Definition: qobject.cpp:2895
QPoint center() const
Returns the center point of the rectangle.
Definition: qrect.h:300
void setRubberBandSelectionMode(Qt::ItemSelectionMode mode)
void setInputMethodHints(Qt::InputMethodHints hints)
Sets the current input method hints of this item to hints.
void setReason(Reason reason)
Sets the reason for the context menu event to reason.
QPoint mapFromScene(const QPointF &point) const
Returns the scene coordinate point to viewport coordinates.
Qt::DropActions possibleActions() const
Returns the possible drop actions that the drag and drop can result in.
QList< QGraphicsItem * > findItems(const QRegion &exposedRegion, bool *allItems, const QTransform &viewTransform) const
Adjustments in findItems: mapToScene(QRect) forces us to adjust theinput rectangle by (0...
Qt::ItemSelectionMode rubberBandSelectionMode() const
void mouseMoveEvent(QMouseEvent *event)
Reimplemented Function
bool hasCursor() const
Returns true if this item has a cursor set; otherwise, false is returned.
The QStyleHintReturnMask class provides style hints that return a QRegion.
Definition: qstyleoption.h:923
The QGraphicsSceneHelpEvent class provides events when a tooltip is requested.
int top() const
Returns the y-coordinate of the rectangle&#39;s top edge.
Definition: qrect.h:243
bool event(QEvent *event)
Reimplemented Function
qreal angle(const QPointF &p1, const QPointF &p2)
Qt::MouseButtons mouseButtons() const
Returns the mouse buttons that are pressed.
Definition: qevent.h:487
void setLastScenePos(const QPointF &lastScenePos)
Definition: qevent.cpp:4751
QString toolTip() const
The QDropEvent class provides an event which is sent when a drag and drop action is completed...
Definition: qevent.h:476
void setAcceptDrops(bool on)
Definition: qwidget.cpp:3534
static QWidget * activePopupWidget()
Returns the active popup widget.
QRegion boundingRegion(const QTransform &itemToDeviceTransform) const
Returns the bounding region for this item.
void scale(qreal sx, qreal sy)
Scales the current view transformation by (sx, sy).
Qt::MouseButtons buttons() const
Returns the button state when the event was generated.
Definition: qevent.h:102
void setClipRegion(const QRegion &, Qt::ClipOperation op=Qt::ReplaceClip)
Sets the clip region to the given region using the specified clip operation.
Definition: qpainter.cpp:2917
void setScreenPos(const QPoint &pos)
int right() const
Returns the x-coordinate of the rectangle&#39;s right edge.
Definition: qrect.h:246
const QTransform & worldTransform() const
Returns the world transformation matrix.
Definition: qpainter.cpp:9652
void map(int x, int y, int *tx, int *ty) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: qmatrix.cpp:384
int x() const
void setSceneRect(const QRectF &rect)
The QGraphicsSceneDragDropEvent class provides events for drag and drop in the graphics view framewor...
virtual void drawItems(QPainter *painter, int numItems, QGraphicsItem *items[], const QStyleOptionGraphicsItem options[])
Draws the items items in the scene using painter, after the background and before the foreground are ...
QPointF scenePos() const
Returns the mouse cursor position in scene coordinates.
QRect rect
the internal geometry of the widget excluding any window frame
Definition: qwidget.h:168
QSizeF boundedTo(const QSizeF &) const
Returns a size holding the minimum width and height of this size and the given otherSize.
Definition: qsize.h:350
Qt::Alignment alignment
QRect toRect() const
Returns the variant as a QRect if the variant has type() Rect ; otherwise returns an invalid QRect...
Definition: qvariant.cpp:2416
static void translateTouchEvent(QGraphicsViewPrivate *d, QTouchEvent *touchEvent)
QPoint toPoint() const
Rounds the coordinates of this point to the nearest integer, and returns a QPoint object with the rou...
Definition: qpoint.h:376
bool updateRegion(const QRectF &rect, const QTransform &xform)
Type type() const
Returns the storage type of the value stored in the variant.
Definition: qvariant.cpp:1901
bool updateRect(const QRect &rect)
iterator insert(const Key &key, const T &value)
Inserts a new item with the key key and a value of value.
Definition: qmap.h:559
QWidget * source() const
If the source of the drag operation is a widget in this application, this function returns that sourc...
Definition: qevent.cpp:2739
QObject * parent() const
Returns a pointer to the parent object.
Definition: qobject.h:273
The QDragEnterEvent class provides an event which is sent to a widget when a drag and drop action ent...
Definition: qevent.h:555
The QPoint class defines a point in the plane using integer precision.
Definition: qpoint.h:53
QVector< QRect > rects() const
Returns an array of non-overlapping rectangles that make up the region.
Definition: qregion.cpp:4412
virtual bool focusNextPrevChild(bool next)
Finds a new widget to give the keyboard focus to, as appropriate for Tab and Shift+Tab, and returns true if it can find a new widget, or false if it can&#39;t.
Definition: qwidget.cpp:6836
const QList< QTouchEvent::TouchPoint > & touchPoints() const
Returns the list of touch points contained in the touch event.
Definition: qevent.h:820
virtual void drawControl(ControlElement element, const QStyleOption *opt, QPainter *p, const QWidget *w=0) const =0
Draws the given element with the provided painter with the style options specified by option...
unsigned int quint32
Definition: qglobal.h:938
QScrollBar * horizontalScrollBar() const
Returns the horizontal scroll bar.
#define QT_NO_RUBBERBAND
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
void setModifiers(Qt::KeyboardModifiers modifiers)
Sets the keyboard modifiers that were pressed when the event was created to modifiers.
void setWidget(QWidget *widget)
Sets the widget for this event to the widget specified.
Definition: qevent.cpp:5039
void updateSceneRect(const QRectF &rect)
Notifies QGraphicsView that the scene&#39;s scene rect has changed.
void setScenePos(const QPointF &pos)
Sets the position associated with the context menu to the given point in scene coordinates.
virtual void drawBackground(QPainter *painter, const QRectF &rect)
Draws the background of the scene using painter, before any items and the foreground are drawn...
bool viewportEvent(QEvent *event)
Reimplemented Function
int height() const
Returns the height.
Definition: qsize.h:129
const QPoint & globalPos() const
Returns the mouse cursor position when the event was generated in global coordinates.
Definition: qevent.h:598
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
Definition: qnamespace.h:54
#define Q_AUTOTEST_EXPORT
Definition: qglobal.h:1510
Qt::MouseButton mousePressButton
QPainterPath clipPath() const
Returns this item&#39;s clip path, or an empty QPainterPath if this item is not clipped.
QRubberBand::Shape shape
the shape of the rubber band
Definition: qstyleoption.h:675
void setButtons(Qt::MouseButtons buttons)
Sets the mouse buttons that were pressed when the event was created to buttons.
void setWorldTransform(const QTransform &matrix, bool combine=false)
Sets the world transformation matrix.
Definition: qpainter.cpp:9630
const QPoint & globalPos() const
Returns the global position of the mouse pointer at the time of the event.
Definition: qevent.h:152
QRect mapToViewRect(const QGraphicsItem *item, const QRectF &rect) const
void setProposedAction(Qt::DropAction action)
Sets the proposed action to action.
static void mouseEvent(MouseAction action, QWidget *widget, Qt::MouseButton button, Qt::KeyboardModifiers stateKey, QPoint pos, int delay=-1)
Definition: qtestmouse.h:71
void setForegroundBrush(const QBrush &brush)
QPointF scenePos() const
Returns the position of the mouse in scene coordinates.
qreal dx() const
Returns the horizontal translation factor.
Definition: qtransform.h:273
qreal & ry()
Returns a reference to the y coordinate of this point.
Definition: qpoint.h:307
int y() const
Returns the y coordinate of this point.
Definition: qpoint.h:131
void setAttribute(Qt::WidgetAttribute, bool on=true)
Sets the attribute attribute on this widget if on is true; otherwise clears the attribute.
Definition: qwidget.cpp:11087
qreal y() const
Returns the y-coordinate of this point.
Definition: qpoint.h:287
QGraphicsView::DragMode dragMode
QPoint mapFromGlobal(const QPoint &) const
Translates the global screen coordinate pos to widget coordinates.
QWidget * window() const
Returns the window for this widget, i.e.
Definition: qwidget.cpp:4492
QObject * parent
Definition: qobject.h:92
The TouchPoint class provides information about a touch point in a QTouchEvent.
Definition: qevent.h:744
void setCacheMode(CacheMode mode)
QScopedPointer< QObjectData > d_ptr
Definition: qobject.h:320
The QGraphicsView class provides a widget for displaying the contents of a QGraphicsScene.
Definition: qgraphicsview.h:64
qreal top() const
Returns the y-coordinate of the rectangle&#39;s top edge.
Definition: qrect.h:526
bool event(QEvent *)
Reimplemented Function
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...
Definition: qpainter.cpp:5619
TransformData * transformData
QGraphicsView::OptimizationFlags optimizationFlags
void paintEvent(QPaintEvent *event)
Reimplemented Function
The QTouchEvent class contains parameters that describe a touch event.
Definition: qevent.h:741
QMap< QWidget *, QRect > paintedViewBoundingRects
const QMimeData * mimeData() const
Returns the data that was dropped on the widget and its associated MIME type information.
Definition: qevent.h:498
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:53
T * data()
Returns a pointer to the data stored in the vector.
Definition: qvector.h:152
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...
Definition: qtransform.cpp:462
void keyPressEvent(QKeyEvent *)
This function is called with key event e when key presses occur.
QTransform & scale(qreal sx, qreal sy)
Scales the coordinate system by sx horizontally and sy vertically, and returns a reference to the mat...
Definition: qtransform.cpp:485
void setWidget(QWidget *awidget)
Definition: qevent.h:823
void setViewport(QWidget *widget)
Sets the viewport to be the given widget.
QRegion translated(int dx, int dy) const
Returns a copy of the region that is translated dx along the x axis and dy along the y axis...
Definition: qregion.cpp:743
bool isRightToLeft() const
Definition: qwidget.h:428
quint32 mustResizeBackgroundPixmap
~QGraphicsView()
Destructs the QGraphicsView object.
bool qt_sendSpontaneousEvent(QObject *receiver, QEvent *event)
bool intersects(const QRect &r) const
Returns true if this rectangle intersects with the given rectangle (i.
Definition: qrect.cpp:1429
RenderHints renderHints() const
Returns a flag that specifies the rendering hints that are set for this painter.
Definition: qpainter.cpp:7675
void centerView(QGraphicsView::ViewportAnchor anchor)
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...
Definition: qpainter.cpp:3365
void reserve(int size)
Attempts to allocate memory for at least size elements.
Definition: qvector.h:339
int x() const
Returns the x coordinate of this point.
Definition: qpoint.h:128
void setScreenPos(const QPoint &pos)
Sets the position associated with the context menu to the given point in screen coordinates.
void setRenderHints(QPainter::RenderHints hints)
void setRenderHint(QPainter::RenderHint hint, bool enabled=true)
If enabled is true, the render hint hint is enabled; otherwise it is disabled.
qint64 verticalScroll() const
Returns the vertical scroll value (the X value of the top edge of the viewport).
QGraphicsSceneDragDropEvent * lastDragDropEvent
The QGraphicsSceneWheelEvent class provides wheel events in the graphics view framework.
void setOpacity(qreal opacity)
Sets the opacity of the painter to opacity.
Definition: qpainter.cpp:2139
int capacity() const
Returns the maximum number of items that can be stored in the vector without forcing a reallocation...
Definition: qvector.h:143
QTouchEventSequence touchEvent(QWidget *widget=0, QTouchEvent::DeviceType deviceType=QTouchEvent::TouchScreen)
Creates and returns a QTouchEventSequence for the device deviceType to simulate events for widget...
Definition: qtesttouch.h:141
qreal bottom() const
Returns the y-coordinate of the rectangle&#39;s bottom edge.
Definition: qrect.h:528
QList< QGraphicsItem * > items() const
Returns a list of all the items in the associated scene, in descending stacking order (i...
QRegion region
the region for style hints that return a QRegion
Definition: qstyleoption.h:930
quint32 mustAllocateStyleOptions
void setLastScreenPos(const QPoint &pos)
QRectF translated(qreal dx, qreal dy) const
Returns a copy of the rectangle that is translated dx along the x axis and dy along the y axis...
Definition: qrect.h:740
bool isValid() const
Returns true if the rectangle is valid, otherwise returns false.
Definition: qrect.h:237
bool isEmpty() const
Returns true if the rectangle is empty, otherwise returns false.
Definition: qrect.h:658
Qt::InputMethodHints inputMethodHints
What input method specific hints the widget has.
Definition: qwidget.h:224
QPointF topRight() const
Returns the position of the rectangle&#39;s top-right corner.
Definition: qrect.h:541
void centerOn(const QPointF &pos)
Scrolls the contents of the viewport to ensure that the scene coordinate pos, is centered in the view...
Qt::KeyboardModifiers modifiers() const
Returns the keyboard modifier flags that existed immediately before the event occurred.
Definition: qevent.h:79
void wheelEvent(QWheelEvent *event)
Reimplemented Function
The QPaintEvent class contains event parameters for paint events.
Definition: qevent.h:298
int maximum() const
void setTouchPoints(const QList< QTouchEvent::TouchPoint > &atouchPoints)
Sets the list of touch points for this event.
Definition: qevent.h:826
ViewportUpdateMode viewportUpdateMode() const
void setButtonDownScreenPos(Qt::MouseButton button, const QPoint &pos)
void setOptimizationFlags(OptimizationFlags flags)
void mouseReleaseEvent(QMouseEvent *event)
Reimplemented Function
QStyleOptionGraphicsItem * allocStyleOptionsArray(int numItems)
QPointer< QGraphicsScene > scene
Reason
This enum describes the reason why the context event was sent.
void setButton(Qt::MouseButton button)
The QEvent class is the base class of all event classes.
Definition: qcoreevent.h:56
QVariant inputMethodQuery(Qt::InputMethodQuery query) const
Reimplemented Function
Type type() const
Returns the event type.
Definition: qcoreevent.h:303
void setViewportUpdateMode(ViewportUpdateMode mode)
const QPoint & globalPos() const
Returns the global position of the mouse cursor at the time of the event.
Definition: qevent.h:96
Q_CORE_EXPORT QTextStream & left(QTextStream &s)
QPointF center() const
Returns the center point of the rectangle.
Definition: qrect.h:686
void setDragMode(DragMode mode)
QGraphicsScene * scene() const
Returns a pointer to the scene that is currently visualized in the view.
The QStyleOptionGraphicsItem class is used to describe the parameters needed to draw a QGraphicsItem...
Definition: qstyleoption.h:867
QSize sizeHint() const
Reimplemented Function
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729
void setOrientation(Qt::Orientation orientation)
void setScreenPos(const QPoint &pos)
Sets the mouse position relative to the screen to pos.
int size() const
Returns the number of items in the vector.
Definition: qvector.h:137
bool isNull() const
Returns true if the rectangle is a null rectangle, otherwise returns false.
Definition: qrect.h:655
QRectF sceneBoundingRect() const
Returns the bounding rect of this item in scene coordinates, by combining sceneTransform() with bound...
virtual void focusInEvent(QFocusEvent *)
This event handler can be reimplemented in a subclass to receive keyboard focus events (focus receive...
Definition: qwidget.cpp:9431
Qt::ItemSelectionMode rubberBandSelectionMode
QRect rect
the area that should be used for various calculations and painting
Definition: qstyleoption.h:90
#define INT_MAX
void resetMatrix()
Resets the view transformation matrix to the identity matrix.
#define enabled
The QFocusEvent class contains event parameters for widget focus events.
Definition: qevent.h:275
QPoint toPoint() const
Returns the variant as a QPoint if the variant has type() Point or PointF ; otherwise returns a null ...
Definition: qvariant.cpp:2400
QGraphicsView::ViewportAnchor resizeAnchor
virtual const QMetaObject * metaObject() const
Returns a pointer to the meta-object of this object.
bool end()
Ends painting.
Definition: qpainter.cpp:1929
QWidget * widget() const
Returns a pointer to the embedded widget.
QMatrix inverted(bool *invertible=0) const
Returns an inverted copy of this matrix.
Definition: qmatrix.cpp:1066
void mousePressEvent(QMouseEvent *event)
Reimplemented Function
const QPoint & pos() const
Returns the position where the drop was made.
Definition: qevent.h:486
void fillRect(const QRectF &, const QBrush &)
Fills the given rectangle with the brush specified.
Definition: qpainter.cpp:7420
Qt::MouseButtons buttons() const
Returns the combination of mouse buttons that were pressed at the time the event was sent...
ViewportAnchor transformationAnchor() const
static QPoint pos()
Returns the position of the cursor (hot spot) in global screen coordinates.
Definition: qcursor_mac.mm:310
QPointF startPos() const
Returns the starting position of this touch point, relative to the widget or QGraphicsItem that recei...
Definition: qevent.cpp:4522
void setFocusPolicy(Qt::FocusPolicy policy)
Definition: qwidget.cpp:7631
ViewportUpdateMode
This enum describes how QGraphicsView updates its viewport when the scene contents change or are expo...
The QTransform class specifies 2D transformations of a coordinate system.
Definition: qtransform.h:65
void dropEvent(QDropEvent *event)
Reimplemented Function
ViewportAnchor
This enums describe the possible anchors that QGraphicsView can use when the user resizes the view or...
Definition: qgraphicsview.h:86
The QHelpEvent class provides an event that is used to request helpful information about a particular...
Definition: qevent.h:586
void setTransformationAnchor(ViewportAnchor anchor)
AspectRatioMode
Definition: qnamespace.h:1317
The QGraphicsSceneContextMenuEvent class provides context menu events in the graphics view framework...
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:597