ctkCollapsibleGroupBox.h 2.9 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.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. ctkCollapsibleGroupBox(QWidget* parent = 0);
  30. ctkCollapsibleGroupBox(const QString& title, QWidget* parent = 0);
  31. virtual ~ctkCollapsibleGroupBox();
  32. /// Utility function to collapse the groupbox
  33. /// Collapse(close) the group box if collapse is true, expand(open)
  34. /// it otherwise.
  35. /// \sa QGroupBox::setChecked(bool)
  36. inline void setCollapsed(bool collapse);
  37. /// Return the collapse state of the groupbox
  38. /// true if the groupbox is collapsed (closed), false if it is expanded(open)
  39. inline bool collapsed()const;
  40. /// Reimplemtented for internal reasons
  41. virtual int heightForWidth(int w) const;
  42. /// Reimplemtented for internal reasons
  43. virtual QSize minimumSizeHint()const;
  44. /// Reimplemtented for internal reasons
  45. virtual QSize sizeHint()const;
  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. /// reimplemented for internal reasons
  52. virtual void childEvent(QChildEvent*);
  53. #if QT_VERSION < 0x040600
  54. virtual void paintEvent(QPaintEvent*);
  55. virtual void mousePressEvent(QMouseEvent*);
  56. virtual void mouseReleaseEvent(QMouseEvent*);
  57. #endif
  58. virtual void resizeEvent(QResizeEvent*);
  59. private:
  60. void init();
  61. /// Size of the widget for collapsing
  62. QSize OldSize;
  63. /// Maximum allowed height
  64. int MaxHeight;
  65. };
  66. //----------------------------------------------------------------------------
  67. bool ctkCollapsibleGroupBox::collapsed()const
  68. {
  69. return !this->isChecked();
  70. }
  71. //----------------------------------------------------------------------------
  72. void ctkCollapsibleGroupBox::setCollapsed(bool collapse)
  73. {
  74. this->setChecked(!collapse);
  75. }
  76. #endif