ctkDoubleSlider.h 5.5 KB

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