VirtualBox

Ignore:
Timestamp:
Apr 27, 2018 2:33:48 PM (7 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
122420
Message:

FE/Qt: bugref:9049: Full and huge cleanup for UISettingsDialog 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

    r72057 r72059  
    520520        src/selector/graphics/details/UIGDetailsElements.h \
    521521        src/selector/graphics/details/UIGMachinePreview.h \
    522         src/settings/UISettingsDialog.h \
    523522        src/settings/UISettingsDialogSpecific.h \
    524523        src/settings/UISettingsPage.h \
     
    664663        src/selector/UIActionPoolSelector.h \
    665664        src/selector/UIVirtualBoxEventHandler.h \
     665        src/settings/UISettingsDialog.h \
    666666        src/widgets/UIAddDiskEncryptionPasswordDialog.h \
    667667        src/widgets/UIBootTable.h \
     
    777777        src/selector/UIActionPoolSelector.h \
    778778        src/selector/UIVirtualBoxEventHandler.h \
     779        src/settings/UISettingsDialog.h \
    779780        src/widgets/UIAddDiskEncryptionPasswordDialog.h \
    780781        src/widgets/UIBootTable.h \
     
    10341035        src/selector/graphics/details/UIGDetailsElements.cpp \
    10351036        src/selector/graphics/details/UIGMachinePreview.cpp \
    1036         src/settings/UISettingsDialog.cpp \
    10371037        src/settings/UISettingsDialogSpecific.cpp \
    10381038        src/settings/UISettingsPage.cpp \
     
    12191219        src/selector/UIVirtualBoxEventHandler.cpp \
    12201220        src/settings/UISettingsDefs.cpp \
     1221        src/settings/UISettingsDialog.cpp \
    12211222        src/widgets/UIAddDiskEncryptionPasswordDialog.cpp \
    12221223        src/widgets/UIBootTable.cpp \
     
    13591360        src/selector/UIVirtualBoxEventHandler.cpp \
    13601361        src/settings/UISettingsDefs.cpp \
     1362        src/settings/UISettingsDialog.cpp \
    13611363        src/widgets/UIAddDiskEncryptionPasswordDialog.cpp \
    13621364        src/widgets/UIBootTable.cpp \
  • trunk/src/VBox/Frontends/VirtualBox/src/settings/UISettingsDialog.cpp

    r71027 r72059  
    55
    66/*
    7  * Copyright (C) 2006-2017 Oracle Corporation
     7 * Copyright (C) 2006-2018 Oracle Corporation
    88 *
    99 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    2020#else  /* !VBOX_WITH_PRECOMPILED_HEADERS */
    2121
    22 /* Global includes */
     22/* Qt includes: */
     23# include <QCloseEvent>
    2324# include <QProgressBar>
    2425# include <QPushButton>
    2526# include <QStackedWidget>
    2627# include <QTimer>
    27 # include <QCloseEvent>
    28 
    29 /* Local includes */
     28
     29/* GUI includes: */
     30# include "QIWidgetValidator.h"
     31# include "VBoxGlobal.h"
     32# include "UIConverter.h"
     33# include "UIIconPool.h"
     34# include "UIMessageCenter.h"
     35# include "UIModalWindowManager.h"
     36# include "UIPopupCenter.h"
    3037# include "UISettingsDialog.h"
     38# include "UISettingsPage.h"
     39# include "UISettingsSelector.h"
     40# include "UISettingsSerializer.h"
     41# include "UIToolBar.h"
    3142# include "UIWarningPane.h"
    32 # include "VBoxGlobal.h"
    33 # include "UIMessageCenter.h"
    34 # include "UIPopupCenter.h"
    35 # include "QIWidgetValidator.h"
    36 # include "UISettingsSelector.h"
    37 # include "UIModalWindowManager.h"
    38 # include "UISettingsSerializer.h"
    39 # include "UISettingsPage.h"
    40 # include "UIToolBar.h"
    41 # include "UIIconPool.h"
    42 # include "UIConverter.h"
    4343# ifdef VBOX_WS_MAC
    4444#  include "VBoxUtils.h"
    45 # endif /* VBOX_WS_MAC */
     45# endif
    4646
    4747#endif /* !VBOX_WITH_PRECOMPILED_HEADERS */
     
    4949#ifdef VBOX_WS_MAC
    5050# define VBOX_GUI_WITH_TOOLBAR_SETTINGS
    51 #endif /* VBOX_WS_MAC */
    52 
    53 /* Settings Dialog Constructor: */
     51#endif
     52
     53
    5454UISettingsDialog::UISettingsDialog(QWidget *pParent)
    55     /* Parent class: */
    5655    : QIWithRetranslateUI<QIMainDialog>(pParent)
    57     /* Protected variables: */
    5856    , m_pSelector(0)
    5957    , m_pStack(0)
    60     /* Common variables: */
    61     , m_configurationAccessLevel(ConfigurationAccessLevel_Null)
    6258    , m_fPolished(false)
    63     /* Serialization stuff: */
     59    , m_enmConfigurationAccessLevel(ConfigurationAccessLevel_Null)
    6460    , m_pSerializeProcess(0)
    6561    , m_fSerializationIsInProgress(false)
    6662    , m_fSerializationClean(true)
    67     /* Status-bar stuff: */
    6863    , m_pStatusBar(0)
    69     /* Process-bar stuff: */
    7064    , m_pProcessBar(0)
    71     /* Warning-pane stuff: */
    7265    , m_pWarningPane(0)
    7366    , m_fValid(true)
    7467    , m_fSilent(true)
    75     /* Whats-this stuff: */
    7668    , m_pWhatsThisTimer(new QTimer(this))
    77     , m_pWhatsThisCandidate(0)
    78 {
    79     /* Apply UI decorations: */
    80     Ui::UISettingsDialog::setupUi(this);
    81 
    82     /* Page-title font is derived from the system font: */
    83     QFont pageTitleFont = font();
    84     pageTitleFont.setBold(true);
    85     pageTitleFont.setPointSize(pageTitleFont.pointSize() + 2);
    86     m_pLbTitle->setFont(pageTitleFont);
    87 
    88     /* Prepare selector: */
    89     QGridLayout *pMainLayout = static_cast<QGridLayout*>(centralWidget()->layout());
    90 #ifdef VBOX_GUI_WITH_TOOLBAR_SETTINGS
    91     /* No page-title with tool-bar: */
    92     m_pLbTitle->hide();
    93     /* Create modern tool-bar selector: */
    94     m_pSelector = new UISettingsSelectorToolBar(this);
    95     static_cast<UIToolBar*>(m_pSelector->widget())->enableMacToolbar();
    96     addToolBar(qobject_cast<QToolBar*>(m_pSelector->widget()));
    97     /* No title in this mode, we change the title of the window: */
    98     pMainLayout->setColumnMinimumWidth(0, 0);
    99     pMainLayout->setHorizontalSpacing(0);
    100 #else
    101     /* Create classical tree-view selector: */
    102     m_pSelector = new UISettingsSelectorTreeView(this);
    103     pMainLayout->addWidget(m_pSelector->widget(), 0, 0, 2, 1);
    104     m_pSelector->widget()->setFocus();
    105 #endif /* VBOX_GUI_WITH_TOOLBAR_SETTINGS */
    106     connect(m_pSelector, SIGNAL(sigCategoryChanged(int)), this, SLOT(sltCategoryChanged(int)));
    107 
    108     /* Prepare page-stack: */
    109     m_pStack = new QStackedWidget(m_pWtStackHandler);
    110     popupCenter().setPopupStackOrientation(m_pStack, UIPopupStackOrientation_Bottom);
    111     QVBoxLayout *pStackLayout = new QVBoxLayout(m_pWtStackHandler);
    112     pStackLayout->setContentsMargins(0, 0, 0, 0);
    113     pStackLayout->addWidget(m_pStack);
    114 
    115     /* Prepare button-box: */
    116     m_pButtonBox->button(QDialogButtonBox::Ok)->setDefault(true);
    117     connect(m_pButtonBox, SIGNAL(helpRequested()), &msgCenter(), SLOT(sltShowHelpHelpDialog()));
    118 
    119     /* Prepare process-bar: */
    120     m_pProcessBar = new QProgressBar;
    121     m_pProcessBar->setMaximum(100);
    122     m_pProcessBar->setMinimum(0);
    123 
    124     /* Prepare warning-pane: */
    125     m_pWarningPane = new UIWarningPane;
    126     connect(m_pWarningPane, SIGNAL(sigHoverEnter(UIPageValidator*)), this, SLOT(sltHandleWarningPaneHovered(UIPageValidator*)));
    127     connect(m_pWarningPane, SIGNAL(sigHoverLeave(UIPageValidator*)), this, SLOT(sltHandleWarningPaneUnhovered(UIPageValidator*)));
    128 
    129     /* Prepare status-bar: */
    130     m_pStatusBar = new QStackedWidget;
    131     /* Add empty widget: */
    132     m_pStatusBar->addWidget(new QWidget);
    133     /* Add process-bar widget: */
    134     m_pStatusBar->addWidget(m_pProcessBar);
    135     /* Add warning-pane: */
    136     m_pStatusBar->addWidget(m_pWarningPane);
    137     /* Add status-bar to button-box: */
    138     m_pButtonBox->addExtraWidget(m_pStatusBar);
    139 
    140     /* Setup whatsthis stuff: */
    141     qApp->installEventFilter(this);
    142     m_pWhatsThisTimer->setSingleShot(true);
    143     connect(m_pWhatsThisTimer, SIGNAL(timeout()), this, SLOT(sltUpdateWhatsThis()));
    144 
    145     /* Translate UI: */
    146     retranslateUi();
     69{
     70    /* Prepare: */
     71    prepare();
    14772}
    14873
     
    185110}
    186111
     112void UISettingsDialog::reject()
     113{
     114    if (!isSerializationInProgress())
     115        QIWithRetranslateUI<QIMainDialog>::reject();
     116}
     117
    187118void UISettingsDialog::sltCategoryChanged(int cId)
    188119{
    189     int index = m_pages[cId];
     120    const int iIndex = m_pages.value(cId);
     121
    190122#ifdef VBOX_WS_MAC
    191123    /* If index is within the stored size list bounds: */
    192     if (index < m_sizeList.count())
     124    if (iIndex < m_sizeList.count())
    193125    {
    194126        /* Get current/stored size: */
    195127        const QSize cs = size();
    196         const QSize ss = m_sizeList.at(index);
     128        const QSize ss = m_sizeList.at(iIndex);
    197129
    198130        /* Switch to the new page first if we are shrinking: */
    199131        if (cs.height() > ss.height())
    200             m_pStack->setCurrentIndex(index);
     132            m_pStack->setCurrentIndex(iIndex);
    201133
    202134        /* Do the animation: */
     
    205137        /* Switch to the new page last if we are zooming: */
    206138        if (cs.height() <= ss.height())
    207             m_pStack->setCurrentIndex(index);
     139            m_pStack->setCurrentIndex(iIndex);
    208140
    209141        /* Unlock all page policies but lock the current one: */
    210142        for (int i = 0; i < m_pStack->count(); ++i)
    211             m_pStack->widget(i)->setSizePolicy(QSizePolicy::Minimum, i == index ? QSizePolicy::Minimum : QSizePolicy::Ignored);
     143            m_pStack->widget(i)->setSizePolicy(QSizePolicy::Minimum, i == iIndex ? QSizePolicy::Minimum : QSizePolicy::Ignored);
     144
    212145        /* And make sure layouts are freshly calculated: */
    213146        foreach (QLayout *pLayout, findChildren<QLayout*>())
     
    217150        }
    218151    }
    219 #else
    220     m_pStack->setCurrentIndex(index);
    221 #endif
     152#else /* !VBOX_WS_MAC */
     153    m_pStack->setCurrentIndex(iIndex);
     154#endif /* !VBOX_WS_MAC */
     155
    222156#ifdef VBOX_GUI_WITH_TOOLBAR_SETTINGS
    223157    setWindowTitle(title());
     
    271205}
    272206
     207bool UISettingsDialog::eventFilter(QObject *pObject, QEvent *pEvent)
     208{
     209    /* Ignore objects which are NOT widgets: */
     210    if (!pObject->isWidgetType())
     211        return QIMainDialog::eventFilter(pObject, pEvent);
     212
     213    /* Ignore widgets which window is NOT settings window: */
     214    QWidget *pWidget = static_cast<QWidget*>(pObject);
     215    if (pWidget->window() != this)
     216        return QIMainDialog::eventFilter(pObject, pEvent);
     217
     218    /* Process different event-types: */
     219    switch (pEvent->type())
     220    {
     221        /* Process enter/leave events to remember whats-this candidates: */
     222        case QEvent::Enter:
     223        case QEvent::Leave:
     224        {
     225            if (pEvent->type() == QEvent::Enter)
     226                m_pWhatsThisCandidate = pWidget;
     227            else
     228                m_pWhatsThisCandidate = 0;
     229
     230            m_pWhatsThisTimer->start(100);
     231            break;
     232        }
     233        /* Process focus-in event to update whats-this pane: */
     234        case QEvent::FocusIn:
     235        {
     236            sltUpdateWhatsThis(true /* got focus? */);
     237            break;
     238        }
     239        default:
     240            break;
     241    }
     242
     243    /* Base-class processing: */
     244    return QIMainDialog::eventFilter(pObject, pEvent);
     245}
     246
     247void UISettingsDialog::retranslateUi()
     248{
     249    /* Translate generated stuff: */
     250    Ui::UISettingsDialog::retranslateUi(this);
     251
     252    /* Translate warning stuff: */
     253    m_strWarningHint = tr("Invalid settings detected");
     254    if (!m_fValid || !m_fSilent)
     255        m_pWarningPane->setWarningLabel(m_strWarningHint);
     256
     257#ifndef VBOX_GUI_WITH_TOOLBAR_SETTINGS
     258    /* Retranslate current page headline: */
     259    m_pLbTitle->setText(m_pSelector->itemText(m_pSelector->currentId()));
     260#endif
     261
     262    /* Retranslate all validators: */
     263    foreach (UIPageValidator *pValidator, findChildren<UIPageValidator*>())
     264        if (!pValidator->lastMessage().isEmpty())
     265            revalidate(pValidator);
     266    revalidate();
     267}
     268
     269void UISettingsDialog::showEvent(QShowEvent *pEvent)
     270{
     271    /* Base-class processing: */
     272    QIMainDialog::showEvent(pEvent);
     273
     274    /* One may think that QWidget::polish() is the right place to do things
     275     * below, but apparently, by the time when QWidget::polish() is called,
     276     * the widget style & layout are not fully done, at least the minimum
     277     * size hint is not properly calculated. Since this is sometimes necessary,
     278     * we provide our own "polish" implementation. */
     279    if (m_fPolished)
     280        return;
     281
     282    m_fPolished = true;
     283
     284    int iMinWidth = m_pSelector->minWidth();
     285
     286#ifdef VBOX_WS_MAC
     287
     288    /* Remove all title bar buttons (Buggy Qt): */
     289    ::darwinSetHidesAllTitleButtons(this);
     290
     291    /* Unlock all page policies initially: */
     292    for (int i = 0; i < m_pStack->count(); ++i)
     293        m_pStack->widget(i)->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Ignored);
     294
     295    /* Activate every single page to get the optimal size: */
     296    for (int i = m_pStack->count() - 1; i >= 0; --i)
     297    {
     298        /* Activate current page: */
     299        m_pStack->setCurrentIndex(i);
     300
     301        /* Lock current page policy temporary: */
     302        m_pStack->widget(i)->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
     303        /* And make sure layouts are freshly calculated: */
     304        foreach (QLayout *pLayout, findChildren<QLayout*>())
     305        {
     306            pLayout->update();
     307            pLayout->activate();
     308        }
     309
     310        /* Acquire minimum size-hint: */
     311        QSize s = minimumSizeHint();
     312        // WORKAROUND:
     313        // Take into account the height of native tool-bar title.
     314        // It will be applied only after widget is really shown.
     315        // The height is 11pix * 2 (possible HiDPI support).
     316        s.setHeight(s.height() + 11 * 2);
     317        /* Also make sure that width is no less than tool-bar: */
     318        if (iMinWidth > s.width())
     319            s.setWidth(iMinWidth);
     320        /* And remember the size finally: */
     321        m_sizeList.insert(0, s);
     322
     323        /* Unlock the policy for current page again: */
     324        m_pStack->widget(i)->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Ignored);
     325    }
     326
     327    sltCategoryChanged(m_pSelector->currentId());
     328
     329#else /* VBOX_WS_MAC */
     330
     331    /* Resize to the minimum possible size: */
     332    QSize s = minimumSize();
     333    if (iMinWidth > s.width())
     334        s.setWidth(iMinWidth);
     335    resize(s);
     336
     337#endif /* VBOX_WS_MAC */
     338}
     339
    273340void UISettingsDialog::loadData(QVariant &data)
    274341{
     
    331398}
    332399
    333 void UISettingsDialog::retranslateUi()
    334 {
    335     /* Translate generated stuff: */
    336     Ui::UISettingsDialog::retranslateUi(this);
    337 
    338     /* Translate warning stuff: */
    339     m_strWarningHint = tr("Invalid settings detected");
    340     if (!m_fValid || !m_fSilent)
    341         m_pWarningPane->setWarningLabel(m_strWarningHint);
    342 
    343 #ifndef VBOX_GUI_WITH_TOOLBAR_SETTINGS
    344     /* Retranslate current page headline: */
    345     m_pLbTitle->setText(m_pSelector->itemText(m_pSelector->currentId()));
    346 #endif /* VBOX_GUI_WITH_TOOLBAR_SETTINGS */
    347 
    348     /* Retranslate all validators: */
    349     foreach (UIPageValidator *pValidator, findChildren<UIPageValidator*>())
    350         if (!pValidator->lastMessage().isEmpty())
    351             revalidate(pValidator);
    352     revalidate();
    353 }
    354 
    355 void UISettingsDialog::setConfigurationAccessLevel(ConfigurationAccessLevel newConfigurationAccessLevel)
     400void UISettingsDialog::setConfigurationAccessLevel(ConfigurationAccessLevel enmConfigurationAccessLevel)
    356401{
    357402    /* Make sure something changed: */
    358     if (m_configurationAccessLevel == newConfigurationAccessLevel)
     403    if (m_enmConfigurationAccessLevel == enmConfigurationAccessLevel)
    359404        return;
    360405
    361406    /* Apply new configuration access level: */
    362     m_configurationAccessLevel = newConfigurationAccessLevel;
     407    m_enmConfigurationAccessLevel = enmConfigurationAccessLevel;
    363408
    364409    /* And propagate it to settings-page(s): */
     
    516561}
    517562
    518 void UISettingsDialog::sltUpdateWhatsThis(bool fGotFocus /* = false */)
     563void UISettingsDialog::sltUpdateWhatsThis(bool fGotFocus)
    519564{
    520565    QString strWhatsThisText;
     
    548593}
    549594
    550 void UISettingsDialog::reject()
    551 {
    552     if (!isSerializationInProgress())
    553         QIMainDialog::reject();
    554 }
    555 
    556 bool UISettingsDialog::eventFilter(QObject *pObject, QEvent *pEvent)
    557 {
    558     /* Ignore objects which are NOT widgets: */
    559     if (!pObject->isWidgetType())
    560         return QIMainDialog::eventFilter(pObject, pEvent);
    561 
    562     /* Ignore widgets which window is NOT settings window: */
    563     QWidget *pWidget = static_cast<QWidget*>(pObject);
    564     if (pWidget->window() != this)
    565         return QIMainDialog::eventFilter(pObject, pEvent);
    566 
    567     /* Process different event-types: */
    568     switch (pEvent->type())
    569     {
    570         /* Process enter/leave events to remember whats-this candidates: */
    571         case QEvent::Enter:
    572         case QEvent::Leave:
    573         {
    574             if (pEvent->type() == QEvent::Enter)
    575                 m_pWhatsThisCandidate = pWidget;
    576             else
    577                 m_pWhatsThisCandidate = 0;
    578 
    579             m_pWhatsThisTimer->start(100);
    580             break;
    581         }
    582         /* Process focus-in event to update whats-this pane: */
    583         case QEvent::FocusIn:
    584         {
    585             sltUpdateWhatsThis(true /* got focus? */);
    586             break;
    587         }
    588         default:
    589             break;
    590     }
    591 
    592     /* Base-class processing: */
    593     return QIMainDialog::eventFilter(pObject, pEvent);
    594 }
    595 
    596 void UISettingsDialog::showEvent(QShowEvent *pEvent)
    597 {
    598     /* Base-class processing: */
    599     QIMainDialog::showEvent(pEvent);
    600 
    601     /* One may think that QWidget::polish() is the right place to do things
    602      * below, but apparently, by the time when QWidget::polish() is called,
    603      * the widget style & layout are not fully done, at least the minimum
    604      * size hint is not properly calculated. Since this is sometimes necessary,
    605      * we provide our own "polish" implementation. */
    606     if (m_fPolished)
    607         return;
    608 
    609     m_fPolished = true;
    610 
    611     int iMinWidth = m_pSelector->minWidth();
    612 #ifdef VBOX_WS_MAC
    613     /* Remove all title bar buttons (Buggy Qt): */
    614     ::darwinSetHidesAllTitleButtons(this);
    615 
    616     /* Unlock all page policies initially: */
    617     for (int i = 0; i < m_pStack->count(); ++i)
    618         m_pStack->widget(i)->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Ignored);
    619 
    620     /* Activate every single page to get the optimal size: */
    621     for (int i = m_pStack->count() - 1; i >= 0; --i)
    622     {
    623         /* Activate current page: */
    624         m_pStack->setCurrentIndex(i);
    625 
    626         /* Lock current page policy temporary: */
    627         m_pStack->widget(i)->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
    628         /* And make sure layouts are freshly calculated: */
    629         foreach (QLayout *pLayout, findChildren<QLayout*>())
    630         {
    631             pLayout->update();
    632             pLayout->activate();
    633         }
    634 
    635         /* Acquire minimum size-hint: */
    636         QSize s = minimumSizeHint();
    637         /* HACK ALERT!
    638          * Take into account the height of native tool-bar title.
    639          * It will be applied only after widget is really shown.
    640          * The height is 11pix * 2 (possible HiDPI support). */
    641         s.setHeight(s.height() + 11 * 2);
    642         /* Also make sure that width is no less than tool-bar: */
    643         if (iMinWidth > s.width())
    644             s.setWidth(iMinWidth);
    645         /* And remember the size finally: */
    646         m_sizeList.insert(0, s);
    647 
    648         /* Unlock the policy for current page again: */
    649         m_pStack->widget(i)->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Ignored);
    650     }
    651 
    652     sltCategoryChanged(m_pSelector->currentId());
    653 #else /* VBOX_WS_MAC */
    654     /* Resize to the minimum possible size: */
    655     QSize s = minimumSize();
    656     if (iMinWidth > s.width())
    657         s.setWidth(iMinWidth);
    658     resize(s);
    659 #endif /* VBOX_WS_MAC */
     595void UISettingsDialog::prepare()
     596{
     597    /* Apply UI decorations: */
     598    Ui::UISettingsDialog::setupUi(this);
     599
     600    /* Configure title: */
     601    if (m_pLbTitle)
     602    {
     603        /* Page-title font is bold and larger but derived from the system font: */
     604        QFont pageTitleFont = font();
     605        pageTitleFont.setBold(true);
     606        pageTitleFont.setPointSize(pageTitleFont.pointSize() + 2);
     607        m_pLbTitle->setFont(pageTitleFont);
     608    }
     609
     610    /* Prepare selector: */
     611    QGridLayout *pMainLayout = static_cast<QGridLayout*>(centralWidget()->layout());
     612    if (pMainLayout)
     613    {
     614#ifdef VBOX_GUI_WITH_TOOLBAR_SETTINGS
     615
     616        /* No page-title with tool-bar: */
     617        m_pLbTitle->hide();
     618
     619        /* Create modern tool-bar selector: */
     620        m_pSelector = new UISettingsSelectorToolBar(this);
     621        if (m_pSelector)
     622        {
     623            /* Configure tool-bar: */
     624            static_cast<UIToolBar*>(m_pSelector->widget())->enableMacToolbar();
     625
     626            /* Add tool-bar into page: */
     627            addToolBar(qobject_cast<QToolBar*>(m_pSelector->widget()));
     628        }
     629
     630        /* No title in this mode, we change the title of the window: */
     631        pMainLayout->setColumnMinimumWidth(0, 0);
     632        pMainLayout->setHorizontalSpacing(0);
     633
     634#else /* !VBOX_GUI_WITH_TOOLBAR_SETTINGS */
     635
     636        /* Create classical tree-view selector: */
     637        m_pSelector = new UISettingsSelectorTreeView(this);
     638        if (m_pSelector)
     639        {
     640            /* Add into layout: */
     641            pMainLayout->addWidget(m_pSelector->widget(), 0, 0, 2, 1);
     642
     643            /* Set focus: */
     644            m_pSelector->widget()->setFocus();
     645        }
     646
     647#endif /* !VBOX_GUI_WITH_TOOLBAR_SETTINGS */
     648
     649        connect(m_pSelector, SIGNAL(sigCategoryChanged(int)), this, SLOT(sltCategoryChanged(int)));
     650    }
     651
     652    /* Prepare stack-handler: */
     653    if (m_pWtStackHandler)
     654    {
     655        /* Create page-stack layout: */
     656        QVBoxLayout *pStackLayout = new QVBoxLayout(m_pWtStackHandler);
     657        if (pStackLayout)
     658        {
     659            /* Confugre page-stack layout: */
     660            pStackLayout->setContentsMargins(0, 0, 0, 0);
     661
     662            /* Create page-stack: */
     663            m_pStack = new QStackedWidget;
     664            if (m_pStack)
     665            {
     666                /* Configure page-stack: */
     667                popupCenter().setPopupStackOrientation(m_pStack, UIPopupStackOrientation_Bottom);
     668
     669                /* Add into layout: */
     670                pStackLayout->addWidget(m_pStack);
     671            }
     672        }
     673    }
     674
     675    /* Prepare button-box: */
     676    if (m_pButtonBox)
     677    {
     678        m_pButtonBox->button(QDialogButtonBox::Ok)->setDefault(true);
     679        connect(m_pButtonBox, &QIDialogButtonBox::helpRequested,
     680                &msgCenter(), &UIMessageCenter::sltShowHelpHelpDialog);
     681
     682        /* Create status-bar: */
     683        m_pStatusBar = new QStackedWidget;
     684        if (m_pStatusBar)
     685        {
     686            /* Add empty widget: */
     687            m_pStatusBar->addWidget(new QWidget);
     688
     689            /* Create process-bar: */
     690            m_pProcessBar = new QProgressBar;
     691            if (m_pProcessBar)
     692            {
     693                /* Configure process-bar: */
     694                m_pProcessBar->setMinimum(0);
     695                m_pProcessBar->setMaximum(100);
     696
     697                /* Add into status-bar: */
     698                m_pStatusBar->addWidget(m_pProcessBar);
     699            }
     700
     701            /* Create warning-pane: */
     702            m_pWarningPane = new UIWarningPane;
     703            if (m_pWarningPane)
     704            {
     705                /* Configure warning-pane: */
     706                connect(m_pWarningPane, &UIWarningPane::sigHoverEnter,
     707                        this, &UISettingsDialog::sltHandleWarningPaneHovered);
     708                connect(m_pWarningPane, &UIWarningPane::sigHoverLeave,
     709                        this, &UISettingsDialog::sltHandleWarningPaneUnhovered);
     710
     711                /* Add into status-bar: */
     712                m_pStatusBar->addWidget(m_pWarningPane);
     713            }
     714
     715            /* Add status-bar to button-box: */
     716            m_pButtonBox->addExtraWidget(m_pStatusBar);
     717        }
     718    }
     719
     720    /* Setup what's this stuff: */
     721    qApp->installEventFilter(this);
     722    m_pWhatsThisTimer->setSingleShot(true);
     723    connect(m_pWhatsThisTimer, &QTimer::timeout,
     724            this, &UISettingsDialog::sltUpdateWhatsThisNoFocus);
     725
     726    /* Apply language settings: */
     727    retranslateUi();
    660728}
    661729
     
    672740    pPage->setOrderAfter(m_pSelector->widget());
    673741}
    674 
  • trunk/src/VBox/Frontends/VirtualBox/src/settings/UISettingsDialog.h

    r71027 r72059  
    55
    66/*
    7  * Copyright (C) 2006-2017 Oracle Corporation
     7 * Copyright (C) 2006-2018 Oracle Corporation
    88 *
    99 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    1616 */
    1717
    18 #ifndef __UISettingsDialog_h__
    19 #define __UISettingsDialog_h__
    20 
    21 /* VBox includes: */
     18#ifndef ___UISettingsDialog_h___
     19#define ___UISettingsDialog_h___
     20
     21/* Qt includes: */
     22#include <QPointer>
     23#include <QVariant>
     24
     25/* GUI includes: */
    2226#include "QIMainDialog.h"
    2327#include "QIWithRetranslateUI.h"
     28#include "UISettingsDefs.h"
    2429#include "UISettingsDialog.gen.h"
    25 #include "UISettingsDefs.h"
    2630
    2731/* Forward declarations: */
    28 class UIPageValidator;
     32class QEvent;
     33class QObject;
    2934class QProgressBar;
     35class QShowEvent;
    3036class QStackedWidget;
    3137class QTimer;
     38class UIPageValidator;
     39class UISettingsPage;
     40class UISettingsSelector;
     41class UISettingsSerializer;
    3242class UIWarningPane;
    33 class UISettingsSelector;
    34 class UISettingsPage;
    35 class UISettingsSerializer;
    3643
    3744/* Using declarations: */
    3845using namespace UISettingsDefs;
    3946
    40 /* Base dialog class for both Global & VM settings which encapsulates most of their similar functionalities */
    41 class UISettingsDialog : public QIWithRetranslateUI<QIMainDialog>, public Ui::UISettingsDialog
     47/** QIMainDialog aubclass used as
     48  * base dialog class for both Global & VM settings which encapsulates most of their common functionality. */
     49class SHARED_LIBRARY_STUFF UISettingsDialog : public QIWithRetranslateUI<QIMainDialog>, public Ui::UISettingsDialog
    4250{
    4351    Q_OBJECT;
     
    4553public:
    4654
    47     /* Settings Dialog Constructor/Destructor: */
     55    /** Constructs settings dialog passing @a pParent to the base-class. */
    4856    UISettingsDialog(QWidget *pParent);
    49    ~UISettingsDialog();
    50 
    51     /* Execute API: */
     57    /** Destructs settings dialog. */
     58    virtual ~UISettingsDialog() /* override */;
     59
     60    /** Performs modal dialog call. */
    5261    void execute();
    5362
     
    5564
    5665    /** Hides the modal dialog and sets the result code to Accepted. */
    57     virtual void accept();
    58 
    59     /* Category-change slot: */
     66    virtual void accept() /* override */;
     67    /** Hides the modal dialog and sets the result code to Rejected. */
     68    virtual void reject() /* override */;
     69
     70    /** Handles category change to @a cId. */
    6071    virtual void sltCategoryChanged(int cId);
    6172
    62     /* Mark dialog as loaded: */
     73    /** Marks dialog loaded. */
    6374    virtual void sltMarkLoaded();
    64     /* Mark dialog as saved: */
     75    /** Marks dialog saved. */
    6576    virtual void sltMarkSaved();
    6677
    67     /* Handlers for process bar: */
     78    /** Handles process start. */
    6879    void sltHandleProcessStarted();
     80    /** Handles process progress change to @a iValue. */
    6981    void sltHandleProcessProgressChange(int iValue);
    7082
    7183protected:
    7284
     85    /** Preprocesses any Qt @a pEvent for passed @a pObject. */
     86    virtual bool eventFilter(QObject *pObject, QEvent *pEvent) /* override */;
     87    /** Handles translation event. */
     88    virtual void retranslateUi() /* override */;
     89    /** Handles show @a pEvent. */
     90    virtual void showEvent(QShowEvent *pEvent) /* override */;
     91
    7392    /** Returns the serialize process instance. */
    74     UISettingsSerializer* serializeProcess() const { return m_pSerializeProcess; }
     93    UISettingsSerializer *serializeProcess() const { return m_pSerializeProcess; }
    7594    /** Returns whether the serialization is in progress. */
    7695    bool isSerializationInProgress() const { return m_fSerializationIsInProgress; }
     
    88107    virtual void saveOwnData() = 0;
    89108
    90     /* UI translator: */
    91     virtual void retranslateUi();
    92 
    93109    /** Returns configuration access level. */
    94     ConfigurationAccessLevel configurationAccessLevel() { return m_configurationAccessLevel; }
     110    ConfigurationAccessLevel configurationAccessLevel() const { return m_enmConfigurationAccessLevel; }
    95111    /** Defines configuration access level. */
    96     void setConfigurationAccessLevel(ConfigurationAccessLevel newConfigurationAccessLevel);
     112    void setConfigurationAccessLevel(ConfigurationAccessLevel enmConfigurationAccessLevel);
    97113
    98114    /** Returns the dialog title extension. */
     
    101117    virtual QString title() const = 0;
    102118
    103     /* Add settings page: */
     119    /** Adds an item (page).
     120      * @param  strBigIcon     Brings the big icon.
     121      * @param  strMediumIcon  Brings the medium icon.
     122      * @param  strSmallIcon   Brings the small icon.
     123      * @param  cId            Brings the page ID.
     124      * @param  strLink        Brings the page link.
     125      * @param  pSettingsPage  Brings the page reference.
     126      * @param  iParentId      Brings the page parent ID. */
    104127    void addItem(const QString &strBigIcon, const QString &strMediumIcon, const QString &strSmallIcon,
    105128                 int cId, const QString &strLink,
    106129                 UISettingsPage* pSettingsPage = 0, int iParentId = -1);
    107130
    108     /* Helpers: Validation stuff: */
     131    /** Verifies data integrity between certain @a pSettingsPage and other pages. */
    109132    virtual void recorrelate(UISettingsPage *pSettingsPage) { Q_UNUSED(pSettingsPage); }
     133
     134    /** Validates data correctness using certain @a pValidator. */
    110135    void revalidate(UIPageValidator *pValidator);
     136    /** Validates data correctness. */
    111137    void revalidate();
    112138
    113     /* Protected variables: */
     139    /** Holds the page selector instance. */
    114140    UISettingsSelector *m_pSelector;
    115     QStackedWidget *m_pStack;
     141    /** Holds the page stack instance. */
     142    QStackedWidget     *m_pStack;
    116143
    117144private slots:
    118145
    119     /* Handlers: Validation stuff: */
     146    /** Handles validity change for certain @a pValidator. */
    120147    void sltHandleValidityChange(UIPageValidator *pValidator);
     148
     149    /** Handles hover enter for warning pane specified by @a pValidator. */
    121150    void sltHandleWarningPaneHovered(UIPageValidator *pValidator);
     151    /** Handles hover leave for warning pane specified by @a pValidator. */
    122152    void sltHandleWarningPaneUnhovered(UIPageValidator *pValidator);
    123153
    124     /* Slot to update whats-this: */
    125     void sltUpdateWhatsThis(bool fGotFocus = false);
    126 
    127     /* Slot to handle reject: */
    128     void reject();
     154    /** Updates watch this information depending on whether we have @a fGotFocus. */
     155    void sltUpdateWhatsThis(bool fGotFocus);
     156    /** Updates watch this information. */
     157    void sltUpdateWhatsThisNoFocus() { sltUpdateWhatsThis(false); }
    129158
    130159private:
    131160
    132     /* Event-handlers: */
    133     bool eventFilter(QObject *pObject, QEvent *pEvent);
    134     void showEvent(QShowEvent *pEvent);
    135 
    136     /* Helper: Validation stuff: */
     161    /** Prepares all. */
     162    void prepare();
     163
     164    /** Assigns validater for passed @a pPage. */
    137165    void assignValidator(UISettingsPage *pPage);
    138166
     167    /** Holds whether the dialog is polished. */
     168    bool  m_fPolished;
     169
    139170    /** Holds configuration access level. */
    140     ConfigurationAccessLevel m_configurationAccessLevel;
    141 
    142     /* Global Flags: */
    143     bool m_fPolished;
     171    ConfigurationAccessLevel  m_enmConfigurationAccessLevel;
    144172
    145173    /** Holds the serialize process instance. */
    146174    UISettingsSerializer *m_pSerializeProcess;
     175
    147176    /** Holds whether the serialization is in progress. */
    148     bool m_fSerializationIsInProgress;
     177    bool  m_fSerializationIsInProgress;
    149178    /** Holds whether there were no serialization errors. */
    150     bool m_fSerializationClean;
    151 
    152     /* Status bar widget: */
     179    bool  m_fSerializationClean;
     180
     181    /** Holds the status-bar widget instance. */
    153182    QStackedWidget *m_pStatusBar;
    154 
    155     /* Process bar widget: */
    156     QProgressBar *m_pProcessBar;
    157 
    158     /* Error & Warning stuff: */
    159     UIWarningPane *m_pWarningPane;
    160     bool m_fValid;
    161     bool m_fSilent;
    162     QString m_strWarningHint;
    163 
    164     /* Whats-This stuff: */
    165     QTimer *m_pWhatsThisTimer;
    166     QPointer<QWidget> m_pWhatsThisCandidate;
    167 
    168     QMap<int, int> m_pages;
     183    /** Holds the process-bar widget instance. */
     184    QProgressBar   *m_pProcessBar;
     185    /** Holds the warning-pane instance. */
     186    UIWarningPane  *m_pWarningPane;
     187
     188    /** Holds whether settings dialog is valid (no errors, can be warnings). */
     189    bool  m_fValid;
     190    /** Holds whether settings dialog is silent (no errors and no warnings). */
     191    bool  m_fSilent;
     192
     193    /** Holds the warning hint. */
     194    QString  m_strWarningHint;
     195
     196    /** Holds the what's this hover timer instance. */
     197    QTimer            *m_pWhatsThisTimer;
     198    /** Holds the what's this hover timer instance. */
     199    QPointer<QWidget>  m_pWhatsThisCandidate;
     200
     201    /** Holds the map of settings pages. */
     202    QMap<int, int>  m_pages;
     203
    169204#ifdef VBOX_WS_MAC
    170     QList<QSize> m_sizeList;
    171 #endif /* VBOX_WS_MAC */
     205    /** Holds the list of settings page sizes for animation purposes. */
     206    QList<QSize>  m_sizeList;
     207#endif
    172208};
    173209
    174 #endif // __UISettingsDialog_h__
    175 
     210#endif /* !___UISettingsDialog_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