VirtualBox

Changeset 71521 in vbox


Ignore:
Timestamp:
Mar 26, 2018 5:09:08 PM (7 years ago)
Author:
vboxsync
Message:

FE/Qt: bugref:9049: Full and heavy cleanup for UIPopupStack classes.

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

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/widgets/UIPopupStack.cpp

    r70474 r71521  
    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
     
    1919# include <precomp.h>
    2020#else  /* !VBOX_WITH_PRECOMPILED_HEADERS */
     21
    2122/* Qt includes: */
    22 # include <QVBoxLayout>
    23 # include <QScrollArea>
    2423# include <QEvent>
    2524# include <QMainWindow>
    2625# include <QMenuBar>
     26# include <QScrollArea>
    2727# include <QStatusBar>
     28# include <QVBoxLayout>
    2829
    2930/* GUI includes: */
     
    3536
    3637
    37 UIPopupStack::UIPopupStack(const QString &strID, UIPopupStackOrientation orientation)
     38UIPopupStack::UIPopupStack(const QString &strID, UIPopupStackOrientation enmOrientation)
    3839    : m_strID(strID)
    39     , m_orientation(orientation)
     40    , m_enmOrientation(enmOrientation)
    4041    , m_pScrollArea(0)
    4142    , m_pScrollViewport(0)
     
    4748}
    4849
    49 bool UIPopupStack::exists(const QString &strPopupPaneID) const
     50bool UIPopupStack::exists(const QString &strID) const
    5051{
    5152    /* Redirect question to viewport: */
    52     return m_pScrollViewport->exists(strPopupPaneID);
    53 }
    54 
    55 void UIPopupStack::createPopupPane(const QString &strPopupPaneID,
     53    return m_pScrollViewport->exists(strID);
     54}
     55
     56void UIPopupStack::createPopupPane(const QString &strID,
    5657                                   const QString &strMessage, const QString &strDetails,
    5758                                   const QMap<int, QString> &buttonDescriptions)
    5859{
    5960    /* Redirect request to viewport: */
    60     m_pScrollViewport->createPopupPane(strPopupPaneID,
     61    m_pScrollViewport->createPopupPane(strID,
    6162                                       strMessage, strDetails,
    6263                                       buttonDescriptions);
     
    6667}
    6768
    68 void UIPopupStack::updatePopupPane(const QString &strPopupPaneID,
     69void UIPopupStack::updatePopupPane(const QString &strID,
    6970                                   const QString &strMessage, const QString &strDetails)
    7071{
    7172    /* Redirect request to viewport: */
    72     m_pScrollViewport->updatePopupPane(strPopupPaneID,
     73    m_pScrollViewport->updatePopupPane(strID,
    7374                                       strMessage, strDetails);
    7475}
    7576
    76 void UIPopupStack::recallPopupPane(const QString &strPopupPaneID)
     77void UIPopupStack::recallPopupPane(const QString &strID)
    7778{
    7879    /* Redirect request to viewport: */
    79     m_pScrollViewport->recallPopupPane(strPopupPaneID);
    80 }
    81 
    82 void UIPopupStack::setOrientation(UIPopupStackOrientation orientation)
     80    m_pScrollViewport->recallPopupPane(strID);
     81}
     82
     83void UIPopupStack::setOrientation(UIPopupStackOrientation enmOrientation)
    8384{
    8485    /* Make sure orientation has changed: */
    85     if (m_orientation == orientation)
     86    if (m_enmOrientation == enmOrientation)
    8687        return;
    8788
    8889    /* Update orientation: */
    89     m_orientation = orientation;
     90    m_enmOrientation = enmOrientation;
    9091    sltAdjustGeometry();
    9192}
     
    109110    /* Recalculate parent status-bar height: */
    110111    m_iParentStatusBarHeight = parentStatusBarHeight(pParent);
     112}
     113
     114bool UIPopupStack::eventFilter(QObject *pWatched, QEvent *pEvent)
     115{
     116    /* Call to base-class if that is not parent event: */
     117    if (!parent() || pWatched != parent())
     118        return QWidget::eventFilter(pWatched, pEvent);
     119
     120    /* Handle parent geometry events: */
     121    switch (pEvent->type())
     122    {
     123        case QEvent::Resize:
     124        {
     125            /* Propagate size: */
     126            propagateSize();
     127            /* Adjust geometry: */
     128            sltAdjustGeometry();
     129            break;
     130        }
     131        case QEvent::Move:
     132        {
     133            /* Adjust geometry: */
     134            sltAdjustGeometry();
     135            break;
     136        }
     137        default:
     138            break; /* Shuts up MSC. */
     139    }
     140
     141    /* Call to base-class: */
     142    return QWidget::eventFilter(pWatched, pEvent);
     143}
     144
     145void UIPopupStack::showEvent(QShowEvent*)
     146{
     147    /* Propagate size: */
     148    propagateSize();
     149    /* Adjust geometry: */
     150    sltAdjustGeometry();
    111151}
    112152
     
    149189        iY += geo.y();
    150190    }
    151     switch (m_orientation)
     191    switch (m_enmOrientation)
    152192    {
    153193        case UIPopupStackOrientation_Top:
     
    189229    setAutoFillBackground(false);
    190230#if defined(VBOX_WS_WIN) || defined (VBOX_WS_MAC)
    191     /* Using Qt API to enable translucent background for the Win/Mac host.
    192      * - Under x11 host Qt 4.8.3 has it broken wih KDE 4.9 for now: */
     231    /* Using Qt API to enable translucent background for the Win/Mac host: */
    193232    setAttribute(Qt::WA_TranslucentBackground);
    194 #endif /* VBOX_WS_WIN || VBOX_WS_MAC */
     233#endif
    195234
    196235#ifdef VBOX_WS_MAC
    197     /* Do not hide popup-stack
    198      * and actually the seamless machine-window too
    199      * due to Qt bug on window deactivation... */
     236    /* Do not hide popup-stack: */
    200237    setAttribute(Qt::WA_MacAlwaysShowToolWindow);
    201 #endif /* VBOX_WS_MAC */
     238#endif
    202239
    203240    /* Prepare content: */
     
    249286}
    250287
    251 bool UIPopupStack::eventFilter(QObject *pWatched, QEvent *pEvent)
    252 {
    253     /* Call to base-class if that is not parent event: */
    254     if (!parent() || pWatched != parent())
    255         return QWidget::eventFilter(pWatched, pEvent);
    256 
    257     /* Handle parent geometry events: */
    258     switch (pEvent->type())
    259     {
    260         case QEvent::Resize:
    261         {
    262             /* Propagate size: */
    263             propagateSize();
    264             /* Adjust geometry: */
    265             sltAdjustGeometry();
    266             break;
    267         }
    268         case QEvent::Move:
    269         {
    270             /* Adjust geometry: */
    271             sltAdjustGeometry();
    272             break;
    273         }
    274         default: break; /* Shuts up MSC.  */
    275     }
    276 
    277     /* Call to base-class: */
    278     return QWidget::eventFilter(pWatched, pEvent);
    279 }
    280 
    281 void UIPopupStack::showEvent(QShowEvent*)
    282 {
    283     /* Propagate size: */
    284     propagateSize();
    285     /* Adjust geometry: */
    286     sltAdjustGeometry();
    287 }
    288 
    289288void UIPopupStack::propagateSize()
    290289{
  • trunk/src/VBox/Frontends/VirtualBox/src/widgets/UIPopupStack.h

    r69500 r71521  
    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 __UIPopupStack_h__
    19 #define __UIPopupStack_h__
     18#ifndef ___UIPopupStack_h___
     19#define ___UIPopupStack_h___
    2020
    2121/* Qt includes: */
     
    2727
    2828/* Forward declaration: */
     29class QEvent;
     30class QObject;
     31class QScrollArea;
     32class QShowEvent;
     33class QSize;
     34class QString;
    2935class QVBoxLayout;
    30 class QScrollArea;
    3136class UIPopupStackViewport;
    3237
    33 /* Popup-stack prototype class: */
     38/** QWidget extension providing GUI with popup-stack prototype class. */
    3439class UIPopupStack : public QWidget
    3540{
     
    3843signals:
    3944
    40     /* Notifier: Layout stuff: */
     45    /** Notifies about popup-stack viewport size change. */
    4146    void sigProposeStackViewportSize(QSize newSize);
    4247
    43     /* Notifier: Popup-pane stuff: */
    44     void sigPopupPaneDone(QString strPopupPaneID, int iResultCode);
     48    /** Asks to close popup-pane with @a strID and @a iResultCode. */
     49    void sigPopupPaneDone(QString strID, int iResultCode);
    4550
    46     /* Notifier: Popup-stack stuff: */
     51    /** Asks to close popup-stack with @a strID. */
    4752    void sigRemove(QString strID);
    4853
    4954public:
    5055
    51     /* Constructor: */
    52     UIPopupStack(const QString &strID, UIPopupStackOrientation orientation);
     56    /** Constructs popup-stack with passed @a strID and @a enmOrientation. */
     57    UIPopupStack(const QString &strID, UIPopupStackOrientation enmOrientation);
    5358
    54     /* API: Popup-pane stuff: */
    55     bool exists(const QString &strPopupPaneID) const;
    56     void createPopupPane(const QString &strPopupPaneID,
     59    /** Returns whether pane with passed @a strID exists. */
     60    bool exists(const QString &strID) const;
     61    /** Creates pane with passed @a strID, @a strMessage, @a strDetails and @a buttonDescriptions. */
     62    void createPopupPane(const QString &strID,
    5763                         const QString &strMessage, const QString &strDetails,
    5864                         const QMap<int, QString> &buttonDescriptions);
    59     void updatePopupPane(const QString &strPopupPaneID,
     65    /** Updates pane with passed @a strID, @a strMessage and @a strDetails. */
     66    void updatePopupPane(const QString &strID,
    6067                         const QString &strMessage, const QString &strDetails);
    61     void recallPopupPane(const QString &strPopupPaneID);
    62     void setOrientation(UIPopupStackOrientation orientation);
     68    /** Recalls pane with passed @a strID. */
     69    void recallPopupPane(const QString &strID);
     70    /** Defines stack @a enmOrientation. */
     71    void setOrientation(UIPopupStackOrientation enmOrientation);
    6372
    64     /* API: Parent stuff: */
     73    /** Defines stack @a pParent*/
    6574    void setParent(QWidget *pParent);
    66     void setParent(QWidget *pParent, Qt::WindowFlags flags);
     75    /** Defines stack @a pParent and @a enmFlags. */
     76    void setParent(QWidget *pParent, Qt::WindowFlags enmFlags);
     77
     78protected:
     79
     80    /** Pre-handles standard Qt @a pEvent for passed @a pObject. */
     81    virtual bool eventFilter(QObject *pObject, QEvent *pEvent) /* override */;
     82
     83    /** Handles show @a pEvent. */
     84    virtual void showEvent(QShowEvent *pEvent) /* override */;
    6785
    6886private slots:
    6987
    70     /* Handler: Layout stuff: */
     88    /** Adjusts geometry. */
    7189    void sltAdjustGeometry();
    7290
    73     /* Handlers: Popup-pane stuff: */
    74     void sltPopupPaneRemoved(QString strPopupPaneID);
     91    /** Handles removal of the popup-pane with @a strID. */
     92    void sltPopupPaneRemoved(QString strID);
     93    /** Handles removal of all the popup-panes. */
    7594    void sltPopupPanesRemoved();
    7695
    7796private:
    7897
    79     /* Helpers: Prepare stuff: */
     98    /** Prepares all. */
    8099    void prepare();
     100    /** Prepares contents. */
    81101    void prepareContent();
    82102
    83     /* Handler: Event-filter stuff: */
    84     bool eventFilter(QObject *pWatched, QEvent *pEvent);
    85 
    86     /* Handler: Event stuff: */
    87     void showEvent(QShowEvent *pEvent);
    88 
    89     /* Helper: Layout stuff: */
     103    /** Propagates size. */
    90104    void propagateSize();
    91105
    92     /* Static helpers: Prepare stuff: */
     106    /** Returns @a pParent menu-bar height. */
    93107    static int parentMenuBarHeight(QWidget *pParent);
     108    /** Returns @a pParent status-bar height. */
    94109    static int parentStatusBarHeight(QWidget *pParent);
    95110
    96     /* Variable: General stuff: */
    97     QString m_strID;
    98     UIPopupStackOrientation m_orientation;
     111    /** Holds the stack ID. */
     112    QString                 m_strID;
     113    /** Holds the stack orientation. */
     114    UIPopupStackOrientation m_enmOrientation;
    99115
    100     /* Variables: Widget stuff: */
    101     QVBoxLayout *m_pMainLayout;
    102     QScrollArea *m_pScrollArea;
     116    /** Holds the main-layout instance. */
     117    QVBoxLayout          *m_pMainLayout;
     118    /** Holds the scroll-area instance. */
     119    QScrollArea          *m_pScrollArea;
     120    /** Holds the scroll-viewport instance. */
    103121    UIPopupStackViewport *m_pScrollViewport;
    104122
    105     /* Variables: Layout stuff: */
     123    /** Holds the parent menu-bar height. */
    106124    int m_iParentMenuBarHeight;
     125    /** Holds the parent status-bar height. */
    107126    int m_iParentStatusBarHeight;
    108127};
    109128
    110 #endif /* __UIPopupStack_h__ */
     129#endif /* !___UIPopupStack_h___ */
     130
  • trunk/src/VBox/Frontends/VirtualBox/src/widgets/UIPopupStackViewport.cpp

    r69500 r71521  
    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
     
    1919# include <precomp.h>
    2020#else  /* !VBOX_WITH_PRECOMPILED_HEADERS */
     21
    2122/* GUI includes: */
     23# include "UIPopupPane.h"
    2224# include "UIPopupStackViewport.h"
    23 # include "UIPopupPane.h"
    2425
    2526/* Other VBox includes: */
     
    3536}
    3637
    37 bool UIPopupStackViewport::exists(const QString &strPopupPaneID) const
     38bool UIPopupStackViewport::exists(const QString &strID) const
    3839{
    3940    /* Is there already popup-pane with the same ID? */
    40     return m_panes.contains(strPopupPaneID);
    41 }
    42 
    43 void UIPopupStackViewport::createPopupPane(const QString &strPopupPaneID,
     41    return m_panes.contains(strID);
     42}
     43
     44void UIPopupStackViewport::createPopupPane(const QString &strID,
    4445                                           const QString &strMessage, const QString &strDetails,
    4546                                           const QMap<int, QString> &buttonDescriptions)
    4647{
    4748    /* Make sure there is no such popup-pane already: */
    48     if (m_panes.contains(strPopupPaneID))
     49    if (m_panes.contains(strID))
    4950    {
    5051        AssertMsgFailed(("Popup-pane already exists!"));
     
    5354
    5455    /* Create new popup-pane: */
    55     UIPopupPane *pPopupPane = m_panes[strPopupPaneID] = new UIPopupPane(this,
     56    UIPopupPane *pPopupPane = m_panes[strID] = new UIPopupPane(this,
    5657                                                                        strMessage, strDetails,
    5758                                                                        buttonDescriptions);
     
    6667}
    6768
    68 void UIPopupStackViewport::updatePopupPane(const QString &strPopupPaneID,
     69void UIPopupStackViewport::updatePopupPane(const QString &strID,
    6970                                           const QString &strMessage, const QString &strDetails)
    7071{
    7172    /* Make sure there is such popup-pane already: */
    72     if (!m_panes.contains(strPopupPaneID))
     73    if (!m_panes.contains(strID))
    7374    {
    7475        AssertMsgFailed(("Popup-pane doesn't exists!"));
     
    7778
    7879    /* Get existing popup-pane: */
    79     UIPopupPane *pPopupPane = m_panes[strPopupPaneID];
     80    UIPopupPane *pPopupPane = m_panes[strID];
    8081
    8182    /* Update message and details: */
     
    8485}
    8586
    86 void UIPopupStackViewport::recallPopupPane(const QString &strPopupPaneID)
     87void UIPopupStackViewport::recallPopupPane(const QString &strID)
    8788{
    8889    /* Make sure there is such popup-pane already: */
    89     if (!m_panes.contains(strPopupPaneID))
     90    if (!m_panes.contains(strID))
    9091    {
    9192        AssertMsgFailed(("Popup-pane doesn't exists!"));
     
    9495
    9596    /* Get existing popup-pane: */
    96     UIPopupPane *pPopupPane = m_panes[strPopupPaneID];
     97    UIPopupPane *pPopupPane = m_panes[strID];
    9798
    9899    /* Recall popup-pane: */
     
    133134
    134135    /* Make sure the popup-pane still exists: */
    135     const QString strPopupPaneID(m_panes.key(pPopupPane, QString()));
    136     if (strPopupPaneID.isNull())
     136    const QString strID(m_panes.key(pPopupPane, QString()));
     137    if (strID.isNull())
    137138    {
    138139        AssertMsgFailed(("Popup-pane already destroyed!"));
     
    141142
    142143    /* Notify listeners about popup-pane removal: */
    143     emit sigPopupPaneDone(strPopupPaneID, iResultCode);
     144    emit sigPopupPaneDone(strID, iResultCode);
    144145
    145146    /* Delete popup-pane asyncronously.
    146147     * To avoid issues with events which already posted: */
    147     m_panes.remove(strPopupPaneID);
     148    m_panes.remove(strID);
    148149    pPopupPane->deleteLater();
    149150
    150151    /* Notify listeners about popup-pane removed: */
    151     emit sigPopupPaneRemoved(strPopupPaneID);
     152    emit sigPopupPaneRemoved(strID);
    152153
    153154    /* Adjust geometry: */
  • trunk/src/VBox/Frontends/VirtualBox/src/widgets/UIPopupStackViewport.h

    r69500 r71521  
    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 __UIPopupStackViewport_h__
    19 #define __UIPopupStackViewport_h__
     18#ifndef ___UIPopupStackViewport_h___
     19#define ___UIPopupStackViewport_h___
    2020
    2121/* Qt includes: */
     
    2424
    2525/* Forward declaration: */
     26class QSize;
     27class QString;
    2628class UIPopupPane;
    2729
    28 /* Popup-stack viewport prototype class: */
     30/** QWidget extension providing GUI with popup-stack viewport prototype class. */
    2931class UIPopupStackViewport : public QWidget
    3032{
     
    3335signals:
    3436
    35     /* Notifiers: Layout stuff: */
     37    /** Notifies about popup-pane size change. */
    3638    void sigProposePopupPaneSize(QSize newSize);
     39
     40    /** Notifies about size-hint change. */
    3741    void sigSizeHintChanged();
    3842
    39     /* Notifiers: Popup-pane stuff: */
    40     void sigPopupPaneDone(QString strPopupPaneID, int iResultCode);
    41     void sigPopupPaneRemoved(QString strPopupPaneID);
     43    /** Asks to close popup-pane with @a strID and @a iResultCode. */
     44    void sigPopupPaneDone(QString strID, int iResultCode);
     45    /** Notifies about popup-pane with @a strID was removed. */
     46    void sigPopupPaneRemoved(QString strID);
     47    /** Notifies about popup-panes were removed. */
    4248    void sigPopupPanesRemoved();
    4349
    4450public:
    4551
    46     /* Constructor: */
     52    /** Constructs popup-stack viewport. */
    4753    UIPopupStackViewport();
    4854
    49     /* API: Popup-pane stuff: */
    50     bool exists(const QString &strPopupPaneID) const;
    51     void createPopupPane(const QString &strPopupPaneID,
     55    /** Returns whether pane with passed @a strID exists. */
     56    bool exists(const QString &strID) const;
     57    /** Creates pane with passed @a strID, @a strMessage, @a strDetails and @a buttonDescriptions. */
     58    void createPopupPane(const QString &strID,
    5259                         const QString &strMessage, const QString &strDetails,
    5360                         const QMap<int, QString> &buttonDescriptions);
    54     void updatePopupPane(const QString &strPopupPaneID,
     61    /** Updates pane with passed @a strID, @a strMessage and @a strDetails. */
     62    void updatePopupPane(const QString &strID,
    5563                         const QString &strMessage, const QString &strDetails);
    56     void recallPopupPane(const QString &strPopupPaneID);
     64    /** Recalls pane with passed @a strID. */
     65    void recallPopupPane(const QString &strID);
    5766
    58     /* API: Layout stuff: */
     67    /** Returns minimum size-hint. */
    5968    QSize minimumSizeHint() const { return m_minimumSizeHint; }
    6069
    6170public slots:
    6271
    63     /* Handler: Layout stuff: */
     72    /** Handle proposal for @a newSize. */
    6473    void sltHandleProposalForSize(QSize newSize);
    6574
    6675private slots:
    6776
    68     /* Handler: Layout stuff: */
     77    /** Adjusts geometry. */
    6978    void sltAdjustGeometry();
    7079
    71     /* Handler: Popup-pane stuff: */
     80    /** Handles reuqest to dismiss popup-pane with @a iButtonCode. */
    7281    void sltPopupPaneDone(int iButtonCode);
    7382
    7483private:
    7584
    76     /* Helpers: Layout stuff: */
     85    /** Updates size-hint. */
    7786    void updateSizeHint();
     87    /** Lays the content out. */
    7888    void layoutContent();
    7989
    80     /* Variables: Layout stuff: */
     90    /** Holds the layout margin. */
    8191    const int m_iLayoutMargin;
     92    /** Holds the layout spacing. */
    8293    const int m_iLayoutSpacing;
     94
     95    /** Holds the minimum size-hint. */
    8396    QSize m_minimumSizeHint;
    8497
    85     /* Variables: Children stuff: */
     98    /** Holds the popup-pane instances. */
    8699    QMap<QString, UIPopupPane*> m_panes;
    87100};
    88101
    89 #endif /* __UIPopupStackViewport_h__ */
     102#endif /* !___UIPopupStackViewport_h___ */
     103
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