• 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/virtualconsole/vcmatrixproperties.cpp
1
/*
2
  Q Light Controller Plus
3
  vcmatrixproperties.cpp
4

5
  Copyright (c) Massimo Callegari
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 <QColorDialog>
21
#include <QInputDialog>
22
#include <QTreeWidget>
23

24
#include "vcmatrixpresetselection.h"
25
#include "inputselectionwidget.h"
26
#include "vcmatrixproperties.h"
27
#include "selectinputchannel.h"
28
#include "functionselection.h"
29
#include "inputpatch.h"
30
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
31
 #include "rgbscript.h"
32
#else
33
 #include "rgbscriptv4.h"
34
#endif
35

36
VCMatrixProperties::VCMatrixProperties(VCMatrix* matrix, Doc* doc)
×
37
    : QDialog(matrix)
38
    , m_doc(doc)
×
39
{
40
    Q_ASSERT(matrix != NULL);
×
41
    Q_ASSERT(doc != NULL);
×
42

43
    setupUi(this);
×
44

45
    m_lastAssignedID = 0;
×
46

47
    /* Matrix text and function */
48
    m_matrix = matrix;
×
49
    m_nameEdit->setText(m_matrix->caption());
×
50
    slotSetFunction(m_matrix->function());
×
51

52
    if (m_matrix->instantChanges())
×
53
        m_instantCheck->setChecked(true);
×
54

55
    /* Matrix connections */
56
    connect(m_attachFunction, SIGNAL(clicked()), this, SLOT(slotAttachFunction()));
×
57
    connect(m_detachFunction, SIGNAL(clicked()), this, SLOT(slotSetFunction()));
×
58

59
    /* Slider external input */
60
    m_sliderInputSource = m_matrix->inputSource();
×
61
    updateSliderInputSource();
×
62

63
    connect(m_autoDetectInputButton, SIGNAL(toggled(bool)),
×
64
            this, SLOT(slotAutoDetectSliderInputToggled(bool)));
65
    connect(m_chooseInputButton, SIGNAL(clicked()),
×
66
            this, SLOT(slotChooseSliderInputClicked()));
67

68
    /* Visibility */
69
    quint32 visibilityMask = m_matrix->visibilityMask();
×
70
    if (visibilityMask & VCMatrix::ShowSlider) m_sliderCheck->setChecked(true);
×
71
    if (visibilityMask & VCMatrix::ShowLabel) m_labelCheck->setChecked(true);
×
72
    if (visibilityMask & VCMatrix::ShowStartColorButton) m_startColorButtonCheck->setChecked(true);
×
73
    if (visibilityMask & VCMatrix::ShowEndColorButton) m_endColorButtonCheck->setChecked(true);
×
74
    if (visibilityMask & VCMatrix::ShowPresetCombo) m_presetComboCheck->setChecked(true);
×
75

76
    /* Custom controls */
NEW
77
    foreach (const VCMatrixControl *control, m_matrix->customControls())
×
78
    {
79
        m_controls.append(new VCMatrixControl(*control));
×
80
        if (control->m_id > m_lastAssignedID)
×
81
            m_lastAssignedID = control->m_id;
×
82
    }
83

84
    m_controlsTree->setSelectionMode(QAbstractItemView::SingleSelection);
×
85

86
    updateTree();
×
87

88
    connect(m_controlsTree, SIGNAL(itemClicked(QTreeWidgetItem*,int)),
×
89
            this, SLOT(slotTreeSelectionChanged()));
90

91
    connect(m_addStartColorButton, SIGNAL(clicked()),
×
92
            this, SLOT(slotAddStartColorClicked()));
93
    connect(m_addStartColorKnobsButton, SIGNAL(clicked()),
×
94
            this, SLOT(slotAddStartColorKnobsClicked()));
95
    connect(m_addEndColorButton, SIGNAL(clicked()),
×
96
            this, SLOT(slotAddEndColorClicked()));
97
    connect(m_addEndColorKnobsButton, SIGNAL(clicked()),
×
98
            this, SLOT(slotAddEndColorKnobsClicked()));
99
    connect(m_addEndColorResetButton, SIGNAL(clicked()),
×
100
            this, SLOT(slotAddEndColorResetClicked()));
101
    connect(m_addPresetButton, SIGNAL(clicked()),
×
102
            this, SLOT(slotAddAnimationClicked()));
103
    connect(m_addTextButton, SIGNAL(clicked()),
×
104
            this, SLOT(slotAddTextClicked()));
105

106
    connect(m_removeButton, SIGNAL(clicked()),
×
107
            this, SLOT(slotRemoveClicked()));
108

109
    m_presetInputWidget = new InputSelectionWidget(m_doc, this);
×
110
    m_presetInputWidget->setCustomFeedbackVisibility(true);
×
111
    m_presetInputWidget->setWidgetPage(m_matrix->page());
×
112
    m_presetInputWidget->show();
×
113
    m_presetInputLayout->addWidget(m_presetInputWidget);
×
114

115
    connect(m_presetInputWidget, SIGNAL(inputValueChanged(quint32,quint32)),
×
116
            this, SLOT(slotInputValueChanged(quint32,quint32)));
117
    connect(m_presetInputWidget, SIGNAL(keySequenceChanged(QKeySequence)),
×
118
            this, SLOT(slotKeySequenceChanged(QKeySequence)));
119
}
×
120

121
VCMatrixProperties::~VCMatrixProperties()
×
122
{
123
    foreach (VCMatrixControl* control, m_controls)
×
124
        delete control;
×
125

126
    delete m_presetInputWidget;
×
127
}
×
128

129
/*********************************************************************
130
 * RGB Matrix attachment
131
 *********************************************************************/
132

133
void VCMatrixProperties::slotAttachFunction()
×
134
{
135
    FunctionSelection fs(this, m_doc);
×
136
    fs.setMultiSelection(false);
×
137
    fs.setFilter(Function::RGBMatrixType);
×
138
    fs.disableFilters(Function::SceneType | Function::ChaserType | Function::EFXType |
×
139
                      Function::ShowType | Function::ScriptType | Function::CollectionType |
140
                      Function::AudioType | Function::VideoType);
141

142
    if (fs.exec() == QDialog::Accepted && fs.selection().size() > 0)
×
143
        slotSetFunction(fs.selection().first());
×
144
}
×
145

146
void VCMatrixProperties::slotSetFunction(quint32 fid)
×
147
{
148
    m_function = fid;
×
149
    Function* func = m_doc->function(m_function);
×
150

151
    if (func == NULL)
×
152
    {
153
        m_functionEdit->setText(tr("No function"));
×
154
    }
155
    else
156
    {
157
        m_functionEdit->setText(func->name());
×
158
        if (m_nameEdit->text().simplified().contains(QString::number(m_matrix->id())))
×
159
            m_nameEdit->setText(func->name());
×
160
    }
161
}
×
162

163
/*********************************************************************
164
 * Slider External input
165
 *********************************************************************/
166

167
void VCMatrixProperties::slotAutoDetectSliderInputToggled(bool checked)
×
168
{
169
    if (checked == true)
×
170
    {
171
        connect(m_doc->inputOutputMap(), SIGNAL(inputValueChanged(quint32,quint32,uchar)),
×
172
                this, SLOT(slotSliderInputValueChanged(quint32,quint32)));
173
    }
174
    else
175
    {
176
        disconnect(m_doc->inputOutputMap(), SIGNAL(inputValueChanged(quint32,quint32,uchar)),
×
177
                   this, SLOT(slotSliderInputValueChanged(quint32,quint32)));
178
    }
179
}
×
180

181
void VCMatrixProperties::slotSliderInputValueChanged(quint32 universe, quint32 channel)
×
182
{
183
    m_sliderInputSource = QSharedPointer<QLCInputSource>(new QLCInputSource(universe, (m_matrix->page() << 16) | channel));
×
184
    updateSliderInputSource();
×
185
}
×
186

187
void VCMatrixProperties::slotChooseSliderInputClicked()
×
188
{
189
    SelectInputChannel sic(this, m_doc->inputOutputMap());
×
190
    if (sic.exec() == QDialog::Accepted)
×
191
    {
192
        m_sliderInputSource = QSharedPointer<QLCInputSource>(new QLCInputSource(sic.universe(), sic.channel()));
×
193
        updateSliderInputSource();
×
194
    }
195
}
×
196

197
void VCMatrixProperties::updateSliderInputSource()
×
198
{
199
    QString uniName;
×
200
    QString chName;
×
201

202
    if (m_doc->inputOutputMap()->inputSourceNames(m_sliderInputSource, uniName, chName) == false)
×
203
    {
204
        uniName = KInputNone;
×
205
        chName = KInputNone;
×
206
    }
207

208
    m_inputUniverseEdit->setText(uniName);
×
209
    m_inputChannelEdit->setText(chName);
×
210
}
×
211

212
/*********************************************************************
213
 * Custom controls
214
 *********************************************************************/
215

216
void VCMatrixProperties::updateTree()
×
217
{
218
    m_controlsTree->blockSignals(true);
×
219
    m_controlsTree->clear();
×
NEW
220
    foreach (VCMatrixControl *control, m_controls)
×
221
    {
222
        QTreeWidgetItem *item = new QTreeWidgetItem(m_controlsTree);
×
223
        item->setData(0, Qt::UserRole, control->m_id);
×
224

225
        switch(control->m_type)
×
226
        {
227
            case VCMatrixControl::StartColor:
×
228
                item->setIcon(0, QIcon(":/color.png"));
×
229
                item->setText(0, tr("Start Color"));
×
230
                item->setText(1, control->m_color.name());
×
231
                item->setBackground(1, QBrush(control->m_color));
×
232
            break;
×
233
            case VCMatrixControl::StartColorKnob:
×
234
                item->setIcon(0, QIcon(":/knob.png"));
×
235
                item->setText(0, tr("Start Color Knob"));
×
236
                item->setText(1, control->m_color.name());
×
237
                item->setBackground(1, QBrush(control->m_color));
×
238
            break;
×
239
            case VCMatrixControl::EndColor:
×
240
                item->setIcon(0, QIcon(":/color.png"));
×
241
                item->setText(0, tr("End Color"));
×
242
                item->setText(1, control->m_color.name());
×
243
                item->setBackground(1, QBrush(control->m_color));
×
244
            break;
×
245
            case VCMatrixControl::EndColorKnob:
×
246
                item->setIcon(0, QIcon(":/knob.png"));
×
247
                item->setText(0, tr("End Color Knob"));
×
248
                item->setText(1, control->m_color.name());
×
249
                item->setBackground(1, QBrush(control->m_color));
×
250
            break;
×
251
            case VCMatrixControl::ResetEndColor:
×
252
                item->setIcon(0, QIcon(":/fileclose.png"));
×
253
                item->setText(0, tr("End Color Reset"));
×
254
            break;
×
255
            case VCMatrixControl::Animation:
×
256
            {
257
                item->setIcon(0, QIcon(":/script.png"));
×
258
                item->setText(0, tr("Animation"));
×
259
                QString presetName = control->m_resource;
×
260
                if (!control->m_properties.isEmpty())
×
261
                {
262
                    presetName += " (";
×
263
                    QHashIterator<QString, QString> it(control->m_properties);
×
NEW
264
                    while (it.hasNext())
×
265
                    {
266
                        it.next();
×
267
                        presetName += it.value();
×
268
                        if (it.hasNext())
×
269
                            presetName += ",";
×
270
                    }
271
                    presetName += ")";
×
272
                }
273
                item->setText(1, presetName);
×
274
            }
275
            break;
×
276
            case VCMatrixControl::Image:
×
277
            break;
×
278
            case VCMatrixControl::Text:
×
279
                item->setIcon(0, QIcon(":/fonts.png"));
×
280
                item->setText(0, tr("Text"));
×
281
                item->setText(1, control->m_resource);
×
282
            break;
×
283
        }
284
    }
285
    m_controlsTree->resizeColumnToContents(0);
×
286
    m_controlsTree->blockSignals(false);
×
287
}
×
288

289
VCMatrixControl *VCMatrixProperties::getSelectedControl()
×
290
{
291
    if (m_controlsTree->selectedItems().isEmpty())
×
292
        return NULL;
×
293

294
    QTreeWidgetItem * item = m_controlsTree->selectedItems().first();
×
295
    if (item != NULL)
×
296
    {
297
        quint8 ctlID = item->data(0, Qt::UserRole).toUInt();
×
NEW
298
        foreach (VCMatrixControl *control, m_controls)
×
299
        {
300
            if (control->m_id == ctlID)
×
301
                return control;
×
302
        }
303
    }
304

305
    Q_ASSERT(false);
×
306
    return NULL;
307
}
308

309
QList<QColor> VCMatrixProperties::rgbColorList()
×
310
{
311
    QList<QColor> colors;
×
312
    colors.append(QColor(Qt::red));
×
313
    colors.append(QColor(Qt::green));
×
314
    colors.append(QColor(Qt::blue));
×
315
    return colors;
×
316
}
317

318
void VCMatrixProperties::addControl(VCMatrixControl *control)
×
319
{
320
    m_controls.append(control);
×
321
}
×
322

323
void VCMatrixProperties::removeControl(quint8 id)
×
324
{
NEW
325
    for (int i = 0; i < m_controls.count(); i++)
×
326
    {
327
        if (m_controls.at(i)->m_id == id)
×
328
        {
329
            m_controls.removeAt(i);
×
330
            return;
×
331
        }
332
    }
333
}
334

335
void VCMatrixProperties::slotAddStartColorClicked()
×
336
{
337
    QColor col = QColorDialog::getColor();
×
338
    if (col.isValid() == true)
×
339
    {
340
        VCMatrixControl *newControl = new VCMatrixControl(++m_lastAssignedID);
×
341
        newControl->m_type = VCMatrixControl::StartColor;
×
342
        newControl->m_color = col;
×
343
        addControl(newControl);
×
344
        updateTree();
×
345
    }
346
}
×
347

348
void VCMatrixProperties::slotAddStartColorKnobsClicked()
×
349
{
350
    foreach (QColor col, VCMatrixProperties::rgbColorList())
×
351
    {
352
        VCMatrixControl *newControl = new VCMatrixControl(++m_lastAssignedID);
×
353
        newControl->m_type = VCMatrixControl::StartColorKnob;
×
354
        newControl->m_color = col;
×
355
        addControl(newControl);
×
356
    }
357
    updateTree();
×
358
}
×
359

360
void VCMatrixProperties::slotAddEndColorClicked()
×
361
{
362
    QColor col = QColorDialog::getColor();
×
363
    if (col.isValid() == true)
×
364
    {
365
        VCMatrixControl *newControl = new VCMatrixControl(++m_lastAssignedID);
×
366
        newControl->m_type = VCMatrixControl::EndColor;
×
367
        newControl->m_color = col;
×
368
        addControl(newControl);
×
369
        updateTree();
×
370
    }
371
}
×
372

373
void VCMatrixProperties::slotAddEndColorKnobsClicked()
×
374
{
375
    foreach (QColor col, VCMatrixProperties::rgbColorList())
×
376
    {
377
        VCMatrixControl *newControl = new VCMatrixControl(++m_lastAssignedID);
×
378
        newControl->m_type = VCMatrixControl::EndColorKnob;
×
379
        newControl->m_color = col;
×
380
        addControl(newControl);
×
381
    }
382
    updateTree();
×
383
}
×
384

385
void VCMatrixProperties::slotAddEndColorResetClicked()
×
386
{
387
    VCMatrixControl *newControl = new VCMatrixControl(++m_lastAssignedID);
×
388
    newControl->m_type = VCMatrixControl::ResetEndColor;
×
389
    addControl(newControl);
×
390
    updateTree();
×
391
}
×
392

393
void VCMatrixProperties::slotAddAnimationClicked()
×
394
{
395
    VCMatrixPresetSelection ps(m_doc, this);
×
396

397
    if (ps.exec() == QDialog::Accepted)
×
398
    {
399
        VCMatrixControl *newControl = new VCMatrixControl(++m_lastAssignedID);
×
400
        newControl->m_type = VCMatrixControl::Animation;
×
401
        newControl->m_resource = ps.selectedPreset();
×
402
        newControl->m_properties = ps.customizedProperties();
×
403
        addControl(newControl);
×
404
        updateTree();
×
405
    }
406
}
×
407

408
void VCMatrixProperties::slotAddTextClicked()
×
409
{
410
    bool ok;
411
    QString text = QInputDialog::getText(this, tr("Enter a text"),
×
412
                                      tr("Text"), QLineEdit::Normal,
×
413
                                      "Q Light Controller+", &ok);
×
414
    if (ok && !text.isEmpty())
×
415
    {
416
        VCMatrixControl *newControl = new VCMatrixControl(++m_lastAssignedID);
×
417
        newControl->m_type = VCMatrixControl::Text;
×
418
        newControl->m_resource = text;
×
419
        addControl(newControl);
×
420
        updateTree();
×
421
    }
422
}
×
423

424
void VCMatrixProperties::slotRemoveClicked()
×
425
{
426
    if (m_controlsTree->selectedItems().isEmpty())
×
427
        return;
×
428
    QTreeWidgetItem *selItem = m_controlsTree->selectedItems().first();
×
429
    quint8 ctlID = selItem->data(0, Qt::UserRole).toUInt();
×
430

431
    {
432
        // For R/G/B Knobs:
433
        // Remove the two others
434
        VCMatrixControl *control = getSelectedControl();
×
435
        if (control != NULL)
×
436
        {
437
            if (control->m_type == VCMatrixControl::StartColorKnob
×
438
                    || control->m_type == VCMatrixControl::EndColorKnob)
×
439
            {
440
                if (control->m_color == Qt::red)
×
441
                {
442
                    removeControl(ctlID + 1);
×
443
                    removeControl(ctlID + 2);
×
444
                }
445
                else if (control->m_color == Qt::green)
×
446
                {
447
                    removeControl(ctlID - 1);
×
448
                    removeControl(ctlID + 1);
×
449
                }
450
                else if (control->m_color == Qt::blue)
×
451
                {
452
                    removeControl(ctlID - 2);
×
453
                    removeControl(ctlID - 1);
×
454
                }
455
                else
456
                {
457
                    Q_ASSERT(false);
×
458
                }
459
            }
460
        }
461
    }
462

463
    removeControl(ctlID);
×
464
    updateTree();
×
465
}
466

467
void VCMatrixProperties::slotInputValueChanged(quint32 universe, quint32 channel)
×
468
{
469
    Q_UNUSED(universe);
470
    Q_UNUSED(channel);
471

472
    VCMatrixControl *preset = getSelectedControl();
×
473

474
    if (preset != NULL) {
×
475
        preset->m_inputSource = m_presetInputWidget->inputSource();
×
476
    }
477
}
×
478

479
void VCMatrixProperties::slotKeySequenceChanged(QKeySequence key)
×
480
{
481
    VCMatrixControl *preset = getSelectedControl();
×
482

483
    if (preset != NULL)
×
484
        preset->m_keySequence = key;
×
485
}
×
486

487

488
void VCMatrixProperties::slotTreeSelectionChanged()
×
489
{
490
    VCMatrixControl *control = getSelectedControl();
×
491

492
    if (control != NULL)
×
493
    {
494
        m_presetInputWidget->setInputSource(control->m_inputSource);
×
495
        m_presetInputWidget->setKeySequence(control->m_keySequence.toString(QKeySequence::NativeText));
×
496
        if (control->widgetType() == VCMatrixControl::Button)
×
497
        {
498
            m_presetInputWidget->setCustomFeedbackVisibility(true);
×
499
            m_presetInputWidget->setKeyInputVisibility(true);
×
500
        }
501
        else
502
        {
503
            m_presetInputWidget->setCustomFeedbackVisibility(false);
×
504
            m_presetInputWidget->setKeyInputVisibility(false);
×
505
        }
506
    }
507
}
×
508

509
void VCMatrixProperties::accept()
×
510
{
511
    m_matrix->setCaption(m_nameEdit->text());
×
512
    m_matrix->setFunction(m_function);
×
513
    if (m_instantCheck->isChecked())
×
514
        m_matrix->setInstantChanges(true);
×
515
    else
516
        m_matrix->setInstantChanges(false);
×
517

518
    /* External input */
519
    m_matrix->setInputSource(m_sliderInputSource);
×
520

521
    /* Visibility */
522
    quint32 visibilityMask = 0;
×
523
    if (m_sliderCheck->isChecked()) visibilityMask |= VCMatrix::ShowSlider;
×
524
    if (m_labelCheck->isChecked()) visibilityMask |= VCMatrix::ShowLabel;
×
525
    if (m_startColorButtonCheck->isChecked()) visibilityMask |= VCMatrix::ShowStartColorButton;
×
526
    if (m_endColorButtonCheck->isChecked()) visibilityMask |= VCMatrix::ShowEndColorButton;
×
527
    if (m_presetComboCheck->isChecked()) visibilityMask |= VCMatrix::ShowPresetCombo;
×
528
    m_matrix->setVisibilityMask(visibilityMask);
×
529

530
    /* Controls */
531
    m_matrix->resetCustomControls();
×
532
    for (int i = 0; i < m_controls.count(); i++)
×
533
        m_matrix->addCustomControl(*m_controls.at(i));
×
534

535
    /* Close dialog */
536
    QDialog::accept();
×
537
}
×
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