1 /****************************************************************************
3 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
7 ** This file is part of the examples of the Qt Toolkit.
9 ** $QT_BEGIN_LICENSE:LGPL$
10 ** No Commercial Usage
11 ** This file contains pre-release code and may not be distributed.
12 ** You may use this file in accordance with the terms and conditions
13 ** contained in the Technology Preview License Agreement accompanying
16 ** GNU Lesser General Public License Usage
17 ** Alternatively, this file may be used under the terms of the GNU Lesser
18 ** General Public License version 2.1 as published by the Free Software
19 ** Foundation and appearing in the file LICENSE.LGPL included in the
20 ** packaging of this file. Please review the following information to
21 ** ensure the GNU Lesser General Public License version 2.1 requirements
22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 ** In addition, as a special exception, Nokia gives you certain additional
25 ** rights. These rights are described in the Nokia Qt LGPL Exception
26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 ** If you have questions regarding the use of this file, please contact
29 ** Nokia at qt-info@nokia.com.
40 ****************************************************************************/
42 #include "declarativeinputcontext.h"
44 #include "inputcontextmodule.h"
45 #include "inputcontextfilter.h"
47 #include <QtCore/qdebug.h>
51 DeclarativeInputContext::DeclarativeInputContext(QObject *parent)
52 : QInputContext(parent)
57 DeclarativeInputContext::~DeclarativeInputContext()
61 bool DeclarativeInputContext::isComposing() const
63 return m_module && !m_module->preeditText().isEmpty();
66 QString DeclarativeInputContext::identifierName()
68 return QLatin1String("Qt.labs.inputcontext/1.0");
71 QString DeclarativeInputContext::language()
76 void DeclarativeInputContext::setFocusWidget(QWidget *widget)
78 QInputContext::setFocusWidget(widget);
81 m_module->setFocusWidget(widget);
84 void DeclarativeInputContext::mouseHandler(int x, QMouseEvent *event)
86 if (!m_mouseHandlers.isEmpty()) {
87 InputContextMouseEvent me(*event);
88 foreach (InputContextMouseHandler *handler, m_mouseHandlers) {
89 handler->processEvent(event->type(), x, &me);
90 if (me.isAccepted()) {
91 event->setAccepted(true);
98 bool DeclarativeInputContext::filterMouseEvent(const QMouseEvent *event)
100 if (!m_mouseFilters.isEmpty()) {
101 InputContextMouseEvent me(*event);
102 foreach (InputContextMouseFilter *filter, m_mouseFilters) {
103 filter->processEvent(event->type(), &me);
112 bool DeclarativeInputContext::filterKeyEvent(const QKeyEvent *event)
114 if (!m_keyFilters.isEmpty()) {
115 InputContextKeyEvent ke(*event);
116 foreach (InputContextKeyFilter *filter, m_keyFilters) {
117 filter->processEvent(event->type(), &ke);
125 bool DeclarativeInputContext::filterEvent(const QEvent *event)
127 switch (event->type()) {
128 case QEvent::RequestSoftwareInputPanel:
130 m_module->setVisible(true);
132 case QEvent::CloseSoftwareInputPanel:
134 m_module->setVisible(false);
136 case QEvent::MouseButtonPress:
137 case QEvent::MouseButtonRelease:
138 case QEvent::MouseButtonDblClick:
139 case QEvent::MouseMove:
140 return filterMouseEvent(static_cast<const QMouseEvent *>(event));
141 case QEvent::KeyPress:
142 case QEvent::KeyRelease:
143 return filterKeyEvent(static_cast<const QKeyEvent *>(event));
149 void DeclarativeInputContext::reset()
155 void DeclarativeInputContext::update()
161 void DeclarativeInputContext::setModule(InputContextModule *module)
166 void DeclarativeInputContext::registerMouseHandler(InputContextMouseHandler *handler)
168 connect(handler, SIGNAL(destroyed(QObject*)), this, SLOT(mouseHandlerDestroyed(QObject*)));
169 m_mouseHandlers.append(handler);
172 void DeclarativeInputContext::registerMouseFilter(InputContextMouseFilter *filter)
174 connect(filter, SIGNAL(destroyed(QObject*)), this, SLOT(mouseFilterDestroyed(QObject*)));
175 m_mouseFilters.append(filter);
178 void DeclarativeInputContext::registerKeyFilter(InputContextKeyFilter *filter)
180 connect(filter, SIGNAL(destroyed(QObject*)), this, SLOT(keyFilterDestroyed(QObject*)));
181 m_keyFilters.append(filter);
184 void DeclarativeInputContext::mouseHandlerDestroyed(QObject *handler)
186 m_mouseHandlers.removeAll(static_cast<InputContextMouseHandler *>(handler));
189 void DeclarativeInputContext::mouseFilterDestroyed(QObject *filter)
191 m_mouseFilters.removeAll(static_cast<InputContextMouseFilter *>(filter));
194 void DeclarativeInputContext::keyFilterDestroyed(QObject *filter)
196 m_keyFilters.removeAll(static_cast<InputContextKeyFilter *>(filter));