summaryrefslogtreecommitdiff
path: root/client/collapser.cc
diff options
context:
space:
mode:
Diffstat (limited to 'client/collapser.cc')
-rw-r--r--client/collapser.cc71
1 files changed, 48 insertions, 23 deletions
diff --git a/client/collapser.cc b/client/collapser.cc
index cbbd84e..a00dcff 100644
--- a/client/collapser.cc
+++ b/client/collapser.cc
@@ -27,8 +27,11 @@
#include "collapser.h"
#include <QApplication>
#include <QHBoxLayout>
+#include <QPainter>
-#define ANIM_TIME 100
+#include "debug.h"
+
+#define ANIM_TIME 250
#define ANIM_INTERVAL 20
Collapser::Collapser(QWidget *collapsed, QWidget *expanded, bool setcollapsed,
@@ -61,12 +64,6 @@ void Collapser::setWidgets(QWidget *collapsed, QWidget *expanded)
void Collapser::setCollapsedWidget(QWidget *collapsed)
{
- /*
- if(this->collapsed) {
- delete this->collapsed;
- this->collapsed = NULL;
- }
- */
this->collapsed = collapsed;
if(isCollapsed() == true && collapsed) {
@@ -77,12 +74,6 @@ void Collapser::setCollapsedWidget(QWidget *collapsed)
void Collapser::setExpandedWidget(QWidget *expanded)
{
- /*
- if(this->expanded) {
- delete this->expanded;
- this->expanded = NULL;
- }
- */
this->expanded = expanded;
if(isCollapsed() == false && expanded) {
@@ -123,6 +114,15 @@ void Collapser::collapse()
is_collapsed = true;
timer->start();
+
+ if(expanded) {
+ expanded->setVisible(false);
+ layout()->removeWidget(expanded);
+ }
+
+ layout()->addWidget(&placeholder);
+ placeholder.setVisible(true);
+ if(expanded) placeholder.grab(expanded);
}
void Collapser::expand()
@@ -134,12 +134,15 @@ void Collapser::expand()
// show expanded
if(collapsed) {
collapsed->setVisible(false);
- qApp->processEvents(); // Make sure it is actualle invisble before removing it form the layout.
+ // qApp->processEvents(); // Make sure it is actually invisble before removing it form the layout.
layout()->removeWidget(collapsed);
}
if(expanded) {
- layout()->addWidget(expanded);
- expanded->setVisible(true);
+ layout()->addWidget(&placeholder);
+ placeholder.setVisible(true);
+ placeholder.grab(expanded);
+ // layout()->addWidget(expanded);
+ // expanded->setVisible(true);
}
is_collapsed = false;
@@ -186,15 +189,13 @@ void Collapser::anim()
if(is_collapsed) {
// show collapsed
- if(expanded) {
- expanded->setVisible(false);
- // Make sure it is actualle invisible before removing it from the
- // layout.
- qApp->processEvents();
- layout()->removeWidget(expanded);
- }
+
+ placeholder.setVisible(false);
+ layout()->removeWidget(&placeholder);
+
if(collapsed) {
layout()->addWidget(collapsed);
+ collapsed->setFixedHeight(c_height);
collapsed->setVisible(true);
}
@@ -205,6 +206,13 @@ void Collapser::anim()
} else {
setFixedHeight(e_height);
+ placeholder.setVisible(false);
+ layout()->removeWidget(&placeholder);
+ if(expanded) {
+ layout()->addWidget(expanded);
+ expanded->setVisible(true);
+ }
+
emit doneExpanding();
if(scrollarea && expanded) {
@@ -215,3 +223,20 @@ void Collapser::anim()
}
}
+
+void Collapser::Placeholder::paintEvent(QPaintEvent *)
+{
+ QPainter p(this);
+ p.drawPixmap(rect(), pixmap, pixmap.rect());
+}
+
+void Collapser::Placeholder::grab(QWidget *w)
+{
+ if(!w) return;
+ // w->setFixedWidth(contentsRect().width());
+ QSize sz = w->minimumSizeHint();
+ // w->setFixedHeight(sz.height());
+ DEBUG(collapser, "WIDTH: %d\n", width());
+ w->resize(width(), sz.height());
+ pixmap = QPixmap::grabWidget(w, 0, 0);
+}