• 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/monitor/monitorgraphicsview.cpp
1
/*
2
  Q Light Controller Plus
3
  monitorgraphicsview.cpp
4

5
  Copyright (C) Massimo Callegari
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 "monitorproperties.h"
21
#include "monitorgraphicsview.h"
22
#include "monitorfixtureitem.h"
23
#include "qlcfixturemode.h"
24
#include "doc.h"
25

26
MonitorGraphicsView::MonitorGraphicsView(Doc *doc, QWidget *parent)
×
27
    : QGraphicsView(parent)
28
    , m_doc(doc)
×
29
    , m_unitValue(1000)
×
30
    , m_gridEnabled(true)
×
31
    , m_bgItem(NULL)
×
32
{
33
    m_scene = new QGraphicsScene();
×
34
    m_scene->setSceneRect(this->rect());
×
35
    setScene(m_scene);
×
36

37
    m_gridSize = QSize(5, 5);
×
38

39
    updateGrid();
×
40
}
×
41

42
MonitorGraphicsView::~MonitorGraphicsView()
×
43
{
44
    clearFixtures();
×
45
}
×
46

47
void MonitorGraphicsView::setGridSize(QSize size)
×
48
{
49
    m_gridSize = size;
×
50
    updateGrid();
×
51
    QHashIterator <quint32, MonitorFixtureItem*> it(m_fixtures);
×
52
    while (it.hasNext() == true)
×
53
    {
54
        it.next();
×
55
        updateFixture(it.key());
×
56
    }
57
}
×
58

59
void MonitorGraphicsView::setGridMetrics(float value)
×
60
{
61
    m_unitValue = value;
×
62
    QHashIterator <quint32, MonitorFixtureItem*> it(m_fixtures);
×
63
    while (it.hasNext() == true)
×
64
    {
65
        it.next();
×
66
        updateFixture(it.key());
×
67
    }
68
}
×
69

70
quint32 MonitorGraphicsView::selectedFixtureID()
×
71
{
72
    MonitorFixtureItem *item = getSelectedItem();
×
73
    if (item != NULL)
×
74
        return item->fixtureID();
×
75
    else
76
        return Fixture::invalidId();
×
77
}
78

79
QList<quint32> MonitorGraphicsView::fixturesID() const
×
80
{
81
    return m_fixtures.keys();
×
82
}
83

84
void MonitorGraphicsView::setFixtureGelColor(quint32 id, QColor col)
×
85
{
86
    MonitorFixtureItem *item = m_fixtures[id];
×
87
    if (item != NULL)
×
88
        item->setGelColor(col);
×
89
}
×
90

91
void MonitorGraphicsView::setFixtureRotation(quint32 id, ushort degrees)
×
92
{
93
    MonitorFixtureItem *item = m_fixtures[id];
×
94
    if (item != NULL)
×
95
        item->setRotation(degrees);
×
96
}
×
97

98
void MonitorGraphicsView::showFixturesLabels(bool visible)
×
99
{
100
    foreach (MonitorFixtureItem *item, m_fixtures.values())
×
101
        item->showLabel(visible);
×
102
}
×
103

104
QColor MonitorGraphicsView::fixtureGelColor(quint32 id)
×
105
{
106
    MonitorFixtureItem *item = m_fixtures[id];
×
107
    if (item == NULL)
×
108
        return QColor();
109

110
    return item->getColor();
111
}
112

113
QPointF MonitorGraphicsView::realPositionToPixels(qreal xpos, qreal ypos)
×
114
{
115
    qreal realX = m_xOffset + ((xpos * m_cellPixels) / m_unitValue);
×
116
    qreal realY = m_yOffset + ((ypos * m_cellPixels) / m_unitValue);
×
117

118
    return QPointF(realX, realY);
×
119
}
120

121
void MonitorGraphicsView::updateFixture(quint32 id)
×
122
{
123
    Fixture *fxi = m_doc->fixture(id);
×
124
    if (fxi == NULL || m_fixtures.contains(id) == false)
×
125
        return;
×
126

127
    const QLCFixtureMode *mode = fxi->fixtureMode();
×
128
    int width = 0;
129
    int height = 0;
130

131
    if (mode != 0)
×
132
    {
133
        width = mode->physical().width();
×
134
        height = mode->physical().height();
×
135
    }
136

137
    if (width == 0) width = 300;
×
138
    if (height == 0) height = 300;
×
139

140

141
    MonitorFixtureItem *item = m_fixtures[id];
×
142
    item->setSize(QSize((width * m_cellPixels) / m_unitValue, (height * m_cellPixels) / m_unitValue));
×
143

144
    item->setPos(realPositionToPixels(item->realPosition().x(), item->realPosition().y()));
×
145
}
146

147
void MonitorGraphicsView::setBackgroundImage(QString filename)
×
148
{
149
    m_backgroundImage = filename;
×
150
    if (m_bgItem != NULL)
×
151
    {
152
        m_scene->removeItem(m_bgItem);
×
153
        delete m_bgItem;
×
154
        m_bgItem = NULL;
×
155
    }
156
    if (filename.isEmpty() == false)
×
157
    {
158
        m_bgPixmap = QPixmap(m_backgroundImage);
×
159
        m_bgItem = new QGraphicsPixmapItem(m_bgPixmap);
×
160
        m_bgItem->setZValue(0); // make sure it goes on the bacground
×
161
        m_scene->addItem(m_bgItem);
×
162
    }
163
    updateGrid();
×
164
}
×
165

166
MonitorFixtureItem *MonitorGraphicsView::getSelectedItem()
×
167
{
168
    QHashIterator <quint32, MonitorFixtureItem*> it(m_fixtures);
×
169
    while (it.hasNext() == true)
×
170
    {
171
        it.next();
×
172
        MonitorFixtureItem *item = it.value();
×
173
        if (item->isSelected() == true)
×
174
            return item;
×
175
    }
176
    return NULL;
177
}
178

179
void MonitorGraphicsView::addFixture(quint32 id, QPointF pos)
×
180
{
181
    if (id == Fixture::invalidId() || m_fixtures.contains(id) == true)
×
182
        return;
×
183

184
    if (m_doc->fixture(id) == NULL)
×
185
        return;
186

187
    MonitorFixtureItem *item = new MonitorFixtureItem(m_doc, id);
×
188
    item->setZValue(2);
×
189
    item->setRealPosition(pos);
190
    m_fixtures[id] = item;
×
191
    m_scene->addItem(item);
×
192
    updateFixture(id);
×
193
    connect(item, SIGNAL(itemDropped(MonitorFixtureItem*)),
×
194
            this, SLOT(slotFixtureMoved(MonitorFixtureItem*)));
195
}
196

197
bool MonitorGraphicsView::removeFixture(quint32 id)
×
198
{
199
    MonitorFixtureItem *item = NULL;
200

201
    if (id == Fixture::invalidId())
×
202
    {
203
        item = getSelectedItem();
×
204
        if (item != NULL)
×
205
            id = item->fixtureID();
×
206
    }
207
    else
208
        item = m_fixtures[id];
×
209

210
    if (item == NULL)
×
211
        return false;
212

213
    m_scene->removeItem(item);
×
214
    m_fixtures.take(id);
×
215
    m_doc->monitorProperties()->removeFixture(id);
×
216
    delete item;
×
217

218
    return true;
×
219
}
220

221
void MonitorGraphicsView::clearFixtures()
×
222
{
223
    foreach (MonitorFixtureItem *item, m_fixtures.values())
×
224
        delete item;
×
225
    m_fixtures.clear();
×
226
}
×
227

228
void MonitorGraphicsView::updateGrid()
×
229
{
230
    int itemsCount = m_gridItems.count();
231
    for (int i = 0; i < itemsCount; i++)
×
232
        m_scene->removeItem((QGraphicsItem *)m_gridItems.takeLast());
×
233

234
    if (m_gridEnabled == true)
×
235
    {
236
        m_xOffset = 0;
×
237
        m_yOffset = 0;
×
238
        int xInc = this->width() / m_gridSize.width();
×
239
        int yInc = this->height() / m_gridSize.height();
×
240
        if (yInc < xInc)
×
241
        {
242
            m_cellPixels = yInc;
×
243
            m_xOffset = (this->width() - (m_cellPixels * m_gridSize.width())) / 2;
×
244
        }
245
        else if (xInc < yInc)
×
246
        {
247
            m_cellPixels = xInc;
×
248
            m_yOffset = (this->height() - (m_cellPixels * m_gridSize.height())) / 2;
×
249
        }
250
        int xPos = m_xOffset;
×
251
        int yPos = m_yOffset;
×
252
        for (int i = 0; i < m_gridSize.width() + 1; i++)
×
253
        {
254
            QGraphicsLineItem *item = m_scene->addLine(xPos, m_yOffset, xPos, this->height() - m_yOffset,
×
255
                                                       QPen(QColor(40, 40, 40, 255)));
×
256
            item->setZValue(1);
×
257
            xPos += m_cellPixels;
×
258
            m_gridItems.append(item);
×
259
        }
260

261
        for (int i = 0; i < m_gridSize.height() + 1; i++)
×
262
        {
263
            QGraphicsLineItem *item = m_scene->addLine(m_xOffset, yPos, this->width() - m_xOffset, yPos,
×
264
                                                       QPen(QColor(40, 40, 40, 255)));
×
265
            item->setZValue(1);
×
266
            yPos += m_cellPixels;
×
267
            m_gridItems.append(item);
×
268
        }
269
        if (m_bgItem != NULL)
×
270
        {
271
            m_bgItem->setX(m_xOffset);
×
272
            m_bgItem->setY(m_yOffset);
×
273
            m_bgItem->setPixmap(m_bgPixmap.scaled(xPos - m_cellPixels - m_xOffset, yPos - m_cellPixels - m_yOffset));
×
274
        }
275
    }
276
}
×
277

278
void MonitorGraphicsView::resizeEvent(QResizeEvent *event)
×
279
{
280
    QGraphicsView::resizeEvent(event);
×
281
    updateGrid();
×
282
    QHashIterator <quint32, MonitorFixtureItem*> it(m_fixtures);
×
283
    while (it.hasNext() == true)
×
284
    {
285
        it.next();
×
286
        updateFixture(it.key());
×
287
    }
288
}
×
289

290
void MonitorGraphicsView::mouseReleaseEvent(QMouseEvent *e)
×
291
{
292
    emit viewClicked(e);
×
293

294
    QGraphicsView::mouseReleaseEvent(e);
×
295
}
×
296

297
void MonitorGraphicsView::slotFixtureMoved(MonitorFixtureItem *item)
×
298
{
299
    quint32 fid = m_fixtures.key(item);
×
300

301
    // Convert the pixel position of the fixture into
302
    // position in millimeters
303
    QPointF mmPos;
304
    mmPos.setX(((item->x() - m_xOffset) * m_unitValue) / m_cellPixels);
×
305
    mmPos.setY(((item->y() - m_yOffset) * m_unitValue) / m_cellPixels);
×
306

307
    // update the fixture item's real position
308
    item->setRealPosition(mmPos);
×
309

310
    emit fixtureMoved(fid, mmPos);
×
311
}
×
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