+#include "sigsession.h"
+#include "signal.h"
+
+#include "extdef.h"
+
+#include <QMouseEvent>
+#include <QTextStream>
+
+#include <math.h>
+
+#include <boost/foreach.hpp>
+
+using namespace boost;
+using namespace std;
+
+const int SigView::SignalHeight = 50;
+const int SigView::LabelMarginWidth = 70;
+const int SigView::RulerHeight = 30;
+
+const int SigView::MinorTickSubdivision = 4;
+const int SigView::ScaleUnits[3] = {1, 2, 5};
+
+const QString SigView::SIPrefixes[9] =
+ {"f", "p", "n", QChar(0x03BC), "m", "", "k", "M", "G"};
+const int SigView::FirstSIPrefixPower = -15;
+
+SigView::SigView(SigSession &session, QWidget *parent) :
+ QGLWidget(parent),
+ _session(session),
+ _scale(1e-6),
+ _offset(0)
+{
+ connect(&_session, SIGNAL(data_updated()),
+ this, SLOT(data_updated()));
+
+ setMouseTracking(true);
+ setAutoFillBackground(false);
+}
+
+void SigView::initializeGL()
+{
+}
+
+void SigView::resizeGL(int width, int height)
+{
+ setup_viewport(width, height);
+}
+
+void SigView::paintEvent(QPaintEvent *event)
+{
+ int offset;
+
+ const vector< shared_ptr<Signal> > &sigs =
+ _session.get_signals();
+
+ // Prepare for OpenGL rendering
+ makeCurrent();
+ glMatrixMode(GL_MODELVIEW);
+ glPushMatrix();
+
+ setup_viewport(width(), height());
+
+ qglClearColor(Qt::white);
+ glClear(GL_COLOR_BUFFER_BIT);
+
+ // Plot the signal
+ offset = RulerHeight;
+ BOOST_FOREACH(const shared_ptr<Signal> s, sigs)
+ {
+ assert(s);
+
+ const QRect signal_rect(LabelMarginWidth, offset,
+ width() - LabelMarginWidth, SignalHeight);
+
+ s->paint(*this, signal_rect, _scale, _offset);
+
+ offset += SignalHeight;
+ }
+
+ // Prepare for QPainter rendering
+ glMatrixMode(GL_MODELVIEW);
+ glPopMatrix();
+
+ QPainter painter(this);
+ painter.setRenderHint(QPainter::Antialiasing);
+
+ // Paint the labels
+ offset = RulerHeight;
+ BOOST_FOREACH(const shared_ptr<Signal> s, sigs)
+ {
+ assert(s);
+
+ const QRect label_rect(0, offset,
+ LabelMarginWidth, SignalHeight);
+ s->paint_label(painter, label_rect);
+
+ offset += SignalHeight;
+ }
+
+ // Paint the ruler
+ paint_ruler(painter);
+
+ painter.end();
+}
+
+void SigView::data_updated()
+{
+ update();
+}
+
+void SigView::mousePressEvent(QMouseEvent *event)
+{
+ assert(event);
+
+ _mouse_down_point = event->pos();
+ _mouse_down_offset = _offset;
+}
+
+void SigView::mouseMoveEvent(QMouseEvent *event)