ctkSliderWidget.h 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. /*=========================================================================
  2. Library: CTK
  3. Copyright (c) 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 __ctkSliderWidget_h
  15. #define __ctkSliderWidget_h
  16. // Qt includes
  17. #include <QSlider>
  18. // CTK includes
  19. #include <ctkPimpl.h>
  20. #include "ctkWidgetsExport.h"
  21. class ctkSliderWidgetPrivate;
  22. ///
  23. /// ctkSliderWidget is a wrapper around a ctkDoubleSlider and a QDoubleSpinBox
  24. /// where the slider value and the spinbox value are synchronized.
  25. /// \sa ctkRangeWidget, ctkDoubleRangeSlider, QSpinBox
  26. class CTK_WIDGETS_EXPORT ctkSliderWidget : public QWidget
  27. {
  28. Q_OBJECT
  29. Q_PROPERTY(int decimals READ decimals WRITE setDecimals)
  30. Q_PROPERTY(double singleStep READ singleStep WRITE setSingleStep)
  31. Q_PROPERTY(double pageStep READ pageStep WRITE setPageStep)
  32. Q_PROPERTY(double minimum READ minimum WRITE setMinimum)
  33. Q_PROPERTY(double maximum READ maximum WRITE setMaximum)
  34. Q_PROPERTY(double value READ value WRITE setValue)
  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 spinBoxAlignment READ spinBoxAlignment WRITE setSpinBoxAlignment)
  40. Q_PROPERTY(bool tracking READ hasTracking WRITE setTracking)
  41. public:
  42. /// Superclass typedef
  43. typedef QWidget Superclass;
  44. /// Constructors
  45. explicit ctkSliderWidget(QWidget* parent = 0);
  46. virtual ~ctkSliderWidget();
  47. ///
  48. /// This property holds the sliders and spinbox minimum value.
  49. /// FIXME: Test following specs.
  50. /// When setting this property, the maximum is adjusted if necessary
  51. /// to ensure that the range remains valid.
  52. /// Also the slider's current value is adjusted to be within the new range.
  53. double minimum()const;
  54. void setMinimum(double minimum);
  55. ///
  56. /// This property holds the sliders and spinbox minimum value.
  57. /// FIXME: Test following specs.
  58. /// When setting this property, the maximum is adjusted if necessary
  59. /// to ensure that the range remains valid.
  60. /// Also the slider's current value is adjusted to be within the new range.
  61. double maximum()const;
  62. void setMaximum(double maximum);
  63. /// Description
  64. /// Utility function that set the min/max in once
  65. void setRange(double min, double max);
  66. ///
  67. /// This property holds the current slider position.
  68. /// If tracking is enabled (the default), this is identical to value.
  69. //double sliderPosition()const;
  70. //void setSliderPosition(double position);
  71. ///
  72. /// This property holds the slider and spinbox current value.
  73. /// ctkSliderWidget forces the value to be within the
  74. /// legal range: minimum <= value <= maximum.
  75. double value()const;
  76. ///
  77. /// This property holds the single step.
  78. /// The smaller of two natural steps that the
  79. /// slider provides and typically corresponds to the
  80. /// user pressing an arrow key.
  81. double singleStep()const;
  82. void setSingleStep(double step);
  83. ///
  84. /// This property holds the page step.
  85. /// The larger of two natural steps that an abstract slider provides and
  86. /// typically corresponds to the user pressing PageUp or PageDown.
  87. double pageStep()const;
  88. void setPageStep(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 interpreting doubles.
  92. int decimals()const;
  93. void setDecimals(int decimals);
  94. ///
  95. /// This property holds the spin box's prefix.
  96. /// The prefix is prepended to the start of the displayed value.
  97. /// Typical use is to display a unit of measurement or a currency symbol
  98. QString prefix()const;
  99. void setPrefix(const QString& prefix);
  100. ///
  101. /// This property holds the spin box's suffix.
  102. /// The suffix is appended to the end of the displayed value.
  103. /// Typical use is to display a unit of measurement or a currency symbol
  104. QString suffix()const;
  105. void setSuffix(const QString& suffix);
  106. ///
  107. /// This property holds the interval between tickmarks.
  108. /// This is a value interval, not a pixel interval.
  109. /// If it is 0, the slider will choose between lineStep() and pageStep().
  110. /// The default value is 0.
  111. double tickInterval()const;
  112. void setTickInterval(double ti);
  113. ///
  114. /// This property holds the alignment of the spin box.
  115. /// Possible Values are Qt::AlignLeft, Qt::AlignRight, and Qt::AlignHCenter.
  116. /// By default, the alignment is Qt::AlignLeft
  117. void setSpinBoxAlignment(Qt::Alignment alignment);
  118. Qt::Alignment spinBoxAlignment()const;
  119. ///
  120. /// This property holds whether slider tracking is enabled.
  121. /// If tracking is enabled (the default), the widget emits the valueChanged()
  122. /// signal while the slider or spinbox is being dragged. If tracking is
  123. /// disabled, the widget emits the valueChanged() signal only when the user
  124. /// releases the slider or spinbox.
  125. void setTracking(bool enable);
  126. bool hasTracking()const;
  127. ///
  128. /// Set/Get the auto spinbox width
  129. /// When the autoSpinBoxWidth property is on, the width of the SpinBox is
  130. /// set to the same width of the largest QSpinBox of its
  131. // ctkSliderWidget siblings.
  132. bool isAutoSpinBoxWidth()const;
  133. void setAutoSpinBoxWidth(bool autoWidth);
  134. public slots:
  135. ///
  136. /// Reset the slider and spinbox to zero (value and position)
  137. void reset();
  138. void setValue(double value);
  139. signals:
  140. /// When tracking is on (default), valueChanged is emitted when the
  141. /// user drags the slider.
  142. /// If tracking is off, valueChanged() is emitted only when the user
  143. /// releases the mouse.
  144. /// \sa valueIsChanging QAbstractSlider::valueChanged
  145. void valueChanged(double value);
  146. /// valueIsChanging() is emitted whenever the slider is dragged and tracking
  147. /// is turned off. You might want to use valueChanged instead.
  148. /// It behaves the same way than QAbstractSlider::sliderMoved()
  149. /// \sa valueChanged QAbstractSlider::sliderMoved
  150. void valueIsChanging(double value);
  151. protected slots:
  152. void startChanging();
  153. void stopChanging();
  154. void changeValue(double value);
  155. protected:
  156. virtual bool eventFilter(QObject *obj, QEvent *event);
  157. protected:
  158. QScopedPointer<ctkSliderWidgetPrivate> d_ptr;
  159. private:
  160. Q_DECLARE_PRIVATE(ctkSliderWidget);
  161. Q_DISABLE_COPY(ctkSliderWidget);
  162. };
  163. #endif