• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

mcallegari / qlcplus / 9226455509

24 May 2024 03:34PM UTC coverage: 31.637% (-0.4%) from 32.007%
9226455509

Pull #1422

github

web-flow
Merge 9870df2c8 into b9e7b67e6
Pull Request #1422: RgbScript make stage colors available to scripts

60 of 910 new or added lines in 11 files covered. (6.59%)

9 existing lines in 4 files now uncovered.

15421 of 48743 relevant lines covered (31.64%)

22674.46 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/ui/src/virtualconsole/vcmatrix.cpp
1
/*
2
  Q Light Controller Plus
3
  vcmatrix.cpp
4

5
  Copyright (c) Massimo Callegari
6

7
  Licensed under the Apache License, Version 2.0 (the "License");
8
  you may not use this file except in compliance with the License.
9
  You may obtain a copy of the License at
10

11
      http://www.apache.org/licenses/LICENSE-2.0.txt
12

13
  Unless required by applicable law or agreed to in writing, software
14
  distributed under the License is distributed on an "AS IS" BASIS,
15
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
  See the License for the specific language governing permissions and
17
  limitations under the License.
18
*/
19

20
#include <QXmlStreamReader>
21
#include <QXmlStreamWriter>
22
#include <QWidgetAction>
23
#include <QComboBox>
24
#include <QSettings>
25
#include <QLayout>
26
#include <QDebug>
27
#include <QTimer>
28
#include <QLabel>
29
#include <QMenu>
30
#include <math.h>
31

32
#include "vcmatrixproperties.h"
33
#include "vcpropertieseditor.h"
34
#include "clickandgoslider.h"
35
#include "clickandgowidget.h"
36
#include "knobwidget.h"
37
#include "qlcmacros.h"
38
#include "rgbalgorithm.h"
39
#include "flowlayout.h"
40
#include "rgbmatrix.h"
41
#include "vcmatrix.h"
42
#include "function.h"
43
#include "rgbtext.h"
44
#include "doc.h"
45

46
#define UPDATE_TIMEOUT 50
47

48
static const QString controlBtnSS = "QPushButton { background-color: %1; height: 32px; border: 2px solid #6A6A6A; border-radius: 5px; }"
49
                                    "QPushButton:pressed { border: 2px solid #0000FF; }"
50
                                    "QPushButton:disabled { border: 2px solid #BBBBBB; color: #8f8f8f }";
51

52
const QSize VCMatrix::defaultSize(QSize(160, 120));
53

54
VCMatrix::VCMatrix(QWidget *parent, Doc *doc)
×
55
    : VCWidget(parent, doc)
56
    , m_sliderExternalMovement(false)
57
    , m_matrixID(Function::invalidId())
×
58
    , m_instantApply(true)
59
    , m_visibilityMask(VCMatrix::defaultVisibilityMask())
×
60
{
61
    /* Set the class name "VCMatrix" as the object name as well */
62
    setObjectName(VCMatrix::staticMetaObject.className());
×
63
    setFrameStyle(KVCFrameStyleSunken);
×
64

65
    QHBoxLayout *hBox = new QHBoxLayout(this);
×
66
    //hBox->setContentsMargins(3, 3, 3, 10);
67
    //hBox->setSpacing(5);
68

69
    m_slider = new ClickAndGoSlider();
×
70
    m_slider->setSliderStyleSheet(CNG_DEFAULT_STYLE);
×
71
    m_slider->setFixedWidth(32);
×
72
    m_slider->setRange(0, 255);
×
73
    m_slider->setPageStep(1);
×
74
    m_slider->setInvertedAppearance(false);
×
75
    hBox->addWidget(m_slider);
×
76

77
    connect(m_slider, SIGNAL(valueChanged(int)),
×
78
            this, SLOT(slotSliderMoved(int)));
79

80
    QVBoxLayout *vbox = new QVBoxLayout();
×
81

82
    /* Color 1 Button */
NEW
83
    m_mtxColor1Button = new QToolButton(this);
×
NEW
84
    m_mtxColor1Button->setFixedSize(48, 48);
×
NEW
85
    m_mtxColor1Button->setIconSize(QSize(42, 42));
×
86

87
    QWidgetAction* scAction = new QWidgetAction(this);
×
NEW
88
    m_mtxColor1CnGWidget = new ClickAndGoWidget();
×
NEW
89
    m_mtxColor1CnGWidget->setType(ClickAndGoWidget::RGB, NULL);
×
NEW
90
    scAction->setDefaultWidget(m_mtxColor1CnGWidget);
×
NEW
91
    QMenu *color1Menu = new QMenu();
×
NEW
92
    color1Menu->addAction(scAction);
×
NEW
93
    m_mtxColor1Button->setMenu(color1Menu);
×
NEW
94
    m_mtxColor1Button->setPopupMode(QToolButton::InstantPopup);
×
95

NEW
96
    connect(m_mtxColor1CnGWidget, SIGNAL(colorChanged(QRgb)),
×
97
            this, SLOT(slotColor1Changed(QRgb)));
98

99
    /* Color 2 Button */
NEW
100
    m_mtxColor2Button = new QToolButton(this);
×
NEW
101
    m_mtxColor2Button->setFixedSize(48, 48);
×
NEW
102
    m_mtxColor2Button->setIconSize(QSize(42, 42));
×
103

NEW
104
    QWidgetAction* ecAction2 = new QWidgetAction(this);
×
NEW
105
    m_mtxColor2CnGWidget = new ClickAndGoWidget();
×
NEW
106
    m_mtxColor2CnGWidget->setType(ClickAndGoWidget::RGB, NULL);
×
NEW
107
    ecAction2->setDefaultWidget(m_mtxColor2CnGWidget);
×
NEW
108
    QMenu *color2Menu = new QMenu();
×
NEW
109
    color2Menu->addAction(ecAction2);
×
NEW
110
    m_mtxColor2Button->setMenu(color2Menu);
×
NEW
111
    m_mtxColor2Button->setPopupMode(QToolButton::InstantPopup);
×
112

NEW
113
    connect(m_mtxColor2CnGWidget, SIGNAL(colorChanged(QRgb)),
×
114
            this, SLOT(slotColor2Changed(QRgb)));
115

116
    /* 3rd Color Button */
NEW
117
    m_mtxColor3Button = new QToolButton(this);
×
NEW
118
    m_mtxColor3Button->setFixedSize(48, 48);
×
NEW
119
    m_mtxColor3Button->setIconSize(QSize(42, 42));
×
120

NEW
121
    QWidgetAction* ecAction3 = new QWidgetAction(this);
×
NEW
122
    m_mtxColor3CnGWidget = new ClickAndGoWidget();
×
NEW
123
    m_mtxColor3CnGWidget->setType(ClickAndGoWidget::RGB, NULL);
×
NEW
124
    ecAction3->setDefaultWidget(m_mtxColor3CnGWidget);
×
NEW
125
    QMenu *color3Menu = new QMenu();
×
NEW
126
    color3Menu->addAction(ecAction3);
×
NEW
127
    m_mtxColor3Button->setMenu(color3Menu);
×
NEW
128
    m_mtxColor3Button->setPopupMode(QToolButton::InstantPopup);
×
129

NEW
130
    connect(m_mtxColor3CnGWidget, SIGNAL(colorChanged(QRgb)),
×
131
            this, SLOT(slotColor3Changed(QRgb)));
132

133
    /* 4th Color Button */
NEW
134
    m_mtxColor4Button = new QToolButton(this);
×
NEW
135
    m_mtxColor4Button->setFixedSize(48, 48);
×
NEW
136
    m_mtxColor4Button->setIconSize(QSize(42, 42));
×
137

NEW
138
    QWidgetAction* ecAction4 = new QWidgetAction(this);
×
NEW
139
    m_mtxColor4CnGWidget = new ClickAndGoWidget();
×
NEW
140
    m_mtxColor4CnGWidget->setType(ClickAndGoWidget::RGB, NULL);
×
NEW
141
    ecAction4->setDefaultWidget(m_mtxColor4CnGWidget);
×
NEW
142
    QMenu *color4Menu = new QMenu();
×
NEW
143
    color4Menu->addAction(ecAction4);
×
NEW
144
    m_mtxColor4Button->setMenu(color4Menu);
×
NEW
145
    m_mtxColor4Button->setPopupMode(QToolButton::InstantPopup);
×
146

NEW
147
    connect(m_mtxColor4CnGWidget, SIGNAL(colorChanged(QRgb)),
×
148
            this, SLOT(slotColor4Changed(QRgb)));
149

150
    /* 5th Color Button */
NEW
151
    m_mtxColor5Button = new QToolButton(this);
×
NEW
152
    m_mtxColor5Button->setFixedSize(48, 48);
×
NEW
153
    m_mtxColor5Button->setIconSize(QSize(42, 42));
×
154

NEW
155
    QWidgetAction* ecAction5 = new QWidgetAction(this);
×
NEW
156
    m_mtxColor5CnGWidget = new ClickAndGoWidget();
×
NEW
157
    m_mtxColor5CnGWidget->setType(ClickAndGoWidget::RGB, NULL);
×
NEW
158
    ecAction5->setDefaultWidget(m_mtxColor5CnGWidget);
×
NEW
159
    QMenu *color5Menu = new QMenu();
×
NEW
160
    color5Menu->addAction(ecAction5);
×
NEW
161
    m_mtxColor5Button->setMenu(color5Menu);
×
NEW
162
    m_mtxColor5Button->setPopupMode(QToolButton::InstantPopup);
×
163

NEW
164
    connect(m_mtxColor5CnGWidget, SIGNAL(colorChanged(QRgb)),
×
165
            this, SLOT(slotColor5Changed(QRgb)));
166

167
    m_label = new QLabel(this);
×
168
    m_label->setAlignment(Qt::AlignCenter);
×
169
    m_label->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
×
170
    vbox->addWidget(m_label);
×
171

172
    QHBoxLayout *btnHbox = new QHBoxLayout();
×
173

NEW
174
    btnHbox->addWidget(m_mtxColor1Button);
×
NEW
175
    btnHbox->addWidget(m_mtxColor2Button);
×
NEW
176
    btnHbox->addWidget(m_mtxColor3Button);
×
NEW
177
    btnHbox->addWidget(m_mtxColor4Button);
×
NEW
178
    btnHbox->addWidget(m_mtxColor5Button);
×
179

180
    vbox->addLayout(btnHbox);
×
181

182
    m_presetCombo = new QComboBox(this);
×
183
    //m_presetCombo->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding);
184
    m_presetCombo->addItems(RGBAlgorithm::algorithms(m_doc));
×
185
    connect(m_presetCombo, SIGNAL(currentIndexChanged(QString)),
×
186
            this, SLOT(slotAnimationChanged(QString)));
187
    vbox->addWidget(m_presetCombo);
×
188

189
    hBox->addLayout(vbox);
×
190

191
    m_controlsLayout = new FlowLayout();
×
192
    vbox->addLayout(m_controlsLayout);
×
193

194
    setType(VCWidget::AnimationWidget);
×
195
    setCaption(QString());
×
196
    /* Initial size */
197
    QSettings settings;
×
198
    QVariant var = settings.value(SETTINGS_RGBMATRIX_SIZE);
×
199
    if (var.isValid() == true)
×
200
        resize(var.toSize());
×
201
    else
202
        resize(defaultSize);
×
203

204
    /* Update timer */
205
    m_updateTimer = new QTimer(this);
×
206
    connect(m_updateTimer, SIGNAL(timeout()),
×
207
            this, SLOT(slotUpdate()));
208
    m_updateTimer->setSingleShot(true);
×
209

210
    /* Update the slider according to current mode */
211
    slotModeChanged(m_doc->mode());
×
212
    setLiveEdit(m_liveEdit);
×
213
}
×
214

215
VCMatrix::~VCMatrix()
×
216
{
217
    foreach (VCMatrixControl* control, m_controls)
×
218
    {
219
        delete control;
×
220
    }
221
}
×
222

223
void VCMatrix::setID(quint32 id)
×
224
{
225
    VCWidget::setID(id);
×
226

227
    if (caption().isEmpty())
×
228
        setCaption(tr("Animation %1").arg(id));
×
229
}
×
230

231
/*********************************************************************
232
 * Clipboard
233
 *********************************************************************/
234

235
VCWidget *VCMatrix::createCopy(VCWidget *parent)
×
236
{
237
    Q_ASSERT(parent != NULL);
×
238

239
    VCMatrix* matrix = new VCMatrix(parent, m_doc);
×
240
    if (matrix->copyFrom(this) == false)
×
241
    {
242
        delete matrix;
×
243
        matrix = NULL;
×
244
    }
245

246
    return matrix;
×
247
}
248

249
bool VCMatrix::copyFrom(const VCWidget* widget)
×
250
{
251
    const VCMatrix* matrix = qobject_cast <const VCMatrix*> (widget);
×
252
    if (matrix == NULL)
×
253
        return false;
×
254

255
    /* Copy vcmatrix-specific stuff */
256
    setFunction(matrix->function());
×
257
    setInstantChanges(matrix->instantChanges());
×
258
    setVisibilityMask(matrix->visibilityMask());
×
259

260
    resetCustomControls();
×
261
    foreach (VCMatrixControl const* control, matrix->customControls())
×
262
    {
263
        addCustomControl(*control);
×
264
    }
265

266
    /* Copy common stuff */
267
    return VCWidget::copyFrom(widget);
×
268
}
269

270
/*********************************************************************
271
 * GUI
272
 *********************************************************************/
273

274
void VCMatrix::setCaption(const QString &text)
×
275
{
276
    VCWidget::setCaption(text);
×
277
    m_label->setText(text);
×
278
}
×
279

280
void VCMatrix::enableWidgetUI(bool enable)
×
281
{
282
    m_slider->setEnabled(enable);
×
NEW
283
    m_mtxColor1Button->setEnabled(enable);
×
NEW
284
    m_mtxColor2Button->setEnabled(enable);
×
NEW
285
    m_mtxColor3Button->setEnabled(enable);
×
NEW
286
    m_mtxColor4Button->setEnabled(enable);
×
NEW
287
    m_mtxColor5Button->setEnabled(enable);
×
UNCOV
288
    m_presetCombo->setEnabled(enable);
×
289

290
    foreach (QWidget *ctlBtn, m_controls.keys())
×
291
        ctlBtn->setEnabled(enable);
×
292

293
    // Update buttons state
294
    if (enable)
×
295
        slotUpdate();
×
296
}
×
297

298
void VCMatrix::slotSetSliderValue(int value)
×
299
{
300
    m_slider->setValue(value);
×
301
    slotSliderMoved(value);
×
302
}
×
303

304
void VCMatrix::slotSliderMoved(int value)
×
305
{
306
    Function* function = m_doc->function(m_matrixID);
×
307
    if (function == NULL || mode() == Doc::Design)
×
308
        return;
×
309

310
    if (m_sliderExternalMovement)
×
311
        return;
×
312

313
    if (value == 0)
×
314
    {
315
        // Make sure we ignore the fade out time
316
        adjustFunctionIntensity(function, 0);
×
317
        if (function->stopped() == false)
×
318
        {
319
            function->stop(functionParent());
×
320
            resetIntensityOverrideAttribute();
×
321
        }
322
    }
323
    else
324
    {
325
        qreal pIntensity = qreal(value) / qreal(UCHAR_MAX);
×
326
        emit functionStarting(m_matrixID, pIntensity);
×
327
        adjustFunctionIntensity(function, pIntensity * intensity());
×
328
        if (function->stopped() == true)
×
329
        {
330
            // TODO once #758 is fixed: function started by a fader -> override fade in time
331
            function->start(m_doc->masterTimer(), functionParent());
×
332
        }
333
    }
334

335
    emit sliderValueChanged(value);
×
336
}
337

338
int VCMatrix::sliderValue()
×
339
{
340
    return m_slider->value();
×
341
}
342

NEW
343
void VCMatrix::slotSetColor1(QColor color)
×
344
{
345
    RGBMatrix *matrix = qobject_cast<RGBMatrix*>(m_doc->function(m_matrixID));
×
346
    if (matrix == NULL)
×
347
        return;
×
348

NEW
349
    if (matrix->getColor(0) != color)
×
350
    {
NEW
351
        matrix->setColor(0, color);
×
NEW
352
        emit mtxColor1Changed();
×
353
    }
354
}
355

NEW
356
void VCMatrix::slotSetColor2(QColor color)
×
357
{
358
    RGBMatrix *matrix = qobject_cast<RGBMatrix*>(m_doc->function(m_matrixID));
×
359
    if (matrix == NULL)
×
NEW
360
        return;
×
361

NEW
362
    if (matrix->getColor(1) != color)
×
363
    {
NEW
364
        matrix->setColor(1, color);
×
NEW
365
        emit mtxColor2Changed();
×
366
    }
367
}
368

NEW
369
void VCMatrix::slotSetColor3(QColor color)
×
370
{
NEW
371
    RGBMatrix *matrix = qobject_cast<RGBMatrix*>(m_doc->function(m_matrixID));
×
NEW
372
    if (matrix == NULL)
×
NEW
373
        return;
×
374

NEW
375
    if (matrix->getColor(2) != color)
×
376
    {
NEW
377
        matrix->setColor(2, color);
×
NEW
378
        emit mtxColor3Changed();
×
379
    }
380
}
381

NEW
382
void VCMatrix::slotSetColor4(QColor color)
×
383
{
NEW
384
    RGBMatrix *matrix = qobject_cast<RGBMatrix*>(m_doc->function(m_matrixID));
×
NEW
385
    if (matrix == NULL)
×
UNCOV
386
        return;
×
387

NEW
388
    if (matrix->getColor(3) != color)
×
389
    {
NEW
390
        matrix->setColor(3, color);
×
NEW
391
        emit mtxColor4Changed();
×
392
    }
393
}
394

NEW
395
void VCMatrix::slotSetColor5(QColor color)
×
396
{
397
    RGBMatrix *matrix = qobject_cast<RGBMatrix*>(m_doc->function(m_matrixID));
×
398
    if (matrix == NULL)
×
399
        return;
×
400

NEW
401
    if (matrix->getColor(4) != color)
×
402
    {
NEW
403
        matrix->setColor(4, color);
×
NEW
404
        emit mtxColor5Changed();
×
405
    }
406
}
407

NEW
408
QColor VCMatrix::mtxColor(int id)
×
409
{
410
    RGBMatrix *matrix = qobject_cast<RGBMatrix*>(m_doc->function(m_matrixID));
×
411
    if (matrix == NULL)
×
412
        return QColor();
×
413

NEW
414
    return matrix->getColor(id);
×
415
}
416

NEW
417
void VCMatrix::slotColor1Changed(QRgb color)
×
418
{
419
    QColor col(color);
×
NEW
420
    slotSetColor1(col);
×
421
    QPixmap px(42, 42);
×
422
    px.fill(col);
×
NEW
423
    m_mtxColor1Button->setIcon(px);
×
424

425
    RGBMatrix* matrix = qobject_cast<RGBMatrix*>(m_doc->function(m_matrixID));
×
426
    if (matrix == NULL || mode() == Doc::Design)
×
427
        return;
×
428

NEW
429
    matrix->setColor(0, col);
×
430
    if (instantChanges() == true)
×
431
        matrix->updateColorDelta();
×
432
}
433

NEW
434
void VCMatrix::slotColor2Changed(QRgb color)
×
435
{
NEW
436
    QColor col(color);
×
NEW
437
    slotSetColor2(col);
×
NEW
438
    QPixmap px(42, 42);
×
NEW
439
    px.fill(col);
×
NEW
440
    m_mtxColor2Button->setIcon(px);
×
441

NEW
442
    RGBMatrix* matrix = qobject_cast<RGBMatrix*>(m_doc->function(m_matrixID));
×
NEW
443
    if (matrix == NULL || mode() == Doc::Design)
×
NEW
444
        return;
×
445

NEW
446
    matrix->setColor(1, col);
×
NEW
447
    if (instantChanges() == true)
×
NEW
448
        matrix->updateColorDelta();
×
449
}
450

NEW
451
void VCMatrix::slotColor3Changed(QRgb color)
×
452
{
NEW
453
    QColor col(color);
×
NEW
454
    slotSetColor3(col);
×
NEW
455
    QPixmap px(42, 42);
×
NEW
456
    px.fill(col);
×
NEW
457
    m_mtxColor3Button->setIcon(px);
×
458

NEW
459
    RGBMatrix* matrix = qobject_cast<RGBMatrix*>(m_doc->function(m_matrixID));
×
NEW
460
    if (matrix == NULL || mode() == Doc::Design)
×
NEW
461
        return;
×
462

NEW
463
    matrix->setColor(2, col);
×
464
}
465

NEW
466
void VCMatrix::slotColor4Changed(QRgb color)
×
467
{
NEW
468
    QColor col(color);
×
NEW
469
    slotSetColor4(col);
×
NEW
470
    QPixmap px(42, 42);
×
NEW
471
    px.fill(col);
×
NEW
472
    m_mtxColor4Button->setIcon(px);
×
473

NEW
474
    RGBMatrix* matrix = qobject_cast<RGBMatrix*>(m_doc->function(m_matrixID));
×
NEW
475
    if (matrix == NULL || mode() == Doc::Design)
×
NEW
476
        return;
×
477

NEW
478
    matrix->setColor(3, col);
×
479
}
480

NEW
481
void VCMatrix::slotColor5Changed(QRgb color)
×
482
{
NEW
483
    QColor col(color);
×
NEW
484
    slotSetColor5(col);
×
NEW
485
    QPixmap px(42, 42);
×
NEW
486
    px.fill(col);
×
NEW
487
    m_mtxColor5Button->setIcon(px);
×
488

NEW
489
    RGBMatrix* matrix = qobject_cast<RGBMatrix*>(m_doc->function(m_matrixID));
×
NEW
490
    if (matrix == NULL || mode() == Doc::Design)
×
NEW
491
        return;
×
492

NEW
493
    matrix->setColor(4, col);
×
494
}
495

UNCOV
496
void VCMatrix::slotSetAnimationValue(QString name)
×
497
{
498
    m_presetCombo->setCurrentText(name);
×
499
    slotAnimationChanged(name);
×
500
}
×
501

502
void VCMatrix::slotAnimationChanged(QString name)
×
503
{
504
    emit animationValueChanged(name);
×
505
    RGBMatrix* matrix = qobject_cast<RGBMatrix*>(m_doc->function(m_matrixID));
×
506
    if (matrix == NULL || mode() == Doc::Design)
×
507
        return;
×
508

509
    RGBAlgorithm* algo = RGBAlgorithm::algorithm(m_doc, name);
×
510
    matrix->setAlgorithm(algo);
×
511
    if (instantChanges() == true)
×
512
        matrix->updateColorDelta();
×
513
}
514

515
QString VCMatrix::animationValue()
×
516
{
517
    return m_presetCombo->currentText();
×
518
}
519

520
void VCMatrix::setVisibilityMask(quint32 mask)
×
521
{
522
    if (mask & ShowSlider) m_slider->show();
×
523
    else m_slider->hide();
×
524

525
    if (mask & ShowLabel) m_label->show();
×
526
    else m_label->hide();
×
527

NEW
528
    if (mask & ShowColor1Button) m_mtxColor1Button->show();
×
NEW
529
    else m_mtxColor1Button->hide();
×
530

NEW
531
    if (mask & ShowColor2Button) m_mtxColor2Button->show();
×
NEW
532
    else m_mtxColor2Button->hide();
×
533

NEW
534
    if (mask & ShowColor3Button) m_mtxColor3Button->show();
×
NEW
535
    else m_mtxColor3Button->hide();
×
536

NEW
537
    if (mask & ShowColor4Button) m_mtxColor4Button->show();
×
NEW
538
    else m_mtxColor4Button->hide();
×
539

NEW
540
    if (mask & ShowColor5Button) m_mtxColor5Button->show();
×
NEW
541
    else m_mtxColor5Button->hide();
×
542

543
    if (mask & ShowPresetCombo) m_presetCombo->show();
×
544
    else m_presetCombo->hide();
×
545

546
    m_visibilityMask = mask;
×
547
}
×
548

549
quint32 VCMatrix::visibilityMask() const
×
550
{
551
    return m_visibilityMask;
×
552
}
553

554
quint32 VCMatrix::defaultVisibilityMask()
×
555
{
556
    return ShowSlider
557
        | ShowLabel
558
        | ShowPresetCombo
559
        | ShowColor1Button
560
        | ShowColor2Button
561
        | ShowColor3Button
562
        | ShowColor4Button
NEW
563
        | ShowColor5Button
×
564
        ;
565
}
566

567
/*********************************************************************
568
 * Properties
569
 *********************************************************************/
570

571
void VCMatrix::editProperties()
×
572
{
573
    VCMatrixProperties prop(this, m_doc);
×
574
    if (prop.exec() == QDialog::Accepted)
×
575
        m_doc->setModified();
×
576
}
×
577

578
/*************************************************************************
579
 * VCWidget-inherited
580
 *************************************************************************/
581

582
void VCMatrix::adjustIntensity(qreal val)
×
583
{
584
    VCWidget::adjustIntensity(val);
×
585
    this->slotSliderMoved(this->m_slider->value());
×
586
}
×
587

588
/*********************************************************************
589
 * Function attachment
590
 *********************************************************************/
591

592
void VCMatrix::setFunction(quint32 id)
×
593
{
594
    Function *old = m_doc->function(m_matrixID);
×
595
    if (old != NULL)
×
596
    {
597
        disconnect(old, SIGNAL(stopped(quint32)),
×
598
                this, SLOT(slotFunctionStopped()));
599
        disconnect(old, SIGNAL(changed(quint32)),
×
600
                this, SLOT(slotFunctionChanged()));
601
    }
602

603
    RGBMatrix* matrix = qobject_cast<RGBMatrix*> (m_doc->function(id));
×
604

605
    if (matrix == NULL)
×
606
        m_matrixID = Function::invalidId();
×
607
    else
608
    {
609
        m_matrixID = id;
×
610
        connect(matrix, SIGNAL(stopped(quint32)),
×
611
                this, SLOT(slotFunctionStopped()));
612
        connect(matrix, SIGNAL(changed(quint32)),
×
613
                this, SLOT(slotFunctionChanged()));
614
    }
615

616
    slotUpdate();
×
617
}
×
618

619
quint32 VCMatrix::function() const
×
620
{
621
    return m_matrixID;
×
622
}
623

624
void VCMatrix::notifyFunctionStarting(quint32 fid, qreal functionIntensity)
×
625
{
626
    if (mode() == Doc::Design)
×
627
        return;
×
628

629
    if (fid == m_matrixID)
×
630
        return;
×
631

632
    int value = SCALE(1.0 - functionIntensity,
×
633
            0, 1.0,
634
            m_slider->minimum(), m_slider->maximum());
635
    if (m_slider->value() > value)
×
636
    {
637
        m_sliderExternalMovement = true;
×
638
        m_slider->setValue(value);
×
639
        m_sliderExternalMovement = false;
×
640

641
        Function* function = m_doc->function(m_matrixID);
×
642
        if (function != NULL)
×
643
        {
644
            qreal pIntensity = qreal(value) / qreal(UCHAR_MAX);
×
645
            adjustFunctionIntensity(function, pIntensity * intensity());
×
646
            if (value == 0 && !function->stopped())
×
647
            {
648
                function->stop(functionParent());
×
649
                resetIntensityOverrideAttribute();
×
650
            }
651
        }
652
    }
653
}
654

655
void VCMatrix::slotFunctionStopped()
×
656
{
657
    m_slider->blockSignals(true);
×
658
    m_slider->setValue(0);
×
659
    resetIntensityOverrideAttribute();
×
660
    m_slider->blockSignals(false);
×
661
}
×
662

663
void VCMatrix::slotFunctionChanged()
×
664
{
665
    m_updateTimer->start(UPDATE_TIMEOUT);
×
666
}
×
667

668
void VCMatrix::slotUpdate()
×
669
{
670
    if (m_matrixID == Function::invalidId())
×
671
        return;
×
672

673
    RGBMatrix *matrix = qobject_cast<RGBMatrix*>(m_doc->function(m_matrixID));
×
674
    if (matrix == NULL)
×
675
        return;
×
676

677
    QString algorithmName;
×
678
    RGBAlgorithm::Type algorithmType = RGBAlgorithm::Plain;
×
679
    QHash<QString, QString> algorithmProperties;
×
680
    QString algorithmText;
×
681

682
    {
683
        QMutexLocker locker(&matrix->algorithmMutex());
×
684

685
        RGBAlgorithm *algo = matrix->algorithm();
×
686
        if (algo != NULL)
×
687
        {
688
            algorithmName = algo->name();
×
689
            algorithmType = algo->type();
×
690
            if (algorithmType == RGBAlgorithm::Script)
×
691
            {
692
                algorithmProperties = reinterpret_cast<RGBScript*>(algo)->propertiesAsStrings();
×
693
            }
694
            else if (algorithmType == RGBAlgorithm::Text)
×
695
            {
696
                algorithmText = reinterpret_cast<RGBText*>(algo)->text();
×
697
            }
698
        }
699
    }
700

701
    // Color buttons
702
    QPixmap px(42, 42);
×
NEW
703
    px.fill(matrix->getColor(0));
×
NEW
704
    m_mtxColor1Button->setIcon(px);
×
705

NEW
706
    if (matrix->getColor(1) == QColor())
×
NEW
707
        px.fill(Qt::transparent);
×
708
    else
NEW
709
        px.fill(matrix->getColor(1));
×
NEW
710
    m_mtxColor2Button->setIcon(px);
×
711

NEW
712
    if (matrix->getColor(2) == QColor())
×
NEW
713
        px.fill(Qt::transparent);
×
714
    else
NEW
715
        px.fill(matrix->getColor(2));
×
NEW
716
    m_mtxColor3Button->setIcon(px);
×
717

NEW
718
    if (matrix->getColor(3) == QColor())
×
NEW
719
        px.fill(Qt::transparent);
×
720
    else
NEW
721
        px.fill(matrix->getColor(3));
×
NEW
722
    m_mtxColor4Button->setIcon(px);
×
723

NEW
724
    if (matrix->getColor(4) == QColor())
×
NEW
725
        px.fill(Qt::transparent);
×
726
    else
NEW
727
        px.fill(matrix->getColor(4));
×
NEW
728
    m_mtxColor5Button->setIcon(px);
×
729

730
    // Algo combo box
731
    if (algorithmName != QString())
×
732
    {
733
        m_presetCombo->blockSignals(true);
×
734
        m_presetCombo->setCurrentText(algorithmName);
×
735
        m_presetCombo->blockSignals(false);
×
736
    }
737

738
    // Custom Buttons
739
    for (QHash<QWidget *, VCMatrixControl *>::iterator it = m_controls.begin();
×
740
            it != m_controls.end(); ++it)
×
741
    {
742
        QWidget *widget = it.key();
×
743
        VCMatrixControl *control = it.value();
×
744

NEW
745
        if (control->m_type == VCMatrixControl::Color1Knob)
×
746
        {
747
            KnobWidget *knob = reinterpret_cast<KnobWidget*>(widget);
×
NEW
748
            int val = control->rgbToValue(matrix->getColor(0).rgb());
×
749
            if (knob->value() != val)
×
750
            {
751
                knob->blockSignals(true);
×
752
                knob->setValue(val);
×
753
                emit matrixControlKnobValueChanged(control->m_id, val);
×
754
                knob->blockSignals(false);
×
755
            }
756
        }
NEW
757
        else if (control->m_type == VCMatrixControl::Color2Knob)
×
758
        {
759
            KnobWidget *knob = reinterpret_cast<KnobWidget*>(widget);
×
NEW
760
            int val = control->rgbToValue(matrix->getColor(1).rgb());
×
761
            if (knob->value() != val)
×
762
            {
763
                knob->blockSignals(true);
×
764
                knob->setValue(val);
×
765
                emit matrixControlKnobValueChanged(control->m_id, val);
×
766
                knob->blockSignals(false);
×
767
            }
768
        }
NEW
769
        else if (control->m_type == VCMatrixControl::Color3Knob)
×
770
        {
NEW
771
            KnobWidget *knob = reinterpret_cast<KnobWidget*>(widget);
×
NEW
772
            int val = control->rgbToValue(matrix->getColor(2).rgb());
×
NEW
773
            if (knob->value() != val)
×
774
            {
NEW
775
                knob->blockSignals(true);
×
NEW
776
                knob->setValue(val);
×
NEW
777
                emit matrixControlKnobValueChanged(control->m_id, val);
×
NEW
778
                knob->blockSignals(false);
×
779
            }
780
        }
NEW
781
        else if (control->m_type == VCMatrixControl::Color4Knob)
×
782
        {
NEW
783
            KnobWidget *knob = reinterpret_cast<KnobWidget*>(widget);
×
NEW
784
            int val = control->rgbToValue(matrix->getColor(3).rgb());
×
NEW
785
            if (knob->value() != val)
×
786
            {
NEW
787
                knob->blockSignals(true);
×
NEW
788
                knob->setValue(val);
×
NEW
789
                emit matrixControlKnobValueChanged(control->m_id, val);
×
NEW
790
                knob->blockSignals(false);
×
791
            }
792
        }
NEW
793
        else if (control->m_type == VCMatrixControl::Color5Knob)
×
794
        {
NEW
795
            KnobWidget *knob = reinterpret_cast<KnobWidget*>(widget);
×
NEW
796
            int val = control->rgbToValue(matrix->getColor(4).rgb());
×
NEW
797
            if (knob->value() != val)
×
798
            {
NEW
799
                knob->blockSignals(true);
×
NEW
800
                knob->setValue(val);
×
NEW
801
                emit matrixControlKnobValueChanged(control->m_id, val);
×
NEW
802
                knob->blockSignals(false);
×
803
            }
804
        }
NEW
805
        else if (control->m_type == VCMatrixControl::Color1)
×
806
        {
NEW
807
            QPushButton* button = reinterpret_cast<QPushButton*>(it.key());
×
NEW
808
            button->setDown(matrix->getColor(0) == control->m_color);
×
809
        }
NEW
810
        else if (control->m_type == VCMatrixControl::Color2)
×
811
        {
NEW
812
            QPushButton* button = reinterpret_cast<QPushButton*>(it.key());
×
NEW
813
            button->setDown(matrix->getColor(1) == control->m_color);
×
814
        }
NEW
815
        else if (control->m_type == VCMatrixControl::Color3)
×
816
        {
NEW
817
            QPushButton* button = reinterpret_cast<QPushButton*>(it.key());
×
NEW
818
            button->setDown(matrix->getColor(2) == control->m_color);
×
819
        }
NEW
820
        else if (control->m_type == VCMatrixControl::Color4)
×
821
        {
NEW
822
            QPushButton* button = reinterpret_cast<QPushButton*>(it.key());
×
NEW
823
            button->setDown(matrix->getColor(3) == control->m_color);
×
824
        }
NEW
825
        else if (control->m_type == VCMatrixControl::Color5)
×
826
        {
NEW
827
            QPushButton* button = reinterpret_cast<QPushButton*>(it.key());
×
NEW
828
            button->setDown(matrix->getColor(4) == control->m_color);
×
829
        }
830
        else if (control->m_type == VCMatrixControl::Animation)
×
831
        {
832
            bool on = false;
×
833
            if (algorithmType == RGBAlgorithm::Script &&
×
834
                algorithmName == control->m_resource)
×
835
            {
836
                on = true;
×
837
                for (QHash<QString, QString>::const_iterator it = control->m_properties.begin();
×
838
                        it != control->m_properties.end(); ++it)
×
839
                {
840
                    if (algorithmProperties.value(it.key(), QString()) != it.value())
×
841
                        on = false;
×
842
                }
843
            }
844

845
            QPushButton *button = reinterpret_cast<QPushButton*>(it.key());
×
846
            button->setDown(on);
×
847
        }
848
        else if (control->m_type == VCMatrixControl::Text)
×
849
        {
850
            bool on = false;
×
851
            if (algorithmType == RGBAlgorithm::Text &&
×
852
                algorithmText == control->m_resource)
×
853
            {
854
                on = true;
×
855
            }
856

857
            QPushButton *button = reinterpret_cast<QPushButton*>(it.key());
×
858
            button->setDown(on);
×
859
        }
860
    }
861

862
    updateFeedback();
×
863
}
864

865
FunctionParent VCMatrix::functionParent() const
×
866
{
867
    return FunctionParent(FunctionParent::ManualVCWidget, id());
×
868
}
869

870
/*********************************************************************
871
 * Instant changes apply
872
 *********************************************************************/
873

874
void VCMatrix::setInstantChanges(bool instantly)
×
875
{
876
    m_instantApply = instantly;
×
877
}
×
878

879
bool VCMatrix::instantChanges() const
×
880
{
881
    return m_instantApply;
×
882
}
883

884
/*********************************************************************
885
 * Custom controls
886
 *********************************************************************/
887

888
void VCMatrix::addCustomControl(VCMatrixControl const& control)
×
889
{
890
    QWidget *controlWidget = NULL;
×
891

NEW
892
    if (control.m_type == VCMatrixControl::Color1)
×
893
    {
894
        QPushButton *controlButton = new QPushButton(this);
×
895
        controlWidget = controlButton;
×
896
        controlButton->setStyleSheet(controlBtnSS.arg(control.m_color.name()));
×
897
        controlButton->setFixedWidth(36);
×
898
        controlButton->setFocusPolicy(Qt::TabFocus);
×
NEW
899
        controlButton->setText("1");
×
900
    }
NEW
901
    else if (control.m_type == VCMatrixControl::Color2)
×
902
    {
903
        QPushButton *controlButton = new QPushButton(this);
×
904
        controlWidget = controlButton;
×
905
        controlButton->setStyleSheet(controlBtnSS.arg(control.m_color.name()));
×
906
        controlButton->setFixedWidth(36);
×
907
        controlButton->setFocusPolicy(Qt::TabFocus);
×
NEW
908
        controlButton->setText("2");
×
909
    }
NEW
910
    else if (control.m_type == VCMatrixControl::Color3)
×
911
    {
NEW
912
        QPushButton *controlButton = new QPushButton(this);
×
NEW
913
        controlWidget = controlButton;
×
NEW
914
        controlButton->setStyleSheet(controlBtnSS.arg(control.m_color.name()));
×
NEW
915
        controlButton->setFixedWidth(36);
×
NEW
916
        controlButton->setFocusPolicy(Qt::TabFocus);
×
NEW
917
        controlButton->setText("3");
×
918
    }
NEW
919
    else if (control.m_type == VCMatrixControl::Color4)
×
920
    {
NEW
921
        QPushButton *controlButton = new QPushButton(this);
×
NEW
922
        controlWidget = controlButton;
×
NEW
923
        controlButton->setStyleSheet(controlBtnSS.arg(control.m_color.name()));
×
NEW
924
        controlButton->setFixedWidth(36);
×
NEW
925
        controlButton->setFocusPolicy(Qt::TabFocus);
×
NEW
926
        controlButton->setText("4");
×
927
    }
NEW
928
    else if (control.m_type == VCMatrixControl::Color5)
×
929
    {
NEW
930
        QPushButton *controlButton = new QPushButton(this);
×
NEW
931
        controlWidget = controlButton;
×
NEW
932
        controlButton->setStyleSheet(controlBtnSS.arg(control.m_color.name()));
×
NEW
933
        controlButton->setFixedWidth(36);
×
NEW
934
        controlButton->setFocusPolicy(Qt::TabFocus);
×
NEW
935
        controlButton->setText("5");
×
936
    }
NEW
937
    else if (control.m_type == VCMatrixControl::Color2Reset)
×
938
    {
939
        QPushButton *controlButton = new QPushButton(this);
×
940
        controlWidget = controlButton;
×
941
        controlButton->setStyleSheet(controlBtnSS.arg("#BBBBBB"));
×
942
        controlButton->setMinimumWidth(36);
×
943
        controlButton->setMaximumWidth(80);
×
944
        controlButton->setFocusPolicy(Qt::TabFocus);
×
NEW
945
        QString btnLabel = tr("Color 2 Reset");
×
NEW
946
        controlButton->setToolTip(btnLabel);
×
NEW
947
        controlButton->setText(fontMetrics().elidedText(btnLabel, Qt::ElideRight, 72));
×
948
    }
NEW
949
    else if (control.m_type == VCMatrixControl::Color3Reset)
×
950
    {
NEW
951
        QPushButton *controlButton = new QPushButton(this);
×
NEW
952
        controlWidget = controlButton;
×
NEW
953
        controlButton->setStyleSheet(controlBtnSS.arg("#BBBBBB"));
×
NEW
954
        controlButton->setMinimumWidth(36);
×
NEW
955
        controlButton->setMaximumWidth(80);
×
NEW
956
        controlButton->setFocusPolicy(Qt::TabFocus);
×
NEW
957
        QString btnLabel = tr("Color 3 Reset");
×
NEW
958
        controlButton->setToolTip(btnLabel);
×
NEW
959
        controlButton->setText(fontMetrics().elidedText(btnLabel, Qt::ElideRight, 72));
×
960
    }
NEW
961
    else if (control.m_type == VCMatrixControl::Color4Reset)
×
962
    {
NEW
963
        QPushButton *controlButton = new QPushButton(this);
×
NEW
964
        controlWidget = controlButton;
×
NEW
965
        controlButton->setStyleSheet(controlBtnSS.arg("#BBBBBB"));
×
NEW
966
        controlButton->setMinimumWidth(36);
×
NEW
967
        controlButton->setMaximumWidth(80);
×
NEW
968
        controlButton->setFocusPolicy(Qt::TabFocus);
×
NEW
969
        QString btnLabel = tr("Color 4 Reset");
×
NEW
970
        controlButton->setToolTip(btnLabel);
×
NEW
971
        controlButton->setText(fontMetrics().elidedText(btnLabel, Qt::ElideRight, 72));
×
972
    }
NEW
973
    else if (control.m_type == VCMatrixControl::Color5Reset)
×
974
    {
NEW
975
        QPushButton *controlButton = new QPushButton(this);
×
NEW
976
        controlWidget = controlButton;
×
NEW
977
        controlButton->setStyleSheet(controlBtnSS.arg("#BBBBBB"));
×
NEW
978
        controlButton->setMinimumWidth(36);
×
NEW
979
        controlButton->setMaximumWidth(80);
×
NEW
980
        controlButton->setFocusPolicy(Qt::TabFocus);
×
NEW
981
        QString btnLabel = tr("Color 5 Reset");
×
982
        controlButton->setToolTip(btnLabel);
×
983
        controlButton->setText(fontMetrics().elidedText(btnLabel, Qt::ElideRight, 72));
×
984
    }
985
    else if (control.m_type == VCMatrixControl::Animation ||
×
986
             control.m_type == VCMatrixControl::Text)
×
987
    {
988
        QPushButton *controlButton = new QPushButton(this);
×
989
        controlWidget = controlButton;
×
990
        controlButton->setStyleSheet(controlBtnSS.arg("#BBBBBB"));
×
991
        controlButton->setMinimumWidth(36);
×
992
        controlButton->setMaximumWidth(80);
×
993
        controlButton->setFocusPolicy(Qt::TabFocus);
×
994
        QString btnLabel = control.m_resource;
×
995
        if (!control.m_properties.isEmpty())
×
996
        {
997
            btnLabel += " (";
×
998
            QHashIterator<QString, QString> it(control.m_properties);
×
999
            while (it.hasNext())
×
1000
            {
1001
                it.next();
×
1002
                btnLabel += it.value();
×
1003
                if (it.hasNext())
×
1004
                    btnLabel += ",";
×
1005
            }
1006
            btnLabel += ")";
×
1007
        }
1008
        controlButton->setToolTip(btnLabel);
×
1009
        controlButton->setText(fontMetrics().elidedText(btnLabel, Qt::ElideRight, 72));
×
1010
    }
NEW
1011
    else if (control.m_type == VCMatrixControl::Color1Knob)
×
1012
    {
1013
        KnobWidget *controlKnob = new KnobWidget(this);
×
1014
        controlWidget = controlKnob;
×
1015
        controlKnob->setColor(control.m_color);
×
1016
        controlKnob->setFixedWidth(36);
×
1017
        controlKnob->setFixedHeight(36);
×
1018
        QString knobLabel;
×
1019
        if (control.m_color == Qt::red)
×
NEW
1020
            knobLabel = tr("Color 1 Red component");
×
1021
        else if (control.m_color == Qt::green)
×
NEW
1022
            knobLabel = tr("Color 1 Green component");
×
1023
        else if (control.m_color == Qt::blue)
×
NEW
1024
            knobLabel = tr("Color 1 Blue component");
×
1025
        controlKnob->setToolTip(knobLabel);
×
1026
    }
NEW
1027
    else if (control.m_type == VCMatrixControl::Color2Knob)
×
1028
    {
1029
        KnobWidget *controlKnob = new KnobWidget(this);
×
1030
        controlWidget = controlKnob;
×
1031
        controlKnob->setColor(control.m_color.darker(250));
×
1032
        controlKnob->setFixedWidth(36);
×
1033
        controlKnob->setFixedHeight(36);
×
1034
        QString knobLabel;
×
1035
        if (control.m_color == Qt::red)
×
NEW
1036
            knobLabel = tr("Color 2 Red component");
×
1037
        else if (control.m_color == Qt::green)
×
NEW
1038
            knobLabel = tr("Color 2 Green component");
×
1039
        else if (control.m_color == Qt::blue)
×
NEW
1040
            knobLabel = tr("Color 2 Blue component");
×
NEW
1041
        controlKnob->setToolTip(knobLabel);
×
1042
    }
NEW
1043
    else if (control.m_type == VCMatrixControl::Color3Knob)
×
1044
    {
NEW
1045
        KnobWidget *controlKnob = new KnobWidget(this);
×
NEW
1046
        controlWidget = controlKnob;
×
NEW
1047
        controlKnob->setColor(control.m_color.darker(250));
×
NEW
1048
        controlKnob->setFixedWidth(36);
×
NEW
1049
        controlKnob->setFixedHeight(36);
×
NEW
1050
        QString knobLabel;
×
NEW
1051
        if (control.m_color == Qt::red)
×
NEW
1052
            knobLabel = tr("Color 3 Red component");
×
NEW
1053
        else if (control.m_color == Qt::green)
×
NEW
1054
            knobLabel = tr("Color 3 Green component");
×
NEW
1055
        else if (control.m_color == Qt::blue)
×
NEW
1056
            knobLabel = tr("Color 3 Blue component");
×
NEW
1057
        controlKnob->setToolTip(knobLabel);
×
1058
    }
NEW
1059
    else if (control.m_type == VCMatrixControl::Color4Knob)
×
1060
    {
NEW
1061
        KnobWidget *controlKnob = new KnobWidget(this);
×
NEW
1062
        controlWidget = controlKnob;
×
NEW
1063
        controlKnob->setColor(control.m_color.darker(250));
×
NEW
1064
        controlKnob->setFixedWidth(36);
×
NEW
1065
        controlKnob->setFixedHeight(36);
×
NEW
1066
        QString knobLabel;
×
NEW
1067
        if (control.m_color == Qt::red)
×
NEW
1068
            knobLabel = tr("Color 4 Red component");
×
NEW
1069
        else if (control.m_color == Qt::green)
×
NEW
1070
            knobLabel = tr("Color 4 Green component");
×
NEW
1071
        else if (control.m_color == Qt::blue)
×
NEW
1072
            knobLabel = tr("Color 4 Blue component");
×
NEW
1073
        controlKnob->setToolTip(knobLabel);
×
1074
    }
NEW
1075
    else if (control.m_type == VCMatrixControl::Color5Knob)
×
1076
    {
NEW
1077
        KnobWidget *controlKnob = new KnobWidget(this);
×
NEW
1078
        controlWidget = controlKnob;
×
NEW
1079
        controlKnob->setColor(control.m_color.darker(250));
×
NEW
1080
        controlKnob->setFixedWidth(36);
×
NEW
1081
        controlKnob->setFixedHeight(36);
×
NEW
1082
        QString knobLabel;
×
NEW
1083
        if (control.m_color == Qt::red)
×
NEW
1084
            knobLabel = tr("Color 5 Red component");
×
NEW
1085
        else if (control.m_color == Qt::green)
×
NEW
1086
            knobLabel = tr("Color 5 Green component");
×
NEW
1087
        else if (control.m_color == Qt::blue)
×
NEW
1088
            knobLabel = tr("Color 5 Blue component");
×
UNCOV
1089
        controlKnob->setToolTip(knobLabel);
×
1090
    }
1091

1092
    Q_ASSERT(controlWidget != NULL);
×
1093

1094
    if (control.widgetType() == VCMatrixControl::Knob)
×
1095
    {
1096
        connect(reinterpret_cast<KnobWidget*>(controlWidget), SIGNAL(valueChanged(int)),
×
1097
                this, SLOT(slotCustomControlValueChanged()));
1098
    }
1099
    else
1100
    {
1101
        connect(reinterpret_cast<QPushButton*>(controlWidget), SIGNAL(clicked()),
×
1102
                this, SLOT(slotCustomControlClicked()));
1103
    }
1104

1105

1106
    if (mode() == Doc::Design)
×
1107
        controlWidget->setEnabled(false);
×
1108

1109
    VCMatrixControl *c_control = new VCMatrixControl(control);
×
1110
    m_controls[controlWidget] = c_control;
×
1111
    m_widgets[c_control] = controlWidget;
×
1112

1113
    m_controlsLayout->addWidget(controlWidget);
×
1114

1115
    if (m_controls[controlWidget]->m_inputSource != NULL)
×
1116
    {
1117
        setInputSource(m_controls[controlWidget]->m_inputSource, m_controls[controlWidget]->m_id);
×
1118
    }
1119

1120
    slotFunctionChanged(); // Start update timer
×
1121
}
×
1122

1123
void VCMatrix::resetCustomControls()
×
1124
{
1125
    for (QHash<QWidget *, VCMatrixControl *>::iterator it = m_controls.begin();
×
1126
            it != m_controls.end(); ++it)
×
1127
    {
1128
        QWidget* widget = it.key();
×
1129
        m_controlsLayout->removeWidget(widget);
×
1130
        delete widget;
×
1131

1132
        VCMatrixControl* control = it.value();
×
1133
        if (!control->m_inputSource.isNull())
×
1134
            setInputSource(QSharedPointer<QLCInputSource>(), control->m_id);
×
1135
        delete control;
×
1136
    }
1137
    m_controls.clear();
×
1138
    m_widgets.clear();
×
1139
}
×
1140

1141
QList<VCMatrixControl *> VCMatrix::customControls() const
×
1142
{
1143
    QList<VCMatrixControl*> controls = m_controls.values();
×
1144
    std::sort(controls.begin(), controls.end(), VCMatrixControl::compare);
×
1145
    return controls;
×
1146
}
1147

1148
QMap<quint32,QString> VCMatrix::customControlsMap() const
×
1149
{
1150
    QMap<quint32,QString> map;
×
1151

1152
    foreach (VCMatrixControl *control, m_controls.values())
×
1153
        map.insert(control->m_id, VCMatrixControl::typeToString(control->m_type));
×
1154

1155
    return map;
×
1156
}
1157

1158
QWidget *VCMatrix::getWidget(VCMatrixControl* control) const
×
1159
{
1160
    return m_widgets[control];
×
1161
}
1162

1163
void VCMatrix::slotCustomControlClicked()
×
1164
{
1165
    QPushButton *btn = qobject_cast<QPushButton*>(sender());
×
1166
    VCMatrixControl *control = m_controls[btn];
×
1167
    if (control != NULL)
×
1168
    {
1169
        RGBMatrix* matrix = qobject_cast<RGBMatrix*>(m_doc->function(m_matrixID));
×
1170
        if (matrix == NULL || mode() == Doc::Design)
×
1171
            return;
×
1172

NEW
1173
        if (control->m_type == VCMatrixControl::Color1)
×
1174
        {
NEW
1175
            matrix->setColor(0, control->m_color);
×
1176
            if (instantChanges() == true)
×
1177
                matrix->updateColorDelta();
×
1178
            btn->setDown(true);
×
NEW
1179
            emit mtxColor1Changed();
×
1180
        }
NEW
1181
        else if (control->m_type == VCMatrixControl::Color2)
×
1182
        {
NEW
1183
            matrix->setColor(1, control->m_color);
×
1184
            if (instantChanges() == true)
×
1185
                matrix->updateColorDelta();
×
1186
            btn->setDown(true);
×
NEW
1187
            emit mtxColor2Changed();
×
1188
        }
NEW
1189
        else if (control->m_type == VCMatrixControl::Color3)
×
1190
        {
NEW
1191
            matrix->setColor(2, control->m_color);
×
NEW
1192
            btn->setDown(true);
×
NEW
1193
            emit mtxColor3Changed();
×
1194
        }
NEW
1195
        else if (control->m_type == VCMatrixControl::Color4)
×
1196
        {
NEW
1197
            matrix->setColor(3, control->m_color);
×
NEW
1198
            btn->setDown(true);
×
NEW
1199
            emit mtxColor4Changed();
×
1200
        }
NEW
1201
        else if (control->m_type == VCMatrixControl::Color5)
×
1202
        {
NEW
1203
            matrix->setColor(4, control->m_color);
×
NEW
1204
            btn->setDown(true);
×
NEW
1205
            emit mtxColor5Changed();
×
1206
        }
NEW
1207
        else if (control->m_type == VCMatrixControl::Color2Reset)
×
1208
        {
NEW
1209
            matrix->setColor(1, QColor());
×
1210
            if (instantChanges() == true)
×
1211
                matrix->updateColorDelta();
×
NEW
1212
            emit mtxColor2Changed();
×
1213
        }
NEW
1214
        else if (control->m_type == VCMatrixControl::Color3Reset)
×
1215
        {
NEW
1216
            matrix->setColor(2, QColor());
×
NEW
1217
            emit mtxColor3Changed();
×
1218
        }
NEW
1219
        else if (control->m_type == VCMatrixControl::Color4Reset)
×
1220
        {
NEW
1221
            matrix->setColor(3, QColor());
×
NEW
1222
            emit mtxColor4Changed();
×
1223
        }
NEW
1224
        else if (control->m_type == VCMatrixControl::Color5Reset)
×
1225
        {
NEW
1226
            matrix->setColor(4, QColor());
×
NEW
1227
            emit mtxColor5Changed();
×
1228
        }
1229
        else if (control->m_type == VCMatrixControl::Animation)
×
1230
        {
1231
            RGBAlgorithm* algo = RGBAlgorithm::algorithm(m_doc, control->m_resource);
×
1232
            if (!control->m_properties.isEmpty())
×
1233
            {
1234
                RGBScript *script = static_cast<RGBScript*> (algo);
×
1235
                QHashIterator<QString, QString> it(control->m_properties);
×
1236
                while (it.hasNext())
×
1237
                {
1238
                    it.next();
×
1239
                    script->setProperty(it.key(), it.value());
×
1240
                    matrix->setProperty(it.key(), it.value());
×
1241
                }
1242
            }
1243
            matrix->setAlgorithm(algo);
×
1244
            if (instantChanges() == true)
×
1245
                matrix->updateColorDelta();
×
1246
            btn->setDown(true);
×
1247
        }
1248
        else if (control->m_type == VCMatrixControl::Text)
×
1249
        {
1250
            RGBAlgorithm* algo = RGBAlgorithm::algorithm(m_doc, "Text");
×
1251
            RGBText* text = static_cast<RGBText*> (algo);
×
1252
            text->setText(control->m_resource);
×
1253
            matrix->setAlgorithm(algo);
×
1254
            if (instantChanges() == true)
×
1255
                matrix->updateColorDelta();
×
1256
            btn->setDown(true);
×
1257
        }
1258
    }
1259
}
1260

1261
void VCMatrix::slotCustomControlValueChanged()
×
1262
{
1263
    KnobWidget *knob = qobject_cast<KnobWidget*>(sender());
×
1264
    VCMatrixControl *control = m_controls[knob];
×
1265
    if (control != NULL)
×
1266
    {
1267
        RGBMatrix* matrix = qobject_cast<RGBMatrix*>(m_doc->function(m_matrixID));
×
1268
        if (matrix == NULL || mode() == Doc::Design)
×
1269
            return;
×
1270

NEW
1271
        if (control->m_type == VCMatrixControl::Color1Knob)
×
1272
        {
NEW
1273
            QRgb color = matrix->getColor(0).rgb();
×
1274
            QRgb knobValueColor = control->valueToRgb(knob->value());
×
1275
            color = (color & ~control->m_color.rgb()) | (knobValueColor & control->m_color.rgb());
×
1276

NEW
1277
            matrix->setColor(0, color);
×
1278
            if (instantChanges() == true)
×
1279
                matrix->updateColorDelta();
×
NEW
1280
            emit mtxColor1Changed();
×
1281
        }
NEW
1282
        else if (control->m_type == VCMatrixControl::Color2Knob)
×
1283
        {
NEW
1284
            QRgb color = matrix->getColor(1).rgb();
×
1285
            QRgb knobValueColor = control->valueToRgb(knob->value());
×
1286
            color = (color & ~control->m_color.rgb()) | (knobValueColor & control->m_color.rgb());
×
1287

NEW
1288
            matrix->setColor(1, color);
×
1289
            if (instantChanges() == true)
×
1290
                matrix->updateColorDelta();
×
NEW
1291
            emit mtxColor2Changed();
×
1292
        }
NEW
1293
        else if (control->m_type == VCMatrixControl::Color3Knob)
×
1294
        {
NEW
1295
            QRgb color = matrix->getColor(2).rgb();
×
NEW
1296
            QRgb knobValueColor = control->valueToRgb(knob->value());
×
NEW
1297
            color = (color & ~control->m_color.rgb()) | (knobValueColor & control->m_color.rgb());
×
1298

NEW
1299
            matrix->setColor(2, color);
×
NEW
1300
            emit mtxColor3Changed();
×
1301
        }
NEW
1302
        else if (control->m_type == VCMatrixControl::Color4Knob)
×
1303
        {
NEW
1304
            QRgb color = matrix->getColor(3).rgb();
×
NEW
1305
            QRgb knobValueColor = control->valueToRgb(knob->value());
×
NEW
1306
            color = (color & ~control->m_color.rgb()) | (knobValueColor & control->m_color.rgb());
×
1307

NEW
1308
            matrix->setColor(3, color);
×
NEW
1309
            emit mtxColor4Changed();
×
1310
        }
NEW
1311
        else if (control->m_type == VCMatrixControl::Color5Knob)
×
1312
        {
NEW
1313
            QRgb color = matrix->getColor(4).rgb();
×
NEW
1314
            QRgb knobValueColor = control->valueToRgb(knob->value());
×
NEW
1315
            color = (color & ~control->m_color.rgb()) | (knobValueColor & control->m_color.rgb());
×
1316

NEW
1317
            matrix->setColor(4, color);
×
NEW
1318
            emit mtxColor5Changed();
×
1319
        }
1320
        else
1321
        {
1322
            // We are not supposed to be here
1323
            Q_ASSERT(false);
×
1324
        }
1325
        emit matrixControlKnobValueChanged(control->m_id, knob->value());
×
1326
    }
1327
}
1328

1329
void VCMatrix::slotMatrixControlKnobValueChanged(int controlID, int value)
×
1330
{
1331
    QList<VCMatrixControl *> customControls = this->customControls();
×
1332
    for (int i = 0; i < customControls.length(); i++)
×
1333
    {
1334
        if (customControls[i]->m_id == controlID)
×
1335
        {
NEW
1336
            if (customControls[i]->m_type == VCMatrixControl::Color1Knob
×
NEW
1337
                    || customControls[i]->m_type == VCMatrixControl::Color2Knob
×
NEW
1338
                    || customControls[i]->m_type == VCMatrixControl::Color3Knob
×
NEW
1339
                    || customControls[i]->m_type == VCMatrixControl::Color4Knob
×
NEW
1340
                    || customControls[i]->m_type == VCMatrixControl::Color5Knob)
×
1341
            {
1342
                KnobWidget *knob = qobject_cast<KnobWidget*>(this->getWidget(customControls[i]));
×
1343
                knob->setValue(value);
×
1344
                break;
×
1345
            }
1346
        }
1347
    }
1348
}
×
1349

1350
void VCMatrix::slotMatrixControlPushButtonClicked(int controlID)
×
1351
{
1352
    QList<VCMatrixControl *> customControls = this->customControls();
×
1353
    for (int i = 0; i < customControls.length(); i++)
×
1354
    {
1355
        if (customControls[i]->m_id == controlID)
×
1356
        {
1357
            QPushButton *btn = qobject_cast<QPushButton*>(this->getWidget(customControls[i]));
×
1358
            btn->click();
×
1359
            break;
×
1360
        }
1361
    }
1362
}
×
1363

1364
void VCMatrix::slotModeChanged(Doc::Mode mode)
×
1365
{
1366
    if (mode == Doc::Operate)
×
1367
        enableWidgetUI(true);
×
1368
    else
1369
        enableWidgetUI(false);
×
1370

1371
    VCWidget::slotModeChanged(mode);
×
1372
}
×
1373

1374
/*********************************************************************
1375
 * External input
1376
 *********************************************************************/
1377

1378
void VCMatrix::slotKeyPressed(const QKeySequence &keySequence)
×
1379
{
1380
    if (acceptsInput() == false)
×
1381
        return;
×
1382

1383
    for (QHash<QWidget *, VCMatrixControl *>::iterator it = m_controls.begin();
×
1384
            it != m_controls.end(); ++it)
×
1385
    {
1386
        VCMatrixControl *control = it.value();
×
1387
        if (control->m_keySequence == keySequence &&
×
1388
                control->widgetType() == VCMatrixControl::Button) // Only for buttons
×
1389
        {
1390
            QPushButton *button = reinterpret_cast<QPushButton*>(it.key());
×
1391
            button->click();
×
1392
        }
1393
    }
1394
}
1395

1396
void VCMatrix::updateFeedback()
×
1397
{
1398
    sendFeedback(m_slider->value());
×
1399

1400
    for (QHash<QWidget *, VCMatrixControl *>::iterator it = m_controls.begin();
×
1401
            it != m_controls.end(); ++it)
×
1402
    {
1403
        VCMatrixControl *control = it.value();
×
1404
        if (control->m_inputSource != NULL)
×
1405
        {
1406
            if (control->widgetType() == VCMatrixControl::Knob)
×
1407
            {
1408
                KnobWidget* knob = reinterpret_cast<KnobWidget*>(it.key());
×
1409
                sendFeedback(knob->value(), control->m_inputSource);
×
1410
            }
1411
            else // if (control->widgetType() == VCMatrixControl::Button)
1412
            {
1413
                QPushButton* button = reinterpret_cast<QPushButton*>(it.key());
×
1414
                sendFeedback(button->isDown() ?
×
1415
                                 control->m_inputSource->feedbackValue(QLCInputFeedback::UpperValue) :
×
1416
                                 control->m_inputSource->feedbackValue(QLCInputFeedback::LowerValue),
×
1417
                                 control->m_inputSource);
×
1418
            }
1419
        }
1420
    }
1421
}
×
1422

1423
void VCMatrix::slotInputValueChanged(quint32 universe, quint32 channel, uchar value)
×
1424
{
1425
    /* Don't let input data through in design mode or if disabled */
1426
    if (acceptsInput() == false)
×
1427
        return;
×
1428

1429
    quint32 pagedCh = (page() << 16) | channel;
×
1430

1431
    if (checkInputSource(universe, pagedCh, value, sender()))
×
1432
    {
1433
        m_slider->setValue((int) value);
×
1434
        return;
×
1435
    }
1436

1437
    for (QHash<QWidget *, VCMatrixControl *>::iterator it = m_controls.begin();
×
1438
            it != m_controls.end(); ++it)
×
1439
    {
1440
        VCMatrixControl *control = it.value();
×
1441
        if (control->m_inputSource != NULL &&
×
1442
                control->m_inputSource->universe() == universe &&
×
1443
                control->m_inputSource->channel() == pagedCh)
×
1444
        {
1445
            if (control->widgetType() == VCMatrixControl::Knob)
×
1446
            {
1447
                KnobWidget* knob = reinterpret_cast<KnobWidget*>(it.key());
×
1448
                knob->setValue(value);
×
1449
            }
1450
            else
1451
            {
1452
                QPushButton *button = reinterpret_cast<QPushButton*>(it.key());
×
1453
                button->click();
×
1454
            }
1455
        }
1456
    }
1457
}
1458

1459
bool VCMatrix::loadXML(QXmlStreamReader &root)
×
1460
{
1461
    QString str;
×
1462

1463
    if (root.name() != KXMLQLCVCMatrix)
×
1464
    {
1465
        qWarning() << Q_FUNC_INFO << "Matrix node not found";
×
1466
        return false;
×
1467
    }
1468

1469
    /* Widget commons */
1470
    loadXMLCommon(root);
×
1471

1472
    // Sorted list for new controls
1473
    QList<VCMatrixControl> newControls;
×
1474

1475
    /* Children */
1476
    while (root.readNextStartElement())
×
1477
    {
1478
        if (root.name() == KXMLQLCWindowState)
×
1479
        {
1480
            bool visible = false;
×
1481
            int x = 0, y = 0, w = 0, h = 0;
×
1482
            loadXMLWindowState(root, &x, &y, &w, &h, &visible);
×
1483
            setGeometry(x, y, w, h);
×
1484
        }
1485
        else if (root.name() == KXMLQLCVCWidgetAppearance)
×
1486
        {
1487
            loadXMLAppearance(root);
×
1488
        }
1489
        else if (root.name() == KXMLQLCVCMatrixFunction)
×
1490
        {
1491
            QXmlStreamAttributes attrs = root.attributes();
×
1492
            str = attrs.value(KXMLQLCVCMatrixFunctionID).toString();
×
1493
            setFunction(str.toUInt());
×
1494
            if (attrs.hasAttribute(KXMLQLCVCMatrixInstantApply))
×
1495
                setInstantChanges(true);
×
1496
            root.skipCurrentElement();
×
1497
        }
1498
        else if (root.name() == KXMLQLCVCWidgetInput)
×
1499
        {
1500
            loadXMLInput(root);
×
1501
        }
1502
        else if (root.name() == KXMLQLCVCMatrixControl)
×
1503
        {
1504
            VCMatrixControl control(0xff);
×
1505
            if (control.loadXML(root))
×
1506
                newControls.insert(std::lower_bound(newControls.begin(), newControls.end(), control), control);
×
1507
        }
1508
        else if (root.name() == KXMLQLCVCMatrixVisibilityMask)
×
1509
        {
1510
            setVisibilityMask(root.readElementText().toUInt());
×
1511
        }
1512
        else
1513
        {
1514
            qWarning() << Q_FUNC_INFO << "Unknown VCMatrix tag:" << root.name().toString();
×
1515
            root.skipCurrentElement();
×
1516
        }
1517
    }
1518

1519
    foreach (VCMatrixControl const& control, newControls)
×
1520
        addCustomControl(control);
×
1521

1522
    return true;
×
1523
}
1524

1525
bool VCMatrix::saveXML(QXmlStreamWriter *doc)
×
1526
{
1527
    Q_ASSERT(doc != NULL);
×
1528

1529
    /* VC button entry */
1530
    doc->writeStartElement(KXMLQLCVCMatrix);
×
1531

1532
    saveXMLCommon(doc);
×
1533

1534
    /* Window state */
1535
    saveXMLWindowState(doc);
×
1536

1537
    /* Appearance */
1538
    saveXMLAppearance(doc);
×
1539

1540
    /* Function */
1541
    doc->writeStartElement(KXMLQLCVCMatrixFunction);
×
1542
    doc->writeAttribute(KXMLQLCVCMatrixFunctionID, QString::number(function()));
×
1543

1544
    if (instantChanges() == true)
×
1545
        doc->writeAttribute(KXMLQLCVCMatrixInstantApply, "true");
×
1546
    doc->writeEndElement();
×
1547

1548
    /* Default controls visibility  */
1549
    if (m_visibilityMask != VCMatrix::defaultVisibilityMask())
×
1550
        doc->writeTextElement(KXMLQLCVCMatrixVisibilityMask, QString::number(m_visibilityMask));
×
1551

1552
    /* Slider External input */
1553
    saveXMLInput(doc);
×
1554

1555
    foreach (VCMatrixControl *control, customControls())
×
1556
        control->saveXML(doc);
×
1557

1558
    /* End the <Matrix> tag */
1559
    doc->writeEndElement();
×
1560

1561
    return true;
×
1562
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc