ctkCheckablePushButton.h 3.9 KB

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