diff --git a/src/widgets/DisassemblerGraphView.cpp b/src/widgets/DisassemblerGraphView.cpp index 2bd37639..61e72eb9 100644 --- a/src/widgets/DisassemblerGraphView.cpp +++ b/src/widgets/DisassemblerGraphView.cpp @@ -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() diff --git a/src/widgets/DisassemblerGraphView.h b/src/widgets/DisassemblerGraphView.h index d1ee656d..16250685 100644 --- a/src/widgets/DisassemblerGraphView.h +++ b/src/widgets/DisassemblerGraphView.h @@ -219,6 +219,7 @@ private: signals: void viewRefreshed(); + void viewZoomed(); }; #endif // DISASSEMBLERGRAPHVIEW_H diff --git a/src/widgets/GraphView.cpp b/src/widgets/GraphView.cpp index 76bb31d7..ca9fb1e0 100644 --- a/src/widgets/GraphView.cpp +++ b/src/widgets/GraphView.cpp @@ -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)); diff --git a/src/widgets/GraphWidget.cpp b/src/widgets/GraphWidget.cpp index 5c778811..080b4f76 100644 --- a/src/widgets/GraphWidget.cpp +++ b/src/widgets/GraphWidget.cpp @@ -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; + } +} diff --git a/src/widgets/GraphWidget.h b/src/widgets/GraphWidget.h index f13f14c2..48bcc819 100644 --- a/src/widgets/GraphWidget.h +++ b/src/widgets/GraphWidget.h @@ -23,6 +23,7 @@ private: private slots: void adjustOverview(); void adjustGraph(); + void adjustOffset(); }; #endif // GRAPHWIDGET_H diff --git a/src/widgets/OverviewView.cpp b/src/widgets/OverviewView.cpp index 8a8a34d6..86f2f3a9 100644 --- a/src/widgets/OverviewView.cpp +++ b/src/widgets/OverviewView.cpp @@ -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();