ctkCollapsibleButton.h 4.1 KB

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