Debian Codegraph @

src/qutescope.h

raw symbols SCIP
1 /*
2 Copyright (C) 2008, 2009 Andres Cabrera
3 [email protected]
4
5 This file is part of CsoundQt.
6
7 CsoundQt is free software; you can redistribute it
8 and/or modify it under the terms of the GNU Lesser General Public
9 License as published by the Free Software Foundation; either
10 version 2.1 of the License, or (at your option) any later version.
11
12 CsoundQt is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU Lesser General Public License for more details.
16
17 You should have received a copy of the GNU Lesser General Public
18 License along with Csound; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
20 02111-1307 USA
21 */
22
23 #ifndef QUTESCOPE_H
24 #define QUTESCOPE_H
25
26 #include "qutewidget.h"
27 #include "csoundengine.h" //necessary for the CsoundUserData struct
28
29 class ScopeParams;
30 class DataDisplay;
31 class ScopeData;
32 class LissajouData;
33 class PoincareData;
34
35
36 enum TriggerMode {
37 NoTrigger = 0,
38 TriggerUp = 1
39 };
40
41 //
42 // To add a new kind of display you have to derive a class from the abstract
43 // class DataDisplay. This new class will be created in the constructor of
44 // the QuteScope class and referenced through a pointer, member of the
45 // later class.
46 // You have then to modify the QuteScope destructor and setType member
47 // accordingly.
48 // Finally the new type has to appear in the createPropertiesDialog method
49 //
50 class QuteScope : public QuteWidget
51 {
52 Q_OBJECT
53 public:
54 QuteScope(QWidget *parent);
55
56 ~QuteScope();
57
58 virtual QString getWidgetLine();
59 virtual QString getWidgetXmlText();
60 virtual QString getWidgetType();
61 // virtual void setWidgetGeometry(int x,int y,int width,int height);
62 virtual void createPropertiesDialog();
63 void setType(QString type);
64 void setValue(double value); //Value for this widget indicates zoom level
65 // void setChannel(int channel);
66 void setUd(CsoundUserData *ud);
67
68 virtual void applyInternalProperties();
69
70 protected:
71 // QString m_type;
72 // int m_channel;
73 // int m_zoom;
74 QLabel * m_label;
75 QComboBox *typeComboBox;
76 QComboBox *channelBox;
77 QComboBox *triggerBox;
78 QDoubleSpinBox *zoomxBox;
79 QDoubleSpinBox *zoomyBox;
80 ScopeParams *m_params;
81 DataDisplay *m_dataDisplay;
82 ScopeData *m_scopeData;
83 LissajouData *m_lissajouData;
84 PoincareData *m_poincareData;
85
86 virtual void resizeEvent(QResizeEvent * event);
87 virtual void applyProperties();
88 QReadWriteLock scopeLock;
89
90 private:
91 void updateLabel();
92
93 public slots:
94 void updateData();
95 };
96
97 class ScopeWidget : public QGraphicsView
98 {
99 Q_OBJECT
100 public:
101 ScopeWidget(QWidget* parent) : QGraphicsView(parent)
102 {
103 setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
104 setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
105 freeze = false;
106 setStyleSheet("QGraphicsView { border-style: none; }");
107 }
108 ~ScopeWidget() {}
109
110 bool freeze;
111
112 protected:
113 // virtual void contextMenuEvent(QContextMenuEvent *event)
114 // {emit(popUpMenu(event->globalPos()));}
115 virtual void mousePressEvent(QMouseEvent *event)
116 {
117 if (event->button() & Qt::LeftButton)
118 freeze = true;
119 }
120 virtual void mouseReleaseEvent(QMouseEvent * /* event */)
121 {
122 freeze = false;
123 }
124
125 // signals:
126 // void popUpMenu(QPoint pos);
127 };
128
129
130
131 //
132 // This class encapsulates data common to all types of displays
133 // ie ud (user data), scene, widget, mutex, width and height
134 //
135 class ScopeParams
136 {
137 public:
138 ScopeParams(CsoundUserData *ud, QGraphicsScene *scene, ScopeWidget *widget,
139 QReadWriteLock *mutex, int width, int height)
140 {
141 this->ud = ud;
142 this->scene = scene;
143 this->widget = widget;
144 this->mutex = mutex;
145 this->width = width;
146 this->height = height;
147 this->triggerMode = TriggerMode::NoTrigger;
148 }
149 void setWidth(int width)
150 {
151 this->width = width;
152 }
153 void setHeight(int height)
154 {
155 this->height = height;
156 }
157
158 CsoundUserData *ud;
159 QGraphicsScene *scene;
160 ScopeWidget *widget;
161 QReadWriteLock *mutex;
162 int width;
163 int height;
164 TriggerMode triggerMode;
165 };
166
167
168 //
169 // A custom QGraphicsItem to display sets of points
170 //
171 class ScopeItem : public QGraphicsItem
172 {
173 public:
174 ScopeItem(int width, int height);
175 QRectF boundingRect() const
176 {
177 return QRectF(-m_width/2, -m_height/2, m_width, m_height);
178 }
179 void paint(QPainter *p, const QStyleOptionGraphicsItem *option, QWidget *widget);
180 void setPen(const QPen & pen);
181 void setPolygon(const QPolygonF & polygon);
182 void setSize(int width, int height);
183
184 protected:
185 int m_width;
186 int m_height;
187 QPen m_pen;
188 QPolygonF m_polygon;
189 };
190
191
192 //
193 // Abstract base class for displays. The inherited classes will differ
194 // mainly through the updateData method
195 //
196 class DataDisplay
197 {
198 public:
199 DataDisplay(ScopeParams *params)
200 {
201 m_params = params;
202 }
203 virtual void resize() = 0;
204 virtual void updateData(int channel, double zoomx, double zoomy, bool freeze) = 0;
205 virtual void show() = 0;
206 virtual void hide() = 0;
207
208 protected:
209 ScopeParams *m_params;
210 };
211
212
213 //
214 // Display class for oscilloscope view
215 //
216 class ScopeData : public DataDisplay
217 {
218 public:
219 ScopeData(ScopeParams *params);
220 virtual ~ScopeData() {}
221 virtual void resize();
222 virtual void updateData(int channel, double zoomx, double zoomy, bool freeze);
223 virtual void show();
224 virtual void hide();
225
226
227 protected:
228 QPolygonF curveData;
229 QGraphicsPolygonItem *curve;
230
231 };
232
233
234 //
235 // Display class for Lissajou curves or two dimensional map
236 //
237 class LissajouData : public DataDisplay
238 {
239 public:
240 LissajouData(ScopeParams *params);
241 virtual ~LissajouData() {}
242 virtual void resize();
243 virtual void updateData(int channel, double zoomx, double zoomy, bool freeze);
244 virtual void show();
245 virtual void hide();
246
247 protected:
248 QPolygonF curveData;
249 ScopeItem *curve;
250 };
251
252
253 //
254 // Display class for Poincare map
255 //
256 class PoincareData : public DataDisplay
257 {
258 public:
259 PoincareData(ScopeParams *params);
260 virtual ~PoincareData() {}
261 virtual void resize();
262 virtual void updateData(int channel, double zoomx, double zoomy, bool freeze);
263 virtual void show();
264 virtual void hide();
265
266 protected:
267 QPolygonF curveData;
268 ScopeItem *curve;
269 double lastValue; // holds the last ordinate value to become abcsissa value of the next pass
270 };
271
272 #endif
273