Support for pinch gesture (zooming) on touchpad. ref #831.

--HG--
branch : develop
This commit is contained in:
Roman Telezhynskyi 2018-04-16 11:14:17 +03:00
parent 702c256c87
commit 50c858ce30
2 changed files with 33 additions and 0 deletions

View File

@ -47,6 +47,7 @@
#include <QWidget>
#include <QDesktopWidget>
#include <QThread>
#include <QGestureEvent>
#if QT_VERSION >= QT_VERSION_CHECK(5, 4, 0)
# include <QOpenGLWidget>
@ -80,6 +81,7 @@ GraphicsViewZoom::GraphicsViewZoom(QGraphicsView* view)
_numScheduledHorizontalScrollings(0)
{
_view->viewport()->installEventFilter(this);
_view->viewport()->grabGesture(Qt::PinchGesture);
_view->setMouseTracking(true);
verticalScrollAnim->setUpdateInterval(updateInterval);
@ -249,6 +251,10 @@ bool GraphicsViewZoom::eventFilter(QObject *object, QEvent *event)
}
}
}
else if (event->type() == QEvent::Gesture)
{
return GestureEvent(static_cast<QGestureEvent*>(event));
}
return QObject::eventFilter(object, event);
}
@ -353,6 +359,28 @@ bool GraphicsViewZoom::StartHorizontalScrollings(QWheelEvent *wheel_event)
return true;
}
//---------------------------------------------------------------------------------------------------------------------
bool GraphicsViewZoom::GestureEvent(QGestureEvent *event)
{
if (QGesture *pinch = event->gesture(Qt::PinchGesture))
{
PinchTriggered(static_cast<QPinchGesture *>(pinch));
return true;
}
return false;
}
//---------------------------------------------------------------------------------------------------------------------
void GraphicsViewZoom::PinchTriggered(QPinchGesture *gesture)
{
QPinchGesture::ChangeFlags changeFlags = gesture->changeFlags();
if (changeFlags & QPinchGesture::ScaleFactorChanged)
{
qreal currentStepScaleFactor = gesture->lastScaleFactor();
gentle_zoom(currentStepScaleFactor);
}
}
const unsigned long VMainGraphicsView::scrollDelay = 80;
//---------------------------------------------------------------------------------------------------------------------

View File

@ -66,6 +66,8 @@
*/
class QTimeLine;
class QGestureEvent;
class QPinchGesture;
class GraphicsViewZoom : public QObject
{
@ -104,6 +106,9 @@ private:
bool StartVerticalScrollings(QWheelEvent* wheel_event);
bool StartHorizontalScrollings(QWheelEvent* wheel_event);
bool GestureEvent(QGestureEvent *event);
void PinchTriggered(QPinchGesture* gesture);
};
/**