save work
This commit is contained in:
parent
6e0bcdb872
commit
4d7a454019
4 changed files with 36 additions and 3 deletions
|
@ -7,6 +7,10 @@
|
||||||
#include <QCloseEvent>
|
#include <QCloseEvent>
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
|
|
||||||
|
#include <chrono>
|
||||||
|
|
||||||
|
using namespace std::chrono_literals;
|
||||||
|
|
||||||
BaseToastNotification::BaseToastNotification(QWidget* parent) : QDialog(parent) {
|
BaseToastNotification::BaseToastNotification(QWidget* parent) : QDialog(parent) {
|
||||||
setAttribute(Qt::WidgetAttribute::WA_ShowWithoutActivating);
|
setAttribute(Qt::WidgetAttribute::WA_ShowWithoutActivating);
|
||||||
setFixedWidth(NOTIFICATIONS_WIDTH);
|
setFixedWidth(NOTIFICATIONS_WIDTH);
|
||||||
|
@ -23,7 +27,6 @@ BaseToastNotification::BaseToastNotification(QWidget* parent) : QDialog(parent)
|
||||||
Qt::WindowType::FramelessWindowHint | Qt::WindowType::WindowStaysOnTopHint | Qt::WindowType::WindowSystemMenuHint);
|
Qt::WindowType::FramelessWindowHint | Qt::WindowType::WindowStaysOnTopHint | Qt::WindowType::WindowSystemMenuHint);
|
||||||
|
|
||||||
setStyleSheet(QSL("BaseToastNotification { border: 1px solid black; }"));
|
setStyleSheet(QSL("BaseToastNotification { border: 1px solid black; }"));
|
||||||
|
|
||||||
installEventFilter(this);
|
installEventFilter(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -36,7 +39,7 @@ void BaseToastNotification::setupCloseButton(QAbstractButton* btn) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void BaseToastNotification::setupTimedClosing() {
|
void BaseToastNotification::setupTimedClosing() {
|
||||||
QTimer::singleShot(15000, this, &BaseToastNotification::close);
|
QTimer::singleShot(15s, this, &BaseToastNotification::close);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool BaseToastNotification::eventFilter(QObject* watched, QEvent* event) {
|
bool BaseToastNotification::eventFilter(QObject* watched, QEvent* event) {
|
||||||
|
|
|
@ -15,8 +15,16 @@ ToastNotification::ToastNotification(Notification::Event event,
|
||||||
: BaseToastNotification(parent) {
|
: BaseToastNotification(parent) {
|
||||||
m_ui.setupUi(this);
|
m_ui.setupUi(this);
|
||||||
|
|
||||||
|
auto fon = m_ui.m_lblTitle->font();
|
||||||
|
|
||||||
|
fon.setBold(true);
|
||||||
|
// fon.s
|
||||||
|
|
||||||
|
m_ui.m_lblTitle->setFont(fon);
|
||||||
|
|
||||||
setupCloseButton(m_ui.m_btnClose);
|
setupCloseButton(m_ui.m_btnClose);
|
||||||
setupTimedClosing();
|
setupTimedClosing();
|
||||||
|
|
||||||
loadNotification(event, msg, action);
|
loadNotification(event, msg, action);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -27,4 +35,25 @@ bool ToastNotification::alwaysOnTop() const {
|
||||||
void ToastNotification::loadNotification(Notification::Event event, const GuiMessage& msg, const GuiAction& action) {
|
void ToastNotification::loadNotification(Notification::Event event, const GuiMessage& msg, const GuiAction& action) {
|
||||||
m_ui.m_lblTitle->setText(msg.m_title);
|
m_ui.m_lblTitle->setText(msg.m_title);
|
||||||
m_ui.m_lblBody->setText(msg.m_message);
|
m_ui.m_lblBody->setText(msg.m_message);
|
||||||
|
|
||||||
|
m_ui.m_lblIcon->setPixmap(iconForType(msg.m_type)
|
||||||
|
.pixmap({
|
||||||
|
32,
|
||||||
|
32,
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
QIcon ToastNotification::iconForType(QSystemTrayIcon::MessageIcon icon) const {
|
||||||
|
switch (icon) {
|
||||||
|
case QSystemTrayIcon::Warning:
|
||||||
|
return qApp->icons()->fromTheme(QSL("dialog-warning"));
|
||||||
|
|
||||||
|
case QSystemTrayIcon::Critical:
|
||||||
|
return qApp->icons()->fromTheme(QSL("dialog-error"));
|
||||||
|
|
||||||
|
case QSystemTrayIcon::Information:
|
||||||
|
case QSystemTrayIcon::NoIcon:
|
||||||
|
default:
|
||||||
|
return qApp->icons()->fromTheme(QSL("dialog-information"));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,6 +22,7 @@ class ToastNotification : public BaseToastNotification {
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void loadNotification(Notification::Event event, const GuiMessage& msg, const GuiAction& action);
|
void loadNotification(Notification::Event event, const GuiMessage& msg, const GuiAction& action);
|
||||||
|
QIcon iconForType(QSystemTrayIcon::MessageIcon icon) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Ui::ToastNotification m_ui;
|
Ui::ToastNotification m_ui;
|
||||||
|
|
|
@ -36,7 +36,7 @@
|
||||||
</layout>
|
</layout>
|
||||||
</item>
|
</item>
|
||||||
<item row="1" column="0">
|
<item row="1" column="0">
|
||||||
<widget class="QLabel" name="label_2">
|
<widget class="QLabel" name="m_lblIcon">
|
||||||
<property name="sizePolicy">
|
<property name="sizePolicy">
|
||||||
<sizepolicy hsizetype="Preferred" vsizetype="Expanding">
|
<sizepolicy hsizetype="Preferred" vsizetype="Expanding">
|
||||||
<horstretch>0</horstretch>
|
<horstretch>0</horstretch>
|
||||||
|
|
Loading…
Add table
Reference in a new issue