From 6f2c3b90ce29a20e14cc769841056d4b36c42d50 Mon Sep 17 00:00:00 2001 From: Bent Bisballe Nyeng Date: Sat, 29 Dec 2018 21:30:28 +0100 Subject: Implement drag'n'move. --- src/outputwindow.cc | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) (limited to 'src/outputwindow.cc') diff --git a/src/outputwindow.cc b/src/outputwindow.cc index 8c4cb7b..95c3c7b 100644 --- a/src/outputwindow.cc +++ b/src/outputwindow.cc @@ -164,6 +164,34 @@ void OutputWindow::reset() } } +void OutputWindow::mouseMoveEvent(QMouseEvent* event) +{ + if(dragging) + { + dragOffset = event->pos() - dragOffsetOrigo; + } +} + +void OutputWindow::mousePressEvent(QMouseEvent* event) +{ + if(event->buttons() & Qt::MiddleButton) + { + dragging = true; + dragOffsetOrigo = event->pos(); + dragOffset = {}; + } +} + +void OutputWindow::mouseReleaseEvent(QMouseEvent* event) +{ + if(event->buttons() & Qt::MiddleButton) + { + dragging = false; + offset = dragOffsetOrigo - event->pos(); + dragOffset = dragOffsetOrigo = {}; + } +} + void OutputWindow::wheelEvent(QWheelEvent* event) { double delta = event->delta() / 120.0 * scale; @@ -178,7 +206,9 @@ void OutputWindow::paintEvent(QPaintEvent *) { //sem.acquire(); QPainter painter(this); - paint(painter, {width() / 2.0, height() / 2.0}, true, scale); + paint(painter, + { width() / 2.0 + offset.x() + dragOffset.x(), + height() / 2.0 + offset.y() + dragOffset.y() }, true, scale); sem.release(); } -- cgit v1.2.3