src/hbplugins/inputmethods/hardwareinput/hbhardwareinputbasic12keyhandler.cpp
changeset 34 ed14f46c0e55
parent 1 f7ac710697a9
equal deleted inserted replaced
31:7516d6d86cf5 34:ed14f46c0e55
    33 #include "hbinputabstractbase.h"
    33 #include "hbinputabstractbase.h"
    34 #include "hbhardware12key.h"
    34 #include "hbhardware12key.h"
    35 
    35 
    36 class HbHardwareInputBasic12KeyHandlerPrivate: public HbInputBasicHandlerPrivate
    36 class HbHardwareInputBasic12KeyHandlerPrivate: public HbInputBasicHandlerPrivate
    37 {
    37 {
    38 	Q_DECLARE_PUBLIC(HbHardwareInputBasic12KeyHandler)
    38     Q_DECLARE_PUBLIC(HbHardwareInputBasic12KeyHandler)
    39 
    39 
    40 public:
    40 public:
    41 	HbHardwareInputBasic12KeyHandlerPrivate();
    41     HbHardwareInputBasic12KeyHandlerPrivate();
    42 	~HbHardwareInputBasic12KeyHandlerPrivate();
    42     ~HbHardwareInputBasic12KeyHandlerPrivate();
    43 
    43 
    44 	void handleAlphaEvent(int buttonId);
    44     void handleAlphaEvent(int buttonId);
    45 	bool keyPressed(const QKeyEvent *keyEvent);
    45     bool keyPressed(const QKeyEvent *keyEvent);
    46 	bool keyReleased(const QKeyEvent *keyEvent);
    46     bool keyReleased(const QKeyEvent *keyEvent);
    47 	bool actionHandler(HbInputModeHandler::HbInputModeAction action);
    47     bool actionHandler(HbInputModeHandler::HbInputModeAction action);
    48 
    48 
    49 	void _q_timeout();
    49     void _q_timeout();
    50 public:
    50 public:
    51 	int mLastKey;
    51     int mLastKey;
    52 	QChar mCurrentChar;
    52     QChar mCurrentChar;
    53 	int mNumChr;
    53     int mNumChr;
    54 	bool mButtonDown;
    54     bool mButtonDown;
    55 	HbInputFocusObject *mCurrentlyFocused;
    55     HbInputFocusObject *mCurrentlyFocused;
    56 };
    56 };
    57 
    57 
    58 HbHardwareInputBasic12KeyHandlerPrivate::HbHardwareInputBasic12KeyHandlerPrivate()
    58 HbHardwareInputBasic12KeyHandlerPrivate::HbHardwareInputBasic12KeyHandlerPrivate()
    59 :    mLastKey(0),
    59 :    mLastKey(0),
    60 mCurrentChar(0),
    60 mCurrentChar(0),
    69 }
    69 }
    70 
    70 
    71 // handles the key press events. It starts a multitap timer as well.
    71 // handles the key press events. It starts a multitap timer as well.
    72 void HbHardwareInputBasic12KeyHandlerPrivate::handleAlphaEvent(int buttonId)
    72 void HbHardwareInputBasic12KeyHandlerPrivate::handleAlphaEvent(int buttonId)
    73 {
    73 {
    74 	Q_Q(HbHardwareInputBasic12KeyHandler);
    74     Q_Q(HbHardwareInputBasic12KeyHandler);
    75 	HbInputFocusObject *focusObject = 0;
    75     HbInputFocusObject *focusObject = 0;
    76 	focusObject = mInputMethod->focusObject();
    76     focusObject = mInputMethod->focusObject();
    77 	if (!focusObject) {
    77     if (!focusObject) {
    78 		return;
    78         return;
    79 	}
    79     }
    80 
    80 
    81 	mCurrentChar = q->getNthCharacterInKey(mNumChr, buttonId);
    81     mCurrentChar = q->getNthCharacterInKey(mNumChr, buttonId);
    82 
    82 
    83 	if (mCurrentChar != 0) {
    83     if (mCurrentChar != 0) {
    84 		QString str;
    84         QString str;
    85 		str += mCurrentChar;
    85         str += mCurrentChar;
    86 
    86 
    87 		QList<QInputMethodEvent::Attribute> list;
    87         QList<QInputMethodEvent::Attribute> list;
    88 		QInputMethodEvent event(str, list);
    88         QInputMethodEvent event(str, list);
    89 		focusObject->sendEvent(event);
    89         focusObject->sendEvent(event);
    90 		mTimer->start(HbMultiTapTimerTimeout);
    90         mTimer->start(HbMultiTapTimerTimeout);
    91 	}
    91     }
    92 }
    92 }
    93 
    93 
    94 bool HbHardwareInputBasic12KeyHandlerPrivate::keyPressed(const QKeyEvent *keyEvent)
    94 bool HbHardwareInputBasic12KeyHandlerPrivate::keyPressed(const QKeyEvent *keyEvent)
    95 {
    95 {
    96 	Q_Q(HbHardwareInputBasic12KeyHandler);
    96     Q_Q(HbHardwareInputBasic12KeyHandler);
    97 	HbInputFocusObject *focusObject = 0;
    97     HbInputFocusObject *focusObject = 0;
    98 	focusObject = mInputMethod->focusObject();
    98     focusObject = mInputMethod->focusObject();
    99 	if (!focusObject) {
    99     if (!focusObject) {
   100 		return false;
   100         return false;
   101 	}
   101     }
   102 
   102 
   103 	int buttonId = keyEvent->key();
   103     int buttonId = keyEvent->key();
   104 	
   104     
   105 
   105 
   106 	if( mLastKey != buttonId) {
   106     if( mLastKey != buttonId) {
   107 		mLastKey = buttonId;
   107         mLastKey = buttonId;
   108 		if(mTimer->isActive()) {
   108         if(mTimer->isActive()) {
   109 			mTimer->stop();
   109             mTimer->stop();
   110 			mNumChr = 0;
   110             mNumChr = 0;
   111 			if (isEnterCharacter(mCurrentChar)) {
   111             if (isEnterCharacter(mCurrentChar)) {
   112 				focusObject->sendPreEditString(QString("")); // Make sure the enter character is cleared.
   112                 focusObject->sendPreEditString(QString("")); // Make sure the enter character is cleared.
   113 				mCurrentChar = QChar('\n');                  // Convert enter character to line feed.
   113                 mCurrentChar = QChar('\n');                  // Convert enter character to line feed.
   114 			}
   114             }
   115 
   115 
   116 			if(mCurrentChar != 0) {
   116             if(mCurrentChar != 0) {
   117 				focusObject->filterAndCommitCharacter(mCurrentChar);
   117                 focusObject->filterAndCommitCharacter(mCurrentChar);
   118 			}			
   118             }           
   119 			// For QLineEdit it works fine. For HbLineEdit, need to set the state 
   119             // For QLineEdit it works fine. For HbLineEdit, need to set the state 
   120 			// to lower by calling activateState().
   120             // to lower by calling activateState().
   121 			// This is needed for the scenario - When automatic text case is true
   121             // This is needed for the scenario - When automatic text case is true
   122 			// click a button and before the multitap timer expires click on
   122             // click a button and before the multitap timer expires click on
   123 			// another button.
   123             // another button.
   124 			mInputMethod->updateState();
   124             mInputMethod->updateState();
   125 
   125 
   126         refreshAutoCompleter();
   126         refreshAutoCompleter();
   127 		}
   127         }
   128 	}
   128     }
   129 
   129 
   130 	if (buttonId == Qt::Key_Return) {
   130     if (buttonId == Qt::Key_Return) {
   131 		mLastKey = buttonId;
   131         mLastKey = buttonId;
   132 		return true;
   132         return true;
   133 	} else if (buttonId == Qt::Key_Shift) {
   133     } else if (buttonId == Qt::Key_Shift) {
   134 		// For single key press, change the text input case. If the second shift key press is 
   134         // For single key press, change the text input case. If the second shift key press is 
   135 		// received within long key press time out interval, then activate the next state
   135         // received within long key press time out interval, then activate the next state
   136 		if (mTimer->isActive() && (mLastKey == buttonId)){
   136         if (mTimer->isActive() && (mLastKey == buttonId)){
   137 			mTimer->stop();
   137             mTimer->stop();
   138              HbInputState rootState;
   138              HbInputState rootState;
   139              mInputMethod->editorRootState(rootState);
   139              mInputMethod->editorRootState(rootState);
   140              mInputMethod->activateState(rootState);            
   140              mInputMethod->activateState(rootState);            
   141 		} else {
   141         } else {
   142 			updateTextCase();
   142             updateTextCase();
   143 			mTimer->start(HbLongPressTimerTimeout);
   143             mTimer->start(HbLongPressTimerTimeout);
   144 		}
   144         }
   145 		mCurrentChar = 0;
   145         mCurrentChar = 0;
   146 		mButtonDown = true;
   146         mButtonDown = true;
   147 		mCurrentChar = 0;
   147         mCurrentChar = 0;
   148 		return true;
   148         return true;
   149 	}
   149     }
   150 	// Let's see if we can get the handler for this button in the base class.
   150     // Let's see if we can get the handler for this button in the base class.
   151 	if (q->HbInputBasicHandler::filterEvent(keyEvent)) {
   151     if (q->HbInputBasicHandler::filterEvent(keyEvent)) {
   152 		return true;
   152         return true;
   153 	}
   153     }
   154 
   154 
   155 	mLastKey = buttonId;
   155     mLastKey = buttonId;
   156 	mButtonDown = true;
   156     mButtonDown = true;
   157 
   157 
   158 	handleAlphaEvent(buttonId);
   158     handleAlphaEvent(buttonId);
   159 	return true;
   159     return true;
   160 }
   160 }
   161 
   161 
   162 /*!
   162 /*!
   163 Handles the key release events from the VKB. Launches the SCT with key release event of
   163 Handles the key release events from the VKB. Launches the SCT with key release event of
   164 asterisk.
   164 asterisk.
   165 */
   165 */
   166 bool HbHardwareInputBasic12KeyHandlerPrivate::keyReleased(const QKeyEvent *keyEvent)
   166 bool HbHardwareInputBasic12KeyHandlerPrivate::keyReleased(const QKeyEvent *keyEvent)
   167 {
   167 {
   168 	Q_Q(HbHardwareInputBasic12KeyHandler);
   168     Q_Q(HbHardwareInputBasic12KeyHandler);
   169 	mButtonDown = false;
   169     mButtonDown = false;
   170 	int buttonId = keyEvent->key();
   170     int buttonId = keyEvent->key();
   171 
   171 
   172 	if (buttonId == Qt::Key_Asterisk) {
   172     if (buttonId == Qt::Key_Asterisk) {
   173 		//Same asterisk key is used for launching candidate list (long key press)
   173         //Same asterisk key is used for launching candidate list (long key press)
   174 		//and also for SCT. So, do not launch SCT if candidate list is already launched.            
   174         //and also for SCT. So, do not launch SCT if candidate list is already launched.            
   175 		mInputMethod->switchMode(buttonId);
   175         mInputMethod->switchMode(buttonId);
   176 		return true;
   176         return true;
   177 	} else if (buttonId == Qt::Key_Delete) {
   177     } else if (buttonId == Qt::Key_Delete) {
   178 		QKeyEvent keyEvent(QEvent::KeyRelease, Qt::Key_Backspace, Qt::NoModifier);
   178         QKeyEvent keyEvent(QEvent::KeyRelease, Qt::Key_Backspace, Qt::NoModifier);
   179 		q->sendAndUpdate(keyEvent);
   179         q->sendAndUpdate(keyEvent);
   180 		return true;
   180         return true;
   181 	}
   181     }
   182 
   182 
   183 	return false;
   183     return false;
   184 }
   184 }
   185 
   185 
   186 
   186 
   187 void HbHardwareInputBasic12KeyHandlerPrivate::_q_timeout()
   187 void HbHardwareInputBasic12KeyHandlerPrivate::_q_timeout()
   188 {
   188 {
   189 	Q_Q(HbHardwareInputBasic12KeyHandler);
   189     Q_Q(HbHardwareInputBasic12KeyHandler);
   190 	mTimer->stop();
   190     mTimer->stop();
   191 	mNumChr = 0;
   191     mNumChr = 0;
   192 
   192 
   193 	HbInputFocusObject *focusedObject = 0;
   193     HbInputFocusObject *focusedObject = 0;
   194 	focusedObject = mInputMethod->focusObject();
   194     focusedObject = mInputMethod->focusObject();
   195 	if (!focusedObject) {
   195     if (!focusedObject) {
   196 		qDebug("HbHardwareInputBasic12KeyHandler::timeout focusObject == 0");
   196         qDebug("HbHardwareInputBasic12KeyHandler::timeout focusObject == 0");
   197 		return;
   197         return;
   198 	}
   198     }
   199 
   199 
   200 	if (isEnterCharacter(mCurrentChar)) {
   200     if (isEnterCharacter(mCurrentChar)) {
   201 		focusedObject->sendPreEditString(QString("")); // Make sure the enter character is cleared.
   201         focusedObject->sendPreEditString(QString("")); // Make sure the enter character is cleared.
   202 		mCurrentChar = QChar('\n');                    // Convert enter character to line feed.
   202         mCurrentChar = QChar('\n');                    // Convert enter character to line feed.
   203 	}
   203     }
   204 
   204 
   205 	//Long key press number key is applicable to all keys
   205     //Long key press number key is applicable to all keys
   206 	if (mButtonDown) {
   206     if (mButtonDown) {
   207 		//switch to numeric mode for long key press of Hash key	
   207         //switch to numeric mode for long key press of Hash key 
   208 		if (mLastKey == Qt::Key_Shift){
   208         if (mLastKey == Qt::Key_Shift){
   209 			updateTextCase();
   209             updateTextCase();
   210 			mInputMethod->switchMode(Qt::Key_Shift);				
   210             mInputMethod->switchMode(Qt::Key_Shift);                
   211 		}else {		
   211         }else {     
   212 			q->commitFirstMappedNumber(mLastKey);
   212             q->commitFirstMappedNumber(mLastKey);
   213 		}		  
   213         }         
   214 	} else if(mLastKey != Qt::Key_Shift){
   214     } else if(mLastKey != Qt::Key_Shift){
   215 		if (!focusedObject->characterAllowedInEditor(mCurrentChar)) {
   215         if (!focusedObject->characterAllowedInEditor(mCurrentChar)) {
   216 			focusedObject->sendCommitString(QString());
   216             focusedObject->sendCommitString(QString());
   217 		} else {
   217         } else {
   218 			if ( mCurrentChar != 0){
   218             if ( mCurrentChar != 0){
   219 				QString curString;
   219                 QString curString;
   220 				curString.append(mCurrentChar);
   220                 curString.append(mCurrentChar);
   221 				focusedObject->sendCommitString(curString);
   221                 focusedObject->sendCommitString(curString);
   222 			}		
   222             }       
   223 			mInputMethod->updateState();
   223             mInputMethod->updateState();
   224 			// pass this character to autocompleter.
   224             // pass this character to autocompleter.
   225             refreshAutoCompleter();
   225             refreshAutoCompleter();
   226 		}
   226         }
   227 	}
   227     }
   228 	return;	
   228     return; 
   229 }
   229 }
   230 
   230 
   231 bool HbHardwareInputBasic12KeyHandlerPrivate::actionHandler(HbInputModeHandler::HbInputModeAction action)
   231 bool HbHardwareInputBasic12KeyHandlerPrivate::actionHandler(HbInputModeHandler::HbInputModeAction action)
   232 {
   232 {
   233 	HbInputFocusObject *focusObject = 0;
   233     HbInputFocusObject *focusObject = 0;
   234 	focusObject = mInputMethod->focusObject();
   234     focusObject = mInputMethod->focusObject();
   235 	if (!focusObject) {
   235     if (!focusObject) {
   236 		return false;
   236         return false;
   237 	}
   237     }
   238 
   238 
   239 	bool ret = true;
   239     bool ret = true;
   240 	switch (action) {
   240     switch (action) {
   241 case HbInputModeHandler::HbInputModeActionReset:
   241 case HbInputModeHandler::HbInputModeActionReset:
   242 	mLastKey = 0;
   242     mLastKey = 0;
   243 	mNumChr = 0;
   243     mNumChr = 0;
   244 	if (mTimer->isActive()) {
   244     if (mTimer->isActive()) {
   245 		mTimer->stop();
   245         mTimer->stop();
   246 	}
   246     }
   247 	break;
   247     break;
   248 case HbInputModeHandler::HbInputModeActionDeleteAndCommit:{
   248 case HbInputModeHandler::HbInputModeActionDeleteAndCommit:{
   249 	mTimer->stop();
   249     mTimer->stop();
   250 	QString empty;
   250     QString empty;
   251 	if(mInputMethod) {
   251     if(mInputMethod) {
   252 		//In case of the sct the character is already committed
   252         //In case of the sct the character is already committed
   253 		//We need to remove the committed character.
   253         //We need to remove the committed character.
   254 		QList<QInputMethodEvent::Attribute> list;
   254         QList<QInputMethodEvent::Attribute> list;
   255 		QInputMethodEvent event(QString(), list);
   255         QInputMethodEvent event(QString(), list);
   256 		event.setCommitString(empty, -1, 1);
   256         event.setCommitString(empty, -1, 1);
   257 		focusObject->sendEvent(event);
   257         focusObject->sendEvent(event);
   258 	} else {
   258     } else {
   259 		// Close event was originated from a button press, remove the uncommitted character.
   259         // Close event was originated from a button press, remove the uncommitted character.
   260 		focusObject->sendCommitString(empty);
   260         focusObject->sendCommitString(empty);
   261 	}
   261     }
   262 														  }
   262                                                           }
   263 														  break;
   263                                                           break;
   264 case HbInputModeHandler::HbInputModeActionFocusRecieved:
   264 case HbInputModeHandler::HbInputModeActionFocusRecieved:
   265 	mTimer->stop();
   265     mTimer->stop();
   266 	mNumChr = 0;
   266     mNumChr = 0;
   267 	if (mCurrentlyFocused != focusObject) {
   267     if (mCurrentlyFocused != focusObject) {
   268 		mCurrentlyFocused = focusObject;
   268         mCurrentlyFocused = focusObject;
   269 		if (mAutoCompleter) {
   269         if (mAutoCompleter) {
   270 			mAutoCompleter->commit();
   270             mAutoCompleter->commit();
   271 		}
   271         }
   272 	}
   272     }
   273 	// set up auto completer
   273     // set up auto completer
   274 	setUpAutoCompleter();
   274     setUpAutoCompleter();
   275 	break;
   275     break;
   276 case HbInputModeHandler::HbInputModeActionCommit:
   276 case HbInputModeHandler::HbInputModeActionCommit:
   277 case HbInputModeHandler::HbInputModeActionFocusLost:
   277 case HbInputModeHandler::HbInputModeActionFocusLost:
   278 	if (mTimer->isActive()) {
   278     if (mTimer->isActive()) {
   279 		mTimer->stop();
   279         mTimer->stop();
   280 		if (mCurrentChar != 0) {
   280         if (mCurrentChar != 0) {
   281 			if (isEnterCharacter(mCurrentChar)) {
   281             if (isEnterCharacter(mCurrentChar)) {
   282 				focusObject->sendPreEditString(QString("")); // Make sure the enter character is cleared.
   282                 focusObject->sendPreEditString(QString("")); // Make sure the enter character is cleared.
   283 				mCurrentChar = QChar('\n');                    // Convert enter character to line feed.
   283                 mCurrentChar = QChar('\n');                    // Convert enter character to line feed.
   284 			}
   284             }
   285 			focusObject->filterAndCommitCharacter(mCurrentChar);
   285             focusObject->filterAndCommitCharacter(mCurrentChar);
   286 			mCurrentChar = 0;
   286             mCurrentChar = 0;
   287 		}
   287         }
   288 		mLastKey = 0;
   288         mLastKey = 0;
   289 		mNumChr = 0;
   289         mNumChr = 0;
   290 		mInputMethod->updateState();
   290         mInputMethod->updateState();
   291 	}
   291     }
   292 	break;
   292     break;
   293 default: {
   293 default: {
   294 	ret = false;
   294     ret = false;
   295 		 }
   295          }
   296 		 break;
   296          break;
   297 	};
   297     };
   298 
   298 
   299 	return ret;
   299     return ret;
   300 }
   300 }
   301 
   301 
   302 
   302 
   303 HbHardwareInputBasic12KeyHandler::HbHardwareInputBasic12KeyHandler(HbInputAbstractMethod* inputMethod)
   303 HbHardwareInputBasic12KeyHandler::HbHardwareInputBasic12KeyHandler(HbInputAbstractMethod* inputMethod)
   304 :HbInputBasicHandler( *new HbHardwareInputBasic12KeyHandlerPrivate, inputMethod)
   304 :HbInputBasicHandler( *new HbHardwareInputBasic12KeyHandlerPrivate, inputMethod)
   305 {
   305 {
   306 	Q_D(HbHardwareInputBasic12KeyHandler);
   306     Q_D(HbHardwareInputBasic12KeyHandler);
   307 	d->q_ptr = this;
   307     d->q_ptr = this;
   308 }
   308 }
   309 
   309 
   310 HbHardwareInputBasic12KeyHandler::~HbHardwareInputBasic12KeyHandler()
   310 HbHardwareInputBasic12KeyHandler::~HbHardwareInputBasic12KeyHandler()
   311 {
   311 {
   312 }
   312 }
   314 /*!
   314 /*!
   315 filterEvent function for handling different keyevents.
   315 filterEvent function for handling different keyevents.
   316 */
   316 */
   317 bool HbHardwareInputBasic12KeyHandler::filterEvent(const QKeyEvent * event)
   317 bool HbHardwareInputBasic12KeyHandler::filterEvent(const QKeyEvent * event)
   318 {
   318 {
   319 	Q_D(HbHardwareInputBasic12KeyHandler);
   319     Q_D(HbHardwareInputBasic12KeyHandler);
   320 
   320 
   321 	if (event->isAutoRepeat()) {
   321     if (event->isAutoRepeat()) {
   322 		// Ignore all repeat events after first repeat event
   322         // Ignore all repeat events after first repeat event
   323 		return true;	
   323         return true;    
   324 	} else if (event->type() == QEvent::KeyRelease) {
   324     } else if (event->type() == QEvent::KeyRelease) {
   325 		return d->keyReleased(event);
   325         return d->keyReleased(event);
   326 	} else {
   326     } else {
   327 		return d->keyPressed(event);
   327         return d->keyPressed(event);
   328 	}
   328     }
   329 }
   329 }
   330 
   330 
   331 /*!
   331 /*!
   332 returns true if in inline edit.
   332 returns true if in inline edit.
   333 */
   333 */
   334 bool HbHardwareInputBasic12KeyHandler::isComposing() const
   334 bool HbHardwareInputBasic12KeyHandler::isComposing() const
   335 {
   335 {
   336 	Q_D(const HbHardwareInputBasic12KeyHandler);
   336     Q_D(const HbHardwareInputBasic12KeyHandler);
   337 	return d->mTimer->isActive();
   337     return d->mTimer->isActive();
   338 }
   338 }
   339 
   339 
   340 /*!
   340 /*!
   341 Action Handler
   341 Action Handler
   342 */
   342 */
   343 bool HbHardwareInputBasic12KeyHandler::actionHandler(HbInputModeAction action)
   343 bool HbHardwareInputBasic12KeyHandler::actionHandler(HbInputModeAction action)
   344 {
   344 {
   345 	Q_D(HbHardwareInputBasic12KeyHandler);
   345     Q_D(HbHardwareInputBasic12KeyHandler);
   346 	if (!d->actionHandler(action)) {
   346     if (!d->actionHandler(action)) {
   347 		// no action taken so let's pass it to the base class.
   347         // no action taken so let's pass it to the base class.
   348 		return HbInputBasicHandler::actionHandler(action);
   348         return HbInputBasicHandler::actionHandler(action);
   349 	}
   349     }
   350 	return false;
   350     return false;
   351 }
   351 }
   352 // EOF
   352 // EOF