VirtualBox

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


Ignore:
Timestamp:
Apr 18, 2018 5:02:14 PM (7 years ago)
Author:
vboxsync
Message:

FE/Qt: bugref:9049: Full and heavy cleanup for UIFilmContainer and move it to VBoxGlobal library.

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

Legend:

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

    r71901 r71905  
    570570        src/widgets/UINameAndSystemEditor.h \
    571571        src/widgets/UIWarningPane.h \
    572         src/widgets/UIFilmContainer.h \
    573572        src/widgets/graphics/UIGraphicsButton.h \
    574573        src/widgets/graphics/UIGraphicsRotatorButton.h \
     
    685684        src/widgets/UIBootTable.h \
    686685        src/widgets/UIFilePathSelector.h \
     686        src/widgets/UIFilmContainer.h \
    687687        src/widgets/UIHostComboEditor.h \
    688688        src/widgets/UIPopupBox.h \
     
    775775        src/widgets/UIBootTable.h \
    776776        src/widgets/UIFilePathSelector.h \
     777        src/widgets/UIFilmContainer.h \
    777778        src/widgets/UIHostComboEditor.h \
    778779        src/widgets/UIPopupBox.h \
     
    856857        src/selector/UIActionPoolSelector.cpp \
    857858        src/selector/UIVirtualBoxEventHandler.cpp \
     859        src/widgets/UIFilmContainer.cpp \
    858860        src/widgets/UIProgressDialog.cpp
    859861
     
    894896        src/selector/UIActionPoolSelector.cpp \
    895897        src/selector/UIVirtualBoxEventHandler.cpp \
     898        src/widgets/UIFilmContainer.cpp \
    896899        src/widgets/UIProgressDialog.cpp
    897900
     
    10561059        src/widgets/UINameAndSystemEditor.cpp \
    10571060        src/widgets/UIWarningPane.cpp \
    1058         src/widgets/UIFilmContainer.cpp \
    10591061        src/widgets/graphics/UIGraphicsButton.cpp \
    10601062        src/widgets/graphics/UIGraphicsRotatorButton.cpp \
     
    12101212        src/widgets/UIBootTable.cpp \
    12111213        src/widgets/UIFilePathSelector.cpp \
     1214        src/widgets/UIFilmContainer.cpp \
    12121215        src/widgets/UIHostComboEditor.cpp \
    12131216        src/widgets/UIPopupBox.cpp \
     
    13261329        src/widgets/UIBootTable.cpp \
    13271330        src/widgets/UIFilePathSelector.cpp \
     1331        src/widgets/UIFilmContainer.cpp \
    13281332        src/widgets/UIHostComboEditor.cpp \
    13291333        src/widgets/UIPopupBox.cpp \
  • trunk/src/VBox/Frontends/VirtualBox/src/widgets/UIFilmContainer.cpp

    r71027 r71905  
    55
    66/*
    7  * Copyright (C) 2013-2017 Oracle Corporation
     7 * Copyright (C) 2013-2018 Oracle Corporation
    88 *
    99 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    2121
    2222/* Qt includes: */
     23# include <QCheckBox>
    2324# include <QHBoxLayout>
    24 # include <QVBoxLayout>
     25# include <QPainter>
    2526# include <QScrollArea>
    2627# include <QScrollBar>
    2728# include <QStyle>
    28 # include <QCheckBox>
    29 # include <QPainter>
     29# include <QVBoxLayout>
    3030
    3131/* GUI includes: */
     
    3535
    3636
    37 UIFilmContainer::UIFilmContainer(QWidget *pParent /* = 0*/)
    38     : QWidget(pParent)
    39     , m_pMainLayout(0)
    40     , m_pScroller(0)
    41 {
    42     /* Prepare: */
    43     prepare();
    44 }
    45 
    46 QVector<BOOL> UIFilmContainer::value() const
    47 {
    48     /* Enumerate all the existing widgets: */
    49     QVector<BOOL> value;
    50     foreach (UIFilm *pWidget, m_widgets)
    51         value << static_cast<BOOL>(pWidget->checked());
    52 
    53     /* Return value: */
    54     return value;
    55 }
    56 
    57 void UIFilmContainer::setValue(const QVector<BOOL> &value)
    58 {
    59     /* Cleanup viewport/widget list: */
    60     delete m_pScroller->takeWidget();
    61     m_widgets.clear();
    62 
    63     /* Create widget: */
    64     if (QWidget *pWidget = new QWidget)
    65     {
    66         /* Create viewport layout: */
    67         if (QHBoxLayout *pWidgetLayout = new QHBoxLayout(pWidget))
    68         {
    69             /* Configure viewport layout: */
    70             pWidgetLayout->setMargin(0);
    71 #ifdef VBOX_WS_MAC
    72             pWidgetLayout->setSpacing(5);
    73 #else
    74             pWidgetLayout->setSpacing(qApp->style()->pixelMetric(QStyle::PM_LayoutHorizontalSpacing) / 2);
    75 #endif
    76             /* Create new widgets according passed vector: */
    77             for (int iScreenIndex = 0; iScreenIndex < value.size(); ++iScreenIndex)
    78             {
    79                 /* Create new widget: */
    80                 UIFilm *pWidget = new UIFilm(iScreenIndex, value[iScreenIndex]);
    81                 /* Add widget into the widget list: */
    82                 m_widgets << pWidget;
    83                 /* Add widget into the viewport layout: */
    84                 pWidgetLayout->addWidget(pWidget);
    85             }
    86         }
    87         /* Assign scroller with widget: */
    88         m_pScroller->setWidget(pWidget);
    89         /* Reconfigure scroller widget: */
    90         m_pScroller->widget()->setAutoFillBackground(false);
    91         /* And adjust that widget geometry: */
    92         QSize msh = m_pScroller->widget()->minimumSizeHint();
    93         int iMinimumHeight = msh.height();
    94         m_pScroller->viewport()->setFixedHeight(iMinimumHeight);
    95     }
    96 }
    97 
    98 void UIFilmContainer::prepare()
    99 {
    100     /* Prepare layout: */
    101     prepareLayout();
    102 
    103     /* Prepare scroller: */
    104     prepareScroller();
    105 
    106     /* Append with 'default' value: */
    107     setValue(QVector<BOOL>() << true);
    108 }
    109 
    110 void UIFilmContainer::prepareLayout()
    111 {
    112     /* Create layout: */
    113     m_pMainLayout = new QVBoxLayout(this);
    114 
    115     /* Configure layout: */
    116     m_pMainLayout->setMargin(0);
    117     m_pMainLayout->setSpacing(0);
    118 }
    119 
    120 void UIFilmContainer::prepareScroller()
    121 {
    122     /* Create scroller: */
    123     m_pScroller = new QScrollArea;
    124 
    125     /* Configure scroller: */
    126     m_pScroller->setFrameShape(QFrame::NoFrame);
    127     m_pScroller->viewport()->setAutoFillBackground(false);
    128     m_pScroller->setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded);
    129     m_pScroller->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Fixed);
    130     m_pMainLayout->addWidget(m_pScroller);
    131 }
     37/** QWidget subclass providing GUI with UIFilmContainer item prototype.
     38  * @todo Rename to something more suitable like UIScreenThumbnail. */
     39class UIFilm : public QIWithRetranslateUI<QWidget>
     40{
     41    Q_OBJECT;
     42
     43public:
     44
     45    /** Constructs film widget passing @a pParent to the base-class.
     46      * @param  iScreenIndex  Brings the guest-screen index this film referencing.
     47      * @param  fEnabled      Brings whether the guest-screen mentioned above is enabled. */
     48    UIFilm(int iScreenIndex, BOOL fEnabled, QWidget *pParent = 0);
     49
     50    /** Returns whether guest-screen is enabled. */
     51    bool checked() const;
     52
     53protected:
     54
     55    /** Handles translation event. */
     56    virtual void retranslateUi() /* override */;
     57
     58    /** Handles paint @a pEvent. */
     59    virtual void paintEvent(QPaintEvent *pEvent) /* override */;
     60
     61    /** Returns minimum size-hint. */
     62    virtual QSize minimumSizeHint() const /* override */;
     63
     64private:
     65
     66    /** Prepares all. */
     67    void prepare();
     68    /** Prepares layout. */
     69    void prepareLayout();
     70    /** Prepares check-box. */
     71    void prepareCheckBox();
     72
     73    /** Holds the guest-screen index. */
     74    int  m_iScreenIndex;
     75    /** Holds whether guest-screen was enabled. */
     76    BOOL m_fWasEnabled;
     77
     78    /** Holds the main-layout instance. */
     79    QVBoxLayout *m_pMainLayout;
     80    /** Holds the check-box instance. */
     81    QCheckBox   *m_pCheckBox;
     82};
     83
     84
     85/*********************************************************************************************************************************
     86*   Class UIFilm implementation.                                                                                                 *
     87*********************************************************************************************************************************/
    13288
    13389UIFilm::UIFilm(int iScreenIndex, BOOL fEnabled, QWidget *pParent /* = 0*/)
     
    154110}
    155111
    156 void UIFilm::prepare()
    157 {
    158     /* Prepare layout: */
    159     prepareLayout();
    160 
    161     /* Prepare check-box: */
    162     prepareCheckBox();
    163 
    164     /* Translate finally: */
    165     retranslateUi();
    166 }
    167 
    168 void UIFilm::prepareLayout()
    169 {
    170     /* Create layout: */
    171     m_pMainLayout = new QVBoxLayout(this);
    172 
    173     /* Configure layout: */
    174 #ifdef VBOX_WS_MAC
    175     m_pMainLayout->setContentsMargins(10, 10, 15, 10);
    176 #endif /* VBOX_WS_MAC */
    177 
    178     /* Add strech: */
    179     m_pMainLayout->addStretch();
    180 }
    181 
    182 void UIFilm::prepareCheckBox()
    183 {
    184     /* Create check-box: */
    185     m_pCheckBox = new QCheckBox;
    186     m_pCheckBox->setChecked(static_cast<bool>(m_fWasEnabled));
    187 
    188     /* Configure font: */
    189     QFont currentFont = m_pCheckBox->font();
    190 #ifdef VBOX_WS_MAC
    191     currentFont.setPointSize(currentFont.pointSize() - 2);
    192 #else /* VBOX_WS_MAC */
    193     currentFont.setPointSize(currentFont.pointSize() - 1);
    194 #endif /* !VBOX_WS_MAC */
    195     m_pCheckBox->setFont(currentFont);
    196 
    197     /* Insert check-box into layout: */
    198     m_pMainLayout->insertWidget(0, m_pCheckBox);
    199 }
    200 
    201 QSize UIFilm::minimumSizeHint() const
    202 {
    203     /* Return 16:9 aspect-ratio msh: */
    204     QSize msh = QWidget::minimumSizeHint();
    205     return QSize(msh.width(), (msh.width() * 9) / 16);
    206 }
    207 
    208 void UIFilm::paintEvent(QPaintEvent*)
     112void UIFilm::paintEvent(QPaintEvent *)
    209113{
    210114    /* Compose painting rectangle: */
     
    247151}
    248152
     153QSize UIFilm::minimumSizeHint() const
     154{
     155    /* Return 16:9 aspect-ratio msh: */
     156    QSize msh = QWidget::minimumSizeHint();
     157    return QSize(msh.width(), (msh.width() * 9) / 16);
     158}
     159
     160void UIFilm::prepare()
     161{
     162    /* Prepare layout: */
     163    prepareLayout();
     164    /* Prepare check-box: */
     165    prepareCheckBox();
     166
     167    /* Apply language settings: */
     168    retranslateUi();
     169}
     170
     171void UIFilm::prepareLayout()
     172{
     173    /* Create layout: */
     174    m_pMainLayout = new QVBoxLayout(this);
     175    if (m_pMainLayout)
     176    {
     177        /* Configure layout: */
     178#ifdef VBOX_WS_MAC
     179        m_pMainLayout->setContentsMargins(10, 10, 15, 10);
     180#endif
     181
     182        /* Add strech: */
     183        m_pMainLayout->addStretch();
     184    }
     185}
     186
     187void UIFilm::prepareCheckBox()
     188{
     189    /* Create check-box: */
     190    m_pCheckBox = new QCheckBox;
     191    if (m_pCheckBox)
     192    {
     193        /* Configure check-box: */
     194        m_pCheckBox->setChecked(static_cast<bool>(m_fWasEnabled));
     195        /* Configure font: */
     196        QFont currentFont = m_pCheckBox->font();
     197#ifdef VBOX_WS_MAC
     198        currentFont.setPointSize(currentFont.pointSize() - 2);
     199#else
     200        currentFont.setPointSize(currentFont.pointSize() - 1);
     201#endif
     202        m_pCheckBox->setFont(currentFont);
     203
     204        /* Insert into layout: */
     205        m_pMainLayout->insertWidget(0, m_pCheckBox);
     206    }
     207}
     208
     209
     210/*********************************************************************************************************************************
     211*   Class UIFilmContainer implementation.                                                                                        *
     212*********************************************************************************************************************************/
     213
     214UIFilmContainer::UIFilmContainer(QWidget *pParent /* = 0*/)
     215    : QWidget(pParent)
     216    , m_pMainLayout(0)
     217    , m_pScroller(0)
     218{
     219    /* Prepare: */
     220    prepare();
     221}
     222
     223QVector<BOOL> UIFilmContainer::value() const
     224{
     225    /* Enumerate all the existing widgets: */
     226    QVector<BOOL> value;
     227    foreach (UIFilm *pWidget, m_widgets)
     228        value << static_cast<BOOL>(pWidget->checked());
     229
     230    /* Return value: */
     231    return value;
     232}
     233
     234void UIFilmContainer::setValue(const QVector<BOOL> &value)
     235{
     236    /* Cleanup viewport/widget list: */
     237    delete m_pScroller->takeWidget();
     238    m_widgets.clear();
     239
     240    /* Create widget: */
     241    QWidget *pWidget = new QWidget;
     242    if (pWidget)
     243    {
     244        /* Create widget-layout: */
     245        QHBoxLayout *pWidgetLayout = new QHBoxLayout(pWidget);
     246        if (pWidgetLayout)
     247        {
     248            /* Configure widget-layout: */
     249            pWidgetLayout->setMargin(0);
     250#ifdef VBOX_WS_MAC
     251            pWidgetLayout->setSpacing(5);
     252#else
     253            pWidgetLayout->setSpacing(qApp->style()->pixelMetric(QStyle::PM_LayoutHorizontalSpacing) / 2);
     254#endif
     255
     256            /* Create new films according passed vector: */
     257            for (int iScreenIndex = 0; iScreenIndex < value.size(); ++iScreenIndex)
     258            {
     259                /* Create new film: */
     260                UIFilm *pFilm = new UIFilm(iScreenIndex, value[iScreenIndex]);
     261                if (pFilm)
     262                {
     263                    /* Add film into the widget list: */
     264                    m_widgets << pFilm;
     265
     266                    /* Add into layout: */
     267                    pWidgetLayout->addWidget(pFilm);
     268                }
     269            }
     270        }
     271
     272        /* Assign scroller with widget: */
     273        m_pScroller->setWidget(pWidget);
     274        /* Reconfigure scroller widget: */
     275        m_pScroller->widget()->setAutoFillBackground(false);
     276        /* And adjust that widget geometry: */
     277        QSize msh = m_pScroller->widget()->minimumSizeHint();
     278        int iMinimumHeight = msh.height();
     279        m_pScroller->viewport()->setFixedHeight(iMinimumHeight);
     280    }
     281}
     282
     283void UIFilmContainer::prepare()
     284{
     285    /* Prepare layout: */
     286    prepareLayout();
     287    /* Prepare scroller: */
     288    prepareScroller();
     289
     290    /* Append with 'default' value: */
     291    setValue(QVector<BOOL>() << true);
     292}
     293
     294void UIFilmContainer::prepareLayout()
     295{
     296    /* Create layout: */
     297    m_pMainLayout = new QVBoxLayout(this);
     298    if (m_pMainLayout)
     299    {
     300        /* Configure layout: */
     301        m_pMainLayout->setMargin(0);
     302        m_pMainLayout->setSpacing(0);
     303    }
     304}
     305
     306void UIFilmContainer::prepareScroller()
     307{
     308    /* Create scroller: */
     309    m_pScroller = new QScrollArea;
     310    if (m_pScroller)
     311    {
     312        /* Configure scroller: */
     313        m_pScroller->setFrameShape(QFrame::NoFrame);
     314        m_pScroller->viewport()->setAutoFillBackground(false);
     315        m_pScroller->setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded);
     316        m_pScroller->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Fixed);
     317
     318        /* Add into layout: */
     319        m_pMainLayout->addWidget(m_pScroller);
     320    }
     321}
     322
     323
     324#include "UIFilmContainer.moc"
  • trunk/src/VBox/Frontends/VirtualBox/src/widgets/UIFilmContainer.h

    r71027 r71905  
    55
    66/*
    7  * Copyright (C) 2013-2017 Oracle Corporation
     7 * Copyright (C) 2013-2018 Oracle Corporation
    88 *
    99 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    1616 */
    1717
    18 #ifndef __UIFilmContainer_h__
    19 #define __UIFilmContainer_h__
     18#ifndef ___UIFilmContainer_h___
     19#define ___UIFilmContainer_h___
    2020
    2121/* Qt includes: */
     
    2424/* GUI includes: */
    2525#include "QIWithRetranslateUI.h"
     26#include "UILibraryDefs.h"
    2627
    2728/* Other VBox includes: */
     
    2930
    3031/* Forward declarations: */
     32class QCheckBox;
     33class QScrollArea;
    3134class QVBoxLayout;
    32 class QScrollArea;
    3335class UIFilm;
    34 class QCheckBox;
    3536
    36 /* Transparent QScrollArea container for UIFilm widgets: */
    37 class UIFilmContainer : public QWidget
     37/** QWidget subclass providing GUI with QScrollArea-based container for UIFilm widgets.
     38  * @todo Rename to something more suitable like UIScreenThumbnailContainer. */
     39class SHARED_LIBRARY_STUFF UIFilmContainer : public QWidget
    3840{
    3941    Q_OBJECT;
     
    4143public:
    4244
    43     /* Constructor: */
     45    /** Constructs film-container passing @a pParent to the base-class. */
    4446    UIFilmContainer(QWidget *pParent = 0);
    4547
    46     /* API: Value stuff: */
     48    /** Returns the film-container check-box values. */
    4749    QVector<BOOL> value() const;
    48     void setValue(const QVector<BOOL> &value);
     50    /** Defines the film-container check-box @a values. */
     51    void setValue(const QVector<BOOL> &values);
    4952
    5053private:
    5154
    52     /* Helpers: Prepare stuff: */
     55    /** Prepares all. */
    5356    void prepare();
     57    /** Prepares layout. */
    5458    void prepareLayout();
     59    /** Prepares scroller. */
    5560    void prepareScroller();
    5661
    57     /* Variables: */
    58     QVBoxLayout *m_pMainLayout;
    59     QScrollArea *m_pScroller;
    60     QList<UIFilm*> m_widgets;
     62    /** Holds the main layout intance. */
     63    QVBoxLayout    *m_pMainLayout;
     64    /** Holds the scroller intance. */
     65    QScrollArea    *m_pScroller;
     66    /** Holds the list of film widgets. */
     67    QList<UIFilm*>  m_widgets;
    6168};
    6269
    63 /* QWidget item prototype for UIFilmContainer: */
    64 class UIFilm : public QIWithRetranslateUI<QWidget>
    65 {
    66     Q_OBJECT;
    67 
    68 public:
    69 
    70     /* Constructor: */
    71     UIFilm(int iScreenIndex, BOOL fEnabled, QWidget *pParent = 0);
    72 
    73     /* API: Check-box stuff: */
    74     bool checked() const;
    75 
    76 private:
    77 
    78     /* Handler: Translate stuff: */
    79     void retranslateUi();
    80 
    81     /* Helpers: Prepare stuff: */
    82     void prepare();
    83     void prepareLayout();
    84     void prepareCheckBox();
    85 
    86     /* Helper: Layout stuff: */
    87     QSize minimumSizeHint() const;
    88 
    89     /* Handler: Paint stuff: */
    90     void paintEvent(QPaintEvent *pEvent);
    91 
    92     /* Variables: */
    93     int m_iScreenIndex;
    94     BOOL m_fWasEnabled;
    95     QVBoxLayout *m_pMainLayout;
    96     QCheckBox *m_pCheckBox;
    97 };
    98 
    99 #endif /* __UIFilmContainer_h__ */
     70#endif /* !___UIFilmContainer_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