From c2a7fd85a4b8ec92228e04cc3a29457aefcee07a Mon Sep 17 00:00:00 2001 From: karliss Date: Mon, 22 Jul 2019 22:28:11 +0300 Subject: [PATCH] Transfer zoom events from overview to main graph. (#1685) --- src/widgets/OverviewView.cpp | 7 +++++++ src/widgets/OverviewView.h | 2 ++ src/widgets/OverviewWidget.cpp | 22 ++++++++++++++++++++++ src/widgets/OverviewWidget.h | 2 ++ 4 files changed, 33 insertions(+) diff --git a/src/widgets/OverviewView.cpp b/src/widgets/OverviewView.cpp index 111ce8bb..6eeb4930 100644 --- a/src/widgets/OverviewView.cpp +++ b/src/widgets/OverviewView.cpp @@ -27,6 +27,13 @@ void OverviewView::setData(int baseWidth, int baseHeight, viewport()->update(); } +void OverviewView::centreRect() +{ + qreal w = rangeRect.width(); + qreal h = rangeRect.height(); + initialDiff = QPointF(w / 2, h / 2); +} + OverviewView::~OverviewView() { } diff --git a/src/widgets/OverviewView.h b/src/widgets/OverviewView.h index b0bf4f7b..1761c17c 100644 --- a/src/widgets/OverviewView.h +++ b/src/widgets/OverviewView.h @@ -32,6 +32,8 @@ public: void setData(int baseWidth, int baseHeight, std::unordered_map baseBlocks, DisassemblerGraphView::EdgeConfigurationMapping baseEdgeConfigurations); + void centreRect(); + public slots: /** * @brief scale and center all nodes in, then run update diff --git a/src/widgets/OverviewWidget.cpp b/src/widgets/OverviewWidget.cpp index dcafcfac..0d781368 100644 --- a/src/widgets/OverviewWidget.cpp +++ b/src/widgets/OverviewWidget.cpp @@ -18,6 +18,14 @@ OverviewWidget::OverviewWidget(MainWindow *main, QAction *action) : graphDataRefreshDeferrer = createRefreshDeferrer([this]() { updateGraphData(); }); + + // Zoom shortcuts + QShortcut *shortcut_zoom_in = new QShortcut(QKeySequence(Qt::Key_Plus), this); + shortcut_zoom_in->setContext(Qt::WidgetWithChildrenShortcut); + connect(shortcut_zoom_in, &QShortcut::activated, this, [this](){ zoomTarget(1); }); + QShortcut *shortcut_zoom_out = new QShortcut(QKeySequence(Qt::Key_Minus), this); + shortcut_zoom_out->setContext(Qt::WidgetWithChildrenShortcut); + connect(shortcut_zoom_out, &QShortcut::activated, this, [this](){ zoomTarget(-1); }); } OverviewWidget::~OverviewWidget() {} @@ -65,6 +73,14 @@ void OverviewWidget::setUserOpened(bool userOpened) emit userOpenedChanged(userOpened); } +void OverviewWidget::zoomTarget(int d) +{ + if (!targetGraphWidget) { + return; + } + targetGraphWidget->getGraphView()->zoom(QPointF(0.5, 0.5), d); +} + void OverviewWidget::setTargetGraphWidget(GraphWidget *widget) { if (widget == targetGraphWidget) { @@ -90,6 +106,12 @@ void OverviewWidget::setTargetGraphWidget(GraphWidget *widget) setIsAvailable(targetGraphWidget != nullptr); } +void OverviewWidget::wheelEvent(QWheelEvent *event) +{ + zoomTarget(event->angleDelta().y() / 90); + graphView->centreRect(); +} + void OverviewWidget::targetClosed() { setTargetGraphWidget(nullptr); diff --git a/src/widgets/OverviewWidget.h b/src/widgets/OverviewWidget.h index cb497d4f..ad9e61f8 100644 --- a/src/widgets/OverviewWidget.h +++ b/src/widgets/OverviewWidget.h @@ -31,6 +31,7 @@ private: void setIsAvailable(bool isAvailable); void setUserOpened(bool userOpened); + void zoomTarget(int d); private slots: void showEvent(QShowEvent *event) override; @@ -87,6 +88,7 @@ public: bool getUserOpened() const { return userOpened; } OverviewView *getGraphView() const { return graphView; } + void wheelEvent(QWheelEvent *event) override; }; #endif // OverviewWIDGET_H