ctkSliderSpinBoxWidget.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  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. class CTK_WIDGETS_EXPORT ctkSliderSpinBoxWidget : 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 value READ value WRITE setValue)
  28. Q_PROPERTY(double singleStep READ singleStep WRITE setSingleStep)
  29. Q_PROPERTY(int decimals READ decimals WRITE setDecimals)
  30. Q_PROPERTY(QString prefix READ prefix WRITE setPrefix)
  31. Q_PROPERTY(QString suffix READ suffix WRITE setSuffix)
  32. Q_PROPERTY(double tickInterval READ tickInterval WRITE setTickInterval)
  33. Q_PROPERTY(bool autoSpinBoxWidth READ isAutoSpinBoxWidth WRITE setAutoSpinBoxWidth)
  34. Q_PROPERTY(Qt::Alignment spinBoxAlignment READ spinBoxAlignment WRITE setSpinBoxAlignment)
  35. Q_PROPERTY(bool tracking READ hasTracking WRITE setTracking)
  36. public:
  37. /// Superclass typedef
  38. typedef QWidget Superclass;
  39. /// Constructors
  40. explicit ctkSliderSpinBoxWidget(QWidget* parent = 0);
  41. virtual ~ctkSliderSpinBoxWidget(){}
  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 current slider position.
  63. /// If tracking is enabled (the default), this is identical to value.
  64. //double sliderPosition()const;
  65. //void setSliderPosition(double position);
  66. ///
  67. /// This property holds the slider and spinbox current value.
  68. /// ctkSliderSpinBoxWidget forces the value to be within the
  69. /// legal range: minimum <= value <= maximum.
  70. double value()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. // ctkSliderSpinBoxWidget 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 setValue(double value);
  128. signals:
  129. /// Use with care:
  130. /// sliderMoved is emitted only when the user moves the slider
  131. //void sliderMoved(double position);
  132. void valueChanged(double value);
  133. void valueIsChanging(double value);
  134. protected slots:
  135. void startChanging();
  136. void stopChanging();
  137. void changeValue(double value);
  138. protected:
  139. virtual bool eventFilter(QObject *obj, QEvent *event);
  140. private:
  141. CTK_DECLARE_PRIVATE(ctkSliderSpinBoxWidget);
  142. };
  143. #endif