ctkRangeWidget.h 7.4 KB

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