game_launcher 1.1.0
Modern Linux game launcher with Steam / Proton / Wine integration
Loading...
Searching...
No Matches
qt_notification_service.h
Go to the documentation of this file.
1// SPDX-License-Identifier: MIT
2// ==============================================================================
3// qt/qt_notification_service.h
4// ==============================================================================
5// Qt implementation of INotificationService
6// Shows in-app toast notifications as overlay widgets
7// ==============================================================================
8
9#pragma once
10
12
13#include <QGraphicsOpacityEffect>
14#include <QLabel>
15#include <QObject>
16#include <QPropertyAnimation>
17#include <QPushButton>
18#include <QTimer>
19#include <QVBoxLayout>
20#include <QWidget>
21
22class ThemeManager;
23
24// ==============================================================================
25// ToastWidget - Individual notification toast
26// ==============================================================================
27
28class ToastWidget : public QWidget
29{
30 Q_OBJECT
31
32 public:
33 ToastWidget(const QString& message, core::NotificationType type, float duration,
34 QWidget* parent, ThemeManager* themeManager = nullptr);
35
36 void showAnimated();
37 void dismissAnimated();
38
39 signals:
40 void dismissed();
41
42 private:
43 void applyTypeStyle(core::NotificationType type);
44
45 QLabel* iconLabel_ = nullptr;
46 QLabel* messageLabel_ = nullptr;
47 QPushButton* closeBtn_ = nullptr;
48 QTimer* autoCloseTimer_ = nullptr;
49 QGraphicsOpacityEffect* opacityEffect_ = nullptr;
50 bool closing_ = false;
51 ThemeManager* themeManager_;
52};
53
54// ==============================================================================
55// ToastContainer - Manages stacked toast notifications
56// ==============================================================================
57
58class ToastContainer : public QWidget
59{
60 Q_OBJECT
61
62 public:
63 explicit ToastContainer(QWidget* parent, ThemeManager* themeManager = nullptr);
64 void addToast(const QString& message, core::NotificationType type, float duration);
65 void clearAll();
66
67 protected:
68 bool eventFilter(QObject* obj, QEvent* event) override;
69
70 private:
71 void repositionToasts();
72 void removeToast(ToastWidget* toast);
73
74 QList<ToastWidget*> activeToasts_;
75 static constexpr int kMaxToasts = 5;
76 static constexpr int kToastWidth = 380;
77 static constexpr int kSpacing = 8;
78 static constexpr int kMarginRight = 16;
79 static constexpr int kMarginBottom = 16;
80 ThemeManager* themeManager_;
81};
82
83// ==============================================================================
84// QtNotificationService - INotificationService implementation
85// ==============================================================================
86
88{
89 Q_OBJECT
90
91 public:
92 explicit QtNotificationService(QObject* parent = nullptr, ThemeManager* themeManager = nullptr);
94
95 void setParentWidget(QWidget* widget);
96
97 // INotificationService implementation
98 void info(const std::string& message, float duration = 3.0f) override;
99 void success(const std::string& message, float duration = 3.0f) override;
100 void warning(const std::string& message, float duration = 5.0f) override;
101 void error(const std::string& message, float duration = 5.0f) override;
102 void show(const core::Notification& notification) override;
103 void clearAll() override;
104
105 signals:
106 void notificationReceived(const QString& message, int type, float duration);
107
108 private slots:
109 void processNotification(const QString& message, int type, float duration);
110
111 private:
112 QWidget* parentWidget_ = nullptr;
113 ToastContainer* container_ = nullptr;
114 ThemeManager* themeManager_;
115};
void info(const std::string &message, float duration=3.0f) override
Show an info notification.
void error(const std::string &message, float duration=5.0f) override
Show an error notification.
void clearAll() override
Clear all notifications.
QtNotificationService(QObject *parent=nullptr, ThemeManager *themeManager=nullptr)
void warning(const std::string &message, float duration=5.0f) override
Show a warning notification.
void setParentWidget(QWidget *widget)
~QtNotificationService() override
void success(const std::string &message, float duration=3.0f) override
Show a success notification.
void notificationReceived(const QString &message, int type, float duration)
void show(const core::Notification &notification) override
Show a notification with full control.
void addToast(const QString &message, core::NotificationType type, float duration)
bool eventFilter(QObject *obj, QEvent *event) override
ToastContainer(QWidget *parent, ThemeManager *themeManager=nullptr)
ToastWidget(const QString &message, core::NotificationType type, float duration, QWidget *parent, ThemeManager *themeManager=nullptr)
void dismissed()