VirtualBox

Changeset 90484 in vbox for trunk


Ignore:
Timestamp:
Aug 2, 2021 5:18:43 PM (4 years ago)
Author:
vboxsync
Message:

FE/Qt: bugref:10067: UINotificationCenter: Further work on notification scroll-area; Adjust width to contents hint; Handle content hint changes.

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

Legend:

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

    r90358 r90484  
    10231023        src/medium/viso/UIVisoHostBrowser.cpp \
    10241024        src/medium/viso/UIVisoBrowserBase.cpp \
     1025        src/notificationcenter/UINotificationCenter.cpp \
    10251026        src/settings/editors/UIBaseMemoryEditor.cpp \
    10261027        src/settings/editors/UIBootOrderEditor.cpp \
  • trunk/src/VBox/Frontends/VirtualBox/src/notificationcenter/UINotificationCenter.cpp

    r90464 r90484  
    4040
    4141
     42/** QScrollArea extension to make notification scroll-area more versatile. */
     43class UINotificationScrollArea : public QScrollArea
     44{
     45    Q_OBJECT;
     46
     47public:
     48
     49    /** Creates notification scroll-area passing @a pParent to the base-class. */
     50    UINotificationScrollArea(QWidget *pParent = 0);
     51
     52    /** Returns minimum size-hint. */
     53    virtual QSize minimumSizeHint() const /* override final */;
     54
     55    /** Assigns scrollable @a pWidget.
     56      * @note  Keep in mind that's an override, but NOT a virtual method. */
     57    void setWidget(QWidget *pWidget);
     58
     59protected:
     60
     61    /** Preprocesses @a pEvent for registered @a pWatched object. */
     62    virtual bool eventFilter(QObject *pWatched, QEvent *pEvent) /* override final */;
     63};
     64
     65
     66/*********************************************************************************************************************************
     67*   Class UINotificationScrollArea implementation.                                                                               *
     68*********************************************************************************************************************************/
     69
     70UINotificationScrollArea::UINotificationScrollArea(QWidget *pParent /* = 0 */)
     71    : QScrollArea(pParent)
     72{
     73    setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
     74}
     75
     76QSize UINotificationScrollArea::minimumSizeHint() const
     77{
     78    /* So, here is the logic,
     79     * we are taking width from widget if it's present,
     80     * while keeping height calculated by the base-class. */
     81    const QSize msh = QScrollArea::minimumSizeHint();
     82    return widget() ? QSize(widget()->minimumSizeHint().width(), msh.height()) : msh;
     83}
     84
     85void UINotificationScrollArea::setWidget(QWidget *pWidget)
     86{
     87    /* We'd like to listen for a new widget's events: */
     88    if (widget())
     89        widget()->removeEventFilter(this);
     90    pWidget->installEventFilter(this);
     91
     92    /* Call to base-class: */
     93    QScrollArea::setWidget(pWidget);
     94}
     95
     96bool UINotificationScrollArea::eventFilter(QObject *pWatched, QEvent *pEvent)
     97{
     98    /* For listened widget: */
     99    if (pWatched == widget())
     100    {
     101        switch (pEvent->type())
     102        {
     103            /* We'd like to handle layout-request events: */
     104            case QEvent::LayoutRequest:
     105                updateGeometry();
     106                break;
     107            default:
     108                break;
     109        }
     110    }
     111
     112    /* Call to base-class: */
     113    return QScrollArea::eventFilter(pWatched, pEvent);
     114}
     115
     116
     117/*********************************************************************************************************************************
     118*   Class UINotificationCenter implementation.                                                                                   *
     119*********************************************************************************************************************************/
     120
    42121/* static */
    43122UINotificationCenter *UINotificationCenter::s_pInstance = 0;
     
    127206    switch (pEvent->type())
    128207    {
     208        /* When we are being asked to update layout
     209         * we want to adjust overlay accordingly. */
     210        case QEvent::LayoutRequest:
     211        {
     212            adjustGeometry();
     213            break;
     214        }
    129215        /* When we are being resized or moved we want
    130216         * to adjust transparency mask accordingly. */
     
    233319
    234320        /* Create items scroll-area: */
    235         QScrollArea *pScrollAreaItems = new QScrollArea(this);
     321        UINotificationScrollArea *pScrollAreaItems = new UINotificationScrollArea(this);
    236322        if (pScrollAreaItems)
    237323        {
     
    446532    setMask(region);
    447533}
     534
     535
     536#include "UINotificationCenter.moc"
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