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

mcallegari / qlcplus / 7252848206

18 Dec 2023 07:26PM UTC coverage: 32.067% (+0.001%) from 32.066%
7252848206

push

github

mcallegari
Code style review #1427

199 of 628 new or added lines in 101 files covered. (31.69%)

8 existing lines in 2 files now uncovered.

15169 of 47304 relevant lines covered (32.07%)

23733.74 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
    unsigned long seq_duration = m_chaser->totalDuration();
×
53

54
    if (seq_duration != 0)
×
55
        newWidth = ((50/(float)getTimeScale()) * (float)seq_duration) / 1000;
×
56

57
    if (newWidth < (50 / m_timeScale))
×
58
        newWidth = 50 / m_timeScale;
×
59
    setWidth(newWidth);
×
60
}
×
61

62
void SequenceItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
×
63
{
64
    float xpos = 0;
×
65
    float timeScale = 50/(float)m_timeScale;
×
66
    int stepIdx = 0;
×
67

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

70
    if (this->isSelected() == false)
×
71
        m_selectedStep = -1;
×
72

73
    foreach (ChaserStep step, m_chaser->steps())
×
74
    {
75
        uint stepFadeIn = step.fadeIn;
×
76
        uint stepFadeOut = step.fadeOut;
×
77
        uint stepDuration = step.duration;
×
78
        if (m_chaser->fadeInMode() == Chaser::Common)
×
79
            stepFadeIn = m_chaser->fadeInSpeed();
×
80
        if (m_chaser->fadeOutMode() == Chaser::Common)
×
81
            stepFadeOut = m_chaser->fadeOutSpeed();
×
82
        if (m_chaser->durationMode() == Chaser::Common)
×
83
            stepDuration = m_chaser->duration();
×
84

85
        // draw fade in line
86
        if (stepFadeIn > 0)
×
87
        {
88
            int fadeXpos = xpos + ((timeScale * (float)stepFadeIn) / 1000);
×
89
            // doesn't even draw it if too small
90
            if (fadeXpos - xpos > 5)
×
91
            {
92
                painter->setPen(QPen(Qt::gray, 1));
×
93
                painter->drawLine(xpos, TRACK_HEIGHT - 4, fadeXpos, 1);
×
94
            }
95
        }
96
        float stepWidth = ((timeScale * (float)stepDuration) / 1000);
×
97
        // draw selected step
98
        if (stepIdx == m_selectedStep)
×
99
        {
100
            painter->setPen(QPen(Qt::yellow, 2));
×
101
            painter->setBrush(QBrush(Qt::NoBrush));
×
102
            painter->drawRect(xpos, 0, stepWidth, TRACK_HEIGHT - 3);
×
103
        }
104
        xpos += stepWidth;
×
105

106
        // draw step vertical delimiter
107
        painter->setPen(QPen(Qt::white, 1));
×
108
        painter->drawLine(xpos, 1, xpos, TRACK_HEIGHT - 5);
×
109

110
        // draw fade out line
111
        if (stepFadeOut > 0)
×
112
        {
113
            int fadeXpos = xpos + ((timeScale * (float)stepFadeOut) / 1000);
×
114
            // doesn't even draw it if too small
115
            if (fadeXpos - xpos > 5)
×
116
            {
117
                painter->setPen(QPen(Qt::gray, 1));
×
118
                painter->drawLine(xpos, 1, fadeXpos, TRACK_HEIGHT - 4);
×
119
            }
120
        }
121
        stepIdx++;
×
122
    }
123

124
    ShowItem::postPaint(painter);
×
125
}
×
126

127
void SequenceItem::setTimeScale(int val)
×
128
{
129
    ShowItem::setTimeScale(val);
×
130
    calculateWidth();
×
131
}
×
132

133
void SequenceItem::setDuration(quint32 msec, bool stretch)
×
134
{
135
    Q_UNUSED(stretch)
136
    m_chaser->setTotalDuration(msec);
×
137
}
×
138

139
QString SequenceItem::functionName()
×
140
{
141
    if (m_chaser)
×
142
        return m_chaser->name();
×
143
    return QString();
×
144
}
145

146
void SequenceItem::setSelectedStep(int idx)
×
147
{
148
    m_selectedStep = idx;
×
149
    update();
×
150
}
×
151

152
Chaser *SequenceItem::getChaser()
×
153
{
154
    return m_chaser;
×
155
}
156

157
void SequenceItem::slotSequenceChanged(quint32)
×
158
{
159
    prepareGeometryChange();
×
160
    calculateWidth();
×
161
    if (m_function)
×
162
        m_function->setDuration(m_chaser->totalDuration());
×
163
    updateTooltip();
×
164
}
×
165

166
void SequenceItem::contextMenuEvent(QGraphicsSceneContextMenuEvent *)
×
167
{
168
    QMenu menu;
×
169
    QFont menuFont = qApp->font();
×
170
    menuFont.setPixelSize(14);
×
171
    menu.setFont(menuFont);
×
172

NEW
173
    foreach (QAction *action, getDefaultActions())
×
174
        menu.addAction(action);
×
175

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