- Timestamp:
- Mar 22, 2018 12:40:17 PM (7 years ago)
- 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 5 5 6 6 /* 7 * Copyright (C) 2006-201 7Oracle Corporation7 * Copyright (C) 2006-2018 Oracle Corporation 8 8 * 9 9 * This file is part of VirtualBox Open Source Edition (OSE), as … … 29 29 # ifdef VBOX_WS_X11 30 30 # include <QX11Info> 31 # endif /* VBOX_WS_X11 */31 # endif 32 32 33 33 /* GUI includes: */ 34 # include "QIToolButton.h" 35 # include "VBoxGlobal.h" 36 # include "UIExtraDataManager.h" 34 37 # include "UIHostComboEditor.h" 35 # include "UIExtraDataManager.h"36 38 # include "UIIconPool.h" 37 # include "VBoxGlobal.h"38 # include "QIToolButton.h"39 39 # ifdef VBOX_WS_MAC 40 40 # include "UICocoaApplication.h" … … 47 47 #if defined(VBOX_WS_MAC) || defined(VBOX_WS_WIN) 48 48 # include <QAbstractNativeEventFilter> 49 #endif /* VBOX_WS_MAC || VBOX_WS_WIN */49 #endif 50 50 51 51 /* GUI includes: */ … … 56 56 #elif defined(VBOX_WS_X11) 57 57 # include "XKeyboard.h" 58 #endif /* VBOX_WS_X11 */58 #endif 59 59 60 60 /* Other VBox includes: */ 61 61 #if defined(VBOX_WS_X11) 62 62 # include <VBox/VBoxKeyboard.h> 63 #endif /* VBOX_WS_X11 */63 #endif 64 64 65 65 /* External includes: */ … … 168 168 #elif defined(VBOX_WS_WIN) 169 169 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. 174 175 int iScan; 175 176 switch (iKeyCode) … … 267 268 268 269 return false; 270 269 271 #endif 270 272 } … … 468 470 } 469 471 472 void UIHostComboEditor::retranslateUi() 473 { 474 /* Translate 'clear' tool-button: */ 475 m_pButtonClear->setToolTip(QApplication::translate("UIHotKeyEditor", "Unset shortcut")); 476 } 477 470 478 void UIHostComboEditor::sltCommitData() 471 479 { … … 511 519 } 512 520 513 void UIHostComboEditor::retranslateUi()514 {515 /* Translate 'clear' tool-button: */516 m_pButtonClear->setToolTip(QApplication::translate("UIHotKeyEditor", "Unset shortcut"));517 }518 519 521 void UIHostComboEditor::setCombo(const UIHostComboWrapper &strCombo) 520 522 { … … 539 541 #if defined(VBOX_WS_MAC) || defined(VBOX_WS_WIN) 540 542 , m_pPrivateEventFilter(0) 541 #endif /* VBOX_WS_MAC || VBOX_WS_WIN */543 #endif 542 544 #ifdef VBOX_WS_WIN 543 545 , m_pAltGrMonitor(0) 544 #endif /* VBOX_WS_WIN */546 #endif 545 547 { 546 548 /* Configure widget: */ … … 638 640 EventRef event = static_cast<EventRef>(darwinCocoaToCarbonEvent(pMessage)); 639 641 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. 643 645 switch(::GetEventClass(event)) 644 646 { … … 694 696 MSG *pEvent = static_cast<MSG*>(pMessage); 695 697 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. 699 701 switch (pEvent->message) 700 702 { … … 722 724 m_shownKeys.remove(VK_LCONTROL); 723 725 } 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. 726 729 if (!m_pressedKeys.contains(VK_LCONTROL)) 727 730 m_releasedKeys.remove(VK_LCONTROL); … … 742 745 xcb_generic_event_t *pEvent = static_cast<xcb_generic_event_t*>(pMessage); 743 746 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. 747 750 switch (pEvent->response_type & ~0x80) 748 751 { -
trunk/src/VBox/Frontends/VirtualBox/src/widgets/UIHostComboEditor.h
r69500 r71451 5 5 6 6 /* 7 * Copyright (C) 2006-201 7Oracle Corporation7 * Copyright (C) 2006-2018 Oracle Corporation 8 8 * 9 9 * This file is part of VirtualBox Open Source Edition (OSE), as … … 21 21 /* Qt includes: */ 22 22 #include <QLineEdit> 23 #include <QMap> 23 24 #include <QMetaType> 24 #include <QMap>25 25 #include <QSet> 26 26 … … 33 33 #if defined(VBOX_WS_MAC) || defined(VBOX_WS_WIN) 34 34 class ComboEditorEventFilter; 35 #endif /* VBOX_WS_MAC || VBOX_WS_WIN */35 #endif 36 36 #ifdef VBOX_WS_WIN 37 37 class WinAltGrMonitor; 38 #endif /* VBOX_WS_WIN */39 40 41 /* Native hot-key namespace to unify42 * 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. */ 43 43 namespace UINativeHotKey 44 44 { 45 /** Translates passed @a iKeyCode to string. */ 45 46 QString toString(int iKeyCode); 47 48 /** Returns whether passed @a iKeyCode is valid. */ 46 49 bool isValidKey(int iKeyCode); 47 /** Translates a modifier key in host platform 50 51 /** Translates passed @a iKeyCode in host platform 48 52 * encoding to the corresponding set 1 PC scan code. 49 53 * @note Non-modifier keys will return zero. */ 50 54 unsigned modifierToSet1ScanCode(int iKeyCode); 55 51 56 #if defined(VBOX_WS_WIN) 57 /** Distinguishes modifier VKey by @a wParam and @a lParam. */ 52 58 int distinguishModifierVKey(int wParam, int lParam); 53 59 #elif defined(VBOX_WS_X11) 60 /** Retranslates key names. */ 54 61 void retranslateKeyNames(); 55 #endif /* VBOX_WS_X11 */62 #endif 56 63 } 57 64 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. */ 60 68 namespace UIHostCombo 61 69 { 70 /** Returns host-combo modifier index. */ 62 71 int hostComboModifierIndex(); 72 /** Returns host-combo modifier name. */ 63 73 QString hostComboModifierName(); 74 /** Returns host-combo cached key. */ 64 75 QString hostComboCacheKey(); 76 77 /** Translates passed @strKeyCombo to readable string. */ 65 78 QString toReadableString(const QString &strKeyCombo); 79 /** Translates passed @strKeyCombo to key codes list. */ 66 80 QList<int> toKeyCodeList(const QString &strKeyCombo); 81 67 82 /** Returns a sequence of the set 1 PC scan codes for all 68 83 * modifiers contained in the (host platform format) sequence passed. */ 69 84 QList<unsigned> modifiersToScanCodes(const QString &strKeyCombo); 85 86 /** Returns whether passed @a strKeyCombo is valid. */ 70 87 bool isValidKeyCombo(const QString &strKeyCombo); 71 88 } 72 89 73 /* Host-combo wrapper: */ 90 91 /** Host-combo QString wrapper. */ 74 92 class UIHostComboWrapper 75 93 { 76 94 public: 77 95 96 /** Constructs host-combo wrapper on the basis of passed @a strHostCombo. */ 78 97 UIHostComboWrapper(const QString &strHostCombo = QString()) 79 98 : m_strHostCombo(strHostCombo) 80 99 {} 81 100 82 const QString& toString() const { return m_strHostCombo; } 101 /** Returns the host-combo. */ 102 const QString &toString() const { return m_strHostCombo; } 83 103 84 104 private: 85 105 106 /** Holds the host-combo. */ 86 107 QString m_strHostCombo; 87 108 }; 88 109 Q_DECLARE_METATYPE(UIHostComboWrapper); 89 110 111 90 112 /** Host-combo editor widget. */ 91 113 class UIHostComboEditor : public QIWithRetranslateUI<QWidget> … … 101 123 public: 102 124 103 /** Constructs host-combo editor for passed @a pParent. */125 /** Constructs host-combo editor passing @a pParent to the base-class. */ 104 126 UIHostComboEditor(QWidget *pParent); 127 128 protected: 129 130 /** Translates widget content. */ 131 virtual void retranslateUi() /* override */; 105 132 106 133 private slots: … … 111 138 private: 112 139 113 /** Prepares widget content. */140 /** Prepares all. */ 114 141 void prepare(); 115 142 116 /** Translates widget content. */ 117 void retranslateUi(); 118 119 /** Defines host-combo sequence. */ 143 /** Defines host @a strCombo sequence. */ 120 144 void setCombo(const UIHostComboWrapper &strCombo); 121 145 /** Returns host-combo sequence. */ … … 125 149 UIHostComboEditorPrivate *m_pEditor; 126 150 /** <b>Clear</b> QIToolButton instance. */ 127 QIToolButton *m_pButtonClear;151 QIToolButton *m_pButtonClear; 128 152 }; 129 153 130 /* Host-combo editor widget private stuff: */ 154 155 /** Host-combo editor widget private stuff. */ 131 156 class UIHostComboEditorPrivate : public QLineEdit 132 157 { … … 140 165 public: 141 166 167 /** Constructs host-combo editor private part. */ 142 168 UIHostComboEditorPrivate(); 169 /** Destructs host-combo editor private part. */ 143 170 ~UIHostComboEditorPrivate(); 144 171 172 /** Defines host @a strCombo sequence. */ 145 173 void setCombo(const UIHostComboWrapper &strCombo); 174 /** Returns host-combo sequence. */ 146 175 UIHostComboWrapper combo() const; 147 176 148 177 public slots: 149 178 179 /** Clears the host-combo selection. */ 150 180 void sltDeselect(); 181 /** Clears the host-combo editor. */ 151 182 void sltClear(); 152 183 153 184 protected: 154 185 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. */ 158 190 void keyPressEvent(QKeyEvent *pEvent); 191 /** Handles key-release @a pEvent. */ 159 192 void keyReleaseEvent(QKeyEvent *pEvent); 193 /** Handles mouse-press @a pEvent. */ 160 194 void mousePressEvent(QMouseEvent *pEvent); 195 /** Handles mouse-release @a pEvent. */ 161 196 void mouseReleaseEvent(QMouseEvent *pEvent); 162 197 163 198 private slots: 164 199 200 /** Releases pending keys. */ 165 201 void sltReleasePendingKeys(); 166 202 167 203 private: 168 204 205 /** PRocesses key event of @a fKeyPress type for a passed @a iKeyCode. */ 169 206 bool processKeyEvent(int iKeyCode, bool fKeyPress); 207 208 /** Updates text. */ 170 209 void updateText(); 171 210 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. */ 174 216 QMap<int, QString> m_shownKeys; 175 217 176 QTimer* m_pReleaseTimer; 218 /** Holds the release timer instance. */ 219 QTimer *m_pReleaseTimer; 220 221 /** Holds whether new sequence should be started. */ 177 222 bool m_fStartNewSequence; 178 223 … … 180 225 /** Mac, Win: Holds the native event filter instance. */ 181 226 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. */ 184 228 friend class ComboEditorEventFilter; 185 229 #endif /* VBOX_WS_MAC || VBOX_WS_WIN */ 186 230 187 231 #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. */ 190 233 uint32_t m_uDarwinKeyModifiers; 191 234 #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. */ 194 236 WinAltGrMonitor *m_pAltGrMonitor; 195 237 #endif /* VBOX_WS_WIN */ 196 238 }; 197 239 240 198 241 #endif /* !___UIHostComboEditor_h___ */ 199 242
Note:
See TracChangeset
for help on using the changeset viewer.