#12434 add event handler for pinch-to-zoom gesture

This commit is contained in:
Stephan Witt 2022-01-03 07:37:03 +01:00
parent d4cfa5204c
commit d432403430

View File

@ -110,6 +110,8 @@
#include <QTimer>
#include <QUrl>
#include <QWindowStateChangeEvent>
#include <QGestureEvent>
#include <QPinchGesture>
// sync with GuiAlert.cpp
@ -694,6 +696,9 @@ GuiView::GuiView(int id)
connect(statusBar(), SIGNAL(customContextMenuRequested(QPoint)),
this, SLOT(showZoomContextMenu()));
// enable pinch to zoom
grabGesture(Qt::PinchGesture);
int const iconheight = max(int(d.normalIconSize), fm.height());
QSize const iconsize(iconheight, iconheight);
@ -1621,6 +1626,21 @@ bool GuiView::event(QEvent * e)
return QMainWindow::event(e);
}
case QEvent::Gesture: {
QGestureEvent *ge = static_cast<QGestureEvent*>(e);
QGesture *gp = ge->gesture(Qt::PinchGesture);
if (gp) {
QPinchGesture *pinch = static_cast<QPinchGesture *>(gp);
QPinchGesture::ChangeFlags changeFlags = pinch->changeFlags();
if (changeFlags & QPinchGesture::ScaleFactorChanged) {
qreal factor = lyxrc.currentZoom*pinch->scaleFactor();
//factor = ceil(factor/20)*20;
zoomValueChanged(factor);
}
}
return QMainWindow::event(e);
}
default:
return QMainWindow::event(e);
}