src/hbplugins/inputmethods/common/hbinputspellquerydialog.cpp
changeset 5 627c4a0fd0e7
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 #include <QGraphicsScene>
       
    27 #include <hbinputmethod.h>
       
    28 #include <hbinputkeymapfactory.h>
       
    29 #include <hbinputpredictionengine.h>
       
    30 #include <hbinputsettingproxy.h>
       
    31 #include <hbinputvirtualkeyboard.h>
       
    32 #include <hbinputvkbhost.h>
       
    33 #include <hbaction.h>
       
    34 #include <hbmainwindow.h>
       
    35 #include <hbinstance.h>
       
    36 #include <hbeffect.h>
       
    37 #include <hbinputregioncollector_p.h>
       
    38 
       
    39 #include "hbinputspellquerydialog.h"
       
    40 #include "hbinputmodehandler.h"
       
    41 
       
    42 #define MAXUDBWORDSIZE 64
       
    43 
       
    44 HbInputSpellQuery::HbInputSpellQuery(HbInputMethod *inputMethod, HbInputPredictionHandler *predictionHandler)
       
    45  : mOwner(inputMethod), mPredictionHandler(predictionHandler), mPrimaryAction(0) 
       
    46 {
       
    47     setInputMode(HbInputDialog::TextInput);
       
    48     setPromptText(tr("Word:"));
       
    49     setActive(true);
       
    50     HbInputRegionCollector::instance()->attach(this);
       
    51 }
       
    52 
       
    53 HbInputSpellQuery::~HbInputSpellQuery()
       
    54 {
       
    55 }
       
    56 
       
    57 void HbInputSpellQuery::launch(QString editorText)
       
    58 {
       
    59     HbInputFocusObject *focusObject = 0;
       
    60     if (!mOwner || !(focusObject = mOwner->focusObject())) {
       
    61         return;
       
    62     }
       
    63     mSavedState = mOwner->inputState();
       
    64     // close the keypad before showing the spell dialog
       
    65     HbVkbHost *vkbHost = focusObject->editorInterface().vkbHost();
       
    66     if (vkbHost && vkbHost->keypadStatus() != HbVkbHost::HbVkbStatusClosed) {
       
    67         vkbHost->closeKeypad();
       
    68     }
       
    69 
       
    70     setValue(QVariant(editorText));
       
    71 
       
    72     // set the spell dialog position
       
    73     QPointF newPos((qreal)HbDeviceProfile::current().logicalSize().width() * 0.5,
       
    74                    (qreal)HbDeviceProfile::current().logicalSize().height() * 0.5);
       
    75     if (vkbHost) {
       
    76         newPos.setY(((qreal)HbDeviceProfile::current().logicalSize().height() -
       
    77                     vkbHost->activeKeypad()->preferredKeyboardSize().height()) * 0.5);
       
    78     }
       
    79     setPreferredPos(newPos, HbPopup::Center);
       
    80 
       
    81     // change the focus to spell dialog editor
       
    82     HbLineEdit *spellEdit = lineEdit();
       
    83     if (spellEdit) {
       
    84         spellEdit->setMaxLength(MAXUDBWORDSIZE);
       
    85         spellEdit->setSmileysEnabled(false);
       
    86         HbEditorInterface eInt(spellEdit);
       
    87         // we don't want prediction and automatic textcase in spell query dialog
       
    88         spellEdit->setInputMethodHints(spellEdit->inputMethodHints() | Qt::ImhNoPredictiveText | Qt::ImhNoAutoUppercase);
       
    89         eInt.setLastFocusedState(mSavedState);
       
    90         spellEdit->setFocus();
       
    91     }
       
    92     // execute the spell dialog
       
    93     mSavedFocusObject = focusObject->object();
       
    94     mSavedEditorText = editorText;
       
    95     mDidHandleFinish = false;
       
    96     mainWindow()->setProperty("SpellQueryLaunched", true);
       
    97     open(this,SLOT(dialogClosed(HbAction*)));
       
    98     mPrimaryAction = qobject_cast<HbAction*>(actions().first()); 
       
    99 }
       
   100 
       
   101 void HbInputSpellQuery::dialogClosed(HbAction* action)
       
   102 {
       
   103     mainWindow()->setProperty("SpellQueryLaunched", false);
       
   104     //There are multiple dialog closed event received. This will make sure we handle finish
       
   105     //only once
       
   106     if(mDidHandleFinish) {
       
   107         return;
       
   108     } else {
       
   109         mDidHandleFinish = true;
       
   110     }
       
   111 
       
   112     bool isOk = false;
       
   113     bool isCancel = false;
       
   114     bool isExternalClose = false;
       
   115     // action is null when input query is closed externally , for example by calling
       
   116     // HbDialog::close() function.
       
   117     if (action) {
       
   118         isOk = mPrimaryAction == action ? true : false; 
       
   119         isCancel = mPrimaryAction != action ? true : false; 
       
   120     } else {
       
   121         isExternalClose = true;
       
   122     }
       
   123 
       
   124     //Need to disable effects as asynchronous hide will commit the word otherwise.
       
   125     HbEffect::disable(this);
       
   126     hide();
       
   127     HbEffect::enable(this);  
       
   128 
       
   129     QString string = mSavedEditorText;
       
   130     bool status = false;
       
   131     if (isOk) {
       
   132         string = value().toString();
       
   133         status = true;
       
   134     } else if (isCancel) {
       
   135         status = false;
       
   136     } else if (isExternalClose) {
       
   137         status = true;
       
   138     }
       
   139     mPredictionHandler->spellQueryDialogClosed(mSavedFocusObject,status,string);
       
   140     mSavedFocusObject = 0;
       
   141     mSavedEditorText.clear();
       
   142     mPrimaryAction = 0;
       
   143 }
       
   144 
       
   145 // End of file