File indexing completed on 2024-04-28 03:42:25
0001 /* 0002 SPDX-FileCopyrightText: Kitware Inc. 0003 SPDX-License-Identifier: Apache-2.0 0004 0005 Modified from the original code to support 3 sliders, May 2023. 0006 */ 0007 0008 0009 #ifndef __ctk3Slider_h 0010 #define __ctk3Slider_h 0011 0012 #include <QSlider> 0013 0014 class QStylePainter; 0015 class ctk3SliderPrivate; 0016 0017 /// \ingroup Widgets 0018 /// 0019 /// A ctk3Slider is a slider that lets you input 2 values instead of one 0020 /// (see QSlider). These values are typically a lower and upper bound. 0021 /// Values are comprised between the range of the slider. See setRange(), 0022 /// minimum() and maximum(). The upper bound can't be smaller than the 0023 /// lower bound and vice-versa. 0024 /// When setting new values (setMinimumValue(), setMaximumValue() or 0025 /// setValues()), make sure they lie between the range (minimum(), maximum()) 0026 /// of the slider, they would be forced otherwised. If it is not the behavior 0027 /// you desire, you can set the range first (setRange(), setMinimum(), 0028 /// setMaximum()) 0029 /// \sa ctkDoubleRangeSlider, ctkDoubleSlider, ctkRangeWidget 0030 class ctk3Slider : public QSlider 0031 { 0032 Q_OBJECT 0033 Q_PROPERTY(int minimumValue READ minimumValue WRITE setMinimumValue) 0034 Q_PROPERTY(int maximumValue READ maximumValue WRITE setMaximumValue) 0035 Q_PROPERTY(int midValue READ midValue WRITE setMidValue) 0036 Q_PROPERTY(int minimumPosition READ minimumPosition WRITE setMinimumPosition) 0037 Q_PROPERTY(int maximumPosition READ maximumPosition WRITE setMaximumPosition) 0038 Q_PROPERTY(int midPosition READ midPosition WRITE setMidPosition) 0039 Q_PROPERTY(QString handleToolTip READ handleToolTip WRITE setHandleToolTip) 0040 0041 public: 0042 // Superclass typedef 0043 typedef QSlider Superclass; 0044 /// Constructor, builds a ctk3Slider that ranges from 0 to 100 and has 0045 /// a lower and upper values of 0 and 100 respectively, other properties 0046 /// are set the QSlider default properties. 0047 explicit ctk3Slider( Qt::Orientation o, QWidget* par = 0 ); 0048 explicit ctk3Slider( QWidget* par = 0 ); 0049 virtual ~ctk3Slider(); 0050 0051 /// 0052 /// This property holds the slider's current minimum value. 0053 /// The slider silently forces minimumValue to be within the legal range: 0054 /// minimum() <= minimumValue() <= maximumValue() <= maximum(). 0055 /// Changing the minimumValue also changes the minimumPosition. 0056 int minimumValue() const; 0057 0058 /// 0059 /// This property holds the slider's current maximum value. 0060 /// The slider forces the maximum value to be within the legal range: 0061 /// The slider silently forces maximumValue to be within the legal range: 0062 /// Changing the maximumValue also changes the maximumPosition. 0063 int maximumValue() const; 0064 0065 /// 0066 /// This property holds the slider's current mid value. 0067 /// The slider forces the mid value to be within the legal range: 0068 /// The slider silently forces midValue to be within the legal range: 0069 /// Changing the midValue also changes the midPosition. 0070 int midValue() const; 0071 0072 /// 0073 /// This property holds the current slider minimum position. 0074 /// If tracking is enabled (the default), this is identical to minimumValue. 0075 int minimumPosition() const; 0076 void setMinimumPosition(int min); 0077 0078 /// 0079 /// This property holds the current slider maximum position. 0080 /// If tracking is enabled (the default), this is identical to maximumValue. 0081 int maximumPosition() const; 0082 void setMaximumPosition(int max); 0083 0084 /// 0085 /// This property holds the current slider mid position. 0086 /// If tracking is enabled (the default), this is identical to midValue. 0087 int midPosition() const; 0088 void setMidPosition(int mid); 0089 0090 /// 0091 /// Utility function that set the minimum, mid and maximum position at once. 0092 void setPositions(int min, int mid, int max); 0093 0094 /// 0095 /// Controls the text to display for the handle tooltip. It is in addition 0096 /// to the widget tooltip. 0097 /// "%1" is replaced by the current value of the slider. 0098 /// Empty string (by default) means no tooltip. 0099 QString handleToolTip()const; 0100 void setHandleToolTip(const QString &toolTip); 0101 0102 /// Returns true if the minimum value handle is down, false if it is up. 0103 /// \sa isMaximumSliderDown() 0104 bool isMinimumSliderDown()const; 0105 /// Returns true if the maximum value handle is down, false if it is up. 0106 /// \sa isMinimumSliderDown() 0107 bool isMaximumSliderDown()const; 0108 /// Returns true if the mid value handle is down, false if it is up. 0109 /// \sa isMinimumSliderDown() 0110 bool isMidSliderDown()const; 0111 0112 Q_SIGNALS: 0113 /// 0114 /// This signal is emitted when the slider minimum value has changed, 0115 /// with the new slider value as argument. 0116 void minimumValueChanged(int min); 0117 /// 0118 /// This signal is emitted when the slider maximum value has changed, 0119 /// with the new slider value as argument. 0120 void maximumValueChanged(int max); 0121 /// 0122 /// This signal is emitted when the slider mid value has changed, 0123 /// with the new slider value as argument. 0124 void midValueChanged(int mid); 0125 /// 0126 /// Utility signal that is fired when minimum, mid or maximum values have changed. 0127 void valuesChanged(int min, int mid, int max); 0128 0129 /// 0130 /// This signal is emitted when sliderDown is true and the slider moves. 0131 /// This usually happens when the user is dragging the minimum slider. 0132 /// The value is the new slider minimum position. 0133 /// This signal is emitted even when tracking is turned off. 0134 void minimumPositionChanged(int min); 0135 0136 /// 0137 /// This signal is emitted when sliderDown is true and the slider moves. 0138 /// This usually happens when the user is dragging the maximum slider. 0139 /// The value is the new slider maximum position. 0140 /// This signal is emitted even when tracking is turned off. 0141 void maximumPositionChanged(int max); 0142 0143 /// 0144 /// This signal is emitted when sliderDown is true and the slider moves. 0145 /// This usually happens when the user is dragging the mid slider. 0146 /// The value is the new slider mid position. 0147 /// This signal is emitted even when tracking is turned off. 0148 void midPositionChanged(int max); 0149 0150 /// 0151 /// Utility signal that is fired when minimum or maximum positions 0152 /// have changed. 0153 void positionsChanged(int min, int mid, int max); 0154 0155 // Emitted when the mouse is let go. 0156 void released(int min, int mid, int max); 0157 0158 public Q_SLOTS: 0159 /// 0160 /// This property holds the slider's current minimum value. 0161 /// The slider silently forces min to be within the legal range: 0162 /// minimum() <= min <= mid <= maximumValue() <= maximum(). 0163 /// Note: Changing the minimumValue also changes the minimumPosition. 0164 /// \sa stMaximumValue, setValues, setMinimum, setMaximum, setRange 0165 void setMinimumValue(int min); 0166 0167 /// 0168 /// This property holds the slider's current maximum value. 0169 /// The slider silently forces max to be within the legal range: 0170 /// minimum() <= minimumValue() <= mid <= max <= maximum(). 0171 /// Note: Changing the maximumValue also changes the maximumPosition. 0172 /// \sa stMinimumValue, setValues, setMinimum, setMaximum, setRange 0173 void setMaximumValue(int max); 0174 0175 /// 0176 /// This property holds the slider's current mid value. 0177 /// The slider silently forces max to be within the legal range: 0178 /// minimum() <= minimumValue() <= mid <= max <= maximum(). 0179 /// Note: Changing the midValue also changes the midPosition. 0180 /// \sa setMidValue, setValues, setMinimum, setMaximum, setRange 0181 void setMidValue(int mid); 0182 0183 /// 0184 /// Utility function that set the minimum value and maximum value at once. 0185 /// The slider silently forces min and max to be within the legal range: 0186 /// minimum() <= min <= max <= maximum(). 0187 /// Note: Changing the minimumValue and maximumValue also changes the 0188 /// minimumPosition and maximumPosition. 0189 /// \sa setMinimumValue, setMaximumValue, setMinimum, setMaximum, setRange 0190 void setValues(int min, int mid, int max); 0191 0192 protected Q_SLOTS: 0193 void onRangeChanged(int minimum, int maximum); 0194 0195 protected: 0196 ctk3Slider( ctk3SliderPrivate* impl, Qt::Orientation o, QWidget* par = 0 ); 0197 ctk3Slider( ctk3SliderPrivate* impl, QWidget* par = 0 ); 0198 0199 // Description: 0200 // Standard Qt UI events 0201 virtual void mousePressEvent(QMouseEvent* ev) override; 0202 virtual void mouseMoveEvent(QMouseEvent* ev) override; 0203 virtual void mouseReleaseEvent(QMouseEvent* ev) override; 0204 0205 // Description: 0206 // Rendering is done here. 0207 virtual void paintEvent(QPaintEvent* ev) override; 0208 virtual void initMinimumSliderStyleOption(QStyleOptionSlider* option) const; 0209 virtual void initMaximumSliderStyleOption(QStyleOptionSlider* option) const; 0210 virtual void initMidSliderStyleOption(QStyleOptionSlider* option) const; 0211 0212 // Description: 0213 // Reimplemented for the tooltips 0214 virtual bool event(QEvent* event) override; 0215 0216 protected: 0217 QScopedPointer<ctk3SliderPrivate> d_ptr; 0218 0219 private: 0220 Q_DECLARE_PRIVATE(ctk3Slider); 0221 Q_DISABLE_COPY(ctk3Slider); 0222 }; 0223 0224 #endif 0225