qtmobileextensions/src/keycapture/keymapper.cpp
branchRCL_3
changeset 23 cd2778e5acfe
parent 22 5d007b20cfd0
child 25 19a54be74e5e
equal deleted inserted replaced
22:5d007b20cfd0 23:cd2778e5acfe
     1 /*
       
     2  * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3  * All rights reserved.
       
     4  *
       
     5  * This program is free software: you can redistribute it and/or modify
       
     6  * it under the terms of the GNU Lesser General Public License as published by
       
     7  * the Free Software Foundation, version 2.1 of the License.
       
     8  * 
       
     9  * This program is distributed in the hope that it will be useful,
       
    10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
       
    11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
       
    12  * GNU Lesser General Public License for more details.
       
    13  *
       
    14  * You should have received a copy of the GNU Lesser General Public License
       
    15  * along with this program.  If not, 
       
    16  * see "http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html/".
       
    17  *
       
    18  * Description:
       
    19  *
       
    20  */
       
    21 
       
    22 //
       
    23 // TODO: this file is only tempral while we wait for Qt patch approval and include
       
    24 // 
       
    25  
       
    26 #include "keymapper.h"
       
    27 #include <e32keys.h>
       
    28 using namespace Qt;
       
    29 
       
    30 static const KeyMapping keyMapping[] = {
       
    31     {EKeyBackspace, EStdKeyBackspace, Key_Backspace},
       
    32     {EKeyTab, EStdKeyTab, Key_Tab},
       
    33     {EKeyEnter, EStdKeyEnter, Key_Enter},
       
    34     {EKeyEscape, EStdKeyEscape, Key_Escape},
       
    35     {EKeySpace, EStdKeySpace, Key_Space},
       
    36     {EKeyDelete, EStdKeyDelete, Key_Delete},
       
    37     {EKeyPrintScreen, EStdKeyPrintScreen, Key_SysReq},
       
    38     {EKeyPause, EStdKeyPause, Key_Pause},
       
    39     {EKeyHome, EStdKeyHome, Key_Home},
       
    40     {EKeyEnd, EStdKeyEnd, Key_End},
       
    41     {EKeyPageUp, EStdKeyPageUp, Key_PageUp},
       
    42     {EKeyPageDown, EStdKeyPageDown, Key_PageDown},
       
    43     {EKeyInsert, EStdKeyInsert, Key_Insert},
       
    44     {EKeyLeftArrow, EStdKeyLeftArrow, Key_Left},
       
    45     {EKeyRightArrow, EStdKeyRightArrow, Key_Right},
       
    46     {EKeyUpArrow, EStdKeyUpArrow, Key_Up},
       
    47     {EKeyDownArrow, EStdKeyDownArrow, Key_Down},
       
    48     {EKeyLeftShift, EStdKeyLeftShift, Key_Shift},
       
    49     {EKeyRightShift, EStdKeyRightShift, Key_Shift},
       
    50     {EKeyLeftAlt, EStdKeyLeftAlt, Key_Alt},
       
    51     {EKeyRightAlt, EStdKeyRightAlt, Key_AltGr},
       
    52     {EKeyLeftCtrl, EStdKeyLeftCtrl, Key_Control},
       
    53     {EKeyRightCtrl, EStdKeyRightCtrl, Key_Control},
       
    54     {EKeyLeftFunc, EStdKeyLeftFunc, Key_Super_L},
       
    55     {EKeyRightFunc, EStdKeyRightFunc, Key_Super_R},
       
    56     {EKeyCapsLock, EStdKeyCapsLock, Key_CapsLock},
       
    57     {EKeyNumLock, EStdKeyNumLock, Key_NumLock},
       
    58     {EKeyScrollLock, EStdKeyScrollLock, Key_ScrollLock},
       
    59     {EKeyF1, EStdKeyF1, Key_F1},
       
    60     {EKeyF2, EStdKeyF2, Key_F2},
       
    61     {EKeyF3, EStdKeyF3, Key_F3},
       
    62     {EKeyF4, EStdKeyF4, Key_F4},
       
    63     {EKeyF5, EStdKeyF5, Key_F5},
       
    64     {EKeyF6, EStdKeyF6, Key_F6},
       
    65     {EKeyF7, EStdKeyF7, Key_F7},
       
    66     {EKeyF8, EStdKeyF8, Key_F8},
       
    67     {EKeyF9, EStdKeyF9, Key_F9},
       
    68     {EKeyF10, EStdKeyF10, Key_F10},
       
    69     {EKeyF11, EStdKeyF11, Key_F11},
       
    70     {EKeyF12, EStdKeyF12, Key_F12},
       
    71     {EKeyF13, EStdKeyF13, Key_F13},
       
    72     {EKeyF14, EStdKeyF14, Key_F14},
       
    73     {EKeyF15, EStdKeyF15, Key_F15},
       
    74     {EKeyF16, EStdKeyF16, Key_F16},
       
    75     {EKeyF17, EStdKeyF17, Key_F17},
       
    76     {EKeyF18, EStdKeyF18, Key_F18},
       
    77     {EKeyF19, EStdKeyF19, Key_F19},
       
    78     {EKeyF20, EStdKeyF20, Key_F20},
       
    79     {EKeyF21, EStdKeyF21, Key_F21},
       
    80     {EKeyF22, EStdKeyF22, Key_F22},
       
    81     {EKeyF23, EStdKeyF23, Key_F23},
       
    82     {EKeyF24, EStdKeyF24, Key_F24},
       
    83     {EKeyOff, EStdKeyOff, Key_PowerOff},
       
    84 //    {EKeyMenu, EStdKeyMenu, Key_Menu}, // Menu is EKeyApplication0
       
    85     {EKeyHelp, EStdKeyHelp, Key_Help},
       
    86     {EKeyDial, EStdKeyDial, Key_Call},
       
    87     {EKeyIncVolume, EStdKeyIncVolume, Key_VolumeUp},
       
    88     {EKeyDecVolume, EStdKeyDecVolume, Key_VolumeDown},
       
    89     {EKeyDevice0, EStdKeyDevice0, Key_Context1}, // Found by manual testing.
       
    90     {EKeyDevice1, EStdKeyDevice1, Key_Context2}, // Found by manual testing.
       
    91     {EKeyDevice3, EStdKeyDevice3, Key_Select},
       
    92     {EKeyDevice7, EStdKeyDevice7, Key_Camera},  
       
    93     {EKeyApplication0, EStdKeyApplication0, Key_Menu}, // Found by manual testing.
       
    94     {EKeyApplication1, EStdKeyApplication1, Key_Launch1}, // Found by manual testing.
       
    95     {EKeyApplication2, EStdKeyApplication2, Key_MediaPlay}, // Found by manual testing.
       
    96     {EKeyApplication3, EStdKeyApplication3, Key_MediaStop}, // Found by manual testing.
       
    97     {EKeyApplication4, EStdKeyApplication4, Key_MediaNext}, // Found by manual testing.
       
    98     {EKeyApplication5, EStdKeyApplication5, Key_MediaPrevious}, // Found by manual testing.
       
    99     {EKeyApplication6, EStdKeyApplication6, Key_Launch6},
       
   100     {EKeyApplication7, EStdKeyApplication7, Key_Launch7},
       
   101     {EKeyApplication8, EStdKeyApplication8, Key_Launch8},
       
   102     {EKeyApplication9, EStdKeyApplication9, Key_Launch9},
       
   103     {EKeyApplicationA, EStdKeyApplicationA, Key_LaunchA},
       
   104     {EKeyApplicationB, EStdKeyApplicationB, Key_LaunchB},
       
   105     {EKeyApplicationC, EStdKeyApplicationC, Key_LaunchC},
       
   106     {EKeyApplicationD, EStdKeyApplicationD, Key_LaunchD},
       
   107     {EKeyApplicationE, EStdKeyApplicationE, Key_LaunchE},
       
   108     {EKeyApplicationF, EStdKeyApplicationF, Key_LaunchF},
       
   109     {EKeyApplication19, EStdKeyApplication19, Key_CameraFocus}, 
       
   110     {EKeyYes, EStdKeyYes, Key_Yes},
       
   111     {EKeyNo, EStdKeyNo, Key_No},
       
   112     {TKeyCode(0), TStdScanCode(0), Qt::Key(0)}
       
   113 };
       
   114 
       
   115 QKeyMapper::QKeyMapper()
       
   116 {
       
   117    // fillKeyMap();
       
   118 }
       
   119 
       
   120 QKeyMapper::~QKeyMapper()
       
   121 {
       
   122 }
       
   123 
       
   124 int QKeyMapper::mapS60KeyToQt(TUint s60key)
       
   125 {
       
   126     int res = Qt::Key_unknown;
       
   127     for (int i = 0; keyMapping[i].s60KeyCode != 0; i++) {
       
   128         if (keyMapping[i].s60KeyCode == s60key) {
       
   129             res = keyMapping[i].qtKey;
       
   130             break;
       
   131         }
       
   132     }
       
   133     return res;
       
   134 }
       
   135 
       
   136 int QKeyMapper::mapS60ScanCodesToQt(TUint s60scanCode)
       
   137 {
       
   138     int res = Qt::Key_unknown;
       
   139     for (int i = 0; keyMapping[i].s60KeyCode != 0; i++) {
       
   140         if (keyMapping[i].s60ScanCode == s60scanCode) {
       
   141             res = keyMapping[i].qtKey;
       
   142             break;
       
   143         }
       
   144     }
       
   145     return res;
       
   146 }
       
   147 
       
   148 int QKeyMapper::mapQtToS60Key(int qtKey)
       
   149 {
       
   150     int res = KErrUnknown;
       
   151     for (int i = 0; keyMapping[i].s60KeyCode != 0; i++) {
       
   152         if (keyMapping[i].qtKey == qtKey) {
       
   153             res = keyMapping[i].s60KeyCode;
       
   154             break;
       
   155         }
       
   156     }
       
   157     return res;
       
   158 }
       
   159 
       
   160 int QKeyMapper::mapQtToS60ScanCodes(int qtKey)
       
   161 {
       
   162     int res = KErrUnknown;
       
   163     for (int i = 0; keyMapping[i].s60KeyCode != 0; i++) {
       
   164         if (keyMapping[i].qtKey == qtKey) {
       
   165             res = keyMapping[i].s60ScanCode;
       
   166             break;
       
   167         }
       
   168     }
       
   169     return res;
       
   170 }