ctkCollapsibleGroupBox.h 3.0 KB

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