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

mcallegari / qlcplus / 19545862789

20 Nov 2025 05:26PM UTC coverage: 34.232% (-0.001%) from 34.233%
19545862789

push

github

mcallegari
showmanager: fix crash with infinite duration matrix

0 of 11 new or added lines in 1 file covered. (0.0%)

17724 of 51776 relevant lines covered (34.23%)

19629.69 hits per line

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

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

26
#include "rgbmatrixitem.h"
27
#include "trackitem.h"
28

29
RGBMatrixItem::RGBMatrixItem(RGBMatrix *rgbm, ShowFunction *func)
×
30
    : ShowItem(func)
31
    , m_matrix(rgbm)
×
32
{
33
    Q_ASSERT(rgbm != NULL);
×
34

35
    if (func->color().isValid())
×
36
        setColor(func->color());
×
37
    else
38
        setColor(ShowFunction::defaultColor(Function::RGBMatrixType));
×
39

40
    calculateWidth();
×
41
    connect(m_matrix, SIGNAL(changed(quint32)), this, SLOT(slotRGBMatrixChanged(quint32)));
×
42
}
×
43

44
void RGBMatrixItem::calculateWidth()
×
45
{
46
    int newWidth = 0;
×
47
    qint64 matrixDuration = getDuration();
×
48

49
    if (matrixDuration != 0)
×
50
        newWidth = ((50 / float(getTimeScale())) * float(matrixDuration)) / 1000;
×
51
    else
52
        newWidth = 100;
×
53

54
    if (newWidth < (50 / m_timeScale))
×
55
        newWidth = 50 / m_timeScale;
×
56
    setWidth(newWidth);
×
57
}
×
58

59
void RGBMatrixItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
×
60
{
61
    Q_UNUSED(option);
62
    Q_UNUSED(widget);
63

NEW
64
    float xpos = 0;
×
NEW
65
    float timeUnit = 50.0 / float(getTimeScale());
×
66

67
    ShowItem::paint(painter, option, widget);
×
68

NEW
69
    int loopCount = 0;
×
NEW
70
    if (getDuration() == Function::infiniteSpeed())
×
NEW
71
        loopCount = 10000 / m_matrix->duration();
×
NEW
72
    else if (getDuration() > 0)
×
NEW
73
        loopCount = qFloor(getDuration() / m_matrix->duration());
×
74

NEW
75
    for (int i = 0; i < loopCount; i++)
×
76
    {
NEW
77
        xpos += ((timeUnit * float(m_matrix->totalDuration())) / 1000);
×
78
        // draw loop vertical delimiter
NEW
79
        painter->setPen(QPen(Qt::white, 1));
×
NEW
80
        painter->drawLine(int(xpos), 1, int(xpos), TRACK_HEIGHT - 5);
×
81
    }
82

83
    ShowItem::postPaint(painter);
×
84
}
×
85

86
void RGBMatrixItem::setTimeScale(int val)
×
87
{
88
    ShowItem::setTimeScale(val);
×
89
    calculateWidth();
×
90
}
×
91

92
void RGBMatrixItem::setDuration(quint32 msec, bool stretch)
×
93
{
94
    if (stretch == true)
×
95
    {
96
        m_matrix->setTotalDuration(msec);
×
97
    }
98
    else
99
    {
100
        if (m_function)
×
101
            m_function->setDuration(msec);
×
102
        prepareGeometryChange();
×
103
        calculateWidth();
×
104
        updateTooltip();
×
105
    }
106
}
×
107

108
quint32 RGBMatrixItem::getDuration()
×
109
{
110
    return m_function->duration() ? m_function->duration() : m_matrix->totalDuration();
×
111
}
112

113
QString RGBMatrixItem::functionName()
×
114
{
115
    if (m_matrix)
×
116
        return m_matrix->name();
×
117
    return QString();
×
118
}
119

120
RGBMatrix *RGBMatrixItem::getRGBMatrix()
×
121
{
122
    return m_matrix;
×
123
}
124

125
void RGBMatrixItem::slotRGBMatrixChanged(quint32)
×
126
{
127
    prepareGeometryChange();
×
128
    calculateWidth();
×
129
    updateTooltip();
×
130
}
×
131

132
void RGBMatrixItem::contextMenuEvent(QGraphicsSceneContextMenuEvent *)
×
133
{
134
    QMenu menu;
×
135
    QFont menuFont = qApp->font();
×
136
    menuFont.setPixelSize(14);
×
137
    menu.setFont(menuFont);
×
138

139
    foreach (QAction *action, getDefaultActions())
×
140
        menu.addAction(action);
×
141

142
    menu.exec(QCursor::pos());
×
143
}
×
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