VirtualBox

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

Last change on this file since 35740 was 28800, checked in by vboxsync, 14 years ago

Automated rebranding to Oracle copyright/license strings via filemuncher

  • Property svn:eol-style set to native
  • Property svn:keywords set to Date Revision Author Id
File size: 4.4 KB
Line 
1/* $Id: QIDialog.cpp 28800 2010-04-27 08:22:32Z vboxsync $ */
2/** @file
3 *
4 * VBox frontends: Qt GUI ("VirtualBox"):
5 * VirtualBox Qt extensions: QIDialog class implementation
6 */
7
8/*
9 * Copyright (C) 2008-2009 Oracle Corporation
10 *
11 * This file is part of VirtualBox Open Source Edition (OSE), as
12 * available from http://www.virtualbox.org. This file is free software;
13 * you can redistribute it and/or modify it under the terms of the GNU
14 * General Public License (GPL) as published by the Free Software
15 * Foundation, in version 2 as it comes in the "COPYING" file of the
16 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
17 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
18 */
19
20/* VBox includes */
21#include "QIDialog.h"
22#include "VBoxGlobal.h"
23#ifdef Q_WS_MAC
24# include "VBoxUtils.h"
25#endif /* Q_WS_MAC */
26
27/* Qt includes */
28#include <QPointer>
29
30QIDialog::QIDialog (QWidget *aParent /* = 0 */, Qt::WindowFlags aFlags /* = 0 */)
31 : QDialog (aParent, aFlags)
32 , mPolished (false)
33 , mEventLoop (0)
34{
35}
36
37void QIDialog::showEvent (QShowEvent * /* aEvent */)
38{
39 /* Two thinks to do for fixed size dialogs on MacOS X:
40 * 1. Make sure the layout is polished and have the right size
41 * 2. Disable that _unnecessary_ size grip (Bug in Qt?) */
42 QSizePolicy policy = sizePolicy();
43 if ((policy.horizontalPolicy() == QSizePolicy::Fixed &&
44 policy.verticalPolicy() == QSizePolicy::Fixed) ||
45 (windowFlags() & Qt::Sheet) == Qt::Sheet)
46 {
47 adjustSize();
48 setFixedSize (size());
49#ifdef Q_WS_MAC
50 ::darwinSetShowsResizeIndicator (this, false);
51#endif /* Q_WS_MAC */
52 }
53
54 /* Polishing border */
55 if (mPolished)
56 return;
57 mPolished = true;
58
59 /* Explicit widget centering relatively to it's parent
60 * if any or desktop if parent is missed. */
61 VBoxGlobal::centerWidget (this, parentWidget(), false);
62}
63
64int QIDialog::exec (bool aShow /* = true */)
65{
66 /* Reset the result code */
67 setResult (QDialog::Rejected);
68
69 bool wasDeleteOnClose = testAttribute (Qt::WA_DeleteOnClose);
70 setAttribute (Qt::WA_DeleteOnClose, false);
71#if defined(Q_WS_MAC) && QT_VERSION >= 0x040500
72 /* After 4.5 Qt changed the behavior of Sheets for the window/application
73 * modal case. See "New Ways of Using Dialogs" in
74 * http://doc.trolltech.com/qq/QtQuarterly30.pdf why. We want the old
75 * behavior back, where all modal windows where shown as sheets. So make
76 * the modal mode window, but be application modal in any case. */
77 Qt::WindowModality winModality = windowModality();
78 bool wasSetWinModality = testAttribute (Qt::WA_SetWindowModality);
79 if ((windowFlags() & Qt::Sheet) == Qt::Sheet)
80 {
81 setWindowModality (Qt::WindowModal);
82 setAttribute (Qt::WA_SetWindowModality, false);
83 }
84#endif /* defined(Q_WS_MAC) && QT_VERSION >= 0x040500 */
85 /* The dialog has to modal in any case. Save the current modality to
86 * restore it later. */
87 bool wasShowModal = testAttribute (Qt::WA_ShowModal);
88 setAttribute (Qt::WA_ShowModal, true);
89
90 /* Create a local event loop */
91 mEventLoop = new QEventLoop();
92 /* Show the window if requested */
93 if (aShow)
94 show();
95 /* A guard to ourself for the case we destroy ourself. */
96 QPointer<QIDialog> guard = this;
97 /* Start the event loop. This blocks. */
98 mEventLoop->exec();
99 /* Delete the event loop */
100 delete mEventLoop;
101 mEventLoop = 0;
102 /* Are we valid anymore? */
103 if (guard.isNull())
104 return QDialog::Rejected;
105 /* Save the result code in case we delete ourself */
106 QDialog::DialogCode res = (QDialog::DialogCode)result();
107#if defined(Q_WS_MAC) && QT_VERSION >= 0x040500
108 /* Restore old modality mode */
109 if ((windowFlags() & Qt::Sheet) == Qt::Sheet)
110 {
111 setWindowModality (winModality);
112 setAttribute (Qt::WA_SetWindowModality, wasSetWinModality);
113 }
114#endif /* defined(Q_WS_MAC) && QT_VERSION >= 0x040500 */
115 /* Set the old show modal attribute */
116 setAttribute (Qt::WA_ShowModal, wasShowModal);
117 /* Delete us in the case we should do so on close */
118 if (wasDeleteOnClose)
119 delete this;
120 /* Return the final result */
121 return res;
122}
123
124void QIDialog::setVisible (bool aVisible)
125{
126 QDialog::setVisible (aVisible);
127 /* Exit from the event loop if there is any and we are changing our state
128 * from visible to invisible. */
129 if (mEventLoop && !aVisible)
130 mEventLoop->exit();
131}
132
Note: See TracBrowser for help on using the repository browser.

© 2023 Oracle
ContactPrivacy policyTerms of Use