ctkCheckablePushButton.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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.
  29. class CTK_WIDGETS_EXPORT ctkCheckablePushButton : public QPushButton
  30. {
  31. Q_OBJECT
  32. Q_PROPERTY(Qt::Alignment buttonTextAlignment READ buttonTextAlignment WRITE setButtonTextAlignment)
  33. Q_PROPERTY(Qt::Alignment indicatorAlignment READ indicatorAlignment WRITE setIndicatorAlignment)
  34. Q_PROPERTY(Qt::CheckState checkState READ checkState WRITE setCheckState NOTIFY checkStateChanged)
  35. Q_PROPERTY(bool checkBoxControlsButton READ checkBoxControlsButton WRITE setCheckBoxControlsButton)
  36. Q_PROPERTY(bool checkBoxUserCheckable READ isCheckBoxUserCheckable WRITE setCheckBoxUserCheckable)
  37. public:
  38. ctkCheckablePushButton(QWidget *parent = 0);
  39. ctkCheckablePushButton(const QString& text, QWidget *parent = 0);
  40. virtual ~ctkCheckablePushButton();
  41. ///
  42. /// Set the alignment of the text on the button,
  43. /// Qt::Left|Qt::VCenter by default.
  44. void setButtonTextAlignment(Qt::Alignment textAlignment);
  45. Qt::Alignment buttonTextAlignment()const;
  46. ///
  47. /// Set the alignment of the indicator (arrow) on the button,
  48. /// Qt::Left|Qt::VCenter by default.
  49. void setIndicatorAlignment(Qt::Alignment indicatorAlignment);
  50. Qt::Alignment indicatorAlignment()const;
  51. virtual QSize minimumSizeHint()const;
  52. virtual QSize sizeHint()const;
  53. virtual Qt::CheckState checkState()const;
  54. virtual void setCheckState(Qt::CheckState checkState);
  55. virtual bool checkBoxControlsButton()const;
  56. virtual void setCheckBoxControlsButton(bool b);
  57. virtual bool isCheckBoxUserCheckable()const;
  58. virtual void setCheckBoxUserCheckable(bool b);
  59. signals:
  60. void checkStateChanged(Qt::CheckState newCheckState);
  61. protected:
  62. /// Reimplemented for internal reasons
  63. virtual void paintEvent(QPaintEvent*);
  64. /// Reimplemented for internal reasons
  65. virtual void mousePressEvent(QMouseEvent* event);
  66. /// Reimplemented for internal reasons
  67. virtual bool hitButton(const QPoint & pos) const;
  68. /// Reimplemented for internal reasons
  69. virtual void initStyleOption ( QStyleOptionButton * option ) const;
  70. protected:
  71. QScopedPointer<ctkCheckablePushButtonPrivate> d_ptr;
  72. private:
  73. Q_DECLARE_PRIVATE(ctkCheckablePushButton);
  74. Q_DISABLE_COPY(ctkCheckablePushButton);
  75. };
  76. #endif