Transfer zoom events from overview to main graph. (#1685)

This commit is contained in:
karliss 2019-07-22 22:28:11 +03:00 committed by GitHub
parent 9dd3b2f2f3
commit c2a7fd85a4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 33 additions and 0 deletions

View File

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

View File

@ -32,6 +32,8 @@ public:
void setData(int baseWidth, int baseHeight, std::unordered_map<ut64, GraphBlock> baseBlocks,
DisassemblerGraphView::EdgeConfigurationMapping baseEdgeConfigurations);
void centreRect();
public slots:
/**
* @brief scale and center all nodes in, then run update

View File

@ -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);

View File

@ -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