From 47561fdd6e67ab1918acf8f44ed54759bdf467a7 Mon Sep 17 00:00:00 2001 From: deva Date: Tue, 22 Feb 2011 15:41:12 +0000 Subject: Make collapser use QPixmap during animation. --- client/collapser.cc | 71 ++++++++++++++++++++++++++++++++++----------------- client/collapser.h | 13 ++++++++++ client/macrowindow.cc | 9 ++++--- 3 files changed, 66 insertions(+), 27 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 #include +#include -#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); +} diff --git a/client/collapser.h b/client/collapser.h index 8b38359..2b1ad3c 100644 --- a/client/collapser.h +++ b/client/collapser.h @@ -30,7 +30,9 @@ #include #include #include + #include +#include class Collapser : public QWidget { Q_OBJECT @@ -65,6 +67,17 @@ protected: // void timerEvent(QTimerEvent *); private: + class Placeholder : public QWidget { + public: + QPixmap pixmap; + void grab(QWidget *w); + + protected: + void paintEvent(QPaintEvent*); + }; + + Placeholder placeholder; + QWidget *collapsed; QWidget *expanded; diff --git a/client/macrowindow.cc b/client/macrowindow.cc index 481ee0c..04cc2cb 100644 --- a/client/macrowindow.cc +++ b/client/macrowindow.cc @@ -233,13 +233,14 @@ void MacroWindow::expandWrapper() } } } - if(mainwidget) setExpandedWidget(mainwidget->qwidget()); - expand(); - // Set values here, to be sure that the widgets are visible and thereby - // validate correctly. + // Set values here, to be sure that the widgets are visible to the value + // system and thereby validate correctly. if(mainwidget) mainwidget->setValues(); + if(mainwidget) setExpandedWidget(mainwidget->qwidget()); + expand(); + // Set keyboard focus on the first focusable widget in the macro. QVector< Widget* > widgets; if(mainwidget) widgets = mainwidget->widgetList(true); -- cgit v1.2.3