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

mcallegari / qlcplus / 40027806002

23 Oct 2026 09:34PM UTC coverage: 36.076% (+0.2%) from 35.891%
40027806002

push

github

mcallegari
engine: add test units for universe split

18801 of 52115 relevant lines covered (36.08%)

42105.94 hits per line

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

0.0
/ui/src/fixturemanager.cpp
1
/*
2
  Q Light Controller
3
  fixturemanager.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 <QXmlStreamReader>
21
#include <QXmlStreamWriter>
22
#include <QTreeWidgetItem>
23
#include <QTextBrowser>
24
#include <QVBoxLayout>
25
#include <QTreeWidget>
26
#include <QScrollArea>
27
#include <QMessageBox>
28
#include <QToolButton>
29
#include <QFileDialog>
30
#include <QTabWidget>
31
#include <QSplitter>
32
#include <QToolBar>
33
#include <QAction>
34
#include <QString>
35
#include <QDebug>
36
#include <QIcon>
37
#include <QMenu>
38
#include <QtGui>
39

40
#include "qlcfixturemode.h"
41
#include "qlcfixturedef.h"
42
#include "qlcchannel.h"
43
#include "qlcfile.h"
44

45
#include "createfixturegroup.h"
46
#include "fixturegroupeditor.h"
47
#include "fixturetreewidget.h"
48
#include "channelsselection.h"
49
#include "addchannelsgroup.h"
50
#include "fixturemanager.h"
51
#include "fixtureremap.h"
52
#include "addrgbpanel.h"
53
#include "addfixture.h"
54
#include "rdmmanager.h"
55
#include "serviceloader.h"
56
#include "qlcrdmservice.h"
57
#include "universe.h"
58
#include "fixture.h"
59
#include "apputil.h"
60
#include "doc.h"
61

62
#define SETTINGS_SPLITTER "fixturemanager/splitterstate"
63

64
// List view column numbers
65
#define KColumnName     0
66
#define KColumnChannels 1
67
#define KColumnAddress  2
68

69
FixtureManager* FixtureManager::s_instance = NULL;
70

71
/*****************************************************************************
72
 * Initialization
73
 *****************************************************************************/
74

75
FixtureManager::FixtureManager(QWidget* parent, Doc* doc)
×
76
    : QWidget(parent)
77
    , m_doc(doc)
×
78
    , m_splitter(NULL)
×
79
    , m_fixtures_tree(NULL)
×
80
    , m_channel_groups_tree(NULL)
×
81
    , m_rdmManager(NULL)
×
82
    , m_tabs(NULL)
×
83
    , m_info(NULL)
×
84
    , m_groupEditor(NULL)
×
85
    , m_currentTabIndex(0)
×
86
    , m_addAction(NULL)
×
87
    , m_addRGBAction(NULL)
×
88
    , m_removeAction(NULL)
×
89
    , m_propertiesAction(NULL)
×
90
    , m_fadeConfigAction(NULL)
×
91
    , m_remapAction(NULL)
×
92
    , m_groupAction(NULL)
×
93
    , m_unGroupAction(NULL)
×
94
    , m_newGroupAction(NULL)
×
95
    , m_moveUpAction(NULL)
×
96
    , m_moveDownAction(NULL)
×
97
    , m_importAction(NULL)
×
98
    , m_exportAction(NULL)
×
99
    , m_groupMenu(NULL)
×
100
{
101
    Q_ASSERT(s_instance == NULL);
×
102
    s_instance = this;
×
103

104
    Q_ASSERT(doc != NULL);
×
105

106
    new QVBoxLayout(this);
×
107
    layout()->setContentsMargins(0, 0, 0, 0);
×
108
    layout()->setSpacing(0);
×
109

110
    initActions();
×
111
    initToolBar();
×
112
    initDataView();
×
113
    updateView();
×
114
    updateChannelsGroupView();
×
115

116
    QTreeWidgetItem* grpItem = m_fixtures_tree->topLevelItem(0);
×
117
    if (grpItem != NULL)
×
118
        grpItem->setExpanded(true);
×
119

120
    /* Connect fixture list change signals from the new document object */
121
    connect(m_doc, SIGNAL(fixtureRemoved(quint32)),
×
122
            this, SLOT(slotFixtureRemoved(quint32)));
123

124
    connect(m_doc, SIGNAL(channelsGroupRemoved(quint32)),
×
125
            this, SLOT(slotChannelsGroupRemoved(quint32)));
126

127
    connect(m_doc, SIGNAL(modeChanged(Doc::Mode)),
×
128
            this, SLOT(slotModeChanged(Doc::Mode)));
129

130
    connect(m_doc, SIGNAL(fixtureGroupRemoved(quint32)),
×
131
            this, SLOT(slotFixtureGroupRemoved(quint32)));
132

133
    connect(m_doc, SIGNAL(fixtureGroupChanged(quint32)),
×
134
            this, SLOT(slotFixtureGroupChanged(quint32)));
135

136
    connect(m_doc, SIGNAL(loaded()),
×
137
            this, SLOT(slotDocLoaded()));
138

139
    slotModeChanged(m_doc->mode());
×
140

141
    QSettings settings;
×
142
    QVariant var = settings.value(SETTINGS_SPLITTER);
×
143
    if (var.isValid() == true)
×
144
        m_splitter->restoreState(var.toByteArray());
×
145
    else
146
        m_splitter->setSizes(QList <int> () << int(this->width() / 2) << int(this->width() / 2));
×
147
}
×
148

149
FixtureManager::~FixtureManager()
×
150
{
151
    QSettings settings;
×
152
    settings.setValue(SETTINGS_SPLITTER, m_splitter->saveState());
×
153
    FixtureManager::s_instance = NULL;
×
154

155
    s_instance = NULL;
×
156
}
×
157

158
FixtureManager* FixtureManager::instance()
×
159
{
160
    return s_instance;
×
161
}
162

163
/*****************************************************************************
164
 * Doc signal handlers
165
 *****************************************************************************/
166

167
void FixtureManager::slotFixtureRemoved(quint32 id)
×
168
{
169
    QList<QTreeWidgetItem*> groupsToDelete;
×
170

171
    for (int i = 0; i < m_fixtures_tree->topLevelItemCount(); i++)
×
172
    {
173
        QTreeWidgetItem* grpItem = m_fixtures_tree->topLevelItem(i);
×
174
        Q_ASSERT(grpItem != NULL);
×
175
        for (int j = 0; j < grpItem->childCount(); j++)
×
176
        {
177
            QTreeWidgetItem* fxiItem = grpItem->child(j);
×
178
            Q_ASSERT(fxiItem != NULL);
×
179
            QVariant var = fxiItem->data(KColumnName, PROP_ID);
×
180
            if (var.isValid() == true && var.toUInt() == id)
×
181
            {
182
                delete fxiItem;
×
183
                break;
×
184
            }
185
        }
×
186
        if (grpItem->childCount() == 0)
×
187
            groupsToDelete << grpItem;
×
188
    }
189
    foreach (QTreeWidgetItem* groupToDelete, groupsToDelete)
×
190
    {
191
        QVariant var = groupToDelete->data(KColumnName, PROP_GROUP);
×
192
        // If the group is a fixture group, delete it from doc.
193
        // If not, it is a universe, just "hide" it from the ui.
194
        if (var.isValid() == true)
×
195
            m_doc->deleteFixtureGroup(groupToDelete->data(KColumnName, PROP_GROUP).toUInt());
×
196
        else
197
            delete groupToDelete;
×
198
    }
×
199
}
×
200

201
void FixtureManager::slotChannelsGroupRemoved(quint32 id)
×
202
{
203
    qDebug() << "Channel group removed: " << id;
×
204
    for (int i = 0; i < m_channel_groups_tree->topLevelItemCount(); i++)
×
205
    {
206
        QTreeWidgetItem* grpItem = m_channel_groups_tree->topLevelItem(i);
×
207
        Q_ASSERT(grpItem != NULL);
×
208
        QVariant var = grpItem->data(KColumnName, PROP_ID);
×
209
        if (var.isValid() == true && var.toUInt() == id)
×
210
            delete grpItem;
×
211
    }
×
212
}
×
213

214
void FixtureManager::slotModeChanged(Doc::Mode mode)
×
215
{
216
    if (mode == Doc::Design)
×
217
    {
218
        int selected = m_fixtures_tree->selectedItems().size();
×
219

220
        QTreeWidgetItem* item = m_fixtures_tree->currentItem();
×
221
        if (item == NULL)
×
222
        {
223
            m_addAction->setEnabled(true);
×
224
            m_addRGBAction->setEnabled(true);
×
225
            m_removeAction->setEnabled(false);
×
226
            m_propertiesAction->setEnabled(false);
×
227
            m_groupAction->setEnabled(false);
×
228
            m_unGroupAction->setEnabled(false);
×
229
            m_importAction->setEnabled(true);
×
230
        }
231
        else if (item->data(KColumnName, PROP_ID).isValid() == true)
×
232
        {
233
            // Fixture selected
234
            m_addAction->setEnabled(true);
×
235
            m_addRGBAction->setEnabled(true);
×
236
            m_removeAction->setEnabled(true);
×
237
            if (selected == 1)
×
238
                m_propertiesAction->setEnabled(true);
×
239
            else
240
                m_propertiesAction->setEnabled(false);
×
241
            m_groupAction->setEnabled(true);
×
242

243
            // Don't allow ungrouping from the "All fixtures" group
244
            if (item->parent()->data(KColumnName, PROP_GROUP).isValid() == true)
×
245
                m_unGroupAction->setEnabled(true);
×
246
            else
247
                m_unGroupAction->setEnabled(false);
×
248
        }
249
        else if (item->data(KColumnName, PROP_GROUP).isValid() == true)
×
250
        {
251
            // Fixture group selected
252
            m_addAction->setEnabled(true);
×
253
            m_addRGBAction->setEnabled(true);
×
254
            m_removeAction->setEnabled(true);
×
255
            m_propertiesAction->setEnabled(false);
×
256
            m_groupAction->setEnabled(false);
×
257
            m_unGroupAction->setEnabled(false);
×
258
        }
259
        else
260
        {
261
            // All fixtures selected
262
            m_addAction->setEnabled(true);
×
263
            m_addRGBAction->setEnabled(true);
×
264
            m_removeAction->setEnabled(false);
×
265
            m_propertiesAction->setEnabled(false);
×
266
            m_groupAction->setEnabled(false);
×
267
            m_unGroupAction->setEnabled(false);
×
268
        }
269
        if (m_doc->fixtures().count() > 0)
×
270
            m_fadeConfigAction->setEnabled(true);
×
271
        else
272
            m_fadeConfigAction->setEnabled(false);
×
273
    }
274
    else
275
    {
276
        m_addAction->setEnabled(false);
×
277
        m_addRGBAction->setEnabled(false);
×
278
        m_removeAction->setEnabled(false);
×
279
        m_propertiesAction->setEnabled(false);
×
280
        m_fadeConfigAction->setEnabled(false);
×
281
        m_groupAction->setEnabled(false);
×
282
        m_unGroupAction->setEnabled(false);
×
283
    }
284
}
×
285

286
void FixtureManager::slotFixtureGroupRemoved(quint32 id)
×
287
{
288
    for (int i = 0; i < m_fixtures_tree->topLevelItemCount(); i++)
×
289
    {
290
        QTreeWidgetItem* item = m_fixtures_tree->topLevelItem(i);
×
291
        Q_ASSERT(item != NULL);
×
292
        QVariant var = item->data(KColumnName, PROP_GROUP);
×
293
        if (var.isValid() && var.toUInt() == id)
×
294
        {
295
            delete item;
×
296
            break;
×
297
        }
298
    }
×
299

300
    updateGroupMenu();
×
301
}
×
302

303
void FixtureManager::slotFixtureGroupChanged(quint32 id)
×
304
{
305
    QTreeWidgetItem* item = m_fixtures_tree->groupItem(id);
×
306
    if (item == NULL)
×
307
        return;
×
308

309
    FixtureGroup* grp = m_doc->fixtureGroup(id);
×
310
    Q_ASSERT(grp != NULL);
×
311
    m_fixtures_tree->updateGroupItem(item, grp);
×
312
    updateGroupMenu();
×
313
}
314

315
void FixtureManager::slotDocLoaded()
×
316
{
317
    slotTabChanged(m_currentTabIndex);
×
318
}
×
319

320
/*****************************************************************************
321
 * Data view
322
 *****************************************************************************/
323

324
void FixtureManager::initDataView()
×
325
{
326
    // Create a splitter to divide list view and text view
327
    m_splitter = new QSplitter(Qt::Horizontal, this);
×
328
    layout()->addWidget(m_splitter);
×
329
    m_splitter->setSizePolicy(QSizePolicy::Expanding,
×
330
                              QSizePolicy::Expanding);
331

332
    QTabWidget *tabs = new QTabWidget(this);
×
333
    m_tabs = tabs;
×
334
    m_splitter->addWidget(tabs);
×
335

336
    /* Create a tree widget to the left part of the splitter */
337
    quint32 treeFlags = FixtureTreeWidget::UniverseNumber |
×
338
                        FixtureTreeWidget::AddressRange |
339
                        FixtureTreeWidget::ShowGroups;
340

341
    m_fixtures_tree = new FixtureTreeWidget(m_doc, treeFlags, this);
×
342
    m_fixtures_tree->setIconSize(QSize(32, 32));
×
343
    m_fixtures_tree->setContextMenuPolicy(Qt::CustomContextMenu);
×
344
    m_fixtures_tree->setSelectionMode(QAbstractItemView::ExtendedSelection);
×
345
    m_fixtures_tree->sortByColumn(KColumnAddress, Qt::AscendingOrder);
×
346

347
    connect(m_fixtures_tree, SIGNAL(itemSelectionChanged()),
×
348
            this, SLOT(slotSelectionChanged()));
349

350
    connect(m_fixtures_tree, SIGNAL(itemDoubleClicked(QTreeWidgetItem*,int)),
×
351
            this, SLOT(slotDoubleClicked(QTreeWidgetItem*)));
352

353
    connect(m_fixtures_tree, SIGNAL(customContextMenuRequested(const QPoint&)),
×
354
            this, SLOT(slotContextMenuRequested(const QPoint&)));
355

356
    connect(m_fixtures_tree, SIGNAL(expanded(QModelIndex)),
×
357
            this, SLOT(slotFixtureItemExpanded()));
358

359
    connect(m_fixtures_tree, SIGNAL(collapsed(QModelIndex)),
×
360
            this, SLOT(slotFixtureItemExpanded()));
361

362
    tabs->addTab(m_fixtures_tree, tr("Fixture Groups"));
×
363

364
    m_channel_groups_tree = new QTreeWidget(this);
×
365
    QStringList chan_labels;
×
366
    chan_labels << tr("Name") << tr("Channels");
×
367
    m_channel_groups_tree->setHeaderLabels(chan_labels);
×
368
    m_channel_groups_tree->setRootIsDecorated(false);
×
369
    m_channel_groups_tree->setAllColumnsShowFocus(true);
×
370
    m_channel_groups_tree->setIconSize(QSize(32, 32));
×
371
    m_channel_groups_tree->setSelectionMode(QAbstractItemView::ExtendedSelection);
×
372

373
    connect(m_channel_groups_tree, SIGNAL(itemSelectionChanged()),
×
374
            this, SLOT(slotChannelsGroupSelectionChanged()));
375
    connect(m_channel_groups_tree, SIGNAL(itemDoubleClicked(QTreeWidgetItem*,int)),
×
376
            this, SLOT(slotChannelsGroupDoubleClicked(QTreeWidgetItem*)));
377

378
    tabs->addTab(m_channel_groups_tree, tr("Channel Groups"));
×
379

380
    // the RDM tab only exists if the RDM service plugin is installed
381
    addRDMTab();
×
382
    connect(m_doc->serviceLoader(), SIGNAL(serviceAvailable(QString)),
×
383
            this, SLOT(slotServiceAvailable(QString)));
384

385
    connect(tabs, SIGNAL(currentChanged(int)), this, SLOT(slotTabChanged(int)));
×
386

387
    /* Create the text view */
388
    createInfo();
×
389

390
    slotSelectionChanged();
×
391
}
×
392

393
void FixtureManager::updateView()
×
394
{
395
    // Record which top level items are open
396
    QList <QVariant> openGroups;
×
397
    for (int i = 0; i < m_fixtures_tree->topLevelItemCount(); i++)
×
398
    {
399
        QTreeWidgetItem* item = m_fixtures_tree->topLevelItem(i);
×
400
        if (item->isExpanded() == true)
×
401
            openGroups << item->data(KColumnName, PROP_GROUP);
×
402
    }
403

404
    if (m_doc->fixtures().count() > 0)
×
405
    {
406
        m_exportAction->setEnabled(true);
×
407
        m_remapAction->setEnabled(true);
×
408
        m_fadeConfigAction->setEnabled(true);
×
409
    }
410
    else
411
    {
412
        m_exportAction->setEnabled(false);
×
413
        m_fadeConfigAction->setEnabled(false);
×
414
        m_remapAction->setEnabled(false);
×
415
    }
416
    m_addRGBAction->setEnabled(true);
×
417
    m_importAction->setEnabled(true);
×
418
    m_moveUpAction->setEnabled(false);
×
419
    m_moveDownAction->setEnabled(false);
×
420

421
    m_fixtures_tree->updateTree();
×
422

423
    // Reopen groups that were open before update
424
    for (int i = 0; i < m_fixtures_tree->topLevelItemCount(); i++)
×
425
    {
426
        QTreeWidgetItem* item = m_fixtures_tree->topLevelItem(i);
×
427
        QVariant var = item->data(KColumnName, PROP_GROUP);
×
428
        if (openGroups.contains(var) == true)
×
429
        {
430
            item->setExpanded(true);
×
431
            openGroups.removeAll(var);
×
432
        }
433
    }
×
434

435
    updateGroupMenu();
×
436
    slotModeChanged(m_doc->mode());
×
437

438
    m_fixtures_tree->header()->resizeSections(QHeaderView::ResizeToContents);
×
439
}
×
440

441
void FixtureManager::updateChannelsGroupView()
×
442
{
443
    quint32 selGroupID = ChannelsGroup::invalidId();
×
444

445
    if (m_channel_groups_tree->selectedItems().size() > 0)
×
446
    {
447
        QTreeWidgetItem *item = m_channel_groups_tree->selectedItems().first();
×
448
        selGroupID = item->data(KColumnName, PROP_ID).toUInt();
×
449
    }
450

451
    if (m_channel_groups_tree->topLevelItemCount() > 0)
×
452
        for (int i = m_channel_groups_tree->topLevelItemCount() - 1; i >= 0; i--)
×
453
            m_channel_groups_tree->takeTopLevelItem(i);
×
454

455
    foreach (ChannelsGroup *grp, m_doc->channelsGroups())
×
456
    {
457
        QTreeWidgetItem *grpItem = new QTreeWidgetItem(m_channel_groups_tree);
×
458
        grpItem->setText(KColumnName, grp->name());
×
459
        grpItem->setData(KColumnName, PROP_ID, grp->id());
×
460
        grpItem->setText(KColumnChannels, QString("%1").arg(grp->getChannels().count()));
×
461
        if (grp->getChannels().count() > 0)
×
462
        {
463
            SceneValue scv = grp->getChannels().at(0);
×
464
            Fixture *fxi = m_doc->fixture(scv.fxi);
×
465
            if (fxi == NULL)
×
466
                continue;
×
467

468
            const QLCChannel *ch = fxi->channel(scv.channel);
×
469
            if (ch != NULL)
×
470
                grpItem->setIcon(KColumnName, ch->getIcon());
×
471
        }
×
472
        if (selGroupID == grp->id())
×
473
            grpItem->setSelected(true);
×
474
    }
×
475
    m_addRGBAction->setEnabled(false);
×
476
    m_propertiesAction->setEnabled(false);
×
477
    m_groupAction->setEnabled(false);
×
478
    m_unGroupAction->setEnabled(false);
×
479
    m_fadeConfigAction->setEnabled(false);
×
480
    m_exportAction->setEnabled(false);
×
481
    m_importAction->setEnabled(false);
×
482
    m_remapAction->setEnabled(false);
×
483

484
    m_channel_groups_tree->header()->resizeSections(QHeaderView::ResizeToContents);
×
485
}
×
486

487
void FixtureManager::updateRDMView()
×
488
{
489
    m_addRGBAction->setEnabled(false);
×
490
    m_propertiesAction->setEnabled(false);
×
491
    m_groupAction->setEnabled(false);
×
492
    m_unGroupAction->setEnabled(false);
×
493
    m_fadeConfigAction->setEnabled(false);
×
494
    m_exportAction->setEnabled(false);
×
495
    m_importAction->setEnabled(false);
×
496
    m_remapAction->setEnabled(false);
×
497
}
×
498

499
void FixtureManager::fixtureSelected(quint32 id)
×
500
{
501
    Fixture* fxi = m_doc->fixture(id);
×
502
    if (fxi == NULL)
×
503
        return;
×
504

505
    if (m_info == NULL)
×
506
        createInfo();
×
507

508
    m_info->setText(QString("%1<BODY>%2</BODY></HTML>")
×
509
                    .arg(fixtureInfoStyleSheetHeader())
×
510
                    .arg(fixtureInfo(fxi)));
×
511

512
    // Enable/disable actions
513
    slotModeChanged(m_doc->mode());
×
514
}
515

516
void FixtureManager::fixtureGroupSelected(FixtureGroup* grp)
×
517
{
518
    QByteArray state = m_splitter->saveState();
×
519

520
    if (m_info != NULL)
×
521
    {
522
        delete m_info;
×
523
        m_info = NULL;
×
524
    }
525

526
    if (m_groupEditor != NULL)
×
527
    {
528
        delete m_groupEditor;
×
529
        m_groupEditor = NULL;
×
530
    }
531

532
    m_groupEditor = new FixtureGroupEditor(grp, m_doc, this);
×
533
    m_splitter->addWidget(m_groupEditor);
×
534

535
    m_splitter->restoreState(state);
×
536
}
×
537

538
void FixtureManager::createInfo()
×
539
{
540
    QByteArray state = m_splitter->saveState();
×
541

542
    if (m_info != NULL)
×
543
    {
544
        delete m_info;
×
545
        m_info = NULL;
×
546
    }
547

548
    if (m_groupEditor != NULL)
×
549
    {
550
        delete m_groupEditor;
×
551
        m_groupEditor = NULL;
×
552
    }
553

554
    m_info = new QTextBrowser(this);
×
555
    m_splitter->addWidget(m_info);
×
556

557
    m_splitter->restoreState(state);
×
558
}
×
559

560
void FixtureManager::slotSelectionChanged()
×
561
{
562
    int selectedCount = m_fixtures_tree->selectedItems().size();
×
563
    if (selectedCount == 1)
×
564
    {
565
        QTreeWidgetItem* item = m_fixtures_tree->selectedItems().first();
×
566
        Q_ASSERT(item != NULL);
×
567

568
        // Set the text view's contents
569
        QVariant fxivar = item->data(KColumnName, PROP_ID);
×
570
        QVariant grpvar = item->data(KColumnName, PROP_GROUP);
×
571
        if (fxivar.isValid() == true)
×
572
        {
573
            // Selected a fixture
574
            fixtureSelected(fxivar.toUInt());
×
575
        }
576
        else if (grpvar.isValid() == true)
×
577
        {
578
            FixtureGroup* grp = m_doc->fixtureGroup(grpvar.toUInt());
×
579
            Q_ASSERT(grp != NULL);
×
580
            fixtureGroupSelected(grp);
×
581
        }
582
        else
583
        {
584
            QString info = "<HTML><BODY>";
×
585
            QString uniName;
×
586
            double totalWeight = 0;
×
587
            int totalPower = 0;
×
588
            QVariant uniID = item->data(KColumnName, PROP_UNIVERSE);
×
589
            if (uniID.isValid() == true)
×
590
                uniName = m_doc->inputOutputMap()->getUniverseNameByID(uniID.toUInt());
×
591

592
            foreach (Fixture *fixture, m_doc->fixtures())
×
593
            {
594
                if (fixture == NULL || fixture->universe() != uniID.toUInt() || fixture->fixtureMode() == NULL)
×
595
                    continue;
×
596

597
                QLCFixtureMode *mode = fixture->fixtureMode();
×
598
                totalWeight += mode->physical().weight();
×
599
                totalPower += mode->physical().powerConsumption();
×
600
            }
×
601

602
            if (m_info == NULL)
×
603
                createInfo();
×
604

605
            info += QString("<H1>%1</H1><P>%2 <B>%3</B></P>")
×
606
                    .arg(uniName).arg(tr("This group contains all fixtures of"))
×
607
                    .arg(uniName);
×
608

609
            info += QString("<BR><P><B>%1</B>: %2Kg<BR><B>%3</B>: %4W</P>")
×
610
                    .arg(tr("Total estimated weight")).arg(QString::number(totalWeight))
×
611
                    .arg(tr("Maximum estimated power consumption")).arg(totalPower);
×
612

613
            info += "</BODY></HTML>";
×
614

615
            m_info->setText(info);
×
616
        }
×
617
    }
×
618
    else
619
    {
620
        // More than one or less than one selected
621
        QString info = "<HTML><BODY>";
×
622
        if (selectedCount > 1)
×
623
        {
624
            // Enable removal of multiple items in design mode
625
            if (m_doc->mode() == Doc::Design)
×
626
            {
627
                double totalWeight = 0;
×
628
                int totalPower = 0;
×
629

630
                info += tr("<H1>Multiple fixtures selected</H1>" \
×
631
                          "<P>Click <IMG SRC=\"" ":/edit_remove.png\">" \
632
                          " to remove the selected fixtures.</P>");
×
633

634
                foreach (QTreeWidgetItem *item, m_fixtures_tree->selectedItems())
×
635
                {
636
                    QVariant fxID = item->data(KColumnName, PROP_ID);
×
637
                    if (fxID.isValid() == false)
×
638
                        continue;
×
639

640
                    Fixture *fixture = m_doc->fixture(fxID.toUInt());
×
641

642
                    if (fixture == NULL || fixture->fixtureMode() == NULL)
×
643
                        continue;
×
644

645
                    QLCFixtureMode *mode = fixture->fixtureMode();
×
646
                    totalWeight += mode->physical().weight();
×
647
                    totalPower += mode->physical().powerConsumption();
×
648
                }
×
649

650
                info += QString("<BR><P><B>%1</B>: %2Kg<BR><B>%3</B>: %4W</P>")
×
651
                        .arg(tr("Total estimated weight")).arg(QString::number(totalWeight))
×
652
                        .arg(tr("Maximum estimated power consumption")).arg(totalPower);
×
653
            }
654
            else
655
            {
656
                info += tr("<H1>Multiple fixtures selected</H1>" \
×
657
                          "<P>Fixture list modification is not permitted" \
658
                          " in operate mode.</P>");
×
659
            }
660
        }
661
        else
662
        {
663
            if (m_fixtures_tree->topLevelItemCount() <= 0)
×
664
            {
665
                info += tr("<H1>No fixtures</H1>" \
×
666
                          "<P>Click <IMG SRC=\"" ":/edit_add.png\">" \
667
                          " to add fixtures.</P>");
×
668
            }
669
            else
670
            {
671
                info += tr("<H1>Nothing selected</H1>" \
×
672
                          "<P>Select a fixture from the list or " \
673
                          "click <IMG SRC=\"" ":/edit_add.png\">" \
674
                          " to add fixtures.</P>");
×
675
            }
676
        }
677
        info += "</BODY></HTML>";
×
678

679
        if (m_info == NULL)
×
680
            createInfo();
×
681
        m_info->setText(info);
×
682
    }
×
683

684
    // Enable/disable actions
685
    slotModeChanged(m_doc->mode());
×
686
}
×
687

688
void FixtureManager::slotChannelsGroupSelectionChanged()
×
689
{
690
    if (m_info == NULL)
×
691
        createInfo();
×
692

693
    int selectedCount = m_channel_groups_tree->selectedItems().size();
×
694

695
    if (selectedCount == 1)
×
696
    {
697
        QTreeWidgetItem* item = m_channel_groups_tree->selectedItems().first();
×
698
        Q_ASSERT(item != NULL);
×
699

700
        // Set the text view's contents
701
        QVariant grpvar = item->data(KColumnName, PROP_ID);
×
702
        if (grpvar.isValid() == true)
×
703
        {
704
            ChannelsGroup *chGroup = m_doc->channelsGroup(grpvar.toUInt());
×
705
            if (chGroup != NULL)
×
706
                m_info->setText(QString("%1<BODY>%2</BODY></HTML>")
×
707
                                .arg(channelsGroupInfoStyleSheetHeader())
×
708
                                .arg(channelsGroupInfo(chGroup)));
×
709
        }
710
        m_removeAction->setEnabled(true);
×
711
        m_propertiesAction->setEnabled(true);
×
712
        int selIdx = m_channel_groups_tree->currentIndex().row();
×
713
        if (selIdx == 0)
×
714
            m_moveUpAction->setEnabled(false);
×
715
        else
716
            m_moveUpAction->setEnabled(true);
×
717
        if (selIdx == m_channel_groups_tree->topLevelItemCount() - 1)
×
718
            m_moveDownAction->setEnabled(false);
×
719
        else
720
            m_moveDownAction->setEnabled(true);
×
721
    }
×
722
    else if (selectedCount > 1)
×
723
    {
724
        m_info->setText(tr("<HTML><BODY><H1>Multiple groups selected</H1>" \
×
725
                  "<P>Click <IMG SRC=\"" ":/edit_remove.png\">" \
726
                  " to remove the selected groups.</P></BODY></HTML>"));
727
        m_removeAction->setEnabled(true);
×
728
        m_propertiesAction->setEnabled(false);
×
729
    }
730
    else
731
    {
732
        m_info->setText(tr("<HTML><BODY><H1>Nothing selected</H1>" \
×
733
                  "<P>Select a channel group from the list or " \
734
                  "click <IMG SRC=\"" ":/edit_add.png\">" \
735
                  " to add a new channels group.</P></BODY></HTML>"));
736
        m_removeAction->setEnabled(false);
×
737
        m_propertiesAction->setEnabled(false);
×
738
    }
739
}
×
740

741
void FixtureManager::slotDoubleClicked(QTreeWidgetItem* item)
×
742
{
743
    if (item != NULL && m_doc->mode() != Doc::Operate)
×
744
        slotProperties();
×
745
}
×
746

747
void FixtureManager::slotChannelsGroupDoubleClicked(QTreeWidgetItem*)
×
748
{
749
    slotChannelsGroupSelectionChanged();
×
750
    editChannelGroupProperties();
×
751
}
×
752

753
void FixtureManager::slotTabChanged(int index)
×
754
{
755
    if (index == 1)
×
756
    {
757
        m_addAction->setToolTip(tr("Add group..."));
×
758
        updateChannelsGroupView();
×
759
        slotChannelsGroupSelectionChanged();
×
760
    }
761
    else if (index == 2)
×
762
    {
763
        m_addAction->setToolTip(tr("Add fixture..."));
×
764
        updateRDMView();
×
765
    }
766
    else
767
    {
768
        m_addAction->setToolTip(tr("Add fixture..."));
×
769
        updateView();
×
770
        slotSelectionChanged();
×
771
    }
772

773
    m_currentTabIndex = index;
×
774
}
×
775

776
void FixtureManager::slotFixtureItemExpanded()
×
777
{
778
    m_fixtures_tree->header()->resizeSections(QHeaderView::ResizeToContents);
×
779
}
×
780

781
void FixtureManager::slotDisplayFixtureInfo(QString &info)
×
782
{
783
    m_info->setText(info);
×
784
}
×
785

786
void FixtureManager::slotServiceAvailable(const QString &id)
×
787
{
788
    if (id == QLCRDM_SERVICE_ID)
×
789
        addRDMTab();
×
790
}
×
791

792
void FixtureManager::addRDMTab()
×
793
{
794
    if (m_rdmManager != NULL || m_tabs == NULL)
×
795
        return;
×
796

797
    QObject *service = m_doc->serviceLoader()->service(QLCRDM_SERVICE_ID);
×
798
    if (service == NULL || qobject_cast<QLCRDMService*>(service) == NULL)
×
799
        return;
×
800

801
    RDMManager *rdm = new RDMManager(this, service);
×
802
    m_rdmManager = rdm;
×
803
    m_tabs->addTab(m_rdmManager, "RDM");
×
804
    connect(rdm, SIGNAL(fixtureInfoReady(QString&)),
×
805
            this, SLOT(slotDisplayFixtureInfo(QString&)));
806
}
807

808
void FixtureManager::selectGroup(quint32 id)
×
809
{
810
    for (int i = 0; i < m_fixtures_tree->topLevelItemCount(); i++)
×
811
    {
812
        QTreeWidgetItem* item = m_fixtures_tree->topLevelItem(i);
×
813
        QVariant var = item->data(KColumnName, PROP_GROUP);
×
814
        if (var.isValid() == false)
×
815
            continue;
×
816

817
        if (var.toUInt() == id)
×
818
        {
819
            m_fixtures_tree->setCurrentItem(item);
×
820
            slotSelectionChanged();
×
821
            break;
×
822
        }
823
    }
×
824
}
×
825

826
QString FixtureManager::fixtureInfoStyleSheetHeader() const
×
827
{
828
    QString info;
×
829

830
    QPalette pal;
×
831
    QColor hlBack(pal.color(QPalette::Highlight));
×
832
    QColor hlText(pal.color(QPalette::HighlightedText));
×
833

834
    info += "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">";
×
835
    info += "<HTML><HEAD></HEAD><STYLE>";
×
836
    info += QString(".hilite {" \
×
837
                    "   background-color: %1;" \
838
                    "   color: %2;" \
839
                    "   font-size: x-large;" \
840
                    "}").arg(hlBack.name()).arg(hlText.name());
×
841
    info += QString(".subhi {" \
×
842
                    "   background-color: %1;" \
843
                    "   color: %2;" \
844
                    "   font-weight: bold;" \
845
                    "}").arg(hlBack.name()).arg(hlText.name());
×
846
    info += QString(".emphasis {" \
×
847
                    "   font-weight: bold;" \
848
                    "}");
×
849
    info += QString(".tiny {"\
×
850
                    "   font-size: small;" \
851
                    "}");
×
852
    info += QString(".author {" \
×
853
                    "   font-weight: light;" \
854
                    "   font-style: italic;" \
855
                    "   text-align: right;" \
856
                    "   font-size: small;"  \
857
                    "}");
×
858
    info += "</STYLE>";
×
859
    return info;
×
860
}
×
861

862
QString FixtureManager::fixtureInfo(const Fixture *fixture) const
×
863
{
864
    QString info;
×
865

866
    QString title("<TR><TD CLASS='hilite' COLSPAN='3'>%1</TD></TR>");
×
867
    QString subTitle("<TR><TD CLASS='subhi' COLSPAN='3'>%1</TD></TR>");
×
868
    QString genInfo("<TR><TD CLASS='emphasis'>%1</TD><TD COLSPAN='2'>%2</TD></TR>");
×
869

870
    /********************************************************************
871
     * General info
872
     ********************************************************************/
873

874
    info += "<TABLE COLS='3' WIDTH='100%'>";
×
875

876
    if (fixture == NULL)
×
877
    {
878
        info += "</TABLE>";
×
879
        return info;
×
880
    }
881

882
    // Fixture title
883
    info += title.arg(fixture->name());
×
884

885
    const QLCFixtureDef* fixtureDef = fixture->fixtureDef();
×
886
    const QLCFixtureMode* fixtureMode = fixture->fixtureMode();
×
887

888
    if (fixtureDef != NULL && fixtureMode != NULL)
×
889
    {
890
        // Manufacturer
891
        info += genInfo.arg(tr("Manufacturer")).arg(fixtureDef->manufacturer());
×
892
        info += genInfo.arg(tr("Model")).arg(fixtureDef->model());
×
893
        info += genInfo.arg(tr("Mode")).arg(fixtureMode->name());
×
894
        info += genInfo.arg(tr("Type")).arg(fixtureDef->typeToString(fixtureDef->type()));
×
895
    }
896

897
    // Universe
898
    info += genInfo.arg(tr("Universe")).arg(fixture->universe() + 1);
×
899

900
    // Address
901
    QString range = QString("%1 - %2").arg(fixture->address() + 1).arg(fixture->address() + fixture->channels());
×
902
    info += genInfo.arg(tr("Address Range")).arg(range);
×
903

904
    // Channels
905
    info += genInfo.arg(tr("Channels")).arg(fixture->channels());
×
906

907
    // Binary address
908
    QString binaryStr = QString("%1").arg(fixture->address() + 1, 10, 2, QChar('0'));
×
909
    QString dipTable("<TABLE COLS='33' cellspacing='0'><TR><TD COLSPAN='33'><IMG SRC=\"" ":/ds_top.png\"></TD></TR>");
×
910
    dipTable += "<TR><TD><IMG SRC=\"" ":/ds_border.png\"></TD><TD><IMG SRC=\"" ":/ds_border.png\"></TD>";
×
911
    for (int i = 9; i >= 0; i--)
×
912
    {
913
        if (binaryStr.at(i) == '0')
×
914
            dipTable += "<TD COLSPAN='3'><IMG SRC=\"" ":/ds_off.png\"></TD>";
×
915
        else
916
            dipTable += "<TD COLSPAN='3'><IMG SRC=\"" ":/ds_on.png\"></TD>";
×
917
    }
918
    dipTable += "<TD><IMG SRC=\"" ":/ds_border.png\"></TD></TR>";
×
919
    dipTable += "<TR><TD COLSPAN='33'><IMG SRC=\"" ":/ds_bottom.png\"></TD></TR>";
×
920
    dipTable += "</TABLE>";
×
921

922
    info += genInfo.arg(tr("Binary Address (DIP)"))
×
923
            .arg(QString("%1").arg(dipTable));
×
924

925
    /********************************************************************
926
     * Channels
927
     ********************************************************************/
928

929
    // Title row
930
    info += QString("<TR><TD CLASS='subhi'>%1</TD>").arg(tr("Channel"));
×
931
    info += QString("<TD CLASS='subhi'>%1</TD>").arg(tr("DMX"));
×
932
    info += QString("<TD CLASS='subhi'>%1</TD></TR>").arg(tr("Name"));
×
933

934
    // Fill table with the fixture's channels
935
    for (quint32 ch = 0; ch < fixture->channels(); ch++)
×
936
    {
937
        QString chInfo("<TR><TD>%1</TD><TD>%2</TD><TD>%3</TD></TR>");
×
938
        info += chInfo.arg(ch + 1).arg(fixture->address() + ch + 1)
×
939
                .arg(fixture->channel(ch)->name());
×
940
    }
×
941

942
    /********************************************************************
943
     * Extended device information
944
     ********************************************************************/
945

946
    if (fixtureMode != NULL)
×
947
    {
948
        const QLCPhysical physical = fixtureMode->physical();
×
949
        info += title.arg(tr("Physical"));
×
950

951
        float mmInch = 0.0393700787;
×
952
        float kgLbs = 2.20462262;
×
953
        QString mm("%1mm (%2\")");
×
954
        QString kg("%1kg (%2 lbs)");
×
955
        QString W("%1W");
×
956
        info += genInfo.arg(tr("Width")).arg(mm.arg(physical.width()))
×
957
                                        .arg(physical.width() * mmInch, 0, 'g', 4);
×
958
        info += genInfo.arg(tr("Height")).arg(mm.arg(physical.height()))
×
959
                                         .arg(physical.height() * mmInch, 0, 'g', 4);
×
960
        info += genInfo.arg(tr("Depth")).arg(mm.arg(physical.depth()))
×
961
                                        .arg(physical.depth() * mmInch, 0, 'g', 4);
×
962
        info += genInfo.arg(tr("Weight")).arg(kg.arg(physical.weight()))
×
963
                                         .arg(physical.weight() * kgLbs, 0, 'g', 4);
×
964
        info += genInfo.arg(tr("Power consumption")).arg(W.arg(physical.powerConsumption()));
×
965
        info += genInfo.arg(tr("DMX Connector")).arg(physical.dmxConnector());
×
966

967
        // Bulb
968
        QString K("%1K");
×
969
        QString lm("%1lm");
×
970
        info += subTitle.arg(tr("Bulb"));
×
971
        info += genInfo.arg(tr("Type")).arg(physical.bulbType());
×
972
        info += genInfo.arg(tr("Luminous Flux")).arg(lm.arg(physical.bulbLumens()));
×
973
        info += genInfo.arg(tr("Colour Temperature")).arg(K.arg(physical.bulbColourTemperature()));
×
974

975
        // Lens
976
        QString angle1("%1&deg;");
×
977
        QString angle2("%1&deg; &ndash; %2&deg;");
×
978

979
        info += subTitle.arg(tr("Lens"));
×
980
        info += genInfo.arg(tr("Name")).arg(physical.lensName());
×
981

982
        if (physical.lensDegreesMin() == physical.lensDegreesMax())
×
983
        {
984
            info += genInfo.arg(tr("Beam Angle"))
×
985
                .arg(angle1.arg(physical.lensDegreesMin()));
×
986
        }
987
        else
988
        {
989
            info += genInfo.arg(tr("Beam Angle"))
×
990
                .arg(angle2.arg(physical.lensDegreesMin())
×
991
                .arg(physical.lensDegreesMax()));
×
992
        }
993

994
        // Focus
995
        QString frange("%1&deg;");
×
996
        info += subTitle.arg(tr("Head(s)"));
×
997
        info += genInfo.arg(tr("Type")).arg(physical.focusType());
×
998
        info += genInfo.arg(tr("Pan Range")).arg(frange.arg(physical.focusPanMax()));
×
999
        info += genInfo.arg(tr("Tilt Range")).arg(frange.arg(physical.focusTiltMax()));
×
1000
        if (physical.layoutSize() != QSize(1, 1))
×
1001
        {
1002
            info += genInfo.arg(tr("Layout"))
×
1003
                           .arg(QString("%1 x %2").arg(physical.layoutSize().width()).arg(physical.layoutSize().height()));
×
1004
        }
1005
    }
×
1006

1007
    // HTML document & table closure
1008
    info += "</TABLE>";
×
1009

1010
    if (fixtureDef != NULL)
×
1011
    {
1012
        info += "<HR>";
×
1013
        info += "<DIV CLASS='author' ALIGN='right'>";
×
1014
        info += tr("Fixture definition author: ") + fixtureDef->author();
×
1015
        info += "</DIV>";
×
1016
    }
1017

1018
    return info;
×
1019
}
×
1020

1021
QString FixtureManager::channelsGroupInfoStyleSheetHeader() const
×
1022
{
1023
    QString info;
×
1024

1025
    QPalette pal;
×
1026
    QColor hlBack(pal.color(QPalette::Highlight));
×
1027
    QColor hlBackSmall(pal.color(QPalette::Shadow));
×
1028
    QColor hlText(pal.color(QPalette::HighlightedText));
×
1029

1030
    info += "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">";
×
1031
    info += "<HTML><HEAD></HEAD><STYLE>";
×
1032
    info += QString(".hilite {" \
×
1033
                    "   background-color: %1;" \
1034
                    "   color: %2;" \
1035
                    "   font-size: x-large;" \
1036
                    "}").arg(hlBack.name()).arg(hlText.name());
×
1037
    info += QString(".subhi {" \
×
1038
                    "   background-color: %1;" \
1039
                    "   color: %2;" \
1040
                    "   font-weight: bold;" \
1041
                    "}").arg(hlBackSmall.name()).arg(hlText.name());
×
1042
    info += QString(".emphasis {" \
×
1043
                    "   font-weight: bold;" \
1044
                    "}");
×
1045
    info += QString(".tiny {"\
×
1046
                    "   font-size: small;" \
1047
                    "}");
×
1048
    info += "</STYLE>";
×
1049
    return info;
×
1050
}
×
1051

1052
QString FixtureManager::channelsGroupInfo(const ChannelsGroup *channelsGroup) const
×
1053
{
1054
    QString info;
×
1055

1056
    info += "<TABLE COLS='3' WIDTH='100%'>";
×
1057

1058
    if (channelsGroup != NULL)
×
1059
    {
1060
        // Fixture title
1061
        const QString title("<TR><TD CLASS='hilite' COLSPAN='3'><CENTER>%1</CENTER></TD></TR>");
×
1062
        info += title.arg(channelsGroup->name());
×
1063

1064
        /********************************************************************
1065
         * Channels
1066
         ********************************************************************/
1067

1068
        // Title row
1069
        info += QString("<TR><TD CLASS='subhi'>%1</TD>").arg(tr("Fixture"));
×
1070
        info += QString("<TD CLASS='subhi'>%1</TD>").arg(tr("Channel"));
×
1071
        info += QString("<TD CLASS='subhi'>%1</TD></TR>").arg(tr("Description"));
×
1072

1073
        foreach (const SceneValue value, channelsGroup->getChannels())
×
1074
        {
1075
            const Fixture *fixture = m_doc->fixture(value.fxi);
×
1076
            if (fixture == NULL)
×
1077
                continue;
×
1078

1079
            const QLCFixtureMode *mode = fixture->fixtureMode();
×
1080
            const QString chInfo("<TR><TD>%1</TD><TD>%2</TD><TD>%3</TD></TR>");
×
1081
            if (mode != NULL)
×
1082
            {
1083
                info += chInfo.arg(fixture->name()).arg(value.channel + 1)
×
1084
                    .arg(mode->channels().at(value.channel)->name());
×
1085
            }
1086
            else
1087
            {
1088
                info += chInfo.arg(fixture->name()).arg(value.channel + 1)
×
1089
                    .arg(QString(tr("Channel %1")).arg(value.channel));
×
1090
            }
1091
        }
×
1092
    }
×
1093

1094
    // HTML document & table closure
1095
    info += "</TABLE>";
×
1096

1097
    return info;
×
1098
}
×
1099

1100
/*****************************************************************************
1101
 * Menu, toolbar and actions
1102
 *****************************************************************************/
1103

1104
void FixtureManager::initActions()
×
1105
{
1106
    // Fixture actions
1107
    m_addAction = new QAction(QIcon(":/edit_add.png"),
×
1108
                              tr("Add fixture..."), this);
×
1109
    connect(m_addAction, SIGNAL(triggered(bool)),
×
1110
            this, SLOT(slotAdd()));
1111

1112
    m_addRGBAction = new QAction(QIcon(":/rgbpanel.png"),
×
1113
                              tr("Add RGB panel..."), this);
×
1114
    connect(m_addRGBAction, SIGNAL(triggered(bool)),
×
1115
            this, SLOT(slotAddRGBPanel()));
1116

1117
    m_removeAction = new QAction(QIcon(":/edit_remove.png"),
×
1118
                                 tr("Delete items"), this);
×
1119
    connect(m_removeAction, SIGNAL(triggered(bool)),
×
1120
            this, SLOT(slotRemove()));
1121

1122
    m_propertiesAction = new QAction(QIcon(":/configure.png"),
×
1123
                                     tr("Properties..."), this);
×
1124
    connect(m_propertiesAction, SIGNAL(triggered(bool)),
×
1125
            this, SLOT(slotProperties()));
1126

1127
    m_fadeConfigAction = new QAction(QIcon(":/fade.png"),
×
1128
                                     tr("Channels Fade Configuration..."), this);
×
1129
    connect(m_fadeConfigAction, SIGNAL(triggered(bool)),
×
1130
            this, SLOT(slotFadeConfig()));
1131

1132
    // Group actions
1133
    m_groupAction = new QAction(QIcon(":/group.png"),
×
1134
                                tr("Add fixture to group..."), this);
×
1135

1136
    m_unGroupAction = new QAction(QIcon(":/ungroup.png"),
×
1137
                                tr("Remove fixture from group"), this);
×
1138
    connect(m_unGroupAction, SIGNAL(triggered(bool)),
×
1139
            this, SLOT(slotUnGroup()));
1140

1141
    m_newGroupAction = new QAction(tr("New Group..."), this);
×
1142

1143
    m_moveUpAction = new QAction(QIcon(":/up.png"),
×
1144
                                 tr("Move channel group up..."), this);
×
1145
    m_moveUpAction->setEnabled(false);
×
1146
    connect(m_moveUpAction, SIGNAL(triggered(bool)),
×
1147
            this, SLOT(slotMoveGroupUp()));
1148

1149
    m_moveDownAction = new QAction(QIcon(":/down.png"),
×
1150
                                 tr("Move channel group down..."), this);
×
1151
    m_moveDownAction->setEnabled(false);
×
1152
    connect(m_moveDownAction, SIGNAL(triggered(bool)),
×
1153
            this, SLOT(slotMoveGroupDown()));
1154

1155
    m_importAction = new QAction(QIcon(":/fileimport.png"),
×
1156
                                 tr("Import fixtures..."), this);
×
1157
    connect(m_importAction, SIGNAL(triggered(bool)),
×
1158
            this, SLOT(slotImport()));
1159

1160
    m_exportAction = new QAction(QIcon(":/fileexport.png"),
×
1161
                                 tr("Export fixtures..."), this);
×
1162

1163
    connect(m_exportAction, SIGNAL(triggered(bool)),
×
1164
            this, SLOT(slotExport()));
1165

1166
    m_remapAction = new QAction(QIcon(":/remap.png"),
×
1167
                               tr("Remap fixtures..."), this);
×
1168
    connect(m_remapAction, SIGNAL(triggered(bool)),
×
1169
            this, SLOT(slotRemap()));
1170
}
×
1171

1172
void FixtureManager::updateGroupMenu()
×
1173
{
1174
    if (m_groupMenu == NULL)
×
1175
    {
1176
        m_groupMenu = new QMenu(this);
×
1177
        connect(m_groupMenu, SIGNAL(triggered(QAction*)),
×
1178
                this, SLOT(slotGroupSelected(QAction*)));
1179
    }
1180

1181
    foreach (QAction* a, m_groupMenu->actions())
×
1182
        m_groupMenu->removeAction(a);
×
1183

1184
    // Put all known fixture groups to the menu
1185
    foreach (FixtureGroup* grp, m_doc->fixtureGroups())
×
1186
    {
1187
        QAction* a = m_groupMenu->addAction(grp->name());
×
1188
        a->setData((qulonglong) grp);
×
1189
    }
×
1190

1191
    // Put a new group action to the group menu
1192
    m_groupMenu->addAction(m_newGroupAction);
×
1193

1194
    // Put the group menu to the group action
1195
    m_groupAction->setMenu(m_groupMenu);
×
1196
}
×
1197

1198
void FixtureManager::initToolBar()
×
1199
{
1200
    QToolBar* toolbar = new QToolBar(tr("Fixture manager"), this);
×
1201
    toolbar->setFloatable(false);
×
1202
    toolbar->setMovable(false);
×
1203
    layout()->setMenuBar(toolbar);
×
1204
    toolbar->addAction(m_addAction);
×
1205
    toolbar->addAction(m_addRGBAction);
×
1206
    toolbar->addAction(m_removeAction);
×
1207
    toolbar->addAction(m_propertiesAction);
×
1208
    toolbar->addAction(m_fadeConfigAction);
×
1209
    toolbar->addSeparator();
×
1210
    toolbar->addAction(m_groupAction);
×
1211
    toolbar->addAction(m_unGroupAction);
×
1212
    toolbar->addSeparator();
×
1213
    toolbar->addAction(m_moveUpAction);
×
1214
    toolbar->addAction(m_moveDownAction);
×
1215
    toolbar->addSeparator();
×
1216
    toolbar->addAction(m_importAction);
×
1217
    toolbar->addAction(m_exportAction);
×
1218
    toolbar->addAction(m_remapAction);
×
1219

1220
    QToolButton* btn = qobject_cast<QToolButton*> (toolbar->widgetForAction(m_groupAction));
×
1221
    Q_ASSERT(btn != NULL);
×
1222
    btn->setPopupMode(QToolButton::InstantPopup);
×
1223
}
×
1224

1225
void FixtureManager::addFixture()
×
1226
{
1227
    AddFixture af(this, m_doc);
×
1228
    if (af.exec() == QDialog::Rejected)
×
1229
        return;
×
1230

1231
    if (af.invalidAddress())
×
1232
    {
1233
        QMessageBox msg(QMessageBox::Critical, tr("Error"),
×
1234
                tr("Please enter a valid address"), QMessageBox::Ok);
×
1235
        msg.exec();
×
1236
        return;
×
1237
    }
×
1238

1239
    quint32 latestFxi = Fixture::invalidId();
×
1240

1241
    QString name = af.name();
×
1242
    quint32 address = af.address();
×
1243
    quint32 universe = af.universe();
×
1244
    quint32 channels = af.channels();
×
1245
    int gap = af.gap();
×
1246

1247
    QLCFixtureDef* fixtureDef = af.fixtureDef();
×
1248
    QLCFixtureMode* mode = af.mode();
×
1249

1250
    FixtureGroup* addToGroup = NULL;
×
1251
    QTreeWidgetItem* current = m_fixtures_tree->currentItem();
×
1252
    if (current != NULL)
×
1253
    {
1254
        if (current->parent() != NULL)
×
1255
        {
1256
            // Fixture selected
1257
            QVariant var = current->parent()->data(KColumnName, PROP_GROUP);
×
1258
            if (var.isValid() == true)
×
1259
                addToGroup = m_doc->fixtureGroup(var.toUInt());
×
1260
        }
×
1261
        else
1262
        {
1263
            // Group selected
1264
            QVariant var = current->data(KColumnName, PROP_GROUP);
×
1265
            if (var.isValid() == true)
×
1266
                addToGroup = m_doc->fixtureGroup(var.toUInt());
×
1267
        }
×
1268
    }
1269

1270
    /* If an empty name was given use the model instead */
1271
    if (name.simplified().isEmpty())
×
1272
    {
1273
        if (fixtureDef != NULL)
×
1274
            name = fixtureDef->model();
×
1275
        else
1276
            name = tr("Generic Dimmer");
×
1277
    }
1278

1279
    /* Add the rest (if any) WITH address gap */
1280
    for (int i = 0; i < af.amount(); i++)
×
1281
    {
1282
        QString modname;
×
1283

1284
        /* If we're adding more than one fixture,
1285
           append a number to the end of the name */
1286
        if (af.amount() > 1)
×
1287
            modname = QString("%1 #%2").arg(name).arg(i + 1, AppUtil::digits(af.amount()), 10, QChar('0'));
×
1288
        else
1289
            modname = name;
×
1290

1291
        /* Create the fixture */
1292
        Fixture* fxi = new Fixture(m_doc);
×
1293

1294
        /* Assign the next address AFTER the previous fixture
1295
           address space plus gap. */
1296
        fxi->setAddress(address + (i * channels) + (i * gap));
×
1297
        fxi->setUniverse(universe);
×
1298
        fxi->setName(modname);
×
1299
        /* Set a fixture definition & mode if they were
1300
           selected. Otherwise create a fixture definition
1301
           and mode for a generic dimmer. */
1302
        if (fixtureDef != NULL && mode != NULL)
×
1303
        {
1304
            fxi->setFixtureDefinition(fixtureDef, mode);
×
1305
        }
1306
        else
1307
        {
1308
            QLCFixtureDef* genericDef = fxi->genericDimmerDef(channels);
×
1309
            QLCFixtureMode* genericMode = fxi->genericDimmerMode(genericDef, channels);
×
1310
            fxi->setFixtureDefinition(genericDef, genericMode);
×
1311
        }
1312

1313
        m_doc->addFixture(fxi);
×
1314
        latestFxi = fxi->id();
×
1315
        if (addToGroup != NULL)
×
1316
            addToGroup->assignFixture(latestFxi);
×
1317
    }
×
1318

1319
    QTreeWidgetItem* selectItem = m_fixtures_tree->fixtureItem(latestFxi);
×
1320
    if (selectItem != NULL)
×
1321
        m_fixtures_tree->setCurrentItem(selectItem);
×
1322

1323
    updateView();
×
1324
}
×
1325

1326
void FixtureManager::addChannelsGroup()
×
1327
{
1328
    ChannelsGroup *group = new ChannelsGroup(m_doc);
×
1329

1330
    AddChannelsGroup cs(this, m_doc, group);
×
1331
    if (cs.exec() == QDialog::Accepted)
×
1332
    {
1333
        qDebug() << "Channels group added. Count: " << group->getChannels().count();
×
1334
        m_doc->addChannelsGroup(group, group->id());
×
1335
        updateChannelsGroupView();
×
1336
    }
1337
    else
1338
        delete group;
×
1339
}
×
1340

1341
void FixtureManager::slotAdd()
×
1342
{
1343
    if (m_currentTabIndex == 1)
×
1344
        addChannelsGroup();
×
1345
    else
1346
        addFixture();
×
1347
}
×
1348

1349
void FixtureManager::slotAddRGBPanel()
×
1350
{
1351
    AddRGBPanel rgb(this, m_doc);
×
1352
    if (rgb.exec() == QDialog::Accepted)
×
1353
    {
1354
        int rows = rgb.rows();
×
1355
        int columns = rgb.columns();
×
1356
        Fixture::Components components = rgb.components();
×
1357

1358
        FixtureGroup *grp = new FixtureGroup(m_doc);
×
1359
        Q_ASSERT(grp != NULL);
×
1360
        grp->setName(rgb.name());
×
1361
        QSize panelSize(columns, rows);
×
1362
        grp->setSize(panelSize);
×
1363
        m_doc->addFixtureGroup(grp);
×
1364
        updateGroupMenu();
×
1365

1366
        int transpose = 0;
×
1367
        if (rgb.direction() == AddRGBPanel::Vertical)
×
1368
        {
1369
            int tmp = columns;
×
1370
            columns = rows;
×
1371
            rows = tmp;
×
1372
            transpose = 1;
×
1373
        }
1374

1375
        QLCFixtureDef *rowDef = NULL;
×
1376
        QLCFixtureMode *rowMode = NULL;
×
1377
        quint32 address = (quint32)rgb.address();
×
1378
        int uniIndex = rgb.universeIndex();
×
1379
        int currRow = 0;
×
1380
        int rowInc = 1;
×
1381
        int xPosStart = 0;
×
1382
        int xPosEnd = columns - 1;
×
1383
        int xPosInc = 1;
×
1384

1385
        quint32 phyWidth = rgb.physicalWidth();
×
1386
        quint32 phyHeight = rgb.physicalHeight() / rows;
×
1387

1388
        if (transpose)
×
1389
        {
1390
            if (rgb.orientation() == AddRGBPanel::TopRight ||
×
1391
                rgb.orientation() == AddRGBPanel::BottomRight)
×
1392
            {
1393
                currRow = rows -1;
×
1394
                rowInc = -1;
×
1395
            }
1396
            if (rgb.orientation() == AddRGBPanel::BottomRight ||
×
1397
                rgb.orientation() == AddRGBPanel::BottomLeft)
×
1398
            {
1399
                xPosStart = columns - 1;
×
1400
                xPosEnd = 0;
×
1401
                xPosInc = -1;
×
1402
            }
1403
        }
1404
        else
1405
        {
1406
            if (rgb.orientation() == AddRGBPanel::BottomLeft ||
×
1407
                rgb.orientation() == AddRGBPanel::BottomRight)
×
1408
            {
1409
                currRow = rows -1;
×
1410
                rowInc = -1;
×
1411
            }
1412
            if (rgb.orientation() == AddRGBPanel::TopRight ||
×
1413
                rgb.orientation() == AddRGBPanel::BottomRight)
×
1414
            {
1415
                xPosStart = columns - 1;
×
1416
                xPosEnd = 0;
×
1417
                xPosInc = -1;
×
1418
            }
1419
        }
1420

1421
        for (int i = 0; i < rows; i++)
×
1422
        {
1423
            Fixture *fxi = new Fixture(m_doc);
×
1424
            Q_ASSERT(fxi != NULL);
×
1425
            fxi->setName(tr("%1 - Row %2").arg(rgb.name()).arg(i + 1));
×
1426
            if (rowDef == NULL)
×
1427
                rowDef = fxi->genericRGBPanelDef(columns, components, rgb.is16Bit());
×
1428
            if (rowMode == NULL)
×
1429
                rowMode = fxi->genericRGBPanelMode(rowDef, components, rgb.is16Bit(), phyWidth, phyHeight);
×
1430
            fxi->setFixtureDefinition(rowDef, rowMode);
×
1431

1432
            // Check universe span
1433
            quint32 rowChannels = fxi->channels();
×
1434
            if (address + rowChannels > 512)
×
1435
            {
1436
                // channels of a single pixel (6 or 8 when 16bit)
1437
                quint32 pixelSize = fxi->heads() > 0 ? rowChannels / fxi->heads() : 1;
×
1438

1439
                switch (rgb.crossUniverse())
×
1440
                {
1441
                    case Fixture::CrossUniverseNone:
×
1442
                        // move the entire row to the next universe.
1443
                        // A row larger than a universe is split by pixel
1444
                        if (rowChannels <= 512)
×
1445
                        {
1446
                            uniIndex++;
×
1447
                            address = 0;
×
1448
                        }
1449
                        else
1450
                        {
1451
                            if (address > 0)
×
1452
                            {
1453
                                uniIndex++;
×
1454
                                address = 0;
×
1455
                            }
1456
                            fxi->setCrossUniverse(Fixture::CrossUniversePixel);
×
1457
                        }
1458
                    break;
×
1459
                    case Fixture::CrossUniversePixel:
×
1460
                        // not even a pixel fits: start from the next universe
1461
                        if (512 - address < pixelSize)
×
1462
                        {
1463
                            uniIndex++;
×
1464
                            address = 0;
×
1465
                        }
1466
                        if (address + rowChannels > 512)
×
1467
                            fxi->setCrossUniverse(Fixture::CrossUniversePixel);
×
1468
                    break;
×
1469
                    case Fixture::CrossUniverseFill:
×
1470
                        fxi->setCrossUniverse(Fixture::CrossUniverseFill);
×
1471
                    break;
×
1472
                }
1473
            }
1474
            if (m_doc->inputOutputMap()->getUniverseID(uniIndex) == m_doc->inputOutputMap()->invalidUniverse())
×
1475
            {
1476
                m_doc->inputOutputMap()->addUniverse();
×
1477
                m_doc->inputOutputMap()->startUniverses();
×
1478
            }
1479

1480
            fxi->setUniverse(m_doc->inputOutputMap()->getUniverseID(uniIndex));
×
1481
            fxi->setAddress(address);
×
1482
            // Doc takes care of adding the universes spanned by a cross-universe fixture
1483
            m_doc->addFixture(fxi, Fixture::invalidId());
×
1484

1485
            // next row starts right after the last channel of this one
1486
            quint32 lastAddress = fxi->channelAddress(rowChannels - 1);
×
1487
            uniIndex += (lastAddress >> 9) - fxi->universe();
×
1488
            address = (lastAddress & 0x01FF) + 1;
×
1489
            if (address >= 512)
×
1490
            {
1491
                address = 0;
×
1492
                uniIndex++;
×
1493
            }
1494

1495
            if (rgb.type() == AddRGBPanel::ZigZag)
×
1496
            {
1497
                int xPos = xPosStart;
×
1498
                for (int h = 0; h < fxi->heads(); h++)
×
1499
                {
1500
                    if (transpose)
×
1501
                        grp->assignHead(QLCPoint(currRow, xPos), GroupHead(fxi->id(), h));
×
1502
                    else
1503
                        grp->assignHead(QLCPoint(xPos, currRow), GroupHead(fxi->id(), h));
×
1504
                    xPos += xPosInc;
×
1505
                }
1506
            }
1507
            else if (rgb.type() == AddRGBPanel::Snake)
×
1508
            {
1509
                if (i%2 == 0)
×
1510
                {
1511
                    int xPos = xPosStart;
×
1512
                    for (int h = 0; h < fxi->heads(); h++)
×
1513
                    {
1514
                        if (transpose)
×
1515
                            grp->assignHead(QLCPoint(currRow, xPos), GroupHead(fxi->id(), h));
×
1516
                        else
1517
                            grp->assignHead(QLCPoint(xPos, currRow), GroupHead(fxi->id(), h));
×
1518
                        xPos += xPosInc;
×
1519
                    }
1520
                }
1521
                else
1522
                {
1523
                    int xPos = xPosEnd;
×
1524
                    for (int h = 0; h < fxi->heads(); h++)
×
1525
                    {
1526
                        if (transpose)
×
1527
                            grp->assignHead(QLCPoint(currRow, xPos), GroupHead(fxi->id(), h));
×
1528
                        else
1529
                            grp->assignHead(QLCPoint(xPos, currRow), GroupHead(fxi->id(), h));
×
1530
                        xPos += (-xPosInc);
×
1531
                    }
1532
                }
1533
            }
1534
            currRow += rowInc;
×
1535
        }
1536

1537
        updateView();
×
1538
        m_doc->setModified();
×
1539
    }
1540
}
×
1541

1542
void FixtureManager::removeFixture()
×
1543
{
1544
    // Ask before deletion
1545
    if (QMessageBox::question(this, tr("Delete Fixtures"),
×
1546
                              tr("Do you want to delete the selected items?"),
×
1547
                              QMessageBox::Yes, QMessageBox::No) == QMessageBox::No)
×
1548
    {
1549
        return;
×
1550
    }
1551

1552
    QListIterator <QTreeWidgetItem*> it(m_fixtures_tree->selectedItems());
×
1553

1554
    // We put items to delete in sets,
1555
    // so no segfault happens when the same fixture is selected twice
1556
    QSet <quint32> groupsToDelete;
×
1557
    QSet <quint32> fixturesToDelete;
×
1558
    while (it.hasNext() == true)
×
1559
    {
1560
        QTreeWidgetItem* item(it.next());
×
1561
        Q_ASSERT(item != NULL);
×
1562

1563
        // Is the item a fixture ?
1564
        QVariant var = item->data(KColumnName, PROP_ID);
×
1565
        if (var.isValid() == true)
×
1566
            fixturesToDelete << var.toUInt();
×
1567
        else
1568
        {
1569
            // Is the item a fixture group ?
1570
            var = item->data(KColumnName, PROP_GROUP);
×
1571
            if (var.isValid() == true)
×
1572
                groupsToDelete << var.toUInt();
×
1573
        }
1574
    }
×
1575

1576
    // delete fixture groups
1577
    foreach (quint32 id, groupsToDelete)
×
1578
        m_doc->deleteFixtureGroup(id);
×
1579

1580
    // delete fixtures
1581
    foreach (quint32 id, fixturesToDelete)
×
1582
    {
1583
        /** @todo This is REALLY bogus here, since Fixture or Doc should do
1584
            this. However, FixtureManager is the only place to destroy fixtures,
1585
            so it's rather safe to reset the fixture's address space here. */
1586
        Fixture* fxi = m_doc->fixture(id);
×
1587
        Q_ASSERT(fxi != NULL);
×
1588
        QList<Universe*> ua = m_doc->inputOutputMap()->claimUniverses();
×
1589
        int universe = fxi->universe();
×
1590
        if (universe < ua.count())
×
1591
            ua[universe]->reset(fxi->address(), fxi->channels());
×
1592
        m_doc->inputOutputMap()->releaseUniverses();
×
1593

1594
        m_doc->deleteFixture(id);
×
1595
    }
×
1596
}
×
1597

1598
void FixtureManager::removeChannelsGroup()
×
1599
{
1600
    // Ask before deletion
1601
    if (QMessageBox::question(this, tr("Delete Channels Group"),
×
1602
                              tr("Do you want to delete the selected groups?"),
×
1603
                              QMessageBox::Yes, QMessageBox::No) == QMessageBox::No)
×
1604
    {
1605
        return;
×
1606
    }
1607

1608
    disconnect(m_channel_groups_tree, SIGNAL(itemSelectionChanged()),
×
1609
            this, SLOT(slotChannelsGroupSelectionChanged()));
1610

1611
    QListIterator <QTreeWidgetItem*> it(m_channel_groups_tree->selectedItems());
×
1612
    while (it.hasNext() == true)
×
1613
    {
1614
        QTreeWidgetItem* item(it.next());
×
1615
        Q_ASSERT(item != NULL);
×
1616

1617
        QVariant var = item->data(KColumnName, PROP_ID);
×
1618
        if (var.isValid() == true)
×
1619
            m_doc->deleteChannelsGroup(var.toUInt());
×
1620
    }
×
1621
    updateChannelsGroupView();
×
1622

1623
    connect(m_channel_groups_tree, SIGNAL(itemSelectionChanged()),
×
1624
            this, SLOT(slotChannelsGroupSelectionChanged()));
1625
}
×
1626

1627
void FixtureManager::slotRemove()
×
1628
{
1629
    if (m_currentTabIndex == 1)
×
1630
        removeChannelsGroup();
×
1631
    else
1632
        removeFixture();
×
1633
}
×
1634

1635
void FixtureManager::editFixtureProperties()
×
1636
{
1637
    QTreeWidgetItem* item = m_fixtures_tree->currentItem();
×
1638
    if (item == NULL)
×
1639
        return;
×
1640

1641
    QVariant var = item->data(KColumnName, PROP_ID);
×
1642
    if (var.isValid() == false)
×
1643
        return;
×
1644

1645
    quint32 id = var.toUInt();
×
1646
    Fixture* fxi = m_doc->fixture(id);
×
1647
    if (fxi == NULL)
×
1648
        return;
×
1649

1650
    QString manuf;
×
1651
    QString model;
×
1652
    QString mode;
×
1653

1654
    if (fxi->fixtureDef() != NULL)
×
1655
    {
1656
        manuf = fxi->fixtureDef()->manufacturer();
×
1657
        model = fxi->fixtureDef()->model();
×
1658
        mode = fxi->fixtureMode()->name();
×
1659
    }
1660

1661
    AddFixture af(this, m_doc, fxi);
×
1662
    af.setWindowTitle(tr("Change fixture properties"));
×
1663
    if (af.exec() == QDialog::Accepted)
×
1664
    {
1665
        if (af.invalidAddress() == false)
×
1666
        {
1667
            bool changed = false;
×
1668

1669
            fxi->blockSignals(true);
×
1670
            if (fxi->name() != af.name())
×
1671
            {
1672
                fxi->setName(af.name());
×
1673
                changed = true;
×
1674
            }
1675
            if (fxi->universe() != af.universe())
×
1676
            {
1677
                fxi->setUniverse(af.universe());
×
1678
                changed = true;
×
1679
            }
1680
            if (fxi->address() != af.address())
×
1681
            {
1682
                fxi->setAddress(af.address());
×
1683
                changed = true;
×
1684
            }
1685
            fxi->blockSignals(false);
×
1686

1687
            if (af.fixtureDef() != NULL && af.mode() != NULL)
×
1688
            {
1689
                if (af.fixtureDef()->manufacturer() == KXMLFixtureGeneric &&
×
1690
                    af.fixtureDef()->model() == KXMLFixtureGeneric)
×
1691
                {
1692
                    if (fxi->channels() != af.channels())
×
1693
                    {
1694
                        QLCFixtureDef* fixtureDef = fxi->genericDimmerDef(af.channels());
×
1695
                        QLCFixtureMode* fixtureMode = fxi->genericDimmerMode(fixtureDef, af.channels());
×
1696
                        fxi->setFixtureDefinition(fixtureDef, fixtureMode);
×
1697
                    }
1698
                }
1699
                else
1700
                {
1701
                    fxi->setFixtureDefinition(af.fixtureDef(), af.mode());
×
1702
                }
1703
            }
1704
            else
1705
            {
1706
                /* Generic dimmer */
1707
                fxi->setFixtureDefinition(NULL, NULL);
×
1708
                fxi->setChannels(af.channels());
×
1709
            }
1710

1711
            // Emit changed signal
1712
            if (changed)
×
1713
                fxi->setID(fxi->id());
×
1714

1715
            updateView();
×
1716
            slotSelectionChanged();
×
1717
        }
1718
        else
1719
        {
1720
            QMessageBox msg(QMessageBox::Critical, tr("Error"),
×
1721
                    tr("Please enter a valid address"), QMessageBox::Ok);
×
1722
            msg.exec();
×
1723
        }
×
1724
    }
1725
}
×
1726

1727
void FixtureManager::editChannelGroupProperties()
×
1728
{
1729
    int selectedCount = m_channel_groups_tree->selectedItems().size();
×
1730

1731
    if (selectedCount > 0)
×
1732
    {
1733
        QTreeWidgetItem* current = m_channel_groups_tree->selectedItems().first();
×
1734
        QVariant var = current->data(KColumnName, PROP_ID);
×
1735
        if (var.isValid() == true)
×
1736
        {
1737
            ChannelsGroup *group = m_doc->channelsGroup(var.toUInt());
×
1738

1739
            AddChannelsGroup cs(this, m_doc, group);
×
1740
            if (cs.exec() == QDialog::Accepted)
×
1741
            {
1742
                qDebug() << "CHANNEL GROUP MODIFIED. Count: " << group->getChannels().count();
×
1743
                m_doc->addChannelsGroup(group, group->id());
×
1744
                updateChannelsGroupView();
×
1745
            }
1746
        }
×
1747
    }
×
1748
}
×
1749

1750
int FixtureManager::headCount(const QList <QTreeWidgetItem*>& items) const
×
1751
{
1752
    int count = 0;
×
1753
    QListIterator <QTreeWidgetItem*> it(items);
×
1754
    while (it.hasNext() == true)
×
1755
    {
1756
        QTreeWidgetItem* item = it.next();
×
1757
        Q_ASSERT(item != NULL);
×
1758

1759
        QVariant var = item->data(KColumnName, PROP_ID);
×
1760
        if (var.isValid() == false)
×
1761
            continue;
×
1762

1763
        Fixture* fxi = m_doc->fixture(var.toUInt());
×
1764
        count += fxi->heads();
×
1765
    }
×
1766

1767
    return count;
×
1768
}
×
1769

1770
void FixtureManager::slotProperties()
×
1771
{
1772
    if (m_currentTabIndex == 1)
×
1773
        editChannelGroupProperties();
×
1774
    else
1775
        editFixtureProperties();
×
1776
}
×
1777

1778
void FixtureManager::slotFadeConfig()
×
1779
{
1780
    ChannelsSelection cfg(m_doc, this, ChannelsSelection::ConfigurationMode);
×
1781
    if (cfg.exec() == QDialog::Rejected)
×
1782
        return; // User pressed cancel
×
1783
    m_doc->setModified();
×
1784
}
×
1785

1786
void FixtureManager::slotRemap()
×
1787
{
1788
    FixtureRemap fxr(m_doc);
×
1789
    if (fxr.exec() == QDialog::Rejected)
×
1790
        return; // User pressed cancel
×
1791

1792
    updateView();
×
1793
}
×
1794

1795
void FixtureManager::slotUnGroup()
×
1796
{
1797
    if (QMessageBox::question(this, tr("Ungroup fixtures?"),
×
1798
                              tr("Do you want to ungroup the selected fixtures?"),
×
1799
                              QMessageBox::Yes, QMessageBox::No) == QMessageBox::No)
×
1800
    {
1801
        return;
×
1802
    }
1803

1804
    // Because FixtureGroup::resignFixture() emits changed(), which makes the tree
1805
    // update its contents in the middle, invalidating m_tree->selectedItems(),
1806
    // we must pick the list of fixtures and groups first and then resign them in
1807
    // one big bunch.
1808
    QList <QPair<quint32,quint32> > resignList;
×
1809

1810
    foreach (QTreeWidgetItem* item, m_fixtures_tree->selectedItems())
×
1811
    {
1812
        if (item->parent() == NULL)
×
1813
            continue;
×
1814

1815
        QVariant var = item->parent()->data(KColumnName, PROP_GROUP);
×
1816
        if (var.isValid() == false)
×
1817
            continue;
×
1818
        quint32 grp = var.toUInt();
×
1819

1820
        var = item->data(KColumnName, PROP_ID);
×
1821
        if (var.isValid() == false)
×
1822
            continue;
×
1823
        quint32 fxi = var.toUInt();
×
1824

1825
        resignList << QPair <quint32,quint32> (grp, fxi);
×
1826
    }
×
1827

1828
    QListIterator <QPair<quint32,quint32> > it(resignList);
×
1829
    while (it.hasNext() == true)
×
1830
    {
1831
        QPair <quint32,quint32> pair(it.next());
×
1832
        FixtureGroup* grp = m_doc->fixtureGroup(pair.first);
×
1833
        Q_ASSERT(grp != NULL);
×
1834
        grp->resignFixture(pair.second);
×
1835
    }
1836
}
×
1837

1838
void FixtureManager::slotGroupSelected(QAction* action)
×
1839
{
1840
    FixtureGroup* grp = NULL;
×
1841

1842
    if (action->data().isValid() == true)
×
1843
    {
1844
        // Existing group selected
1845
        grp = (FixtureGroup*) (action->data().toULongLong());
×
1846
        Q_ASSERT(grp != NULL);
×
1847
    }
1848
    else
1849
    {
1850
        // New Group selected.
1851

1852
        // Suggest an equilateral grid
1853
        qreal side = sqrt(headCount(m_fixtures_tree->selectedItems()));
×
1854
        if (side != floor(side))
×
1855
            side += 1; // Fixture number doesn't provide a full square
×
1856

1857
        CreateFixtureGroup cfg(this);
×
1858
        cfg.setSize(QSize(side, side));
×
1859
        if (cfg.exec() != QDialog::Accepted)
×
1860
            return; // User pressed cancel
×
1861

1862
        grp = new FixtureGroup(m_doc);
×
1863
        Q_ASSERT(grp != NULL);
×
1864
        grp->setName(cfg.name());
×
1865
        grp->setSize(cfg.size());
×
1866
        m_doc->addFixtureGroup(grp);
×
1867
        updateGroupMenu();
×
1868
    }
×
1869

1870
    // Assign selected fixture items to the group
1871
    foreach (QTreeWidgetItem* item, m_fixtures_tree->selectedItems())
×
1872
    {
1873
        QVariant var = item->data(KColumnName, PROP_ID);
×
1874
        if (var.isValid() == false)
×
1875
            continue;
×
1876

1877
        grp->assignFixture(var.toUInt());
×
1878
    }
×
1879

1880
    updateView();
×
1881
}
1882

1883
void FixtureManager::slotMoveGroupUp()
×
1884
{
1885
    if (m_channel_groups_tree->selectedItems().size() > 0)
×
1886
    {
1887
        QTreeWidgetItem* item = m_channel_groups_tree->selectedItems().first();
×
1888
        quint32 grpID = item->data(KColumnName, PROP_ID).toUInt();
×
1889
        m_doc->moveChannelGroup(grpID, -1);
×
1890
        updateChannelsGroupView();
×
1891
    }
1892
}
×
1893

1894
void FixtureManager::slotMoveGroupDown()
×
1895
{
1896
    if (m_channel_groups_tree->selectedItems().size() > 0)
×
1897
    {
1898
        QTreeWidgetItem* item = m_channel_groups_tree->selectedItems().first();
×
1899
        quint32 grpID = item->data(KColumnName, PROP_ID).toUInt();
×
1900
        m_doc->moveChannelGroup(grpID, 1);
×
1901
        updateChannelsGroupView();
×
1902
    }
1903
}
×
1904

1905
QString FixtureManager::createDialog(bool import)
×
1906
{
1907
    QString fileName;
×
1908

1909
    /* Create a file save dialog */
1910
    QFileDialog dialog(this);
×
1911
    if (import == true)
×
1912
    {
1913
        dialog.setWindowTitle(tr("Import Fixtures List"));
×
1914
        dialog.setAcceptMode(QFileDialog::AcceptOpen);
×
1915
    }
1916
    else
1917
    {
1918
        dialog.setWindowTitle(tr("Export Fixtures List As"));
×
1919
        dialog.setAcceptMode(QFileDialog::AcceptSave);
×
1920
    }
1921

1922
    /* Append file filters to the dialog */
1923
    QStringList filters;
×
1924
    filters << tr("Fixtures List (*%1)").arg(KExtFixtureList);
×
1925
#if defined(WIN32) || defined(Q_OS_WIN)
1926
    filters << tr("All Files (*.*)");
1927
#else
1928
    filters << tr("All Files (*)");
×
1929
#endif
1930
    dialog.setNameFilters(filters);
×
1931

1932
    /* Append useful URLs to the dialog */
1933
    QList <QUrl> sidebar;
×
1934
    sidebar.append(QUrl::fromLocalFile(QDir::homePath()));
×
1935
    sidebar.append(QUrl::fromLocalFile(QDir::rootPath()));
×
1936
    dialog.setSidebarUrls(sidebar);
×
1937

1938
    /* Get file name */
1939
    if (dialog.exec() != QDialog::Accepted)
×
1940
        return "";
×
1941

1942
    fileName = dialog.selectedFiles().first();
×
1943
    if (fileName.isEmpty() == true)
×
1944
        return "";
×
1945

1946
    /* Always use the fixture definition suffix */
1947
    if (import == false && fileName.right(5) != KExtFixtureList)
×
1948
        fileName += KExtFixtureList;
×
1949

1950
    return fileName;
×
1951
}
×
1952

1953
void FixtureManager::slotImport()
×
1954
{
1955
    QString fileName = createDialog(true);
×
1956

1957
    QXmlStreamReader *doc = QLCFile::getXMLReader(fileName);
×
1958
    if (doc == NULL || doc->device() == NULL || doc->hasError())
×
1959
    {
1960
        qWarning() << Q_FUNC_INFO << "Unable to read from" << fileName;
×
1961
        return;
×
1962
    }
1963

1964
    while (!doc->atEnd())
×
1965
    {
1966
        if (doc->readNext() == QXmlStreamReader::DTD)
×
1967
            break;
×
1968
    }
1969
    if (doc->hasError())
×
1970
    {
1971
        QLCFile::releaseXMLReader(doc);
×
1972
        return;
×
1973
    }
1974

1975
    if (doc->dtdName() == KXMLQLCFixturesList)
×
1976
    {
1977
        doc->readNextStartElement();
×
1978
        if (doc->name() != KXMLQLCFixturesList)
×
1979
        {
1980
            qWarning() << Q_FUNC_INFO << "Fixture Definition node not found";
×
1981
            QLCFile::releaseXMLReader(doc);
×
1982
            return;
×
1983
        }
1984

1985
        while (doc->readNextStartElement())
×
1986
        {
1987
            if (doc->name() == KXMLFixture)
×
1988
            {
1989
                Fixture* fxi = new Fixture(m_doc);
×
1990
                Q_ASSERT(fxi != NULL);
×
1991

1992
                if (fxi->loadXML(*doc, m_doc, m_doc->fixtureDefCache()) == true)
×
1993
                {
1994
                    if (m_doc->addFixture(fxi /*, fxi->id()*/) == true)
×
1995
                    {
1996
                        /* Success */
1997
                        qWarning() << Q_FUNC_INFO << "Fixture" << fxi->name() << "successfully created.";
×
1998
                    }
1999
                    else
2000
                    {
2001
                        /* Doc is full */
2002
                        qWarning() << Q_FUNC_INFO << "Fixture" << fxi->name() << "cannot be created.";
×
2003
                        delete fxi;
×
2004
                    }
2005
                }
2006
                else
2007
                {
2008
                    qWarning() << Q_FUNC_INFO << "Fixture" << fxi->name() << "cannot be loaded.";
×
2009
                    delete fxi;
×
2010
                }
2011
            }
2012
            else if (doc->name() == KXMLQLCFixtureGroup)
×
2013
            {
2014
                FixtureGroup* grp = new FixtureGroup(m_doc);
×
2015
                Q_ASSERT(grp != NULL);
×
2016

2017
                if (grp->loadXML(*doc) == true)
×
2018
                {
2019
                    m_doc->addFixtureGroup(grp, grp->id());
×
2020
                }
2021
                else
2022
                {
2023
                    qWarning() << Q_FUNC_INFO << "FixtureGroup" << grp->name() << "cannot be loaded.";
×
2024
                    delete grp;
×
2025
                }
2026
            }
2027
            else
2028
            {
2029
                qWarning() << Q_FUNC_INFO << "Unknown label tag:" << doc->name().toString();
×
2030
                doc->skipCurrentElement();
×
2031
            }
2032
        }
2033
        updateView();
×
2034
    }
2035
    QLCFile::releaseXMLReader(doc);
×
2036
}
×
2037

2038
void FixtureManager::slotExport()
×
2039
{
2040
    QString fileName = createDialog(false);
×
2041

2042
    QFile file(fileName);
×
2043
    if (file.open(QIODevice::WriteOnly) == false)
×
2044
        return;
×
2045

2046
    QXmlStreamWriter doc(&file);
×
2047
    doc.setAutoFormatting(true);
×
2048
    doc.setAutoFormattingIndent(1);
×
2049
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
2050
    doc.setCodec("UTF-8");
2051
#endif
2052
    QLCFile::writeXMLHeader(&doc, KXMLQLCFixturesList);
×
2053

2054
    QListIterator <Fixture*> fxit(m_doc->fixtures());
×
2055
    while (fxit.hasNext() == true)
×
2056
    {
2057
        Fixture* fxi(fxit.next());
×
2058
        Q_ASSERT(fxi != NULL);
×
2059
        fxi->saveXML(&doc);
×
2060
    }
2061

2062
    QListIterator <FixtureGroup*>grpit(m_doc->fixtureGroups());
×
2063
    while (grpit.hasNext() == true)
×
2064
    {
2065
        FixtureGroup *fxgrp(grpit.next());
×
2066
        Q_ASSERT(fxgrp != NULL);
×
2067
        fxgrp->saveXML(&doc);
×
2068
    }
2069

2070
    doc.writeEndDocument();
×
2071
    file.close();
×
2072
}
×
2073

2074
void FixtureManager::slotContextMenuRequested(const QPoint&)
×
2075
{
2076
    QMenu menu(this);
×
2077
    menu.addAction(m_addAction);
×
2078
    menu.addAction(m_addRGBAction);
×
2079
    menu.addAction(m_propertiesAction);
×
2080
    menu.addAction(m_removeAction);
×
2081
    menu.addSeparator();
×
2082
    menu.addAction(m_groupAction);
×
2083
    menu.addAction(m_unGroupAction);
×
2084
    menu.exec(QCursor::pos());
×
2085
}
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc