diff options
author | axis <qt-info@nokia.com> | 2010-02-25 15:40:52 (GMT) |
---|---|---|
committer | axis <qt-info@nokia.com> | 2010-02-25 16:03:48 (GMT) |
commit | 1dc6431ea5225716d2fc77791d63a7318a980325 (patch) | |
tree | 18ae9c977338a94912f216c42f92ec33045d8106 | |
parent | 133f853e569494303fc432f6c6009dd44c504446 (diff) | |
download | Qt-1dc6431ea5225716d2fc77791d63a7318a980325.zip Qt-1dc6431ea5225716d2fc77791d63a7318a980325.tar.gz Qt-1dc6431ea5225716d2fc77791d63a7318a980325.tar.bz2 |
Reduced the code and memory footprint of the keymap.
This was done by using a static const data structure instead of a
list.
RevBy: Alessandro Portale
-rw-r--r-- | src/gui/kernel/qkeymapper_p.h | 12 | ||||
-rw-r--r-- | src/gui/kernel/qkeymapper_s60.cpp | 241 |
2 files changed, 124 insertions, 129 deletions
diff --git a/src/gui/kernel/qkeymapper_p.h b/src/gui/kernel/qkeymapper_p.h index 706ee23..4fbfff0 100644 --- a/src/gui/kernel/qkeymapper_p.h +++ b/src/gui/kernel/qkeymapper_p.h @@ -137,15 +137,6 @@ struct QXCoreDesc { KeySym lock_meaning; }; -#elif defined(Q_OS_SYMBIAN) -#include <e32keys.h> -class KeyMapping{ -public: - KeyMapping(TKeyCode aS60KeyCode, TStdScanCode aS60ScanCode, Qt::Key aQtKey) : s60KeyCode(aS60KeyCode), s60ScanCode(aS60ScanCode), qtKey(aQtKey) { }; - TKeyCode s60KeyCode; - TStdScanCode s60ScanCode; - Qt::Key qtKey; -}; #endif struct KeyboardLayoutItem; @@ -216,9 +207,6 @@ public: KeyboardLayoutItem *keyLayout[256]; #elif defined(Q_WS_QWS) #elif defined(Q_OS_SYMBIAN) -private: - QList<KeyMapping> keyMapping; - void fillKeyMap(); public: QString translateKeyEvent(int keySym, Qt::KeyboardModifiers modifiers); int mapS60KeyToQt(TUint s60key); diff --git a/src/gui/kernel/qkeymapper_s60.cpp b/src/gui/kernel/qkeymapper_s60.cpp index 039be14..fd263ef 100644 --- a/src/gui/kernel/qkeymapper_s60.cpp +++ b/src/gui/kernel/qkeymapper_s60.cpp @@ -46,7 +46,6 @@ QT_BEGIN_NAMESPACE QKeyMapperPrivate::QKeyMapperPrivate() { - fillKeyMap(); } QKeyMapperPrivate::~QKeyMapperPrivate() @@ -74,137 +73,145 @@ QString QKeyMapperPrivate::translateKeyEvent(int keySym, Qt::KeyboardModifiers / return QString(QChar(keySym)); } -void QKeyMapperPrivate::fillKeyMap() -{ - using namespace Qt; - keyMapping.append(KeyMapping(EKeyBackspace, EStdKeyBackspace, Key_Backspace)); - keyMapping.append(KeyMapping(EKeyTab, EStdKeyTab, Key_Tab)); - keyMapping.append(KeyMapping(EKeyEnter, EStdKeyEnter, Key_Enter)); - keyMapping.append(KeyMapping(EKeyEscape, EStdKeyEscape, Key_Escape)); - keyMapping.append(KeyMapping(EKeySpace, EStdKeySpace, Key_Space)); - keyMapping.append(KeyMapping(EKeyDelete, EStdKeyDelete, Key_Delete)); - keyMapping.append(KeyMapping(EKeyPrintScreen, EStdKeyPrintScreen, Key_SysReq)); - keyMapping.append(KeyMapping(EKeyPause, EStdKeyPause, Key_Pause)); - keyMapping.append(KeyMapping(EKeyHome, EStdKeyHome, Key_Home)); - keyMapping.append(KeyMapping(EKeyEnd, EStdKeyEnd, Key_End)); - keyMapping.append(KeyMapping(EKeyPageUp, EStdKeyPageUp, Key_PageUp)); - keyMapping.append(KeyMapping(EKeyPageDown, EStdKeyPageDown, Key_PageDown)); - keyMapping.append(KeyMapping(EKeyInsert, EStdKeyInsert, Key_Insert)); - keyMapping.append(KeyMapping(EKeyLeftArrow, EStdKeyLeftArrow, Key_Left)); - keyMapping.append(KeyMapping(EKeyRightArrow, EStdKeyRightArrow, Key_Right)); - keyMapping.append(KeyMapping(EKeyUpArrow, EStdKeyUpArrow, Key_Up)); - keyMapping.append(KeyMapping(EKeyDownArrow, EStdKeyDownArrow, Key_Down)); - keyMapping.append(KeyMapping(EKeyLeftShift, EStdKeyLeftShift, Key_Shift)); - keyMapping.append(KeyMapping(EKeyRightShift, EStdKeyRightShift, Key_Shift)); - keyMapping.append(KeyMapping(EKeyLeftAlt, EStdKeyLeftAlt, Key_Alt)); - keyMapping.append(KeyMapping(EKeyRightAlt, EStdKeyRightAlt, Key_AltGr)); - keyMapping.append(KeyMapping(EKeyLeftCtrl, EStdKeyLeftCtrl, Key_Control)); - keyMapping.append(KeyMapping(EKeyRightCtrl, EStdKeyRightCtrl, Key_Control)); - keyMapping.append(KeyMapping(EKeyLeftFunc, EStdKeyLeftFunc, Key_Super_L)); - keyMapping.append(KeyMapping(EKeyRightFunc, EStdKeyRightFunc, Key_Super_R)); - keyMapping.append(KeyMapping(EKeyCapsLock, EStdKeyCapsLock, Key_CapsLock)); - keyMapping.append(KeyMapping(EKeyNumLock, EStdKeyNumLock, Key_NumLock)); - keyMapping.append(KeyMapping(EKeyScrollLock, EStdKeyScrollLock, Key_ScrollLock)); - keyMapping.append(KeyMapping(EKeyF1, EStdKeyF1, Key_F1)); - keyMapping.append(KeyMapping(EKeyF2, EStdKeyF2, Key_F2)); - keyMapping.append(KeyMapping(EKeyF3, EStdKeyF3, Key_F3)); - keyMapping.append(KeyMapping(EKeyF4, EStdKeyF4, Key_F4)); - keyMapping.append(KeyMapping(EKeyF5, EStdKeyF5, Key_F5)); - keyMapping.append(KeyMapping(EKeyF6, EStdKeyF6, Key_F6)); - keyMapping.append(KeyMapping(EKeyF7, EStdKeyF7, Key_F7)); - keyMapping.append(KeyMapping(EKeyF8, EStdKeyF8, Key_F8)); - keyMapping.append(KeyMapping(EKeyF9, EStdKeyF9, Key_F9)); - keyMapping.append(KeyMapping(EKeyF10, EStdKeyF10, Key_F10)); - keyMapping.append(KeyMapping(EKeyF11, EStdKeyF11, Key_F11)); - keyMapping.append(KeyMapping(EKeyF12, EStdKeyF12, Key_F12)); - keyMapping.append(KeyMapping(EKeyF13, EStdKeyF13, Key_F13)); - keyMapping.append(KeyMapping(EKeyF14, EStdKeyF14, Key_F14)); - keyMapping.append(KeyMapping(EKeyF15, EStdKeyF15, Key_F15)); - keyMapping.append(KeyMapping(EKeyF16, EStdKeyF16, Key_F16)); - keyMapping.append(KeyMapping(EKeyF17, EStdKeyF17, Key_F17)); - keyMapping.append(KeyMapping(EKeyF18, EStdKeyF18, Key_F18)); - keyMapping.append(KeyMapping(EKeyF19, EStdKeyF19, Key_F19)); - keyMapping.append(KeyMapping(EKeyF20, EStdKeyF20, Key_F20)); - keyMapping.append(KeyMapping(EKeyF21, EStdKeyF21, Key_F21)); - keyMapping.append(KeyMapping(EKeyF22, EStdKeyF22, Key_F22)); - keyMapping.append(KeyMapping(EKeyF23, EStdKeyF23, Key_F23)); - keyMapping.append(KeyMapping(EKeyF24, EStdKeyF24, Key_F24)); - keyMapping.append(KeyMapping(EKeyOff, EStdKeyOff, Key_PowerOff)); -// keyMapping.append(KeyMapping(EKeyMenu, EStdKeyMenu, Key_Menu)); // Menu is EKeyApplication0 - keyMapping.append(KeyMapping(EKeyHelp, EStdKeyHelp, Key_Help)); - keyMapping.append(KeyMapping(EKeyDial, EStdKeyDial, Key_Call)); - keyMapping.append(KeyMapping(EKeyIncVolume, EStdKeyIncVolume, Key_VolumeUp)); - keyMapping.append(KeyMapping(EKeyDecVolume, EStdKeyDecVolume, Key_VolumeDown)); - keyMapping.append(KeyMapping(EKeyDevice0, EStdKeyDevice0, Key_Context1)); // Found by manual testing. - keyMapping.append(KeyMapping(EKeyDevice1, EStdKeyDevice1, Key_Context2)); // Found by manual testing. - keyMapping.append(KeyMapping(EKeyDevice3, EStdKeyDevice3, Key_Select)); -// keyMapping.append(KeyMapping(EKeyDevice7, EStdKeyDevice7, Key_Camera)); //not supported by qt yet - keyMapping.append(KeyMapping(EKeyApplication0, EStdKeyApplication0, Key_Menu)); // Found by manual testing. - keyMapping.append(KeyMapping(EKeyApplication1, EStdKeyApplication1, Key_Launch1)); // Found by manual testing. - keyMapping.append(KeyMapping(EKeyApplication2, EStdKeyApplication2, Key_MediaPlay)); // Found by manual testing. - keyMapping.append(KeyMapping(EKeyApplication3, EStdKeyApplication3, Key_MediaStop)); // Found by manual testing. - keyMapping.append(KeyMapping(EKeyApplication4, EStdKeyApplication4, Key_MediaNext)); // Found by manual testing. - keyMapping.append(KeyMapping(EKeyApplication5, EStdKeyApplication5, Key_MediaPrevious)); // Found by manual testing. - keyMapping.append(KeyMapping(EKeyApplication6, EStdKeyApplication6, Key_Launch6)); - keyMapping.append(KeyMapping(EKeyApplication7, EStdKeyApplication7, Key_Launch7)); - keyMapping.append(KeyMapping(EKeyApplication8, EStdKeyApplication8, Key_Launch8)); - keyMapping.append(KeyMapping(EKeyApplication9, EStdKeyApplication9, Key_Launch9)); - keyMapping.append(KeyMapping(EKeyApplicationA, EStdKeyApplicationA, Key_LaunchA)); - keyMapping.append(KeyMapping(EKeyApplicationB, EStdKeyApplicationB, Key_LaunchB)); - keyMapping.append(KeyMapping(EKeyApplicationC, EStdKeyApplicationC, Key_LaunchC)); - keyMapping.append(KeyMapping(EKeyApplicationD, EStdKeyApplicationD, Key_LaunchD)); - keyMapping.append(KeyMapping(EKeyApplicationE, EStdKeyApplicationE, Key_LaunchE)); - keyMapping.append(KeyMapping(EKeyApplicationF, EStdKeyApplicationF, Key_LaunchF)); -// keyMapping.append(KeyMapping(EKeyApplication19, EStdKeyApplication19, Key_CameraFocus)); //not supported by qt yet - keyMapping.append(KeyMapping(EKeyYes, EStdKeyYes, Key_Yes)); - keyMapping.append(KeyMapping(EKeyNo, EStdKeyNo, Key_No)); -} +#include <e32keys.h> +struct KeyMapping{ + TKeyCode s60KeyCode; + TStdScanCode s60ScanCode; + Qt::Key qtKey; +}; + +using namespace Qt; + +static const KeyMapping keyMapping[] = { + {EKeyBackspace, EStdKeyBackspace, Key_Backspace}, + {EKeyTab, EStdKeyTab, Key_Tab}, + {EKeyEnter, EStdKeyEnter, Key_Enter}, + {EKeyEscape, EStdKeyEscape, Key_Escape}, + {EKeySpace, EStdKeySpace, Key_Space}, + {EKeyDelete, EStdKeyDelete, Key_Delete}, + {EKeyPrintScreen, EStdKeyPrintScreen, Key_SysReq}, + {EKeyPause, EStdKeyPause, Key_Pause}, + {EKeyHome, EStdKeyHome, Key_Home}, + {EKeyEnd, EStdKeyEnd, Key_End}, + {EKeyPageUp, EStdKeyPageUp, Key_PageUp}, + {EKeyPageDown, EStdKeyPageDown, Key_PageDown}, + {EKeyInsert, EStdKeyInsert, Key_Insert}, + {EKeyLeftArrow, EStdKeyLeftArrow, Key_Left}, + {EKeyRightArrow, EStdKeyRightArrow, Key_Right}, + {EKeyUpArrow, EStdKeyUpArrow, Key_Up}, + {EKeyDownArrow, EStdKeyDownArrow, Key_Down}, + {EKeyLeftShift, EStdKeyLeftShift, Key_Shift}, + {EKeyRightShift, EStdKeyRightShift, Key_Shift}, + {EKeyLeftAlt, EStdKeyLeftAlt, Key_Alt}, + {EKeyRightAlt, EStdKeyRightAlt, Key_AltGr}, + {EKeyLeftCtrl, EStdKeyLeftCtrl, Key_Control}, + {EKeyRightCtrl, EStdKeyRightCtrl, Key_Control}, + {EKeyLeftFunc, EStdKeyLeftFunc, Key_Super_L}, + {EKeyRightFunc, EStdKeyRightFunc, Key_Super_R}, + {EKeyCapsLock, EStdKeyCapsLock, Key_CapsLock}, + {EKeyNumLock, EStdKeyNumLock, Key_NumLock}, + {EKeyScrollLock, EStdKeyScrollLock, Key_ScrollLock}, + {EKeyF1, EStdKeyF1, Key_F1}, + {EKeyF2, EStdKeyF2, Key_F2}, + {EKeyF3, EStdKeyF3, Key_F3}, + {EKeyF4, EStdKeyF4, Key_F4}, + {EKeyF5, EStdKeyF5, Key_F5}, + {EKeyF6, EStdKeyF6, Key_F6}, + {EKeyF7, EStdKeyF7, Key_F7}, + {EKeyF8, EStdKeyF8, Key_F8}, + {EKeyF9, EStdKeyF9, Key_F9}, + {EKeyF10, EStdKeyF10, Key_F10}, + {EKeyF11, EStdKeyF11, Key_F11}, + {EKeyF12, EStdKeyF12, Key_F12}, + {EKeyF13, EStdKeyF13, Key_F13}, + {EKeyF14, EStdKeyF14, Key_F14}, + {EKeyF15, EStdKeyF15, Key_F15}, + {EKeyF16, EStdKeyF16, Key_F16}, + {EKeyF17, EStdKeyF17, Key_F17}, + {EKeyF18, EStdKeyF18, Key_F18}, + {EKeyF19, EStdKeyF19, Key_F19}, + {EKeyF20, EStdKeyF20, Key_F20}, + {EKeyF21, EStdKeyF21, Key_F21}, + {EKeyF22, EStdKeyF22, Key_F22}, + {EKeyF23, EStdKeyF23, Key_F23}, + {EKeyF24, EStdKeyF24, Key_F24}, + {EKeyOff, EStdKeyOff, Key_PowerOff}, +// {EKeyMenu, EStdKeyMenu, Key_Menu}, // Menu is EKeyApplication0 + {EKeyHelp, EStdKeyHelp, Key_Help}, + {EKeyDial, EStdKeyDial, Key_Call}, + {EKeyIncVolume, EStdKeyIncVolume, Key_VolumeUp}, + {EKeyDecVolume, EStdKeyDecVolume, Key_VolumeDown}, + {EKeyDevice0, EStdKeyDevice0, Key_Context1}, // Found by manual testing. + {EKeyDevice1, EStdKeyDevice1, Key_Context2}, // Found by manual testing. + {EKeyDevice3, EStdKeyDevice3, Key_Select}, +// {EKeyDevice7, EStdKeyDevice7, Key_Camera}, //not supported by qt yet + {EKeyApplication0, EStdKeyApplication0, Key_Menu}, // Found by manual testing. + {EKeyApplication1, EStdKeyApplication1, Key_Launch1}, // Found by manual testing. + {EKeyApplication2, EStdKeyApplication2, Key_MediaPlay}, // Found by manual testing. + {EKeyApplication3, EStdKeyApplication3, Key_MediaStop}, // Found by manual testing. + {EKeyApplication4, EStdKeyApplication4, Key_MediaNext}, // Found by manual testing. + {EKeyApplication5, EStdKeyApplication5, Key_MediaPrevious}, // Found by manual testing. + {EKeyApplication6, EStdKeyApplication6, Key_Launch6}, + {EKeyApplication7, EStdKeyApplication7, Key_Launch7}, + {EKeyApplication8, EStdKeyApplication8, Key_Launch8}, + {EKeyApplication9, EStdKeyApplication9, Key_Launch9}, + {EKeyApplicationA, EStdKeyApplicationA, Key_LaunchA}, + {EKeyApplicationB, EStdKeyApplicationB, Key_LaunchB}, + {EKeyApplicationC, EStdKeyApplicationC, Key_LaunchC}, + {EKeyApplicationD, EStdKeyApplicationD, Key_LaunchD}, + {EKeyApplicationE, EStdKeyApplicationE, Key_LaunchE}, + {EKeyApplicationF, EStdKeyApplicationF, Key_LaunchF}, +// {EKeyApplication19, EStdKeyApplication19, Key_CameraFocus}, //not supported by qt yet + {EKeyYes, EStdKeyYes, Key_Yes}, + {EKeyNo, EStdKeyNo, Key_No}, + {TKeyCode(0), TStdScanCode(0), Qt::Key(0)} +}; int QKeyMapperPrivate::mapS60KeyToQt(TUint s60key) { - int res = Qt::Key_unknown; - for ( int i = 0, size = keyMapping.count(); i<size; i++){ - if ( keyMapping[i].s60KeyCode == s60key){ - res = keyMapping[i].qtKey; - break; - } - } - return res; + int res = Qt::Key_unknown; + for (int i = 0; keyMapping[i].s60KeyCode != 0; i++) { + if (keyMapping[i].s60KeyCode == s60key) { + res = keyMapping[i].qtKey; + break; + } + } + return res; } int QKeyMapperPrivate::mapS60ScanCodesToQt(TUint s60scanCode) { - int res = Qt::Key_unknown; - for ( int i = 0, size = keyMapping.count(); i<size; i++){ - if ( keyMapping[i].s60ScanCode == s60scanCode){ - res = keyMapping[i].qtKey; - break; - } - } - return res; + int res = Qt::Key_unknown; + for (int i = 0; keyMapping[i].s60KeyCode != 0; i++) { + if (keyMapping[i].s60ScanCode == s60scanCode) { + res = keyMapping[i].qtKey; + break; + } + } + return res; } int QKeyMapperPrivate::mapQtToS60Key(int qtKey) { int res = KErrUnknown; - for ( int i = 0, size = keyMapping.count(); i<size; i++){ - if ( keyMapping[i].qtKey == qtKey){ - res = keyMapping[i].s60KeyCode; - break; - } - } - return res; + for (int i = 0; keyMapping[i].s60KeyCode != 0; i++) { + if (keyMapping[i].qtKey == qtKey) { + res = keyMapping[i].s60KeyCode; + break; + } + } + return res; } int QKeyMapperPrivate::mapQtToS60ScanCodes(int qtKey) { - int res = KErrUnknown; - for ( int i = 0, size = keyMapping.count(); i<size; i++){ - if ( keyMapping[i].qtKey == qtKey){ - res = keyMapping[i].s60ScanCode; - break; - } - } - return res; + int res = KErrUnknown; + for (int i = 0; keyMapping[i].s60KeyCode != 0; i++) { + if (keyMapping[i].qtKey == qtKey) { + res = keyMapping[i].s60ScanCode; + break; + } + } + return res; } QT_END_NAMESPACE |