2 * This file is part of the sigrok project.
4 * Copyright (C) 2012 Joel Holdsworth <joel@airwebreathe.org.uk>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23 #include "sigsession.h"
26 #include <QMouseEvent>
28 #include <boost/foreach.hpp>
30 using namespace boost;
33 const int SigView::SignalHeight = 50;
34 const int SigView::LabelMarginWidth = 70;
36 SigView::SigView(SigSession &session, QWidget *parent) :
42 connect(&_session, SIGNAL(dataUpdated()),
43 this, SLOT(dataUpdated()));
45 setMouseTracking(true);
46 setAutoFillBackground(false);
49 void SigView::initializeGL()
53 void SigView::resizeGL(int width, int height)
55 setupViewport(width, height);
58 void SigView::paintEvent(QPaintEvent *event)
62 const vector< shared_ptr<Signal> > &sigs =
63 _session.get_signals();
65 // Prepare for OpenGL rendering
67 glMatrixMode(GL_MODELVIEW);
70 setupViewport(width(), height());
72 qglClearColor(Qt::white);
73 glClear(GL_COLOR_BUFFER_BIT);
77 BOOST_FOREACH(const shared_ptr<Signal> s, sigs)
81 const QRect signal_rect(LabelMarginWidth, offset,
82 width() - LabelMarginWidth, SignalHeight);
84 s->paint(*this, signal_rect, _scale, _offset);
86 offset += SignalHeight;
89 // Prepare for QPainter rendering
90 glMatrixMode(GL_MODELVIEW);
93 QPainter painter(this);
94 painter.setRenderHint(QPainter::Antialiasing);
98 BOOST_FOREACH(const shared_ptr<Signal> s, sigs)
102 const QRect label_rect(0, offset,
103 LabelMarginWidth, SignalHeight);
104 s->paint_label(painter, label_rect);
106 offset += SignalHeight;
112 void SigView::dataUpdated()
117 void SigView::mouseMoveEvent(QMouseEvent *event)
122 void SigView::mousePressEvent(QMouseEvent *event)
127 void SigView::mouseReleaseEvent(QMouseEvent *event)
131 const double cursor_offset = _offset + _scale * (double)event->x();
133 switch(event->button())
139 case Qt::RightButton:
144 _offset = cursor_offset - _scale * (double)event->x();
149 void SigView::setupViewport(int width, int height)
151 glViewport(0, 0, (GLint)width, (GLint)height);
152 glMatrixMode(GL_PROJECTION);
154 glOrtho(0, width, height, 0, -1, 1);
155 glMatrixMode(GL_MODELVIEW);