• 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/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
#include <QSettings>
26

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

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

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

52
#define KFunctionName               0
53
#define KFunctionOddEven            1
54

55
#define KWidgetName                 0
56

57
#define SETTINGS_GEOMETRY "functionwizard/geometry"
58

UNCOV
59
FunctionWizard::FunctionWizard(QWidget* parent, Doc* doc)
×
60
    : QDialog(parent)
61
    , m_doc(doc)
×
62
{
63
    Q_ASSERT(doc != NULL);
×
64
    setupUi(this);
×
65

66
    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));";
×
67
    m_wizardLogo->setStyleSheet(trbgSS);
×
68
    m_introText->setStyleSheet(trbgSS);
×
69

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

75
    m_fixtureTree->sortItems(KFixtureColumnName, Qt::AscendingOrder);
×
76

NEW
77
    QSettings settings;
×
NEW
78
    QVariant geometrySettings = settings.value(SETTINGS_GEOMETRY);
×
NEW
79
    if (geometrySettings.isValid() == true)
×
NEW
80
        restoreGeometry(geometrySettings.toByteArray());
×
81

UNCOV
82
    connect(m_nextButton, SIGNAL(clicked()),
×
83
            this, SLOT(slotNextPageClicked()));
84

85
    connect(m_tabWidget, SIGNAL(currentChanged(int)),
×
86
            this, SLOT(slotTabClicked()));
87

88
    checkTabsAndButtons();
×
89
}
×
90

91
FunctionWizard::~FunctionWizard()
×
92
{
NEW
93
    QSettings settings;
×
NEW
94
    settings.setValue(SETTINGS_GEOMETRY, saveGeometry());
×
95

96
    m_paletteList.clear();
×
97
}
×
98

99
void FunctionWizard::slotNextPageClicked()
×
100
{
101
    int newIdx = m_tabWidget->currentIndex() + 1;
×
102
    if (newIdx == 4)
×
103
        return;
×
104

105
    m_tabWidget->setCurrentIndex(newIdx);
×
106
    checkTabsAndButtons();
×
107
}
108

109
void FunctionWizard::slotTabClicked()
×
110
{
111
    checkTabsAndButtons();
×
112
}
×
113

114
void FunctionWizard::accept()
×
115
{
116

117
    foreach (PaletteGenerator *palette, m_paletteList)
×
118
        palette->addToDoc();
×
119

120
    addWidgetsToVirtualConsole();
×
121

122
    m_doc->setModified();
×
123

124
    QDialog::accept();
×
125
}
×
126

127
void FunctionWizard::checkTabsAndButtons()
×
128
{
129
    switch(m_tabWidget->currentIndex())
×
130
    {
131
        case 0:
×
132
        {
133
            m_nextButton->setEnabled(true);
×
134
            m_tabWidget->setTabEnabled(2, false);
×
135
            m_tabWidget->setTabEnabled(3, false);
×
136
        }
137
        break;
×
138
        case 1:
×
139
        {
140
            if (m_allFuncsTree->topLevelItemCount() == 0)
×
141
            {
142
                m_nextButton->setEnabled(false);
×
143
                m_tabWidget->setTabEnabled(2, false);
×
144
            }
145
            else
146
            {
147
                m_nextButton->setEnabled(true);
×
148
                m_tabWidget->setTabEnabled(2, true);
×
149
            }
150
        }
151
        break;
×
152
        case 2:
×
153
        {
154
            if (m_paletteList.isEmpty() == false)
×
155
            {
156
                m_tabWidget->setTabEnabled(3, true);
×
157
                m_nextButton->setEnabled(true);
×
158
            }
159
            else
160
            {
161
                m_tabWidget->setTabEnabled(3, false);
×
162
                m_nextButton->setEnabled(false);
×
163
            }
164
        }
165
        break;
×
166
        case 3:
×
167
            m_nextButton->setEnabled(false);
×
168
        break;
×
169
    }
170
}
×
171

172
/****************************************************************************
173
 * Fixtures
174
 ****************************************************************************/
175

176
QTreeWidgetItem *FunctionWizard::getFixtureGroupItem(QString manufacturer, QString model)
×
177
{
178
    for (int i = 0; i < m_fixtureTree->topLevelItemCount(); i++)
×
179
    {
180
        QTreeWidgetItem *item = m_fixtureTree->topLevelItem(i);
×
181
        if (item->text(KFixtureColumnManufacturer) == manufacturer &&
×
182
            item->text(KFixtureColumnModel) == model)
×
183
                return item;
×
184
    }
185
    // if we're here then the group doesn't exist. Create it
186
    QTreeWidgetItem* newGrp = new QTreeWidgetItem(m_fixtureTree);
×
187
    newGrp->setText(KFixtureColumnName, tr("%1 group").arg(model));
×
188
    newGrp->setIcon(KFixtureColumnName, QIcon(":/group.png"));
×
189
    newGrp->setText(KFixtureColumnManufacturer, manufacturer);
×
190
    newGrp->setText(KFixtureColumnModel, model);
×
191
    newGrp->setExpanded(true);
×
192
    return newGrp;
×
193
}
194

195
void FunctionWizard::addFixture(quint32 fxi_id)
×
196
{
197
    Fixture* fxi = m_doc->fixture(fxi_id);
×
198
    Q_ASSERT(fxi != NULL);
×
199

200
    QStringList caps = PaletteGenerator::getCapabilities(fxi);
×
201

202
    if (caps.join(", ").isEmpty())
×
203
    {
204
        QMessageBox::warning(this, tr("Error"), tr("%1 has no capability supported by this wizard.").arg(fxi->name()));
×
205
        return;
×
206
    }
207
    else
208
    {
209
        QTreeWidgetItem *groupItem = getFixtureGroupItem(fxi->fixtureDef()->manufacturer(), fxi->fixtureDef()->model());
×
210
        Q_ASSERT(groupItem != NULL);
×
211

212
        QTreeWidgetItem* item = new QTreeWidgetItem(groupItem);
×
213
        item->setText(KFixtureColumnName, fxi->name());
×
214
        item->setIcon(KFixtureColumnName, fxi->getIconFromType());
×
215
        item->setData(KFixtureColumnName, Qt::UserRole, fxi_id);
×
216
        item->setText(KFixtureColumnCaps, caps.join(", "));
×
217
    }
218
    m_fixtureTree->resizeColumnToContents(KFixtureColumnName);
×
219
}
220

221
void FunctionWizard::slotAddClicked()
×
222
{
223
    FixtureSelection fs(this, m_doc);
×
224
    fs.setMultiSelection(true);
×
225
    fs.setDisabledFixtures(fixtureIds());
×
226
    if (fs.exec() == QDialog::Accepted)
×
227
    {
228
        QListIterator <quint32> it(fs.selection());
×
229
        while (it.hasNext() == true)
×
230
            addFixture(it.next());
×
231

232
        if (m_fixtureTree->topLevelItemCount() > 0)
×
233
            updateAvailableFunctionsTree();
×
234
    }
235
    checkTabsAndButtons();
×
236
}
×
237

238
void FunctionWizard::slotRemoveClicked()
×
239
{
240
    QListIterator <QTreeWidgetItem*> it(m_fixtureTree->selectedItems());
×
241
    while (it.hasNext() == true)
×
242
        delete it.next();
×
243

244
    checkTabsAndButtons();
×
245
}
×
246

247
QList <quint32> FunctionWizard::fixtureIds() const
×
248
{
249
    QList <quint32> list;
×
250
    for (int i = 0; i < m_fixtureTree->topLevelItemCount(); i++)
×
251
    {
252
        QTreeWidgetItem* item(m_fixtureTree->topLevelItem(i));
×
253
        Q_ASSERT(item != NULL);
×
254

255
        for (int j = 0; j < item->childCount(); j++)
×
256
        {
257
            QTreeWidgetItem *child = item->child(j);
×
258
            Q_ASSERT(child != NULL);
×
259

260
            list << child->data(KFixtureColumnName, Qt::UserRole).toInt();
×
261
        }
262
    }
263

264
    return list;
×
265
}
266

267
/********************************************************************
268
 * Functions
269
 ********************************************************************/
270

271
void FunctionWizard::addFunctionsGroup(QTreeWidgetItem *fxGrpItem, QTreeWidgetItem *grpItem,
×
272
                                       QString name, PaletteGenerator::PaletteType type)
273
{
274
    if (grpItem == NULL)
×
275
        return;
×
276

277
    QTreeWidgetItem *item = new QTreeWidgetItem(grpItem);
×
278
    item->setText(KFunctionName, name);
×
279
    item->setCheckState(KFunctionName, Qt::Unchecked);
×
280
    item->setData(KFunctionName, Qt::UserRole, type);
×
281

282
    if (fxGrpItem != NULL && fxGrpItem->childCount() > 1)
×
283
    {
284
        item->setCheckState(KFunctionOddEven, Qt::Unchecked);
×
285
    }
286
}
287

288
void FunctionWizard::updateAvailableFunctionsTree()
×
289
{
290
    disconnect(m_allFuncsTree, SIGNAL(itemChanged(QTreeWidgetItem*, int)),
×
291
            this, SLOT(slotFunctionItemChanged(QTreeWidgetItem*,int)));
292

293
    m_allFuncsTree->clear();
×
294
    m_resFuncsTree->clear();
×
295

296
    for (int i = 0; i < m_fixtureTree->topLevelItemCount(); i++)
×
297
    {
298
        QTreeWidgetItem *fxGrpItem = m_fixtureTree->topLevelItem(i);
×
299
        Q_ASSERT(fxGrpItem != NULL);
×
300

301
        if (fxGrpItem->childCount() == 0)
×
302
            continue;
×
303

304
        QTreeWidgetItem *grpItem = new QTreeWidgetItem(m_allFuncsTree);
×
305
        grpItem->setText(KFunctionName, fxGrpItem->text(KFixtureColumnName));
×
306
        grpItem->setIcon(KFunctionName, fxGrpItem->icon(KFixtureColumnName));
×
307
        grpItem->setExpanded(true);
×
308

309
        // since groups contain fixture of the same type, get the first
310
        // child and create categories on its capabilities
311
        QTreeWidgetItem *fxItem = fxGrpItem->child(0);
×
312
        quint32 fxID = fxItem->data(KFixtureColumnName, Qt::UserRole).toUInt();
×
313
        Fixture* fxi = m_doc->fixture(fxID);
×
314
        Q_ASSERT(fxi != NULL);
×
315

316
        QStringList caps = PaletteGenerator::getCapabilities(fxi);
×
317

NEW
318
        foreach (QString cap, caps)
×
319
        {
320
            if (cap == KQLCChannelRGB || cap == KQLCChannelCMY)
×
321
            {
322
                addFunctionsGroup(fxGrpItem, grpItem,
×
323
                                  PaletteGenerator::typetoString(PaletteGenerator::PrimaryColors),
×
324
                                  PaletteGenerator::PrimaryColors);
325
                addFunctionsGroup(fxGrpItem, grpItem,
×
326
                                  PaletteGenerator::typetoString(PaletteGenerator::SixteenColors),
×
327
                                  PaletteGenerator::SixteenColors);
328
                addFunctionsGroup(fxGrpItem, grpItem,
×
329
                                  PaletteGenerator::typetoString(PaletteGenerator::Animation),
×
330
                                  PaletteGenerator::Animation);
331
            }
332
            else if (cap == QLCChannel::groupToString(QLCChannel::Gobo))
×
333
                addFunctionsGroup(fxGrpItem, grpItem,
×
334
                                  PaletteGenerator::typetoString(PaletteGenerator::Gobos),
×
335
                                  PaletteGenerator::Gobos);
336
            else if (cap == QLCChannel::groupToString(QLCChannel::Shutter))
×
337
                addFunctionsGroup(fxGrpItem, grpItem,
×
338
                                  PaletteGenerator::typetoString(PaletteGenerator::Shutter),
×
339
                                  PaletteGenerator::Shutter);
340
            else if (cap == QLCChannel::groupToString(QLCChannel::Colour))
×
341
                addFunctionsGroup(fxGrpItem, grpItem,
×
342
                                  PaletteGenerator::typetoString(PaletteGenerator::ColourMacro),
×
343
                                  PaletteGenerator::ColourMacro);
344
        }
345
    }
346

347
    m_allFuncsTree->resizeColumnToContents(KFunctionName);
×
348

349
    connect(m_allFuncsTree, SIGNAL(itemChanged(QTreeWidgetItem*, int)),
×
350
            this, SLOT(slotFunctionItemChanged(QTreeWidgetItem*,int)));
351
}
×
352

353
QTreeWidgetItem *FunctionWizard::getFunctionGroupItem(const Function *func)
×
354
{
355
    for (int i = 0; i < m_resFuncsTree->topLevelItemCount(); i++)
×
356
    {
357
        QTreeWidgetItem *item = m_resFuncsTree->topLevelItem(i);
×
358
        int grpType = item->data(KFunctionName, Qt::UserRole).toInt();
×
359
        if (grpType == func->type())
×
360
            return item;
×
361
    }
362
    // if we're here then the group doesn't exist. Create it
363
    QTreeWidgetItem* newGrp = new QTreeWidgetItem(m_resFuncsTree);
×
364
    newGrp->setText(KFixtureColumnName, Function::typeToString(func->type()));
×
365
    newGrp->setIcon(KFixtureColumnName, func->getIcon());
×
366
    newGrp->setData(KFunctionName, Qt::UserRole, func->type());
×
367
    newGrp->setExpanded(true);
×
368
    return newGrp;
×
369
}
370

371
void FunctionWizard::updateResultFunctionsTree()
×
372
{
373
    m_resFuncsTree->clear();
×
374
    m_paletteList.clear();
×
375

376
    for (int i = 0; i < m_allFuncsTree->topLevelItemCount(); i++)
×
377
    {
378
        QTreeWidgetItem *funcGrpItem = m_allFuncsTree->topLevelItem(i);
×
379
        Q_ASSERT(funcGrpItem != NULL);
×
380

381
        if (funcGrpItem->childCount() == 0)
×
382
            continue;
×
383

384
        // retrieve the list of fixtures involved in this group
385
        QList <Fixture *> fxList;
×
386
        QTreeWidgetItem *fxiGrpItem = m_fixtureTree->topLevelItem(i);
×
387

388
        for (int f = 0; f < fxiGrpItem->childCount(); f++)
×
389
        {
390
            QTreeWidgetItem *fItem = fxiGrpItem->child(f);
×
391
            quint32 fxID = fItem->data(KFixtureColumnName, Qt::UserRole).toUInt();
×
392
            Fixture *fixture = m_doc->fixture(fxID);
×
393
            if (fixture != NULL)
×
394
                fxList.append(fixture);
×
395
        }
396

397
        // iterate through the function group children to see which are checked
398
        for (int c = 0; c < funcGrpItem->childCount(); c++)
×
399
        {
400
            QTreeWidgetItem *funcItem = funcGrpItem->child(c);
×
401
            if (funcItem->checkState(KFunctionName) == Qt::Checked)
×
402
            {
403
                int type = funcItem->data(KFunctionName, Qt::UserRole).toInt();
×
404
                int subType = PaletteGenerator::All;
×
405
                if (funcItem->checkState(KFunctionOddEven) == Qt::Checked)
×
406
                    subType = PaletteGenerator::OddEven;
×
407
                PaletteGenerator *palette = new PaletteGenerator(m_doc, fxList,
408
                                                                 (PaletteGenerator::PaletteType)type,
409
                                                                 (PaletteGenerator::PaletteSubType)subType);
×
410
                m_paletteList.append(palette);
×
411

NEW
412
                foreach (Scene *scene, palette->scenes())
×
413
                {
414
                    QTreeWidgetItem *item = new QTreeWidgetItem(getFunctionGroupItem(scene));
×
415
                    item->setText(KFunctionName, scene->name());
×
416
                    item->setIcon(KFunctionName, scene->getIcon());
×
417
                }
NEW
418
                foreach (Chaser *chaser, palette->chasers())
×
419
                {
420
                    QTreeWidgetItem *item = new QTreeWidgetItem(getFunctionGroupItem(chaser));
×
421
                    item->setText(KFunctionName, chaser->name());
×
422
                    item->setIcon(KFunctionName, chaser->getIcon());
×
423
                }
NEW
424
                foreach (RGBMatrix *matrix, palette->matrices())
×
425
                {
426
                    QTreeWidgetItem *item = new QTreeWidgetItem(getFunctionGroupItem(matrix));
×
427
                    item->setText(KFunctionName, matrix->name());
×
428
                    item->setIcon(KFunctionName, matrix->getIcon());
×
429
                }
430
            }
431
        }
432
    }
433
}
×
434

435
void FunctionWizard::slotFunctionItemChanged(QTreeWidgetItem *item, int col)
×
436
{
437
    Q_UNUSED(col)
438
    Q_UNUSED(item)
439

440
    updateResultFunctionsTree();
×
441

442
    if (m_paletteList.isEmpty() == false)
×
443
        updateWidgetsTree();
×
444

445
    checkTabsAndButtons();
×
446
}
×
447

448
/********************************************************************
449
 * Widgets
450
 ********************************************************************/
451

452
void FunctionWizard::updateWidgetsTree()
×
453
{
454
    m_widgetsTree->clear();
×
455

NEW
456
    foreach (PaletteGenerator *palette, m_paletteList)
×
457
    {
458
        QTreeWidgetItem *frame = new QTreeWidgetItem(m_widgetsTree);
×
459
        frame->setText(KWidgetName, palette->fullName());
×
460
        if (palette->type() == PaletteGenerator::Animation)
×
461
        {
462
            frame->setIcon(KWidgetName, VCWidget::typeToIcon(VCWidget::SoloFrameWidget));
×
463
            frame->setData(KWidgetName, Qt::UserRole, VCWidget::SoloFrameWidget);
×
464
        }
465
        else
466
        {
467
            frame->setIcon(KWidgetName, VCWidget::typeToIcon(VCWidget::FrameWidget));
×
468
            frame->setData(KWidgetName, Qt::UserRole, VCWidget::FrameWidget);
×
469
        }
470
        frame->setData(KWidgetName, Qt::UserRole + 1, QVariant::fromValue((void *)palette));
×
471
        frame->setFlags(frame->flags() | Qt::ItemIsUserCheckable | Qt::ItemIsAutoTristate);
×
472
        frame->setCheckState(KWidgetName, Qt::Unchecked);
×
473

474
        QTreeWidgetItem *soloFrameItem = NULL;
×
475
        if (palette->scenes().count() > 0)
×
476
        {
477
            soloFrameItem = new QTreeWidgetItem(frame);
×
478
            soloFrameItem->setText(KWidgetName, tr("Presets solo frame"));
×
479
            soloFrameItem->setIcon(KWidgetName, VCWidget::typeToIcon(VCWidget::SoloFrameWidget));
×
480
            soloFrameItem->setFlags(soloFrameItem->flags() | Qt::ItemIsUserCheckable | Qt::ItemIsAutoTristate);
×
481
            soloFrameItem->setCheckState(KWidgetName, Qt::Unchecked);
×
482
            soloFrameItem->setData(KWidgetName, Qt::UserRole, VCWidget::SoloFrameWidget);
×
483
        }
NEW
484
        foreach (Scene *scene, palette->scenes())
×
485
        {
486
            QTreeWidgetItem *item = NULL;
×
487
            if (soloFrameItem != NULL)
×
488
                item = new QTreeWidgetItem(soloFrameItem);
×
489
            else
490
                item = new QTreeWidgetItem(frame);
×
491
            QString toRemove = " - " + palette->model();
×
492
            item->setText(KWidgetName, scene->name().remove(toRemove));
×
493
            item->setIcon(KWidgetName, VCWidget::typeToIcon(VCWidget::ButtonWidget));
×
494
            item->setCheckState(KWidgetName, Qt::Unchecked);
×
495
            item->setData(KWidgetName, Qt::UserRole, VCWidget::ButtonWidget);
×
496
            item->setData(KWidgetName, Qt::UserRole + 1, QVariant::fromValue((void *)scene));
×
497

498
        }
NEW
499
        foreach (Chaser *chaser, palette->chasers())
×
500
        {
501
            QTreeWidgetItem *item = new QTreeWidgetItem(frame);
×
502
            QString toRemove = " - " + palette->model();
×
503
            item->setText(KWidgetName, chaser->name().remove(toRemove));
×
504
            item->setIcon(KWidgetName, VCWidget::typeToIcon(VCWidget::CueListWidget));
×
505
            item->setCheckState(KWidgetName, Qt::Unchecked);
×
506
            item->setData(KWidgetName, Qt::UserRole, VCWidget::CueListWidget);
×
507
            item->setData(KWidgetName, Qt::UserRole + 1, QVariant::fromValue((void *)chaser));
×
508
        }
509

NEW
510
        foreach (RGBMatrix *matrix, palette->matrices())
×
511
        {
512
            QTreeWidgetItem *item = NULL;
×
513
            if (soloFrameItem != NULL)
×
514
                item = new QTreeWidgetItem(soloFrameItem);
×
515
            else
516
                item = new QTreeWidgetItem(frame);
×
517
            QString toRemove = " - " + palette->model();
×
518
            item->setText(KWidgetName, matrix->name().remove(toRemove));
×
519
            item->setIcon(KWidgetName, VCWidget::typeToIcon(VCWidget::ButtonWidget));
×
520
            item->setCheckState(KWidgetName, Qt::Unchecked);
×
521
            item->setData(KWidgetName, Qt::UserRole, VCWidget::ButtonWidget);
×
522
            item->setData(KWidgetName, Qt::UserRole + 1, QVariant::fromValue((void *)matrix));
×
523
        }
524

525
        if (palette->scenes().count() > 0)
×
526
        {
527
            int pType = palette->type();
×
528
            QTreeWidgetItem *item = new QTreeWidgetItem(frame);
×
529
            if (pType == PaletteGenerator::PrimaryColors ||
×
530
                pType == PaletteGenerator::SixteenColors)
531
                    item->setText(KWidgetName, tr("Click & Go RGB"));
×
532
            else if (pType == PaletteGenerator::Gobos ||
×
533
                     pType == PaletteGenerator::Shutter ||
×
534
                     pType == PaletteGenerator::ColourMacro)
535
                        item->setText(KWidgetName, tr("Click & Go Macro"));
×
536

537
            item->setIcon(KWidgetName, VCWidget::typeToIcon(VCWidget::SliderWidget));
×
538
            item->setCheckState(KWidgetName, Qt::Unchecked);
×
539
            item->setData(KWidgetName, Qt::UserRole, VCWidget::SliderWidget);
×
540
            Scene *firstScene = palette->scenes().at(0);
×
541
            item->setData(KWidgetName, Qt::UserRole + 1, QVariant::fromValue((void *)firstScene));
×
542
        }
543
    }
544
}
×
545

546
VCWidget *FunctionWizard::createWidget(int type, VCWidget *parent, int xpos, int ypos,
×
547
                                       Function *func, int pType)
548
{
549
    VirtualConsole *vc = VirtualConsole::instance();
×
550
    VCWidget *widget = NULL;
×
551

552
    if (parent == NULL)
×
553
        return NULL;
×
554

555
    switch(type)
×
556
    {
557
        case VCWidget::FrameWidget:
×
558
        {
559
            VCFrame* frame = new VCFrame(parent, m_doc, true);
×
560
            vc->setupWidget(frame, parent);
×
561
            frame->move(QPoint(xpos, ypos));
×
562
            widget = frame;
×
563
        }
564
        break;
×
565
        case VCWidget::SoloFrameWidget:
×
566
        {
567
            VCSoloFrame* frame = new VCSoloFrame(parent, m_doc, true);
×
568
            vc->setupWidget(frame, parent);
×
569
            frame->move(QPoint(xpos, ypos));
×
570
            widget = frame;
×
571
        }
572
        break;
×
573
        case VCWidget::ButtonWidget:
×
574
        {
575
            VCButton* button = new VCButton(parent, m_doc);
×
576
            vc->setupWidget(button, parent);
×
577
            button->move(QPoint(xpos, ypos));
×
578
            if (func != NULL)
×
579
                button->setFunction(func->id());
×
580

581
            widget = button;
×
582
        }
583
        break;
×
584
        case VCWidget::CueListWidget:
×
585
        {
586
            VCCueList* cuelist = new VCCueList(parent, m_doc);
×
587
            vc->setupWidget(cuelist, parent);
×
588
            cuelist->move(QPoint(xpos, ypos));
×
589
            if (func != NULL)
×
590
                cuelist->setChaser(func->id());
×
591
            widget = cuelist;
×
592
        }
593
        break;
×
594
        case VCWidget::SliderWidget:
×
595
        {
596
            VCSlider* slider = new VCSlider(parent, m_doc);
×
597
            vc->setupWidget(slider, parent);
×
598
            slider->move(QPoint(xpos, ypos));
×
599
            if (func != NULL)
×
600
            {
601
                Scene *scene = qobject_cast<Scene*> (func);
×
602
                foreach (SceneValue scv, scene->values())
×
603
                    slider->addLevelChannel(scv.fxi, scv.channel);
×
604

605
                if (pType == PaletteGenerator::PrimaryColors ||
×
606
                    pType == PaletteGenerator::SixteenColors)
607
                        slider->setClickAndGoType(ClickAndGoWidget::RGB);
×
608
                else
609
                    slider->setClickAndGoType(ClickAndGoWidget::Preset);
×
610
                slider->setSliderMode(VCSlider::Level);
×
611
            }
612
            widget = slider;
×
613
        }
614
        break;
×
615
        default:
×
616
        break;
×
617
    }
618

619
    if (widget != NULL && func != NULL)
×
620
    {
621
        if (func->type() == Function::SceneType && type == VCWidget::ButtonWidget)
×
622
        {
623
            Scene *scene = qobject_cast<Scene*> (func);
×
624

625
            if (pType == PaletteGenerator::PrimaryColors ||
×
626
                pType == PaletteGenerator::SixteenColors ||
×
627
                pType == PaletteGenerator::ColourMacro)
628
            {
629
                QColor col = scene->colorValue();
×
630
                if (col.isValid())
×
631
                    widget->setBackgroundColor(col);
×
632
            }
633
            else if (pType == PaletteGenerator::Gobos)
×
634
            {
NEW
635
                foreach (SceneValue scv, scene->values())
×
636
                {
637
                    Fixture *fixture = m_doc->fixture(scv.fxi);
×
638
                    if (fixture == NULL)
×
639
                        continue;
×
640

641
                    const QLCChannel* channel(fixture->channel(scv.channel));
×
642
                    if (channel->group() == QLCChannel::Gobo)
×
643
                    {
644
                        QLCCapability *cap = channel->searchCapability(scv.value);
×
645
                        if (cap->resource(0).isValid())
×
646
                        {
647
                            widget->setBackgroundImage(cap->resource(0).toString());
×
648
                            break;
×
649
                        }
650
                    }
651
                }
652
            }
653
        }
654
    }
655

656
    return widget;
×
657
}
658

659
QSize FunctionWizard::recursiveCreateWidget(QTreeWidgetItem *item, VCWidget *parent, int type)
×
660
{
661
    QSize groupSize(100, 50);
×
662
    int subX = 10, subY = 40;
×
663

664
    for (int c = 0; c < item->childCount(); c++)
×
665
    {
666
        QTreeWidgetItem *childItem = item->child(c);
×
667

668
        if (childItem->checkState(KWidgetName) == Qt::Checked ||
×
669
            childItem->checkState(KWidgetName) == Qt::PartiallyChecked)
×
670
        {
671
            int cType = childItem->data(KWidgetName, Qt::UserRole).toInt();
×
672
            Function *func = (Function *) childItem->data(KWidgetName, Qt::UserRole + 1).value<void *>();
×
673

674
            VCWidget *childWidget = createWidget(cType, parent, subX, subY, func, type);
×
675
            if (childWidget != NULL)
×
676
            {
677
                childWidget->setCaption(childItem->text(KWidgetName));
×
678

679
                if (childItem->childCount() > 0)
×
680
                {
681
                    childWidget->resize(QSize(1000, 1000));
×
682

683
                    QSize size = recursiveCreateWidget(childItem, childWidget, type);
×
684

685
                    childWidget->resize(size);
×
686

687
                }
688

689
                if (subX + childWidget->width() > groupSize.width())
×
690
                    groupSize.setWidth(subX + childWidget->width() + 10);
×
691
                if (subY + childWidget->height() > groupSize.height())
×
692
                    groupSize.setHeight(subY + childWidget->height() + 10);
×
693

694

695
                if (c > 0 && (c + 1)%4 == 0)
×
696
                {
697
                    subX = 10;
×
698
                    subY += childWidget->height() + 10;
×
699
                }
700
                else
701
                    subX += childWidget->width() + 10;
×
702
            }
703
        }
704
    }
705

706
    return groupSize;
×
707
}
708

709

710

711
void FunctionWizard::addWidgetsToVirtualConsole()
×
712
{
713
    int xPos = 10;
×
714
    int yPos = 10;
×
715

716
    VirtualConsole *vc = VirtualConsole::instance();
×
717
    VCFrame *mainFrame = vc->contents();
×
718
    Q_ASSERT(mainFrame != NULL);
×
719

720
    for (int i = 0; i < m_widgetsTree->topLevelItemCount(); i++)
×
721
    {
722
        QTreeWidgetItem *wItem = m_widgetsTree->topLevelItem(i);
×
723

724
        if (wItem->checkState(KWidgetName) == Qt::Checked ||
×
725
            wItem->checkState(KWidgetName) == Qt::PartiallyChecked)
×
726
        {
727
            int wType = wItem->data(KWidgetName, Qt::UserRole).toInt();
×
728
            VCWidget *widget = createWidget(wType, mainFrame, xPos, yPos);
×
729
            if (widget == NULL)
×
730
                continue;
×
731

732
            widget->resize(QSize(1000, 1000));
×
733
            PaletteGenerator *pal = (PaletteGenerator *) wItem->data(KWidgetName, Qt::UserRole + 1).value<void *>();
×
734
            int pType = pal->type();
×
735

736
            widget->setCaption(wItem->text(KWidgetName));
×
737

738
            QSize size = recursiveCreateWidget(wItem, widget, pType);
×
739

740
            widget->resize(size);
×
741
            xPos += widget->width() + 10;
×
742
        }
743
    }
UNCOV
744
}
×
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