src/hbplugins/inputmethods/touchinput/hbinputprediction12keythaihandler.cpp
changeset 1 f7ac710697a9
child 2 06ff229162e9
equal deleted inserted replaced
0:16d8024aca5e 1:f7ac710697a9
       
     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 
       
    31 #include "virtual12key.h"
       
    32 
       
    33 #include "hbinputprediction12keyhandler_p.h"
       
    34 #include "hbinputprediction12keythaihandler.h"
       
    35 
       
    36 class HbInputPrediction12KeyThaiHandlerPrivate: public HbInputPrediction12KeyHandlerPrivate
       
    37 {
       
    38     Q_DECLARE_PUBLIC(HbInputPrediction12KeyThaiHandler)
       
    39 
       
    40 public:
       
    41     HbInputPrediction12KeyThaiHandlerPrivate();
       
    42     ~HbInputPrediction12KeyThaiHandlerPrivate();
       
    43 
       
    44     bool buttonReleased(const QKeyEvent *keyEvent);
       
    45     bool buttonPressed(const QKeyEvent *keyEvent);
       
    46     void _q_timeout();
       
    47 };
       
    48 
       
    49 HbInputPrediction12KeyThaiHandlerPrivate::HbInputPrediction12KeyThaiHandlerPrivate()
       
    50 {
       
    51 }
       
    52 
       
    53 HbInputPrediction12KeyThaiHandlerPrivate::~HbInputPrediction12KeyThaiHandlerPrivate()
       
    54 {
       
    55    
       
    56 }
       
    57 
       
    58 void HbInputPrediction12KeyThaiHandlerPrivate::_q_timeout()
       
    59 {
       
    60 	Q_Q(HbInputPrediction12KeyHandler);
       
    61     // let's stop the timer first.
       
    62     mTimer->stop();
       
    63 
       
    64     if (mButtonDown) {
       
    65 		if(mLastKey == Qt::Key_0){
       
    66 			q->actionHandler(HbInputModeHandler::HbInputModeActionCommit);
       
    67 			q->commitFirstMappedNumber(mLastKey);		
       
    68 		} else if(mLastKey != Qt::Key_Asterisk) {
       
    69 			//Long key press number key is applicable to all keys so pass it to Base class
       
    70 			HbInputPrediction12KeyHandlerPrivate::_q_timeout();            
       
    71         }
       
    72     }
       
    73 }
       
    74 
       
    75 bool HbInputPrediction12KeyThaiHandlerPrivate::buttonPressed(const QKeyEvent *keyEvent)
       
    76 {
       
    77     mLongPressHappened = false;
       
    78     HbInputFocusObject *focusObject = 0;
       
    79     focusObject = mInputMethod->focusObject();
       
    80     if (!focusObject) {
       
    81         return false;
       
    82     }
       
    83 	
       
    84     int buttonId = keyEvent->key();
       
    85 
       
    86     //Pass the event to base class except Shift key
       
    87 	if (buttonId == Qt::Key_Shift ) {		
       
    88 	  mLastKey = buttonId;
       
    89 	  mButtonDown = true;
       
    90 	} else {
       
    91 		HbInputPrediction12KeyHandlerPrivate::buttonPressed(keyEvent);
       
    92 	}
       
    93 	// custom button should not start timer.
       
    94     if ((buttonId & CUSTOM_INPUT_MASK) != CUSTOM_INPUT_MASK) {
       
    95         mTimer->start(HbLongPressTimerTimeout);
       
    96     }
       
    97     return false;
       
    98 }
       
    99 
       
   100 /*!
       
   101 Handles the key release events from the VKB. Launches the SCT with key release event of
       
   102 asterisk.
       
   103 */
       
   104 bool HbInputPrediction12KeyThaiHandlerPrivate::buttonReleased(const QKeyEvent *keyEvent)
       
   105 {
       
   106     Q_Q(HbInputPrediction12KeyHandler);
       
   107     
       
   108     if(!mButtonDown || mLongPressHappened){
       
   109         return false;
       
   110     }
       
   111 
       
   112     int buttonId = keyEvent->key(); 
       
   113     // it was a long press on sct swith button. so just return form here.
       
   114     if (!mTimer->isActive() && buttonId == Qt::Key_Control) {
       
   115         return true;
       
   116     }
       
   117 
       
   118 	if (buttonId == Qt::Key_Asterisk && !mInputMethod->isSctModeActive()) {
       
   119 		//Handle if key Asterisk pressed and SCT is not launched or else pass it to base handlers
       
   120 		if (q->HbInputPredictionHandler::filterEvent(keyEvent)) {
       
   121 			mButtonDown = false;
       
   122 			return true;
       
   123 		}
       
   124     } else if ( buttonId == Qt::Key_Shift ) {
       
   125 		//As we can't map charatcers to Shift key in keymapping, making use of "#" key i.e. Qt::Key_NumberSign
       
   126 		//in keymapping and manipulating event to Qt::Key_NumberSign when shift key is pressed
       
   127 		const QKeyEvent *event = new QKeyEvent(QEvent::KeyPress, Qt::Key_NumberSign, Qt::NoModifier);
       
   128 		if (q->HbInputPredictionHandler::filterEvent(event)) {
       
   129 			mButtonDown = false;
       
   130 			return true;
       
   131 		}		
       
   132 	} else {
       
   133 		HbInputPrediction12KeyHandlerPrivate::buttonReleased(keyEvent);
       
   134 	}
       
   135     return false;
       
   136 }
       
   137 
       
   138 
       
   139 HbInputPrediction12KeyThaiHandler::HbInputPrediction12KeyThaiHandler(HbInputAbstractMethod *inputMethod)
       
   140     :HbInputPrediction12KeyHandler(* new HbInputPrediction12KeyThaiHandlerPrivate, inputMethod)
       
   141 {
       
   142     Q_D(HbInputPrediction12KeyThaiHandler);
       
   143     d->q_ptr = this;
       
   144 }
       
   145 
       
   146 HbInputPrediction12KeyThaiHandler::~HbInputPrediction12KeyThaiHandler()
       
   147 {
       
   148 }
       
   149 /*!
       
   150     filterEvent to handler keypress/release events.
       
   151 */
       
   152 
       
   153 bool HbInputPrediction12KeyThaiHandler::filterEvent(const QKeyEvent * event)
       
   154 {
       
   155     Q_D(HbInputPrediction12KeyThaiHandler);
       
   156     HbInputFocusObject *focusObject = 0;
       
   157     focusObject = d->mInputMethod->focusObject();
       
   158 
       
   159     //If there was a handling for empty candidate-list, i.e. the engine did not predict
       
   160     //any meaningful word for the input sequence. 
       
   161    
       
   162 	if(!d->mCanContinuePrediction) {
       
   163 		int eventKey = event->key();
       
   164 		//let's us return If engine did not predict any meaningful word for the input sequence 
       
   165 		//for Shift,Asterisk and Control
       
   166 		if(eventKey == Qt::Key_Control || eventKey == Qt::Key_0) {
       
   167 			if(d->mCandidates->size() && focusObject ) {
       
   168 				//Remove the "?" mark
       
   169 				(*d->mCandidates)[d->mBestGuessLocation].chop(1);
       
   170 				d->updateEditor();
       
   171 				d->mCanContinuePrediction = true;
       
   172 			}
       
   173 		} else if (eventKey != Qt::Key_Shift && eventKey != Qt::Key_Asterisk){
       
   174 			// For Shift key and Asterisk key Will handle it in button release Since we have character mapped to Shift and Asterisk
       
   175 			// or else pass it to Prediction12KeyHandler handler
       
   176 			HbInputPrediction12KeyHandler::filterEvent(event);
       
   177 		}
       
   178     }	
       
   179 
       
   180 	// If the word is in inline edit First tap of Qt::Key_0 should commit the word in the editor
       
   181 	// For successive tap prediction mode can't handle Qt::Key_0, so we will emit a passFilterEvent
       
   182     // this signal must be connected to by the plugin to a modehandler.
       
   183     // which can handle it.
       
   184 
       
   185 	if (event->key() == Qt::Key_0 && d->mEngine->inputLength() >= 1 ) {
       
   186 		if(event->type() == QEvent::KeyPress) {
       
   187 			d->mButtonDown = true;
       
   188 			// start Long Press timer as zero key should be allowed to enter
       
   189 			d->mTimer->start(HbLongPressTimerTimeout);
       
   190 		} else if(event->type() == QEvent::KeyRelease) {
       
   191 			d->mTimer->stop();
       
   192 			d->mButtonDown = false;
       
   193 			actionHandler(HbInputModeHandler::HbInputModeActionCommit);
       
   194 		}
       
   195 		d->mLastKey = Qt::Key_0;
       
   196 		return true;
       
   197 	} else if (event->key() == Qt::Key_0) {
       
   198 		emit passFilterEvent(event);
       
   199 		d->mLastKey = Qt::Key_0;
       
   200 		return true;
       
   201 	} else {
       
   202 		if (d->mLastKey == Qt::Key_0) {
       
   203 			emit passActionHandler(HbInputModeActionCommit);
       
   204 		}
       
   205 		if (event->type() == QEvent::KeyRelease) {
       
   206 			return d->buttonReleased(event);
       
   207 		} else {
       
   208 			return d->buttonPressed(event);
       
   209 		}
       
   210 	}
       
   211 }
       
   212 
       
   213 
       
   214 //EOF
       
   215