CuteLogger
Fast and simple logging solution for Qt based applications
doublesliderspinner.h
1/*
2 * Copyright (c) 2026 Meltytech, LLC
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18#ifndef DOUBLESLIDERSPINNER_H
19#define DOUBLESLIDERSPINNER_H
20
21#include <QWidget>
22
23class QDoubleSpinBox;
24class QSlider;
25
26class DoubleSliderSpinner : public QWidget
27{
28 Q_OBJECT
29 Q_PROPERTY(double value READ value WRITE setValue NOTIFY valueChanged)
30 Q_PROPERTY(double minimum READ minimum WRITE setMinimum)
31 Q_PROPERTY(double maximum READ maximum WRITE setMaximum)
32 Q_PROPERTY(double singleStep READ singleStep WRITE setSingleStep)
33 Q_PROPERTY(int decimals READ decimals WRITE setDecimals)
34 Q_PROPERTY(QString prefix READ prefix WRITE setPrefix)
35 Q_PROPERTY(QString suffix READ suffix WRITE setSuffix)
36 Q_PROPERTY(QString specialValueText READ specialValueText WRITE setSpecialValueText)
37 Q_PROPERTY(double defaultValue READ defaultValue WRITE setDefaultValue)
38 Q_PROPERTY(bool showResetButton READ showResetButton WRITE setShowResetButton)
39
40public:
41 explicit DoubleSliderSpinner(QWidget *parent = nullptr);
42
43 double value() const;
44 double minimum() const;
45 double maximum() const;
46 double singleStep() const;
47 int decimals() const;
48 QString prefix() const;
49 QString suffix() const;
50 QString specialValueText() const;
51 double defaultValue() const;
52 bool showResetButton() const;
53
54public slots:
55 void setValue(double value);
56 void setMinimum(double value);
57 void setMaximum(double value);
58 void setRange(double min, double max);
59 void setSingleStep(double value);
60 void setDecimals(int decimals);
61 void setPrefix(const QString &prefix);
62 void setSuffix(const QString &suffix);
63 void setSpecialValueText(const QString &text);
64 void setDefaultValue(double value);
65 void setShowResetButton(bool show);
66
67signals:
68 void valueChanged(double value);
69
70private slots:
71 void onSliderValueChanged(int value);
72 void onSpinValueChanged(double value);
73 void onResetButtonClicked();
74
75private:
76 int toSliderValue(double value) const;
77 double toSpinValue(int value) const;
78 void updateScale();
79 void updateSliderRange();
80 void updateResetButtonState();
81
82 QSlider *m_slider;
83 QDoubleSpinBox *m_spinBox;
84 class QToolButton *m_resetButton;
85 int m_scale;
86 double m_defaultValue;
87 bool m_showResetButton;
88};
89
90#endif // DOUBLESLIDERSPINNER_H