VirtualBox

Ignore:
Timestamp:
Aug 28, 2023 3:43:56 PM (18 months ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
158931
Message:

FE/Qt: bugref:10513: UIAdvancedSettingsDialog: Adding frames with names around pages of scroll-area.

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

Legend:

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

    r100989 r100990  
    3030#include <QGridLayout>
    3131#include <QLabel>
     32#include <QPainter>
    3233#include <QProgressBar>
    3334#include <QPushButton>
     
    3536#include <QScrollBar>
    3637#include <QStackedWidget>
     38#include <QStyle>
    3739#include <QVariant>
    3840
     
    8284};
    8385
     86/** QWidget sub-class,
     87  * used as settings group-box. */
     88class UISettingsGroupBox : public QWidget
     89{
     90    Q_OBJECT;
     91
     92public:
     93
     94    /** Constructs details element passing @a pParent to the base-class. */
     95    UISettingsGroupBox(QWidget *pParent = 0);
     96
     97    /** Defines @a strName. */
     98    void setName(const QString &strName);
     99
     100    /** Adds a @a pWidget into group-box. */
     101    void addWidget(QWidget *pWidget);
     102
     103protected:
     104
     105    /** Handles paint @a pEvent. */
     106    virtual void paintEvent(QPaintEvent *pEvent) RT_OVERRIDE;
     107
     108private:
     109
     110    /** Prepares all. */
     111    void prepare();
     112
     113    /** Holds the element name.*/
     114    QString  m_strName;
     115
     116    /** Holds the name label instance. */
     117    QLabel  *m_pLabelName;
     118    /** Holds the contents widget instance. */
     119    QWidget *m_pWidget;
     120    /** Holds the contents layout instance. */
     121    QLayout *m_pLayout;
     122};
     123
    84124
    85125/*********************************************************************************************************************************
     
    104144                                (int)(iMinWidth / 1.6));
    105145    return QSize(iMinWidth, iMinHeight);
     146}
     147
     148
     149/*********************************************************************************************************************************
     150*   Class UISettingsGroupBox implementation.                                                                                     *
     151*********************************************************************************************************************************/
     152
     153UISettingsGroupBox::UISettingsGroupBox(QWidget *pParent /* = 0 */)
     154    : QWidget(pParent)
     155    , m_pLabelName(0)
     156    , m_pWidget(0)
     157    , m_pLayout(0)
     158{
     159    prepare();
     160}
     161
     162void UISettingsGroupBox::setName(const QString &strName)
     163{
     164    if (m_strName == strName)
     165        return;
     166
     167    m_strName = strName;
     168    if (m_pLabelName)
     169        m_pLabelName->setText(m_strName);
     170}
     171
     172void UISettingsGroupBox::addWidget(QWidget *pWidget)
     173{
     174    m_pLayout->addWidget(pWidget);
     175}
     176
     177void UISettingsGroupBox::paintEvent(QPaintEvent *pPaintEvent)
     178{
     179    /* Prepare painter: */
     180    QPainter painter(this);
     181    /* Avoid painting more than necessary: */
     182    painter.setClipRect(pPaintEvent->rect());
     183
     184    /* Prepare palette colors: */
     185    const QPalette pal = QApplication::palette();
     186    QColor color0 = pal.color(QPalette::Window);
     187    QColor color1 = pal.color(QPalette::Window).lighter(110);
     188    color1.setAlpha(0);
     189    QColor color2 = pal.color(QPalette::Window).darker(200);
     190
     191    /* Acquire contents rect: */
     192    QRect cRect = m_pWidget->geometry();
     193    const int iX = cRect.x();
     194    const int iY = cRect.y();
     195    const int iWidth = cRect.width();
     196    const int iHeight = cRect.height();
     197
     198    /* Invent pixel metric: */
     199    const int iMetric = QApplication::style()->pixelMetric(QStyle::PM_SmallIconSize) / 4;
     200
     201    /* Top-left corner: */
     202    QRadialGradient grad1(QPointF(iX + iMetric, iY + iMetric), iMetric);
     203    {
     204        grad1.setColorAt(0, color2);
     205        grad1.setColorAt(1, color1);
     206    }
     207    /* Top-right corner: */
     208    QRadialGradient grad2(QPointF(iX + iWidth - iMetric, iY + iMetric), iMetric);
     209    {
     210        grad2.setColorAt(0, color2);
     211        grad2.setColorAt(1, color1);
     212    }
     213    /* Bottom-left corner: */
     214    QRadialGradient grad3(QPointF(iX + iMetric, iY + iHeight - iMetric), iMetric);
     215    {
     216        grad3.setColorAt(0, color2);
     217        grad3.setColorAt(1, color1);
     218    }
     219    /* Botom-right corner: */
     220    QRadialGradient grad4(QPointF(iX + iWidth - iMetric, iY + iHeight - iMetric), iMetric);
     221    {
     222        grad4.setColorAt(0, color2);
     223        grad4.setColorAt(1, color1);
     224    }
     225
     226    /* Top line: */
     227    QLinearGradient grad5(QPointF(iX + iMetric, iY), QPointF(iX + iMetric, iY + iMetric));
     228    {
     229        grad5.setColorAt(0, color1);
     230        grad5.setColorAt(1, color2);
     231    }
     232    /* Bottom line: */
     233    QLinearGradient grad6(QPointF(iX + iMetric, iY + iHeight), QPointF(iX + iMetric, iY + iHeight - iMetric));
     234    {
     235        grad6.setColorAt(0, color1);
     236        grad6.setColorAt(1, color2);
     237    }
     238    /* Left line: */
     239    QLinearGradient grad7(QPointF(iX, iY + iHeight - iMetric), QPointF(iX + iMetric, iY + iHeight - iMetric));
     240    {
     241        grad7.setColorAt(0, color1);
     242        grad7.setColorAt(1, color2);
     243    }
     244    /* Right line: */
     245    QLinearGradient grad8(QPointF(iX + iWidth, iY + iHeight - iMetric), QPointF(iX + iWidth - iMetric, iY + iHeight - iMetric));
     246    {
     247        grad8.setColorAt(0, color1);
     248        grad8.setColorAt(1, color2);
     249    }
     250
     251    /* Paint shape/shadow: */
     252    painter.fillRect(QRect(iX + iMetric,          iY + iMetric,           iWidth - iMetric * 2, iHeight - iMetric * 2), color0);
     253    painter.fillRect(QRect(iX,                    iY,                     iMetric,              iMetric),               grad1);
     254    painter.fillRect(QRect(iX + iWidth - iMetric, iY,                     iMetric,              iMetric),               grad2);
     255    painter.fillRect(QRect(iX,                    iY + iHeight - iMetric, iMetric,              iMetric),               grad3);
     256    painter.fillRect(QRect(iX + iWidth - iMetric, iY + iHeight - iMetric, iMetric,              iMetric),               grad4);
     257    painter.fillRect(QRect(iX + iMetric,          iY,                     iWidth - iMetric * 2, iMetric),               grad5);
     258    painter.fillRect(QRect(iX + iMetric,          iY + iHeight - iMetric, iWidth - iMetric * 2, iMetric),               grad6);
     259    painter.fillRect(QRect(iX,                    iY + iMetric,           iMetric,              iHeight - iMetric * 2), grad7);
     260    painter.fillRect(QRect(iX + iWidth - iMetric, iY + iMetric,           iMetric,              iHeight - iMetric * 2), grad8);
     261}
     262
     263void UISettingsGroupBox::prepare()
     264{
     265    /* Create main layout: */
     266    QVBoxLayout *pLayoutMain = new QVBoxLayout(this);
     267    if (pLayoutMain)
     268    {
     269        pLayoutMain->setContentsMargins(0, 0, 0, 0);
     270
     271        /* Create name label: */
     272        m_pLabelName = new QLabel(this);
     273        if (m_pLabelName)
     274            pLayoutMain->addWidget(m_pLabelName);
     275
     276        /* Create contents widget: */
     277        m_pWidget = new QWidget(this);
     278        if (m_pWidget)
     279        {
     280            m_pLayout = new QVBoxLayout(m_pWidget);
     281            pLayoutMain->addWidget(m_pWidget);
     282        }
     283    }
    106284}
    107285
     
    214392    /* Translate warning-pane stuff: */
    215393    m_pWarningPane->setWarningLabelText(tr("Invalid settings detected"));
     394
     395    /* Translate group-boxes: */
     396    foreach (int cId, m_pages.keys())
     397        m_pages.value(cId)->setName(m_pSelector->itemText(cId));
    216398
    217399    /* Retranslate all validators: */
     
    392574                                              cId, strLink, pSettingsPage, iParentId))
    393575    {
    394         /* Add page to scroll-viewport layout: */
    395         m_pScrollViewport->layout()->addWidget(pPage);
    396 
    397         /* Remember widget for referencing: */
    398         m_pages[cId] = pPage;
     576        /* Create group-box with page inside: */
     577        UISettingsGroupBox *pGroupBox = new UISettingsGroupBox(m_pScrollViewport);
     578        if (pGroupBox)
     579        {
     580            pGroupBox->addWidget(pPage);
     581            m_pScrollViewport->layout()->addWidget(pGroupBox);
     582
     583            /* Remember group-box for referencing: */
     584            m_pages[cId] = pGroupBox;
     585        }
    399586    }
    400587
  • trunk/src/VBox/Frontends/VirtualBox/src/settings/UIAdvancedSettingsDialog.h

    r100989 r100990  
    4747class QVariant;
    4848class QIDialogButtonBox;
     49class UISettingsGroupBox;
    4950class UISettingsPage;
    5051class UISettingsPageValidator;
     
    229230
    230231    /** Holds the map of settings pages. */
    231     QMap<int, QWidget*>  m_pages;
     232    QMap<int, UISettingsGroupBox*>  m_pages;
    232233
    233234    /** Stores the help tag per page. */
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