VirtualBox

Changeset 100923 in vbox for trunk/src/VBox/Frontends


Ignore:
Timestamp:
Aug 21, 2023 1:23:49 PM (16 months ago)
Author:
vboxsync
Message:

FE/Qt: UISettingsDialog: Large cleanup for prepare/cleanup cascade.

Location:
trunk/src/VBox/Frontends/VirtualBox/src/settings
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/settings/UISettingsDialog.cpp

    r100902 r100923  
    6767    , m_strControl(strControl)
    6868    , m_pSelector(0)
    69     , m_pStack(0)
    7069    , m_enmConfigurationAccessLevel(ConfigurationAccessLevel_Null)
    7170    , m_pSerializeProcess(0)
     
    7978    , m_fValid(true)
    8079    , m_fSilent(true)
     80    , m_pLayoutMain(0)
    8181    , m_pLabelTitle(0)
     82    , m_pStack(0)
    8283    , m_pButtonBox(0)
    83     , m_pWidgetStackHandler(0)
    84 {
    85     /* Prepare: */
     84{
    8685    prepare();
    8786}
     
    208207void UISettingsDialog::retranslateUi()
    209208{
    210     m_pLabelTitle->setText(QString());
     209#ifndef VBOX_GUI_WITH_TOOLBAR_SETTINGS
     210    /* Retranslate current page headline: */
     211    m_pLabelTitle->setText(m_pSelector->itemText(m_pSelector->currentId()));
     212#endif
    211213
    212214    /* Translate warning stuff: */
     
    214216    if (!m_fValid || !m_fSilent)
    215217        m_pWarningPane->setWarningLabel(m_strWarningHint);
    216 
    217 #ifndef VBOX_GUI_WITH_TOOLBAR_SETTINGS
    218     /* Retranslate current page headline: */
    219     m_pLabelTitle->setText(m_pSelector->itemText(m_pSelector->currentId()));
    220 #endif
    221218
    222219    /* Retranslate all validators: */
     
    600597void UISettingsDialog::prepare()
    601598{
    602     prepareWidgets();
    603 
    604     /* Configure title: */
     599    /* Prepare central-widget: */
     600    setCentralWidget(new QWidget);
     601    if (centralWidget())
     602    {
     603        /* Prepare main layout: */
     604        m_pLayoutMain = new QGridLayout(centralWidget());
     605        if (m_pLayoutMain)
     606        {
     607            /* Prepare widgets: */
     608            prepareSelector();
     609            prepareStack();
     610            prepareButtonBox();
     611        }
     612    }
     613
     614    /* Apply language settings: */
     615    retranslateUi();
     616}
     617
     618void UISettingsDialog::prepareSelector()
     619{
     620#ifdef VBOX_GUI_WITH_TOOLBAR_SETTINGS
     621    /* Prepare modern tool-bar selector: */
     622    m_pSelector = new UISettingsSelectorToolBar(this);
     623    if (m_pSelector)
     624    {
     625        static_cast<QIToolBar*>(m_pSelector->widget())->enableMacToolbar();
     626        addToolBar(qobject_cast<QToolBar*>(m_pSelector->widget()));
     627    }
     628
     629    /* No title in this mode, we change the title of the window: */
     630    m_pLayoutMain->setColumnMinimumWidth(0, 0);
     631    m_pLayoutMain->setHorizontalSpacing(0);
     632
     633#else /* !VBOX_GUI_WITH_TOOLBAR_SETTINGS */
     634
     635    /* Prepare classical tree-view selector: */
     636    m_pSelector = new UISettingsSelectorTreeView(centralWidget());
     637    if (m_pSelector)
     638    {
     639        m_pLayoutMain->addWidget(m_pSelector->widget(), 0, 0, 2, 1);
     640        m_pSelector->widget()->setFocus();
     641    }
     642
     643    /* Prepare title label: */
     644    m_pLabelTitle = new QLabel(centralWidget());
    605645    if (m_pLabelTitle)
    606646    {
    607         /* Page-title font is bold and larger but derived from the system font: */
    608         QFont pageTitleFont = font();
    609         pageTitleFont.setBold(true);
    610         pageTitleFont.setPointSize(pageTitleFont.pointSize() + 2);
    611         m_pLabelTitle->setFont(pageTitleFont);
    612     }
    613 
    614     /* Prepare selector: */
    615     QGridLayout *pMainLayout = static_cast<QGridLayout*>(centralWidget()->layout());
    616     if (pMainLayout)
    617     {
    618 #ifdef VBOX_GUI_WITH_TOOLBAR_SETTINGS
    619 
    620         /* No page-title with tool-bar: */
    621         m_pLabelTitle->hide();
    622 
    623         /* Create modern tool-bar selector: */
    624         m_pSelector = new UISettingsSelectorToolBar(this);
    625         if (m_pSelector)
    626         {
    627             /* Configure tool-bar: */
    628             static_cast<QIToolBar*>(m_pSelector->widget())->enableMacToolbar();
    629 
    630             /* Add tool-bar into page: */
    631             addToolBar(qobject_cast<QToolBar*>(m_pSelector->widget()));
    632         }
    633 
    634         /* No title in this mode, we change the title of the window: */
    635         pMainLayout->setColumnMinimumWidth(0, 0);
    636         pMainLayout->setHorizontalSpacing(0);
    637 
    638 #else /* !VBOX_GUI_WITH_TOOLBAR_SETTINGS */
    639 
    640         /* Create classical tree-view selector: */
    641         m_pSelector = new UISettingsSelectorTreeView(this);
    642         if (m_pSelector)
    643         {
    644             /* Add into layout: */
    645             pMainLayout->addWidget(m_pSelector->widget(), 0, 0, 2, 1);
    646 
    647             /* Set focus: */
    648             m_pSelector->widget()->setFocus();
    649         }
    650 
     647        m_pLabelTitle->setSizePolicy(QSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Fixed));
     648        QPalette pal = QApplication::palette();
     649        pal.setColor(QPalette::Active, QPalette::Window, pal.color(QPalette::Active, QPalette::Base));
     650        m_pLabelTitle->setPalette(pal);
     651        QFont fnt;
     652        fnt.setFamily(QStringLiteral("Sans Serif"));
     653//        fnt.setPointSize(11);
     654        fnt.setPointSize(fnt.pointSize() + 2);
     655        fnt.setBold(true);
     656        fnt.setWeight(QFont::ExtraBold);
     657        m_pLabelTitle->setFont(fnt);
     658        m_pLabelTitle->setAutoFillBackground(true);
     659        m_pLabelTitle->setFrameShadow(QFrame::Sunken);
     660        m_pLabelTitle->setMargin(9);
     661
     662        /* Add title-label into main layout: */
     663        m_pLayoutMain->addWidget(m_pLabelTitle, 0, 1);
     664    }
    651665#endif /* !VBOX_GUI_WITH_TOOLBAR_SETTINGS */
    652666
    653         connect(m_pSelector, &UISettingsSelectorTreeView::sigCategoryChanged, this, &UISettingsDialog::sltCategoryChanged);
    654     }
    655 
    656     /* Prepare stack-handler: */
    657     if (m_pWidgetStackHandler)
    658     {
    659         /* Create page-stack layout: */
    660         QVBoxLayout *pStackLayout = new QVBoxLayout(m_pWidgetStackHandler);
    661         if (pStackLayout)
    662         {
    663             /* Confugre page-stack layout: */
    664             pStackLayout->setContentsMargins(0, 0, 0, 0);
    665 
    666             /* Create page-stack: */
    667             m_pStack = new QStackedWidget;
    668             if (m_pStack)
    669             {
    670                 /* Configure page-stack: */
    671                 popupCenter().setPopupStackOrientation(m_pStack, UIPopupStackOrientation_Bottom);
    672 
    673                 /* Add into layout: */
    674                 pStackLayout->addWidget(m_pStack);
    675             }
    676         }
    677     }
    678 
     667    /* Configure selector created above: */
     668    if (m_pSelector)
     669        connect(m_pSelector, &UISettingsSelectorTreeView::sigCategoryChanged,
     670                this, &UISettingsDialog::sltCategoryChanged);
     671}
     672
     673void UISettingsDialog::prepareStack()
     674{
     675    /* Prepare page-stack: */
     676    m_pStack = new QStackedWidget(centralWidget());
     677    if (m_pStack)
     678    {
     679        /* Configure page-stack: */
     680        popupCenter().setPopupStackOrientation(m_pStack, UIPopupStackOrientation_Bottom);
     681
     682        /* Add page-stack into main layout: */
     683        m_pLayoutMain->addWidget(m_pStack, 1, 1);
     684    }
     685}
     686
     687void UISettingsDialog::prepareButtonBox()
     688{
    679689    /* Prepare button-box: */
     690    m_pButtonBox = new QIDialogButtonBox(centralWidget());
    680691    if (m_pButtonBox)
    681692    {
    682         /* Create status-bar: */
    683         m_pStatusBar = new QStackedWidget;
     693#ifndef VBOX_WS_MAC
     694        m_pButtonBox->setStandardButtons(QDialogButtonBox::Ok | QDialogButtonBox::Cancel |
     695                                         QDialogButtonBox::NoButton | QDialogButtonBox::Help);
     696        m_pButtonBox->button(QDialogButtonBox::Help)->setShortcut(QKeySequence::HelpContents);
     697#else
     698        // WORKAROUND:
     699        // No Help button on macOS for now, conflict with old Qt.
     700        m_pButtonBox->setStandardButtons(QDialogButtonBox::Ok | QDialogButtonBox::Cancel |
     701                                         QDialogButtonBox::NoButton);
     702#endif
     703        m_pButtonBox->button(QDialogButtonBox::Ok)->setShortcut(Qt::Key_Return);
     704        m_pButtonBox->button(QDialogButtonBox::Cancel)->setShortcut(Qt::Key_Escape);
     705        connect(m_pButtonBox, &QIDialogButtonBox::rejected, this, &UISettingsDialog::close);
     706        connect(m_pButtonBox, &QIDialogButtonBox::accepted, this, &UISettingsDialog::accept);
     707#ifndef VBOX_WS_MAC
     708        connect(m_pButtonBox->button(QDialogButtonBox::Help), &QAbstractButton::pressed,
     709                m_pButtonBox, &QIDialogButtonBox::sltHandleHelpRequest);
     710#endif
     711
     712        /* Prepare status-bar: */
     713        m_pStatusBar = new QStackedWidget(m_pButtonBox);
    684714        if (m_pStatusBar)
    685715        {
     
    687717            m_pStatusBar->addWidget(new QWidget);
    688718
    689             /* Create process-bar: */
    690             m_pProcessBar = new QProgressBar;
     719            /* Prepare process-bar: */
     720            m_pProcessBar = new QProgressBar(m_pStatusBar);
    691721            if (m_pProcessBar)
    692722            {
    693                 /* Configure process-bar: */
    694723                m_pProcessBar->setMinimum(0);
    695724                m_pProcessBar->setMaximum(100);
    696 
    697                 /* Add into status-bar: */
    698725                m_pStatusBar->addWidget(m_pProcessBar);
    699726            }
    700727
    701             /* Create warning-pane: */
    702             m_pWarningPane = new UIWarningPane;
     728            /* Prepare warning-pane: */
     729            m_pWarningPane = new UIWarningPane(m_pStatusBar);
    703730            if (m_pWarningPane)
    704731            {
    705                 /* Configure warning-pane: */
    706732                connect(m_pWarningPane, &UIWarningPane::sigHoverEnter,
    707733                        this, &UISettingsDialog::sltHandleWarningPaneHovered);
    708734                connect(m_pWarningPane, &UIWarningPane::sigHoverLeave,
    709735                        this, &UISettingsDialog::sltHandleWarningPaneUnhovered);
    710 
    711                 /* Add into status-bar: */
    712736                m_pStatusBar->addWidget(m_pWarningPane);
    713737            }
     
    716740            m_pButtonBox->addExtraWidget(m_pStatusBar);
    717741        }
    718     }
    719 
    720     /* Apply language settings: */
    721     retranslateUi();
    722 }
    723 
    724 void UISettingsDialog::prepareWidgets()
    725 {
    726     /* Prepare central-widget: */
    727     setCentralWidget(new QWidget);
    728     if (centralWidget())
    729     {
    730         /* Prepare main layout: */
    731         QGridLayout *pLayoutMain = new QGridLayout(centralWidget());
    732         if (pLayoutMain)
    733         {
    734             /* Prepare title label: */
    735             m_pLabelTitle = new QLabel(centralWidget());
    736             if (m_pLabelTitle)
    737             {
    738                 m_pLabelTitle->setSizePolicy(QSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Fixed));
    739                 QPalette pal = QApplication::palette();
    740                 pal.setColor(QPalette::Active, QPalette::Window, pal.color(QPalette::Active, QPalette::Base));
    741                 m_pLabelTitle->setPalette(pal);
    742                 QFont fnt;
    743                 fnt.setFamily(QStringLiteral("Sans Serif"));
    744                 fnt.setPointSize(11);
    745                 fnt.setBold(true);
    746                 fnt.setWeight(QFont::ExtraBold);
    747                 m_pLabelTitle->setFont(fnt);
    748                 m_pLabelTitle->setAutoFillBackground(true);
    749                 m_pLabelTitle->setFrameShadow(QFrame::Sunken);
    750                 m_pLabelTitle->setMargin(9);
    751 
    752                 pLayoutMain->addWidget(m_pLabelTitle, 0, 1);
    753             }
    754 
    755             /* Prepare widget stack handler: */
    756             m_pWidgetStackHandler = new QWidget(centralWidget());
    757             if (m_pWidgetStackHandler)
    758             {
    759                 m_pWidgetStackHandler->setSizePolicy(QSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding));
    760                 pLayoutMain->addWidget(m_pWidgetStackHandler, 1, 1);
    761             }
    762 
    763             /* Prepare button-box: */
    764             m_pButtonBox = new QIDialogButtonBox(centralWidget());
    765             if (m_pButtonBox)
    766             {
    767 #ifndef VBOX_WS_MAC
    768                 m_pButtonBox->setStandardButtons(QDialogButtonBox::Ok | QDialogButtonBox::Cancel |
    769                                                  QDialogButtonBox::NoButton | QDialogButtonBox::Help);
    770                 m_pButtonBox->button(QDialogButtonBox::Help)->setShortcut(QKeySequence::HelpContents);
    771 #else
    772                 // WORKAROUND:
    773                 // No Help button on macOS for now, conflict with old Qt.
    774                 m_pButtonBox->setStandardButtons(QDialogButtonBox::Ok | QDialogButtonBox::Cancel |
    775                                                  QDialogButtonBox::NoButton);
    776 #endif
    777                 m_pButtonBox->button(QDialogButtonBox::Ok)->setShortcut(Qt::Key_Return);
    778                 m_pButtonBox->button(QDialogButtonBox::Cancel)->setShortcut(Qt::Key_Escape);
    779                 connect(m_pButtonBox, &QIDialogButtonBox::rejected, this, &UISettingsDialog::close);
    780                 connect(m_pButtonBox, &QIDialogButtonBox::accepted, this, &UISettingsDialog::accept);
    781 #ifndef VBOX_WS_MAC
    782                 connect(m_pButtonBox->button(QDialogButtonBox::Help), &QAbstractButton::pressed,
    783                         m_pButtonBox, &QIDialogButtonBox::sltHandleHelpRequest);
    784 #endif
    785 
    786                 pLayoutMain->addWidget(m_pButtonBox, 2, 0, 1, 2);
    787             }
    788         }
     742
     743        /* Add button-box into main layout: */
     744        m_pLayoutMain->addWidget(m_pButtonBox, 2, 0, 1, 2);
    789745    }
    790746}
  • trunk/src/VBox/Frontends/VirtualBox/src/settings/UISettingsDialog.h

    r100902 r100923  
    4141/* Forward declarations: */
    4242class QEvent;
     43class QGridLayout;
    4344class QObject;
    4445class QLabel;
     
    174175    /** Holds the page selector instance. */
    175176    UISettingsSelector *m_pSelector;
    176     /** Holds the page stack instance. */
    177     QStackedWidget     *m_pStack;
    178177
    179178private slots:
     
    189188private:
    190189
    191     /** Prepares all. */
    192     void prepare();
    193     /** Prepares widgets. */
    194     void prepareWidgets();
     190    /** @name Prepare/cleanup cascade.
     191     * @{ */
     192        /** Prepares all. */
     193        void prepare();
     194        /** Prepares selector. */
     195        void prepareSelector();
     196        /** Prepare stack. */
     197        void prepareStack();
     198        /** Prepare button-box. */
     199        void prepareButtonBox();
     200    /** @} */
     201
    195202    /** Assigns validater for passed @a pPage. */
    196203    void assignValidator(UISettingsPage *pPage);
     
    239246    /** @name Widgets
    240247     * @{ */
    241        QLabel            *m_pLabelTitle;
    242        QIDialogButtonBox *m_pButtonBox;
    243        QWidget           *m_pWidgetStackHandler;
     248        /** Holds the main layout instance. */
     249        QGridLayout       *m_pLayoutMain;
     250        /** Holds the title-label instance. */
     251        QLabel            *m_pLabelTitle;
     252        /** Holds the page-stack instance. */
     253        QStackedWidget    *m_pStack;
     254        /** Holds the button-box instance. */
     255        QIDialogButtonBox *m_pButtonBox;
    244256    /** @} */
    245257};
Note: See TracChangeset for help on using the changeset viewer.

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