ctkCollapsibleGroupBox.h 3.1 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 __ctkCollapsibleGroupBox_h
  15. #define __ctkCollapsibleGroupBox_h
  16. // Qt includes
  17. #include <QGroupBox>
  18. // CTK includes
  19. #include "ctkWidgetsExport.h"
  20. class ctkCollapsibleGroupBoxPrivate;
  21. /// \ingroup Widgets
  22. /// A QGroupBox with an arrow indicator that shows/hides the groupbox contents
  23. /// when clicked. It responds to the slot QGroupBox::setChecked(bool) or
  24. /// ctkCollapsibleGroupBox::setCollapsed(bool)
  25. /// When checked is true, the groupbox is expanded
  26. /// When checked is false, the groupbox is collapsed
  27. class CTK_WIDGETS_EXPORT ctkCollapsibleGroupBox : public QGroupBox
  28. {
  29. Q_OBJECT
  30. Q_PROPERTY(bool collapsed READ collapsed WRITE setCollapsed)
  31. public:
  32. ctkCollapsibleGroupBox(QWidget* parent = 0);
  33. ctkCollapsibleGroupBox(const QString& title, QWidget* parent = 0);
  34. virtual ~ctkCollapsibleGroupBox();
  35. /// Utility function to collapse the groupbox
  36. /// Collapse(close) the group box if collapse is true, expand(open)
  37. /// it otherwise.
  38. /// \sa QGroupBox::setChecked(bool)
  39. inline void setCollapsed(bool collapse);
  40. /// Return the collapse state of the groupbox
  41. /// true if the groupbox is collapsed (closed), false if it is expanded(open)
  42. inline bool collapsed()const;
  43. /// Reimplemented for internal reasons
  44. /// Catch when a child widget's visibility is externally changed
  45. virtual bool eventFilter(QObject* child, QEvent* e);
  46. /// Reimplemented for internal reasons
  47. virtual void setVisible(bool show);
  48. protected Q_SLOTS:
  49. /// called when the arrow indicator is clicked
  50. /// users can call it programatically by calling setChecked(bool)
  51. virtual void expand(bool expand);
  52. protected:
  53. QScopedPointer<ctkCollapsibleGroupBoxPrivate> d_ptr;
  54. /// reimplemented for internal reasons
  55. virtual void childEvent(QChildEvent*);
  56. #if QT_VERSION < 0x040600
  57. virtual void paintEvent(QPaintEvent*);
  58. virtual void mousePressEvent(QMouseEvent*);
  59. virtual void mouseReleaseEvent(QMouseEvent*);
  60. #endif
  61. private:
  62. Q_DECLARE_PRIVATE(ctkCollapsibleGroupBox);
  63. Q_DISABLE_COPY(ctkCollapsibleGroupBox);
  64. };
  65. //----------------------------------------------------------------------------
  66. bool ctkCollapsibleGroupBox::collapsed()const
  67. {
  68. return !this->isChecked();
  69. }
  70. //----------------------------------------------------------------------------
  71. void ctkCollapsibleGroupBox::setCollapsed(bool collapse)
  72. {
  73. this->setChecked(!collapse);
  74. }
  75. #endif