]> git.lyx.org Git - features.git/commitdiff
#12434 add event handler for pinch-to-zoom gesture
authorStephan Witt <switt@lyx.org>
Mon, 3 Jan 2022 06:37:03 +0000 (07:37 +0100)
committerStephan Witt <switt@lyx.org>
Mon, 3 Jan 2022 06:37:03 +0000 (07:37 +0100)
src/frontends/qt/GuiView.cpp

index ffcbc3d3ac8b4af44847de91bdaa8fa7d6229023..791a2c2b42a52bc34d29c82eb02425608deb904f 100644 (file)
 #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);
        }