ctkDoubleSlider.h 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  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(bool tracking READ hasTracking WRITE setTracking)
  43. Q_PROPERTY(Qt::Orientation orientation READ orientation WRITE setOrientation)
  44. Q_PROPERTY(QString handleToolTip READ handleToolTip WRITE setHandleToolTip)
  45. public:
  46. /// Superclass typedef
  47. typedef QWidget Superclass;
  48. /// Constructors, builds a slider whose default values are the same as
  49. /// QSlider (vertical by default).
  50. explicit ctkDoubleSlider(QWidget* parent = 0);
  51. /// Constructors, builds a slider whose default values are the same as
  52. /// QSlider (vertical by default).
  53. explicit ctkDoubleSlider(Qt::Orientation orient, QWidget* parent = 0);
  54. /// Destructor
  55. virtual ~ctkDoubleSlider();
  56. ///
  57. /// This property holds the sliders's minimum value.
  58. /// When setting this property, the maximum is adjusted if necessary to
  59. /// ensure that the range remains valid. Also the slider's current value
  60. /// is adjusted to be within the new range.
  61. void setMinimum(double min);
  62. double minimum()const;
  63. ///
  64. /// This property holds the slider's maximum value.
  65. /// When setting this property, the minimum is adjusted if necessary to
  66. /// ensure that the range remains valid. Also the slider's current value
  67. /// is adjusted to be within the new range.
  68. void setMaximum(double max);
  69. double maximum()const;
  70. ///
  71. /// Sets the slider's minimum to min and its maximum to max.
  72. /// If max is smaller than min, min becomes the only legal value.
  73. void setRange(double min, double max);
  74. ///
  75. /// This property holds the slider's current value.
  76. /// The slider forces the value to be within the legal range:
  77. /// minimum <= value <= maximum.
  78. /// Changing the value also changes the sliderPosition.
  79. double value()const;
  80. ///
  81. /// This property holds the single step.
  82. /// The smaller of two natural steps that an abstract sliders provides and
  83. /// typically corresponds to the user pressing an arrow key
  84. /// Default value is 1.
  85. void setSingleStep(double step);
  86. double singleStep()const;
  87. ///
  88. /// This property holds the page step.
  89. /// The larger of two natural steps that an abstract slider provides and
  90. /// typically corresponds to the user pressing PageUp or PageDown.
  91. /// Default value is 10.
  92. void setPageStep(double step);
  93. double pageStep()const;
  94. ///
  95. /// This property holds the interval between tickmarks.
  96. /// This is a value interval, not a pixel interval. If it is 0, the slider
  97. /// will choose between lineStep() and pageStep().
  98. /// The default value is 0.
  99. void setTickInterval(double ti);
  100. double tickInterval()const;
  101. ///
  102. /// This property holds the current slider position.
  103. /// If tracking is enabled (the default), this is identical to value.
  104. double sliderPosition()const;
  105. void setSliderPosition(double);
  106. ///
  107. /// This property holds whether slider tracking is enabled.
  108. /// If tracking is enabled (the default), the slider emits the valueChanged()
  109. /// signal while the slider is being dragged. If tracking is disabled, the
  110. /// slider emits the valueChanged() signal only when the user releases the
  111. /// slider.
  112. void setTracking(bool enable);
  113. bool hasTracking()const;
  114. ///
  115. /// Triggers a slider action. Possible actions are SliderSingleStepAdd,
  116. /// SliderSingleStepSub, SliderPageStepAdd, SliderPageStepSub,
  117. /// SliderToMinimum, SliderToMaximum, and SliderMove.
  118. void triggerAction(QAbstractSlider::SliderAction action);
  119. ///
  120. /// This property holds the orientation of the slider.
  121. /// The orientation must be Qt::Vertical (the default) or Qt::Horizontal.
  122. Qt::Orientation orientation()const;
  123. ///
  124. /// Controls the text to display for the handle tooltip. It is in addition
  125. /// to the widget tooltip.
  126. /// "%1" is replaced by the current value of the slider.
  127. /// Empty string (by default) means no tooltip.
  128. QString handleToolTip()const;
  129. void setHandleToolTip(const QString& toolTip);
  130. /// Reimplemented for internal reasons (handle tooltip).
  131. virtual bool eventFilter(QObject*, QEvent*);
  132. public Q_SLOTS:
  133. ///
  134. /// This property holds the slider's current value.
  135. /// The slider forces the value to be within the legal range:
  136. /// minimum <= value <= maximum.
  137. /// Changing the value also changes the sliderPosition.
  138. void setValue(double value);
  139. ///
  140. /// This property holds the orientation of the slider.
  141. /// The orientation must be Qt::Vertical (the default) or Qt::Horizontal.
  142. void setOrientation(Qt::Orientation orientation);
  143. Q_SIGNALS:
  144. ///
  145. /// This signal is emitted when the slider value has changed, with the new
  146. /// slider value as argument.
  147. void valueChanged(double value);
  148. ///
  149. /// This signal is emitted when sliderDown is true and the slider moves.
  150. /// This usually happens when the user is dragging the slider. The value
  151. /// is the new slider position.
  152. /// This signal is emitted even when tracking is turned off.
  153. void sliderMoved(double position);
  154. ///
  155. /// This signal is emitted when the user presses the slider with the mouse,
  156. /// or programmatically when setSliderDown(true) is called.
  157. void sliderPressed();
  158. ///
  159. /// This signal is emitted when the user releases the slider with the mouse,
  160. /// or programmatically when setSliderDown(false) is called.
  161. void sliderReleased();
  162. ///
  163. /// This signal is emitted when the slider range has changed, with min being
  164. /// the new minimum, and max being the new maximum.
  165. /// Warning: don't confound with valuesChanged(double, double);
  166. /// \sa QAbstractSlider::rangeChanged()
  167. void rangeChanged(double min, double max);
  168. protected Q_SLOTS:
  169. void onValueChanged(int value);
  170. void onSliderMoved(int position);
  171. void onRangeChanged(int min, int max);
  172. protected:
  173. QScopedPointer<ctkDoubleSliderPrivate> d_ptr;
  174. private:
  175. Q_DECLARE_PRIVATE(ctkDoubleSlider);
  176. Q_DISABLE_COPY(ctkDoubleSlider);
  177. };
  178. #endif