ctkDoubleRangeSlider.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  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. class ctkValueProxy;
  25. /// \ingroup Widgets
  26. /// ctkDoubleRangeSlider is a slider that controls 2 numbers as double.
  27. /// ctkDoubleRangeSlider internally aggregates a ctkRangeSlider (not in the
  28. /// API to prevent misuse). Only subclasses can have access to it.
  29. /// \sa ctkRangeSlider, ctkDoubleSlider, ctkRangeWidget
  30. class CTK_WIDGETS_EXPORT ctkDoubleRangeSlider : public QWidget
  31. {
  32. Q_OBJECT
  33. Q_PROPERTY(double minimum READ minimum WRITE setMinimum)
  34. Q_PROPERTY(double maximum READ maximum WRITE setMaximum)
  35. Q_PROPERTY(double singleStep READ singleStep WRITE setSingleStep)
  36. Q_PROPERTY(double minimumValue READ minimumValue WRITE setMinimumValue)
  37. Q_PROPERTY(double maximumValue READ maximumValue WRITE setMaximumValue)
  38. Q_PROPERTY(double minimumPosition READ minimumPosition WRITE setMinimumPosition)
  39. Q_PROPERTY(double maximumPosition READ maximumPosition WRITE setMaximumPosition)
  40. Q_PROPERTY(bool tracking READ hasTracking WRITE setTracking)
  41. Q_PROPERTY(Qt::Orientation orientation READ orientation WRITE setOrientation)
  42. Q_PROPERTY(double tickInterval READ tickInterval WRITE setTickInterval)
  43. Q_PROPERTY(QSlider::TickPosition tickPosition READ tickPosition WRITE setTickPosition)
  44. Q_PROPERTY(bool symmetricMoves READ symmetricMoves WRITE setSymmetricMoves)
  45. public:
  46. // Superclass typedef
  47. typedef QWidget Superclass;
  48. /// Constructor, builds a ctkDoubleRangeSlider whose default values are the same
  49. /// as ctkRangeSlider.
  50. ctkDoubleRangeSlider( Qt::Orientation o, QWidget* par= 0 );
  51. /// Constructor, builds a ctkDoubleRangeSlider whose default values are the same
  52. /// as ctkRangeSlider.
  53. ctkDoubleRangeSlider( QWidget* par = 0 );
  54. /// Destructor
  55. virtual ~ctkDoubleRangeSlider();
  56. ///
  57. /// This property holds the single step.
  58. /// The smaller of two natural steps that an abstract sliders provides and
  59. /// typically corresponds to the user pressing an arrow key
  60. /// \sa isValidStep()
  61. void setSingleStep(double ss);
  62. double singleStep()const;
  63. /// Return true if the step can be handled by the slider, false otherwise.
  64. /// An invalid step is a step that can't be used to convert from double
  65. /// to int (too large or too small).
  66. /// \sa singleStep
  67. bool isValidStep(double step)const;
  68. ///
  69. /// This property holds the interval between tickmarks.
  70. /// This is a value interval, not a pixel interval. If it is 0, the slider
  71. /// will choose between lineStep() and pageStep().
  72. /// The default value is 0.
  73. void setTickInterval(double ti);
  74. double tickInterval()const;
  75. ///
  76. /// This property holds the tickmark position for this slider.
  77. /// The valid values are described by the QSlider::TickPosition enum.
  78. /// The default value is QSlider::NoTicks.
  79. void setTickPosition(QSlider::TickPosition position);
  80. QSlider::TickPosition tickPosition()const;
  81. ///
  82. /// This property holds the sliders's minimum value.
  83. /// When setting this property, the maximum 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 minimum()const;
  87. void setMinimum(double min);
  88. ///
  89. /// This property holds the slider's maximum value.
  90. /// When setting this property, the minimum is adjusted if necessary to
  91. /// ensure that the range remains valid. Also the slider's current values
  92. /// are adjusted to be within the new range.
  93. double maximum()const;
  94. void setMaximum(double max);
  95. ///
  96. /// Sets the slider's minimum to min and its maximum to max.
  97. /// If max is smaller than min, min becomes the only legal value.
  98. void setRange(double min, double max);
  99. ///
  100. /// This property holds the slider's current minimum value.
  101. /// The slider forces the minimum value to be within the legal range:
  102. /// minimum <= minvalue <= maxvalue <= maximum.
  103. /// Changing the minimumValue also changes the minimumPosition.
  104. double minimumValue() const;
  105. ///
  106. /// This property holds the slider's current maximum value.
  107. /// The slider forces the maximum value to be within the legal range:
  108. /// minimum <= minvalue <= maxvalue <= maximum.
  109. /// Changing the maximumValue also changes the maximumPosition.
  110. double maximumValue() const;
  111. ///
  112. /// This property holds the current slider minimum position.
  113. /// If tracking is enabled (the default), this is identical to minimumValue.
  114. double minimumPosition() const;
  115. void setMinimumPosition(double minPos);
  116. ///
  117. /// This property holds the current slider maximum position.
  118. /// If tracking is enabled (the default), this is identical to maximumValue.
  119. double maximumPosition() const;
  120. void setMaximumPosition(double maxPos);
  121. ///
  122. /// Utility function that set the minimum position and
  123. /// maximum position at once.
  124. void setPositions(double minPos, double maxPos);
  125. ///
  126. /// This property holds whether slider tracking is enabled.
  127. /// If tracking is enabled (the default), the slider emits the minimumValueChanged()
  128. /// signal while the left/bottom handler is being dragged and the slider emits
  129. /// the maximumValueChanged() signal while the right/top handler is being dragged.
  130. /// If tracking is disabled, the slider emits the minimumValueChanged()
  131. /// and maximumValueChanged() signals only when the user releases the slider.
  132. void setTracking(bool enable);
  133. bool hasTracking()const;
  134. ///
  135. /// Triggers a slider action on the current slider. Possible actions are
  136. /// SliderSingleStepAdd, SliderSingleStepSub, SliderPageStepAdd,
  137. /// SliderPageStepSub, SliderToMinimum, SliderToMaximum, and SliderMove.
  138. void triggerAction(QAbstractSlider::SliderAction action);
  139. ///
  140. /// This property holds the orientation of the slider.
  141. /// The orientation must be Qt::Vertical (the default) or Qt::Horizontal.
  142. Qt::Orientation orientation()const;
  143. void setOrientation(Qt::Orientation orientation);
  144. ///
  145. /// When symmetricMoves is true, moving a handle will move the other handle
  146. /// symmetrically, otherwise the handles are independent. False by default
  147. bool symmetricMoves()const;
  148. void setSymmetricMoves(bool symmetry);
  149. /// Set/Get the value proxy of the internal range slider.
  150. /// \sa setValueProxy(), valueProxy()
  151. void setValueProxy(ctkValueProxy* proxy);
  152. ctkValueProxy* valueProxy() const;
  153. Q_SIGNALS:
  154. ///
  155. /// This signal is emitted when the slider minimum value has changed,
  156. /// with the new slider value as argument.
  157. void minimumValueChanged(double minVal);
  158. ///
  159. /// This signal is emitted when the slider maximum value has changed,
  160. /// with the new slider value as argument.
  161. void maximumValueChanged(double maxVal);
  162. ///
  163. /// Utility signal that is fired when minimum or maximum values have changed.
  164. void valuesChanged(double minVal, double maxVal);
  165. ///
  166. /// This signal is emitted when sliderDown is true and the slider moves.
  167. /// This usually happens when the user is dragging the minimum slider.
  168. /// The value is the new slider minimum position.
  169. /// This signal is emitted even when tracking is turned off.
  170. void minimumPositionChanged(double minPos);
  171. ///
  172. /// This signal is emitted when sliderDown is true and the slider moves.
  173. /// This usually happens when the user is dragging the maximum slider.
  174. /// The value is the new slider maximum position.
  175. /// This signal is emitted even when tracking is turned off.
  176. void maximumPositionChanged(double maxPos);
  177. ///
  178. /// Utility signal that is fired when minimum or maximum positions
  179. /// have changed.
  180. void positionsChanged(double minPos, double maxPos);
  181. ///
  182. /// This signal is emitted when the user presses one slider with the mouse,
  183. /// or programmatically when setSliderDown(true) is called.
  184. void sliderPressed();
  185. ///
  186. /// This signal is emitted when the user releases one slider with the mouse,
  187. /// or programmatically when setSliderDown(false) is called.
  188. void sliderReleased();
  189. ///
  190. /// This signal is emitted when the slider range has changed, with min being
  191. /// the new minimum, and max being the new maximum.
  192. /// Warning: don't confound with valuesChanged(double, double);
  193. /// \sa QAbstractSlider::rangeChanged()
  194. void rangeChanged(double min, double max);
  195. public Q_SLOTS:
  196. ///
  197. /// This property holds the slider's current minimum value.
  198. /// The slider forces the minimum value to be within the legal range:
  199. /// minimum <= minvalue <= maxvalue <= maximum.
  200. /// Changing the minimumValue also changes the minimumPosition.
  201. void setMinimumValue(double minVal);
  202. ///
  203. /// This property holds the slider's current maximum value.
  204. /// The slider forces the maximum value to be within the legal range:
  205. /// minimum <= minvalue <= maxvalue <= maximum.
  206. /// Changing the maximumValue also changes the maximumPosition.
  207. void setMaximumValue(double maxVal);
  208. ///
  209. /// Utility function that set the minimum value and maximum value at once.
  210. void setValues(double minVal, double maxVal);
  211. protected Q_SLOTS:
  212. void onValuesChanged(int min, int max);
  213. void onMinPosChanged(int value);
  214. void onMaxPosChanged(int value);
  215. void onPositionsChanged(int min, int max);
  216. void onRangeChanged(int min, int max);
  217. void onValueProxyAboutToBeModified();
  218. void onValueProxyModified();
  219. protected:
  220. ctkRangeSlider* slider()const;
  221. /// Subclasses can change the internal slider
  222. void setSlider(ctkRangeSlider* slider);
  223. protected:
  224. QScopedPointer<ctkDoubleRangeSliderPrivate> d_ptr;
  225. private:
  226. Q_DECLARE_PRIVATE(ctkDoubleRangeSlider);
  227. Q_DISABLE_COPY(ctkDoubleRangeSlider);
  228. };
  229. #endif