QIMainDialog.cpp revision e0b4007776ecc4b476e118a0d29ed5fa68667f18
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync * VBox frontends: Qt GUI ("VirtualBox"):
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync * VirtualBox Qt extensions: QIMainDialog class implementation
e64031e20c39650a7bc902a3e1aba613b9415deevboxsync * Copyright (C) 2008 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.
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync/* Qt includes */
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsyncQIMainDialog::QIMainDialog (QWidget *aParent /* = 0 */,
ff58db82d953628895c2060fb6f9169b5cc8cd19vboxsync /* Check for the recursive run: */
ff58db82d953628895c2060fb6f9169b5cc8cd19vboxsync AssertMsg(!mEventLoop, ("QIMainDialog::exec() is called recursively!\n"));
ff58db82d953628895c2060fb6f9169b5cc8cd19vboxsync /* Reset the result code: */
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 bool fWasShowModal = testAttribute(Qt::WA_ShowModal);
ff58db82d953628895c2060fb6f9169b5cc8cd19vboxsync /* Create a local event-loop: */
ff58db82d953628895c2060fb6f9169b5cc8cd19vboxsync /* Show the window: */
ff58db82d953628895c2060fb6f9169b5cc8cd19vboxsync /* A guard to ourself for the case we destroy ourself: */
ff58db82d953628895c2060fb6f9169b5cc8cd19vboxsync /* Start the event-loop: */
ff58db82d953628895c2060fb6f9169b5cc8cd19vboxsync /* Check if dialog is still valid: */
ff58db82d953628895c2060fb6f9169b5cc8cd19vboxsync /* Prepare result: */
ff58db82d953628895c2060fb6f9169b5cc8cd19vboxsync /* Restore old show-modal attribute: */
ff58db82d953628895c2060fb6f9169b5cc8cd19vboxsync /* Return the final result: */
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsyncvoid QIMainDialog::setFileForProxyIcon (const QString& aFile)
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsyncvoid QIMainDialog::setSizeGripEnabled (bool aEnabled)
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsyncvoid QIMainDialog::setDefaultButton (QPushButton* aButton)
3f001a14123f18f268775568f603105a7ed246b8vboxsyncvoid QIMainDialog::setAutoCenteringEnabled(bool fIsAutoCentering)
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. */
f0bd3112311126f4b8aa45d059a4c75d9abaecf3vboxsync action->setIcon (vboxGlobal().icon(QFileInfo (dir, "")));
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. */
3f001a14123f18f268775568f603105a7ed246b8vboxsync 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 */