ctkCollapsibleButton.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. /*=========================================================================
  2. Library: CTK
  3. Copyright (c) Kitware Inc.
  4. All rights reserved.
  5. Distributed under a BSD License. See LICENSE.txt file.
  6. This software is distributed "AS IS" WITHOUT ANY WARRANTY; without even
  7. the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  8. See the above copyright notice for more information.
  9. =========================================================================*/
  10. #ifndef __ctkCollapsibleButton_h
  11. #define __ctkCollapsibleButton_h
  12. // Qt includes
  13. #include <QAbstractButton>
  14. #include <QFrame>
  15. // CTK includes
  16. #include <ctkPimpl.h>
  17. #include "CTKWidgetsExport.h"
  18. class ctkCollapsibleButtonPrivate;
  19. class QStyleOptionButton;
  20. /// Description
  21. /// A Collapsible widget that show/hide its children depending on its checked/collapsed properties
  22. class CTK_WIDGETS_EXPORT ctkCollapsibleButton : public QAbstractButton
  23. {
  24. Q_OBJECT
  25. Q_PROPERTY(bool collapsed READ collapsed WRITE setCollapsed DESIGNABLE isCheckable NOTIFY contentsCollapsed)
  26. Q_PROPERTY(int collapsedHeight READ collapsedHeight WRITE setCollapsedHeight)
  27. Q_PROPERTY(QFrame::Shape contentsFrameShape READ contentsFrameShape WRITE setContentsFrameShape)
  28. Q_PROPERTY(QFrame::Shadow contentsFrameShadow READ contentsFrameShadow WRITE setContentsFrameShadow)
  29. Q_PROPERTY(int contentsLineWidth READ contentsLineWidth WRITE setContentsLineWidth)
  30. Q_PROPERTY(int contentsMidLineWidth READ contentsMidLineWidth WRITE setContentsMidLineWidth)
  31. public:
  32. ctkCollapsibleButton(QWidget *parent = 0);
  33. ctkCollapsibleButton(const QString& text, QWidget *parent = 0);
  34. virtual ~ctkCollapsibleButton();
  35. ///
  36. /// Property that describes if the widget is collapsed or not.
  37. /// When collapsed, the children are invisible and the widget
  38. /// has a sized defined by CollapsedHeight
  39. void setCollapsed(bool);
  40. bool collapsed()const;
  41. ///
  42. /// Height used when the widget is collapsed
  43. void setCollapsedHeight(int);
  44. int collapsedHeight()const;
  45. ///
  46. /// Set the frame shape of the contents
  47. /// Hint: StyledPanel is probably the shape you are looking for
  48. QFrame::Shape contentsFrameShape() const;
  49. void setContentsFrameShape(QFrame::Shape);
  50. ///
  51. /// Set the frame shadow of the contents
  52. /// Hint: Raised is probably the shadow you are looking for
  53. QFrame::Shadow contentsFrameShadow() const;
  54. void setContentsFrameShadow(QFrame::Shadow);
  55. ///
  56. /// Set the line width of the frame around the contents
  57. int contentsLineWidth() const;
  58. void setContentsLineWidth(int);
  59. ///
  60. /// Set the mid line width of the frame around the contents
  61. int contentsMidLineWidth() const;
  62. void setContentsMidLineWidth(int);
  63. ///
  64. /// Reimplement for internal reasons
  65. virtual QSize minimumSizeHint()const;
  66. ///
  67. /// Reimplement for internal reasons
  68. virtual QSize sizeHint()const;
  69. signals:
  70. ///
  71. /// Signal emitted when the widget is collapsed or expanded.
  72. /// See signal toggled(bool) for the opposite.
  73. void contentsCollapsed(bool);
  74. protected slots:
  75. ///
  76. /// Perform the collapse.
  77. virtual void collapse(bool c);
  78. virtual void onToggled(bool clicked = false);
  79. protected:
  80. virtual void paintEvent(QPaintEvent*);
  81. //virtual void mousePressEvent(QMouseEvent* event);
  82. //virtual void mouseReleaseEvent(QMouseEvent* event);
  83. virtual void childEvent(QChildEvent* c);
  84. virtual bool hitButton(const QPoint & pos) const;
  85. /// Compute the size hint of the head button only. The sizehint depends on the text.
  86. virtual QSize buttonSizeHint() const;
  87. /// Initialize option with the values from this ctkCollapsibleButton.
  88. /// This method is useful for subclasses when they need a QStyleOptionButton,
  89. /// but don't want to fill in all the information themselves.
  90. virtual void initStyleOption(QStyleOptionButton* option)const;
  91. private:
  92. CTK_DECLARE_PRIVATE(ctkCollapsibleButton);
  93. };
  94. #endif