• 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

22.58
/ui/src/clickandgoslider.cpp
1
/*
2
  Q Light Controller Plus
3
  clickandgoslider.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 "clickandgoslider.h"
21
#include <QStyleOptionSlider>
22
#include <QPainter>
23
#include <QStyle>
24

25
ClickAndGoSlider::ClickAndGoSlider(QWidget *parent) : QSlider(parent)
92✔
26
{
27
    m_shadowLevel = -1;
92✔
28
}
92✔
29

30
void ClickAndGoSlider::setSliderStyleSheet(const QString &styleSheet)
15✔
31
{
32
    if (isVisible())
15✔
33
        QSlider::setStyleSheet(styleSheet);
×
34
    else
35
        m_styleSheet = styleSheet;
15✔
36
}
15✔
37

38
void ClickAndGoSlider::setShadowLevel(int level)
×
39
{
40
    m_shadowLevel = level;
×
41
    update();
×
42
}
×
43

44
void ClickAndGoSlider::mousePressEvent(QMouseEvent *e)
×
45
{
46
    if (e->modifiers() == Qt::ControlModifier)
×
47
    {
48
        emit controlClicked();
×
49
        return;
×
50
    }
51

52
    QStyleOptionSlider opt;
×
53
    initStyleOption(&opt);
×
54
    QRect sr = style()->subControlRect(QStyle::CC_Slider, &opt, QStyle::SC_SliderHandle, this);
×
55

56
    if (e->button() == Qt::LeftButton && // react only to left button press
×
57
        sr.contains(e->pos()) == false) // check if the click is not over the slider's handle
×
58
    {
59
        int newVal = 0;
×
60
        if (orientation() == Qt::Vertical)
×
61
            newVal = minimum() + ((maximum() - minimum()) * (height() - e->pos().y())) / height();
×
62
        else
63
            newVal = minimum() + ((maximum() - minimum()) * e->pos().x()) / width();
×
64

65
        setSliderDown(true);
×
66
        if (invertedAppearance() == true)
×
67
            setValue(maximum() - newVal);
×
68
        else
69
            setValue(newVal);
×
70
        setSliderDown(false);
×
71

72
        e->accept();
×
73
    }
74
    QSlider::mousePressEvent(e);
×
75
}
×
76

77
void ClickAndGoSlider::wheelEvent(QWheelEvent *e)
×
78
{
79
    setSliderDown(true);
×
80
    QSlider::wheelEvent(e);
×
81
    setSliderDown(false);
×
82
}
×
83

84
void ClickAndGoSlider::keyPressEvent(QKeyEvent *e)
×
85
{
86
    if (e->key() == Qt::Key_Up || e->key() == Qt::Key_Down)
×
87
        setSliderDown(true);
×
88
    QSlider::keyPressEvent(e);
×
89
    if (e->key() == Qt::Key_Up || e->key() == Qt::Key_Down)
×
90
        setSliderDown(false);
×
91
}
×
92

93
void ClickAndGoSlider::paintEvent(QPaintEvent *e)
5✔
94
{
95
    if (m_shadowLevel >= 0)
5✔
96
    {
97
        QPainter p(this);
×
98
        int levHeight = ((float)height() / 255.0) * m_shadowLevel;
×
99
        p.drawRect(width() - 6, 0, width(), height());
×
100
        p.fillRect(width() - 5, 0, width() - 1, height(), QColor(Qt::darkGray));
×
101
        if (invertedAppearance())
×
102
            p.fillRect(width() - 5, 0, width() - 1, levHeight, QColor(Qt::green));
×
103
        else
104
            p.fillRect(width() - 5, height() - levHeight, width() - 1, height(), QColor(Qt::green));
×
105
    }
×
106

107
    QSlider::paintEvent(e);
5✔
108
}
5✔
109

110
void ClickAndGoSlider::showEvent(QShowEvent *)
2✔
111
{
112
    if (m_styleSheet.isEmpty() == false)
2✔
113
    {
114
        setSliderStyleSheet(m_styleSheet);
×
115
        m_styleSheet = "";
×
116
    }
117
}
2✔
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