summary refs log tree commit diff
path: root/src/ui
diff options
context:
space:
mode:
authorKonstantinos Sideris <sideris.konstantin@gmail.com>2018-05-08 23:38:57 +0300
committerKonstantinos Sideris <sideris.konstantin@gmail.com>2018-05-08 23:38:57 +0300
commit7d809be79f1a8b075272dba91893bfe9086fa079 (patch)
treef0e6eafed071b6670c2a1ea18ec7c4c761180cf4 /src/ui
parentDon't use shared pointers for cache (diff)
downloadnheko-7d809be79f1a8b075272dba91893bfe9086fa079.tar.xz
Hide SnackBar initially & guard against access of an empty list
Diffstat (limited to 'src/ui')
-rw-r--r--src/ui/SnackBar.cc34
1 files changed, 19 insertions, 15 deletions
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<QTimer>(new QTimer); - hideTimer_ = QSharedPointer<QTimer>(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);