VirtualBox

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

Last change on this file since 82781 was 81356, checked in by vboxsync, 5 years ago

FE/Qt: QIManagerDialog: Fix bug and coding-style of r119699.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 7.0 KB
Line 
1/* $Id: QIManagerDialog.cpp 81356 2019-10-18 14:07:02Z vboxsync $ */
2/** @file
3 * VBox Qt GUI - Qt extensions: QIManagerDialog class implementation.
4 */
5
6/*
7 * Copyright (C) 2009-2019 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 */
17
18/* Qt includes: */
19#include <QMenuBar>
20#include <QPushButton>
21#include <QStyle>
22#include <QVBoxLayout>
23
24/* GUI includes: */
25#include "QIDialogButtonBox.h"
26#include "QIManagerDialog.h"
27#include "UICommon.h"
28#include "UIDesktopWidgetWatchdog.h"
29#ifdef VBOX_WS_MAC
30# include "UIToolBar.h"
31# include "UIWindowMenuManager.h"
32#endif
33
34
35/*********************************************************************************************************************************
36* Class QIManagerDialogFactory implementation. *
37*********************************************************************************************************************************/
38
39void QIManagerDialogFactory::prepare(QIManagerDialog *&pDialog, QWidget *pCenterWidget /* = 0 */)
40{
41 create(pDialog, pCenterWidget);
42 pDialog->prepare();
43}
44
45void QIManagerDialogFactory::cleanup(QIManagerDialog *&pDialog)
46{
47 pDialog->cleanup();
48 delete pDialog;
49 pDialog = 0;
50}
51
52
53/*********************************************************************************************************************************
54* Class QIManagerDialog implementation. *
55*********************************************************************************************************************************/
56
57QIManagerDialog::QIManagerDialog(QWidget *pCenterWidget)
58 : m_pCenterWidget(pCenterWidget)
59 , m_fCloseEmitted(false)
60 , m_pWidget(0)
61 , m_pWidgetMenu(0)
62#ifdef VBOX_WS_MAC
63 , m_pWidgetToolbar(0)
64#endif
65 , m_pButtonBox(0)
66{
67}
68
69void QIManagerDialog::prepare()
70{
71 /* Tell the application we are not that important: */
72 setAttribute(Qt::WA_QuitOnClose, false);
73
74 /* Invent initial size: */
75 QSize proposedSize;
76 const int iHostScreen = gpDesktop->screenNumber(m_pCenterWidget);
77 if (iHostScreen >= 0 && iHostScreen < gpDesktop->screenCount())
78 {
79 /* On the basis of current host-screen geometry if possible: */
80 const QRect screenGeometry = gpDesktop->screenGeometry(iHostScreen);
81 if (screenGeometry.isValid())
82 proposedSize = screenGeometry.size() * 7 / 15;
83 }
84 /* Fallback to default size if we failed: */
85 if (proposedSize.isNull())
86 proposedSize = QSize(800, 600);
87 /* Resize to initial size: */
88 resize(proposedSize);
89
90 /* Configure: */
91 configure();
92
93 /* Prepare central-widget: */
94 prepareCentralWidget();
95 /* Prepare menu-bar: */
96 prepareMenuBar();
97#ifdef VBOX_WS_MAC
98 /* Prepare toolbar: */
99 prepareToolBar();
100#endif
101
102 /* Finalize: */
103 finalize();
104
105 /* Center according requested widget: */
106 UICommon::centerWidget(this, m_pCenterWidget, false);
107
108 /* Load the dialog's settings from extradata */
109 loadSettings();
110}
111
112void QIManagerDialog::prepareCentralWidget()
113{
114 /* Create central-widget: */
115 setCentralWidget(new QWidget);
116 AssertPtrReturnVoid(centralWidget());
117 {
118 /* Create main-layout: */
119 new QVBoxLayout(centralWidget());
120 AssertPtrReturnVoid(centralWidget()->layout());
121 {
122 /* Configure layout: */
123 const int iL = qApp->style()->pixelMetric(QStyle::PM_LayoutLeftMargin) / 2;
124 const int iT = qApp->style()->pixelMetric(QStyle::PM_LayoutTopMargin) / 2;
125 const int iR = qApp->style()->pixelMetric(QStyle::PM_LayoutRightMargin) / 2;
126 const int iB = qApp->style()->pixelMetric(QStyle::PM_LayoutBottomMargin) / 2;
127 centralWidget()->layout()->setContentsMargins(iL, iT, iR, iB);
128
129 /* Configure central-widget: */
130 configureCentralWidget();
131
132 /* Prepare button-box: */
133 prepareButtonBox();
134 }
135 }
136}
137
138void QIManagerDialog::prepareButtonBox()
139{
140 /* Create button-box: */
141 m_pButtonBox = new QIDialogButtonBox;
142 AssertPtrReturnVoid(m_pButtonBox);
143 {
144 /* Configure button-box: */
145#ifdef VBOX_WS_WIN
146 m_pButtonBox->setStandardButtons(QDialogButtonBox::Reset | QDialogButtonBox::Save | QDialogButtonBox::Close);
147#else
148 m_pButtonBox->setStandardButtons(QDialogButtonBox::Reset | QDialogButtonBox::Apply | QDialogButtonBox::Close);
149#endif
150 m_buttons[ButtonType_Reset] = m_pButtonBox->button(QDialogButtonBox::Reset);
151#ifdef VBOX_WS_WIN
152 m_buttons[ButtonType_Apply] = m_pButtonBox->button(QDialogButtonBox::Save);
153#else
154 m_buttons[ButtonType_Apply] = m_pButtonBox->button(QDialogButtonBox::Apply);
155#endif
156 m_buttons[ButtonType_Close] = m_pButtonBox->button(QDialogButtonBox::Close);
157 /* Assign shortcuts: */
158 button(ButtonType_Close)->setShortcut(Qt::Key_Escape);
159 /* Hide 'Reset' and 'Apply' initially: */
160 button(ButtonType_Reset)->hide();
161 button(ButtonType_Apply)->hide();
162 /* Disable 'Reset' and 'Apply' initially: */
163 button(ButtonType_Reset)->setEnabled(false);
164 button(ButtonType_Apply)->setEnabled(false);
165 connect(m_pButtonBox, &QIDialogButtonBox::rejected, this, &QIManagerDialog::close);
166
167 /* Configure button-box: */
168 configureButtonBox();
169
170 /* Add into layout: */
171 centralWidget()->layout()->addWidget(m_pButtonBox);
172 }
173}
174
175void QIManagerDialog::prepareMenuBar()
176{
177 if (!m_pWidgetMenu)
178 return;
179 /* Add widget menu: */
180 menuBar()->addMenu(m_pWidgetMenu);
181
182#ifdef VBOX_WS_MAC
183 /* Prepare 'Window' menu: */
184 if (gpWindowMenuManager)
185 {
186 menuBar()->addMenu(gpWindowMenuManager->createMenu(this));
187 gpWindowMenuManager->addWindow(this);
188 }
189#endif
190}
191
192#ifdef VBOX_WS_MAC
193void QIManagerDialog::prepareToolBar()
194{
195 if (!m_pWidgetToolbar)
196 return;
197 /* Enable unified toolbar on macOS: */
198 addToolBar(m_pWidgetToolbar);
199 m_pWidgetToolbar->enableMacToolbar();
200}
201#endif
202
203void QIManagerDialog::cleanupMenuBar()
204{
205#ifdef VBOX_WS_MAC
206 /* Cleanup 'Window' menu: */
207 if (gpWindowMenuManager)
208 {
209 gpWindowMenuManager->removeWindow(this);
210 gpWindowMenuManager->destroyMenu(this);
211 }
212#endif
213}
214
215void QIManagerDialog::cleanup()
216{
217 saveSettings();
218 /* Cleanup menu-bar: */
219 cleanupMenuBar();
220}
221
222void QIManagerDialog::closeEvent(QCloseEvent *pEvent)
223{
224 /* Ignore the event itself: */
225 pEvent->ignore();
226 /* But tell the listener to close us (once): */
227 if (!m_fCloseEmitted)
228 {
229 m_fCloseEmitted = true;
230 emit sigClose();
231 }
232}
Note: See TracBrowser for help on using the repository browser.

© 2023 Oracle
ContactPrivacy policyTerms of Use