4d00469edbec74de8ddcfe9556235a6edb6c4ee6vboxsync * VBox Qt GUI - Qt extensions: QIMainDialog class implementation.
4d00469edbec74de8ddcfe9556235a6edb6c4ee6vboxsync * Copyright (C) 2008-2015 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 */
4d00469edbec74de8ddcfe9556235a6edb6c4ee6vboxsync/* Qt includes: */
4d00469edbec74de8ddcfe9556235a6edb6c4ee6vboxsync/* GUI includes: */
4d00469edbec74de8ddcfe9556235a6edb6c4ee6vboxsync/* Other VBox includes: */
4d00469edbec74de8ddcfe9556235a6edb6c4ee6vboxsync#endif /* !VBOX_WITH_PRECOMPILED_HEADERS */
4d00469edbec74de8ddcfe9556235a6edb6c4ee6vboxsyncQIMainDialog::QIMainDialog(QWidget *pParent /* = 0 */,
4d00469edbec74de8ddcfe9556235a6edb6c4ee6vboxsync /* Install event-filter: */
4d00469edbec74de8ddcfe9556235a6edb6c4ee6vboxsyncQDialog::DialogCode QIMainDialog::exec(bool fApplicationModal /* = true */)
ff58db82d953628895c2060fb6f9169b5cc8cd19vboxsync /* Check for the recursive run: */
4d00469edbec74de8ddcfe9556235a6edb6c4ee6vboxsync AssertMsgReturn(!m_pEventLoop, ("QIMainDialog::exec() is called recursively!\n"), QDialog::Rejected);
ff58db82d953628895c2060fb6f9169b5cc8cd19vboxsync /* Reset the result code: */
4d00469edbec74de8ddcfe9556235a6edb6c4ee6vboxsync /* Should we delete ourself on close in theory? */
4d00469edbec74de8ddcfe9556235a6edb6c4ee6vboxsync const bool fOldDeleteOnClose = testAttribute(Qt::WA_DeleteOnClose);
4d00469edbec74de8ddcfe9556235a6edb6c4ee6vboxsync /* For the exec() time, set this attribute to 'false': */
4d00469edbec74de8ddcfe9556235a6edb6c4ee6vboxsync /* Which is the current window-modality? */
4d00469edbec74de8ddcfe9556235a6edb6c4ee6vboxsync const Qt::WindowModality oldModality = windowModality();
4d00469edbec74de8ddcfe9556235a6edb6c4ee6vboxsync /* For the exec() time, set this attribute to 'window-modal' or 'application-modal': */
4d00469edbec74de8ddcfe9556235a6edb6c4ee6vboxsync setWindowModality(!fApplicationModal ? Qt::WindowModal : Qt::ApplicationModal);
4d00469edbec74de8ddcfe9556235a6edb6c4ee6vboxsync /* Show ourself: */
4d00469edbec74de8ddcfe9556235a6edb6c4ee6vboxsync /* Create a local event-loop: */
4d00469edbec74de8ddcfe9556235a6edb6c4ee6vboxsync /* Guard ourself for the case
4d00469edbec74de8ddcfe9556235a6edb6c4ee6vboxsync * we destroyed ourself in our event-loop: */
4d00469edbec74de8ddcfe9556235a6edb6c4ee6vboxsync /* Start the blocking event-loop: */
4d00469edbec74de8ddcfe9556235a6edb6c4ee6vboxsync /* Are we still valid? */
4d00469edbec74de8ddcfe9556235a6edb6c4ee6vboxsync /* Save the result code early (we can delete ourself on close): */
4d00469edbec74de8ddcfe9556235a6edb6c4ee6vboxsync const QDialog::DialogCode enmResultCode = result();
4d00469edbec74de8ddcfe9556235a6edb6c4ee6vboxsync /* Return old modality: */
4d00469edbec74de8ddcfe9556235a6edb6c4ee6vboxsync /* Reset attribute to previous value: */
4d00469edbec74de8ddcfe9556235a6edb6c4ee6vboxsync setAttribute(Qt::WA_DeleteOnClose, fOldDeleteOnClose);
4d00469edbec74de8ddcfe9556235a6edb6c4ee6vboxsync /* Delete ourself if we should do that on close: */
4d00469edbec74de8ddcfe9556235a6edb6c4ee6vboxsync delete this;
4d00469edbec74de8ddcfe9556235a6edb6c4ee6vboxsync /* Return the result code: */
4d00469edbec74de8ddcfe9556235a6edb6c4ee6vboxsyncvoid QIMainDialog::setDefaultButton(QPushButton *pButton)
4d00469edbec74de8ddcfe9556235a6edb6c4ee6vboxsyncvoid QIMainDialog::setSizeGripEnabled(bool fEnabled)
4d00469edbec74de8ddcfe9556235a6edb6c4ee6vboxsync /* Create if missed: */
4d00469edbec74de8ddcfe9556235a6edb6c4ee6vboxsync /* Destroy if present: */
4d00469edbec74de8ddcfe9556235a6edb6c4ee6vboxsync /* Call to base-class: */
4d00469edbec74de8ddcfe9556235a6edb6c4ee6vboxsync /* Exit from the event-loop if there is any and
4d00469edbec74de8ddcfe9556235a6edb6c4ee6vboxsync * we are changing our state from visible to hidden. */
4d00469edbec74de8ddcfe9556235a6edb6c4ee6vboxsync /* Depending on event-type: */
4d00469edbec74de8ddcfe9556235a6edb6c4ee6vboxsync /* Initially search for the default-button: */
4d00469edbec74de8ddcfe9556235a6edb6c4ee6vboxsync /* Call to base-class: */
4d00469edbec74de8ddcfe9556235a6edb6c4ee6vboxsync /* Make sure we should polish dialog: */
4d00469edbec74de8ddcfe9556235a6edb6c4ee6vboxsync /* Call to polish-event: */
4d00469edbec74de8ddcfe9556235a6edb6c4ee6vboxsync /* Mark dialog as polished: */
4d00469edbec74de8ddcfe9556235a6edb6c4ee6vboxsync /* Explicit centering according to our parent: */
4d00469edbec74de8ddcfe9556235a6edb6c4ee6vboxsync VBoxGlobal::centerWidget(this, parentWidget(), false);
4d00469edbec74de8ddcfe9556235a6edb6c4ee6vboxsyncvoid QIMainDialog::resizeEvent(QResizeEvent *pEvent)
4d00469edbec74de8ddcfe9556235a6edb6c4ee6vboxsync /* Call to base-class: */
4d00469edbec74de8ddcfe9556235a6edb6c4ee6vboxsync /* Adjust the size-grip location for the current resize event: */
4d00469edbec74de8ddcfe9556235a6edb6c4ee6vboxsync m_pSizeGrip->move(rect().bottomLeft() - m_pSizeGrip->rect().bottomLeft());
4d00469edbec74de8ddcfe9556235a6edb6c4ee6vboxsync m_pSizeGrip->move(rect().bottomRight() - m_pSizeGrip->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: */
4d00469edbec74de8ddcfe9556235a6edb6c4ee6vboxsyncbool QIMainDialog::eventFilter(QObject *pObject, QEvent *pEvent)
4d00469edbec74de8ddcfe9556235a6edb6c4ee6vboxsync /* Skip for inactive window: */
4d00469edbec74de8ddcfe9556235a6edb6c4ee6vboxsync /* Skip for children of other than this one window: */
4d00469edbec74de8ddcfe9556235a6edb6c4ee6vboxsync /* Depending on event-type: */
4d00469edbec74de8ddcfe9556235a6edb6c4ee6vboxsync /* Auto-default-button focus-in processor used to move the "default"
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync * button property into the currently focused button. */
4d00469edbec74de8ddcfe9556235a6edb6c4ee6vboxsync qobject_cast<QDialogButtonBox*>(pObject->parent())))
4d00469edbec74de8ddcfe9556235a6edb6c4ee6vboxsync qobject_cast<QPushButton*>(pObject)->setDefault(pObject != m_pDefaultButton);
4d00469edbec74de8ddcfe9556235a6edb6c4ee6vboxsync m_pDefaultButton->setDefault(pObject == m_pDefaultButton);
4d00469edbec74de8ddcfe9556235a6edb6c4ee6vboxsync /* Auto-default-button focus-out processor used to remove the "default"
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync * button property from the previously focused button. */
4d00469edbec74de8ddcfe9556235a6edb6c4ee6vboxsync qobject_cast<QDialogButtonBox*>(pObject->parent())))
4d00469edbec74de8ddcfe9556235a6edb6c4ee6vboxsync m_pDefaultButton->setDefault(pObject != m_pDefaultButton);
4d00469edbec74de8ddcfe9556235a6edb6c4ee6vboxsync qobject_cast<QPushButton*>(pObject)->setDefault(pObject == m_pDefaultButton);
4d00469edbec74de8ddcfe9556235a6edb6c4ee6vboxsync /* Call to base-class: */
4d00469edbec74de8ddcfe9556235a6edb6c4ee6vboxsyncQPushButton* QIMainDialog::searchDefaultButton() const
4d00469edbec74de8ddcfe9556235a6edb6c4ee6vboxsync /* Search for the first default-button in the dialog: */
4d00469edbec74de8ddcfe9556235a6edb6c4ee6vboxsync QList<QPushButton*> list = qFindChildren<QPushButton*>(this);
4d00469edbec74de8ddcfe9556235a6edb6c4ee6vboxsync qobject_cast<QDialogButtonBox*>(pButton->parent())))
4d00469edbec74de8ddcfe9556235a6edb6c4ee6vboxsyncvoid QIMainDialog::done(QDialog::DialogCode enmResult)
4d00469edbec74de8ddcfe9556235a6edb6c4ee6vboxsync /* Set the final result: */
4d00469edbec74de8ddcfe9556235a6edb6c4ee6vboxsync /* Hide: */