• 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/rgbmatrixeditor.cpp
1
/*
2
  Q Light Controller
3
  rgbmatrixeditor.cpp
4

5
  Copyright (c) Heikki Junnila
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 <QGraphicsEllipseItem>
21
#include <QGraphicsRectItem>
22
#include <QGraphicsEffect>
23
#include <QGraphicsScene>
24
#include <QGraphicsView>
25
#include <QColorDialog>
26
#include <QFileDialog>
27
#include <QFontDialog>
28
#include <QGradient>
29
#include <QSettings>
30
#include <QComboBox>
31
#include <QLineEdit>
32
#include <QSpinBox>
33
#include <QLabel>
34
#include <QTimer>
35
#include <QDebug>
36
#include <QMutex>
37

38
#include "fixtureselection.h"
39
#include "speeddialwidget.h"
40
#include "rgbmatrixeditor.h"
41
#include "qlcfixturehead.h"
42
#include "qlcmacros.h"
43
#include "rgbimage.h"
44
#include "sequence.h"
45
#include "rgbitem.h"
46
#include "rgbtext.h"
47
#include "scene.h"
48

49
#define SETTINGS_GEOMETRY "rgbmatrixeditor/geometry"
50
#define RECT_SIZE 30
51
#define RECT_PADDING 0
52
#define ITEM_SIZE 28
53
#define ITEM_PADDING 2
54

55
/****************************************************************************
56
 * Initialization
57
 ****************************************************************************/
58

59
RGBMatrixEditor::RGBMatrixEditor(QWidget* parent, RGBMatrix* mtx, Doc* doc)
×
60
    : QWidget(parent)
61
    , m_doc(doc)
62
    , m_matrix(mtx)
63
    , m_previewHandler(new RGBMatrixStep())
×
64
    , m_speedDials(NULL)
65
    , m_scene(new QGraphicsScene(this))
×
66
    , m_previewTimer(new QTimer(this))
×
67
    , m_previewIterator(0)
×
68
{
69
    Q_ASSERT(doc != NULL);
70
    Q_ASSERT(mtx != NULL);
71

72
    setupUi(this);
×
73

74
    // Set a nice gradient backdrop
75
    m_scene->setBackgroundBrush(Qt::darkGray);
×
76
    QLinearGradient gradient(200, 200, 200, 2000);
×
77
    gradient.setSpread(QGradient::ReflectSpread);
78
    m_scene->setBackgroundBrush(gradient);
×
79

80
    connect(m_previewTimer, SIGNAL(timeout()), this, SLOT(slotPreviewTimeout()));
×
81
    connect(m_doc, SIGNAL(modeChanged(Doc::Mode)), this, SLOT(slotModeChanged(Doc::Mode)));
×
82
    connect(m_doc, SIGNAL(fixtureGroupAdded(quint32)), this, SLOT(slotFixtureGroupAdded()));
×
83
    connect(m_doc, SIGNAL(fixtureGroupRemoved(quint32)), this, SLOT(slotFixtureGroupRemoved()));
×
84
    connect(m_doc, SIGNAL(fixtureGroupChanged(quint32)), this, SLOT(slotFixtureGroupChanged(quint32)));
×
85

86
    init();
×
87

88
    slotModeChanged(m_doc->mode());
×
89

90
    // Set focus to the editor
91
    m_nameEdit->setFocus();
×
92
}
×
93

94
RGBMatrixEditor::~RGBMatrixEditor()
×
95
{
96
    m_previewTimer->stop();
×
97

98
    if (m_testButton->isChecked() == true)
×
99
        m_matrix->stopAndWait();
×
100

101
    delete m_previewHandler;
×
102
}
×
103

104
void RGBMatrixEditor::stopTest()
×
105
{
106
    if (m_testButton->isChecked() == true)
×
107
        m_testButton->click();
×
108
}
×
109

110
void RGBMatrixEditor::slotFunctionManagerActive(bool active)
×
111
{
112
    if (active == true)
×
113
    {
114
        if (m_speedDials == NULL)
×
115
            updateSpeedDials();
×
116
    }
117
    else
118
    {
119
        if (m_speedDials != NULL)
×
120
            m_speedDials->deleteLater();
×
121
        m_speedDials = NULL;
×
122
    }
123
}
×
124

125
void RGBMatrixEditor::init()
×
126
{
127
    /* Name */
128
    m_nameEdit->setText(m_matrix->name());
×
129
    m_nameEdit->setSelection(0, m_matrix->name().length());
×
130

131
    /* Running order */
132
    switch (m_matrix->runOrder())
×
133
    {
134
        default:
×
135
        case Function::Loop:
136
            m_loop->setChecked(true);
×
137
        break;
138
        case Function::PingPong:
×
139
            m_pingPong->setChecked(true);
×
140
        break;
141
        case Function::SingleShot:
×
142
            m_singleShot->setChecked(true);
×
143
        break;
144
    }
145

146
    /* Running direction */
147
    switch (m_matrix->direction())
×
148
    {
149
        default:
×
150
        case Function::Forward:
151
            m_forward->setChecked(true);
×
152
        break;
153
        case Function::Backward:
×
154
            m_backward->setChecked(true);
×
155
        break;
156
    }
157

158

159
    /* Blend mode */
160
    m_blendModeCombo->setCurrentIndex(m_matrix->blendMode());
×
161

162
    /* Color mode */
163
    m_controlModeCombo->setCurrentIndex(m_matrix->controlMode());
×
164

165
    /* Dimmer control */
166
    if (m_matrix->dimmerControl())
×
167
        m_dimmerControlCb->setChecked(m_matrix->dimmerControl());
×
168
    else
169
        m_intensityGroup->hide();
×
170

171
    fillPatternCombo();
×
172
    fillFixtureGroupCombo();
×
173
    fillAnimationCombo();
×
174
    fillImageAnimationCombo();
×
175

176
    QPixmap pm(50, 26);
×
177
    pm.fill(m_matrix->getColor(0));
×
178
    m_mtxColor1Button->setIcon(QIcon(pm));
×
179

180
    if (m_matrix->getColor(1).isValid())
×
181
        pm.fill(m_matrix->getColor(1));
×
182
    else
183
        pm.fill(Qt::transparent);
×
184
    m_mtxColor2Button->setIcon(QIcon(pm));
×
185

186
    if (m_matrix->getColor(2).isValid())
×
187
        pm.fill(m_matrix->getColor(2));
×
188
    else
189
        pm.fill(Qt::transparent);
×
UNCOV
190
    m_mtxColor3Button->setIcon(QIcon(pm));
×
191

UNCOV
192
    if (m_matrix->getColor(3).isValid())
×
193
        pm.fill(m_matrix->getColor(3));
×
194
    else
195
        pm.fill(Qt::transparent);
×
UNCOV
196
    m_mtxColor4Button->setIcon(QIcon(pm));
×
197

UNCOV
198
    if (m_matrix->getColor(4).isValid())
×
199
        pm.fill(m_matrix->getColor(4));
×
200
    else
201
        pm.fill(Qt::transparent);
×
UNCOV
202
    m_mtxColor5Button->setIcon(QIcon(pm));
×
203

UNCOV
204
    updateExtraOptions();
×
205
    updateSpeedDials();
×
206

207
    connect(m_nameEdit, SIGNAL(textEdited(const QString&)),
×
208
            this, SLOT(slotNameEdited(const QString&)));
209
    connect(m_speedDialButton, SIGNAL(toggled(bool)),
×
210
            this, SLOT(slotSpeedDialToggle(bool)));
211
    connect(m_saveToSequenceButton, SIGNAL(clicked()),
×
212
            this, SLOT(slotSaveToSequenceClicked()));
213
    connect(m_shapeButton, SIGNAL(toggled(bool)),
×
214
            this, SLOT(slotShapeToggle(bool)));
215
    connect(m_patternCombo, SIGNAL(activated(int)),
×
216
            this, SLOT(slotPatternActivated(int)));
217
    connect(m_fixtureGroupCombo, SIGNAL(activated(int)),
×
218
            this, SLOT(slotFixtureGroupActivated(int)));
219
    connect(m_blendModeCombo, SIGNAL(activated(int)),
×
220
            this, SLOT(slotBlendModeChanged(int)));
221
    connect(m_controlModeCombo, SIGNAL(activated(int)),
×
222
            this, SLOT(slotControlModeChanged(int)));
223
    connect(m_mtxColor1Button, SIGNAL(clicked()),
×
224
            this, SLOT(slotMtxColor1ButtonClicked()));
225
    connect(m_mtxColor2Button, SIGNAL(clicked()),
×
226
            this, SLOT(slotMtxColor2ButtonClicked()));
UNCOV
227
    connect(m_resetMtxColor2Button, SIGNAL(clicked()),
×
228
            this, SLOT(slotResetMtxColor2ButtonClicked()));
229
    connect(m_mtxColor3Button, SIGNAL(clicked()),
×
230
            this, SLOT(slotMtxColor3ButtonClicked()));
231
    connect(m_resetMtxColor3Button, SIGNAL(clicked()),
×
232
            this, SLOT(slotResetMtxColor3ButtonClicked()));
233
    connect(m_mtxColor4Button, SIGNAL(clicked()),
×
234
            this, SLOT(slotMtxColor4ButtonClicked()));
UNCOV
235
    connect(m_resetMtxColor4Button, SIGNAL(clicked()),
×
236
            this, SLOT(slotResetMtxColor4ButtonClicked()));
UNCOV
237
    connect(m_mtxColor5Button, SIGNAL(clicked()),
×
238
            this, SLOT(slotMtxColor5ButtonClicked()));
239
    connect(m_resetMtxColor5Button, SIGNAL(clicked()),
×
240
            this, SLOT(slotResetMtxColor5ButtonClicked()));
241
    connect(m_textEdit, SIGNAL(textEdited(const QString&)),
×
242
            this, SLOT(slotTextEdited(const QString&)));
UNCOV
243
    connect(m_fontButton, SIGNAL(clicked()),
×
244
            this, SLOT(slotFontButtonClicked()));
UNCOV
245
    connect(m_animationCombo, SIGNAL(activated(int)),
×
246
            this, SLOT(slotAnimationActivated(int)));
UNCOV
247
    connect(m_imageEdit, SIGNAL(editingFinished()),
×
248
            this, SLOT(slotImageEdited()));
249
    connect(m_imageButton, SIGNAL(clicked()),
×
250
            this, SLOT(slotImageButtonClicked()));
UNCOV
251
    connect(m_imageAnimationCombo, SIGNAL(activated(int)),
×
252
            this, SLOT(slotImageAnimationActivated(int)));
253
    connect(m_xOffsetSpin, SIGNAL(valueChanged(int)),
×
254
            this, SLOT(slotOffsetSpinChanged()));
255
    connect(m_yOffsetSpin, SIGNAL(valueChanged(int)),
×
256
            this, SLOT(slotOffsetSpinChanged()));
257

258
    connect(m_loop, SIGNAL(clicked()), this, SLOT(slotLoopClicked()));
×
259
    connect(m_pingPong, SIGNAL(clicked()), this, SLOT(slotPingPongClicked()));
×
UNCOV
260
    connect(m_singleShot, SIGNAL(clicked()), this, SLOT(slotSingleShotClicked()));
×
261
    connect(m_forward, SIGNAL(clicked()), this, SLOT(slotForwardClicked()));
×
262
    connect(m_backward, SIGNAL(clicked()), this, SLOT(slotBackwardClicked()));
×
263
    connect(m_dimmerControlCb, SIGNAL(clicked()), this, SLOT(slotDimmerControlClicked()));
×
264

265
    // Test slots
266
    connect(m_testButton, SIGNAL(clicked(bool)),
×
267
            this, SLOT(slotTestClicked()));
268

269
    m_preview->setScene(m_scene);
×
UNCOV
270
    if (createPreviewItems() == true)
×
271
        m_previewTimer->start(MasterTimer::tick());
×
272
}
×
273

274
void RGBMatrixEditor::updateSpeedDials()
×
275
{
276
    if (m_speedDialButton->isChecked() == false)
×
277
        return;
278

UNCOV
279
    if (m_speedDials != NULL)
×
280
        return;
281

282
    m_speedDials = new SpeedDialWidget(this);
×
283
    m_speedDials->setAttribute(Qt::WA_DeleteOnClose);
×
UNCOV
284
    m_speedDials->setWindowTitle(m_matrix->name());
×
285
    m_speedDials->show();
×
286
    m_speedDials->setFadeInSpeed(m_matrix->fadeInSpeed());
×
UNCOV
287
    m_speedDials->setFadeOutSpeed(m_matrix->fadeOutSpeed());
×
288
    if ((int)m_matrix->duration() < 0)
×
UNCOV
289
        m_speedDials->setDuration(m_matrix->duration());
×
290
    else
291
        m_speedDials->setDuration(m_matrix->duration() - m_matrix->fadeInSpeed());
×
292
    connect(m_speedDials, SIGNAL(fadeInChanged(int)), this, SLOT(slotFadeInChanged(int)));
×
UNCOV
293
    connect(m_speedDials, SIGNAL(fadeOutChanged(int)), this, SLOT(slotFadeOutChanged(int)));
×
294
    connect(m_speedDials, SIGNAL(holdChanged(int)), this, SLOT(slotHoldChanged(int)));
×
UNCOV
295
    connect(m_speedDials, SIGNAL(holdTapped()), this, SLOT(slotDurationTapped()));
×
296
    connect(m_speedDials, SIGNAL(destroyed(QObject*)), this, SLOT(slotDialDestroyed(QObject*)));
×
297
}
298

299
void RGBMatrixEditor::fillPatternCombo()
×
300
{
301
    m_patternCombo->addItems(RGBAlgorithm::algorithms(m_doc));
×
UNCOV
302
    if (m_matrix->algorithm() != NULL)
×
303
    {
304
        int index = m_patternCombo->findText(m_matrix->algorithm()->name());
×
UNCOV
305
        if (index >= 0)
×
306
            m_patternCombo->setCurrentIndex(index);
×
307
    }
308
}
×
309

UNCOV
310
void RGBMatrixEditor::fillFixtureGroupCombo()
×
311
{
312
    m_fixtureGroupCombo->clear();
×
313
    m_fixtureGroupCombo->addItem(tr("None"));
×
314

315
    QListIterator <FixtureGroup*> it(m_doc->fixtureGroups());
×
316
    while (it.hasNext() == true)
×
317
    {
UNCOV
318
        FixtureGroup* grp(it.next());
×
319
        Q_ASSERT(grp != NULL);
UNCOV
320
        m_fixtureGroupCombo->addItem(grp->name(), grp->id());
×
321
        if (m_matrix->fixtureGroup() == grp->id())
×
322
            m_fixtureGroupCombo->setCurrentIndex(m_fixtureGroupCombo->count() - 1);
×
323
    }
UNCOV
324
}
×
325

UNCOV
326
void RGBMatrixEditor::fillAnimationCombo()
×
327
{
328
    m_animationCombo->addItems(RGBText::animationStyles());
×
329
}
×
330

331
void RGBMatrixEditor::fillImageAnimationCombo()
×
332
{
333
    m_imageAnimationCombo->addItems(RGBImage::animationStyles());
×
334
}
×
335

UNCOV
336
void RGBMatrixEditor::updateExtraOptions()
×
337
{
UNCOV
338
    resetProperties(m_propertiesLayout->layout());
×
339
    m_propertiesGroup->hide();
×
340

341
    if (m_matrix->algorithm() == NULL ||
×
342
        m_matrix->algorithm()->type() == RGBAlgorithm::Script ||
×
343
        m_matrix->algorithm()->type() == RGBAlgorithm::Audio)
×
344
    {
345
        m_textGroup->hide();
×
346
        m_imageGroup->hide();
×
UNCOV
347
        m_offsetGroup->hide();
×
348

349
        if (m_matrix->algorithm() != NULL && m_matrix->algorithm()->type() == RGBAlgorithm::Script)
×
350
        {
351
            RGBScript *script = static_cast<RGBScript*> (m_matrix->algorithm());
×
352
            displayProperties(script);
×
353
        }
354
    }
355
    else if (m_matrix->algorithm()->type() == RGBAlgorithm::Plain)
×
356
    {
357
        m_textGroup->hide();
×
UNCOV
358
        m_imageGroup->hide();
×
359
        m_offsetGroup->hide();
×
360
    }
361
    else if (m_matrix->algorithm()->type() == RGBAlgorithm::Image)
×
362
    {
363
        m_textGroup->hide();
×
364
        m_imageGroup->show();
×
UNCOV
365
        m_offsetGroup->show();
×
366

367
        RGBImage *image = static_cast<RGBImage*> (m_matrix->algorithm());
×
368
        Q_ASSERT(image != NULL);
369
        m_imageEdit->setText(image->filename());
×
370

UNCOV
371
        int index = m_imageAnimationCombo->findText(RGBImage::animationStyleToString(image->animationStyle()));
×
372
        if (index != -1)
×
373
            m_imageAnimationCombo->setCurrentIndex(index);
×
374

375
        m_xOffsetSpin->setValue(image->xOffset());
×
376
        m_yOffsetSpin->setValue(image->yOffset());
×
377

378
    }
UNCOV
379
    else if (m_matrix->algorithm()->type() == RGBAlgorithm::Text)
×
380
    {
UNCOV
381
        m_textGroup->show();
×
382
        m_offsetGroup->show();
×
UNCOV
383
        m_imageGroup->hide();
×
384

385
        RGBText *text = static_cast<RGBText*> (m_matrix->algorithm());
×
386
        Q_ASSERT(text != NULL);
UNCOV
387
        m_textEdit->setText(text->text());
×
388

389
        int index = m_animationCombo->findText(RGBText::animationStyleToString(text->animationStyle()));
×
390
        if (index != -1)
×
UNCOV
391
            m_animationCombo->setCurrentIndex(index);
×
392

393
        m_xOffsetSpin->setValue(text->xOffset());
×
UNCOV
394
        m_yOffsetSpin->setValue(text->yOffset());
×
395
    }
396

UNCOV
397
    updateColorOptions();
×
398
}
×
399

400
void RGBMatrixEditor::updateColorOptions()
×
401
{
402
    if (m_matrix->algorithm() != NULL)
×
403
    {
UNCOV
404
        int accColors = m_matrix->algorithm()->acceptColors();
×
405

UNCOV
406
        m_mtxColor1Button->setVisible(accColors == 0 ? false : true);
×
407
        m_mtxColor2Button->setVisible(accColors > 1 ? true : false);
×
408
        m_resetMtxColor2Button->setVisible(accColors > 1 ? true : false);
×
UNCOV
409
        m_mtxColor3Button->setVisible(accColors > 2 ? true : false);
×
410
        m_resetMtxColor3Button->setVisible(accColors > 2 ? true : false);
×
UNCOV
411
        m_mtxColor4Button->setVisible(accColors > 3 ? true : false);
×
412
        m_resetMtxColor4Button->setVisible(accColors > 3 ? true : false);
×
413
        m_mtxColor5Button->setVisible(accColors > 4 ? true : false);
×
414
        m_resetMtxColor5Button->setVisible(accColors > 4 ? true : false);
×
415

416
        m_blendModeLabel->setVisible(accColors == 0 ? false : true);
×
UNCOV
417
        m_blendModeCombo->setVisible(accColors == 0 ? false : true);
×
418
    }
419
}
×
420

421
void RGBMatrixEditor::updateColors()
×
422
{
423
    if (m_matrix->algorithm() != NULL)
×
424
    {
425
        int accColors = m_matrix->algorithm()->acceptColors();
×
UNCOV
426
        if (accColors > 0)
×
427
        {
428
            if (m_matrix->blendMode() == Universe::MaskBlend)
×
429
            {
UNCOV
430
                m_matrix->setColor(0, Qt::white);
×
431
                // Overwrite more colors only if applied.
432
                if (accColors <= 2)
×
UNCOV
433
                    m_matrix->setColor(1, QColor());
×
434
                if (accColors <= 3)
×
UNCOV
435
                    m_matrix->setColor(2, QColor());
×
436
                if (accColors <= 4)
×
UNCOV
437
                    m_matrix->setColor(3, QColor());
×
438
                if (accColors <= 5)
×
UNCOV
439
                    m_matrix->setColor(4, QColor());
×
440

UNCOV
441
                m_previewHandler->calculateColorDelta(m_matrix->getColor(0), m_matrix->getColor(1),
×
442
                        m_matrix->algorithm());
×
443

444
                QPixmap pm(50, 26);
×
UNCOV
445
                pm.fill(Qt::white);
×
446
                m_mtxColor1Button->setIcon(QIcon(pm));
×
447

448
                pm.fill(Qt::transparent);
×
UNCOV
449
                m_mtxColor2Button->setIcon(QIcon(pm));
×
450
                m_mtxColor3Button->setIcon(QIcon(pm));
×
451
                m_mtxColor4Button->setIcon(QIcon(pm));
×
UNCOV
452
                m_mtxColor5Button->setIcon(QIcon(pm));
×
453
            }
UNCOV
454
            else if (m_controlModeCombo->currentIndex() != RGBMatrix::ControlModeRgb)
×
455
            {
456
                // Convert color 1 to grayscale for single color modes
UNCOV
457
                uchar gray = qGray(m_matrix->getColor(0).rgb());
×
UNCOV
458
                m_matrix->setColor(0, QColor(gray, gray, gray));
×
UNCOV
459
                QPixmap pm(50, 26);
×
460
                pm.fill(QColor(gray, gray, gray));
×
UNCOV
461
                m_mtxColor1Button->setIcon(QIcon(pm));
×
462

463
                // Convert color 2 and following to grayscale for single color modes
UNCOV
464
                if (accColors < 2)
×
465
                    m_matrix->setColor(1, QColor());
×
UNCOV
466
                if (m_matrix->getColor(1) == QColor())
×
467
                {
UNCOV
468
                    pm.fill(Qt::transparent);
×
469
                }
470
                else
471
                {
UNCOV
472
                    gray = qGray(m_matrix->getColor(1).rgb());
×
473
                    m_matrix->setColor(1, QColor(gray, gray, gray));
×
474
                    pm.fill(QColor(gray, gray, gray));
×
475
                }
476
                m_mtxColor2Button->setIcon(QIcon(pm));
×
477

478
                if (accColors < 3)
×
479
                    m_matrix->setColor(2, QColor());
×
UNCOV
480
                if (m_matrix->getColor(2) == QColor())
×
481
                {
UNCOV
482
                    pm.fill(Qt::transparent);
×
483
                }
484
                else
485
                {
UNCOV
486
                    gray = qGray(m_matrix->getColor(2).rgb());
×
487
                    m_matrix->setColor(2, QColor(gray, gray, gray));
×
UNCOV
488
                    pm.fill(QColor(gray, gray, gray));
×
489
                }
UNCOV
490
                m_mtxColor3Button->setIcon(QIcon(pm));
×
491

UNCOV
492
                if (accColors < 4)
×
493
                    m_matrix->setColor(3, QColor());
×
494
                if (m_matrix->getColor(3) == QColor())
×
495
                {
UNCOV
496
                    pm.fill(Qt::transparent);
×
497
                }
498
                else
499
                {
500
                    gray = qGray(m_matrix->getColor(3).rgb());
×
501
                    m_matrix->setColor(3, QColor(gray, gray, gray));
×
UNCOV
502
                    pm.fill(QColor(gray, gray, gray));
×
503
                }
504
                m_mtxColor4Button->setIcon(QIcon(pm));
×
505

506
                if (accColors < 5)
×
UNCOV
507
                    m_matrix->setColor(4, QColor());
×
UNCOV
508
                if (m_matrix->getColor(4) == QColor())
×
509
                {
510
                    pm.fill(Qt::transparent);
×
511
                }
512
                else
513
                {
UNCOV
514
                    gray = qGray(m_matrix->getColor(4).rgb());
×
515
                    m_matrix->setColor(4, QColor(gray, gray, gray));
×
UNCOV
516
                    pm.fill(QColor(gray, gray, gray));
×
517
                }
UNCOV
518
                m_mtxColor5Button->setIcon(QIcon(pm));
×
519

520
                m_previewHandler->calculateColorDelta(m_matrix->getColor(0), m_matrix->getColor(1),
×
521
                        m_matrix->algorithm());
×
522
            }
523
            else 
524
            {
525
                QPixmap pm(50, 26);
×
UNCOV
526
                pm.fill(m_matrix->getColor(0));
×
527
                m_mtxColor1Button->setIcon(QIcon(pm));
×
528

529
                // Preserve the colors (do not set them to QColor().
530
                // RGBMatrixStep::calculateColorDelta will ensure correct color application
531
                if (m_matrix->getColor(1) == QColor())
×
532
                    pm.fill(Qt::transparent);
×
533
                else
UNCOV
534
                    pm.fill(m_matrix->getColor(1));
×
535
                m_mtxColor2Button->setIcon(QIcon(pm));
×
536

537
                if (m_matrix->getColor(2) == QColor())
×
UNCOV
538
                    pm.fill(Qt::transparent);
×
539
                else
540
                    pm.fill(m_matrix->getColor(2));
×
UNCOV
541
                m_mtxColor3Button->setIcon(QIcon(pm));
×
542

UNCOV
543
                if (m_matrix->getColor(3) == QColor())
×
UNCOV
544
                    pm.fill(Qt::transparent);
×
545
                else
546
                    pm.fill(m_matrix->getColor(3));
×
547
                m_mtxColor4Button->setIcon(QIcon(pm));
×
548

549
                if (m_matrix->getColor(4) == QColor())
×
550
                    pm.fill(Qt::transparent);
×
551
                else
UNCOV
552
                    pm.fill(m_matrix->getColor(4));
×
553
                m_mtxColor5Button->setIcon(QIcon(pm));
×
554

UNCOV
555
                m_previewHandler->calculateColorDelta(m_matrix->getColor(0), m_matrix->getColor(1),
×
556
                        m_matrix->algorithm());
×
557
            }
558
        }
559
    }
UNCOV
560
}
×
561

562
/**
563
 * Helper function. Deletes all child widgets of the given layout @a item.
564
 */
UNCOV
565
void RGBMatrixEditor::resetProperties(QLayoutItem *item)
×
566
{
UNCOV
567
    if (item->layout()) 
×
568
    {
569
        // Process all child items recursively.
UNCOV
570
        for (int i = item->layout()->count() - 1; i >= 0; i--)
×
571
            resetProperties(item->layout()->itemAt(i));
×
572
    }
573
    delete item->widget();
×
574
}
×
575

576
void RGBMatrixEditor::displayProperties(RGBScript *script)
×
577
{
578
    if (script == NULL)
×
579
        return;
×
580

581
    int gridRowIdx = 0;
582

583
    QList<RGBScriptProperty> properties = script->properties();
×
UNCOV
584
    if (properties.count() > 0)
×
UNCOV
585
        m_propertiesGroup->show();
×
586

587
    foreach (RGBScriptProperty prop, properties)
×
588
    {
UNCOV
589
        switch(prop.m_type)
×
590
        {
591
            case RGBScriptProperty::List:
592
            {
593
                QLabel *propLabel = new QLabel(prop.m_displayName);
×
UNCOV
594
                m_propertiesLayout->addWidget(propLabel, gridRowIdx, 0);
×
595
                QComboBox *propCombo = new QComboBox(this);
×
596
                propCombo->addItems(prop.m_listValues);
UNCOV
597
                propCombo->setProperty("pName", prop.m_name);
×
UNCOV
598
                connect(propCombo, SIGNAL(currentIndexChanged(int)),
×
599
                        this, SLOT(slotPropertyComboChanged(int)));
UNCOV
600
                m_propertiesLayout->addWidget(propCombo, gridRowIdx, 1);
×
601
                if (m_matrix != NULL)
×
602
                {
603
                    QString pValue = m_matrix->property(prop.m_name);
×
604
                    if (!pValue.isEmpty())
×
605
                    {
606
                        propCombo->setCurrentText(pValue);
×
607
                    }
608
                    else
609
                    {
610
                        pValue = script->property(prop.m_name);
×
611
                        if (!pValue.isEmpty())
×
612
                            propCombo->setCurrentText(pValue);
×
613
                    }
614
                }
615
                gridRowIdx++;
×
616
            }
UNCOV
617
            break;
×
618
            case RGBScriptProperty::Range:
619
            {
620
                QLabel *propLabel = new QLabel(prop.m_displayName);
×
UNCOV
621
                m_propertiesLayout->addWidget(propLabel, gridRowIdx, 0);
×
UNCOV
622
                QSpinBox *propSpin = new QSpinBox(this);
×
623
                propSpin->setRange(prop.m_rangeMinValue, prop.m_rangeMaxValue);
×
UNCOV
624
                propSpin->setProperty("pName", prop.m_name);
×
625
                connect(propSpin, SIGNAL(valueChanged(int)),
×
626
                        this, SLOT(slotPropertySpinChanged(int)));
627
                m_propertiesLayout->addWidget(propSpin, gridRowIdx, 1);
×
UNCOV
628
                if (m_matrix != NULL)
×
629
                {
UNCOV
630
                    QString pValue = m_matrix->property(prop.m_name);
×
UNCOV
631
                    if (!pValue.isEmpty())
×
632
                        propSpin->setValue(pValue.toInt());
×
633
                    else
634
                    {
635
                        pValue = script->property(prop.m_name);
×
636
                        if (!pValue.isEmpty())
×
637
                            propSpin->setValue(pValue.toInt());
×
638
                    }
639
                }
640
                gridRowIdx++;
×
641
            }
UNCOV
642
            break;
×
643
            case RGBScriptProperty::Float:
644
            {
645
                QLabel *propLabel = new QLabel(prop.m_displayName);
×
646
                m_propertiesLayout->addWidget(propLabel, gridRowIdx, 0);
×
647
                QDoubleSpinBox *propSpin = new QDoubleSpinBox(this);
×
UNCOV
648
                propSpin->setDecimals(3);
×
UNCOV
649
                propSpin->setRange(-1000000, 1000000);
×
650
                propSpin->setProperty("pName", prop.m_name);
×
UNCOV
651
                connect(propSpin, SIGNAL(valueChanged(double)),
×
652
                        this, SLOT(slotPropertyDoubleSpinChanged(double)));
653
                m_propertiesLayout->addWidget(propSpin, gridRowIdx, 1);
×
654
                if (m_matrix != NULL)
×
655
                {
656
                    QString pValue = m_matrix->property(prop.m_name);
×
UNCOV
657
                    if (!pValue.isEmpty())
×
UNCOV
658
                        propSpin->setValue(pValue.toDouble());
×
659
                    else
660
                    {
UNCOV
661
                        pValue = script->property(prop.m_name);
×
UNCOV
662
                        if (!pValue.isEmpty())
×
663
                            propSpin->setValue(pValue.toDouble());
×
664
                    }
665
                }
UNCOV
666
                gridRowIdx++;
×
667
            }
668
            break;
×
669
            case RGBScriptProperty::String:
670
            {
UNCOV
671
                QLabel *propLabel = new QLabel(prop.m_displayName);
×
672
                m_propertiesLayout->addWidget(propLabel, gridRowIdx, 0);
×
673
                QLineEdit *propEdit = new QLineEdit(this);
×
UNCOV
674
                propEdit->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Preferred);
×
675
                propEdit->setProperty("pName", prop.m_name);
×
UNCOV
676
                connect(propEdit, SIGNAL(textEdited(QString)),
×
677
                        this, SLOT(slotPropertyEditChanged(QString)));
678
                m_propertiesLayout->addWidget(propEdit, gridRowIdx, 1);
×
UNCOV
679
                if (m_matrix != NULL)
×
680
                {
UNCOV
681
                    QString pValue = m_matrix->property(prop.m_name);
×
682
                    if (!pValue.isEmpty())
×
UNCOV
683
                        propEdit->setText(pValue);
×
684
                    else
685
                    {
UNCOV
686
                        pValue = script->property(prop.m_name);
×
687
                        if (!pValue.isEmpty())
×
688
                            propEdit->setText(pValue);
×
689
                    }
690
                }
691
                gridRowIdx++;
×
692
            }
UNCOV
693
            break;
×
694
            default:
UNCOV
695
                qWarning() << "Type" << prop.m_type << "not handled yet";
×
UNCOV
696
            break;
×
697
        }
698
    }
699
}
700

UNCOV
701
bool RGBMatrixEditor::createPreviewItems()
×
702
{
703
    m_previewHash.clear();
×
704
    m_scene->clear();
×
705

UNCOV
706
    FixtureGroup* grp = m_doc->fixtureGroup(m_matrix->fixtureGroup());
×
707
    if (grp == NULL)
×
708
    {
709
        QGraphicsTextItem* text = new QGraphicsTextItem(tr("No fixture group to control"));
×
710
        text->setDefaultTextColor(Qt::white);
×
UNCOV
711
        m_scene->addItem(text);
×
UNCOV
712
        return false;
×
713
    }
714

715
    m_previewHandler->initializeDirection(m_matrix->direction(), m_matrix->getColor(0),
×
UNCOV
716
                                      m_matrix->getColor(1), m_matrix->stepsCount(),
×
717
                                      m_matrix->algorithm());
×
718

719
    m_matrix->previewMap(m_previewHandler->currentStepIndex(), m_previewHandler);
×
720

721
    if (m_previewHandler->m_map.isEmpty())
×
722
        return false;
723

724
    for (int x = 0; x < grp->size().width(); x++)
×
725
    {
726
        for (int y = 0; y < grp->size().height(); y++)
×
727
        {
728
            QLCPoint pt(x, y);
×
729

730
            if (grp->headsMap().contains(pt) == true)
×
731
            {
732
                RGBItem *item;
UNCOV
733
                if (m_shapeButton->isChecked() == false)
×
734
                {
735
                    QGraphicsEllipseItem* circleItem = new QGraphicsEllipseItem();
×
UNCOV
736
                    circleItem->setRect(
×
737
                            x * RECT_SIZE + RECT_PADDING + ITEM_PADDING,
×
UNCOV
738
                            y * RECT_SIZE + RECT_PADDING + ITEM_PADDING,
×
739
                            ITEM_SIZE - (2 * ITEM_PADDING),
740
                            ITEM_SIZE - (2 * ITEM_PADDING));
UNCOV
741
                    item = new RGBItem(circleItem);
×
742
                }
743
                else
744
                {
UNCOV
745
                    QGraphicsRectItem *rectItem = new QGraphicsRectItem();
×
UNCOV
746
                    rectItem->setRect(
×
747
                            x * RECT_SIZE + RECT_PADDING + ITEM_PADDING,
×
748
                            y * RECT_SIZE + RECT_PADDING + ITEM_PADDING,
×
749
                            ITEM_SIZE - (2 * ITEM_PADDING),
750
                            ITEM_SIZE - (2 * ITEM_PADDING));
751
                    item = new RGBItem(rectItem);
×
752
                }
753

UNCOV
754
                item->setColor(m_previewHandler->m_map[y][x]);
×
755
                item->draw(0, 0);
×
UNCOV
756
                m_scene->addItem(item->graphicsItem());
×
757
                m_previewHash[pt] = item;
×
758
            }
759
        }
760
    }
761
    return true;
762
}
763

UNCOV
764
void RGBMatrixEditor::slotPreviewTimeout()
×
765
{
766
    if (m_matrix->duration() <= 0)
×
767
        return;
768

UNCOV
769
    m_previewIterator += MasterTimer::tick();
×
770
    uint elapsed = 0;
UNCOV
771
    while (m_previewIterator >= MAX(m_matrix->duration(), MasterTimer::tick()))
×
772
    {
773
        m_previewHandler->checkNextStep(m_matrix->runOrder(), m_matrix->getColor(0),
×
774
                                        m_matrix->getColor(1), m_matrix->stepsCount());
×
775

776
        m_matrix->previewMap(m_previewHandler->currentStepIndex(), m_previewHandler);
×
777

778
        m_previewIterator -= MAX(m_matrix->duration(), MasterTimer::tick());
×
UNCOV
779
        elapsed += MAX(m_matrix->duration(), MasterTimer::tick());
×
780
    }
781
    for (int y = 0; y < m_previewHandler->m_map.size(); y++)
×
782
    {
783
        for (int x = 0; x < m_previewHandler->m_map[y].size(); x++)
×
784
        {
785
            QLCPoint pt(x, y);
×
UNCOV
786
            if (m_previewHash.contains(pt) == true)
×
787
            {
UNCOV
788
                RGBItem* shape = m_previewHash[pt];
×
789
                if (shape->color() != QColor(m_previewHandler->m_map[y][x]).rgb())
×
UNCOV
790
                    shape->setColor(m_previewHandler->m_map[y][x]);
×
791

792
                if (shape->color() == QColor(Qt::black).rgb())
×
UNCOV
793
                    shape->draw(elapsed, m_matrix->fadeOutSpeed());
×
794
                else
795
                    shape->draw(elapsed, m_matrix->fadeInSpeed());
×
796
            }
797
        }
798
    }
799
}
800

UNCOV
801
void RGBMatrixEditor::slotNameEdited(const QString& text)
×
802
{
803
    m_matrix->setName(text);
×
804
    if (m_speedDials != NULL)
×
805
        m_speedDials->setWindowTitle(text);
×
806
}
×
807

808
void RGBMatrixEditor::slotSpeedDialToggle(bool state)
×
809
{
810
    if (state == true)
×
UNCOV
811
        updateSpeedDials();
×
812
    else
813
    {
UNCOV
814
        if (m_speedDials != NULL)
×
815
            m_speedDials->deleteLater();
×
816
        m_speedDials = NULL;
×
817
    }
818
}
×
819

820
void RGBMatrixEditor::slotDialDestroyed(QObject *)
×
821
{
822
    m_speedDialButton->setChecked(false);
×
UNCOV
823
}
×
824

UNCOV
825
void RGBMatrixEditor::slotPatternActivated(int patternIndex)
×
826
{
UNCOV
827
    QString algoName = m_patternCombo->itemText(patternIndex);
×
UNCOV
828
    RGBAlgorithm *algo = RGBAlgorithm::algorithm(m_doc, algoName);
×
829
    m_matrix->setAlgorithm(algo);
×
830
    if (algo != NULL) {
×
831
        updateColors();
×
832
#if (5 != RGBAlgorithmColorDisplayCount)
833
#error "Further colors need to be displayed."
834
#endif
835
        QVector<QColor> colors = {
UNCOV
836
                m_matrix->getColor(0),
×
837
                m_matrix->getColor(1),
×
UNCOV
838
                m_matrix->getColor(2),
×
UNCOV
839
                m_matrix->getColor(3),
×
840
                m_matrix->getColor(4)
×
UNCOV
841
        };
×
842
        algo->setColors(colors);
×
UNCOV
843
        m_previewHandler->calculateColorDelta(m_matrix->getColor(0), m_matrix->getColor(1),
×
844
                m_matrix->algorithm());
×
845
    }
846
    updateExtraOptions();
×
847

UNCOV
848
    slotRestartTest();
×
849
}
×
850

851
void RGBMatrixEditor::slotFixtureGroupActivated(int index)
×
852
{
853
    QVariant var = m_fixtureGroupCombo->itemData(index);
×
UNCOV
854
    if (var.isValid() == true)
×
855
    {
UNCOV
856
        m_matrix->setFixtureGroup(var.toUInt());
×
857
        slotRestartTest();
×
858
    }
859
    else
860
    {
861
        m_matrix->setFixtureGroup(FixtureGroup::invalidId());
×
UNCOV
862
        m_previewTimer->stop();
×
UNCOV
863
        m_scene->clear();
×
864
    }
865
}
×
866

867
void RGBMatrixEditor::slotBlendModeChanged(int index)
×
868
{
869
    m_matrix->setBlendMode(Universe::BlendMode(index));
×
870

871
    if (index == Universe::MaskBlend)
×
872
    {
873
        m_mtxColor1Button->setEnabled(false);
×
874
    }
875
    else
876
    {
UNCOV
877
        m_mtxColor1Button->setEnabled(true);
×
878
    }
879
    updateExtraOptions();
×
880
    updateColors();
×
UNCOV
881
    slotRestartTest();
×
882
}
×
883

UNCOV
884
void RGBMatrixEditor::slotControlModeChanged(int index)
×
885
{
886
    RGBMatrix::ControlMode mode = RGBMatrix::ControlMode(index);
×
887
    m_matrix->setControlMode(mode);
×
UNCOV
888
    updateColors();
×
889
    slotRestartTest();
×
890
}
×
891

UNCOV
892
void RGBMatrixEditor::slotMtxColor1ButtonClicked()
×
893
{
UNCOV
894
    QColor col = QColorDialog::getColor(m_matrix->getColor(0));
×
895
    if (col.isValid() == true)
×
896
    {
897
        m_matrix->setColor(0, col);
×
UNCOV
898
        updateColors();
×
899
        slotRestartTest();
×
900
    }
UNCOV
901
}
×
902

903
void RGBMatrixEditor::slotMtxColor2ButtonClicked()
×
904
{
UNCOV
905
    QColor col = QColorDialog::getColor(m_matrix->getColor(1));
×
906
    if (col.isValid() == true)
×
907
    {
908
        m_matrix->setColor(1, col);
×
UNCOV
909
        updateColors();
×
910
        slotRestartTest();
×
911
    }
912
}
×
913

914
void RGBMatrixEditor::slotResetMtxColor2ButtonClicked()
×
915
{
UNCOV
916
    m_matrix->setColor(1, QColor());
×
917
    updateColors();
×
918
    slotRestartTest();
×
919
}
×
920

921
void RGBMatrixEditor::slotMtxColor3ButtonClicked()
×
922
{
UNCOV
923
    QColor col = QColorDialog::getColor(m_matrix->getColor(2));
×
924
    if (col.isValid() == true)
×
925
    {
926
        m_matrix->setColor(2, col);
×
UNCOV
927
        updateColors();
×
UNCOV
928
        slotRestartTest();
×
929
    }
930
}
×
931

UNCOV
932
void RGBMatrixEditor::slotResetMtxColor3ButtonClicked()
×
933
{
UNCOV
934
    m_matrix->setColor(2, QColor());
×
935
    updateColors();
×
UNCOV
936
    slotRestartTest();
×
937
}
×
938

939
void RGBMatrixEditor::slotMtxColor4ButtonClicked()
×
940
{
941
    QColor col = QColorDialog::getColor(m_matrix->getColor(3));
×
942
    if (col.isValid() == true)
×
943
    {
944
        m_matrix->setColor(3, col);
×
UNCOV
945
        updateColors();
×
946
        slotRestartTest();
×
947
    }
948
}
×
949

UNCOV
950
void RGBMatrixEditor::slotResetMtxColor4ButtonClicked()
×
951
{
UNCOV
952
    m_matrix->setColor(3, QColor());
×
953
    updateColors();
×
954
    slotRestartTest();
×
955
}
×
956

UNCOV
957
void RGBMatrixEditor::slotMtxColor5ButtonClicked()
×
958
{
UNCOV
959
    QColor col = QColorDialog::getColor(m_matrix->getColor(4));
×
960
    if (col.isValid() == true)
×
961
    {
962
        m_matrix->setColor(4, col);
×
963
        updateColors();
×
UNCOV
964
        slotRestartTest();
×
965
    }
UNCOV
966
}
×
967

968
void RGBMatrixEditor::slotResetMtxColor5ButtonClicked()
×
969
{
970
    m_matrix->setColor(4, QColor());
×
UNCOV
971
    updateColors();
×
972
    slotRestartTest();
×
UNCOV
973
}
×
974

975
void RGBMatrixEditor::slotTextEdited(const QString& text)
×
976
{
977
    if (m_matrix->algorithm() != NULL && m_matrix->algorithm()->type() == RGBAlgorithm::Text)
×
978
    {
979
        RGBText *algo = static_cast<RGBText*> (m_matrix->algorithm());
×
980
        Q_ASSERT(algo != NULL);
981
        {
982
            QMutexLocker algorithmLocker(&m_matrix->algorithmMutex());
×
983
            algo->setText(text);
×
984
        }
UNCOV
985
        slotRestartTest();
×
986
    }
UNCOV
987
}
×
988

989
void RGBMatrixEditor::slotFontButtonClicked()
×
990
{
991
    if (m_matrix->algorithm() != NULL && m_matrix->algorithm()->type() == RGBAlgorithm::Text)
×
992
    {
993
        RGBText *algo = static_cast<RGBText*> (m_matrix->algorithm());
×
994
        Q_ASSERT(algo != NULL);
995

UNCOV
996
        bool ok = false;
×
997
        QFont font = QFontDialog::getFont(&ok, algo->font(), this);
×
UNCOV
998
        if (ok == true)
×
999
        {
1000
            {
UNCOV
1001
                QMutexLocker algorithmLocker(&m_matrix->algorithmMutex());
×
1002
                algo->setFont(font);
×
1003
            }
1004
            slotRestartTest();
×
1005
        }
1006
    }
1007
}
×
1008

UNCOV
1009
void RGBMatrixEditor::slotAnimationActivated(int index)
×
1010
{
UNCOV
1011
    if (m_matrix->algorithm() != NULL && m_matrix->algorithm()->type() == RGBAlgorithm::Text)
×
1012
    {
UNCOV
1013
        RGBText *algo = static_cast<RGBText*> (m_matrix->algorithm());
×
1014
        Q_ASSERT(algo != NULL);
1015
        {
UNCOV
1016
            QMutexLocker algorithmLocker(&m_matrix->algorithmMutex());
×
1017
            QString text = m_animationCombo->itemText(index);
×
1018
            algo->setAnimationStyle(RGBText::stringToAnimationStyle(text));
×
1019
        }
UNCOV
1020
        slotRestartTest();
×
1021
    }
1022
}
×
1023

1024
void RGBMatrixEditor::slotImageEdited()
×
1025
{
1026
    if (m_matrix->algorithm() != NULL && m_matrix->algorithm()->type() == RGBAlgorithm::Image)
×
1027
    {
1028
        RGBImage *algo = static_cast<RGBImage*> (m_matrix->algorithm());
×
1029
        Q_ASSERT(algo != NULL);
1030
        {
1031
            QMutexLocker algorithmLocker(&m_matrix->algorithmMutex());
×
1032
            algo->setFilename(m_imageEdit->text());
×
1033
        }
UNCOV
1034
        slotRestartTest();
×
1035
    }
UNCOV
1036
}
×
1037

UNCOV
1038
void RGBMatrixEditor::slotImageButtonClicked()
×
1039
{
UNCOV
1040
    if (m_matrix->algorithm() != NULL && m_matrix->algorithm()->type() == RGBAlgorithm::Image)
×
1041
    {
UNCOV
1042
        RGBImage *algo = static_cast<RGBImage*> (m_matrix->algorithm());
×
1043
        Q_ASSERT(algo != NULL);
1044

UNCOV
1045
        QString path = algo->filename();
×
1046
        path = QFileDialog::getOpenFileName(this,
×
UNCOV
1047
                                            tr("Select image"),
×
1048
                                            path,
1049
                                            QString("%1 (*.png *.bmp *.jpg *.jpeg *.gif)").arg(tr("Images")));
×
1050
        if (path.isEmpty() == false)
×
1051
        {
1052
            {
UNCOV
1053
                QMutexLocker algorithmLocker(&m_matrix->algorithmMutex());
×
1054
                algo->setFilename(path);
×
1055
            }
UNCOV
1056
            m_imageEdit->setText(path);
×
1057
            slotRestartTest();
×
1058
        }
1059
    }
UNCOV
1060
}
×
1061

UNCOV
1062
void RGBMatrixEditor::slotImageAnimationActivated(int index)
×
1063
{
1064
    if (m_matrix->algorithm() != NULL && m_matrix->algorithm()->type() == RGBAlgorithm::Image)
×
1065
    {
1066
        RGBImage *algo = static_cast<RGBImage*> (m_matrix->algorithm());
×
1067
        Q_ASSERT(algo != NULL);
1068
        {
UNCOV
1069
            QMutexLocker algorithmLocker(&m_matrix->algorithmMutex());
×
1070
            QString text = m_imageAnimationCombo->itemText(index);
×
UNCOV
1071
            algo->setAnimationStyle(RGBImage::stringToAnimationStyle(text));
×
1072
        }
UNCOV
1073
        slotRestartTest();
×
1074
    }
1075
}
×
1076

1077
void RGBMatrixEditor::slotOffsetSpinChanged()
×
1078
{
UNCOV
1079
    if (m_matrix->algorithm() != NULL && m_matrix->algorithm()->type() == RGBAlgorithm::Text)
×
1080
    {
UNCOV
1081
        RGBText *algo = static_cast<RGBText*> (m_matrix->algorithm());
×
1082
        Q_ASSERT(algo != NULL);
1083
        {
1084
            QMutexLocker algorithmLocker(&m_matrix->algorithmMutex());
×
UNCOV
1085
            algo->setXOffset(m_xOffsetSpin->value());
×
UNCOV
1086
            algo->setYOffset(m_yOffsetSpin->value());
×
1087
        }
1088
        slotRestartTest();
×
1089
    }
1090

1091
    if (m_matrix->algorithm() != NULL && m_matrix->algorithm()->type() == RGBAlgorithm::Image)
×
1092
    {
UNCOV
1093
        RGBImage *algo = static_cast<RGBImage*> (m_matrix->algorithm());
×
1094
        Q_ASSERT(algo != NULL);
1095
        {
UNCOV
1096
            QMutexLocker algorithmLocker(&m_matrix->algorithmMutex());
×
1097
            algo->setXOffset(m_xOffsetSpin->value());
×
1098
            algo->setYOffset(m_yOffsetSpin->value());
×
1099
        }
UNCOV
1100
        slotRestartTest();
×
1101
    }
UNCOV
1102
}
×
1103

1104
void RGBMatrixEditor::slotLoopClicked()
×
1105
{
UNCOV
1106
    m_matrix->setRunOrder(Function::Loop);
×
1107
    m_previewHandler->calculateColorDelta(m_matrix->getColor(0), m_matrix->getColor(1),
×
1108
            m_matrix->algorithm());
×
UNCOV
1109
    slotRestartTest();
×
1110
}
×
1111

1112
void RGBMatrixEditor::slotPingPongClicked()
×
1113
{
1114
    m_matrix->setRunOrder(Function::PingPong);
×
UNCOV
1115
    m_previewHandler->calculateColorDelta(m_matrix->getColor(0), m_matrix->getColor(1),
×
UNCOV
1116
            m_matrix->algorithm());
×
1117
    slotRestartTest();
×
UNCOV
1118
}
×
1119

UNCOV
1120
void RGBMatrixEditor::slotSingleShotClicked()
×
1121
{
1122
    m_matrix->setRunOrder(Function::SingleShot);
×
UNCOV
1123
    m_previewHandler->calculateColorDelta(m_matrix->getColor(0), m_matrix->getColor(1),
×
1124
            m_matrix->algorithm());
×
1125
    slotRestartTest();
×
UNCOV
1126
}
×
1127

UNCOV
1128
void RGBMatrixEditor::slotForwardClicked()
×
1129
{
1130
    m_matrix->setDirection(Function::Forward);
×
1131
    m_previewHandler->calculateColorDelta(m_matrix->getColor(0), m_matrix->getColor(1),
×
1132
            m_matrix->algorithm());
×
1133
    slotRestartTest();
×
1134
}
×
1135

1136
void RGBMatrixEditor::slotBackwardClicked()
×
1137
{
1138
    m_matrix->setDirection(Function::Backward);
×
1139
    m_previewHandler->calculateColorDelta(m_matrix->getColor(0), m_matrix->getColor(1),
×
1140
            m_matrix->algorithm());
×
1141
    slotRestartTest();
×
UNCOV
1142
}
×
1143

1144
void RGBMatrixEditor::slotDimmerControlClicked()
×
1145
{
UNCOV
1146
    m_matrix->setDimmerControl(m_dimmerControlCb->isChecked());
×
UNCOV
1147
    if (m_dimmerControlCb->isChecked() == false)
×
1148
        m_dimmerControlCb->setEnabled(false);
×
UNCOV
1149
}
×
1150

UNCOV
1151
void RGBMatrixEditor::slotFadeInChanged(int ms)
×
1152
{
1153
    m_matrix->setFadeInSpeed(ms);
×
UNCOV
1154
    uint duration = Function::speedAdd(ms, m_speedDials->duration());
×
1155
    m_matrix->setDuration(duration);
×
UNCOV
1156
}
×
1157

UNCOV
1158
void RGBMatrixEditor::slotFadeOutChanged(int ms)
×
1159
{
1160
    m_matrix->setFadeOutSpeed(ms);
×
UNCOV
1161
}
×
1162

UNCOV
1163
void RGBMatrixEditor::slotHoldChanged(int ms)
×
1164
{
1165
    uint duration = Function::speedAdd(m_matrix->fadeInSpeed(), ms);
×
UNCOV
1166
    m_matrix->setDuration(duration);
×
1167
}
×
1168

1169
void RGBMatrixEditor::slotDurationTapped()
×
1170
{
1171
    m_matrix->tap();
×
UNCOV
1172
}
×
1173

UNCOV
1174
void RGBMatrixEditor::slotTestClicked()
×
1175
{
1176
    if (m_testButton->isChecked() == true)
×
UNCOV
1177
        m_matrix->start(m_doc->masterTimer(), functionParent());
×
1178
    else
UNCOV
1179
        m_matrix->stopAndWait();
×
1180
}
×
1181

UNCOV
1182
void RGBMatrixEditor::slotRestartTest()
×
1183
{
1184
    m_previewTimer->stop();
×
1185

1186
    if (m_testButton->isChecked() == true)
×
1187
    {
1188
        // Toggle off, toggle on. Duh.
1189
        m_testButton->click();
×
1190
        m_testButton->click();
×
1191
    }
1192

UNCOV
1193
    if (createPreviewItems() == true)
×
1194
        m_previewTimer->start(MasterTimer::tick());
×
1195

1196
}
×
1197

1198
void RGBMatrixEditor::slotModeChanged(Doc::Mode mode)
×
1199
{
UNCOV
1200
    if (mode == Doc::Operate)
×
1201
    {
1202
        if (m_testButton->isChecked() == true)
×
1203
            m_matrix->stopAndWait();
×
UNCOV
1204
        m_testButton->setChecked(false);
×
1205
        m_testButton->setEnabled(false);
×
1206
    }
1207
    else
1208
    {
UNCOV
1209
        m_testButton->setEnabled(true);
×
1210
    }
UNCOV
1211
}
×
1212

1213
void RGBMatrixEditor::slotFixtureGroupAdded()
×
1214
{
UNCOV
1215
    fillFixtureGroupCombo();
×
UNCOV
1216
}
×
1217

UNCOV
1218
void RGBMatrixEditor::slotFixtureGroupRemoved()
×
1219
{
UNCOV
1220
    fillFixtureGroupCombo();
×
1221
    slotFixtureGroupActivated(m_fixtureGroupCombo->currentIndex());
×
1222
}
×
1223

UNCOV
1224
void RGBMatrixEditor::slotFixtureGroupChanged(quint32 id)
×
1225
{
1226
    if (id == m_matrix->fixtureGroup())
×
1227
    {
1228
        // Update the whole chain -> maybe the fixture layout has changed
UNCOV
1229
        fillFixtureGroupCombo();
×
1230
        slotFixtureGroupActivated(m_fixtureGroupCombo->currentIndex());
×
1231
    }
1232
    else
1233
    {
1234
        // Just change the name of the group, nothing else is interesting at this point
UNCOV
1235
        int index = m_fixtureGroupCombo->findData(id);
×
UNCOV
1236
        if (index != -1)
×
1237
        {
1238
            FixtureGroup* grp = m_doc->fixtureGroup(id);
×
1239
            m_fixtureGroupCombo->setItemText(index, grp->name());
×
1240
        }
1241
    }
1242
}
×
1243

1244
void RGBMatrixEditor::slotSaveToSequenceClicked()
×
1245
{
UNCOV
1246
    if (m_matrix == NULL || m_matrix->fixtureGroup() == FixtureGroup::invalidId())
×
1247
        return;
×
1248

1249
    FixtureGroup* grp = m_doc->fixtureGroup(m_matrix->fixtureGroup());
×
1250
    if (grp != NULL && m_matrix->algorithm() != NULL)
×
1251
    {
1252
        bool testRunning = false;
1253

1254
        if (m_testButton->isChecked() == true)
×
1255
        {
UNCOV
1256
            m_testButton->click();
×
1257
            testRunning = true;
1258
        }
1259
        else
UNCOV
1260
            m_previewTimer->stop();
×
1261

1262
        Scene *grpScene = new Scene(m_doc);
×
1263
        grpScene->setName(grp->name());
×
1264
        grpScene->setVisible(false);
×
1265

1266
        QList<GroupHead> headList = grp->headList();
×
UNCOV
1267
        foreach (GroupHead head, headList)
×
1268
        {
1269
            Fixture *fxi = m_doc->fixture(head.fxi);
×
UNCOV
1270
            if (fxi == NULL)
×
UNCOV
1271
                continue;
×
1272

UNCOV
1273
            if (m_controlModeCombo->currentIndex() == RGBMatrix::ControlModeRgb)
×
1274
            {
1275

1276
                    QVector <quint32> rgb = fxi->rgbChannels(head.head);
×
1277

1278
                    // in case of CMY, dump those channels
UNCOV
1279
                    if (rgb.count() == 0)
×
UNCOV
1280
                        rgb = fxi->cmyChannels(head.head);
×
1281

UNCOV
1282
                    if (rgb.count() == 3)
×
1283
                    {
1284
                        grpScene->setValue(head.fxi, rgb.at(0), 0);
×
UNCOV
1285
                        grpScene->setValue(head.fxi, rgb.at(1), 0);
×
1286
                        grpScene->setValue(head.fxi, rgb.at(2), 0);
×
1287
                    }
1288
            }
1289
            else if (m_controlModeCombo->currentIndex() == RGBMatrix::ControlModeDimmer)
×
1290
            {
1291
                quint32 channel = fxi->masterIntensityChannel();
×
1292

1293
                if (channel == QLCChannel::invalid())
×
UNCOV
1294
                    channel = fxi->channelNumber(QLCChannel::Intensity, QLCChannel::MSB, head.head);
×
1295

UNCOV
1296
                if (channel != QLCChannel::invalid())
×
1297
                    grpScene->setValue(head.fxi, channel, 0);
×
1298
            }
1299
            else
1300
            {
UNCOV
1301
                quint32 channel = QLCChannel::invalid();
×
1302
                if (m_controlModeCombo->currentIndex() == RGBMatrix::ControlModeWhite)
×
1303
                    channel = fxi->channelNumber(QLCChannel::White, QLCChannel::MSB, head.head);
×
UNCOV
1304
                else if (m_controlModeCombo->currentIndex() == RGBMatrix::ControlModeAmber)
×
1305
                    channel = fxi->channelNumber(QLCChannel::Amber, QLCChannel::MSB, head.head);
×
1306
                else if (m_controlModeCombo->currentIndex() == RGBMatrix::ControlModeUV)
×
1307
                    channel = fxi->channelNumber(QLCChannel::UV, QLCChannel::MSB, head.head);
×
UNCOV
1308
                else if (m_controlModeCombo->currentIndex() == RGBMatrix::ControlModeShutter)
×
1309
                {
UNCOV
1310
                    QLCFixtureHead fHead = fxi->head(head.head);
×
1311
                    QVector <quint32> shutters = fHead.shutterChannels();
×
UNCOV
1312
                    if (shutters.count())
×
UNCOV
1313
                        channel = shutters.first();
×
1314
                }
1315

UNCOV
1316
                if (channel != QLCChannel::invalid())
×
1317
                    grpScene->setValue(head.fxi, channel, 0);
×
1318
            }
1319
        }
UNCOV
1320
        m_doc->addFunction(grpScene);
×
1321

UNCOV
1322
        int totalSteps = m_matrix->stepsCount();
×
1323
        int increment = 1;
1324
        int currentStep = 0;
UNCOV
1325
        m_previewHandler->setStepColor(m_matrix->getColor(0));
×
1326

1327
        if (m_matrix->direction() == Function::Backward)
×
1328
        {
1329
            currentStep = totalSteps - 1;
×
1330
            increment = -1;
1331
            if (m_matrix->getColor(1).isValid())
×
UNCOV
1332
                m_previewHandler->setStepColor(m_matrix->getColor(1));
×
1333
        }
UNCOV
1334
        m_previewHandler->calculateColorDelta(m_matrix->getColor(0), m_matrix->getColor(1),
×
1335
                m_matrix->algorithm());
×
1336

1337
        if (m_matrix->runOrder() == RGBMatrix::PingPong)
×
UNCOV
1338
            totalSteps = (totalSteps * 2) - 1;
×
1339

UNCOV
1340
        Sequence *sequence = new Sequence(m_doc);
×
UNCOV
1341
        sequence->setName(QString("%1 %2").arg(m_matrix->name()).arg(tr("Sequence")));
×
UNCOV
1342
        sequence->setBoundSceneID(grpScene->id());
×
UNCOV
1343
        sequence->setDurationMode(Chaser::PerStep);
×
UNCOV
1344
        sequence->setDuration(m_matrix->duration());
×
1345

UNCOV
1346
        if (m_matrix->fadeInSpeed() != 0)
×
1347
        {
UNCOV
1348
            sequence->setFadeInMode(Chaser::PerStep);
×
UNCOV
1349
            sequence->setFadeInSpeed(m_matrix->fadeInSpeed());
×
1350
        }
UNCOV
1351
        if (m_matrix->fadeOutSpeed() != 0)
×
1352
        {
UNCOV
1353
            sequence->setFadeOutMode(Chaser::PerStep);
×
UNCOV
1354
            sequence->setFadeOutSpeed(m_matrix->fadeOutSpeed());
×
1355
        }
1356

UNCOV
1357
        for (int i = 0; i < totalSteps; i++)
×
1358
        {
UNCOV
1359
            m_matrix->previewMap(currentStep, m_previewHandler);
×
UNCOV
1360
            ChaserStep step;
×
UNCOV
1361
            step.fid = grpScene->id();
×
UNCOV
1362
            step.hold = m_matrix->duration() - m_matrix->fadeInSpeed();
×
UNCOV
1363
            step.duration = m_matrix->duration();
×
UNCOV
1364
            step.fadeIn = m_matrix->fadeInSpeed();
×
UNCOV
1365
            step.fadeOut = m_matrix->fadeOutSpeed();
×
1366

UNCOV
1367
            for (int y = 0; y < m_previewHandler->m_map.size(); y++)
×
1368
            {
UNCOV
1369
                for (int x = 0; x < m_previewHandler->m_map[y].size(); x++)
×
1370
                {
UNCOV
1371
                    uint col = m_previewHandler->m_map[y][x];
×
UNCOV
1372
                    GroupHead head = grp->head(QLCPoint(x, y));
×
1373

UNCOV
1374
                    Fixture *fxi = m_doc->fixture(head.fxi);
×
UNCOV
1375
                    if (fxi == NULL)
×
UNCOV
1376
                        continue;
×
1377

UNCOV
1378
                    if (m_controlModeCombo->currentIndex() == RGBMatrix::ControlModeRgb)
×
1379
                    {
UNCOV
1380
                        QVector <quint32> rgb = fxi->rgbChannels(head.head);
×
UNCOV
1381
                        QVector <quint32> cmy = fxi->cmyChannels(head.head);
×
1382

UNCOV
1383
                        if (rgb.count() == 3)
×
1384
                        {
UNCOV
1385
                            step.values.append(SceneValue(head.fxi, rgb.at(0), qRed(col)));
×
UNCOV
1386
                            step.values.append(SceneValue(head.fxi, rgb.at(1), qGreen(col)));
×
UNCOV
1387
                            step.values.append(SceneValue(head.fxi, rgb.at(2), qBlue(col)));
×
1388
                        }
1389

UNCOV
1390
                        if (cmy.count() == 3)
×
1391
                        {
UNCOV
1392
                            QColor cmyCol(col);
×
1393

UNCOV
1394
                            step.values.append(SceneValue(head.fxi, cmy.at(0), cmyCol.cyan()));
×
UNCOV
1395
                            step.values.append(SceneValue(head.fxi, cmy.at(1), cmyCol.magenta()));
×
UNCOV
1396
                            step.values.append(SceneValue(head.fxi, cmy.at(2), cmyCol.yellow()));
×
1397
                        }
1398
                    }
UNCOV
1399
                    else if (m_controlModeCombo->currentIndex() == RGBMatrix::ControlModeDimmer)
×
1400
                    {
UNCOV
1401
                        quint32 channel = fxi->masterIntensityChannel();
×
1402

UNCOV
1403
                        if (channel == QLCChannel::invalid())
×
UNCOV
1404
                            channel = fxi->channelNumber(QLCChannel::Intensity, QLCChannel::MSB, head.head);
×
1405

UNCOV
1406
                        if (channel != QLCChannel::invalid())
×
UNCOV
1407
                            step.values.append(SceneValue(head.fxi, channel, RGBMatrix::rgbToGrey(col)));
×
1408
                    }
1409
                    else
1410
                    {
UNCOV
1411
                        quint32 channel = QLCChannel::invalid();
×
UNCOV
1412
                        if (m_controlModeCombo->currentIndex() == RGBMatrix::ControlModeWhite)
×
UNCOV
1413
                            channel = fxi->channelNumber(QLCChannel::White, QLCChannel::MSB, head.head);
×
UNCOV
1414
                        else if (m_controlModeCombo->currentIndex() == RGBMatrix::ControlModeAmber)
×
UNCOV
1415
                            channel = fxi->channelNumber(QLCChannel::Amber, QLCChannel::MSB, head.head);
×
UNCOV
1416
                        else if (m_controlModeCombo->currentIndex() == RGBMatrix::ControlModeUV)
×
UNCOV
1417
                            channel = fxi->channelNumber(QLCChannel::UV, QLCChannel::MSB, head.head);
×
UNCOV
1418
                        else if (m_controlModeCombo->currentIndex() == RGBMatrix::ControlModeShutter)
×
1419
                        {
UNCOV
1420
                            QLCFixtureHead fHead = fxi->head(head.head);
×
UNCOV
1421
                            QVector <quint32> shutters = fHead.shutterChannels();
×
UNCOV
1422
                            if (shutters.count())
×
UNCOV
1423
                                channel = shutters.first();
×
1424
                        }
1425

UNCOV
1426
                        if (channel != QLCChannel::invalid())
×
UNCOV
1427
                            step.values.append(SceneValue(head.fxi, channel, RGBMatrix::rgbToGrey(col)));
×
1428
                    }
1429
                }
1430
            }
1431
            // !! Important !! matrix's heads can be displaced randomly but in a sequence
1432
            // we absolutely need ordered values. So do it now !
1433
            std::sort(step.values.begin(), step.values.end());
1434

UNCOV
1435
            sequence->addStep(step);
×
UNCOV
1436
            currentStep += increment;
×
UNCOV
1437
            if (currentStep == totalSteps && m_matrix->runOrder() == RGBMatrix::PingPong)
×
1438
            {
UNCOV
1439
                currentStep = totalSteps - 2;
×
1440
                increment = -1;
1441
            }
UNCOV
1442
            m_previewHandler->updateStepColor(currentStep, m_matrix->getColor(0), m_matrix->stepsCount());
×
1443
        }
1444

UNCOV
1445
        m_doc->addFunction(sequence);
×
1446

UNCOV
1447
        if (testRunning == true)
×
UNCOV
1448
            m_testButton->click();
×
UNCOV
1449
        else if (createPreviewItems() == true)
×
UNCOV
1450
            m_previewTimer->start(MasterTimer::tick());
×
1451
    }
1452
}
1453

UNCOV
1454
void RGBMatrixEditor::slotShapeToggle(bool)
×
1455
{
UNCOV
1456
    createPreviewItems();
×
UNCOV
1457
}
×
1458

UNCOV
1459
void RGBMatrixEditor::slotPropertyComboChanged(int index)
×
1460
{
UNCOV
1461
    if (m_matrix->algorithm() == NULL ||
×
UNCOV
1462
        m_matrix->algorithm()->type() == RGBAlgorithm::Script)
×
1463
    {
UNCOV
1464
        QComboBox *combo = qobject_cast<QComboBox *>(sender());
×
UNCOV
1465
        QString pName = combo->property("pName").toString();
×
UNCOV
1466
        QString pValue = combo->itemText(index);
×
1467
        qDebug() << "Property combo changed to" << pValue;
UNCOV
1468
        m_matrix->setProperty(pName, pValue);
×
1469

UNCOV
1470
        updateColorOptions();
×
UNCOV
1471
        updateColors();
×
1472
    }
UNCOV
1473
}
×
1474

UNCOV
1475
void RGBMatrixEditor::slotPropertySpinChanged(int value)
×
1476
{
1477
    qDebug() << "Property spin changed to" << value;
UNCOV
1478
    if (m_matrix->algorithm() == NULL ||
×
UNCOV
1479
        m_matrix->algorithm()->type() == RGBAlgorithm::Script)
×
1480
    {
UNCOV
1481
        QSpinBox *spin = qobject_cast<QSpinBox *>(sender());
×
UNCOV
1482
        QString pName = spin->property("pName").toString();
×
UNCOV
1483
        m_matrix->setProperty(pName, QString::number(value));
×
1484
    }
UNCOV
1485
}
×
1486

UNCOV
1487
void RGBMatrixEditor::slotPropertyDoubleSpinChanged(double value)
×
1488
{
1489
    qDebug() << "Property float changed to" << value;
UNCOV
1490
    if (m_matrix->algorithm() == NULL ||
×
UNCOV
1491
        m_matrix->algorithm()->type() == RGBAlgorithm::Script)
×
1492
    {
UNCOV
1493
        QDoubleSpinBox *spin = qobject_cast<QDoubleSpinBox *>(sender());
×
UNCOV
1494
        QString pName = spin->property("pName").toString();
×
UNCOV
1495
        m_matrix->setProperty(pName, QString::number(value));
×
1496
    }
UNCOV
1497
}
×
1498

UNCOV
1499
void RGBMatrixEditor::slotPropertyEditChanged(QString text)
×
1500
{
1501
    qDebug() << "Property string changed to" << text;
UNCOV
1502
    if (m_matrix->algorithm() == NULL ||
×
UNCOV
1503
        m_matrix->algorithm()->type() == RGBAlgorithm::Script)
×
1504
    {
UNCOV
1505
        QLineEdit *edit = qobject_cast<QLineEdit *>(sender());
×
UNCOV
1506
        QString pName = edit->property("pName").toString();
×
UNCOV
1507
        m_matrix->setProperty(pName, text);
×
1508
    }
UNCOV
1509
}
×
1510

UNCOV
1511
FunctionParent RGBMatrixEditor::functionParent() const
×
1512
{
UNCOV
1513
    return FunctionParent::master();
×
1514
}
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