1 | /* $Id: UINativeWizard.h 99946 2023-05-24 06:53:04Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VBox Qt GUI - UINativeWizard 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_wizards_UINativeWizard_h
|
---|
29 | #define FEQT_INCLUDED_SRC_wizards_UINativeWizard_h
|
---|
30 | #ifndef RT_WITHOUT_PRAGMA_ONCE
|
---|
31 | # pragma once
|
---|
32 | #endif
|
---|
33 |
|
---|
34 | /* Qt includes: */
|
---|
35 | #include <QMap>
|
---|
36 | #include <QPointer>
|
---|
37 |
|
---|
38 | /* GUI includes: */
|
---|
39 | #include "QIWithRetranslateUI.h"
|
---|
40 | #include "UIExtraDataDefs.h"
|
---|
41 | #include "UILibraryDefs.h"
|
---|
42 |
|
---|
43 | /* Forward declarations: */
|
---|
44 | class QLabel;
|
---|
45 | class QPushButton;
|
---|
46 | class QStackedWidget;
|
---|
47 | class QVBoxLayout;
|
---|
48 | class UINativeWizardPage;
|
---|
49 | class UINotificationCenter;
|
---|
50 | class UINotificationProgress;
|
---|
51 |
|
---|
52 | /** Native wizard buttons. */
|
---|
53 | enum WizardButtonType
|
---|
54 | {
|
---|
55 | WizardButtonType_Invalid,
|
---|
56 | WizardButtonType_Help,
|
---|
57 | WizardButtonType_Expert,
|
---|
58 | WizardButtonType_Back,
|
---|
59 | WizardButtonType_Next,
|
---|
60 | WizardButtonType_Cancel,
|
---|
61 | WizardButtonType_Max,
|
---|
62 | };
|
---|
63 | Q_DECLARE_METATYPE(WizardButtonType);
|
---|
64 |
|
---|
65 | #ifdef VBOX_WS_MAC
|
---|
66 | /** QWidget-based QFrame analog with one particular purpose to
|
---|
67 | * simulate macOS wizard frame without influencing palette hierarchy. */
|
---|
68 | class SHARED_LIBRARY_STUFF UIFrame : public QWidget
|
---|
69 | {
|
---|
70 | Q_OBJECT;
|
---|
71 |
|
---|
72 | public:
|
---|
73 |
|
---|
74 | /** Constructs UIFrame passing @a pParent to the base-class. */
|
---|
75 | UIFrame(QWidget *pParent);
|
---|
76 |
|
---|
77 | protected:
|
---|
78 |
|
---|
79 | /** Handles paint @a pEvent. */
|
---|
80 | virtual void paintEvent(QPaintEvent *pEvent) /* final */;
|
---|
81 | };
|
---|
82 | #endif /* VBOX_WS_MAC */
|
---|
83 |
|
---|
84 | /** QDialog extension with advanced functionality emulating QWizard behavior. */
|
---|
85 | class SHARED_LIBRARY_STUFF UINativeWizard : public QIWithRetranslateUI2<QDialog>
|
---|
86 | {
|
---|
87 | Q_OBJECT;
|
---|
88 |
|
---|
89 | signals:
|
---|
90 |
|
---|
91 | /** Notifies listeners about dialog should be closed. */
|
---|
92 | void sigClose(WizardType enmType);
|
---|
93 |
|
---|
94 | public:
|
---|
95 |
|
---|
96 | /** Constructs wizard passing @a pParent to the base-class.
|
---|
97 | * @param enmType Brings the wizard type.
|
---|
98 | * @param enmMode Brings the wizard mode.
|
---|
99 | * @param strHelpKeyword Brings the wizard help keyword. */
|
---|
100 | UINativeWizard(QWidget *pParent,
|
---|
101 | WizardType enmType,
|
---|
102 | WizardMode enmMode = WizardMode_Auto,
|
---|
103 | const QString &strHelpKeyword = QString());
|
---|
104 | /** Destructs wizard. */
|
---|
105 | virtual ~UINativeWizard() RT_OVERRIDE;
|
---|
106 |
|
---|
107 | /** Returns local notification-center reference. */
|
---|
108 | UINotificationCenter *notificationCenter() const;
|
---|
109 | /** Immediately handles notification @a pProgress object. */
|
---|
110 | bool handleNotificationProgressNow(UINotificationProgress *pProgress);
|
---|
111 |
|
---|
112 | /** Returns wizard button of specified @a enmType. */
|
---|
113 | QPushButton *wizardButton(const WizardButtonType &enmType) const;
|
---|
114 |
|
---|
115 | public slots:
|
---|
116 |
|
---|
117 | /** Executes wizard in window modal mode.
|
---|
118 | * @note You shouldn't have to override it! */
|
---|
119 | virtual int exec() /* final */;
|
---|
120 | /** Shows wizard in non-mode.
|
---|
121 | * @note You shouldn't have to override it! */
|
---|
122 | virtual void show() /* final */;
|
---|
123 |
|
---|
124 | protected:
|
---|
125 |
|
---|
126 | /** Returns wizard type. */
|
---|
127 | WizardType type() const { return m_enmType; }
|
---|
128 | /** Returns wizard mode. */
|
---|
129 | WizardMode mode() const { return m_enmMode; }
|
---|
130 | /** Defines @a strName for wizard button of specified @a enmType. */
|
---|
131 | void setWizardButtonName(const WizardButtonType &enmType, const QString &strName);
|
---|
132 |
|
---|
133 | /** Defines pixmap @a strName. */
|
---|
134 | void setPixmapName(const QString &strName);
|
---|
135 |
|
---|
136 | /** Returns whether the page with certain @a iIndex is visible. */
|
---|
137 | bool isPageVisible(int iIndex) const;
|
---|
138 | /** Defines whether the page with certain @a iIndex is @a fVisible. */
|
---|
139 | void setPageVisible(int iIndex, bool fVisible);
|
---|
140 |
|
---|
141 | /** Appends wizard @a pPage.
|
---|
142 | * @returns assigned page index. */
|
---|
143 | int addPage(UINativeWizardPage *pPage);
|
---|
144 | /** Populates pages.
|
---|
145 | * @note In your subclasses you should add
|
---|
146 | * pages via addPage declared above. */
|
---|
147 | virtual void populatePages() = 0;
|
---|
148 |
|
---|
149 | /** Handles translation event. */
|
---|
150 | virtual void retranslateUi() RT_OVERRIDE;
|
---|
151 |
|
---|
152 | /** Handles key-press @a pEvent. */
|
---|
153 | virtual void keyPressEvent(QKeyEvent *pEvent) RT_OVERRIDE;
|
---|
154 | /** Handles close @a pEvent. */
|
---|
155 | virtual void closeEvent(QCloseEvent *pEvent) RT_OVERRIDE;
|
---|
156 |
|
---|
157 | /** Performs wizard-specific cleanup in case of wizard-mode change
|
---|
158 | * such as folder deletion in New VM wizard etc. */
|
---|
159 | virtual void cleanWizard() {}
|
---|
160 |
|
---|
161 | private slots:
|
---|
162 |
|
---|
163 | /** Handles current-page change to page with @a iIndex. */
|
---|
164 | void sltCurrentIndexChanged(int iIndex = -1);
|
---|
165 | /** Handles page validity changes. */
|
---|
166 | void sltCompleteChanged();
|
---|
167 |
|
---|
168 | /** Toggles between basic and expert modes. */
|
---|
169 | void sltExpert();
|
---|
170 | /** Switches to previous page. */
|
---|
171 | void sltPrevious();
|
---|
172 | /** Switches to next page. */
|
---|
173 | void sltNext();
|
---|
174 |
|
---|
175 | /** Handle help request*/
|
---|
176 | void sltHandleHelpRequest();
|
---|
177 |
|
---|
178 | private:
|
---|
179 |
|
---|
180 | /** Prepares all. */
|
---|
181 | void prepare();
|
---|
182 | /** Cleanups all. */
|
---|
183 | void cleanup();
|
---|
184 | /** Inits all. */
|
---|
185 | void init();
|
---|
186 | /** Deinits all. */
|
---|
187 | void deinit();
|
---|
188 |
|
---|
189 | /** Performs pages translation. */
|
---|
190 | void retranslatePages();
|
---|
191 |
|
---|
192 | /** Resizes wizard to golden ratio. */
|
---|
193 | void resizeToGoldenRatio();
|
---|
194 | #ifdef VBOX_WS_MAC
|
---|
195 | /** Assigns wizard background. */
|
---|
196 | void assignBackground();
|
---|
197 | #else
|
---|
198 | /** Assigns wizard watermark. */
|
---|
199 | void assignWatermark();
|
---|
200 | #endif
|
---|
201 | /** Checks if the pages coming after the page with iPageIndex is visible or not. Returns true if
|
---|
202 | * page with iPageIndex is the last visible page of the wizard. Returns false otherwise. */
|
---|
203 | bool isLastVisiblePage(int iPageIndex) const;
|
---|
204 |
|
---|
205 | /** Holds the wizard type. */
|
---|
206 | WizardType m_enmType;
|
---|
207 | /** Holds the wizard mode. */
|
---|
208 | WizardMode m_enmMode;
|
---|
209 | /** Holds the wizard help keyword. */
|
---|
210 | QString m_strHelpKeyword;
|
---|
211 | /** Holds the pixmap name. */
|
---|
212 | QString m_strPixmapName;
|
---|
213 | /** Holds the last entered page index. */
|
---|
214 | int m_iLastIndex;
|
---|
215 | /** Holds the set of invisible pages. */
|
---|
216 | QSet<int> m_invisiblePages;
|
---|
217 | /** Holds whether the dialod had emitted signal to be closed. */
|
---|
218 | bool m_fClosed;
|
---|
219 |
|
---|
220 | /** Holds the pixmap label instance. */
|
---|
221 | QLabel *m_pLabelPixmap;
|
---|
222 | /** Holds the right layout instance. */
|
---|
223 | QVBoxLayout *m_pLayoutRight;
|
---|
224 | /** Holds the title label instance. */
|
---|
225 | QLabel *m_pLabelPageTitle;
|
---|
226 | /** Holds the widget-stack instance. */
|
---|
227 | QStackedWidget *m_pWidgetStack;
|
---|
228 | /** Holds button instance map. */
|
---|
229 | QMap<WizardButtonType, QPushButton*> m_buttons;
|
---|
230 |
|
---|
231 | /** Holds the local notification-center instance. */
|
---|
232 | UINotificationCenter *m_pNotificationCenter;
|
---|
233 | };
|
---|
234 |
|
---|
235 | /** Native wizard interface pointer. */
|
---|
236 | typedef QPointer<UINativeWizard> UINativeWizardPointer;
|
---|
237 |
|
---|
238 | #endif /* !FEQT_INCLUDED_SRC_wizards_UINativeWizard_h */
|
---|