]> sigrok.org Git - pulseview.git/commitdiff
Implemented dragging and zooming
authorJoel Holdsworth <redacted>
Sat, 30 Jun 2012 12:49:56 +0000 (13:49 +0100)
committerJoel Holdsworth <redacted>
Mon, 3 Sep 2012 12:59:06 +0000 (13:59 +0100)
sigview.cpp
sigview.h

index a8e8535923d5a2acfc1a1aa2ae84ec804315d434..6a2b62044ddc488959dde2c64798a5554b83a105 100644 (file)
@@ -130,35 +130,38 @@ void SigView::dataUpdated()
        update();
 }
 
-void SigView::mouseMoveEvent(QMouseEvent *event)
+void SigView::mousePressEvent(QMouseEvent *event)
 {
        assert(event);
+
+       _mouse_down_point = event->pos();
+       _mouse_down_offset = _offset;
 }
 
-void SigView::mousePressEvent(QMouseEvent *event)
+void SigView::mouseMoveEvent(QMouseEvent *event)
 {
        assert(event);
+
+       if(event->buttons() & Qt::LeftButton)
+       {
+               _offset = _mouse_down_offset + (_mouse_down_point - event->pos()).x() * _scale;
+               update();
+       }
 }
 
 void SigView::mouseReleaseEvent(QMouseEvent *event)
 {
        assert(event);
+}
 
-       const double cursor_offset = _offset + _scale * (double)event->x();
-
-       switch(event->button())
-       {
-       case Qt::LeftButton:
-               _scale *= 2.0 / 3.0;
-               break;
-
-       case Qt::RightButton:
-               _scale *= 3.0 / 2.0;
-               break;
-       }
-
-       _offset = cursor_offset - _scale * (double)event->x();
+void SigView::wheelEvent(QWheelEvent *event)
+{
+       assert(event);
 
+       const double x = event->x() - LabelMarginWidth;
+       const double cursor_offset = _offset + _scale * x;
+       _scale *= powf(3.0/2.0, -event->delta() / 120);
+       _offset = cursor_offset - _scale * x;
        update();
 }
 
index 34eeb95993e8f27eb1878db4b449595daed6684f..d66898f4c0981b8f2a933cc425402e1251570fc5 100644 (file)
--- a/sigview.h
+++ b/sigview.h
@@ -55,9 +55,10 @@ protected:
        void paintEvent(QPaintEvent *event);
 
 private:
-       void mouseMoveEvent(QMouseEvent *event);
        void mousePressEvent(QMouseEvent *event);
+       void mouseMoveEvent(QMouseEvent *event);
        void mouseReleaseEvent(QMouseEvent *event);
+       void wheelEvent(QWheelEvent *event);
 
 private:
        void setupViewport(int width, int height);
@@ -72,6 +73,9 @@ private:
 
        double _scale;
        double _offset;
+
+       QPoint _mouse_down_point;
+       double _mouse_down_offset;
 };
 
 #endif // SIGVIEW_H