1 | /* $Id: UINotificationCenter.h 101122 2023-09-14 15:59:37Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VBox Qt GUI - UINotificationCenter class declaration.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2021-2023 Oracle and/or its affiliates.
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox base platform packages, as
|
---|
10 | * available from https://www.virtualbox.org.
|
---|
11 | *
|
---|
12 | * This program is free software; you can redistribute it and/or
|
---|
13 | * modify it under the terms of the GNU General Public License
|
---|
14 | * as published by the Free Software Foundation, in version 3 of the
|
---|
15 | * License.
|
---|
16 | *
|
---|
17 | * This program is distributed in the hope that it will be useful, but
|
---|
18 | * WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
20 | * General Public License for more details.
|
---|
21 | *
|
---|
22 | * You should have received a copy of the GNU General Public License
|
---|
23 | * along with this program; if not, see <https://www.gnu.org/licenses>.
|
---|
24 | *
|
---|
25 | * SPDX-License-Identifier: GPL-3.0-only
|
---|
26 | */
|
---|
27 |
|
---|
28 | #ifndef FEQT_INCLUDED_SRC_notificationcenter_UINotificationCenter_h
|
---|
29 | #define FEQT_INCLUDED_SRC_notificationcenter_UINotificationCenter_h
|
---|
30 | #ifndef RT_WITHOUT_PRAGMA_ONCE
|
---|
31 | # pragma once
|
---|
32 | #endif
|
---|
33 |
|
---|
34 | /* Qt includes: */
|
---|
35 | #include <QEventLoop>
|
---|
36 | #include <QPointer>
|
---|
37 | #include <QUuid>
|
---|
38 | #include <QWidget>
|
---|
39 |
|
---|
40 | /* GUI includes: */
|
---|
41 | #include "QIWithRetranslateUI.h"
|
---|
42 | #include "UILibraryDefs.h"
|
---|
43 | #include "UINotificationObjects.h"
|
---|
44 |
|
---|
45 | /* Forward declarations: */
|
---|
46 | class QHBoxLayout;
|
---|
47 | class QPainter;
|
---|
48 | class QStateMachine;
|
---|
49 | class QTimer;
|
---|
50 | class QVBoxLayout;
|
---|
51 | class QIToolButton;
|
---|
52 | class UINotificationModel;
|
---|
53 | class UINotificationObject;
|
---|
54 | class UINotificationObjectItem;
|
---|
55 |
|
---|
56 | /** QWidget-based notification-center overlay. */
|
---|
57 | class SHARED_LIBRARY_STUFF UINotificationCenter : public QIWithRetranslateUI<QWidget>
|
---|
58 | {
|
---|
59 | Q_OBJECT;
|
---|
60 | Q_PROPERTY(int animatedValue READ animatedValue WRITE setAnimatedValue);
|
---|
61 |
|
---|
62 | signals:
|
---|
63 |
|
---|
64 | /** Requests sliding state-machine to open overlay. */
|
---|
65 | void sigOpen();
|
---|
66 | /** Requests sliding state-machine to close overlay. */
|
---|
67 | void sigClose();
|
---|
68 |
|
---|
69 | /** Notifies listener about all operations aborted. */
|
---|
70 | void sigOperationsAborted();
|
---|
71 |
|
---|
72 | public:
|
---|
73 |
|
---|
74 | /** Creates notification-center for passed @a pParent. */
|
---|
75 | static void create(QWidget *pParent = 0);
|
---|
76 | /** Destroys notification-center. */
|
---|
77 | static void destroy();
|
---|
78 | /** Returns notification-center singleton instance. */
|
---|
79 | static UINotificationCenter *instance();
|
---|
80 |
|
---|
81 | /** Constructs notification-center passing @a pParent to the base-class. */
|
---|
82 | UINotificationCenter(QWidget *pParent);
|
---|
83 | /** Destructs notification-center. */
|
---|
84 | virtual ~UINotificationCenter() /* override final */;
|
---|
85 |
|
---|
86 | /** Defines notification-center @a pParent. */
|
---|
87 | void setParent(QWidget *pParent);
|
---|
88 |
|
---|
89 | /** Invokes notification-center. */
|
---|
90 | void invoke();
|
---|
91 |
|
---|
92 | /** Appends a notification @a pObject to intenal model. */
|
---|
93 | QUuid append(UINotificationObject *pObject);
|
---|
94 | /** Revokes a notification object referenced by @a uId from intenal model. */
|
---|
95 | void revoke(const QUuid &uId);
|
---|
96 |
|
---|
97 | /** Immediately and synchronously handles passed notification @a pProgress.
|
---|
98 | * @note It's a blocking call finished by sltHandleProgressFinished(). */
|
---|
99 | bool handleNow(UINotificationProgress *pProgress);
|
---|
100 | /** Returns whether center has blocking operation. */
|
---|
101 | bool hasOperationsPending() const;
|
---|
102 | /** Aborts blocking operations being performed. */
|
---|
103 | void abortOperations();
|
---|
104 |
|
---|
105 | protected:
|
---|
106 |
|
---|
107 | /** Handles translation event. */
|
---|
108 | virtual void retranslateUi() /* override final */;
|
---|
109 |
|
---|
110 | /** Preprocesses any Qt @a pEvent for passed @a pObject. */
|
---|
111 | virtual bool eventFilter(QObject *pObject, QEvent *pEvent) /* override final */;
|
---|
112 |
|
---|
113 | /** Handles any Qt @a pEvent. */
|
---|
114 | virtual bool event(QEvent *pEvent) /* override final */;
|
---|
115 |
|
---|
116 | /** Handles paint @a pEvent. */
|
---|
117 | virtual void paintEvent(QPaintEvent *pEvent) /* override final */;
|
---|
118 |
|
---|
119 | private slots:
|
---|
120 |
|
---|
121 | /** Handles alignment changes. */
|
---|
122 | void sltHandleAlignmentChange();
|
---|
123 |
|
---|
124 | /** Issues order changes. */
|
---|
125 | void sltIssueOrderChange();
|
---|
126 | /** Handles order changes. */
|
---|
127 | void sltHandleOrderChange();
|
---|
128 |
|
---|
129 | /** Issues request to make open button @a fToggled. */
|
---|
130 | void sltHandleOpenButtonToggled(bool fToggled);
|
---|
131 | #ifdef VBOX_NOTIFICATION_CENTER_WITH_KEEP_BUTTON
|
---|
132 | /** Toggles notification-progresses keep approach. */
|
---|
133 | void sltHandleKeepButtonToggled(bool fToggled);
|
---|
134 | #endif
|
---|
135 | /** Removes finished notifications. */
|
---|
136 | void sltHandleRemoveFinishedButtonClicked();
|
---|
137 |
|
---|
138 | /** Invokes open button context menu at specified @a position. */
|
---|
139 | void sltHandleOpenButtonContextMenuRequested(const QPoint &position);
|
---|
140 |
|
---|
141 | /** Handles open-timer timeout. */
|
---|
142 | void sltHandleOpenTimerTimeout();
|
---|
143 |
|
---|
144 | /** Handles signal about model item with specified @a uId was added. */
|
---|
145 | void sltHandleModelItemAdded(const QUuid &uId);
|
---|
146 | /** Handles signal about model item with specified @a uId was removed. */
|
---|
147 | void sltHandleModelItemRemoved(const QUuid &uId);
|
---|
148 |
|
---|
149 | /** Handles immediate progress being finished.
|
---|
150 | * @note Breaks blocking handleNow() call. */
|
---|
151 | void sltHandleProgressFinished();
|
---|
152 |
|
---|
153 | private:
|
---|
154 |
|
---|
155 | /** Prepares everything. */
|
---|
156 | void prepare();
|
---|
157 | /** Prepares model. */
|
---|
158 | void prepareModel();
|
---|
159 | /** Prepares widgets. */
|
---|
160 | void prepareWidgets();
|
---|
161 | /** Prepares sliding state-machine. */
|
---|
162 | void prepareStateMachineSliding();
|
---|
163 | /** Prepares open-timer. */
|
---|
164 | void prepareOpenTimer();
|
---|
165 | /** Cleanups model. */
|
---|
166 | void cleanupModel();
|
---|
167 | /** Cleanups items. */
|
---|
168 | void cleanupItems();
|
---|
169 | /** Cleanups everything. */
|
---|
170 | void cleanup();
|
---|
171 |
|
---|
172 | /** Paints background using pre-configured @a pPainter. */
|
---|
173 | void paintBackground(QPainter *pPainter);
|
---|
174 | /** Paints frame using pre-configured @a pPainter. */
|
---|
175 | void paintFrame(QPainter *pPainter);
|
---|
176 |
|
---|
177 | /** Defines animated @a iValue. */
|
---|
178 | void setAnimatedValue(int iValue);
|
---|
179 | /** Returns animated value. */
|
---|
180 | int animatedValue() const;
|
---|
181 |
|
---|
182 | /** Adjusts geometry. */
|
---|
183 | void adjustGeometry();
|
---|
184 | /** Adjusts mask. */
|
---|
185 | void adjustMask();
|
---|
186 |
|
---|
187 | /** Holds the notification-center singleton instance. */
|
---|
188 | static UINotificationCenter *s_pInstance;
|
---|
189 |
|
---|
190 | /** Holds the model instance. */
|
---|
191 | UINotificationModel *m_pModel;
|
---|
192 |
|
---|
193 | /** Holds the alignment. */
|
---|
194 | Qt::Alignment m_enmAlignment;
|
---|
195 | /** Holds the order. */
|
---|
196 | Qt::SortOrder m_enmOrder;
|
---|
197 |
|
---|
198 | /** Holds the main layout instance. */
|
---|
199 | QVBoxLayout *m_pLayoutMain;
|
---|
200 | /** Holds the buttons layout instance. */
|
---|
201 | QHBoxLayout *m_pLayoutButtons;
|
---|
202 | /** Holds the open button instance. */
|
---|
203 | QIToolButton *m_pButtonOpen;
|
---|
204 | /** Holds the toggle-sorting button instance. */
|
---|
205 | QIToolButton *m_pButtonToggleSorting;
|
---|
206 | #ifdef VBOX_NOTIFICATION_CENTER_WITH_KEEP_BUTTON
|
---|
207 | /** Holds the keep-finished button instance. */
|
---|
208 | QIToolButton *m_pButtonKeepFinished;
|
---|
209 | #endif
|
---|
210 | /** Holds the remove-finished button instance. */
|
---|
211 | QIToolButton *m_pButtonRemoveFinished;
|
---|
212 | /** Holds the items layout instance. */
|
---|
213 | QVBoxLayout *m_pLayoutItems;
|
---|
214 |
|
---|
215 | /** Holds the map of item instances. */
|
---|
216 | QMap<QUuid, UINotificationObjectItem*> m_items;
|
---|
217 |
|
---|
218 | /** Holds the sliding state-machine instance. */
|
---|
219 | QStateMachine *m_pStateMachineSliding;
|
---|
220 | /** Holds the sliding animation current value. */
|
---|
221 | int m_iAnimatedValue;
|
---|
222 |
|
---|
223 | /** Holds the open-timer instance. */
|
---|
224 | QTimer *m_pTimerOpen;
|
---|
225 | /** Holds the open-object ID. */
|
---|
226 | QUuid m_uOpenObjectId;
|
---|
227 |
|
---|
228 | /** Holds the separate event-loop instance.
|
---|
229 | * @note This event-loop is only used when the center
|
---|
230 | * handles progress directly via handleNow(). */
|
---|
231 | QPointer<QEventLoop> m_pEventLoop;
|
---|
232 | /** Holds the last handleNow() result. */
|
---|
233 | bool m_fLastResult;
|
---|
234 | };
|
---|
235 |
|
---|
236 | /** Singleton notification-center 'official' name. */
|
---|
237 | #define gpNotificationCenter UINotificationCenter::instance()
|
---|
238 |
|
---|
239 | /** QObject subclass receiving notification value and storing is as a property. */
|
---|
240 | class SHARED_LIBRARY_STUFF UINotificationReceiver : public QObject
|
---|
241 | {
|
---|
242 | Q_OBJECT;
|
---|
243 |
|
---|
244 | public slots:
|
---|
245 |
|
---|
246 | /** Defines received property by @a value. */
|
---|
247 | void setReceiverProperty(const QVariant &value);
|
---|
248 | };
|
---|
249 |
|
---|
250 | #endif /* !FEQT_INCLUDED_SRC_notificationcenter_UINotificationCenter_h */
|
---|