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

mcallegari / qlcplus / 7252848206

18 Dec 2023 07:26PM UTC coverage: 32.067% (+0.001%) from 32.066%
7252848206

push

github

mcallegari
Code style review #1427

199 of 628 new or added lines in 101 files covered. (31.69%)

8 existing lines in 2 files now uncovered.

15169 of 47304 relevant lines covered (32.07%)

23733.74 hits per line

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

0.0
/ui/src/functionwizard.cpp
1
/*
2
  Q Light Controller
3
  functionwizard.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 <QMessageBox>
21
#include <QString>
22
#include <QDebug>
23
#include <QHash>
24
#include <QAction>
25

26
#include "palettegenerator.h"
27
#include "fixtureselection.h"
28
#include "functionwizard.h"
29
#include "virtualconsole.h"
30
#include "vcsoloframe.h"
31
#include "vccuelist.h"
32
#include "rgbmatrix.h"
33
#include "vcwidget.h"
34
#include "vcbutton.h"
35
#include "vcslider.h"
36
#include "vcframe.h"
37
#include "fixture.h"
38
#include "chaser.h"
39
#include "scene.h"
40
#include "doc.h"
41

42
#include "qlcfixturedef.h"
43
#include "qlccapability.h"
44
#include "qlcchannel.h"
45

46
#define KFixtureColumnName          0
47
#define KFixtureColumnCaps          1
48
#define KFixtureColumnManufacturer  2
49
#define KFixtureColumnModel         3
50

51
#define KFunctionName               0
52
#define KFunctionOddEven            1
53

54
#define KWidgetName                 0
55

56
FunctionWizard::FunctionWizard(QWidget* parent, Doc* doc)
×
57
    : QDialog(parent)
58
    , m_doc(doc)
×
59
{
60
    Q_ASSERT(doc != NULL);
×
61
    setupUi(this);
×
62

63
    QString trbgSS = "background-color: qlineargradient(spread:pad, x1:0, y1:0, x2:1, y2:0, stop:0 rgba(0, 0, 0, 0), stop:1 rgba(255, 255, 255, 0));";
×
64
    m_wizardLogo->setStyleSheet(trbgSS);
×
65
    m_introText->setStyleSheet(trbgSS);
×
66

67
    QAction* action = new QAction(this);
×
68
    action->setShortcut(QKeySequence(QKeySequence::Close));
×
69
    connect(action, SIGNAL(triggered(bool)), this, SLOT(reject()));
×
70
    addAction(action);
×
71

72
    m_fixtureTree->sortItems(KFixtureColumnName, Qt::AscendingOrder);
×
73

74
    connect(m_nextButton, SIGNAL(clicked()),
×
75
            this, SLOT(slotNextPageClicked()));
76

77
    connect(m_tabWidget, SIGNAL(currentChanged(int)),
×
78
            this, SLOT(slotTabClicked()));
79

80
    checkTabsAndButtons();
×
81
}
×
82

83
FunctionWizard::~FunctionWizard()
×
84
{
85
    m_paletteList.clear();
×
86
}
×
87

88
void FunctionWizard::slotNextPageClicked()
×
89
{
90
    int newIdx = m_tabWidget->currentIndex() + 1;
×
91
    if (newIdx == 4)
×
92
        return;
×
93

94
    m_tabWidget->setCurrentIndex(newIdx);
×
95
    checkTabsAndButtons();
×
96
}
97

98
void FunctionWizard::slotTabClicked()
×
99
{
100
    checkTabsAndButtons();
×
101
}
×
102

103
void FunctionWizard::accept()
×
104
{
105

106
    foreach (PaletteGenerator *palette, m_paletteList)
×
107
        palette->addToDoc();
×
108

109
    addWidgetsToVirtualConsole();
×
110

111
    m_doc->setModified();
×
112

113
    QDialog::accept();
×
114
}
×
115

116
void FunctionWizard::checkTabsAndButtons()
×
117
{
118
    switch(m_tabWidget->currentIndex())
×
119
    {
120
        case 0:
×
121
        {
122
            m_nextButton->setEnabled(true);
×
123
            m_tabWidget->setTabEnabled(2, false);
×
124
            m_tabWidget->setTabEnabled(3, false);
×
125
        }
126
        break;
×
127
        case 1:
×
128
        {
129
            if (m_allFuncsTree->topLevelItemCount() == 0)
×
130
            {
131
                m_nextButton->setEnabled(false);
×
132
                m_tabWidget->setTabEnabled(2, false);
×
133
            }
134
            else
135
            {
136
                m_nextButton->setEnabled(true);
×
137
                m_tabWidget->setTabEnabled(2, true);
×
138
            }
139
        }
140
        break;
×
141
        case 2:
×
142
        {
143
            if (m_paletteList.isEmpty() == false)
×
144
            {
145
                m_tabWidget->setTabEnabled(3, true);
×
146
                m_nextButton->setEnabled(true);
×
147
            }
148
            else
149
            {
150
                m_tabWidget->setTabEnabled(3, false);
×
151
                m_nextButton->setEnabled(false);
×
152
            }
153
        }
154
        break;
×
155
        case 3:
×
156
            m_nextButton->setEnabled(false);
×
157
        break;
×
158
    }
159
}
×
160

161
/****************************************************************************
162
 * Fixtures
163
 ****************************************************************************/
164

165
QTreeWidgetItem *FunctionWizard::getFixtureGroupItem(QString manufacturer, QString model)
×
166
{
167
    for (int i = 0; i < m_fixtureTree->topLevelItemCount(); i++)
×
168
    {
169
        QTreeWidgetItem *item = m_fixtureTree->topLevelItem(i);
×
170
        if (item->text(KFixtureColumnManufacturer) == manufacturer &&
×
171
            item->text(KFixtureColumnModel) == model)
×
172
                return item;
×
173
    }
174
    // if we're here then the group doesn't exist. Create it
175
    QTreeWidgetItem* newGrp = new QTreeWidgetItem(m_fixtureTree);
×
176
    newGrp->setText(KFixtureColumnName, tr("%1 group").arg(model));
×
177
    newGrp->setIcon(KFixtureColumnName, QIcon(":/group.png"));
×
178
    newGrp->setText(KFixtureColumnManufacturer, manufacturer);
×
179
    newGrp->setText(KFixtureColumnModel, model);
×
180
    newGrp->setExpanded(true);
×
181
    return newGrp;
×
182
}
183

184
void FunctionWizard::addFixture(quint32 fxi_id)
×
185
{
186
    Fixture* fxi = m_doc->fixture(fxi_id);
×
187
    Q_ASSERT(fxi != NULL);
×
188

189
    QStringList caps = PaletteGenerator::getCapabilities(fxi);
×
190

191
    if (caps.join(", ").isEmpty())
×
192
    {
193
        QMessageBox::warning(this, tr("Error"), tr("%1 has no capability supported by this wizard.").arg(fxi->name()));
×
194
        return;
×
195
    }
196
    else
197
    {
198
        QTreeWidgetItem *groupItem = getFixtureGroupItem(fxi->fixtureDef()->manufacturer(), fxi->fixtureDef()->model());
×
199
        Q_ASSERT(groupItem != NULL);
×
200

201
        QTreeWidgetItem* item = new QTreeWidgetItem(groupItem);
×
202
        item->setText(KFixtureColumnName, fxi->name());
×
203
        item->setIcon(KFixtureColumnName, fxi->getIconFromType());
×
204
        item->setData(KFixtureColumnName, Qt::UserRole, fxi_id);
×
205
        item->setText(KFixtureColumnCaps, caps.join(", "));
×
206
    }
207
    m_fixtureTree->resizeColumnToContents(KFixtureColumnName);
×
208
}
209

210
void FunctionWizard::slotAddClicked()
×
211
{
212
    FixtureSelection fs(this, m_doc);
×
213
    fs.setMultiSelection(true);
×
214
    fs.setDisabledFixtures(fixtureIds());
×
215
    if (fs.exec() == QDialog::Accepted)
×
216
    {
217
        QListIterator <quint32> it(fs.selection());
×
218
        while (it.hasNext() == true)
×
219
            addFixture(it.next());
×
220

221
        if (m_fixtureTree->topLevelItemCount() > 0)
×
222
            updateAvailableFunctionsTree();
×
223
    }
224
    checkTabsAndButtons();
×
225
}
×
226

227
void FunctionWizard::slotRemoveClicked()
×
228
{
229
    QListIterator <QTreeWidgetItem*> it(m_fixtureTree->selectedItems());
×
230
    while (it.hasNext() == true)
×
231
        delete it.next();
×
232

233
    checkTabsAndButtons();
×
234
}
×
235

236
QList <quint32> FunctionWizard::fixtureIds() const
×
237
{
238
    QList <quint32> list;
×
239
    for (int i = 0; i < m_fixtureTree->topLevelItemCount(); i++)
×
240
    {
241
        QTreeWidgetItem* item(m_fixtureTree->topLevelItem(i));
×
242
        Q_ASSERT(item != NULL);
×
243

244
        for (int j = 0; j < item->childCount(); j++)
×
245
        {
246
            QTreeWidgetItem *child = item->child(j);
×
247
            Q_ASSERT(child != NULL);
×
248

249
            list << child->data(KFixtureColumnName, Qt::UserRole).toInt();
×
250
        }
251
    }
252

253
    return list;
×
254
}
255

256
/********************************************************************
257
 * Functions
258
 ********************************************************************/
259

260
void FunctionWizard::addFunctionsGroup(QTreeWidgetItem *fxGrpItem, QTreeWidgetItem *grpItem,
×
261
                                       QString name, PaletteGenerator::PaletteType type)
262
{
263
    if (grpItem == NULL)
×
264
        return;
×
265

266
    QTreeWidgetItem *item = new QTreeWidgetItem(grpItem);
×
267
    item->setText(KFunctionName, name);
×
268
    item->setCheckState(KFunctionName, Qt::Unchecked);
×
269
    item->setData(KFunctionName, Qt::UserRole, type);
×
270

271
    if (fxGrpItem != NULL && fxGrpItem->childCount() > 1)
×
272
    {
273
        item->setCheckState(KFunctionOddEven, Qt::Unchecked);
×
274
    }
275
}
276

277
void FunctionWizard::updateAvailableFunctionsTree()
×
278
{
279
    disconnect(m_allFuncsTree, SIGNAL(itemChanged(QTreeWidgetItem*, int)),
×
280
            this, SLOT(slotFunctionItemChanged(QTreeWidgetItem*,int)));
281

282
    m_allFuncsTree->clear();
×
283
    m_resFuncsTree->clear();
×
284

285
    for (int i = 0; i < m_fixtureTree->topLevelItemCount(); i++)
×
286
    {
287
        QTreeWidgetItem *fxGrpItem = m_fixtureTree->topLevelItem(i);
×
288
        Q_ASSERT(fxGrpItem != NULL);
×
289

290
        if (fxGrpItem->childCount() == 0)
×
291
            continue;
×
292

293
        QTreeWidgetItem *grpItem = new QTreeWidgetItem(m_allFuncsTree);
×
294
        grpItem->setText(KFunctionName, fxGrpItem->text(KFixtureColumnName));
×
295
        grpItem->setIcon(KFunctionName, fxGrpItem->icon(KFixtureColumnName));
×
296
        grpItem->setExpanded(true);
×
297

298
        // since groups contain fixture of the same type, get the first
299
        // child and create categories on its capabilities
300
        QTreeWidgetItem *fxItem = fxGrpItem->child(0);
×
301
        quint32 fxID = fxItem->data(KFixtureColumnName, Qt::UserRole).toUInt();
×
302
        Fixture* fxi = m_doc->fixture(fxID);
×
303
        Q_ASSERT(fxi != NULL);
×
304

305
        QStringList caps = PaletteGenerator::getCapabilities(fxi);
×
306

NEW
307
        foreach (QString cap, caps)
×
308
        {
309
            if (cap == KQLCChannelRGB || cap == KQLCChannelCMY)
×
310
            {
311
                addFunctionsGroup(fxGrpItem, grpItem,
×
312
                                  PaletteGenerator::typetoString(PaletteGenerator::PrimaryColors),
×
313
                                  PaletteGenerator::PrimaryColors);
314
                addFunctionsGroup(fxGrpItem, grpItem,
×
315
                                  PaletteGenerator::typetoString(PaletteGenerator::SixteenColors),
×
316
                                  PaletteGenerator::SixteenColors);
317
                addFunctionsGroup(fxGrpItem, grpItem,
×
318
                                  PaletteGenerator::typetoString(PaletteGenerator::Animation),
×
319
                                  PaletteGenerator::Animation);
320
            }
321
            else if (cap == QLCChannel::groupToString(QLCChannel::Gobo))
×
322
                addFunctionsGroup(fxGrpItem, grpItem,
×
323
                                  PaletteGenerator::typetoString(PaletteGenerator::Gobos),
×
324
                                  PaletteGenerator::Gobos);
325
            else if (cap == QLCChannel::groupToString(QLCChannel::Shutter))
×
326
                addFunctionsGroup(fxGrpItem, grpItem,
×
327
                                  PaletteGenerator::typetoString(PaletteGenerator::Shutter),
×
328
                                  PaletteGenerator::Shutter);
329
            else if (cap == QLCChannel::groupToString(QLCChannel::Colour))
×
330
                addFunctionsGroup(fxGrpItem, grpItem,
×
331
                                  PaletteGenerator::typetoString(PaletteGenerator::ColourMacro),
×
332
                                  PaletteGenerator::ColourMacro);
333
        }
334
    }
335

336
    m_allFuncsTree->resizeColumnToContents(KFunctionName);
×
337

338
    connect(m_allFuncsTree, SIGNAL(itemChanged(QTreeWidgetItem*, int)),
×
339
            this, SLOT(slotFunctionItemChanged(QTreeWidgetItem*,int)));
340
}
×
341

342
QTreeWidgetItem *FunctionWizard::getFunctionGroupItem(const Function *func)
×
343
{
344
    for (int i = 0; i < m_resFuncsTree->topLevelItemCount(); i++)
×
345
    {
346
        QTreeWidgetItem *item = m_resFuncsTree->topLevelItem(i);
×
347
        int grpType = item->data(KFunctionName, Qt::UserRole).toInt();
×
348
        if (grpType == func->type())
×
349
            return item;
×
350
    }
351
    // if we're here then the group doesn't exist. Create it
352
    QTreeWidgetItem* newGrp = new QTreeWidgetItem(m_resFuncsTree);
×
353
    newGrp->setText(KFixtureColumnName, Function::typeToString(func->type()));
×
354
    newGrp->setIcon(KFixtureColumnName, func->getIcon());
×
355
    newGrp->setData(KFunctionName, Qt::UserRole, func->type());
×
356
    newGrp->setExpanded(true);
×
357
    return newGrp;
×
358
}
359

360
void FunctionWizard::updateResultFunctionsTree()
×
361
{
362
    m_resFuncsTree->clear();
×
363
    m_paletteList.clear();
×
364

365
    for (int i = 0; i < m_allFuncsTree->topLevelItemCount(); i++)
×
366
    {
367
        QTreeWidgetItem *funcGrpItem = m_allFuncsTree->topLevelItem(i);
×
368
        Q_ASSERT(funcGrpItem != NULL);
×
369

370
        if (funcGrpItem->childCount() == 0)
×
371
            continue;
×
372

373
        // retrieve the list of fixtures involved in this group
374
        QList <Fixture *> fxList;
×
375
        QTreeWidgetItem *fxiGrpItem = m_fixtureTree->topLevelItem(i);
×
376

377
        for (int f = 0; f < fxiGrpItem->childCount(); f++)
×
378
        {
379
            QTreeWidgetItem *fItem = fxiGrpItem->child(f);
×
380
            quint32 fxID = fItem->data(KFixtureColumnName, Qt::UserRole).toUInt();
×
381
            Fixture *fixture = m_doc->fixture(fxID);
×
382
            if (fixture != NULL)
×
383
                fxList.append(fixture);
×
384
        }
385

386
        // iterate through the function group children to see which are checked
387
        for (int c = 0; c < funcGrpItem->childCount(); c++)
×
388
        {
389
            QTreeWidgetItem *funcItem = funcGrpItem->child(c);
×
390
            if (funcItem->checkState(KFunctionName) == Qt::Checked)
×
391
            {
392
                int type = funcItem->data(KFunctionName, Qt::UserRole).toInt();
×
393
                int subType = PaletteGenerator::All;
×
394
                if (funcItem->checkState(KFunctionOddEven) == Qt::Checked)
×
395
                    subType = PaletteGenerator::OddEven;
×
396
                PaletteGenerator *palette = new PaletteGenerator(m_doc, fxList,
397
                                                                 (PaletteGenerator::PaletteType)type,
398
                                                                 (PaletteGenerator::PaletteSubType)subType);
×
399
                m_paletteList.append(palette);
×
400

NEW
401
                foreach (Scene *scene, palette->scenes())
×
402
                {
403
                    QTreeWidgetItem *item = new QTreeWidgetItem(getFunctionGroupItem(scene));
×
404
                    item->setText(KFunctionName, scene->name());
×
405
                    item->setIcon(KFunctionName, scene->getIcon());
×
406
                }
NEW
407
                foreach (Chaser *chaser, palette->chasers())
×
408
                {
409
                    QTreeWidgetItem *item = new QTreeWidgetItem(getFunctionGroupItem(chaser));
×
410
                    item->setText(KFunctionName, chaser->name());
×
411
                    item->setIcon(KFunctionName, chaser->getIcon());
×
412
                }
NEW
413
                foreach (RGBMatrix *matrix, palette->matrices())
×
414
                {
415
                    QTreeWidgetItem *item = new QTreeWidgetItem(getFunctionGroupItem(matrix));
×
416
                    item->setText(KFunctionName, matrix->name());
×
417
                    item->setIcon(KFunctionName, matrix->getIcon());
×
418
                }
419
            }
420
        }
421
    }
422
}
×
423

424
void FunctionWizard::slotFunctionItemChanged(QTreeWidgetItem *item, int col)
×
425
{
426
    Q_UNUSED(col)
427
    Q_UNUSED(item)
428

429
    updateResultFunctionsTree();
×
430

431
    if (m_paletteList.isEmpty() == false)
×
432
        updateWidgetsTree();
×
433

434
    checkTabsAndButtons();
×
435
}
×
436

437
/********************************************************************
438
 * Widgets
439
 ********************************************************************/
440

441
void FunctionWizard::updateWidgetsTree()
×
442
{
443
    m_widgetsTree->clear();
×
444

NEW
445
    foreach (PaletteGenerator *palette, m_paletteList)
×
446
    {
447
        QTreeWidgetItem *frame = new QTreeWidgetItem(m_widgetsTree);
×
448
        frame->setText(KWidgetName, palette->fullName());
×
449
        if (palette->type() == PaletteGenerator::Animation)
×
450
        {
451
            frame->setIcon(KWidgetName, VCWidget::typeToIcon(VCWidget::SoloFrameWidget));
×
452
            frame->setData(KWidgetName, Qt::UserRole, VCWidget::SoloFrameWidget);
×
453
        }
454
        else
455
        {
456
            frame->setIcon(KWidgetName, VCWidget::typeToIcon(VCWidget::FrameWidget));
×
457
            frame->setData(KWidgetName, Qt::UserRole, VCWidget::FrameWidget);
×
458
        }
459
        frame->setData(KWidgetName, Qt::UserRole + 1, QVariant::fromValue((void *)palette));
×
460
        frame->setFlags(frame->flags() | Qt::ItemIsUserCheckable | Qt::ItemIsAutoTristate);
×
461
        frame->setCheckState(KWidgetName, Qt::Unchecked);
×
462

463
        QTreeWidgetItem *soloFrameItem = NULL;
×
464
        if (palette->scenes().count() > 0)
×
465
        {
466
            soloFrameItem = new QTreeWidgetItem(frame);
×
467
            soloFrameItem->setText(KWidgetName, tr("Presets solo frame"));
×
468
            soloFrameItem->setIcon(KWidgetName, VCWidget::typeToIcon(VCWidget::SoloFrameWidget));
×
469
            soloFrameItem->setFlags(soloFrameItem->flags() | Qt::ItemIsUserCheckable | Qt::ItemIsAutoTristate);
×
470
            soloFrameItem->setCheckState(KWidgetName, Qt::Unchecked);
×
471
            soloFrameItem->setData(KWidgetName, Qt::UserRole, VCWidget::SoloFrameWidget);
×
472
        }
NEW
473
        foreach (Scene *scene, palette->scenes())
×
474
        {
475
            QTreeWidgetItem *item = NULL;
×
476
            if (soloFrameItem != NULL)
×
477
                item = new QTreeWidgetItem(soloFrameItem);
×
478
            else
479
                item = new QTreeWidgetItem(frame);
×
480
            QString toRemove = " - " + palette->model();
×
481
            item->setText(KWidgetName, scene->name().remove(toRemove));
×
482
            item->setIcon(KWidgetName, VCWidget::typeToIcon(VCWidget::ButtonWidget));
×
483
            item->setCheckState(KWidgetName, Qt::Unchecked);
×
484
            item->setData(KWidgetName, Qt::UserRole, VCWidget::ButtonWidget);
×
485
            item->setData(KWidgetName, Qt::UserRole + 1, QVariant::fromValue((void *)scene));
×
486

487
        }
NEW
488
        foreach (Chaser *chaser, palette->chasers())
×
489
        {
490
            QTreeWidgetItem *item = new QTreeWidgetItem(frame);
×
491
            QString toRemove = " - " + palette->model();
×
492
            item->setText(KWidgetName, chaser->name().remove(toRemove));
×
493
            item->setIcon(KWidgetName, VCWidget::typeToIcon(VCWidget::CueListWidget));
×
494
            item->setCheckState(KWidgetName, Qt::Unchecked);
×
495
            item->setData(KWidgetName, Qt::UserRole, VCWidget::CueListWidget);
×
496
            item->setData(KWidgetName, Qt::UserRole + 1, QVariant::fromValue((void *)chaser));
×
497
        }
498

NEW
499
        foreach (RGBMatrix *matrix, palette->matrices())
×
500
        {
501
            QTreeWidgetItem *item = NULL;
×
502
            if (soloFrameItem != NULL)
×
503
                item = new QTreeWidgetItem(soloFrameItem);
×
504
            else
505
                item = new QTreeWidgetItem(frame);
×
506
            QString toRemove = " - " + palette->model();
×
507
            item->setText(KWidgetName, matrix->name().remove(toRemove));
×
508
            item->setIcon(KWidgetName, VCWidget::typeToIcon(VCWidget::ButtonWidget));
×
509
            item->setCheckState(KWidgetName, Qt::Unchecked);
×
510
            item->setData(KWidgetName, Qt::UserRole, VCWidget::ButtonWidget);
×
511
            item->setData(KWidgetName, Qt::UserRole + 1, QVariant::fromValue((void *)matrix));
×
512
        }
513

514
        if (palette->scenes().count() > 0)
×
515
        {
516
            int pType = palette->type();
×
517
            QTreeWidgetItem *item = new QTreeWidgetItem(frame);
×
518
            if (pType == PaletteGenerator::PrimaryColors ||
×
519
                pType == PaletteGenerator::SixteenColors)
520
                    item->setText(KWidgetName, tr("Click & Go RGB"));
×
521
            else if (pType == PaletteGenerator::Gobos ||
×
522
                     pType == PaletteGenerator::Shutter ||
×
523
                     pType == PaletteGenerator::ColourMacro)
524
                        item->setText(KWidgetName, tr("Click & Go Macro"));
×
525

526
            item->setIcon(KWidgetName, VCWidget::typeToIcon(VCWidget::SliderWidget));
×
527
            item->setCheckState(KWidgetName, Qt::Unchecked);
×
528
            item->setData(KWidgetName, Qt::UserRole, VCWidget::SliderWidget);
×
529
            Scene *firstScene = palette->scenes().at(0);
×
530
            item->setData(KWidgetName, Qt::UserRole + 1, QVariant::fromValue((void *)firstScene));
×
531
        }
532
    }
533
}
×
534

535
VCWidget *FunctionWizard::createWidget(int type, VCWidget *parent, int xpos, int ypos,
×
536
                                       Function *func, int pType)
537
{
538
    VirtualConsole *vc = VirtualConsole::instance();
×
539
    VCWidget *widget = NULL;
×
540

541
    if (parent == NULL)
×
542
        return NULL;
×
543

544
    switch(type)
×
545
    {
546
        case VCWidget::FrameWidget:
×
547
        {
548
            VCFrame* frame = new VCFrame(parent, m_doc, true);
×
549
            vc->setupWidget(frame, parent);
×
550
            frame->move(QPoint(xpos, ypos));
×
551
            widget = frame;
×
552
        }
553
        break;
×
554
        case VCWidget::SoloFrameWidget:
×
555
        {
556
            VCSoloFrame* frame = new VCSoloFrame(parent, m_doc, true);
×
557
            vc->setupWidget(frame, parent);
×
558
            frame->move(QPoint(xpos, ypos));
×
559
            widget = frame;
×
560
        }
561
        break;
×
562
        case VCWidget::ButtonWidget:
×
563
        {
564
            VCButton* button = new VCButton(parent, m_doc);
×
565
            vc->setupWidget(button, parent);
×
566
            button->move(QPoint(xpos, ypos));
×
567
            if (func != NULL)
×
568
                button->setFunction(func->id());
×
569

570
            widget = button;
×
571
        }
572
        break;
×
573
        case VCWidget::CueListWidget:
×
574
        {
575
            VCCueList* cuelist = new VCCueList(parent, m_doc);
×
576
            vc->setupWidget(cuelist, parent);
×
577
            cuelist->move(QPoint(xpos, ypos));
×
578
            if (func != NULL)
×
579
                cuelist->setChaser(func->id());
×
580
            widget = cuelist;
×
581
        }
582
        break;
×
583
        case VCWidget::SliderWidget:
×
584
        {
585
            VCSlider* slider = new VCSlider(parent, m_doc);
×
586
            vc->setupWidget(slider, parent);
×
587
            slider->move(QPoint(xpos, ypos));
×
588
            if (func != NULL)
×
589
            {
590
                Scene *scene = qobject_cast<Scene*> (func);
×
591
                foreach (SceneValue scv, scene->values())
×
592
                    slider->addLevelChannel(scv.fxi, scv.channel);
×
593

594
                if (pType == PaletteGenerator::PrimaryColors ||
×
595
                    pType == PaletteGenerator::SixteenColors)
596
                        slider->setClickAndGoType(ClickAndGoWidget::RGB);
×
597
                else
598
                    slider->setClickAndGoType(ClickAndGoWidget::Preset);
×
599
                slider->setSliderMode(VCSlider::Level);
×
600
            }
601
            widget = slider;
×
602
        }
603
        break;
×
604
        default:
×
605
        break;
×
606
    }
607

608
    if (widget != NULL && func != NULL)
×
609
    {
610
        if (func->type() == Function::SceneType && type == VCWidget::ButtonWidget)
×
611
        {
612
            Scene *scene = qobject_cast<Scene*> (func);
×
613

614
            if (pType == PaletteGenerator::PrimaryColors ||
×
615
                pType == PaletteGenerator::SixteenColors ||
×
616
                pType == PaletteGenerator::ColourMacro)
617
            {
618
                QColor col = scene->colorValue();
×
619
                if (col.isValid())
×
620
                    widget->setBackgroundColor(col);
×
621
            }
622
            else if (pType == PaletteGenerator::Gobos)
×
623
            {
NEW
624
                foreach (SceneValue scv, scene->values())
×
625
                {
626
                    Fixture *fixture = m_doc->fixture(scv.fxi);
×
627
                    if (fixture == NULL)
×
628
                        continue;
×
629

630
                    const QLCChannel* channel(fixture->channel(scv.channel));
×
631
                    if (channel->group() == QLCChannel::Gobo)
×
632
                    {
633
                        QLCCapability *cap = channel->searchCapability(scv.value);
×
634
                        if (cap->resource(0).isValid())
×
635
                        {
636
                            widget->setBackgroundImage(cap->resource(0).toString());
×
637
                            break;
×
638
                        }
639
                    }
640
                }
641
            }
642
        }
643
    }
644

645
    return widget;
×
646
}
647

648
QSize FunctionWizard::recursiveCreateWidget(QTreeWidgetItem *item, VCWidget *parent, int type)
×
649
{
650
    QSize groupSize(100, 50);
×
651
    int subX = 10, subY = 40;
×
652

653
    for (int c = 0; c < item->childCount(); c++)
×
654
    {
655
        QTreeWidgetItem *childItem = item->child(c);
×
656

657
        if (childItem->checkState(KWidgetName) == Qt::Checked ||
×
658
            childItem->checkState(KWidgetName) == Qt::PartiallyChecked)
×
659
        {
660
            int cType = childItem->data(KWidgetName, Qt::UserRole).toInt();
×
661
            Function *func = (Function *) childItem->data(KWidgetName, Qt::UserRole + 1).value<void *>();
×
662

663
            VCWidget *childWidget = createWidget(cType, parent, subX, subY, func, type);
×
664
            if (childWidget != NULL)
×
665
            {
666
                childWidget->setCaption(childItem->text(KWidgetName));
×
667

668
                if (childItem->childCount() > 0)
×
669
                {
670
                    childWidget->resize(QSize(1000, 1000));
×
671

672
                    QSize size = recursiveCreateWidget(childItem, childWidget, type);
×
673

674
                    childWidget->resize(size);
×
675

676
                }
677

678
                if (subX + childWidget->width() > groupSize.width())
×
679
                    groupSize.setWidth(subX + childWidget->width() + 10);
×
680
                if (subY + childWidget->height() > groupSize.height())
×
681
                    groupSize.setHeight(subY + childWidget->height() + 10);
×
682

683

684
                if (c > 0 && (c + 1)%4 == 0)
×
685
                {
686
                    subX = 10;
×
687
                    subY += childWidget->height() + 10;
×
688
                }
689
                else
690
                    subX += childWidget->width() + 10;
×
691
            }
692
        }
693
    }
694

695
    return groupSize;
×
696
}
697

698

699

700
void FunctionWizard::addWidgetsToVirtualConsole()
×
701
{
702
    int xPos = 10;
×
703
    int yPos = 10;
×
704

705
    VirtualConsole *vc = VirtualConsole::instance();
×
706
    VCFrame *mainFrame = vc->contents();
×
707
    Q_ASSERT(mainFrame != NULL);
×
708

709
    for (int i = 0; i < m_widgetsTree->topLevelItemCount(); i++)
×
710
    {
711
        QTreeWidgetItem *wItem = m_widgetsTree->topLevelItem(i);
×
712

713
        if (wItem->checkState(KWidgetName) == Qt::Checked ||
×
714
            wItem->checkState(KWidgetName) == Qt::PartiallyChecked)
×
715
        {
716
            int wType = wItem->data(KWidgetName, Qt::UserRole).toInt();
×
717
            VCWidget *widget = createWidget(wType, mainFrame, xPos, yPos);
×
718
            if (widget == NULL)
×
719
                continue;
×
720

721
            widget->resize(QSize(1000, 1000));
×
722
            PaletteGenerator *pal = (PaletteGenerator *) wItem->data(KWidgetName, Qt::UserRole + 1).value<void *>();
×
723
            int pType = pal->type();
×
724

725
            widget->setCaption(wItem->text(KWidgetName));
×
726

727
            QSize size = recursiveCreateWidget(wItem, widget, pType);
×
728

729
            widget->resize(size);
×
730
            xPos += widget->width() + 10;
×
731
        }
732
    }
733
}
×
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