UISettingsDialog.cpp revision cb48b678483eed76053da41c3f0f2600eeeed5f4
/* $Id$ */
/** @file
*
* VBox frontends: Qt GUI ("VirtualBox"):
* UISettingsDialog class implementation
*/
/*
* Copyright (C) 2006-2011 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.
*/
/* Global includes */
#include <QProgressBar>
#include <QPushButton>
#include <QStackedWidget>
#include <QTimer>
#include <QCloseEvent>
/* Local includes */
#include "UISettingsDialog.h"
#include "VBoxWarningPane.h"
#include "VBoxGlobal.h"
#include "UIMessageCenter.h"
#include "QIWidgetValidator.h"
#include "VBoxSettingsSelector.h"
#include "UISettingsPage.h"
#include "UIToolBar.h"
#include "UIIconPool.h"
#ifdef Q_WS_MAC
# include "VBoxUtils.h"
# if MAC_LEOPARD_STYLE
# define VBOX_GUI_WITH_TOOLBAR_SETTINGS
# endif /* MAC_LEOPARD_STYLE */
#endif /* Q_WS_MAC */
/* Settings Dialog Constructor: */
/* Parent class: */
/* Protected variables: */
, m_pSelector(0)
, m_pStack(0)
/* Common variables: */
, m_fPolished(false)
, m_fLoaded(false)
, m_fSaved(false)
/* Status bar stuff: */
, m_pStatusBar(new QStackedWidget(this))
/* Process bar stuff: */
, m_pProcessBar(new QProgressBar(this))
, m_fValid(true)
, m_fSilent(true)
, m_pWarningPane(new VBoxWarningPane(this))
/* Whats-this stuff: */
, m_pWhatsThisTimer(new QTimer(this))
{
/* Apply UI decorations: */
#ifdef Q_WS_MAC
/* No status bar on the mac: */
setSizeGripEnabled(false);
setStatusBar(0);
#endif /* Q_WS_MAC */
/* Page-title font is derived from the system font: */
pageTitleFont.setBold(true);
/* Get main grid layout: */
/* No page-title with tool-bar: */
m_pLbTitle->hide();
/* No whats-this with tool-bar: */
m_pLbWhatsThis->hide();
/* Create modern tool-bar selector: */
m_pSelector = new VBoxSettingsToolBarSelector(this);
/* No title in this mode, we change the title of the window: */
pMainLayout->setColumnMinimumWidth(0, 0);
#else
/* Create classical tree-view selector: */
m_pSelector = new VBoxSettingsTreeViewSelector(this);
#endif /* VBOX_GUI_WITH_TOOLBAR_SETTINGS */
/* Creating stack of pages: */
pStackLayout->setContentsMargins(0, 0, 0, 0);
/* Status bar: */
/* Setup process bar stuff: */
/* Setup error & warning stuff: */
/* Setup whatsthis stuff: */
qApp->installEventFilter(this);
m_pWhatsThisTimer->setSingleShot(true);
m_pLbWhatsThis->setAutoFillBackground(true);
/* Set the default button: */
/* Setup connections: */
/* Translate UI: */
}
{
/* Delete selector early! */
delete m_pSelector;
}
void UISettingsDialog::execute()
{
/* Load data: */
loadData();
/* Execute dialog and wait for completion: */
return;
/* Save data: */
saveData();
}
{
/* Get related settings page: */
/* Prepare empty warning & title: */
/* Recorrelate page with others before revalidation: */
/* Revalidate the page: */
/* Compose a message: */
/* Remember validation status: */
}
{
#ifdef Q_WS_MAC
{
/* Switch to the new page first if we are shrinking: */
/* Do the animation: */
/* Switch to the new page last if we are zooming: */
}
::darwinSetShowsResizeIndicator(this, false);
#else
#endif
setWindowTitle(title());
#endif /* VBOX_GUI_WITH_TOOLBAR_SETTINGS */
}
void UISettingsDialog::sltMarkLoaded()
{
m_fLoaded = true;
}
void UISettingsDialog::sltMarkSaved()
{
m_fSaved = true;
}
{
m_pProcessBar->setValue(0);
}
{
{
else
}
}
void UISettingsDialog::loadData()
{
m_fLoaded = false;
}
void UISettingsDialog::saveData()
{
m_fSaved = false;
}
void UISettingsDialog::retranslateUi()
{
/* Translate generated stuff: */
if (!m_fValid)
else if (!m_fSilent)
#ifndef VBOX_GUI_WITH_TOOLBAR_SETTINGS
/* Retranslate current page headline: */
#endif /* VBOX_GUI_WITH_TOOLBAR_SETTINGS */
/* Get the list of validators: */
/* Retranslate all validators: */
for (int i = 0; i < validatorsList.size(); ++i)
{
pValidator->setCaption(m_pSelector->itemTextByPage(qobject_cast<UISettingsPage*>(pValidator->widget())));
}
/* Revalidate all pages to retranslate the warning messages also: */
for (int i = 0; i < validatorsList.size(); ++i)
{
if (!pValidator->isValid())
}
}
{
{
}
}
{
#else
return tr("Settings");
#endif
}
{
/* Do not touching QILabel until dialog is polished
* otherwise it can change its size to undefined: */
if (m_fPolished)
{
else
sltUpdateWhatsThis(true /* got focus? */);
}
}
{
/* Do not touching QILabel until dialog is polished
* otherwise it can change its size to undefined: */
if (m_fPolished)
{
else
sltUpdateWhatsThis(true /* got focus? */);
}
}
const QString &strBigIconDisabled,
const QString &strSmallIcon,
const QString &strSmallIconDisabled,
int cId,
int iParentId /* = -1 */)
{
if (pPage)
{
#ifdef Q_WS_MAC
/* On OSX we add a stretch to the vertical end to make sure the page is
* always top aligned. */
pW->setContentsMargins(0, 0, 0, 0);
pBox->addStretch(0);
#else /* Q_WS_MAC */
#endif /* !Q_WS_MAC */
/* Update process bar: */
m_pProcessBar->setMinimum(0);
}
if (pSettingsPage)
}
{
/* Get validators list: */
/* Detect ERROR presence: */
{
bool fNewValid = true;
for (int i = 0; i < validatorsList.size(); ++i)
{
if (!fNewValid)
{
break;
}
}
/* Try to set the generic error message when invalid
* but no specific message is provided: */
#ifdef Q_WS_MAC
#endif /* Q_WS_MAC */
if (!m_fValid)
return;
}
/* Detect WARNING presence: */
{
setWarning(QString());
bool fNewSilent = true;
for (int i = 0; i < validatorsList.size(); ++i)
{
{
fNewSilent = false;
if (strWarning.isNull())
break;
}
}
/* Try to set the generic error message when invalid
* but no specific message is provided: */
#ifdef Q_WS_MAC
#endif /* Q_WS_MAC */
}
}
{
QWidget *pWhatsThisWidget = 0;
/* If focus had NOT changed: */
if (!fGotFocus)
{
/* We will use the recommended candidate: */
if (m_pWhatsThisCandidate && m_pWhatsThisCandidate != this)
}
/* If focus had changed: */
else
{
/* We will use the focused widget instead: */
}
/* If the given widget lacks the whats-this text, look at its parent: */
while (pWhatsThisWidget && pWhatsThisWidget != this)
{
if (!strWhatsThisText.isEmpty())
break;
}
#ifndef Q_WS_MAC
{
}
if (strWhatsThisText.isEmpty())
#else
#endif
}
void UISettingsDialog::reject()
{
if (m_fLoaded)
QIMainDialog::reject();
}
{
/* Ignore objects which are NOT widgets: */
if (!pObject->isWidgetType())
/* Ignore widgets which window is NOT settings dialog: */
/* Process different event-types: */
{
{
else
break;
}
/* Process focus-in event to update whats-this pane: */
{
sltUpdateWhatsThis(true /* got focus? */);
break;
}
default:
break;
}
/* Base-class processing: */
}
{
/* Base-class processing: */
/* One may think that QWidget::polish() is the right place to do things
* below, but apparently, by the time when QWidget::polish() is called,
* the widget style & layout are not fully done, at least the minimum
* size hint is not properly calculated. Since this is sometimes necessary,
* we provide our own "polish" implementation. */
if (m_fPolished)
return;
m_fPolished = true;
#ifdef Q_WS_MAC
/* Remove all title bar buttons (Buggy Qt): */
::darwinSetHidesAllTitleButtons(this);
/* Set all size policies to ignored: */
/* Activate every single page to get the optimal size: */
{
* available on Mac OS X. Not sure why this happens but this seems to help
* against. */
{
}
m_pStack->setCurrentIndex(i);
/* Now make sure the layout is freshly calculated. */
QSize s = minimumSize();
m_sizeList.insert(0, s);
}
#else /* Q_WS_MAC */
/* Resize to the minimum possible size: */
QSize s = minimumSize();
resize(s);
#endif /* Q_WS_MAC */
}
{
if (m_fLoaded)
else
}
{
QIWidgetValidator *pValidator = new QIWidgetValidator(m_pSelector->itemTextByPage(pPage), pPage, this);
connect(pValidator, SIGNAL(validityChanged(const QIWidgetValidator*)), this, SLOT(sltHandleValidityChanged(const QIWidgetValidator*)));
connect(pValidator, SIGNAL(isValidRequested(QIWidgetValidator*)), this, SLOT(sltRevalidate(QIWidgetValidator*)));
}