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

mcallegari / qlcplus / 19144422256

06 Nov 2025 05:33PM UTC coverage: 34.256% (-0.1%) from 34.358%
19144422256

push

github

mcallegari
Back to 5.1.0 debug

17718 of 51723 relevant lines covered (34.26%)

19528.23 hits per line

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

0.0
/ui/src/showmanager/showitem.cpp
1
/*
2
  Q Light Controller Plus
3
  showitem.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 <QGraphicsSceneEvent>
21
#include <QApplication>
22
#include <QPainter>
23
#include <QDebug>
24
#include <QMenu>
25

26
#include "headeritems.h"
27
#include "trackitem.h"
28
#include "showitem.h"
29
#include "function.h"
30

31
ShowItem::ShowItem(ShowFunction *function, QObject *)
×
32
    : m_color(100, 100, 100)
×
33
    , m_locked(false)
×
34
    , m_pressed(false)
×
35
    , m_width(50)
×
36
    , m_timeScale(3)
×
37
    , m_trackIdx(-1)
×
38
    , m_function(function)
×
39
    , m_alignToCursor(NULL)
×
40
    , m_lockAction(NULL)
×
41
{
42
    Q_ASSERT(function != NULL);
×
43

44
    setCursor(Qt::OpenHandCursor);
×
45
    setFlag(QGraphicsItem::ItemIsSelectable, true);
×
46

47
    m_font = qApp->font();
×
48
    m_font.setBold(true);
×
49
    m_font.setPixelSize(12);
×
50

51
    setLocked(m_function->isLocked());
×
52

53
    m_alignToCursor = new QAction(tr("Align to cursor"), this);
×
54
    connect(m_alignToCursor, SIGNAL(triggered()),
×
55
            this, SLOT(slotAlignToCursorClicked()));
56
    m_lockAction = new QAction(tr("Lock item"), this);
×
57
    connect(m_lockAction, SIGNAL(triggered()),
×
58
            this, SLOT(slotLockItemClicked()));
59
}
×
60

61
void ShowItem::updateTooltip()
×
62
{
63
    if (m_function == NULL)
×
64
        return;
×
65

66
    setToolTip(QString(tr("Name: %1\nStart time: %2\nDuration: %3\n%4"))
×
67
              .arg(functionName())
×
68
              .arg(Function::speedToString(m_function->startTime()))
×
69
              .arg(Function::speedToString(getDuration()))
×
70
              .arg(tr("Click to move this item along the timeline")));
×
71
}
72

73
QList<QAction *> ShowItem::getDefaultActions()
×
74
{
75
    QList<QAction *> actions;
×
76
    actions.append(m_alignToCursor);
×
77

78
    if (isLocked())
×
79
    {
80
        m_lockAction->setText(tr("Unlock item"));
×
81
        m_lockAction->setIcon(QIcon(":/unlock.png"));
×
82
    }
83
    else
84
    {
85
        m_lockAction->setText(tr("Lock item"));
×
86
        m_lockAction->setIcon(QIcon(":/lock.png"));
×
87
    }
88
    actions.append(m_lockAction);
×
89

90
    return actions;
×
91
}
×
92

93
void ShowItem::setTimeScale(int val)
×
94
{
95
    prepareGeometryChange();
×
96
    m_timeScale = val;
×
97
}
×
98

99
int ShowItem::getTimeScale()
×
100
{
101
    return m_timeScale;
×
102
}
103

104
void ShowItem::setStartTime(quint32 time)
×
105
{
106
    if (m_function == NULL)
×
107
        return;
×
108

109
    m_function->setStartTime(time);
×
110
    updateTooltip();
×
111
}
112

113
quint32 ShowItem::getStartTime()
×
114
{
115
    if (m_function)
×
116
        return m_function->startTime();
×
117
    return 0;
×
118
}
119

120
void ShowItem::setDuration(quint32 msec, bool stretch)
×
121
{
122
    Q_UNUSED(stretch)
123

124
    if (m_function == NULL)
×
125
        return;
×
126

127
    m_function->setDuration(msec);
×
128
    updateTooltip();
×
129
}
130

131
quint32 ShowItem::getDuration()
×
132
{
133
    if (m_function)
×
134
        return m_function->duration();
×
135
    return 0;
×
136
}
137

138
void ShowItem::setWidth(int w)
×
139
{
140
    m_width = w;
×
141
    updateTooltip();
×
142
}
×
143

144
int ShowItem::getWidth()
×
145
{
146
    return m_width;
×
147
}
148

149
QPointF ShowItem::getDraggingPos()
×
150
{
151
    return m_pos;
×
152
}
153

154
void ShowItem::setTrackIndex(int idx)
×
155
{
156
    m_trackIdx = idx;
×
157
}
×
158

159
int ShowItem::getTrackIndex()
×
160
{
161
    return m_trackIdx;
×
162
}
163

164
void ShowItem::setColor(QColor col)
×
165
{
166
    m_color = col;
×
167
    if (m_function)
×
168
        m_function->setColor(col);
×
169
    update();
×
170
}
×
171

172
QColor ShowItem::getColor()
×
173
{
174
    return m_color;
×
175
}
176

177
void ShowItem::setLocked(bool locked)
×
178
{
179
    m_locked = locked;
×
180
    if (m_function)
×
181
        m_function->setLocked(locked);
×
182
    setFlag(QGraphicsItem::ItemIsMovable, !locked);
×
183
    update();
×
184
}
×
185

186
bool ShowItem::isLocked()
×
187
{
188
    return m_locked;
×
189
}
190

191
void ShowItem::setFunctionID(quint32 id)
×
192
{
193
    if (m_function != NULL)
×
194
        m_function->setFunctionID(id);
×
195
}
×
196

197
quint32 ShowItem::functionID()
×
198
{
199
    if (m_function != NULL)
×
200
        return m_function->functionID();
×
201

202
    return Function::invalidId();
×
203
}
204

205
ShowFunction *ShowItem::showFunction() const
×
206
{
207
    return m_function;
×
208
}
209

210
QString ShowItem::functionName()
×
211
{
212
    return QString();
×
213
}
214

215
void ShowItem::slotAlignToCursorClicked()
×
216
{
217
    emit alignToCursor(this);
×
218
}
×
219

220
void ShowItem::slotLockItemClicked()
×
221
{
222
    setLocked(!isLocked());
×
223
    //update();
224
}
×
225

226
void ShowItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
×
227
{
228
    QGraphicsItem::mousePressEvent(event);
×
229
    m_pos = this->pos();
×
230
    if (event->button() == Qt::LeftButton)
×
231
        m_pressed = true;
×
232
    this->setSelected(true);
×
233
}
×
234

235
void ShowItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
×
236
{
237
    QGraphicsItem::mouseReleaseEvent(event);
×
238
    qDebug() << Q_FUNC_INFO << "mouse RELEASE event - <" << event->pos().toPoint().x() << "> - <" << event->pos().toPoint().y() << ">";
×
239
    setCursor(Qt::OpenHandCursor);
×
240
    m_pressed = false;
×
241
    emit itemDropped(event, this);
×
242
}
×
243

244
void ShowItem::contextMenuEvent(QGraphicsSceneContextMenuEvent *event)
×
245
{
246
    Q_UNUSED(event)
247

248
    QMenu menu;
×
249
    QFont menuFont = qApp->font();
×
250
    menuFont.setPixelSize(14);
×
251
    menu.setFont(menuFont);
×
252

253
    menu.addAction(m_alignToCursor);
×
254
    if (isLocked())
×
255
    {
256
        m_lockAction->setText(tr("Unlock item"));
×
257
        m_lockAction->setIcon(QIcon(":/unlock.png"));
×
258
    }
259
    else
260
    {
261
        m_lockAction->setText(tr("Lock item"));
×
262
        m_lockAction->setIcon(QIcon(":/lock.png"));
×
263
    }
264
    menu.addAction(m_lockAction);
×
265
    menu.exec(QCursor::pos());
×
266
}
×
267

268

269
QRectF ShowItem::boundingRect() const
×
270
{
271
    return QRectF(0, 0, m_width, TRACK_HEIGHT - 3);
×
272
}
273

274
void ShowItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
×
275
{
276
    Q_UNUSED(option);
277
    Q_UNUSED(widget);
278

279
    if (this->isSelected() == true)
×
280
        painter->setPen(QPen(Qt::white, 3));
×
281
    else
282
        painter->setPen(QPen(Qt::white, 1));
×
283

284
    // draw item background
285
    painter->setBrush(QBrush(m_color));
×
286
    painter->drawRect(0, 0, m_width, TRACK_HEIGHT - 3);
×
287

288
    painter->setFont(m_font);
×
289
}
×
290

291
void ShowItem::postPaint(QPainter *painter)
×
292
{
293
    // draw the function name shadow
294
    painter->setPen(QPen(QColor(10, 10, 10, 150), 2));
×
295
    painter->drawText(QRect(4, 6, m_width - 6, 71), Qt::AlignLeft | Qt::TextWordWrap, functionName());
×
296

297
    // draw the function name
298
    painter->setPen(QPen(QColor(220, 220, 220, 255), 2));
×
299
    painter->drawText(QRect(3, 5, m_width - 5, 72), Qt::AlignLeft | Qt::TextWordWrap, functionName());
×
300

301
    if (m_locked)
×
302
        painter->drawPixmap(3, TRACK_HEIGHT >> 1, 24, 24, QIcon(":/lock.png").pixmap(24, 24));
×
303

304
    if (m_pressed)
×
305
    {
306
        quint32 s_time = 0;
×
307
        if (x() > TRACK_WIDTH)
×
308
            s_time = (double)(x() - TRACK_WIDTH - 2) * (m_timeScale * 500) /
×
309
                     (double)(HALF_SECOND_WIDTH);
310
        painter->drawText(3, TRACK_HEIGHT - 10, Function::speedToString(s_time));
×
311
    }
312
}
×
313

314

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

© 2026 Coveralls, Inc