1 /***************************************************************************
2 **
3 ** Copyright (C) 2013 BlackBerry Limited. All rights reserved.
4 ** Contact: https://www.qt.io/licensing/
5 **
6 ** This file is part of the plugins of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and The Qt Company. For licensing terms
14 ** and conditions see https://www.qt.io/terms-conditions. For further
15 ** information use the contact form at https://www.qt.io/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 3 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL3 included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 3 requirements
23 ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24 **
25 ** GNU General Public License Usage
26 ** Alternatively, this file may be used under the terms of the GNU
27 ** General Public License version 2.0 or (at your option) the GNU General
28 ** Public license version 3 or any later version approved by the KDE Free
29 ** Qt Foundation. The licenses are as published by the Free Software
30 ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31 ** included in the packaging of this file. Please review the following
32 ** information to ensure the GNU General Public License requirements will
33 ** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34 ** https://www.gnu.org/licenses/gpl-3.0.html.
35 **
36 ** $QT_END_LICENSE$
37 **
38 ****************************************************************************/
39 
40 #include "qqnxinputcontext_noimf.h"
41 #include "qqnxabstractvirtualkeyboard.h"
42 #include "qqnxintegration.h"
43 #include "qqnxscreen.h"
44 
45 #include <QtCore/QDebug>
46 #include <QtGui/QGuiApplication>
47 #include <QtGui/QInputMethodEvent>
48 
49 #if defined(QQNXINPUTCONTEXT_DEBUG)
50 #define qInputContextDebug qDebug
51 #else
52 #define qInputContextDebug QT_NO_QDEBUG_MACRO
53 #endif
54 
55 QT_BEGIN_NAMESPACE
56 
QQnxInputContext(QQnxIntegration * integration,QQnxAbstractVirtualKeyboard & keyboard)57 QQnxInputContext::QQnxInputContext(QQnxIntegration *integration, QQnxAbstractVirtualKeyboard &keyboard) :
58     QPlatformInputContext(),
59     m_inputPanelVisible(false),
60     m_inputPanelLocale(QLocale::c()),
61     m_integration(integration),
62     m_virtualKeyboard(keyboard)
63 {
64     connect(&keyboard, SIGNAL(heightChanged(int)), this, SLOT(keyboardHeightChanged()));
65     connect(&keyboard, SIGNAL(visibilityChanged(bool)), this, SLOT(keyboardVisibilityChanged(bool)));
66     connect(&keyboard, SIGNAL(localeChanged(QLocale)), this, SLOT(keyboardLocaleChanged(QLocale)));
67     keyboardVisibilityChanged(keyboard.isVisible());
68     keyboardLocaleChanged(keyboard.locale());
69 }
70 
~QQnxInputContext()71 QQnxInputContext::~QQnxInputContext()
72 {
73 }
74 
isValid() const75 bool QQnxInputContext::isValid() const
76 {
77     return true;
78 }
79 
hasPhysicalKeyboard()80 bool QQnxInputContext::hasPhysicalKeyboard()
81 {
82     // TODO: This should query the system to check if a USB keyboard is connected.
83     return false;
84 }
85 
reset()86 void QQnxInputContext::reset()
87 {
88 }
89 
filterEvent(const QEvent * event)90 bool QQnxInputContext::filterEvent( const QEvent *event )
91 {
92     if (hasPhysicalKeyboard())
93         return false;
94 
95     if (event->type() == QEvent::CloseSoftwareInputPanel) {
96         m_virtualKeyboard.hideKeyboard();
97         qInputContextDebug("hiding virtual keyboard");
98         return false;
99     }
100 
101     if (event->type() == QEvent::RequestSoftwareInputPanel) {
102         m_virtualKeyboard.showKeyboard();
103         qInputContextDebug("requesting virtual keyboard");
104         return false;
105     }
106 
107     return false;
108 
109 }
110 
keyboardRect() const111 QRectF QQnxInputContext::keyboardRect() const
112 {
113     QRect screenGeometry = m_integration->primaryDisplay()->geometry();
114     return QRectF(screenGeometry.x(), screenGeometry.height() - m_virtualKeyboard.height(),
115                   screenGeometry.width(), m_virtualKeyboard.height());
116 }
117 
handleKeyboardEvent(int flags,int sym,int mod,int scan,int cap)118 bool QQnxInputContext::handleKeyboardEvent(int flags, int sym, int mod, int scan, int cap)
119 {
120     Q_UNUSED(flags);
121     Q_UNUSED(sym);
122     Q_UNUSED(mod);
123     Q_UNUSED(scan);
124     Q_UNUSED(cap);
125     return false;
126 }
127 
showInputPanel()128 void QQnxInputContext::showInputPanel()
129 {
130     qInputContextDebug();
131     m_virtualKeyboard.showKeyboard();
132 }
133 
hideInputPanel()134 void QQnxInputContext::hideInputPanel()
135 {
136     qInputContextDebug();
137     m_virtualKeyboard.hideKeyboard();
138 }
139 
isInputPanelVisible() const140 bool QQnxInputContext::isInputPanelVisible() const
141 {
142     return m_inputPanelVisible;
143 }
144 
locale() const145 QLocale QQnxInputContext::locale() const
146 {
147     return m_inputPanelLocale;
148 }
149 
keyboardHeightChanged()150 void QQnxInputContext::keyboardHeightChanged()
151 {
152     emitKeyboardRectChanged();
153 }
154 
keyboardVisibilityChanged(bool visible)155 void QQnxInputContext::keyboardVisibilityChanged(bool visible)
156 {
157     qInputContextDebug() << "visible=" << visible;
158     if (m_inputPanelVisible != visible) {
159         m_inputPanelVisible = visible;
160         emitInputPanelVisibleChanged();
161     }
162 }
163 
keyboardLocaleChanged(const QLocale & locale)164 void QQnxInputContext::keyboardLocaleChanged(const QLocale &locale)
165 {
166     qInputContextDebug() << "locale=" << locale;
167     if (m_inputPanelLocale != locale) {
168         m_inputPanelLocale = locale;
169         emitLocaleChanged();
170     }
171 }
172 
setFocusObject(QObject * object)173 void QQnxInputContext::setFocusObject(QObject *object)
174 {
175     qInputContextDebug() << "input item=" << object;
176 
177     if (!inputMethodAccepted()) {
178         if (m_inputPanelVisible)
179             hideInputPanel();
180     } else {
181         QInputMethodQueryEvent query(Qt::ImHints | Qt::ImEnterKeyType);
182         QCoreApplication::sendEvent(object, &query);
183         int inputHints = query.value(Qt::ImHints).toInt();
184         Qt::EnterKeyType qtEnterKeyType = Qt::EnterKeyType(query.value(Qt::ImEnterKeyType).toInt());
185 
186         m_virtualKeyboard.setInputHints(inputHints);
187         m_virtualKeyboard.setEnterKeyType(
188             QQnxAbstractVirtualKeyboard::qtEnterKeyTypeToQnx(qtEnterKeyType)
189         );
190 
191         if (!m_inputPanelVisible)
192             showInputPanel();
193     }
194 }
195 
196 QT_END_NAMESPACE
197