diff --git a/src/widgets/CutterGraphView.cpp b/src/widgets/CutterGraphView.cpp index 6addab41..b885eb18 100644 --- a/src/widgets/CutterGraphView.cpp +++ b/src/widgets/CutterGraphView.cpp @@ -80,6 +80,8 @@ CutterGraphView::CutterGraphView(QWidget *parent) } layoutMenu->addActions(layoutGroup->actions()); + + grabGesture(Qt::PinchGesture); } QPoint CutterGraphView::getTextOffset(int line) const @@ -236,6 +238,30 @@ void CutterGraphView::refreshView() setLayoutConfig(getLayoutConfig()); } +bool CutterGraphView::gestureEvent(QGestureEvent *event) +{ + if (!event) { + return false; + } + + if (auto gesture = + static_cast(event->gesture(Qt::PinchGesture))) { + auto changeFlags = gesture->changeFlags(); + + if (changeFlags & QPinchGesture::ScaleFactorChanged) { + auto cursorPos = gesture->centerPoint(); + cursorPos.rx() /= size().width(); + cursorPos.ry() /= size().height(); + + setZoom(cursorPos, getViewScale() * gesture->scaleFactor()); + } + + event->accept(gesture); + return true; + } + + return false; +} void CutterGraphView::wheelEvent(QWheelEvent *event) { diff --git a/src/widgets/CutterGraphView.h b/src/widgets/CutterGraphView.h index 4403802a..f815ad4e 100644 --- a/src/widgets/CutterGraphView.h +++ b/src/widgets/CutterGraphView.h @@ -7,6 +7,8 @@ #include #include +#include + #include "widgets/GraphView.h" #include "common/CachedFontMetrics.h" @@ -32,7 +34,8 @@ public: * @param graphCommand r2 graph printing command without type, not required for direct image export * @param address object address for commands like agf */ - void exportGraph(QString filePath, GraphExportType type, QString graphCommand = "", RVA address = RVA_INVALID); + void exportGraph(QString filePath, GraphExportType type, QString graphCommand = "", + RVA address = RVA_INVALID); /** * @brief Export image using r2 ag*w command and graphviz. * Requires graphviz dot executable in the path. @@ -86,6 +89,7 @@ protected: void mouseMoveEvent(QMouseEvent *event) override; void wheelEvent(QWheelEvent *event) override; void resizeEvent(QResizeEvent *event) override; + bool gestureEvent(QGestureEvent *event) override; /** * @brief Save the the currently viewed or displayed block. diff --git a/src/widgets/GraphView.cpp b/src/widgets/GraphView.cpp index 08b84dba..83179360 100644 --- a/src/widgets/GraphView.cpp +++ b/src/widgets/GraphView.cpp @@ -104,11 +104,21 @@ bool GraphView::event(QEvent *event) if (helpEvent(static_cast(event))) { return true; } + } else if (event->type() == QEvent::Gesture) { + if (gestureEvent(static_cast(event))) { + return true; + } } return QAbstractScrollArea::event(event); } +bool GraphView::gestureEvent(QGestureEvent *event) +{ + Q_UNUSED(event) + return false; +} + void GraphView::contextMenuEvent(QContextMenuEvent *event) { event->ignore(); diff --git a/src/widgets/GraphView.h b/src/widgets/GraphView.h index 36c921fb..73bd098b 100644 --- a/src/widgets/GraphView.h +++ b/src/widgets/GraphView.h @@ -8,6 +8,7 @@ #include #include #include +#include #include #include @@ -134,6 +135,7 @@ protected: virtual void wheelEvent(QWheelEvent *event) override; virtual EdgeConfiguration edgeConfiguration(GraphView::GraphBlock &from, GraphView::GraphBlock *to, bool interactive = true); + virtual bool gestureEvent(QGestureEvent *event); /** * @brief Called when user requested context menu for a block. Should open a block specific contextmenu. * Typically triggered by right click.