VirtualBox

Changeset 71451 in vbox for trunk/src


Ignore:
Timestamp:
Mar 22, 2018 12:40:17 PM (7 years ago)
Author:
vboxsync
Message:

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

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

Legend:

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

    r71355 r71451  
    55
    66/*
    7  * Copyright (C) 2006-2017 Oracle Corporation
     7 * Copyright (C) 2006-2018 Oracle Corporation
    88 *
    99 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    2929# ifdef VBOX_WS_X11
    3030#  include <QX11Info>
    31 # endif /* VBOX_WS_X11 */
     31# endif
    3232
    3333/* GUI includes: */
     34# include "QIToolButton.h"
     35# include "VBoxGlobal.h"
     36# include "UIExtraDataManager.h"
    3437# include "UIHostComboEditor.h"
    35 # include "UIExtraDataManager.h"
    3638# include "UIIconPool.h"
    37 # include "VBoxGlobal.h"
    38 # include "QIToolButton.h"
    3939# ifdef VBOX_WS_MAC
    4040#  include "UICocoaApplication.h"
     
    4747#if defined(VBOX_WS_MAC) || defined(VBOX_WS_WIN)
    4848# include <QAbstractNativeEventFilter>
    49 #endif /* VBOX_WS_MAC || VBOX_WS_WIN */
     49#endif
    5050
    5151/* GUI includes: */
     
    5656#elif defined(VBOX_WS_X11)
    5757# include "XKeyboard.h"
    58 #endif /* VBOX_WS_X11 */
     58#endif
    5959
    6060/* Other VBox includes: */
    6161#if defined(VBOX_WS_X11)
    6262# include <VBox/VBoxKeyboard.h>
    63 #endif /* VBOX_WS_X11 */
     63#endif
    6464
    6565/* External includes: */
     
    168168#elif defined(VBOX_WS_WIN)
    169169
    170     /* MapVirtualKey doesn't distinguish between right and left vkeys,
    171      * even under XP, despite that it stated in MSDN. Do it by hands.
    172      * Besides that it can't recognize such virtual keys as
    173      * VK_DIVIDE & VK_PAUSE, this is also known bug. */
     170    // WORKAROUND:
     171    // MapVirtualKey doesn't distinguish between right and left vkeys,
     172    // even under XP, despite that it stated in MSDN. Do it by hands.
     173    // Besides that it can't recognize such virtual keys as
     174    // VK_DIVIDE & VK_PAUSE, this is also known bug.
    174175    int iScan;
    175176    switch (iKeyCode)
     
    267268
    268269    return false;
     270
    269271#endif
    270272}
     
    468470}
    469471
     472void UIHostComboEditor::retranslateUi()
     473{
     474    /* Translate 'clear' tool-button: */
     475    m_pButtonClear->setToolTip(QApplication::translate("UIHotKeyEditor", "Unset shortcut"));
     476}
     477
    470478void UIHostComboEditor::sltCommitData()
    471479{
     
    511519}
    512520
    513 void UIHostComboEditor::retranslateUi()
    514 {
    515     /* Translate 'clear' tool-button: */
    516     m_pButtonClear->setToolTip(QApplication::translate("UIHotKeyEditor", "Unset shortcut"));
    517 }
    518 
    519521void UIHostComboEditor::setCombo(const UIHostComboWrapper &strCombo)
    520522{
     
    539541#if defined(VBOX_WS_MAC) || defined(VBOX_WS_WIN)
    540542    , m_pPrivateEventFilter(0)
    541 #endif /* VBOX_WS_MAC || VBOX_WS_WIN */
     543#endif
    542544#ifdef VBOX_WS_WIN
    543545    , m_pAltGrMonitor(0)
    544 #endif /* VBOX_WS_WIN */
     546#endif
    545547{
    546548    /* Configure widget: */
     
    638640    EventRef event = static_cast<EventRef>(darwinCocoaToCarbonEvent(pMessage));
    639641
    640     /* Check if some NSEvent should be filtered out.
    641      * Returning @c true means filtering-out,
    642      * Returning @c false means passing event to Qt. */
     642    /* Check if some NSEvent should be filtered out: */
     643    // Returning @c true means filtering-out,
     644    // Returning @c false means passing event to Qt.
    643645    switch(::GetEventClass(event))
    644646    {
     
    694696    MSG *pEvent = static_cast<MSG*>(pMessage);
    695697
    696     /* Check if some MSG event should be filtered out.
    697      * Returning @c true means filtering-out,
    698      * Returning @c false means passing event to Qt. */
     698    /* Check if some MSG event should be filtered out: */
     699    // Returning @c true means filtering-out,
     700    // Returning @c false means passing event to Qt.
    699701    switch (pEvent->message)
    700702    {
     
    722724                    m_shownKeys.remove(VK_LCONTROL);
    723725                }
    724                 /* Fake LCtrl release events can also end up in the released
    725                  * key set.  Detect them on the immediately following RAlt up. */
     726                // WORKAROUND:
     727                // Fake LCtrl release events can also end up in the released
     728                // key set.  Detect them on the immediately following RAlt up.
    726729                if (!m_pressedKeys.contains(VK_LCONTROL))
    727730                    m_releasedKeys.remove(VK_LCONTROL);
     
    742745    xcb_generic_event_t *pEvent = static_cast<xcb_generic_event_t*>(pMessage);
    743746
    744     /* Check if some XCB event should be filtered out.
    745      * Returning @c true means filtering-out,
    746      * Returning @c false means passing event to Qt. */
     747    /* Check if some XCB event should be filtered out: */
     748    // Returning @c true means filtering-out,
     749    // Returning @c false means passing event to Qt.
    747750    switch (pEvent->response_type & ~0x80)
    748751    {
  • trunk/src/VBox/Frontends/VirtualBox/src/widgets/UIHostComboEditor.h

    r69500 r71451  
    55
    66/*
    7  * Copyright (C) 2006-2017 Oracle Corporation
     7 * Copyright (C) 2006-2018 Oracle Corporation
    88 *
    99 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    2121/* Qt includes: */
    2222#include <QLineEdit>
     23#include <QMap>
    2324#include <QMetaType>
    24 #include <QMap>
    2525#include <QSet>
    2626
     
    3333#if defined(VBOX_WS_MAC) || defined(VBOX_WS_WIN)
    3434class ComboEditorEventFilter;
    35 #endif /* VBOX_WS_MAC || VBOX_WS_WIN */
     35#endif
    3636#ifdef VBOX_WS_WIN
    3737class WinAltGrMonitor;
    38 #endif /* VBOX_WS_WIN */
    39 
    40 
    41 /* Native hot-key namespace to unify
    42  * all the related hot-key processing stuff: */
     38#endif
     39
     40
     41/** Native hot-key namespace to unify
     42  * all the related hot-key processing stuff. */
    4343namespace UINativeHotKey
    4444{
     45    /** Translates passed @a iKeyCode to string. */
    4546    QString toString(int iKeyCode);
     47
     48    /** Returns whether passed @a iKeyCode is valid. */
    4649    bool isValidKey(int iKeyCode);
    47     /** Translates a modifier key in host platform
     50
     51    /** Translates passed @a iKeyCode in host platform
    4852      * encoding to the corresponding set 1 PC scan code.
    4953      * @note  Non-modifier keys will return zero. */
    5054    unsigned modifierToSet1ScanCode(int iKeyCode);
     55
    5156#if defined(VBOX_WS_WIN)
     57    /** Distinguishes modifier VKey by @a wParam and @a lParam. */
    5258    int distinguishModifierVKey(int wParam, int lParam);
    5359#elif defined(VBOX_WS_X11)
     60    /** Retranslates key names. */
    5461    void retranslateKeyNames();
    55 #endif /* VBOX_WS_X11 */
     62#endif
    5663}
    5764
    58 /* Host-combo namespace to unify
    59  * all the related hot-combo processing stuff: */
     65
     66/** Host-combo namespace to unify
     67  * all the related hot-combo processing stuff. */
    6068namespace UIHostCombo
    6169{
     70    /** Returns host-combo modifier index. */
    6271    int hostComboModifierIndex();
     72    /** Returns host-combo modifier name. */
    6373    QString hostComboModifierName();
     74    /** Returns host-combo cached key. */
    6475    QString hostComboCacheKey();
     76
     77    /** Translates passed @strKeyCombo to readable string. */
    6578    QString toReadableString(const QString &strKeyCombo);
     79    /** Translates passed @strKeyCombo to key codes list. */
    6680    QList<int> toKeyCodeList(const QString &strKeyCombo);
     81
    6782    /** Returns a sequence of the set 1 PC scan codes for all
    6883      * modifiers contained in the (host platform format) sequence passed. */
    6984    QList<unsigned> modifiersToScanCodes(const QString &strKeyCombo);
     85
     86    /** Returns whether passed @a strKeyCombo is valid. */
    7087    bool isValidKeyCombo(const QString &strKeyCombo);
    7188}
    7289
    73 /* Host-combo wrapper: */
     90
     91/** Host-combo QString wrapper. */
    7492class UIHostComboWrapper
    7593{
    7694public:
    7795
     96    /** Constructs host-combo wrapper on the basis of passed @a strHostCombo. */
    7897    UIHostComboWrapper(const QString &strHostCombo = QString())
    7998        : m_strHostCombo(strHostCombo)
    8099    {}
    81100
    82     const QString& toString() const { return m_strHostCombo; }
     101    /** Returns the host-combo. */
     102    const QString &toString() const { return m_strHostCombo; }
    83103
    84104private:
    85105
     106    /** Holds the host-combo. */
    86107    QString m_strHostCombo;
    87108};
    88109Q_DECLARE_METATYPE(UIHostComboWrapper);
    89110
     111
    90112/** Host-combo editor widget. */
    91113class UIHostComboEditor : public QIWithRetranslateUI<QWidget>
     
    101123public:
    102124
    103     /** Constructs host-combo editor for passed @a pParent. */
     125    /** Constructs host-combo editor passing @a pParent to the base-class. */
    104126    UIHostComboEditor(QWidget *pParent);
     127
     128protected:
     129
     130    /** Translates widget content. */
     131    virtual void retranslateUi() /* override */;
    105132
    106133private slots:
     
    111138private:
    112139
    113     /** Prepares widget content. */
     140    /** Prepares all. */
    114141    void prepare();
    115142
    116     /** Translates widget content. */
    117     void retranslateUi();
    118 
    119     /** Defines host-combo sequence. */
     143    /** Defines host @a strCombo sequence. */
    120144    void setCombo(const UIHostComboWrapper &strCombo);
    121145    /** Returns host-combo sequence. */
     
    125149    UIHostComboEditorPrivate *m_pEditor;
    126150    /** <b>Clear</b> QIToolButton instance. */
    127     QIToolButton *m_pButtonClear;
     151    QIToolButton             *m_pButtonClear;
    128152};
    129153
    130 /* Host-combo editor widget private stuff: */
     154
     155/** Host-combo editor widget private stuff. */
    131156class UIHostComboEditorPrivate : public QLineEdit
    132157{
     
    140165public:
    141166
     167    /** Constructs host-combo editor private part. */
    142168    UIHostComboEditorPrivate();
     169    /** Destructs host-combo editor private part. */
    143170    ~UIHostComboEditorPrivate();
    144171
     172    /** Defines host @a strCombo sequence. */
    145173    void setCombo(const UIHostComboWrapper &strCombo);
     174    /** Returns host-combo sequence. */
    146175    UIHostComboWrapper combo() const;
    147176
    148177public slots:
    149178
     179    /** Clears the host-combo selection. */
    150180    void sltDeselect();
     181    /** Clears the host-combo editor. */
    151182    void sltClear();
    152183
    153184protected:
    154185
    155     /** Qt5: Handles all native events. */
    156     bool nativeEvent(const QByteArray &eventType, void *pMessage, long *pResult);
    157 
     186    /** Handles native events. */
     187    virtual bool nativeEvent(const QByteArray &eventType, void *pMessage, long *pResult) /* override */;
     188
     189    /** Handles key-press @a pEvent. */
    158190    void keyPressEvent(QKeyEvent *pEvent);
     191    /** Handles key-release @a pEvent. */
    159192    void keyReleaseEvent(QKeyEvent *pEvent);
     193    /** Handles mouse-press @a pEvent. */
    160194    void mousePressEvent(QMouseEvent *pEvent);
     195    /** Handles mouse-release @a pEvent. */
    161196    void mouseReleaseEvent(QMouseEvent *pEvent);
    162197
    163198private slots:
    164199
     200    /** Releases pending keys. */
    165201    void sltReleasePendingKeys();
    166202
    167203private:
    168204
     205    /** PRocesses key event of @a fKeyPress type for a passed @a iKeyCode. */
    169206    bool processKeyEvent(int iKeyCode, bool fKeyPress);
     207
     208    /** Updates text. */
    170209    void updateText();
    171210
    172     QSet<int> m_pressedKeys;
    173     QSet<int> m_releasedKeys;
     211    /** Holds the pressed keys. */
     212    QSet<int>          m_pressedKeys;
     213    /** Holds the released keys. */
     214    QSet<int>          m_releasedKeys;
     215    /** Holds the shown keys. */
    174216    QMap<int, QString> m_shownKeys;
    175217
    176     QTimer* m_pReleaseTimer;
     218    /** Holds the release timer instance. */
     219    QTimer *m_pReleaseTimer;
     220
     221    /** Holds whether new sequence should be started. */
    177222    bool m_fStartNewSequence;
    178223
     
    180225    /** Mac, Win: Holds the native event filter instance. */
    181226    ComboEditorEventFilter *m_pPrivateEventFilter;
    182     /** Mac, Win: Allows the native event filter to
    183       * redirect events directly to nativeEvent handler. */
     227    /** Mac, Win: Allows the native event filter to redirect events directly to nativeEvent handler. */
    184228    friend class ComboEditorEventFilter;
    185229#endif /* VBOX_WS_MAC || VBOX_WS_WIN */
    186230
    187231#if defined(VBOX_WS_MAC)
    188     /** Mac: Holds the current modifier key mask. Used to figure out which modifier
    189       * key was pressed when we get a kEventRawKeyModifiersChanged event. */
     232    /** Mac: Holds the current modifier key mask. */
    190233    uint32_t m_uDarwinKeyModifiers;
    191234#elif defined(VBOX_WS_WIN)
    192     /** Win: Holds the object monitoring key event
    193       * stream for problematic AltGr events. */
     235    /** Win: Holds the object monitoring key event stream for problematic AltGr events. */
    194236    WinAltGrMonitor *m_pAltGrMonitor;
    195237#endif /* VBOX_WS_WIN */
    196238};
    197239
     240
    198241#endif /* !___UIHostComboEditor_h___ */
    199242
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