Initial interractive zoom support
[pulseview.git] / sigview.cpp
index b682cce950cd22ddff85f4b6df8860e7a025979e..df1eefec2745fec15041766a4777d086d6e114eb 100644 (file)
 #include "sigview.h"
 
 #include "sigsession.h"
+#include "signal.h"
+
+#include <QMouseEvent>
+
+#include <boost/foreach.hpp>
+
+using namespace boost;
+using namespace std;
+
+const int SigView::SignalHeight = 50;
 
 SigView::SigView(SigSession &session, QWidget *parent) :
        QGLWidget(parent),
-        _session(session)
+        _session(session),
+       _scale(1000000000ULL),
+       _offset(0)
 {
        connect(&_session, SIGNAL(dataUpdated()),
                this, SLOT(dataUpdated()));
@@ -55,10 +67,48 @@ void SigView::resizeGL(int width, int height)
 void SigView::paintGL()
 {
        glClear(GL_COLOR_BUFFER_BIT);
+
+       QRect rect(0, 0, width(), SignalHeight);
+       const vector< shared_ptr<Signal> > &sigs =
+               _session.get_signals();
+       BOOST_FOREACH(const shared_ptr<Signal> s, sigs)
+       {
+               assert(s);
+               s->paint(*this, rect, _scale, _offset);
+               rect.translate(0, SignalHeight);
+       }
 }
 
 void SigView::dataUpdated()
 {
-       printf("Data Updated\n");
+       update();
+}
+
+void SigView::mouseMoveEvent(QMouseEvent *event)
+{
+       assert(event);
+}
+
+void SigView::mousePressEvent(QMouseEvent *event)
+{
+       assert(event);
+}
+
+void SigView::mouseReleaseEvent(QMouseEvent *event)
+{
+       assert(event);
+
+       switch(event->button())
+       {
+       case Qt::LeftButton:
+               _scale = (_scale * 2) / 3;
+               break;
+
+       case Qt::RightButton:
+               _scale = (_scale * 3) / 2;
+               break;
+       }
+
+       updateGL();
 }