Initial work moving ruler into the pv::view::Ruler widget
[pulseview.git] / pv / view / view.cpp
index 49b96ba390a093326ba770ce80d8e1995ddace60..4e0fed063fca8c4d42e67c5bcb6cb58c23cee390 100644 (file)
@@ -26,6 +26,8 @@
 #include <QEvent>
 #include <QScrollBar>
 
+#include "header.h"
+#include "ruler.h"
 #include "view.h"
 #include "viewport.h"
 
@@ -45,10 +47,14 @@ const double View::MinScale = 1e-15;
 const int View::LabelMarginWidth = 70;
 const int View::RulerHeight = 30;
 
+const int View::SignalHeight = 50;
+
 View::View(SigSession &session, QWidget *parent) :
        QAbstractScrollArea(parent),
        _session(session),
        _viewport(new Viewport(*this)),
+       _ruler(new Ruler(*this)),
+       _header(new Header(*this)),
        _data_length(0),
        _scale(1e-6),
        _offset(0),
@@ -60,9 +66,16 @@ View::View(SigSession &session, QWidget *parent) :
                this, SLOT(v_scroll_value_changed(int)));
        connect(&_session, SIGNAL(data_updated()),
                this, SLOT(data_updated()));
+
+       setViewportMargins(LabelMarginWidth, RulerHeight, 0, 0);
        setViewport(_viewport);
 }
 
+SigSession& View::session()
+{
+       return _session;
+}
+
 double View::scale() const
 {
        return _scale;
@@ -87,7 +100,9 @@ void View::set_scale_offset(double scale, double offset)
 {
        _scale = scale;
        _offset = offset;
+
        update_scroll();
+       _ruler->update();
        _viewport->update();
 }
 
@@ -123,6 +138,8 @@ void View::zoom(double steps, int offset)
        _scale *= pow(3.0/2.0, -steps);
        _scale = max(min(_scale, MaxScale), MinScale);
        _offset = cursor_offset - _scale * offset;
+
+       _ruler->update();
        _viewport->update();
        update_scroll();
 }
@@ -145,18 +162,24 @@ bool View::viewportEvent(QEvent *e)
 
 void View::resizeEvent(QResizeEvent *e)
 {
+       _ruler->setGeometry(_viewport->x(), 0,
+               _viewport->width(), _viewport->y());
+       _header->setGeometry(0, _viewport->y(),
+               _viewport->x(), _viewport->height());
        update_scroll();
 }
 
 void View::h_scroll_value_changed(int value)
 {
        _offset = _scale * value;
+       _ruler->update();
        _viewport->update();
 }
 
 void View::v_scroll_value_changed(int value)
 {
        _v_offset = value;
+       _header->update();
        _viewport->update();
 }