summaryrefslogtreecommitdiff
path: root/client/collapser.cc
diff options
context:
space:
mode:
Diffstat (limited to 'client/collapser.cc')
-rw-r--r--client/collapser.cc72
1 files changed, 55 insertions, 17 deletions
diff --git a/client/collapser.cc b/client/collapser.cc
index a00dcff..6ae9d21 100644
--- a/client/collapser.cc
+++ b/client/collapser.cc
@@ -31,7 +31,7 @@
#include "debug.h"
-#define ANIM_TIME 250
+#define ANIM_TIME 2000
#define ANIM_INTERVAL 20
Collapser::Collapser(QWidget *collapsed, QWidget *expanded, bool setcollapsed,
@@ -58,48 +58,57 @@ Collapser::Collapser(QWidget *collapsed, QWidget *expanded, bool setcollapsed,
void Collapser::setWidgets(QWidget *collapsed, QWidget *expanded)
{
+ DEBUG(collapser, "\n");
setCollapsedWidget(collapsed);
setExpandedWidget(expanded);
}
void Collapser::setCollapsedWidget(QWidget *collapsed)
{
+ DEBUG(collapser, "\n");
this->collapsed = collapsed;
-
+ /*
if(isCollapsed() == true && collapsed) {
layout()->addWidget(collapsed);
collapsed->setVisible(true);
}
+ */
}
void Collapser::setExpandedWidget(QWidget *expanded)
{
+ DEBUG(collapser, "\n");
this->expanded = expanded;
-
+ /*
if(isCollapsed() == false && expanded) {
layout()->addWidget(expanded);
expanded->setVisible(true);
}
+ */
}
QWidget *Collapser::collapsedWidget()
{
+ DEBUG(collapser, "\n");
return collapsed;
}
QWidget *Collapser::expandedWidget()
{
+ DEBUG(collapser, "\n");
return expanded;
}
bool Collapser::isCollapsed()
{
+ DEBUG(collapser, "\n");
return is_collapsed;
}
void Collapser::setCollapsed(bool setcollapsed)
{
+ DEBUG(collapser, "\n");
if(this->is_collapsed == setcollapsed) return;
if(setcollapsed) collapse();
@@ -108,6 +117,7 @@ void Collapser::setCollapsed(bool setcollapsed)
void Collapser::collapse()
{
+ DEBUG(collapser, "\n");
emit collapsing();
t_anim.start();
@@ -119,14 +129,17 @@ void Collapser::collapse()
expanded->setVisible(false);
layout()->removeWidget(expanded);
}
+ if(expanded) placeholder.grab_from(expanded);
layout()->addWidget(&placeholder);
placeholder.setVisible(true);
- if(expanded) placeholder.grab(expanded);
+
+ if(collapsed) placeholder.grab_to(collapsed);
}
void Collapser::expand()
{
+ DEBUG(collapser, "\n");
emit expanding();
t_anim.start();
@@ -134,16 +147,16 @@ void Collapser::expand()
// show expanded
if(collapsed) {
collapsed->setVisible(false);
- // qApp->processEvents(); // Make sure it is actually invisble before removing it form the layout.
+ //qApp->processEvents(); // Make sure it is actually invisble before removing it form the layout.
layout()->removeWidget(collapsed);
+
+ placeholder.grab_from(collapsed);
}
- if(expanded) {
- layout()->addWidget(&placeholder);
- placeholder.setVisible(true);
- placeholder.grab(expanded);
- // layout()->addWidget(expanded);
- // expanded->setVisible(true);
- }
+
+ layout()->addWidget(&placeholder);
+ placeholder.setVisible(true);
+
+ if(expanded) placeholder.grab_to(expanded);
is_collapsed = false;
timer->start();
@@ -151,12 +164,14 @@ void Collapser::expand()
void Collapser::toggleCollapse()
{
+ DEBUG(collapser, "\n");
if(!is_collapsed) collapse();
else expand();
}
void Collapser::anim()
{
+ DEBUG(collapser, "\n");
int c_height = 16;
int e_height = 16;
if(collapsed) {
@@ -175,6 +190,8 @@ void Collapser::anim()
if(x < 1) {
y = x * x * x;
+ placeholder.setWeight(x);
+
int height;
if(!is_collapsed) {
height = (int)((1 - y) * c_height + y * e_height);
@@ -195,7 +212,7 @@ void Collapser::anim()
if(collapsed) {
layout()->addWidget(collapsed);
- collapsed->setFixedHeight(c_height);
+ // collapsed->setFixedHeight(c_height);
collapsed->setVisible(true);
}
@@ -227,16 +244,37 @@ void Collapser::anim()
void Collapser::Placeholder::paintEvent(QPaintEvent *)
{
QPainter p(this);
- p.drawPixmap(rect(), pixmap, pixmap.rect());
+ p.setOpacity(1 - weight);
+ p.drawPixmap(rect(), pixmap_from, pixmap_from.rect());
+ p.setOpacity(weight);
+ p.drawPixmap(rect(), pixmap_to, pixmap_to.rect());
+}
+
+void Collapser::Placeholder::grab_from(QWidget *w)
+{
+ weight = 0; // Reset
+
+ if(!w) return;
+ // w->setFixedWidth(contentsRect().width());
+ QSize sz = w->minimumSizeHint();
+ // w->setFixedHeight(sz.height());
+ w->resize(width(), sz.height());
+ pixmap_from = QPixmap::grabWidget(w, 0, 0);
}
-void Collapser::Placeholder::grab(QWidget *w)
+void Collapser::Placeholder::grab_to(QWidget *w)
{
+ weight = 0; // Reset
+
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);
+ pixmap_to = QPixmap::grabWidget(w, 0, 0);
+}
+
+void Collapser::Placeholder::setWeight(double w)
+{
+ weight = w * w * w;
}