X-Git-Url: http://git.code-monkey.de/?a=blobdiff_plain;f=sigview.cpp;h=4097ae5c25fe1f316b4cd9359dbe44b79bd8a8cf;hb=e5335d4f0973a90ef7f7f69095e9db36e3feb0cb;hp=ac7e76c8fe5185bd7fcd33bd75b7957ecb70e086;hpb=6fa02541c670ebdd8a1985a29aba798823469f64;p=pulseview.git diff --git a/sigview.cpp b/sigview.cpp index ac7e76c..4097ae5 100644 --- a/sigview.cpp +++ b/sigview.cpp @@ -20,7 +20,99 @@ #include "sigview.h" -SigView::SigView(QWidget *parent) : - QAbstractScrollArea(parent) +#include "sigsession.h" +#include "signal.h" + +#include + +#include + +using namespace boost; +using namespace std; + +const int SigView::SignalHeight = 50; + +SigView::SigView(SigSession &session, QWidget *parent) : + QGLWidget(parent), + _session(session), + _scale(1e-6), + _offset(0) +{ + connect(&_session, SIGNAL(dataUpdated()), + this, SLOT(dataUpdated())); + + setMouseTracking(true); +} + +void SigView::initializeGL() +{ + glDisable(GL_TEXTURE_2D); + glDisable(GL_DEPTH_TEST); + glDisable(GL_COLOR_MATERIAL); + glEnable(GL_BLEND); + glEnable(GL_POLYGON_SMOOTH); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + glClearColor(1.0, 1.0, 1.0, 0); +} + +void SigView::resizeGL(int width, int height) +{ + glViewport(0, 0, (GLint)width, (GLint)height); + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + glOrtho(0, width, height, 0, -1, 1); + glMatrixMode(GL_MODELVIEW); +} + +void SigView::paintGL() +{ + glClear(GL_COLOR_BUFFER_BIT); + + QRect rect(0, 0, width(), SignalHeight); + const vector< shared_ptr > &sigs = + _session.get_signals(); + BOOST_FOREACH(const shared_ptr s, sigs) + { + assert(s); + s->paint(*this, rect, _scale, _offset); + rect.translate(0, SignalHeight); + } +} + +void SigView::dataUpdated() +{ + update(); +} + +void SigView::mouseMoveEvent(QMouseEvent *event) { + assert(event); } + +void SigView::mousePressEvent(QMouseEvent *event) +{ + assert(event); +} + +void SigView::mouseReleaseEvent(QMouseEvent *event) +{ + assert(event); + + const double cursor_offset = _offset + _scale * (double)event->x(); + + switch(event->button()) + { + case Qt::LeftButton: + _scale *= 2.0 / 3.0; + break; + + case Qt::RightButton: + _scale *= 3.0 / 2.0; + break; + } + + _offset = cursor_offset - _scale * (double)event->x(); + + updateGL(); +} +