ctkRangeWidget.h 6.4 KB

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