Add fancy snackbar animation
This commit is contained in:
parent
343acaf434
commit
4a6becacca
@ -217,6 +217,12 @@ set(SRC_FILES
|
|||||||
include(MatrixStructs)
|
include(MatrixStructs)
|
||||||
include_directories(${MATRIX_STRUCTS_INCLUDE_DIRS})
|
include_directories(${MATRIX_STRUCTS_INCLUDE_DIRS})
|
||||||
|
|
||||||
|
#
|
||||||
|
# libtweeny
|
||||||
|
#
|
||||||
|
include(Tweeny)
|
||||||
|
include_directories(${TWEENY_INCLUDE_DIRS})
|
||||||
|
|
||||||
#
|
#
|
||||||
# lmdbxx
|
# lmdbxx
|
||||||
#
|
#
|
||||||
@ -342,7 +348,7 @@ else()
|
|||||||
target_link_libraries (nheko ${NHEKO_LIBS} Qt5::Multimedia)
|
target_link_libraries (nheko ${NHEKO_LIBS} Qt5::Multimedia)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
add_dependencies(nheko MatrixStructs lmdbxx)
|
add_dependencies(nheko MatrixStructs Tweeny lmdbxx)
|
||||||
|
|
||||||
if(UNIX AND NOT APPLE)
|
if(UNIX AND NOT APPLE)
|
||||||
install (TARGETS nheko RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}")
|
install (TARGETS nheko RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}")
|
||||||
|
25
cmake/Tweeny.cmake
Normal file
25
cmake/Tweeny.cmake
Normal file
@ -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;
|
void mousePressEvent(QMouseEvent *event) override;
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void onTimeout();
|
|
||||||
void hideMessage();
|
void hideMessage();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
|
|
||||||
|
#include <tweeny.h>
|
||||||
|
|
||||||
#include "SnackBar.h"
|
#include "SnackBar.h"
|
||||||
|
|
||||||
constexpr int STARTING_OFFSET = 1;
|
constexpr int STARTING_OFFSET = 1;
|
||||||
@ -27,7 +29,18 @@ SnackBar::SnackBar(QWidget *parent)
|
|||||||
hideTimer_ = QSharedPointer<QTimer>(new QTimer);
|
hideTimer_ = QSharedPointer<QTimer>(new QTimer);
|
||||||
hideTimer_->setSingleShot(true);
|
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()));
|
connect(hideTimer_.data(), SIGNAL(timeout()), this, SLOT(hideMessage()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -75,19 +88,6 @@ SnackBar::showMessage(const QString &msg)
|
|||||||
start();
|
start();
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
|
||||||
SnackBar::onTimeout()
|
|
||||||
{
|
|
||||||
offset_ -= 1.1;
|
|
||||||
|
|
||||||
if (offset_ <= 0.0) {
|
|
||||||
showTimer_->stop();
|
|
||||||
hideTimer_->start(duration_);
|
|
||||||
}
|
|
||||||
|
|
||||||
update();
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
void
|
||||||
SnackBar::mousePressEvent(QMouseEvent *)
|
SnackBar::mousePressEvent(QMouseEvent *)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user