Scrolling delay.

When object is close to edge of view Valentina begins scrolling scene to ensure
that the object is visible. In many cases this happens to fast for user. As
solution after correction Valentina will wait 80 milliseconds before procedding
next move. This will give users enough time to react. Such delay is called only
if view was scrolled.

--HG--
branch : develop
This commit is contained in:
Roman Telezhynskyi 2017-10-02 16:25:18 +03:00
parent da2cc857df
commit 08df3b4486
8 changed files with 69 additions and 18 deletions

View File

@ -425,12 +425,13 @@ void VToolSpline::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
const QList<QGraphicsView *> viewList = scene()->views();
if (not viewList.isEmpty())
{
if (QGraphicsView *view = viewList.at(0))
if (VMainGraphicsView *view = qobject_cast<VMainGraphicsView *>(viewList.at(0)))
{
VMainGraphicsScene *currentScene = qobject_cast<VMainGraphicsScene *>(scene());
SCASSERT(currentScene)
const QPointF cursorPosition = currentScene->getScenePos();
view->ensureVisible(QRectF(cursorPosition.x()-5, cursorPosition.y()-5, 10, 10));
view->EnsureVisibleWithDelay(QRectF(cursorPosition.x()-5, cursorPosition.y()-5, 10, 10),
VMainGraphicsView::scrollDelay);
}
}
changeFinished = true;

View File

@ -565,12 +565,13 @@ void VToolSplinePath::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
const QList<QGraphicsView *> viewList = scene()->views();
if (not viewList.isEmpty())
{
if (QGraphicsView *view = viewList.at(0))
if (VMainGraphicsView *view = qobject_cast<VMainGraphicsView *>(viewList.at(0)))
{
VMainGraphicsScene *currentScene = qobject_cast<VMainGraphicsScene *>(scene());
SCASSERT(currentScene)
const QPointF cursorPosition = currentScene->getScenePos();
view->ensureVisible(QRectF(cursorPosition.x()-5, cursorPosition.y()-5, 10, 10));
view->EnsureVisibleWithDelay(QRectF(cursorPosition.x()-5, cursorPosition.y()-5, 10, 10),
VMainGraphicsView::scrollDelay);
}
}
changeFinished = true;

View File

@ -193,7 +193,7 @@ QVariant VToolBasePoint::itemChange(QGraphicsItem::GraphicsItemChange change, co
const QList<QGraphicsView *> viewList = scene()->views();
if (not viewList.isEmpty())
{
if (QGraphicsView *view = viewList.at(0))
if (VMainGraphicsView *view = qobject_cast<VMainGraphicsView *>(viewList.at(0)))
{
const int xmargin = 50;
const int ymargin = 50;
@ -205,7 +205,7 @@ QVariant VToolBasePoint::itemChange(QGraphicsItem::GraphicsItemChange change, co
if (itemRect.height() + 2*ymargin < viewRect.height() &&
itemRect.width() + 2*xmargin < viewRect.width())
{
view->ensureVisible(itemRect, xmargin, ymargin);
view->EnsureVisibleWithDelay(itemRect, VMainGraphicsView::scrollDelay, xmargin, ymargin);
}
else
{
@ -213,7 +213,8 @@ QVariant VToolBasePoint::itemChange(QGraphicsItem::GraphicsItemChange change, co
VMainGraphicsScene *currentScene = qobject_cast<VMainGraphicsScene *>(scene());
SCASSERT(currentScene)
const QPointF cursorPosition = currentScene->getScenePos();
view->ensureVisible(QRectF(cursorPosition.x()-5, cursorPosition.y()-5, 10, 10));
view->EnsureVisibleWithDelay(QRectF(cursorPosition.x()-5, cursorPosition.y()-5, 10, 10),
VMainGraphicsView::scrollDelay);
}
}
}

View File

@ -914,7 +914,7 @@ QVariant VToolSeamAllowance::itemChange(QGraphicsItem::GraphicsItemChange change
const QList<QGraphicsView *> viewList = scene()->views();
if (not viewList.isEmpty())
{
if (QGraphicsView *view = viewList.at(0))
if (VMainGraphicsView *view = qobject_cast<VMainGraphicsView *>(viewList.at(0)))
{
const int xmargin = 50;
const int ymargin = 50;
@ -926,7 +926,7 @@ QVariant VToolSeamAllowance::itemChange(QGraphicsItem::GraphicsItemChange change
if (itemRect.height() + 2*ymargin < viewRect.height() &&
itemRect.width() + 2*xmargin < viewRect.width())
{
view->ensureVisible(itemRect, xmargin, ymargin);
view->EnsureVisibleWithDelay(itemRect, VMainGraphicsView::scrollDelay, xmargin, ymargin);
}
else
{
@ -934,7 +934,8 @@ QVariant VToolSeamAllowance::itemChange(QGraphicsItem::GraphicsItemChange change
VMainGraphicsScene *currentScene = qobject_cast<VMainGraphicsScene *>(scene());
SCASSERT(currentScene);
const QPointF cursorPosition = currentScene->getScenePos();
view->ensureVisible(QRectF(cursorPosition.x()-5, cursorPosition.y()-5, 10, 10));
view->EnsureVisibleWithDelay(QRectF(cursorPosition.x()-5, cursorPosition.y()-5, 10, 10),
VMainGraphicsView::scrollDelay);
}
}
}

View File

@ -176,7 +176,7 @@ QVariant VControlPointSpline::itemChange(QGraphicsItem::GraphicsItemChange chang
const QList<QGraphicsView *> viewList = scene()->views();
if (not viewList.isEmpty())
{
if (QGraphicsView *view = viewList.at(0))
if (VMainGraphicsView *view = qobject_cast<VMainGraphicsView *>(viewList.at(0)))
{
const int xmargin = 50;
const int ymargin = 50;
@ -188,7 +188,8 @@ QVariant VControlPointSpline::itemChange(QGraphicsItem::GraphicsItemChange chang
if (itemRect.height() + 2*ymargin < viewRect.height() &&
itemRect.width() + 2*xmargin < viewRect.width())
{
view->ensureVisible(itemRect, xmargin, ymargin);
view->EnsureVisibleWithDelay(itemRect, VMainGraphicsView::scrollDelay, xmargin,
ymargin);
}
else
{
@ -196,7 +197,8 @@ QVariant VControlPointSpline::itemChange(QGraphicsItem::GraphicsItemChange chang
VMainGraphicsScene *currentScene = qobject_cast<VMainGraphicsScene *>(scene());
SCASSERT(currentScene)
const QPointF cursorPosition = currentScene->getScenePos();
view->ensureVisible(QRectF(cursorPosition.x()-5, cursorPosition.y()-5, 10, 10));
view->EnsureVisibleWithDelay(QRectF(cursorPosition.x()-5, cursorPosition.y()-5, 10, 10),
VMainGraphicsView::scrollDelay);
}
}
}

View File

@ -138,10 +138,17 @@ QVariant VGraphicsSimpleTextItem::itemChange(GraphicsItemChange change, const QV
const QList<QGraphicsView *> viewList = scene()->views();
if (not viewList.isEmpty())
{
if (QGraphicsView *view = viewList.at(0))
if (VMainGraphicsView *view = qobject_cast<VMainGraphicsView *>(viewList.at(0)))
{
const int xmargin = 50;
const int ymargin = 50;
int xmargin = 50;
int ymargin = 50;
const int scale = qRound(SceneScale(scene()));
if (scale > 1)
{
xmargin /= scale;
ymargin /= scale;
}
const QRectF viewRect = VMainGraphicsView::SceneVisibleArea(view);
const QRectF itemRect = mapToScene(boundingRect()).boundingRect();
@ -150,7 +157,7 @@ QVariant VGraphicsSimpleTextItem::itemChange(GraphicsItemChange change, const QV
if (itemRect.height() + 2*ymargin < viewRect.height() &&
itemRect.width() + 2*xmargin < viewRect.width())
{
view->ensureVisible(itemRect, xmargin, ymargin);
view->EnsureVisibleWithDelay(itemRect, VMainGraphicsView::scrollDelay, xmargin, ymargin);
}
else
{
@ -158,7 +165,9 @@ QVariant VGraphicsSimpleTextItem::itemChange(GraphicsItemChange change, const QV
VMainGraphicsScene *currentScene = qobject_cast<VMainGraphicsScene *>(scene());
SCASSERT(currentScene)
const QPointF cursorPosition = currentScene->getScenePos();
view->ensureVisible(QRectF(cursorPosition.x()-5, cursorPosition.y()-5, 10, 10));
view->EnsureVisibleWithDelay(QRectF(cursorPosition.x()-5, cursorPosition.y()-5, 10, 10),
VMainGraphicsView::scrollDelay);
}
}
}

View File

@ -46,6 +46,7 @@
#include <QWheelEvent>
#include <QWidget>
#include <QDesktopWidget>
#include <QThread>
#include "../vmisc/def.h"
#include "../vmisc/vmath.h"
@ -339,6 +340,8 @@ bool GraphicsViewZoom::StartHorizontalScrollings(QWheelEvent *wheel_event)
return true;
}
const unsigned long VMainGraphicsView::scrollDelay = 80;
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief VMainGraphicsView constructor.
@ -529,6 +532,34 @@ qreal VMainGraphicsView::MaxScale()
return maxSceneSize / screenSize;
}
//---------------------------------------------------------------------------------------------------------------------
void VMainGraphicsView::EnsureVisibleWithDelay(const QRectF &rect, unsigned long msecs, int xmargin, int ymargin)
{
const int hbar = horizontalScrollBar()->value();
const int vbar = verticalScrollBar()->value();
ensureVisible(rect, xmargin, ymargin);
if (hbar != horizontalScrollBar()->value() || vbar != verticalScrollBar()->value())
{
QThread::msleep(msecs);
}
}
//---------------------------------------------------------------------------------------------------------------------
void VMainGraphicsView::EnsureVisibleWithDelay(const QGraphicsItem *item, unsigned long msecs, int xmargin, int ymargin)
{
const int hbar = horizontalScrollBar()->value();
const int vbar = verticalScrollBar()->value();
ensureVisible(item, xmargin, ymargin);
if (hbar != horizontalScrollBar()->value() || vbar != verticalScrollBar()->value())
{
QThread::msleep(msecs);
}
}
//---------------------------------------------------------------------------------------------------------------------
void VMainGraphicsView::setShowToolOptions(bool value)
{

View File

@ -124,6 +124,11 @@ public:
static qreal MinScale();
static qreal MaxScale();
void EnsureVisibleWithDelay(const QRectF &rect, unsigned long msecs, int xmargin = 50, int ymargin = 50);
void EnsureVisibleWithDelay(const QGraphicsItem *item, unsigned long msecs, int xmargin = 50, int ymargin = 50);
static const unsigned long scrollDelay;
signals:
/**
* @brief MouseRelease help catch mouse release event.