2 This file is part of the KDE libraries
3 Copyright (C) 2005 Daniel Molkentin <molkentin@kde.org>
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License version 2 as published by the Free Software Foundation.
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Steet, Fifth Floor,
17 Boston, MA 02110-1301, USA.
22 #include <collapsiblewidget.h>
24 /******************************************************************
26 *****************************************************************/
28 class CollapsibleWidget::Private
32 QGridLayout
*gridLayout
;
37 class SettingsContainer::Private
43 /******************************************************************
45 *****************************************************************/
47 SettingsContainer::SettingsContainer(QWidget
*parent
)
48 : QScrollArea( parent
), d(new SettingsContainer::Private
)
50 QWidget
*w
= new QWidget
;
51 QVBoxLayout
*helperLay
= new QVBoxLayout(w
);
52 d
->layout
= new QVBoxLayout
;
53 helperLay
->addLayout( d
->layout
);
54 helperLay
->addStretch(1);
56 setWidgetResizable(true);
59 SettingsContainer::~SettingsContainer()
64 CollapsibleWidget
* SettingsContainer::insertWidget( QWidget
*w
, const QString
& name
)
68 if ( w
&& w
->layout() ) {
69 QLayout
*lay
= w
->layout();
74 CollapsibleWidget
*cw
= new CollapsibleWidget( this );
75 d
->layout
->addWidget( cw
);
76 cw
->setInnerWidget( w
);
80 CollapsibleWidget::CollapsibleWidget(QWidget
*parent
)
81 : QWidget(parent
), d(new CollapsibleWidget::Private
)
86 void CollapsibleWidget::init()
91 d
->timeline
= new QTimeLine( 150, this );
92 d
->timeline
->setCurveShape( QTimeLine::EaseInOutCurve
);
93 connect( d
->timeline
, SIGNAL(valueChanged(qreal
)),
94 this, SLOT(animateCollapse(qreal
)) );
95 connect( d
->timeline
, SIGNAL(finished()),
96 this, SLOT(signalCompletion()) );
98 d
->gridLayout
= new QGridLayout( this );
99 d
->gridLayout
->setMargin(0);
105 CollapsibleWidget::~CollapsibleWidget()
110 QWidget
* CollapsibleWidget::innerWidget() const
112 return d
->innerWidget
;
115 void CollapsibleWidget::setInnerWidget(QWidget
*w
)
123 if ( !isExpanded() ) {
124 d
->innerWidget
->hide();
126 d
->gridLayout
->addWidget( d
->innerWidget
, 2, 2 );
127 d
->gridLayout
->setRowStretch( 2, 1 );
131 if ( isExpanded() ) {
136 void CollapsibleWidget::setExpanded(bool expanded
)
138 if ( !d
->innerWidget
) {
142 d
->expanded
= expanded
;
145 d
->innerWidget
->setVisible( false );
148 d
->timeline
->setDirection( expanded
? QTimeLine::Forward
149 : QTimeLine::Backward
);
150 d
->timeline
->start();
153 void CollapsibleWidget::animateCollapse( qreal showAmount
)
155 int pixels
= d
->innerWidget
->sizeHint().height() * showAmount
;
157 d
->gridLayout
->setRowMinimumHeight( 2, pixels
);
159 if ( showAmount
== 1 ) {
160 d
->innerWidget
->setVisible( true );
164 void CollapsibleWidget::signalCompletion()
166 if ( isExpanded() ) {
167 emit
expandCompleted();
169 emit
collapseCompleted();
173 bool CollapsibleWidget::isExpanded() const
178 #include "collapsiblewidget.moc"