src/hbplugins/inputmethods/touchinput/hbinputprediction12keythaihandler.cpp
changeset 5 627c4a0fd0e7
parent 3 11d3954df52a
child 6 c3690ec91ef8
equal deleted inserted replaced
3:11d3954df52a 5:627c4a0fd0e7
     1 /****************************************************************************
       
     2 **
       
     3 ** Copyright (C) 2008-2010 Nokia Corporation and/or its subsidiary(-ies).
       
     4 ** All rights reserved.
       
     5 ** Contact: Nokia Corporation (developer.feedback@nokia.com)
       
     6 **
       
     7 ** This file is part of the HbPlugins module of the UI Extensions for Mobile.
       
     8 **
       
     9 ** GNU Lesser General Public License Usage
       
    10 ** This file may be used under the terms of the GNU Lesser General Public
       
    11 ** License version 2.1 as published by the Free Software Foundation and
       
    12 ** appearing in the file LICENSE.LGPL included in the packaging of this file.
       
    13 ** Please review the following information to ensure the GNU Lesser General
       
    14 ** Public License version 2.1 requirements will be met:
       
    15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
       
    16 **
       
    17 ** In addition, as a special exception, Nokia gives you certain additional
       
    18 ** rights.  These rights are described in the Nokia Qt LGPL Exception
       
    19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
       
    20 **
       
    21 ** If you have questions regarding the use of this file, please contact
       
    22 ** Nokia at developer.feedback@nokia.com.
       
    23 **
       
    24 ****************************************************************************/
       
    25 #include <QTimer>
       
    26 
       
    27 #include <hbinputsettingproxy.h>
       
    28 #include <hbinputkeymapfactory.h>
       
    29 #include <hbinputpredictionengine.h>
       
    30 #include <hbinputbutton.h>
       
    31 
       
    32 #include "virtual12key.h"
       
    33 
       
    34 #include "hbinputprediction12keyhandler_p.h"
       
    35 #include "hbinputprediction12keythaihandler.h"
       
    36 
       
    37 class HbInputPrediction12KeyThaiHandlerPrivate: public HbInputPrediction12KeyHandlerPrivate
       
    38 {
       
    39     Q_DECLARE_PUBLIC(HbInputPrediction12KeyThaiHandler)
       
    40 
       
    41 public:
       
    42     HbInputPrediction12KeyThaiHandlerPrivate();
       
    43     ~HbInputPrediction12KeyThaiHandlerPrivate();
       
    44 
       
    45     bool buttonReleased(const QKeyEvent *keyEvent);
       
    46     bool buttonPressed(const QKeyEvent *keyEvent);
       
    47 };
       
    48 
       
    49 HbInputPrediction12KeyThaiHandlerPrivate::HbInputPrediction12KeyThaiHandlerPrivate()
       
    50 {
       
    51 }
       
    52 
       
    53 HbInputPrediction12KeyThaiHandlerPrivate::~HbInputPrediction12KeyThaiHandlerPrivate()
       
    54 {
       
    55    
       
    56 }
       
    57 
       
    58 bool HbInputPrediction12KeyThaiHandlerPrivate::buttonPressed(const QKeyEvent *keyEvent)
       
    59 {
       
    60     Q_Q(HbInputPrediction12KeyThaiHandler);
       
    61 
       
    62     mLongPressHappened = false;
       
    63     HbInputFocusObject *focusObject = 0;
       
    64     focusObject = mInputMethod->focusObject();
       
    65     if (!focusObject) {
       
    66         return false;
       
    67     }
       
    68 
       
    69     int buttonId = keyEvent->key();
       
    70 
       
    71     if (keyEvent->isAutoRepeat() && mLastKey == buttonId) {
       
    72         if (buttonId == Qt::Key_0) {
       
    73 			q->actionHandler(HbInputModeHandler::HbInputModeActionCommit);
       
    74 			q->commitFirstMappedNumber(buttonId, mInputMethod->currentKeyboardType());
       
    75             mLongPressHappened = true;
       
    76         } else if (buttonId != HbInputButton::ButtonKeyCodeAsterisk) {
       
    77             return HbInputPrediction12KeyHandlerPrivate::buttonPressed(keyEvent);
       
    78         }
       
    79         if (mLongPressHappened) {
       
    80             mLastKey = 0;
       
    81             return true;
       
    82         }        
       
    83     }
       
    84 
       
    85     //Pass the event to base class except Shift key
       
    86 	if (buttonId == Qt::Key_Shift) {		
       
    87 	  mLastKey = buttonId;
       
    88 	  mButtonDown = true;
       
    89 	} else {
       
    90 		return HbInputPrediction12KeyHandlerPrivate::buttonPressed(keyEvent);
       
    91 	}
       
    92     return false;
       
    93 }
       
    94 
       
    95 /*!
       
    96 Handles the key release events from the VKB. Launches the SCT with key release event of
       
    97 asterisk.
       
    98 */
       
    99 bool HbInputPrediction12KeyThaiHandlerPrivate::buttonReleased(const QKeyEvent *keyEvent)
       
   100 {
       
   101     Q_Q(HbInputPrediction12KeyHandler);
       
   102     
       
   103     if(!mButtonDown || mLongPressHappened){
       
   104         mLongPressHappened = false;
       
   105         return false;
       
   106     }
       
   107 
       
   108     int buttonId = keyEvent->key(); 
       
   109 
       
   110 	if (buttonId == HbInputButton::ButtonKeyCodeAsterisk && !mInputMethod->isSctModeActive()) {
       
   111 		//Handle if key Asterisk pressed and SCT is not launched or else pass it to base handlers
       
   112 		if (q->HbInputPredictionHandler::filterEvent(keyEvent)) {
       
   113 			mButtonDown = false;
       
   114 			return true;
       
   115 		}
       
   116     } else if ( buttonId == HbInputButton::ButtonKeyCodeShift ) {
       
   117 		//As we can't map charatcers to Shift key in keymapping, making use of "#" key i.e. Qt::Key_NumberSign
       
   118 		//in keymapping and manipulating event to Qt::Key_NumberSign when shift key is pressed
       
   119 		const QKeyEvent *event = new QKeyEvent(QEvent::KeyPress, Qt::Key_NumberSign, Qt::NoModifier);
       
   120 		if (q->HbInputPredictionHandler::filterEvent(event)) {
       
   121 			mButtonDown = false;
       
   122 			return true;
       
   123 		}		
       
   124 	} else {
       
   125 		HbInputPrediction12KeyHandlerPrivate::buttonReleased(keyEvent);
       
   126 	}
       
   127     return false;
       
   128 }
       
   129 
       
   130 
       
   131 HbInputPrediction12KeyThaiHandler::HbInputPrediction12KeyThaiHandler(HbInputAbstractMethod *inputMethod)
       
   132     :HbInputPrediction12KeyHandler(* new HbInputPrediction12KeyThaiHandlerPrivate, inputMethod)
       
   133 {
       
   134     Q_D(HbInputPrediction12KeyThaiHandler);
       
   135     d->q_ptr = this;
       
   136 }
       
   137 
       
   138 HbInputPrediction12KeyThaiHandler::~HbInputPrediction12KeyThaiHandler()
       
   139 {
       
   140 }
       
   141 /*!
       
   142     filterEvent to handler keypress/release events.
       
   143 */
       
   144 
       
   145 bool HbInputPrediction12KeyThaiHandler::filterEvent(const QKeyEvent * event)
       
   146 {
       
   147     Q_D(HbInputPrediction12KeyThaiHandler);
       
   148     HbInputFocusObject *focusObject = 0;
       
   149     focusObject = d->mInputMethod->focusObject();
       
   150 
       
   151     //If there was a handling for empty candidate-list, i.e. the engine did not predict
       
   152     //any meaningful word for the input sequence. 
       
   153    
       
   154 	if(!d->mCanContinuePrediction) {
       
   155 		int eventKey = event->key();
       
   156 		//let's us return If engine did not predict any meaningful word for the input sequence 
       
   157 		//for Shift,Asterisk and Control
       
   158 		if(eventKey == Qt::Key_Control || eventKey == Qt::Key_0) {
       
   159 			if(d->mCandidates->size() && focusObject ) {
       
   160 				//Remove the "?" mark
       
   161 				(*d->mCandidates)[d->mBestGuessLocation].chop(1);
       
   162 				d->updateEditor();
       
   163 				d->mCanContinuePrediction = true;
       
   164 			}
       
   165 		} else if (eventKey != Qt::Key_Shift && eventKey != Qt::Key_Asterisk){
       
   166 			// For Shift key and Asterisk key Will handle it in button release Since we have character mapped to Shift and Asterisk
       
   167 			// or else pass it to Prediction12KeyHandler handler
       
   168 			HbInputPrediction12KeyHandler::filterEvent(event);
       
   169 		}
       
   170     }	
       
   171 
       
   172 	// If the word is in inline edit First tap of Qt::Key_0 should commit the word in the editor
       
   173 	// For successive tap prediction mode can't handle Qt::Key_0, so we will emit a passFilterEvent
       
   174     // this signal must be connected to by the plugin to a modehandler.
       
   175     // which can handle it.
       
   176 
       
   177 	if (event->key() == Qt::Key_0 && d->mEngine->inputLength() >= 1 ) {
       
   178 		if(event->type() == QEvent::KeyPress) {
       
   179 			d->mButtonDown = true;
       
   180 		} else if(event->type() == QEvent::KeyRelease) {
       
   181 			d->mTimer->stop();
       
   182 			d->mButtonDown = false;
       
   183 			actionHandler(HbInputModeHandler::HbInputModeActionCommit);
       
   184 		}
       
   185 		d->mLastKey = Qt::Key_0;
       
   186 		return true;
       
   187 	} else if (event->key() == Qt::Key_0) {
       
   188 		emit passFilterEvent(event);
       
   189 		d->mLastKey = Qt::Key_0;
       
   190 		return true;
       
   191 	} else {
       
   192 		if (d->mLastKey == Qt::Key_0) {
       
   193 			emit passActionHandler(HbInputModeActionCommit);
       
   194 		}
       
   195 		if (event->type() == QEvent::KeyRelease) {
       
   196 			return d->buttonReleased(event);
       
   197 		} else {
       
   198 			return d->buttonPressed(event);
       
   199 		}
       
   200 	}
       
   201 }
       
   202 
       
   203 
       
   204 //EOF
       
   205