1 | /* $Id: QIManagerDialog.h 103704 2024-03-06 15:15:36Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VBox Qt GUI - Qt extensions: QIManagerDialog class declaration.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2009-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_extensions_QIManagerDialog_h
|
---|
29 | #define FEQT_INCLUDED_SRC_extensions_QIManagerDialog_h
|
---|
30 | #ifndef RT_WITHOUT_PRAGMA_ONCE
|
---|
31 | # pragma once
|
---|
32 | #endif
|
---|
33 |
|
---|
34 | /* Qt includes: */
|
---|
35 | #include <QMainWindow>
|
---|
36 | #include <QMap>
|
---|
37 |
|
---|
38 | /* GUI includes: */
|
---|
39 | #include "QIWithRestorableGeometry.h"
|
---|
40 | #include "UILibraryDefs.h"
|
---|
41 |
|
---|
42 | /* Forward declarations: */
|
---|
43 | class QPushButton;
|
---|
44 | class QIDialogButtonBox;
|
---|
45 | class QIManagerDialog;
|
---|
46 | #ifdef VBOX_WS_MAC
|
---|
47 | class QIToolBar;
|
---|
48 | #endif
|
---|
49 |
|
---|
50 |
|
---|
51 | /** Widget embedding type. */
|
---|
52 | enum EmbedTo
|
---|
53 | {
|
---|
54 | EmbedTo_Dialog,
|
---|
55 | EmbedTo_Stack
|
---|
56 | };
|
---|
57 |
|
---|
58 |
|
---|
59 | /** Dialog button types. */
|
---|
60 | enum ButtonType
|
---|
61 | {
|
---|
62 | ButtonType_Invalid = 0,
|
---|
63 | ButtonType_Reset = RT_BIT(0),
|
---|
64 | ButtonType_Apply = RT_BIT(1),
|
---|
65 | ButtonType_Embed = RT_BIT(2),
|
---|
66 | ButtonType_Close = RT_BIT(3),
|
---|
67 | ButtonType_Help = RT_BIT(4),
|
---|
68 | };
|
---|
69 |
|
---|
70 |
|
---|
71 | /** Manager dialog factory insterface. */
|
---|
72 | class SHARED_LIBRARY_STUFF QIManagerDialogFactory
|
---|
73 | {
|
---|
74 |
|
---|
75 | public:
|
---|
76 |
|
---|
77 | /** Constructs Manager dialog factory. */
|
---|
78 | QIManagerDialogFactory() {}
|
---|
79 | /** Destructs Manager dialog factory. */
|
---|
80 | virtual ~QIManagerDialogFactory() {}
|
---|
81 |
|
---|
82 | /** Prepares Manager dialog @a pDialog instance.
|
---|
83 | * @param pCenterWidget Brings the widget reference to center according to. */
|
---|
84 | virtual void prepare(QIManagerDialog *&pDialog, QWidget *pCenterWidget = 0);
|
---|
85 | /** Cleanups Manager dialog @a pDialog instance. */
|
---|
86 | virtual void cleanup(QIManagerDialog *&pDialog);
|
---|
87 |
|
---|
88 | protected:
|
---|
89 |
|
---|
90 | /** Creates derived @a pDialog instance.
|
---|
91 | * @param pCenterWidget Brings the widget reference to center according to. */
|
---|
92 | virtual void create(QIManagerDialog *&pDialog, QWidget *pCenterWidget) = 0;
|
---|
93 | };
|
---|
94 |
|
---|
95 |
|
---|
96 | /** QMainWindow sub-class used as various manager dialogs. */
|
---|
97 | class SHARED_LIBRARY_STUFF QIManagerDialog : public QIWithRestorableGeometry<QMainWindow>
|
---|
98 | {
|
---|
99 | Q_OBJECT;
|
---|
100 |
|
---|
101 | signals:
|
---|
102 |
|
---|
103 | /** Notifies listeners about dialog should be embedded. */
|
---|
104 | void sigEmbed();
|
---|
105 | /** Notifies listeners about dialog should be closed. */
|
---|
106 | void sigClose();
|
---|
107 |
|
---|
108 | protected:
|
---|
109 |
|
---|
110 | /** Constructs Manager dialog.
|
---|
111 | * @param pCenterWidget Brings the widget reference to center according to. */
|
---|
112 | QIManagerDialog(QWidget *pCenterWidget);
|
---|
113 |
|
---|
114 | /** @name Virtual prepare/cleanup cascade.
|
---|
115 | * @{ */
|
---|
116 | /** Configures all.
|
---|
117 | * @note Injected into prepare(), reimplement to configure all there. */
|
---|
118 | virtual void configure() {}
|
---|
119 | /** Configures central-widget.
|
---|
120 | * @note Injected into prepareCentralWidget(), reimplement to configure central-widget there. */
|
---|
121 | virtual void configureCentralWidget() {}
|
---|
122 | /** Configures button-box.
|
---|
123 | * @note Injected into prepareButtonBox(), reimplement to configure button-box there. */
|
---|
124 | virtual void configureButtonBox() {}
|
---|
125 | /** Performs final preparations.
|
---|
126 | * @note Injected into prepare(), reimplement to postprocess all there. */
|
---|
127 | virtual void finalize() {}
|
---|
128 | /** Loads dialog setting from extradata. */
|
---|
129 | virtual void loadSettings() {}
|
---|
130 |
|
---|
131 | /** Saves dialog setting into extradata. */
|
---|
132 | virtual void saveSettings() {}
|
---|
133 | /** @} */
|
---|
134 |
|
---|
135 | /** @name Widget stuff.
|
---|
136 | * @{ */
|
---|
137 | /** Defines the @a pWidget instance. */
|
---|
138 | void setWidget(QWidget *pWidget) { m_pWidget = pWidget; }
|
---|
139 | /** Defines the reference to widget menu, replacing current one. */
|
---|
140 | void setWidgetMenu(QMenu *pWidgetMenu) { m_widgetMenus = QList<QMenu*>() << pWidgetMenu; }
|
---|
141 | /** Defines the list of references to widget menus, replacing current one. */
|
---|
142 | void setWidgetMenus(QList<QMenu*> widgetMenus) { m_widgetMenus = widgetMenus; }
|
---|
143 | #ifdef VBOX_WS_MAC
|
---|
144 | /** Defines the @a pWidgetToolbar instance. */
|
---|
145 | void setWidgetToolbar(QIToolBar *pWidgetToolbar) { m_pWidgetToolbar = pWidgetToolbar; }
|
---|
146 | #endif
|
---|
147 |
|
---|
148 | /** Returns the widget. */
|
---|
149 | virtual QWidget *widget() { return m_pWidget; }
|
---|
150 | /** Returns the button-box instance. */
|
---|
151 | QIDialogButtonBox *buttonBox() { return m_pButtonBox; }
|
---|
152 | /** Returns button of passed @a enmType. */
|
---|
153 | QPushButton *button(ButtonType enmType) { return m_buttons.value(enmType); }
|
---|
154 | /** Returns the widget reference to center manager dialog according. */
|
---|
155 | QWidget *centerWidget() const { return m_pCenterWidget; }
|
---|
156 | /** @} */
|
---|
157 |
|
---|
158 | /** @name Event-handling stuff.
|
---|
159 | * @{ */
|
---|
160 | /** Handles close @a pEvent. */
|
---|
161 | virtual void closeEvent(QCloseEvent *pEvent) RT_OVERRIDE;
|
---|
162 |
|
---|
163 | /** Returns whether the manager had emitted command to be closed. */
|
---|
164 | bool closeEmitted() const { return m_fCloseEmitted; }
|
---|
165 | /** @} */
|
---|
166 |
|
---|
167 | private slots:
|
---|
168 |
|
---|
169 | /** Handles help request. */
|
---|
170 | void sltHandleHelpRequested();
|
---|
171 |
|
---|
172 | private:
|
---|
173 |
|
---|
174 | /** @name Private prepare/cleanup cascade.
|
---|
175 | * @{ */
|
---|
176 | /** Prepares all. */
|
---|
177 | void prepare();
|
---|
178 | /** Prepares central-widget. */
|
---|
179 | void prepareCentralWidget();
|
---|
180 | /** Prepares button-box. */
|
---|
181 | void prepareButtonBox();
|
---|
182 | /** Prepares menu-bar. */
|
---|
183 | void prepareMenuBar();
|
---|
184 | #ifdef VBOX_WS_MAC
|
---|
185 | /** Prepares toolbar. */
|
---|
186 | void prepareToolBar();
|
---|
187 | #endif
|
---|
188 |
|
---|
189 | /** Cleanup menu-bar. */
|
---|
190 | void cleanupMenuBar();
|
---|
191 | /** Cleanups all. */
|
---|
192 | void cleanup();
|
---|
193 | /** @} */
|
---|
194 |
|
---|
195 | /** @name General stuff.
|
---|
196 | * @{ */
|
---|
197 | /** Holds the widget reference to center manager dialog according. */
|
---|
198 | QWidget *m_pCenterWidget;
|
---|
199 |
|
---|
200 | /** Holds whether the manager had emitted command to be closed. */
|
---|
201 | bool m_fCloseEmitted;
|
---|
202 | /** @} */
|
---|
203 |
|
---|
204 | /** @name Widget stuff.
|
---|
205 | * @{ */
|
---|
206 | /** Holds the widget instance. */
|
---|
207 | QWidget *m_pWidget;
|
---|
208 |
|
---|
209 | /** Holds a list of widget menu references. */
|
---|
210 | QList<QMenu*> m_widgetMenus;
|
---|
211 |
|
---|
212 | #ifdef VBOX_WS_MAC
|
---|
213 | /** Holds the widget toolbar instance. */
|
---|
214 | QIToolBar *m_pWidgetToolbar;
|
---|
215 | #endif
|
---|
216 | /** @} */
|
---|
217 |
|
---|
218 | /** @name Button-box stuff.
|
---|
219 | * @{ */
|
---|
220 | /** Holds the dialog button-box instance. */
|
---|
221 | QIDialogButtonBox *m_pButtonBox;
|
---|
222 |
|
---|
223 | /** Holds the button-box button references. */
|
---|
224 | QMap<ButtonType, QPushButton*> m_buttons;
|
---|
225 | /** @} */
|
---|
226 |
|
---|
227 | /** Allow factory access to private/protected members: */
|
---|
228 | friend class QIManagerDialogFactory;
|
---|
229 | };
|
---|
230 |
|
---|
231 |
|
---|
232 | #endif /* !FEQT_INCLUDED_SRC_extensions_QIManagerDialog_h */
|
---|