ctkDoubleSpinBox.cpp 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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. // QT includes
  15. #include <QApplication>
  16. // CTK includes
  17. #include "ctkDoubleSpinBox.h"
  18. // ----------------------------------------------------------------------------
  19. class ctkDoubleSpinBoxPrivate
  20. {
  21. public:
  22. ctkDoubleSpinBoxPrivate();
  23. bool InvertedControls;
  24. };
  25. // ----------------------------------------------------------------------------
  26. // Methods ctkDoubleSpinBoxPrivate
  27. // ----------------------------------------------------------------------------
  28. ctkDoubleSpinBoxPrivate::ctkDoubleSpinBoxPrivate()
  29. {
  30. this->InvertedControls = false;
  31. }
  32. // ----------------------------------------------------------------------------
  33. // Methods ctkDoubleSpinBox
  34. // ----------------------------------------------------------------------------
  35. ctkDoubleSpinBox::ctkDoubleSpinBox(QWidget *_parent)
  36. :Superclass(_parent)
  37. , d_ptr(new ctkDoubleSpinBoxPrivate())
  38. {
  39. }
  40. // ----------------------------------------------------------------------------
  41. ctkDoubleSpinBox::~ctkDoubleSpinBox()
  42. {
  43. }
  44. // ----------------------------------------------------------------------------
  45. void ctkDoubleSpinBox::setInvertedControls(bool invertedControls)
  46. {
  47. Q_D(ctkDoubleSpinBox);
  48. d->InvertedControls = invertedControls;
  49. }
  50. // ----------------------------------------------------------------------------
  51. bool ctkDoubleSpinBox::invertedControls() const
  52. {
  53. Q_D(const ctkDoubleSpinBox);
  54. return d->InvertedControls;
  55. }
  56. // ----------------------------------------------------------------------------
  57. void ctkDoubleSpinBox::stepBy(int steps)
  58. {
  59. Q_D(const ctkDoubleSpinBox);
  60. if (d->InvertedControls)
  61. {
  62. steps = -steps;
  63. }
  64. Superclass::stepBy(steps);
  65. }
  66. // ----------------------------------------------------------------------------
  67. QAbstractSpinBox::StepEnabled ctkDoubleSpinBox::stepEnabled() const
  68. {
  69. Q_D(const ctkDoubleSpinBox);
  70. if (!d->InvertedControls)
  71. {
  72. return Superclass::stepEnabled();
  73. }
  74. if (this->isReadOnly())
  75. {
  76. return StepNone;
  77. }
  78. if (this->wrapping())
  79. {
  80. return StepEnabled(StepUpEnabled | StepDownEnabled);
  81. }
  82. StepEnabled ret = StepNone;
  83. double value = this->value();
  84. if (value < this->maximum())
  85. {
  86. ret |= StepDownEnabled;
  87. }
  88. if (value > this->minimum())
  89. {
  90. ret |= StepUpEnabled;
  91. }
  92. return ret;
  93. }