mirror of
https://github.com/f4exb/sdrangel.git
synced 2024-11-25 17:28:50 -05:00
Add pinch gesture to GraphicsViewZoom
This commit is contained in:
parent
7e7a9fdb84
commit
038cb3b973
@ -18,6 +18,9 @@
|
|||||||
#include <QMouseEvent>
|
#include <QMouseEvent>
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
#include <QScrollBar>
|
#include <QScrollBar>
|
||||||
|
#include <QGestureEvent>
|
||||||
|
#include <QPinchGesture>
|
||||||
|
|
||||||
#include <qmath.h>
|
#include <qmath.h>
|
||||||
|
|
||||||
#include "graphicsviewzoom.h"
|
#include "graphicsviewzoom.h"
|
||||||
@ -30,6 +33,7 @@ GraphicsViewZoom::GraphicsViewZoom(QGraphicsView* view) :
|
|||||||
{
|
{
|
||||||
m_view->viewport()->installEventFilter(this);
|
m_view->viewport()->installEventFilter(this);
|
||||||
m_view->setMouseTracking(true);
|
m_view->setMouseTracking(true);
|
||||||
|
m_view->viewport()->grabGesture(Qt::PinchGesture);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GraphicsViewZoom::gentleZoom(double factor)
|
void GraphicsViewZoom::gentleZoom(double factor)
|
||||||
@ -79,6 +83,19 @@ bool GraphicsViewZoom::eventFilter(QObject *object, QEvent *event)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if (event->type() == QEvent::Gesture)
|
||||||
|
{
|
||||||
|
QGestureEvent *gestureEvent = static_cast<QGestureEvent *>(event);
|
||||||
|
if (QPinchGesture *pinchGesture = static_cast<QPinchGesture *>(gestureEvent->gesture(Qt::PinchGesture)))
|
||||||
|
{
|
||||||
|
if (pinchGesture->changeFlags() & QPinchGesture::ScaleFactorChanged)
|
||||||
|
{
|
||||||
|
m_view->scale(pinchGesture->scaleFactor(), pinchGesture->scaleFactor());
|
||||||
|
emit zoomed();
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Q_UNUSED(object)
|
Q_UNUSED(object)
|
||||||
return false;
|
return false;
|
||||||
|
@ -23,7 +23,7 @@
|
|||||||
|
|
||||||
#include "export.h"
|
#include "export.h"
|
||||||
|
|
||||||
// GraphicsView that allows scroll wheel to be used for zoom
|
// GraphicsView that allows scroll wheel and pinch gesture to be used for zoom
|
||||||
// https://stackoverflow.com/questions/19113532/qgraphicsview-zooming-in-and-out-under-mouse-position-using-mouse-wheel
|
// https://stackoverflow.com/questions/19113532/qgraphicsview-zooming-in-and-out-under-mouse-position-using-mouse-wheel
|
||||||
class SDRGUI_API GraphicsViewZoom : public QObject {
|
class SDRGUI_API GraphicsViewZoom : public QObject {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
@ -39,7 +39,7 @@ private:
|
|||||||
Qt::KeyboardModifiers m_modifiers;
|
Qt::KeyboardModifiers m_modifiers;
|
||||||
double m_zoomFactorBase;
|
double m_zoomFactorBase;
|
||||||
QPointF m_targetScenePos, m_targetViewportPos;
|
QPointF m_targetScenePos, m_targetViewportPos;
|
||||||
bool eventFilter(QObject* object, QEvent* event);
|
bool eventFilter(QObject* object, QEvent* event) override;
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void zoomed();
|
void zoomed();
|
||||||
|
Loading…
Reference in New Issue
Block a user