diff --git a/src/utils/Configuration.cpp b/src/utils/Configuration.cpp index 3f351628..6924ff81 100644 --- a/src/utils/Configuration.cpp +++ b/src/utils/Configuration.cpp @@ -103,6 +103,7 @@ void Configuration::loadDefaultTheme() setColor("gui.dataoffset", QColor(0, 0, 0)); setColor("gui.border", QColor(0, 0, 0)); setColor("highlight", QColor(210, 210, 255)); + setColor("highlightWord", QColor(210, 210, 255)); // Windows background setColor("gui.background", QColor(255, 255, 255)); setColor("gui.disass_selected", QColor(255, 255, 255)); @@ -169,6 +170,7 @@ void Configuration::loadDarkTheme() setColor("gui.disass_selected", QColor(36, 66, 79)); // Disassembly line selected setColor("highlight", QColor(64, 115, 115)); + setColor("highlightWord", QColor(64, 115, 115)); } void Configuration::loadDarkGreyTheme() @@ -183,6 +185,7 @@ void Configuration::loadDarkGreyTheme() setColor("gui.disass_selected", QColor(44, 53, 54)); // Disassembly line selected setColor("highlight", QColor(21, 29, 29)); + setColor("highlightWord", QColor(100, 100, 100)); } const QFont Configuration::getFont() const diff --git a/src/widgets/DisassemblerGraphView.cpp b/src/widgets/DisassemblerGraphView.cpp index e554b0c2..b8b8ee37 100644 --- a/src/widgets/DisassemblerGraphView.cpp +++ b/src/widgets/DisassemblerGraphView.cpp @@ -507,20 +507,20 @@ void DisassemblerGraphView::onSeekChanged(RVA addr) sent_seek = false; } -void DisassemblerGraphView::zoomIn() +void DisassemblerGraphView::zoomIn(QPoint mouse) { current_scale += 0.1; auto areaSize = viewport()->size(); - adjustSize(areaSize.width(), areaSize.height()); + adjustSize(areaSize.width(), areaSize.height(), mouse); viewport()->update(); } -void DisassemblerGraphView::zoomOut() +void DisassemblerGraphView::zoomOut(QPoint mouse) { current_scale -= 0.1; current_scale = std::max(current_scale, 0.3); auto areaSize = viewport()->size(); - adjustSize(areaSize.width(), areaSize.height()); + adjustSize(areaSize.width(), areaSize.height(), mouse); viewport()->update(); } @@ -677,3 +677,25 @@ void DisassemblerGraphView::on_actionExportGraph_triggered() QTextStream fileOut(&file); fileOut << Core()->cmd("ag -"); } + + +void DisassemblerGraphView::wheelEvent(QWheelEvent *event) +{ + // when CTRL is pressed, we zoom in/out with mouse wheel + if (Qt::ControlModifier == event->modifiers()) { + const QPoint numDegrees = event->angleDelta() / 8; + if (!numDegrees.isNull()) { + const QPoint numSteps = numDegrees / 15; + QPoint mouse = event->globalPos(); + if (numSteps.y() > 0) { + zoomIn(mouse); + } else if (numSteps.y() < 0) { + zoomOut(mouse); + } + } + event->accept(); + } else { + // use mouse wheel for scrolling when CTRL is not pressed + GraphView::wheelEvent(event); + } +} diff --git a/src/widgets/DisassemblerGraphView.h b/src/widgets/DisassemblerGraphView.h index 1b7b4c8b..6b341fb7 100644 --- a/src/widgets/DisassemblerGraphView.h +++ b/src/widgets/DisassemblerGraphView.h @@ -150,8 +150,8 @@ public slots: void fontsUpdatedSlot(); void onSeekChanged(RVA addr); - void zoomIn(); - void zoomOut(); + void zoomIn(QPoint mouse = QPoint(0, 0)); + void zoomOut(QPoint mouse = QPoint(0, 0)); void zoomReset(); void takeTrue(); @@ -159,6 +159,10 @@ public slots: void nextInstr(); void prevInstr(); + +protected: + virtual void wheelEvent(QWheelEvent *event) override; + private slots: void seekPrev(); diff --git a/src/widgets/DisassemblyWidget.cpp b/src/widgets/DisassemblyWidget.cpp index debafed1..243ea83a 100644 --- a/src/widgets/DisassemblyWidget.cpp +++ b/src/widgets/DisassemblyWidget.cpp @@ -281,7 +281,7 @@ void DisassemblyWidget::highlightCurrentLine() QList extraSelections; QColor highlightColor = ConfigColor("highlight"); - QColor highlightWordColor = ConfigColor("highlight"); + QColor highlightWordColor = ConfigColor("highlightWord"); highlightWordColor.setAlpha(128); QColor highlightWordCurrentLineColor = ConfigColor("gui.background"); highlightWordCurrentLineColor.setAlpha(128); diff --git a/src/widgets/GraphView.cpp b/src/widgets/GraphView.cpp index 11c78fe7..4407f1b0 100644 --- a/src/widgets/GraphView.cpp +++ b/src/widgets/GraphView.cpp @@ -105,24 +105,30 @@ GraphView::EdgeConfiguration GraphView::edgeConfiguration(GraphView::GraphBlock return ec; } -void GraphView::adjustSize(int new_width, int new_height) +void GraphView::adjustSize(int new_width, int new_height, QPoint mouse) { - double hfactor = 0.0; - double vfactor = 0.0; - if (horizontalScrollBar()->maximum()) { - hfactor = (double)horizontalScrollBar()->value() / (double)horizontalScrollBar()->maximum(); - } - if (verticalScrollBar()->maximum()) { - vfactor = (double)verticalScrollBar()->value() / (double)verticalScrollBar()->maximum(); - } + int originalRangeX = horizontalScrollBar()->maximum(); + int originalRangeY = verticalScrollBar()->maximum(); + int newMaxX = width - (new_width / current_scale); + int newMaxY = height - (new_height / current_scale); - //Update scroll bar information + // Update scroll bar information horizontalScrollBar()->setPageStep(new_width); - horizontalScrollBar()->setRange(0, width - (new_width / current_scale)); + horizontalScrollBar()->setRange(0, newMaxX); verticalScrollBar()->setPageStep(new_height); - verticalScrollBar()->setRange(0, height - (new_height / current_scale)); - horizontalScrollBar()->setValue((int)((double)horizontalScrollBar()->maximum() * hfactor)); - verticalScrollBar()->setValue((int)((double)verticalScrollBar()->maximum() * vfactor)); + verticalScrollBar()->setRange(0, newMaxY); + + // Compute new scrollBar values so that the mouse always points + // to the same place when zooming + QPoint mouseLocal = mapFromGlobal(mouse); + + int topX = horizontalScrollBar()->value(); + int topY = verticalScrollBar()->value(); + + int dx = newMaxX - originalRangeX; + int dy = newMaxY - originalRangeY; + horizontalScrollBar()->setValue(topX + dx*((float)mouseLocal.x()/new_width)); + verticalScrollBar()->setValue(topY + dy*((float)mouseLocal.y()/new_height)); } bool GraphView::event(QEvent *event) diff --git a/src/widgets/GraphView.h b/src/widgets/GraphView.h index 7bd50ca2..96aa5c9b 100644 --- a/src/widgets/GraphView.h +++ b/src/widgets/GraphView.h @@ -123,7 +123,7 @@ protected: virtual void blockTransitionedTo(GraphView::GraphBlock *to); virtual EdgeConfiguration edgeConfiguration(GraphView::GraphBlock &from, GraphView::GraphBlock *to); - void adjustSize(int new_width, int new_height); + void adjustSize(int new_width, int new_height, QPoint mouse = QPoint(0, 0)); bool event(QEvent *event) override; private: