Hide SnackBar initially & guard against access of an empty list
This commit is contained in:
parent
ebed87ea57
commit
7d809be79f
@ -2,8 +2,8 @@
|
|||||||
|
|
||||||
#include <QCoreApplication>
|
#include <QCoreApplication>
|
||||||
#include <QPaintEvent>
|
#include <QPaintEvent>
|
||||||
#include <QSharedPointer>
|
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
|
#include <deque>
|
||||||
|
|
||||||
#include "OverlayWidget.h"
|
#include "OverlayWidget.h"
|
||||||
|
|
||||||
@ -44,10 +44,10 @@ private:
|
|||||||
qreal bgOpacity_;
|
qreal bgOpacity_;
|
||||||
qreal offset_;
|
qreal offset_;
|
||||||
|
|
||||||
QList<QString> messages_;
|
std::deque<QString> messages_;
|
||||||
|
|
||||||
QSharedPointer<QTimer> showTimer_;
|
QTimer showTimer_;
|
||||||
QSharedPointer<QTimer> hideTimer_;
|
QTimer hideTimer_;
|
||||||
|
|
||||||
int duration_;
|
int duration_;
|
||||||
int boxWidth_;
|
int boxWidth_;
|
||||||
|
@ -204,7 +204,7 @@ MainWindow::removeOverlayProgressBar()
|
|||||||
});
|
});
|
||||||
|
|
||||||
// FIXME: Snackbar doesn't work if it's initialized in the constructor.
|
// FIXME: Snackbar doesn't work if it's initialized in the constructor.
|
||||||
QTimer::singleShot(100, this, [this]() {
|
QTimer::singleShot(0, this, [this]() {
|
||||||
snackBar_ = QSharedPointer<SnackBar>(new SnackBar(this));
|
snackBar_ = QSharedPointer<SnackBar>(new SnackBar(this));
|
||||||
connect(chat_page_,
|
connect(chat_page_,
|
||||||
&ChatPage::showNotification,
|
&ChatPage::showNotification,
|
||||||
|
@ -25,32 +25,35 @@ SnackBar::SnackBar(QWidget *parent)
|
|||||||
font.setWeight(50);
|
font.setWeight(50);
|
||||||
setFont(font);
|
setFont(font);
|
||||||
|
|
||||||
showTimer_ = QSharedPointer<QTimer>(new QTimer);
|
hideTimer_.setSingleShot(true);
|
||||||
hideTimer_ = QSharedPointer<QTimer>(new QTimer);
|
|
||||||
hideTimer_->setSingleShot(true);
|
|
||||||
|
|
||||||
auto offset_anim = tweeny::from(1.0f).to(0.0f).during(100).via(tweeny::easing::cubicOut);
|
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) {
|
if (offset_anim.progress() < 1.0f) {
|
||||||
offset_ = offset_anim.step(0.07f);
|
offset_ = offset_anim.step(0.07f);
|
||||||
update();
|
update();
|
||||||
} else {
|
} else {
|
||||||
showTimer_->stop();
|
showTimer_.stop();
|
||||||
hideTimer_->start(duration_);
|
hideTimer_.start(duration_);
|
||||||
offset_anim.seek(0.0f);
|
offset_anim.seek(0.0f);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
connect(hideTimer_.data(), SIGNAL(timeout()), this, SLOT(hideMessage()));
|
connect(&hideTimer_, SIGNAL(timeout()), this, SLOT(hideMessage()));
|
||||||
|
|
||||||
|
hide();
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
SnackBar::start()
|
SnackBar::start()
|
||||||
{
|
{
|
||||||
|
if (messages_.empty())
|
||||||
|
return;
|
||||||
|
|
||||||
show();
|
show();
|
||||||
raise();
|
raise();
|
||||||
|
|
||||||
showTimer_->start(10);
|
showTimer_.start(10);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@ -59,21 +62,22 @@ SnackBar::hideMessage()
|
|||||||
stopTimers();
|
stopTimers();
|
||||||
hide();
|
hide();
|
||||||
|
|
||||||
// Moving on to the next message.
|
if (!messages_.empty())
|
||||||
messages_.removeFirst();
|
// Moving on to the next message.
|
||||||
|
messages_.pop_front();
|
||||||
|
|
||||||
// Reseting the starting position of the widget.
|
// Reseting the starting position of the widget.
|
||||||
offset_ = STARTING_OFFSET;
|
offset_ = STARTING_OFFSET;
|
||||||
|
|
||||||
if (!messages_.isEmpty())
|
if (!messages_.empty())
|
||||||
start();
|
start();
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
SnackBar::stopTimers()
|
SnackBar::stopTimers()
|
||||||
{
|
{
|
||||||
showTimer_->stop();
|
showTimer_.stop();
|
||||||
hideTimer_->stop();
|
hideTimer_.stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@ -99,10 +103,10 @@ SnackBar::paintEvent(QPaintEvent *event)
|
|||||||
{
|
{
|
||||||
Q_UNUSED(event)
|
Q_UNUSED(event)
|
||||||
|
|
||||||
if (messages_.isEmpty())
|
if (messages_.empty())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
auto message_ = messages_.first();
|
auto message_ = messages_.front();
|
||||||
|
|
||||||
QPainter p(this);
|
QPainter p(this);
|
||||||
p.setRenderHint(QPainter::Antialiasing);
|
p.setRenderHint(QPainter::Antialiasing);
|
||||||
|
Loading…
Reference in New Issue
Block a user