UIWizard.cpp revision ca87590cb28f22bccab88dc2f87c5ce2682b1ba1
/* $Id$ */
/** @file
* VBox Qt GUI - UIWizard class implementation.
*/
/*
* Copyright (C) 2009-2012 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 <QAbstractButton>
#include <QLayout>
#include <qmath.h>
/* Local includes: */
#include "UIWizard.h"
#include "UIWizardPage.h"
#include "VBoxGlobal.h"
#include "QIRichTextLabel.h"
#include "UIExtraDataManager.h"
{
bool fIsHideShowDescriptionButtonAvailable = false;
if (iId == 0)
/* But first-run wizard has no such button anyway: */
if (m_type == WizardType_FirstRun)
}
{
/* Handle 1st button: */
if (iId == CustomButton1)
{
/* Cleanup: */
cleanup();
/* Toggle mode: */
switch (m_mode)
{
}
/* Save mode: */
/* Prepare: */
prepare();
}
}
{
#ifdef Q_WS_WIN
/* Hide window icon: */
setWindowIcon(QIcon());
#endif /* Q_WS_WIN */
#ifdef Q_WS_MAC
/* I'm really not sure why there shouldn't be any default button on Mac OS X.
* This prevents the using of Enter to jump to the next page. */
#endif /* Q_WS_MAC */
/* All our wizards would like to have window-modality,
* Under Mac OS it will be represented as Mac OS Sheet. */
/* Setup connections: */
}
void UIWizard::retranslateUi()
{
switch (m_mode)
{
}
}
void UIWizard::retranslatePages()
{
/* Translate all the pages: */
}
{
/* Configure page first: */
/* Add page finally: */
}
{
/* Translate wizard: */
/* Translate wizard pages: */
/* Resize wizard to 'golden ratio': */
/* Notify pages they are ready: */
/* Make sure custom buttons shown even if final page is first to show: */
}
{
/* Remove all the pages: */
{
/* Get enumerated page ID: */
/* Get corresponding page: */
/* Remove page from the wizard: */
/* Delete page finally: */
delete pWizardPage;
}
#ifndef Q_WS_MAC
/* Cleanup watermark: */
if (!m_strWatermarkName.isEmpty())
#endif /* !Q_WS_MAC */
}
void UIWizard::resizeToGoldenRatio()
{
/* Check if wizard is in basic or expert mode: */
if (m_mode == WizardMode_Expert)
{
/* Unfortunately QWizard hides some of useful API in private part,
* and also have few layouting bugs which could be easy fixed
* by that API, so we will use QWizard::restart() method
* to call the same functionality indirectly...
* Early call restart() which is usually goes on show()! */
restart();
/* Now we have correct label size-hint(s) for all the pages.
* We have to make sure all the pages uses maximum available size-hint. */
/* Search for the maximum available size-hint: */
{
}
/* Feat corresponding height: */
/* Use that size-hint for all the pages: */
/* Relayout widgets: */
/* Unfortunately QWizard hides some of useful API in private part,
* BUT it also have few layouting bugs which could be easy fixed
* by that API, so we will use QWizard::restart() method
* to call the same functionality indirectly...
* And now we call restart() after layout activation procedure! */
restart();
/* Resize it to minimum size: */
}
else
{
/* Use some small (!) initial QIRichTextLabel width: */
int iInitialLabelWidth = 200;
/* Resize wizard according that initial width,
* actually there could be other content
* which wants to be wider than that initial width. */
/* Get some (first) of those pages: */
/* Calculate actual label width: */
/* Calculate summary margin length,
* including margins of the page and the wizard: */
/* Get current wizard width and height: */
int iCurrentWizardWidth = width();
int iCurrentWizardHeight = height();
#ifndef Q_WS_MAC
/* We should take into account watermark like its assigned already: */
#endif /* !Q_WS_MAC */
/* Calculating nearest to 'golden ratio' label width: */
#ifndef Q_WS_MAC
/* We should take into account watermark like its assigned already: */
#endif /* !Q_WS_MAC */
/* Choose maximum between current and proposed label width: */
/* Finally resize wizard according new label width,
* taking into account all the content and 'golden ratio' rule: */
}
#ifndef Q_WS_MAC
/* Really assign watermark: */
if (!m_strWatermarkName.isEmpty())
#endif /* !Q_WS_MAC */
}
#ifndef Q_WS_MAC
{
# ifdef Q_WS_WIN
/* There is a Qt bug about Windows7 do NOT match conditions for 'aero' wizard-style,
* so its silently fallbacks to 'modern' one without any notification,
* so QWizard::wizardStyle() returns QWizard::ModernStyle, while using aero, at least partially. */
# endif /* Q_WS_WIN */
)
}
#else
{
}
#endif
{
/* Resize to minimum possible size: */
resize(0, 0);
/* Call to base-class: */
}
{
/* Page margins: */
switch (wizardStyle())
{
case QWizard::ClassicStyle:
{
break;
}
default:
break;
}
}
{
/* Unfortunately QWizard hides some of useful API in private part,
* and also have few layouting bugs which could be easy fixed
* by that API, so we will use QWizard::restart() method
* to call the same functionality indirectly...
* Early call restart() which is usually goes on show()! */
restart();
/* Update QIRichTextLabel(s) text-width(s): */
/* Now we have correct label size-hint(s) for all the pages.
* We have to make sure all the pages uses maximum available size-hint. */
/* Search for the maximum available size-hint: */
{
}
/* Use that size-hint for all the pages: */
/* Relayout widgets: */
/* Unfortunately QWizard hides some of useful API in private part,
* BUT it also have few layouting bugs which could be easy fixed
* by that API, so we will use QWizard::restart() method
* to call the same functionality indirectly...
* And now we call restart() after layout activation procedure! */
restart();
/* Resize it to minimum size: */
}
{
/* Default value: */
double dRatio = 1.6;
#ifdef Q_WS_WIN
switch (wizardStyle())
{
case QWizard::ClassicStyle:
case QWizard::ModernStyle:
/* There is a Qt bug about Windows7 do NOT match conditions for 'aero' wizard-style,
* so its silently fallbacks to 'modern' one without any notification,
* so QWizard::wizardStyle() returns QWizard::ModernStyle, while using aero, at least partially. */
{
dRatio = 2;
break;
}
dRatio = 2.2;
break;
default:
break;
}
#endif /* Q_WS_WIN */
switch (m_type)
{
case WizardType_CloneVM:
dRatio -= 0.4;
break;
case WizardType_NewVD:
case WizardType_CloneVD:
dRatio += 0.1;
break;
dRatio += 0.3;
break;
case WizardType_FirstRun:
dRatio += 0.3;
break;
default:
break;
}
/* Return final result: */
return dRatio;
}
#ifndef Q_WS_MAC
int UIWizard::proposedWatermarkHeight()
{
/* We should calculate suitable height for watermark pixmap,
* for that we have to take into account:
* 1. wizard-layout top-margin (for modern style),
* 2. wizard-header height,
* 3. spacing between wizard-header and wizard-page,
* 4. wizard-page height,
* 5. wizard-layout bottom-margin (for modern style). */
/* Get current application style: */
/* Acquire wizard-layout top-margin: */
int iTopMargin = 0;
if (m_mode == WizardMode_Basic)
{
}
/* Acquire wizard-header height: */
int iTitleHeight = 0;
if (m_mode == WizardMode_Basic)
{
/* We have no direct access to QWizardHeader inside QWizard private data...
* From Qt sources it seems title font is hardcoded as current font point-size + 4: */
}
/* Acquire spacing between wizard-header and wizard-page: */
int iMarginBetweenTitleAndPage = 0;
if (m_mode == WizardMode_Basic)
{
/* We have no direct access to margin between QWizardHeader and wizard-pages...
* From Qt sources it seems its hardcoded as just 7 pixels: */
}
/* Acquire wizard-page height: */
int iPageHeight = 0;
if (page(0))
{
}
/* Acquire wizard-layout bottom-margin: */
int iBottomMargin = 0;
/* Finally, calculate summary height: */
}
void UIWizard::assignWatermarkHelper()
{
/* Create initial watermark: */
/* Convert watermark to image which
* allows to manage pixel data directly: */
/* Use the right-top watermark pixel as frame color: */
/* Create final image on the basis of incoming, applying the rules: */
QImage imgWatermarkNew(imgWatermark.width(), qMax(imgWatermark.height(), proposedWatermarkHeight()), imgWatermark.format());
for (int y = 0; y < imgWatermarkNew.height(); ++y)
{
for (int x = 0; x < imgWatermarkNew.width(); ++x)
{
/* Border rule 1 - draw border for ClassicStyle */
/* Border rule 2 - draw border for ModernStyle */
/* Horizontal extension rule - use last used color */
/* Vertical extension rule - use last used color */
/* Common extension rule - use last used color */
imgWatermarkNew.setPixel(x, y, imgWatermark.pixel(imgWatermark.width() - 1, imgWatermark.height() - 1));
/* Else just copy color */
else
}
}
/* Convert processed image to pixmap and assign it to wizard's watermark. */
}
#endif /* !Q_WS_MAC */