ctkRangeSlider.h 5.4 KB

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