ctkSliderSpinBoxWidget.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  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 __ctkSliderSpinBoxWidget_h
  15. #define __ctkSliderSpinBoxWidget_h
  16. // Qt includes
  17. #include <QSlider>
  18. // CTK includes
  19. #include <ctkPimpl.h>
  20. #include "CTKWidgetsExport.h"
  21. class ctkSliderSpinBoxWidgetPrivate;
  22. ///
  23. /// ctkSliderSpinBoxWidget is a wrapper around a ctkDoubleSlider and a
  24. /// synchronized QDoubleSpinBox.
  25. /// TODO: rename ctkSliderSpinBoxWidget into ctkSliderWidget
  26. /// \sa ctkRangeWidget, ctkDoubleRangeSlider, QSpinBox
  27. class CTK_WIDGETS_EXPORT ctkSliderSpinBoxWidget : public QWidget
  28. {
  29. Q_OBJECT
  30. Q_PROPERTY(double minimum READ minimum WRITE setMinimum)
  31. Q_PROPERTY(double maximum READ maximum WRITE setMaximum)
  32. Q_PROPERTY(double value READ value WRITE setValue)
  33. Q_PROPERTY(double singleStep READ singleStep WRITE setSingleStep)
  34. Q_PROPERTY(int decimals READ decimals WRITE setDecimals)
  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 ctkSliderSpinBoxWidget(QWidget* parent = 0);
  46. virtual ~ctkSliderSpinBoxWidget(){}
  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. /// ctkSliderSpinBoxWidget 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 precision of the spin box, in decimals.
  85. /// Sets how many decimals the spinbox will use for displaying and interpreting doubles.
  86. int decimals()const;
  87. void setDecimals(int decimals);
  88. ///
  89. /// This property holds the spin box's prefix.
  90. /// The prefix is prepended to the start of the displayed value.
  91. /// Typical use is to display a unit of measurement or a currency symbol
  92. QString prefix()const;
  93. void setPrefix(const QString& prefix);
  94. ///
  95. /// This property holds the spin box's suffix.
  96. /// The suffix is appended to the end of the displayed value.
  97. /// Typical use is to display a unit of measurement or a currency symbol
  98. QString suffix()const;
  99. void setSuffix(const QString& suffix);
  100. ///
  101. /// This property holds the interval between tickmarks.
  102. /// This is a value interval, not a pixel interval.
  103. /// If it is 0, the slider will choose between lineStep() and pageStep().
  104. /// The default value is 0.
  105. double tickInterval()const;
  106. void setTickInterval(double ti);
  107. ///
  108. /// This property holds the alignment of the spin box.
  109. /// Possible Values are Qt::AlignLeft, Qt::AlignRight, and Qt::AlignHCenter.
  110. /// By default, the alignment is Qt::AlignLeft
  111. void setSpinBoxAlignment(Qt::Alignment alignment);
  112. Qt::Alignment spinBoxAlignment()const;
  113. ///
  114. /// This property holds whether slider tracking is enabled.
  115. /// If tracking is enabled (the default), the widget emits the valueChanged()
  116. /// signal while the slider or spinbox is being dragged. If tracking is
  117. /// disabled, the widget emits the valueChanged() signal only when the user
  118. /// releases the slider or spinbox.
  119. void setTracking(bool enable);
  120. bool hasTracking()const;
  121. ///
  122. /// Set/Get the auto spinbox width
  123. /// When the autoSpinBoxWidth property is on, the width of the SpinBox is
  124. /// set to the same width of the largest QSpinBox of its
  125. // ctkSliderSpinBoxWidget siblings.
  126. bool isAutoSpinBoxWidth()const;
  127. void setAutoSpinBoxWidth(bool autoWidth);
  128. public slots:
  129. ///
  130. /// Reset the slider and spinbox to zero (value and position)
  131. void reset();
  132. void setValue(double value);
  133. signals:
  134. /// Use with care:
  135. /// sliderMoved is emitted only when the user moves the slider
  136. //void sliderMoved(double position);
  137. void valueChanged(double value);
  138. void valueIsChanging(double value);
  139. protected slots:
  140. void startChanging();
  141. void stopChanging();
  142. void changeValue(double value);
  143. protected:
  144. virtual bool eventFilter(QObject *obj, QEvent *event);
  145. private:
  146. CTK_DECLARE_PRIVATE(ctkSliderSpinBoxWidget);
  147. };
  148. #endif