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

mcallegari / qlcplus / 13633248611

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

push

github

web-flow
actions: add chrpath to profile

14689 of 46089 relevant lines covered (31.87%)

26426.11 hits per line

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

0.0
/ui/src/fixtureconsole.cpp
1
/*
2
  Q Light Controller
3
  fixtureconsole.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 <QHBoxLayout>
21
#include <QDebug>
22
#include <QIcon>
23
#include <QList>
24

25
#include "fixtureconsole.h"
26
#include "consolechannel.h"
27
#include "fixture.h"
28
#include "apputil.h"
29
#include "doc.h"
30

31
/*****************************************************************************
32
 * Initialization
33
 *****************************************************************************/
34

35
FixtureConsole::FixtureConsole(QWidget *parent, Doc *doc, GroupType type, bool showCheck)
×
36
    : QGroupBox(parent)
37
    , m_doc(doc)
×
38
    , m_groupType(type)
×
39
    , m_showCheckBoxes(showCheck)
×
40
    , m_fixture(Fixture::invalidId())
×
41
{
42
    Q_ASSERT(doc != NULL);
43

44
    m_layout = new QHBoxLayout(this);
×
45
    layout()->setSpacing(0);
×
46
    layout()->setContentsMargins(0, 1, 0, 1);
×
47

48
    int topMargin = m_showCheckBoxes ? 16 : 1;
×
49

50
    QString ssFcCommon = "QGroupBox::title {top:-15px; left: 12px; subcontrol-origin: border; background-color: transparent; } "
51
                         "QGroupBox::indicator { width: 18px; height: 18px; } "
52
                         "QGroupBox::indicator:checked { image: url(:/checkbox_full.png) } "
53
                         "QGroupBox::indicator:unchecked { image: url(:/checkbox_empty.png) }";
×
54

55
    QString ssFcEven = "QGroupBox { background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #C3D1C9, stop: 1 #AFBBB4); "
56
                       "border: 1px solid gray; border-radius: 4px; margin-top: %1px; margin-right: 1px; } ";
×
57

58
    QString ssFcOdd = "QGroupBox { background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #D6D5E0, stop: 1 #A7A6AF); "
59
                      "border: 1px solid gray; border-radius: 4px; margin-top: %1px; margin-right: 1px; } ";
×
60

61
    QString ssFcNone = "QGroupBox { background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #D6D2D0, stop: 1 #AFACAB); "
62
                       "border: 1px solid gray; border-radius: 4px; margin-top: %1px; margin-right: 1px; } ";
×
63

64
    QString userStyle = AppUtil::getStyleSheet("FIXTURE_CONSOLE_COMMON");
×
65
    if (!userStyle.isEmpty())
×
66
        ssFcCommon = userStyle;
×
67

68
    if (m_groupType == GroupEven)
×
69
    {
70
        userStyle = AppUtil::getStyleSheet("FIXTURE_CONSOLE_EVEN");
×
71
        if (!userStyle.isEmpty())
×
72
            ssFcEven = userStyle;
×
73
        m_styleSheet = QString(ssFcEven + (m_showCheckBoxes ? ssFcCommon : "")).arg(topMargin);
×
74
    }
75
    else if (m_groupType == GroupOdd)
×
76
    {
77
        userStyle = AppUtil::getStyleSheet("FIXTURE_CONSOLE_ODD");
×
78
        if (!userStyle.isEmpty())
×
79
            ssFcOdd = userStyle;
×
80
        m_styleSheet = QString(ssFcOdd + (m_showCheckBoxes ? ssFcCommon : "")).arg(topMargin);
×
81
    }
82
    else
83
    {
84
        userStyle = AppUtil::getStyleSheet("FIXTURE_CONSOLE_NORMAL");
×
85
        if (!userStyle.isEmpty())
×
86
            ssFcNone = userStyle;
×
87
        m_styleSheet = QString(ssFcNone + (m_showCheckBoxes ? ssFcCommon : "")).arg(topMargin);
×
88
    }
89
}
×
90

91
FixtureConsole::~FixtureConsole()
×
92
{
93
}
×
94

95
void FixtureConsole::enableResetButton(bool enable)
×
96
{
97
    QListIterator <ConsoleChannel*> it(m_channels);
×
98
    while (it.hasNext() == true)
×
99
    {
100
        ConsoleChannel* cc = it.next();
×
101
        Q_ASSERT(cc != NULL);
102
        cc->showResetButton(enable);
×
103
        connect(cc, SIGNAL(resetRequest(quint32,quint32)),
×
104
                this, SIGNAL(resetRequest(quint32,quint32)));
105
    }
106
}
×
107

108
void FixtureConsole::showEvent(QShowEvent *)
×
109
{
110
    QListIterator <ConsoleChannel*> it(m_channels);
×
111
    while (it.hasNext() == true)
×
112
    {
113
        ConsoleChannel* cc = it.next();
×
114
        Q_ASSERT(cc != NULL);
115
        cc->setVisible(true);
×
116
    }
117
}
×
118

119
/*****************************************************************************
120
 * Fixture
121
 *****************************************************************************/
122

123
void FixtureConsole::setFixture(quint32 id)
×
124
{
125
    /* Get rid of any previous channels */
126
    while (m_channels.isEmpty() == false)
×
127
        delete m_channels.takeFirst();
×
128

129
    /* Get the new fixture */
130
    Fixture *fxi = m_doc->fixture(id);
×
131
    Q_ASSERT(fxi != NULL);
132
    if (m_groupType != GroupNone)
×
133
        setTitle(fxi->name());
×
134

135
    /* Create channel units */
136
    for (uint i = 0; i < fxi->channels(); i++)
×
137
    {
138
        const QLCChannel *ch = fxi->channel(i);
×
139
        Q_ASSERT(ch != NULL);
140
        if (ch->group() == QLCChannel::NoGroup)
×
141
            continue;
×
142

143
        ConsoleChannel* cc = new ConsoleChannel(this, m_doc, id, i, m_showCheckBoxes);
×
144
        cc->setVisible(false);
×
145
        cc->setChannelStyleSheet(m_styleSheet);
×
146

147
        m_layout->addWidget(cc);
×
148
        m_channels.append(cc);
×
149
        connect(cc, SIGNAL(valueChanged(quint32,quint32,uchar)),
×
150
                this, SIGNAL(valueChanged(quint32,quint32,uchar)));
151
        connect(cc, SIGNAL(checked(quint32,quint32,bool)),
×
152
                this, SIGNAL(checked(quint32,quint32,bool)));
153
    }
154

155
    /* Make a spacer item eat excess space to justify channels left */
156
    m_layout->addItem(new QSpacerItem(0, 0, QSizePolicy::Expanding));
×
157

158
    m_fixture = id;
×
159

160
    connect(fxi, SIGNAL(aliasChanged()), this, SLOT(slotAliasChanged()));
×
161
}
×
162

163
quint32 FixtureConsole::fixture() const
×
164
{
165
    return m_fixture;
×
166
}
167

168
void FixtureConsole::slotAliasChanged()
×
169
{
170
    quint32 i = 0;
171
    Fixture *fxi = m_doc->fixture(m_fixture);
×
172

173
    QListIterator <ConsoleChannel*> it(m_channels);
×
174
    while (it.hasNext() == true)
×
175
    {
176
        ConsoleChannel* cc = it.next();
×
177
        if (cc->channel() != fxi->channel(i))
×
178
        {
179
            disconnect(cc, SIGNAL(valueChanged(quint32,quint32,uchar)),
×
180
                       this, SIGNAL(valueChanged(quint32,quint32,uchar)));
181
            disconnect(cc, SIGNAL(checked(quint32,quint32,bool)),
×
182
                       this, SIGNAL(checked(quint32,quint32,bool)));
183

184
            ConsoleChannel* newCC = new ConsoleChannel(this, m_doc, fxi->id(), i, m_showCheckBoxes);
×
185
            newCC->setVisible(false);
×
186
            newCC->setChannelStyleSheet(m_styleSheet);
×
187
            if (cc->hasResetButton())
×
188
                newCC->showResetButton(true);
×
189
            newCC->setValue(cc->value());
×
190
            newCC->setVisible(true);
×
191

192
            connect(newCC, SIGNAL(valueChanged(quint32,quint32,uchar)),
×
193
                    this, SIGNAL(valueChanged(quint32,quint32,uchar)));
194
            connect(newCC, SIGNAL(checked(quint32,quint32,bool)),
×
195
                    this, SIGNAL(checked(quint32,quint32,bool)));
196

197
            QLayoutItem *item = m_layout->replaceWidget(cc, newCC);
×
198
            delete item;
×
199
            delete cc;
×
200
            m_channels.replace(i, newCC);
×
201
        }
202
        i++;
×
203
    }
204
}
×
205

206
/*****************************************************************************
207
 * Channels
208
 *****************************************************************************/
209

210
void FixtureConsole::setChecked(bool state, quint32 channel)
×
211
{
212
    QListIterator <ConsoleChannel*> it(m_channels);
×
213
    while (it.hasNext() == true)
×
214
    {
215
        ConsoleChannel* cc = it.next();
×
216
        Q_ASSERT(cc != NULL);
217
        if (channel == UINT_MAX || channel == cc->channelIndex())
×
218
            cc->setChecked(state);
×
219
    }
220
}
×
221

222
void FixtureConsole::setSceneValue(const SceneValue& scv)
×
223
{
224
    Q_ASSERT(scv.fxi == m_fixture);
225

226
    QListIterator <ConsoleChannel*> it(m_channels);
×
227
    while (it.hasNext() == true)
×
228
    {
229
        ConsoleChannel* cc = it.next();
×
230
        Q_ASSERT(cc != NULL);
231
        if (cc->channelIndex() == scv.channel)
×
232
        {
233
            cc->setChecked(true);
×
234
            cc->setValue(scv.value);
×
235
        }
236
    }
237
}
×
238

239
QList <SceneValue> FixtureConsole::values() const
×
240
{
241
    QList <SceneValue> list; // list of all checked channels
242
    QList <SceneValue> selectedList; // list of selected channels only
243
    QListIterator <ConsoleChannel*> it(m_channels);
×
244
    while (it.hasNext() == true)
×
245
    {
246
        ConsoleChannel* cc = it.next();
×
247
        Q_ASSERT(cc != NULL);
248
        if (cc->isChecked() == true)
×
249
        {
250
            list.append(SceneValue(m_fixture, cc->channelIndex(), cc->value()));
×
251
            if (cc->isSelected())
×
252
                selectedList.append(SceneValue(m_fixture, cc->channelIndex(), cc->value()));
×
253
        }
254
    }
255

256
    if (selectedList.count() > 0)
×
257
        return selectedList;
258
    else
259
        return list;
260
}
×
261

262
bool FixtureConsole::hasSelections()
×
263
{
264
    foreach (ConsoleChannel *cc, m_channels)
×
265
    {
266
        Q_ASSERT(cc != NULL);
267
        if (cc->isChecked() && cc->isSelected())
×
268
            return true;
269
    }
270

271
    return false;
×
272
}
273

274
void FixtureConsole::setValues(const QList <SceneValue>& list, bool fromSelection)
×
275
{
276
    QList<ConsoleChannel *> toUncheckList = m_channels;
×
277

278
    QListIterator <SceneValue> it(list);
×
279
    while (it.hasNext() == true)
×
280
    {
281
        SceneValue val(it.next());
×
282
        if (val.channel < quint32(children().size()))
×
283
        {
284
            ConsoleChannel* cc = channel(val.channel);
×
285
            if (cc != NULL)
×
286
            {
287
                if (cc->isChecked() == false)
×
288
                    cc->setChecked(true);
×
289
                cc->setValue(val.value);
×
290
                toUncheckList.removeOne(cc);
×
291
            }
292
        }
293
    }
×
294

295
    if (fromSelection == false)
×
296
    {
297
        foreach (ConsoleChannel *cc, toUncheckList)
×
298
            cc->setChecked(false);
×
299
    }
300
}
×
301

302
void FixtureConsole::setValue(quint32 ch, uchar value, bool apply)
×
303
{
304
    ConsoleChannel* cc = channel(ch);
×
305
    if (cc != NULL)
×
306
        cc->setValue(value, apply);
×
307
}
×
308

309
uchar FixtureConsole::value(quint32 ch) const
×
310
{
311
    ConsoleChannel* cc = channel(ch);
×
312
    if (cc != NULL)
×
313
        return cc->value();
×
314
    else
315
        return 0;
316
}
317

318
void FixtureConsole::setChannelStylesheet(quint32 ch, QString ss)
×
319
{
320
    ConsoleChannel* cc = channel(ch);
×
321
    if (cc != NULL)
×
322
        cc->setChannelStyleSheet(ss);
×
323
}
×
324

325
void FixtureConsole::resetChannelsStylesheet()
×
326
{
327
    QListIterator <ConsoleChannel*> it(m_channels);
×
328
    while (it.hasNext() == true)
×
329
    {
330
        ConsoleChannel* cc = it.next();
×
331
        Q_ASSERT(cc != NULL);
332
        cc->setChannelStyleSheet(m_styleSheet);
×
333
    }
334
}
×
335

336
ConsoleChannel* FixtureConsole::channel(quint32 ch) const
×
337
{
338
    QListIterator <ConsoleChannel*> it(m_channels);
×
339
    while (it.hasNext() == true)
×
340
    {
341
        ConsoleChannel* cc = it.next();
×
342
        Q_ASSERT(cc != NULL);
343
        if (cc->channelIndex() == ch)
×
344
            return cc;
×
345
    }
346

347
    return NULL;
348
}
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