1 | /****************************************************************************
|
---|
2 | **
|
---|
3 | ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
---|
4 | ** All rights reserved.
|
---|
5 | ** Contact: Nokia Corporation ([email protected])
|
---|
6 | **
|
---|
7 | ** This file is part of the plugins of the Qt Toolkit.
|
---|
8 | **
|
---|
9 | ** $QT_BEGIN_LICENSE:LGPL$
|
---|
10 | ** Commercial Usage
|
---|
11 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
---|
12 | ** accordance with the Qt Commercial License Agreement provided with the
|
---|
13 | ** Software or, alternatively, in accordance with the terms contained in
|
---|
14 | ** a written agreement between you and Nokia.
|
---|
15 | **
|
---|
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.
|
---|
23 | **
|
---|
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.
|
---|
27 | **
|
---|
28 | ** GNU General Public License Usage
|
---|
29 | ** Alternatively, this file may be used under the terms of the GNU
|
---|
30 | ** General Public License version 3.0 as published by the Free Software
|
---|
31 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
---|
32 | ** packaging of this file. Please review the following information to
|
---|
33 | ** ensure the GNU General Public License version 3.0 requirements will be
|
---|
34 | ** met: http://www.gnu.org/copyleft/gpl.html.
|
---|
35 | **
|
---|
36 | ** If you have questions regarding the use of this file, please contact
|
---|
37 | ** Nokia at [email protected].
|
---|
38 | ** $QT_END_LICENSE$
|
---|
39 | **
|
---|
40 | ****************************************************************************/
|
---|
41 |
|
---|
42 | /****************************************************************************
|
---|
43 | **
|
---|
44 | ** Implementation of QMultiInputContext class
|
---|
45 | **
|
---|
46 | ** Copyright (C) 2004 immodule for Qt Project. All rights reserved.
|
---|
47 | **
|
---|
48 | ** This file is written to contribute to Nokia Corporation and/or its subsidiary(-ies) under their own
|
---|
49 | ** licence. You may use this file under your Qt license. Following
|
---|
50 | ** description is copied from their original file headers. Contact
|
---|
51 | ** [email protected] if any conditions of this licensing are
|
---|
52 | ** not clear to you.
|
---|
53 | **
|
---|
54 | ****************************************************************************/
|
---|
55 |
|
---|
56 | #ifndef QT_NO_IM
|
---|
57 | #include "qmultiinputcontext.h"
|
---|
58 | #include <qinputcontextfactory.h>
|
---|
59 | #include <qstringlist.h>
|
---|
60 | #include <qaction.h>
|
---|
61 | #include <qsettings.h>
|
---|
62 | #include <qmenu.h>
|
---|
63 |
|
---|
64 | #include <stdlib.h>
|
---|
65 |
|
---|
66 | QT_BEGIN_NAMESPACE
|
---|
67 |
|
---|
68 | QMultiInputContext::QMultiInputContext()
|
---|
69 | : QInputContext(), current(-1)
|
---|
70 | {
|
---|
71 | keys = QInputContextFactory::keys();
|
---|
72 | for (int i = keys.size()-1; i >= 0; --i)
|
---|
73 | if (keys.at(i).contains(QLatin1String("imsw")))
|
---|
74 | keys.removeAt(i);
|
---|
75 |
|
---|
76 | QString def = QLatin1String(getenv("QT4_IM_MODULE"));
|
---|
77 | if (def.isEmpty())
|
---|
78 | def = QLatin1String(getenv("QT_IM_MODULE"));
|
---|
79 | if (def.isEmpty()) {
|
---|
80 | QSettings settings(QSettings::UserScope, QLatin1String("Trolltech"));
|
---|
81 | settings.beginGroup(QLatin1String("Qt"));
|
---|
82 | def = settings.value(QLatin1String("DefaultInputMethod"), QLatin1String("xim")).toString();
|
---|
83 | }
|
---|
84 | current = keys.indexOf(def);
|
---|
85 | if (current < 0)
|
---|
86 | current = 0;
|
---|
87 |
|
---|
88 | menu = new QMenu(tr("Select IM"));
|
---|
89 | separator = new QAction(this);
|
---|
90 | separator->setSeparator(true);
|
---|
91 |
|
---|
92 | QActionGroup *group = new QActionGroup(this);
|
---|
93 | for (int i = 0; i < keys.size(); ++i) {
|
---|
94 | slaves.append(0);
|
---|
95 | const QString key = keys.at(i);
|
---|
96 | QAction *a = menu->addAction(QInputContextFactory::displayName(key));
|
---|
97 | a->setData(key);
|
---|
98 | a->setCheckable(true);
|
---|
99 | group->addAction(a);
|
---|
100 | if (i == current) {
|
---|
101 | slaves.replace(current, QInputContextFactory::create(key, this));
|
---|
102 | a->setChecked(true);
|
---|
103 | }
|
---|
104 | }
|
---|
105 | connect(group, SIGNAL(triggered(QAction*)), this, SLOT(changeSlave(QAction*)));
|
---|
106 | }
|
---|
107 |
|
---|
108 | QMultiInputContext::~QMultiInputContext()
|
---|
109 | {
|
---|
110 | delete menu;
|
---|
111 | }
|
---|
112 |
|
---|
113 |
|
---|
114 | QString QMultiInputContext::identifierName()
|
---|
115 | {
|
---|
116 | return (slave()) ? slave()->identifierName() : QLatin1String("");
|
---|
117 | }
|
---|
118 |
|
---|
119 | QString QMultiInputContext::language()
|
---|
120 | {
|
---|
121 | return (slave()) ? slave()->language() : QLatin1String("");
|
---|
122 | }
|
---|
123 |
|
---|
124 |
|
---|
125 | #if defined(Q_WS_X11)
|
---|
126 | bool QMultiInputContext::x11FilterEvent(QWidget *keywidget, XEvent *event)
|
---|
127 | {
|
---|
128 | return (slave()) ? slave()->x11FilterEvent(keywidget, event) : false;
|
---|
129 | }
|
---|
130 | #endif // Q_WS_X11
|
---|
131 |
|
---|
132 |
|
---|
133 | bool QMultiInputContext::filterEvent(const QEvent *event)
|
---|
134 | {
|
---|
135 | return (slave()) ? slave()->filterEvent(event) : false;
|
---|
136 | }
|
---|
137 |
|
---|
138 | void QMultiInputContext::reset()
|
---|
139 | {
|
---|
140 | if (slave())
|
---|
141 | slave()->reset();
|
---|
142 | }
|
---|
143 |
|
---|
144 | void QMultiInputContext::update()
|
---|
145 | {
|
---|
146 | if (slave())
|
---|
147 | slave()->update();
|
---|
148 | }
|
---|
149 |
|
---|
150 | void QMultiInputContext::mouseHandler(int x, QMouseEvent *event)
|
---|
151 | {
|
---|
152 | if (slave())
|
---|
153 | slave()->mouseHandler(x, event);
|
---|
154 | }
|
---|
155 |
|
---|
156 | QFont QMultiInputContext::font() const
|
---|
157 | {
|
---|
158 | return (slave()) ? slave()->font() : QInputContext::font();
|
---|
159 | }
|
---|
160 |
|
---|
161 | void QMultiInputContext::setFocusWidget(QWidget *w)
|
---|
162 | {
|
---|
163 | QInputContext::setFocusWidget(w);
|
---|
164 | if (slave())
|
---|
165 | slave()->setFocusWidget(w);
|
---|
166 | }
|
---|
167 |
|
---|
168 | QWidget *QMultiInputContext::focusWidget() const
|
---|
169 | {
|
---|
170 | return QInputContext::focusWidget();
|
---|
171 | }
|
---|
172 |
|
---|
173 | void QMultiInputContext::widgetDestroyed(QWidget *w)
|
---|
174 | {
|
---|
175 | if (slave())
|
---|
176 | slave()->widgetDestroyed(w);
|
---|
177 | }
|
---|
178 |
|
---|
179 | bool QMultiInputContext::isComposing() const
|
---|
180 | {
|
---|
181 | return (slave()) ? slave()->isComposing() : false;
|
---|
182 | }
|
---|
183 |
|
---|
184 | QList<QAction *> QMultiInputContext::actions()
|
---|
185 | {
|
---|
186 | QList<QAction *> a = slave()->actions();
|
---|
187 | a.append(separator);
|
---|
188 | a.append(menu->menuAction());
|
---|
189 | return a;
|
---|
190 | }
|
---|
191 |
|
---|
192 | void QMultiInputContext::changeSlave(QAction *a)
|
---|
193 | {
|
---|
194 | for (int i = 0; i < slaves.size(); ++i) {
|
---|
195 | if (keys.at(i) == a->data().toString()) {
|
---|
196 | if (slaves.at(i) == 0)
|
---|
197 | slaves.replace(i, QInputContextFactory::create(keys.at(i), this));
|
---|
198 | QInputContext *qic = slaves.at(current);
|
---|
199 | QWidget *oldWidget = qic->focusWidget();
|
---|
200 | qic->reset();
|
---|
201 | qic->setFocusWidget(0);
|
---|
202 | current = i;
|
---|
203 | qic = slaves.at(current);
|
---|
204 | qic->setFocusWidget(oldWidget);
|
---|
205 | return;
|
---|
206 | }
|
---|
207 | }
|
---|
208 | }
|
---|
209 |
|
---|
210 | QT_END_NAMESPACE
|
---|
211 |
|
---|
212 | #endif // QT_NO_IM
|
---|