4be39ac606cc80de5b28e745a94b099557387ff7vboxsync/* $Id$ */
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync/** @file
4d00469edbec74de8ddcfe9556235a6edb6c4ee6vboxsync * VBox Qt GUI - Qt extensions: QIMainDialog class implementation.
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync */
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync/*
4d00469edbec74de8ddcfe9556235a6edb6c4ee6vboxsync * Copyright (C) 2008-2015 Oracle Corporation
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync *
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.
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync */
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync
a9b62afc62b28da7a1a77f34259f8013892d9664vboxsync#ifdef VBOX_WITH_PRECOMPILED_HEADERS
a9b62afc62b28da7a1a77f34259f8013892d9664vboxsync# include <precomp.h>
a9b62afc62b28da7a1a77f34259f8013892d9664vboxsync#else /* !VBOX_WITH_PRECOMPILED_HEADERS */
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync
4d00469edbec74de8ddcfe9556235a6edb6c4ee6vboxsync/* Qt includes: */
a9b62afc62b28da7a1a77f34259f8013892d9664vboxsync# include <QDir>
a9b62afc62b28da7a1a77f34259f8013892d9664vboxsync# include <QUrl>
a9b62afc62b28da7a1a77f34259f8013892d9664vboxsync# include <QMenu>
4d00469edbec74de8ddcfe9556235a6edb6c4ee6vboxsync# include <QProcess>
4d00469edbec74de8ddcfe9556235a6edb6c4ee6vboxsync# include <QSizeGrip>
4d00469edbec74de8ddcfe9556235a6edb6c4ee6vboxsync# include <QEventLoop>
a9b62afc62b28da7a1a77f34259f8013892d9664vboxsync# include <QPushButton>
4d00469edbec74de8ddcfe9556235a6edb6c4ee6vboxsync# include <QApplication>
a9b62afc62b28da7a1a77f34259f8013892d9664vboxsync# include <QDialogButtonBox>
a9b62afc62b28da7a1a77f34259f8013892d9664vboxsync
4d00469edbec74de8ddcfe9556235a6edb6c4ee6vboxsync/* GUI includes: */
4d00469edbec74de8ddcfe9556235a6edb6c4ee6vboxsync# include "QIMainDialog.h"
4d00469edbec74de8ddcfe9556235a6edb6c4ee6vboxsync# include "VBoxGlobal.h"
4d00469edbec74de8ddcfe9556235a6edb6c4ee6vboxsync# include "VBoxUtils.h"
a9b62afc62b28da7a1a77f34259f8013892d9664vboxsync
4d00469edbec74de8ddcfe9556235a6edb6c4ee6vboxsync/* Other VBox includes: */
4d00469edbec74de8ddcfe9556235a6edb6c4ee6vboxsync# include <iprt/assert.h>
7e3a9a30ad06aaa937b5bfe12eef894f23091ec4vboxsync
4d00469edbec74de8ddcfe9556235a6edb6c4ee6vboxsync#endif /* !VBOX_WITH_PRECOMPILED_HEADERS */
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync
4d00469edbec74de8ddcfe9556235a6edb6c4ee6vboxsyncQIMainDialog::QIMainDialog(QWidget *pParent /* = 0 */,
4d00469edbec74de8ddcfe9556235a6edb6c4ee6vboxsync Qt::WindowFlags enmFlags /* = Qt::Dialog */,
4d00469edbec74de8ddcfe9556235a6edb6c4ee6vboxsync bool fIsAutoCentering /* = true */)
4d00469edbec74de8ddcfe9556235a6edb6c4ee6vboxsync : QMainWindow(pParent, enmFlags)
4d00469edbec74de8ddcfe9556235a6edb6c4ee6vboxsync , m_fIsAutoCentering(fIsAutoCentering)
4d00469edbec74de8ddcfe9556235a6edb6c4ee6vboxsync , m_fPolished(false)
4d00469edbec74de8ddcfe9556235a6edb6c4ee6vboxsync , m_enmResult(QDialog::Rejected)
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync{
4d00469edbec74de8ddcfe9556235a6edb6c4ee6vboxsync /* Install event-filter: */
4d00469edbec74de8ddcfe9556235a6edb6c4ee6vboxsync qApp->installEventFilter(this);
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync}
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync
4d00469edbec74de8ddcfe9556235a6edb6c4ee6vboxsyncQDialog::DialogCode QIMainDialog::exec(bool fApplicationModal /* = true */)
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync{
ff58db82d953628895c2060fb6f9169b5cc8cd19vboxsync /* Check for the recursive run: */
4d00469edbec74de8ddcfe9556235a6edb6c4ee6vboxsync AssertMsgReturn(!m_pEventLoop, ("QIMainDialog::exec() is called recursively!\n"), QDialog::Rejected);
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync
ff58db82d953628895c2060fb6f9169b5cc8cd19vboxsync /* Reset the result code: */
ff58db82d953628895c2060fb6f9169b5cc8cd19vboxsync setResult(QDialog::Rejected);
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync
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': */
ff58db82d953628895c2060fb6f9169b5cc8cd19vboxsync setAttribute(Qt::WA_DeleteOnClose, false);
ff58db82d953628895c2060fb6f9169b5cc8cd19vboxsync
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);
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync
4d00469edbec74de8ddcfe9556235a6edb6c4ee6vboxsync /* Show ourself: */
4d00469edbec74de8ddcfe9556235a6edb6c4ee6vboxsync show();
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync
4d00469edbec74de8ddcfe9556235a6edb6c4ee6vboxsync /* Create a local event-loop: */
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync {
4d00469edbec74de8ddcfe9556235a6edb6c4ee6vboxsync QEventLoop eventLoop;
4d00469edbec74de8ddcfe9556235a6edb6c4ee6vboxsync m_pEventLoop = &eventLoop;
4d00469edbec74de8ddcfe9556235a6edb6c4ee6vboxsync
4d00469edbec74de8ddcfe9556235a6edb6c4ee6vboxsync /* Guard ourself for the case
4d00469edbec74de8ddcfe9556235a6edb6c4ee6vboxsync * we destroyed ourself in our event-loop: */
4d00469edbec74de8ddcfe9556235a6edb6c4ee6vboxsync QPointer<QIMainDialog> guard = this;
4d00469edbec74de8ddcfe9556235a6edb6c4ee6vboxsync
4d00469edbec74de8ddcfe9556235a6edb6c4ee6vboxsync /* Start the blocking event-loop: */
4d00469edbec74de8ddcfe9556235a6edb6c4ee6vboxsync eventLoop.exec();
4d00469edbec74de8ddcfe9556235a6edb6c4ee6vboxsync
4d00469edbec74de8ddcfe9556235a6edb6c4ee6vboxsync /* Are we still valid? */
4d00469edbec74de8ddcfe9556235a6edb6c4ee6vboxsync if (guard.isNull())
4d00469edbec74de8ddcfe9556235a6edb6c4ee6vboxsync return QDialog::Rejected;
4d00469edbec74de8ddcfe9556235a6edb6c4ee6vboxsync
4d00469edbec74de8ddcfe9556235a6edb6c4ee6vboxsync m_pEventLoop = 0;
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync }
4d00469edbec74de8ddcfe9556235a6edb6c4ee6vboxsync
4d00469edbec74de8ddcfe9556235a6edb6c4ee6vboxsync /* Save the result code early (we can delete ourself on close): */
4d00469edbec74de8ddcfe9556235a6edb6c4ee6vboxsync const QDialog::DialogCode enmResultCode = result();
4d00469edbec74de8ddcfe9556235a6edb6c4ee6vboxsync
4d00469edbec74de8ddcfe9556235a6edb6c4ee6vboxsync /* Return old modality: */
4d00469edbec74de8ddcfe9556235a6edb6c4ee6vboxsync setWindowModality(oldModality);
4d00469edbec74de8ddcfe9556235a6edb6c4ee6vboxsync
4d00469edbec74de8ddcfe9556235a6edb6c4ee6vboxsync /* Reset attribute to previous value: */
4d00469edbec74de8ddcfe9556235a6edb6c4ee6vboxsync setAttribute(Qt::WA_DeleteOnClose, fOldDeleteOnClose);
4d00469edbec74de8ddcfe9556235a6edb6c4ee6vboxsync /* Delete ourself if we should do that on close: */
4d00469edbec74de8ddcfe9556235a6edb6c4ee6vboxsync if (fOldDeleteOnClose)
4d00469edbec74de8ddcfe9556235a6edb6c4ee6vboxsync delete this;
4d00469edbec74de8ddcfe9556235a6edb6c4ee6vboxsync
4d00469edbec74de8ddcfe9556235a6edb6c4ee6vboxsync /* Return the result code: */
4d00469edbec74de8ddcfe9556235a6edb6c4ee6vboxsync return enmResultCode;
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync}
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync
4d00469edbec74de8ddcfe9556235a6edb6c4ee6vboxsyncQPushButton* QIMainDialog::defaultButton() const
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync{
4d00469edbec74de8ddcfe9556235a6edb6c4ee6vboxsync return m_pDefaultButton;
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync}
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync
4d00469edbec74de8ddcfe9556235a6edb6c4ee6vboxsyncvoid QIMainDialog::setDefaultButton(QPushButton *pButton)
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync{
4d00469edbec74de8ddcfe9556235a6edb6c4ee6vboxsync m_pDefaultButton = pButton;
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync}
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync
4d00469edbec74de8ddcfe9556235a6edb6c4ee6vboxsyncbool QIMainDialog::isSizeGripEnabled() const
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync{
4d00469edbec74de8ddcfe9556235a6edb6c4ee6vboxsync return m_pSizeGrip;
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync}
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync
4d00469edbec74de8ddcfe9556235a6edb6c4ee6vboxsyncvoid QIMainDialog::setSizeGripEnabled(bool fEnabled)
3f001a14123f18f268775568f603105a7ed246b8vboxsync{
4d00469edbec74de8ddcfe9556235a6edb6c4ee6vboxsync /* Create if missed: */
4d00469edbec74de8ddcfe9556235a6edb6c4ee6vboxsync if (!m_pSizeGrip && fEnabled)
4d00469edbec74de8ddcfe9556235a6edb6c4ee6vboxsync {
4d00469edbec74de8ddcfe9556235a6edb6c4ee6vboxsync m_pSizeGrip = new QSizeGrip(this);
4d00469edbec74de8ddcfe9556235a6edb6c4ee6vboxsync m_pSizeGrip->resize(m_pSizeGrip->sizeHint());
4d00469edbec74de8ddcfe9556235a6edb6c4ee6vboxsync m_pSizeGrip->show();
4d00469edbec74de8ddcfe9556235a6edb6c4ee6vboxsync }
4d00469edbec74de8ddcfe9556235a6edb6c4ee6vboxsync /* Destroy if present: */
4d00469edbec74de8ddcfe9556235a6edb6c4ee6vboxsync else if (m_pSizeGrip && !fEnabled)
4d00469edbec74de8ddcfe9556235a6edb6c4ee6vboxsync {
4d00469edbec74de8ddcfe9556235a6edb6c4ee6vboxsync delete m_pSizeGrip;
4d00469edbec74de8ddcfe9556235a6edb6c4ee6vboxsync m_pSizeGrip = 0;
4d00469edbec74de8ddcfe9556235a6edb6c4ee6vboxsync }
3f001a14123f18f268775568f603105a7ed246b8vboxsync}
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync
4d00469edbec74de8ddcfe9556235a6edb6c4ee6vboxsyncvoid QIMainDialog::setVisible(bool fVisible)
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync{
4d00469edbec74de8ddcfe9556235a6edb6c4ee6vboxsync /* Call to base-class: */
4d00469edbec74de8ddcfe9556235a6edb6c4ee6vboxsync QMainWindow::setVisible(fVisible);
4d00469edbec74de8ddcfe9556235a6edb6c4ee6vboxsync
4d00469edbec74de8ddcfe9556235a6edb6c4ee6vboxsync /* Exit from the event-loop if there is any and
4d00469edbec74de8ddcfe9556235a6edb6c4ee6vboxsync * we are changing our state from visible to hidden. */
4d00469edbec74de8ddcfe9556235a6edb6c4ee6vboxsync if (m_pEventLoop && !fVisible)
4d00469edbec74de8ddcfe9556235a6edb6c4ee6vboxsync m_pEventLoop->exit();
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync}
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync
4d00469edbec74de8ddcfe9556235a6edb6c4ee6vboxsyncbool QIMainDialog::event(QEvent *pEvent)
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync{
4d00469edbec74de8ddcfe9556235a6edb6c4ee6vboxsync /* Depending on event-type: */
4d00469edbec74de8ddcfe9556235a6edb6c4ee6vboxsync switch (pEvent->type())
4d00469edbec74de8ddcfe9556235a6edb6c4ee6vboxsync {
4d00469edbec74de8ddcfe9556235a6edb6c4ee6vboxsync case QEvent::Polish:
4d00469edbec74de8ddcfe9556235a6edb6c4ee6vboxsync {
4d00469edbec74de8ddcfe9556235a6edb6c4ee6vboxsync /* Initially search for the default-button: */
4d00469edbec74de8ddcfe9556235a6edb6c4ee6vboxsync m_pDefaultButton = searchDefaultButton();
4d00469edbec74de8ddcfe9556235a6edb6c4ee6vboxsync break;
4d00469edbec74de8ddcfe9556235a6edb6c4ee6vboxsync }
4d00469edbec74de8ddcfe9556235a6edb6c4ee6vboxsync default:
4d00469edbec74de8ddcfe9556235a6edb6c4ee6vboxsync break;
4d00469edbec74de8ddcfe9556235a6edb6c4ee6vboxsync }
4d00469edbec74de8ddcfe9556235a6edb6c4ee6vboxsync
4d00469edbec74de8ddcfe9556235a6edb6c4ee6vboxsync /* Call to base-class: */
4d00469edbec74de8ddcfe9556235a6edb6c4ee6vboxsync return QMainWindow::event(pEvent);
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync}
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync
4d00469edbec74de8ddcfe9556235a6edb6c4ee6vboxsyncvoid QIMainDialog::showEvent(QShowEvent *pEvent)
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync{
4d00469edbec74de8ddcfe9556235a6edb6c4ee6vboxsync /* Make sure we should polish dialog: */
4d00469edbec74de8ddcfe9556235a6edb6c4ee6vboxsync if (m_fPolished)
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync return;
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync
4d00469edbec74de8ddcfe9556235a6edb6c4ee6vboxsync /* Call to polish-event: */
4d00469edbec74de8ddcfe9556235a6edb6c4ee6vboxsync polishEvent(pEvent);
4d00469edbec74de8ddcfe9556235a6edb6c4ee6vboxsync
4d00469edbec74de8ddcfe9556235a6edb6c4ee6vboxsync /* Mark dialog as polished: */
4d00469edbec74de8ddcfe9556235a6edb6c4ee6vboxsync m_fPolished = true;
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync}
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync
4d00469edbec74de8ddcfe9556235a6edb6c4ee6vboxsyncvoid QIMainDialog::polishEvent(QShowEvent*)
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync{
4d00469edbec74de8ddcfe9556235a6edb6c4ee6vboxsync /* Explicit centering according to our parent: */
4d00469edbec74de8ddcfe9556235a6edb6c4ee6vboxsync if (m_fIsAutoCentering)
4d00469edbec74de8ddcfe9556235a6edb6c4ee6vboxsync VBoxGlobal::centerWidget(this, parentWidget(), false);
4d00469edbec74de8ddcfe9556235a6edb6c4ee6vboxsync}
4d00469edbec74de8ddcfe9556235a6edb6c4ee6vboxsync
4d00469edbec74de8ddcfe9556235a6edb6c4ee6vboxsyncvoid QIMainDialog::resizeEvent(QResizeEvent *pEvent)
4d00469edbec74de8ddcfe9556235a6edb6c4ee6vboxsync{
4d00469edbec74de8ddcfe9556235a6edb6c4ee6vboxsync /* Call to base-class: */
4d00469edbec74de8ddcfe9556235a6edb6c4ee6vboxsync QMainWindow::resizeEvent(pEvent);
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync
4d00469edbec74de8ddcfe9556235a6edb6c4ee6vboxsync /* Adjust the size-grip location for the current resize event: */
4d00469edbec74de8ddcfe9556235a6edb6c4ee6vboxsync if (m_pSizeGrip)
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync {
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync if (isRightToLeft())
4d00469edbec74de8ddcfe9556235a6edb6c4ee6vboxsync m_pSizeGrip->move(rect().bottomLeft() - m_pSizeGrip->rect().bottomLeft());
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync else
4d00469edbec74de8ddcfe9556235a6edb6c4ee6vboxsync m_pSizeGrip->move(rect().bottomRight() - m_pSizeGrip->rect().bottomRight());
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync }
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync}
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync
3c289d46692c2d35e80d06c51a0f3b96a2cfb88fvboxsyncvoid QIMainDialog::keyPressEvent(QKeyEvent *pEvent)
3c289d46692c2d35e80d06c51a0f3b96a2cfb88fvboxsync{
3c289d46692c2d35e80d06c51a0f3b96a2cfb88fvboxsync /* Make sure that we only proceed if no
3c289d46692c2d35e80d06c51a0f3b96a2cfb88fvboxsync * popup or other modal widgets are open. */
3c289d46692c2d35e80d06c51a0f3b96a2cfb88fvboxsync if (qApp->activePopupWidget() ||
3c289d46692c2d35e80d06c51a0f3b96a2cfb88fvboxsync (qApp->activeModalWidget() && qApp->activeModalWidget() != this))
3c289d46692c2d35e80d06c51a0f3b96a2cfb88fvboxsync {
3c289d46692c2d35e80d06c51a0f3b96a2cfb88fvboxsync /* Call to base-class: */
3c289d46692c2d35e80d06c51a0f3b96a2cfb88fvboxsync return QMainWindow::keyPressEvent(pEvent);
3c289d46692c2d35e80d06c51a0f3b96a2cfb88fvboxsync }
3c289d46692c2d35e80d06c51a0f3b96a2cfb88fvboxsync
3c289d46692c2d35e80d06c51a0f3b96a2cfb88fvboxsync /* Special handling for some keys: */
3c289d46692c2d35e80d06c51a0f3b96a2cfb88fvboxsync switch (pEvent->key())
3c289d46692c2d35e80d06c51a0f3b96a2cfb88fvboxsync {
3c289d46692c2d35e80d06c51a0f3b96a2cfb88fvboxsync /* Special handling for Escape key: */
3c289d46692c2d35e80d06c51a0f3b96a2cfb88fvboxsync case Qt::Key_Escape:
3c289d46692c2d35e80d06c51a0f3b96a2cfb88fvboxsync {
3c289d46692c2d35e80d06c51a0f3b96a2cfb88fvboxsync if (pEvent->modifiers() == Qt::NoModifier)
3c289d46692c2d35e80d06c51a0f3b96a2cfb88fvboxsync {
3c289d46692c2d35e80d06c51a0f3b96a2cfb88fvboxsync reject();
3c289d46692c2d35e80d06c51a0f3b96a2cfb88fvboxsync return;
3c289d46692c2d35e80d06c51a0f3b96a2cfb88fvboxsync }
3c289d46692c2d35e80d06c51a0f3b96a2cfb88fvboxsync break;
3c289d46692c2d35e80d06c51a0f3b96a2cfb88fvboxsync }
3c289d46692c2d35e80d06c51a0f3b96a2cfb88fvboxsync#ifdef Q_WS_MAC
3c289d46692c2d35e80d06c51a0f3b96a2cfb88fvboxsync /* Special handling for Period key: */
3c289d46692c2d35e80d06c51a0f3b96a2cfb88fvboxsync case Qt::Key_Period:
3c289d46692c2d35e80d06c51a0f3b96a2cfb88fvboxsync {
3c289d46692c2d35e80d06c51a0f3b96a2cfb88fvboxsync if (pEvent->modifiers() == Qt::ControlModifier)
3c289d46692c2d35e80d06c51a0f3b96a2cfb88fvboxsync {
3c289d46692c2d35e80d06c51a0f3b96a2cfb88fvboxsync reject();
3c289d46692c2d35e80d06c51a0f3b96a2cfb88fvboxsync return;
3c289d46692c2d35e80d06c51a0f3b96a2cfb88fvboxsync }
3c289d46692c2d35e80d06c51a0f3b96a2cfb88fvboxsync break;
3c289d46692c2d35e80d06c51a0f3b96a2cfb88fvboxsync }
3c289d46692c2d35e80d06c51a0f3b96a2cfb88fvboxsync#endif /* Q_WS_MAC */
3c289d46692c2d35e80d06c51a0f3b96a2cfb88fvboxsync /* Special handling for Return/Enter key: */
3c289d46692c2d35e80d06c51a0f3b96a2cfb88fvboxsync case Qt::Key_Return:
3c289d46692c2d35e80d06c51a0f3b96a2cfb88fvboxsync case Qt::Key_Enter:
3c289d46692c2d35e80d06c51a0f3b96a2cfb88fvboxsync {
3c289d46692c2d35e80d06c51a0f3b96a2cfb88fvboxsync if (((pEvent->modifiers() == Qt::NoModifier) && (pEvent->key() == Qt::Key_Return)) ||
3c289d46692c2d35e80d06c51a0f3b96a2cfb88fvboxsync ((pEvent->modifiers() & Qt::KeypadModifier) && (pEvent->key() == Qt::Key_Enter)))
3c289d46692c2d35e80d06c51a0f3b96a2cfb88fvboxsync {
3c289d46692c2d35e80d06c51a0f3b96a2cfb88fvboxsync if (QPushButton *pCurrentDefault = searchDefaultButton())
3c289d46692c2d35e80d06c51a0f3b96a2cfb88fvboxsync {
3c289d46692c2d35e80d06c51a0f3b96a2cfb88fvboxsync pCurrentDefault->animateClick();
3c289d46692c2d35e80d06c51a0f3b96a2cfb88fvboxsync return;
3c289d46692c2d35e80d06c51a0f3b96a2cfb88fvboxsync }
3c289d46692c2d35e80d06c51a0f3b96a2cfb88fvboxsync }
3c289d46692c2d35e80d06c51a0f3b96a2cfb88fvboxsync break;
3c289d46692c2d35e80d06c51a0f3b96a2cfb88fvboxsync }
3c289d46692c2d35e80d06c51a0f3b96a2cfb88fvboxsync /* Default handling for others: */
3c289d46692c2d35e80d06c51a0f3b96a2cfb88fvboxsync default: break;
3c289d46692c2d35e80d06c51a0f3b96a2cfb88fvboxsync }
4d00469edbec74de8ddcfe9556235a6edb6c4ee6vboxsync
3c289d46692c2d35e80d06c51a0f3b96a2cfb88fvboxsync /* Call to base-class: */
3c289d46692c2d35e80d06c51a0f3b96a2cfb88fvboxsync return QMainWindow::keyPressEvent(pEvent);
3c289d46692c2d35e80d06c51a0f3b96a2cfb88fvboxsync}
3c289d46692c2d35e80d06c51a0f3b96a2cfb88fvboxsync
4d00469edbec74de8ddcfe9556235a6edb6c4ee6vboxsyncbool QIMainDialog::eventFilter(QObject *pObject, QEvent *pEvent)
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync{
4d00469edbec74de8ddcfe9556235a6edb6c4ee6vboxsync /* Skip for inactive window: */
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync if (!isActiveWindow())
4d00469edbec74de8ddcfe9556235a6edb6c4ee6vboxsync return QMainWindow::eventFilter(pObject, pEvent);
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync
4d00469edbec74de8ddcfe9556235a6edb6c4ee6vboxsync /* Skip for children of other than this one window: */
4d00469edbec74de8ddcfe9556235a6edb6c4ee6vboxsync if (qobject_cast<QWidget*>(pObject) &&
4d00469edbec74de8ddcfe9556235a6edb6c4ee6vboxsync qobject_cast<QWidget*>(pObject)->window() != this)
4d00469edbec74de8ddcfe9556235a6edb6c4ee6vboxsync return QMainWindow::eventFilter(pObject, pEvent);
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync
4d00469edbec74de8ddcfe9556235a6edb6c4ee6vboxsync /* Depending on event-type: */
4d00469edbec74de8ddcfe9556235a6edb6c4ee6vboxsync switch (pEvent->type())
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync {
4d00469edbec74de8ddcfe9556235a6edb6c4ee6vboxsync /* Auto-default-button focus-in processor used to move the "default"
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync * button property into the currently focused button. */
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync case QEvent::FocusIn:
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync {
4d00469edbec74de8ddcfe9556235a6edb6c4ee6vboxsync if (qobject_cast<QPushButton*>(pObject) &&
4d00469edbec74de8ddcfe9556235a6edb6c4ee6vboxsync (pObject->parent() == centralWidget() ||
4d00469edbec74de8ddcfe9556235a6edb6c4ee6vboxsync qobject_cast<QDialogButtonBox*>(pObject->parent())))
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync {
4d00469edbec74de8ddcfe9556235a6edb6c4ee6vboxsync qobject_cast<QPushButton*>(pObject)->setDefault(pObject != m_pDefaultButton);
4d00469edbec74de8ddcfe9556235a6edb6c4ee6vboxsync if (m_pDefaultButton)
4d00469edbec74de8ddcfe9556235a6edb6c4ee6vboxsync m_pDefaultButton->setDefault(pObject == m_pDefaultButton);
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync }
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync break;
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync }
4d00469edbec74de8ddcfe9556235a6edb6c4ee6vboxsync /* Auto-default-button focus-out processor used to remove the "default"
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync * button property from the previously focused button. */
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync case QEvent::FocusOut:
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync {
4d00469edbec74de8ddcfe9556235a6edb6c4ee6vboxsync if (qobject_cast<QPushButton*>(pObject) &&
4d00469edbec74de8ddcfe9556235a6edb6c4ee6vboxsync (pObject->parent() == centralWidget() ||
4d00469edbec74de8ddcfe9556235a6edb6c4ee6vboxsync qobject_cast<QDialogButtonBox*>(pObject->parent())))
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync {
4d00469edbec74de8ddcfe9556235a6edb6c4ee6vboxsync if (m_pDefaultButton)
4d00469edbec74de8ddcfe9556235a6edb6c4ee6vboxsync m_pDefaultButton->setDefault(pObject != m_pDefaultButton);
4d00469edbec74de8ddcfe9556235a6edb6c4ee6vboxsync qobject_cast<QPushButton*>(pObject)->setDefault(pObject == m_pDefaultButton);
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync }
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync break;
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync }
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync default:
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync break;
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync }
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync
4d00469edbec74de8ddcfe9556235a6edb6c4ee6vboxsync /* Call to base-class: */
4d00469edbec74de8ddcfe9556235a6edb6c4ee6vboxsync return QMainWindow::eventFilter(pObject, pEvent);
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync}
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync
4d00469edbec74de8ddcfe9556235a6edb6c4ee6vboxsyncQPushButton* QIMainDialog::searchDefaultButton() const
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync{
4d00469edbec74de8ddcfe9556235a6edb6c4ee6vboxsync /* Search for the first default-button in the dialog: */
4d00469edbec74de8ddcfe9556235a6edb6c4ee6vboxsync QList<QPushButton*> list = qFindChildren<QPushButton*>(this);
4d00469edbec74de8ddcfe9556235a6edb6c4ee6vboxsync foreach (QPushButton *pButton, list)
4d00469edbec74de8ddcfe9556235a6edb6c4ee6vboxsync if (pButton->isDefault() &&
4d00469edbec74de8ddcfe9556235a6edb6c4ee6vboxsync (pButton->parent() == centralWidget() ||
4d00469edbec74de8ddcfe9556235a6edb6c4ee6vboxsync qobject_cast<QDialogButtonBox*>(pButton->parent())))
4d00469edbec74de8ddcfe9556235a6edb6c4ee6vboxsync return pButton;
4d00469edbec74de8ddcfe9556235a6edb6c4ee6vboxsync return 0;
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync}
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync
4d00469edbec74de8ddcfe9556235a6edb6c4ee6vboxsyncvoid QIMainDialog::done(QDialog::DialogCode enmResult)
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync{
4d00469edbec74de8ddcfe9556235a6edb6c4ee6vboxsync /* Set the final result: */
4d00469edbec74de8ddcfe9556235a6edb6c4ee6vboxsync setResult(enmResult);
4d00469edbec74de8ddcfe9556235a6edb6c4ee6vboxsync /* Hide: */
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync hide();
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync}
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync