diff options
author | deva <deva> | 2008-09-19 12:07:48 +0000 |
---|---|---|
committer | deva <deva> | 2008-09-19 12:07:48 +0000 |
commit | 3541224f0fb3d5b7b531eef45318d7e41cb51915 (patch) | |
tree | 450e6fc9d3ae57f7db7a79cfa87386e0b7b09c92 /client/collapser.cc | |
parent | eff75e9193b0e1d9175f49e003977d524c6a2d36 (diff) |
First working version of the collapser-pracro view.
Diffstat (limited to 'client/collapser.cc')
-rw-r--r-- | client/collapser.cc | 105 |
1 files changed, 79 insertions, 26 deletions
diff --git a/client/collapser.cc b/client/collapser.cc index 391f9b1..7faf175 100644 --- a/client/collapser.cc +++ b/client/collapser.cc @@ -33,25 +33,55 @@ Collapser::Collapser(QWidget *collapsed, QWidget *expanded, bool setcollapsed) { + this->collapsed = NULL; + this->expanded = NULL; + setLayout(new QHBoxLayout()); layout()->setContentsMargins(0,0,0,0); + setWidgets(collapsed, expanded); + + is_collapsed = !setcollapsed; // Make sure setCollapsed actually does something. + setCollapsed(setcollapsed); +} + +void Collapser::setWidgets(QWidget *collapsed, QWidget *expanded) +{ + setCollapsedWidget(collapsed); + setExpandedWidget(expanded); +} + +void Collapser::setCollapsedWidget(QWidget *collapsed) +{ + if(this->collapsed) { + // delete this->collapsed; + this->collapsed = NULL; + } + this->collapsed = collapsed; - collapsed->show(); - c_height = collapsed->height(); - collapsed->setVisible(false); +} + +void Collapser::setExpandedWidget(QWidget *expanded) +{ + if(this->expanded) { + // delete this->expanded; + this->expanded = NULL; + } this->expanded = expanded; - expanded->show(); - e_height = expanded->height(); - expanded->setVisible(false); +} - collapsed->setVisible(false); - expanded->setVisible(false); +QWidget *Collapser::collapsedWidget() +{ + return collapsed; +} - setCollapsed(setcollapsed); +QWidget *Collapser::expandedWidget() +{ + return expanded; } + bool Collapser::isCollapsed() { return is_collapsed; @@ -69,7 +99,6 @@ void Collapser::collapse() { t_anim.start(); - is_collapsed = true; timer_id = startTimer(ANIM_INTERVAL); } @@ -79,10 +108,14 @@ void Collapser::expand() t_anim.start(); // show expanded - collapsed->setVisible(false); - layout()->removeWidget(collapsed); - layout()->addWidget(expanded); - expanded->setVisible(true); + if(collapsed) { + collapsed->setVisible(false); + layout()->removeWidget(collapsed); + } + if(expanded) { + layout()->addWidget(expanded); + expanded->setVisible(true); + } is_collapsed = false; timer_id = startTimer(ANIM_INTERVAL); @@ -91,12 +124,25 @@ void Collapser::expand() void Collapser::toggleCollapse() { if(!is_collapsed) collapse(); - else expand(); } void Collapser::anim() { + int c_height = 16; + int e_height = 16; + if(collapsed) { + QSize sz = collapsed->minimumSizeHint(); + c_height = sz.height(); + //c_height = collapsed->minimumHeight(); + } + + if(expanded) { + QSize sz = expanded->minimumSizeHint(); + e_height = sz.height(); + //e_height = expanded->minimumHeight(); + } + killTimer(timer_id); double x = (double)(t_anim.elapsed()) / ANIM_TIME; @@ -105,25 +151,32 @@ void Collapser::anim() if(x < 1) { y = x * x * x; + if(!is_collapsed) { + setFixedHeight((1 - y) * c_height + y * e_height); + } else { + setFixedHeight((1 - y) * e_height + y * c_height); + } + timer_id = startTimer(ANIM_INTERVAL); } else { if(is_collapsed) { // show collapsed - expanded->setVisible(false); - layout()->removeWidget(expanded); - layout()->addWidget(collapsed); - collapsed->setVisible(true); - + if(expanded) { + expanded->setVisible(false); + layout()->removeWidget(expanded); + } + if(collapsed) { + layout()->addWidget(collapsed); + collapsed->setVisible(true); + } + + setFixedHeight(c_height); + } else { + setFixedHeight(e_height); } } - - if(!is_collapsed) { - setFixedHeight((1 - y) * c_height + y * e_height); - } else { - setFixedHeight((1 - y) * e_height + y * c_height); - } } void Collapser::timerEvent(QTimerEvent *) |