Changeset 45162 in vbox
- Timestamp:
- Mar 25, 2013 11:35:01 AM (12 years ago)
- svn:sync-xref-src-repo-rev:
- 84485
- Location:
- trunk/src/VBox/Frontends/VirtualBox/src/extensions
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/src/extensions/QIDialog.cpp
r44528 r45162 7 7 8 8 /* 9 * Copyright (C) 2008-201 2Oracle Corporation9 * Copyright (C) 2008-2013 Oracle Corporation 10 10 * 11 11 * This file is part of VirtualBox Open Source Edition (OSE), as … … 18 18 */ 19 19 20 /* VBox includes*/20 /* GUI includes: */ 21 21 #include "QIDialog.h" 22 22 #include "VBoxGlobal.h" … … 25 25 #endif /* Q_WS_MAC */ 26 26 27 QIDialog::QIDialog (QWidget *aParent /* = 0 */, Qt::WindowFlags aFlags /* = 0 */)28 : QDialog (aParent, aFlags)29 , m Polished(false)27 QIDialog::QIDialog(QWidget *pParent /* = 0 */, Qt::WindowFlags flags /* = 0 */) 28 : QDialog(pParent, flags) 29 , m_fPolished(false) 30 30 { 31 31 } 32 32 33 void QIDialog::showEvent (QShowEvent * /* aEvent */) 33 QIDialog::~QIDialog() 34 { 35 } 36 37 void QIDialog::showEvent(QShowEvent * /* pEvent */) 34 38 { 35 39 /* Two thinks to do for fixed size dialogs on MacOS X: … … 42 46 { 43 47 adjustSize(); 44 setFixedSize 48 setFixedSize(size()); 45 49 #ifdef Q_WS_MAC 46 50 ::darwinSetShowsResizeIndicator (this, false); … … 48 52 } 49 53 50 /* Polishing border*/51 if (m Polished)54 /* Polishing: */ 55 if (m_fPolished) 52 56 return; 53 m Polished = true;57 m_fPolished = true; 54 58 55 /* Explicit widget centering relatively to it's parent 56 * if any or desktop if parent is missed. */ 57 VBoxGlobal::centerWidget (this, parentWidget(), false); 59 /* Explicit centering according to our parent: */ 60 VBoxGlobal::centerWidget(this, parentWidget(), false); 58 61 } 59 62 60 int QIDialog::exec (bool aShow /* = true */)63 int QIDialog::exec(bool fShow /* = true */) 61 64 { 62 /* Reset the result code*/63 setResult 65 /* Reset the result-code: */ 66 setResult(QDialog::Rejected); 64 67 65 bool wasDeleteOnClose = testAttribute(Qt::WA_DeleteOnClose);66 setAttribute 68 bool fWasDeleteOnClose = testAttribute(Qt::WA_DeleteOnClose); 69 setAttribute(Qt::WA_DeleteOnClose, false); 67 70 #if defined(Q_WS_MAC) && QT_VERSION >= 0x040500 68 71 /* After 4.5 Qt changed the behavior of Sheets for the window/application … … 72 75 * the modal mode window, but be application modal in any case. */ 73 76 Qt::WindowModality winModality = windowModality(); 74 bool wasSetWinModality = testAttribute 77 bool wasSetWinModality = testAttribute(Qt::WA_SetWindowModality); 75 78 if ((windowFlags() & Qt::Sheet) == Qt::Sheet) 76 79 { 77 setWindowModality 78 setAttribute 80 setWindowModality(Qt::WindowModal); 81 setAttribute(Qt::WA_SetWindowModality, false); 79 82 } 80 83 #endif /* defined(Q_WS_MAC) && QT_VERSION >= 0x040500 */ 81 /* The dialog has to modal in any case. Save the current modality to82 * restore it later. */83 bool wasShowModal = testAttribute 84 setAttribute 84 /* The dialog has to modal in any case. 85 * Save the current modality to restore it later. */ 86 bool wasShowModal = testAttribute(Qt::WA_ShowModal); 87 setAttribute(Qt::WA_ShowModal, true); 85 88 86 /* Create a local event loop*/89 /* Create a local event-loop: */ 87 90 QEventLoop eventLoop; 88 mEventLoop = &eventLoop; 89 /* Show the window if requested */ 90 if (aShow) 91 m_pEventLoop = &eventLoop; 92 93 /* Show ourself if requested: */ 94 if (fShow) 91 95 show(); 92 /* A guard to ourself for the case we destroy ourself. */ 96 97 /* Guard ourself for the case 98 * we destroyed ourself in our event-loop: */ 93 99 QPointer<QIDialog> guard = this; 94 /* Start the event loop. This blocks. */ 100 101 /* Start the blocking event-loop: */ 95 102 eventLoop.exec(); 96 /* Are we valid anymore? */ 103 104 /* Are we still valid? */ 97 105 if (guard.isNull()) 98 106 return QDialog::Rejected; 99 mEventLoop = 0; 100 /* Save the result code in case we delete ourself */ 101 QDialog::DialogCode res = (QDialog::DialogCode)result(); 107 108 m_pEventLoop = 0; 109 110 /* Save the result-code early (we can delete ourself on close): */ 111 QDialog::DialogCode resultCode = (QDialog::DialogCode)result(); 112 102 113 #if defined(Q_WS_MAC) && QT_VERSION >= 0x040500 103 /* Restore old modality mode */114 /* Restore old modality mode: */ 104 115 if ((windowFlags() & Qt::Sheet) == Qt::Sheet) 105 116 { 106 setWindowModality 107 setAttribute 117 setWindowModality(winModality); 118 setAttribute(Qt::WA_SetWindowModality, wasSetWinModality); 108 119 } 109 120 #endif /* defined(Q_WS_MAC) && QT_VERSION >= 0x040500 */ 121 110 122 /* Set the old show modal attribute */ 111 123 setAttribute (Qt::WA_ShowModal, wasShowModal); 112 /* Delete us in the case we should do so on close*/113 if ( wasDeleteOnClose)124 /* Delete ourself if we should do that on close: */ 125 if (fWasDeleteOnClose) 114 126 delete this; 115 /* Return the final result */ 116 return res; 127 128 /* Return the result-code: */ 129 return resultCode; 117 130 } 118 131 119 void QIDialog::setVisible (bool aVisible)132 void QIDialog::setVisible(bool fVisible) 120 133 { 121 QDialog::setVisible (aVisible); 122 /* Exit from the event loop if there is any and we are changing our state 123 * from visible to invisible. */ 124 if (mEventLoop && !aVisible) 125 mEventLoop->exit(); 134 /* Call to base-class: */ 135 QDialog::setVisible(fVisible); 136 137 /* Exit from the event-loop if 138 * 1. there is any and 139 * 2. we are changing our state from visible to invisible: */ 140 if (m_pEventLoop && !fVisible) 141 m_pEventLoop->exit(); 126 142 } 127 143 -
trunk/src/VBox/Frontends/VirtualBox/src/extensions/QIDialog.h
r44528 r45162 2 2 * 3 3 * VBox frontends: Qt GUI ("VirtualBox"): 4 * VirtualBox Qt extensions: QIDialog class implementation4 * VirtualBox Qt extensions: QIDialog class declaration 5 5 */ 6 6 7 7 /* 8 * Copyright (C) 2008-201 2Oracle Corporation8 * Copyright (C) 2008-2013 Oracle Corporation 9 9 * 10 10 * This file is part of VirtualBox Open Source Edition (OSE), as … … 20 20 #define __QIDialog_h__ 21 21 22 /* Qt includes */22 /* Qt includes: */ 23 23 #include <QDialog> 24 24 #include <QPointer> 25 25 26 /* Qt forwards declarations*/26 /* Forward declarations: */ 27 27 class QEventLoop; 28 28 29 /* Qt dialog extension: */ 29 30 class QIDialog: public QDialog 30 31 { … … 32 33 33 34 public: 34 QIDialog (QWidget *aParent = 0, Qt::WindowFlags aFlags = 0); 35 void setVisible (bool aVisible); 35 36 /* Constructor/destructor: */ 37 QIDialog(QWidget *pParent = 0, Qt::WindowFlags flags = 0); 38 ~QIDialog(); 39 40 /* API: Visibility stuff: */ 41 void setVisible(bool fVisible); 36 42 37 43 public slots: 38 int exec (bool aShow = true); 44 45 /* API: Exec stuff: */ 46 int exec(bool fShow = true); 39 47 40 48 protected: 41 void showEvent (QShowEvent *aEvent); 49 50 /* Handler: Show-event stuff: */ 51 void showEvent(QShowEvent *pEvent); 42 52 43 53 private: 44 /* Private member vars */ 45 bool mPolished; 46 QPointer<QEventLoop> mEventLoop; 54 55 /* Variables: */ 56 bool m_fPolished; 57 QPointer<QEventLoop> m_pEventLoop; 47 58 }; 48 59
Note:
See TracChangeset
for help on using the changeset viewer.