summary refs log tree commit diff
path: root/include
diff options
context:
space:
mode:
authorKonstantinos Sideris <sideris.konstantin@gmail.com>2017-10-08 16:49:56 +0300
committerKonstantinos Sideris <sideris.konstantin@gmail.com>2017-10-08 22:01:18 +0300
commitac525970b086443bdb17899ff314aef6a5bdba06 (patch)
treeab0e7fdf5ba71dce41cf68aad4320b0fc6499e41 /include
parentDrop the loading screen if consensus can't be achieved (diff)
downloadnheko-ac525970b086443bdb17899ff314aef6a5bdba06.tar.xz
Add snackbar
Diffstat (limited to 'include')
-rw-r--r--include/ui/SnackBar.h80
1 files changed, 80 insertions, 0 deletions
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 <QCoreApplication> +#include <QPaintEvent> +#include <QStateMachine> +#include <QTimer> + +#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<QString> 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(); +}