diff options
Diffstat (limited to 'src/widgets/graphicsview')
-rw-r--r-- | src/widgets/graphicsview/qgraphicsitem.cpp | 31 | ||||
-rw-r--r-- | src/widgets/graphicsview/qgraphicsview.cpp | 106 | ||||
-rw-r--r-- | src/widgets/graphicsview/qgraphicsview_p.h | 1 |
3 files changed, 67 insertions, 71 deletions
diff --git a/src/widgets/graphicsview/qgraphicsitem.cpp b/src/widgets/graphicsview/qgraphicsitem.cpp index 48430e60db..f76e89f1a0 100644 --- a/src/widgets/graphicsview/qgraphicsitem.cpp +++ b/src/widgets/graphicsview/qgraphicsitem.cpp @@ -1436,6 +1436,7 @@ QGraphicsItem::~QGraphicsItem() #endif clearFocus(); + setFocusProxy(0); // Update focus scope item ptr. QGraphicsItem *p = d_ptr->parent; @@ -1771,24 +1772,6 @@ void QGraphicsItem::setFlag(GraphicsItemFlag flag, bool enabled) } /*! - \internal - - Sets the flag \a flag on \a item and all its children, to \a enabled. -*/ -static void _q_qgraphicsItemSetFlag(QGraphicsItem *item, QGraphicsItem::GraphicsItemFlag flag, - bool enabled) -{ - if (item->flags() & flag) { - // If this item already has the correct flag set, we don't have to - // propagate it. - return; - } - item->setFlag(flag, enabled); - foreach (QGraphicsItem *child, item->childItems()) - _q_qgraphicsItemSetFlag(child, flag, enabled); -} - -/*! Sets the item flags to \a flags. All flags in \a flags are enabled; all flags not in \a flags are disabled. @@ -3348,6 +3331,12 @@ void QGraphicsItem::clearFocus() */ void QGraphicsItemPrivate::clearFocusHelper(bool giveFocusToParent, bool hiddenByParentPanel) { + QGraphicsItem *subFocusItem = q_ptr; + if (flags & QGraphicsItem::ItemIsFocusScope) { + while (subFocusItem->d_ptr->focusScopeItem) + subFocusItem = subFocusItem->d_ptr->focusScopeItem; + } + if (giveFocusToParent) { // Pass focus to the closest parent focus scope if (!inDestructor) { @@ -3356,10 +3345,10 @@ void QGraphicsItemPrivate::clearFocusHelper(bool giveFocusToParent, bool hiddenB if (p->flags() & QGraphicsItem::ItemIsFocusScope) { if (p->d_ptr->focusScopeItem == q_ptr) { p->d_ptr->focusScopeItem = 0; - if (!q_ptr->hasFocus()) //if it has focus, focusScopeItemChange is called elsewhere + if (!subFocusItem->hasFocus()) //if it has focus, focusScopeItemChange is called elsewhere focusScopeItemChange(false); } - if (q_ptr->hasFocus()) + if (subFocusItem->hasFocus()) p->d_ptr->setFocusHelper(Qt::OtherFocusReason, /* climb = */ false, /* focusFromHide = */ false); return; @@ -3369,7 +3358,7 @@ void QGraphicsItemPrivate::clearFocusHelper(bool giveFocusToParent, bool hiddenB } } - if (q_ptr->hasFocus()) { + if (subFocusItem->hasFocus()) { // Invisible items with focus must explicitly clear subfocus. if (!hiddenByParentPanel) clearSubFocus(q_ptr); diff --git a/src/widgets/graphicsview/qgraphicsview.cpp b/src/widgets/graphicsview/qgraphicsview.cpp index 2012f980db..a1ee562807 100644 --- a/src/widgets/graphicsview/qgraphicsview.cpp +++ b/src/widgets/graphicsview/qgraphicsview.cpp @@ -616,6 +616,10 @@ void QGraphicsViewPrivate::mouseMoveEventHandler(QMouseEvent *event) { Q_Q(QGraphicsView); +#ifndef QT_NO_RUBBERBAND + updateRubberBand(event); +#endif + storeMouseEvent(event); lastMouseEvent.setAccepted(false); @@ -701,6 +705,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 /*! @@ -3211,56 +3267,6 @@ 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); - 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); - - // 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 |