2017-10-08 16:49:56 +03:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <QCoreApplication>
|
|
|
|
#include <QPaintEvent>
|
|
|
|
#include <QTimer>
|
2018-05-08 23:38:57 +03:00
|
|
|
#include <deque>
|
2017-10-08 16:49:56 +03:00
|
|
|
|
|
|
|
#include "OverlayWidget.h"
|
|
|
|
|
2017-10-15 22:08:51 +03:00
|
|
|
enum class SnackBarPosition
|
|
|
|
{
|
2017-10-08 16:49:56 +03:00
|
|
|
Bottom,
|
|
|
|
Top,
|
|
|
|
};
|
|
|
|
|
|
|
|
class SnackBar : public OverlayWidget
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
|
|
|
explicit SnackBar(QWidget *parent);
|
|
|
|
|
|
|
|
inline void setBackgroundColor(const QColor &color);
|
|
|
|
inline void setTextColor(const QColor &color);
|
|
|
|
inline void setPosition(SnackBarPosition pos);
|
|
|
|
|
|
|
|
public slots:
|
|
|
|
void showMessage(const QString &msg);
|
|
|
|
|
|
|
|
protected:
|
|
|
|
void paintEvent(QPaintEvent *event) override;
|
|
|
|
void mousePressEvent(QMouseEvent *event) override;
|
|
|
|
|
|
|
|
private slots:
|
|
|
|
void hideMessage();
|
|
|
|
|
|
|
|
private:
|
|
|
|
void stopTimers();
|
|
|
|
void start();
|
|
|
|
|
|
|
|
QColor bgColor_;
|
|
|
|
QColor textColor_;
|
|
|
|
|
|
|
|
qreal bgOpacity_;
|
|
|
|
qreal offset_;
|
|
|
|
|
2018-05-08 23:38:57 +03:00
|
|
|
std::deque<QString> messages_;
|
2017-10-08 16:49:56 +03:00
|
|
|
|
2018-05-08 23:38:57 +03:00
|
|
|
QTimer showTimer_;
|
|
|
|
QTimer hideTimer_;
|
2017-10-08 16:49:56 +03:00
|
|
|
|
|
|
|
int duration_;
|
|
|
|
int boxWidth_;
|
|
|
|
int boxHeight_;
|
|
|
|
int boxPadding_;
|
|
|
|
|
|
|
|
SnackBarPosition position_;
|
|
|
|
};
|
|
|
|
|
|
|
|
inline void
|
|
|
|
SnackBar::setPosition(SnackBarPosition pos)
|
|
|
|
{
|
|
|
|
position_ = pos;
|
|
|
|
update();
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void
|
|
|
|
SnackBar::setBackgroundColor(const QColor &color)
|
|
|
|
{
|
|
|
|
bgColor_ = color;
|
|
|
|
update();
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void
|
|
|
|
SnackBar::setTextColor(const QColor &color)
|
|
|
|
{
|
|
|
|
textColor_ = color;
|
|
|
|
update();
|
|
|
|
}
|