ctkRangeSlider.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  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 __ctkRangeSlider_h
  11. #define __ctkRangeSlider_h
  12. // Qt includes
  13. #include <QSlider>
  14. // CTK includes
  15. #include <ctkPimpl.h>
  16. #include "CTKWidgetsExport.h"
  17. class QStylePainter;
  18. class ctkRangeSliderPrivate;
  19. ///
  20. /// A ctkRangeSlider is a slider that lets you input 2 values instead of one
  21. /// (see QSlider). These values are typically a lower and upper bound.
  22. /// Values are comprised between the range of the slider. (see setRange(),
  23. /// minimum() and maximum()). The upper bound can't be smaller than the
  24. /// lower bound and vice-versa.
  25. /// FIXME: support triggerAction(QAbstractSlider::SliderSingleStepSub) that
  26. /// moves both values at a time.
  27. class CTK_WIDGETS_EXPORT ctkRangeSlider : public QSlider
  28. {
  29. Q_OBJECT
  30. Q_PROPERTY(int minimumValue READ minimumValue WRITE setMinimumValue)
  31. Q_PROPERTY(int maximumValue READ maximumValue WRITE setMaximumValue)
  32. Q_PROPERTY(int minimumPosition READ minimumPosition WRITE setMinimumPosition)
  33. Q_PROPERTY(int maximumPosition READ maximumPosition WRITE setMaximumPosition)
  34. public:
  35. // Superclass typedef
  36. typedef QSlider Superclass;
  37. // Constructors
  38. explicit ctkRangeSlider( Qt::Orientation o, QWidget* par= 0 );
  39. explicit ctkRangeSlider( QWidget* par = 0 );
  40. virtual ~ctkRangeSlider();
  41. ///
  42. /// This property holds the slider's current minimum value.
  43. /// The slider forces the minimum value to be within the legal range:
  44. /// minimum <= minvalue <= maxvalue <= maximum.
  45. /// Changing the minimumValue also changes the minimumPosition.
  46. int minimumValue() const;
  47. ///
  48. /// This property holds the slider's current maximum value.
  49. /// The slider forces the maximum value to be within the legal range:
  50. /// minimum <= minvalue <= maxvalue <= maximum.
  51. /// Changing the maximumValue also changes the maximumPosition.
  52. int maximumValue() const;
  53. ///
  54. /// This property holds the current slider minimum position.
  55. /// If tracking is enabled (the default), this is identical to minimumValue.
  56. int minimumPosition() const;
  57. void setMinimumPosition(int min);
  58. ///
  59. /// This property holds the current slider maximum position.
  60. /// If tracking is enabled (the default), this is identical to maximumValue.
  61. int maximumPosition() const;
  62. void setMaximumPosition(int max);
  63. ///
  64. /// Utility function that set the minimum position and
  65. /// maximum position at once.
  66. void setPositions(int min, int max);
  67. signals:
  68. ///
  69. /// This signal is emitted when the slider minimum value has changed,
  70. /// with the new slider value as argument.
  71. void minimumValueChanged(int min);
  72. ///
  73. /// This signal is emitted when the slider maximum value has changed,
  74. /// with the new slider value as argument.
  75. void maximumValueChanged(int max);
  76. ///
  77. /// Utility signal that is fired when minimum or maximum values have changed.
  78. void valuesChanged(int min, int max);
  79. ///
  80. /// This signal is emitted when sliderDown is true and the slider moves.
  81. /// This usually happens when the user is dragging the minimum slider.
  82. /// The value is the new slider minimum position.
  83. /// This signal is emitted even when tracking is turned off.
  84. void minimumPositionChanged(int min);
  85. ///
  86. /// This signal is emitted when sliderDown is true and the slider moves.
  87. /// This usually happens when the user is dragging the maximum slider.
  88. /// The value is the new slider maximum position.
  89. /// This signal is emitted even when tracking is turned off.
  90. void maximumPositionChanged(int max);
  91. ///
  92. /// Utility signal that is fired when minimum or maximum positions
  93. /// have changed.
  94. void positionsChanged(int min, int max);
  95. public slots:
  96. ///
  97. /// This property holds the slider's current minimum value.
  98. /// The slider forces the minimum value to be within the legal range:
  99. /// minimum <= minvalue <= maxvalue <= maximum.
  100. /// Changing the minimumValue also changes the minimumPosition.
  101. void setMinimumValue(int min);
  102. ///
  103. /// This property holds the slider's current maximum value.
  104. /// The slider forces the maximum value to be within the legal range:
  105. /// minimum <= minvalue <= maxvalue <= maximum.
  106. /// Changing the maximumValue also changes the maximumPosition.
  107. void setMaximumValue(int max);
  108. ///
  109. /// Utility function that set the minimum value and maximum value at once.
  110. void setValues(int min, int max);
  111. protected slots:
  112. void onRangeChanged(int minimum, int maximum);
  113. protected:
  114. // Description:
  115. // Standard Qt UI events
  116. virtual void mousePressEvent(QMouseEvent* ev);
  117. virtual void mouseMoveEvent(QMouseEvent* ev);
  118. virtual void mouseReleaseEvent(QMouseEvent* ev);
  119. // Description:
  120. // Rendering is done here.
  121. virtual void paintEvent(QPaintEvent* ev);
  122. private:
  123. CTK_DECLARE_PRIVATE(ctkRangeSlider);
  124. };
  125. #endif