๐Ÿ“ฆ motiz88 / GR-55Floorboard

๐Ÿ“„ customGraphicEQGraph.cpp ยท 473 lines
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
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473/****************************************************************************
**
** Copyright (C) 2007~2013 Colin Willcocks.
** Copyright (C) 2005~2007 Uco Mesdag.
** All rights reserved.
** This file is part of "GR-55B FloorBoard".
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License along
** with this program; if not, write to the Free Software Foundation, Inc.,
** 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
**
****************************************************************************/

#include "customGraphicEQGraph.h"
//#include <QMessageBox>
#include <QPainter>
#include <QMouseEvent>

customGraphicEQGraph::customGraphicEQGraph (QWidget *parent) : poly(13), m_iDragNode(-1)
{
    QFrame::setFrameShape(QFrame::Panel);
    QFrame::setFrameShadow(QFrame::Sunken);

}

customGraphicEQGraph::~customGraphicEQGraph (void)
{
}

void customGraphicEQGraph::setBand_1 ( unsigned short iBand_1 )
{
    if (iBand_1 > 24) iBand_1 = 24;
    if (m_iBand_1 != iBand_1) {
        m_iBand_1  = iBand_1;
        update();
        emit Band_1Changed(Band_1());
    };
}

unsigned short customGraphicEQGraph::Band_1 (void) const
{
    return m_iBand_1;
}


void customGraphicEQGraph::setBand_2 ( unsigned short iBand_2 )
{
    if (iBand_2 > 24) iBand_2 = 24;
    if (m_iBand_2 != iBand_2) {
        m_iBand_2  = iBand_2;
        update();
        emit Band_2Changed(Band_2());
    };
}

unsigned short customGraphicEQGraph::Band_2 (void) const
{
    return m_iBand_2;
}


void customGraphicEQGraph::setBand_3 ( unsigned short iBand_3 )
{
    if (iBand_3 > 24) iBand_3 = 24;
    if (m_iBand_3 != iBand_3) {
        m_iBand_3  = iBand_3;
        update();
        emit Band_3Changed(Band_3());
    };
}

unsigned short customGraphicEQGraph::Band_3 (void) const
{
    return m_iBand_3;
}


void customGraphicEQGraph::setBand_4 ( unsigned short iBand_4 )
{
    if (iBand_4 > 24) iBand_4 = 24;
    if (m_iBand_4 != iBand_4) {
        m_iBand_4  = iBand_4;
        update();
        emit Band_4Changed(Band_4());
    }
}

unsigned short customGraphicEQGraph::Band_4 (void) const
{
    return m_iBand_4;
}


void customGraphicEQGraph::setBand_5 ( unsigned short iBand_5 )
{
    if (iBand_5 > 24) iBand_5 = 24;
    if (m_iBand_5 != iBand_5) {
        m_iBand_5  = iBand_5;
        update();
        emit Band_5Changed(Band_5());
    }
}

unsigned short customGraphicEQGraph::Band_5 (void) const
{
    return m_iBand_5;
}


void customGraphicEQGraph::setBand_6 ( unsigned short iBand_6 )
{
    if (iBand_6 > 24) iBand_6 = 24;
    if (m_iBand_6 != iBand_6) {
        m_iBand_6  = iBand_6;
        update();
        emit Band_6Changed(Band_6());
    }
}

unsigned short customGraphicEQGraph::Band_6 (void) const
{
    return m_iBand_6;
}

void customGraphicEQGraph::setBand_7 ( unsigned short iBand_7 )
{
    if (iBand_7 > 24) iBand_7 = 24;
    if (m_iBand_7 != iBand_7) {
        m_iBand_7  = iBand_7;
        update();
        emit Band_7Changed(Band_7());
    }
}

unsigned short customGraphicEQGraph::Band_7 (void) const
{
    return m_iBand_7;
}


void customGraphicEQGraph::setBand_8 ( unsigned short iBand_8 )
{
    if (iBand_8 > 24) iBand_8 = 24;
    if (m_iBand_8 != iBand_8) {
        m_iBand_8  = iBand_8;
        update();
        emit Band_8Changed(Band_8());
    }
}

unsigned short customGraphicEQGraph::Band_8 (void) const
{
    return m_iBand_8;
}

void customGraphicEQGraph::setBand_9 ( unsigned short iBand_9 )
{
    if (iBand_9 > 24) iBand_9 = 24;
    if (m_iBand_9 != iBand_9) {
        m_iBand_9  = iBand_9;
        update();
        emit Band_9Changed(Band_9());
    };
}

unsigned short customGraphicEQGraph::Band_9 (void) const
{
    return m_iBand_9;
}

void customGraphicEQGraph::setBand_10 ( unsigned short iBand_10 )
{
    if (iBand_10 > 24) iBand_10 = 24;
    if (m_iBand_10 != iBand_10) {
        m_iBand_10  = iBand_10;
        update();
        emit Band_10Changed(Band_10());
    };
}

unsigned short customGraphicEQGraph::Band_10 (void) const
{
    return m_iBand_10;
}

void customGraphicEQGraph::setLevel ( unsigned short iLevel )
{
    if (iLevel > 24) iLevel = 24;
    if (m_iLevel != iLevel) {
        m_iLevel  = iLevel;
        update();
        emit LevelChanged(Level());
    };
}

unsigned short customGraphicEQGraph::Level (void) const
{
    return m_iLevel;
}

void customGraphicEQGraph::paintEvent ( QPaintEvent *pPaintEvent )
{
    QPixmap image = QPixmap(":images/EQ_graph.png");
    QRectF target(0.0, 0.0, image.width()*85/100, image.height()*43/100);
    QRectF source(0.0, 0.0, image.width(), image.height());

    QPainter painter(this);
    painter.drawPixmap(target, image, source);

    int h  = height();
    int w  = width();

    int b1 = h - (m_iBand_1*4) - 25;
    int b2 = h - (m_iBand_2*4) - 25;
    int b3 = h - (m_iBand_3*4) - 25;
    int b4 = h - (m_iBand_4*4) - 25;
    int b5 = h - (m_iBand_5*4) - 25;
    int b6 = h - (m_iBand_6*4) - 25;
    int b7 = h - (m_iBand_7*4) - 25;
    int b8 = h - (m_iBand_8*4) - 25;
    int b9 = h - (m_iBand_9*4) - 25;
    int b10 = h - (m_iBand_10*4) - 25;

    int lev = h/6 - (m_iLevel*4);

    QLinearGradient grad(0, 0, w << 1, h << 1);
    grad.setColorAt(0.0f, Qt::yellow);
    grad.setColorAt(1.0f, Qt::black);

    int spacer = w/9;
    poly.putPoints(0, 13,
                   0,    h,
                   0,    b1+lev,
                   spacer*1, b2+lev,
                   spacer*2, b3+lev,
                   spacer*3, b4+lev,
                   spacer*4, b5+lev,
                   spacer*5, b6+lev,
                   spacer*6, b7+lev,
                   spacer*7, b8+lev,
                   spacer*8, b9+lev,
                   spacer*9, b10+lev,
                   w,    b10+lev,
                   w,    h     );

    QPainterPath path;
    path.moveTo(poly.at(0));
    path.addPolygon(poly);

    painter.setPen(Qt::yellow);
    painter.setBrush(grad);
    painter.drawPath((path));

    painter.setBrush(Qt::red);
    painter.drawRect(nodeRect(1));
    painter.drawRect(nodeRect(2));
    painter.drawRect(nodeRect(3));
    painter.drawRect(nodeRect(4));
    painter.drawRect(nodeRect(5));
    painter.drawRect(nodeRect(6));
    painter.drawRect(nodeRect(7));
    painter.drawRect(nodeRect(8));
    painter.drawRect(nodeRect(9));
    painter.drawRect(nodeRect(10));

    painter.end();
    QFrame::paintEvent(pPaintEvent);
}

void customGraphicEQGraph::mousePressEvent ( QMouseEvent *pMouseEvent )
{
    if (pMouseEvent->button() == Qt::LeftButton) {
        const QPoint& pos = pMouseEvent->pos();
        int iDragNode = nodeIndex(pos);
        if (iDragNode >= 0) {setCursor(Qt::SizeVerCursor);
            m_iDragNode = iDragNode;
            m_posDrag = pos;
        }
    }
    QFrame::mousePressEvent(pMouseEvent);
}


void customGraphicEQGraph::mouseMoveEvent ( QMouseEvent *pMouseEvent )
{

    dragNode(pMouseEvent->pos());
}


void customGraphicEQGraph::mouseReleaseEvent ( QMouseEvent *pMouseEvent )
{
    QFrame::mouseReleaseEvent(pMouseEvent);

    dragNode(pMouseEvent->pos());

    if (m_iDragNode >= 0) {
        m_iDragNode = -1;
        unsetCursor();
    }
}


QRect customGraphicEQGraph::nodeRect ( int iNode ) const
{
    const QPoint& pos = poly.at(iNode);
    return QRect(pos.x() - 10, pos.y() - 4, 20, 8);
}


int customGraphicEQGraph::nodeIndex ( const QPoint& pos ) const
{
    if (nodeRect(10).contains(pos))
        return 10; // Band_10

    if (nodeRect(9).contains(pos))
        return 9; // Band_9

    if (nodeRect(8).contains(pos))
        return 8; // Band_8

    if (nodeRect(7).contains(pos))
        return 7; // Band_7

    if (nodeRect(6).contains(pos))
        return 6; // Band_6

    if (nodeRect(5).contains(pos))
        return 5; // Band_5

    if (nodeRect(4).contains(pos))
        return 4; // Band_4

    if (nodeRect(3).contains(pos))
        return 3; // Band_3

    if (nodeRect(2).contains(pos))
        return 2; // Band_2

    if (nodeRect(1).contains(pos))
        return 1; //Band_1

    return -1;
}

void customGraphicEQGraph::dragNode ( const QPoint& pos )
{
    unsigned short *piLevel = NULL;
    switch (m_iDragNode) {
    case 1: // Band_1
        piLevel = &m_iBand_1;
        break;
    case 2: // Band_2
        piLevel = &m_iBand_2;
        break;
    case 3: // Band_3/
        piLevel = &m_iBand_3;
        break;
    case 4: // Band_4
        piLevel = &m_iBand_4;
        break;
    case 5: // Band_5
        piLevel = &m_iBand_5;
        break;
    case 6: // Band_6
        piLevel = &m_iBand_6;
        break;
    case 7: // Band_7
        piLevel = &m_iBand_7;
        break;
    case 8: // Band_8
        piLevel = &m_iBand_8;
    case 9: // Band_9
        piLevel = &m_iBand_9;
        break;
    case 10: // Band_10
        piLevel = &m_iBand_10;
        break;
    }

    if (piLevel) {
        int iLevel = int(*piLevel) + ((m_posDrag.y() - pos.y()) << 5) / height();
        if (iLevel < 0) iLevel = 0;
        else if (iLevel > 24) iLevel = 24;
        if (*piLevel != (unsigned short) iLevel) {
            m_posDrag = pos;
            switch (m_iDragNode) {
            case 1: // Band_1
                setBand_1(iLevel);
                break;
            case 2: // Band_2
                setBand_2(iLevel);
                break;
            case 3: // Band_3
                setBand_3(iLevel);
                break;
            case 4: // Band_4
                setBand_4(iLevel);
                break;
            case 5: // Band_5
                setBand_5(iLevel);
                break;
            case 6: // Band_6
                setBand_6(iLevel);
                break;
            case 7: // Band_7
                setBand_7(iLevel);
                break;
            case 8: // Band_8
                setBand_8(iLevel);
                break;
            case 9: // Band_9
                setBand_9(iLevel);
                break;
            case 10: // Band_10
                setBand_10(iLevel);
                break;
            }
        }
    } else if (nodeIndex(pos) >= 0) {
        setCursor(Qt::PointingHandCursor);
    } else {
        unsetCursor();
    }
}

void customGraphicEQGraph::updateSlot(  QString hex_1, QString hex_2, QString hex_3,
                                        QString hex_4, QString hex_5, QString hex_6,
                                        QString hex_7, QString hex_8, QString hex_9,
                                        QString hex_10, QString hex_11)
{
    this->hex_1 = hex_1;
    this->hex_2 = hex_2;
    this->hex_3 = hex_3;
    this->hex_4 = hex_4;
    this->hex_5 = hex_5;
    this->hex_6 = hex_6;
    this->hex_7 = hex_7;
    this->hex_8 = hex_8;
    this->hex_9 = hex_9;
    this->hex_10 = hex_10;
    this->hex_11 = hex_11;
    bool ok;
    setBand_1(this->hex_1.toShort(&ok, 16));
    setBand_2(this->hex_2.toShort(&ok, 16));
    setBand_3(this->hex_3.toShort(&ok, 16));
    setBand_4(this->hex_4.toShort(&ok, 16));
    setBand_5(this->hex_5.toShort(&ok, 16));
    setBand_6(this->hex_6.toShort(&ok, 16));
    setBand_7(this->hex_7.toShort(&ok, 16));
    setBand_8(this->hex_8.toShort(&ok, 16));
    setBand_9(this->hex_9.toShort(&ok, 16));
    setBand_10(this->hex_10.toShort(&ok, 16));
    setLevel(this->hex_11.toShort(&ok, 16));

}