ctkCheckablePushButton.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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.commontk.org/LICENSE
  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. class CTK_WIDGETS_EXPORT ctkCheckablePushButton : public QPushButton
  26. {
  27. Q_OBJECT
  28. Q_PROPERTY(Qt::Alignment buttonTextAlignment READ buttonTextAlignment WRITE setButtonTextAlignment)
  29. Q_PROPERTY(Qt::Alignment indicatorAlignment READ indicatorAlignment WRITE setIndicatorAlignment)
  30. public:
  31. ctkCheckablePushButton(QWidget *parent = 0);
  32. ctkCheckablePushButton(const QString& text, QWidget *parent = 0);
  33. virtual ~ctkCheckablePushButton();
  34. ///
  35. /// Set the alignment of the text on the button,
  36. /// Qt::Left|Qt::VCenter by default.
  37. void setButtonTextAlignment(Qt::Alignment textAlignment);
  38. Qt::Alignment buttonTextAlignment()const;
  39. ///
  40. /// Set the alignment of the indicator (arrow) on the button,
  41. /// Qt::Left|Qt::VCenter by default.
  42. void setIndicatorAlignment(Qt::Alignment indicatorAlignment);
  43. Qt::Alignment indicatorAlignment()const;
  44. virtual QSize minimumSizeHint()const;
  45. virtual QSize sizeHint()const;
  46. protected:
  47. /// Reimplemented for internal reasons
  48. virtual void paintEvent(QPaintEvent*);
  49. /// Reimplemented for internal reasons
  50. virtual void mousePressEvent(QMouseEvent* event);
  51. /// Reimplemented for internal reasons
  52. virtual bool hitButton(const QPoint & pos) const;
  53. /// Reimplemented for internal reasons
  54. virtual void initStyleOption ( QStyleOptionButton * option ) const;
  55. protected:
  56. QScopedPointer<ctkCheckablePushButtonPrivate> d_ptr;
  57. private:
  58. Q_DECLARE_PRIVATE(ctkCheckablePushButton);
  59. Q_DISABLE_COPY(ctkCheckablePushButton);
  60. };
  61. #endif