src/hbplugins/inputmethods/common/hbinputspellquerydialog.cpp
branchGCC_SURGE
changeset 15 f378acbc9cfb
parent 7 923ff622b8b9
child 21 4633027730f5
child 34 ed14f46c0e55
equal deleted inserted replaced
9:730c025d4b77 15:f378acbc9cfb
       
     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 static const qint16 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     // Open keypad for the spell query
       
   101     QInputContext *ic = qApp->inputContext();
       
   102     if (ic) {
       
   103         QEvent *event = new QEvent(QEvent::RequestSoftwareInputPanel);
       
   104         ic->filterEvent(event);
       
   105         delete event;
       
   106     }
       
   107 }
       
   108 
       
   109 void HbInputSpellQuery::dialogClosed(HbAction* action)
       
   110 {
       
   111     mainWindow()->setProperty("SpellQueryLaunched", false);
       
   112     //There are multiple dialog closed event received. This will make sure we handle finish
       
   113     //only once
       
   114     if(mDidHandleFinish) {
       
   115         return;
       
   116     } else {
       
   117         mDidHandleFinish = true;
       
   118     }
       
   119 
       
   120     HbSpellCloseReason closeReason = HbForceClose;
       
   121     QString string = mSavedEditorText;
       
   122     // action is null when input query is closed externally , for example by calling
       
   123     // HbDialog::close() function.
       
   124     if (action) {
       
   125         if(mPrimaryAction == action) {
       
   126             closeReason = HbOkPressed;
       
   127             string = value().toString();
       
   128         } else {
       
   129             closeReason = HbCancelPressed;
       
   130         }
       
   131     }
       
   132     //Need to disable effects as asynchronous hide will commit the word otherwise.
       
   133     HbEffect::disable(this);
       
   134     hide();
       
   135     HbEffect::enable(this);  
       
   136 
       
   137     mPredictionHandler->spellQueryDialogClosed(mSavedFocusObject,closeReason,string);
       
   138     mSavedFocusObject = 0;
       
   139     mSavedEditorText.clear();
       
   140     mPrimaryAction = 0;
       
   141 }
       
   142 
       
   143 // End of file