ctkDoubleSlider.h 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  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 __ctkDoubleSlider_h
  15. #define __ctkDoubleSlider_h
  16. // Qt includes
  17. #include <QSlider>
  18. #include <QWidget>
  19. // CTK includes
  20. #include <ctkPimpl.h>
  21. #include "ctkWidgetsExport.h"
  22. class ctkDoubleSliderPrivate;
  23. /// \ingroup Widgets
  24. /// ctkDoubleSlider is a QSlider that controls doubles instead of integers.
  25. /// ctkDoubleSlider internally aggregates a QSlider
  26. /// TODO: ctkDoubleSlider tries to represent a double value with integers. It's
  27. /// of course non-optimal and can lead to errors, it would be better if
  28. /// ctkDoubleSlider works like QDoubleSpinBox, where the value is a QVariant
  29. /// and the conversion between double and integer is only done to convert
  30. /// to/from screen coordinates.
  31. /// \sa ctkRangeSlider, ctkDoubleRangeSlider, ctkRangeWidget
  32. class CTK_WIDGETS_EXPORT ctkDoubleSlider : public QWidget
  33. {
  34. Q_OBJECT
  35. Q_PROPERTY(double value READ value WRITE setValue)
  36. Q_PROPERTY(double sliderPosition READ sliderPosition WRITE setSliderPosition)
  37. Q_PROPERTY(double singleStep READ singleStep WRITE setSingleStep)
  38. Q_PROPERTY(double pageStep READ pageStep WRITE setPageStep)
  39. Q_PROPERTY(double minimum READ minimum WRITE setMinimum)
  40. Q_PROPERTY(double maximum READ maximum WRITE setMaximum)
  41. Q_PROPERTY(double tickInterval READ tickInterval WRITE setTickInterval)
  42. Q_PROPERTY(QSlider::TickPosition tickPosition READ tickPosition WRITE setTickPosition)
  43. Q_PROPERTY(bool tracking READ hasTracking WRITE setTracking)
  44. Q_PROPERTY(Qt::Orientation orientation READ orientation WRITE setOrientation)
  45. Q_PROPERTY(QString handleToolTip READ handleToolTip WRITE setHandleToolTip)
  46. Q_PROPERTY(bool invertedAppearance READ invertedAppearance WRITE setInvertedAppearance)
  47. Q_PROPERTY(bool invertedControls READ invertedControls WRITE setInvertedControls)
  48. public:
  49. /// Superclass typedef
  50. typedef QWidget Superclass;
  51. /// Constructors, builds a slider whose default values are the same as
  52. /// QSlider (vertical by default).
  53. explicit ctkDoubleSlider(QWidget* parent = 0);
  54. /// Constructors, builds a slider whose default values are the same as
  55. /// QSlider (vertical by default).
  56. explicit ctkDoubleSlider(Qt::Orientation orient, QWidget* parent = 0);
  57. /// Destructor
  58. virtual ~ctkDoubleSlider();
  59. ///
  60. /// This property holds the sliders's minimum value.
  61. /// When setting this property, the maximum is adjusted if necessary to
  62. /// ensure that the range remains valid. Also the slider's current value
  63. /// is adjusted to be within the new range.
  64. void setMinimum(double min);
  65. double minimum()const;
  66. ///
  67. /// This property holds the slider's maximum value.
  68. /// When setting this property, the minimum is adjusted if necessary to
  69. /// ensure that the range remains valid. Also the slider's current value
  70. /// is adjusted to be within the new range.
  71. void setMaximum(double max);
  72. double maximum()const;
  73. ///
  74. /// Sets the slider's minimum to min and its maximum to max.
  75. /// If max is smaller than min, min becomes the only legal value.
  76. void setRange(double min, double max);
  77. ///
  78. /// This property holds the slider's current value.
  79. /// The slider forces the value to be within the legal range:
  80. /// minimum <= value <= maximum.
  81. /// Changing the value also changes the sliderPosition.
  82. double value()const;
  83. ///
  84. /// This property holds the single step.
  85. /// The smaller of two natural steps that an abstract sliders provides and
  86. /// typically corresponds to the user pressing an arrow key
  87. /// Default value is 1.
  88. void setSingleStep(double step);
  89. double singleStep()const;
  90. ///
  91. /// This property holds the page step.
  92. /// The larger of two natural steps that an abstract slider provides and
  93. /// typically corresponds to the user pressing PageUp or PageDown.
  94. /// Default value is 10.
  95. void setPageStep(double step);
  96. double pageStep()const;
  97. ///
  98. /// This property holds the interval between tickmarks.
  99. /// This is a value interval, not a pixel interval. If it is 0, the slider
  100. /// will choose between lineStep() and pageStep().
  101. /// The default value is 0.
  102. void setTickInterval(double ti);
  103. double tickInterval()const;
  104. ///
  105. /// This property holds the tickmark position for this slider.
  106. /// The valid values are described by the QSlider::TickPosition enum.
  107. /// The default value is QSlider::NoTicks.
  108. void setTickPosition(QSlider::TickPosition position);
  109. QSlider::TickPosition tickPosition()const;
  110. ///
  111. /// This property holds the current slider position.
  112. /// If tracking is enabled (the default), this is identical to value.
  113. double sliderPosition()const;
  114. void setSliderPosition(double);
  115. ///
  116. /// This property holds whether slider tracking is enabled.
  117. /// If tracking is enabled (the default), the slider emits the valueChanged()
  118. /// signal while the slider is being dragged. If tracking is disabled, the
  119. /// slider emits the valueChanged() signal only when the user releases the
  120. /// slider.
  121. void setTracking(bool enable);
  122. bool hasTracking()const;
  123. ///
  124. /// Triggers a slider action. Possible actions are SliderSingleStepAdd,
  125. /// SliderSingleStepSub, SliderPageStepAdd, SliderPageStepSub,
  126. /// SliderToMinimum, SliderToMaximum, and SliderMove.
  127. void triggerAction(QAbstractSlider::SliderAction action);
  128. ///
  129. /// This property holds the orientation of the slider.
  130. /// The orientation must be Qt::Vertical (the default) or Qt::Horizontal.
  131. Qt::Orientation orientation()const;
  132. /// This property holds whether or not a slider shows its values inverted.
  133. /// If this property is false (the default), the minimum and maximum will
  134. /// be shown in its classic position for the inherited widget. If the value
  135. /// is true, the minimum and maximum appear at their opposite location.
  136. /// Note: This property makes most sense for sliders and dials. For scroll
  137. /// bars, the visual effect of the scroll bar subcontrols depends on whether
  138. /// or not the styles understand inverted appearance; most styles ignore this
  139. /// property for scroll bars.
  140. /// \sa invertedControls
  141. void setInvertedAppearance(bool invertedAppearance);
  142. bool invertedAppearance()const;
  143. /// This property holds whether or not the slider inverts its wheel and key
  144. /// events.
  145. /// If this property is false, scrolling the mouse wheel "up" and using keys
  146. /// like page up will increase the slider's value towards its maximum.
  147. /// Otherwise pressing page up will move value towards the slider's minimum.
  148. /// \sa invertedAppearance
  149. void setInvertedControls(bool invertedControls);
  150. bool invertedControls()const;
  151. ///
  152. /// Controls the text to display for the handle tooltip. It is in addition
  153. /// to the widget tooltip.
  154. /// "%1" is replaced by the current value of the slider.
  155. /// Empty string (by default) means no tooltip.
  156. QString handleToolTip()const;
  157. void setHandleToolTip(const QString& toolTip);
  158. /// Reimplemented for internal reasons (handle tooltip).
  159. virtual bool eventFilter(QObject*, QEvent*);
  160. public Q_SLOTS:
  161. ///
  162. /// This property holds the slider's current value.
  163. /// The slider forces the value to be within the legal range:
  164. /// minimum <= value <= maximum.
  165. /// Changing the value also changes the sliderPosition.
  166. void setValue(double value);
  167. ///
  168. /// This property holds the orientation of the slider.
  169. /// The orientation must be Qt::Vertical (the default) or Qt::Horizontal.
  170. void setOrientation(Qt::Orientation orientation);
  171. Q_SIGNALS:
  172. ///
  173. /// This signal is emitted when the slider value has changed, with the new
  174. /// slider value as argument.
  175. void valueChanged(double value);
  176. ///
  177. /// This signal is emitted when sliderDown is true and the slider moves.
  178. /// This usually happens when the user is dragging the slider. The value
  179. /// is the new slider position.
  180. /// This signal is emitted even when tracking is turned off.
  181. void sliderMoved(double position);
  182. ///
  183. /// This signal is emitted when the user presses the slider with the mouse,
  184. /// or programmatically when setSliderDown(true) is called.
  185. void sliderPressed();
  186. ///
  187. /// This signal is emitted when the user releases the slider with the mouse,
  188. /// or programmatically when setSliderDown(false) is called.
  189. void sliderReleased();
  190. ///
  191. /// This signal is emitted when the slider range has changed, with min being
  192. /// the new minimum, and max being the new maximum.
  193. /// Warning: don't confound with valuesChanged(double, double);
  194. /// \sa QAbstractSlider::rangeChanged()
  195. void rangeChanged(double min, double max);
  196. protected Q_SLOTS:
  197. void onValueChanged(int value);
  198. void onSliderMoved(int position);
  199. void onRangeChanged(int min, int max);
  200. protected:
  201. QScopedPointer<ctkDoubleSliderPrivate> d_ptr;
  202. private:
  203. Q_DECLARE_PRIVATE(ctkDoubleSlider);
  204. Q_DISABLE_COPY(ctkDoubleSlider);
  205. };
  206. #endif