VirtualBox

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

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

Renaming VBoxGlobal to UICommon for bugref:9049 as planned.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 3.6 KB
Line 
1/* $Id: QIDialog.cpp 79365 2019-06-26 15:57:32Z vboxsync $ */
2/** @file
3 * VBox Qt GUI - Qt extensions: QIDialog class implementation.
4 */
5
6/*
7 * Copyright (C) 2008-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 <QEventLoop>
20
21/* GUI includes: */
22#include "QIDialog.h"
23#include "UICommon.h"
24
25
26QIDialog::QIDialog(QWidget *pParent /* = 0 */, Qt::WindowFlags enmFlags /* = 0 */)
27 : QDialog(pParent, enmFlags)
28 , m_fPolished(false)
29{
30 /* Do not count that window as important for application,
31 * it will NOT be taken into account when other top-level windows will be closed: */
32 setAttribute(Qt::WA_QuitOnClose, false);
33}
34
35void QIDialog::setVisible(bool fVisible)
36{
37 /* Call to base-class: */
38 QDialog::setVisible(fVisible);
39
40 /* Exit from the event-loop if there is any and
41 * we are changing our state from visible to hidden. */
42 if (m_pEventLoop && !fVisible)
43 m_pEventLoop->exit();
44}
45
46int QIDialog::execute(bool fShow /* = true */, bool fApplicationModal /* = false */)
47{
48 /* Check for the recursive run: */
49 AssertMsgReturn(!m_pEventLoop, ("QIDialog::execute() is called recursively!\n"), QDialog::Rejected);
50
51 /* Reset the result-code: */
52 setResult(QDialog::Rejected);
53
54 /* Should we delete ourself on close in theory? */
55 const bool fOldDeleteOnClose = testAttribute(Qt::WA_DeleteOnClose);
56 /* For the exec() time, set this attribute to 'false': */
57 setAttribute(Qt::WA_DeleteOnClose, false);
58
59 /* Which is the current window-modality? */
60 const Qt::WindowModality oldModality = windowModality();
61 /* For the exec() time, set this attribute to 'window-modal' or 'application-modal': */
62 setWindowModality(!fApplicationModal ? Qt::WindowModal : Qt::ApplicationModal);
63
64 /* Show ourself if requested: */
65 if (fShow)
66 show();
67
68 /* Create a local event-loop: */
69 {
70 QEventLoop eventLoop;
71 m_pEventLoop = &eventLoop;
72
73 /* Guard ourself for the case
74 * we destroyed ourself in our event-loop: */
75 QPointer<QIDialog> guard = this;
76
77 /* Start the blocking event-loop: */
78 eventLoop.exec();
79
80 /* Are we still valid? */
81 if (guard.isNull())
82 return QDialog::Rejected;
83
84 m_pEventLoop = 0;
85 }
86
87 /* Save the result-code early (we can delete ourself on close): */
88 const int iResultCode = result();
89
90 /* Return old modality: */
91 setWindowModality(oldModality);
92
93 /* Reset attribute to previous value: */
94 setAttribute(Qt::WA_DeleteOnClose, fOldDeleteOnClose);
95 /* Delete ourself if we should do that on close: */
96 if (fOldDeleteOnClose)
97 delete this;
98
99 /* Return the result-code: */
100 return iResultCode;
101}
102
103void QIDialog::showEvent(QShowEvent *pEvent)
104{
105 /* Make sure we should polish dialog: */
106 if (m_fPolished)
107 return;
108
109 /* Call to polish-event: */
110 polishEvent(pEvent);
111
112 /* Mark dialog as polished: */
113 m_fPolished = true;
114}
115
116void QIDialog::polishEvent(QShowEvent *)
117{
118 /* Make sure layout is polished: */
119 adjustSize();
120#ifdef VBOX_WS_MAC
121 /* And dialog have fixed size: */
122 setFixedSize(size());
123#endif /* VBOX_WS_MAC */
124
125 /* Explicit centering according to our parent: */
126 UICommon::centerWidget(this, parentWidget(), false);
127}
Note: See TracBrowser for help on using the repository browser.

© 2023 Oracle
ContactPrivacy policyTerms of Use