diff options
author | Lars Knoll <lars.knoll@nokia.com> | 2011-06-21 16:00:36 +0200 |
---|---|---|
committer | Lars Knoll <lars.knoll@nokia.com> | 2011-06-22 10:46:12 +0200 |
commit | 4363d836f6a2b245e8e12d1e5eb08db791e95fce (patch) | |
tree | 6b14e2e3b03d42ecd7dad378ba87d85276f19c90 /src/widgets/kernel | |
parent | e1293b49e3adbcff8eade91dc64901d40aeb5099 (diff) |
remove the plugin support for QInputContext
This will be handled through the lighthouse plugin
instead.
Diffstat (limited to 'src/widgets/kernel')
-rw-r--r-- | src/widgets/kernel/kernel.pri | 2 | ||||
-rw-r--r-- | src/widgets/kernel/qapplication.cpp | 33 | ||||
-rw-r--r-- | src/widgets/kernel/qinputcontext.cpp | 521 | ||||
-rw-r--r-- | src/widgets/kernel/qinputcontext.h | 140 |
4 files changed, 664 insertions, 32 deletions
diff --git a/src/widgets/kernel/kernel.pri b/src/widgets/kernel/kernel.pri index a4754018b2..08ec6ac81a 100644 --- a/src/widgets/kernel/kernel.pri +++ b/src/widgets/kernel/kernel.pri @@ -21,6 +21,7 @@ HEADERS += \ kernel/qiconloader_p.h \ kernel/qiconengine.h \ kernel/qiconengineplugin.h \ + kernel/qinputcontext.h \ kernel/qlayout.h \ kernel/qlayout_p.h \ kernel/qlayoutengine_p.h \ @@ -54,6 +55,7 @@ SOURCES += \ kernel/qiconloader.cpp \ kernel/qiconengine.cpp \ kernel/qiconengineplugin.cpp \ + kernel/qinputcontext.cpp \ kernel/qlayout.cpp \ kernel/qlayoutengine.cpp \ kernel/qlayoutitem.cpp \ diff --git a/src/widgets/kernel/qapplication.cpp b/src/widgets/kernel/qapplication.cpp index 7595290d11..517df5252f 100644 --- a/src/widgets/kernel/qapplication.cpp +++ b/src/widgets/kernel/qapplication.cpp @@ -5222,38 +5222,7 @@ void QApplication::setInputContext(QInputContext *inputContext) */ QInputContext *QApplication::inputContext() const { - Q_D(const QApplication); - Q_UNUSED(d);// only static members being used. - if (QApplicationPrivate::is_app_closing) - return d->inputContext; -#ifdef Q_WS_X11 - if (!X11) - return 0; - if (!d->inputContext) { - QApplication *that = const_cast<QApplication *>(this); - QInputContext *qic = QInputContextFactory::create(X11->default_im, that); - // fallback to default X Input Method. - if (!qic) - qic = QInputContextFactory::create(QLatin1String("xim"), that); - that->d_func()->inputContext = qic; - } -#elif defined(Q_OS_SYMBIAN) - if (!d->inputContext) { - QApplication *that = const_cast<QApplication *>(this); - const QStringList keys = QInputContextFactory::keys(); - // Try hbim and coefep first, then try others. - if (keys.contains(QLatin1String("hbim"))) { - that->d_func()->inputContext = QInputContextFactory::create(QLatin1String("hbim"), that); - } else if (keys.contains(QLatin1String("coefep"))) { - that->d_func()->inputContext = QInputContextFactory::create(QLatin1String("coefep"), that); - } else { - for (int c = 0; c < keys.size() && !d->inputContext; ++c) { - that->d_func()->inputContext = QInputContextFactory::create(keys[c], that); - } - } - } -#endif - return d->inputContext; + return QApplicationPrivate::inputContext; } #endif // QT_NO_IM diff --git a/src/widgets/kernel/qinputcontext.cpp b/src/widgets/kernel/qinputcontext.cpp new file mode 100644 index 0000000000..a3e73eb288 --- /dev/null +++ b/src/widgets/kernel/qinputcontext.cpp @@ -0,0 +1,521 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtGui module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +/**************************************************************************** +** +** Implementation of QInputContext class +** +** Copyright (C) 2003-2004 immodule for Qt Project. All rights reserved. +** +** This file is written to contribute to Nokia Corporation and/or its subsidiary(-ies) under their own +** license. You may use this file under your Qt license. Following +** description is copied from their original file headers. Contact +** immodule-qt@freedesktop.org if any conditions of this licensing are +** not clear to you. +** +****************************************************************************/ + +//#define QT_NO_IM_PREEDIT_RELOCATION + +#include "qinputcontext.h" + +#ifndef QT_NO_IM + +#include "qplatformdefs.h" + +#include "qapplication.h" +#include "private/qguiapplication_p.h" +#include "qplatformintegration_qpa.h" +#include "qplatforminputcontext_qpa.h" +#include "qmenu.h" +#include "qtextformat.h" +#include "qpalette.h" + +#include <stdlib.h> +#include <limits.h> + +QT_BEGIN_NAMESPACE + +/*! + \class QInputContext + \brief The QInputContext class abstracts the input method dependent data and composing state. + + \ingroup i18n + + An input method is responsible for inputting complex text that cannot + be inputted via simple keymap. It converts a sequence of input + events (typically key events) into a text string through the input + method specific converting process. The class of the processes are + widely ranging from simple finite state machine to complex text + translator that pools a whole paragraph of a text with text + editing capability to perform grammar and semantic analysis. + + To abstract such different input method specific intermediate + information, Qt offers the QInputContext as base class. The + concept is well known as 'input context' in the input method + domain. An input context is created for a text widget in response + to a demand. It is ensured that an input context is prepared for + an input method before input to a text widget. + + Multiple input contexts that belong to a single input method + may concurrently coexist. Suppose multi-window text editor. Each + text widget of window A and B holds different QInputContext + instance which contains different state information such as + partially composed text. + + \section1 Groups of Functions + + \table + \header \o Context \o Functions + + \row \o Receiving information \o + x11FilterEvent(), + filterEvent(), + mouseHandler() + + \row \o Sending back composed text \o + sendEvent() + + \row \o State change notification \o + setFocusWidget(), + reset() + + \row \o Context information \o + identifierName(), + language(), + font(), + isComposing() + + \endtable + + \section1 Licensing Information + + \legalese + Copyright (C) 2003-2004 immodule for Qt Project. All rights reserved. + + This file is written to contribute to Nokia Corporation and/or its subsidiary(-ies) under their own + license. You may use this file under your Qt license. Following + description is copied from their original file headers. Contact + immodule-qt@freedesktop.org if any conditions of this licensing are + not clear to you. + \endlegalese + + \sa QInputContextPlugin, QInputContextFactory, QApplication::setInputContext() +*/ + +/*! + Constructs an input context with the given \a parent. +*/ +QInputContext::QInputContext(QObject* parent) + : QObject(parent) +{ +} + + +/*! + Destroys the input context. +*/ +QInputContext::~QInputContext() +{ +} + +/*! + Returns the widget that has an input focus for this input + context. + + The return value may differ from holderWidget() if the input + context is shared between several text widgets. + + \warning To ensure platform independence and support flexible + configuration of widgets, ordinary input methods should not call + this function directly. + + \sa setFocusWidget() +*/ +QWidget *QInputContext::focusWidget() const +{ + QPlatformInputContext *ic = QGuiApplicationPrivate::platformIntegration()->inputContext(); + if (ic) + return qobject_cast<QWidget *>(ic->focusObject()); + return 0; +} + + +/*! + Sets the \a widget that has an input focus for this input context. + + \warning Ordinary input methods must not call this function + directly. + + \sa focusWidget() +*/ +void QInputContext::setFocusWidget(QWidget *widget) +{ + Q_ASSERT(!widget || widget->testAttribute(Qt::WA_InputMethodEnabled)); + QPlatformInputContext *ic = QGuiApplicationPrivate::platformIntegration()->inputContext(); + if (ic) + ic->setFocusObject(widget); +} + +/*! + \fn bool QInputContext::isComposing() const + \obsolete + + This function indicates whether InputMethodStart event had been + sent to the current focus widget. It is ensured that an input + context can send InputMethodCompose or InputMethodEnd event safely + if this function returned true. + + The state is automatically being tracked through sendEvent(). + + \sa sendEvent() +*/ + +/*! + This function can be reimplemented in a subclass to filter input + events. + + Return true if the \a event has been consumed. Otherwise, the + unfiltered \a event will be forwarded to widgets as ordinary + way. Although the input events have accept() and ignore() + methods, leave it untouched. + + \a event is currently restricted to events of these types: + + \list + \i CloseSoftwareInputPanel + \i KeyPress + \i KeyRelease + \i MouseButtonDblClick + \i MouseButtonPress + \i MouseButtonRelease + \i MouseMove + \i RequestSoftwareInputPanel + \endlist + + But some input method related events such as QWheelEvent or + QTabletEvent may be added in future. + + The filtering opportunity is always given to the input context as + soon as possible. It has to be taken place before any other key + event consumers such as eventfilters and accelerators because some + input methods require quite various key combination and + sequences. It often conflicts with accelerators and so on, so we + must give the input context the filtering opportunity first to + ensure all input methods work properly regardless of application + design. + + Ordinary input methods require discrete key events to work + properly, so Qt's key compression is always disabled for any input + contexts. + + \sa QKeyEvent, x11FilterEvent() +*/ +bool QInputContext::filterEvent(const QEvent * /*event*/) +{ + return false; +} + +/*! + Sends an input method event specified by \a event to the current focus + widget. Implementations of QInputContext should call this method to + send the generated input method events and not + QApplication::sendEvent(), as the events might have to get dispatched + to a different application on some platforms. + + Some complex input methods route the handling to several child + contexts (e.g. to enable language switching). To account for this, + QInputContext will check if the parent object is a QInputContext. If + yes, it will call the parents sendEvent() implementation instead of + sending the event directly. + + \sa QInputMethodEvent +*/ +void QInputContext::sendEvent(const QInputMethodEvent &event) +{ + // route events over input context parents to make chaining possible. + QInputContext *p = qobject_cast<QInputContext *>(parent()); + if (p) { + p->sendEvent(event); + return; + } + + QWidget *focus = focusWidget(); + if (!focus) + return; + + QInputMethodEvent e(event); + QApplication::sendEvent(focus, &e); +} + + +/*! + This function can be reimplemented in a subclass to handle mouse + press, release, double-click, and move events within the preedit + text. You can use the function to implement mouse-oriented user + interface such as text selection or popup menu for candidate + selection. + + The \a x parameter is the offset within the string that was sent + with the InputMethodCompose event. The alteration boundary of \a + x is ensured as character boundary of preedit string accurately. + + The \a event parameter is the event that was sent to the editor + widget. The event type is QEvent::MouseButtonPress, + QEvent::MouseButtonRelease, QEvent::MouseButtonDblClick or + QEvent::MouseMove. The event's button and state indicate + the kind of operation that was performed. +*/ +void QInputContext::mouseHandler(int x, QMouseEvent *event) +{ + QPlatformInputContext *ic = QGuiApplicationPrivate::platformIntegration()->inputContext(); + if (ic) + ic->mouseHandler(x, event); +} + + +/*! + Returns the font of the current input widget +*/ +QFont QInputContext::font() const +{ + QWidget *focus = focusWidget(); + if (!focus) + return QApplication::font(); + + return qvariant_cast<QFont>(focus->inputMethodQuery(Qt::ImFont)); +} + +/*! + This virtual function is called when a state in the focus widget + has changed. QInputContext can then use + QWidget::inputMethodQuery() to query the new state of the widget. +*/ +void QInputContext::update() +{ + QPlatformInputContext *ic = QGuiApplicationPrivate::platformIntegration()->inputContext(); + if (ic) + ic->update(); +} + +/*! + This virtual function is called when the specified \a widget is + destroyed. The \a widget is a widget on which this input context + is installed. +*/ +void QInputContext::widgetDestroyed(QWidget *widget) +{ + if (widget == focusWidget()) + setFocusWidget(0); +} + +/*! + \fn void QInputContext::reset() + + This function can be reimplemented in a subclass to reset the + state of the input method. + + This function is called by several widgets to reset input + state. For example, a text widget call this function before + inserting a text to make widget ready to accept a text. + + Default implementation is sufficient for simple input method. You + can override this function to reset external input method engines + in complex input method. In the case, call QInputContext::reset() + to ensure proper termination of inputting. + + In a reimplementation of reset(), you must not send any + QInputMethodEvent containing preedit text. You can only commit + string and attributes; otherwise, you risk breaking input state + consistency. +*/ +void QInputContext::reset() +{ + QPlatformInputContext *ic = QGuiApplicationPrivate::platformIntegration()->inputContext(); + if (ic) + ic->reset(); +} + + +/*! + \fn QString QInputContext::identifierName() + + This function must be implemented in any subclasses to return the + identifier name of the input method. + + Return value is the name to identify and specify input methods for + the input method switching mechanism and so on. The name has to be + consistent with QInputContextPlugin::keys(). The name has to + consist of ASCII characters only. + + There are two different names with different responsibility in the + input method domain. This function returns one of them. Another + name is called 'display name' that stands for the name for + endusers appeared in a menu and so on. + + \sa QInputContextPlugin::keys(), QInputContextPlugin::displayName() +*/ +QString QInputContext::identifierName() +{ + return QLatin1String("qpa"); +} + + +/*! + \fn QString QInputContext::language() + + This function must be implemented in any subclasses to return a + language code (e.g. "zh_CN", "zh_TW", "zh_HK", "ja", "ko", ...) + of the input context. If the input context can handle multiple + languages, return the currently used one. The name has to be + consistent with QInputContextPlugin::language(). + + This information will be used by language tagging feature in + QInputMethodEvent. It is required to distinguish unified han characters + correctly. It enables proper font and character code + handling. Suppose CJK-awared multilingual web browser + (that automatically modifies fonts in CJK-mixed text) and XML editor + (that automatically inserts lang attr). +*/ +QString QInputContext::language() +{ + return QString(); +} + + +/*! + This is a preliminary interface for Qt 4. +*/ +QList<QAction *> QInputContext::actions() +{ + return QList<QAction *>(); +} + +/*! + \enum QInputContext::StandardFormat + + \value PreeditFormat The preedit text. + \value SelectionFormat The selection text. + + \sa standardFormat() +*/ + +/*! + Returns a QTextFormat object that specifies the format for + component \a s. +*/ +QTextFormat QInputContext::standardFormat(StandardFormat s) const +{ + QWidget *focus = focusWidget(); + const QPalette &pal = focus ? focus->palette() : QApplication::palette(); + + QTextCharFormat fmt; + QColor bg; + switch (s) { + case QInputContext::PreeditFormat: { + fmt.setUnderlineStyle(QTextCharFormat::DashUnderline); + break; + } + case QInputContext::SelectionFormat: { + bg = pal.text().color(); + fmt.setBackground(QBrush(bg)); + fmt.setForeground(pal.background()); + break; + } + } + return fmt; +} + +#ifdef Q_WS_X11 +/*! + This function may be overridden only if input method is depending + on X11 and you need raw XEvent. Otherwise, this function must not. + + This function is designed to filter raw key events for XIM, but + other input methods may use this to implement some special + features such as distinguishing Shift_L and Shift_R. + + Return true if the \a event has been consumed. Otherwise, the + unfiltered \a event will be translated into QEvent and forwarded + to filterEvent(). Filtering at both x11FilterEvent() and + filterEvent() in single input method is allowed. + + \a keywidget is a client widget into which a text is inputted. \a + event is inputted XEvent. + + \sa filterEvent() +*/ +bool QInputContext::x11FilterEvent(QWidget * /*keywidget*/, XEvent * /*event*/) +{ + return false; +} +#endif // Q_WS_X11 + +#ifdef Q_OS_SYMBIAN +/*! + \since 4.6 + + This function may be overridden only if input method is depending + on Symbian and you need raw Symbian events. Otherwise, this function must not. + + This function is designed to filter raw key events on Symbian, but + other input methods may use this to implement some special + features. + + Return true if the \a event has been consumed. Otherwise, the + unfiltered \a event will be translated into QEvent and forwarded + to filterEvent(). Filtering at both symbianFilterEvent() and + filterEvent() in single input method is allowed. + + \a keywidget is a client widget into which a text is inputted. \a + event is inputted QSymbianEvent. + + \sa filterEvent() +*/ +bool QInputContext::symbianFilterEvent(QWidget * /*keywidget*/, const QSymbianEvent * /*event*/) +{ + return false; +} +#endif // Q_OS_SYMBIAN + +QT_END_NAMESPACE + +#endif //Q_NO_IM diff --git a/src/widgets/kernel/qinputcontext.h b/src/widgets/kernel/qinputcontext.h new file mode 100644 index 0000000000..fba0c7cf2c --- /dev/null +++ b/src/widgets/kernel/qinputcontext.h @@ -0,0 +1,140 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtGui module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +/**************************************************************************** +** +** Definition of QInputContext class +** +** Copyright (C) 2003-2004 immodule for Qt Project. All rights reserved. +** +** This file is written to contribute to Nokia Corporation and/or its subsidiary(-ies) under their own +** license. You may use this file under your Qt license. Following +** description is copied from their original file headers. Contact +** immodule-qt@freedesktop.org if any conditions of this licensing are +** not clear to you. +** +****************************************************************************/ + +#ifndef QINPUTCONTEXT_H +#define QINPUTCONTEXT_H + +#include <QtCore/qobject.h> +#include <QtCore/qglobal.h> +#include <QtGui/qevent.h> +#include <QtCore/qstring.h> +#include <QtCore/qlist.h> +#include <QtWidgets/qaction.h> + +#ifndef QT_NO_IM + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Gui) + +class QWidget; +class QFont; +class QPopupMenu; +class QInputContextPrivate; +#ifdef Q_OS_SYMBIAN +class QSymbianEvent; +#endif + +class Q_WIDGETS_EXPORT QInputContext : public QObject +{ + Q_OBJECT +public: + explicit QInputContext(QObject* parent = 0); + virtual ~QInputContext(); + + virtual QString identifierName(); + virtual QString language(); + + virtual void reset(); + virtual void update(); + + virtual void mouseHandler( int x, QMouseEvent *event); + virtual QFont font() const; + + QWidget *focusWidget() const; + virtual void setFocusWidget( QWidget *w ); + + virtual void widgetDestroyed(QWidget *w); + + virtual QList<QAction *> actions(); + +#if defined(Q_WS_X11) + virtual bool x11FilterEvent( QWidget *keywidget, XEvent *event ); +#endif // Q_WS_X11 +#if defined(Q_OS_SYMBIAN) + virtual bool symbianFilterEvent( QWidget *keywidget, const QSymbianEvent *event ); +#endif // Q_OS_SYMBIAN + virtual bool filterEvent( const QEvent *event ); + + void sendEvent(const QInputMethodEvent &event); + + virtual bool isComposing() const { return false; } + +private: + enum StandardFormat { + PreeditFormat, + SelectionFormat + }; + QTextFormat standardFormat(StandardFormat s) const; +private: + friend class QWidget; + friend class QWidgetPrivate; + friend class QInputContextFactory; + friend class QApplication; +private: // Disabled copy constructor and operator= + QInputContext( const QInputContext & ); + QInputContext &operator=( const QInputContext & ); + +}; + +QT_END_NAMESPACE + +QT_END_HEADER + +#endif //Q_NO_IM + +#endif // QINPUTCONTEXT_H |