src/hbplugins/inputmethods/hardwareinput/hbhardwareinputbasic12keyhandler.cpp
author hgs
Mon, 18 Oct 2010 18:23:13 +0300
changeset 34 ed14f46c0e55
parent 1 f7ac710697a9
permissions -rw-r--r--
201041
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
16d8024aca5e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
     1
/****************************************************************************
16d8024aca5e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
     2
**
16d8024aca5e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
     3
** Copyright (C) 2008-2010 Nokia Corporation and/or its subsidiary(-ies).
16d8024aca5e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
     4
** All rights reserved.
16d8024aca5e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
     5
** Contact: Nokia Corporation (developer.feedback@nokia.com)
16d8024aca5e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
     6
**
16d8024aca5e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
     7
** This file is part of the HbPlugins module of the UI Extensions for Mobile.
16d8024aca5e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
     8
**
16d8024aca5e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
     9
** GNU Lesser General Public License Usage
16d8024aca5e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    10
** This file may be used under the terms of the GNU Lesser General Public
16d8024aca5e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    11
** License version 2.1 as published by the Free Software Foundation and
16d8024aca5e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    12
** appearing in the file LICENSE.LGPL included in the packaging of this file.
16d8024aca5e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    13
** Please review the following information to ensure the GNU Lesser General
16d8024aca5e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    14
** Public License version 2.1 requirements will be met:
16d8024aca5e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    15
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
16d8024aca5e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    16
**
16d8024aca5e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    17
** In addition, as a special exception, Nokia gives you certain additional
16d8024aca5e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    18
** rights.  These rights are described in the Nokia Qt LGPL Exception
16d8024aca5e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    19
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
16d8024aca5e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    20
**
16d8024aca5e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    21
** If you have questions regarding the use of this file, please contact
16d8024aca5e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    22
** Nokia at developer.feedback@nokia.com.
16d8024aca5e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    23
**
16d8024aca5e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    24
****************************************************************************/
16d8024aca5e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    25
16d8024aca5e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    26
#include <QTimer>
16d8024aca5e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    27
#include <hbinputkeymapfactory.h>
16d8024aca5e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    28
#include <hbinputpredictionengine.h>
16d8024aca5e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    29
#include <HbInputSettingProxy.h>
16d8024aca5e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    30
16d8024aca5e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    31
#include "hbhardwareinputbasic12keyhandler.h"
16d8024aca5e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    32
#include "hbinputbasichandler_p.h"
16d8024aca5e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    33
#include "hbinputabstractbase.h"
16d8024aca5e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    34
#include "hbhardware12key.h"
16d8024aca5e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    35
16d8024aca5e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    36
class HbHardwareInputBasic12KeyHandlerPrivate: public HbInputBasicHandlerPrivate
16d8024aca5e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    37
{
34
hgs
parents: 1
diff changeset
    38
    Q_DECLARE_PUBLIC(HbHardwareInputBasic12KeyHandler)
0
16d8024aca5e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    39
16d8024aca5e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    40
public:
34
hgs
parents: 1
diff changeset
    41
    HbHardwareInputBasic12KeyHandlerPrivate();
hgs
parents: 1
diff changeset
    42
    ~HbHardwareInputBasic12KeyHandlerPrivate();
0
16d8024aca5e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    43
34
hgs
parents: 1
diff changeset
    44
    void handleAlphaEvent(int buttonId);
hgs
parents: 1
diff changeset
    45
    bool keyPressed(const QKeyEvent *keyEvent);
hgs
parents: 1
diff changeset
    46
    bool keyReleased(const QKeyEvent *keyEvent);
hgs
parents: 1
diff changeset
    47
    bool actionHandler(HbInputModeHandler::HbInputModeAction action);
0
16d8024aca5e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    48
34
hgs
parents: 1
diff changeset
    49
    void _q_timeout();
0
16d8024aca5e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    50
public:
34
hgs
parents: 1
diff changeset
    51
    int mLastKey;
hgs
parents: 1
diff changeset
    52
    QChar mCurrentChar;
hgs
parents: 1
diff changeset
    53
    int mNumChr;
hgs
parents: 1
diff changeset
    54
    bool mButtonDown;
hgs
parents: 1
diff changeset
    55
    HbInputFocusObject *mCurrentlyFocused;
0
16d8024aca5e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    56
};
16d8024aca5e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    57
16d8024aca5e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    58
HbHardwareInputBasic12KeyHandlerPrivate::HbHardwareInputBasic12KeyHandlerPrivate()
16d8024aca5e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    59
:    mLastKey(0),
16d8024aca5e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    60
mCurrentChar(0),
16d8024aca5e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    61
mNumChr(0),
16d8024aca5e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    62
mButtonDown(false),
16d8024aca5e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    63
mCurrentlyFocused(0)
16d8024aca5e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    64
{
16d8024aca5e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    65
}
16d8024aca5e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    66
16d8024aca5e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    67
HbHardwareInputBasic12KeyHandlerPrivate::~HbHardwareInputBasic12KeyHandlerPrivate()
16d8024aca5e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    68
{
16d8024aca5e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    69
}
16d8024aca5e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    70
16d8024aca5e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    71
// handles the key press events. It starts a multitap timer as well.
16d8024aca5e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    72
void HbHardwareInputBasic12KeyHandlerPrivate::handleAlphaEvent(int buttonId)
16d8024aca5e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    73
{
34
hgs
parents: 1
diff changeset
    74
    Q_Q(HbHardwareInputBasic12KeyHandler);
hgs
parents: 1
diff changeset
    75
    HbInputFocusObject *focusObject = 0;
hgs
parents: 1
diff changeset
    76
    focusObject = mInputMethod->focusObject();
hgs
parents: 1
diff changeset
    77
    if (!focusObject) {
hgs
parents: 1
diff changeset
    78
        return;
hgs
parents: 1
diff changeset
    79
    }
0
16d8024aca5e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    80
34
hgs
parents: 1
diff changeset
    81
    mCurrentChar = q->getNthCharacterInKey(mNumChr, buttonId);
0
16d8024aca5e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    82
34
hgs
parents: 1
diff changeset
    83
    if (mCurrentChar != 0) {
hgs
parents: 1
diff changeset
    84
        QString str;
hgs
parents: 1
diff changeset
    85
        str += mCurrentChar;
0
16d8024aca5e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    86
34
hgs
parents: 1
diff changeset
    87
        QList<QInputMethodEvent::Attribute> list;
hgs
parents: 1
diff changeset
    88
        QInputMethodEvent event(str, list);
hgs
parents: 1
diff changeset
    89
        focusObject->sendEvent(event);
hgs
parents: 1
diff changeset
    90
        mTimer->start(HbMultiTapTimerTimeout);
hgs
parents: 1
diff changeset
    91
    }
0
16d8024aca5e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    92
}
16d8024aca5e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    93
16d8024aca5e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    94
bool HbHardwareInputBasic12KeyHandlerPrivate::keyPressed(const QKeyEvent *keyEvent)
16d8024aca5e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    95
{
34
hgs
parents: 1
diff changeset
    96
    Q_Q(HbHardwareInputBasic12KeyHandler);
hgs
parents: 1
diff changeset
    97
    HbInputFocusObject *focusObject = 0;
hgs
parents: 1
diff changeset
    98
    focusObject = mInputMethod->focusObject();
hgs
parents: 1
diff changeset
    99
    if (!focusObject) {
hgs
parents: 1
diff changeset
   100
        return false;
hgs
parents: 1
diff changeset
   101
    }
0
16d8024aca5e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   102
34
hgs
parents: 1
diff changeset
   103
    int buttonId = keyEvent->key();
hgs
parents: 1
diff changeset
   104
    
0
16d8024aca5e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   105
34
hgs
parents: 1
diff changeset
   106
    if( mLastKey != buttonId) {
hgs
parents: 1
diff changeset
   107
        mLastKey = buttonId;
hgs
parents: 1
diff changeset
   108
        if(mTimer->isActive()) {
hgs
parents: 1
diff changeset
   109
            mTimer->stop();
hgs
parents: 1
diff changeset
   110
            mNumChr = 0;
hgs
parents: 1
diff changeset
   111
            if (isEnterCharacter(mCurrentChar)) {
hgs
parents: 1
diff changeset
   112
                focusObject->sendPreEditString(QString("")); // Make sure the enter character is cleared.
hgs
parents: 1
diff changeset
   113
                mCurrentChar = QChar('\n');                  // Convert enter character to line feed.
hgs
parents: 1
diff changeset
   114
            }
0
16d8024aca5e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   115
34
hgs
parents: 1
diff changeset
   116
            if(mCurrentChar != 0) {
hgs
parents: 1
diff changeset
   117
                focusObject->filterAndCommitCharacter(mCurrentChar);
hgs
parents: 1
diff changeset
   118
            }           
hgs
parents: 1
diff changeset
   119
            // For QLineEdit it works fine. For HbLineEdit, need to set the state 
hgs
parents: 1
diff changeset
   120
            // to lower by calling activateState().
hgs
parents: 1
diff changeset
   121
            // This is needed for the scenario - When automatic text case is true
hgs
parents: 1
diff changeset
   122
            // click a button and before the multitap timer expires click on
hgs
parents: 1
diff changeset
   123
            // another button.
hgs
parents: 1
diff changeset
   124
            mInputMethod->updateState();
0
16d8024aca5e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   125
16d8024aca5e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   126
        refreshAutoCompleter();
34
hgs
parents: 1
diff changeset
   127
        }
hgs
parents: 1
diff changeset
   128
    }
0
16d8024aca5e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   129
34
hgs
parents: 1
diff changeset
   130
    if (buttonId == Qt::Key_Return) {
hgs
parents: 1
diff changeset
   131
        mLastKey = buttonId;
hgs
parents: 1
diff changeset
   132
        return true;
hgs
parents: 1
diff changeset
   133
    } else if (buttonId == Qt::Key_Shift) {
hgs
parents: 1
diff changeset
   134
        // For single key press, change the text input case. If the second shift key press is 
hgs
parents: 1
diff changeset
   135
        // received within long key press time out interval, then activate the next state
hgs
parents: 1
diff changeset
   136
        if (mTimer->isActive() && (mLastKey == buttonId)){
hgs
parents: 1
diff changeset
   137
            mTimer->stop();
0
16d8024aca5e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   138
             HbInputState rootState;
16d8024aca5e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   139
             mInputMethod->editorRootState(rootState);
16d8024aca5e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   140
             mInputMethod->activateState(rootState);            
34
hgs
parents: 1
diff changeset
   141
        } else {
hgs
parents: 1
diff changeset
   142
            updateTextCase();
hgs
parents: 1
diff changeset
   143
            mTimer->start(HbLongPressTimerTimeout);
hgs
parents: 1
diff changeset
   144
        }
hgs
parents: 1
diff changeset
   145
        mCurrentChar = 0;
hgs
parents: 1
diff changeset
   146
        mButtonDown = true;
hgs
parents: 1
diff changeset
   147
        mCurrentChar = 0;
hgs
parents: 1
diff changeset
   148
        return true;
hgs
parents: 1
diff changeset
   149
    }
hgs
parents: 1
diff changeset
   150
    // Let's see if we can get the handler for this button in the base class.
hgs
parents: 1
diff changeset
   151
    if (q->HbInputBasicHandler::filterEvent(keyEvent)) {
hgs
parents: 1
diff changeset
   152
        return true;
hgs
parents: 1
diff changeset
   153
    }
0
16d8024aca5e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   154
34
hgs
parents: 1
diff changeset
   155
    mLastKey = buttonId;
hgs
parents: 1
diff changeset
   156
    mButtonDown = true;
0
16d8024aca5e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   157
34
hgs
parents: 1
diff changeset
   158
    handleAlphaEvent(buttonId);
hgs
parents: 1
diff changeset
   159
    return true;
0
16d8024aca5e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   160
}
16d8024aca5e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   161
16d8024aca5e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   162
/*!
16d8024aca5e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   163
Handles the key release events from the VKB. Launches the SCT with key release event of
16d8024aca5e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   164
asterisk.
16d8024aca5e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   165
*/
16d8024aca5e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   166
bool HbHardwareInputBasic12KeyHandlerPrivate::keyReleased(const QKeyEvent *keyEvent)
16d8024aca5e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   167
{
34
hgs
parents: 1
diff changeset
   168
    Q_Q(HbHardwareInputBasic12KeyHandler);
hgs
parents: 1
diff changeset
   169
    mButtonDown = false;
hgs
parents: 1
diff changeset
   170
    int buttonId = keyEvent->key();
0
16d8024aca5e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   171
34
hgs
parents: 1
diff changeset
   172
    if (buttonId == Qt::Key_Asterisk) {
hgs
parents: 1
diff changeset
   173
        //Same asterisk key is used for launching candidate list (long key press)
hgs
parents: 1
diff changeset
   174
        //and also for SCT. So, do not launch SCT if candidate list is already launched.            
hgs
parents: 1
diff changeset
   175
        mInputMethod->switchMode(buttonId);
hgs
parents: 1
diff changeset
   176
        return true;
hgs
parents: 1
diff changeset
   177
    } else if (buttonId == Qt::Key_Delete) {
hgs
parents: 1
diff changeset
   178
        QKeyEvent keyEvent(QEvent::KeyRelease, Qt::Key_Backspace, Qt::NoModifier);
hgs
parents: 1
diff changeset
   179
        q->sendAndUpdate(keyEvent);
hgs
parents: 1
diff changeset
   180
        return true;
hgs
parents: 1
diff changeset
   181
    }
0
16d8024aca5e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   182
34
hgs
parents: 1
diff changeset
   183
    return false;
0
16d8024aca5e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   184
}
16d8024aca5e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   185
16d8024aca5e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   186
16d8024aca5e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   187
void HbHardwareInputBasic12KeyHandlerPrivate::_q_timeout()
16d8024aca5e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   188
{
34
hgs
parents: 1
diff changeset
   189
    Q_Q(HbHardwareInputBasic12KeyHandler);
hgs
parents: 1
diff changeset
   190
    mTimer->stop();
hgs
parents: 1
diff changeset
   191
    mNumChr = 0;
0
16d8024aca5e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   192
34
hgs
parents: 1
diff changeset
   193
    HbInputFocusObject *focusedObject = 0;
hgs
parents: 1
diff changeset
   194
    focusedObject = mInputMethod->focusObject();
hgs
parents: 1
diff changeset
   195
    if (!focusedObject) {
hgs
parents: 1
diff changeset
   196
        qDebug("HbHardwareInputBasic12KeyHandler::timeout focusObject == 0");
hgs
parents: 1
diff changeset
   197
        return;
hgs
parents: 1
diff changeset
   198
    }
0
16d8024aca5e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   199
34
hgs
parents: 1
diff changeset
   200
    if (isEnterCharacter(mCurrentChar)) {
hgs
parents: 1
diff changeset
   201
        focusedObject->sendPreEditString(QString("")); // Make sure the enter character is cleared.
hgs
parents: 1
diff changeset
   202
        mCurrentChar = QChar('\n');                    // Convert enter character to line feed.
hgs
parents: 1
diff changeset
   203
    }
0
16d8024aca5e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   204
34
hgs
parents: 1
diff changeset
   205
    //Long key press number key is applicable to all keys
hgs
parents: 1
diff changeset
   206
    if (mButtonDown) {
hgs
parents: 1
diff changeset
   207
        //switch to numeric mode for long key press of Hash key 
hgs
parents: 1
diff changeset
   208
        if (mLastKey == Qt::Key_Shift){
hgs
parents: 1
diff changeset
   209
            updateTextCase();
hgs
parents: 1
diff changeset
   210
            mInputMethod->switchMode(Qt::Key_Shift);                
hgs
parents: 1
diff changeset
   211
        }else {     
hgs
parents: 1
diff changeset
   212
            q->commitFirstMappedNumber(mLastKey);
hgs
parents: 1
diff changeset
   213
        }         
hgs
parents: 1
diff changeset
   214
    } else if(mLastKey != Qt::Key_Shift){
hgs
parents: 1
diff changeset
   215
        if (!focusedObject->characterAllowedInEditor(mCurrentChar)) {
hgs
parents: 1
diff changeset
   216
            focusedObject->sendCommitString(QString());
hgs
parents: 1
diff changeset
   217
        } else {
hgs
parents: 1
diff changeset
   218
            if ( mCurrentChar != 0){
hgs
parents: 1
diff changeset
   219
                QString curString;
hgs
parents: 1
diff changeset
   220
                curString.append(mCurrentChar);
hgs
parents: 1
diff changeset
   221
                focusedObject->sendCommitString(curString);
hgs
parents: 1
diff changeset
   222
            }       
hgs
parents: 1
diff changeset
   223
            mInputMethod->updateState();
hgs
parents: 1
diff changeset
   224
            // pass this character to autocompleter.
0
16d8024aca5e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   225
            refreshAutoCompleter();
34
hgs
parents: 1
diff changeset
   226
        }
hgs
parents: 1
diff changeset
   227
    }
hgs
parents: 1
diff changeset
   228
    return; 
0
16d8024aca5e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   229
}
16d8024aca5e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   230
16d8024aca5e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   231
bool HbHardwareInputBasic12KeyHandlerPrivate::actionHandler(HbInputModeHandler::HbInputModeAction action)
16d8024aca5e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   232
{
34
hgs
parents: 1
diff changeset
   233
    HbInputFocusObject *focusObject = 0;
hgs
parents: 1
diff changeset
   234
    focusObject = mInputMethod->focusObject();
hgs
parents: 1
diff changeset
   235
    if (!focusObject) {
hgs
parents: 1
diff changeset
   236
        return false;
hgs
parents: 1
diff changeset
   237
    }
0
16d8024aca5e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   238
34
hgs
parents: 1
diff changeset
   239
    bool ret = true;
hgs
parents: 1
diff changeset
   240
    switch (action) {
0
16d8024aca5e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   241
case HbInputModeHandler::HbInputModeActionReset:
34
hgs
parents: 1
diff changeset
   242
    mLastKey = 0;
hgs
parents: 1
diff changeset
   243
    mNumChr = 0;
hgs
parents: 1
diff changeset
   244
    if (mTimer->isActive()) {
hgs
parents: 1
diff changeset
   245
        mTimer->stop();
hgs
parents: 1
diff changeset
   246
    }
hgs
parents: 1
diff changeset
   247
    break;
0
16d8024aca5e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   248
case HbInputModeHandler::HbInputModeActionDeleteAndCommit:{
34
hgs
parents: 1
diff changeset
   249
    mTimer->stop();
hgs
parents: 1
diff changeset
   250
    QString empty;
hgs
parents: 1
diff changeset
   251
    if(mInputMethod) {
hgs
parents: 1
diff changeset
   252
        //In case of the sct the character is already committed
hgs
parents: 1
diff changeset
   253
        //We need to remove the committed character.
hgs
parents: 1
diff changeset
   254
        QList<QInputMethodEvent::Attribute> list;
hgs
parents: 1
diff changeset
   255
        QInputMethodEvent event(QString(), list);
hgs
parents: 1
diff changeset
   256
        event.setCommitString(empty, -1, 1);
hgs
parents: 1
diff changeset
   257
        focusObject->sendEvent(event);
hgs
parents: 1
diff changeset
   258
    } else {
hgs
parents: 1
diff changeset
   259
        // Close event was originated from a button press, remove the uncommitted character.
hgs
parents: 1
diff changeset
   260
        focusObject->sendCommitString(empty);
hgs
parents: 1
diff changeset
   261
    }
hgs
parents: 1
diff changeset
   262
                                                          }
hgs
parents: 1
diff changeset
   263
                                                          break;
0
16d8024aca5e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   264
case HbInputModeHandler::HbInputModeActionFocusRecieved:
34
hgs
parents: 1
diff changeset
   265
    mTimer->stop();
hgs
parents: 1
diff changeset
   266
    mNumChr = 0;
hgs
parents: 1
diff changeset
   267
    if (mCurrentlyFocused != focusObject) {
hgs
parents: 1
diff changeset
   268
        mCurrentlyFocused = focusObject;
hgs
parents: 1
diff changeset
   269
        if (mAutoCompleter) {
hgs
parents: 1
diff changeset
   270
            mAutoCompleter->commit();
hgs
parents: 1
diff changeset
   271
        }
hgs
parents: 1
diff changeset
   272
    }
hgs
parents: 1
diff changeset
   273
    // set up auto completer
hgs
parents: 1
diff changeset
   274
    setUpAutoCompleter();
hgs
parents: 1
diff changeset
   275
    break;
0
16d8024aca5e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   276
case HbInputModeHandler::HbInputModeActionCommit:
16d8024aca5e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   277
case HbInputModeHandler::HbInputModeActionFocusLost:
34
hgs
parents: 1
diff changeset
   278
    if (mTimer->isActive()) {
hgs
parents: 1
diff changeset
   279
        mTimer->stop();
hgs
parents: 1
diff changeset
   280
        if (mCurrentChar != 0) {
hgs
parents: 1
diff changeset
   281
            if (isEnterCharacter(mCurrentChar)) {
hgs
parents: 1
diff changeset
   282
                focusObject->sendPreEditString(QString("")); // Make sure the enter character is cleared.
hgs
parents: 1
diff changeset
   283
                mCurrentChar = QChar('\n');                    // Convert enter character to line feed.
hgs
parents: 1
diff changeset
   284
            }
hgs
parents: 1
diff changeset
   285
            focusObject->filterAndCommitCharacter(mCurrentChar);
hgs
parents: 1
diff changeset
   286
            mCurrentChar = 0;
hgs
parents: 1
diff changeset
   287
        }
hgs
parents: 1
diff changeset
   288
        mLastKey = 0;
hgs
parents: 1
diff changeset
   289
        mNumChr = 0;
hgs
parents: 1
diff changeset
   290
        mInputMethod->updateState();
hgs
parents: 1
diff changeset
   291
    }
hgs
parents: 1
diff changeset
   292
    break;
0
16d8024aca5e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   293
default: {
34
hgs
parents: 1
diff changeset
   294
    ret = false;
hgs
parents: 1
diff changeset
   295
         }
hgs
parents: 1
diff changeset
   296
         break;
hgs
parents: 1
diff changeset
   297
    };
0
16d8024aca5e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   298
34
hgs
parents: 1
diff changeset
   299
    return ret;
0
16d8024aca5e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   300
}
16d8024aca5e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   301
16d8024aca5e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   302
16d8024aca5e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   303
HbHardwareInputBasic12KeyHandler::HbHardwareInputBasic12KeyHandler(HbInputAbstractMethod* inputMethod)
16d8024aca5e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   304
:HbInputBasicHandler( *new HbHardwareInputBasic12KeyHandlerPrivate, inputMethod)
16d8024aca5e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   305
{
34
hgs
parents: 1
diff changeset
   306
    Q_D(HbHardwareInputBasic12KeyHandler);
hgs
parents: 1
diff changeset
   307
    d->q_ptr = this;
0
16d8024aca5e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   308
}
16d8024aca5e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   309
16d8024aca5e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   310
HbHardwareInputBasic12KeyHandler::~HbHardwareInputBasic12KeyHandler()
16d8024aca5e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   311
{
16d8024aca5e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   312
}
16d8024aca5e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   313
16d8024aca5e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   314
/*!
16d8024aca5e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   315
filterEvent function for handling different keyevents.
16d8024aca5e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   316
*/
16d8024aca5e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   317
bool HbHardwareInputBasic12KeyHandler::filterEvent(const QKeyEvent * event)
16d8024aca5e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   318
{
34
hgs
parents: 1
diff changeset
   319
    Q_D(HbHardwareInputBasic12KeyHandler);
0
16d8024aca5e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   320
34
hgs
parents: 1
diff changeset
   321
    if (event->isAutoRepeat()) {
hgs
parents: 1
diff changeset
   322
        // Ignore all repeat events after first repeat event
hgs
parents: 1
diff changeset
   323
        return true;    
hgs
parents: 1
diff changeset
   324
    } else if (event->type() == QEvent::KeyRelease) {
hgs
parents: 1
diff changeset
   325
        return d->keyReleased(event);
hgs
parents: 1
diff changeset
   326
    } else {
hgs
parents: 1
diff changeset
   327
        return d->keyPressed(event);
hgs
parents: 1
diff changeset
   328
    }
0
16d8024aca5e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   329
}
16d8024aca5e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   330
16d8024aca5e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   331
/*!
16d8024aca5e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   332
returns true if in inline edit.
16d8024aca5e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   333
*/
16d8024aca5e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   334
bool HbHardwareInputBasic12KeyHandler::isComposing() const
16d8024aca5e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   335
{
34
hgs
parents: 1
diff changeset
   336
    Q_D(const HbHardwareInputBasic12KeyHandler);
hgs
parents: 1
diff changeset
   337
    return d->mTimer->isActive();
0
16d8024aca5e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   338
}
16d8024aca5e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   339
16d8024aca5e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   340
/*!
16d8024aca5e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   341
Action Handler
16d8024aca5e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   342
*/
16d8024aca5e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   343
bool HbHardwareInputBasic12KeyHandler::actionHandler(HbInputModeAction action)
16d8024aca5e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   344
{
34
hgs
parents: 1
diff changeset
   345
    Q_D(HbHardwareInputBasic12KeyHandler);
hgs
parents: 1
diff changeset
   346
    if (!d->actionHandler(action)) {
hgs
parents: 1
diff changeset
   347
        // no action taken so let's pass it to the base class.
hgs
parents: 1
diff changeset
   348
        return HbInputBasicHandler::actionHandler(action);
hgs
parents: 1
diff changeset
   349
    }
hgs
parents: 1
diff changeset
   350
    return false;
0
16d8024aca5e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   351
}
16d8024aca5e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   352
// EOF