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

mcallegari / qlcplus / 8440834527

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

Pull #1422

github

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

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

9 existing lines in 4 files now uncovered.

15408 of 48592 relevant lines covered (31.71%)

22631.0 hits per line

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

0.0
/ui/src/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(const QString&)),
×
216
            this, SLOT(slotPatternActivated(const QString&)));
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(const QString&)),
×
246
            this, SLOT(slotAnimationActivated(const QString&)));
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(const QString&)),
×
252
            this, SLOT(slotImageAnimationActivated(const QString&)));
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(const QString& text)
×
884
{
885
    RGBAlgorithm* algo = RGBAlgorithm::algorithm(m_doc, text);
×
886
    m_matrix->setAlgorithm(algo);
×
NEW
887
    if (algo != NULL) {
×
NEW
888
        updateColors();
×
889
        QColor colors[RGBAlgorithmRawColorCount] = {
NEW
890
                m_matrix->getColor(0),
×
NEW
891
                m_matrix->getColor(1),
×
NEW
892
                m_matrix->getColor(2),
×
NEW
893
                m_matrix->getColor(3),
×
NEW
894
                m_matrix->getColor(4)
×
NEW
895
        };
×
NEW
896
        algo->setColors(colors);
×
NEW
897
        m_previewHandler->calculateColorDelta(m_matrix->getColor(0), m_matrix->getColor(1),
×
NEW
898
                m_matrix->algorithm());
×
899
    }
UNCOV
900
    updateExtraOptions();
×
901

902
    slotRestartTest();
×
903
}
×
904

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

1210
void RGBMatrixEditor::slotFadeOutChanged(int ms)
×
1211
{
1212
    m_matrix->setFadeOutSpeed(ms);
×
1213
}
×
1214

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

1221
void RGBMatrixEditor::slotDurationTapped()
×
1222
{
1223
    m_matrix->tap();
×
1224
}
×
1225

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

1234
void RGBMatrixEditor::slotRestartTest()
×
1235
{
1236
    m_previewTimer->stop();
×
1237

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

1245
    if (createPreviewItems() == true)
×
1246
        m_previewTimer->start(MasterTimer::tick());
×
1247

1248
}
×
1249

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

1265
void RGBMatrixEditor::slotFixtureGroupAdded()
×
1266
{
1267
    fillFixtureGroupCombo();
×
1268
}
×
1269

1270
void RGBMatrixEditor::slotFixtureGroupRemoved()
×
1271
{
1272
    fillFixtureGroupCombo();
×
1273
    slotFixtureGroupActivated(m_fixtureGroupCombo->currentIndex());
×
1274
}
×
1275

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

1296
void RGBMatrixEditor::slotSaveToSequenceClicked()
×
1297
{
1298
    if (m_matrix == NULL || m_matrix->fixtureGroup() == FixtureGroup::invalidId())
×
1299
        return;
×
1300

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

1306
        if (m_testButton->isChecked() == true)
×
1307
        {
1308
            m_testButton->click();
×
1309
            testRunning = true;
×
1310
        }
1311
        else
1312
            m_previewTimer->stop();
×
1313

1314
        Scene *grpScene = new Scene(m_doc);
×
1315
        grpScene->setName(grp->name());
×
1316
        grpScene->setVisible(false);
×
1317

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

1325
            if (m_controlModeCombo->currentIndex() == RGBMatrix::ControlModeRgb)
×
1326
            {
1327

1328
                    QVector <quint32> rgb = fxi->rgbChannels(head.head);
×
1329

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

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

1345
                if (channel == QLCChannel::invalid())
×
1346
                    channel = fxi->channelNumber(QLCChannel::Intensity, QLCChannel::MSB, head.head);
×
1347

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

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

1374
        int totalSteps = m_matrix->stepsCount();
×
1375
        int increment = 1;
×
1376
        int currentStep = 0;
×
NEW
1377
        m_previewHandler->setStepColor(m_matrix->getColor(0));
×
1378

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

1389
        if (m_matrix->runOrder() == RGBMatrix::PingPong)
×
1390
            totalSteps = (totalSteps * 2) - 1;
×
1391

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

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

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

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

1426
                    Fixture *fxi = m_doc->fixture(head.fxi);
×
1427
                    if (fxi == NULL)
×
1428
                        continue;
×
1429

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

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

1442
                        if (cmy.count() == 3)
×
1443
                        {
1444
                            QColor cmyCol(col);
×
1445

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

1455
                        if (channel == QLCChannel::invalid())
×
1456
                            channel = fxi->channelNumber(QLCChannel::Intensity, QLCChannel::MSB, head.head);
×
1457

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

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

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

1497
        m_doc->addFunction(sequence);
×
1498

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

1506
void RGBMatrixEditor::slotShapeToggle(bool)
×
1507
{
1508
    createPreviewItems();
×
1509
}
×
1510

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

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

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

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

1559
FunctionParent RGBMatrixEditor::functionParent() const
×
1560
{
1561
    return FunctionParent::master();
×
1562
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc