VirtualBox

Changeset 101333 in vbox for trunk/src/VBox


Ignore:
Timestamp:
Oct 3, 2023 2:40:43 PM (16 months ago)
Author:
vboxsync
Message:

FE/Qt: bugref:10513: Layout adjustment for VM settings / Storage page; This one is more complex, it prevents page size-hint blinking while changing selection from controller to attachment every time.

File:
1 edited

Legend:

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

    r101332 r101333  
    4242#include <QMouseEvent>
    4343#include <QPainter>
     44#include <QSizePolicy>
    4445#include <QSpinBox>
    4546#include <QStackedWidget>
     
    818819    /** Holds the medium device type. */
    819820    UIMediumDeviceType  m_enmType;
     821};
     822
     823
     824/** QWidget sub-class
     825  * with manual size-hint recalculation.
     826  * Tries to take into account size-hint even for hidden items.
     827  * Assumes QGridLayout is present as this widget is used purely
     828  * for controller/attachment pane. */
     829class UIWidgetOfMaximumSize : public QWidget
     830{
     831    Q_OBJECT;
     832
     833public:
     834
     835    /** Constructs widget passing @a pParent to base-class. */
     836    UIWidgetOfMaximumSize(QWidget *pParent = 0);
     837
     838    /** Returns the minimum widget size. */
     839    virtual QSize minimumSizeHint() const RT_OVERRIDE;
    820840};
    821841
     
    28292849
    28302850/*********************************************************************************************************************************
     2851*   Class UIWidgetOfMaximumSize implementation.                                                                                  *
     2852*********************************************************************************************************************************/
     2853
     2854UIWidgetOfMaximumSize::UIWidgetOfMaximumSize(QWidget *pParent /* = 0 */)
     2855    : QWidget(pParent)
     2856{
     2857}
     2858
     2859QSize UIWidgetOfMaximumSize::minimumSizeHint() const
     2860{
     2861    /* Assume there is just one grid-layout: */
     2862    QList<QGridLayout*> gridLayouts = findChildren<QGridLayout*>();
     2863    AssertReturn(gridLayouts.size() == 1, QWidget::minimumSizeHint());
     2864    QGridLayout *pLayout = gridLayouts.first();
     2865    AssertPtrReturn(pLayout, QWidget::minimumSizeHint());
     2866
     2867    /* Acquire layout spacing: */
     2868    const int iSpacing = pLayout->spacing();
     2869
     2870    /* Calcualte column widths: */
     2871    QList<int> columns(pLayout->columnCount());
     2872    for (int iColumn = 0; iColumn < pLayout->columnCount(); ++iColumn)
     2873        for (int iRow = 0; iRow < pLayout->rowCount(); ++iRow)
     2874        {
     2875            QLayoutItem *pItem = pLayout->itemAtPosition(iRow, iColumn);
     2876            if (!pItem)
     2877                continue;
     2878            if (QWidget *pWidget = pItem->widget())
     2879            {
     2880                const QSizePolicy sp = pWidget->sizePolicy();
     2881                if (sp.horizontalPolicy() != QSizePolicy::Ignored)
     2882                    columns[iColumn] = qMax(columns.at(iColumn), pWidget->minimumSizeHint().width());
     2883            }
     2884        }
     2885
     2886    /* Calcualte row heights: */
     2887    QList<int> rows(pLayout->rowCount());
     2888    for (int iRow = 0; iRow < pLayout->rowCount(); ++iRow)
     2889        for (int iColumn = 0; iColumn < pLayout->columnCount(); ++iColumn)
     2890        {
     2891            QLayoutItem *pItem = pLayout->itemAtPosition(iRow, iColumn);
     2892            if (!pItem)
     2893                continue;
     2894            if (QWidget *pWidget = pItem->widget())
     2895            {
     2896                const QSizePolicy sp = pWidget->sizePolicy();
     2897                if (sp.verticalPolicy() != QSizePolicy::Ignored)
     2898                    rows[iRow] = qMax(rows.at(iRow), pWidget->minimumSizeHint().height());
     2899            }
     2900        }
     2901
     2902    /* Calculate effective layout size: */
     2903    int iTotalWidth = 0;
     2904    for (int iColumn = 0; iColumn < columns.size(); ++iColumn)
     2905        iTotalWidth += columns.at(iColumn) + iSpacing;
     2906    int iTotalHeight = 0;
     2907    for (int iRow = 0; iRow < rows.size(); ++iRow)
     2908        iTotalHeight += rows.at(iRow) + iSpacing;
     2909    return QSize(iTotalWidth, iTotalHeight);
     2910}
     2911
     2912
     2913/*********************************************************************************************************************************
    28312914*   Class UIStorageSettingsEditor implementation.                                                                                *
    28322915*********************************************************************************************************************************/
     
    45414624{
    45424625    /* Create widget for controller case: */
    4543     QWidget *pWidgetController = new QWidget;
     4626    UIWidgetOfMaximumSize *pWidgetController = new UIWidgetOfMaximumSize;
    45444627    if (pWidgetController)
    45454628    {
     
    46204703{
    46214704    /* Create widget for attachment case: */
    4622     QWidget *pWidgetAttachment = new QWidget;
     4705    UIWidgetOfMaximumSize *pWidgetAttachment = new UIWidgetOfMaximumSize;
    46234706    if (pWidgetAttachment)
    46244707    {
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