VirtualBox

Changeset 72027 in vbox for trunk


Ignore:
Timestamp:
Apr 25, 2018 5:47:28 PM (7 years ago)
Author:
vboxsync
Message:

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

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

Legend:

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

    r72026 r72027  
    465465        src/runtime/UIMultiScreenLayout.h \
    466466        src/runtime/UISession.h \
    467         src/runtime/UISlidingToolBar.h \
    468467        src/runtime/UIVMCloseDialog.h \
    469468        src/runtime/fullscreen/UIKeyboardHandlerFullscreen.h \
     
    686685        src/widgets/UIPortForwardingTable.h \
    687686        src/widgets/UIProgressDialog.h \
     687        src/widgets/UISlidingToolBar.h \
    688688        src/widgets/UISpecialControls.h \
    689689        src/widgets/UIStatusBarEditorWindow.h \
     
    795795        src/widgets/UIPortForwardingTable.h \
    796796        src/widgets/UIProgressDialog.h \
     797        src/widgets/UISlidingToolBar.h \
    797798        src/widgets/UISpecialControls.h \
    798799        src/widgets/UIStatusBarEditorWindow.h \
     
    975976        src/runtime/UIMultiScreenLayout.cpp \
    976977        src/runtime/UISession.cpp \
    977         src/runtime/UISlidingToolBar.cpp \
    978978        src/runtime/UIVMCloseDialog.cpp \
    979979        src/runtime/fullscreen/UIKeyboardHandlerFullscreen.cpp \
     
    12351235        src/widgets/UIPortForwardingTable.cpp \
    12361236        src/widgets/UIProgressDialog.cpp \
     1237        src/widgets/UISlidingToolBar.cpp \
    12371238        src/widgets/UISpecialControls.cpp \
    12381239        src/widgets/UIStatusBarEditorWindow.cpp \
     
    13701371        src/widgets/UIPortForwardingTable.cpp \
    13711372        src/widgets/UIProgressDialog.cpp \
     1373        src/widgets/UISlidingToolBar.cpp \
    13721374        src/widgets/UISpecialControls.cpp \
    13731375        src/widgets/UIStatusBarEditorWindow.cpp \
  • trunk/src/VBox/Frontends/VirtualBox/src/widgets/UISlidingToolBar.cpp

    r72026 r72027  
    55
    66/*
    7  * Copyright (C) 2014-2017 Oracle Corporation
     7 * Copyright (C) 2014-2018 Oracle Corporation
    88 *
    99 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    3535
    3636
    37 UISlidingToolBar::UISlidingToolBar(QWidget *pParentWidget, QWidget *pIndentWidget, QWidget *pChildWidget, Position position)
     37UISlidingToolBar::UISlidingToolBar(QWidget *pParentWidget, QWidget *pIndentWidget, QWidget *pChildWidget, Position enmPosition)
    3838    : QWidget(pParentWidget, Qt::Tool | Qt::FramelessWindowHint)
    39     , m_position(position)
     39    , m_enmPosition(enmPosition)
    4040    , m_parentRect(pParentWidget ? pParentWidget->geometry() : QRect())
    4141    , m_indentRect(pIndentWidget ? pIndentWidget->geometry() : QRect())
     
    5050}
    5151
     52#ifdef VBOX_WS_MAC
     53bool UISlidingToolBar::event(QEvent *pEvent)
     54{
     55    /* Depending on event-type: */
     56    switch (pEvent->type())
     57    {
     58        case QEvent::Resize:
     59        case QEvent::WindowActivate:
     60        {
     61            // WORKAROUND:
     62            // By some strange reason
     63            // cocoa resets NSWindow::setHasShadow option
     64            // for frameless windows on every window resize/activation.
     65            // So we have to make sure window still has no shadows.
     66            darwinSetWindowHasShadow(this, false);
     67            break;
     68        }
     69        default:
     70            break;
     71    }
     72    /* Call to base-class: */
     73    return QWidget::event(pEvent);
     74}
     75#endif /* VBOX_WS_MAC */
     76
     77void UISlidingToolBar::showEvent(QShowEvent *)
     78{
     79    /* If window isn't expanded: */
     80    if (!m_fExpanded)
     81    {
     82        /* Start expand animation: */
     83        emit sigShown();
     84    }
     85}
     86
     87void UISlidingToolBar::closeEvent(QCloseEvent *pEvent)
     88{
     89    /* If window isn't expanded: */
     90    if (!m_fExpanded)
     91    {
     92        /* Ignore close-event: */
     93        pEvent->ignore();
     94        return;
     95    }
     96
     97    /* If animation state is Final: */
     98    const QString strAnimationState = property("AnimationState").toString();
     99    bool fAnimationComplete = strAnimationState == "Final";
     100    if (fAnimationComplete)
     101    {
     102        /* Ignore close-event: */
     103        pEvent->ignore();
     104        /* And start collapse animation: */
     105        emit sigCollapse();
     106    }
     107}
     108
    52109void UISlidingToolBar::sltParentGeometryChanged(const QRect &parentRect)
    53110{
     
    62119void UISlidingToolBar::prepare()
    63120{
    64     /* Do not count that window as important for application,
    65      * it will NOT be taken into account when other top-level windows will be closed: */
     121    /* Tell the application we are not that important: */
    66122    setAttribute(Qt::WA_QuitOnClose, false);
    67123    /* Delete window when closed: */
     
    94150    /* Create main-layout: */
    95151    m_pMainLayout = new QHBoxLayout(this);
    96     AssertPtrReturnVoid(m_pMainLayout);
     152    if (m_pMainLayout)
    97153    {
    98154        /* Configure main-layout: */
     
    101157        /* Create area: */
    102158        m_pArea = new QWidget;
    103         AssertPtrReturnVoid(m_pArea);
     159        if (m_pArea)
    104160        {
    105161            /* Configure area: */
     
    110166            m_pArea->setPalette(pal1);
    111167            /* Make sure valid child-widget passed: */
    112             AssertPtrReturnVoid(m_pWidget);
     168            if (m_pWidget)
    113169            {
    114170                /* Configure child-widget: */
     
    131187     * But move sub-window to initial position: */
    132188    const QSize sh = m_pWidget->sizeHint();
    133     switch (m_position)
     189    switch (m_enmPosition)
    134190    {
    135191        case Position_Top:
     
    155211        setMask(m_pWidget->geometry());
    156212    }
    157 #endif /* VBOX_WS_X11 */
     213#endif
    158214
    159215#ifdef VBOX_WS_WIN
    160216    /* Raise tool-window for proper z-order. */
    161217    raise();
    162 #endif /* VBOX_WS_WIN */
     218#endif
    163219
    164220    /* Activate window after it was shown: */
     
    188244    /* Adjust geometry based on parent and sub-window size-hints: */
    189245    const QSize sh = m_pWidget->sizeHint();
    190     switch (m_position)
     246    switch (m_enmPosition)
    191247    {
    192248        case Position_Top:
     
    212268        setMask(m_pWidget->geometry());
    213269    }
    214 #endif /* VBOX_WS_X11 */
     270#endif
    215271
    216272#ifdef VBOX_WS_WIN
    217273    /* Raise tool-window for proper z-order. */
    218274    raise();
    219 #endif /* VBOX_WS_WIN */
     275#endif
    220276}
    221277
     
    228284    /* Recalculate sub-window geometry animation boundaries based on size-hint: */
    229285    const QSize sh = m_pWidget->sizeHint();
    230     switch (m_position)
     286    switch (m_enmPosition)
    231287    {
    232288        case Position_Top:    m_startWidgetGeometry = QRect(0, -sh.height(), qMax(width(), sh.width()), sh.height()); break;
     
    237293}
    238294
    239 void UISlidingToolBar::showEvent(QShowEvent*)
    240 {
    241     /* If window isn't expanded: */
    242     if (!m_fExpanded)
    243     {
    244         /* Start expand animation: */
    245         emit sigShown();
    246     }
    247 }
    248 
    249 void UISlidingToolBar::closeEvent(QCloseEvent *pEvent)
    250 {
    251     /* If window isn't expanded: */
    252     if (!m_fExpanded)
    253     {
    254         /* Ignore close-event: */
    255         pEvent->ignore();
    256         return;
    257     }
    258 
    259     /* If animation state is Final: */
    260     const QString strAnimationState = property("AnimationState").toString();
    261     bool fAnimationComplete = strAnimationState == "Final";
    262     if (fAnimationComplete)
    263     {
    264         /* Ignore close-event: */
    265         pEvent->ignore();
    266         /* And start collapse animation: */
    267         emit sigCollapse();
    268     }
    269 }
    270 
    271 #ifdef VBOX_WS_MAC
    272 bool UISlidingToolBar::event(QEvent *pEvent)
    273 {
    274     /* Depending on event-type: */
    275     switch (pEvent->type())
    276     {
    277         case QEvent::Resize:
    278         case QEvent::WindowActivate:
    279         {
    280             /* By some strange reason
    281              * cocoa resets NSWindow::setHasShadow option
    282              * for frameless windows on every window resize/activation.
    283              * So we have to make sure window still has no shadows. */
    284             darwinSetWindowHasShadow(this, false);
    285             break;
    286         }
    287         default:
    288             break;
    289     }
    290     /* Call to base-class: */
    291     return QWidget::event(pEvent);
    292 }
    293 #endif /* VBOX_WS_MAC */
    294 
    295295void UISlidingToolBar::setWidgetGeometry(const QRect &rect)
    296296{
     
    304304        setMask(m_pWidget->geometry());
    305305    }
    306 #endif /* VBOX_WS_X11 */
     306#endif
    307307}
    308308
     
    312312    return m_pWidget->geometry();
    313313}
    314 
  • trunk/src/VBox/Frontends/VirtualBox/src/widgets/UISlidingToolBar.h

    r72026 r72027  
    55
    66/*
    7  * Copyright (C) 2014-2017 Oracle Corporation
     7 * Copyright (C) 2014-2018 Oracle Corporation
    88 *
    99 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    2222#include <QWidget>
    2323
     24/* GUI includes: */
     25#include "UILibraryDefs.h"
     26
    2427/* Forward declarations: */
     28class QCloseEvent;
     29class QEvent;
    2530class QHBoxLayout;
     31class QRect;
     32class QShowEvent;
     33class QWidget;
    2634class UIAnimation;
    2735
    28 /** QWidget reimplementation
     36/** QWidget subclass
    2937  * providing GUI with slideable tool-bar. */
    30 class UISlidingToolBar : public QWidget
     38class SHARED_LIBRARY_STUFF UISlidingToolBar : public QWidget
    3139{
    3240    Q_OBJECT;
     
    5361    };
    5462
    55     /** Constructor, passes @a pParentWidget to the QWidget constructor.
    56       * @param pParentWidget is used to get parent-widget geoemtry,
    57       * @param pIndentWidget is used to get indent-widget geometry,
    58       * @param pChildWidget  brings child-widget to be injected into tool-bar. */
    59     UISlidingToolBar(QWidget *pParentWidget, QWidget *pIndentWidget, QWidget *pChildWidget, Position position);
     63    /** Constructs sliding tool-bar passing @a pParentWidget to the base-class.
     64      * @param  pParentWidget  Brings the parent-widget geometry.
     65      * @param  pIndentWidget  Brings the indent-widget geometry.
     66      * @param  pChildWidget   Brings the child-widget to be injected into tool-bar.
     67      * @param  enmPosition    Brings the tool-bar position. */
     68    UISlidingToolBar(QWidget *pParentWidget, QWidget *pIndentWidget, QWidget *pChildWidget, Position enmPosition);
     69
     70protected:
     71
     72#ifdef VBOX_WS_MAC
     73    /** Handles any Qt @a pEvent. */
     74    virtual bool event(QEvent *pEvent) /* override */;
     75#endif
     76    /** Handles show @a pEvent. */
     77    virtual void showEvent(QShowEvent *pEvent) /* override */;
     78    /** Handles close @a pEvent. */
     79    virtual void closeEvent(QCloseEvent *pEvent) /* override */;
    6080
    6181private slots:
     
    7494private:
    7595
    76     /** Prepare routine. */
     96    /** Prepares all. */
    7797    void prepare();
    78     /** Prepare contents routine. */
     98    /** Prepares contents. */
    7999    void prepareContents();
    80     /** Prepare geometry routine. */
     100    /** Prepares geometry. */
    81101    void prepareGeometry();
    82     /** Prepare animation routine. */
     102    /** Prepares animation. */
    83103    void prepareAnimation();
    84104
    85     /** Update geometry. */
     105    /** Updates geometry. */
    86106    void adjustGeometry();
    87107    /** Updates animation. */
    88108    void updateAnimation();
    89 
    90     /** Show event handler. */
    91     virtual void showEvent(QShowEvent *pEvent);
    92     /** Close event handler. */
    93     virtual void closeEvent(QCloseEvent *pEvent);
    94 #ifdef VBOX_WS_MAC
    95     /** Common event handler. */
    96     virtual bool event(QEvent *pEvent);
    97 #endif /* VBOX_WS_MAC */
    98109
    99110    /** Defines sub-window geometry. */
     
    109120      * @{ */
    110121        /** Holds the tool-bar position. */
    111         const Position m_position;
     122        const Position  m_enmPosition;
    112123        /** Holds the cached parent-widget geometry. */
    113         QRect m_parentRect;
     124        QRect           m_parentRect;
    114125        /** Holds the cached indent-widget geometry. */
    115         QRect m_indentRect;
     126        QRect           m_indentRect;
    116127    /** @} */
    117128
     
    121132        UIAnimation *m_pAnimation;
    122133        /** Holds whether window is expanded. */
    123         bool m_fExpanded;
     134        bool         m_fExpanded;
    124135        /** Holds sub-window start-geometry. */
    125         QRect m_startWidgetGeometry;
     136        QRect        m_startWidgetGeometry;
    126137        /** Holds sub-window final-geometry. */
    127         QRect m_finalWidgetGeometry;
     138        QRect        m_finalWidgetGeometry;
    128139    /** @} */
    129140
     
    133144        QHBoxLayout *m_pMainLayout;
    134145        /** Holds the area instance. */
    135         QWidget *m_pArea;
     146        QWidget     *m_pArea;
    136147        /** Holds the child-widget reference. */
    137         QWidget *m_pWidget;
     148        QWidget     *m_pWidget;
    138149    /** @} */
    139150};
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