ctkSliderWidget.h 6.5 KB

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