QIMainDialog.cpp revision 7e3a9a30ad06aaa937b5bfe12eef894f23091ec4
d34409ad02ea0d28e08a6c4b089a412fdb3b4c9cvboxsync * VBox Qt GUI - VirtualBox Qt extensions: QIMainDialog class implementation.
c7814cf6e1240a519cbec0441e033d0e2470ed00vboxsync * Copyright (C) 2008-2012 Oracle Corporation
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync * available from http://www.virtualbox.org. This file is free software;
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync * you can redistribute it and/or modify it under the terms of the GNU
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync * General Public License (GPL) as published by the Free Software
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
a9b62afc62b28da7a1a77f34259f8013892d9664vboxsync#else /* !VBOX_WITH_PRECOMPILED_HEADERS */
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync/* Qt includes */
a9b62afc62b28da7a1a77f34259f8013892d9664vboxsync#endif /* !VBOX_WITH_PRECOMPILED_HEADERS */
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsyncQIMainDialog::QIMainDialog (QWidget *aParent /* = 0 */,
ff58db82d953628895c2060fb6f9169b5cc8cd19vboxsync /* Check for the recursive run: */
ff58db82d953628895c2060fb6f9169b5cc8cd19vboxsync AssertMsg(!mEventLoop, ("QIMainDialog::exec() is called recursively!\n"));
ff58db82d953628895c2060fb6f9169b5cc8cd19vboxsync /* Reset the result code: */
ff58db82d953628895c2060fb6f9169b5cc8cd19vboxsync /* Tune some attributes: */
e0b4007776ecc4b476e118a0d29ed5fa68667f18vboxsync bool fDeleteOnClose = testAttribute(Qt::WA_DeleteOnClose); NOREF(fDeleteOnClose);
ff58db82d953628895c2060fb6f9169b5cc8cd19vboxsync AssertMsg(!fDeleteOnClose, ("QIMainDialog is NOT supposed to be run in 'delete-on-close' mode!"));
ff58db82d953628895c2060fb6f9169b5cc8cd19vboxsync bool fWasShowModal = testAttribute(Qt::WA_ShowModal);
ff58db82d953628895c2060fb6f9169b5cc8cd19vboxsync /* Create a local event-loop: */
ff58db82d953628895c2060fb6f9169b5cc8cd19vboxsync /* Show the window: */
ff58db82d953628895c2060fb6f9169b5cc8cd19vboxsync /* A guard to ourself for the case we destroy ourself: */
ff58db82d953628895c2060fb6f9169b5cc8cd19vboxsync /* Start the event-loop: */
ff58db82d953628895c2060fb6f9169b5cc8cd19vboxsync /* Check if dialog is still valid: */
ff58db82d953628895c2060fb6f9169b5cc8cd19vboxsync /* Prepare result: */
ff58db82d953628895c2060fb6f9169b5cc8cd19vboxsync /* Restore old show-modal attribute: */
ff58db82d953628895c2060fb6f9169b5cc8cd19vboxsync /* Return the final result: */
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsyncvoid QIMainDialog::setSizeGripEnabled (bool aEnabled)
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsyncvoid QIMainDialog::setDefaultButton (QPushButton* aButton)
3f001a14123f18f268775568f603105a7ed246b8vboxsyncvoid QIMainDialog::setAutoCenteringEnabled(bool fIsAutoCentering)
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync /* Exit from the event loop if there is any and we are changing our state
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync * from visible to invisible. */
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync /* Initially search for the default button. */
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync /* Polishing border */
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync /* Explicit widget centering relatively to it's centering
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync * widget if any or desktop if centering widget is missed. */
3f001a14123f18f268775568f603105a7ed246b8vboxsync VBoxGlobal::centerWidget (this, mCenterWidget, false);
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsyncvoid QIMainDialog::resizeEvent (QResizeEvent *aEvent)
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync /* Adjust the size-grip location for the current resize event */
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync mSizeGrip->move (rect().bottomLeft() - mSizeGrip->rect().bottomLeft());
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync mSizeGrip->move (rect().bottomRight() - mSizeGrip->rect().bottomRight());
3c289d46692c2d35e80d06c51a0f3b96a2cfb88fvboxsync /* Make sure that we only proceed if no
3c289d46692c2d35e80d06c51a0f3b96a2cfb88fvboxsync * popup or other modal widgets are open. */
3c289d46692c2d35e80d06c51a0f3b96a2cfb88fvboxsync (qApp->activeModalWidget() && qApp->activeModalWidget() != this))
3c289d46692c2d35e80d06c51a0f3b96a2cfb88fvboxsync /* Call to base-class: */
3c289d46692c2d35e80d06c51a0f3b96a2cfb88fvboxsync /* Special handling for some keys: */
3c289d46692c2d35e80d06c51a0f3b96a2cfb88fvboxsync /* Special handling for Escape key: */
3c289d46692c2d35e80d06c51a0f3b96a2cfb88fvboxsync /* Special handling for Period key: */
3c289d46692c2d35e80d06c51a0f3b96a2cfb88fvboxsync#endif /* Q_WS_MAC */
3c289d46692c2d35e80d06c51a0f3b96a2cfb88fvboxsync /* Special handling for Return/Enter key: */
3c289d46692c2d35e80d06c51a0f3b96a2cfb88fvboxsync if (((pEvent->modifiers() == Qt::NoModifier) && (pEvent->key() == Qt::Key_Return)) ||
3c289d46692c2d35e80d06c51a0f3b96a2cfb88fvboxsync ((pEvent->modifiers() & Qt::KeypadModifier) && (pEvent->key() == Qt::Key_Enter)))
3c289d46692c2d35e80d06c51a0f3b96a2cfb88fvboxsync if (QPushButton *pCurrentDefault = searchDefaultButton())
3c289d46692c2d35e80d06c51a0f3b96a2cfb88fvboxsync /* Default handling for others: */
3c289d46692c2d35e80d06c51a0f3b96a2cfb88fvboxsync default: break;
3c289d46692c2d35e80d06c51a0f3b96a2cfb88fvboxsync /* Call to base-class: */
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsyncbool QIMainDialog::eventFilter (QObject *aObject, QEvent *aEvent)
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync qobject_cast<QWidget*> (aObject)->window() != this)
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync /* Auto-default button focus-in processor used to move the "default"
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync * button property into the currently focused button. */
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync qobject_cast<QDialogButtonBox*> (aObject->parent())))
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync qobject_cast<QPushButton*> (aObject)->setDefault (aObject != mDefaultButton);
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync mDefaultButton->setDefault (aObject == mDefaultButton);
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync /* Auto-default button focus-out processor used to remove the "default"
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync * button property from the previously focused button. */
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync qobject_cast<QDialogButtonBox*> (aObject->parent())))
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync mDefaultButton->setDefault (aObject != mDefaultButton);
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync qobject_cast<QPushButton*> (aObject)->setDefault (aObject == mDefaultButton);
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsyncQPushButton* QIMainDialog::searchDefaultButton() const
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync /* Search for the first default button in the dialog. */
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync QList<QPushButton*> list = qFindChildren<QPushButton*> (this);
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync qobject_cast<QDialogButtonBox*> (button->parent())))
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsyncvoid QIMainDialog::done (QDialog::DialogCode aResult)
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync /* Set the final result */
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync /* Hide this window */
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync /* And close the window */