From 4a6becacca08fbb66d254fdca4870a33013df77a Mon Sep 17 00:00:00 2001 From: Konstantinos Sideris Date: Fri, 16 Mar 2018 17:56:45 +0200 Subject: Add fancy snackbar animation --- src/ui/SnackBar.cc | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) (limited to 'src/ui') diff --git a/src/ui/SnackBar.cc b/src/ui/SnackBar.cc index 1f02ee95..123d83e8 100644 --- a/src/ui/SnackBar.cc +++ b/src/ui/SnackBar.cc @@ -1,6 +1,8 @@ #include #include +#include + #include "SnackBar.h" constexpr int STARTING_OFFSET = 1; @@ -27,7 +29,18 @@ SnackBar::SnackBar(QWidget *parent) hideTimer_ = QSharedPointer(new QTimer); hideTimer_->setSingleShot(true); - connect(showTimer_.data(), SIGNAL(timeout()), this, SLOT(onTimeout())); + auto offset_anim = tweeny::from(1.0f).to(0.0f).during(4000).via(tweeny::easing::elasticOut); + connect(showTimer_.data(), &QTimer::timeout, this, [this, offset_anim]() mutable { + if (offset_anim.progress() < 1.0f) { + offset_ = offset_anim.step(0.02f); + update(); + } else { + showTimer_->stop(); + hideTimer_->start(duration_); + offset_anim.seek(0.0f); + } + }); + connect(hideTimer_.data(), SIGNAL(timeout()), this, SLOT(hideMessage())); } @@ -75,19 +88,6 @@ SnackBar::showMessage(const QString &msg) start(); } -void -SnackBar::onTimeout() -{ - offset_ -= 1.1; - - if (offset_ <= 0.0) { - showTimer_->stop(); - hideTimer_->start(duration_); - } - - update(); -} - void SnackBar::mousePressEvent(QMouseEvent *) { -- cgit 1.5.1