GOFIGURE2  0.9.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
ctkCollapsibleGroupBox.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Library: CTK
4 
5  Copyright (c) Kitware Inc.
6 
7  Licensed under the Apache License, Version 2.0 (the "License");
8  you may not use this file except in compliance with the License.
9  You may obtain a copy of the License at
10 
11  http://www.commontk.org/LICENSE
12 
13  Unless required by applicable law or agreed to in writing, software
14  distributed under the License is distributed on an "AS IS" BASIS,
15  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  See the License for the specific language governing permissions and
17  limitations under the License.
18 
19 =========================================================================*/
20 
21 #ifndef __ctkCollapsibleGroupBox_h
22 #define __ctkCollapsibleGroupBox_h
23 
24 // Qt includes
25 #include <QGroupBox>
26 
27 // CTK includes
28 #include "ctkConfigure.h"
29 
30 #if QT_VERSION >= 0x040600
31 #include <QProxyStyle>
32 
33 //-----------------------------------------------------------------------------
34 class ctkCollapsibleGroupBoxStyle:public QProxyStyle
35 {
36  public:
37 
38  virtual void drawPrimitive(PrimitiveElement pe, const QStyleOption * opt, QPainter * p, const QWidget * widget = 0) const
39  {
40  if (pe == QStyle::PE_IndicatorCheckBox)
41  {
42  const QGroupBox* groupBox= qobject_cast<const QGroupBox*>(widget);
43  if (groupBox)
44  {
45  this->QProxyStyle::drawPrimitive(groupBox->isChecked() ? QStyle::PE_IndicatorArrowUp : QStyle::PE_IndicatorArrowDown, opt, p, widget);
46  return;
47  }
48  }
49  this->QProxyStyle::drawPrimitive(pe, opt, p, widget);
50  }
51 };
52 #else
53 
54 #endif
55 
61 class ctk_EXPORT ctkCollapsibleGroupBox : public QGroupBox
62 {
63  Q_OBJECT
64 public:
65  ctkCollapsibleGroupBox(QWidget* parent = 0);
66  ctkCollapsibleGroupBox(const QString& title, QWidget* parent = 0);
67  virtual ~ctkCollapsibleGroupBox();
68 
73  inline void setCollapsed(bool collapse);
74 
77  inline bool collapsed()const;
78 
80  virtual int heightForWidth(int w) const;
82  virtual QSize minimumSizeHint()const;
84  virtual QSize sizeHint()const;
85 
86 protected slots:
89  virtual void expand(bool expand);
90 
91 protected:
93  virtual void childEvent(QChildEvent*);
94 
95 #if QT_VERSION < 0x040600
96  virtual void paintEvent(QPaintEvent*);
97  virtual void mousePressEvent(QMouseEvent*);
98  virtual void mouseReleaseEvent(QMouseEvent*);
99 #endif
100  virtual void resizeEvent(QResizeEvent*);
101 private:
102  void init();
107  ctkCollapsibleGroupBoxStyle* Style;
108 };
109 
110 //----------------------------------------------------------------------------
112 {
113  return !this->isChecked();
114 }
115 
116 //----------------------------------------------------------------------------
118 {
119  this->setChecked(!collapse);
120 }
121 
122 #endif
virtual int heightForWidth(int w) const
void setCollapsed(bool collapse)
virtual void childEvent(QChildEvent *c)
QSize OldSize
Size of the widget for collapsing.
virtual void drawPrimitive(PrimitiveElement element, const QStyleOption *option, QPainter *painter, const QWidget *widget) const
virtual QSize minimumSizeHint() const
bool isChecked() const
virtual void mouseReleaseEvent(QMouseEvent *event)
virtual void paintEvent(QPaintEvent *event)
virtual QSize sizeHint() const
virtual void resizeEvent(QResizeEvent *e)
ctkCollapsibleGroupBoxStyle * Style
int MaxHeight
Maximum allowed height.
virtual void mousePressEvent(QMouseEvent *event)