QIMainDialog.cpp revision f0bd3112311126f4b8aa45d059a4c75d9abaecf3
/* $Id$ */
/** @file
*
* VBox frontends: Qt GUI ("VirtualBox"):
* VirtualBox Qt extensions: QIMainDialog class implementation
*/
/*
* Copyright (C) 2008 Oracle Corporation
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* General Public License (GPL) as published by the Free Software
* Foundation, in version 2 as it comes in the "COPYING" file of the
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
*/
#include "QIMainDialog.h"
#include "VBoxUtils.h"
#include "VBoxGlobal.h"
/* Qt includes */
#include <QProcess>
#include <QEventLoop>
#include <QApplication>
#include <QDir>
#include <QUrl>
#include <QMenu>
#include <QSizeGrip>
#include <QPushButton>
#include <QDialogButtonBox>
, mPolished (false)
, mIsAutoCentering (true)
, mCenterWidget (aParent)
{
qApp->installEventFilter (this);
}
{
/* Reset the result code */
/* Create a local event loop */
mEventLoop = new QEventLoop();
/* Show the window */
show();
/* A guard to ourself for the case we destroy ourself. */
/* Start the event loop. This blocks. */
mEventLoop->exec();
/* Delete the event loop */
delete mEventLoop;
/* Are we valid anymore? */
/* Set the old show modal attribute */
/* Delete us in the case we should do so on close */
if (deleteOnClose)
delete this;
/* Return the final result */
return res;
}
{
return mRescode;
}
{
}
{
return mFileForProxyIcon;
}
{
{
}
delete mSizeGrip;
}
bool QIMainDialog::isSizeGripEnabled() const
{
return mSizeGrip;
}
{
}
{
return mDefaultButton;
}
{
}
{
/* Exit from the event loop if there is any and we are changing our state
* from visible to invisible. */
if (mEventLoop && !aVisible)
mEventLoop->exit();
}
{
{
#ifdef Q_WS_MAC
{
{
if (!mFileForProxyIcon.isEmpty())
{
/* Create a drag object we can use */
/* Set the appropriate url data */
/* Make a nice looking DnD icon */
QPixmap cursorPixmap (::darwinCreateDragPixmap (QPixmap (windowIcon().pixmap (16, 16)), fi.fileName()));
/* Start the DnD action */
return true;
}
}
#if QT_VERSION < 0x040400
#else
#endif
{
if (!mFileForProxyIcon.isEmpty())
{
/* Create the proxy icon menu */
/* Add the file with the disk icon to the menu */
/* Create some nice looking menu out of the other
* directory parts. */
do
{
else
}
/* Show the menu */
return true;
}
}
break;
}
#endif /* Q_WS_MAC */
{
/* Initially search for the default button. */
break;
}
default:
break;
}
}
{
/* Polishing border */
if (mPolished)
return;
mPolished = true;
/* Explicit widget centering relatively to it's centering
* widget if any or desktop if centering widget is missed. */
if (mIsAutoCentering)
}
{
/* Adjust the size-grip location for the current resize event */
if (mSizeGrip)
{
if (isRightToLeft())
else
}
}
{
if (!isActiveWindow())
{
/* Auto-default button focus-in processor used to move the "default"
* button property into the currently focused button. */
{
{
if (mDefaultButton)
}
break;
}
/* Auto-default button focus-out processor used to remove the "default"
* button property from the previously focused button. */
{
{
if (mDefaultButton)
}
break;
}
{
/* Bug in Qt below 4.4.2. The key events are send to the current
* window even if a menu is shown & has the focus. See
if (::darwinIsMenuOpen())
return true;
#endif /* defined (Q_WS_MAC) && (QT_VERSION < 0x040402) */
/* Make sure that we only proceed if no
* popup or other modal widgets are open. */
if (qApp->activePopupWidget() ||
break;
#ifdef Q_WS_MAC
reject();
else
#endif
{
{
case Qt::Key_Return:
{
if (currentDefault)
{
/* We handle this, so return true after
* that. */
return true;
}
break;
}
case Qt::Key_Escape:
{
reject();
return true;
break;
}
}
}
}
default:
break;
}
}
{
/* Search for the first default button in the dialog. */
return button;
return NULL;
}
void QIMainDialog::accept()
{
}
void QIMainDialog::reject()
{
}
{
/* Set the final result */
/* Hide this window */
hide();
/* And close the window */
close();
}
{
}
{
#ifdef Q_WS_MAC
if (!mFileForProxyIcon.isEmpty())
{
QString path = mFileForProxyIcon.left (mFileForProxyIcon.indexOf (aAction->text())) + aAction->text();
/* Check for the first item */
if (mFileForProxyIcon != path)
{
/* @todo: vboxGlobal().openURL (path); should be able to open paths */
}
}
#else /* Q_WS_MAC */
#endif /* Q_WS_MAC */
}