• 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/showmanager/sequenceitem.cpp
1
/*
2
  Q Light Controller Plus
3
  sequenceitem.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 <QMenu>
23

24
#include "sequenceitem.h"
25
#include "chaserstep.h"
26
#include "trackitem.h"
27

28
SequenceItem::SequenceItem(Chaser *seq, ShowFunction *func)
×
29
    : ShowItem(func)
30
    , m_chaser(seq)
×
31
    , m_selectedStep(-1)
×
32
{
33
    Q_ASSERT(seq != NULL);
34

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

40
    if (func->duration() == 0)
×
41
        func->setDuration(seq->totalDuration());
×
42

43
    calculateWidth();
×
44

45
    connect(m_chaser, SIGNAL(changed(quint32)),
×
46
            this, SLOT(slotSequenceChanged(quint32)));
47
}
×
48

49
void SequenceItem::calculateWidth()
×
50
{
51
    int newWidth = 0;
52
    quint32 seq_duration = m_chaser->totalDuration();
×
53
    float timeUnit = 50.0 / float(getTimeScale());
×
54

55
    if (seq_duration == Function::infiniteSpeed())
×
56
    {
57
        newWidth = timeUnit * 10000;
×
58
    }
59
    else
60
    {
61
        if (seq_duration != 0)
×
62
            newWidth = (timeUnit * float(seq_duration)) / 1000.0;
×
63

64
        if (newWidth < timeUnit)
×
65
            newWidth = timeUnit;
×
66
    }
67
    setWidth(newWidth);
×
68
}
×
69

70
void SequenceItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
×
71
{
72
    float xpos = 0;
73
    float timeUnit = 50.0 / float(m_timeScale);
×
74
    int stepIdx = 0;
75

76
    ShowItem::paint(painter, option, widget);
×
77

78
    if (this->isSelected() == false)
×
79
        m_selectedStep = -1;
×
80

81
    foreach (ChaserStep step, m_chaser->steps())
×
82
    {
83
        uint stepFadeIn = step.fadeIn;
×
84
        uint stepFadeOut = step.fadeOut;
×
85
        uint stepDuration = step.duration;
×
86

87
        if (m_chaser->fadeInMode() == Chaser::Common)
×
88
            stepFadeIn = m_chaser->fadeInSpeed();
×
89
        if (m_chaser->fadeOutMode() == Chaser::Common)
×
90
            stepFadeOut = m_chaser->fadeOutSpeed();
×
91
        if (m_chaser->durationMode() == Chaser::Common)
×
92
            stepDuration = m_chaser->duration();
×
93

94
        // avoid hanging on infinite duration
95
        if (stepDuration == Function::infiniteSpeed())
×
96
            stepDuration = 10 * 1000 * 1000;
97

98
        // draw fade in line
99
        if (stepFadeIn > 0)
×
100
        {
101
            int fadeXpos = xpos + ((timeUnit * (float)stepFadeIn) / 1000);
×
102
            // doesn't even draw it if too small
103
            if (fadeXpos - xpos > 5)
×
104
            {
105
                painter->setPen(QPen(Qt::gray, 1));
×
106
                painter->drawLine(xpos, TRACK_HEIGHT - 4, fadeXpos, 1);
×
107
            }
108
        }
109
        float stepWidth = ((timeUnit * (float)stepDuration) / 1000);
×
110
        // draw selected step
111
        if (stepIdx == m_selectedStep)
×
112
        {
113
            painter->setPen(QPen(Qt::yellow, 2));
×
114
            painter->setBrush(QBrush(Qt::NoBrush));
×
115
            painter->drawRect(xpos, 0, stepWidth, TRACK_HEIGHT - 3);
×
116
        }
117

118
        QRect textRect = QRect(xpos + 1, 0, stepWidth - 1, TRACK_HEIGHT - 3);
×
119
        painter->drawText(textRect, Qt::AlignBottom, step.note);
×
120

121
        xpos += stepWidth;
×
122

123
        // draw step vertical delimiter
124
        painter->setPen(QPen(Qt::white, 1));
×
125
        painter->drawLine(xpos, 1, xpos, TRACK_HEIGHT - 5);
×
126

127
        // draw fade out line
128
        if (stepFadeOut > 0)
×
129
        {
130
            int fadeXpos = xpos + ((timeUnit * (float)stepFadeOut) / 1000);
×
131
            // doesn't even draw it if too small
132
            if (fadeXpos - xpos > 5)
×
133
            {
134
                painter->setPen(QPen(Qt::gray, 1));
×
135
                painter->drawLine(xpos, 1, fadeXpos, TRACK_HEIGHT - 4);
136
            }
137
        }
138
        stepIdx++;
×
139
    }
140

141
    ShowItem::postPaint(painter);
×
142
}
×
143

144
void SequenceItem::setTimeScale(int val)
×
145
{
146
    ShowItem::setTimeScale(val);
×
147
    calculateWidth();
×
148
}
×
149

150
void SequenceItem::setDuration(quint32 msec, bool stretch)
×
151
{
152
    Q_UNUSED(stretch)
153
    m_chaser->setTotalDuration(msec);
×
154
}
×
155

156
QString SequenceItem::functionName()
×
157
{
158
    if (m_chaser)
×
159
        return m_chaser->name();
×
160
    return QString();
161
}
162

163
void SequenceItem::setSelectedStep(int idx)
×
164
{
165
    m_selectedStep = idx;
×
166
    update();
×
167
}
×
168

169
Chaser *SequenceItem::getChaser()
×
170
{
171
    return m_chaser;
×
172
}
173

174
void SequenceItem::slotSequenceChanged(quint32)
×
175
{
176
    prepareGeometryChange();
×
177
    calculateWidth();
×
178
    if (m_function)
×
179
        m_function->setDuration(m_chaser->totalDuration());
×
180
    updateTooltip();
×
181
}
×
182

183
void SequenceItem::contextMenuEvent(QGraphicsSceneContextMenuEvent *)
×
184
{
185
    QMenu menu;
×
186
    QFont menuFont = qApp->font();
×
187
    menuFont.setPixelSize(14);
×
188
    menu.setFont(menuFont);
×
189

190
    foreach (QAction *action, getDefaultActions())
×
191
        menu.addAction(action);
×
192

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