src/hbcore/inputfw/hbinputcontextproxy.cpp
changeset 6 c3690ec91ef8
parent 5 627c4a0fd0e7
child 7 923ff622b8b9
equal deleted inserted replaced
5:627c4a0fd0e7 6:c3690ec91ef8
    27 #include <hbgraphicsscene.h>
    27 #include <hbgraphicsscene.h>
    28 #include <hbinputfocusobject.h>
    28 #include <hbinputfocusobject.h>
    29 #include <QGraphicsProxyWidget>
    29 #include <QGraphicsProxyWidget>
    30 #include <QGraphicsView>
    30 #include <QGraphicsView>
    31 #include <hbinputmethod.h>
    31 #include <hbinputmethod.h>
       
    32 #include <hbinputsettingproxy.h>
    32 
    33 
    33 /*!
    34 /*!
    34 @alpha
    35 @alpha
    35 @hbcore
    36 @hbcore
    36 \class HbInputContextProxy
    37 \class HbInputContextProxy
    48 
    49 
    49 \sa QInputContext
    50 \sa QInputContext
    50 \sa HbInputMethod
    51 \sa HbInputMethod
    51 */
    52 */
    52 
    53 
    53 HbInputContextProxy::HbInputContextProxy(HbInputMethod* target) : mTarget(target)
    54 HbInputContextProxy::HbInputContextProxy(HbInputMethod *target) : mTarget(target)
    54 {
    55 {
    55 }
    56 }
    56 
    57 
    57 HbInputContextProxy::~HbInputContextProxy()
    58 HbInputContextProxy::~HbInputContextProxy()
    58 {
    59 {
    66 {
    67 {
    67     if (mTarget) {
    68     if (mTarget) {
    68         return mTarget->actions();
    69         return mTarget->actions();
    69     }
    70     }
    70 
    71 
    71     return QList<QAction*>();
    72     return QList<QAction *>();
    72 }
    73 }
    73 
    74 
    74 /*!
    75 /*!
    75 \internal
    76 \internal
    76 Returns true if given editor widget already has input framework focus.
    77 Returns true if given editor widget already has input framework focus.
    91 \internal
    92 \internal
    92 Sets input framework focus to given widget if it is valid.
    93 Sets input framework focus to given widget if it is valid.
    93 */
    94 */
    94 void HbInputContextProxy::setInputFrameworkFocus(QObject *widget)
    95 void HbInputContextProxy::setInputFrameworkFocus(QObject *widget)
    95 {
    96 {
    96     if(mTarget) {
    97     if (mTarget) {
    97         if(!widget) {
    98         if (!widget) {
    98             mTarget->setFocusObject(0);
    99             mTarget->setFocusObject(0);
    99         } else if (HbInputFocusObject::isEditor(widget) && !HbInputFocusObject::isReadOnlyWidget(widget)) {           
   100         } else if (HbInputFocusObject::isEditor(widget) && !HbInputFocusObject::isReadOnlyWidget(widget)) {
   100             mTarget->setFocusObject(new HbInputFocusObject(widget));
   101             mTarget->setFocusObject(new HbInputFocusObject(widget));
   101         }
   102         }
   102     }
   103     }
   103 }
   104 }
   104 
   105 
   105 /*!
   106 /*!
   106 \internal
   107 \internal
   107 \reimp
   108 \reimp
   108 */
   109 */
   109 bool HbInputContextProxy::filterEvent(const QEvent* event)
   110 bool HbInputContextProxy::filterEvent(const QEvent *event)
   110 {
   111 {
   111     if (mTarget) {
   112     if (mTarget) {
   112 #if QT_VERSION >= 0x040600
   113 #if QT_VERSION >= 0x040600
   113         if (event->type() == QEvent::CloseSoftwareInputPanel) {
   114         bool orientationCompleted = HbInputSettingProxy::instance()->orientationChangeCompleted();
       
   115         if (event->type() == QEvent::CloseSoftwareInputPanel && orientationCompleted) {
   114             setInputFrameworkFocus(0);
   116             setInputFrameworkFocus(0);
   115             return true;            
   117             return true;
   116         } else if (event->type() == QEvent::RequestSoftwareInputPanel) {           
   118         } else if (event->type() == QEvent::RequestSoftwareInputPanel && orientationCompleted) {           
   117             if(QWidget * focusedWidget =  qApp->focusWidget()) {
   119             if (QWidget *focusedWidget =  qApp->focusWidget()) {
   118                 // see if the focused widget is graphics view, if so get the focused graphics item in the view
   120                 // see if the focused widget is graphics view, if so get the focused graphics item in the view
   119                 // and acivate inputmethod for the focused graphics item
   121                 // and acivate inputmethod for the focused graphics item
   120                 if (QGraphicsView * graphicsView = qobject_cast<QGraphicsView*>(focusedWidget)) {
   122                 if (QGraphicsView *graphicsView = qobject_cast<QGraphicsView *>(focusedWidget)) {
   121                     if (QGraphicsScene * scene = graphicsView->scene()) {
   123                     if (QGraphicsScene *scene = graphicsView->scene()) {
   122                         if (QGraphicsItem * fItem = scene->focusItem()) {
   124                         if (QGraphicsItem *fItem = scene->focusItem()) {
   123                             QGraphicsProxyWidget *proxy  = qgraphicsitem_cast<QGraphicsProxyWidget *>(fItem);
   125                             QGraphicsProxyWidget *proxy  = qgraphicsitem_cast<QGraphicsProxyWidget *>(fItem);
   124                             if (proxy) {    
   126                             if (proxy) {
   125                                 setInputFrameworkFocus(proxy->widget()->focusWidget());
   127                                 setInputFrameworkFocus(proxy->widget()->focusWidget());
   126                             } else {
   128                             } else {
   127                                 setInputFrameworkFocus(static_cast<QGraphicsWidget*>(fItem));
   129                                 setInputFrameworkFocus(static_cast<QGraphicsWidget *>(fItem));
   128                             }
   130                             }
   129                         }
   131                         }
   130                     }
   132                     }
   131                 } else {
   133                 } else {
   132                     // focused wiget is not graphics view, let see if it is native qt editor
   134                     // focused wiget is not graphics view, let see if it is native qt editor
   140 
   142 
   141 #ifdef Q_OS_SYMBIAN
   143 #ifdef Q_OS_SYMBIAN
   142         const quint32 HbInputContextProxyExternalKeyboardModifier = 0x00200000;
   144         const quint32 HbInputContextProxyExternalKeyboardModifier = 0x00200000;
   143 
   145 
   144         if (event->type() == QEvent::QEvent::KeyPress || event->type() == QEvent::KeyRelease) {
   146         if (event->type() == QEvent::QEvent::KeyPress || event->type() == QEvent::KeyRelease) {
   145             const QKeyEvent *keyEvent = static_cast<const QKeyEvent*>(event);
   147             const QKeyEvent *keyEvent = static_cast<const QKeyEvent *>(event);
   146             if (keyEvent->nativeModifiers() & HbInputContextProxyExternalKeyboardModifier) {
   148             if (keyEvent->nativeModifiers() & HbInputContextProxyExternalKeyboardModifier) {
   147                 // Operating system indicates that the event originated from an external keyboard.
   149                 // Operating system indicates that the event originated from an external keyboard.
   148                 // We let it pass here untouched.
   150                 // We let it pass here untouched.
   149                 if (mTarget) {
   151                 if (mTarget) {
   150                     mTarget->reset();
   152                     mTarget->reset();
   151                 }
   153                 }
   152                 return false;
   154                 return false;
   153 			}
   155             }
   154 		} 
   156         }
   155 #endif
   157 #endif
   156 		if(event->type() == QEvent::KeyPress || event->type() == QEvent::KeyRelease) {
   158         if (event->type() == QEvent::KeyPress || event->type() == QEvent::KeyRelease) {
   157 			const QKeyEvent *keyEvent = static_cast<const QKeyEvent *>(event);
   159             const QKeyEvent *keyEvent = static_cast<const QKeyEvent *>(event);
   158 			if (Qt::Key_unknown == keyEvent->key()) {
   160             if (Qt::Key_unknown == keyEvent->key()) {
   159 				return false;
   161                 return false;
   160 			}
   162             }
   161 		}
   163         }
   162 		return mTarget->filterEvent(event);
   164         return mTarget->filterEvent(event);
   163 	}
   165     }
   164 
   166 
   165 	return false;
   167     return false;
   166 }
   168 }
   167 
   169 
   168 /*!
   170 /*!
   169 \internal
   171 \internal
   170 \reimp
   172 \reimp
   207 /*!
   209 /*!
   208 \internal
   210 \internal
   209 \reimp
   211 \reimp
   210 */
   212 */
   211 QString HbInputContextProxy::language()
   213 QString HbInputContextProxy::language()
   212 {   
   214 {
   213     if (mTarget) {
   215     if (mTarget) {
   214         return mTarget->language();
   216         return mTarget->language();
   215     }
   217     }
   216 
   218 
   217     return QString();
   219     return QString();
   219 
   221 
   220 /*!
   222 /*!
   221 \internal
   223 \internal
   222 \reimp
   224 \reimp
   223 */
   225 */
   224 void HbInputContextProxy::mouseHandler(int x, QMouseEvent* event)
   226 void HbInputContextProxy::mouseHandler(int x, QMouseEvent *event)
   225 {
   227 {
   226     if (mTarget) {
   228     if (mTarget) {
   227         mTarget->mouseHandler(x, event);
   229         mTarget->mouseHandler(x, event);
   228     }
   230     }
   229 }
   231 }
   241 
   243 
   242 /*!
   244 /*!
   243 \internal
   245 \internal
   244 \reimp
   246 \reimp
   245 */
   247 */
   246 void HbInputContextProxy::sendEvent(const QInputMethodEvent& event)
   248 void HbInputContextProxy::sendEvent(const QInputMethodEvent &event)
   247 {
   249 {
   248     if (mTarget) {
   250     if (mTarget) {
   249         mTarget->sendEvent(event);
   251         mTarget->sendEvent(event);
   250     }
   252     }
   251 }
   253 }
   263 
   265 
   264 /*!
   266 /*!
   265 \internal
   267 \internal
   266 \reimp
   268 \reimp
   267 */
   269 */
   268 void HbInputContextProxy::widgetDestroyed(QWidget* widget)
   270 void HbInputContextProxy::widgetDestroyed(QWidget *widget)
   269 {
   271 {
   270     if (mTarget) {
   272     if (mTarget) {
   271         mTarget->widgetDestroyed(widget);
   273         mTarget->widgetDestroyed(widget);
   272     }
   274     }
   273 }
   275 }
   274 
   276 
   275 /*!
   277 /*!
   276 \internal
   278 \internal
   277 \reimp
   279 \reimp
   278 */
   280 */
   279 void HbInputContextProxy::setFocusWidget(QWidget* widget)
   281 void HbInputContextProxy::setFocusWidget(QWidget *widget)
   280 {
   282 {
   281     if (mTarget) {
   283     if (mTarget) {
   282         mTarget->setFocusWidget(widget);
   284         mTarget->setFocusWidget(widget);
   283     }
   285     }
   284 }
   286 }