VirtualBox

Changeset 101028 in vbox for trunk


Ignore:
Timestamp:
Sep 6, 2023 1:32:37 PM (13 months ago)
Author:
vboxsync
Message:

FE/Qt: bugref:10513: Moving UISettingsGroupBox to UISettingsPage; Renaming to UISettingsPageFrame.

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

Legend:

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

    r100990 r101028  
    2929#include <QCloseEvent>
    3030#include <QGridLayout>
    31 #include <QLabel>
    32 #include <QPainter>
    3331#include <QProgressBar>
    3432#include <QPushButton>
     
    3634#include <QScrollBar>
    3735#include <QStackedWidget>
    38 #include <QStyle>
    3936#include <QVariant>
     37#include <QVBoxLayout>
    4038
    4139/* GUI includes: */
     
    8482};
    8583
    86 /** QWidget sub-class,
    87   * used as settings group-box. */
    88 class UISettingsGroupBox : public QWidget
    89 {
    90     Q_OBJECT;
    91 
    92 public:
    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 
    103 protected:
    104 
    105     /** Handles paint @a pEvent. */
    106     virtual void paintEvent(QPaintEvent *pEvent) RT_OVERRIDE;
    107 
    108 private:
    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 
    12484
    12585/*********************************************************************************************************************************
     
    144104                                (int)(iMinWidth / 1.6));
    145105    return QSize(iMinWidth, iMinHeight);
    146 }
    147 
    148 
    149 /*********************************************************************************************************************************
    150 *   Class UISettingsGroupBox implementation.                                                                                     *
    151 *********************************************************************************************************************************/
    152 
    153 UISettingsGroupBox::UISettingsGroupBox(QWidget *pParent /* = 0 */)
    154     : QWidget(pParent)
    155     , m_pLabelName(0)
    156     , m_pWidget(0)
    157     , m_pLayout(0)
    158 {
    159     prepare();
    160 }
    161 
    162 void 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 
    172 void UISettingsGroupBox::addWidget(QWidget *pWidget)
    173 {
    174     m_pLayout->addWidget(pWidget);
    175 }
    176 
    177 void 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 
    263 void 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     }
    284106}
    285107
     
    350172    iShift -= iT;
    351173    /* And actual page position according to parent: */
    352     const QPoint pnt = m_pages.value(cId)->pos();
     174    const QPoint pnt = m_frames.value(cId)->pos();
    353175    iShift += pnt.y();
    354176    /* Make sure corresponding page is visible: */
     
    393215    m_pWarningPane->setWarningLabelText(tr("Invalid settings detected"));
    394216
    395     /* Translate group-boxes: */
    396     foreach (int cId, m_pages.keys())
    397         m_pages.value(cId)->setName(m_pSelector->itemText(cId));
     217    /* Translate page-frames: */
     218    foreach (int cId, m_frames.keys())
     219        m_frames.value(cId)->setName(m_pSelector->itemText(cId));
    398220
    399221    /* Retranslate all validators: */
     
    571393{
    572394    /* Add new selector item: */
    573     if (QWidget *pPage = m_pSelector->addItem(strBigIcon, strMediumIcon, strSmallIcon,
    574                                               cId, strLink, pSettingsPage, iParentId))
    575     {
    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;
     395    if (m_pSelector->addItem(strBigIcon, strMediumIcon, strSmallIcon,
     396                             cId, strLink, pSettingsPage, iParentId))
     397    {
     398        /* Create frame with page inside: */
     399        UISettingsPageFrame *pFrame = new UISettingsPageFrame(pSettingsPage, m_pScrollViewport);
     400        if (pFrame)
     401        {
     402            /* Add frame to scroll-viewport: */
     403            m_pScrollViewport->layout()->addWidget(pFrame);
     404
     405            /* Remember page-frame for referencing: */
     406            m_frames[cId] = pFrame;
    585407        }
    586408    }
     
    773595        {
    774596            QVBoxLayout *pLayout = new QVBoxLayout(m_pScrollViewport);
    775             int iL, iT, iR, iB;
    776             pLayout->getContentsMargins(&iL, &iT, &iR, &iB);
    777             pLayout->setContentsMargins(0, 0, iR, 0);
    778             int iSpacing = pLayout->spacing();
    779             pLayout->setSpacing(2 * iSpacing);
     597            if (pLayout)
     598            {
     599                pLayout->setAlignment(Qt::AlignTop);
     600                int iL, iT, iR, iB;
     601                pLayout->getContentsMargins(&iL, &iT, &iR, &iB);
     602                pLayout->setContentsMargins(0, 0, iR, 0);
     603                int iSpacing = pLayout->spacing();
     604                pLayout->setSpacing(2 * iSpacing);
     605            }
    780606            m_pScrollArea->setWidget(m_pScrollViewport);
    781607        }
  • trunk/src/VBox/Frontends/VirtualBox/src/settings/UIAdvancedSettingsDialog.h

    r100990 r101028  
    4747class QVariant;
    4848class QIDialogButtonBox;
    49 class UISettingsGroupBox;
    5049class UISettingsPage;
     50class UISettingsPageFrame;
    5151class UISettingsPageValidator;
    5252class UISettingsSelector;
     
    229229    QString  m_strWarningHint;
    230230
    231     /** Holds the map of settings pages. */
    232     QMap<int, UISettingsGroupBox*>  m_pages;
     231    /** Holds the map of settings page frames. */
     232    QMap<int, UISettingsPageFrame*>  m_frames;
    233233
    234234    /** Stores the help tag per page. */
  • trunk/src/VBox/Frontends/VirtualBox/src/settings/UISettingsPage.cpp

    r100968 r101028  
    2525 * SPDX-License-Identifier: GPL-3.0-only
    2626 */
     27
     28/* Qt includes: */
     29#include <QLabel>
     30#include <QPainter>
     31#include <QStyle>
     32#include <QVariant>
     33#include <QVBoxLayout>
    2734
    2835/* GUI includes: */
     
    152159    data = QVariant::fromValue(UISettingsDataMachine(m_machine, m_console));
    153160}
     161
     162
     163/*********************************************************************************************************************************
     164*   Class UISettingsPageFrame implementation.                                                                                    *
     165*********************************************************************************************************************************/
     166
     167UISettingsPageFrame::UISettingsPageFrame(UISettingsPage *pPage, QWidget *pParent /* = 0 */)
     168    : QWidget(pParent)
     169    , m_pPage(pPage)
     170    , m_pLabelName(0)
     171    , m_pWidget(0)
     172    , m_pLayout(0)
     173{
     174    prepare();
     175}
     176
     177void UISettingsPageFrame::setName(const QString &strName)
     178{
     179    if (m_strName == strName)
     180        return;
     181
     182    m_strName = strName;
     183    if (m_pLabelName)
     184        m_pLabelName->setText(m_strName);
     185}
     186
     187void UISettingsPageFrame::paintEvent(QPaintEvent *pPaintEvent)
     188{
     189    /* Prepare painter: */
     190    QPainter painter(this);
     191    /* Avoid painting more than necessary: */
     192    painter.setClipRect(pPaintEvent->rect());
     193
     194    /* Prepare palette colors: */
     195    const QPalette pal = QApplication::palette();
     196    QColor color0 = pal.color(QPalette::Window);
     197    QColor color1 = pal.color(QPalette::Window).lighter(110);
     198    color1.setAlpha(0);
     199    QColor color2 = pal.color(QPalette::Window).darker(200);
     200
     201    /* Acquire contents rect: */
     202    QRect cRect = m_pWidget->geometry();
     203    const int iX = cRect.x();
     204    const int iY = cRect.y();
     205    const int iWidth = cRect.width();
     206    const int iHeight = cRect.height();
     207
     208    /* Invent pixel metric: */
     209    const int iMetric = QApplication::style()->pixelMetric(QStyle::PM_SmallIconSize) / 4;
     210
     211    /* Top-left corner: */
     212    QRadialGradient grad1(QPointF(iX + iMetric, iY + iMetric), iMetric);
     213    {
     214        grad1.setColorAt(0, color2);
     215        grad1.setColorAt(1, color1);
     216    }
     217    /* Top-right corner: */
     218    QRadialGradient grad2(QPointF(iX + iWidth - iMetric, iY + iMetric), iMetric);
     219    {
     220        grad2.setColorAt(0, color2);
     221        grad2.setColorAt(1, color1);
     222    }
     223    /* Bottom-left corner: */
     224    QRadialGradient grad3(QPointF(iX + iMetric, iY + iHeight - iMetric), iMetric);
     225    {
     226        grad3.setColorAt(0, color2);
     227        grad3.setColorAt(1, color1);
     228    }
     229    /* Botom-right corner: */
     230    QRadialGradient grad4(QPointF(iX + iWidth - iMetric, iY + iHeight - iMetric), iMetric);
     231    {
     232        grad4.setColorAt(0, color2);
     233        grad4.setColorAt(1, color1);
     234    }
     235
     236    /* Top line: */
     237    QLinearGradient grad5(QPointF(iX + iMetric, iY), QPointF(iX + iMetric, iY + iMetric));
     238    {
     239        grad5.setColorAt(0, color1);
     240        grad5.setColorAt(1, color2);
     241    }
     242    /* Bottom line: */
     243    QLinearGradient grad6(QPointF(iX + iMetric, iY + iHeight), QPointF(iX + iMetric, iY + iHeight - iMetric));
     244    {
     245        grad6.setColorAt(0, color1);
     246        grad6.setColorAt(1, color2);
     247    }
     248    /* Left line: */
     249    QLinearGradient grad7(QPointF(iX, iY + iHeight - iMetric), QPointF(iX + iMetric, iY + iHeight - iMetric));
     250    {
     251        grad7.setColorAt(0, color1);
     252        grad7.setColorAt(1, color2);
     253    }
     254    /* Right line: */
     255    QLinearGradient grad8(QPointF(iX + iWidth, iY + iHeight - iMetric), QPointF(iX + iWidth - iMetric, iY + iHeight - iMetric));
     256    {
     257        grad8.setColorAt(0, color1);
     258        grad8.setColorAt(1, color2);
     259    }
     260
     261    /* Paint shape/shadow: */
     262    painter.fillRect(QRect(iX + iMetric,          iY + iMetric,           iWidth - iMetric * 2, iHeight - iMetric * 2), color0);
     263    painter.fillRect(QRect(iX,                    iY,                     iMetric,              iMetric),               grad1);
     264    painter.fillRect(QRect(iX + iWidth - iMetric, iY,                     iMetric,              iMetric),               grad2);
     265    painter.fillRect(QRect(iX,                    iY + iHeight - iMetric, iMetric,              iMetric),               grad3);
     266    painter.fillRect(QRect(iX + iWidth - iMetric, iY + iHeight - iMetric, iMetric,              iMetric),               grad4);
     267    painter.fillRect(QRect(iX + iMetric,          iY,                     iWidth - iMetric * 2, iMetric),               grad5);
     268    painter.fillRect(QRect(iX + iMetric,          iY + iHeight - iMetric, iWidth - iMetric * 2, iMetric),               grad6);
     269    painter.fillRect(QRect(iX,                    iY + iMetric,           iMetric,              iHeight - iMetric * 2), grad7);
     270    painter.fillRect(QRect(iX + iWidth - iMetric, iY + iMetric,           iMetric,              iHeight - iMetric * 2), grad8);
     271}
     272
     273void UISettingsPageFrame::prepare()
     274{
     275    /* Keep minimum vertical size: */
     276    setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Fixed);
     277
     278    /* Create main layout: */
     279    QVBoxLayout *pLayoutMain = new QVBoxLayout(this);
     280    if (pLayoutMain)
     281    {
     282        pLayoutMain->setContentsMargins(0, 0, 0, 0);
     283
     284        /* Create name label: */
     285        m_pLabelName = new QLabel(this);
     286        if (m_pLabelName)
     287            pLayoutMain->addWidget(m_pLabelName);
     288
     289        /* Create contents widget: */
     290        m_pWidget = new QWidget(this);
     291        if (m_pWidget)
     292        {
     293            m_pLayout = new QVBoxLayout(m_pWidget);
     294            if (m_pLayout)
     295                m_pLayout->addWidget(m_pPage);
     296            pLayoutMain->addWidget(m_pWidget);
     297        }
     298    }
     299}
  • trunk/src/VBox/Frontends/VirtualBox/src/settings/UISettingsPage.h

    r100959 r101028  
    3232#endif
    3333
    34 /* Qt includes: */
    35 #include <QVariant>
    36 #include <QWidget>
    37 
    3834/* GUI includes: */
    39 #include "QIWithRetranslateUI.h"
     35#include "UIEditor.h"
    4036#include "UIExtraDataDefs.h"
    4137#include "UISettingsDefs.h"
     
    4945
    5046/* Forward declarations: */
    51 class QShowEvent;
    52 class QString;
     47class QLabel;
     48class QLayout;
    5349class QVariant;
    5450class QWidget;
     
    9692
    9793/** QWidget subclass used as settings page interface. */
    98 class SHARED_LIBRARY_STUFF UISettingsPage : public QIWithRetranslateUI<QWidget>
     94class UISettingsPage : public QIWithRetranslateUI<QWidget>
    9995{
    10096    Q_OBJECT;
     
    221217
    222218/** UISettingsPage extension used as Global Preferences page interface. */
    223 class SHARED_LIBRARY_STUFF UISettingsPageGlobal : public UISettingsPage
     219class UISettingsPageGlobal : public UISettingsPage
    224220{
    225221    Q_OBJECT;
     
    255251
    256252/** UISettingsPage extension used as Machine Settings page interface. */
    257 class SHARED_LIBRARY_STUFF UISettingsPageMachine : public UISettingsPage
     253class UISettingsPageMachine : public UISettingsPage
    258254{
    259255    Q_OBJECT;
     
    285281
    286282
     283/** QWidget sub-class, used as settings page frame. */
     284class UISettingsPageFrame : public QWidget
     285{
     286    Q_OBJECT;
     287
     288public:
     289
     290    /** Constructs details element passing @a pParent to the base-class.
     291      * @param  pPage  Brings the page to wrap with frame. */
     292    UISettingsPageFrame(UISettingsPage *pPage, QWidget *pParent = 0);
     293
     294    /** Defines @a strName. */
     295    void setName(const QString &strName);
     296
     297protected:
     298
     299    /** Handles paint @a pEvent. */
     300    virtual void paintEvent(QPaintEvent *pEvent) RT_OVERRIDE;
     301
     302private:
     303
     304    /** Prepares all. */
     305    void prepare();
     306
     307    /** Holds the page reference. */
     308    UISettingsPage *m_pPage;
     309
     310    /** Holds the element name.*/
     311    QString  m_strName;
     312
     313    /** Holds the name label instance. */
     314    QLabel  *m_pLabelName;
     315    /** Holds the contents widget instance. */
     316    QWidget *m_pWidget;
     317    /** Holds the contents layout instance. */
     318    QLayout *m_pLayout;
     319};
     320
     321
    287322#endif /* !FEQT_INCLUDED_SRC_settings_UISettingsPage_h */
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