ctkCollapsibleGroupBox.h 2.9 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.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 __ctkCollapsibleGroupBox_h
  15. #define __ctkCollapsibleGroupBox_h
  16. // Qt includes
  17. #include <QGroupBox>
  18. // CTK includes
  19. #include "ctkWidgetsExport.h"
  20. /// A QGroupBox with an arrow indicator that shows/hides the groupbox contents
  21. /// when clicked. It responds to the slot QGroupBox::setChecked(bool) or
  22. /// ctkCollapsibleGroupBox::setCollapsed(bool)
  23. /// When checked is true, the groupbox is expanded
  24. /// When checked is false, the groupbox is collapsed
  25. class CTK_WIDGETS_EXPORT ctkCollapsibleGroupBox : public QGroupBox
  26. {
  27. Q_OBJECT
  28. public:
  29. explicit ctkCollapsibleGroupBox(QWidget* parent = 0);
  30. virtual ~ctkCollapsibleGroupBox();
  31. /// Utility function to collapse the groupbox
  32. /// Collapse(close) the group box if collapse is true, expand(open)
  33. /// it otherwise.
  34. /// \sa QGroupBox::setChecked(bool)
  35. inline void setCollapsed(bool collapse);
  36. /// Return the collapse state of the groupbox
  37. /// true if the groupbox is collapsed (closed), false if it is expanded(open)
  38. inline bool collapsed()const;
  39. /// Reimplemtented for internal reasons
  40. virtual int heightForWidth(int w) const;
  41. /// Reimplemtented for internal reasons
  42. virtual QSize minimumSizeHint()const;
  43. /// Reimplemtented for internal reasons
  44. virtual QSize sizeHint()const;
  45. protected slots:
  46. /// called when the arrow indicator is clicked
  47. /// users can call it programatically by calling setChecked(bool)
  48. virtual void expand(bool expand);
  49. protected:
  50. /// reimplemented for internal reasons
  51. virtual void childEvent(QChildEvent*);
  52. #if QT_VERSION < 0x040600
  53. virtual void paintEvent(QPaintEvent*);
  54. virtual void mousePressEvent(QMouseEvent*);
  55. virtual void mouseReleaseEvent(QMouseEvent*);
  56. #endif
  57. virtual void resizeEvent(QResizeEvent*);
  58. /// Size of the widget for collapsing
  59. QSize OldSize;
  60. /// Maximum allowed height
  61. int MaxHeight;
  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