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

mcallegari / qlcplus / 10668847825

02 Sep 2024 02:18PM UTC coverage: 31.426% (-0.07%) from 31.498%
10668847825

push

github

web-flow
Merge pull request #1610 from Ledjlale/fix/qt6_rebase2

qmltoqt6 rebasing

25 of 290 new or added lines in 19 files covered. (8.62%)

25 existing lines in 11 files now uncovered.

15012 of 47769 relevant lines covered (31.43%)

19745.74 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->startColor());
×
178
    m_startColorButton->setIcon(QIcon(pm));
×
179

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

186
    updateExtraOptions();
×
187
    updateSpeedDials();
×
188

189
    connect(m_nameEdit, SIGNAL(textEdited(const QString&)),
×
190
            this, SLOT(slotNameEdited(const QString&)));
191
    connect(m_speedDialButton, SIGNAL(toggled(bool)),
×
192
            this, SLOT(slotSpeedDialToggle(bool)));
193
    connect(m_saveToSequenceButton, SIGNAL(clicked()),
×
194
            this, SLOT(slotSaveToSequenceClicked()));
195
    connect(m_shapeButton, SIGNAL(toggled(bool)),
×
196
            this, SLOT(slotShapeToggle(bool)));
NEW
197
    connect(m_patternCombo, SIGNAL(activated(int)),
×
198
            this, SLOT(slotPatternActivated(int)));
UNCOV
199
    connect(m_fixtureGroupCombo, SIGNAL(activated(int)),
×
200
            this, SLOT(slotFixtureGroupActivated(int)));
201
    connect(m_blendModeCombo, SIGNAL(activated(int)),
×
202
            this, SLOT(slotBlendModeChanged(int)));
203
    connect(m_controlModeCombo, SIGNAL(activated(int)),
×
204
            this, SLOT(slotControlModeChanged(int)));
205
    connect(m_startColorButton, SIGNAL(clicked()),
×
206
            this, SLOT(slotStartColorButtonClicked()));
207
    connect(m_endColorButton, SIGNAL(clicked()),
×
208
            this, SLOT(slotEndColorButtonClicked()));
209
    connect(m_resetEndColorButton, SIGNAL(clicked()),
×
210
            this, SLOT(slotResetEndColorButtonClicked()));
211
    connect(m_textEdit, SIGNAL(textEdited(const QString&)),
×
212
            this, SLOT(slotTextEdited(const QString&)));
213
    connect(m_fontButton, SIGNAL(clicked()),
×
214
            this, SLOT(slotFontButtonClicked()));
NEW
215
    connect(m_animationCombo, SIGNAL(activated(int)),
×
216
            this, SLOT(slotAnimationActivated(int)));
UNCOV
217
    connect(m_imageEdit, SIGNAL(editingFinished()),
×
218
            this, SLOT(slotImageEdited()));
219
    connect(m_imageButton, SIGNAL(clicked()),
×
220
            this, SLOT(slotImageButtonClicked()));
NEW
221
    connect(m_imageAnimationCombo, SIGNAL(activated(int)),
×
222
            this, SLOT(slotImageAnimationActivated(int)));
UNCOV
223
    connect(m_xOffsetSpin, SIGNAL(valueChanged(int)),
×
224
            this, SLOT(slotOffsetSpinChanged()));
225
    connect(m_yOffsetSpin, SIGNAL(valueChanged(int)),
×
226
            this, SLOT(slotOffsetSpinChanged()));
227

228
    connect(m_loop, SIGNAL(clicked()), this, SLOT(slotLoopClicked()));
×
229
    connect(m_pingPong, SIGNAL(clicked()), this, SLOT(slotPingPongClicked()));
×
230
    connect(m_singleShot, SIGNAL(clicked()), this, SLOT(slotSingleShotClicked()));
×
231
    connect(m_forward, SIGNAL(clicked()), this, SLOT(slotForwardClicked()));
×
232
    connect(m_backward, SIGNAL(clicked()), this, SLOT(slotBackwardClicked()));
×
233
    connect(m_dimmerControlCb, SIGNAL(clicked()), this, SLOT(slotDimmerControlClicked()));
×
234

235
    // Test slots
236
    connect(m_testButton, SIGNAL(clicked(bool)),
×
237
            this, SLOT(slotTestClicked()));
238

239
    m_preview->setScene(m_scene);
×
240
    if (createPreviewItems() == true)
×
241
        m_previewTimer->start(MasterTimer::tick());
×
242
}
×
243

244
void RGBMatrixEditor::updateSpeedDials()
×
245
{
246
    if (m_speedDialButton->isChecked() == false)
×
247
        return;
×
248

249
    if (m_speedDials != NULL)
×
250
        return;
×
251

252
    m_speedDials = new SpeedDialWidget(this);
×
253
    m_speedDials->setAttribute(Qt::WA_DeleteOnClose);
×
254
    m_speedDials->setWindowTitle(m_matrix->name());
×
255
    m_speedDials->show();
×
256
    m_speedDials->setFadeInSpeed(m_matrix->fadeInSpeed());
×
257
    m_speedDials->setFadeOutSpeed(m_matrix->fadeOutSpeed());
×
258
    if ((int)m_matrix->duration() < 0)
×
259
        m_speedDials->setDuration(m_matrix->duration());
×
260
    else
261
        m_speedDials->setDuration(m_matrix->duration() - m_matrix->fadeInSpeed());
×
262
    connect(m_speedDials, SIGNAL(fadeInChanged(int)), this, SLOT(slotFadeInChanged(int)));
×
263
    connect(m_speedDials, SIGNAL(fadeOutChanged(int)), this, SLOT(slotFadeOutChanged(int)));
×
264
    connect(m_speedDials, SIGNAL(holdChanged(int)), this, SLOT(slotHoldChanged(int)));
×
265
    connect(m_speedDials, SIGNAL(holdTapped()), this, SLOT(slotDurationTapped()));
×
266
    connect(m_speedDials, SIGNAL(destroyed(QObject*)), this, SLOT(slotDialDestroyed(QObject*)));
×
267
}
268

269
void RGBMatrixEditor::fillPatternCombo()
×
270
{
271
    m_patternCombo->addItems(RGBAlgorithm::algorithms(m_doc));
×
272
    if (m_matrix->algorithm() != NULL)
×
273
    {
274
        int index = m_patternCombo->findText(m_matrix->algorithm()->name());
×
275
        if (index >= 0)
×
276
            m_patternCombo->setCurrentIndex(index);
×
277
    }
278
}
×
279

280
void RGBMatrixEditor::fillFixtureGroupCombo()
×
281
{
282
    m_fixtureGroupCombo->clear();
×
283
    m_fixtureGroupCombo->addItem(tr("None"));
×
284

285
    QListIterator <FixtureGroup*> it(m_doc->fixtureGroups());
×
286
    while (it.hasNext() == true)
×
287
    {
288
        FixtureGroup* grp(it.next());
×
289
        Q_ASSERT(grp != NULL);
×
290
        m_fixtureGroupCombo->addItem(grp->name(), grp->id());
×
291
        if (m_matrix->fixtureGroup() == grp->id())
×
292
            m_fixtureGroupCombo->setCurrentIndex(m_fixtureGroupCombo->count() - 1);
×
293
    }
294
}
×
295

296
void RGBMatrixEditor::fillAnimationCombo()
×
297
{
298
    m_animationCombo->addItems(RGBText::animationStyles());
×
299
}
×
300

301
void RGBMatrixEditor::fillImageAnimationCombo()
×
302
{
303
    m_imageAnimationCombo->addItems(RGBImage::animationStyles());
×
304
}
×
305

306
void RGBMatrixEditor::updateExtraOptions()
×
307
{
308
    resetProperties(m_propertiesLayout->layout());
×
309
    m_propertiesGroup->hide();
×
310

311
    if (m_matrix->algorithm() == NULL ||
×
312
        m_matrix->algorithm()->type() == RGBAlgorithm::Script ||
×
313
        m_matrix->algorithm()->type() == RGBAlgorithm::Audio)
×
314
    {
315
        m_textGroup->hide();
×
316
        m_imageGroup->hide();
×
317
        m_offsetGroup->hide();
×
318

319
        if (m_matrix->algorithm() != NULL && m_matrix->algorithm()->type() == RGBAlgorithm::Script)
×
320
        {
321
            RGBScript *script = static_cast<RGBScript*> (m_matrix->algorithm());
×
322
            displayProperties(script);
×
323
        }
324
    }
325
    else if (m_matrix->algorithm()->type() == RGBAlgorithm::Plain)
×
326
    {
327
        m_textGroup->hide();
×
328
        m_imageGroup->hide();
×
329
        m_offsetGroup->hide();
×
330
    }
331
    else if (m_matrix->algorithm()->type() == RGBAlgorithm::Image)
×
332
    {
333
        m_textGroup->hide();
×
334
        m_imageGroup->show();
×
335
        m_offsetGroup->show();
×
336

337
        RGBImage *image = static_cast<RGBImage*> (m_matrix->algorithm());
×
338
        Q_ASSERT(image != NULL);
×
339
        m_imageEdit->setText(image->filename());
×
340

341
        int index = m_imageAnimationCombo->findText(RGBImage::animationStyleToString(image->animationStyle()));
×
342
        if (index != -1)
×
343
            m_imageAnimationCombo->setCurrentIndex(index);
×
344

345
        m_xOffsetSpin->setValue(image->xOffset());
×
346
        m_yOffsetSpin->setValue(image->yOffset());
×
347

348
    }
349
    else if (m_matrix->algorithm()->type() == RGBAlgorithm::Text)
×
350
    {
351
        m_textGroup->show();
×
352
        m_offsetGroup->show();
×
353
        m_imageGroup->hide();
×
354

355
        RGBText *text = static_cast<RGBText*> (m_matrix->algorithm());
×
356
        Q_ASSERT(text != NULL);
×
357
        m_textEdit->setText(text->text());
×
358

359
        int index = m_animationCombo->findText(RGBText::animationStyleToString(text->animationStyle()));
×
360
        if (index != -1)
×
361
            m_animationCombo->setCurrentIndex(index);
×
362

363
        m_xOffsetSpin->setValue(text->xOffset());
×
364
        m_yOffsetSpin->setValue(text->yOffset());
×
365
    }
366

367
    if (m_matrix->algorithm() != NULL)
×
368
    {
369
        int accColors = m_matrix->algorithm()->acceptColors();
×
370
        if (accColors == 0)
×
371
        {
372
            m_startColorButton->hide();
×
373
            m_endColorButton->hide();
×
374
            m_resetEndColorButton->hide();
×
375
            m_blendModeLabel->hide();
×
376
            m_blendModeCombo->hide();
×
377
        }
378
        else
379
        {
380
            m_startColorButton->show();
×
381

382
            if (accColors == 1 || m_blendModeCombo->currentIndex() == Universe::MaskBlend)
×
383
            {
384
                m_endColorButton->hide();
×
385
                m_resetEndColorButton->hide();
×
386
            }
387
            else // accColors > 1
388
            {
389
                m_endColorButton->show();
×
390
                m_resetEndColorButton->show();
×
391
            }
392
            m_blendModeLabel->show();
×
393
            m_blendModeCombo->show();
×
394
        }
395
    }
396
}
×
397

398
void RGBMatrixEditor::updateColors()
×
399
{
400
    if (m_matrix->algorithm() != NULL)
×
401
    {
402
        int accColors = m_matrix->algorithm()->acceptColors();
×
403
        if (accColors > 0)
×
404
        {
405
            if (m_matrix->blendMode() == Universe::MaskBlend)
×
406
            {
407
                m_matrix->setStartColor(Qt::white);
×
408
                m_matrix->setEndColor(QColor());
×
409

410
                m_previewHandler->calculateColorDelta(m_matrix->startColor(), m_matrix->endColor());
×
411

412
                QPixmap pm(50, 26);
×
413
                pm.fill(Qt::white);
×
414
                m_startColorButton->setIcon(QIcon(pm));
×
415
            }
416
            else if (m_controlModeCombo->currentIndex() != RGBMatrix::ControlModeRgb)
×
417
            {
418
                // Convert startColor to grayscale for single color modes
419
                uchar gray = qGray(m_matrix->startColor().rgb());
×
420
                QPixmap pm(50, 26);
×
421
                pm.fill(QColor(gray, gray, gray));
×
422
                m_startColorButton->setIcon(QIcon(pm));
×
423
                m_matrix->setStartColor(QColor(gray, gray, gray));
×
424

425
                if (accColors > 1)
×
426
                {
427
                    // Convert endColor to grayscale for single color modes
428
                    gray = qGray(m_matrix->endColor().rgb());
×
429
                    m_matrix->setEndColor(QColor(gray, gray, gray));
×
430

431
                    if (m_matrix->endColor() == QColor())
×
432
                        pm.fill(Qt::transparent);
×
433
                    else
434
                        pm.fill(QColor(gray, gray, gray));
×
435

436
                    m_endColorButton->setIcon(QIcon(pm));
×
437
                }
438
                m_previewHandler->calculateColorDelta(m_matrix->startColor(), m_matrix->endColor());
×
439
            }
440
            else 
441
            {
442
                QPixmap pm(50, 26);
×
443
                pm.fill(m_matrix->startColor());
×
444
                m_startColorButton->setIcon(QIcon(pm));
×
445

446
                if (accColors > 1)
×
447
                {
448
                    m_previewHandler->calculateColorDelta(m_matrix->startColor(), m_matrix->endColor());
×
449

450
                    if (m_matrix->endColor() == QColor())
×
451
                        pm.fill(Qt::transparent);
×
452
                    else
453
                        pm.fill(m_matrix->endColor());
×
454

455
                    m_endColorButton->setIcon(QIcon(pm));
×
456
                }
457
            }
458
        }
459
    }
460
}
×
461

462
/**
463
 * Helper function. Deletes all child widgets of the given layout @a item.
464
 */
465
void RGBMatrixEditor::resetProperties(QLayoutItem *item)
×
466
{
467
    if (item->layout()) 
×
468
    {
469
        // Process all child items recursively.
470
        for (int i = item->layout()->count() - 1; i >= 0; i--)
×
471
            resetProperties(item->layout()->itemAt(i));
×
472
    }
473
    delete item->widget();
×
474
}
×
475

476
void RGBMatrixEditor::displayProperties(RGBScript *script)
×
477
{
478
    if (script == NULL)
×
479
        return;
×
480

481
    int gridRowIdx = 0;
×
482

483
    QList<RGBScriptProperty> properties = script->properties();
×
484
    if (properties.count() > 0)
×
485
        m_propertiesGroup->show();
×
486

487
    foreach (RGBScriptProperty prop, properties)
×
488
    {
489
        switch(prop.m_type)
×
490
        {
491
            case RGBScriptProperty::List:
×
492
            {
493
                QLabel *propLabel = new QLabel(prop.m_displayName);
×
494
                m_propertiesLayout->addWidget(propLabel, gridRowIdx, 0);
×
495
                QComboBox *propCombo = new QComboBox(this);
×
496
                propCombo->addItems(prop.m_listValues);
×
497
                propCombo->setProperty("pName", prop.m_name);
×
498
                connect(propCombo, SIGNAL(currentIndexChanged(QString)),
×
499
                        this, SLOT(slotPropertyComboChanged(QString)));
500
                m_propertiesLayout->addWidget(propCombo, gridRowIdx, 1);
×
501
                if (m_matrix != NULL)
×
502
                {
503
                    QString pValue = m_matrix->property(prop.m_name);
×
504
                    if (!pValue.isEmpty())
×
505
                    {
506
                        propCombo->setCurrentText(pValue);
×
507
                    }
508
                    else
509
                    {
510
                        pValue = script->property(prop.m_name);
×
511
                        if (!pValue.isEmpty())
×
512
                            propCombo->setCurrentText(pValue);
×
513
                    }
514
                }
515
                gridRowIdx++;
×
516
            }
517
            break;
×
518
            case RGBScriptProperty::Range:
×
519
            {
520
                QLabel *propLabel = new QLabel(prop.m_displayName);
×
521
                m_propertiesLayout->addWidget(propLabel, gridRowIdx, 0);
×
522
                QSpinBox *propSpin = new QSpinBox(this);
×
523
                propSpin->setRange(prop.m_rangeMinValue, prop.m_rangeMaxValue);
×
524
                propSpin->setProperty("pName", prop.m_name);
×
525
                connect(propSpin, SIGNAL(valueChanged(int)),
×
526
                        this, SLOT(slotPropertySpinChanged(int)));
527
                m_propertiesLayout->addWidget(propSpin, gridRowIdx, 1);
×
528
                if (m_matrix != NULL)
×
529
                {
530
                    QString pValue = m_matrix->property(prop.m_name);
×
531
                    if (!pValue.isEmpty())
×
532
                        propSpin->setValue(pValue.toInt());
×
533
                    else
534
                    {
535
                        pValue = script->property(prop.m_name);
×
536
                        if (!pValue.isEmpty())
×
537
                            propSpin->setValue(pValue.toInt());
×
538
                    }
539
                }
540
                gridRowIdx++;
×
541
            }
542
            break;
×
543
            case RGBScriptProperty::Float:
×
544
            {
545
                QLabel *propLabel = new QLabel(prop.m_displayName);
×
546
                m_propertiesLayout->addWidget(propLabel, gridRowIdx, 0);
×
547
                QDoubleSpinBox *propSpin = new QDoubleSpinBox(this);
×
548
                propSpin->setDecimals(3);
×
549
                propSpin->setRange(-1000000, 1000000);
×
550
                propSpin->setProperty("pName", prop.m_name);
×
551
                connect(propSpin, SIGNAL(valueChanged(double)),
×
552
                        this, SLOT(slotPropertyDoubleSpinChanged(double)));
553
                m_propertiesLayout->addWidget(propSpin, gridRowIdx, 1);
×
554
                if (m_matrix != NULL)
×
555
                {
556
                    QString pValue = m_matrix->property(prop.m_name);
×
557
                    if (!pValue.isEmpty())
×
558
                        propSpin->setValue(pValue.toDouble());
×
559
                    else
560
                    {
561
                        pValue = script->property(prop.m_name);
×
562
                        if (!pValue.isEmpty())
×
563
                            propSpin->setValue(pValue.toDouble());
×
564
                    }
565
                }
566
                gridRowIdx++;
×
567
            }
568
            break;
×
569
            case RGBScriptProperty::String:
×
570
            {
571
                QLabel *propLabel = new QLabel(prop.m_displayName);
×
572
                m_propertiesLayout->addWidget(propLabel, gridRowIdx, 0);
×
573
                QLineEdit *propEdit = new QLineEdit(this);
×
574
                propEdit->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Preferred);
×
575
                propEdit->setProperty("pName", prop.m_name);
×
576
                connect(propEdit, SIGNAL(textEdited(QString)),
×
577
                        this, SLOT(slotPropertyEditChanged(QString)));
578
                m_propertiesLayout->addWidget(propEdit, gridRowIdx, 1);
×
579
                if (m_matrix != NULL)
×
580
                {
581
                    QString pValue = m_matrix->property(prop.m_name);
×
582
                    if (!pValue.isEmpty())
×
583
                        propEdit->setText(pValue);
×
584
                    else
585
                    {
586
                        pValue = script->property(prop.m_name);
×
587
                        if (!pValue.isEmpty())
×
588
                            propEdit->setText(pValue);
×
589
                    }
590
                }
591
                gridRowIdx++;
×
592
            }
593
            break;
×
594
            default:
×
595
                qWarning() << "Type" << prop.m_type << "not handled yet";
×
596
            break;
×
597
        }
598
    }
599
}
600

601
bool RGBMatrixEditor::createPreviewItems()
×
602
{
603
    m_previewHash.clear();
×
604
    m_scene->clear();
×
605

606
    FixtureGroup* grp = m_doc->fixtureGroup(m_matrix->fixtureGroup());
×
607
    if (grp == NULL)
×
608
    {
609
        QGraphicsTextItem* text = new QGraphicsTextItem(tr("No fixture group to control"));
×
610
        text->setDefaultTextColor(Qt::white);
×
611
        m_scene->addItem(text);
×
612
        return false;
×
613
    }
614

615
    m_previewHandler->initializeDirection(m_matrix->direction(), m_matrix->startColor(),
×
616
                                          m_matrix->endColor(), m_matrix->stepsCount());
×
617

618
    m_matrix->previewMap(m_previewHandler->currentStepIndex(), m_previewHandler);
×
619

620
    if (m_previewHandler->m_map.isEmpty())
×
621
        return false;
×
622

623
    for (int x = 0; x < grp->size().width(); x++)
×
624
    {
625
        for (int y = 0; y < grp->size().height(); y++)
×
626
        {
627
            QLCPoint pt(x, y);
×
628

629
            if (grp->headsMap().contains(pt) == true)
×
630
            {
631
                RGBItem *item;
632
                if (m_shapeButton->isChecked() == false)
×
633
                {
634
                    QGraphicsEllipseItem* circleItem = new QGraphicsEllipseItem();
×
635
                    circleItem->setRect(
×
636
                            x * RECT_SIZE + RECT_PADDING + ITEM_PADDING,
×
637
                            y * RECT_SIZE + RECT_PADDING + ITEM_PADDING,
×
638
                            ITEM_SIZE - (2 * ITEM_PADDING),
639
                            ITEM_SIZE - (2 * ITEM_PADDING));
640
                    item = new RGBItem(circleItem);
×
641
                }
642
                else
643
                {
644
                    QGraphicsRectItem *rectItem = new QGraphicsRectItem();
×
645
                    rectItem->setRect(
×
646
                            x * RECT_SIZE + RECT_PADDING + ITEM_PADDING,
×
647
                            y * RECT_SIZE + RECT_PADDING + ITEM_PADDING,
×
648
                            ITEM_SIZE - (2 * ITEM_PADDING),
649
                            ITEM_SIZE - (2 * ITEM_PADDING));
650
                    item = new RGBItem(rectItem);
×
651
                }
652

653
                item->setColor(m_previewHandler->m_map[y][x]);
×
654
                item->draw(0, 0);
×
655
                m_scene->addItem(item->graphicsItem());
×
656
                m_previewHash[pt] = item;
×
657
            }
658
        }
659
    }
660
    return true;
×
661
}
662

663
void RGBMatrixEditor::slotPreviewTimeout()
×
664
{
665
    if (m_matrix->duration() <= 0)
×
666
        return;
×
667

668
    m_previewIterator += MasterTimer::tick();
×
669
    uint elapsed = 0;
×
670
    while (m_previewIterator >= MAX(m_matrix->duration(), MasterTimer::tick()))
×
671
    {
672
        m_previewHandler->checkNextStep(m_matrix->runOrder(), m_matrix->startColor(),
×
673
                                        m_matrix->endColor(), m_matrix->stepsCount());
×
674

675
        m_matrix->previewMap(m_previewHandler->currentStepIndex(), m_previewHandler);
×
676

677
        m_previewIterator -= MAX(m_matrix->duration(), MasterTimer::tick());
×
678
        elapsed += MAX(m_matrix->duration(), MasterTimer::tick());
×
679
    }
680
    for (int y = 0; y < m_previewHandler->m_map.size(); y++)
×
681
    {
682
        for (int x = 0; x < m_previewHandler->m_map[y].size(); x++)
×
683
        {
684
            QLCPoint pt(x, y);
×
685
            if (m_previewHash.contains(pt) == true)
×
686
            {
687
                RGBItem* shape = m_previewHash[pt];
×
688
                if (shape->color() != QColor(m_previewHandler->m_map[y][x]).rgb())
×
689
                    shape->setColor(m_previewHandler->m_map[y][x]);
×
690

691
                if (shape->color() == QColor(Qt::black).rgb())
×
692
                    shape->draw(elapsed, m_matrix->fadeOutSpeed());
×
693
                else
694
                    shape->draw(elapsed, m_matrix->fadeInSpeed());
×
695
            }
696
        }
697
    }
698
}
699

700
void RGBMatrixEditor::slotNameEdited(const QString& text)
×
701
{
702
    m_matrix->setName(text);
×
703
    if (m_speedDials != NULL)
×
704
        m_speedDials->setWindowTitle(text);
×
705
}
×
706

707
void RGBMatrixEditor::slotSpeedDialToggle(bool state)
×
708
{
709
    if (state == true)
×
710
        updateSpeedDials();
×
711
    else
712
    {
713
        if (m_speedDials != NULL)
×
714
            m_speedDials->deleteLater();
×
715
        m_speedDials = NULL;
×
716
    }
717
}
×
718

719
void RGBMatrixEditor::slotDialDestroyed(QObject *)
×
720
{
721
    m_speedDialButton->setChecked(false);
×
722
}
×
723

NEW
724
void RGBMatrixEditor::slotPatternActivated(int patternIndex)
×
725
{
NEW
726
    QString algoName = m_patternCombo->itemText(patternIndex);
×
NEW
727
    RGBAlgorithm *algo = RGBAlgorithm::algorithm(m_doc, algoName);
×
728
    if (algo != NULL)
×
729
        algo->setColors(m_matrix->startColor(), m_matrix->endColor());
×
730
    m_matrix->setAlgorithm(algo);
×
731
    m_previewHandler->calculateColorDelta(m_matrix->startColor(), m_matrix->endColor());
×
732
    updateExtraOptions();
×
733

734
    slotRestartTest();
×
735
}
×
736

737
void RGBMatrixEditor::slotFixtureGroupActivated(int index)
×
738
{
739
    QVariant var = m_fixtureGroupCombo->itemData(index);
×
740
    if (var.isValid() == true)
×
741
    {
742
        m_matrix->setFixtureGroup(var.toUInt());
×
743
        slotRestartTest();
×
744
    }
745
    else
746
    {
747
        m_matrix->setFixtureGroup(FixtureGroup::invalidId());
×
748
        m_previewTimer->stop();
×
749
        m_scene->clear();
×
750
    }
751
}
×
752

753
void RGBMatrixEditor::slotBlendModeChanged(int index)
×
754
{
755
    m_matrix->setBlendMode(Universe::BlendMode(index));
×
756

757
    if (index == Universe::MaskBlend)
×
758
    {
759
        m_startColorButton->setEnabled(false);
×
760
    }
761
    else
762
    {
763
        m_startColorButton->setEnabled(true);
×
764
    }
765
    updateExtraOptions();
×
766
    updateColors();
×
767
    slotRestartTest();
×
768
}
×
769

770
void RGBMatrixEditor::slotControlModeChanged(int index)
×
771
{
772
    RGBMatrix::ControlMode mode = RGBMatrix::ControlMode(index);
×
773
    m_matrix->setControlMode(mode);
×
774
    updateColors();
×
775
    slotRestartTest();
×
776
}
×
777

778
void RGBMatrixEditor::slotStartColorButtonClicked()
×
779
{
780
    QColor col = QColorDialog::getColor(m_matrix->startColor());
×
781
    if (col.isValid() == true)
×
782
    {
783
        m_matrix->setStartColor(col);
×
784
        updateColors();
×
785
        slotRestartTest();
×
786
    }
787
}
×
788

789
void RGBMatrixEditor::slotEndColorButtonClicked()
×
790
{
791
    QColor col = QColorDialog::getColor(m_matrix->endColor());
×
792
    if (col.isValid() == true)
×
793
    {
794
        m_matrix->setEndColor(col);
×
795
        updateColors();
×
796
        slotRestartTest();
×
797
    }
798
}
×
799

800
void RGBMatrixEditor::slotResetEndColorButtonClicked()
×
801
{
802
    m_matrix->setEndColor(QColor());
×
803
    m_previewHandler->calculateColorDelta(m_matrix->startColor(), m_matrix->endColor());
×
804
    updateColors();
×
805
    slotRestartTest();
×
806
}
×
807

808
void RGBMatrixEditor::slotTextEdited(const QString& text)
×
809
{
810
    if (m_matrix->algorithm() != NULL && m_matrix->algorithm()->type() == RGBAlgorithm::Text)
×
811
    {
NEW
812
        RGBText *algo = static_cast<RGBText*> (m_matrix->algorithm());
×
813
        Q_ASSERT(algo != NULL);
×
814
        {
815
            QMutexLocker algorithmLocker(&m_matrix->algorithmMutex());
×
816
            algo->setText(text);
×
817
        }
818
        slotRestartTest();
×
819
    }
820
}
×
821

822
void RGBMatrixEditor::slotFontButtonClicked()
×
823
{
824
    if (m_matrix->algorithm() != NULL && m_matrix->algorithm()->type() == RGBAlgorithm::Text)
×
825
    {
NEW
826
        RGBText *algo = static_cast<RGBText*> (m_matrix->algorithm());
×
827
        Q_ASSERT(algo != NULL);
×
828

829
        bool ok = false;
×
830
        QFont font = QFontDialog::getFont(&ok, algo->font(), this);
×
831
        if (ok == true)
×
832
        {
833
            {
834
                QMutexLocker algorithmLocker(&m_matrix->algorithmMutex());
×
835
                algo->setFont(font);
×
836
            }
837
            slotRestartTest();
×
838
        }
839
    }
840
}
×
841

NEW
842
void RGBMatrixEditor::slotAnimationActivated(int index)
×
843
{
844
    if (m_matrix->algorithm() != NULL && m_matrix->algorithm()->type() == RGBAlgorithm::Text)
×
845
    {
NEW
846
        RGBText *algo = static_cast<RGBText*> (m_matrix->algorithm());
×
847
        Q_ASSERT(algo != NULL);
×
848
        {
849
            QMutexLocker algorithmLocker(&m_matrix->algorithmMutex());
×
NEW
850
            QString text = m_animationCombo->itemText(index);
×
UNCOV
851
            algo->setAnimationStyle(RGBText::stringToAnimationStyle(text));
×
852
        }
853
        slotRestartTest();
×
854
    }
855
}
×
856

857
void RGBMatrixEditor::slotImageEdited()
×
858
{
859
    if (m_matrix->algorithm() != NULL && m_matrix->algorithm()->type() == RGBAlgorithm::Image)
×
860
    {
NEW
861
        RGBImage *algo = static_cast<RGBImage*> (m_matrix->algorithm());
×
862
        Q_ASSERT(algo != NULL);
×
863
        {
864
            QMutexLocker algorithmLocker(&m_matrix->algorithmMutex());
×
865
            algo->setFilename(m_imageEdit->text());
×
866
        }
867
        slotRestartTest();
×
868
    }
869
}
×
870

871
void RGBMatrixEditor::slotImageButtonClicked()
×
872
{
873
    if (m_matrix->algorithm() != NULL && m_matrix->algorithm()->type() == RGBAlgorithm::Image)
×
874
    {
NEW
875
        RGBImage *algo = static_cast<RGBImage*> (m_matrix->algorithm());
×
876
        Q_ASSERT(algo != NULL);
×
877

878
        QString path = algo->filename();
×
879
        path = QFileDialog::getOpenFileName(this,
×
880
                                            tr("Select image"),
×
881
                                            path,
882
                                            QString("%1 (*.png *.bmp *.jpg *.jpeg *.gif)").arg(tr("Images")));
×
883
        if (path.isEmpty() == false)
×
884
        {
885
            {
886
                QMutexLocker algorithmLocker(&m_matrix->algorithmMutex());
×
887
                algo->setFilename(path);
×
888
            }
889
            m_imageEdit->setText(path);
×
890
            slotRestartTest();
×
891
        }
892
    }
893
}
×
894

NEW
895
void RGBMatrixEditor::slotImageAnimationActivated(int index)
×
896
{
897
    if (m_matrix->algorithm() != NULL && m_matrix->algorithm()->type() == RGBAlgorithm::Image)
×
898
    {
NEW
899
        RGBImage *algo = static_cast<RGBImage*> (m_matrix->algorithm());
×
900
        Q_ASSERT(algo != NULL);
×
901
        {
902
            QMutexLocker algorithmLocker(&m_matrix->algorithmMutex());
×
NEW
903
            QString text = m_imageAnimationCombo->itemText(index);
×
UNCOV
904
            algo->setAnimationStyle(RGBImage::stringToAnimationStyle(text));
×
905
        }
906
        slotRestartTest();
×
907
    }
908
}
×
909

910
void RGBMatrixEditor::slotOffsetSpinChanged()
×
911
{
912
    if (m_matrix->algorithm() != NULL && m_matrix->algorithm()->type() == RGBAlgorithm::Text)
×
913
    {
NEW
914
        RGBText *algo = static_cast<RGBText*> (m_matrix->algorithm());
×
915
        Q_ASSERT(algo != NULL);
×
916
        {
917
            QMutexLocker algorithmLocker(&m_matrix->algorithmMutex());
×
918
            algo->setXOffset(m_xOffsetSpin->value());
×
919
            algo->setYOffset(m_yOffsetSpin->value());
×
920
        }
921
        slotRestartTest();
×
922
    }
923

924
    if (m_matrix->algorithm() != NULL && m_matrix->algorithm()->type() == RGBAlgorithm::Image)
×
925
    {
NEW
926
        RGBImage *algo = static_cast<RGBImage*> (m_matrix->algorithm());
×
927
        Q_ASSERT(algo != NULL);
×
928
        {
929
            QMutexLocker algorithmLocker(&m_matrix->algorithmMutex());
×
930
            algo->setXOffset(m_xOffsetSpin->value());
×
931
            algo->setYOffset(m_yOffsetSpin->value());
×
932
        }
933
        slotRestartTest();
×
934
    }
935
}
×
936

937
void RGBMatrixEditor::slotLoopClicked()
×
938
{
939
    m_matrix->setRunOrder(Function::Loop);
×
940
    m_previewHandler->calculateColorDelta(m_matrix->startColor(), m_matrix->endColor());
×
941
    slotRestartTest();
×
942
}
×
943

944
void RGBMatrixEditor::slotPingPongClicked()
×
945
{
946
    m_matrix->setRunOrder(Function::PingPong);
×
947
    m_previewHandler->calculateColorDelta(m_matrix->startColor(), m_matrix->endColor());
×
948
    slotRestartTest();
×
949
}
×
950

951
void RGBMatrixEditor::slotSingleShotClicked()
×
952
{
953
    m_matrix->setRunOrder(Function::SingleShot);
×
954
    m_previewHandler->calculateColorDelta(m_matrix->startColor(), m_matrix->endColor());
×
955
    slotRestartTest();
×
956
}
×
957

958
void RGBMatrixEditor::slotForwardClicked()
×
959
{
960
    m_matrix->setDirection(Function::Forward);
×
961
    m_previewHandler->calculateColorDelta(m_matrix->startColor(), m_matrix->endColor());
×
962
    slotRestartTest();
×
963
}
×
964

965
void RGBMatrixEditor::slotBackwardClicked()
×
966
{
967
    m_matrix->setDirection(Function::Backward);
×
968
    m_previewHandler->calculateColorDelta(m_matrix->startColor(), m_matrix->endColor());
×
969
    slotRestartTest();
×
970
}
×
971

972
void RGBMatrixEditor::slotDimmerControlClicked()
×
973
{
974
    m_matrix->setDimmerControl(m_dimmerControlCb->isChecked());
×
975
    if (m_dimmerControlCb->isChecked() == false)
×
976
        m_dimmerControlCb->setEnabled(false);
×
977
}
×
978

979
void RGBMatrixEditor::slotFadeInChanged(int ms)
×
980
{
981
    m_matrix->setFadeInSpeed(ms);
×
982
    uint duration = Function::speedAdd(ms, m_speedDials->duration());
×
983
    m_matrix->setDuration(duration);
×
984
}
×
985

986
void RGBMatrixEditor::slotFadeOutChanged(int ms)
×
987
{
988
    m_matrix->setFadeOutSpeed(ms);
×
989
}
×
990

991
void RGBMatrixEditor::slotHoldChanged(int ms)
×
992
{
993
    uint duration = Function::speedAdd(m_matrix->fadeInSpeed(), ms);
×
994
    m_matrix->setDuration(duration);
×
995
}
×
996

997
void RGBMatrixEditor::slotDurationTapped()
×
998
{
999
    m_matrix->tap();
×
1000
}
×
1001

1002
void RGBMatrixEditor::slotTestClicked()
×
1003
{
1004
    if (m_testButton->isChecked() == true)
×
1005
        m_matrix->start(m_doc->masterTimer(), functionParent());
×
1006
    else
1007
        m_matrix->stopAndWait();
×
1008
}
×
1009

1010
void RGBMatrixEditor::slotRestartTest()
×
1011
{
1012
    m_previewTimer->stop();
×
1013

1014
    if (m_testButton->isChecked() == true)
×
1015
    {
1016
        // Toggle off, toggle on. Duh.
1017
        m_testButton->click();
×
1018
        m_testButton->click();
×
1019
    }
1020

1021
    if (createPreviewItems() == true)
×
1022
        m_previewTimer->start(MasterTimer::tick());
×
1023

1024
}
×
1025

1026
void RGBMatrixEditor::slotModeChanged(Doc::Mode mode)
×
1027
{
1028
    if (mode == Doc::Operate)
×
1029
    {
1030
        if (m_testButton->isChecked() == true)
×
1031
            m_matrix->stopAndWait();
×
1032
        m_testButton->setChecked(false);
×
1033
        m_testButton->setEnabled(false);
×
1034
    }
1035
    else
1036
    {
1037
        m_testButton->setEnabled(true);
×
1038
    }
1039
}
×
1040

1041
void RGBMatrixEditor::slotFixtureGroupAdded()
×
1042
{
1043
    fillFixtureGroupCombo();
×
1044
}
×
1045

1046
void RGBMatrixEditor::slotFixtureGroupRemoved()
×
1047
{
1048
    fillFixtureGroupCombo();
×
1049
    slotFixtureGroupActivated(m_fixtureGroupCombo->currentIndex());
×
1050
}
×
1051

1052
void RGBMatrixEditor::slotFixtureGroupChanged(quint32 id)
×
1053
{
1054
    if (id == m_matrix->fixtureGroup())
×
1055
    {
1056
        // Update the whole chain -> maybe the fixture layout has changed
1057
        fillFixtureGroupCombo();
×
1058
        slotFixtureGroupActivated(m_fixtureGroupCombo->currentIndex());
×
1059
    }
1060
    else
1061
    {
1062
        // Just change the name of the group, nothing else is interesting at this point
1063
        int index = m_fixtureGroupCombo->findData(id);
×
1064
        if (index != -1)
×
1065
        {
1066
            FixtureGroup* grp = m_doc->fixtureGroup(id);
×
1067
            m_fixtureGroupCombo->setItemText(index, grp->name());
×
1068
        }
1069
    }
1070
}
×
1071

1072
void RGBMatrixEditor::slotSaveToSequenceClicked()
×
1073
{
1074
    if (m_matrix == NULL || m_matrix->fixtureGroup() == FixtureGroup::invalidId())
×
1075
        return;
×
1076

1077
    FixtureGroup* grp = m_doc->fixtureGroup(m_matrix->fixtureGroup());
×
1078
    if (grp != NULL && m_matrix->algorithm() != NULL)
×
1079
    {
1080
        bool testRunning = false;
×
1081

1082
        if (m_testButton->isChecked() == true)
×
1083
        {
1084
            m_testButton->click();
×
1085
            testRunning = true;
×
1086
        }
1087
        else
1088
            m_previewTimer->stop();
×
1089

1090
        Scene *grpScene = new Scene(m_doc);
×
1091
        grpScene->setName(grp->name());
×
1092
        grpScene->setVisible(false);
×
1093

1094
        QList<GroupHead> headList = grp->headList();
×
1095
        foreach (GroupHead head, headList)
×
1096
        {
1097
            Fixture *fxi = m_doc->fixture(head.fxi);
×
1098
            if (fxi == NULL)
×
1099
                continue;
×
1100

1101
            if (m_controlModeCombo->currentIndex() == RGBMatrix::ControlModeRgb)
×
1102
            {
1103

1104
                    QVector <quint32> rgb = fxi->rgbChannels(head.head);
×
1105

1106
                    // in case of CMY, dump those channels
1107
                    if (rgb.count() == 0)
×
1108
                        rgb = fxi->cmyChannels(head.head);
×
1109

1110
                    if (rgb.count() == 3)
×
1111
                    {
1112
                        grpScene->setValue(head.fxi, rgb.at(0), 0);
×
1113
                        grpScene->setValue(head.fxi, rgb.at(1), 0);
×
1114
                        grpScene->setValue(head.fxi, rgb.at(2), 0);
×
1115
                    }
1116
            }
1117
            else if (m_controlModeCombo->currentIndex() == RGBMatrix::ControlModeDimmer)
×
1118
            {
1119
                quint32 channel = fxi->masterIntensityChannel();
×
1120

1121
                if (channel == QLCChannel::invalid())
×
1122
                    channel = fxi->channelNumber(QLCChannel::Intensity, QLCChannel::MSB, head.head);
×
1123

1124
                if (channel != QLCChannel::invalid())
×
1125
                    grpScene->setValue(head.fxi, channel, 0);
×
1126
            }
1127
            else
1128
            {
1129
                quint32 channel = QLCChannel::invalid();
×
1130
                if (m_controlModeCombo->currentIndex() == RGBMatrix::ControlModeWhite)
×
1131
                    channel = fxi->channelNumber(QLCChannel::White, QLCChannel::MSB, head.head);
×
1132
                else if (m_controlModeCombo->currentIndex() == RGBMatrix::ControlModeAmber)
×
1133
                    channel = fxi->channelNumber(QLCChannel::Amber, QLCChannel::MSB, head.head);
×
1134
                else if (m_controlModeCombo->currentIndex() == RGBMatrix::ControlModeUV)
×
1135
                    channel = fxi->channelNumber(QLCChannel::UV, QLCChannel::MSB, head.head);
×
1136
                else if (m_controlModeCombo->currentIndex() == RGBMatrix::ControlModeShutter)
×
1137
                {
1138
                    QLCFixtureHead fHead = fxi->head(head.head);
×
1139
                    QVector <quint32> shutters = fHead.shutterChannels();
×
1140
                    if (shutters.count())
×
1141
                        channel = shutters.first();
×
1142
                }
1143

1144
                if (channel != QLCChannel::invalid())
×
1145
                    grpScene->setValue(head.fxi, channel, 0);
×
1146
            }
1147
        }
1148
        m_doc->addFunction(grpScene);
×
1149

1150
        int totalSteps = m_matrix->stepsCount();
×
1151
        int increment = 1;
×
1152
        int currentStep = 0;
×
1153
        m_previewHandler->setStepColor(m_matrix->startColor());
×
1154

1155
        if (m_matrix->direction() == Function::Backward)
×
1156
        {
1157
            currentStep = totalSteps - 1;
×
1158
            increment = -1;
×
1159
            if (m_matrix->endColor().isValid())
×
1160
                m_previewHandler->setStepColor(m_matrix->endColor());
×
1161
        }
1162
        m_previewHandler->calculateColorDelta(m_matrix->startColor(), m_matrix->endColor());
×
1163

1164
        if (m_matrix->runOrder() == RGBMatrix::PingPong)
×
1165
            totalSteps = (totalSteps * 2) - 1;
×
1166

1167
        Sequence *sequence = new Sequence(m_doc);
×
1168
        sequence->setName(QString("%1 %2").arg(m_matrix->name()).arg(tr("Sequence")));
×
1169
        sequence->setBoundSceneID(grpScene->id());
×
1170
        sequence->setDurationMode(Chaser::PerStep);
×
1171
        sequence->setDuration(m_matrix->duration());
×
1172

1173
        if (m_matrix->fadeInSpeed() != 0)
×
1174
        {
1175
            sequence->setFadeInMode(Chaser::PerStep);
×
1176
            sequence->setFadeInSpeed(m_matrix->fadeInSpeed());
×
1177
        }
1178
        if (m_matrix->fadeOutSpeed() != 0)
×
1179
        {
1180
            sequence->setFadeOutMode(Chaser::PerStep);
×
1181
            sequence->setFadeOutSpeed(m_matrix->fadeOutSpeed());
×
1182
        }
1183

1184
        for (int i = 0; i < totalSteps; i++)
×
1185
        {
1186
            m_matrix->previewMap(currentStep, m_previewHandler);
×
1187
            ChaserStep step;
×
1188
            step.fid = grpScene->id();
×
1189
            step.hold = m_matrix->duration() - m_matrix->fadeInSpeed();
×
1190
            step.duration = m_matrix->duration();
×
1191
            step.fadeIn = m_matrix->fadeInSpeed();
×
1192
            step.fadeOut = m_matrix->fadeOutSpeed();
×
1193

1194
            for (int y = 0; y < m_previewHandler->m_map.size(); y++)
×
1195
            {
1196
                for (int x = 0; x < m_previewHandler->m_map[y].size(); x++)
×
1197
                {
1198
                    uint col = m_previewHandler->m_map[y][x];
×
1199
                    GroupHead head = grp->head(QLCPoint(x, y));
×
1200

1201
                    Fixture *fxi = m_doc->fixture(head.fxi);
×
1202
                    if (fxi == NULL)
×
1203
                        continue;
×
1204

1205
                    if (m_controlModeCombo->currentIndex() == RGBMatrix::ControlModeRgb)
×
1206
                    {
1207
                        QVector <quint32> rgb = fxi->rgbChannels(head.head);
×
1208
                        QVector <quint32> cmy = fxi->cmyChannels(head.head);
×
1209

1210
                        if (rgb.count() == 3)
×
1211
                        {
1212
                            step.values.append(SceneValue(head.fxi, rgb.at(0), qRed(col)));
×
1213
                            step.values.append(SceneValue(head.fxi, rgb.at(1), qGreen(col)));
×
1214
                            step.values.append(SceneValue(head.fxi, rgb.at(2), qBlue(col)));
×
1215
                        }
1216

1217
                        if (cmy.count() == 3)
×
1218
                        {
1219
                            QColor cmyCol(col);
×
1220

1221
                            step.values.append(SceneValue(head.fxi, cmy.at(0), cmyCol.cyan()));
×
1222
                            step.values.append(SceneValue(head.fxi, cmy.at(1), cmyCol.magenta()));
×
1223
                            step.values.append(SceneValue(head.fxi, cmy.at(2), cmyCol.yellow()));
×
1224
                        }
1225
                    }
1226
                    else if (m_controlModeCombo->currentIndex() == RGBMatrix::ControlModeDimmer)
×
1227
                    {
1228
                        quint32 channel = fxi->masterIntensityChannel();
×
1229

1230
                        if (channel == QLCChannel::invalid())
×
1231
                            channel = fxi->channelNumber(QLCChannel::Intensity, QLCChannel::MSB, head.head);
×
1232

1233
                        if (channel != QLCChannel::invalid())
×
1234
                            step.values.append(SceneValue(head.fxi, channel, RGBMatrix::rgbToGrey(col)));
×
1235
                    }
1236
                    else
1237
                    {
1238
                        quint32 channel = QLCChannel::invalid();
×
1239
                        if (m_controlModeCombo->currentIndex() == RGBMatrix::ControlModeWhite)
×
1240
                            channel = fxi->channelNumber(QLCChannel::White, QLCChannel::MSB, head.head);
×
1241
                        else if (m_controlModeCombo->currentIndex() == RGBMatrix::ControlModeAmber)
×
1242
                            channel = fxi->channelNumber(QLCChannel::Amber, QLCChannel::MSB, head.head);
×
1243
                        else if (m_controlModeCombo->currentIndex() == RGBMatrix::ControlModeUV)
×
1244
                            channel = fxi->channelNumber(QLCChannel::UV, QLCChannel::MSB, head.head);
×
1245
                        else if (m_controlModeCombo->currentIndex() == RGBMatrix::ControlModeShutter)
×
1246
                        {
1247
                            QLCFixtureHead fHead = fxi->head(head.head);
×
1248
                            QVector <quint32> shutters = fHead.shutterChannels();
×
1249
                            if (shutters.count())
×
1250
                                channel = shutters.first();
×
1251
                        }
1252

1253
                        if (channel != QLCChannel::invalid())
×
1254
                            step.values.append(SceneValue(head.fxi, channel, RGBMatrix::rgbToGrey(col)));
×
1255
                    }
1256
                }
1257
            }
1258
            // !! Important !! matrix's heads can be displaced randomly but in a sequence
1259
            // we absolutely need ordered values. So do it now !
1260
            std::sort(step.values.begin(), step.values.end());
×
1261

1262
            sequence->addStep(step);
×
1263
            currentStep += increment;
×
1264
            if (currentStep == totalSteps && m_matrix->runOrder() == RGBMatrix::PingPong)
×
1265
            {
1266
                currentStep = totalSteps - 2;
×
1267
                increment = -1;
×
1268
            }
1269
            m_previewHandler->updateStepColor(currentStep, m_matrix->startColor(), m_matrix->stepsCount());
×
1270
        }
1271

1272
        m_doc->addFunction(sequence);
×
1273

1274
        if (testRunning == true)
×
1275
            m_testButton->click();
×
1276
        else if (createPreviewItems() == true)
×
1277
            m_previewTimer->start(MasterTimer::tick());
×
1278
    }
1279
}
1280

1281
void RGBMatrixEditor::slotShapeToggle(bool)
×
1282
{
1283
    createPreviewItems();
×
1284
}
×
1285

1286
void RGBMatrixEditor::slotPropertyComboChanged(QString value)
×
1287
{
1288
    qDebug() << "Property combo changed to" << value;
×
1289
    if (m_matrix->algorithm() == NULL ||
×
1290
        m_matrix->algorithm()->type() == RGBAlgorithm::Script)
×
1291
    {
1292
        QComboBox *combo = qobject_cast<QComboBox *>(sender());
×
1293
        QString pName = combo->property("pName").toString();
×
1294
        m_matrix->setProperty(pName, value);
×
1295
    }
1296
}
×
1297

1298
void RGBMatrixEditor::slotPropertySpinChanged(int value)
×
1299
{
1300
    qDebug() << "Property spin changed to" << value;
×
1301
    if (m_matrix->algorithm() == NULL ||
×
1302
        m_matrix->algorithm()->type() == RGBAlgorithm::Script)
×
1303
    {
1304
        QSpinBox *spin = qobject_cast<QSpinBox *>(sender());
×
1305
        QString pName = spin->property("pName").toString();
×
1306
        m_matrix->setProperty(pName, QString::number(value));
×
1307
    }
1308
}
×
1309

1310
void RGBMatrixEditor::slotPropertyDoubleSpinChanged(double value)
×
1311
{
1312
    qDebug() << "Property float changed to" << value;
×
1313
    if (m_matrix->algorithm() == NULL ||
×
1314
        m_matrix->algorithm()->type() == RGBAlgorithm::Script)
×
1315
    {
1316
        QDoubleSpinBox *spin = qobject_cast<QDoubleSpinBox *>(sender());
×
1317
        QString pName = spin->property("pName").toString();
×
1318
        m_matrix->setProperty(pName, QString::number(value));
×
1319
    }
1320
}
×
1321

1322
void RGBMatrixEditor::slotPropertyEditChanged(QString text)
×
1323
{
1324
    qDebug() << "Property string changed to" << text;
×
1325
    if (m_matrix->algorithm() == NULL ||
×
1326
        m_matrix->algorithm()->type() == RGBAlgorithm::Script)
×
1327
    {
1328
        QLineEdit *edit = qobject_cast<QLineEdit *>(sender());
×
1329
        QString pName = edit->property("pName").toString();
×
1330
        m_matrix->setProperty(pName, text);
×
1331
    }
1332
}
×
1333

1334
FunctionParent RGBMatrixEditor::functionParent() const
×
1335
{
1336
    return FunctionParent::master();
×
1337
}
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