diff --git a/include/ui/SnackBar.h b/include/ui/SnackBar.h index 89a8adaa..eed59c87 100644 --- a/include/ui/SnackBar.h +++ b/include/ui/SnackBar.h @@ -2,8 +2,8 @@ #include #include -#include #include +#include #include "OverlayWidget.h" @@ -44,10 +44,10 @@ private: qreal bgOpacity_; qreal offset_; - QList messages_; + std::deque messages_; - QSharedPointer showTimer_; - QSharedPointer hideTimer_; + QTimer showTimer_; + QTimer hideTimer_; int duration_; int boxWidth_; diff --git a/src/MainWindow.cc b/src/MainWindow.cc index 745fb210..e256e6c9 100644 --- a/src/MainWindow.cc +++ b/src/MainWindow.cc @@ -204,7 +204,7 @@ MainWindow::removeOverlayProgressBar() }); // FIXME: Snackbar doesn't work if it's initialized in the constructor. - QTimer::singleShot(100, this, [this]() { + QTimer::singleShot(0, this, [this]() { snackBar_ = QSharedPointer(new SnackBar(this)); connect(chat_page_, &ChatPage::showNotification, diff --git a/src/ui/SnackBar.cc b/src/ui/SnackBar.cc index d548a128..c6e7ace8 100644 --- a/src/ui/SnackBar.cc +++ b/src/ui/SnackBar.cc @@ -25,32 +25,35 @@ SnackBar::SnackBar(QWidget *parent) font.setWeight(50); setFont(font); - showTimer_ = QSharedPointer(new QTimer); - hideTimer_ = QSharedPointer(new QTimer); - hideTimer_->setSingleShot(true); + hideTimer_.setSingleShot(true); auto offset_anim = tweeny::from(1.0f).to(0.0f).during(100).via(tweeny::easing::cubicOut); - connect(showTimer_.data(), &QTimer::timeout, this, [this, offset_anim]() mutable { + connect(&showTimer_, &QTimer::timeout, this, [this, offset_anim]() mutable { if (offset_anim.progress() < 1.0f) { offset_ = offset_anim.step(0.07f); update(); } else { - showTimer_->stop(); - hideTimer_->start(duration_); + showTimer_.stop(); + hideTimer_.start(duration_); offset_anim.seek(0.0f); } }); - connect(hideTimer_.data(), SIGNAL(timeout()), this, SLOT(hideMessage())); + connect(&hideTimer_, SIGNAL(timeout()), this, SLOT(hideMessage())); + + hide(); } void SnackBar::start() { + if (messages_.empty()) + return; + show(); raise(); - showTimer_->start(10); + showTimer_.start(10); } void @@ -59,21 +62,22 @@ SnackBar::hideMessage() stopTimers(); hide(); - // Moving on to the next message. - messages_.removeFirst(); + if (!messages_.empty()) + // Moving on to the next message. + messages_.pop_front(); // Reseting the starting position of the widget. offset_ = STARTING_OFFSET; - if (!messages_.isEmpty()) + if (!messages_.empty()) start(); } void SnackBar::stopTimers() { - showTimer_->stop(); - hideTimer_->stop(); + showTimer_.stop(); + hideTimer_.stop(); } void @@ -99,10 +103,10 @@ SnackBar::paintEvent(QPaintEvent *event) { Q_UNUSED(event) - if (messages_.isEmpty()) + if (messages_.empty()) return; - auto message_ = messages_.first(); + auto message_ = messages_.front(); QPainter p(this); p.setRenderHint(QPainter::Antialiasing);