save work

This commit is contained in:
Martin Rotter 2023-09-15 06:59:05 +02:00
parent 6e0bcdb872
commit 4d7a454019
4 changed files with 36 additions and 3 deletions

View file

@ -7,6 +7,10 @@
#include <QCloseEvent>
#include <QTimer>
#include <chrono>
using namespace std::chrono_literals;
BaseToastNotification::BaseToastNotification(QWidget* parent) : QDialog(parent) {
setAttribute(Qt::WidgetAttribute::WA_ShowWithoutActivating);
setFixedWidth(NOTIFICATIONS_WIDTH);
@ -23,7 +27,6 @@ BaseToastNotification::BaseToastNotification(QWidget* parent) : QDialog(parent)
Qt::WindowType::FramelessWindowHint | Qt::WindowType::WindowStaysOnTopHint | Qt::WindowType::WindowSystemMenuHint);
setStyleSheet(QSL("BaseToastNotification { border: 1px solid black; }"));
installEventFilter(this);
}
@ -36,7 +39,7 @@ void BaseToastNotification::setupCloseButton(QAbstractButton* btn) {
}
void BaseToastNotification::setupTimedClosing() {
QTimer::singleShot(15000, this, &BaseToastNotification::close);
QTimer::singleShot(15s, this, &BaseToastNotification::close);
}
bool BaseToastNotification::eventFilter(QObject* watched, QEvent* event) {

View file

@ -15,8 +15,16 @@ ToastNotification::ToastNotification(Notification::Event event,
: BaseToastNotification(parent) {
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);
setupTimedClosing();
loadNotification(event, msg, action);
}
@ -27,4 +35,25 @@ bool ToastNotification::alwaysOnTop() const {
void ToastNotification::loadNotification(Notification::Event event, const GuiMessage& msg, const GuiAction& action) {
m_ui.m_lblTitle->setText(msg.m_title);
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"));
}
}

View file

@ -22,6 +22,7 @@ class ToastNotification : public BaseToastNotification {
private:
void loadNotification(Notification::Event event, const GuiMessage& msg, const GuiAction& action);
QIcon iconForType(QSystemTrayIcon::MessageIcon icon) const;
private:
Ui::ToastNotification m_ui;

View file

@ -36,7 +36,7 @@
</layout>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_2">
<widget class="QLabel" name="m_lblIcon">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Expanding">
<horstretch>0</horstretch>