ctkCheckablePushButton.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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. #ifndef __ctkCheckablePushButton_h
  15. #define __ctkCheckablePushButton_h
  16. // Qt includes
  17. #include <QPushButton>
  18. // CTK includes
  19. #include <ctkPimpl.h>
  20. #include "ctkWidgetsExport.h"
  21. class ctkCheckablePushButtonPrivate;
  22. /// Description
  23. /// ctkCheckablePushButton is a QPushButton with a checkbox. By default
  24. /// the checkbox is connected to the checkable property of the push button.
  25. /// You can change this behaviour by clearing the "checkBoxControlsButton"
  26. /// property.
  27. /// The checkBoxUserCheckable property determines if the state of the
  28. /// checkbox can be changed interactively by the user by clicking on the
  29. /// checkbox.
  30. /// \note In checkBoxControlsButton mode, calling setCheckable instead of
  31. /// setCheckState may not refresh the button automatically. Use setCheckState
  32. /// instead.
  33. /// \note You can automatically check the button when the user checks the
  34. /// checkbox by connecting the checkBoxToggled(bool) signal with the
  35. /// setChecked(bool) slot.
  36. class CTK_WIDGETS_EXPORT ctkCheckablePushButton : public QPushButton
  37. {
  38. Q_OBJECT
  39. Q_PROPERTY(Qt::Alignment buttonTextAlignment READ buttonTextAlignment WRITE setButtonTextAlignment)
  40. Q_PROPERTY(Qt::Alignment indicatorAlignment READ indicatorAlignment WRITE setIndicatorAlignment)
  41. Q_PROPERTY(Qt::CheckState checkState READ checkState WRITE setCheckState NOTIFY checkStateChanged)
  42. Q_PROPERTY(bool checkBoxControlsButton READ checkBoxControlsButton WRITE setCheckBoxControlsButton)
  43. Q_PROPERTY(bool checkBoxUserCheckable READ isCheckBoxUserCheckable WRITE setCheckBoxUserCheckable)
  44. public:
  45. ctkCheckablePushButton(QWidget *parent = 0);
  46. ctkCheckablePushButton(const QString& text, QWidget *parent = 0);
  47. virtual ~ctkCheckablePushButton();
  48. ///
  49. /// Set the alignment of the text on the button,
  50. /// Qt::Left|Qt::VCenter by default.
  51. void setButtonTextAlignment(Qt::Alignment textAlignment);
  52. Qt::Alignment buttonTextAlignment()const;
  53. ///
  54. /// Set the alignment of the indicator (arrow) on the button,
  55. /// Qt::Left|Qt::VCenter by default.
  56. void setIndicatorAlignment(Qt::Alignment indicatorAlignment);
  57. Qt::Alignment indicatorAlignment()const;
  58. virtual QSize minimumSizeHint()const;
  59. virtual QSize sizeHint()const;
  60. virtual Qt::CheckState checkState()const;
  61. virtual void setCheckState(Qt::CheckState checkState);
  62. virtual bool checkBoxControlsButton()const;
  63. virtual void setCheckBoxControlsButton(bool b);
  64. virtual bool isCheckBoxUserCheckable()const;
  65. virtual void setCheckBoxUserCheckable(bool b);
  66. Q_SIGNALS:
  67. /// Fired anytime the checkbox change of state
  68. void checkBoxToggled(bool);
  69. /// Fired anytime the checkbox change of state
  70. void checkStateChanged(Qt::CheckState newCheckState);
  71. protected:
  72. /// Reimplemented for internal reasons
  73. virtual void paintEvent(QPaintEvent*);
  74. /// Reimplemented for internal reasons
  75. virtual void mousePressEvent(QMouseEvent* event);
  76. /// Reimplemented for internal reasons
  77. virtual bool hitButton(const QPoint & pos) const;
  78. /// Reimplemented for internal reasons
  79. virtual void initStyleOption ( QStyleOptionButton * option ) const;
  80. protected:
  81. QScopedPointer<ctkCheckablePushButtonPrivate> d_ptr;
  82. private:
  83. Q_DECLARE_PRIVATE(ctkCheckablePushButton);
  84. Q_DISABLE_COPY(ctkCheckablePushButton);
  85. };
  86. #endif