Changeset 846 for trunk/src/gui/graphicsview/qgraphicsview.cpp
- Timestamp:
- May 5, 2011, 5:36:53 AM (14 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk
- Property svn:mergeinfo changed
/branches/vendor/nokia/qt/4.7.2 (added) merged: 845 /branches/vendor/nokia/qt/current merged: 844 /branches/vendor/nokia/qt/4.6.3 removed
- Property svn:mergeinfo changed
-
trunk/src/gui/graphicsview/qgraphicsview.cpp
r769 r846 1 1 /**************************************************************************** 2 2 ** 3 ** Copyright (C) 201 0Nokia Corporation and/or its subsidiary(-ies).3 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). 4 4 ** All rights reserved. 5 5 ** Contact: Nokia Corporation (qt-info@nokia.com) … … 54 54 QGraphicsView visualizes the contents of a QGraphicsScene in a scrollable 55 55 viewport. To create a scene with geometrical items, see QGraphicsScene's 56 documentation. QGraphicsView is part of \l{TheGraphics View Framework}.56 documentation. QGraphicsView is part of the \l{Graphics View Framework}. 57 57 58 58 To visualize a scene, you start by constructing a QGraphicsView object, … … 328 328 sceneInteractionAllowed(true), hasSceneRect(false), 329 329 connectedToScene(false), 330 mousePressButton(Qt::NoButton),330 useLastMouseEvent(false), 331 331 identityMatrix(true), 332 332 dirtyScroll(true), 333 333 accelerateScrolling(true), 334 keepLastCenterPoint(true), 335 transforming(false), 336 handScrolling(false), 337 mustAllocateStyleOptions(false), 338 mustResizeBackgroundPixmap(true), 339 fullUpdatePending(true), 340 hasUpdateClip(false), 341 mousePressButton(Qt::NoButton), 334 342 leftIndent(0), topIndent(0), 335 343 lastMouseEvent(QEvent::None, QPoint(), Qt::NoButton, 0, 0), 336 useLastMouseEvent(false),337 keepLastCenterPoint(true),338 344 alignment(Qt::AlignCenter), 339 transforming(false),340 345 transformationAnchor(QGraphicsView::AnchorViewCenter), resizeAnchor(QGraphicsView::NoAnchor), 341 346 viewportUpdateMode(QGraphicsView::MinimalViewportUpdate), … … 346 351 rubberBandSelectionMode(Qt::IntersectsItemShape), 347 352 #endif 348 handScrolling(false), handScrollMotions(0), cacheMode(0), 349 mustAllocateStyleOptions(false), 350 mustResizeBackgroundPixmap(true), 353 handScrollMotions(0), cacheMode(0), 351 354 #ifndef QT_NO_CURSOR 352 355 hasStoredOriginalCursor(false), 353 356 #endif 354 357 lastDragDropEvent(0), 355 fullUpdatePending(true),356 358 updateSceneSlotReimplementedChecked(false) 357 359 { … … 734 736 735 737 // Restore the original viewport cursor. 736 hasStoredOriginalCursor = false; 737 if (dragMode == QGraphicsView::ScrollHandDrag) 738 viewport->setCursor(Qt::OpenHandCursor); 739 else 740 viewport->setCursor(originalCursor); 738 if (hasStoredOriginalCursor) { 739 hasStoredOriginalCursor = false; 740 if (dragMode == QGraphicsView::ScrollHandDrag) 741 viewport->setCursor(Qt::OpenHandCursor); 742 else 743 viewport->setCursor(originalCursor); 744 } 741 745 } 742 746 #endif … … 853 857 viewport->update(); 854 858 } else if (viewportUpdateMode == QGraphicsView::BoundingRectViewportUpdate) { 855 if (optimizationFlags & QGraphicsView::DontAdjustForAntialiasing) 856 viewport->update(dirtyBoundingRect.adjusted(-1, -1, 1, 1)); 857 else 858 viewport->update(dirtyBoundingRect.adjusted(-2, -2, 2, 2)); 859 viewport->update(dirtyBoundingRect); 859 860 } else { 860 861 viewport->update(dirtyRegion); // Already adjusted in updateRect/Region. … … 881 882 } 882 883 883 bool QGraphicsViewPrivate::updateRegion(const QRegion &r) 884 { 885 if (fullUpdatePending || viewportUpdateMode == QGraphicsView::NoViewportUpdate || r.isEmpty()) 884 /* 885 Calling this function results in update rects being clipped to the item's 886 bounding rect. Note that updates prior to this function call is not clipped. 887 The clip is removed by passing 0. 888 */ 889 void QGraphicsViewPrivate::setUpdateClip(QGraphicsItem *item) 890 { 891 Q_Q(QGraphicsView); 892 // We simply ignore the request if the update mode is either FullViewportUpdate 893 // or NoViewportUpdate; in that case there's no point in clipping anything. 894 if (!item || viewportUpdateMode == QGraphicsView::NoViewportUpdate 895 || viewportUpdateMode == QGraphicsView::FullViewportUpdate) { 896 hasUpdateClip = false; 897 return; 898 } 899 900 // Calculate the clip (item's bounding rect in view coordinates). 901 // Optimized version of: 902 // QRect clip = item->deviceTransform(q->viewportTransform()) 903 // .mapRect(item->boundingRect()).toAlignedRect(); 904 QRect clip; 905 if (item->d_ptr->itemIsUntransformable()) { 906 QTransform xform = item->deviceTransform(q->viewportTransform()); 907 clip = xform.mapRect(item->boundingRect()).toAlignedRect(); 908 } else if (item->d_ptr->sceneTransformTranslateOnly && identityMatrix) { 909 QRectF r(item->boundingRect()); 910 r.translate(item->d_ptr->sceneTransform.dx() - horizontalScroll(), 911 item->d_ptr->sceneTransform.dy() - verticalScroll()); 912 clip = r.toAlignedRect(); 913 } else if (!q->isTransformed()) { 914 clip = item->d_ptr->sceneTransform.mapRect(item->boundingRect()).toAlignedRect(); 915 } else { 916 QTransform xform = item->d_ptr->sceneTransform; 917 xform *= q->viewportTransform(); 918 clip = xform.mapRect(item->boundingRect()).toAlignedRect(); 919 } 920 921 if (hasUpdateClip) { 922 // Intersect with old clip. 923 updateClip &= clip; 924 } else { 925 updateClip = clip; 926 hasUpdateClip = true; 927 } 928 } 929 930 bool QGraphicsViewPrivate::updateRegion(const QRectF &rect, const QTransform &xform) 931 { 932 if (rect.isEmpty()) 886 933 return false; 887 934 888 const QRect boundingRect = r.boundingRect(); 889 if (!intersectsViewport(boundingRect, viewport->width(), viewport->height())) 890 return false; // Update region outside viewport. 935 if (viewportUpdateMode != QGraphicsView::MinimalViewportUpdate 936 && viewportUpdateMode != QGraphicsView::SmartViewportUpdate) { 937 // No point in updating with QRegion granularity; use the rect instead. 938 return updateRectF(xform.mapRect(rect)); 939 } 940 941 // Update mode is either Minimal or Smart, so we have to do a potentially slow operation, 942 // which is clearly documented here: QGraphicsItem::setBoundingRegionGranularity. 943 const QRegion region = xform.map(QRegion(rect.toAlignedRect())); 944 QRect viewRect = region.boundingRect(); 945 const bool dontAdjustForAntialiasing = optimizationFlags & QGraphicsView::DontAdjustForAntialiasing; 946 if (dontAdjustForAntialiasing) 947 viewRect.adjust(-1, -1, 1, 1); 948 else 949 viewRect.adjust(-2, -2, 2, 2); 950 if (!intersectsViewport(viewRect, viewport->width(), viewport->height())) 951 return false; // Update region for sure outside viewport. 952 953 const QVector<QRect> &rects = region.rects(); 954 for (int i = 0; i < rects.size(); ++i) { 955 viewRect = rects.at(i); 956 if (dontAdjustForAntialiasing) 957 viewRect.adjust(-1, -1, 1, 1); 958 else 959 viewRect.adjust(-2, -2, 2, 2); 960 if (hasUpdateClip) 961 viewRect &= updateClip; 962 dirtyRegion += viewRect; 963 } 964 965 return true; 966 } 967 968 // NB! Assumes the rect 'r' is already aligned and adjusted for antialiasing. 969 // For QRectF use updateRectF(const QRectF &) to ensure proper adjustments. 970 bool QGraphicsViewPrivate::updateRect(const QRect &r) 971 { 972 if (fullUpdatePending || viewportUpdateMode == QGraphicsView::NoViewportUpdate 973 || !intersectsViewport(r, viewport->width(), viewport->height())) { 974 return false; 975 } 891 976 892 977 switch (viewportUpdateMode) { … … 896 981 break; 897 982 case QGraphicsView::BoundingRectViewportUpdate: 898 QRect_unite(&dirtyBoundingRect, boundingRect); 983 if (hasUpdateClip) 984 QRect_unite(&dirtyBoundingRect, r & updateClip); 985 else 986 QRect_unite(&dirtyBoundingRect, r); 899 987 if (containsViewport(dirtyBoundingRect, viewport->width(), viewport->height())) { 900 988 fullUpdatePending = true; … … 904 992 case QGraphicsView::SmartViewportUpdate: // ### DEPRECATE 905 993 case QGraphicsView::MinimalViewportUpdate: 906 { 907 const QVector<QRect> &rects = r.rects(); 908 for (int i = 0; i < rects.size(); ++i) { 909 if (optimizationFlags & QGraphicsView::DontAdjustForAntialiasing) 910 dirtyRegion += rects.at(i).adjusted(-1, -1, 1, 1); 911 else 912 dirtyRegion += rects.at(i).adjusted(-2, -2, 2, 2); 913 } 914 break; 915 } 916 default: 917 break; 918 } 919 920 return true; 921 } 922 923 bool QGraphicsViewPrivate::updateRect(const QRect &r) 924 { 925 if (fullUpdatePending || viewportUpdateMode == QGraphicsView::NoViewportUpdate 926 || !intersectsViewport(r, viewport->width(), viewport->height())) { 927 return false; 928 } 929 930 switch (viewportUpdateMode) { 931 case QGraphicsView::FullViewportUpdate: 932 fullUpdatePending = true; 933 viewport->update(); 934 break; 935 case QGraphicsView::BoundingRectViewportUpdate: 936 QRect_unite(&dirtyBoundingRect, r); 937 if (containsViewport(dirtyBoundingRect, viewport->width(), viewport->height())) { 938 fullUpdatePending = true; 939 viewport->update(); 940 } 941 break; 942 case QGraphicsView::SmartViewportUpdate: // ### DEPRECATE 943 case QGraphicsView::MinimalViewportUpdate: 944 if (optimizationFlags & QGraphicsView::DontAdjustForAntialiasing) 945 dirtyRegion += r.adjusted(-1, -1, 1, 1); 994 if (hasUpdateClip) 995 dirtyRegion += r & updateClip; 946 996 else 947 dirtyRegion += r .adjusted(-2, -2, 2, 2);997 dirtyRegion += r; 948 998 break; 949 999 default: … … 1036 1086 { 1037 1087 Q_Q(QGraphicsView); 1038 bool enabled = scene && scene->focusItem() 1039 && (scene->focusItem()->flags() & QGraphicsItem::ItemAcceptsInputMethod); 1088 QGraphicsItem *focusItem = 0; 1089 bool enabled = scene && (focusItem = scene->focusItem()) 1090 && (focusItem->d_ptr->flags & QGraphicsItem::ItemAcceptsInputMethod); 1040 1091 q->setAttribute(Qt::WA_InputMethodEnabled, enabled); 1041 1092 q->viewport()->setAttribute(Qt::WA_InputMethodEnabled, enabled); 1093 1094 if (!enabled) { 1095 q->setInputMethodHints(0); 1096 return; 1097 } 1098 1099 QGraphicsProxyWidget *proxy = focusItem->d_ptr->isWidget && focusItem->d_ptr->isProxyWidget() 1100 ? static_cast<QGraphicsProxyWidget *>(focusItem) : 0; 1101 if (!proxy) { 1102 q->setInputMethodHints(focusItem->inputMethodHints()); 1103 } else if (QWidget *widget = proxy->widget()) { 1104 if (QWidget *fw = widget->focusWidget()) 1105 widget = fw; 1106 q->setInputMethodHints(widget->inputMethodHints()); 1107 } else { 1108 q->setInputMethodHints(0); 1109 } 1042 1110 } 1043 1111 … … 1808 1876 { 1809 1877 Q_D(QGraphicsView); 1810 Q_UNUSED(xmargin);1811 Q_UNUSED(ymargin);1812 1878 qreal width = viewport()->width(); 1813 1879 qreal height = viewport()->height(); … … 2429 2495 QVariant value = d->scene->inputMethodQuery(query); 2430 2496 if (value.type() == QVariant::RectF) 2431 value = mapFromScene(value.toRectF()).boundingRect();2497 value = d->mapRectFromScene(value.toRectF()); 2432 2498 else if (value.type() == QVariant::PointF) 2433 2499 value = mapFromScene(value.toPointF()); … … 2531 2597 // Convert scene rects to viewport rects. 2532 2598 foreach (const QRectF &rect, rects) { 2533 QRect xrect = transform.mapRect(rect).to Rect();2599 QRect xrect = transform.mapRect(rect).toAlignedRect(); 2534 2600 if (!(d->optimizationFlags & DontAdjustForAntialiasing)) 2535 2601 xrect.adjust(-2, -2, 2, 2); 2602 else 2603 xrect.adjust(-1, -1, 1, 1); 2536 2604 if (!viewportRect.intersects(xrect)) 2537 2605 continue; … … 2622 2690 if (d->scene && !d->scene->d_func()->allItemsIgnoreTouchEvents) 2623 2691 widget->setAttribute(Qt::WA_AcceptTouchEvents); 2692 2693 #ifndef QT_NO_GESTURES 2694 if (d->scene) { 2695 foreach (Qt::GestureType gesture, d->scene->d_func()->grabbedGestures.keys()) 2696 widget->grabGesture(gesture); 2697 } 2698 #endif 2624 2699 2625 2700 widget->setAcceptDrops(acceptDrops()); … … 2768 2843 return true; 2769 2844 } 2845 #ifndef QT_NO_GESTURES 2770 2846 case QEvent::Gesture: 2771 2847 case QEvent::GestureOverride: … … 2781 2857 return true; 2782 2858 } 2859 #endif // QT_NO_GESTURES 2783 2860 default: 2784 2861 break; … … 3384 3461 // Items 3385 3462 if (!(d->optimizationFlags & IndirectPainting)) { 3463 const quint32 oldRectAdjust = d->scene->d_func()->rectAdjust; 3464 if (d->optimizationFlags & QGraphicsView::DontAdjustForAntialiasing) 3465 d->scene->d_func()->rectAdjust = 1; 3466 else 3467 d->scene->d_func()->rectAdjust = 2; 3386 3468 d->scene->d_func()->drawItems(&painter, viewTransformed ? &viewTransform : 0, 3387 3469 &d->exposedRegion, viewport()); 3470 d->scene->d_func()->rectAdjust = oldRectAdjust; 3388 3471 // Make sure the painter's world transform is restored correctly when 3389 3472 // drawing without painter state protection (DontSavePainterState). … … 3393 3476 // and restore() in QGraphicsScene::drawItems(). 3394 3477 if (!d->scene->d_func()->painterStateProtection) 3395 painter.setWorldTransform(viewTransform); 3478 painter.setOpacity(1.0); 3479 painter.setWorldTransform(viewTransform); 3396 3480 } else { 3397 3481 // Make sure we don't have unpolished items before we draw
Note:
See TracChangeset
for help on using the changeset viewer.