ctkCheckablePushButton.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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 that controls the
  24. /// checkable property of the button.
  25. /// You can change this behavior by assigning flags to the checkbox by the
  26. /// setCheckBoxFlags function. The Qt::ItemIsEnabled flag causes that the
  27. /// checkbox can be used
  28. /// independently from the containing button. (It will not control the checkable
  29. /// property of the button.) The following flags are supported:
  30. /// Qt::ItemIsEnabled, Qt::ItemIsUserCheckable, Qt::ItemIsTriState.
  31. /// In default, no flags are set (Qt::NoItemFlags) that means the original behavior.
  32. class CTK_WIDGETS_EXPORT ctkCheckablePushButton : public QPushButton
  33. {
  34. Q_OBJECT
  35. Q_PROPERTY(Qt::Alignment buttonTextAlignment READ buttonTextAlignment WRITE setButtonTextAlignment)
  36. Q_PROPERTY(Qt::Alignment indicatorAlignment READ indicatorAlignment WRITE setIndicatorAlignment)
  37. Q_PROPERTY(Qt::ItemFlags checkBoxFlags READ checkBoxFlags WRITE setCheckBoxFlags)
  38. Q_PROPERTY(Qt::CheckState checkState READ checkState WRITE setCheckState)
  39. public:
  40. ctkCheckablePushButton(QWidget *parent = 0);
  41. ctkCheckablePushButton(const QString& text, QWidget *parent = 0);
  42. virtual ~ctkCheckablePushButton();
  43. ///
  44. /// Set the alignment of the text on the button,
  45. /// Qt::Left|Qt::VCenter by default.
  46. void setButtonTextAlignment(Qt::Alignment textAlignment);
  47. Qt::Alignment buttonTextAlignment()const;
  48. ///
  49. /// Set the alignment of the indicator (arrow) on the button,
  50. /// Qt::Left|Qt::VCenter by default.
  51. void setIndicatorAlignment(Qt::Alignment indicatorAlignment);
  52. Qt::Alignment indicatorAlignment()const;
  53. virtual QSize minimumSizeHint()const;
  54. virtual QSize sizeHint()const;
  55. virtual Qt::ItemFlags checkBoxFlags()const;
  56. virtual void setCheckBoxFlags(Qt::ItemFlags checkBoxFlags);
  57. virtual Qt::CheckState checkState()const;
  58. virtual void setCheckState(Qt::CheckState checkState);
  59. protected:
  60. /// Reimplemented for internal reasons
  61. virtual void paintEvent(QPaintEvent*);
  62. /// Reimplemented for internal reasons
  63. virtual void mousePressEvent(QMouseEvent* event);
  64. /// Reimplemented for internal reasons
  65. virtual bool hitButton(const QPoint & pos) const;
  66. /// Reimplemented for internal reasons
  67. virtual void initStyleOption ( QStyleOptionButton * option ) const;
  68. protected:
  69. QScopedPointer<ctkCheckablePushButtonPrivate> d_ptr;
  70. private:
  71. Q_DECLARE_PRIVATE(ctkCheckablePushButton);
  72. Q_DISABLE_COPY(ctkCheckablePushButton);
  73. };
  74. #endif