Refactoring. Smooth scrolling.
--HG-- branch : develop
This commit is contained in:
parent
6ba9bb8b28
commit
3beb8a8b7c
|
@ -90,29 +90,19 @@ void GraphicsViewZoom::set_zoom_factor_base(double value)
|
|||
void GraphicsViewZoom::scrollingTime(qreal x)
|
||||
{
|
||||
Q_UNUSED(x);
|
||||
qreal factor = 1.0;
|
||||
if (_numScheduledScalings < 0)
|
||||
|
||||
qreal scroll = _view->verticalScrollBar()->pageStep()/60;
|
||||
if (_numScheduledScalings > 0)
|
||||
{
|
||||
factor = factor*13.8;
|
||||
scroll = scroll * -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
factor = factor*-13.8;
|
||||
}
|
||||
_view->verticalScrollBar()->setValue(qRound(_view->verticalScrollBar()->value() + factor));
|
||||
_view->verticalScrollBar()->setValue(qRound(_view->verticalScrollBar()->value() + scroll));
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void GraphicsViewZoom::animFinished()
|
||||
{
|
||||
if (_numScheduledScalings > 0)
|
||||
{
|
||||
_numScheduledScalings--;
|
||||
}
|
||||
else
|
||||
{
|
||||
_numScheduledScalings++;
|
||||
}
|
||||
_numScheduledScalings > 0 ? _numScheduledScalings-- : _numScheduledScalings++;
|
||||
anim->stop();
|
||||
|
||||
/*
|
||||
|
@ -147,6 +137,7 @@ bool GraphicsViewZoom::eventFilter(QObject *object, QEvent *event)
|
|||
target_viewport_pos = mouse_event->pos();
|
||||
target_scene_pos = _view->mapToScene(mouse_event->pos());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
else if (event->type() == QEvent::Wheel)
|
||||
{
|
||||
|
@ -163,7 +154,22 @@ bool GraphicsViewZoom::eventFilter(QObject *object, QEvent *event)
|
|||
}
|
||||
else
|
||||
{
|
||||
int numSteps = wheel_event->delta() / 8 / 15; // see QWheelEvent documentation
|
||||
const QPoint numPixels = wheel_event->pixelDelta();
|
||||
const QPoint numDegrees = wheel_event->angleDelta() / 8;
|
||||
int numSteps;
|
||||
|
||||
if (not numPixels.isNull())
|
||||
{
|
||||
numSteps = numPixels.y();
|
||||
}
|
||||
else if (not numDegrees.isNull())
|
||||
{
|
||||
numSteps = numDegrees.y() / 15;
|
||||
}
|
||||
else
|
||||
{
|
||||
return true;//Just ignore
|
||||
}
|
||||
|
||||
_numScheduledScalings += numSteps;
|
||||
if (_numScheduledScalings * numSteps < 0)
|
||||
|
@ -178,8 +184,8 @@ bool GraphicsViewZoom::eventFilter(QObject *object, QEvent *event)
|
|||
return true;
|
||||
}
|
||||
}
|
||||
Q_UNUSED(object)
|
||||
return false;
|
||||
|
||||
return QObject::eventFilter(object, event);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
|
|
|
@ -73,6 +73,8 @@ signals:
|
|||
public slots:
|
||||
void scrollingTime(qreal x);
|
||||
void animFinished();
|
||||
protected:
|
||||
virtual bool eventFilter(QObject* object, QEvent* event) Q_DECL_OVERRIDE;
|
||||
private:
|
||||
Q_DISABLE_COPY(GraphicsViewZoom)
|
||||
QGraphicsView* _view;
|
||||
|
@ -84,7 +86,6 @@ private:
|
|||
/** @brief _numScheduledScalings keep number scheduled scalings. */
|
||||
qint32 _numScheduledScalings;
|
||||
|
||||
virtual bool eventFilter(QObject* object, QEvent* event) Q_DECL_OVERRIDE;
|
||||
void FictiveSceneRect(QGraphicsScene *sc, QGraphicsView *view);
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user