diff options
author | Nicolas Werner <nicolas.werner@hotmail.de> | 2021-03-05 14:04:11 +0100 |
---|---|---|
committer | Nicolas Werner <nicolas.werner@hotmail.de> | 2021-03-05 14:04:30 +0100 |
commit | 626d8bf1517783d35e6cc0d0bfa9715a742154e2 (patch) | |
tree | 9deb308802a249d1899ebb286bcff740efc2d362 /src/ui | |
parent | Merge pull request #505 from Nheko-Reborn/license-headers (diff) | |
download | nheko-626d8bf1517783d35e6cc0d0bfa9715a742154e2.tar.xz |
Remove tweeny
Diffstat (limited to 'src/ui')
-rw-r--r-- | src/ui/SnackBar.cpp | 23 | ||||
-rw-r--r-- | src/ui/SnackBar.h | 17 |
2 files changed, 26 insertions, 14 deletions
diff --git a/src/ui/SnackBar.cpp b/src/ui/SnackBar.cpp index 03609802..2453369d 100644 --- a/src/ui/SnackBar.cpp +++ b/src/ui/SnackBar.cpp @@ -4,8 +4,6 @@ #include <QPainter> -#include <tweeny.h> - #include "SnackBar.h" constexpr int STARTING_OFFSET = 1; @@ -16,6 +14,7 @@ constexpr double MIN_WIDTH_PERCENTAGE = 0.3; SnackBar::SnackBar(QWidget *parent) : OverlayWidget(parent) + , offset_anim(this, "offset", this) { QFont font; font.setPointSizeF(font.pointSizeF() * 1.2); @@ -28,17 +27,16 @@ SnackBar::SnackBar(QWidget *parent) hideTimer_.setSingleShot(true); - auto offset_anim = tweeny::from(1.0f).to(0.0f).during(100).via(tweeny::easing::cubicOut); - connect(&showTimer_, &QTimer::timeout, this, [this, offset_anim]() mutable { - if (offset_anim.progress() < 1.0f) { - offset_ = offset_anim.step(0.07f); + offset_anim.setStartValue(1.0); + offset_anim.setEndValue(0.0); + offset_anim.setDuration(100); + offset_anim.setEasingCurve(QEasingCurve::OutCubic); + + connect(this, &SnackBar::offsetChanged, this, [this]() mutable { repaint(); - } else { - showTimer_.stop(); - hideTimer_.start(ANIMATION_DURATION); - offset_anim.seek(0.0f); - } }); + connect( + &offset_anim, &QPropertyAnimation::finished, this, [this]() { hideTimer_.start(10000); }); connect(&hideTimer_, SIGNAL(timeout()), this, SLOT(hideMessage())); @@ -54,7 +52,7 @@ SnackBar::start() show(); raise(); - showTimer_.start(10); + offset_anim.start(); } void @@ -77,7 +75,6 @@ SnackBar::hideMessage() void SnackBar::stopTimers() { - showTimer_.stop(); hideTimer_.stop(); } diff --git a/src/ui/SnackBar.h b/src/ui/SnackBar.h index 5459159e..8d127933 100644 --- a/src/ui/SnackBar.h +++ b/src/ui/SnackBar.h @@ -6,6 +6,7 @@ #include <QCoreApplication> #include <QPaintEvent> +#include <QPropertyAnimation> #include <QTimer> #include <deque> @@ -23,6 +24,7 @@ class SnackBar : public OverlayWidget Q_PROPERTY(QColor bgColor READ backgroundColor WRITE setBackgroundColor) Q_PROPERTY(QColor textColor READ textColor WRITE setTextColor) + Q_PROPERTY(double offset READ offset WRITE setOffset NOTIFY offsetChanged) public: explicit SnackBar(QWidget *parent); @@ -46,9 +48,21 @@ public: update(); } + double offset() { return offset_; } + void setOffset(double offset) + { + if (offset != offset_) { + offset_ = offset; + emit offsetChanged(); + } + } + public slots: void showMessage(const QString &msg); +signals: + void offsetChanged(); + protected: void paintEvent(QPaintEvent *event) override; void mousePressEvent(QMouseEvent *event) override; @@ -68,10 +82,11 @@ private: std::deque<QString> messages_; - QTimer showTimer_; QTimer hideTimer_; double boxHeight_; + QPropertyAnimation offset_anim; + SnackBarPosition position_; }; |