Trackpad gesture support for graph views (#2453)

Zooming using pinch gesture.
This commit is contained in:
Hikaru Terazono 2020-11-03 15:23:12 +09:00 committed by GitHub
parent 6039dab2ff
commit 8ba2164d00
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 43 additions and 1 deletions

View File

@ -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<QPinchGesture *>(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)
{

View File

@ -7,6 +7,8 @@
#include <QShortcut>
#include <QLabel>
#include <QGestureEvent>
#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.

View File

@ -104,11 +104,21 @@ bool GraphView::event(QEvent *event)
if (helpEvent(static_cast<QHelpEvent *>(event))) {
return true;
}
} else if (event->type() == QEvent::Gesture) {
if (gestureEvent(static_cast<QGestureEvent *>(event))) {
return true;
}
}
return QAbstractScrollArea::event(event);
}
bool GraphView::gestureEvent(QGestureEvent *event)
{
Q_UNUSED(event)
return false;
}
void GraphView::contextMenuEvent(QContextMenuEvent *event)
{
event->ignore();

View File

@ -8,6 +8,7 @@
#include <QScrollBar>
#include <QElapsedTimer>
#include <QHelpEvent>
#include <QGestureEvent>
#include <unordered_map>
#include <unordered_set>
@ -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.