ctkDoubleRangeSlider.h 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  1. /*=========================================================================
  2. Library: CTK
  3. Copyright (c) Kitware Inc.
  4. Licensed under the Apache License, Version 2.0 (the "License");
  5. you may not use this file except in compliance with the License.
  6. You may obtain a copy of the License at
  7. http://www.apache.org/licenses/LICENSE-2.0.txt
  8. Unless required by applicable law or agreed to in writing, software
  9. distributed under the License is distributed on an "AS IS" BASIS,
  10. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. See the License for the specific language governing permissions and
  12. limitations under the License.
  13. =========================================================================*/
  14. #ifndef __ctkDoubleRangeSlider_h
  15. #define __ctkDoubleRangeSlider_h
  16. // Qt includes
  17. #include <QWidget>
  18. #include <QSlider>
  19. // CTK includes
  20. #include <ctkPimpl.h>
  21. #include "ctkWidgetsExport.h"
  22. class ctkRangeSlider;
  23. class ctkDoubleRangeSliderPrivate;
  24. /// \ingroup Widgets
  25. /// ctkDoubleRangeSlider is a slider that controls 2 numbers as double.
  26. /// ctkDoubleRangeSlider internally aggregates a ctkRangeSlider (not in the
  27. /// API to prevent misuse). Only subclasses can have access to it.
  28. /// \sa ctkRangeSlider, ctkDoubleSlider, ctkRangeWidget
  29. class CTK_WIDGETS_EXPORT ctkDoubleRangeSlider : public QWidget
  30. {
  31. Q_OBJECT
  32. Q_PROPERTY(double minimum READ minimum WRITE setMinimum)
  33. Q_PROPERTY(double maximum READ maximum WRITE setMaximum)
  34. Q_PROPERTY(double singleStep READ singleStep WRITE setSingleStep)
  35. Q_PROPERTY(double minimumValue READ minimumValue WRITE setMinimumValue)
  36. Q_PROPERTY(double maximumValue READ maximumValue WRITE setMaximumValue)
  37. Q_PROPERTY(double minimumPosition READ minimumPosition WRITE setMinimumPosition)
  38. Q_PROPERTY(double maximumPosition READ maximumPosition WRITE setMaximumPosition)
  39. Q_PROPERTY(bool tracking READ hasTracking WRITE setTracking)
  40. Q_PROPERTY(Qt::Orientation orientation READ orientation WRITE setOrientation)
  41. Q_PROPERTY(double tickInterval READ tickInterval WRITE setTickInterval)
  42. Q_PROPERTY(QSlider::TickPosition tickPosition READ tickPosition WRITE setTickPosition)
  43. Q_PROPERTY(bool symmetricMoves READ symmetricMoves WRITE setSymmetricMoves)
  44. public:
  45. // Superclass typedef
  46. typedef QWidget Superclass;
  47. /// Constructor, builds a ctkDoubleRangeSlider whose default values are the same
  48. /// as ctkRangeSlider.
  49. ctkDoubleRangeSlider( Qt::Orientation o, QWidget* par= 0 );
  50. /// Constructor, builds a ctkDoubleRangeSlider whose default values are the same
  51. /// as ctkRangeSlider.
  52. ctkDoubleRangeSlider( QWidget* par = 0 );
  53. /// Destructor
  54. virtual ~ctkDoubleRangeSlider();
  55. ///
  56. /// This property holds the single step.
  57. /// The smaller of two natural steps that an abstract sliders provides and
  58. /// typically corresponds to the user pressing an arrow key
  59. void setSingleStep(double ss);
  60. double singleStep()const;
  61. ///
  62. /// This property holds the interval between tickmarks.
  63. /// This is a value interval, not a pixel interval. If it is 0, the slider
  64. /// will choose between lineStep() and pageStep().
  65. /// The default value is 0.
  66. void setTickInterval(double ti);
  67. double tickInterval()const;
  68. ///
  69. /// This property holds the tickmark position for this slider.
  70. /// The valid values are described by the QSlider::TickPosition enum.
  71. /// The default value is QSlider::NoTicks.
  72. void setTickPosition(QSlider::TickPosition position);
  73. QSlider::TickPosition tickPosition()const;
  74. ///
  75. /// This property holds the sliders's minimum value.
  76. /// When setting this property, the maximum is adjusted if necessary to
  77. /// ensure that the range remains valid. Also the slider's current values
  78. /// are adjusted to be within the new range.
  79. double minimum()const;
  80. void setMinimum(double min);
  81. ///
  82. /// This property holds the slider's maximum value.
  83. /// When setting this property, the minimum is adjusted if necessary to
  84. /// ensure that the range remains valid. Also the slider's current values
  85. /// are adjusted to be within the new range.
  86. double maximum()const;
  87. void setMaximum(double max);
  88. ///
  89. /// Sets the slider's minimum to min and its maximum to max.
  90. /// If max is smaller than min, min becomes the only legal value.
  91. void setRange(double min, double max);
  92. ///
  93. /// This property holds the slider's current minimum value.
  94. /// The slider forces the minimum value to be within the legal range:
  95. /// minimum <= minvalue <= maxvalue <= maximum.
  96. /// Changing the minimumValue also changes the minimumPosition.
  97. double minimumValue() const;
  98. ///
  99. /// This property holds the slider's current maximum value.
  100. /// The slider forces the maximum value to be within the legal range:
  101. /// minimum <= minvalue <= maxvalue <= maximum.
  102. /// Changing the maximumValue also changes the maximumPosition.
  103. double maximumValue() const;
  104. ///
  105. /// This property holds the current slider minimum position.
  106. /// If tracking is enabled (the default), this is identical to minimumValue.
  107. double minimumPosition() const;
  108. void setMinimumPosition(double minPos);
  109. ///
  110. /// This property holds the current slider maximum position.
  111. /// If tracking is enabled (the default), this is identical to maximumValue.
  112. double maximumPosition() const;
  113. void setMaximumPosition(double maxPos);
  114. ///
  115. /// Utility function that set the minimum position and
  116. /// maximum position at once.
  117. void setPositions(double minPos, double maxPos);
  118. ///
  119. /// This property holds whether slider tracking is enabled.
  120. /// If tracking is enabled (the default), the slider emits the minimumValueChanged()
  121. /// signal while the left/bottom handler is being dragged and the slider emits
  122. /// the maximumValueChanged() signal while the right/top handler is being dragged.
  123. /// If tracking is disabled, the slider emits the minimumValueChanged()
  124. /// and maximumValueChanged() signals only when the user releases the slider.
  125. void setTracking(bool enable);
  126. bool hasTracking()const;
  127. ///
  128. /// Triggers a slider action on the current slider. Possible actions are
  129. /// SliderSingleStepAdd, SliderSingleStepSub, SliderPageStepAdd,
  130. /// SliderPageStepSub, SliderToMinimum, SliderToMaximum, and SliderMove.
  131. void triggerAction(QAbstractSlider::SliderAction action);
  132. ///
  133. /// This property holds the orientation of the slider.
  134. /// The orientation must be Qt::Vertical (the default) or Qt::Horizontal.
  135. Qt::Orientation orientation()const;
  136. void setOrientation(Qt::Orientation orientation);
  137. ///
  138. /// When symmetricMoves is true, moving a handle will move the other handle
  139. /// symmetrically, otherwise the handles are independent. False by default
  140. bool symmetricMoves()const;
  141. void setSymmetricMoves(bool symmetry);
  142. Q_SIGNALS:
  143. ///
  144. /// This signal is emitted when the slider minimum value has changed,
  145. /// with the new slider value as argument.
  146. void minimumValueChanged(double minVal);
  147. ///
  148. /// This signal is emitted when the slider maximum value has changed,
  149. /// with the new slider value as argument.
  150. void maximumValueChanged(double maxVal);
  151. ///
  152. /// Utility signal that is fired when minimum or maximum values have changed.
  153. void valuesChanged(double minVal, double maxVal);
  154. ///
  155. /// This signal is emitted when sliderDown is true and the slider moves.
  156. /// This usually happens when the user is dragging the minimum slider.
  157. /// The value is the new slider minimum position.
  158. /// This signal is emitted even when tracking is turned off.
  159. void minimumPositionChanged(double minPos);
  160. ///
  161. /// This signal is emitted when sliderDown is true and the slider moves.
  162. /// This usually happens when the user is dragging the maximum slider.
  163. /// The value is the new slider maximum position.
  164. /// This signal is emitted even when tracking is turned off.
  165. void maximumPositionChanged(double maxPos);
  166. ///
  167. /// Utility signal that is fired when minimum or maximum positions
  168. /// have changed.
  169. void positionsChanged(double minPos, double maxPos);
  170. ///
  171. /// This signal is emitted when the user presses one slider with the mouse,
  172. /// or programmatically when setSliderDown(true) is called.
  173. void sliderPressed();
  174. ///
  175. /// This signal is emitted when the user releases one slider with the mouse,
  176. /// or programmatically when setSliderDown(false) is called.
  177. void sliderReleased();
  178. ///
  179. /// This signal is emitted when the slider range has changed, with min being
  180. /// the new minimum, and max being the new maximum.
  181. /// Warning: don't confound with valuesChanged(double, double);
  182. /// \sa QAbstractSlider::rangeChanged()
  183. void rangeChanged(double min, double max);
  184. public Q_SLOTS:
  185. ///
  186. /// This property holds the slider's current minimum value.
  187. /// The slider forces the minimum value to be within the legal range:
  188. /// minimum <= minvalue <= maxvalue <= maximum.
  189. /// Changing the minimumValue also changes the minimumPosition.
  190. void setMinimumValue(double minVal);
  191. ///
  192. /// This property holds the slider's current maximum value.
  193. /// The slider forces the maximum value to be within the legal range:
  194. /// minimum <= minvalue <= maxvalue <= maximum.
  195. /// Changing the maximumValue also changes the maximumPosition.
  196. void setMaximumValue(double maxVal);
  197. ///
  198. /// Utility function that set the minimum value and maximum value at once.
  199. void setValues(double minVal, double maxVal);
  200. protected Q_SLOTS:
  201. void onValuesChanged(int min, int max);
  202. void onMinPosChanged(int value);
  203. void onMaxPosChanged(int value);
  204. void onPositionsChanged(int min, int max);
  205. void onRangeChanged(int min, int max);
  206. protected:
  207. ctkRangeSlider* slider()const;
  208. /// Subclasses can change the internal slider
  209. void setSlider(ctkRangeSlider* slider);
  210. protected:
  211. QScopedPointer<ctkDoubleRangeSliderPrivate> d_ptr;
  212. private:
  213. Q_DECLARE_PRIVATE(ctkDoubleRangeSlider);
  214. Q_DISABLE_COPY(ctkDoubleRangeSlider);
  215. };
  216. #endif