VirtualBox

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

Last change on this file since 104245 was 104245, checked in by vboxsync, 8 weeks ago

FE/Qt. bugref:10622. Using new UITranslationEventListener in the extenion pack manager and notification center classes.

  • 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 104245 2024-04-09 08:03:20Z 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 "UILibraryDefs.h"
42#include "UINotificationObjects.h"
43
44/* Forward declarations: */
45class QHBoxLayout;
46class QPainter;
47class QStateMachine;
48class QTimer;
49class QVBoxLayout;
50class QIToolButton;
51class UINotificationModel;
52class UINotificationObject;
53class UINotificationObjectItem;
54
55/** QWidget-based notification-center overlay. */
56class SHARED_LIBRARY_STUFF UINotificationCenter : public QWidget
57{
58 Q_OBJECT;
59 Q_PROPERTY(int animatedValue READ animatedValue WRITE setAnimatedValue);
60
61signals:
62
63 /** Requests sliding state-machine to open overlay. */
64 void sigOpen();
65 /** Requests sliding state-machine to close overlay. */
66 void sigClose();
67
68 /** Notifies listener about all operations aborted. */
69 void sigOperationsAborted();
70
71public:
72
73 /** Creates notification-center for passed @a pParent. */
74 static void create(QWidget *pParent = 0);
75 /** Destroys notification-center. */
76 static void destroy();
77 /** Returns notification-center singleton instance. */
78 static UINotificationCenter *instance();
79
80 /** Constructs notification-center passing @a pParent to the base-class. */
81 UINotificationCenter(QWidget *pParent);
82 /** Destructs notification-center. */
83 virtual ~UINotificationCenter() RT_OVERRIDE RT_FINAL;
84
85 /** Defines notification-center @a pParent. */
86 void setParent(QWidget *pParent);
87
88 /** Invokes notification-center. */
89 void invoke();
90
91 /** Appends a notification @a pObject to intenal model. */
92 QUuid append(UINotificationObject *pObject);
93 /** Revokes a notification object referenced by @a uId from intenal model. */
94 void revoke(const QUuid &uId);
95
96 /** Immediately and synchronously handles passed notification @a pProgress.
97 * @note It's a blocking call finished by sltHandleProgressFinished(). */
98 bool handleNow(UINotificationProgress *pProgress);
99 /** Returns whether center has blocking operation. */
100 bool hasOperationsPending() const;
101 /** Aborts blocking operations being performed. */
102 void abortOperations();
103
104protected:
105
106 /** Preprocesses any Qt @a pEvent for passed @a pObject. */
107 virtual bool eventFilter(QObject *pObject, QEvent *pEvent) RT_OVERRIDE RT_FINAL;
108
109 /** Handles any Qt @a pEvent. */
110 virtual bool event(QEvent *pEvent) RT_OVERRIDE RT_FINAL;
111
112 /** Handles paint @a pEvent. */
113 virtual void paintEvent(QPaintEvent *pEvent) RT_OVERRIDE RT_FINAL;
114
115private slots:
116
117 /** Handles alignment changes. */
118 void sltHandleAlignmentChange();
119
120 /** Issues order changes. */
121 void sltIssueOrderChange();
122 /** Handles order changes. */
123 void sltHandleOrderChange();
124
125 /** Issues request to make open button @a fToggled. */
126 void sltHandleOpenButtonToggled(bool fToggled);
127#ifdef VBOX_NOTIFICATION_CENTER_WITH_KEEP_BUTTON
128 /** Toggles notification-progresses keep approach. */
129 void sltHandleKeepButtonToggled(bool fToggled);
130#endif
131 /** Removes finished notifications. */
132 void sltHandleRemoveFinishedButtonClicked();
133
134 /** Invokes open button context menu at specified @a position. */
135 void sltHandleOpenButtonContextMenuRequested(const QPoint &position);
136
137 /** Handles open-timer timeout. */
138 void sltHandleOpenTimerTimeout();
139
140 /** Handles signal about model item with specified @a uId was added. */
141 void sltHandleModelItemAdded(const QUuid &uId);
142 /** Handles signal about model item with specified @a uId was removed. */
143 void sltHandleModelItemRemoved(const QUuid &uId);
144
145 /** Handles immediate progress being finished.
146 * @note Breaks blocking handleNow() call. */
147 void sltHandleProgressFinished();
148
149 /** Handles translation event. */
150 void sltRetranslateUI();
151
152private:
153
154 /** Prepares everything. */
155 void prepare();
156 /** Prepares model. */
157 void prepareModel();
158 /** Prepares widgets. */
159 void prepareWidgets();
160 /** Prepares sliding state-machine. */
161 void prepareStateMachineSliding();
162 /** Prepares open-timer. */
163 void prepareOpenTimer();
164 /** Cleanups model. */
165 void cleanupModel();
166 /** Cleanups items. */
167 void cleanupItems();
168 /** Cleanups everything. */
169 void cleanup();
170
171 /** Paints background using pre-configured @a pPainter. */
172 void paintBackground(QPainter *pPainter);
173 /** Paints frame using pre-configured @a pPainter. */
174 void paintFrame(QPainter *pPainter);
175
176 /** Defines animated @a iValue. */
177 void setAnimatedValue(int iValue);
178 /** Returns animated value. */
179 int animatedValue() const;
180
181 /** Adjusts geometry. */
182 void adjustGeometry();
183 /** Adjusts mask. */
184 void adjustMask();
185
186 /** Holds the notification-center singleton instance. */
187 static UINotificationCenter *s_pInstance;
188
189 /** Holds the model instance. */
190 UINotificationModel *m_pModel;
191
192 /** Holds the alignment. */
193 Qt::Alignment m_enmAlignment;
194 /** Holds the order. */
195 Qt::SortOrder m_enmOrder;
196
197 /** Holds the main layout instance. */
198 QVBoxLayout *m_pLayoutMain;
199 /** Holds the buttons layout instance. */
200 QHBoxLayout *m_pLayoutButtons;
201 /** Holds the open button instance. */
202 QIToolButton *m_pButtonOpen;
203 /** Holds the toggle-sorting button instance. */
204 QIToolButton *m_pButtonToggleSorting;
205#ifdef VBOX_NOTIFICATION_CENTER_WITH_KEEP_BUTTON
206 /** Holds the keep-finished button instance. */
207 QIToolButton *m_pButtonKeepFinished;
208#endif
209 /** Holds the remove-finished button instance. */
210 QIToolButton *m_pButtonRemoveFinished;
211 /** Holds the items layout instance. */
212 QVBoxLayout *m_pLayoutItems;
213
214 /** Holds the map of item instances. */
215 QMap<QUuid, UINotificationObjectItem*> m_items;
216
217 /** Holds the sliding state-machine instance. */
218 QStateMachine *m_pStateMachineSliding;
219 /** Holds the sliding animation current value. */
220 int m_iAnimatedValue;
221
222 /** Holds the open-timer instance. */
223 QTimer *m_pTimerOpen;
224 /** Holds the open-object ID. */
225 QUuid m_uOpenObjectId;
226
227 /** Holds the separate event-loop instance.
228 * @note This event-loop is only used when the center
229 * handles progress directly via handleNow(). */
230 QPointer<QEventLoop> m_pEventLoop;
231 /** Holds the last handleNow() result. */
232 bool m_fLastResult;
233};
234
235/** Singleton notification-center 'official' name. */
236#define gpNotificationCenter UINotificationCenter::instance()
237
238/** QObject subclass receiving notification value and storing is as a property. */
239class SHARED_LIBRARY_STUFF UINotificationReceiver : public QObject
240{
241 Q_OBJECT;
242
243public slots:
244
245 /** Defines received property by @a value. */
246 void setReceiverProperty(const QVariant &value);
247};
248
249#endif /* !FEQT_INCLUDED_SRC_notificationcenter_UINotificationCenter_h */
Note: See TracBrowser for help on using the repository browser.

© 2023 Oracle
ContactPrivacy policyTerms of Use