VirtualBox

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

Last change on this file since 104158 was 103578, checked in by vboxsync, 11 months ago

FE/Qt: UIShortcutPool: macOS no more support CMD+? as the default one help Contents shortcut; Let's use another one like CMD+/ (which is same just with Shift modifier released, because CMD+Shift+? now used for system-wide help Search menu).

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