ctkDoubleSlider.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. /*=========================================================================
  2. Library: CTK
  3. Copyright (c) 2010 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. class CTK_WIDGETS_EXPORT ctkDoubleSlider : public QWidget
  24. {
  25. Q_OBJECT
  26. Q_PROPERTY(double value READ value WRITE setValue)
  27. Q_PROPERTY(double sliderPosition READ sliderPosition WRITE setSliderPosition)
  28. Q_PROPERTY(double singleStep READ singleStep WRITE setSingleStep)
  29. Q_PROPERTY(double minimum READ minimum WRITE setMinimum)
  30. Q_PROPERTY(double maximum READ maximum WRITE setMaximum)
  31. Q_PROPERTY(double tickInterval READ tickInterval WRITE setTickInterval)
  32. Q_PROPERTY(bool tracking READ hasTracking WRITE setTracking)
  33. Q_PROPERTY(Qt::Orientation orientation READ orientation WRITE setOrientation)
  34. public:
  35. /// Superclass typedef
  36. typedef QWidget Superclass;
  37. ///
  38. /// Constructors
  39. /// Vertical by default
  40. explicit ctkDoubleSlider(QWidget* parent = 0);
  41. explicit ctkDoubleSlider(Qt::Orientation orient, QWidget* parent = 0);
  42. /// Destructor
  43. virtual ~ctkDoubleSlider();
  44. ///
  45. /// This property holds the sliders's minimum value.
  46. /// When setting this property, the maximum is adjusted if necessary to
  47. /// ensure that the range remains valid. Also the slider's current value
  48. /// is adjusted to be within the new range.
  49. void setMinimum(double min);
  50. double minimum()const;
  51. ///
  52. /// This property holds the slider's maximum value.
  53. /// When setting this property, the minimum is adjusted if necessary to
  54. /// ensure that the range remains valid. Also the slider's current value
  55. /// is adjusted to be within the new range.
  56. void setMaximum(double max);
  57. double maximum()const;
  58. ///
  59. /// Sets the slider's minimum to min and its maximum to max.
  60. /// If max is smaller than min, min becomes the only legal value.
  61. void setRange(double min, double max);
  62. ///
  63. /// This property holds the slider's current value.
  64. /// The slider forces the value to be within the legal range:
  65. /// minimum <= value <= maximum.
  66. /// Changing the value also changes the sliderPosition.
  67. double value()const;
  68. ///
  69. /// This property holds the single step.
  70. /// The smaller of two natural steps that an abstract sliders provides and
  71. /// typically corresponds to the user pressing an arrow key
  72. void setSingleStep(double step);
  73. double singleStep()const;
  74. ///
  75. /// This property holds the interval between tickmarks.
  76. /// This is a value interval, not a pixel interval. If it is 0, the slider
  77. /// will choose between lineStep() and pageStep().
  78. /// The default value is 0.
  79. void setTickInterval(double ti);
  80. double tickInterval()const;
  81. ///
  82. /// This property holds the current slider position.
  83. /// If tracking is enabled (the default), this is identical to value.
  84. double sliderPosition()const;
  85. void setSliderPosition(double);
  86. ///
  87. /// This property holds whether slider tracking is enabled.
  88. /// If tracking is enabled (the default), the slider emits the valueChanged()
  89. /// signal while the slider is being dragged. If tracking is disabled, the
  90. /// slider emits the valueChanged() signal only when the user releases the
  91. /// slider.
  92. void setTracking(bool enable);
  93. bool hasTracking()const;
  94. ///
  95. /// Triggers a slider action. Possible actions are SliderSingleStepAdd,
  96. /// SliderSingleStepSub, SliderPageStepAdd, SliderPageStepSub,
  97. /// SliderToMinimum, SliderToMaximum, and SliderMove.
  98. void triggerAction(QAbstractSlider::SliderAction action);
  99. ///
  100. /// This property holds the orientation of the slider.
  101. /// The orientation must be Qt::Vertical (the default) or Qt::Horizontal.
  102. Qt::Orientation orientation()const;
  103. public slots:
  104. ///
  105. /// This property holds the slider's current value.
  106. /// The slider forces the value to be within the legal range:
  107. /// minimum <= value <= maximum.
  108. /// Changing the value also changes the sliderPosition.
  109. void setValue(double value);
  110. ///
  111. /// This property holds the orientation of the slider.
  112. /// The orientation must be Qt::Vertical (the default) or Qt::Horizontal.
  113. void setOrientation(Qt::Orientation orientation);
  114. protected slots:
  115. void onValueChanged(int value);
  116. void onSliderMoved(int position);
  117. signals:
  118. ///
  119. /// This signal is emitted when the slider value has changed, with the new
  120. /// slider value as argument.
  121. void valueChanged(double value);
  122. ///
  123. /// This signal is emitted when sliderDown is true and the slider moves.
  124. /// This usually happens when the user is dragging the slider. The value
  125. /// is the new slider position.
  126. /// This signal is emitted even when tracking is turned off.
  127. void sliderMoved(double position);
  128. ///
  129. /// This signal is emitted when the user presses the slider with the mouse,
  130. /// or programmatically when setSliderDown(true) is called.
  131. void sliderPressed();
  132. ///
  133. /// This signal is emitted when the user releases the slider with the mouse,
  134. /// or programmatically when setSliderDown(false) is called.
  135. void sliderReleased();
  136. private:
  137. CTK_DECLARE_PRIVATE(ctkDoubleSlider);
  138. };
  139. #endif