Add fancy snackbar animation

remotes/origin/HEAD
Konstantinos Sideris 7 years ago
parent 343acaf434
commit 4a6becacca
  1. 8
      CMakeLists.txt
  2. 25
      cmake/Tweeny.cmake
  3. 1
      include/ui/SnackBar.h
  4. 28
      src/ui/SnackBar.cc

@ -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}")

@ -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)

@ -32,7 +32,6 @@ protected:
void mousePressEvent(QMouseEvent *event) override;
private slots:
void onTimeout();
void hideMessage();
private:

@ -1,6 +1,8 @@
#include <QDebug>
#include <QPainter>
#include <tweeny.h>
#include "SnackBar.h"
constexpr int STARTING_OFFSET = 1;
@ -27,7 +29,18 @@ SnackBar::SnackBar(QWidget *parent)
hideTimer_ = QSharedPointer<QTimer>(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 *)
{

Loading…
Cancel
Save