mirror of
https://github.com/rizinorg/cutter.git
synced 2025-01-19 02:48:49 +00:00
Fix graph zoom for overview (#1152)
This commit is contained in:
parent
60bb972cfd
commit
f5709830b9
@ -697,6 +697,7 @@ void DisassemblerGraphView::zoomIn(QPoint mouse)
|
||||
auto areaSize = viewport()->size();
|
||||
adjustSize(areaSize.width(), areaSize.height(), mouse);
|
||||
viewport()->update();
|
||||
emit viewZoomed();
|
||||
}
|
||||
|
||||
void DisassemblerGraphView::zoomOut(QPoint mouse)
|
||||
@ -706,6 +707,7 @@ void DisassemblerGraphView::zoomOut(QPoint mouse)
|
||||
auto areaSize = viewport()->size();
|
||||
adjustSize(areaSize.width(), areaSize.height(), mouse);
|
||||
viewport()->update();
|
||||
emit viewZoomed();
|
||||
}
|
||||
|
||||
void DisassemblerGraphView::zoomReset()
|
||||
@ -714,6 +716,7 @@ void DisassemblerGraphView::zoomReset()
|
||||
auto areaSize = viewport()->size();
|
||||
adjustSize(areaSize.width(), areaSize.height());
|
||||
viewport()->update();
|
||||
emit viewZoomed();
|
||||
}
|
||||
|
||||
void DisassemblerGraphView::takeTrue()
|
||||
|
@ -219,6 +219,7 @@ private:
|
||||
|
||||
signals:
|
||||
void viewRefreshed();
|
||||
void viewZoomed();
|
||||
};
|
||||
|
||||
#endif // DISASSEMBLERGRAPHVIEW_H
|
||||
|
@ -420,8 +420,8 @@ void GraphView::paintEvent(QPaintEvent *event)
|
||||
int render_height = viewport()->size().height() / current_scale;
|
||||
|
||||
// Do we have scrollbars?
|
||||
bool hscrollbar = horizontalScrollBar()->pageStep() < width;
|
||||
bool vscrollbar = verticalScrollBar()->pageStep() < height;
|
||||
bool hscrollbar = horizontalScrollBar()->pageStep() < width * current_scale;
|
||||
bool vscrollbar = verticalScrollBar()->pageStep() < height * current_scale;
|
||||
|
||||
// Draw background
|
||||
QRect viewportRect(viewport()->rect().topLeft(), viewport()->rect().bottomRight() - QPoint(1, 1));
|
||||
|
@ -54,13 +54,17 @@ void GraphWidget::toggleOverview(bool visibility)
|
||||
}
|
||||
if (visibility) {
|
||||
connect(graphView, SIGNAL(refreshBlock()), this, SLOT(adjustOverview()));
|
||||
connect(graphView, SIGNAL(viewZoomed()), this, SLOT(adjustOverview()));
|
||||
connect(graphView->horizontalScrollBar(), SIGNAL(valueChanged(int)), this, SLOT(adjustOverview()));
|
||||
connect(graphView->verticalScrollBar(), SIGNAL(valueChanged(int)), this, SLOT(adjustOverview()));
|
||||
connect(overviewWidget->graphView, SIGNAL(refreshBlock()), this, SLOT(adjustOffset()));
|
||||
connect(overviewWidget->graphView, SIGNAL(mouseMoved()), this, SLOT(adjustGraph()));
|
||||
} else {
|
||||
disconnect(graphView, SIGNAL(refreshBlock()), this, SLOT(adjustOverview()));
|
||||
disconnect(graphView, SIGNAL(viewZoomed()), this, SLOT(adjustOverview()));
|
||||
disconnect(graphView->horizontalScrollBar(), SIGNAL(valueChanged(int)), this, SLOT(adjustOverview()));
|
||||
disconnect(graphView->verticalScrollBar(), SIGNAL(valueChanged(int)), this, SLOT(adjustOverview()));
|
||||
disconnect(overviewWidget->graphView, SIGNAL(refreshBlock()), this, SLOT(adjustOffset()));
|
||||
disconnect(overviewWidget->graphView, SIGNAL(mouseMoved()), this, SLOT(adjustGraph()));
|
||||
disableOverviewRect();
|
||||
}
|
||||
@ -80,8 +84,8 @@ void GraphWidget::adjustOverview()
|
||||
if (!overviewWidget) {
|
||||
return;
|
||||
}
|
||||
bool scrollXVisible = graphView->unscrolled_render_offset_x == 0;
|
||||
bool scrollYVisible = graphView->unscrolled_render_offset_y == 0;
|
||||
bool scrollXVisible = graphView->horizontalScrollBar()->isVisible();
|
||||
bool scrollYVisible = graphView->verticalScrollBar()->isVisible();
|
||||
if (!scrollXVisible && !scrollYVisible) {
|
||||
disableOverviewRect();
|
||||
return;
|
||||
@ -91,28 +95,24 @@ void GraphWidget::adjustOverview()
|
||||
qreal w = overviewWidget->graphView->viewport()->width();
|
||||
qreal h = overviewWidget->graphView->viewport()->height();
|
||||
qreal curScale = overviewWidget->graphView->current_scale;
|
||||
qreal xoff = overviewWidget->graphView->unscrolled_render_offset_x;;
|
||||
qreal yoff = overviewWidget->graphView->unscrolled_render_offset_y;;
|
||||
qreal baseScale = graphView->current_scale;
|
||||
|
||||
w = graphView->viewport()->width();
|
||||
h = graphView->viewport()->height();
|
||||
|
||||
if (scrollXVisible) {
|
||||
x = graphView->horizontalScrollBar()->value();
|
||||
w *= curScale;
|
||||
} else {
|
||||
xoff = 0;
|
||||
w *= curScale / baseScale;
|
||||
}
|
||||
|
||||
if (scrollYVisible) {
|
||||
y = graphView->verticalScrollBar()->value();
|
||||
h *= curScale;
|
||||
} else {
|
||||
yoff = 0;
|
||||
h *= curScale / baseScale;
|
||||
}
|
||||
x *= curScale;
|
||||
y *= curScale;
|
||||
overviewWidget->graphView->rangeRect = QRectF(x + xoff, y + yoff, w, h);
|
||||
overviewWidget->graphView->rangeRect = QRectF(x + overviewWidget->graphView->unscrolled_render_offset_x,
|
||||
y + overviewWidget->graphView->unscrolled_render_offset_y, w, h);
|
||||
overviewWidget->graphView->viewport()->update();
|
||||
}
|
||||
|
||||
@ -129,3 +129,15 @@ void GraphWidget::adjustGraph()
|
||||
graphView->horizontalScrollBar()->setValue(x1 + x2);
|
||||
graphView->verticalScrollBar()->setValue(y1 + y2);
|
||||
}
|
||||
|
||||
void GraphWidget::adjustOffset()
|
||||
{
|
||||
bool scrollXVisible = graphView->horizontalScrollBar()->isVisible();
|
||||
bool scrollYVisible = graphView->verticalScrollBar()->isVisible();
|
||||
if (!scrollXVisible) {
|
||||
overviewWidget->graphView->unscrolled_render_offset_x = 0;
|
||||
}
|
||||
if (!scrollYVisible) {
|
||||
overviewWidget->graphView->unscrolled_render_offset_y = 0;
|
||||
}
|
||||
}
|
||||
|
@ -23,6 +23,7 @@ private:
|
||||
private slots:
|
||||
void adjustOverview();
|
||||
void adjustGraph();
|
||||
void adjustOffset();
|
||||
};
|
||||
|
||||
#endif // GRAPHWIDGET_H
|
||||
|
@ -113,16 +113,16 @@ void OverviewView::mouseMoveEvent(QMouseEvent *event)
|
||||
qreal rect_right = x + w;
|
||||
qreal rect_bottom = y + h;
|
||||
if (rect_right >= max_right) {
|
||||
x = real_width - w;
|
||||
x = unscrolled_render_offset_x + real_width - w;
|
||||
}
|
||||
if (rect_bottom >= max_bottom) {
|
||||
y = real_height - h;
|
||||
y = unscrolled_render_offset_y + real_height - h;
|
||||
}
|
||||
if (x <= 0) {
|
||||
x = 0;
|
||||
if (x <= unscrolled_render_offset_x) {
|
||||
x = unscrolled_render_offset_x;
|
||||
}
|
||||
if (y <= 0) {
|
||||
y = 0;
|
||||
if (y <= unscrolled_render_offset_y) {
|
||||
y = unscrolled_render_offset_y;
|
||||
}
|
||||
rangeRect = QRectF(x, y, w, h);
|
||||
viewport()->update();
|
||||
|
Loading…
Reference in New Issue
Block a user