From 0e814da91c8e041897a4c3f7e6e9234bbc7c6f7a Mon Sep 17 00:00:00 2001 From: Konstantinos Sideris Date: Tue, 17 Jul 2018 16:37:25 +0300 Subject: Move all files under src/ --- src/ui/SnackBar.h | 79 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 src/ui/SnackBar.h (limited to 'src/ui/SnackBar.h') diff --git a/src/ui/SnackBar.h b/src/ui/SnackBar.h new file mode 100644 index 00000000..eed59c87 --- /dev/null +++ b/src/ui/SnackBar.h @@ -0,0 +1,79 @@ +#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); + + 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_; + + std::deque 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