ctkDoubleSpinBox_p.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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.apache.org/licenses/LICENSE-2.0.txt
  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. // CTK includes
  15. #include "ctkDoubleSpinBox.h"
  16. // Qt includes
  17. #include <QDoubleSpinBox>
  18. //-----------------------------------------------------------------------------
  19. class ctkQDoubleSpinBox: public QDoubleSpinBox
  20. {
  21. Q_OBJECT
  22. /// This property controls whether decreasing the value by the mouse
  23. /// button or mouse wheel increases the value of the widget, and inverts the
  24. /// control similarly in the other way round or not. The property is switched off by
  25. /// default.
  26. /// \sa invertedControls(), setInvertedControls()
  27. Q_PROPERTY(bool invertedControls READ invertedControls WRITE setInvertedControls)
  28. public:
  29. typedef QDoubleSpinBox Superclass;
  30. ctkQDoubleSpinBox(QWidget* widget);
  31. void setInvertedControls(bool invertedControls);
  32. bool invertedControls() const;
  33. /// Overrides QDoubleSpinBox::stepBy(int) and negates the step number if the
  34. /// invertedControls property is true.
  35. virtual void stepBy(int steps);
  36. protected:
  37. /// If the invertedControls property is false (by default) then this function
  38. /// behavesLike QDoubleSpinBox::stepEnabled(). If the property is true then
  39. /// stepping down is allowed if the value is less then the maximum, and
  40. /// stepping up is allowed if the value is greater then the minimum.
  41. virtual StepEnabled stepEnabled () const;
  42. bool InvertedControls;
  43. private:
  44. Q_DISABLE_COPY(ctkQDoubleSpinBox);
  45. };
  46. //-----------------------------------------------------------------------------
  47. class ctkDoubleSpinBoxPrivate
  48. {
  49. Q_DECLARE_PUBLIC(ctkDoubleSpinBox);
  50. protected:
  51. ctkDoubleSpinBox* const q_ptr;
  52. public:
  53. ctkDoubleSpinBoxPrivate(ctkDoubleSpinBox& object);
  54. ctkQDoubleSpinBox* SpinBox;
  55. ctkDoubleSpinBox::SetMode Mode;
  56. int DefaultDecimals;
  57. ctkDoubleSpinBox::DecimalsOptions DOption;
  58. bool InvertedControls;
  59. void init();
  60. // Compare two double previously rounded according to the number of decimals
  61. bool compare(double x1, double x2) const;
  62. // Set the number of decimals of the spinbox and emit the signal
  63. // No check if they are the same.
  64. void setDecimals(int dec);
  65. };