GOFIGURE2  0.9.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
ctkCollapsibleGroupBox.cpp
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 // Qt includes
22 #include <QDebug>
23 #include <QChildEvent>
24 #include <QMouseEvent>
25 #include <QStylePainter>
26 #include <QStyleOptionGroupBox>
27 #include <QStyle>
28 
29 // CTK includes
30 #include "ctkCollapsibleGroupBox.h"
31 
32 //-----------------------------------------------------------------------------
34  :QGroupBox(_parent)
35 {
36  this->init();
37 }
38 
39 //-----------------------------------------------------------------------------
41  :QGroupBox(_title, _parent)
42 {
43  this->init();
44 }
45 
46 //-----------------------------------------------------------------------------
48 {
49  if(Style)
50  {
51  delete Style;
52  }
53 }
54 
55 //-----------------------------------------------------------------------------
57 {
58  this->setCheckable(true);
59  connect(this, SIGNAL(toggled(bool)), this, SLOT(expand(bool)));
60 
61  this->MaxHeight = this->maximumHeight();
62 
63 #if QT_VERSION >= 0x040600
64  Style = new ctkCollapsibleGroupBoxStyle;
65  this->setStyle(Style);
66 #else
67  this->setStyleSheet(
68  "ctkCollapsibleGroupBox::indicator:checked{"
69  "image: url(:/Icons/expand-up.png);}"
70  "ctkCollapsibleGroupBox::indicator:unchecked{"
71  "image: url(:/Icons/expand-down.png);}");
72 #endif
73 }
74 
75 //-----------------------------------------------------------------------------
77 {
78  if (!_expand)
79  {
80  this->OldSize = this->size();
81  }
82 
83  /*QObjectList childList = this->children();
84  for (int i = 0; i < childList.size(); ++i)
85  {
86  QObject *o = childList.at(i);
87  if (o && o->isWidgetType())
88  {
89  QWidget *w = static_cast<QWidget *>(o);
90  if ( w )
91  {
92  w->setVisible(_expand);
93  }
94  }
95  }*/
96 
97  if (_expand)
98  {
99  this->setMaximumHeight(this->MaxHeight);
100  this->resize(this->OldSize);
101  this->setFlat(false);
102  }
103  else
104  {
105  this->MaxHeight = this->maximumHeight();
106  this->setMaximumHeight(22);
107  this->setFlat(true);
108  }
109 
110  //this->updateGeometry();
111  //this->sizeHint();
112 }
113 
114 //-----------------------------------------------------------------------------
116 {
117  if(c && c->type() == QEvent::ChildAdded)
118  {
119  if (c->child() && c->child()->isWidgetType())
120  {
121  QWidget *w = static_cast<QWidget*>(c->child());
122  w->setVisible(this->isChecked());
123  }
124  }
126 }
127 
128 #if QT_VERSION < 0x040600
129 //-----------------------------------------------------------------------------
131 {
132  this->QGroupBox::paintEvent(e);
133 
134  QStylePainter paint(this);
135  QStyleOptionGroupBox option;
136  initStyleOption(&option);
137  option.activeSubControls &= !QStyle::SC_GroupBoxCheckBox;
138  paint.drawComplexControl(QStyle::CC_GroupBox, option);
139 
140 }
141 
142 //-----------------------------------------------------------------------------
144 {
145  if (event->button() != Qt::LeftButton) {
146  event->ignore();
147  return;
148  }
149  // no animation
150 }
151 
152 //-----------------------------------------------------------------------------
154 {
155  if (event->button() != Qt::LeftButton) {
156  event->ignore();
157  return;
158  }
159 
161  initStyleOption(&box);
162  box.activeSubControls &= !QStyle::SC_GroupBoxCheckBox;
163  QStyle::SubControl released = style()->hitTestComplexControl(QStyle::CC_GroupBox, &box,
164  event->pos(), this);
165  bool toggle = this->isCheckable() && (released == QStyle::SC_GroupBoxLabel
166  || released == QStyle::SC_GroupBoxCheckBox);
167  if (toggle)
168  {
169  this->setChecked(!this->isChecked());
170  }
171 }
172 
173 #endif
174 
175 //-----------------------------------------------------------------------------
177 {
178  //qDebug() << "ctkCollapsibleGroupBox::minimumSizeHint::" << this->QGroupBox::minimumSizeHint() ;
179  return this->QGroupBox::minimumSizeHint();
180 }
181 
182 //-----------------------------------------------------------------------------
184 {
185  //qDebug() << "ctkCollapsibleGroupBox::sizeHint::" << this->QGroupBox::sizeHint() ;
186  return this->QGroupBox::sizeHint();
187 }
188 
189 //-----------------------------------------------------------------------------
191 {
192  //qDebug() << "ctkCollapsibleGroupBox::heightForWidth::" << this->QGroupBox::heightForWidth(w) ;
193  return this->QGroupBox::heightForWidth(w);
194 }
195 
196 //-----------------------------------------------------------------------------
198 {
199  //qDebug() << "ctkCollapsibleGroupBox::resizeEvent::" << _event->oldSize() << _event->size() ;
200  return this->QGroupBox::resizeEvent(_event);
201 }
virtual int heightForWidth(int w) const
void setStyleSheet(const QString &styleSheet)
Type type() const
virtual void childEvent(QChildEvent *c)
QSize OldSize
Size of the widget for collapsing.
ctkCollapsibleGroupBox(QWidget *parent=0)
QStyle * style() const
virtual void mousePressEvent(QMouseEvent *)
virtual void setVisible(bool visible)
QObject * child() const
void setFlat(bool flat)
virtual QSize minimumSizeHint() const
Reimplemtented for internal reasons.
virtual QSize minimumSizeHint() const
QSize size() const
virtual void childEvent(QChildEvent *)
reimplemented for internal reasons
bool isChecked() const
virtual void expand(bool expand)
virtual void paintEvent(QPaintEvent *event)
Qt::MouseButton button() const
virtual void resizeEvent(QResizeEvent *)
virtual QSize sizeHint() const
virtual void paintEvent(QPaintEvent *)
virtual void resizeEvent(QResizeEvent *e)
void toggled(bool on)
ctkCollapsibleGroupBoxStyle * Style
int maximumHeight() const
void setCheckable(bool checkable)
int MaxHeight
Maximum allowed height.
virtual int heightForWidth(int w) const
Reimplemtented for internal reasons.
void initStyleOption(QStyleOptionGroupBox *option) const
void drawComplexControl(QStyle::ComplexControl cc, const QStyleOptionComplex &option)
virtual SubControl hitTestComplexControl(ComplexControl control, const QStyleOptionComplex *option, const QPoint &position, const QWidget *widget) const =0
const QPoint & pos() const
virtual void mouseReleaseEvent(QMouseEvent *)
bool isWidgetType() const
virtual QSize sizeHint() const
Reimplemtented for internal reasons.
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
void setStyle(QStyle *style)