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

mcallegari / qlcplus / 13633248611

03 Mar 2025 02:31PM UTC coverage: 31.871% (+0.4%) from 31.5%
13633248611

push

github

web-flow
actions: add chrpath to profile

14689 of 46089 relevant lines covered (31.87%)

26426.11 hits per line

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

0.0
/ui/src/rgbmatrixeditor.cpp
1
/*
2
  Q Light Controller
3
  rgbmatrixeditor.cpp
4

5
  Copyright (c) Heikki Junnila
6

7
  Licensed under the Apache License, Version 2.0 (the "License");
8
  you may not use this file except in compliance with the License.
9
  You may obtain a copy of the License at
10

11
      http://www.apache.org/licenses/LICENSE-2.0.txt
12

13
  Unless required by applicable law or agreed to in writing, software
14
  distributed under the License is distributed on an "AS IS" BASIS,
15
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
  See the License for the specific language governing permissions and
17
  limitations under the License.
18
*/
19

20
#include <QGraphicsEllipseItem>
21
#include <QGraphicsRectItem>
22
#include <QGraphicsEffect>
23
#include <QGraphicsScene>
24
#include <QGraphicsView>
25
#include <QColorDialog>
26
#include <QFileDialog>
27
#include <QFontDialog>
28
#include <QGradient>
29
#include <QSettings>
30
#include <QComboBox>
31
#include <QLineEdit>
32
#include <QSpinBox>
33
#include <QLabel>
34
#include <QTimer>
35
#include <QDebug>
36
#include <QMutex>
37

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

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

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

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

72
    setupUi(this);
×
73

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

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

86
    init();
×
87

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

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

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

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

101
    delete m_previewHandler;
×
102
}
×
103

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

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

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

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

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

158

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

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

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

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

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

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

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

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

198
    if (m_matrix->getColor(4).isValid())
×
199
        pm.fill(m_matrix->getColor(4));
×
200
    else
201
        pm.fill(Qt::transparent);
×
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)));
223
    connect(m_mtxColor1Button, SIGNAL(clicked()),
×
224
            this, SLOT(slotMtxColor1ButtonClicked()));
225
    connect(m_mtxColor2Button, SIGNAL(clicked()),
×
226
            this, SLOT(slotMtxColor2ButtonClicked()));
227
    connect(m_resetMtxColor2Button, SIGNAL(clicked()),
×
228
            this, SLOT(slotResetMtxColor2ButtonClicked()));
229
    connect(m_mtxColor3Button, SIGNAL(clicked()),
×
230
            this, SLOT(slotMtxColor3ButtonClicked()));
231
    connect(m_resetMtxColor3Button, SIGNAL(clicked()),
×
232
            this, SLOT(slotResetMtxColor3ButtonClicked()));
233
    connect(m_mtxColor4Button, SIGNAL(clicked()),
×
234
            this, SLOT(slotMtxColor4ButtonClicked()));
235
    connect(m_resetMtxColor4Button, SIGNAL(clicked()),
×
236
            this, SLOT(slotResetMtxColor4ButtonClicked()));
237
    connect(m_mtxColor5Button, SIGNAL(clicked()),
×
238
            this, SLOT(slotMtxColor5ButtonClicked()));
239
    connect(m_resetMtxColor5Button, SIGNAL(clicked()),
×
240
            this, SLOT(slotResetMtxColor5ButtonClicked()));
241
    connect(m_textEdit, SIGNAL(textEdited(const QString&)),
×
242
            this, SLOT(slotTextEdited(const QString&)));
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
    updateColorOptions();
×
398
}
×
399

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

581
    int gridRowIdx = 0;
582

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

848
    slotRestartTest();
×
849
}
×
850

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

1196
}
×
1197

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

1445
        m_doc->addFunction(sequence);
×
1446

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

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

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

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

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

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

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

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

© 2025 Coveralls, Inc