Make QGraphicsViewPrivate::updateRubberBand more readable
This patch changes QGraphicsViewPrivate::updateRubberBand to return at once in case some of the first conditions (which were needed to do something with the rubberband) are not true. The indentation after these ifs is fixed, and there are a few style fixes, but beside the first 2 ifs, there are only white-space and new-line changes. Change-Id: I7e2edb7bfd334b35ee8ab246f733d854bff7e0f7 Reviewed-by: Andreas Aardal Hanssen <andreas@hanssen.name> Reviewed-by: Andy Shaw <andy.shaw@digia.com>bb10
parent
8d2679673e
commit
686dcce5fb
|
|
@ -709,52 +709,47 @@ QRegion QGraphicsViewPrivate::rubberBandRegion(const QWidget *widget, const QRec
|
|||
void QGraphicsViewPrivate::updateRubberBand(const QMouseEvent *event)
|
||||
{
|
||||
Q_Q(QGraphicsView);
|
||||
if (dragMode == QGraphicsView::RubberBandDrag && sceneInteractionAllowed) {
|
||||
if (rubberBanding) {
|
||||
// Check for enough drag distance
|
||||
if ((mousePressViewPoint - event->pos()).manhattanLength()
|
||||
< QApplication::startDragDistance()) {
|
||||
return;
|
||||
}
|
||||
if (dragMode != QGraphicsView::RubberBandDrag || !sceneInteractionAllowed || !rubberBanding)
|
||||
return;
|
||||
// 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());
|
||||
}
|
||||
// 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
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue