From 55be4efb8c5e63d5b8a292dbb4819cd41702af1d Mon Sep 17 00:00:00 2001 From: Xaltonon Date: Mon, 21 May 2018 10:33:46 -0700 Subject: [PATCH] Graph improvements (#500) * Add antialiasing to graphview * Make panning speed up/slow down with current zoom * Made scrolling proportional to zoom level --- src/widgets/GraphView.cpp | 17 +++++++++++++++-- src/widgets/GraphView.h | 1 + 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/widgets/GraphView.cpp b/src/widgets/GraphView.cpp index 4407f1b0..75ec4751 100644 --- a/src/widgets/GraphView.cpp +++ b/src/widgets/GraphView.cpp @@ -411,6 +411,9 @@ void GraphView::paintEvent(QPaintEvent *event) { Q_UNUSED(event); QPainter p(viewport()); + + p.setRenderHint(QPainter::Antialiasing); + int render_offset_x = -horizontalScrollBar()->value() * current_scale; int render_offset_y = -verticalScrollBar()->value() * current_scale; int render_width = viewport()->size().width() / current_scale; @@ -861,8 +864,8 @@ void GraphView::mouseMoveEvent(QMouseEvent *event) int y_delta = scroll_base_y - event->y(); scroll_base_x = event->x(); scroll_base_y = event->y(); - horizontalScrollBar()->setValue(horizontalScrollBar()->value() + x_delta); - verticalScrollBar()->setValue(verticalScrollBar()->value() + y_delta); + horizontalScrollBar()->setValue(horizontalScrollBar()->value() + x_delta * (1/current_scale)); + verticalScrollBar()->setValue(verticalScrollBar()->value() + y_delta * (1/current_scale)); } } @@ -903,3 +906,13 @@ void GraphView::mouseReleaseEvent(QMouseEvent *event) viewport()->releaseMouse(); } } + +void GraphView::wheelEvent(QWheelEvent *event) +{ + const QPoint delta = -event->angleDelta(); + int x_delta = delta.x(); + int y_delta = delta.y(); + horizontalScrollBar()->setValue(horizontalScrollBar()->value() + x_delta * (1/current_scale)); + verticalScrollBar()->setValue(verticalScrollBar()->value() + y_delta * (1/current_scale)); + event->accept(); +} diff --git a/src/widgets/GraphView.h b/src/widgets/GraphView.h index 96aa5c9b..333d89e8 100644 --- a/src/widgets/GraphView.h +++ b/src/widgets/GraphView.h @@ -121,6 +121,7 @@ protected: virtual void blockHelpEvent(GraphView::GraphBlock &block, QHelpEvent *event, QPoint pos); virtual bool helpEvent(QHelpEvent *event); virtual void blockTransitionedTo(GraphView::GraphBlock *to); + virtual void wheelEvent(QWheelEvent *event) override; virtual EdgeConfiguration edgeConfiguration(GraphView::GraphBlock &from, GraphView::GraphBlock *to); void adjustSize(int new_width, int new_height, QPoint mouse = QPoint(0, 0));