From 4a6becacca08fbb66d254fdca4870a33013df77a Mon Sep 17 00:00:00 2001 From: Konstantinos Sideris Date: Fri, 16 Mar 2018 17:56:45 +0200 Subject: [PATCH] Add fancy snackbar animation --- CMakeLists.txt | 8 +++++++- cmake/Tweeny.cmake | 25 +++++++++++++++++++++++++ include/ui/SnackBar.h | 1 - src/ui/SnackBar.cc | 28 ++++++++++++++-------------- 4 files changed, 46 insertions(+), 16 deletions(-) create mode 100644 cmake/Tweeny.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 48c79496..ddbd3d35 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -217,6 +217,12 @@ set(SRC_FILES include(MatrixStructs) include_directories(${MATRIX_STRUCTS_INCLUDE_DIRS}) +# +# libtweeny +# +include(Tweeny) +include_directories(${TWEENY_INCLUDE_DIRS}) + # # lmdbxx # @@ -342,7 +348,7 @@ else() target_link_libraries (nheko ${NHEKO_LIBS} Qt5::Multimedia) endif() -add_dependencies(nheko MatrixStructs lmdbxx) +add_dependencies(nheko MatrixStructs Tweeny lmdbxx) if(UNIX AND NOT APPLE) install (TARGETS nheko RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}") diff --git a/cmake/Tweeny.cmake b/cmake/Tweeny.cmake new file mode 100644 index 00000000..87a2ade8 --- /dev/null +++ b/cmake/Tweeny.cmake @@ -0,0 +1,25 @@ +include(ExternalProject) + +# +# Build tweeny +# + +set(THIRD_PARTY_ROOT ${CMAKE_SOURCE_DIR}/.third-party) +set(TWEENY_ROOT ${THIRD_PARTY_ROOT}/tweeny) + +set(TWEENY_INCLUDE_DIRS ${TWEENY_ROOT}/include) + +ExternalProject_Add( + Tweeny + + GIT_REPOSITORY https://github.com/mobius3/tweeny + GIT_TAG b94ce07cfb02a0eb8ac8aaf66137dabdaea857cf + + BUILD_IN_SOURCE 1 + SOURCE_DIR ${TWEENY_ROOT} + CONFIGURE_COMMAND "" + BUILD_COMMAND "" + INSTALL_COMMAND "" +) + +include_directories(SYSTEM ${TWEENY_ROOT}/include) diff --git a/include/ui/SnackBar.h b/include/ui/SnackBar.h index bb579e92..89a8adaa 100644 --- a/include/ui/SnackBar.h +++ b/include/ui/SnackBar.h @@ -32,7 +32,6 @@ protected: void mousePressEvent(QMouseEvent *event) override; private slots: - void onTimeout(); void hideMessage(); private: 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 *) {