]>
Commit | Line | Data |
---|---|---|
6fa02541 JH |
1 | /* |
2 | * This file is part of the sigrok project. | |
3 | * | |
4 | * Copyright (C) 2012 Joel Holdsworth <joel@airwebreathe.org.uk> | |
5 | * | |
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. | |
10 | * | |
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. | |
15 | * | |
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 | |
19 | */ | |
20 | ||
21 | #include "sigview.h" | |
22 | ||
009e1503 | 23 | #include "sigsession.h" |
e3f65ace JH |
24 | #include "signal.h" |
25 | ||
7cd5faf8 JH |
26 | #include <QMouseEvent> |
27 | ||
e3f65ace JH |
28 | #include <boost/foreach.hpp> |
29 | ||
30 | using namespace boost; | |
31 | using namespace std; | |
32 | ||
33 | const int SigView::SignalHeight = 50; | |
009e1503 JH |
34 | |
35 | SigView::SigView(SigSession &session, QWidget *parent) : | |
36 | QGLWidget(parent), | |
3b18c57d | 37 | _session(session), |
fb0d32cb | 38 | _scale(1e-6), |
3b18c57d | 39 | _offset(0) |
6fa02541 | 40 | { |
009e1503 JH |
41 | connect(&_session, SIGNAL(dataUpdated()), |
42 | this, SLOT(dataUpdated())); | |
43 | ||
d7002724 JH |
44 | setMouseTracking(true); |
45 | } | |
46 | ||
47 | void SigView::initializeGL() | |
48 | { | |
49 | glDisable(GL_TEXTURE_2D); | |
50 | glDisable(GL_DEPTH_TEST); | |
51 | glDisable(GL_COLOR_MATERIAL); | |
52 | glEnable(GL_BLEND); | |
53 | glEnable(GL_POLYGON_SMOOTH); | |
54 | glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); | |
55 | glClearColor(1.0, 1.0, 1.0, 0); | |
56 | } | |
57 | ||
58 | void SigView::resizeGL(int width, int height) | |
59 | { | |
60 | glViewport(0, 0, (GLint)width, (GLint)height); | |
61 | glMatrixMode(GL_PROJECTION); | |
62 | glLoadIdentity(); | |
63 | glOrtho(0, width, height, 0, -1, 1); | |
64 | glMatrixMode(GL_MODELVIEW); | |
65 | } | |
66 | ||
67 | void SigView::paintGL() | |
68 | { | |
69 | glClear(GL_COLOR_BUFFER_BIT); | |
e3f65ace JH |
70 | |
71 | QRect rect(0, 0, width(), SignalHeight); | |
72 | const vector< shared_ptr<Signal> > &sigs = | |
73 | _session.get_signals(); | |
74 | BOOST_FOREACH(const shared_ptr<Signal> s, sigs) | |
75 | { | |
76 | assert(s); | |
3b18c57d | 77 | s->paint(*this, rect, _scale, _offset); |
e3f65ace JH |
78 | rect.translate(0, SignalHeight); |
79 | } | |
6fa02541 | 80 | } |
009e1503 JH |
81 | |
82 | void SigView::dataUpdated() | |
83 | { | |
e3f65ace | 84 | update(); |
009e1503 JH |
85 | } |
86 | ||
7cd5faf8 JH |
87 | void SigView::mouseMoveEvent(QMouseEvent *event) |
88 | { | |
89 | assert(event); | |
90 | } | |
91 | ||
92 | void SigView::mousePressEvent(QMouseEvent *event) | |
93 | { | |
94 | assert(event); | |
95 | } | |
96 | ||
97 | void SigView::mouseReleaseEvent(QMouseEvent *event) | |
98 | { | |
99 | assert(event); | |
100 | ||
fb0d32cb JH |
101 | const double cursor_offset = _offset + _scale * (double)event->x(); |
102 | ||
7cd5faf8 JH |
103 | switch(event->button()) |
104 | { | |
105 | case Qt::LeftButton: | |
fb0d32cb | 106 | _scale *= 2.0 / 3.0; |
7cd5faf8 JH |
107 | break; |
108 | ||
109 | case Qt::RightButton: | |
fb0d32cb | 110 | _scale *= 3.0 / 2.0; |
7cd5faf8 JH |
111 | break; |
112 | } | |
113 | ||
fb0d32cb JH |
114 | _offset = cursor_offset - _scale * (double)event->x(); |
115 | ||
7cd5faf8 JH |
116 | updateGL(); |
117 | } | |
118 |