From c57f60ffa9bf6ff77dfb3449a40420e15458f5ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thorbj=C3=B8rn=20Lund=20Martsum?= Date: Mon, 3 Dec 2012 21:37:16 +0100 Subject: QGraphicsView - move rubberband-handling into a private function This patch moves the rubberband-handling from QGraphicsView::mouseMoveEvent to QGraphicsViewPrivate::updateRubberBand. This function is then called from QGraphicsView::mouseMoveEvent. I have removed some d-> and added some q-> but beside that nothing is changed in the code. Change-Id: Iab70c55635c43733e0e02bb70e2bb03b90bf62f0 Reviewed-by: Andy Shaw Reviewed-by: Marc Mutz --- src/widgets/graphicsview/qgraphicsview.cpp | 102 +++++++++++++++-------------- src/widgets/graphicsview/qgraphicsview_p.h | 1 + 2 files changed, 55 insertions(+), 48 deletions(-) (limited to 'src/widgets') diff --git a/src/widgets/graphicsview/qgraphicsview.cpp b/src/widgets/graphicsview/qgraphicsview.cpp index 2147e2ac2b..3da202c986 100644 --- a/src/widgets/graphicsview/qgraphicsview.cpp +++ b/src/widgets/graphicsview/qgraphicsview.cpp @@ -701,6 +701,58 @@ QRegion QGraphicsViewPrivate::rubberBandRegion(const QWidget *widget, const QRec tmp &= mask.region; return tmp; } + +void QGraphicsViewPrivate::updateRubberBand(QMouseEvent *event) +{ + Q_Q(QGraphicsView); + if (dragMode == QGraphicsView::RubberBandDrag && sceneInteractionAllowed) { + storeMouseEvent(event); + if (rubberBanding) { + // Check for enough drag distance + if ((mousePressViewPoint - event->pos()).manhattanLength() + < QApplication::startDragDistance()) { + return; + } + + // Update old rubberband + if (viewportUpdateMode != QGraphicsView::NoViewportUpdate && !rubberBandRect.isEmpty()) { + if (viewportUpdateMode != QGraphicsView::FullViewportUpdate) + q->viewport()->update(rubberBandRegion(q->viewport(), rubberBandRect)); + else + updateAll(); + } + + // Stop rubber banding if the user has let go of all buttons (even + // if we didn't get the release events). + if (!event->buttons()) { + rubberBanding = false; + rubberBandRect = QRect(); + return; + } + + // Update rubberband position + const QPoint mp = q->mapFromScene(mousePressScenePoint); + const QPoint ep = event->pos(); + rubberBandRect = QRect(qMin(mp.x(), ep.x()), qMin(mp.y(), ep.y()), + qAbs(mp.x() - ep.x()) + 1, qAbs(mp.y() - ep.y()) + 1); + + // Update new rubberband + if (viewportUpdateMode != QGraphicsView::NoViewportUpdate){ + if (viewportUpdateMode != QGraphicsView::FullViewportUpdate) + q->viewport()->update(rubberBandRegion(q->viewport(), rubberBandRect)); + else + updateAll(); + } + // Set the new selection area + QPainterPath selectionArea; + selectionArea.addPolygon(mapToScene(rubberBandRect)); + selectionArea.closeSubpath(); + if (scene) + scene->setSelectionArea(selectionArea, rubberBandSelectionMode, + q->viewportTransform()); + } + } +} #endif /*! @@ -3212,55 +3264,9 @@ void QGraphicsView::mouseMoveEvent(QMouseEvent *event) Q_D(QGraphicsView); #ifndef QT_NO_RUBBERBAND - if (d->dragMode == QGraphicsView::RubberBandDrag && d->sceneInteractionAllowed) { - d->storeMouseEvent(event); - if (d->rubberBanding) { - // Check for enough drag distance - if ((d->mousePressViewPoint - event->pos()).manhattanLength() - < QApplication::startDragDistance()) { - return; - } - - // Update old rubberband - if (d->viewportUpdateMode != QGraphicsView::NoViewportUpdate && !d->rubberBandRect.isEmpty()) { - if (d->viewportUpdateMode != FullViewportUpdate) - viewport()->update(d->rubberBandRegion(viewport(), d->rubberBandRect)); - else - d->updateAll(); - } - - // Stop rubber banding if the user has let go of all buttons (even - // if we didn't get the release events). - if (!event->buttons()) { - d->rubberBanding = false; - d->rubberBandRect = QRect(); - return; - } - - // Update rubberband position - const QPoint mp = mapFromScene(d->mousePressScenePoint); - const QPoint ep = event->pos(); - d->rubberBandRect = QRect(qMin(mp.x(), ep.x()), qMin(mp.y(), ep.y()), - qAbs(mp.x() - ep.x()) + 1, qAbs(mp.y() - ep.y()) + 1); + d->updateRubberBand(event); +#endif - // Update new rubberband - if (d->viewportUpdateMode != QGraphicsView::NoViewportUpdate){ - if (d->viewportUpdateMode != FullViewportUpdate) - viewport()->update(d->rubberBandRegion(viewport(), d->rubberBandRect)); - else - d->updateAll(); - } - // Set the new selection area - QPainterPath selectionArea; - selectionArea.addPolygon(mapToScene(d->rubberBandRect)); - selectionArea.closeSubpath(); - if (d->scene) - d->scene->setSelectionArea(selectionArea, d->rubberBandSelectionMode, - viewportTransform()); - return; - } - } else -#endif // QT_NO_RUBBERBAND if (d->dragMode == QGraphicsView::ScrollHandDrag) { if (d->handScrolling) { QScrollBar *hBar = horizontalScrollBar(); diff --git a/src/widgets/graphicsview/qgraphicsview_p.h b/src/widgets/graphicsview/qgraphicsview_p.h index 6b15fb61f2..bb6b44af19 100644 --- a/src/widgets/graphicsview/qgraphicsview_p.h +++ b/src/widgets/graphicsview/qgraphicsview_p.h @@ -138,6 +138,7 @@ public: #ifndef QT_NO_RUBBERBAND QRect rubberBandRect; QRegion rubberBandRegion(const QWidget *widget, const QRect &rect) const; + void updateRubberBand(QMouseEvent *event); bool rubberBanding; Qt::ItemSelectionMode rubberBandSelectionMode; #endif -- cgit v1.2.3