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

mcallegari / qlcplus / 8961243534

05 May 2024 09:23PM UTC coverage: 32.068% (+4.0%) from 28.094%
8961243534

push

github

mcallegari
Merge branch 'master' into qmltoqt6

902 of 2557 new or added lines in 140 files covered. (35.28%)

166 existing lines in 76 files now uncovered.

15395 of 48008 relevant lines covered (32.07%)

22949.67 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)));
197
    connect(m_patternCombo, SIGNAL(activated(const QString&)),
×
198
            this, SLOT(slotPatternActivated(const QString&)));
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()));
215
    connect(m_animationCombo, SIGNAL(activated(const QString&)),
×
216
            this, SLOT(slotAnimationActivated(const QString&)));
217
    connect(m_imageEdit, SIGNAL(editingFinished()),
×
218
            this, SLOT(slotImageEdited()));
219
    connect(m_imageButton, SIGNAL(clicked()),
×
220
            this, SLOT(slotImageButtonClicked()));
221
    connect(m_imageAnimationCombo, SIGNAL(activated(const QString&)),
×
222
            this, SLOT(slotImageAnimationActivated(const QString&)));
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
{
UNCOV
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

NEW
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

NEW
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

NEW
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())
×
UNCOV
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;
×
NEW
543
            case RGBScriptProperty::Float:
×
544
            {
NEW
545
                QLabel *propLabel = new QLabel(prop.m_displayName);
×
NEW
546
                m_propertiesLayout->addWidget(propLabel, gridRowIdx, 0);
×
NEW
547
                QDoubleSpinBox *propSpin = new QDoubleSpinBox(this);
×
NEW
548
                propSpin->setDecimals(3);
×
NEW
549
                propSpin->setRange(-1000000, 1000000);
×
NEW
550
                propSpin->setProperty("pName", prop.m_name);
×
NEW
551
                connect(propSpin, SIGNAL(valueChanged(double)),
×
552
                        this, SLOT(slotPropertyDoubleSpinChanged(double)));
NEW
553
                m_propertiesLayout->addWidget(propSpin, gridRowIdx, 1);
×
NEW
554
                if (m_matrix != NULL)
×
555
                {
NEW
556
                    QString pValue = m_matrix->property(prop.m_name);
×
NEW
557
                    if (!pValue.isEmpty())
×
NEW
558
                        propSpin->setValue(pValue.toDouble());
×
559
                    else
560
                    {
NEW
561
                        pValue = script->property(prop.m_name);
×
NEW
562
                        if (!pValue.isEmpty())
×
NEW
563
                            propSpin->setValue(pValue.toDouble());
×
564
                    }
565
                }
NEW
566
                gridRowIdx++;
×
567
            }
NEW
568
            break;
×
NEW
569
            case RGBScriptProperty::String:
×
570
            {
NEW
571
                QLabel *propLabel = new QLabel(prop.m_displayName);
×
NEW
572
                m_propertiesLayout->addWidget(propLabel, gridRowIdx, 0);
×
NEW
573
                QLineEdit *propEdit = new QLineEdit(this);
×
NEW
574
                propEdit->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Preferred);
×
NEW
575
                propEdit->setProperty("pName", prop.m_name);
×
NEW
576
                connect(propEdit, SIGNAL(textEdited(QString)),
×
577
                        this, SLOT(slotPropertyEditChanged(QString)));
NEW
578
                m_propertiesLayout->addWidget(propEdit, gridRowIdx, 1);
×
NEW
579
                if (m_matrix != NULL)
×
580
                {
NEW
581
                    QString pValue = m_matrix->property(prop.m_name);
×
NEW
582
                    if (!pValue.isEmpty())
×
NEW
583
                        propEdit->setText(pValue);
×
584
                    else
585
                    {
NEW
586
                        pValue = script->property(prop.m_name);
×
NEW
587
                        if (!pValue.isEmpty())
×
NEW
588
                            propEdit->setText(pValue);
×
589
                    }
590
                }
NEW
591
                gridRowIdx++;
×
592
            }
NEW
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

724
void RGBMatrixEditor::slotPatternActivated(const QString& text)
×
725
{
726
    RGBAlgorithm* algo = RGBAlgorithm::algorithm(m_doc, text);
×
727
    if (algo != NULL)
×
728
        algo->setColors(m_matrix->startColor(), m_matrix->endColor());
×
729
    m_matrix->setAlgorithm(algo);
×
730
    m_previewHandler->calculateColorDelta(m_matrix->startColor(), m_matrix->endColor());
×
731
    updateExtraOptions();
×
732

733
    slotRestartTest();
×
734
}
×
735

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

983
void RGBMatrixEditor::slotFadeOutChanged(int ms)
×
984
{
985
    m_matrix->setFadeOutSpeed(ms);
×
986
}
×
987

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

994
void RGBMatrixEditor::slotDurationTapped()
×
995
{
996
    m_matrix->tap();
×
997
}
×
998

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

1007
void RGBMatrixEditor::slotRestartTest()
×
1008
{
1009
    m_previewTimer->stop();
×
1010

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

1018
    if (createPreviewItems() == true)
×
1019
        m_previewTimer->start(MasterTimer::tick());
×
1020

1021
}
×
1022

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

1038
void RGBMatrixEditor::slotFixtureGroupAdded()
×
1039
{
1040
    fillFixtureGroupCombo();
×
1041
}
×
1042

1043
void RGBMatrixEditor::slotFixtureGroupRemoved()
×
1044
{
1045
    fillFixtureGroupCombo();
×
1046
    slotFixtureGroupActivated(m_fixtureGroupCombo->currentIndex());
×
1047
}
×
1048

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

1069
void RGBMatrixEditor::slotSaveToSequenceClicked()
×
1070
{
1071
    if (m_matrix == NULL || m_matrix->fixtureGroup() == FixtureGroup::invalidId())
×
1072
        return;
×
1073

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

1079
        if (m_testButton->isChecked() == true)
×
1080
        {
1081
            m_testButton->click();
×
1082
            testRunning = true;
×
1083
        }
1084
        else
1085
            m_previewTimer->stop();
×
1086

1087
        Scene *grpScene = new Scene(m_doc);
×
1088
        grpScene->setName(grp->name());
×
1089
        grpScene->setVisible(false);
×
1090

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

1098
            if (m_controlModeCombo->currentIndex() == RGBMatrix::ControlModeRgb)
×
1099
            {
1100

1101
                    QVector <quint32> rgb = fxi->rgbChannels(head.head);
×
1102

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

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

1118
                if (channel == QLCChannel::invalid())
×
1119
                    channel = fxi->channelNumber(QLCChannel::Intensity, QLCChannel::MSB, head.head);
×
1120

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

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

1147
        int totalSteps = m_matrix->stepsCount();
×
1148
        int increment = 1;
×
1149
        int currentStep = 0;
×
1150
        m_previewHandler->setStepColor(m_matrix->startColor());
×
1151

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

1161
        if (m_matrix->runOrder() == RGBMatrix::PingPong)
×
1162
            totalSteps = (totalSteps * 2) - 1;
×
1163

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

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

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

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

1198
                    Fixture *fxi = m_doc->fixture(head.fxi);
×
1199
                    if (fxi == NULL)
×
1200
                        continue;
×
1201

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

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

1214
                        if (cmy.count() == 3)
×
1215
                        {
1216
                            QColor cmyCol(col);
×
1217

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

1227
                        if (channel == QLCChannel::invalid())
×
1228
                            channel = fxi->channelNumber(QLCChannel::Intensity, QLCChannel::MSB, head.head);
×
1229

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

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

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

1269
        m_doc->addFunction(sequence);
×
1270

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

NEW
1278
void RGBMatrixEditor::slotShapeToggle(bool)
×
1279
{
1280
    createPreviewItems();
×
1281
}
×
1282

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

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

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

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

UNCOV
1331
FunctionParent RGBMatrixEditor::functionParent() const
×
1332
{
1333
    return FunctionParent::master();
×
1334
}
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