VirtualBox

source: vbox/trunk/src/VBox/Frontends/VirtualBox/src/extensions/QIManagerDialog.cpp

Last change on this file was 106061, checked in by vboxsync, 4 weeks ago

Copyright year updates by scm.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 8.3 KB
Line 
1/* $Id: QIManagerDialog.cpp 106061 2024-09-16 14:03:52Z vboxsync $ */
2/** @file
3 * VBox Qt GUI - Qt extensions: QIManagerDialog class implementation.
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/* Qt includes: */
29#include <QApplication>
30#include <QMenuBar>
31#include <QPushButton>
32#include <QStyle>
33#include <QVBoxLayout>
34
35/* GUI includes: */
36#include "QIDialogButtonBox.h"
37#include "QIManagerDialog.h"
38#include "UICommon.h"
39#include "UIDesktopWidgetWatchdog.h"
40#include "UIHelpBrowserDialog.h"
41#include "UIMessageCenter.h"
42#include "UIShortcutPool.h"
43#ifdef VBOX_WS_MAC
44# include "QIToolBar.h"
45# include "UIWindowMenuManager.h"
46#endif
47
48
49/*********************************************************************************************************************************
50* Class QIManagerDialogFactory implementation. *
51*********************************************************************************************************************************/
52
53void QIManagerDialogFactory::prepare(QIManagerDialog *&pDialog, QWidget *pCenterWidget /* = 0 */)
54{
55 create(pDialog, pCenterWidget);
56 pDialog->prepare();
57}
58
59void QIManagerDialogFactory::cleanup(QIManagerDialog *&pDialog)
60{
61 if (pDialog)
62 {
63 pDialog->cleanup();
64 delete pDialog;
65 pDialog = 0;
66 }
67}
68
69
70/*********************************************************************************************************************************
71* Class QIManagerDialog implementation. *
72*********************************************************************************************************************************/
73
74QIManagerDialog::QIManagerDialog(QWidget *pCenterWidget)
75 : m_pCenterWidget(pCenterWidget)
76 , m_fCloseEmitted(false)
77 , m_pWidget(0)
78#ifdef VBOX_WS_MAC
79 , m_pWidgetToolbar(0)
80#endif
81 , m_pButtonBox(0)
82{
83}
84
85void QIManagerDialog::closeEvent(QCloseEvent *pEvent)
86{
87 /* Ignore the event itself: */
88 pEvent->ignore();
89 /* But tell the listener to close us (once): */
90 if (!m_fCloseEmitted)
91 {
92 m_fCloseEmitted = true;
93 emit sigClose();
94 }
95}
96
97void QIManagerDialog::sltHandleHelpRequested()
98{
99 UIHelpBrowserDialog::findManualFileAndShow(uiCommon().helpKeyword(m_pWidget));
100}
101
102void QIManagerDialog::prepare()
103{
104 /* Tell the application we are not that important: */
105 setAttribute(Qt::WA_QuitOnClose, false);
106
107 /* Invent initial size: */
108 QSize proposedSize;
109 const int iHostScreen = UIDesktopWidgetWatchdog::screenNumber(m_pCenterWidget);
110 if (iHostScreen >= 0 && iHostScreen < UIDesktopWidgetWatchdog::screenCount())
111 {
112 /* On the basis of current host-screen geometry if possible: */
113 const QRect screenGeometry = gpDesktop->screenGeometry(iHostScreen);
114 if (screenGeometry.isValid())
115 proposedSize = screenGeometry.size() * 7 / 15;
116 }
117 /* Fallback to default size if we failed: */
118 if (proposedSize.isNull())
119 proposedSize = QSize(800, 600);
120 /* Resize to initial size: */
121 resize(proposedSize);
122
123 /* Configure: */
124 configure();
125
126 /* Prepare central-widget: */
127 prepareCentralWidget();
128 /* Prepare menu-bar: */
129 prepareMenuBar();
130#ifdef VBOX_WS_MAC
131 /* Prepare toolbar: */
132 prepareToolBar();
133#endif
134
135 /* Finalize: */
136 finalize();
137
138 /* Center according requested widget: */
139 gpDesktop->centerWidget(this, m_pCenterWidget, false);
140
141 /* Load the dialog's settings from extradata */
142 loadSettings();
143}
144
145void QIManagerDialog::prepareCentralWidget()
146{
147 /* Create central-widget: */
148 setCentralWidget(new QWidget);
149 AssertPtrReturnVoid(centralWidget());
150 {
151 /* Create main-layout: */
152 new QVBoxLayout(centralWidget());
153 AssertPtrReturnVoid(centralWidget()->layout());
154 {
155 /* Configure layout: */
156 const int iL = qApp->style()->pixelMetric(QStyle::PM_LayoutLeftMargin) / 2;
157 const int iT = qApp->style()->pixelMetric(QStyle::PM_LayoutTopMargin) / 2;
158 const int iR = qApp->style()->pixelMetric(QStyle::PM_LayoutRightMargin) / 2;
159 const int iB = qApp->style()->pixelMetric(QStyle::PM_LayoutBottomMargin) / 2;
160 centralWidget()->layout()->setContentsMargins(iL, iT, iR, iB);
161
162 /* Configure central-widget: */
163 configureCentralWidget();
164
165 /* Prepare button-box: */
166 prepareButtonBox();
167 }
168 }
169}
170
171void QIManagerDialog::prepareButtonBox()
172{
173 /* Create button-box: */
174 m_pButtonBox = new QIDialogButtonBox;
175 AssertPtrReturnVoid(m_pButtonBox);
176 {
177 /* Configure button-box: */
178 m_pButtonBox->setStandardButtons( QDialogButtonBox::Reset
179#ifdef VBOX_WS_WIN
180 | QDialogButtonBox::Save
181#else
182 | QDialogButtonBox::Apply
183#endif
184 | QDialogButtonBox::Cancel
185 | QDialogButtonBox::Close
186 | QDialogButtonBox::Help);
187 m_buttons[ButtonType_Reset] = m_pButtonBox->button(QDialogButtonBox::Reset);
188#ifdef VBOX_WS_WIN
189 m_buttons[ButtonType_Apply] = m_pButtonBox->button(QDialogButtonBox::Save);
190#else
191 m_buttons[ButtonType_Apply] = m_pButtonBox->button(QDialogButtonBox::Apply);
192#endif
193 m_buttons[ButtonType_Embed] = m_pButtonBox->button(QDialogButtonBox::Cancel);
194 m_buttons[ButtonType_Close] = m_pButtonBox->button(QDialogButtonBox::Close);
195 m_buttons[ButtonType_Help] = m_pButtonBox->button(QDialogButtonBox::Help);
196
197 /* Assign shortcuts: */
198 button(ButtonType_Close)->setShortcut(Qt::Key_Escape);
199 button(ButtonType_Help)->setShortcut(UIShortcutPool::standardSequence(QKeySequence::HelpContents));
200
201 /* Hide some of buttons initially: */
202 button(ButtonType_Reset)->hide();
203 button(ButtonType_Apply)->hide();
204 button(ButtonType_Embed)->hide();
205 /* Disable some of buttons initially: */
206 button(ButtonType_Reset)->setEnabled(false);
207 button(ButtonType_Apply)->setEnabled(false);
208 button(ButtonType_Embed)->setEnabled(false);
209
210 /* Configure connections: */
211 connect(m_pButtonBox, &QIDialogButtonBox::rejected, this, &QIManagerDialog::close);
212 connect(m_pButtonBox, &QIDialogButtonBox::helpRequested, this, &QIManagerDialog::sltHandleHelpRequested);
213
214 /* Configure button-box: */
215 configureButtonBox();
216
217 /* Add into layout: */
218 centralWidget()->layout()->addWidget(m_pButtonBox);
219 }
220}
221
222void QIManagerDialog::prepareMenuBar()
223{
224 /* Skip the call if there are no menus to add: */
225 if (m_widgetMenus.isEmpty())
226 return;
227
228 /* Add all the widget menus: */
229 foreach (QMenu *pMenu, m_widgetMenus)
230 menuBar()->addMenu(pMenu);
231
232#ifdef VBOX_WS_MAC
233 /* Prepare 'Window' menu: */
234 if (gpWindowMenuManager)
235 {
236 menuBar()->addMenu(gpWindowMenuManager->createMenu(this));
237 gpWindowMenuManager->addWindow(this);
238 }
239#endif
240}
241
242#ifdef VBOX_WS_MAC
243void QIManagerDialog::prepareToolBar()
244{
245 if (!m_pWidgetToolbar)
246 return;
247 /* Enable unified toolbar on macOS: */
248 addToolBar(m_pWidgetToolbar);
249 m_pWidgetToolbar->enableMacToolbar();
250}
251#endif
252
253void QIManagerDialog::cleanupMenuBar()
254{
255#ifdef VBOX_WS_MAC
256 /* Cleanup 'Window' menu: */
257 if (gpWindowMenuManager)
258 {
259 gpWindowMenuManager->removeWindow(this);
260 gpWindowMenuManager->destroyMenu(this);
261 }
262#endif
263}
264
265void QIManagerDialog::cleanup()
266{
267 saveSettings();
268 /* Cleanup menu-bar: */
269 cleanupMenuBar();
270}
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