From: Joel Holdsworth Date: Sat, 30 Jun 2012 12:49:56 +0000 (+0100) Subject: Implemented dragging and zooming X-Git-Tag: pulseview-0.1.0~329 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=1dd95c70180967864bd83d9679f3e9a6c2a4e383;p=pulseview.git Implemented dragging and zooming --- diff --git a/sigview.cpp b/sigview.cpp index a8e85359..6a2b6204 100644 --- a/sigview.cpp +++ b/sigview.cpp @@ -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(); } diff --git a/sigview.h b/sigview.h index 34eeb959..d66898f4 100644 --- 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