summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/outputwindow.cc32
-rw-r--r--src/outputwindow.h8
2 files changed, 39 insertions, 1 deletions
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();
}
diff --git a/src/outputwindow.h b/src/outputwindow.h
index bb7ef7b..182499a 100644
--- a/src/outputwindow.h
+++ b/src/outputwindow.h
@@ -65,6 +65,9 @@ public slots:
void reset();
protected:
+ void mouseMoveEvent(QMouseEvent* event);
+ void mousePressEvent(QMouseEvent* event);
+ void mouseReleaseEvent(QMouseEvent* event);
void wheelEvent(QWheelEvent* event);
void paintEvent(QPaintEvent* event);
@@ -92,4 +95,9 @@ private:
QString penfile;
volatile float scale{2.0f};
+
+ bool dragging{false};
+ QPoint dragOffsetOrigo{0, 0};
+ QPoint dragOffset{0, 0};
+ QPoint offset{0, 0};
};