Kstars

ctk3slider.h
1/*
2 SPDX-FileCopyrightText: Kitware Inc.
3 SPDX-License-Identifier: Apache-2.0
4
5 Modified from the original code to support 3 sliders, May 2023.
6*/
7
8
9#ifndef __ctk3Slider_h
10#define __ctk3Slider_h
11
12#include <QSlider>
13
14class QStylePainter;
15class ctk3SliderPrivate;
16
17/// \ingroup Widgets
18///
19/// A ctk3Slider is a slider that lets you input 2 values instead of one
20/// (see QSlider). These values are typically a lower and upper bound.
21/// Values are comprised between the range of the slider. See setRange(),
22/// minimum() and maximum(). The upper bound can't be smaller than the
23/// lower bound and vice-versa.
24/// When setting new values (setMinimumValue(), setMaximumValue() or
25/// setValues()), make sure they lie between the range (minimum(), maximum())
26/// of the slider, they would be forced otherwised. If it is not the behavior
27/// you desire, you can set the range first (setRange(), setMinimum(),
28/// setMaximum())
29/// \sa ctkDoubleRangeSlider, ctkDoubleSlider, ctkRangeWidget
30class ctk3Slider : public QSlider
31{
33 Q_PROPERTY(int minimumValue READ minimumValue WRITE setMinimumValue)
34 Q_PROPERTY(int maximumValue READ maximumValue WRITE setMaximumValue)
35 Q_PROPERTY(int midValue READ midValue WRITE setMidValue)
36 Q_PROPERTY(int minimumPosition READ minimumPosition WRITE setMinimumPosition)
37 Q_PROPERTY(int maximumPosition READ maximumPosition WRITE setMaximumPosition)
38 Q_PROPERTY(int midPosition READ midPosition WRITE setMidPosition)
39 Q_PROPERTY(QString handleToolTip READ handleToolTip WRITE setHandleToolTip)
40
41 public:
42 // Superclass typedef
43 typedef QSlider Superclass;
44 /// Constructor, builds a ctk3Slider that ranges from 0 to 100 and has
45 /// a lower and upper values of 0 and 100 respectively, other properties
46 /// are set the QSlider default properties.
47 explicit ctk3Slider( Qt::Orientation o, QWidget* par = 0 );
48 explicit ctk3Slider( QWidget* par = 0 );
49 virtual ~ctk3Slider();
50
51 ///
52 /// This property holds the slider's current minimum value.
53 /// The slider silently forces minimumValue to be within the legal range:
54 /// minimum() <= minimumValue() <= maximumValue() <= maximum().
55 /// Changing the minimumValue also changes the minimumPosition.
56 int minimumValue() const;
57
58 ///
59 /// This property holds the slider's current maximum value.
60 /// The slider forces the maximum value to be within the legal range:
61 /// The slider silently forces maximumValue to be within the legal range:
62 /// Changing the maximumValue also changes the maximumPosition.
63 int maximumValue() const;
64
65 ///
66 /// This property holds the slider's current mid value.
67 /// The slider forces the mid value to be within the legal range:
68 /// The slider silently forces midValue to be within the legal range:
69 /// Changing the midValue also changes the midPosition.
70 int midValue() const;
71
72 ///
73 /// This property holds the current slider minimum position.
74 /// If tracking is enabled (the default), this is identical to minimumValue.
75 int minimumPosition() const;
76 void setMinimumPosition(int min);
77
78 ///
79 /// This property holds the current slider maximum position.
80 /// If tracking is enabled (the default), this is identical to maximumValue.
81 int maximumPosition() const;
82 void setMaximumPosition(int max);
83
84 ///
85 /// This property holds the current slider mid position.
86 /// If tracking is enabled (the default), this is identical to midValue.
87 int midPosition() const;
88 void setMidPosition(int mid);
89
90 ///
91 /// Utility function that set the minimum, mid and maximum position at once.
92 void setPositions(int min, int mid, int max);
93
94 ///
95 /// Controls the text to display for the handle tooltip. It is in addition
96 /// to the widget tooltip.
97 /// "%1" is replaced by the current value of the slider.
98 /// Empty string (by default) means no tooltip.
99 QString handleToolTip()const;
100 void setHandleToolTip(const QString &toolTip);
101
102 /// Returns true if the minimum value handle is down, false if it is up.
103 /// \sa isMaximumSliderDown()
104 bool isMinimumSliderDown()const;
105 /// Returns true if the maximum value handle is down, false if it is up.
106 /// \sa isMinimumSliderDown()
107 bool isMaximumSliderDown()const;
108 /// Returns true if the mid value handle is down, false if it is up.
109 /// \sa isMinimumSliderDown()
110 bool isMidSliderDown()const;
111
112 Q_SIGNALS:
113 ///
114 /// This signal is emitted when the slider minimum value has changed,
115 /// with the new slider value as argument.
116 void minimumValueChanged(int min);
117 ///
118 /// This signal is emitted when the slider maximum value has changed,
119 /// with the new slider value as argument.
120 void maximumValueChanged(int max);
121 ///
122 /// This signal is emitted when the slider mid value has changed,
123 /// with the new slider value as argument.
124 void midValueChanged(int mid);
125 ///
126 /// Utility signal that is fired when minimum, mid or maximum values have changed.
127 void valuesChanged(int min, int mid, int max);
128
129 ///
130 /// This signal is emitted when sliderDown is true and the slider moves.
131 /// This usually happens when the user is dragging the minimum slider.
132 /// The value is the new slider minimum position.
133 /// This signal is emitted even when tracking is turned off.
135
136 ///
137 /// This signal is emitted when sliderDown is true and the slider moves.
138 /// This usually happens when the user is dragging the maximum slider.
139 /// The value is the new slider maximum position.
140 /// This signal is emitted even when tracking is turned off.
142
143 ///
144 /// This signal is emitted when sliderDown is true and the slider moves.
145 /// This usually happens when the user is dragging the mid slider.
146 /// The value is the new slider mid position.
147 /// This signal is emitted even when tracking is turned off.
148 void midPositionChanged(int max);
149
150 ///
151 /// Utility signal that is fired when minimum or maximum positions
152 /// have changed.
153 void positionsChanged(int min, int mid, int max);
154
155 // Emitted when the mouse is let go.
156 void released(int min, int mid, int max);
157
158 public Q_SLOTS:
159 ///
160 /// This property holds the slider's current minimum value.
161 /// The slider silently forces min to be within the legal range:
162 /// minimum() <= min <= mid <= maximumValue() <= maximum().
163 /// Note: Changing the minimumValue also changes the minimumPosition.
164 /// \sa stMaximumValue, setValues, setMinimum, setMaximum, setRange
165 void setMinimumValue(int min);
166
167 ///
168 /// This property holds the slider's current maximum value.
169 /// The slider silently forces max to be within the legal range:
170 /// minimum() <= minimumValue() <= mid <= max <= maximum().
171 /// Note: Changing the maximumValue also changes the maximumPosition.
172 /// \sa stMinimumValue, setValues, setMinimum, setMaximum, setRange
173 void setMaximumValue(int max);
174
175 ///
176 /// This property holds the slider's current mid value.
177 /// The slider silently forces max to be within the legal range:
178 /// minimum() <= minimumValue() <= mid <= max <= maximum().
179 /// Note: Changing the midValue also changes the midPosition.
180 /// \sa setMidValue, setValues, setMinimum, setMaximum, setRange
181 void setMidValue(int mid);
182
183 ///
184 /// Utility function that set the minimum value and maximum value at once.
185 /// The slider silently forces min and max to be within the legal range:
186 /// minimum() <= min <= max <= maximum().
187 /// Note: Changing the minimumValue and maximumValue also changes the
188 /// minimumPosition and maximumPosition.
189 /// \sa setMinimumValue, setMaximumValue, setMinimum, setMaximum, setRange
190 void setValues(int min, int mid, int max);
191
192 protected Q_SLOTS:
193 void onRangeChanged(int minimum, int maximum);
194
195 protected:
196 ctk3Slider( ctk3SliderPrivate* impl, Qt::Orientation o, QWidget* par = 0 );
197 ctk3Slider( ctk3SliderPrivate* impl, QWidget* par = 0 );
198
199 // Description:
200 // Standard Qt UI events
201 virtual void mousePressEvent(QMouseEvent* ev) override;
202 virtual void mouseMoveEvent(QMouseEvent* ev) override;
203 virtual void mouseReleaseEvent(QMouseEvent* ev) override;
204
205 // Description:
206 // Rendering is done here.
207 virtual void paintEvent(QPaintEvent* ev) override;
208 virtual void initMinimumSliderStyleOption(QStyleOptionSlider* option) const;
209 virtual void initMaximumSliderStyleOption(QStyleOptionSlider* option) const;
210 virtual void initMidSliderStyleOption(QStyleOptionSlider* option) const;
211
212 // Description:
213 // Reimplemented for the tooltips
214 virtual bool event(QEvent* event) override;
215
216 protected:
218
219 private:
220 Q_DECLARE_PRIVATE(ctk3Slider);
221 Q_DISABLE_COPY(ctk3Slider);
222};
223
224#endif
225
A ctk3Slider is a slider that lets you input 2 values instead of one (see QSlider).
Definition ctk3slider.h:31
void maximumPositionChanged(int max)
This signal is emitted when sliderDown is true and the slider moves.
void setValues(int min, int mid, int max)
Utility function that set the minimum value and maximum value at once.
void setMaximumValue(int max)
This property holds the slider's current maximum value.
void minimumPositionChanged(int min)
This signal is emitted when sliderDown is true and the slider moves.
void maximumValueChanged(int max)
This signal is emitted when the slider maximum value has changed, with the new slider value as argume...
void minimumValueChanged(int min)
This signal is emitted when the slider minimum value has changed, with the new slider value as argume...
void positionsChanged(int min, int mid, int max)
Utility signal that is fired when minimum or maximum positions have changed.
bool isMaximumSliderDown() const
Returns true if the maximum value handle is down, false if it is up.
void setPositions(int min, int mid, int max)
Utility function that set the minimum, mid and maximum position at once.
ctk3Slider(Qt::Orientation o, QWidget *par=0)
Constructor, builds a ctk3Slider that ranges from 0 to 100 and has a lower and upper values of 0 and ...
void setMinimumValue(int min)
This property holds the slider's current minimum value.
void setMidValue(int mid)
This property holds the slider's current mid value.
bool isMidSliderDown() const
Returns true if the mid value handle is down, false if it is up.
void midValueChanged(int mid)
This signal is emitted when the slider mid value has changed, with the new slider value as argument.
void midPositionChanged(int max)
This signal is emitted when sliderDown is true and the slider moves.
void valuesChanged(int min, int mid, int max)
Utility signal that is fired when minimum, mid or maximum values have changed.
bool isMinimumSliderDown() const
Returns true if the minimum value handle is down, false if it is up.
Q_OBJECTQ_OBJECT
Q_PROPERTY(...)
Q_SIGNALSQ_SIGNALS
Q_SLOTSQ_SLOTS
Orientation
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 4 2024 16:38:42 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.