ctkDoubleSlider.h 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  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.commontk.org/LICENSE
  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. /// ctkDoubleSlider is a QSlider that controls doubles instead of integers.
  24. /// ctkDoubleSlider internally aggregates a QSlider
  25. /// TODO: ctkDoubleSlider tries to represent a double value with integers. It's
  26. /// of course non-optimal and can lead to errors, it would be better if
  27. /// ctkDoubleSlider works like QDoubleSpinBox, where the value is a QVariant
  28. /// and the conversion between double and integer is only done to convert
  29. /// to/from screen coordinates.
  30. /// \sa ctkRangeSlider, ctkDoubleRangeSlider, ctkRangeWidget
  31. class CTK_WIDGETS_EXPORT ctkDoubleSlider : public QWidget
  32. {
  33. Q_OBJECT
  34. Q_PROPERTY(double value READ value WRITE setValue)
  35. Q_PROPERTY(double sliderPosition READ sliderPosition WRITE setSliderPosition)
  36. Q_PROPERTY(double singleStep READ singleStep WRITE setSingleStep)
  37. Q_PROPERTY(double minimum READ minimum WRITE setMinimum)
  38. Q_PROPERTY(double maximum READ maximum WRITE setMaximum)
  39. Q_PROPERTY(double tickInterval READ tickInterval WRITE setTickInterval)
  40. Q_PROPERTY(bool tracking READ hasTracking WRITE setTracking)
  41. Q_PROPERTY(Qt::Orientation orientation READ orientation WRITE setOrientation)
  42. public:
  43. /// Superclass typedef
  44. typedef QWidget Superclass;
  45. /// Constructors, builds a slider whose default values are the same as
  46. /// QSlider (vertical by default).
  47. explicit ctkDoubleSlider(QWidget* parent = 0);
  48. /// Constructors, builds a slider whose default values are the same as
  49. /// QSlider (vertical by default).
  50. explicit ctkDoubleSlider(Qt::Orientation orient, QWidget* parent = 0);
  51. /// Destructor
  52. virtual ~ctkDoubleSlider();
  53. ///
  54. /// This property holds the sliders's minimum value.
  55. /// When setting this property, the maximum is adjusted if necessary to
  56. /// ensure that the range remains valid. Also the slider's current value
  57. /// is adjusted to be within the new range.
  58. void setMinimum(double min);
  59. double minimum()const;
  60. ///
  61. /// This property holds the slider's maximum value.
  62. /// When setting this property, the minimum is adjusted if necessary to
  63. /// ensure that the range remains valid. Also the slider's current value
  64. /// is adjusted to be within the new range.
  65. void setMaximum(double max);
  66. double maximum()const;
  67. ///
  68. /// Sets the slider's minimum to min and its maximum to max.
  69. /// If max is smaller than min, min becomes the only legal value.
  70. void setRange(double min, double max);
  71. ///
  72. /// This property holds the slider's current value.
  73. /// The slider forces the value to be within the legal range:
  74. /// minimum <= value <= maximum.
  75. /// Changing the value also changes the sliderPosition.
  76. double value()const;
  77. ///
  78. /// This property holds the single step.
  79. /// The smaller of two natural steps that an abstract sliders provides and
  80. /// typically corresponds to the user pressing an arrow key
  81. void setSingleStep(double step);
  82. double singleStep()const;
  83. ///
  84. /// This property holds the interval between tickmarks.
  85. /// This is a value interval, not a pixel interval. If it is 0, the slider
  86. /// will choose between lineStep() and pageStep().
  87. /// The default value is 0.
  88. void setTickInterval(double ti);
  89. double tickInterval()const;
  90. ///
  91. /// This property holds the current slider position.
  92. /// If tracking is enabled (the default), this is identical to value.
  93. double sliderPosition()const;
  94. void setSliderPosition(double);
  95. ///
  96. /// This property holds whether slider tracking is enabled.
  97. /// If tracking is enabled (the default), the slider emits the valueChanged()
  98. /// signal while the slider is being dragged. If tracking is disabled, the
  99. /// slider emits the valueChanged() signal only when the user releases the
  100. /// slider.
  101. void setTracking(bool enable);
  102. bool hasTracking()const;
  103. ///
  104. /// Triggers a slider action. Possible actions are SliderSingleStepAdd,
  105. /// SliderSingleStepSub, SliderPageStepAdd, SliderPageStepSub,
  106. /// SliderToMinimum, SliderToMaximum, and SliderMove.
  107. void triggerAction(QAbstractSlider::SliderAction action);
  108. ///
  109. /// This property holds the orientation of the slider.
  110. /// The orientation must be Qt::Vertical (the default) or Qt::Horizontal.
  111. Qt::Orientation orientation()const;
  112. public slots:
  113. ///
  114. /// This property holds the slider's current value.
  115. /// The slider forces the value to be within the legal range:
  116. /// minimum <= value <= maximum.
  117. /// Changing the value also changes the sliderPosition.
  118. void setValue(double value);
  119. ///
  120. /// This property holds the orientation of the slider.
  121. /// The orientation must be Qt::Vertical (the default) or Qt::Horizontal.
  122. void setOrientation(Qt::Orientation orientation);
  123. signals:
  124. ///
  125. /// This signal is emitted when the slider value has changed, with the new
  126. /// slider value as argument.
  127. void valueChanged(double value);
  128. ///
  129. /// This signal is emitted when sliderDown is true and the slider moves.
  130. /// This usually happens when the user is dragging the slider. The value
  131. /// is the new slider position.
  132. /// This signal is emitted even when tracking is turned off.
  133. void sliderMoved(double position);
  134. ///
  135. /// This signal is emitted when the user presses the slider with the mouse,
  136. /// or programmatically when setSliderDown(true) is called.
  137. void sliderPressed();
  138. ///
  139. /// This signal is emitted when the user releases the slider with the mouse,
  140. /// or programmatically when setSliderDown(false) is called.
  141. void sliderReleased();
  142. ///
  143. /// This signal is emitted when the slider range has changed, with min being
  144. /// the new minimum, and max being the new maximum.
  145. /// Warning: don't confound with valuesChanged(double, double);
  146. /// \sa QAbstractSlider::rangeChanged()
  147. void rangeChanged(double min, double max);
  148. protected slots:
  149. void onValueChanged(int value);
  150. void onSliderMoved(int position);
  151. void onRangeChanged(int min, int max);
  152. protected:
  153. QScopedPointer<ctkDoubleSliderPrivate> d_ptr;
  154. private:
  155. Q_DECLARE_PRIVATE(ctkDoubleSlider);
  156. Q_DISABLE_COPY(ctkDoubleSlider);
  157. };
  158. #endif