mirror of
https://github.com/rizinorg/cutter.git
synced 2025-01-18 18:38:51 +00:00
Added ctrl+wheel zoom in graph view (#484)
This commit is contained in:
parent
4fa4460cd5
commit
4b148d74de
@ -103,6 +103,7 @@ void Configuration::loadDefaultTheme()
|
|||||||
setColor("gui.dataoffset", QColor(0, 0, 0));
|
setColor("gui.dataoffset", QColor(0, 0, 0));
|
||||||
setColor("gui.border", QColor(0, 0, 0));
|
setColor("gui.border", QColor(0, 0, 0));
|
||||||
setColor("highlight", QColor(210, 210, 255));
|
setColor("highlight", QColor(210, 210, 255));
|
||||||
|
setColor("highlightWord", QColor(210, 210, 255));
|
||||||
// Windows background
|
// Windows background
|
||||||
setColor("gui.background", QColor(255, 255, 255));
|
setColor("gui.background", QColor(255, 255, 255));
|
||||||
setColor("gui.disass_selected", 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));
|
setColor("gui.disass_selected", QColor(36, 66, 79));
|
||||||
// Disassembly line selected
|
// Disassembly line selected
|
||||||
setColor("highlight", QColor(64, 115, 115));
|
setColor("highlight", QColor(64, 115, 115));
|
||||||
|
setColor("highlightWord", QColor(64, 115, 115));
|
||||||
}
|
}
|
||||||
|
|
||||||
void Configuration::loadDarkGreyTheme()
|
void Configuration::loadDarkGreyTheme()
|
||||||
@ -183,6 +185,7 @@ void Configuration::loadDarkGreyTheme()
|
|||||||
setColor("gui.disass_selected", QColor(44, 53, 54));
|
setColor("gui.disass_selected", QColor(44, 53, 54));
|
||||||
// Disassembly line selected
|
// Disassembly line selected
|
||||||
setColor("highlight", QColor(21, 29, 29));
|
setColor("highlight", QColor(21, 29, 29));
|
||||||
|
setColor("highlightWord", QColor(100, 100, 100));
|
||||||
}
|
}
|
||||||
|
|
||||||
const QFont Configuration::getFont() const
|
const QFont Configuration::getFont() const
|
||||||
|
@ -507,20 +507,20 @@ void DisassemblerGraphView::onSeekChanged(RVA addr)
|
|||||||
sent_seek = false;
|
sent_seek = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DisassemblerGraphView::zoomIn()
|
void DisassemblerGraphView::zoomIn(QPoint mouse)
|
||||||
{
|
{
|
||||||
current_scale += 0.1;
|
current_scale += 0.1;
|
||||||
auto areaSize = viewport()->size();
|
auto areaSize = viewport()->size();
|
||||||
adjustSize(areaSize.width(), areaSize.height());
|
adjustSize(areaSize.width(), areaSize.height(), mouse);
|
||||||
viewport()->update();
|
viewport()->update();
|
||||||
}
|
}
|
||||||
|
|
||||||
void DisassemblerGraphView::zoomOut()
|
void DisassemblerGraphView::zoomOut(QPoint mouse)
|
||||||
{
|
{
|
||||||
current_scale -= 0.1;
|
current_scale -= 0.1;
|
||||||
current_scale = std::max(current_scale, 0.3);
|
current_scale = std::max(current_scale, 0.3);
|
||||||
auto areaSize = viewport()->size();
|
auto areaSize = viewport()->size();
|
||||||
adjustSize(areaSize.width(), areaSize.height());
|
adjustSize(areaSize.width(), areaSize.height(), mouse);
|
||||||
viewport()->update();
|
viewport()->update();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -677,3 +677,25 @@ void DisassemblerGraphView::on_actionExportGraph_triggered()
|
|||||||
QTextStream fileOut(&file);
|
QTextStream fileOut(&file);
|
||||||
fileOut << Core()->cmd("ag -");
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -150,8 +150,8 @@ public slots:
|
|||||||
void fontsUpdatedSlot();
|
void fontsUpdatedSlot();
|
||||||
void onSeekChanged(RVA addr);
|
void onSeekChanged(RVA addr);
|
||||||
|
|
||||||
void zoomIn();
|
void zoomIn(QPoint mouse = QPoint(0, 0));
|
||||||
void zoomOut();
|
void zoomOut(QPoint mouse = QPoint(0, 0));
|
||||||
void zoomReset();
|
void zoomReset();
|
||||||
|
|
||||||
void takeTrue();
|
void takeTrue();
|
||||||
@ -159,6 +159,10 @@ public slots:
|
|||||||
|
|
||||||
void nextInstr();
|
void nextInstr();
|
||||||
void prevInstr();
|
void prevInstr();
|
||||||
|
|
||||||
|
protected:
|
||||||
|
virtual void wheelEvent(QWheelEvent *event) override;
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void seekPrev();
|
void seekPrev();
|
||||||
|
|
||||||
|
@ -281,7 +281,7 @@ void DisassemblyWidget::highlightCurrentLine()
|
|||||||
QList<QTextEdit::ExtraSelection> extraSelections;
|
QList<QTextEdit::ExtraSelection> extraSelections;
|
||||||
|
|
||||||
QColor highlightColor = ConfigColor("highlight");
|
QColor highlightColor = ConfigColor("highlight");
|
||||||
QColor highlightWordColor = ConfigColor("highlight");
|
QColor highlightWordColor = ConfigColor("highlightWord");
|
||||||
highlightWordColor.setAlpha(128);
|
highlightWordColor.setAlpha(128);
|
||||||
QColor highlightWordCurrentLineColor = ConfigColor("gui.background");
|
QColor highlightWordCurrentLineColor = ConfigColor("gui.background");
|
||||||
highlightWordCurrentLineColor.setAlpha(128);
|
highlightWordCurrentLineColor.setAlpha(128);
|
||||||
|
@ -105,24 +105,30 @@ GraphView::EdgeConfiguration GraphView::edgeConfiguration(GraphView::GraphBlock
|
|||||||
return ec;
|
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;
|
int originalRangeX = horizontalScrollBar()->maximum();
|
||||||
double vfactor = 0.0;
|
int originalRangeY = verticalScrollBar()->maximum();
|
||||||
if (horizontalScrollBar()->maximum()) {
|
int newMaxX = width - (new_width / current_scale);
|
||||||
hfactor = (double)horizontalScrollBar()->value() / (double)horizontalScrollBar()->maximum();
|
int newMaxY = height - (new_height / current_scale);
|
||||||
}
|
|
||||||
if (verticalScrollBar()->maximum()) {
|
|
||||||
vfactor = (double)verticalScrollBar()->value() / (double)verticalScrollBar()->maximum();
|
|
||||||
}
|
|
||||||
|
|
||||||
//Update scroll bar information
|
// Update scroll bar information
|
||||||
horizontalScrollBar()->setPageStep(new_width);
|
horizontalScrollBar()->setPageStep(new_width);
|
||||||
horizontalScrollBar()->setRange(0, width - (new_width / current_scale));
|
horizontalScrollBar()->setRange(0, newMaxX);
|
||||||
verticalScrollBar()->setPageStep(new_height);
|
verticalScrollBar()->setPageStep(new_height);
|
||||||
verticalScrollBar()->setRange(0, height - (new_height / current_scale));
|
verticalScrollBar()->setRange(0, newMaxY);
|
||||||
horizontalScrollBar()->setValue((int)((double)horizontalScrollBar()->maximum() * hfactor));
|
|
||||||
verticalScrollBar()->setValue((int)((double)verticalScrollBar()->maximum() * vfactor));
|
// 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)
|
bool GraphView::event(QEvent *event)
|
||||||
|
@ -123,7 +123,7 @@ protected:
|
|||||||
virtual void blockTransitionedTo(GraphView::GraphBlock *to);
|
virtual void blockTransitionedTo(GraphView::GraphBlock *to);
|
||||||
virtual EdgeConfiguration edgeConfiguration(GraphView::GraphBlock &from, 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;
|
bool event(QEvent *event) override;
|
||||||
private:
|
private:
|
||||||
|
Loading…
Reference in New Issue
Block a user