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

mcallegari / qlcplus / 13633248611

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

push

github

web-flow
actions: add chrpath to profile

14689 of 46089 relevant lines covered (31.87%)

26426.11 hits per line

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

0.0
/ui/src/fixturegroupeditor.cpp
1
/*
2
  Q Light Controller
3
  fixturegroupeditor.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 <QTableWidgetItem>
21
#include <QTableWidget>
22
#include <QSettings>
23
#include <QLineEdit>
24
#include <QSpinBox>
25
#include <QDebug>
26

27
#include "fixturegroupeditor.h"
28
#include "fixtureselection.h"
29
#include "fixturegroup.h"
30
#include "fixture.h"
31
#include "doc.h"
32

33
#define SETTINGS_GEOMETRY "fixturegroupeditor/geometry"
34

35
#define PROP_FIXTURE Qt::UserRole
36
#define PROP_HEAD Qt::UserRole + 1
37

38
FixtureGroupEditor::FixtureGroupEditor(FixtureGroup* grp, Doc* doc, QWidget* parent)
×
39
    : QWidget(parent)
40
    , m_grp(grp)
×
41
    , m_doc(doc)
×
42
{
43
    Q_ASSERT(grp != NULL);
44
    Q_ASSERT(doc != NULL);
45

46
    setupUi(this);
×
47

48
    m_nameEdit->setText(m_grp->name());
×
49
    m_xSpin->setValue(m_grp->size().width());
×
50
    m_ySpin->setValue(m_grp->size().height());
×
51

52
    connect(m_nameEdit, SIGNAL(textEdited(const QString&)),
×
53
            this, SLOT(slotNameEdited(const QString&)));
54
    connect(m_xSpin, SIGNAL(valueChanged(int)),
×
55
            this, SLOT(slotXSpinValueChanged(int)));
56
    connect(m_ySpin, SIGNAL(valueChanged(int)),
×
57
            this, SLOT(slotYSpinValueChanged(int)));
58

59
    connect(m_rightButton, SIGNAL(clicked()),
×
60
            this, SLOT(slotRightClicked()));
61
    connect(m_leftButton, SIGNAL(clicked()),
×
62
            this, SLOT(slotLeftClicked()));
63
    connect(m_downButton, SIGNAL(clicked()),
×
64
            this, SLOT(slotDownClicked()));
65
    connect(m_upButton, SIGNAL(clicked()),
×
66
            this, SLOT(slotUpClicked())),
×
67
    connect(m_removeButton, SIGNAL(clicked()),
×
68
            this, SLOT(slotRemoveFixtureClicked()));
69

70
    m_table->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
×
71
    m_table->verticalHeader()->setSectionResizeMode(QHeaderView::Stretch);
×
72
    m_table->setIconSize(QSize(20, 20));
×
73
    updateTable();
×
74
}
×
75

76
FixtureGroupEditor::~FixtureGroupEditor()
×
77
{
78
}
×
79

80
void FixtureGroupEditor::updateTable()
×
81
{
82
    qDebug() << Q_FUNC_INFO;
83
    // Store these since they might get reset
84
    int savedRow = m_row;
×
85
    int savedCol = m_column;
×
86

87
    disconnect(m_table, SIGNAL(cellChanged(int,int)),
×
88
               this, SLOT(slotCellChanged(int,int)));
89
    disconnect(m_table, SIGNAL(cellPressed(int,int)),
×
90
               this, SLOT(slotCellActivated(int,int)));
91
    disconnect(m_table->horizontalHeader(), SIGNAL(sectionResized(int,int,int)),
×
92
            this, SLOT(slotResized()));
93

94
    m_table->clear();
×
95

96
    m_table->setRowCount(m_grp->size().height());
×
97
    m_table->setColumnCount(m_grp->size().width());
×
98

99
    QMapIterator <QLCPoint,GroupHead> it(m_grp->headsMap());
×
100
    while (it.hasNext() == true)
×
101
    {
102
        it.next();
×
103

104
        QLCPoint pt(it.key());
×
105

106
        GroupHead head(it.value());
×
107
        Fixture* fxi = m_doc->fixture(head.fxi);
×
108
        if (fxi == NULL)
×
109
            continue;
110

111
        QIcon icon = fxi->getIconFromType();
×
112
        QString str = QString("%1 H:%2\nA:%3 U:%4").arg(fxi->name())
×
113
                                               .arg(head.head + 1)
×
114
                                               .arg(fxi->address() + 1)
×
115
                                               .arg(fxi->universe() + 1);
×
116

117
        QTableWidgetItem* item = new QTableWidgetItem(icon, str);
×
118
        item->setData(PROP_FIXTURE, head.fxi);
×
119
        item->setData(PROP_HEAD, head.head);
×
120
        item->setToolTip(str);
×
121

122
        m_table->setItem(pt.y(), pt.x(), item);
×
123
    }
×
124

125
    connect(m_table, SIGNAL(cellPressed(int,int)),
×
126
            this, SLOT(slotCellActivated(int,int)));
127
    connect(m_table, SIGNAL(cellChanged(int,int)),
×
128
            this, SLOT(slotCellChanged(int,int)));
129
    connect(m_table->horizontalHeader(), SIGNAL(sectionResized(int,int,int)),
×
130
            this, SLOT(slotResized()));
131

132
    if (savedRow < m_table->rowCount() && savedCol < m_table->columnCount())
×
133
    {
134
        m_row = savedRow;
×
135
        m_column = savedCol;
×
136
    }
137
    else
138
    {
139
        m_row = 0;
×
140
        m_column = 0;
×
141
    }
142

143
    m_table->setCurrentCell(m_row, m_column);
×
144
    slotResized();
×
145
}
×
146

147
void FixtureGroupEditor::slotNameEdited(const QString& text)
×
148
{
149
    m_grp->setName(text);
×
150
}
×
151

152
void FixtureGroupEditor::slotXSpinValueChanged(int value)
×
153
{
154
    m_grp->setSize(QSize(value, m_grp->size().height()));
×
155
    updateTable();
×
156
}
×
157

158
void FixtureGroupEditor::slotYSpinValueChanged(int value)
×
159
{
160
    m_grp->setSize(QSize(m_grp->size().width(), value));
×
161
    updateTable();
×
162
}
×
163

164
void FixtureGroupEditor::slotRightClicked()
×
165
{
166
    addFixtureHeads(Qt::RightArrow);
×
167
}
×
168

169
void FixtureGroupEditor::slotLeftClicked()
×
170
{
171
    addFixtureHeads(Qt::LeftArrow);
×
172
}
×
173

174
void FixtureGroupEditor::slotDownClicked()
×
175
{
176
    addFixtureHeads(Qt::DownArrow);
×
177
}
×
178

179
void FixtureGroupEditor::slotUpClicked()
×
180
{
181
    addFixtureHeads(Qt::UpArrow);
×
182
}
×
183

184

185
void FixtureGroupEditor::slotRemoveFixtureClicked()
×
186
{
187
    QTableWidgetItem* item = m_table->currentItem();
×
188
    if (item == NULL)
×
189
        return;
190

191
    if (m_grp->resignHead(QLCPoint(m_column, m_row)) == true)
×
192
        delete item;
×
193
}
194

195
void FixtureGroupEditor::slotCellActivated(int row, int column)
×
196
{
197
    m_row = row;
×
198
    m_column = column;
×
199

200
    if (m_table->currentItem() == NULL)
×
201
        m_removeButton->setEnabled(false);
×
202
    else
203
        m_removeButton->setEnabled(true);
×
204
}
×
205

206
void FixtureGroupEditor::slotCellChanged(int row, int column)
×
207
{
208
    if (row < 0 || column < 0)
×
209
    {
210
        updateTable();
×
211
        return;
×
212
    }
213

214
    QMap <QLCPoint,GroupHead> hash = m_grp->headsMap();
×
215
    QLCPoint from(m_column, m_row);
×
216
    QLCPoint to(column, row);
×
217
    GroupHead fromHead;
×
218
    GroupHead toHead;
×
219

220
    if (hash.contains(from) == true)
×
221
        fromHead = hash[from];
×
222
    if (hash.contains(to) == true)
×
223
        toHead = hash[to];
×
224

225
    m_grp->swap(from, to);
×
226

227
    updateTable();
×
228
    m_table->setCurrentCell(row, column);
×
229
    slotCellActivated(row, column);
×
230
}
×
231

232
void FixtureGroupEditor::slotResized()
×
233
{
234
    disconnect(m_table, SIGNAL(cellChanged(int,int)),
×
235
               this, SLOT(slotCellChanged(int,int)));
236

237
    float cellWidth = (float)(m_table->columnWidth(0) - m_table->iconSize().width());
×
238
    QFont font = m_table->font();
×
239
    QFontMetrics fm(font);
×
240
    float pSizeF = font.pointSizeF();
×
241

242
    for (int y = 0; y < m_table->rowCount(); y++)
×
243
    {
244
        for (int x = 0; x < m_table->columnCount(); x++)
×
245
        {
246
            QTableWidgetItem* item = m_table->item(y, x);
×
247
            if (item != NULL)
×
248
            {
249
                QFont scaledFont = font;
×
250
#if (QT_VERSION < QT_VERSION_CHECK(5, 11, 0))
251
                float baseWidth  = (float)fm.width(item->text());
252
#else
253
                float baseWidth  = (float)fm.horizontalAdvance(item->text());
×
254
#endif
255
                float factor = cellWidth / baseWidth;
×
256
                if (factor != 1)
×
257
                    scaledFont.setPointSizeF((pSizeF * factor) + 2);
×
258
                else
259
                    scaledFont.setPointSize(font.pointSize() - 2);
×
260

261
                item->setFont(scaledFont);
×
262
            }
×
263
        }
264
    }
265

266
    connect(m_table, SIGNAL(cellChanged(int,int)),
×
267
            this, SLOT(slotCellChanged(int,int)));
268
}
×
269

270
void FixtureGroupEditor::addFixtureHeads(Qt::ArrowType direction)
×
271
{
272
    FixtureSelection fs(this, m_doc);
×
273
    fs.setMultiSelection(true);
×
274
    fs.setSelectionMode(FixtureSelection::Heads);
×
275
    fs.setDisabledHeads(m_grp->headList());
×
276
    if (fs.exec() == QDialog::Accepted)
×
277
    {
278
        int row = m_row;
×
279
        int col = m_column;
×
280
        foreach (GroupHead gh, fs.selectedHeads())
×
281
        {
282
            m_grp->assignHead(QLCPoint(col, row), gh);
×
283
            if (direction == Qt::RightArrow)
×
284
                col++;
×
285
            else if (direction == Qt::DownArrow)
×
286
                row++;
×
287
            else if (direction == Qt::LeftArrow)
×
288
                col--;
×
289
            else if (direction == Qt::UpArrow)
×
290
                row--;
×
291
        }
×
292

293
        updateTable();
×
294
        m_table->setCurrentCell(row, col);
×
295
    }
296
}
×
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