]> sigrok.org Git - pulseview.git/commitdiff
Initial work moving headers into the pv::view::Header widget
authorJoel Holdsworth <redacted>
Sat, 8 Sep 2012 08:45:09 +0000 (09:45 +0100)
committerJoel Holdsworth <redacted>
Sun, 9 Sep 2012 10:29:07 +0000 (11:29 +0100)
CMakeLists.txt
pv/view/header.cpp [new file with mode: 0644]
pv/view/header.h [new file with mode: 0644]
pv/view/view.cpp
pv/view/view.h
pv/view/viewport.cpp
pv/view/viewport.h

index db0d5f9b2fa23c07f49ad0b450c00a4be4ee1773..d5818694aac85a4539e4b5230abca85075af8389 100644 (file)
@@ -26,6 +26,7 @@ set(pulseview_SOURCES
        signaldata.cpp
        sigsession.cpp
        signal.cpp
+       pv/view/header.cpp
        pv/view/view.cpp
        pv/view/viewport.cpp
 )
@@ -35,6 +36,7 @@ set(pulseview_HEADERS
        mainwindow.h
        samplingbar.h
        sigsession.h
+       pv/view/header.h
        pv/view/view.h
        pv/view/viewport.h
 )
diff --git a/pv/view/header.cpp b/pv/view/header.cpp
new file mode 100644 (file)
index 0000000..bf003a4
--- /dev/null
@@ -0,0 +1,70 @@
+/*
+ * This file is part of the sigrok project.
+ *
+ * Copyright (C) 2012 Joel Holdsworth <joel@airwebreathe.org.uk>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
+ */
+
+#include "header.h"
+#include "view.h"
+
+#include "../../signal.h"
+#include "../../sigsession.h"
+
+#include <assert.h>
+
+#include <boost/foreach.hpp>
+
+#include <QPainter>
+#include <QRect>
+
+using namespace boost;
+using namespace std;
+
+namespace pv {
+namespace view {
+
+Header::Header(View &parent) :
+       QWidget(&parent),
+       _view(parent)
+{
+}
+
+void Header::paintEvent(QPaintEvent *event)
+{
+       const int w = width();
+       const vector< shared_ptr<Signal> > &sigs =
+               _view.session().get_signals();
+
+       QPainter painter(this);
+       painter.setRenderHint(QPainter::Antialiasing);
+
+       int offset = -_view.v_offset();
+       BOOST_FOREACH(const shared_ptr<Signal> s, sigs)
+       {
+               assert(s);
+
+               const QRect label_rect(0, offset, w, View::SignalHeight);
+               s->paint_label(painter, label_rect);
+
+               offset += View::SignalHeight;
+       }
+
+       painter.end();
+}
+
+} // namespace view
+} // namespace pv
diff --git a/pv/view/header.h b/pv/view/header.h
new file mode 100644 (file)
index 0000000..36b786c
--- /dev/null
@@ -0,0 +1,48 @@
+/*
+ * This file is part of the sigrok project.
+ *
+ * Copyright (C) 2012 Joel Holdsworth <joel@airwebreathe.org.uk>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
+ */
+
+#ifndef PV_VIEW_HEADER_H
+#define PV_VIEW_HEADER_H
+
+#include <QWidget>
+
+namespace pv {
+namespace view {
+
+class View;
+
+class Header : public QWidget
+{
+       Q_OBJECT
+
+public:
+       Header(View &parent);
+
+private:
+       void paintEvent(QPaintEvent *event);
+
+private:
+       View &_view;
+};
+
+} // namespace view
+} // namespace pv
+
+#endif // PV_VIEW_HEADER_H
index e0d3ada7be39df61149417fd6af1651703e90bca..e319b4fc82a8bb378a5dd345d038cef7e5d0228d 100644 (file)
@@ -26,6 +26,7 @@
 #include <QEvent>
 #include <QScrollBar>
 
+#include "header.h"
 #include "view.h"
 #include "viewport.h"
 
@@ -45,10 +46,13 @@ 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)),
+       _header(new Header(*this)),
        _data_length(0),
        _scale(1e-6),
        _offset(0),
@@ -60,6 +64,8 @@ View::View(SigSession &session, QWidget *parent) :
                this, SLOT(v_scroll_value_changed(int)));
        connect(&_session, SIGNAL(data_updated()),
                this, SLOT(data_updated()));
+
+       setViewportMargins(LabelMarginWidth, 0, 0, 0);
        setViewport(_viewport);
 }
 
@@ -150,6 +156,8 @@ bool View::viewportEvent(QEvent *e)
 
 void View::resizeEvent(QResizeEvent *e)
 {
+       _header->setGeometry(0, RulerHeight,
+               _viewport->x(), _viewport->height());
        update_scroll();
 }
 
@@ -162,6 +170,7 @@ void View::h_scroll_value_changed(int value)
 void View::v_scroll_value_changed(int value)
 {
        _v_offset = value;
+       _header->update();
        _viewport->update();
 }
 
index b7769899b7a09bf9d52988b4c469ed473be9fcca..ad607b5ac8ba517cc1ecbc5236c43411e0fb3d5f 100644 (file)
@@ -30,6 +30,7 @@ class SigSession;
 namespace pv {
 namespace view {
 
+class Header;
 class Viewport;
 
 class View : public QAbstractScrollArea {
@@ -42,6 +43,9 @@ private:
        static const int LabelMarginWidth;
        static const int RulerHeight;
 
+public:
+       static const int SignalHeight;
+
 public:
        explicit View(SigSession &session, QWidget *parent = 0);
 
@@ -75,6 +79,7 @@ private:
        SigSession &_session;
 
        Viewport *_viewport;
+       Header *_header;
 
        uint64_t _data_length;
 
index b8598bcb619534b597d66e9b9d21a071049f63b5..ee30965d603e12ee29994c49855ad71188977600 100644 (file)
@@ -39,8 +39,6 @@ using namespace std;
 namespace pv {
 namespace view {
 
-const int Viewport::SignalHeight = 50;
-
 const int Viewport::MinorTickSubdivision = 4;
 const int Viewport::ScaleUnits[3] = {1, 2, 5};
 
@@ -62,7 +60,7 @@ int Viewport::get_total_height() const
        BOOST_FOREACH(const shared_ptr<Signal> s,
                _view.session().get_signals()) {
                assert(s);
-               height += SignalHeight;
+               height += View::SignalHeight;
        }
 
        return height;
@@ -96,18 +94,18 @@ void Viewport::paintEvent(QPaintEvent *event)
 
        // Plot the signal
        glEnable(GL_SCISSOR_TEST);
-       glScissor(View::LabelMarginWidth, 0, width(), height());
+       glScissor(0, 0, width(), height());
        offset = View::RulerHeight - _view.v_offset();
        BOOST_FOREACH(const shared_ptr<Signal> s, sigs)
        {
                assert(s);
 
-               const QRect signal_rect(View::LabelMarginWidth, offset,
-                       width() - View::LabelMarginWidth, SignalHeight);
+               const QRect signal_rect(0, offset,
+                       width(), View::SignalHeight);
 
                s->paint(*this, signal_rect, _view.scale(), _view.offset());
 
-               offset += SignalHeight;
+               offset += View::SignalHeight;
        }
 
        glDisable(GL_SCISSOR_TEST);
@@ -119,19 +117,6 @@ void Viewport::paintEvent(QPaintEvent *event)
        QPainter painter(this);
        painter.setRenderHint(QPainter::Antialiasing);
 
-       // Paint the labels
-       offset = View::RulerHeight - _view.v_offset();
-       BOOST_FOREACH(const shared_ptr<Signal> s, sigs)
-       {
-               assert(s);
-
-               const QRect label_rect(0, offset,
-                       View::LabelMarginWidth, SignalHeight);
-               s->paint_label(painter, label_rect);
-
-               offset += SignalHeight;
-       }
-
        // Paint the ruler
        paint_ruler(painter);
 
@@ -167,8 +152,7 @@ void Viewport::mouseReleaseEvent(QMouseEvent *event)
 void Viewport::wheelEvent(QWheelEvent *event)
 {
        assert(event);
-       _view.zoom(event->delta() / 120, event->x() -
-               View::LabelMarginWidth);
+       _view.zoom(event->delta() / 120, event->x());
 }
 
 void Viewport::setup_viewport(int width, int height)
@@ -219,8 +203,7 @@ void Viewport::paint_ruler(QPainter &p)
        while(1)
        {
                const double t = t0 + division * minor_tick_period;
-               const double x = (t - _view.offset()) / _view.scale() +
-                       View::LabelMarginWidth;
+               const double x = (t - _view.offset()) / _view.scale();
 
                if(x >= width())
                        break;
index 46bf273358e769b2112dc913569bedce82f32f5f..690642c28c2de1f05cab75d86698bd7abdaad9fc 100644 (file)
@@ -38,8 +38,6 @@ class Viewport : public QGLWidget
        Q_OBJECT
 
 private:
-       static const int SignalHeight;
-
        static const int MinorTickSubdivision;
        static const int ScaleUnits[3];