VirtualBox

Ignore:
Timestamp:
Apr 25, 2018 9:36:00 AM (7 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
122269
Message:

FE/Qt: bugref:9049: Full and heavy cleanup for UIWizard and move it to VBoxGlobal library.

Location:
trunk/src/VBox/Frontends/VirtualBox
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/Makefile.kmk

    r71948 r72009  
    568568        src/widgets/graphics/UIGraphicsToolBar.h \
    569569        src/widgets/graphics/UIGraphicsTextPane.h \
    570         src/wizards/UIWizard.h \
    571570        src/wizards/UIWizardPage.h \
    572571        src/wizards/newvm/UIWizardNewVM.h \
     
    675674        src/selector/UIActionPoolSelector.h \
    676675        src/selector/UIVirtualBoxEventHandler.h \
     676        src/wizards/UIWizard.h \
    677677        src/widgets/UIBootTable.h \
    678678        src/widgets/UIFilePathSelector.h \
     
    774774        src/selector/UIActionPoolSelector.h \
    775775        src/selector/UIVirtualBoxEventHandler.h \
     776        src/wizards/UIWizard.h \
    776777        src/widgets/UIBootTable.h \
    777778        src/widgets/UIFilePathSelector.h \
     
    10671068        src/widgets/graphics/UIGraphicsToolBar.cpp \
    10681069        src/widgets/graphics/UIGraphicsTextPane.cpp \
    1069         src/wizards/UIWizard.cpp \
    10701070        src/wizards/UIWizardPage.cpp \
    10711071        src/wizards/newvm/UIWizardNewVM.cpp \
     
    12131213        src/selector/UIVirtualBoxEventHandler.cpp \
    12141214        src/settings/UISettingsDefs.cpp \
     1215        src/wizards/UIWizard.cpp \
    12151216        src/widgets/UIBootTable.cpp \
    12161217        src/widgets/UIFilePathSelector.cpp \
     
    13381339        src/selector/UIVirtualBoxEventHandler.cpp \
    13391340        src/settings/UISettingsDefs.cpp \
     1341        src/wizards/UIWizard.cpp \
    13401342        src/widgets/UIBootTable.cpp \
    13411343        src/widgets/UIFilePathSelector.cpp \
  • trunk/src/VBox/Frontends/VirtualBox/src/wizards/UIWizard.cpp

    r71355 r72009  
    55
    66/*
    7  * Copyright (C) 2009-2017 Oracle Corporation
     7 * Copyright (C) 2009-2018 Oracle Corporation
    88 *
    99 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    3535#endif /* !VBOX_WITH_PRECOMPILED_HEADERS */
    3636
    37 #include <qmath.h>
    38 
    39 
    40 void UIWizard::sltCurrentIdChanged(int iId)
    41 {
    42     /* Hide/show description button disabled by default: */
    43     bool fIsHideShowDescriptionButtonAvailable = false;
    44     /* Enable hide/show description button for 1st page: */
    45     if (iId == 0)
    46         fIsHideShowDescriptionButtonAvailable = true;
    47     /* But first-run wizard has no such button anyway: */
    48     if (m_type == WizardType_FirstRun)
    49         fIsHideShowDescriptionButtonAvailable = false;
    50     /* Set a flag for hide/show description button finally: */
    51     setOption(QWizard::HaveCustomButton1, fIsHideShowDescriptionButtonAvailable);
    52 }
    53 
    54 void UIWizard::sltCustomButtonClicked(int iId)
    55 {
    56     /* Handle 1st button: */
    57     if (iId == CustomButton1)
    58     {
    59         /* Cleanup: */
    60         cleanup();
    61 
    62         /* Toggle mode: */
    63         switch (m_mode)
    64         {
    65             case WizardMode_Basic:  m_mode = WizardMode_Expert; break;
    66             case WizardMode_Expert: m_mode = WizardMode_Basic;  break;
    67             default: AssertMsgFailed(("Invalid mode: %d", m_mode)); break;
    68         }
    69         /* Save mode: */
    70         gEDataManager->setModeForWizardType(m_type, m_mode);
    71 
    72         /* Prepare: */
    73         prepare();
    74     }
    75 }
    76 
    77 UIWizard::UIWizard(QWidget *pParent, WizardType type, WizardMode mode /* = WizardMode_Auto */)
     37/* Qt includes: */
     38#include <QtMath>
     39
     40
     41void UIWizard::prepare()
     42{
     43    /* Translate wizard: */
     44    retranslateUi();
     45    /* Translate wizard pages: */
     46    retranslatePages();
     47
     48    /* Resize wizard to 'golden ratio': */
     49    resizeToGoldenRatio();
     50
     51    /* Notify pages they are ready: */
     52    QList<int> ids = pageIds();
     53    for (int i = 0; i < ids.size(); ++i)
     54        qobject_cast<UIWizardPage*>(page(ids[i]))->markReady();
     55
     56    /* Make sure custom buttons shown even if final page is first to show: */
     57    sltCurrentIdChanged(startId());
     58}
     59
     60UIWizard::UIWizard(QWidget *pParent, WizardType enmType, WizardMode enmMode /* = WizardMode_Auto */)
    7861    : QIWithRetranslateUI<QWizard>(pParent)
    79     , m_type(type)
    80     , m_mode(mode == WizardMode_Auto ? gEDataManager->modeForWizardType(m_type) : mode)
     62    , m_enmType(enmType)
     63    , m_enmMode(enmMode == WizardMode_Auto ? gEDataManager->modeForWizardType(m_enmType) : enmMode)
    8164{
    8265#ifdef VBOX_WS_WIN
    8366    /* Hide window icon: */
    8467    setWindowIcon(QIcon());
    85 #endif /* VBOX_WS_WIN */
     68#endif
    8669
    8770#ifdef VBOX_WS_MAC
    88     /* Since wizards are now represented as Mac OS X Sheets
    89      * we would like to have possibility to cancel them. */
     71    // WORKAROUND:
     72    // Since wizards are now represented as Mac OS X Sheets
     73    // we would like to have possibility to cancel them.
    9074    setOption(QWizard::NoCancelButton, false);
    91     /* I'm really not sure why there shouldn't be any default button on Mac OS X.
    92      * This prevents the using of Enter to jump to the next page. */
     75
     76    // WORKAROUND:
     77    // I'm really not sure why there shouldn't be any default button on Mac OS X.
     78    // This prevents the using of Enter to jump to the next page.
    9379    setOptions(options() ^ QWizard::NoDefaultButton);
    9480#endif /* VBOX_WS_MAC */
    9581
    96     /* All our wizards would like to have window-modality,
    97      * Under Mac OS it will be represented as Mac OS Sheet. */
     82    /* Using window-modality: */
    9883    setWindowModality(Qt::WindowModal);
    9984
     
    10691{
    10792    /* Translate basic/expert button: */
    108     switch (m_mode)
     93    switch (m_enmMode)
    10994    {
    11095        case WizardMode_Basic:
     
    116101            button(QWizard::CustomButton1)->setToolTip(tr("Switch to <nobr><b>Guided Mode</b></nobr>, a step-by-step dialog with detailed explanations."));
    117102            break;
    118         default: AssertMsgFailed(("Invalid mode: %d", m_mode)); break;
    119     }
    120 }
    121 
    122 void UIWizard::retranslatePages()
    123 {
    124     /* Translate all the pages: */
    125     QList<int> ids = pageIds();
    126     for (int i = 0; i < ids.size(); ++i)
    127         qobject_cast<UIWizardPage*>(page(ids[i]))->retranslate();
     103        default:
     104            AssertMsgFailed(("Invalid mode: %d", m_enmMode));
     105            break;
     106    }
     107}
     108
     109void UIWizard::showEvent(QShowEvent *pEvent)
     110{
     111    /* Resize to minimum possible size: */
     112    resize(0, 0);
     113
     114    /* Call to base-class: */
     115    QWizard::showEvent(pEvent);
    128116}
    129117
     
    136124}
    137125
    138 void UIWizard::prepare()
    139 {
    140     /* Translate wizard: */
    141     retranslateUi();
    142     /* Translate wizard pages: */
    143     retranslatePages();
    144 
    145     /* Resize wizard to 'golden ratio': */
    146     resizeToGoldenRatio();
    147 
    148     /* Notify pages they are ready: */
    149     QList<int> ids = pageIds();
    150     for (int i = 0; i < ids.size(); ++i)
    151         qobject_cast<UIWizardPage*>(page(ids[i]))->markReady();
    152 
    153     /* Make sure custom buttons shown even if final page is first to show: */
    154     sltCurrentIdChanged(startId());
    155 }
    156 
    157126void UIWizard::cleanup()
    158127{
    159128    /* Remove all the pages: */
    160     QList<int> ids = pageIds();
     129    const QList<int> ids = pageIds();
    161130    for (int i = ids.size() - 1; i >= 0 ; --i)
    162131    {
    163132        /* Get enumerated page ID: */
    164         int iId = ids[i];
     133        const int iId = ids.at(i);
    165134        /* Get corresponding page: */
    166135        QWizardPage *pWizardPage = page(iId);
     
    176145    if (!m_strWatermarkName.isEmpty())
    177146        setPixmap(QWizard::WatermarkPixmap, QPixmap());
    178 #endif /* !VBOX_WS_MAC */
     147#endif
    179148}
    180149
     
    182151{
    183152    /* Check if wizard is in basic or expert mode: */
    184     if (m_mode == WizardMode_Expert)
    185     {
    186         /* Unfortunately QWizard hides some of useful API in private part,
    187          * and also have few layouting bugs which could be easy fixed
    188          * by that API, so we will use QWizard::restart() method
    189          * to call the same functionality indirectly...
    190          * Early call restart() which is usually goes on show()! */
     153    if (m_enmMode == WizardMode_Expert)
     154    {
     155        // WORKAROUND:
     156        // Unfortunately QWizard hides some of useful API in private part,
     157        // and also have few layouting bugs which could be easy fixed
     158        // by that API, so we will use QWizard::restart() method
     159        // to call the same functionality indirectly...
     160        // Early call restart() which is usually goes on show()!
    191161        restart();
    192162
    193         /* Now we have correct label size-hint(s) for all the pages.
    194          * We have to make sure all the pages uses maximum available size-hint. */
     163        // WORKAROUND:
     164        // Now we have correct label size-hint(s) for all the pages.
     165        // We have to make sure all the pages uses maximum available size-hint.
    195166        QSize maxOfSizeHints;
    196167        QList<UIWizardPage*> pages = findChildren<UIWizardPage*>();
     
    214185            pLayout->activate();
    215186
    216         /* Unfortunately QWizard hides some of useful API in private part,
    217          * BUT it also have few layouting bugs which could be easy fixed
    218          * by that API, so we will use QWizard::restart() method
    219          * to call the same functionality indirectly...
    220          * And now we call restart() after layout activation procedure! */
     187        // WORKAROUND:
     188        // Unfortunately QWizard hides some of useful API in private part,
     189        // and also have few layouting bugs which could be easy fixed
     190        // by that API, so we will use QWizard::restart() method
     191        // to call the same functionality indirectly...
     192        // And now we call restart() after layout activation procedure!
    221193        restart();
    222194
     
    282254    if (!m_strWatermarkName.isEmpty())
    283255        assignWatermarkHelper();
    284 #endif /* !VBOX_WS_MAC */
     256#endif
    285257}
    286258
    287259#ifndef VBOX_WS_MAC
     260
    288261void UIWizard::assignWatermark(const QString &strWatermark)
    289262{
    290263    if (wizardStyle() != QWizard::AeroStyle
    291264# ifdef VBOX_WS_WIN
    292         /* There is a Qt bug about Windows7 do NOT match conditions for 'aero' wizard-style,
    293          * so its silently fallbacks to 'modern' one without any notification,
    294          * so QWizard::wizardStyle() returns QWizard::ModernStyle, while using aero, at least partially. */
     265        // WORKAROUND:
     266        // There is a Qt bug about Windows7 do NOT match conditions for 'aero' wizard-style,
     267        // so its silently fallbacks to 'modern' one without any notification,
     268        // so QWizard::wizardStyle() returns QWizard::ModernStyle, while using aero, at least partially.
    295269        && QSysInfo::windowsVersion() != QSysInfo::WV_WINDOWS7
    296270# endif /* VBOX_WS_WIN */
     
    298272        m_strWatermarkName = strWatermark;
    299273}
     274
    300275#else
     276
    301277void UIWizard::assignBackground(const QString &strBackground)
    302278{
    303279    setPixmap(QWizard::BackgroundPixmap, strBackground);
    304280}
     281
    305282#endif
    306283
    307 void UIWizard::showEvent(QShowEvent *pShowEvent)
    308 {
    309     /* Resize to minimum possible size: */
    310     resize(0, 0);
    311 
    312     /* Call to base-class: */
    313     QWizard::showEvent(pShowEvent);
     284void UIWizard::sltCurrentIdChanged(int iId)
     285{
     286    /* Hide/show description button disabled by default: */
     287    bool fIsHideShowDescriptionButtonAvailable = false;
     288    /* Enable hide/show description button for 1st page: */
     289    if (iId == 0)
     290        fIsHideShowDescriptionButtonAvailable = true;
     291    /* But first-run wizard has no such button anyway: */
     292    if (m_enmType == WizardType_FirstRun)
     293        fIsHideShowDescriptionButtonAvailable = false;
     294    /* Set a flag for hide/show description button finally: */
     295    setOption(QWizard::HaveCustomButton1, fIsHideShowDescriptionButtonAvailable);
     296}
     297
     298void UIWizard::sltCustomButtonClicked(int iId)
     299{
     300    /* Handle 1st button: */
     301    if (iId == CustomButton1)
     302    {
     303        /* Cleanup: */
     304        cleanup();
     305
     306        /* Toggle mode: */
     307        switch (m_enmMode)
     308        {
     309            case WizardMode_Basic:  m_enmMode = WizardMode_Expert; break;
     310            case WizardMode_Expert: m_enmMode = WizardMode_Basic;  break;
     311            default: AssertMsgFailed(("Invalid mode: %d", m_enmMode)); break;
     312        }
     313        /* Save mode: */
     314        gEDataManager->setModeForWizardType(m_enmType, m_enmMode);
     315
     316        /* Prepare: */
     317        prepare();
     318    }
     319}
     320
     321void UIWizard::retranslatePages()
     322{
     323    /* Translate all the pages: */
     324    QList<int> ids = pageIds();
     325    for (int i = 0; i < ids.size(); ++i)
     326        qobject_cast<UIWizardPage*>(page(ids[i]))->retranslate();
    314327}
    315328
     
    333346void UIWizard::resizeAccordingLabelWidth(int iLabelsWidth)
    334347{
    335     /* Unfortunately QWizard hides some of useful API in private part,
    336      * and also have few layouting bugs which could be easy fixed
    337      * by that API, so we will use QWizard::restart() method
    338      * to call the same functionality indirectly...
    339      * Early call restart() which is usually goes on show()! */
     348    // WORKAROUND:
     349    // Unfortunately QWizard hides some of useful API in private part,
     350    // and also have few layouting bugs which could be easy fixed
     351    // by that API, so we will use QWizard::restart() method
     352    // to call the same functionality indirectly...
     353    // Early call restart() which is usually goes on show()!
    340354    restart();
    341355
     
    366380        pLayout->activate();
    367381
    368     /* Unfortunately QWizard hides some of useful API in private part,
    369      * BUT it also have few layouting bugs which could be easy fixed
    370      * by that API, so we will use QWizard::restart() method
    371      * to call the same functionality indirectly...
    372      * And now we call restart() after layout activation procedure! */
     382    // WORKAROUND:
     383    // Unfortunately QWizard hides some of useful API in private part,
     384    // and also have few layouting bugs which could be easy fixed
     385    // by that API, so we will use QWizard::restart() method
     386    // to call the same functionality indirectly...
     387    // And now we call restart() after layout activation procedure!
    373388    restart();
    374389
     
    377392}
    378393
    379 double UIWizard::ratio()
     394double UIWizard::ratio() const
    380395{
    381396    /* Default value: */
     
    387402        case QWizard::ClassicStyle:
    388403        case QWizard::ModernStyle:
    389             /* There is a Qt bug about Windows7 do NOT match conditions for 'aero' wizard-style,
    390              * so its silently fallbacks to 'modern' one without any notification,
    391              * so QWizard::wizardStyle() returns QWizard::ModernStyle, while using aero, at least partially. */
     404            // WORKAROUND:
     405            // There is a Qt bug about Windows7 do NOT match conditions for 'aero' wizard-style,
     406            // so its silently fallbacks to 'modern' one without any notification,
     407            // so QWizard::wizardStyle() returns QWizard::ModernStyle, while using aero, at least partially.
    392408            if (QSysInfo::windowsVersion() != QSysInfo::WV_WINDOWS7)
    393409            {
     
    403419#endif /* VBOX_WS_WIN */
    404420
    405     switch (m_type)
     421    switch (m_enmType)
    406422    {
    407423        case WizardType_CloneVM:
     
    442458    /* Acquire wizard-layout top-margin: */
    443459    int iTopMargin = 0;
    444     if (m_mode == WizardMode_Basic)
     460    if (m_enmMode == WizardMode_Basic)
    445461    {
    446462        if (wizardStyle() == QWizard::ModernStyle)
     
    450466    /* Acquire wizard-header height: */
    451467    int iTitleHeight = 0;
    452     if (m_mode == WizardMode_Basic)
     468    if (m_enmMode == WizardMode_Basic)
    453469    {
    454470        /* We have no direct access to QWizardHeader inside QWizard private data...
     
    462478    /* Acquire spacing between wizard-header and wizard-page: */
    463479    int iMarginBetweenTitleAndPage = 0;
    464     if (m_mode == WizardMode_Basic)
     480    if (m_enmMode == WizardMode_Basic)
    465481    {
    466482        /* We have no direct access to margin between QWizardHeader and wizard-pages...
  • trunk/src/VBox/Frontends/VirtualBox/src/wizards/UIWizard.h

    r71027 r72009  
    55
    66/*
    7  * Copyright (C) 2009-2017 Oracle Corporation
     7 * Copyright (C) 2009-2018 Oracle Corporation
    88 *
    99 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    1616 */
    1717
    18 #ifndef __UIWizard_h__
    19 #define __UIWizard_h__
     18#ifndef ___UIWizard_h___
     19#define ___UIWizard_h___
    2020
    2121/* Qt includes: */
     22#include <QPointer>
    2223#include <QWizard>
    23 #include <QPointer>
    2424
    25 /* Local includes: */
     25/* GUI includes: */
    2626#include "QIWithRetranslateUI.h"
    2727#include "UIExtraDataDefs.h"
     28#include "UILibraryDefs.h"
    2829
    2930/* Forward declarations: */
     31class QShowEvent;
     32class QString;
     33class QWidget;
    3034class UIWizardPage;
    3135
    32 /* QWizard class reimplementation with extended funtionality. */
    33 class UIWizard : public QIWithRetranslateUI<QWizard>
     36/** QWizard extension with advanced functionality. */
     37class SHARED_LIBRARY_STUFF UIWizard : public QIWithRetranslateUI<QWizard>
    3438{
    3539    Q_OBJECT;
     
    3741public:
    3842
    39     /* Mode related stuff: */
    40     WizardMode mode() { return m_mode; }
     43    /** Returns wizard mode. */
     44    WizardMode mode() const { return m_enmMode; }
    4145
    42     /* Page related methods: */
     46    /** Prepare all. */
    4347    virtual void prepare();
     48
     49protected:
     50
     51    /** Constructs wizard passing @a pParent to the base-class.
     52      * @param  enmType  Brings the wizard type.
     53      * @param  enmMode  Brings the wizard mode. */
     54    UIWizard(QWidget *pParent, WizardType enmType, WizardMode enmMode = WizardMode_Auto);
     55
     56    /** Handles translation event. */
     57    virtual void retranslateUi() /* override */;
     58
     59    /** Handles show @a pEvent. */
     60    virtual void showEvent(QShowEvent *pEvent) /* override */;
     61
     62    /** Assigns @a pPage as a wizard page with certain @a iId. */
     63    void setPage(int iId, UIWizardPage *pPage);
     64    /** Removes all the pages. */
     65    void cleanup();
     66
     67    /** Resizes wizard to golden ratio. */
     68    void resizeToGoldenRatio();
     69
     70#ifndef VBOX_WS_MAC
     71    /** Assigns @a strWaterMark. */
     72    void assignWatermark(const QString &strWaterMark);
     73#else
     74    /** Assigns @a strBackground. */
     75    void assignBackground(const QString &strBackground);
     76#endif
    4477
    4578protected slots:
    4679
    47     /* Page change handler: */
     80    /** Handles current-page change to page with @a iId. */
    4881    virtual void sltCurrentIdChanged(int iId);
    49     /* Custom button 1 click handler: */
     82    /** Handles custome-button click for button with @a iId. */
    5083    virtual void sltCustomButtonClicked(int iId);
    51 
    52 protected:
    53 
    54     /* Constructor: */
    55     UIWizard(QWidget *pParent, WizardType type, WizardMode mode = WizardMode_Auto);
    56 
    57     /* Translation stuff: */
    58     void retranslateUi();
    59     void retranslatePages();
    60 
    61     /* Page related methods: */
    62     void setPage(int iId, UIWizardPage *pPage);
    63     void cleanup();
    64 
    65     /* Adjusting stuff: */
    66     void resizeToGoldenRatio();
    67 
    68     /* Design stuff: */
    69 #ifndef VBOX_WS_MAC
    70     void assignWatermark(const QString &strWaterMark);
    71 #else
    72     void assignBackground(const QString &strBackground);
    73 #endif
    74 
    75     /* Show event: */
    76     void showEvent(QShowEvent *pShowEvent);
    7784
    7885private:
    7986
    80     /* Helpers: */
     87    /** Performs pages translation. */
     88    void retranslatePages();
     89
     90    /** Configures certain @a pPage. */
    8191    void configurePage(UIWizardPage *pPage);
     92
     93    /** Resizes wizard according certain @a iLabelWidth. */
    8294    void resizeAccordingLabelWidth(int iLabelWidth);
    83     double ratio();
     95
     96    /** Returns ratio corresponding to current wizard type. */
     97    double ratio() const;
     98
    8499#ifndef VBOX_WS_MAC
     100    /** Returns proposed watermark height. */
    85101    int proposedWatermarkHeight();
     102    /** Assigns cached watermark. */
    86103    void assignWatermarkHelper();
    87 #endif /* !VBOX_WS_MAC */
     104#endif
    88105
    89     /* Variables: */
    90     WizardType m_type;
    91     WizardMode m_mode;
     106    /** Holds the wizard type. */
     107    WizardType  m_enmType;
     108    /** Holds the wizard mode. */
     109    WizardMode  m_enmMode;
    92110#ifndef VBOX_WS_MAC
    93     QString m_strWatermarkName;
    94 #endif /* !VBOX_WS_MAC */
     111    /** Holds the watermark name. */
     112    QString     m_strWatermarkName;
     113#endif
    95114};
    96115
     116/** Wizard interface safe-pointer. */
    97117typedef QPointer<UIWizard> UISafePointerWizard;
    98118
    99 #endif // __UIWizard_h__
    100 
     119#endif /* !___UIWizard_h___ */
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette