QIMainDialog.cpp revision 4be39ac606cc80de5b28e745a94b099557387ff7
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync * VBox frontends: Qt GUI ("VirtualBox"):
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync * VirtualBox Qt extensions: QIMainDialog class implementation
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync * Copyright (C) 2008 Sun Microsystems, Inc.
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 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync * Clara, CA 95054 USA or visit http://www.sun.com if you need
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync * additional information or have any questions.
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync/* Qt includes */
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsyncQIMainDialog::QIMainDialog (QWidget *aParent /* = 0 */,
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync AssertMsg (!mEventLoop, ("exec is called recursively!\n"));
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync /* Reset the result code */
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync bool deleteOnClose = testAttribute (Qt::WA_DeleteOnClose);
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync bool wasShowModal = testAttribute (Qt::WA_ShowModal);
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync /* Create a local event loop */
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync /* Show the window */
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync /* A guard to ourself for the case we destroy ourself. */
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync /* Start the event loop. This blocks. */
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync /* Delete the event loop */
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync /* Are we valid anymore? */
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync /* Set the old show modal attribute */
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync /* Delete us in the case we should do so on close */
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync delete this;
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync /* Return the final result */
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsyncvoid QIMainDialog::setFileForProxyIcon (const QString& aFile)
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsyncvoid QIMainDialog::setSizeGripEnabled (bool aEnabled)
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsyncvoid QIMainDialog::setDefaultButton (QPushButton* aButton)
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync /* Exit from the event loop if there is any and we are changing our state
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync * from visible to invisible. */
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync Qt::KeyboardModifiers currentModifiers = qApp->keyboardModifiers();
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync /* Create a drag object we can use */
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync /* Set the appropriate url data */
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync data->setUrls (QList<QUrl>() << QUrl::fromLocalFile (mFileForProxyIcon));
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync /* Make a nice looking DnD icon */
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync QPixmap cursorPixmap (::darwinCreateDragPixmap (QPixmap (windowIcon().pixmap (16, 16)), fi.fileName()));
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync drag->setHotSpot (QPoint (5, cursorPixmap.height() - 5));
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync /* Start the DnD action */
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync return true;
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync /* Create the proxy icon menu */
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync /* Add the file with the disk icon to the menu */
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync /* Create some nice looking menu out of the other
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync * directory parts. */
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync /* Show the menu */
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync menu.exec (QPoint (QCursor::pos().x() - 20, frameGeometry().y() - 5));
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync return true;
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync#endif /* Q_WS_MAC */
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. */
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync 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());
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);
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync /* Bug in Qt below 4.4.2. The key events are send to the current
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync * window even if a menu is shown & has the focus. See
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync * http://trolltech.com/developer/task-tracker/index_html?method=entry&id=214681. */
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync return true;
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync#endif /* defined (Q_WS_MAC) && (QT_VERSION < 0x040402) */
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync /* Make sure that we only proceed if no
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync * popup or other modal widgets are open. */
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync (qApp->activeModalWidget() && qApp->activeModalWidget() != this))
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync QKeyEvent *event = static_cast<QKeyEvent*> (aEvent);
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync (event->modifiers() & Qt::KeypadModifier && event->key() == Qt::Key_Enter))
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync QPushButton *currentDefault = searchDefaultButton();
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync /* We handle this, so return true after
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync return true;
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync return true;
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 */
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsyncvoid QIMainDialog::setResult (QDialog::DialogCode aRescode)
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync QString path = mFileForProxyIcon.left (mFileForProxyIcon.indexOf (aAction->text())) + aAction->text();
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync /* Check for the first item */
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync /* @todo: vboxGlobal().openURL (path); should be able to open paths */
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync process.start ("/usr/bin/open", QStringList() << path, QIODevice::ReadOnly);
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync#else /* Q_WS_MAC */
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync#endif /* Q_WS_MAC */