QIMainDialog.cpp revision 7e3a9a30ad06aaa937b5bfe12eef894f23091ec4
4be39ac606cc80de5b28e745a94b099557387ff7vboxsync/* $Id$ */
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync/** @file
d34409ad02ea0d28e08a6c4b089a412fdb3b4c9cvboxsync * VBox Qt GUI - VirtualBox Qt extensions: QIMainDialog class implementation.
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync */
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync/*
c7814cf6e1240a519cbec0441e033d0e2470ed00vboxsync * Copyright (C) 2008-2012 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
a9b62afc62b28da7a1a77f34259f8013892d9664vboxsync# include "QIMainDialog.h"
a9b62afc62b28da7a1a77f34259f8013892d9664vboxsync# include "VBoxUtils.h"
a9b62afc62b28da7a1a77f34259f8013892d9664vboxsync# include "VBoxGlobal.h"
a9b62afc62b28da7a1a77f34259f8013892d9664vboxsync
a9b62afc62b28da7a1a77f34259f8013892d9664vboxsync# include <iprt/assert.h>
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync/* Qt includes */
a9b62afc62b28da7a1a77f34259f8013892d9664vboxsync# include <QProcess>
a9b62afc62b28da7a1a77f34259f8013892d9664vboxsync# include <QEventLoop>
a9b62afc62b28da7a1a77f34259f8013892d9664vboxsync# include <QApplication>
a9b62afc62b28da7a1a77f34259f8013892d9664vboxsync# include <QDir>
a9b62afc62b28da7a1a77f34259f8013892d9664vboxsync# include <QUrl>
a9b62afc62b28da7a1a77f34259f8013892d9664vboxsync# include <QMenu>
a9b62afc62b28da7a1a77f34259f8013892d9664vboxsync# include <QPushButton>
a9b62afc62b28da7a1a77f34259f8013892d9664vboxsync# include <QDialogButtonBox>
a9b62afc62b28da7a1a77f34259f8013892d9664vboxsync
a9b62afc62b28da7a1a77f34259f8013892d9664vboxsync#endif /* !VBOX_WITH_PRECOMPILED_HEADERS */
a9b62afc62b28da7a1a77f34259f8013892d9664vboxsync
7e3a9a30ad06aaa937b5bfe12eef894f23091ec4vboxsync#include <QSizeGrip>
7e3a9a30ad06aaa937b5bfe12eef894f23091ec4vboxsync
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsyncQIMainDialog::QIMainDialog (QWidget *aParent /* = 0 */,
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync Qt::WindowFlags aFlags /* = Qt::Dialog */)
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync : QMainWindow (aParent, aFlags)
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync , mRescode (QDialog::Rejected)
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync , mPolished (false)
3f001a14123f18f268775568f603105a7ed246b8vboxsync , mIsAutoCentering (true)
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync , mCenterWidget (aParent)
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync{
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync qApp->installEventFilter (this);
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync}
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsyncQDialog::DialogCode QIMainDialog::exec()
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync{
ff58db82d953628895c2060fb6f9169b5cc8cd19vboxsync /* Check for the recursive run: */
ff58db82d953628895c2060fb6f9169b5cc8cd19vboxsync AssertMsg(!mEventLoop, ("QIMainDialog::exec() is called recursively!\n"));
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync
ff58db82d953628895c2060fb6f9169b5cc8cd19vboxsync /* Reset the result code: */
ff58db82d953628895c2060fb6f9169b5cc8cd19vboxsync setResult(QDialog::Rejected);
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync
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 setAttribute(Qt::WA_DeleteOnClose, false);
ff58db82d953628895c2060fb6f9169b5cc8cd19vboxsync bool fWasShowModal = testAttribute(Qt::WA_ShowModal);
ff58db82d953628895c2060fb6f9169b5cc8cd19vboxsync setAttribute(Qt::WA_ShowModal, true);
ff58db82d953628895c2060fb6f9169b5cc8cd19vboxsync
ff58db82d953628895c2060fb6f9169b5cc8cd19vboxsync /* Create a local event-loop: */
ff58db82d953628895c2060fb6f9169b5cc8cd19vboxsync QEventLoop eventLoop;
ff58db82d953628895c2060fb6f9169b5cc8cd19vboxsync mEventLoop = &eventLoop;
ff58db82d953628895c2060fb6f9169b5cc8cd19vboxsync /* Show the window: */
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync show();
ff58db82d953628895c2060fb6f9169b5cc8cd19vboxsync /* A guard to ourself for the case we destroy ourself: */
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync QPointer<QIMainDialog> guard = this;
ff58db82d953628895c2060fb6f9169b5cc8cd19vboxsync /* Start the event-loop: */
ff58db82d953628895c2060fb6f9169b5cc8cd19vboxsync eventLoop.exec();
ff58db82d953628895c2060fb6f9169b5cc8cd19vboxsync /* Check if dialog is still valid: */
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync if (guard.isNull())
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync return QDialog::Rejected;
ff58db82d953628895c2060fb6f9169b5cc8cd19vboxsync mEventLoop = 0;
ff58db82d953628895c2060fb6f9169b5cc8cd19vboxsync /* Prepare result: */
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync QDialog::DialogCode res = result();
ff58db82d953628895c2060fb6f9169b5cc8cd19vboxsync /* Restore old show-modal attribute: */
ff58db82d953628895c2060fb6f9169b5cc8cd19vboxsync setAttribute(Qt::WA_ShowModal, fWasShowModal);
ff58db82d953628895c2060fb6f9169b5cc8cd19vboxsync /* Return the final result: */
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync return res;
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync}
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsyncQDialog::DialogCode QIMainDialog::result() const
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync{
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync return mRescode;
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync}
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsyncvoid QIMainDialog::setSizeGripEnabled (bool aEnabled)
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync{
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync if (!mSizeGrip && aEnabled)
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync {
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync mSizeGrip = new QSizeGrip (this);
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync mSizeGrip->resize (mSizeGrip->sizeHint());
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync mSizeGrip->show();
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync }
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync else if (mSizeGrip && !aEnabled)
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync delete mSizeGrip;
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync}
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsyncbool QIMainDialog::isSizeGripEnabled() const
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync{
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync return mSizeGrip;
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync}
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsyncvoid QIMainDialog::setDefaultButton (QPushButton* aButton)
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync{
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync mDefaultButton = aButton;
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync}
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsyncQPushButton* QIMainDialog::defaultButton() const
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync{
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync return mDefaultButton;
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync}
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync
3f001a14123f18f268775568f603105a7ed246b8vboxsyncvoid QIMainDialog::setAutoCenteringEnabled(bool fIsAutoCentering)
3f001a14123f18f268775568f603105a7ed246b8vboxsync{
3f001a14123f18f268775568f603105a7ed246b8vboxsync mIsAutoCentering = fIsAutoCentering;
3f001a14123f18f268775568f603105a7ed246b8vboxsync}
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsyncvoid QIMainDialog::setVisible (bool aVisible)
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync{
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync QMainWindow::setVisible (aVisible);
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync /* Exit from the event loop if there is any and we are changing our state
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync * from visible to invisible. */
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync if (mEventLoop && !aVisible)
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync mEventLoop->exit();
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync}
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsyncbool QIMainDialog::event (QEvent *aEvent)
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync{
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync switch (aEvent->type())
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync {
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync case QEvent::Polish:
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync {
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync /* Initially search for the default button. */
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync mDefaultButton = searchDefaultButton();
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync break;
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync }
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync default:
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync break;
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync }
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync return QMainWindow::event (aEvent);
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync}
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsyncvoid QIMainDialog::showEvent (QShowEvent *aEvent)
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync{
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync QMainWindow::showEvent (aEvent);
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync /* Polishing border */
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync if (mPolished)
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync return;
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync mPolished = true;
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync /* Explicit widget centering relatively to it's centering
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync * widget if any or desktop if centering widget is missed. */
3f001a14123f18f268775568f603105a7ed246b8vboxsync if (mIsAutoCentering)
3f001a14123f18f268775568f603105a7ed246b8vboxsync VBoxGlobal::centerWidget (this, mCenterWidget, false);
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync}
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsyncvoid QIMainDialog::resizeEvent (QResizeEvent *aEvent)
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync{
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync QMainWindow::resizeEvent (aEvent);
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync /* Adjust the size-grip location for the current resize event */
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync if (mSizeGrip)
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync {
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync if (isRightToLeft())
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync mSizeGrip->move (rect().bottomLeft() - mSizeGrip->rect().bottomLeft());
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync else
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync mSizeGrip->move (rect().bottomRight() - mSizeGrip->rect().bottomRight());
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync aEvent->accept();
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 }
3c289d46692c2d35e80d06c51a0f3b96a2cfb88fvboxsync /* Call to base-class: */
3c289d46692c2d35e80d06c51a0f3b96a2cfb88fvboxsync return QMainWindow::keyPressEvent(pEvent);
3c289d46692c2d35e80d06c51a0f3b96a2cfb88fvboxsync}
3c289d46692c2d35e80d06c51a0f3b96a2cfb88fvboxsync
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsyncbool QIMainDialog::eventFilter (QObject *aObject, QEvent *aEvent)
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync{
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync if (!isActiveWindow())
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync return QMainWindow::eventFilter (aObject, aEvent);
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync if (qobject_cast<QWidget*> (aObject) &&
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync qobject_cast<QWidget*> (aObject)->window() != this)
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync return QMainWindow::eventFilter (aObject, aEvent);
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync switch (aEvent->type())
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync {
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync /* Auto-default button focus-in processor used to move the "default"
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync * button property into the currently focused button. */
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync case QEvent::FocusIn:
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync {
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync if (qobject_cast<QPushButton*> (aObject) &&
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync (aObject->parent() == centralWidget() ||
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync qobject_cast<QDialogButtonBox*> (aObject->parent())))
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync {
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync qobject_cast<QPushButton*> (aObject)->setDefault (aObject != mDefaultButton);
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync if (mDefaultButton)
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync mDefaultButton->setDefault (aObject == mDefaultButton);
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync }
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync break;
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync }
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync /* Auto-default button focus-out processor used to remove the "default"
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync * button property from the previously focused button. */
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync case QEvent::FocusOut:
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync {
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync if (qobject_cast<QPushButton*> (aObject) &&
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync (aObject->parent() == centralWidget() ||
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync qobject_cast<QDialogButtonBox*> (aObject->parent())))
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync {
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync if (mDefaultButton)
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync mDefaultButton->setDefault (aObject != mDefaultButton);
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync qobject_cast<QPushButton*> (aObject)->setDefault (aObject == mDefaultButton);
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync }
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync break;
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync }
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync default:
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync break;
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync }
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync return QMainWindow::eventFilter (aObject, aEvent);
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync}
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsyncQPushButton* QIMainDialog::searchDefaultButton() const
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync{
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync /* Search for the first default button in the dialog. */
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync QList<QPushButton*> list = qFindChildren<QPushButton*> (this);
12ec5aac02dd8816cf19a6e018e8cea6fed03d37vboxsync foreach (QPushButton *button, list)
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync if (button->isDefault() &&
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync (button->parent() == centralWidget() ||
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync qobject_cast<QDialogButtonBox*> (button->parent())))
12ec5aac02dd8816cf19a6e018e8cea6fed03d37vboxsync return button;
12ec5aac02dd8816cf19a6e018e8cea6fed03d37vboxsync return NULL;
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync}
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsyncvoid QIMainDialog::accept()
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync{
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync done (QDialog::Accepted);
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync}
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsyncvoid QIMainDialog::reject()
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync{
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync done (QDialog::Rejected);
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync}
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsyncvoid QIMainDialog::done (QDialog::DialogCode aResult)
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync{
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync /* Set the final result */
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync setResult (aResult);
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync /* Hide this window */
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync hide();
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync /* And close the window */
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync close();
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync}
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsyncvoid QIMainDialog::setResult (QDialog::DialogCode aRescode)
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync{
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync mRescode = aRescode;
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync}
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync