mirror of
https://github.com/rizinorg/cutter.git
synced 2024-12-18 19:06:10 +00:00
Trackpad gesture support for graph views (#2453)
Zooming using pinch gesture.
This commit is contained in:
parent
6039dab2ff
commit
8ba2164d00
@ -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)
|
||||
{
|
||||
|
@ -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.
|
||||
|
@ -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();
|
||||
|
@ -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.
|
||||
|
Loading…
Reference in New Issue
Block a user