From f16d26b65936b1e0724212fee0ac368b511b34a2 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Sun, 29 Oct 2017 13:46:58 +0200 Subject: [PATCH] Improve EnsureVisibleWithDelay feature. Margins should to be scaled according to scene scale factor. --HG-- branch : develop --- .../tools/drawTools/toolcurve/vtoolspline.cpp | 4 +++- .../drawTools/toolcurve/vtoolsplinepath.cpp | 4 +++- .../toolpoint/toolsinglepoint/vtoolbasepoint.cpp | 8 +++++--- src/libs/vtools/tools/vtoolseamallowance.cpp | 8 +++++--- src/libs/vwidgets/vcontrolpointspline.cpp | 11 +++++++---- src/libs/vwidgets/vgraphicssimpletextitem.cpp | 16 ++++++---------- 6 files changed, 29 insertions(+), 22 deletions(-) diff --git a/src/libs/vtools/tools/drawTools/toolcurve/vtoolspline.cpp b/src/libs/vtools/tools/drawTools/toolcurve/vtoolspline.cpp index a7b8759b9..809a130c8 100644 --- a/src/libs/vtools/tools/drawTools/toolcurve/vtoolspline.cpp +++ b/src/libs/vtools/tools/drawTools/toolcurve/vtoolspline.cpp @@ -478,7 +478,9 @@ void VToolSpline::mouseMoveEvent(QGraphicsSceneMouseEvent *event) VMainGraphicsScene *currentScene = qobject_cast(scene()); SCASSERT(currentScene) const QPointF cursorPosition = currentScene->getScenePos(); - view->EnsureVisibleWithDelay(QRectF(cursorPosition.x()-5, cursorPosition.y()-5, 10, 10), + const qreal scale = SceneScale(scene()); + view->EnsureVisibleWithDelay(QRectF(cursorPosition.x()-5/scale, cursorPosition.y()-5/scale, 10/scale, + 10/scale), VMainGraphicsView::scrollDelay); } } diff --git a/src/libs/vtools/tools/drawTools/toolcurve/vtoolsplinepath.cpp b/src/libs/vtools/tools/drawTools/toolcurve/vtoolsplinepath.cpp index a43836bf1..105e15b43 100644 --- a/src/libs/vtools/tools/drawTools/toolcurve/vtoolsplinepath.cpp +++ b/src/libs/vtools/tools/drawTools/toolcurve/vtoolsplinepath.cpp @@ -638,7 +638,9 @@ void VToolSplinePath::mouseMoveEvent(QGraphicsSceneMouseEvent *event) VMainGraphicsScene *currentScene = qobject_cast(scene()); SCASSERT(currentScene) const QPointF cursorPosition = currentScene->getScenePos(); - view->EnsureVisibleWithDelay(QRectF(cursorPosition.x()-5, cursorPosition.y()-5, 10, 10), + const qreal scale = SceneScale(scene()); + view->EnsureVisibleWithDelay(QRectF(cursorPosition.x()-5/scale, cursorPosition.y()-5/scale, 10/scale, + 10/scale), VMainGraphicsView::scrollDelay); } } diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolbasepoint.cpp b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolbasepoint.cpp index c603c019a..7cad4e6d3 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolbasepoint.cpp +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolbasepoint.cpp @@ -195,8 +195,9 @@ QVariant VToolBasePoint::itemChange(QGraphicsItem::GraphicsItemChange change, co { if (VMainGraphicsView *view = qobject_cast(viewList.at(0))) { - const int xmargin = 50; - const int ymargin = 50; + const qreal scale = SceneScale(scene()); + const int xmargin = qCeil(50/scale); + const int ymargin = qCeil(50/scale); const QRectF viewRect = VMainGraphicsView::SceneVisibleArea(view); const QRectF itemRect = mapToScene(boundingRect()).boundingRect(); @@ -213,7 +214,8 @@ QVariant VToolBasePoint::itemChange(QGraphicsItem::GraphicsItemChange change, co VMainGraphicsScene *currentScene = qobject_cast(scene()); SCASSERT(currentScene) const QPointF cursorPosition = currentScene->getScenePos(); - view->EnsureVisibleWithDelay(QRectF(cursorPosition.x()-5, cursorPosition.y()-5, 10, 10), + view->EnsureVisibleWithDelay(QRectF(cursorPosition.x()-5/scale, cursorPosition.y()-5/scale, + 10/scale, 10/scale), VMainGraphicsView::scrollDelay); } } diff --git a/src/libs/vtools/tools/vtoolseamallowance.cpp b/src/libs/vtools/tools/vtoolseamallowance.cpp index a03d5e46e..69d98e104 100644 --- a/src/libs/vtools/tools/vtoolseamallowance.cpp +++ b/src/libs/vtools/tools/vtoolseamallowance.cpp @@ -1030,8 +1030,9 @@ QVariant VToolSeamAllowance::itemChange(QGraphicsItem::GraphicsItemChange change { if (VMainGraphicsView *view = qobject_cast(viewList.at(0))) { - const int xmargin = 50; - const int ymargin = 50; + const qreal scale = SceneScale(scene()); + const int xmargin = qCeil(50/scale); + const int ymargin = qCeil(50/scale); const QRectF viewRect = VMainGraphicsView::SceneVisibleArea(view); const QRectF itemRect = mapToScene(boundingRect()|childrenBoundingRect()).boundingRect(); @@ -1048,7 +1049,8 @@ QVariant VToolSeamAllowance::itemChange(QGraphicsItem::GraphicsItemChange change VMainGraphicsScene *currentScene = qobject_cast(scene()); SCASSERT(currentScene); const QPointF cursorPosition = currentScene->getScenePos(); - view->EnsureVisibleWithDelay(QRectF(cursorPosition.x()-5, cursorPosition.y()-5, 10, 10), + view->EnsureVisibleWithDelay(QRectF(cursorPosition.x()-5/scale, cursorPosition.y()-5/scale, + 10/scale, 10/scale), VMainGraphicsView::scrollDelay); } } diff --git a/src/libs/vwidgets/vcontrolpointspline.cpp b/src/libs/vwidgets/vcontrolpointspline.cpp index 5cdf4750c..4dd26596f 100644 --- a/src/libs/vwidgets/vcontrolpointspline.cpp +++ b/src/libs/vwidgets/vcontrolpointspline.cpp @@ -178,11 +178,12 @@ QVariant VControlPointSpline::itemChange(QGraphicsItem::GraphicsItemChange chang { if (VMainGraphicsView *view = qobject_cast(viewList.at(0))) { - const int xmargin = 50; - const int ymargin = 50; + const qreal scale = SceneScale(scene()); + const int xmargin = qCeil(50/scale); + const int ymargin = qCeil(50/scale); const QRectF viewRect = VMainGraphicsView::SceneVisibleArea(view); - const QRectF itemRect = mapToScene(boundingRect()).boundingRect(); + const QRectF itemRect = sceneBoundingRect(); // If item's rect is bigger than view's rect ensureVisible works very unstable. if (itemRect.height() + 2*ymargin < viewRect.height() && @@ -196,8 +197,10 @@ QVariant VControlPointSpline::itemChange(QGraphicsItem::GraphicsItemChange chang // Ensure visible only small rect around a cursor VMainGraphicsScene *currentScene = qobject_cast(scene()); SCASSERT(currentScene) + const QPointF cursorPosition = currentScene->getScenePos(); - view->EnsureVisibleWithDelay(QRectF(cursorPosition.x()-5, cursorPosition.y()-5, 10, 10), + view->EnsureVisibleWithDelay(QRectF(cursorPosition.x()-5/scale, + cursorPosition.y()-5/scale, 10/scale, 10/scale), VMainGraphicsView::scrollDelay); } } diff --git a/src/libs/vwidgets/vgraphicssimpletextitem.cpp b/src/libs/vwidgets/vgraphicssimpletextitem.cpp index b85a71aa6..ee7e91335 100644 --- a/src/libs/vwidgets/vgraphicssimpletextitem.cpp +++ b/src/libs/vwidgets/vgraphicssimpletextitem.cpp @@ -47,6 +47,7 @@ #include "vmaingraphicsview.h" #include "global.h" #include "vscenepoint.h" +#include "../vmisc/vmath.h" //--------------------------------------------------------------------------------------------------------------------- /** @@ -161,15 +162,9 @@ QVariant VGraphicsSimpleTextItem::itemChange(GraphicsItemChange change, const QV { if (VMainGraphicsView *view = qobject_cast(viewList.at(0))) { - int xmargin = 50; - int ymargin = 50; - - const int scale = qRound(SceneScale(scene())); - if (scale > 1) - { - xmargin /= scale; - ymargin /= scale; - } + const qreal scale = SceneScale(scene()); + int xmargin = qCeil(50/scale); + int ymargin = qCeil(50/scale); const QRectF viewRect = VMainGraphicsView::SceneVisibleArea(view); const QRectF itemRect = mapToScene(boundingRect()).boundingRect(); @@ -187,7 +182,8 @@ QVariant VGraphicsSimpleTextItem::itemChange(GraphicsItemChange change, const QV SCASSERT(currentScene) const QPointF cursorPosition = currentScene->getScenePos(); - view->EnsureVisibleWithDelay(QRectF(cursorPosition.x()-5, cursorPosition.y()-5, 10, 10), + view->EnsureVisibleWithDelay(QRectF(cursorPosition.x()-5/scale, cursorPosition.y()-5/scale, + 10/scale, 10/scale), VMainGraphicsView::scrollDelay); } }