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

mcallegari / qlcplus / 12611954629

04 Jan 2025 04:17PM UTC coverage: 31.468% (-0.5%) from 31.963%
12611954629

Pull #1649

github

web-flow
Merge d17d3ec9b into 3ed321c32
Pull Request #1649: Function Wizard: create Effects

2 of 53 new or added lines in 2 files covered. (3.77%)

2597 existing lines in 15 files now uncovered.

14093 of 44785 relevant lines covered (31.47%)

26791.82 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 */
83
    m_mtxColor1Button = new QToolButton(this);
×
84
    m_mtxColor1Button->setFixedSize(48, 48);
×
UNCOV
85
    m_mtxColor1Button->setIconSize(QSize(42, 42));
×
86

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

UNCOV
180
    vbox->addLayout(btnHbox);
×
181

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

UNCOV
189
    hBox->addLayout(vbox);
×
190

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

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

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

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

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

UNCOV
223
void VCMatrix::setID(quint32 id)
×
224
{
UNCOV
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);
×
UNCOV
240
    if (matrix->copyFrom(this) == false)
×
241
    {
242
        delete matrix;
×
243
        matrix = NULL;
244
    }
245

UNCOV
246
    return matrix;
×
247
}
248

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

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

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

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

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

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

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

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

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

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

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

310
    if (m_sliderExternalMovement)
×
311
        return;
312

UNCOV
313
    if (value == 0)
×
314
    {
315
        // Make sure we ignore the fade out time
316
        adjustFunctionIntensity(function, 0);
×
UNCOV
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);
×
UNCOV
327
        adjustFunctionIntensity(function, pIntensity * intensity());
×
UNCOV
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

UNCOV
335
    emit sliderValueChanged(value);
×
336
}
337

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

UNCOV
496
void VCMatrix::slotSetAnimationValue(QString name)
×
497
{
498
    for (int i = 0; i < m_presetCombo->count(); i++)
×
499
    {
500
        if (name == m_presetCombo->itemText(i))
×
501
        {
502
            m_presetCombo->setCurrentIndex(i);
×
UNCOV
503
            slotAnimationChanged(i);
×
504
            return;
×
505
        }
506
    }
507
}
508

509
void VCMatrix::slotAnimationChanged(int index)
×
510
{
511
    RGBMatrix* matrix = qobject_cast<RGBMatrix*>(m_doc->function(m_matrixID));
×
512
    if (matrix == NULL || mode() == Doc::Design)
×
UNCOV
513
        return;
×
514

UNCOV
515
    QString pValue = m_presetCombo->itemText(index);
×
UNCOV
516
    RGBAlgorithm* algo = RGBAlgorithm::algorithm(m_doc, pValue);
×
UNCOV
517
    matrix->setAlgorithm(algo);
×
518
    if (instantChanges() == true)
×
UNCOV
519
        matrix->updateColorDelta();
×
520

521
    emit animationValueChanged(pValue);
×
522
}
523

524
QString VCMatrix::animationValue()
×
525
{
526
    return m_presetCombo->currentText();
×
527
}
528

529
void VCMatrix::setVisibilityMask(quint32 mask)
×
530
{
531
    if (mask & ShowSlider) m_slider->show();
×
UNCOV
532
    else m_slider->hide();
×
533

534
    if (mask & ShowLabel) m_label->show();
×
UNCOV
535
    else m_label->hide();
×
536

537
    if (mask & ShowColor1Button) m_mtxColor1Button->show();
×
UNCOV
538
    else m_mtxColor1Button->hide();
×
539

540
    if (mask & ShowColor2Button) m_mtxColor2Button->show();
×
541
    else m_mtxColor2Button->hide();
×
542

UNCOV
543
    if (mask & ShowColor3Button) m_mtxColor3Button->show();
×
544
    else m_mtxColor3Button->hide();
×
545

UNCOV
546
    if (mask & ShowColor4Button) m_mtxColor4Button->show();
×
UNCOV
547
    else m_mtxColor4Button->hide();
×
548

UNCOV
549
    if (mask & ShowColor5Button) m_mtxColor5Button->show();
×
550
    else m_mtxColor5Button->hide();
×
551

UNCOV
552
    if (mask & ShowPresetCombo) m_presetCombo->show();
×
553
    else m_presetCombo->hide();
×
554

555
    m_visibilityMask = mask;
×
UNCOV
556
}
×
557

UNCOV
558
quint32 VCMatrix::visibilityMask() const
×
559
{
UNCOV
560
    return m_visibilityMask;
×
561
}
562

UNCOV
563
quint32 VCMatrix::defaultVisibilityMask()
×
564
{
565
    return ShowSlider
566
        | ShowLabel
567
        | ShowPresetCombo
568
        | ShowColor1Button
569
        | ShowColor2Button
570
        | ShowColor3Button
571
        | ShowColor4Button
572
        | ShowColor5Button
×
573
        ;
574
}
575

576
/*********************************************************************
577
 * Properties
578
 *********************************************************************/
579

580
void VCMatrix::editProperties()
×
581
{
UNCOV
582
    VCMatrixProperties prop(this, m_doc);
×
UNCOV
583
    if (prop.exec() == QDialog::Accepted)
×
UNCOV
584
        m_doc->setModified();
×
585
}
×
586

587
/*************************************************************************
588
 * VCWidget-inherited
589
 *************************************************************************/
590

591
void VCMatrix::adjustIntensity(qreal val)
×
592
{
UNCOV
593
    VCWidget::adjustIntensity(val);
×
594
    this->slotSliderMoved(this->m_slider->value());
×
595
}
×
596

597
/*********************************************************************
598
 * Function attachment
599
 *********************************************************************/
600

UNCOV
601
void VCMatrix::setFunction(quint32 id)
×
602
{
603
    Function *old = m_doc->function(m_matrixID);
×
UNCOV
604
    if (old != NULL)
×
605
    {
606
        disconnect(old, SIGNAL(stopped(quint32)),
×
607
                this, SLOT(slotFunctionStopped()));
UNCOV
608
        disconnect(old, SIGNAL(changed(quint32)),
×
609
                this, SLOT(slotFunctionChanged()));
610
    }
611

612
    RGBMatrix* matrix = qobject_cast<RGBMatrix*> (m_doc->function(id));
×
613

UNCOV
614
    if (matrix == NULL)
×
615
        m_matrixID = Function::invalidId();
×
616
    else
617
    {
618
        m_matrixID = id;
×
UNCOV
619
        connect(matrix, SIGNAL(stopped(quint32)),
×
620
                this, SLOT(slotFunctionStopped()));
UNCOV
621
        connect(matrix, SIGNAL(changed(quint32)),
×
622
                this, SLOT(slotFunctionChanged()));
623
    }
624

625
    slotUpdate();
×
UNCOV
626
}
×
627

628
quint32 VCMatrix::function() const
×
629
{
UNCOV
630
    return m_matrixID;
×
631
}
632

633
void VCMatrix::notifyFunctionStarting(quint32 fid, qreal functionIntensity)
×
634
{
635
    if (mode() == Doc::Design)
×
636
        return;
637

UNCOV
638
    if (fid == m_matrixID)
×
639
        return;
640

641
    int value = SCALE(1.0 - functionIntensity,
×
642
            0, 1.0,
643
            m_slider->minimum(), m_slider->maximum());
UNCOV
644
    if (m_slider->value() > value)
×
645
    {
646
        m_sliderExternalMovement = true;
×
647
        m_slider->setValue(value);
×
UNCOV
648
        m_sliderExternalMovement = false;
×
649

UNCOV
650
        Function* function = m_doc->function(m_matrixID);
×
UNCOV
651
        if (function != NULL)
×
652
        {
653
            qreal pIntensity = qreal(value) / qreal(UCHAR_MAX);
×
UNCOV
654
            adjustFunctionIntensity(function, pIntensity * intensity());
×
UNCOV
655
            if (value == 0 && !function->stopped())
×
656
            {
657
                function->stop(functionParent());
×
UNCOV
658
                resetIntensityOverrideAttribute();
×
659
            }
660
        }
661
    }
662
}
663

UNCOV
664
void VCMatrix::slotFunctionStopped()
×
665
{
UNCOV
666
    m_slider->blockSignals(true);
×
UNCOV
667
    m_slider->setValue(0);
×
UNCOV
668
    resetIntensityOverrideAttribute();
×
669
    m_slider->blockSignals(false);
×
UNCOV
670
}
×
671

672
void VCMatrix::slotFunctionChanged()
×
673
{
674
    m_updateTimer->start(UPDATE_TIMEOUT);
×
UNCOV
675
}
×
676

UNCOV
677
void VCMatrix::slotUpdate()
×
678
{
UNCOV
679
    if (m_matrixID == Function::invalidId())
×
UNCOV
680
        return;
×
681

UNCOV
682
    RGBMatrix *matrix = qobject_cast<RGBMatrix*>(m_doc->function(m_matrixID));
×
683
    if (matrix == NULL)
×
684
        return;
685

UNCOV
686
    QString algorithmName;
×
687
    RGBAlgorithm::Type algorithmType = RGBAlgorithm::Plain;
UNCOV
688
    QHash<QString, QString> algorithmProperties;
×
689
    QString algorithmText;
×
690

691
    {
692
        QMutexLocker locker(&matrix->algorithmMutex());
×
693

694
        RGBAlgorithm *algo = matrix->algorithm();
×
UNCOV
695
        if (algo != NULL)
×
696
        {
UNCOV
697
            algorithmName = algo->name();
×
698
            algorithmType = algo->type();
×
699
            if (algorithmType == RGBAlgorithm::Script)
×
700
            {
701
                algorithmProperties = reinterpret_cast<RGBScript*>(algo)->propertiesAsStrings();
×
702
            }
703
            else if (algorithmType == RGBAlgorithm::Text)
×
704
            {
705
                algorithmText = reinterpret_cast<RGBText*>(algo)->text();
×
706
            }
707
        }
708
    }
709

710
    // Color buttons
711
    QPixmap px(42, 42);
×
712
    px.fill(matrix->getColor(0));
×
713
    m_mtxColor1Button->setIcon(px);
×
714

715
    if (matrix->getColor(1) == QColor())
×
UNCOV
716
        px.fill(Qt::transparent);
×
717
    else
UNCOV
718
        px.fill(matrix->getColor(1));
×
UNCOV
719
    m_mtxColor2Button->setIcon(px);
×
720

721
    if (matrix->getColor(2) == QColor())
×
722
        px.fill(Qt::transparent);
×
723
    else
724
        px.fill(matrix->getColor(2));
×
725
    m_mtxColor3Button->setIcon(px);
×
726

727
    if (matrix->getColor(3) == QColor())
×
UNCOV
728
        px.fill(Qt::transparent);
×
729
    else
730
        px.fill(matrix->getColor(3));
×
731
    m_mtxColor4Button->setIcon(px);
×
732

UNCOV
733
    if (matrix->getColor(4) == QColor())
×
UNCOV
734
        px.fill(Qt::transparent);
×
735
    else
736
        px.fill(matrix->getColor(4));
×
UNCOV
737
    m_mtxColor5Button->setIcon(px);
×
738

739
    // Algo combo box
740
    if (algorithmName != QString())
×
741
    {
UNCOV
742
        m_presetCombo->blockSignals(true);
×
743
        m_presetCombo->setCurrentText(algorithmName);
×
UNCOV
744
        m_presetCombo->blockSignals(false);
×
745
    }
746

747
    // Custom Buttons
748
    for (QHash<QWidget *, VCMatrixControl *>::iterator it = m_controls.begin();
×
749
            it != m_controls.end(); ++it)
×
750
    {
751
        QWidget *widget = it.key();
×
752
        VCMatrixControl *control = it.value();
×
753

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

854
            QPushButton *button = reinterpret_cast<QPushButton*>(it.key());
×
855
            button->setDown(on);
×
856
        }
857
        else if (control->m_type == VCMatrixControl::Text)
×
858
        {
859
            bool on = false;
860
            if (algorithmType == RGBAlgorithm::Text &&
×
861
                algorithmText == control->m_resource)
×
862
            {
863
                on = true;
864
            }
865

UNCOV
866
            QPushButton *button = reinterpret_cast<QPushButton*>(it.key());
×
867
            button->setDown(on);
×
868
        }
869
    }
870

871
    updateFeedback();
×
872
}
873

UNCOV
874
FunctionParent VCMatrix::functionParent() const
×
875
{
876
    return FunctionParent(FunctionParent::ManualVCWidget, id());
×
877
}
878

879
/*********************************************************************
880
 * Instant changes apply
881
 *********************************************************************/
882

883
void VCMatrix::setInstantChanges(bool instantly)
×
884
{
UNCOV
885
    m_instantApply = instantly;
×
886
}
×
887

UNCOV
888
bool VCMatrix::instantChanges() const
×
889
{
890
    return m_instantApply;
×
891
}
892

893
/*********************************************************************
894
 * Custom controls
895
 *********************************************************************/
896

897
void VCMatrix::addCustomControl(VCMatrixControl const& control)
×
898
{
899
    QWidget *controlWidget = NULL;
×
900

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

1101
    Q_ASSERT(controlWidget != NULL);
1102

1103
    if (control.widgetType() == VCMatrixControl::Knob)
×
1104
    {
1105
        connect(reinterpret_cast<KnobWidget*>(controlWidget), SIGNAL(valueChanged(int)),
×
1106
                this, SLOT(slotCustomControlValueChanged()));
1107
    }
1108
    else
1109
    {
UNCOV
1110
        connect(reinterpret_cast<QPushButton*>(controlWidget), SIGNAL(clicked()),
×
1111
                this, SLOT(slotCustomControlClicked()));
1112
    }
1113

1114

1115
    if (mode() == Doc::Design)
×
1116
        controlWidget->setEnabled(false);
×
1117

1118
    VCMatrixControl *c_control = new VCMatrixControl(control);
×
UNCOV
1119
    m_controls[controlWidget] = c_control;
×
1120
    m_widgets[c_control] = controlWidget;
×
1121

1122
    m_controlsLayout->addWidget(controlWidget);
×
1123

1124
    if (m_controls[controlWidget]->m_inputSource != NULL)
×
1125
    {
1126
        setInputSource(m_controls[controlWidget]->m_inputSource, m_controls[controlWidget]->m_id);
×
1127
    }
1128

UNCOV
1129
    slotFunctionChanged(); // Start update timer
×
1130
}
×
1131

UNCOV
1132
void VCMatrix::resetCustomControls()
×
1133
{
1134
    for (QHash<QWidget *, VCMatrixControl *>::iterator it = m_controls.begin();
×
1135
            it != m_controls.end(); ++it)
×
1136
    {
UNCOV
1137
        QWidget* widget = it.key();
×
UNCOV
1138
        m_controlsLayout->removeWidget(widget);
×
1139
        delete widget;
×
1140

UNCOV
1141
        VCMatrixControl* control = it.value();
×
UNCOV
1142
        if (!control->m_inputSource.isNull())
×
UNCOV
1143
            setInputSource(QSharedPointer<QLCInputSource>(), control->m_id);
×
UNCOV
1144
        delete control;
×
1145
    }
UNCOV
1146
    m_controls.clear();
×
UNCOV
1147
    m_widgets.clear();
×
UNCOV
1148
}
×
1149

1150
QList<VCMatrixControl *> VCMatrix::customControls() const
×
1151
{
1152
    QList<VCMatrixControl*> controls = m_controls.values();
×
1153
    std::sort(controls.begin(), controls.end(), VCMatrixControl::compare);
UNCOV
1154
    return controls;
×
1155
}
1156

UNCOV
1157
QMap<quint32,QString> VCMatrix::customControlsMap() const
×
1158
{
1159
    QMap<quint32,QString> map;
1160

1161
    foreach (VCMatrixControl *control, m_controls.values())
×
1162
        map.insert(control->m_id, VCMatrixControl::typeToString(control->m_type));
×
1163

1164
    return map;
×
1165
}
1166

UNCOV
1167
QWidget *VCMatrix::getWidget(VCMatrixControl* control) const
×
1168
{
1169
    return m_widgets[control];
×
1170
}
1171

UNCOV
1172
void VCMatrix::slotCustomControlClicked()
×
1173
{
UNCOV
1174
    QPushButton *btn = qobject_cast<QPushButton*>(sender());
×
1175
    VCMatrixControl *control = m_controls[btn];
×
1176
    if (control != NULL)
×
1177
    {
UNCOV
1178
        RGBMatrix* matrix = qobject_cast<RGBMatrix*>(m_doc->function(m_matrixID));
×
1179
        if (matrix == NULL || mode() == Doc::Design)
×
UNCOV
1180
            return;
×
1181

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

UNCOV
1270
void VCMatrix::slotCustomControlValueChanged()
×
1271
{
UNCOV
1272
    KnobWidget *knob = qobject_cast<KnobWidget*>(sender());
×
UNCOV
1273
    VCMatrixControl *control = m_controls[knob];
×
UNCOV
1274
    if (control != NULL)
×
1275
    {
UNCOV
1276
        RGBMatrix* matrix = qobject_cast<RGBMatrix*>(m_doc->function(m_matrixID));
×
UNCOV
1277
        if (matrix == NULL || mode() == Doc::Design)
×
UNCOV
1278
            return;
×
1279

UNCOV
1280
        if (control->m_type == VCMatrixControl::Color1Knob)
×
1281
        {
UNCOV
1282
            QRgb color = matrix->getColor(0).rgb();
×
UNCOV
1283
            QRgb knobValueColor = control->valueToRgb(knob->value());
×
UNCOV
1284
            color = (color & ~control->m_color.rgb()) | (knobValueColor & control->m_color.rgb());
×
1285

UNCOV
1286
            matrix->setColor(0, color);
×
UNCOV
1287
            if (instantChanges() == true)
×
UNCOV
1288
                matrix->updateColorDelta();
×
UNCOV
1289
            emit mtxColor1Changed();
×
1290
        }
UNCOV
1291
        else if (control->m_type == VCMatrixControl::Color2Knob)
×
1292
        {
UNCOV
1293
            QRgb color = matrix->getColor(1).rgb();
×
UNCOV
1294
            QRgb knobValueColor = control->valueToRgb(knob->value());
×
UNCOV
1295
            color = (color & ~control->m_color.rgb()) | (knobValueColor & control->m_color.rgb());
×
1296

UNCOV
1297
            matrix->setColor(1, color);
×
UNCOV
1298
            if (instantChanges() == true)
×
UNCOV
1299
                matrix->updateColorDelta();
×
UNCOV
1300
            emit mtxColor2Changed();
×
1301
        }
UNCOV
1302
        else if (control->m_type == VCMatrixControl::Color3Knob)
×
1303
        {
UNCOV
1304
            QRgb color = matrix->getColor(2).rgb();
×
UNCOV
1305
            QRgb knobValueColor = control->valueToRgb(knob->value());
×
UNCOV
1306
            color = (color & ~control->m_color.rgb()) | (knobValueColor & control->m_color.rgb());
×
1307

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

UNCOV
1317
            matrix->setColor(3, color);
×
UNCOV
1318
            emit mtxColor4Changed();
×
1319
        }
UNCOV
1320
        else if (control->m_type == VCMatrixControl::Color5Knob)
×
1321
        {
UNCOV
1322
            QRgb color = matrix->getColor(4).rgb();
×
UNCOV
1323
            QRgb knobValueColor = control->valueToRgb(knob->value());
×
UNCOV
1324
            color = (color & ~control->m_color.rgb()) | (knobValueColor & control->m_color.rgb());
×
1325

UNCOV
1326
            matrix->setColor(4, color);
×
UNCOV
1327
            emit mtxColor5Changed();
×
1328
        }
1329
        else
1330
        {
1331
            // We are not supposed to be here
1332
            Q_ASSERT(false);
1333
        }
UNCOV
1334
        emit matrixControlKnobValueChanged(control->m_id, knob->value());
×
1335
    }
1336
}
1337

UNCOV
1338
void VCMatrix::slotMatrixControlKnobValueChanged(int controlID, int value)
×
1339
{
UNCOV
1340
    QList<VCMatrixControl *> customControls = this->customControls();
×
UNCOV
1341
    for (int i = 0; i < customControls.length(); i++)
×
1342
    {
UNCOV
1343
        if (customControls[i]->m_id == controlID)
×
1344
        {
UNCOV
1345
            if (customControls[i]->m_type == VCMatrixControl::Color1Knob
×
UNCOV
1346
                    || customControls[i]->m_type == VCMatrixControl::Color2Knob
×
UNCOV
1347
                    || customControls[i]->m_type == VCMatrixControl::Color3Knob
×
UNCOV
1348
                    || customControls[i]->m_type == VCMatrixControl::Color4Knob
×
UNCOV
1349
                    || customControls[i]->m_type == VCMatrixControl::Color5Knob)
×
1350
            {
UNCOV
1351
                KnobWidget *knob = qobject_cast<KnobWidget*>(this->getWidget(customControls[i]));
×
UNCOV
1352
                knob->setValue(value);
×
1353
                break;
1354
            }
1355
        }
1356
    }
UNCOV
1357
}
×
1358

UNCOV
1359
void VCMatrix::slotMatrixControlPushButtonClicked(int controlID)
×
1360
{
UNCOV
1361
    QList<VCMatrixControl *> customControls = this->customControls();
×
UNCOV
1362
    for (int i = 0; i < customControls.length(); i++)
×
1363
    {
UNCOV
1364
        if (customControls[i]->m_id == controlID)
×
1365
        {
UNCOV
1366
            QPushButton *btn = qobject_cast<QPushButton*>(this->getWidget(customControls[i]));
×
UNCOV
1367
            btn->click();
×
1368
            break;
1369
        }
1370
    }
UNCOV
1371
}
×
1372

UNCOV
1373
void VCMatrix::slotModeChanged(Doc::Mode mode)
×
1374
{
UNCOV
1375
    if (mode == Doc::Operate)
×
UNCOV
1376
        enableWidgetUI(true);
×
1377
    else
UNCOV
1378
        enableWidgetUI(false);
×
1379

UNCOV
1380
    VCWidget::slotModeChanged(mode);
×
UNCOV
1381
}
×
1382

1383
/*********************************************************************
1384
 * External input
1385
 *********************************************************************/
1386

UNCOV
1387
void VCMatrix::slotKeyPressed(const QKeySequence &keySequence)
×
1388
{
UNCOV
1389
    if (acceptsInput() == false)
×
1390
        return;
1391

UNCOV
1392
    for (QHash<QWidget *, VCMatrixControl *>::iterator it = m_controls.begin();
×
UNCOV
1393
            it != m_controls.end(); ++it)
×
1394
    {
UNCOV
1395
        VCMatrixControl *control = it.value();
×
UNCOV
1396
        if (control->m_keySequence == keySequence &&
×
UNCOV
1397
                control->widgetType() == VCMatrixControl::Button) // Only for buttons
×
1398
        {
UNCOV
1399
            QPushButton *button = reinterpret_cast<QPushButton*>(it.key());
×
UNCOV
1400
            button->click();
×
1401
        }
1402
    }
1403
}
1404

UNCOV
1405
void VCMatrix::updateFeedback()
×
1406
{
UNCOV
1407
    sendFeedback(m_slider->value());
×
1408

UNCOV
1409
    for (QHash<QWidget *, VCMatrixControl *>::iterator it = m_controls.begin();
×
UNCOV
1410
            it != m_controls.end(); ++it)
×
1411
    {
UNCOV
1412
        VCMatrixControl *control = it.value();
×
UNCOV
1413
        if (control->m_inputSource != NULL)
×
1414
        {
UNCOV
1415
            if (control->widgetType() == VCMatrixControl::Knob)
×
1416
            {
UNCOV
1417
                KnobWidget* knob = reinterpret_cast<KnobWidget*>(it.key());
×
UNCOV
1418
                sendFeedback(knob->value(), control->m_inputSource);
×
1419
            }
1420
            else // if (control->widgetType() == VCMatrixControl::Button)
1421
            {
UNCOV
1422
                QPushButton* button = reinterpret_cast<QPushButton*>(it.key());
×
UNCOV
1423
                sendFeedback(button->isDown() ?
×
UNCOV
1424
                                 control->m_inputSource->feedbackValue(QLCInputFeedback::UpperValue) :
×
UNCOV
1425
                                 control->m_inputSource->feedbackValue(QLCInputFeedback::LowerValue),
×
1426
                                 control->m_inputSource);
1427
            }
1428
        }
1429
    }
UNCOV
1430
}
×
1431

UNCOV
1432
void VCMatrix::slotInputValueChanged(quint32 universe, quint32 channel, uchar value)
×
1433
{
1434
    /* Don't let input data through in design mode or if disabled */
UNCOV
1435
    if (acceptsInput() == false)
×
1436
        return;
1437

UNCOV
1438
    quint32 pagedCh = (page() << 16) | channel;
×
1439

UNCOV
1440
    if (checkInputSource(universe, pagedCh, value, sender()))
×
1441
    {
UNCOV
1442
        m_slider->setValue((int) value);
×
UNCOV
1443
        return;
×
1444
    }
1445

UNCOV
1446
    for (QHash<QWidget *, VCMatrixControl *>::iterator it = m_controls.begin();
×
UNCOV
1447
            it != m_controls.end(); ++it)
×
1448
    {
UNCOV
1449
        VCMatrixControl *control = it.value();
×
UNCOV
1450
        if (control->m_inputSource != NULL &&
×
UNCOV
1451
                control->m_inputSource->universe() == universe &&
×
UNCOV
1452
                control->m_inputSource->channel() == pagedCh)
×
1453
        {
UNCOV
1454
            if (control->widgetType() == VCMatrixControl::Knob)
×
1455
            {
UNCOV
1456
                KnobWidget* knob = reinterpret_cast<KnobWidget*>(it.key());
×
UNCOV
1457
                knob->setValue(value);
×
1458
            }
1459
            else
1460
            {
UNCOV
1461
                QPushButton *button = reinterpret_cast<QPushButton*>(it.key());
×
UNCOV
1462
                button->click();
×
1463
            }
1464
        }
1465
    }
1466
}
1467

UNCOV
1468
bool VCMatrix::loadXML(QXmlStreamReader &root)
×
1469
{
UNCOV
1470
    QString str;
×
1471

UNCOV
1472
    if (root.name() != KXMLQLCVCMatrix)
×
1473
    {
UNCOV
1474
        qWarning() << Q_FUNC_INFO << "Matrix node not found";
×
UNCOV
1475
        return false;
×
1476
    }
1477

1478
    /* Widget commons */
UNCOV
1479
    loadXMLCommon(root);
×
1480

1481
    // Sorted list for new controls
UNCOV
1482
    QList<VCMatrixControl> newControls;
×
1483

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

UNCOV
1528
    foreach (VCMatrixControl const& control, newControls)
×
UNCOV
1529
        addCustomControl(control);
×
1530

1531
    return true;
1532
}
1533

UNCOV
1534
bool VCMatrix::saveXML(QXmlStreamWriter *doc)
×
1535
{
1536
    Q_ASSERT(doc != NULL);
1537

1538
    /* VC button entry */
UNCOV
1539
    doc->writeStartElement(KXMLQLCVCMatrix);
×
1540

UNCOV
1541
    saveXMLCommon(doc);
×
1542

1543
    /* Window state */
UNCOV
1544
    saveXMLWindowState(doc);
×
1545

1546
    /* Appearance */
UNCOV
1547
    saveXMLAppearance(doc);
×
1548

1549
    /* Function */
UNCOV
1550
    doc->writeStartElement(KXMLQLCVCMatrixFunction);
×
UNCOV
1551
    doc->writeAttribute(KXMLQLCVCMatrixFunctionID, QString::number(function()));
×
1552

UNCOV
1553
    if (instantChanges() == true)
×
UNCOV
1554
        doc->writeAttribute(KXMLQLCVCMatrixInstantApply, "true");
×
UNCOV
1555
    doc->writeEndElement();
×
1556

1557
    /* Default controls visibility  */
UNCOV
1558
    if (m_visibilityMask != VCMatrix::defaultVisibilityMask())
×
UNCOV
1559
        doc->writeTextElement(KXMLQLCVCMatrixVisibilityMask, QString::number(m_visibilityMask));
×
1560

1561
    /* Slider External input */
UNCOV
1562
    saveXMLInput(doc);
×
1563

UNCOV
1564
    foreach (VCMatrixControl *control, customControls())
×
UNCOV
1565
        control->saveXML(doc);
×
1566

1567
    /* End the <Matrix> tag */
UNCOV
1568
    doc->writeEndElement();
×
1569

UNCOV
1570
    return true;
×
1571
}
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

© 2026 Coveralls, Inc