VirtualBox

Changeset 68296 in vbox for trunk


Ignore:
Timestamp:
Aug 4, 2017 10:06:38 AM (7 years ago)
Author:
vboxsync
Message:

FE/Qt: bugref:8900: UITabBar: Split item mouse handling to corresponding event handlers.

File:
1 edited

Legend:

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

    r68295 r68296  
    2525# include <QHBoxLayout>
    2626# include <QLabel>
     27# include <QMouseEvent>
    2728# include <QPainter>
    2829# ifdef VBOX_WS_MAC
     
    4546class QHBoxLayout;
    4647class QLabel;
     48class QMouseEvent;
    4749#ifdef VBOX_WS_MAC
    4850class QStackedLayout;
     
    8284protected:
    8385
    84     /** Handles any Qt @a pEvent. */
    85     virtual bool event(QEvent *pEvent) /* override */;
    86 
    8786    /** Handles paint @a pEvent. */
    8887    virtual void paintEvent(QPaintEvent *pEvent) /* override */;
     88
     89    /** Handles mouse-release @a pEvent. */
     90    virtual void mouseReleaseEvent(QMouseEvent *pEvent) /* override */;
     91    /** Handles mouse-enter @a pEvent. */
     92    virtual void enterEvent(QEvent *pEvent) /* override */;
     93    /** Handles mouse-leave @a pEvent. */
     94    virtual void leaveEvent(QEvent *pEvent) /* override */;
    8995
    9096private slots:
     
    154160    /* And call for repaint: */
    155161    update();
    156 }
    157 
    158 bool UITabBarItem::event(QEvent *pEvent)
    159 {
    160     /* Handle known event types: */
    161     switch (pEvent->type())
    162     {
    163         /* Update the hovered state on/off: */
    164         case QEvent::Enter:
    165         {
    166 #ifdef VBOX_WS_MAC
    167             m_pLayoutStacked->setCurrentWidget(m_pButtonClose);
    168 #endif
    169             m_fHovered = true;
    170             update();
    171             break;
    172         }
    173         case QEvent::Leave:
    174         {
    175 #ifdef VBOX_WS_MAC
    176             m_pLayoutStacked->setCurrentWidget(m_pLabelIcon);
    177 #endif
    178             m_fHovered = false;
    179             update();
    180             break;
    181         }
    182 
    183         /* Notify listeners about the item was clicked: */
    184         case QEvent::MouseButtonRelease:
    185         {
    186             emit sigClicked(this);
    187             break;
    188         }
    189 
    190         default: break;
    191     }
    192     /* Call to base-class: */
    193     return QWidget::event(pEvent);
    194162}
    195163
     
    279247}
    280248
     249void UITabBarItem::mouseReleaseEvent(QMouseEvent *pEvent)
     250{
     251    /* We are interested in left button only: */
     252    if (pEvent->button() != Qt::LeftButton)
     253        return QWidget::mouseReleaseEvent(pEvent);
     254
     255    /* Notify listeners about the item was clicked: */
     256    emit sigClicked(this);
     257}
     258
     259void UITabBarItem::enterEvent(QEvent *pEvent)
     260{
     261    /* Make sure button isn't hovered: */
     262    if (m_fHovered)
     263        return QWidget::enterEvent(pEvent);
     264
     265    /* Invert hovered state: */
     266#ifdef VBOX_WS_MAC
     267    m_pLayoutStacked->setCurrentWidget(m_pButtonClose);
     268#endif
     269    m_fHovered = true;
     270    /* And call for repaint: */
     271    update();
     272}
     273
     274void UITabBarItem::leaveEvent(QEvent *pEvent)
     275{
     276    /* Make sure button is hovered: */
     277    if (!m_fHovered)
     278        return QWidget::enterEvent(pEvent);
     279
     280    /* Invert hovered state: */
     281#ifdef VBOX_WS_MAC
     282    m_pLayoutStacked->setCurrentWidget(m_pLabelIcon);
     283#endif
     284    m_fHovered = false;
     285    /* And call for repaint: */
     286    update();
     287}
     288
    281289void UITabBarItem::prepare()
    282290{
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