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