ctkCollapsibleGroupBox.h 3.0 KB

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