VirtualBox

Changeset 71921 in vbox for trunk


Ignore:
Timestamp:
Apr 19, 2018 1:09:04 PM (7 years ago)
Author:
vboxsync
Message:

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

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

Legend:

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

    r71905 r71921  
    557557        src/widgets/UIApplianceImportEditorWidget.h \
    558558        src/widgets/UIEmptyFilePathSelector.h \
    559         src/widgets/UIHotKeyEditor.h \
    560559        src/widgets/UILineTextEdit.h \
    561560        src/widgets/UIMediumSizeEditor.h \
     
    686685        src/widgets/UIFilmContainer.h \
    687686        src/widgets/UIHostComboEditor.h \
     687        src/widgets/UIHotKeyEditor.h \
    688688        src/widgets/UIPopupBox.h \
    689689        src/widgets/UIPopupPane.h \
     
    777777        src/widgets/UIFilmContainer.h \
    778778        src/widgets/UIHostComboEditor.h \
     779        src/widgets/UIHotKeyEditor.h \
    779780        src/widgets/UIPopupBox.h \
    780781        src/widgets/UIPopupPane.h \
     
    834835        src/settings/machine/UIMachineSettingsStorage.cpp \
    835836        src/settings/machine/UIMachineSettingsUSB.cpp \
    836         src/widgets/UIHotKeyEditor.cpp \
    837837        src/widgets/UIMenuToolBar.cpp \
    838838        src/widgets/UIMiniToolBar.cpp \
     
    858858        src/selector/UIVirtualBoxEventHandler.cpp \
    859859        src/widgets/UIFilmContainer.cpp \
     860        src/widgets/UIHotKeyEditor.cpp \
    860861        src/widgets/UIProgressDialog.cpp
    861862
     
    897898        src/selector/UIVirtualBoxEventHandler.cpp \
    898899        src/widgets/UIFilmContainer.cpp \
     900        src/widgets/UIHotKeyEditor.cpp \
    899901        src/widgets/UIProgressDialog.cpp
    900902
     
    10451047        src/widgets/UIApplianceImportEditorWidget.cpp \
    10461048        src/widgets/UIEmptyFilePathSelector.cpp \
    1047         src/widgets/UIHotKeyEditor.cpp \
    10481049        src/widgets/UILineTextEdit.cpp \
    10491050        src/widgets/UIMediumSizeEditor.cpp \
     
    12141215        src/widgets/UIFilmContainer.cpp \
    12151216        src/widgets/UIHostComboEditor.cpp \
     1217        src/widgets/UIHotKeyEditor.cpp \
    12161218        src/widgets/UIPopupBox.cpp \
    12171219        src/widgets/UIPopupPane.cpp \
     
    13311333        src/widgets/UIFilmContainer.cpp \
    13321334        src/widgets/UIHostComboEditor.cpp \
     1335        src/widgets/UIHotKeyEditor.cpp \
    13331336        src/widgets/UIPopupBox.cpp \
    13341337        src/widgets/UIPopupPane.cpp \
  • trunk/src/VBox/Frontends/VirtualBox/src/widgets/UIHotKeyEditor.cpp

    r70523 r71921  
    11/* $Id$ */
    22/** @file
    3  * VBox Qt GUI - VirtualBox Qt extensions: UIHotKeyEditor class implementation.
     3 * VBox Qt GUI - UIHotKeyEditor class implementation.
    44 */
    55
    66/*
    7  * Copyright (C) 2013-2017 Oracle Corporation
     7 * Copyright (C) 2013-2018 Oracle Corporation
    88 *
    99 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    2828
    2929/* GUI includes; */
     30# include "UIHostComboEditor.h"
    3031# include "UIHotKeyEditor.h"
    3132# include "UIIconPool.h"
    32 # include "UIHostComboEditor.h"
    3333# include "QIToolButton.h"
    3434
     
    3636
    3737
    38 /* A line-edit representing hot-key editor: */
     38/** QLineEdit extension representing hot-key editor. */
    3939class UIHotKeyLineEdit : public QLineEdit
    4040{
     
    4343public:
    4444
    45     /* Constructor: */
     45    /** Constructs hot-key editor passing @a pParent to the base-class. */
    4646    UIHotKeyLineEdit(QWidget *pParent);
    4747
    48 private slots:
    49 
    50     /* Handler: Selection preserver stuff: */
     48protected slots:
     49
     50    /** Deselects the hot-key editor text. */
    5151    void sltDeselect() { deselect(); }
    5252
     53protected:
     54
     55    /** Handles key-press @a pEvent. */
     56    virtual void keyPressEvent(QKeyEvent *pEvent) /* override */;
     57    /** Handles key-release @a pEvent. */
     58    virtual void keyReleaseEvent(QKeyEvent *pEvent) /* override */;
     59
    5360private:
    5461
    55     /* Handlers: Key event processing stuff: */
    56     void keyPressEvent(QKeyEvent *pEvent);
    57     void keyReleaseEvent(QKeyEvent *pEvent);
     62    /** Returns whether the passed @a pevent should be ignored. */
    5863    bool isKeyEventIgnored(QKeyEvent *pEvent);
    5964};
     65
     66
     67/*********************************************************************************************************************************
     68*   Class UIHotKeyLineEdit implementation.                                                                                       *
     69*********************************************************************************************************************************/
    6070
    6171UIHotKeyLineEdit::UIHotKeyLineEdit(QWidget *pParent)
     
    107117}
    108118
     119
     120/*********************************************************************************************************************************
     121*   Class UIHotKeyEditor implementation.                                                                                         *
     122*********************************************************************************************************************************/
    109123
    110124UIHotKeyEditor::UIHotKeyEditor(QWidget *pParent)
     
    178192}
    179193
    180 void UIHotKeyEditor::retranslateUi()
    181 {
    182     m_pResetButton->setToolTip(tr("Reset shortcut to default"));
    183     m_pClearButton->setToolTip(tr("Unset shortcut"));
    184 }
    185 
    186194bool UIHotKeyEditor::eventFilter(QObject *pWatched, QEvent *pEvent)
    187195{
     
    221229    /* Prevent further key event handling: */
    222230    return true;
     231}
     232
     233void UIHotKeyEditor::retranslateUi()
     234{
     235    m_pResetButton->setToolTip(tr("Reset shortcut to default"));
     236    m_pClearButton->setToolTip(tr("Unset shortcut"));
     237}
     238
     239void UIHotKeyEditor::keyPressEvent(QKeyEvent *pEvent)
     240{
     241    /* Is this event ignored? */
     242    if (isKeyEventIgnored(pEvent))
     243        return;
     244    /* Call to base-class: */
     245    return QWidget::keyPressEvent(pEvent);
     246}
     247
     248void UIHotKeyEditor::keyReleaseEvent(QKeyEvent *pEvent)
     249{
     250    /* Is this event ignored? */
     251    if (isKeyEventIgnored(pEvent))
     252        return;
     253    /* Call to base-class: */
     254    return QWidget::keyReleaseEvent(pEvent);
    223255}
    224256
     
    243275    /* Do not skip by default: */
    244276    return false;
    245 }
    246 
    247 void UIHotKeyEditor::keyPressEvent(QKeyEvent *pEvent)
    248 {
    249     /* Is this event ignored? */
    250     if (isKeyEventIgnored(pEvent))
    251         return;
    252     /* Call to base-class: */
    253     return QWidget::keyPressEvent(pEvent);
    254 }
    255 
    256 void UIHotKeyEditor::keyReleaseEvent(QKeyEvent *pEvent)
    257 {
    258     /* Is this event ignored? */
    259     if (isKeyEventIgnored(pEvent))
    260         return;
    261     /* Call to base-class: */
    262     return QWidget::keyReleaseEvent(pEvent);
    263277}
    264278
     
    482496}
    483497
     498
    484499#include "UIHotKeyEditor.moc"
    485 
  • trunk/src/VBox/Frontends/VirtualBox/src/widgets/UIHotKeyEditor.h

    r69500 r71921  
    11/* $Id$ */
    22/** @file
    3  * VBox Qt GUI - VirtualBox Qt extensions: UIHotKeyEditor class declaration.
     3 * VBox Qt GUI - UIHotKeyEditor class declaration.
    44 */
    55
    66/*
    7  * Copyright (C) 2013-2017 Oracle Corporation
     7 * Copyright (C) 2013-2018 Oracle Corporation
    88 *
    99 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    2121/* Qt includes: */
    2222#include <QMetaType>
     23#include <QSet>
    2324#include <QWidget>
    24 #include <QSet>
    2525
    2626/* GUI includes: */
    2727#include "QIWithRetranslateUI.h"
     28#include "UILibraryDefs.h"
    2829
    2930/* Forward declarations: */
     
    3233class UIHotKeyLineEdit;
    3334
    34 /* Host key type enumerator: */
     35
     36/** Hot key types. */
    3537enum UIHotKeyType
    3638{
     
    3941};
    4042
    41 /* A string pair wrapper for hot-key sequence: */
     43
     44/** A string pair wrapper for hot-key sequence. */
    4245class UIHotKey
    4346{
    4447public:
    4548
    46     /* Constructors: */
     49    /** Constructs null hot-key sequence. */
    4750    UIHotKey()
    48         : m_type(UIHotKeyType_Simple)
     51        : m_enmType(UIHotKeyType_Simple)
    4952    {}
    50     UIHotKey(UIHotKeyType type,
    51              const QString &strSequence,
    52              const QString &strDefaultSequence)
    53         : m_type(type)
     53    /** Constructs hot-key sequence on the basis of passed @a enmType, @a strSequence and @a strDefaultSequence. */
     54    UIHotKey(UIHotKeyType enmType, const QString &strSequence, const QString &strDefaultSequence)
     55        : m_enmType(enmType)
    5456        , m_strSequence(strSequence)
    5557        , m_strDefaultSequence(strDefaultSequence)
    5658    {}
     59    /** Constructs hot-key sequence on the basis of @a other hot-key sequence. */
    5760    UIHotKey(const UIHotKey &other)
    58         : m_type(other.type())
     61        : m_enmType(other.type())
    5962        , m_strSequence(other.sequence())
    6063        , m_strDefaultSequence(other.defaultSequence())
    6164    {}
    6265
    63     /* API: Operators stuff: */
    64     UIHotKey& operator=(const UIHotKey &other)
     66    /** Makes a copy of the given other hot-key sequence and assigns it to this one. */
     67    UIHotKey &operator=(const UIHotKey &other)
    6568    {
    66         m_type = other.type();
     69        m_enmType = other.type();
    6770        m_strSequence = other.sequence();
    6871        m_strDefaultSequence = other.defaultSequence();
     
    7073    }
    7174
    72     /* API: Type access stuff: */
    73     UIHotKeyType type() const { return m_type; }
     75    /** Returns the type of this hot-key sequence. */
     76    UIHotKeyType type() const { return m_enmType; }
    7477
    75     /* API: Sequence access stuff: */
    76     const QString& sequence() const { return m_strSequence; }
    77     const QString& defaultSequence() const { return m_strDefaultSequence; }
     78    /** Returns hot-key sequence. */
     79    const QString &sequence() const { return m_strSequence; }
     80    /** Returns default hot-key sequence. */
     81    const QString &defaultSequence() const { return m_strDefaultSequence; }
     82    /** Defines hot-key @a strSequence. */
    7883    void setSequence(const QString &strSequence) { m_strSequence = strSequence; }
    7984
    8085private:
    8186
    82     /* Variables: */
    83     UIHotKeyType m_type;
     87    /** Holds the type of this hot-key sequence. */
     88    UIHotKeyType m_enmType;
     89    /** Holds the hot-key sequence. */
    8490    QString m_strSequence;
     91    /** Holds the default hot-key sequence. */
    8592    QString m_strDefaultSequence;
    8693};
    8794Q_DECLARE_METATYPE(UIHotKey);
    8895
    89 /* A widget wrapper for real hot-key editor: */
    90 class UIHotKeyEditor : public QIWithRetranslateUI<QWidget>
     96
     97/** QWidget subclass wrapping real hot-key editor. */
     98class SHARED_LIBRARY_STUFF UIHotKeyEditor : public QIWithRetranslateUI<QWidget>
    9199{
    92100    Q_OBJECT;
     
    100108public:
    101109
    102     /* Constructor: */
     110    /** Constructs hot-key editor passing @a pParent to the base-class. */
    103111    UIHotKeyEditor(QWidget *pParent);
    104112
    105113private slots:
    106114
    107     /* Handlers: Tool-button stuff: */
     115    /** Resets hot-key sequence to default. */
    108116    void sltReset();
     117    /** Clears hot-key sequence. */
    109118    void sltClear();
     119
     120protected:
     121
     122    /** Preprocesses any Qt @a pEvent for passed @a pObject. */
     123    virtual bool eventFilter(QObject *pObject, QEvent *pEvent) /* override */;
     124
     125    /** Handles translation event. */
     126    virtual void retranslateUi() /* override */;
     127
     128    /** Handles key-press @a pEvent. */
     129    virtual void keyPressEvent(QKeyEvent *pEvent) /* override */;
     130    /** Handles key-release @a pEvent. */
     131    virtual void keyReleaseEvent(QKeyEvent *pEvent) /* override */;
    110132
    111133private:
    112134
    113     /* Helper: Translate stuff: */
    114     void retranslateUi();
    115 
    116     /* Handlers: Line-edit key event pre-processing stuff: */
    117     bool eventFilter(QObject *pWatched, QEvent *pEvent);
     135    /** Returns whether we hould skip key-event to line-edit. */
    118136    bool shouldWeSkipKeyEventToLineEdit(QKeyEvent *pEvent);
    119137
    120     /* Handlers: Key event processing stuff: */
    121     void keyPressEvent(QKeyEvent *pEvent);
    122     void keyReleaseEvent(QKeyEvent *pEvent);
     138    /** Returns whether key @a pEvent is ignored. */
    123139    bool isKeyEventIgnored(QKeyEvent *pEvent);
    124140
    125     /* Helpers: Modifier stuff: */
     141    /** Fetches actual modifier states. */
    126142    void fetchModifiersState();
     143    /** Returns whether Host+ modifier is required. */
    127144    void checkIfHostModifierNeeded();
    128145
    129     /* Handlers: Sequence stuff: */
    130     bool approvedKeyPressed(QKeyEvent *pKeyEvent);
    131     void handleKeyPress(QKeyEvent *pKeyEvent);
    132     void handleKeyRelease(QKeyEvent *pKeyEvent);
     146    /** Handles approved key-press @a pEvent. */
     147    bool approvedKeyPressed(QKeyEvent *pEvent);
     148    /** Handles key-press @a pEvent. */
     149    void handleKeyPress(QKeyEvent *pEvent);
     150    /** Handles key-release @a pEvent. */
     151    void handleKeyRelease(QKeyEvent *pEvent);
     152    /** Reflects recorded sequence in editor. */
    133153    void reflectSequence();
     154    /** Draws recorded sequence in editor. */
    134155    void drawSequence();
    135156
    136     /* API: Editor stuff: */
     157    /** Returns hot-key. */
    137158    UIHotKey hotKey() const;
     159    /** Defines @a hotKey. */
    138160    void setHotKey(const UIHotKey &hotKey);
    139161
    140     /* Variables: */
    141     UIHotKey m_hotKey;
    142     bool m_fIsModifiersAllowed;
    143     QHBoxLayout *m_pMainLayout;
    144     QHBoxLayout *m_pButtonLayout;
     162    /** Holds the hot-key. */
     163    UIHotKey  m_hotKey;
     164
     165    /** Holds whether the modifiers are allowed. */
     166    bool  m_fIsModifiersAllowed;
     167
     168    /** Holds the main-layout instance. */
     169    QHBoxLayout      *m_pMainLayout;
     170    /** Holds the button-layout instance. */
     171    QHBoxLayout      *m_pButtonLayout;
     172    /** Holds the line-edit instance. */
    145173    UIHotKeyLineEdit *m_pLineEdit;
    146     QIToolButton *m_pResetButton;
    147     QIToolButton *m_pClearButton;
    148     QSet<int> m_takenModifiers;
    149     int m_iTakenKey;
    150     bool m_fSequenceTaken;
     174    /** Holds the reset-button instance. */
     175    QIToolButton     *m_pResetButton;
     176    /** Holds the clear-button instance. */
     177    QIToolButton     *m_pClearButton;
     178
     179    /** Holds the taken modifiers. */
     180    QSet<int>  m_takenModifiers;
     181    /** Holds the taken key. */
     182    int        m_iTakenKey;
     183    /** Holds whether sequence is taken. */
     184    bool       m_fSequenceTaken;
    151185};
    152186
     187
    153188#endif /* !___UIHotKeyEditor_h___ */
    154 
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