src/hbplugins/inputmethods/common/hbinputmodehandler.h
changeset 0 16d8024aca5e
child 1 f7ac710697a9
equal deleted inserted replaced
-1:000000000000 0:16d8024aca5e
       
     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 #ifndef hb_input_mode_handler
       
    26 #define hb_input_mode_handler
       
    27 
       
    28 #include <QObject>
       
    29 #include <QStringList>
       
    30 #include <QChar>
       
    31 
       
    32 #include <hbinputmodeproperties.h>
       
    33 #include <hbinputdef.h>
       
    34 #include <hbinputpredictioncallback.h>
       
    35 
       
    36 class HbInputAbstractMethod;
       
    37 class QMouseEvent;
       
    38 class QTimer;
       
    39 class HbKeymap;
       
    40 class QKeyEvent;
       
    41 
       
    42 class HbInputModeHandlerPrivate;
       
    43 class HbInputModeHandler: public QObject
       
    44 {
       
    45     Q_OBJECT
       
    46 public:
       
    47     // Set of actions.
       
    48     enum HbInputModeAction {
       
    49         // mode specific actions
       
    50         HbInputModeActionInit, // keymapping initialization, signal connections etc.
       
    51         HbInputModeActionReset, // resetting the state of the modehandler
       
    52         HbInputModeActionClose, //cleanups like disconnection..!
       
    53 
       
    54         // commit actions
       
    55         HbInputModeActionCommit, // commits the inline characters if any
       
    56         HbInputModeActionDeleteAndCommit,// deletes one character and then commits
       
    57         
       
    58         HbInputModeActionPrimaryLanguageChanged, 
       
    59         HbInputModeActionSecondaryLanguageChanged, 
       
    60 
       
    61         // prediction
       
    62         HbInputModeActionSetCandidateList, // sets the candidate list
       
    63         HbInputModeActionSetKeypad,//sets the keypad
       
    64         HbInputModeActionLaunchCandidatePopup, // launched the candidate popup
       
    65         HbInputModeActionHideTail, //Hides the prediction tail
       
    66 
       
    67         // autocompletion
       
    68         HbInputModeActionSetupAutoCompletion, // setting up of autocompletion
       
    69 
       
    70         // focus change
       
    71         HbInputModeActionFocusRecieved, // focus recived state
       
    72         HbInputModeActionFocusLost, // focus lost state
       
    73         HbInputModeActionCancelButtonPress
       
    74         // more..
       
    75     };
       
    76 
       
    77     virtual ~HbInputModeHandler();
       
    78 
       
    79     // HbInputMethod specific operations.
       
    80     virtual bool isComposing() const {return false;}
       
    81     virtual void listInputModes(QVector<HbInputModeProperties>& modes) const = 0 ;
       
    82     virtual void mouseHandler(int x, QMouseEvent* mouseEvent);
       
    83     virtual bool filterEvent(const QEvent * event);
       
    84 
       
    85     // Utility functions.
       
    86     void commitFirstMappedNumber(int key);
       
    87     void getAndFilterCharactersBoundToKey(QStringList &list, Qt::Key key);
       
    88     QChar getNthCharacterInKey(int &index, int key);
       
    89     virtual void commitAndAppendString(const QString& string);
       
    90     virtual void commitAndUpdate(const QString& string, int replaceFrom = 0, int replaceLength = 0, bool isAsync = false);
       
    91     void sendAndUpdate(QEvent &event);
       
    92     virtual void setKeymap(const HbKeymap* keymap);
       
    93     virtual void characterPreviewAvailable(bool available);
       
    94 
       
    95 signals:
       
    96     // incase one mode handler is not capable of processing the events.
       
    97     // it can pass the event by sending following signals. And then it is 
       
    98     // upto the plugin to decide which two mode handlers needs to be connected.
       
    99     void passFilterEvent(const QKeyEvent *event);
       
   100     void passActionHandler(HbInputModeAction action);
       
   101 
       
   102 public slots:    
       
   103     virtual void sctCharacterSelected(QString character);
       
   104     // filterEvent function
       
   105     virtual bool filterEvent(const QKeyEvent * event);
       
   106     // Action handler for HbInputModeAction actions.
       
   107     virtual bool actionHandler(HbInputModeAction action);
       
   108     virtual void smileySelected(QString smiley);
       
   109     virtual void cursorPositionChanged(int oldPos, int newPos);
       
   110 protected:
       
   111     HbInputModeHandlerPrivate* const d_ptr;
       
   112     HbInputModeHandler(HbInputModeHandlerPrivate &dd, HbInputAbstractMethod* inputMethod);
       
   113 private:
       
   114     Q_DECLARE_PRIVATE_D(d_ptr, HbInputModeHandler)
       
   115     Q_DISABLE_COPY(HbInputModeHandler)
       
   116     Q_PRIVATE_SLOT(d_func(), virtual void _q_timeout())
       
   117 };
       
   118 
       
   119 // long press constant.
       
   120 const int HbLongPressTimerTimeout = 600;
       
   121 // multi tap constant
       
   122 const int HbMultiTapTimerTimeout = 600;
       
   123 
       
   124 // shift key states
       
   125 enum HbInputShiftKeyState {
       
   126     EKeyPressedNone,
       
   127     EShiftKeyPressed
       
   128 };
       
   129 
       
   130 const QString HbAutoCompleteVendorIdString("Nokia HbAutoComplete");
       
   131 
       
   132 /////////////////////////////////////////////////////////////////////////////////////
       
   133 ////////////////////////////// LATIN BASIC //////////////////////////////////////////
       
   134 /////////////////////////////////////////////////////////////////////////////////////
       
   135 class HbInputBasicHandlerPrivate;
       
   136 class HbInputBasicHandler: public HbInputModeHandler
       
   137 {
       
   138     Q_OBJECT
       
   139 public:
       
   140     HbInputBasicHandler(HbInputAbstractMethod* inputMethod);
       
   141     ~HbInputBasicHandler();
       
   142 
       
   143     bool actionHandler(HbInputModeAction action);
       
   144     bool filterEvent(const QKeyEvent * event);
       
   145 
       
   146     // automatic completion apis;
       
   147     void setUpAutoCompleter();
       
   148     void refreshAutoCompleter();
       
   149     void deleteCharacterInAutoCompleter();
       
   150     void appendUnicodeCharacterInAutoCompleter(QChar character);
       
   151     void addWordInAutoCompleter();
       
   152 
       
   153 public slots:
       
   154     void autoCompletionPopupClosed(QString activatedWord, int closingKey);
       
   155     void sctCharacterSelected(QString character);
       
   156     void smileySelected(QString character);
       
   157 protected:
       
   158     HbInputBasicHandler(HbInputBasicHandlerPrivate &dd, HbInputAbstractMethod* inputMethod);
       
   159 private:
       
   160     Q_DECLARE_PRIVATE_D(d_ptr, HbInputBasicHandler)
       
   161     Q_DISABLE_COPY(HbInputBasicHandler)
       
   162 };
       
   163 
       
   164 
       
   165 ////////////////////////////////////////////////////////////////////////////////////
       
   166 ////////////////////////////// PREDICTION //////////////////////////////////////////
       
   167 ////////////////////////////////////////////////////////////////////////////////////
       
   168 class HbInputPredictionHandlerPrivate;
       
   169 class HbInputPredictionHandler: public HbInputModeHandler
       
   170 {
       
   171     Q_OBJECT
       
   172 public:
       
   173     ~HbInputPredictionHandler();
       
   174 
       
   175     bool isComposing();
       
   176     void mouseHandler(int cursorPosition, QMouseEvent* mouseEvent);
       
   177     bool filterEvent(const QKeyEvent * event);
       
   178 
       
   179     // engine related information.
       
   180     QList<HbInputLanguage> supportedLanguages() const;
       
   181     bool actionHandler(HbInputModeAction action);
       
   182 
       
   183     // some utility functions
       
   184     void appendUnicodeCharacter(QChar character);
       
   185     void commitAndAppendCharacter(QChar character);
       
   186     virtual void deleteOneCharacter();
       
   187     virtual void processExactWord(QString exactWord);
       
   188     void commitExactWord();
       
   189     virtual void processCustomWord(QString customWord);
       
   190     virtual void candidatePopupClosed(QString activatedWord, int closingKey);
       
   191     virtual void showExactWordPopupIfNeeded();
       
   192 public slots:
       
   193     // different utility popup callbacks
       
   194     virtual void inputQueryPopupClosed(QString activatedWord, int closingKey);    
       
   195     void sctCharacterSelected(QString character);
       
   196     void smileySelected(QString smiley);
       
   197 signals://some useful signals related to popups
       
   198     void launchInputQueryPopup(QString editWord);
       
   199 
       
   200 protected:
       
   201     HbInputPredictionHandler(HbInputPredictionHandlerPrivate &dd, HbInputAbstractMethod* inputMethod);
       
   202 private:
       
   203     Q_DECLARE_PRIVATE_D(d_ptr, HbInputPredictionHandler)
       
   204     Q_DISABLE_COPY(HbInputPredictionHandler)
       
   205 };
       
   206 
       
   207 
       
   208 /////////////////////////////////////////////////////////////////////////////////////
       
   209 ////////////////////////////// Numeric //////////////////////////////////////////
       
   210 /////////////////////////////////////////////////////////////////////////////////////
       
   211 class HbInputNumericHandlerPrivate;
       
   212 class HbInputNumericHandler: public HbInputModeHandler
       
   213 {
       
   214     Q_OBJECT
       
   215 public:
       
   216     ~HbInputNumericHandler();
       
   217 
       
   218     bool actionHandler(HbInputModeAction action);
       
   219     bool filterEvent(const QKeyEvent * event);
       
   220 
       
   221 protected:
       
   222     HbInputNumericHandler(HbInputNumericHandlerPrivate &dd, HbInputAbstractMethod* inputMethod);
       
   223 private:
       
   224     Q_DECLARE_PRIVATE_D(d_ptr, HbInputNumericHandler)
       
   225     Q_DISABLE_COPY(HbInputNumericHandler)
       
   226 };
       
   227 
       
   228 #endif //hb_input_mode_handler