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

mcallegari / qlcplus / 8440834527

26 Mar 2024 06:08PM UTC coverage: 31.709% (-0.4%) from 32.081%
8440834527

Pull #1422

github

web-flow
Merge 34f746340 into 7e2ec9324
Pull Request #1422: RgbScript make stage colors available to scripts

50 of 898 new or added lines in 11 files covered. (5.57%)

9 existing lines in 4 files now uncovered.

15408 of 48592 relevant lines covered (31.71%)

22631.0 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(&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
QWidget *VCMatrix::getWidget(VCMatrixControl* control) const
×
1149
{
1150
    return m_widgets[control];
×
1151
}
1152

1153
void VCMatrix::slotCustomControlClicked()
×
1154
{
1155
    QPushButton *btn = qobject_cast<QPushButton*>(sender());
×
1156
    VCMatrixControl *control = m_controls[btn];
×
1157
    if (control != NULL)
×
1158
    {
1159
        RGBMatrix* matrix = qobject_cast<RGBMatrix*>(m_doc->function(m_matrixID));
×
1160
        if (matrix == NULL || mode() == Doc::Design)
×
1161
            return;
×
1162

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

1251
void VCMatrix::slotCustomControlValueChanged()
×
1252
{
1253
    KnobWidget *knob = qobject_cast<KnobWidget*>(sender());
×
1254
    VCMatrixControl *control = m_controls[knob];
×
1255
    if (control != NULL)
×
1256
    {
1257
        RGBMatrix* matrix = qobject_cast<RGBMatrix*>(m_doc->function(m_matrixID));
×
1258
        if (matrix == NULL || mode() == Doc::Design)
×
1259
            return;
×
1260

NEW
1261
        if (control->m_type == VCMatrixControl::Color1Knob)
×
1262
        {
NEW
1263
            QRgb color = matrix->getColor(0).rgb();
×
1264
            QRgb knobValueColor = control->valueToRgb(knob->value());
×
1265
            color = (color & ~control->m_color.rgb()) | (knobValueColor & control->m_color.rgb());
×
1266

NEW
1267
            matrix->setColor(0, color);
×
1268
            if (instantChanges() == true)
×
1269
                matrix->updateColorDelta();
×
NEW
1270
            emit mtxColor1Changed();
×
1271
        }
NEW
1272
        else if (control->m_type == VCMatrixControl::Color2Knob)
×
1273
        {
NEW
1274
            QRgb color = matrix->getColor(1).rgb();
×
1275
            QRgb knobValueColor = control->valueToRgb(knob->value());
×
1276
            color = (color & ~control->m_color.rgb()) | (knobValueColor & control->m_color.rgb());
×
1277

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

NEW
1289
            matrix->setColor(2, color);
×
NEW
1290
            emit mtxColor3Changed();
×
1291
        }
NEW
1292
        else if (control->m_type == VCMatrixControl::Color4Knob)
×
1293
        {
NEW
1294
            QRgb color = matrix->getColor(3).rgb();
×
NEW
1295
            QRgb knobValueColor = control->valueToRgb(knob->value());
×
NEW
1296
            color = (color & ~control->m_color.rgb()) | (knobValueColor & control->m_color.rgb());
×
1297

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

NEW
1307
            matrix->setColor(4, color);
×
NEW
1308
            emit mtxColor5Changed();
×
1309
        }
1310
        else
1311
        {
1312
            // We are not supposed to be here
1313
            Q_ASSERT(false);
×
1314
        }
1315
        emit matrixControlKnobValueChanged(control->m_id, knob->value());
×
1316
    }
1317
}
1318

1319
void VCMatrix::slotMatrixControlKnobValueChanged(int controlID, int value)
×
1320
{
1321
    QList<VCMatrixControl *> customControls = this->customControls();
×
1322
    for (int i = 0; i < customControls.length(); i++)
×
1323
    {
1324
        if (customControls[i]->m_id == controlID)
×
1325
        {
NEW
1326
            if (customControls[i]->m_type == VCMatrixControl::Color1Knob
×
NEW
1327
                    || customControls[i]->m_type == VCMatrixControl::Color2Knob
×
NEW
1328
                    || customControls[i]->m_type == VCMatrixControl::Color3Knob
×
NEW
1329
                    || customControls[i]->m_type == VCMatrixControl::Color4Knob
×
NEW
1330
                    || customControls[i]->m_type == VCMatrixControl::Color5Knob)
×
1331
            {
1332
                KnobWidget *knob = qobject_cast<KnobWidget*>(this->getWidget(customControls[i]));
×
1333
                knob->setValue(value);
×
1334
                break;
×
1335
            }
1336
        }
1337
    }
1338
}
×
1339

1340
void VCMatrix::slotMatrixControlPushButtonClicked(int controlID)
×
1341
{
1342
    QList<VCMatrixControl *> customControls = this->customControls();
×
1343
    for (int i = 0; i < customControls.length(); i++)
×
1344
    {
1345
        if (customControls[i]->m_id == controlID)
×
1346
        {
1347
            QPushButton *btn = qobject_cast<QPushButton*>(this->getWidget(customControls[i]));
×
1348
            btn->click();
×
1349
            break;
×
1350
        }
1351
    }
1352
}
×
1353

1354
void VCMatrix::slotModeChanged(Doc::Mode mode)
×
1355
{
1356
    if (mode == Doc::Operate)
×
1357
        enableWidgetUI(true);
×
1358
    else
1359
        enableWidgetUI(false);
×
1360

1361
    VCWidget::slotModeChanged(mode);
×
1362
}
×
1363

1364
/*********************************************************************
1365
 * External input
1366
 *********************************************************************/
1367

1368
void VCMatrix::slotKeyPressed(const QKeySequence &keySequence)
×
1369
{
1370
    if (acceptsInput() == false)
×
1371
        return;
×
1372

1373
    for (QHash<QWidget *, VCMatrixControl *>::iterator it = m_controls.begin();
×
1374
            it != m_controls.end(); ++it)
×
1375
    {
1376
        VCMatrixControl *control = it.value();
×
1377
        if (control->m_keySequence == keySequence &&
×
1378
                control->widgetType() == VCMatrixControl::Button) // Only for buttons
×
1379
        {
1380
            QPushButton *button = reinterpret_cast<QPushButton*>(it.key());
×
1381
            button->click();
×
1382
        }
1383
    }
1384
}
1385

1386
void VCMatrix::updateFeedback()
×
1387
{
1388
    sendFeedback(m_slider->value());
×
1389

1390
    for (QHash<QWidget *, VCMatrixControl *>::iterator it = m_controls.begin();
×
1391
            it != m_controls.end(); ++it)
×
1392
    {
1393
        VCMatrixControl *control = it.value();
×
1394
        if (control->m_inputSource != NULL)
×
1395
        {
1396
            if (control->widgetType() == VCMatrixControl::Knob)
×
1397
            {
1398
                KnobWidget* knob = reinterpret_cast<KnobWidget*>(it.key());
×
1399
                sendFeedback(knob->value(), control->m_inputSource);
×
1400
            }
1401
            else // if (control->widgetType() == VCMatrixControl::Button)
1402
            {
1403
                QPushButton* button = reinterpret_cast<QPushButton*>(it.key());
×
1404
                sendFeedback(button->isDown() ?
×
1405
                                 control->m_inputSource->feedbackValue(QLCInputFeedback::UpperValue) :
×
1406
                                 control->m_inputSource->feedbackValue(QLCInputFeedback::LowerValue),
×
1407
                                 control->m_inputSource);
×
1408
            }
1409
        }
1410
    }
1411
}
×
1412

1413
void VCMatrix::slotInputValueChanged(quint32 universe, quint32 channel, uchar value)
×
1414
{
1415
    /* Don't let input data through in design mode or if disabled */
1416
    if (acceptsInput() == false)
×
1417
        return;
×
1418

1419
    quint32 pagedCh = (page() << 16) | channel;
×
1420

1421
    if (checkInputSource(universe, pagedCh, value, sender()))
×
1422
    {
1423
        m_slider->setValue((int) value);
×
1424
        return;
×
1425
    }
1426

1427
    for (QHash<QWidget *, VCMatrixControl *>::iterator it = m_controls.begin();
×
1428
            it != m_controls.end(); ++it)
×
1429
    {
1430
        VCMatrixControl *control = it.value();
×
1431
        if (control->m_inputSource != NULL &&
×
1432
                control->m_inputSource->universe() == universe &&
×
1433
                control->m_inputSource->channel() == pagedCh)
×
1434
        {
1435
            if (control->widgetType() == VCMatrixControl::Knob)
×
1436
            {
1437
                KnobWidget* knob = reinterpret_cast<KnobWidget*>(it.key());
×
1438
                knob->setValue(value);
×
1439
            }
1440
            else
1441
            {
1442
                QPushButton *button = reinterpret_cast<QPushButton*>(it.key());
×
1443
                button->click();
×
1444
            }
1445
        }
1446
    }
1447
}
1448

1449
bool VCMatrix::loadXML(QXmlStreamReader &root)
×
1450
{
1451
    QString str;
×
1452

1453
    if (root.name() != KXMLQLCVCMatrix)
×
1454
    {
1455
        qWarning() << Q_FUNC_INFO << "Matrix node not found";
×
1456
        return false;
×
1457
    }
1458

1459
    /* Widget commons */
1460
    loadXMLCommon(root);
×
1461

1462
    // Sorted list for new controls
1463
    QList<VCMatrixControl> newControls;
×
1464

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

1509
    foreach (VCMatrixControl const& control, newControls)
×
1510
        addCustomControl(control);
×
1511

1512
    return true;
×
1513
}
1514

1515
bool VCMatrix::saveXML(QXmlStreamWriter *doc)
×
1516
{
1517
    Q_ASSERT(doc != NULL);
×
1518

1519
    /* VC button entry */
1520
    doc->writeStartElement(KXMLQLCVCMatrix);
×
1521

1522
    saveXMLCommon(doc);
×
1523

1524
    /* Window state */
1525
    saveXMLWindowState(doc);
×
1526

1527
    /* Appearance */
1528
    saveXMLAppearance(doc);
×
1529

1530
    /* Function */
1531
    doc->writeStartElement(KXMLQLCVCMatrixFunction);
×
1532
    doc->writeAttribute(KXMLQLCVCMatrixFunctionID, QString::number(function()));
×
1533

1534
    if (instantChanges() == true)
×
1535
        doc->writeAttribute(KXMLQLCVCMatrixInstantApply, "true");
×
1536
    doc->writeEndElement();
×
1537

1538
    /* Default controls visibility  */
1539
    if (m_visibilityMask != VCMatrix::defaultVisibilityMask())
×
1540
        doc->writeTextElement(KXMLQLCVCMatrixVisibilityMask, QString::number(m_visibilityMask));
×
1541

1542
    /* Slider External input */
1543
    saveXMLInput(doc);
×
1544

1545
    foreach (VCMatrixControl *control, customControls())
×
1546
        control->saveXML(doc);
×
1547

1548
    /* End the <Matrix> tag */
1549
    doc->writeEndElement();
×
1550

1551
    return true;
×
1552
}
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