-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlaupalettewidget.h
335 lines (278 loc) · 9.94 KB
/
laupalettewidget.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
#ifndef LAUPALETTEGEARWIDGET_H
#define LAUPALETTEGEARWIDGET_H
#include <QtCore>
#include <QImage>
#include <QLabel>
#include <QPainter>
#include <QtWidgets>
#include <QtSerialPort>
#include "lauzeroconfwidget.h"
#define LAUPALETTEOBJECTSIZE 80
#define LAUPALETTEOBJECTLAMBDA (float)LAUPALETTEOBJECTSIZE/100.0f
/****************************************************************************/
/****************************************************************************/
/****************************************************************************/
class LAUPaletteObject : public QObject
{
Q_OBJECT
public:
enum Orientation { OrientationA = 0, OrientationB = 1, OrientationC = 2, OrientationD = 3, OrientationE = 4 };
enum Palette { PaletteBase = 0, PaletteButton = 1, PaletteDial = 2, PaletteSlider = 3, PaletteNone = 4 };
LAUPaletteObject(unsigned int id, Palette typ, QObject *parent = 0) : QObject(parent), value(0), paletteID(id), paletteType(typ) { ; }
LAUPaletteObject(unsigned int id, Palette typ, QTransform trans, QObject *parent = 0) : QObject(parent), value(0), paletteID(id), paletteType(typ), transform(trans) { ; }
Palette type() const
{
return (paletteType);
}
unsigned int identity() const
{
return (paletteID);
}
QTransform position() const
{
return (transform);
}
void setPosition(QTransform tran)
{
transform = tran;
}
virtual void draw(QPainter *painter) const = 0;
static QTransform neighborTransform(int i, QTransform transform);
virtual Orientation orientation() const;
virtual QPoint location(int a = 0) const;
public slots:
virtual void onValueChanged(int val) = 0;
virtual void onValueChanged(unsigned id, QList<int> samples) = 0;
protected:
int value;
private:
unsigned int paletteID;
Palette paletteType;
QTransform transform;
signals:
void emitValueChanged(int val);
void emitDialRotated(int val);
void emitButtonPressed();
void emitButtonReleased();
};
/****************************************************************************/
/****************************************************************************/
/****************************************************************************/
class LAUPaletteBase : public LAUPaletteObject
{
Q_OBJECT
public:
LAUPaletteBase(unsigned int id, QObject *parent = 0) : LAUPaletteObject(id, PaletteBase, parent) { ; }
LAUPaletteBase(unsigned int id, QTransform trans, QObject *parent = 0) : LAUPaletteObject(id, PaletteBase, trans, parent) { ; }
void draw(QPainter *painter) const;
public slots:
void onValueChanged(int val)
{
Q_UNUSED(val);
}
void onValueChanged(unsigned int id, QList<int> samples)
{
Q_UNUSED(id);
Q_UNUSED(samples);
}
};
/****************************************************************************/
/****************************************************************************/
/****************************************************************************/
class LAUPaletteButton : public LAUPaletteObject
{
Q_OBJECT
public:
LAUPaletteButton(unsigned int id, QObject *parent = 0) : LAUPaletteObject(id, PaletteButton, parent) { ; }
LAUPaletteButton(unsigned int id, QTransform trans, QObject *parent = 0) : LAUPaletteObject(id, PaletteButton, trans, parent) { ; }
void draw(QPainter *painter) const;
public slots:
void onValueChanged(int val)
{
Q_UNUSED(val);
}
void onValueChanged(unsigned id, QList<int> samples)
{
if (id == identity()) {
value = samples.at(0);
emit emitValueChanged(value);
if (value == 1) {
emit emitButtonPressed();
} else {
emit emitButtonReleased();
}
}
}
};
/****************************************************************************/
/****************************************************************************/
/****************************************************************************/
class LAUPaletteDial : public LAUPaletteObject
{
Q_OBJECT
public:
LAUPaletteDial(unsigned int id, QObject *parent = 0) : LAUPaletteObject(id, PaletteDial, parent), upDownFlag(true) { ; }
LAUPaletteDial(unsigned int id, QTransform trans, QObject *parent = 0) : LAUPaletteObject(id, PaletteDial, trans, parent), upDownFlag(true) { ; }
void draw(QPainter *painter) const;
public slots:
void onValueChanged(int val)
{
Q_UNUSED(val);
}
void onValueChanged(unsigned int id, QList<int> samples)
{
if (id == identity()) {
// SEE IF BUTTON WAS TOGGLED
if (upDownFlag != (samples.at(0) == 0)) {
upDownFlag = (samples.at(0) == 0);
// SEE IF BUTTON WAS PRESSED OR RELEASED
if (upDownFlag == true) {
emit emitButtonReleased();
} else {
emit emitButtonPressed();
}
}
value = samples.at(3);
emit emitValueChanged(value);
emit emitDialRotated(samples.at(2) - samples.at(1));
}
}
private:
bool upDownFlag;
};
/****************************************************************************/
/****************************************************************************/
/****************************************************************************/
class LAUPaletteSlider : public LAUPaletteObject
{
Q_OBJECT
public:
LAUPaletteSlider(unsigned int id, QObject *parent = 0) : LAUPaletteObject(id, PaletteSlider, parent) { ; }
LAUPaletteSlider(unsigned int id, QTransform trans, QObject *parent = 0) : LAUPaletteObject(id, PaletteSlider, trans, parent) { ; }
void draw(QPainter *painter) const;
QPoint location(int a = 0) const;
public slots:
void onValueChanged(int val)
{
Q_UNUSED(val);
}
void onValueChanged(unsigned int id, QList<int> samples)
{
if (id == identity()) {
value = samples.at(0);
switch (orientation()) {
case LAUPaletteObject::OrientationA:
emit emitValueChanged(value);
break;
case LAUPaletteObject::OrientationB:
emit emitValueChanged(value);
break;
case LAUPaletteObject::OrientationC:
emit emitValueChanged(255 - value);
break;
case LAUPaletteObject::OrientationD:
emit emitValueChanged(255 - value);
break;
case LAUPaletteObject::OrientationE:
break;
}
}
}
};
/****************************************************************************/
/****************************************************************************/
/****************************************************************************/
class LAUPalette : public QObject
{
Q_OBJECT
public:
typedef struct {
QPoint pos;
LAUPaletteObject::Palette pal;
} Packet;
LAUPalette(QString portString = QString(), QObject *parent = 0);
LAUPalette(QString ipAddr, int portNum, QObject *parent = 0);
~LAUPalette();
bool connectPort();
bool registerLayout(QList<LAUPalette::Packet> list);
QRect boundingBox();
void draw(QPainter *painter)
{
for (int n = 0; n < palettes.count(); n++) {
palettes.at(n)->draw(painter);
}
}
LAUPaletteObject *whatsAt(QPoint point);
private:
QString ipAddress;
int portNumber;
QIODevice *port;
QString errorString;
QList<LAUPalette::Packet> packets;
QList<LAUPaletteObject *> palettes;
void processLayout(QJsonObject object, QTransform transform = QTransform());
private slots:
void onReadyRead();
void onConnected();
void onDisconnected();
void onTcpError(QAbstractSocket::SocketError error);
void onValueChanged(int val);
void onDialRotated(int val);
void onButtonPressed();
void onButtonReleased();
signals:
void emitUpdate();
void emitConnected();
void emitDisconnected();
void emitError(QString string);
void emitValueChanged(QPoint pos, int val);
void emitDialRotated(QPoint pos, int val);
void emitButtonPressed(QPoint pos);
void emitButtonReleased(QPoint pos);
};
/****************************************************************************/
/****************************************************************************/
/****************************************************************************/
class LAUPaletteLabel : public QLabel
{
Q_OBJECT
public:
LAUPaletteLabel(QWidget *parent = 0) : QLabel(parent) { ; }
void setPalette(LAUPalette *pal)
{
palette = pal;
update();
}
protected:
void paintEvent(QPaintEvent *event);
private:
LAUPalette *palette;
};
/****************************************************************************/
/****************************************************************************/
/****************************************************************************/
class LAUPaletteWidget : public QWidget
{
Q_OBJECT
public:
LAUPaletteWidget(QString string = QString("Palette Gear"), QList<LAUPalette::Packet> list = QList<LAUPalette::Packet>(), QWidget *parent = 0);
~LAUPaletteWidget();
void registerLayout(QList<LAUPalette::Packet> list);
virtual void paletteDisconnected() { ; }
virtual void paletteConnected() { ; }
public slots:
virtual void onConnected();
virtual void onDisconnected();
virtual void onError(QString string);
virtual void onValueChanged(QPoint pos, int val);
virtual void onDialRotated(QPoint pos, int val);
virtual void onButtonPressed(QPoint pos);
virtual void onButtonReleased(QPoint pos);
protected:
LAUPalette *palette;
LAUPaletteLabel *label;
unsigned int paletteState;
QList<LAUPalette::Packet> packets;
QString deviceString;
};
#endif // LAUPALETTEGEARWIDGET_H