From ac525970b086443bdb17899ff314aef6a5bdba06 Mon Sep 17 00:00:00 2001 From: Konstantinos Sideris Date: Sun, 8 Oct 2017 16:49:56 +0300 Subject: Add snackbar --- include/ui/SnackBar.h | 80 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 include/ui/SnackBar.h (limited to 'include') diff --git a/include/ui/SnackBar.h b/include/ui/SnackBar.h new file mode 100644 index 00000000..076b7105 --- /dev/null +++ b/include/ui/SnackBar.h @@ -0,0 +1,80 @@ +#pragma once + +#include +#include +#include +#include + +#include "OverlayWidget.h" + +enum class SnackBarPosition { + Bottom, + Top, +}; + +class SnackBar : public OverlayWidget +{ + Q_OBJECT + +public: + explicit SnackBar(QWidget *parent); + ~SnackBar(); + + 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 onTimeout(); + void hideMessage(); + +private: + void stopTimers(); + void start(); + + QColor bgColor_; + QColor textColor_; + + qreal bgOpacity_; + qreal offset_; + + QList messages_; + + QTimer *showTimer_; + QTimer *hideTimer_; + + 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(); +} -- cgit 1.5.1