src/hbcore/inputfw/hbinputcontextproxy.cpp
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 HbCore 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 "hbinputcontextproxy_p.h"
       
    26 #include <hbwidget.h>
       
    27 #include <hbgraphicsscene.h>
       
    28 #include <hbinputfocusobject.h>
       
    29 #include <QGraphicsProxyWidget>
       
    30 #include <QGraphicsView>
       
    31 #include <hbinputmethod.h>
       
    32 
       
    33 /*!
       
    34 @alpha
       
    35 @hbcore
       
    36 \class HbInputContextProxy
       
    37 \brief A proxy class forwarding class from QInputContext to HbInputMethod
       
    38 
       
    39 This class is needed because Qt's input context system assumes the ownership
       
    40 of the installed context and deletes the old one when a new context is installed.
       
    41 HbInput framework wants to cache active input context entities to its local
       
    42 memory structures and keep the ownership of those objects. That's why a proxy object
       
    43 is installed between QInputContext and HbInputMehod classes. When Qt's
       
    44 input context system deletes old context, it will delete the proxy instead of
       
    45 real implementation.
       
    46 
       
    47 We also handle certain common events (such as Qt's input panel events) on this level.
       
    48 This class is not needed outside of framework code.
       
    49 
       
    50 \sa QInputContext
       
    51 \sa HbInputMethod
       
    52 */
       
    53 
       
    54 HbInputContextProxy::HbInputContextProxy(HbInputMethod* target) : mTarget(target)
       
    55 {
       
    56 }
       
    57 
       
    58 HbInputContextProxy::~HbInputContextProxy()
       
    59 {
       
    60 }
       
    61 
       
    62 /*!
       
    63 \internal
       
    64 \reimp
       
    65 */
       
    66 QList<QAction *> HbInputContextProxy::actions()
       
    67 {
       
    68     if (mTarget) {
       
    69         return mTarget->actions();
       
    70     }
       
    71 
       
    72     return QList<QAction*>();
       
    73 }
       
    74 
       
    75 /*!
       
    76 \internal
       
    77 Returns true if given editor widget already has input framework focus.
       
    78 */
       
    79 bool HbInputContextProxy::hasAlreadyInputFrameworkFocus(HbInputMethod *activeMethod, QObject *editorWidget) const
       
    80 {
       
    81     if (activeMethod) {
       
    82         HbInputFocusObject *focusObject = activeMethod->focusObject();
       
    83         if (focusObject) {
       
    84             return focusObject->object() == editorWidget;
       
    85         }
       
    86     }
       
    87 
       
    88     return false;
       
    89 }
       
    90 
       
    91 /*!
       
    92 \internal
       
    93 Sets input framework focus to given widget if it is valid.
       
    94 */
       
    95 void HbInputContextProxy::setInputFrameworkFocus(QObject *widget)
       
    96 {
       
    97     if(mTarget) {
       
    98         if(!widget) {
       
    99             mTarget->setFocusObject(0);
       
   100         } else if (HbInputFocusObject::isEditor(widget) && !HbInputFocusObject::isReadOnlyWidget(widget)) {           
       
   101             mTarget->setFocusObject(new HbInputFocusObject(widget));
       
   102         }
       
   103     }
       
   104 }
       
   105 
       
   106 /*!
       
   107 \internal
       
   108 \reimp
       
   109 */
       
   110 bool HbInputContextProxy::filterEvent(const QEvent* event)
       
   111 {
       
   112     if (mTarget) {
       
   113 #if QT_VERSION >= 0x040600
       
   114         if (event->type() == QEvent::CloseSoftwareInputPanel) {
       
   115             setInputFrameworkFocus(0);
       
   116             return true;
       
   117         } else if (event->type() == QEvent::RequestSoftwareInputPanel) {
       
   118             if(QWidget * focusedWidget =  qApp->focusWidget()) {
       
   119                 // see if the focused widget is graphics view, if so get the focused graphics item in the view
       
   120                 // and acivate inputmethod for the focused graphics item
       
   121                 if(QGraphicsView * graphicsView = qobject_cast<QGraphicsView*>(focusedWidget)) {
       
   122                     if(QGraphicsScene * scene = graphicsView->scene()) {
       
   123                         if(QGraphicsItem * focusingWidget = scene->focusItem()) {
       
   124                             if (focusingWidget->isWidget()) {
       
   125                                 setInputFrameworkFocus(static_cast<QGraphicsWidget*>(focusingWidget));
       
   126                             }
       
   127                         }
       
   128                     }
       
   129                 } else {
       
   130                     // focused wiget is not graphics view, let see if it is native qt editor
       
   131                     // and activate inputmethod for the focused widget
       
   132                     setInputFrameworkFocus(focusedWidget);
       
   133                 }
       
   134             }
       
   135             return true;
       
   136         }
       
   137 #endif
       
   138 
       
   139 #ifdef Q_OS_SYMBIAN
       
   140         const quint32 HbInputContextProxyExternalKeyboardModifier = 0x00200000;
       
   141 
       
   142         if (event->type() == QEvent::QEvent::KeyPress || event->type() == QEvent::KeyRelease) {
       
   143             const QKeyEvent *keyEvent = static_cast<const QKeyEvent*>(event);
       
   144             if (keyEvent->nativeModifiers() & HbInputContextProxyExternalKeyboardModifier) {
       
   145                 // Operating system indicates that the event originated from an external keyboard.
       
   146                 // We let it pass here untouched.
       
   147                 if (mTarget) {
       
   148                     mTarget->reset();
       
   149                 }
       
   150                 return false;
       
   151             }
       
   152         } 
       
   153 #endif
       
   154 
       
   155         return mTarget->filterEvent(event);
       
   156     }
       
   157 
       
   158     return false;
       
   159 }
       
   160 
       
   161 /*!
       
   162 \internal
       
   163 \reimp
       
   164 */
       
   165 QFont HbInputContextProxy::font() const
       
   166 {
       
   167     if (mTarget) {
       
   168         return mTarget->font();
       
   169     }
       
   170 
       
   171     return QFont();
       
   172 }
       
   173 
       
   174 /*!
       
   175 \internal
       
   176 \reimp
       
   177 */
       
   178 QString HbInputContextProxy::identifierName()
       
   179 {
       
   180     if (mTarget) {
       
   181         return mTarget->identifierName();
       
   182     }
       
   183 
       
   184     return QString();
       
   185 }
       
   186 
       
   187 /*!
       
   188 \internal
       
   189 \reimp
       
   190 */
       
   191 bool HbInputContextProxy::isComposing() const
       
   192 {
       
   193     if (mTarget) {
       
   194         return mTarget->isComposing();
       
   195     }
       
   196 
       
   197     return false;
       
   198 }
       
   199 
       
   200 /*!
       
   201 \internal
       
   202 \reimp
       
   203 */
       
   204 QString HbInputContextProxy::language()
       
   205 {   
       
   206     if (mTarget) {
       
   207         return mTarget->language();
       
   208     }
       
   209 
       
   210     return QString();
       
   211 }
       
   212 
       
   213 /*!
       
   214 \internal
       
   215 \reimp
       
   216 */
       
   217 void HbInputContextProxy::mouseHandler(int x, QMouseEvent* event)
       
   218 {
       
   219     if (mTarget) {
       
   220         mTarget->mouseHandler(x, event);
       
   221     }
       
   222 }
       
   223 
       
   224 /*!
       
   225 \internal
       
   226 \reimp
       
   227 */
       
   228 void HbInputContextProxy::reset()
       
   229 {
       
   230     if (mTarget) {
       
   231         mTarget->reset();
       
   232     }
       
   233 }
       
   234 
       
   235 /*!
       
   236 \internal
       
   237 \reimp
       
   238 */
       
   239 void HbInputContextProxy::sendEvent(const QInputMethodEvent& event)
       
   240 {
       
   241     if (mTarget) {
       
   242         mTarget->sendEvent(event);
       
   243     }
       
   244 }
       
   245 
       
   246 /*!
       
   247 \internal
       
   248 \reimp
       
   249 */
       
   250 void HbInputContextProxy::update()
       
   251 {
       
   252     if (mTarget) {
       
   253         mTarget->update();
       
   254     }
       
   255 }
       
   256 
       
   257 /*!
       
   258 \internal
       
   259 \reimp
       
   260 */
       
   261 void HbInputContextProxy::widgetDestroyed(QWidget* widget)
       
   262 {
       
   263     if (mTarget) {
       
   264         mTarget->widgetDestroyed(widget);
       
   265     }
       
   266 }
       
   267 
       
   268 /*!
       
   269 \internal
       
   270 \reimp
       
   271 */
       
   272 void HbInputContextProxy::setFocusWidget(QWidget* widget)
       
   273 {
       
   274     if (mTarget) {
       
   275         mTarget->setFocusWidget(widget);
       
   276     }
       
   277 }
       
   278 
       
   279 // End of file