VirtualBox

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


Ignore:
Timestamp:
Feb 12, 2016 2:20:29 PM (9 years ago)
Author:
vboxsync
Message:

FE/Qt: Qt5 migration (part 89): Implementing keyboard handling for Qt5: Move private native event-filter from machine-view to keyboard-handler to other similar handlers.

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

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIKeyboardHandler.cpp

    r59657 r59658  
    5858
    5959#endif /* !VBOX_WITH_PRECOMPILED_HEADERS */
     60
     61/* Qt includes: */
     62#if QT_VERSION >= 0x050000
     63# include <QAbstractNativeEventFilter>
     64#endif /* QT_VERSION >= 0x050000 */
    6065
    6166/* GUI includes: */
     
    95100enum { KeyExtended = 0x01, KeyPressed = 0x02, KeyPause = 0x04, KeyPrint = 0x08 };
    96101enum { IsKeyPressed = 0x01, IsExtKeyPressed = 0x02, IsKbdCaptured = 0x80 };
     102
     103
     104#if QT_VERSION >= 0x050000
     105/** QAbstractNativeEventFilter extension
     106  * allowing to pre-process native platform events. */
     107class PrivateEventFilter : public QAbstractNativeEventFilter
     108{
     109public:
     110
     111    /** Constructor which takes the passed @a pParent to redirect events to. */
     112    PrivateEventFilter(UIKeyboardHandler *pParent)
     113        : m_pParent(pParent)
     114    {}
     115
     116    /** Handles all native events. */
     117    bool nativeEventFilter(const QByteArray &eventType, void *pMessage, long *pResult)
     118    {
     119        /* Redirect event to parent: */
     120        Q_UNUSED(pResult);
     121        return m_pParent->nativeEventPreprocessor(eventType, pMessage);
     122    }
     123
     124private:
     125
     126    /** Holds the passed parent reference. */
     127    UIKeyboardHandler *m_pParent;
     128};
     129#endif /* QT_VERSION >= 0x050000 */
    97130
    98131
     
    944977#else /* QT_VERSION >= 0x050000 */
    945978
     979bool UIKeyboardHandler::nativeEventPreprocessor(const QByteArray &eventType, void *pMessage)
     980{
     981    /* Redirect event to machine-view: */
     982    return m_views.value(m_iKeyboardHookViewIndex)->nativeEvent(eventType, pMessage);
     983}
     984
    946985bool UIKeyboardHandler::nativeEventPostprocessor(void *pMessage, ulong uScreenId)
    947986{
     
    14191458    , m_pAltGrMonitor(0)
    14201459#endif /* Q_WS_WIN */
     1460#if QT_VERSION >= 0x050000
     1461    , m_pPrivateEventFilter(0)
     1462#endif /* QT_VERSION >= 0x050000 */
    14211463    , m_cMonitors(1)
    14221464{
     
    14971539
    14981540#endif /* Q_WS_WIN */
     1541
     1542#if QT_VERSION >= 0x050000
     1543    /* If private event-filter is installed: */
     1544    if (m_pPrivateEventFilter)
     1545    {
     1546        /* Uninstall existing private event-filter: */
     1547        qApp->removeNativeEventFilter(m_pPrivateEventFilter);
     1548        delete m_pPrivateEventFilter;
     1549        m_pPrivateEventFilter = 0;
     1550    }
     1551#endif /* QT_VERSION >= 0x050000 */
    14991552
    15001553    /* Update keyboard hook view index: */
     
    15851638#endif /* Q_WS_WIN */
    15861639
     1640#if QT_VERSION >= 0x050000
     1641# if defined(Q_WS_WIN) || defined(Q_WS_X11)
     1642                /* If private event-filter is NOT installed;
     1643                 * Or installed but NOT for that view: */
     1644                if (!m_pPrivateEventFilter || (int)uScreenId != m_iKeyboardHookViewIndex)
     1645                {
     1646                    /* If private event-filter is installed: */
     1647                    if (m_pPrivateEventFilter)
     1648                    {
     1649                        /* Uninstall existing private event-filter: */
     1650                        qApp->removeNativeEventFilter(m_pPrivateEventFilter);
     1651                        delete m_pPrivateEventFilter;
     1652                        m_pPrivateEventFilter = 0;
     1653                    }
     1654                    /* Install new private event-filter: */
     1655                    m_pPrivateEventFilter = new PrivateEventFilter(this);
     1656                    qApp->installNativeEventFilter(m_pPrivateEventFilter);
     1657                }
     1658# endif /* Q_WS_WIN || Q_WS_X11 */
     1659#endif /* QT_VERSION >= 0x050000 */
     1660
    15871661                /* Update keyboard hook view index: */
    15881662                m_iKeyboardHookViewIndex = uScreenId;
     
    16291703
    16301704#endif /* Q_WS_WIN */
     1705
     1706#if QT_VERSION >= 0x050000
     1707# if defined(Q_WS_WIN) || defined(Q_WS_X11)
     1708                /* If private event-filter is installed: */
     1709                if (m_pPrivateEventFilter)
     1710                {
     1711                    /* Uninstall existing private event-filter: */
     1712                    qApp->removeNativeEventFilter(m_pPrivateEventFilter);
     1713                    delete m_pPrivateEventFilter;
     1714                    m_pPrivateEventFilter = 0;
     1715                }
     1716# endif /* Q_WS_WIN || Q_WS_X11 */
     1717#endif /* QT_VERSION >= 0x050000 */
    16311718
    16321719                /* Update keyboard hook view index: */
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIKeyboardHandler.h

    r59657 r59658  
    5252# endif /* QT_VERSION < 0x050000 */
    5353#endif /* Q_WS_X11 */
     54#if QT_VERSION >= 0x050000
     55class PrivateEventFilter;
     56#endif /* QT_VERSION >= 0x050000 */
    5457
    5558
     
    118121# endif /* Q_WS_X11 */
    119122#else /* QT_VERSION >= 0x050000 */
     123    /** Qt5: Performs pre-processing of all the native events. */
     124    bool nativeEventPreprocessor(const QByteArray &eventType, void *pMessage);
    120125    /** Qt5: Performs post-processing of all the native events. */
    121126    bool nativeEventPostprocessor(void *pMessage, ulong uScreenId);
     
    231236#endif /* Q_WS_WIN */
    232237
     238#if QT_VERSION >= 0x050000
     239    /** Win: Holds the native event filter instance. */
     240    PrivateEventFilter *m_pPrivateEventFilter;
     241    /** Win: Allows the native event filter to
     242      * redirect events directly to nativeEvent handler. */
     243    friend class PrivateEventFilter;
     244#endif /* QT_VERSION >= 0x050000 */
     245
    233246    ULONG m_cMonitors;
    234247};
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachineView.cpp

    r59656 r59658  
    7070
    7171#endif /* !VBOX_WITH_PRECOMPILED_HEADERS */
    72 
    73 /* Qt includes: */
    74 #if defined(Q_WS_WIN) || defined(Q_WS_X11)
    75 # if QT_VERSION >= 0x050000
    76 #  include <QAbstractNativeEventFilter>
    77 # endif /* QT_VERSION >= 0x050000 */
    78 #endif /* Q_WS_WIN || Q_WS_X11 */
    7972
    8073/* GUI includes: */
     
    130123
    131124
    132 #if defined(Q_WS_WIN) || defined(Q_WS_X11)
    133 # if QT_VERSION >= 0x050000
    134 /** QAbstractNativeEventFilter extension
    135   * allowing to pre-process native platform events. */
    136 class PrivateEventFilter : public QAbstractNativeEventFilter
    137 {
    138 public:
    139 
    140     /** Constructor which takes the passed @a pParent to redirect events to. */
    141     PrivateEventFilter(UIMachineView *pParent)
    142         : m_pParent(pParent)
    143     {}
    144 
    145     /** Handles all native events. */
    146     bool nativeEventFilter(const QByteArray &eventType, void *pMessage, long *pResult)
    147     {
    148         /* Redirect event to parent: */
    149         Q_UNUSED(pResult);
    150         return m_pParent->nativeEvent(eventType, pMessage);
    151     }
    152 
    153 private:
    154 
    155     /** Holds the passed parent reference. */
    156     UIMachineView *m_pParent;
    157 };
    158 # endif /* QT_VERSION >= 0x050000 */
    159 #endif /* Q_WS_WIN || Q_WS_X11 */
    160 
    161 
    162125/* static */
    163126UIMachineView* UIMachineView::create(  UIMachineWindow *pMachineWindow
     
    251214    if (!pMachineView)
    252215        return;
    253 
    254     /* Cleanup event-filters: */
    255     pMachineView->cleanupFilters();
    256216
    257217    /* Cleanup frame-buffer: */
     
    662622    , m_fIsDraggingFromGuest(false)
    663623#endif
    664 #if defined(Q_WS_WIN) || defined(Q_WS_X11)
    665 # if QT_VERSION >= 0x050000
    666     , m_pPrivateEventFilter(0)
    667 # endif /* QT_VERSION >= 0x050000 */
    668 #endif /* Q_WS_WIN || Q_WS_X11 */
    669624{
    670625}
     
    843798    /* We want to be notified on some parent's events: */
    844799    machineWindow()->installEventFilter(this);
    845 
    846 #if defined(Q_WS_WIN) || defined(Q_WS_X11)
    847 # if QT_VERSION >= 0x050000
    848     /* Prepare private event-filter: */
    849     m_pPrivateEventFilter = new PrivateEventFilter(this);
    850     qApp->installNativeEventFilter(m_pPrivateEventFilter);
    851 # endif /* QT_VERSION >= 0x050000 */
    852 #endif /* Q_WS_WIN || Q_WS_X11 */
    853800}
    854801
     
    876823    /* Machine state-change updater: */
    877824    connect(uisession(), SIGNAL(sigMachineStateChange()), this, SLOT(sltMachineStateChanged()));
    878 }
    879 
    880 void UIMachineView::cleanupFilters()
    881 {
    882 #if defined(Q_WS_WIN) || defined(Q_WS_X11)
    883 # if QT_VERSION >= 0x050000
    884     /* Cleanup private event-filter: */
    885     qApp->removeNativeEventFilter(m_pPrivateEventFilter);
    886     delete m_pPrivateEventFilter;
    887     m_pPrivateEventFilter = 0;
    888 # endif /* QT_VERSION >= 0x050000 */
    889 #endif /* Q_WS_WIN || Q_WS_X11 */
    890825}
    891826
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachineView.h

    r59413 r59658  
    6262# endif /* QT_VERSION < 0x050000 */
    6363#endif /* Q_WS_X11 */
    64 #if defined(Q_WS_WIN) || defined(Q_WS_X11)
    65 # if QT_VERSION >= 0x050000
    66 class PrivateEventFilter;
    67 # endif /* QT_VERSION >= 0x050000 */
    68 #endif /* Q_WS_WIN || Q_WS_X11 */
    6964#ifdef VBOX_WITH_DRAG_AND_DROP
    7065 class CDnDTarget;
     
    189184    //virtual void cleanupConsoleConnections() {}
    190185    //virtual void cleanupConnections() {}
    191     virtual void cleanupFilters();
     186    //virtual void cleanupFilters() {}
    192187    //virtual void cleanupCommon() {}
    193188    virtual void cleanupFrameBuffer();
     
    433428#endif
    434429
    435 #if defined(Q_WS_WIN) || defined(Q_WS_X11)
    436 # if QT_VERSION >= 0x050000
    437     /** X11: Holds the native event filter instance. */
    438     PrivateEventFilter *m_pPrivateEventFilter;
    439     /** X11: Allows the native event filter to
    440       * redirect events directly to nativeEvent handler. */
    441     friend class PrivateEventFilter;
    442 # endif /* QT_VERSION >= 0x050000 */
    443 #endif /* Q_WS_WIN || Q_WS_X11 */
    444 
    445430    /* Friend classes: */
    446431    friend class UIKeyboardHandler;
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