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

mcallegari / qlcplus / 6683238402

29 Oct 2023 12:10PM UTC coverage: 28.07%. Remained the same
6683238402

push

github

mcallegari
engine: fix build

15385 of 54809 relevant lines covered (28.07%)

20267.63 hits per line

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

0.0
/ui/src/virtualconsole/vcaudiotriggersproperties.cpp
1
/*
2
  Q Light Controller Plus
3
  audiotriggersconfiguration.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 <QTreeWidgetItem>
21
#include <QToolButton>
22
#include <QComboBox>
23
#include <QSpinBox>
24

25
#include "vcaudiotriggersproperties.h"
26
#include "inputselectionwidget.h"
27
#include "channelsselection.h"
28
#include "functionselection.h"
29
#include "vcwidgetselection.h"
30
#include "vcaudiotriggers.h"
31
#include "qlcmacros.h"
32
#include "audiobar.h"
33

34
#define KColumnName             0
35
#define KColumnType             1
36
#define KColumnAssign           2
37
#define KColumnInfo             3
38
#define KColumnMinThreshold     4
39
#define KColumnMaxThreshold     5
40
#define KColumnDivisor          6
41

42
AudioTriggersConfiguration::AudioTriggersConfiguration(VCAudioTriggers *triggers, Doc *doc,
×
43
                                                       int bandsNumber, int maxFrequency)
×
44
    : QDialog(triggers)
45
    , m_doc(doc)
46
    , m_maxFrequency(maxFrequency)
×
47
{
48
    setupUi(this);
×
49

50
    m_triggers = triggers;
×
51

52
    m_nameEdit->setText(m_triggers->caption());
×
53

54
    m_barsNumSpin->setFixedWidth(70);
×
55
    m_barsNumSpin->setFixedHeight(30);
×
56
    m_barsNumSpin->setValue(bandsNumber);
×
57

58
    connect(m_barsNumSpin, SIGNAL(valueChanged(int)),
×
59
            this, SLOT(updateTree()));
60

61
    /* External input */
62
    m_inputSelWidget = new InputSelectionWidget(m_doc, this);
×
63
    m_inputSelWidget->setCustomFeedbackVisibility(true);
×
64
    m_inputSelWidget->setKeySequence(m_triggers->keySequence());
×
65
    m_inputSelWidget->setInputSource(m_triggers->inputSource());
×
66
    m_inputSelWidget->setWidgetPage(m_triggers->page());
×
67
    m_inputSelWidget->show();
×
68
    m_extControlLayout->addWidget(m_inputSelWidget);
×
69

70
    m_tree->setAlternatingRowColors(true);
×
71
    m_tree->setRootIsDecorated(false);
×
72
    m_tree->setSelectionMode(QAbstractItemView::NoSelection);
×
73
    m_tree->setAllColumnsShowFocus(true);
×
74

75
    updateTree();
×
76
}
×
77

78
AudioTriggersConfiguration::~AudioTriggersConfiguration()
×
79
{
80
}
×
81

82
void AudioTriggersConfiguration::accept()
×
83
{
84
    m_triggers->setCaption(m_nameEdit->text());
×
85
    m_triggers->setKeySequence(m_inputSelWidget->keySequence());
×
86
    m_triggers->setInputSource(m_inputSelWidget->inputSource());
×
87

88
    /* Close dialog */
89
    QDialog::accept();
×
90
}
×
91

92
void AudioTriggersConfiguration::updateTreeItem(QTreeWidgetItem *item, int idx)
×
93
{
94
    if (item == NULL)
×
95
        return;
×
96

97
    AudioBar *bar = m_triggers->getSpectrumBar(idx);
×
98
    bar->setName(item->text(KColumnName));
×
99

100
    bar->debugInfo();
×
101
    QComboBox *currCombo = (QComboBox *)m_tree->itemWidget(item, KColumnType);
×
102
    if (currCombo != NULL)
×
103
    {
104
        disconnect(currCombo, SIGNAL(currentIndexChanged(int)),
×
105
                   this, SLOT(slotTypeComboChanged(int)));
106
        m_tree->removeItemWidget(item, KColumnType);
×
107
    }
108
    m_tree->removeItemWidget(item, KColumnAssign);
×
109
    m_tree->removeItemWidget(item, KColumnMinThreshold);
×
110
    m_tree->removeItemWidget(item, KColumnMaxThreshold);
×
111
    m_tree->removeItemWidget(item, KColumnDivisor);
×
112

113
    QComboBox *combo = new QComboBox();
×
114
    combo->addItem(QIcon(":/uncheck.png"), tr("None"), idx);
×
115
    combo->addItem(QIcon(":/intensity.png"), tr("DMX"), idx);
×
116
    combo->addItem(QIcon(":/function.png"), tr("Function"), idx);
×
117
    combo->addItem(QIcon(":/virtualconsole.png"), tr("VC Widget"), idx);
×
118
    combo->setCurrentIndex(bar->m_type);
×
119
    m_tree->setItemWidget(item, KColumnType, combo);
×
120
    connect(combo, SIGNAL(currentIndexChanged(int)),
×
121
            this, SLOT(slotTypeComboChanged(int)));
122

123
    if (bar->m_type == AudioBar::DMXBar)
×
124
    {
125
        QToolButton *btn = new QToolButton();
×
126
        btn->setIcon(QIcon(":/attach.png"));
×
127
        btn->setProperty("index", idx);
×
128
        m_tree->setItemWidget(item, KColumnAssign, btn);
×
129
        connect(btn, SIGNAL(clicked()), this, SLOT(slotDmxSelectionClicked()));
×
130
        item->setText(KColumnInfo, tr("%1 channels").arg(bar->m_dmxChannels.count()));
×
131
    }
132
    else if (bar->m_type == AudioBar::FunctionBar)
×
133
    {
134
        QToolButton *btn = new QToolButton();
×
135
        btn->setIcon(QIcon(":/attach.png"));
×
136
        btn->setProperty("index", idx);
×
137
        m_tree->setItemWidget(item, KColumnAssign, btn);
×
138
        connect(btn, SIGNAL(clicked()), this, SLOT(slotFunctionSelectionClicked()));
×
139
        if (bar->m_function != NULL)
×
140
        {
141
            item->setText(KColumnInfo, bar->m_function->name());
×
142
            item->setIcon(KColumnInfo, bar->m_function->getIcon());
×
143
        }
144
        else
145
        {
146
            item->setText(KColumnInfo, tr("No function"));
×
147
            item->setIcon(KColumnInfo, QIcon());
×
148
        }
149
    }
150
    else if (bar->m_type == AudioBar::VCWidgetBar)
×
151
    {
152
        QToolButton *btn = new QToolButton();
×
153
        btn->setIcon(QIcon(":/attach.png"));
×
154
        btn->setProperty("index", idx);
×
155
        m_tree->setItemWidget(item, KColumnAssign, btn);
×
156
        connect(btn, SIGNAL(clicked()), this, SLOT(slotWidgetSelectionClicked()));
×
157
        if (bar->widget() != NULL)
×
158
        {
159
            item->setText(KColumnInfo, bar->widget()->caption());
×
160
            item->setIcon(KColumnInfo, VCWidget::typeToIcon(bar->widget()->type()));
×
161
        }
162
        else
163
        {
164
            item->setText(KColumnInfo, tr("No widget"));
×
165
            item->setIcon(KColumnInfo, QIcon());
×
166
        }
167
    }
168
    else
169
    {
170
        item->setText(KColumnInfo, tr("Not assigned"));
×
171
        item->setIcon(KColumnInfo, QIcon());
×
172
    }
173

174
    if (bar->m_type == AudioBar::FunctionBar
×
175
        || (bar->m_type == AudioBar::VCWidgetBar && ((bar->widget() == NULL) || bar->widget()->type() != VCWidget::SliderWidget)))
×
176
    {
177
        QSpinBox *minspin = new QSpinBox();
×
178
        minspin->setMinimum(5);
×
179
        minspin->setMaximum(95);
×
180
        minspin->setSingleStep(1);
×
181
        minspin->setSuffix("%");
×
182
        minspin->setValue(SCALE(float(bar->m_minThreshold), 0.0, 255.0, 0.0, 100.0));
×
183
        minspin->setProperty("index", idx);
×
184
        connect(minspin, SIGNAL(valueChanged(int)), this, SLOT(slotMinThresholdChanged(int)));
×
185
        m_tree->setItemWidget(item, KColumnMinThreshold, minspin);
×
186

187
        QSpinBox *maxspin = new QSpinBox();
×
188
        maxspin->setMinimum(5);
×
189
        maxspin->setMaximum(95);
×
190
        maxspin->setSingleStep(1);
×
191
        maxspin->setSuffix("%");
×
192
        maxspin->setValue(SCALE(float(bar->m_maxThreshold), 0.0, 255.0, 0.0, 100.0));
×
193
        maxspin->setProperty("index", idx);
×
194
        connect(maxspin, SIGNAL(valueChanged(int)), this, SLOT(slotMaxThresholdChanged(int)));
×
195
        m_tree->setItemWidget(item, KColumnMaxThreshold, maxspin);
×
196
    }
197

198
    if (bar->m_type == AudioBar::VCWidgetBar
×
199
        && bar->widget() != NULL
×
200
        && (bar->widget()->type() == VCWidget::SpeedDialWidget || bar->widget()->type() == VCWidget::CueListWidget))
×
201
    {
202
        QSpinBox *divisor = new QSpinBox();
×
203
        divisor->setMinimum(1);
×
204
        divisor->setMaximum(64);
×
205
        divisor->setSingleStep(1);
×
206
        divisor->setValue(bar->m_divisor);
×
207
        divisor->setProperty("index", idx);
×
208
        connect(divisor, SIGNAL(valueChanged(int)), this, SLOT(slotDivisorChanged(int)));
×
209
        m_tree->setItemWidget(item, KColumnDivisor, divisor);
×
210
    }
211
}
212

213
void AudioTriggersConfiguration::updateTree()
×
214
{
215
    if (m_barsNumSpin->value() < m_barsNumSpin->minimum() ||
×
216
        m_barsNumSpin->value() > m_barsNumSpin->maximum())
×
217
            return;
×
218

219
    m_tree->clear();
×
220
    m_triggers->setSpectrumBarsNumber(m_barsNumSpin->value());
×
221

222
    // add volume item
223
    QTreeWidgetItem *volItem = new QTreeWidgetItem(m_tree);
×
224
    volItem->setText(KColumnName, tr("Volume Bar"));
×
225
    updateTreeItem(volItem, 1000);
×
226

227
    double freqIncr = (double)m_maxFrequency / m_barsNumSpin->value();
×
228
    double freqCount = 0.0;
×
229

230
    for (int i = 0; i < m_barsNumSpin->value(); i++)
×
231
    {
232
        QTreeWidgetItem *barItem = new QTreeWidgetItem(m_tree);
×
233
        barItem->setText(KColumnName, tr("#%1 (%2Hz - %3Hz)").arg(i + 1).arg((int)freqCount).arg((int)(freqCount + freqIncr)));
×
234
        updateTreeItem(barItem, i);
×
235
        freqCount += freqIncr;
×
236
    }
237

238
    m_tree->header()->resizeSections(QHeaderView::ResizeToContents);
×
239
}
240

241
void AudioTriggersConfiguration::slotTypeComboChanged(int comboIndex)
×
242
{
243
    QComboBox *combo = (QComboBox *)sender();
×
244
    int index = combo->itemData(comboIndex).toInt();
×
245
    QTreeWidgetItem *item = NULL;
×
246
    if (index == 1000)
×
247
        item = m_tree->topLevelItem(0);
×
248
    else
249
        item = m_tree->topLevelItem(index + 1);
×
250

251
    m_triggers->setSpectrumBarType(index, comboIndex);
×
252

253
    updateTreeItem(item, index);
×
254
}
×
255

256
void AudioTriggersConfiguration::slotDmxSelectionClicked()
×
257
{
258
    QToolButton *btn = (QToolButton *)sender();
×
259
    QVariant prop = btn->property("index");
×
260
    if (prop.isValid())
×
261
    {
262
        AudioBar *bar = m_triggers->getSpectrumBar(prop.toInt());
×
263
        ChannelsSelection cfg(m_doc, this);
×
264
        if (bar != NULL)
×
265
            cfg.setChannelsList(bar->m_dmxChannels);
×
266
        if (cfg.exec() == QDialog::Rejected)
×
267
            return; // User pressed cancel
×
268

269
        QList<SceneValue> dmxList = cfg.channelsList();
×
270
        if (bar != NULL)
×
271
            bar->attachDmxChannels(m_doc, dmxList);
×
272
        QTreeWidgetItem *item = NULL;
×
273
        if (prop.toInt() == 1000)
×
274
            item = m_tree->topLevelItem(0);
×
275
        else
276
            item = m_tree->topLevelItem(prop.toInt() + 1);
×
277
        updateTreeItem(item, prop.toInt());
×
278
    }
279
}
280

281
void AudioTriggersConfiguration::slotFunctionSelectionClicked()
×
282
{
283
    QToolButton *btn = (QToolButton *)sender();
×
284
    QVariant prop = btn->property("index");
×
285
    if (prop.isValid())
×
286
    {
287
        FunctionSelection fs(this, m_doc);
×
288
        fs.setMultiSelection(false);
×
289
        if (fs.exec() == QDialog::Rejected || fs.selection().size() == 0)
×
290
            return; // User pressed cancel or made an invalid selection
×
291
        AudioBar *bar = m_triggers->getSpectrumBar(prop.toInt());
×
292
        Function *f = m_doc->function(fs.selection().first());
×
293
        if (bar != NULL && f != NULL)
×
294
            bar->attachFunction(f);
×
295

296
        QTreeWidgetItem *item = NULL;
×
297
        if (prop.toInt() == 1000)
×
298
            item = m_tree->topLevelItem(0);
×
299
        else
300
            item = m_tree->topLevelItem(prop.toInt() + 1);
×
301
        updateTreeItem(item, prop.toInt());
×
302
    }
303
}
304

305
void AudioTriggersConfiguration::slotWidgetSelectionClicked()
×
306
{
307
    QToolButton *btn = (QToolButton *)sender();
×
308
    QVariant prop = btn->property("index");
×
309
    if (prop.isValid())
×
310
    {
311
        QList<int> filters;
×
312
        filters.append(VCWidget::SliderWidget);
×
313
        filters.append(VCWidget::ButtonWidget);
×
314
        filters.append(VCWidget::SpeedDialWidget);
×
315
        filters.append(VCWidget::CueListWidget);
×
316
        VCWidgetSelection ws(filters, this);
×
317
        if (ws.exec() == QDialog::Rejected || ws.getSelectedWidget() == 0)
×
318
            return; // User pressed cancel or did not select any widget
×
319
        AudioBar *bar = m_triggers->getSpectrumBar(prop.toInt());
×
320
        if (bar != NULL)
×
321
        {
322
            bar->attachWidget(ws.getSelectedWidget()->id());
×
323
        }
324

325
        QTreeWidgetItem *item = NULL;
×
326
        if (prop.toInt() == 1000)
×
327
            item = m_tree->topLevelItem(0);
×
328
        else
329
            item = m_tree->topLevelItem(prop.toInt() + 1);
×
330
        updateTreeItem(item, prop.toInt());
×
331
    }
332
}
333

334
void AudioTriggersConfiguration::slotMinThresholdChanged(int val)
×
335
{
336
    QSpinBox *spin = (QSpinBox *)sender();
×
337
    QVariant prop = spin->property("index");
×
338
    if (prop.isValid())
×
339
    {
340
        AudioBar *bar = m_triggers->getSpectrumBar(prop.toInt());
×
341
        uchar scaledVal = SCALE(float(val), 0.0, 100.0, 0.0, 255.0);
×
342
        if (bar != NULL)
×
343
            bar->setMinThreshold(scaledVal);
×
344
    }
345
}
×
346

347
void AudioTriggersConfiguration::slotMaxThresholdChanged(int val)
×
348
{
349
    QSpinBox *spin = (QSpinBox *)sender();
×
350
    QVariant prop = spin->property("index");
×
351
    if (prop.isValid())
×
352
    {
353
        AudioBar *bar = m_triggers->getSpectrumBar(prop.toInt());
×
354
        uchar scaledVal = SCALE(float(val), 0.0, 100.0, 0.0, 255.0);
×
355
        if (bar != NULL)
×
356
            bar->setMaxThreshold(scaledVal);
×
357
    }
358
}
×
359

360
void AudioTriggersConfiguration::slotDivisorChanged(int val)
×
361
{
362
    QSpinBox *spin = (QSpinBox *)sender();
×
363
    QVariant prop = spin->property("index");
×
364
    if (prop.isValid())
×
365
    {
366
        AudioBar *bar = m_triggers->getSpectrumBar(prop.toInt());
×
367
        if (bar != NULL)
×
368
            bar->setDivisor(val);
×
369
    }
370
}
×
371

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

© 2026 Coveralls, Inc