ctkRangeWidget.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  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 __ctkRangeWidget_h
  11. #define __ctkRangeWidget_h
  12. // Qt includes
  13. #include <QSlider>
  14. // CTK includes
  15. #include <ctkPimpl.h>
  16. #include "CTKWidgetsExport.h"
  17. class ctkRangeWidgetPrivate;
  18. class CTK_WIDGETS_EXPORT ctkRangeWidget : public QWidget
  19. {
  20. Q_OBJECT
  21. Q_PROPERTY(double minimum READ minimum WRITE setMinimum)
  22. Q_PROPERTY(double maximum READ maximum WRITE setMaximum)
  23. Q_PROPERTY(double singleStep READ singleStep WRITE setSingleStep)
  24. Q_PROPERTY(int decimals READ decimals WRITE setDecimals)
  25. Q_PROPERTY(double minimumValue READ minimumValue WRITE setMinimumValue)
  26. Q_PROPERTY(double maximumValue READ maximumValue WRITE setMaximumValue)
  27. Q_PROPERTY(QString prefix READ prefix WRITE setPrefix)
  28. Q_PROPERTY(QString suffix READ suffix WRITE setSuffix)
  29. Q_PROPERTY(double tickInterval READ tickInterval WRITE setTickInterval)
  30. Q_PROPERTY(bool autoSpinBoxWidth READ isAutoSpinBoxWidth WRITE setAutoSpinBoxWidth)
  31. Q_PROPERTY(Qt::Alignment spinBoxAlignment READ spinBoxAlignment WRITE setSpinBoxAlignment)
  32. Q_PROPERTY(bool tracking READ hasTracking WRITE setTracking)
  33. public:
  34. /// Superclass typedef
  35. typedef QWidget Superclass;
  36. /// Constructors
  37. explicit ctkRangeWidget(QWidget* parent = 0);
  38. ///
  39. /// This property holds the sliders and spinbox minimum value.
  40. /// FIXME: Test following specs.
  41. /// When setting this property, the maximum is adjusted if necessary
  42. /// to ensure that the range remains valid.
  43. /// Also the slider's current value is adjusted to be within the new range.
  44. double minimum()const;
  45. void setMinimum(double minimum);
  46. ///
  47. /// This property holds the sliders and spinbox minimum value.
  48. /// FIXME: Test following specs.
  49. /// When setting this property, the maximum is adjusted if necessary
  50. /// to ensure that the range remains valid.
  51. /// Also the slider's current value is adjusted to be within the new range.
  52. double maximum()const;
  53. void setMaximum(double maximum);
  54. /// Description
  55. /// Utility function that set the min/max in once
  56. void setRange(double min, double max);
  57. ///
  58. /// This property holds the slider and spinbox minimum value.
  59. /// ctkRangeWidget forces the value to be within the
  60. /// legal range: minimum <= minimumValue <= maximumValue <= maximum.
  61. double minimumValue()const;
  62. ///
  63. /// This property holds the slider and spinbox maximum value.
  64. /// ctkRangeWidget forces the value to be within the
  65. /// legal range: minimum <= minimumValue <= maximumValue <= maximum.
  66. double maximumValue()const;
  67. ///
  68. /// This property holds the single step.
  69. /// The smaller of two natural steps that the
  70. /// slider provides and typically corresponds to the
  71. /// user pressing an arrow key.
  72. double singleStep()const;
  73. void setSingleStep(double step);
  74. ///
  75. /// This property holds the precision of the spin box, in decimals.
  76. /// Sets how many decimals the spinbox will use for displaying and interpreting doubles.
  77. int decimals()const;
  78. void setDecimals(int decimals);
  79. ///
  80. /// This property holds the spin box's prefix.
  81. /// The prefix is prepended to the start of the displayed value.
  82. /// Typical use is to display a unit of measurement or a currency symbol
  83. QString prefix()const;
  84. void setPrefix(const QString& prefix);
  85. ///
  86. /// This property holds the spin box's suffix.
  87. /// The suffix is appended to the end of the displayed value.
  88. /// Typical use is to display a unit of measurement or a currency symbol
  89. QString suffix()const;
  90. void setSuffix(const QString& suffix);
  91. ///
  92. /// This property holds the interval between tickmarks.
  93. /// This is a value interval, not a pixel interval.
  94. /// If it is 0, the slider will choose between lineStep() and pageStep().
  95. /// The default value is 0.
  96. double tickInterval()const;
  97. void setTickInterval(double ti);
  98. ///
  99. /// This property holds the alignment of the spin box.
  100. /// Possible Values are Qt::AlignLeft, Qt::AlignRight, and Qt::AlignHCenter.
  101. /// By default, the alignment is Qt::AlignLeft
  102. void setSpinBoxAlignment(Qt::Alignment alignment);
  103. Qt::Alignment spinBoxAlignment()const;
  104. ///
  105. /// This property holds whether slider tracking is enabled.
  106. /// If tracking is enabled (the default), the widget emits the valueChanged()
  107. /// signal while the slider or spinbox is being dragged. If tracking is
  108. /// disabled, the widget emits the valueChanged() signal only when the user
  109. /// releases the slider or spinbox.
  110. void setTracking(bool enable);
  111. bool hasTracking()const;
  112. ///
  113. /// Set/Get the auto spinbox width
  114. /// When the autoSpinBoxWidth property is on, the width of the SpinBox is
  115. /// set to the same width of the largest QSpinBox of its
  116. // ctkRangeWidget siblings.
  117. bool isAutoSpinBoxWidth()const;
  118. void setAutoSpinBoxWidth(bool autoWidth);
  119. public slots:
  120. ///
  121. /// Reset the slider and spinbox to zero (value and position)
  122. void reset();
  123. void setMinimumValue(double value);
  124. void setMaximumValue(double value);
  125. signals:
  126. /// Use with care:
  127. /// sliderMoved is emitted only when the user moves the slider
  128. //void sliderMoved(double position);
  129. void minimumValueChanged(double value);
  130. void minimumValueIsChanging(double value);
  131. void maximumValueChanged(double value);
  132. void maximumValueIsChanging(double value);
  133. protected slots:
  134. void startChanging();
  135. void stopChanging();
  136. void changeMinimumValue(double value);
  137. void changeMaximumValue(double value);
  138. void setMinimumToMaximumSpinBox(double minimum);
  139. void setMaximumToMinimumSpinBox(double maximum);
  140. protected:
  141. virtual bool eventFilter(QObject *obj, QEvent *event);
  142. private:
  143. CTK_DECLARE_PRIVATE(ctkRangeWidget);
  144. };
  145. #endif