Added ctrl+wheel zoom in graph view (#484)

This commit is contained in:
fcasal 2018-05-10 15:08:03 +01:00 committed by xarkes
parent 4fa4460cd5
commit 4b148d74de
6 changed files with 57 additions and 22 deletions

View File

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

View File

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

View File

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

View File

@ -281,7 +281,7 @@ void DisassemblyWidget::highlightCurrentLine()
QList<QTextEdit::ExtraSelection> extraSelections;
QColor highlightColor = ConfigColor("highlight");
QColor highlightWordColor = ConfigColor("highlight");
QColor highlightWordColor = ConfigColor("highlightWord");
highlightWordColor.setAlpha(128);
QColor highlightWordCurrentLineColor = ConfigColor("gui.background");
highlightWordCurrentLineColor.setAlpha(128);

View File

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

View File

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