src/hbplugins/inputmethods/touchinput/hbinputbasic12keythaihandler.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 
       
    26 #include "virtual12key.h"
       
    27 #include <QTimer>
       
    28 #include <hbinputbutton.h>
       
    29 #include "hbinputbasic12keythaihandler.h"
       
    30 #include "hbinputbasic12keyhandler_p.h"
       
    31 
       
    32 class HbInputBasic12KeyThaiHandlerPrivate: public HbInputBasic12KeyHandlerPrivate
       
    33 {
       
    34     Q_DECLARE_PUBLIC(HbInputBasic12KeyThaiHandler)
       
    35 
       
    36 public:
       
    37     HbInputBasic12KeyThaiHandlerPrivate();
       
    38     ~HbInputBasic12KeyThaiHandlerPrivate();
       
    39 
       
    40 	void showThaiSpecialCharacters();
       
    41     bool buttonPressed(const QKeyEvent *keyEvent);
       
    42     bool buttonReleased(const QKeyEvent *keyEvent);
       
    43 };
       
    44 
       
    45 HbInputBasic12KeyThaiHandlerPrivate::HbInputBasic12KeyThaiHandlerPrivate()
       
    46 {
       
    47 
       
    48 }
       
    49 
       
    50 HbInputBasic12KeyThaiHandlerPrivate::~HbInputBasic12KeyThaiHandlerPrivate()
       
    51 {
       
    52 
       
    53 }
       
    54 
       
    55 /*!
       
    56 Handles the key press events from the VKB.
       
    57 */
       
    58 bool HbInputBasic12KeyThaiHandlerPrivate::buttonPressed(const QKeyEvent *keyEvent)
       
    59 {
       
    60     if (keyEvent->isAutoRepeat() && mDownKey == keyEvent->key() &&
       
    61         mDownKey == HbInputButton::ButtonKeyCodeAsterisk) {
       
    62         //For Thai Language Launch Special Characters popup 
       
    63 	    mInputMethod->showThaiSpecialCharacters(mDownKey); 
       
    64         mTimer->stop();
       
    65         mLongPressHappened = true;
       
    66         mDownKey = 0;
       
    67         return true;
       
    68     } else {
       
    69         return HbInputBasic12KeyHandlerPrivate::buttonPressed(keyEvent);
       
    70     }
       
    71     return false;
       
    72 }
       
    73 
       
    74 /*!
       
    75 Handles the key release events from the VKB. Launches Thai special popup with key release event of
       
    76 asterisk and shift key.
       
    77 */
       
    78 bool HbInputBasic12KeyThaiHandlerPrivate::buttonReleased(const QKeyEvent *keyEvent)
       
    79 {
       
    80 	Q_UNUSED(keyEvent);
       
    81     HbInputVkbWidget::HbFlickDirection flickDir = static_cast<HbVirtual12Key*>(mInputMethod)->flickDirection();
       
    82 	if (mInputMethod && flickDir!=HbInputVkbWidget::HbFlickDirectionDown) {
       
    83 		int buttonId = keyEvent->key();
       
    84 		HbInputFocusObject *focusObject = 0;
       
    85 		focusObject = mInputMethod->focusObject();
       
    86 		if (!focusObject || !mDownKey) {
       
    87 			return false;
       
    88 		}
       
    89 		if (mLongPressHappened) {
       
    90             mLongPressHappened = false;
       
    91 			return false;
       
    92 		}
       
    93 		//Handle if Shift and Asterisk key release happen or else let's pass it to base class to handle
       
    94 		if (buttonId == Qt::Key_Shift) {
       
    95 			//For Thai Language Launch Special Characters popup 
       
    96 			mInputMethod->showThaiSpecialCharacters(buttonId);
       
    97 			mLastKey = buttonId;
       
    98 			mCurrentChar = 0;
       
    99 			mDownKey = 0;
       
   100 			return true;				
       
   101 		} else if (buttonId == Qt::Key_Asterisk && !mInputMethod->isSctModeActive()) {
       
   102 			//For Thai Language Launch Special Characters popup 
       
   103 			mInputMethod->showThaiSpecialCharacters(buttonId);
       
   104 			mLastKey = buttonId;
       
   105 			mCurrentChar = 0;
       
   106 			mDownKey = 0;
       
   107 			return true;			
       
   108 		} else {
       
   109 			HbInputBasic12KeyHandlerPrivate::buttonReleased(keyEvent);
       
   110 		}
       
   111 	}
       
   112 	return false;
       
   113 }
       
   114 
       
   115 HbInputBasic12KeyThaiHandler::HbInputBasic12KeyThaiHandler(HbInputAbstractMethod* inputMethod)
       
   116 :HbInputBasic12KeyHandler(*new HbInputBasic12KeyThaiHandlerPrivate, inputMethod)
       
   117 {
       
   118     Q_D(HbInputBasic12KeyThaiHandler);
       
   119     d->q_ptr = this;
       
   120 }
       
   121 
       
   122 HbInputBasic12KeyThaiHandler::~HbInputBasic12KeyThaiHandler()
       
   123 {
       
   124 }
       
   125 
       
   126 /*!
       
   127  filterEvent function for handling different keyevents.
       
   128 */
       
   129 bool HbInputBasic12KeyThaiHandler::filterEvent(const QKeyEvent * event)
       
   130 {
       
   131     Q_D(HbInputBasic12KeyThaiHandler);
       
   132 
       
   133     if (event->type() == QEvent::KeyRelease) {
       
   134         return d->buttonReleased(event);
       
   135     } else {
       
   136         return d->buttonPressed(event);
       
   137     }
       
   138 }
       
   139 
       
   140 //End of file
       
   141