VirtualBox

source: vbox/trunk/src/VBox/Frontends/VirtualBox/src/notificationcenter/UINotificationCenter.h

Last change on this file was 104252, checked in by vboxsync, 6 weeks ago

FE/Qt. bugref:10622. Build fix.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 7.8 KB
Line 
1/* $Id: UINotificationCenter.h 104252 2024-04-09 12:38:11Z 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 <QMap>
38#include <QUuid>
39#include <QWidget>
40
41/* GUI includes: */
42#include "UILibraryDefs.h"
43#include "UINotificationObjects.h"
44
45/* Forward declarations: */
46class QHBoxLayout;
47class QPainter;
48class QStateMachine;
49class QTimer;
50class QVBoxLayout;
51class QIToolButton;
52class UINotificationModel;
53class UINotificationObject;
54class UINotificationObjectItem;
55
56/** QWidget-based notification-center overlay. */
57class SHARED_LIBRARY_STUFF UINotificationCenter : public QWidget
58{
59 Q_OBJECT;
60 Q_PROPERTY(int animatedValue READ animatedValue WRITE setAnimatedValue);
61
62signals:
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
72public:
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() RT_OVERRIDE RT_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
105protected:
106
107 /** Preprocesses any Qt @a pEvent for passed @a pObject. */
108 virtual bool eventFilter(QObject *pObject, QEvent *pEvent) RT_OVERRIDE RT_FINAL;
109
110 /** Handles any Qt @a pEvent. */
111 virtual bool event(QEvent *pEvent) RT_OVERRIDE RT_FINAL;
112
113 /** Handles paint @a pEvent. */
114 virtual void paintEvent(QPaintEvent *pEvent) RT_OVERRIDE RT_FINAL;
115
116private slots:
117
118 /** Handles alignment changes. */
119 void sltHandleAlignmentChange();
120
121 /** Issues order changes. */
122 void sltIssueOrderChange();
123 /** Handles order changes. */
124 void sltHandleOrderChange();
125
126 /** Issues request to make open button @a fToggled. */
127 void sltHandleOpenButtonToggled(bool fToggled);
128#ifdef VBOX_NOTIFICATION_CENTER_WITH_KEEP_BUTTON
129 /** Toggles notification-progresses keep approach. */
130 void sltHandleKeepButtonToggled(bool fToggled);
131#endif
132 /** Removes finished notifications. */
133 void sltHandleRemoveFinishedButtonClicked();
134
135 /** Invokes open button context menu at specified @a position. */
136 void sltHandleOpenButtonContextMenuRequested(const QPoint &position);
137
138 /** Handles open-timer timeout. */
139 void sltHandleOpenTimerTimeout();
140
141 /** Handles signal about model item with specified @a uId was added. */
142 void sltHandleModelItemAdded(const QUuid &uId);
143 /** Handles signal about model item with specified @a uId was removed. */
144 void sltHandleModelItemRemoved(const QUuid &uId);
145
146 /** Handles immediate progress being finished.
147 * @note Breaks blocking handleNow() call. */
148 void sltHandleProgressFinished();
149
150 /** Handles translation event. */
151 void sltRetranslateUI();
152
153private:
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. */
240class SHARED_LIBRARY_STUFF UINotificationReceiver : public QObject
241{
242 Q_OBJECT;
243
244public 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 */
Note: See TracBrowser for help on using the repository browser.

© 2023 Oracle
ContactPrivacy policyTerms of Use