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

mcallegari / qlcplus / 9242447442

26 May 2024 10:08AM UTC coverage: 31.637% (-0.4%) from 32.007%
9242447442

Pull #1422

github

web-flow
Merge 8b0046d03 into ff16fdc69
Pull Request #1422: RgbScript make stage colors available to scripts

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

9 existing lines in 4 files now uncovered.

15421 of 48743 relevant lines covered (31.64%)

22692.38 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);
×
NEW
177
    pm.fill(m_matrix->getColor(0));
×
NEW
178
    m_mtxColor1Button->setIcon(QIcon(pm));
×
179

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

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

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

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

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)));
NEW
223
    connect(m_mtxColor1Button, SIGNAL(clicked()),
×
224
            this, SLOT(slotMtxColor1ButtonClicked()));
NEW
225
    connect(m_mtxColor2Button, SIGNAL(clicked()),
×
226
            this, SLOT(slotMtxColor2ButtonClicked()));
NEW
227
    connect(m_resetMtxColor2Button, SIGNAL(clicked()),
×
228
            this, SLOT(slotResetMtxColor2ButtonClicked()));
NEW
229
    connect(m_mtxColor3Button, SIGNAL(clicked()),
×
230
            this, SLOT(slotMtxColor3ButtonClicked()));
NEW
231
    connect(m_resetMtxColor3Button, SIGNAL(clicked()),
×
232
            this, SLOT(slotResetMtxColor3ButtonClicked()));
NEW
233
    connect(m_mtxColor4Button, SIGNAL(clicked()),
×
234
            this, SLOT(slotMtxColor4ButtonClicked()));
NEW
235
    connect(m_resetMtxColor4Button, SIGNAL(clicked()),
×
236
            this, SLOT(slotResetMtxColor4ButtonClicked()));
NEW
237
    connect(m_mtxColor5Button, SIGNAL(clicked()),
×
238
            this, SLOT(slotMtxColor5ButtonClicked()));
NEW
239
    connect(m_resetMtxColor5Button, SIGNAL(clicked()),
×
240
            this, SLOT(slotResetMtxColor5ButtonClicked()));
UNCOV
241
    connect(m_textEdit, SIGNAL(textEdited(const QString&)),
×
242
            this, SLOT(slotTextEdited(const QString&)));
243
    connect(m_fontButton, SIGNAL(clicked()),
×
244
            this, SLOT(slotFontButtonClicked()));
245
    connect(m_animationCombo, SIGNAL(activated(int)),
×
246
            this, SLOT(slotAnimationActivated(int)));
247
    connect(m_imageEdit, SIGNAL(editingFinished()),
×
248
            this, SLOT(slotImageEdited()));
249
    connect(m_imageButton, SIGNAL(clicked()),
×
250
            this, SLOT(slotImageButtonClicked()));
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()));
×
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);
×
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

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

282
    m_speedDials = new SpeedDialWidget(this);
×
283
    m_speedDials->setAttribute(Qt::WA_DeleteOnClose);
×
284
    m_speedDials->setWindowTitle(m_matrix->name());
×
285
    m_speedDials->show();
×
286
    m_speedDials->setFadeInSpeed(m_matrix->fadeInSpeed());
×
287
    m_speedDials->setFadeOutSpeed(m_matrix->fadeOutSpeed());
×
288
    if ((int)m_matrix->duration() < 0)
×
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)));
×
293
    connect(m_speedDials, SIGNAL(fadeOutChanged(int)), this, SLOT(slotFadeOutChanged(int)));
×
294
    connect(m_speedDials, SIGNAL(holdChanged(int)), this, SLOT(slotHoldChanged(int)));
×
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));
×
302
    if (m_matrix->algorithm() != NULL)
×
303
    {
304
        int index = m_patternCombo->findText(m_matrix->algorithm()->name());
×
305
        if (index >= 0)
×
306
            m_patternCombo->setCurrentIndex(index);
×
307
    }
308
}
×
309

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
    {
318
        FixtureGroup* grp(it.next());
×
319
        Q_ASSERT(grp != NULL);
×
320
        m_fixtureGroupCombo->addItem(grp->name(), grp->id());
×
321
        if (m_matrix->fixtureGroup() == grp->id())
×
322
            m_fixtureGroupCombo->setCurrentIndex(m_fixtureGroupCombo->count() - 1);
×
323
    }
324
}
×
325

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

336
void RGBMatrixEditor::updateExtraOptions()
×
337
{
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();
×
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();
×
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();
×
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

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
    }
379
    else if (m_matrix->algorithm()->type() == RGBAlgorithm::Text)
×
380
    {
381
        m_textGroup->show();
×
382
        m_offsetGroup->show();
×
383
        m_imageGroup->hide();
×
384

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

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

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

397
    if (m_matrix->algorithm() != NULL)
×
398
    {
399
        int accColors = m_matrix->algorithm()->acceptColors();
×
400
        if (accColors == 0)
×
401
        {
NEW
402
            m_mtxColor1Button->hide();
×
NEW
403
            m_mtxColor2Button->hide();
×
NEW
404
            m_resetMtxColor2Button->hide();
×
NEW
405
            m_mtxColor3Button->hide();
×
NEW
406
            m_resetMtxColor3Button->hide();
×
NEW
407
            m_mtxColor4Button->hide();
×
NEW
408
            m_resetMtxColor4Button->hide();
×
NEW
409
            m_mtxColor5Button->hide();
×
NEW
410
            m_resetMtxColor5Button->hide();
×
411
            m_blendModeLabel->hide();
×
412
            m_blendModeCombo->hide();
×
413
        }
414
        else
415
        {
NEW
416
            m_mtxColor1Button->show();
×
417

418
            if (accColors == 1 || m_blendModeCombo->currentIndex() == Universe::MaskBlend)
×
419
            {
NEW
420
                m_mtxColor2Button->hide();
×
NEW
421
                m_resetMtxColor2Button->hide();
×
NEW
422
                m_mtxColor3Button->hide();
×
NEW
423
                m_resetMtxColor3Button->hide();
×
NEW
424
                m_mtxColor4Button->hide();
×
NEW
425
                m_resetMtxColor4Button->hide();
×
NEW
426
                m_mtxColor5Button->hide();
×
NEW
427
                m_resetMtxColor5Button->hide();
×
428
            }
NEW
429
            else if (accColors == 2)
×
430
            {
NEW
431
                m_mtxColor2Button->show();
×
NEW
432
                m_resetMtxColor2Button->show();
×
NEW
433
                m_mtxColor3Button->hide();
×
NEW
434
                m_resetMtxColor3Button->hide();
×
NEW
435
                m_mtxColor4Button->hide();
×
NEW
436
                m_resetMtxColor4Button->hide();
×
NEW
437
                m_mtxColor5Button->hide();
×
NEW
438
                m_resetMtxColor5Button->hide();
×
439
            }
NEW
440
            else if (accColors == 3)
×
441
            {
NEW
442
                m_mtxColor2Button->show();
×
NEW
443
                m_resetMtxColor2Button->show();
×
NEW
444
                m_mtxColor3Button->show();
×
NEW
445
                m_resetMtxColor3Button->show();
×
NEW
446
                m_mtxColor4Button->hide();
×
NEW
447
                m_resetMtxColor4Button->hide();
×
NEW
448
                m_mtxColor5Button->hide();
×
NEW
449
                m_resetMtxColor5Button->hide();
×
450
            }
NEW
451
            else if (accColors == 4)
×
452
            {
NEW
453
                m_mtxColor2Button->show();
×
NEW
454
                m_resetMtxColor2Button->show();
×
NEW
455
                m_mtxColor3Button->show();
×
NEW
456
                m_resetMtxColor3Button->show();
×
NEW
457
                m_mtxColor4Button->show();
×
NEW
458
                m_resetMtxColor4Button->show();
×
NEW
459
                m_mtxColor5Button->hide();
×
NEW
460
                m_resetMtxColor5Button->hide();
×
461
            }
462
            else
463
            {
NEW
464
                m_mtxColor2Button->show();
×
NEW
465
                m_resetMtxColor2Button->show();
×
NEW
466
                m_mtxColor3Button->show();
×
NEW
467
                m_resetMtxColor3Button->show();
×
NEW
468
                m_mtxColor4Button->show();
×
NEW
469
                m_resetMtxColor4Button->show();
×
NEW
470
                m_mtxColor5Button->show();
×
NEW
471
                m_resetMtxColor5Button->show();
×
472
            }
473
            m_blendModeLabel->show();
×
474
            m_blendModeCombo->show();
×
475
        }
476
    }
477
}
×
478

479
void RGBMatrixEditor::updateColors()
×
480
{
481
    if (m_matrix->algorithm() != NULL)
×
482
    {
483
        int accColors = m_matrix->algorithm()->acceptColors();
×
484
        if (accColors > 0)
×
485
        {
486
            if (m_matrix->blendMode() == Universe::MaskBlend)
×
487
            {
NEW
488
                m_matrix->setColor(0, Qt::white);
×
489
                // Overwrite more colors only if applied.
NEW
490
                if (accColors <= 2)
×
NEW
491
                    m_matrix->setColor(1, QColor());
×
NEW
492
                if (accColors <= 3)
×
NEW
493
                    m_matrix->setColor(2, QColor());
×
NEW
494
                if (accColors <= 4)
×
NEW
495
                    m_matrix->setColor(3, QColor());
×
NEW
496
                if (accColors <= 5)
×
NEW
497
                    m_matrix->setColor(4, QColor());
×
498

NEW
499
                m_previewHandler->calculateColorDelta(m_matrix->getColor(0), m_matrix->getColor(1),
×
NEW
500
                        m_matrix->algorithm());
×
501

502
                QPixmap pm(50, 26);
×
503
                pm.fill(Qt::white);
×
NEW
504
                m_mtxColor1Button->setIcon(QIcon(pm));
×
505

NEW
506
                pm.fill(Qt::transparent);
×
NEW
507
                m_mtxColor2Button->setIcon(QIcon(pm));
×
NEW
508
                m_mtxColor3Button->setIcon(QIcon(pm));
×
NEW
509
                m_mtxColor4Button->setIcon(QIcon(pm));
×
NEW
510
                m_mtxColor5Button->setIcon(QIcon(pm));
×
511
            }
512
            else if (m_controlModeCombo->currentIndex() != RGBMatrix::ControlModeRgb)
×
513
            {
514
                // Convert color 1 to grayscale for single color modes
NEW
515
                uchar gray = qGray(m_matrix->getColor(0).rgb());
×
NEW
516
                m_matrix->setColor(0, QColor(gray, gray, gray));
×
517
                QPixmap pm(50, 26);
×
518
                pm.fill(QColor(gray, gray, gray));
×
NEW
519
                m_mtxColor1Button->setIcon(QIcon(pm));
×
520

521
                // Convert color 2 and following to grayscale for single color modes
NEW
522
                if (accColors < 2)
×
NEW
523
                    m_matrix->setColor(1, QColor());
×
NEW
524
                if (m_matrix->getColor(1) == QColor())
×
525
                {
NEW
526
                    pm.fill(Qt::transparent);
×
527
                }
528
                else
529
                {
NEW
530
                    gray = qGray(m_matrix->getColor(1).rgb());
×
NEW
531
                    m_matrix->setColor(1, QColor(gray, gray, gray));
×
NEW
532
                    pm.fill(QColor(gray, gray, gray));
×
533
                }
NEW
534
                m_mtxColor2Button->setIcon(QIcon(pm));
×
535

NEW
536
                if (accColors < 3)
×
NEW
537
                    m_matrix->setColor(2, QColor());
×
NEW
538
                if (m_matrix->getColor(2) == QColor())
×
539
                {
NEW
540
                    pm.fill(Qt::transparent);
×
541
                }
542
                else
543
                {
NEW
544
                    gray = qGray(m_matrix->getColor(2).rgb());
×
NEW
545
                    m_matrix->setColor(2, QColor(gray, gray, gray));
×
NEW
546
                    pm.fill(QColor(gray, gray, gray));
×
547
                }
NEW
548
                m_mtxColor3Button->setIcon(QIcon(pm));
×
549

NEW
550
                if (accColors < 4)
×
NEW
551
                    m_matrix->setColor(3, QColor());
×
NEW
552
                if (m_matrix->getColor(3) == QColor())
×
553
                {
NEW
554
                    pm.fill(Qt::transparent);
×
555
                }
556
                else
557
                {
NEW
558
                    gray = qGray(m_matrix->getColor(3).rgb());
×
NEW
559
                    m_matrix->setColor(3, QColor(gray, gray, gray));
×
NEW
560
                    pm.fill(QColor(gray, gray, gray));
×
561
                }
NEW
562
                m_mtxColor4Button->setIcon(QIcon(pm));
×
563

NEW
564
                if (accColors < 5)
×
NEW
565
                    m_matrix->setColor(4, QColor());
×
NEW
566
                if (m_matrix->getColor(4) == QColor())
×
567
                {
NEW
568
                    pm.fill(Qt::transparent);
×
569
                }
570
                else
571
                {
NEW
572
                    gray = qGray(m_matrix->getColor(4).rgb());
×
NEW
573
                    m_matrix->setColor(4, QColor(gray, gray, gray));
×
NEW
574
                    pm.fill(QColor(gray, gray, gray));
×
575
                }
NEW
576
                m_mtxColor5Button->setIcon(QIcon(pm));
×
577

NEW
578
                m_previewHandler->calculateColorDelta(m_matrix->getColor(0), m_matrix->getColor(1),
×
NEW
579
                        m_matrix->algorithm());
×
580
            }
581
            else 
582
            {
583
                QPixmap pm(50, 26);
×
NEW
584
                pm.fill(m_matrix->getColor(0));
×
NEW
585
                m_mtxColor1Button->setIcon(QIcon(pm));
×
586

587
                // Preserve the colors (do not set them to QColor().
588
                // RGBMatrixStep::calculateColorDelta will ensure correct color application
NEW
589
                if (m_matrix->getColor(1) == QColor())
×
NEW
590
                    pm.fill(Qt::transparent);
×
591
                else
NEW
592
                    pm.fill(m_matrix->getColor(1));
×
NEW
593
                m_mtxColor2Button->setIcon(QIcon(pm));
×
594

NEW
595
                if (m_matrix->getColor(2) == QColor())
×
NEW
596
                    pm.fill(Qt::transparent);
×
597
                else
NEW
598
                    pm.fill(m_matrix->getColor(2));
×
NEW
599
                m_mtxColor3Button->setIcon(QIcon(pm));
×
600

NEW
601
                if (m_matrix->getColor(3) == QColor())
×
NEW
602
                    pm.fill(Qt::transparent);
×
603
                else
NEW
604
                    pm.fill(m_matrix->getColor(3));
×
NEW
605
                m_mtxColor4Button->setIcon(QIcon(pm));
×
606

NEW
607
                if (m_matrix->getColor(4) == QColor())
×
NEW
608
                    pm.fill(Qt::transparent);
×
609
                else
NEW
610
                    pm.fill(m_matrix->getColor(4));
×
NEW
611
                m_mtxColor5Button->setIcon(QIcon(pm));
×
612

NEW
613
                m_previewHandler->calculateColorDelta(m_matrix->getColor(0), m_matrix->getColor(1),
×
NEW
614
                        m_matrix->algorithm());
×
615
            }
616
        }
617
    }
618
}
×
619

620
/**
621
 * Helper function. Deletes all child widgets of the given layout @a item.
622
 */
623
void RGBMatrixEditor::resetProperties(QLayoutItem *item)
×
624
{
625
    if (item->layout()) 
×
626
    {
627
        // Process all child items recursively.
628
        for (int i = item->layout()->count() - 1; i >= 0; i--)
×
629
            resetProperties(item->layout()->itemAt(i));
×
630
    }
631
    delete item->widget();
×
632
}
×
633

634
void RGBMatrixEditor::displayProperties(RGBScript *script)
×
635
{
636
    if (script == NULL)
×
637
        return;
×
638

639
    int gridRowIdx = 0;
×
640

641
    QList<RGBScriptProperty> properties = script->properties();
×
642
    if (properties.count() > 0)
×
643
        m_propertiesGroup->show();
×
644

645
    foreach (RGBScriptProperty prop, properties)
×
646
    {
647
        switch(prop.m_type)
×
648
        {
649
            case RGBScriptProperty::List:
×
650
            {
651
                QLabel *propLabel = new QLabel(prop.m_displayName);
×
652
                m_propertiesLayout->addWidget(propLabel, gridRowIdx, 0);
×
653
                QComboBox *propCombo = new QComboBox(this);
×
654
                propCombo->addItems(prop.m_listValues);
×
655
                propCombo->setProperty("pName", prop.m_name);
×
656
                connect(propCombo, SIGNAL(currentIndexChanged(QString)),
×
657
                        this, SLOT(slotPropertyComboChanged(QString)));
658
                m_propertiesLayout->addWidget(propCombo, gridRowIdx, 1);
×
659
                if (m_matrix != NULL)
×
660
                {
661
                    QString pValue = m_matrix->property(prop.m_name);
×
662
                    if (!pValue.isEmpty())
×
663
                    {
664
                        propCombo->setCurrentText(pValue);
×
665
                    }
666
                    else
667
                    {
668
                        pValue = script->property(prop.m_name);
×
669
                        if (!pValue.isEmpty())
×
670
                            propCombo->setCurrentText(pValue);
×
671
                    }
672
                }
673
                gridRowIdx++;
×
674
            }
675
            break;
×
676
            case RGBScriptProperty::Range:
×
677
            {
678
                QLabel *propLabel = new QLabel(prop.m_displayName);
×
679
                m_propertiesLayout->addWidget(propLabel, gridRowIdx, 0);
×
680
                QSpinBox *propSpin = new QSpinBox(this);
×
681
                propSpin->setRange(prop.m_rangeMinValue, prop.m_rangeMaxValue);
×
682
                propSpin->setProperty("pName", prop.m_name);
×
683
                connect(propSpin, SIGNAL(valueChanged(int)),
×
684
                        this, SLOT(slotPropertySpinChanged(int)));
685
                m_propertiesLayout->addWidget(propSpin, gridRowIdx, 1);
×
686
                if (m_matrix != NULL)
×
687
                {
688
                    QString pValue = m_matrix->property(prop.m_name);
×
689
                    if (!pValue.isEmpty())
×
690
                        propSpin->setValue(pValue.toInt());
×
691
                    else
692
                    {
693
                        pValue = script->property(prop.m_name);
×
694
                        if (!pValue.isEmpty())
×
695
                            propSpin->setValue(pValue.toInt());
×
696
                    }
697
                }
698
                gridRowIdx++;
×
699
            }
700
            break;
×
701
            case RGBScriptProperty::Float:
×
702
            {
703
                QLabel *propLabel = new QLabel(prop.m_displayName);
×
704
                m_propertiesLayout->addWidget(propLabel, gridRowIdx, 0);
×
705
                QDoubleSpinBox *propSpin = new QDoubleSpinBox(this);
×
706
                propSpin->setDecimals(3);
×
707
                propSpin->setRange(-1000000, 1000000);
×
708
                propSpin->setProperty("pName", prop.m_name);
×
709
                connect(propSpin, SIGNAL(valueChanged(double)),
×
710
                        this, SLOT(slotPropertyDoubleSpinChanged(double)));
711
                m_propertiesLayout->addWidget(propSpin, gridRowIdx, 1);
×
712
                if (m_matrix != NULL)
×
713
                {
714
                    QString pValue = m_matrix->property(prop.m_name);
×
715
                    if (!pValue.isEmpty())
×
716
                        propSpin->setValue(pValue.toDouble());
×
717
                    else
718
                    {
719
                        pValue = script->property(prop.m_name);
×
720
                        if (!pValue.isEmpty())
×
721
                            propSpin->setValue(pValue.toDouble());
×
722
                    }
723
                }
724
                gridRowIdx++;
×
725
            }
726
            break;
×
727
            case RGBScriptProperty::String:
×
728
            {
729
                QLabel *propLabel = new QLabel(prop.m_displayName);
×
730
                m_propertiesLayout->addWidget(propLabel, gridRowIdx, 0);
×
731
                QLineEdit *propEdit = new QLineEdit(this);
×
732
                propEdit->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Preferred);
×
733
                propEdit->setProperty("pName", prop.m_name);
×
734
                connect(propEdit, SIGNAL(textEdited(QString)),
×
735
                        this, SLOT(slotPropertyEditChanged(QString)));
736
                m_propertiesLayout->addWidget(propEdit, gridRowIdx, 1);
×
737
                if (m_matrix != NULL)
×
738
                {
739
                    QString pValue = m_matrix->property(prop.m_name);
×
740
                    if (!pValue.isEmpty())
×
741
                        propEdit->setText(pValue);
×
742
                    else
743
                    {
744
                        pValue = script->property(prop.m_name);
×
745
                        if (!pValue.isEmpty())
×
746
                            propEdit->setText(pValue);
×
747
                    }
748
                }
749
                gridRowIdx++;
×
750
            }
751
            break;
×
752
            default:
×
753
                qWarning() << "Type" << prop.m_type << "not handled yet";
×
754
            break;
×
755
        }
756
    }
757
}
758

759
bool RGBMatrixEditor::createPreviewItems()
×
760
{
761
    m_previewHash.clear();
×
762
    m_scene->clear();
×
763

764
    FixtureGroup* grp = m_doc->fixtureGroup(m_matrix->fixtureGroup());
×
765
    if (grp == NULL)
×
766
    {
767
        QGraphicsTextItem* text = new QGraphicsTextItem(tr("No fixture group to control"));
×
768
        text->setDefaultTextColor(Qt::white);
×
769
        m_scene->addItem(text);
×
770
        return false;
×
771
    }
772

NEW
773
    m_previewHandler->initializeDirection(m_matrix->direction(), m_matrix->getColor(0),
×
NEW
774
                                      m_matrix->getColor(1), m_matrix->stepsCount(),
×
NEW
775
                                      m_matrix->algorithm());
×
776

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

779
    if (m_previewHandler->m_map.isEmpty())
×
780
        return false;
×
781

782
    for (int x = 0; x < grp->size().width(); x++)
×
783
    {
784
        for (int y = 0; y < grp->size().height(); y++)
×
785
        {
786
            QLCPoint pt(x, y);
×
787

788
            if (grp->headsMap().contains(pt) == true)
×
789
            {
790
                RGBItem *item;
791
                if (m_shapeButton->isChecked() == false)
×
792
                {
793
                    QGraphicsEllipseItem* circleItem = new QGraphicsEllipseItem();
×
794
                    circleItem->setRect(
×
795
                            x * RECT_SIZE + RECT_PADDING + ITEM_PADDING,
×
796
                            y * RECT_SIZE + RECT_PADDING + ITEM_PADDING,
×
797
                            ITEM_SIZE - (2 * ITEM_PADDING),
798
                            ITEM_SIZE - (2 * ITEM_PADDING));
799
                    item = new RGBItem(circleItem);
×
800
                }
801
                else
802
                {
803
                    QGraphicsRectItem *rectItem = new QGraphicsRectItem();
×
804
                    rectItem->setRect(
×
805
                            x * RECT_SIZE + RECT_PADDING + ITEM_PADDING,
×
806
                            y * RECT_SIZE + RECT_PADDING + ITEM_PADDING,
×
807
                            ITEM_SIZE - (2 * ITEM_PADDING),
808
                            ITEM_SIZE - (2 * ITEM_PADDING));
809
                    item = new RGBItem(rectItem);
×
810
                }
811

812
                item->setColor(m_previewHandler->m_map[y][x]);
×
813
                item->draw(0, 0);
×
814
                m_scene->addItem(item->graphicsItem());
×
815
                m_previewHash[pt] = item;
×
816
            }
817
        }
818
    }
819
    return true;
×
820
}
821

822
void RGBMatrixEditor::slotPreviewTimeout()
×
823
{
824
    if (m_matrix->duration() <= 0)
×
825
        return;
×
826

827
    m_previewIterator += MasterTimer::tick();
×
828
    uint elapsed = 0;
×
829
    while (m_previewIterator >= MAX(m_matrix->duration(), MasterTimer::tick()))
×
830
    {
NEW
831
        m_previewHandler->checkNextStep(m_matrix->runOrder(), m_matrix->getColor(0),
×
NEW
832
                                        m_matrix->getColor(1), m_matrix->stepsCount());
×
833

834
        m_matrix->previewMap(m_previewHandler->currentStepIndex(), m_previewHandler);
×
835

836
        m_previewIterator -= MAX(m_matrix->duration(), MasterTimer::tick());
×
837
        elapsed += MAX(m_matrix->duration(), MasterTimer::tick());
×
838
    }
839
    for (int y = 0; y < m_previewHandler->m_map.size(); y++)
×
840
    {
841
        for (int x = 0; x < m_previewHandler->m_map[y].size(); x++)
×
842
        {
843
            QLCPoint pt(x, y);
×
844
            if (m_previewHash.contains(pt) == true)
×
845
            {
846
                RGBItem* shape = m_previewHash[pt];
×
847
                if (shape->color() != QColor(m_previewHandler->m_map[y][x]).rgb())
×
848
                    shape->setColor(m_previewHandler->m_map[y][x]);
×
849

850
                if (shape->color() == QColor(Qt::black).rgb())
×
851
                    shape->draw(elapsed, m_matrix->fadeOutSpeed());
×
852
                else
853
                    shape->draw(elapsed, m_matrix->fadeInSpeed());
×
854
            }
855
        }
856
    }
857
}
858

859
void RGBMatrixEditor::slotNameEdited(const QString& text)
×
860
{
861
    m_matrix->setName(text);
×
862
    if (m_speedDials != NULL)
×
863
        m_speedDials->setWindowTitle(text);
×
864
}
×
865

866
void RGBMatrixEditor::slotSpeedDialToggle(bool state)
×
867
{
868
    if (state == true)
×
869
        updateSpeedDials();
×
870
    else
871
    {
872
        if (m_speedDials != NULL)
×
873
            m_speedDials->deleteLater();
×
874
        m_speedDials = NULL;
×
875
    }
876
}
×
877

878
void RGBMatrixEditor::slotDialDestroyed(QObject *)
×
879
{
880
    m_speedDialButton->setChecked(false);
×
881
}
×
882

883
void RGBMatrixEditor::slotPatternActivated(int patternIndex)
×
884
{
885
    QString algoName = m_patternCombo->itemText(patternIndex);
×
886
    RGBAlgorithm *algo = RGBAlgorithm::algorithm(m_doc, algoName);
×
887
    m_matrix->setAlgorithm(algo);
×
NEW
888
    if (algo != NULL) {
×
NEW
889
        updateColors();
×
890
        QColor colors[RGBAlgorithmRawColorCount] = {
NEW
891
                m_matrix->getColor(0),
×
NEW
892
                m_matrix->getColor(1),
×
NEW
893
                m_matrix->getColor(2),
×
NEW
894
                m_matrix->getColor(3),
×
NEW
895
                m_matrix->getColor(4)
×
NEW
896
        };
×
NEW
897
        algo->setColors(colors);
×
NEW
898
        m_previewHandler->calculateColorDelta(m_matrix->getColor(0), m_matrix->getColor(1),
×
NEW
899
                m_matrix->algorithm());
×
900
    }
UNCOV
901
    updateExtraOptions();
×
902

903
    slotRestartTest();
×
904
}
×
905

906
void RGBMatrixEditor::slotFixtureGroupActivated(int index)
×
907
{
908
    QVariant var = m_fixtureGroupCombo->itemData(index);
×
909
    if (var.isValid() == true)
×
910
    {
911
        m_matrix->setFixtureGroup(var.toUInt());
×
912
        slotRestartTest();
×
913
    }
914
    else
915
    {
916
        m_matrix->setFixtureGroup(FixtureGroup::invalidId());
×
917
        m_previewTimer->stop();
×
918
        m_scene->clear();
×
919
    }
920
}
×
921

922
void RGBMatrixEditor::slotBlendModeChanged(int index)
×
923
{
924
    m_matrix->setBlendMode(Universe::BlendMode(index));
×
925

926
    if (index == Universe::MaskBlend)
×
927
    {
NEW
928
        m_mtxColor1Button->setEnabled(false);
×
929
    }
930
    else
931
    {
NEW
932
        m_mtxColor1Button->setEnabled(true);
×
933
    }
934
    updateExtraOptions();
×
935
    updateColors();
×
936
    slotRestartTest();
×
937
}
×
938

939
void RGBMatrixEditor::slotControlModeChanged(int index)
×
940
{
941
    RGBMatrix::ControlMode mode = RGBMatrix::ControlMode(index);
×
942
    m_matrix->setControlMode(mode);
×
943
    updateColors();
×
944
    slotRestartTest();
×
945
}
×
946

NEW
947
void RGBMatrixEditor::slotMtxColor1ButtonClicked()
×
948
{
NEW
949
    QColor col = QColorDialog::getColor(m_matrix->getColor(0));
×
NEW
950
    if (col.isValid() == true)
×
951
    {
NEW
952
        m_matrix->setColor(0, col);
×
NEW
953
        updateColors();
×
NEW
954
        slotRestartTest();
×
955
    }
NEW
956
}
×
957

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

NEW
969
void RGBMatrixEditor::slotResetMtxColor2ButtonClicked()
×
970
{
NEW
971
    m_matrix->setColor(1, QColor());
×
NEW
972
    updateColors();
×
NEW
973
    slotRestartTest();
×
NEW
974
}
×
975

NEW
976
void RGBMatrixEditor::slotMtxColor3ButtonClicked()
×
977
{
NEW
978
    QColor col = QColorDialog::getColor(m_matrix->getColor(2));
×
NEW
979
    if (col.isValid() == true)
×
980
    {
NEW
981
        m_matrix->setColor(2, col);
×
NEW
982
        updateColors();
×
NEW
983
        slotRestartTest();
×
984
    }
NEW
985
}
×
986

NEW
987
void RGBMatrixEditor::slotResetMtxColor3ButtonClicked()
×
988
{
NEW
989
    m_matrix->setColor(2, QColor());
×
NEW
990
    updateColors();
×
NEW
991
    slotRestartTest();
×
NEW
992
}
×
993

NEW
994
void RGBMatrixEditor::slotMtxColor4ButtonClicked()
×
995
{
NEW
996
    QColor col = QColorDialog::getColor(m_matrix->getColor(3));
×
997
    if (col.isValid() == true)
×
998
    {
NEW
999
        m_matrix->setColor(3, col);
×
1000
        updateColors();
×
1001
        slotRestartTest();
×
1002
    }
1003
}
×
1004

NEW
1005
void RGBMatrixEditor::slotResetMtxColor4ButtonClicked()
×
1006
{
NEW
1007
    m_matrix->setColor(3, QColor());
×
NEW
1008
    updateColors();
×
NEW
1009
    slotRestartTest();
×
NEW
1010
}
×
1011

NEW
1012
void RGBMatrixEditor::slotMtxColor5ButtonClicked()
×
1013
{
NEW
1014
    QColor col = QColorDialog::getColor(m_matrix->getColor(4));
×
1015
    if (col.isValid() == true)
×
1016
    {
NEW
1017
        m_matrix->setColor(4, col);
×
1018
        updateColors();
×
1019
        slotRestartTest();
×
1020
    }
1021
}
×
1022

NEW
1023
void RGBMatrixEditor::slotResetMtxColor5ButtonClicked()
×
1024
{
NEW
1025
    m_matrix->setColor(4, QColor());
×
1026
    updateColors();
×
1027
    slotRestartTest();
×
1028
}
×
1029

1030
void RGBMatrixEditor::slotTextEdited(const QString& text)
×
1031
{
1032
    if (m_matrix->algorithm() != NULL && m_matrix->algorithm()->type() == RGBAlgorithm::Text)
×
1033
    {
1034
        RGBText *algo = static_cast<RGBText*> (m_matrix->algorithm());
×
1035
        Q_ASSERT(algo != NULL);
×
1036
        {
1037
            QMutexLocker algorithmLocker(&m_matrix->algorithmMutex());
×
1038
            algo->setText(text);
×
1039
        }
1040
        slotRestartTest();
×
1041
    }
1042
}
×
1043

1044
void RGBMatrixEditor::slotFontButtonClicked()
×
1045
{
1046
    if (m_matrix->algorithm() != NULL && m_matrix->algorithm()->type() == RGBAlgorithm::Text)
×
1047
    {
1048
        RGBText *algo = static_cast<RGBText*> (m_matrix->algorithm());
×
1049
        Q_ASSERT(algo != NULL);
×
1050

1051
        bool ok = false;
×
1052
        QFont font = QFontDialog::getFont(&ok, algo->font(), this);
×
1053
        if (ok == true)
×
1054
        {
1055
            {
1056
                QMutexLocker algorithmLocker(&m_matrix->algorithmMutex());
×
1057
                algo->setFont(font);
×
1058
            }
1059
            slotRestartTest();
×
1060
        }
1061
    }
1062
}
×
1063

1064
void RGBMatrixEditor::slotAnimationActivated(int index)
×
1065
{
1066
    if (m_matrix->algorithm() != NULL && m_matrix->algorithm()->type() == RGBAlgorithm::Text)
×
1067
    {
1068
        RGBText *algo = static_cast<RGBText*> (m_matrix->algorithm());
×
1069
        Q_ASSERT(algo != NULL);
×
1070
        {
1071
            QMutexLocker algorithmLocker(&m_matrix->algorithmMutex());
×
1072
            QString text = m_animationCombo->itemText(index);
×
1073
            algo->setAnimationStyle(RGBText::stringToAnimationStyle(text));
×
1074
        }
1075
        slotRestartTest();
×
1076
    }
1077
}
×
1078

1079
void RGBMatrixEditor::slotImageEdited()
×
1080
{
1081
    if (m_matrix->algorithm() != NULL && m_matrix->algorithm()->type() == RGBAlgorithm::Image)
×
1082
    {
1083
        RGBImage *algo = static_cast<RGBImage*> (m_matrix->algorithm());
×
1084
        Q_ASSERT(algo != NULL);
×
1085
        {
1086
            QMutexLocker algorithmLocker(&m_matrix->algorithmMutex());
×
1087
            algo->setFilename(m_imageEdit->text());
×
1088
        }
1089
        slotRestartTest();
×
1090
    }
1091
}
×
1092

1093
void RGBMatrixEditor::slotImageButtonClicked()
×
1094
{
1095
    if (m_matrix->algorithm() != NULL && m_matrix->algorithm()->type() == RGBAlgorithm::Image)
×
1096
    {
1097
        RGBImage *algo = static_cast<RGBImage*> (m_matrix->algorithm());
×
1098
        Q_ASSERT(algo != NULL);
×
1099

1100
        QString path = algo->filename();
×
1101
        path = QFileDialog::getOpenFileName(this,
×
1102
                                            tr("Select image"),
×
1103
                                            path,
1104
                                            QString("%1 (*.png *.bmp *.jpg *.jpeg *.gif)").arg(tr("Images")));
×
1105
        if (path.isEmpty() == false)
×
1106
        {
1107
            {
1108
                QMutexLocker algorithmLocker(&m_matrix->algorithmMutex());
×
1109
                algo->setFilename(path);
×
1110
            }
1111
            m_imageEdit->setText(path);
×
1112
            slotRestartTest();
×
1113
        }
1114
    }
1115
}
×
1116

1117
void RGBMatrixEditor::slotImageAnimationActivated(int index)
×
1118
{
1119
    if (m_matrix->algorithm() != NULL && m_matrix->algorithm()->type() == RGBAlgorithm::Image)
×
1120
    {
1121
        RGBImage *algo = static_cast<RGBImage*> (m_matrix->algorithm());
×
1122
        Q_ASSERT(algo != NULL);
×
1123
        {
1124
            QMutexLocker algorithmLocker(&m_matrix->algorithmMutex());
×
1125
            QString text = m_imageAnimationCombo->itemText(index);
×
1126
            algo->setAnimationStyle(RGBImage::stringToAnimationStyle(text));
×
1127
        }
1128
        slotRestartTest();
×
1129
    }
1130
}
×
1131

1132
void RGBMatrixEditor::slotOffsetSpinChanged()
×
1133
{
1134
    if (m_matrix->algorithm() != NULL && m_matrix->algorithm()->type() == RGBAlgorithm::Text)
×
1135
    {
1136
        RGBText *algo = static_cast<RGBText*> (m_matrix->algorithm());
×
1137
        Q_ASSERT(algo != NULL);
×
1138
        {
1139
            QMutexLocker algorithmLocker(&m_matrix->algorithmMutex());
×
1140
            algo->setXOffset(m_xOffsetSpin->value());
×
1141
            algo->setYOffset(m_yOffsetSpin->value());
×
1142
        }
1143
        slotRestartTest();
×
1144
    }
1145

1146
    if (m_matrix->algorithm() != NULL && m_matrix->algorithm()->type() == RGBAlgorithm::Image)
×
1147
    {
1148
        RGBImage *algo = static_cast<RGBImage*> (m_matrix->algorithm());
×
1149
        Q_ASSERT(algo != NULL);
×
1150
        {
1151
            QMutexLocker algorithmLocker(&m_matrix->algorithmMutex());
×
1152
            algo->setXOffset(m_xOffsetSpin->value());
×
1153
            algo->setYOffset(m_yOffsetSpin->value());
×
1154
        }
1155
        slotRestartTest();
×
1156
    }
1157
}
×
1158

1159
void RGBMatrixEditor::slotLoopClicked()
×
1160
{
1161
    m_matrix->setRunOrder(Function::Loop);
×
NEW
1162
    m_previewHandler->calculateColorDelta(m_matrix->getColor(0), m_matrix->getColor(1),
×
NEW
1163
            m_matrix->algorithm());
×
1164
    slotRestartTest();
×
1165
}
×
1166

1167
void RGBMatrixEditor::slotPingPongClicked()
×
1168
{
1169
    m_matrix->setRunOrder(Function::PingPong);
×
NEW
1170
    m_previewHandler->calculateColorDelta(m_matrix->getColor(0), m_matrix->getColor(1),
×
NEW
1171
            m_matrix->algorithm());
×
1172
    slotRestartTest();
×
1173
}
×
1174

1175
void RGBMatrixEditor::slotSingleShotClicked()
×
1176
{
1177
    m_matrix->setRunOrder(Function::SingleShot);
×
NEW
1178
    m_previewHandler->calculateColorDelta(m_matrix->getColor(0), m_matrix->getColor(1),
×
NEW
1179
            m_matrix->algorithm());
×
1180
    slotRestartTest();
×
1181
}
×
1182

1183
void RGBMatrixEditor::slotForwardClicked()
×
1184
{
1185
    m_matrix->setDirection(Function::Forward);
×
NEW
1186
    m_previewHandler->calculateColorDelta(m_matrix->getColor(0), m_matrix->getColor(1),
×
NEW
1187
            m_matrix->algorithm());
×
1188
    slotRestartTest();
×
1189
}
×
1190

1191
void RGBMatrixEditor::slotBackwardClicked()
×
1192
{
1193
    m_matrix->setDirection(Function::Backward);
×
NEW
1194
    m_previewHandler->calculateColorDelta(m_matrix->getColor(0), m_matrix->getColor(1),
×
NEW
1195
            m_matrix->algorithm());
×
1196
    slotRestartTest();
×
1197
}
×
1198

1199
void RGBMatrixEditor::slotDimmerControlClicked()
×
1200
{
1201
    m_matrix->setDimmerControl(m_dimmerControlCb->isChecked());
×
1202
    if (m_dimmerControlCb->isChecked() == false)
×
1203
        m_dimmerControlCb->setEnabled(false);
×
1204
}
×
1205

1206
void RGBMatrixEditor::slotFadeInChanged(int ms)
×
1207
{
1208
    m_matrix->setFadeInSpeed(ms);
×
1209
    uint duration = Function::speedAdd(ms, m_speedDials->duration());
×
1210
    m_matrix->setDuration(duration);
×
1211
}
×
1212

1213
void RGBMatrixEditor::slotFadeOutChanged(int ms)
×
1214
{
1215
    m_matrix->setFadeOutSpeed(ms);
×
1216
}
×
1217

1218
void RGBMatrixEditor::slotHoldChanged(int ms)
×
1219
{
1220
    uint duration = Function::speedAdd(m_matrix->fadeInSpeed(), ms);
×
1221
    m_matrix->setDuration(duration);
×
1222
}
×
1223

1224
void RGBMatrixEditor::slotDurationTapped()
×
1225
{
1226
    m_matrix->tap();
×
1227
}
×
1228

1229
void RGBMatrixEditor::slotTestClicked()
×
1230
{
1231
    if (m_testButton->isChecked() == true)
×
1232
        m_matrix->start(m_doc->masterTimer(), functionParent());
×
1233
    else
1234
        m_matrix->stopAndWait();
×
1235
}
×
1236

1237
void RGBMatrixEditor::slotRestartTest()
×
1238
{
1239
    m_previewTimer->stop();
×
1240

1241
    if (m_testButton->isChecked() == true)
×
1242
    {
1243
        // Toggle off, toggle on. Duh.
1244
        m_testButton->click();
×
1245
        m_testButton->click();
×
1246
    }
1247

1248
    if (createPreviewItems() == true)
×
1249
        m_previewTimer->start(MasterTimer::tick());
×
1250

1251
}
×
1252

1253
void RGBMatrixEditor::slotModeChanged(Doc::Mode mode)
×
1254
{
1255
    if (mode == Doc::Operate)
×
1256
    {
1257
        if (m_testButton->isChecked() == true)
×
1258
            m_matrix->stopAndWait();
×
1259
        m_testButton->setChecked(false);
×
1260
        m_testButton->setEnabled(false);
×
1261
    }
1262
    else
1263
    {
1264
        m_testButton->setEnabled(true);
×
1265
    }
1266
}
×
1267

1268
void RGBMatrixEditor::slotFixtureGroupAdded()
×
1269
{
1270
    fillFixtureGroupCombo();
×
1271
}
×
1272

1273
void RGBMatrixEditor::slotFixtureGroupRemoved()
×
1274
{
1275
    fillFixtureGroupCombo();
×
1276
    slotFixtureGroupActivated(m_fixtureGroupCombo->currentIndex());
×
1277
}
×
1278

1279
void RGBMatrixEditor::slotFixtureGroupChanged(quint32 id)
×
1280
{
1281
    if (id == m_matrix->fixtureGroup())
×
1282
    {
1283
        // Update the whole chain -> maybe the fixture layout has changed
1284
        fillFixtureGroupCombo();
×
1285
        slotFixtureGroupActivated(m_fixtureGroupCombo->currentIndex());
×
1286
    }
1287
    else
1288
    {
1289
        // Just change the name of the group, nothing else is interesting at this point
1290
        int index = m_fixtureGroupCombo->findData(id);
×
1291
        if (index != -1)
×
1292
        {
1293
            FixtureGroup* grp = m_doc->fixtureGroup(id);
×
1294
            m_fixtureGroupCombo->setItemText(index, grp->name());
×
1295
        }
1296
    }
1297
}
×
1298

1299
void RGBMatrixEditor::slotSaveToSequenceClicked()
×
1300
{
1301
    if (m_matrix == NULL || m_matrix->fixtureGroup() == FixtureGroup::invalidId())
×
1302
        return;
×
1303

1304
    FixtureGroup* grp = m_doc->fixtureGroup(m_matrix->fixtureGroup());
×
1305
    if (grp != NULL && m_matrix->algorithm() != NULL)
×
1306
    {
1307
        bool testRunning = false;
×
1308

1309
        if (m_testButton->isChecked() == true)
×
1310
        {
1311
            m_testButton->click();
×
1312
            testRunning = true;
×
1313
        }
1314
        else
1315
            m_previewTimer->stop();
×
1316

1317
        Scene *grpScene = new Scene(m_doc);
×
1318
        grpScene->setName(grp->name());
×
1319
        grpScene->setVisible(false);
×
1320

1321
        QList<GroupHead> headList = grp->headList();
×
1322
        foreach (GroupHead head, headList)
×
1323
        {
1324
            Fixture *fxi = m_doc->fixture(head.fxi);
×
1325
            if (fxi == NULL)
×
1326
                continue;
×
1327

1328
            if (m_controlModeCombo->currentIndex() == RGBMatrix::ControlModeRgb)
×
1329
            {
1330

1331
                    QVector <quint32> rgb = fxi->rgbChannels(head.head);
×
1332

1333
                    // in case of CMY, dump those channels
1334
                    if (rgb.count() == 0)
×
1335
                        rgb = fxi->cmyChannels(head.head);
×
1336

1337
                    if (rgb.count() == 3)
×
1338
                    {
1339
                        grpScene->setValue(head.fxi, rgb.at(0), 0);
×
1340
                        grpScene->setValue(head.fxi, rgb.at(1), 0);
×
1341
                        grpScene->setValue(head.fxi, rgb.at(2), 0);
×
1342
                    }
1343
            }
1344
            else if (m_controlModeCombo->currentIndex() == RGBMatrix::ControlModeDimmer)
×
1345
            {
1346
                quint32 channel = fxi->masterIntensityChannel();
×
1347

1348
                if (channel == QLCChannel::invalid())
×
1349
                    channel = fxi->channelNumber(QLCChannel::Intensity, QLCChannel::MSB, head.head);
×
1350

1351
                if (channel != QLCChannel::invalid())
×
1352
                    grpScene->setValue(head.fxi, channel, 0);
×
1353
            }
1354
            else
1355
            {
1356
                quint32 channel = QLCChannel::invalid();
×
1357
                if (m_controlModeCombo->currentIndex() == RGBMatrix::ControlModeWhite)
×
1358
                    channel = fxi->channelNumber(QLCChannel::White, QLCChannel::MSB, head.head);
×
1359
                else if (m_controlModeCombo->currentIndex() == RGBMatrix::ControlModeAmber)
×
1360
                    channel = fxi->channelNumber(QLCChannel::Amber, QLCChannel::MSB, head.head);
×
1361
                else if (m_controlModeCombo->currentIndex() == RGBMatrix::ControlModeUV)
×
1362
                    channel = fxi->channelNumber(QLCChannel::UV, QLCChannel::MSB, head.head);
×
1363
                else if (m_controlModeCombo->currentIndex() == RGBMatrix::ControlModeShutter)
×
1364
                {
1365
                    QLCFixtureHead fHead = fxi->head(head.head);
×
1366
                    QVector <quint32> shutters = fHead.shutterChannels();
×
1367
                    if (shutters.count())
×
1368
                        channel = shutters.first();
×
1369
                }
1370

1371
                if (channel != QLCChannel::invalid())
×
1372
                    grpScene->setValue(head.fxi, channel, 0);
×
1373
            }
1374
        }
1375
        m_doc->addFunction(grpScene);
×
1376

1377
        int totalSteps = m_matrix->stepsCount();
×
1378
        int increment = 1;
×
1379
        int currentStep = 0;
×
NEW
1380
        m_previewHandler->setStepColor(m_matrix->getColor(0));
×
1381

1382
        if (m_matrix->direction() == Function::Backward)
×
1383
        {
1384
            currentStep = totalSteps - 1;
×
1385
            increment = -1;
×
NEW
1386
            if (m_matrix->getColor(1).isValid())
×
NEW
1387
                m_previewHandler->setStepColor(m_matrix->getColor(1));
×
1388
        }
NEW
1389
        m_previewHandler->calculateColorDelta(m_matrix->getColor(0), m_matrix->getColor(1),
×
NEW
1390
                m_matrix->algorithm());
×
1391

1392
        if (m_matrix->runOrder() == RGBMatrix::PingPong)
×
1393
            totalSteps = (totalSteps * 2) - 1;
×
1394

1395
        Sequence *sequence = new Sequence(m_doc);
×
1396
        sequence->setName(QString("%1 %2").arg(m_matrix->name()).arg(tr("Sequence")));
×
1397
        sequence->setBoundSceneID(grpScene->id());
×
1398
        sequence->setDurationMode(Chaser::PerStep);
×
1399
        sequence->setDuration(m_matrix->duration());
×
1400

1401
        if (m_matrix->fadeInSpeed() != 0)
×
1402
        {
1403
            sequence->setFadeInMode(Chaser::PerStep);
×
1404
            sequence->setFadeInSpeed(m_matrix->fadeInSpeed());
×
1405
        }
1406
        if (m_matrix->fadeOutSpeed() != 0)
×
1407
        {
1408
            sequence->setFadeOutMode(Chaser::PerStep);
×
1409
            sequence->setFadeOutSpeed(m_matrix->fadeOutSpeed());
×
1410
        }
1411

1412
        for (int i = 0; i < totalSteps; i++)
×
1413
        {
1414
            m_matrix->previewMap(currentStep, m_previewHandler);
×
1415
            ChaserStep step;
×
1416
            step.fid = grpScene->id();
×
1417
            step.hold = m_matrix->duration() - m_matrix->fadeInSpeed();
×
1418
            step.duration = m_matrix->duration();
×
1419
            step.fadeIn = m_matrix->fadeInSpeed();
×
1420
            step.fadeOut = m_matrix->fadeOutSpeed();
×
1421

1422
            for (int y = 0; y < m_previewHandler->m_map.size(); y++)
×
1423
            {
1424
                for (int x = 0; x < m_previewHandler->m_map[y].size(); x++)
×
1425
                {
1426
                    uint col = m_previewHandler->m_map[y][x];
×
1427
                    GroupHead head = grp->head(QLCPoint(x, y));
×
1428

1429
                    Fixture *fxi = m_doc->fixture(head.fxi);
×
1430
                    if (fxi == NULL)
×
1431
                        continue;
×
1432

1433
                    if (m_controlModeCombo->currentIndex() == RGBMatrix::ControlModeRgb)
×
1434
                    {
1435
                        QVector <quint32> rgb = fxi->rgbChannels(head.head);
×
1436
                        QVector <quint32> cmy = fxi->cmyChannels(head.head);
×
1437

1438
                        if (rgb.count() == 3)
×
1439
                        {
1440
                            step.values.append(SceneValue(head.fxi, rgb.at(0), qRed(col)));
×
1441
                            step.values.append(SceneValue(head.fxi, rgb.at(1), qGreen(col)));
×
1442
                            step.values.append(SceneValue(head.fxi, rgb.at(2), qBlue(col)));
×
1443
                        }
1444

1445
                        if (cmy.count() == 3)
×
1446
                        {
1447
                            QColor cmyCol(col);
×
1448

1449
                            step.values.append(SceneValue(head.fxi, cmy.at(0), cmyCol.cyan()));
×
1450
                            step.values.append(SceneValue(head.fxi, cmy.at(1), cmyCol.magenta()));
×
1451
                            step.values.append(SceneValue(head.fxi, cmy.at(2), cmyCol.yellow()));
×
1452
                        }
1453
                    }
1454
                    else if (m_controlModeCombo->currentIndex() == RGBMatrix::ControlModeDimmer)
×
1455
                    {
1456
                        quint32 channel = fxi->masterIntensityChannel();
×
1457

1458
                        if (channel == QLCChannel::invalid())
×
1459
                            channel = fxi->channelNumber(QLCChannel::Intensity, QLCChannel::MSB, head.head);
×
1460

1461
                        if (channel != QLCChannel::invalid())
×
1462
                            step.values.append(SceneValue(head.fxi, channel, RGBMatrix::rgbToGrey(col)));
×
1463
                    }
1464
                    else
1465
                    {
1466
                        quint32 channel = QLCChannel::invalid();
×
1467
                        if (m_controlModeCombo->currentIndex() == RGBMatrix::ControlModeWhite)
×
1468
                            channel = fxi->channelNumber(QLCChannel::White, QLCChannel::MSB, head.head);
×
1469
                        else if (m_controlModeCombo->currentIndex() == RGBMatrix::ControlModeAmber)
×
1470
                            channel = fxi->channelNumber(QLCChannel::Amber, QLCChannel::MSB, head.head);
×
1471
                        else if (m_controlModeCombo->currentIndex() == RGBMatrix::ControlModeUV)
×
1472
                            channel = fxi->channelNumber(QLCChannel::UV, QLCChannel::MSB, head.head);
×
1473
                        else if (m_controlModeCombo->currentIndex() == RGBMatrix::ControlModeShutter)
×
1474
                        {
1475
                            QLCFixtureHead fHead = fxi->head(head.head);
×
1476
                            QVector <quint32> shutters = fHead.shutterChannels();
×
1477
                            if (shutters.count())
×
1478
                                channel = shutters.first();
×
1479
                        }
1480

1481
                        if (channel != QLCChannel::invalid())
×
1482
                            step.values.append(SceneValue(head.fxi, channel, RGBMatrix::rgbToGrey(col)));
×
1483
                    }
1484
                }
1485
            }
1486
            // !! Important !! matrix's heads can be displaced randomly but in a sequence
1487
            // we absolutely need ordered values. So do it now !
1488
            std::sort(step.values.begin(), step.values.end());
×
1489

1490
            sequence->addStep(step);
×
1491
            currentStep += increment;
×
1492
            if (currentStep == totalSteps && m_matrix->runOrder() == RGBMatrix::PingPong)
×
1493
            {
1494
                currentStep = totalSteps - 2;
×
1495
                increment = -1;
×
1496
            }
NEW
1497
            m_previewHandler->updateStepColor(currentStep, m_matrix->getColor(0), m_matrix->stepsCount());
×
1498
        }
1499

1500
        m_doc->addFunction(sequence);
×
1501

1502
        if (testRunning == true)
×
1503
            m_testButton->click();
×
1504
        else if (createPreviewItems() == true)
×
1505
            m_previewTimer->start(MasterTimer::tick());
×
1506
    }
1507
}
1508

1509
void RGBMatrixEditor::slotShapeToggle(bool)
×
1510
{
1511
    createPreviewItems();
×
1512
}
×
1513

1514
void RGBMatrixEditor::slotPropertyComboChanged(QString value)
×
1515
{
1516
    qDebug() << "Property combo changed to" << value;
×
1517
    if (m_matrix->algorithm() == NULL ||
×
1518
        m_matrix->algorithm()->type() == RGBAlgorithm::Script)
×
1519
    {
1520
        QComboBox *combo = qobject_cast<QComboBox *>(sender());
×
1521
        QString pName = combo->property("pName").toString();
×
1522
        m_matrix->setProperty(pName, value);
×
1523
    }
1524
}
×
1525

1526
void RGBMatrixEditor::slotPropertySpinChanged(int value)
×
1527
{
1528
    qDebug() << "Property spin changed to" << value;
×
1529
    if (m_matrix->algorithm() == NULL ||
×
1530
        m_matrix->algorithm()->type() == RGBAlgorithm::Script)
×
1531
    {
1532
        QSpinBox *spin = qobject_cast<QSpinBox *>(sender());
×
1533
        QString pName = spin->property("pName").toString();
×
1534
        m_matrix->setProperty(pName, QString::number(value));
×
1535
    }
1536
}
×
1537

1538
void RGBMatrixEditor::slotPropertyDoubleSpinChanged(double value)
×
1539
{
1540
    qDebug() << "Property float changed to" << value;
×
1541
    if (m_matrix->algorithm() == NULL ||
×
1542
        m_matrix->algorithm()->type() == RGBAlgorithm::Script)
×
1543
    {
1544
        QDoubleSpinBox *spin = qobject_cast<QDoubleSpinBox *>(sender());
×
1545
        QString pName = spin->property("pName").toString();
×
1546
        m_matrix->setProperty(pName, QString::number(value));
×
1547
    }
1548
}
×
1549

1550
void RGBMatrixEditor::slotPropertyEditChanged(QString text)
×
1551
{
1552
    qDebug() << "Property string changed to" << text;
×
1553
    if (m_matrix->algorithm() == NULL ||
×
1554
        m_matrix->algorithm()->type() == RGBAlgorithm::Script)
×
1555
    {
1556
        QLineEdit *edit = qobject_cast<QLineEdit *>(sender());
×
1557
        QString pName = edit->property("pName").toString();
×
1558
        m_matrix->setProperty(pName, text);
×
1559
    }
1560
}
×
1561

1562
FunctionParent RGBMatrixEditor::functionParent() const
×
1563
{
1564
    return FunctionParent::master();
×
1565
}
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