From 783e3d57c28f2264a040053b8f39a38ff90c768d Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Wed, 25 Nov 2015 19:26:37 +0200 Subject: [PATCH] Support QGraphicsView autoscroll of a draged object. --HG-- branch : develop --- .../toolpoint/toolsinglepoint/vtoolbasepoint.cpp | 7 +++++++ src/libs/vwidgets/vcontrolpointspline.cpp | 8 ++++++++ src/libs/vwidgets/vgraphicssimpletextitem.cpp | 8 ++++++++ src/libs/vwidgets/vmaingraphicsview.h | 4 ++-- 4 files changed, 25 insertions(+), 2 deletions(-) diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolbasepoint.cpp b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolbasepoint.cpp index 6446f41ce..8900e3b83 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolbasepoint.cpp +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolbasepoint.cpp @@ -153,6 +153,13 @@ QVariant VToolBasePoint::itemChange(QGraphicsItem::GraphicsItemChange change, co MoveSPoint *moveSP = new MoveSPoint(doc, newPos.x(), newPos.y(), id, this->scene()); connect(moveSP, &MoveSPoint::NeedLiteParsing, doc, &VAbstractPattern::LiteParseTree); qApp->getUndoStack()->push(moveSP); + if (scene()) + { + if (QGraphicsView *view = scene()->views().at(0)) + { + view->ensureVisible(this); + } + } changeFinished = true; } } diff --git a/src/libs/vwidgets/vcontrolpointspline.cpp b/src/libs/vwidgets/vcontrolpointspline.cpp index d4ac1c088..7ab55a10b 100644 --- a/src/libs/vwidgets/vcontrolpointspline.cpp +++ b/src/libs/vwidgets/vcontrolpointspline.cpp @@ -29,6 +29,7 @@ #include "vcontrolpointspline.h" #include +#include #include #include @@ -129,6 +130,13 @@ QVariant VControlPointSpline::itemChange(QGraphicsItem::GraphicsItemChange chang // value - new position. QPointF newPos = value.toPointF(); emit ControlPointChangePosition(indexSpline, position, newPos); + if (scene()) + { + if (QGraphicsView *view = scene()->views().at(0)) + { + view->ensureVisible(this); + } + } changeFinished = false; } } diff --git a/src/libs/vwidgets/vgraphicssimpletextitem.cpp b/src/libs/vwidgets/vgraphicssimpletextitem.cpp index 963197bc4..028cd3acf 100644 --- a/src/libs/vwidgets/vgraphicssimpletextitem.cpp +++ b/src/libs/vwidgets/vgraphicssimpletextitem.cpp @@ -34,6 +34,7 @@ #include #include #include +#include //--------------------------------------------------------------------------------------------------------------------- /** @@ -123,6 +124,13 @@ QVariant VGraphicsSimpleTextItem::itemChange(GraphicsItemChange change, const QV changeFinished = false; QPointF newPos = value.toPointF() + this->parentItem()->pos(); emit NameChangePosition(newPos); + if (scene()) + { + if (QGraphicsView *view = scene()->views().at(0)) + { + view->ensureVisible(this); + } + } changeFinished = true; } } diff --git a/src/libs/vwidgets/vmaingraphicsview.h b/src/libs/vwidgets/vmaingraphicsview.h index 755bbd909..4ad9462bd 100644 --- a/src/libs/vwidgets/vmaingraphicsview.h +++ b/src/libs/vwidgets/vmaingraphicsview.h @@ -125,8 +125,8 @@ public slots: void ZoomOriginal(); void ZoomFitBest(); protected: - void mousePressEvent(QMouseEvent *mousePress); - void mouseReleaseEvent(QMouseEvent *event); + virtual void mousePressEvent(QMouseEvent *mousePress) Q_DECL_OVERRIDE; + virtual void mouseReleaseEvent(QMouseEvent *event) Q_DECL_OVERRIDE; private: Q_DISABLE_COPY(VMainGraphicsView) GraphicsViewZoom* zoom;