ctkDoubleRangeSlider.h 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. /*=========================================================================
  2. Library: CTK
  3. Copyright (c) Kitware Inc.
  4. All rights reserved.
  5. Distributed under a BSD License. See LICENSE.txt file.
  6. This software is distributed "AS IS" WITHOUT ANY WARRANTY; without even
  7. the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  8. See the above copyright notice for more information.
  9. =========================================================================*/
  10. #ifndef __ctkDoubleRangeSlider_h
  11. #define __ctkDoubleRangeSlider_h
  12. // Qt includes
  13. #include <QWidget>
  14. #include <QAbstractSlider>
  15. // CTK includes
  16. #include <ctkPimpl.h>
  17. #include "CTKWidgetsExport.h"
  18. class ctkDoubleRangeSliderPrivate;
  19. class CTK_WIDGETS_EXPORT ctkDoubleRangeSlider : public QWidget
  20. {
  21. Q_OBJECT
  22. Q_PROPERTY(double minimum READ minimum WRITE setMinimum)
  23. Q_PROPERTY(double maximum READ maximum WRITE setMaximum)
  24. Q_PROPERTY(double singleStep READ singleStep WRITE setSingleStep)
  25. Q_PROPERTY(double minimumValue READ minimumValue WRITE setMinimumValue)
  26. Q_PROPERTY(double maximumValue READ maximumValue WRITE setMaximumValue)
  27. Q_PROPERTY(double minimumPosition READ minimumPosition WRITE setMinimumPosition)
  28. Q_PROPERTY(double maximumPosition READ maximumPosition WRITE setMaximumPosition)
  29. Q_PROPERTY(bool tracking READ hasTracking WRITE setTracking)
  30. Q_PROPERTY(Qt::Orientation orientation READ orientation WRITE setOrientation)
  31. Q_PROPERTY(double tickInterval READ tickInterval WRITE setTickInterval)
  32. public:
  33. // Superclass typedef
  34. typedef QWidget Superclass;
  35. // Constructors
  36. ctkDoubleRangeSlider( Qt::Orientation o, QWidget* par= 0 );
  37. ctkDoubleRangeSlider( QWidget* par = 0 );
  38. ///
  39. /// This property holds the single step.
  40. /// The smaller of two natural steps that an abstract sliders provides and
  41. /// typically corresponds to the user pressing an arrow key
  42. void setSingleStep(double ss);
  43. double singleStep()const;
  44. ///
  45. /// This property holds the interval between tickmarks.
  46. /// This is a value interval, not a pixel interval. If it is 0, the slider
  47. /// will choose between lineStep() and pageStep().
  48. /// The default value is 0.
  49. void setTickInterval(double ti);
  50. double tickInterval()const;
  51. ///
  52. /// This property holds the sliders's minimum value.
  53. /// When setting this property, the maximum is adjusted if necessary to
  54. /// ensure that the range remains valid. Also the slider's current values
  55. /// are adjusted to be within the new range.
  56. double minimum()const;
  57. void setMinimum(double min);
  58. ///
  59. /// This property holds the slider's maximum value.
  60. /// When setting this property, the minimum is adjusted if necessary to
  61. /// ensure that the range remains valid. Also the slider's current values
  62. /// are adjusted to be within the new range.
  63. double maximum()const;
  64. void setMaximum(double max);
  65. ///
  66. /// Sets the slider's minimum to min and its maximum to max.
  67. /// If max is smaller than min, min becomes the only legal value.
  68. void setRange(double min, double max);
  69. ///
  70. /// This property holds the slider's current minimum value.
  71. /// The slider forces the minimum value to be within the legal range:
  72. /// minimum <= minvalue <= maxvalue <= maximum.
  73. /// Changing the minimumValue also changes the minimumPosition.
  74. double minimumValue() const;
  75. ///
  76. /// This property holds the slider's current maximum value.
  77. /// The slider forces the maximum value to be within the legal range:
  78. /// minimum <= minvalue <= maxvalue <= maximum.
  79. /// Changing the maximumValue also changes the maximumPosition.
  80. double maximumValue() const;
  81. ///
  82. /// This property holds the current slider minimum position.
  83. /// If tracking is enabled (the default), this is identical to minimumValue.
  84. double minimumPosition() const;
  85. void setMinimumPosition(double minPos);
  86. ///
  87. /// This property holds the current slider maximum position.
  88. /// If tracking is enabled (the default), this is identical to maximumValue.
  89. double maximumPosition() const;
  90. void setMaximumPosition(double maxPos);
  91. ///
  92. /// Utility function that set the minimum position and
  93. /// maximum position at once.
  94. void setPositions(double minPos, double maxPos);
  95. ///
  96. /// This property holds whether slider tracking is enabled.
  97. /// If tracking is enabled (the default), the slider emits the minimumValueChanged()
  98. /// signal while the left/bottom handler is being dragged and the slider emits
  99. /// the maximumValueChanged() signal while the right/top handler is being dragged.
  100. /// If tracking is disabled, the slider emits the minimumValueChanged()
  101. /// and maximumValueChanged() signals only when the user releases the slider.
  102. void setTracking(bool enable);
  103. bool hasTracking()const;
  104. ///
  105. /// Triggers a slider action on the current slider. Possible actions are
  106. /// SliderSingleStepAdd, SliderSingleStepSub, SliderPageStepAdd,
  107. /// SliderPageStepSub, SliderToMinimum, SliderToMaximum, and SliderMove.
  108. void triggerAction(QAbstractSlider::SliderAction action);
  109. ///
  110. /// This property holds the orientation of the slider.
  111. /// The orientation must be Qt::Vertical (the default) or Qt::Horizontal.
  112. Qt::Orientation orientation()const;
  113. void setOrientation(Qt::Orientation orientation);
  114. signals:
  115. ///
  116. /// This signal is emitted when the slider minimum value has changed,
  117. /// with the new slider value as argument.
  118. void minimumValueChanged(double minVal);
  119. ///
  120. /// This signal is emitted when the slider maximum value has changed,
  121. /// with the new slider value as argument.
  122. void maximumValueChanged(double maxVal);
  123. ///
  124. /// Utility signal that is fired when minimum or maximum values have changed.
  125. void valuesChanged(double minVal, double maxVal);
  126. ///
  127. /// This signal is emitted when sliderDown is true and the slider moves.
  128. /// This usually happens when the user is dragging the minimum slider.
  129. /// The value is the new slider minimum position.
  130. /// This signal is emitted even when tracking is turned off.
  131. void minimumPositionChanged(double minPos);
  132. ///
  133. /// This signal is emitted when sliderDown is true and the slider moves.
  134. /// This usually happens when the user is dragging the maximum slider.
  135. /// The value is the new slider maximum position.
  136. /// This signal is emitted even when tracking is turned off.
  137. void maximumPositionChanged(double maxPos);
  138. ///
  139. /// Utility signal that is fired when minimum or maximum positions
  140. /// have changed.
  141. void positionsChanged(double minPos, double maxPos);
  142. ///
  143. /// This signal is emitted when the user presses one slider with the mouse,
  144. /// or programmatically when setSliderDown(true) is called.
  145. void sliderPressed();
  146. ///
  147. /// This signal is emitted when the user releases one slider with the mouse,
  148. /// or programmatically when setSliderDown(false) is called.
  149. void sliderReleased();
  150. public slots:
  151. ///
  152. /// This property holds the slider's current minimum value.
  153. /// The slider forces the minimum value to be within the legal range:
  154. /// minimum <= minvalue <= maxvalue <= maximum.
  155. /// Changing the minimumValue also changes the minimumPosition.
  156. void setMinimumValue(double minVal);
  157. ///
  158. /// This property holds the slider's current maximum value.
  159. /// The slider forces the maximum value to be within the legal range:
  160. /// minimum <= minvalue <= maxvalue <= maximum.
  161. /// Changing the maximumValue also changes the maximumPosition.
  162. void setMaximumValue(double maxVal);
  163. ///
  164. /// Utility function that set the minimum value and maximum value at once.
  165. void setValues(double minVal, double maxVal);
  166. protected slots:
  167. void onMinValueChanged(int value);
  168. void onMaxValueChanged(int value);
  169. void onValuesChanged(int min, int max);
  170. void onMinPosChanged(int value);
  171. void onMaxPosChanged(int value);
  172. void onPositionsChanged(int min, int max);
  173. private:
  174. CTK_DECLARE_PRIVATE(ctkDoubleRangeSlider);
  175. };
  176. #endif