From 1d8dca913d07df3a53184e40246eb2e333520e31 Mon Sep 17 00:00:00 2001 From: Joel Holdsworth Date: Sat, 8 Sep 2012 09:45:09 +0100 Subject: [PATCH] Initial work moving headers into the pv::view::Header widget --- CMakeLists.txt | 2 ++ pv/view/header.cpp | 70 ++++++++++++++++++++++++++++++++++++++++++++ pv/view/header.h | 48 ++++++++++++++++++++++++++++++ pv/view/view.cpp | 9 ++++++ pv/view/view.h | 5 ++++ pv/view/viewport.cpp | 31 +++++--------------- pv/view/viewport.h | 2 -- 7 files changed, 141 insertions(+), 26 deletions(-) create mode 100644 pv/view/header.cpp create mode 100644 pv/view/header.h diff --git a/CMakeLists.txt b/CMakeLists.txt index db0d5f9b..d5818694 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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 index 00000000..bf003a4b --- /dev/null +++ b/pv/view/header.cpp @@ -0,0 +1,70 @@ +/* + * This file is part of the sigrok project. + * + * Copyright (C) 2012 Joel Holdsworth + * + * 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 + +#include + +#include +#include + +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 > &sigs = + _view.session().get_signals(); + + QPainter painter(this); + painter.setRenderHint(QPainter::Antialiasing); + + int offset = -_view.v_offset(); + BOOST_FOREACH(const shared_ptr 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 index 00000000..36b786c6 --- /dev/null +++ b/pv/view/header.h @@ -0,0 +1,48 @@ +/* + * This file is part of the sigrok project. + * + * Copyright (C) 2012 Joel Holdsworth + * + * 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 + +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 diff --git a/pv/view/view.cpp b/pv/view/view.cpp index e0d3ada7..e319b4fc 100644 --- a/pv/view/view.cpp +++ b/pv/view/view.cpp @@ -26,6 +26,7 @@ #include #include +#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(); } diff --git a/pv/view/view.h b/pv/view/view.h index b7769899..ad607b5a 100644 --- a/pv/view/view.h +++ b/pv/view/view.h @@ -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; diff --git a/pv/view/viewport.cpp b/pv/view/viewport.cpp index b8598bcb..ee30965d 100644 --- a/pv/view/viewport.cpp +++ b/pv/view/viewport.cpp @@ -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 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 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 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; diff --git a/pv/view/viewport.h b/pv/view/viewport.h index 46bf2733..690642c2 100644 --- a/pv/view/viewport.h +++ b/pv/view/viewport.h @@ -38,8 +38,6 @@ class Viewport : public QGLWidget Q_OBJECT private: - static const int SignalHeight; - static const int MinorTickSubdivision; static const int ScaleUnits[3]; -- 2.30.2