VirtualBox

source: vbox/trunk/src/VBox/Frontends/VirtualBox/src/wizards/UINativeWizard.h

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

FE/Qt: bugref:10665, bugref:10744: UINativeWizard: Make sure wizard is cleanup up if aborted (by Escape key, Cancel button or by closing the window).

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 7.2 KB
Line 
1/* $Id: UINativeWizard.h 105586 2024-08-05 14:28:46Z vboxsync $ */
2/** @file
3 * VBox Qt GUI - UINativeWizard class declaration.
4 */
5
6/*
7 * Copyright (C) 2009-2024 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 <QDialog>
36#include <QMap>
37#include <QPointer>
38#include <QSet>
39
40/* GUI includes: */
41#include "UIExtraDataDefs.h"
42#include "UILibraryDefs.h"
43
44/* Forward declarations: */
45class QLabel;
46class QPushButton;
47class QStackedWidget;
48class QVBoxLayout;
49class UINativeWizardPage;
50class UINotificationCenter;
51class UINotificationProgress;
52
53/** Native wizard buttons. */
54enum WizardButtonType
55{
56 WizardButtonType_Invalid,
57 WizardButtonType_Help,
58 WizardButtonType_Back,
59 WizardButtonType_Next,
60 WizardButtonType_Cancel,
61 WizardButtonType_Max,
62};
63Q_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. */
68class SHARED_LIBRARY_STUFF UIFrame : public QWidget
69{
70 Q_OBJECT;
71
72public:
73
74 /** Constructs UIFrame passing @a pParent to the base-class. */
75 UIFrame(QWidget *pParent);
76
77protected:
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. */
85class SHARED_LIBRARY_STUFF UINativeWizard : public QDialog
86{
87 Q_OBJECT;
88
89signals:
90
91 /** Notifies listeners about dialog should be closed. */
92 void sigClose(WizardType enmType);
93
94public:
95
96 /** Constructs wizard passing @a pParent to the base-class.
97 * @param enmType Brings the wizard type.
98 * @param strHelpKeyword Brings the wizard help keyword. */
99 UINativeWizard(QWidget *pParent,
100 WizardType enmType,
101 const QString &strHelpKeyword = QString());
102 /** Destructs wizard. */
103 virtual ~UINativeWizard() RT_OVERRIDE;
104
105 /** Returns local notification-center reference. */
106 UINotificationCenter *notificationCenter() const;
107 /** Immediately handles notification @a pProgress object. */
108 bool handleNotificationProgressNow(UINotificationProgress *pProgress);
109
110 /** Returns wizard button of specified @a enmType. */
111 QPushButton *wizardButton(const WizardButtonType &enmType) const;
112
113public slots:
114
115 /** Executes wizard in window modal mode.
116 * @note You shouldn't have to override it! */
117 virtual int exec() RT_OVERRIDE RT_FINAL;
118 /** Shows wizard in non-mode.
119 * @note You shouldn't have to override it! */
120 virtual void show() /* final */;
121
122protected:
123
124 /** Returns wizard type. */
125 WizardType type() const { return m_enmType; }
126 /** Returns wizard mode. */
127 WizardMode mode() const { return m_enmMode; }
128 /** Defines @a strName for wizard button of specified @a enmType. */
129 void setWizardButtonName(const WizardButtonType &enmType, const QString &strName);
130
131 /** Defines pixmap @a strName. */
132 void setPixmapName(const QString &strName);
133
134 /** Returns whether the page with certain @a iIndex is visible. */
135 bool isPageVisible(int iIndex) const;
136 /** Defines whether the page with certain @a iIndex is @a fVisible. */
137 void setPageVisible(int iIndex, bool fVisible);
138
139 /** Appends wizard @a pPage.
140 * @returns assigned page index. */
141 int addPage(UINativeWizardPage *pPage);
142 /** Populates pages.
143 * @note In your subclasses you should add
144 * pages via addPage declared above. */
145 virtual void populatePages() = 0;
146
147 /** Handles key-press @a pEvent. */
148 virtual void keyPressEvent(QKeyEvent *pEvent) RT_OVERRIDE RT_FINAL;
149 /** Handles close @a pEvent. */
150 virtual void closeEvent(QCloseEvent *pEvent) RT_OVERRIDE RT_FINAL;
151
152 /** Performs wizard-specific cleanup in case of wizard-mode change
153 * such as folder deletion in New VM wizard etc. */
154 virtual void cleanWizard() {}
155
156protected slots:
157
158 /** Handles translation event. */
159 virtual void sltRetranslateUI();
160
161private 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 /** Switches to previous page. */
169 void sltPrevious();
170 /** Switches to next page. */
171 void sltNext();
172
173 /** Handle help request*/
174 void sltHandleHelpRequest();
175
176private:
177
178 /** Prepares all. */
179 void prepare();
180 /** Cleanups all. */
181 void cleanup();
182 /** Inits all. */
183 void init();
184
185 /** Performs pages translation. */
186 void retranslatePages();
187
188 /** Resizes wizard to golden ratio. */
189 void resizeToGoldenRatio();
190#ifdef VBOX_WS_MAC
191 /** Assigns wizard background. */
192 void assignBackground();
193#else
194 /** Assigns wizard watermark. */
195 void assignWatermark();
196#endif
197 /** Checks if the pages coming after the page with iPageIndex is visible or not. Returns true if
198 * page with iPageIndex is the last visible page of the wizard. Returns false otherwise. */
199 bool isLastVisiblePage(int iPageIndex) const;
200
201 /** Holds the wizard type. */
202 WizardType m_enmType;
203 /** Holds the wizard mode. */
204 WizardMode m_enmMode;
205 /** Holds the wizard help keyword. */
206 QString m_strHelpKeyword;
207 /** Holds the pixmap name. */
208 QString m_strPixmapName;
209 /** Holds the last entered page index. */
210 int m_iLastIndex;
211 /** Holds the set of invisible pages. */
212 QSet<int> m_invisiblePages;
213 /** Holds whether user has requested to abort wizard. */
214 bool m_fAborted;
215 /** Holds whether the dialod had emitted signal to be closed. */
216 bool m_fClosed;
217
218 /** Holds the pixmap label instance. */
219 QLabel *m_pLabelPixmap;
220 /** Holds the right layout instance. */
221 QVBoxLayout *m_pLayoutRight;
222 /** Holds the title label instance. */
223 QLabel *m_pLabelPageTitle;
224 /** Holds the widget-stack instance. */
225 QStackedWidget *m_pWidgetStack;
226 /** Holds button instance map. */
227 QMap<WizardButtonType, QPushButton*> m_buttons;
228
229 /** Holds the local notification-center instance. */
230 UINotificationCenter *m_pNotificationCenter;
231};
232
233/** Native wizard interface pointer. */
234typedef QPointer<UINativeWizard> UINativeWizardPointer;
235
236#endif /* !FEQT_INCLUDED_SRC_wizards_UINativeWizard_h */
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette