VirtualBox

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


Ignore:
Timestamp:
Aug 28, 2023 3:28:43 PM (17 months ago)
Author:
vboxsync
Message:

FE/Qt: bugref:10513: UIAdvancedSettingsDialog: Replace page stack with scroll-area.

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

Legend:

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

    r100979 r100989  
    10771077        src/medium/viso/UIVisoCreator.cpp \
    10781078        src/notificationcenter/UINotificationCenter.cpp \
     1079        src/settings/UIAdvancedSettingsDialog.cpp \
    10791080        src/settings/editors/UIBaseMemoryEditor.cpp \
    10801081        src/settings/editors/UIBootOrderEditor.cpp \
  • trunk/src/VBox/Frontends/VirtualBox/src/settings/UIAdvancedSettingsDialog.cpp

    r100988 r100989  
    3232#include <QProgressBar>
    3333#include <QPushButton>
     34#include <QScrollArea>
     35#include <QScrollBar>
    3436#include <QStackedWidget>
    3537#include <QVariant>
     
    6062#endif
    6163
     64
     65/** QScrollArea extension to be used for
     66  * advanced settings dialog. The idea is to make
     67  * vertical scroll-bar always visible, keeping
     68  * horizontal scroll-bar always hidden. */
     69class UIVerticalScrollArea : public QScrollArea
     70{
     71    Q_OBJECT;
     72
     73public:
     74
     75    /** Constructs vertical scroll-area passing @a pParent to the base-class. */
     76    UIVerticalScrollArea(QWidget *pParent);
     77
     78protected:
     79
     80    /** Holds the minimum widget size. */
     81    virtual QSize minimumSizeHint() const RT_OVERRIDE;
     82};
     83
     84
     85/*********************************************************************************************************************************
     86*   Class UIVerticalScrollArea implementation.                                                                                   *
     87*********************************************************************************************************************************/
     88
     89UIVerticalScrollArea::UIVerticalScrollArea(QWidget *pParent)
     90    : QScrollArea(pParent)
     91{
     92    /* Make vertical scroll-bar always visible. */
     93    setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
     94}
     95
     96QSize UIVerticalScrollArea::minimumSizeHint() const
     97{
     98    /* To make horizontal scroll-bar always hidden we'll
     99     * have to make sure minimum size-hint updated accordingly. */
     100    const int iMinWidth = viewportSizeHint().width()
     101                        + verticalScrollBar()->sizeHint().width()
     102                        + frameWidth() * 2;
     103    const int iMinHeight = qMax(QScrollArea::minimumSizeHint().height(),
     104                                (int)(iMinWidth / 1.6));
     105    return QSize(iMinWidth, iMinHeight);
     106}
     107
     108
     109/*********************************************************************************************************************************
     110*   Class UIAdvancedSettingsDialog implementation.                                                                               *
     111*********************************************************************************************************************************/
    62112
    63113UIAdvancedSettingsDialog::UIAdvancedSettingsDialog(QWidget *pParent,
     
    80130    , m_fSilent(true)
    81131    , m_pLayoutMain(0)
    82     , m_pStack(0)
     132    , m_pScrollArea(0)
     133    , m_pScrollViewport(0)
    83134    , m_pButtonBox(0)
    84135{
     
    110161void UIAdvancedSettingsDialog::sltCategoryChanged(int cId)
    111162{
    112 #ifndef VBOX_WS_MAC
    113     if (m_pButtonBox)
    114         uiCommon().setHelpKeyword(m_pButtonBox->button(QDialogButtonBox::Help), m_pageHelpKeywords[cId]);
    115 #endif
    116     const int iIndex = m_pages.value(cId);
    117 
    118 #ifdef VBOX_WS_MAC
    119     /* If index is within the stored size list bounds: */
    120     if (iIndex < m_sizeList.count())
    121     {
    122         /* Get current/stored size: */
    123         const QSize cs = size();
    124         const QSize ss = m_sizeList.at(iIndex);
    125 
    126         /* Switch to the new page first if we are shrinking: */
    127         if (cs.height() > ss.height())
    128             m_pStack->setCurrentIndex(iIndex);
    129 
    130         /* Do the animation: */
    131         ::darwinWindowAnimateResize(this, QRect (x(), y(), ss.width(), ss.height()));
    132 
    133         /* Switch to the new page last if we are zooming: */
    134         if (cs.height() <= ss.height())
    135             m_pStack->setCurrentIndex(iIndex);
    136 
    137         /* Unlock all page policies but lock the current one: */
    138         for (int i = 0; i < m_pStack->count(); ++i)
    139             m_pStack->widget(i)->setSizePolicy(QSizePolicy::Minimum, i == iIndex ? QSizePolicy::Minimum : QSizePolicy::Ignored);
    140 
    141         /* And make sure layouts are freshly calculated: */
    142         foreach (QLayout *pLayout, findChildren<QLayout*>())
    143         {
    144             pLayout->update();
    145             pLayout->activate();
    146         }
    147     }
    148 #else /* !VBOX_WS_MAC */
    149     m_pStack->setCurrentIndex(iIndex);
    150 #endif /* !VBOX_WS_MAC */
    151 
    152163#ifdef VBOX_GUI_WITH_TOOLBAR_SETTINGS
    153164    setWindowTitle(title());
     165#endif
     166
     167    /* Let's calculate scroll-bar shift: */
     168    int iShift = 0;
     169    /* We'll have to take upper content's margin into account: */
     170    int iL, iT, iR, iB;
     171    m_pScrollViewport->layout()->getContentsMargins(&iL, &iT, &iR, &iB);
     172    iShift -= iT;
     173    /* And actual page position according to parent: */
     174    const QPoint pnt = m_pages.value(cId)->pos();
     175    iShift += pnt.y();
     176    /* Make sure corresponding page is visible: */
     177    m_pScrollArea->verticalScrollBar()->setValue(iShift);
     178
     179#ifndef VBOX_WS_MAC
     180    uiCommon().setHelpKeyword(m_pButtonBox->button(QDialogButtonBox::Help), m_pageHelpKeywords.value(cId));
    154181#endif
    155182}
     
    209236void UIAdvancedSettingsDialog::polishEvent()
    210237{
    211     /* Check what's the minimum selector size: */
    212     const int iMinWidth = m_pSelector->minWidth();
    213 
    214 #ifdef VBOX_WS_MAC
    215 
    216     /* Remove all title bar buttons (Buggy Qt): */
    217     ::darwinSetHidesAllTitleButtons(this);
    218 
    219     /* Unlock all page policies initially: */
    220     for (int i = 0; i < m_pStack->count(); ++i)
    221         m_pStack->widget(i)->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Ignored);
    222 
    223     /* Activate every single page to get the optimal size: */
    224     for (int i = m_pStack->count() - 1; i >= 0; --i)
    225     {
    226         /* Activate current page: */
    227         m_pStack->setCurrentIndex(i);
    228 
    229         /* Lock current page policy temporary: */
    230         m_pStack->widget(i)->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
    231         /* And make sure layouts are freshly calculated: */
    232         foreach (QLayout *pLayout, findChildren<QLayout*>())
    233         {
    234             pLayout->update();
    235             pLayout->activate();
    236         }
    237 
    238         /* Acquire minimum size-hint: */
    239         QSize s = minimumSizeHint();
    240         // WORKAROUND:
    241         // Take into account the height of native tool-bar title.
    242         // It will be applied only after widget is really shown.
    243         // The height is 11pix * 2 (possible HiDPI support).
    244         s.setHeight(s.height() + 11 * 2);
    245         /* Also make sure that width is no less than tool-bar: */
    246         if (iMinWidth > s.width())
    247             s.setWidth(iMinWidth);
    248         /* And remember the size finally: */
    249         m_sizeList.insert(0, s);
    250 
    251         /* Unlock the policy for current page again: */
    252         m_pStack->widget(i)->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Ignored);
    253     }
    254 
    255     sltCategoryChanged(m_pSelector->currentId());
    256 
    257 #else /* VBOX_WS_MAC */
    258 
    259     /* Resize to the minimum possible size: */
    260     QSize s = minimumSize();
    261     if (iMinWidth > s.width())
    262         s.setWidth(iMinWidth);
    263     resize(s);
    264 
    265 #endif /* VBOX_WS_MAC */
     238    /* Resize to minimum size: */
     239    resize(minimumSizeHint());
     240
     241    /* Choose page/tab finally: */
     242    choosePageAndTab();
    266243
    267244    /* Explicit centering according to our parent: */
     
    298275        if (!m_strControl.isNull())
    299276        {
    300             if (QWidget *pWidget = m_pStack->findChild<QWidget*>(m_strControl))
     277            if (QWidget *pWidget = m_pScrollViewport->findChild<QWidget*>(m_strControl))
    301278            {
    302279                QList<QWidget*> parents;
     
    415392                                              cId, strLink, pSettingsPage, iParentId))
    416393    {
    417         /* Add stack-widget page if created: */
    418         m_pages[cId] = m_pStack->addWidget(pPage);
    419     }
     394        /* Add page to scroll-viewport layout: */
     395        m_pScrollViewport->layout()->addWidget(pPage);
     396
     397        /* Remember widget for referencing: */
     398        m_pages[cId] = pPage;
     399    }
     400
    420401    /* Assign validator if necessary: */
    421402    if (pSettingsPage)
     
    523504    /* Show corresponding popup: */
    524505    if (!m_fValid || !m_fSilent)
    525         popupCenter().popup(m_pStack, "SettingsDialogWarning",
     506        popupCenter().popup(m_pScrollArea, "SettingsDialogWarning",
    526507                            pValidator->lastMessage());
    527508}
     
    532513
    533514    /* Recall corresponding popup: */
    534     popupCenter().recall(m_pStack, "SettingsDialogWarning");
     515    popupCenter().recall(m_pScrollArea, "SettingsDialogWarning");
    535516}
    536517
     
    547528            /* Prepare widgets: */
    548529            prepareSelector();
    549             prepareStack();
     530            prepareScrollArea();
    550531            prepareButtonBox();
    551532        }
     
    588569}
    589570
    590 void UIAdvancedSettingsDialog::prepareStack()
    591 {
    592     /* Prepare page-stack: */
    593     m_pStack = new QStackedWidget(centralWidget());
    594     if (m_pStack)
    595     {
    596         /* Configure page-stack: */
    597         popupCenter().setPopupStackOrientation(m_pStack, UIPopupStackOrientation_Bottom);
    598 
    599         /* Add page-stack into main layout: */
    600         m_pLayoutMain->addWidget(m_pStack, 1, 1);
     571void UIAdvancedSettingsDialog::prepareScrollArea()
     572{
     573    /* Prepare scroll-area: */
     574    m_pScrollArea = new UIVerticalScrollArea(centralWidget());
     575    if (m_pScrollArea)
     576    {
     577        /* Configure popup-stack: */
     578        popupCenter().setPopupStackOrientation(m_pScrollArea, UIPopupStackOrientation_Bottom);
     579
     580        m_pScrollArea->setWidgetResizable(true);
     581        m_pScrollArea->setFrameShape(QFrame::NoFrame);
     582
     583        /* Prepare scroll-viewport: */
     584        m_pScrollViewport = new QWidget(m_pScrollArea);
     585        if (m_pScrollViewport)
     586        {
     587            QVBoxLayout *pLayout = new QVBoxLayout(m_pScrollViewport);
     588            int iL, iT, iR, iB;
     589            pLayout->getContentsMargins(&iL, &iT, &iR, &iB);
     590            pLayout->setContentsMargins(0, 0, iR, 0);
     591            int iSpacing = pLayout->spacing();
     592            pLayout->setSpacing(2 * iSpacing);
     593            m_pScrollArea->setWidget(m_pScrollViewport);
     594        }
     595
     596        /* Add scroll-area into main layout: */
     597        m_pLayoutMain->addWidget(m_pScrollArea, 1, 1);
    601598    }
    602599}
     
    670667
    671668    /* Recall popup-pane if any: */
    672     popupCenter().recall(m_pStack, "SettingsDialogWarning");
     669    popupCenter().recall(m_pScrollArea, "SettingsDialogWarning");
    673670
    674671    /* Delete selector early! */
    675672    delete m_pSelector;
    676673}
     674
     675#include "UIAdvancedSettingsDialog.moc"
  • trunk/src/VBox/Frontends/VirtualBox/src/settings/UIAdvancedSettingsDialog.h

    r100988 r100989  
    4242class QGridLayout;
    4343class QProgressBar;
     44class QScrollArea;
    4445class QShowEvent;
    4546class QStackedWidget;
     
    188189        /** Prepares selector. */
    189190        void prepareSelector();
    190         /** Prepare stack. */
    191         void prepareStack();
     191        /** Prepare scroll-area. */
     192        void prepareScrollArea();
    192193        /** Prepare button-box. */
    193194        void prepareButtonBox();
     
    228229
    229230    /** Holds the map of settings pages. */
    230     QMap<int, int>      m_pages;
    231     /** Stores the help tag per page. Key is the page type (either GlobalSettingsPageType or MachineSettingsPageType)
    232       * and value is the help tag. Used in context sensitive help: */
     231    QMap<int, QWidget*>  m_pages;
     232
     233    /** Stores the help tag per page. */
    233234    QMap<int, QString>  m_pageHelpKeywords;
    234 
    235 #ifdef VBOX_WS_MAC
    236     /** Holds the list of settings page sizes for animation purposes. */
    237     QList<QSize>  m_sizeList;
    238 #endif
    239235
    240236    /** @name Widgets
    241237     * @{ */
    242238        /** Holds the main layout instance. */
    243         QGridLayout       *m_pLayoutMain;
    244         /** Holds the page-stack instance. */
    245         QStackedWidget    *m_pStack;
     239        QGridLayout *m_pLayoutMain;
     240
     241        /** Holds the scroll-area instance. */
     242        QScrollArea *m_pScrollArea;
     243        /** Holds the scroll-viewport instance. */
     244        QWidget     *m_pScrollViewport;
     245
    246246        /** Holds the button-box instance. */
    247247        QIDialogButtonBox *m_pButtonBox;
  • trunk/src/VBox/Frontends/VirtualBox/src/settings/UIAdvancedSettingsDialogSpecific.cpp

    r100985 r100989  
    287287    /* Apply language settings: */
    288288    retranslateUi();
    289 
    290     /* Choose page/tab finally: */
    291     choosePageAndTab();
    292289}
    293290
     
    768765    /* Apply language settings: */
    769766    retranslateUi();
    770 
    771     /* Choose page/tab finally: */
    772     choosePageAndTab();
    773767}
    774768
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