signaldata.cpp
sigsession.cpp
signal.cpp
+ pv/view/header.cpp
pv/view/view.cpp
pv/view/viewport.cpp
)
mainwindow.h
samplingbar.h
sigsession.h
+ pv/view/header.h
pv/view/view.h
pv/view/viewport.h
)
--- /dev/null
+/*
+ * 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
--- /dev/null
+/*
+ * 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
#include <QEvent>
#include <QScrollBar>
+#include "header.h"
#include "view.h"
#include "viewport.h"
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),
this, SLOT(v_scroll_value_changed(int)));
connect(&_session, SIGNAL(data_updated()),
this, SLOT(data_updated()));
+
+ setViewportMargins(LabelMarginWidth, 0, 0, 0);
setViewport(_viewport);
}
void View::resizeEvent(QResizeEvent *e)
{
+ _header->setGeometry(0, RulerHeight,
+ _viewport->x(), _viewport->height());
update_scroll();
}
void View::v_scroll_value_changed(int value)
{
_v_offset = value;
+ _header->update();
_viewport->update();
}
namespace pv {
namespace view {
+class Header;
class Viewport;
class View : public QAbstractScrollArea {
static const int LabelMarginWidth;
static const int RulerHeight;
+public:
+ static const int SignalHeight;
+
public:
explicit View(SigSession &session, QWidget *parent = 0);
SigSession &_session;
Viewport *_viewport;
+ Header *_header;
uint64_t _data_length;
namespace pv {
namespace view {
-const int Viewport::SignalHeight = 50;
-
const int Viewport::MinorTickSubdivision = 4;
const int Viewport::ScaleUnits[3] = {1, 2, 5};
BOOST_FOREACH(const shared_ptr<Signal> s,
_view.session().get_signals()) {
assert(s);
- height += SignalHeight;
+ height += View::SignalHeight;
}
return height;
// 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);
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);
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)
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;
Q_OBJECT
private:
- static const int SignalHeight;
-
static const int MinorTickSubdivision;
static const int ScaleUnits[3];