|
1 /**************************************************************************** |
|
2 ** |
|
3 ** Copyright (C) 2008-2010 Nokia Corporation and/or its subsidiary(-ies). |
|
4 ** All rights reserved. |
|
5 ** Contact: Nokia Corporation (developer.feedback@nokia.com) |
|
6 ** |
|
7 ** This file is part of the HbCore module of the UI Extensions for Mobile. |
|
8 ** |
|
9 ** GNU Lesser General Public License Usage |
|
10 ** This file may be used under the terms of the GNU Lesser General Public |
|
11 ** License version 2.1 as published by the Free Software Foundation and |
|
12 ** appearing in the file LICENSE.LGPL included in the packaging of this file. |
|
13 ** Please review the following information to ensure the GNU Lesser General |
|
14 ** Public License version 2.1 requirements will be met: |
|
15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
16 ** |
|
17 ** In addition, as a special exception, Nokia gives you certain additional |
|
18 ** rights. These rights are described in the Nokia Qt LGPL Exception |
|
19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
20 ** |
|
21 ** If you have questions regarding the use of this file, please contact |
|
22 ** Nokia at developer.feedback@nokia.com. |
|
23 ** |
|
24 ****************************************************************************/ |
|
25 #include <QObject> |
|
26 #include <QLocale> |
|
27 #include <QDir> |
|
28 #include <QPluginLoader> |
|
29 #include <QInputContextPlugin> |
|
30 #include <QGraphicsScene> |
|
31 #include <QWidget> |
|
32 #include <QGraphicsWidget> |
|
33 #include <QGraphicsView> |
|
34 #include <QGridLayout> |
|
35 #include <QGraphicsProxyWidget> |
|
36 |
|
37 #include "hbinputkeymap.h" |
|
38 #include "hbinputkeymapfactory.h" |
|
39 #include "hbinputsettingproxy.h" |
|
40 #include "hbinputlanguagedatabase.h" |
|
41 #include "hbinputmodecache_p.h" |
|
42 #include "hbinputlanguage.h" |
|
43 #include "hbinpututils.h" |
|
44 |
|
45 /// @cond |
|
46 |
|
47 static bool usesLatinDigits(QLocale::Language language, HbInputDigitType digitType) |
|
48 { |
|
49 if (digitType == HbDigitTypeDevanagari) { |
|
50 return false; |
|
51 } |
|
52 if (language == QLocale::Urdu || language == QLocale::Persian) { |
|
53 // Latin digits are used in Persian and Urdu ITU-T keypads |
|
54 if (HbInputSettingProxy::instance()->activeKeyboard() == HbKeyboardVirtual12Key) { |
|
55 return true; |
|
56 } else { |
|
57 return false; |
|
58 } |
|
59 } |
|
60 if (language == QLocale::Arabic && digitType == HbDigitTypeArabicIndic) { |
|
61 return false; |
|
62 } |
|
63 |
|
64 return true; |
|
65 } |
|
66 |
|
67 /// @endcond |
|
68 |
|
69 /*! |
|
70 \class HbInputUtils |
|
71 \brief A collection input related utility methods. |
|
72 |
|
73 This class contains a collection of static input related utility methods that do not |
|
74 naturally belong to any other scope. There are convenience methods for testing |
|
75 attributes of keyboard and input mode types, instantiating plugins etc. |
|
76 |
|
77 \sa HbInputMethod |
|
78 \sa QInputContextPlugin |
|
79 */ |
|
80 |
|
81 /*! |
|
82 Finds the fist number character bound to key using given mapping data. |
|
83 @param keyboardType Type of the keyboard |
|
84 @param key Key code where to look for number character |
|
85 @param keymapData Pointer to keymap data where to look |
|
86 @param digitType Type of digit if not latin |
|
87 */ |
|
88 QChar HbInputUtils::findFirstNumberCharacterBoundToKey(const HbMappedKey* key, |
|
89 const HbInputLanguage language, |
|
90 const HbInputDigitType digitType) |
|
91 { |
|
92 if (key) { |
|
93 QString chars = key->characters(HbModifierNone); |
|
94 if (usesLatinDigits(language.language(), digitType)) { |
|
95 for (int i = 0; i < chars.length(); i++) { |
|
96 if (chars.at(i) >= '0' && chars.at(i) <= '9') { |
|
97 return chars.at(i); |
|
98 } |
|
99 } |
|
100 } else if (digitType == HbDigitTypeDevanagari) { |
|
101 for (int i = 0; i < chars.length(); i++) { |
|
102 if (chars.at(i) >= 0x0966 && chars.at(i) <= 0x096F) { |
|
103 return chars.at(i); |
|
104 } |
|
105 } |
|
106 } else if (digitType == HbDigitTypeArabicIndic) { |
|
107 for (int i = 0; i < chars.length(); i++) { |
|
108 if (chars.at(i) >= 0x0660 && chars.at(i) <= 0x0669) { |
|
109 return chars.at(i); |
|
110 } |
|
111 } |
|
112 } else if (digitType == HbDigitTypeEasternArabic) { |
|
113 for (int i = 0; i < chars.length(); i++) { |
|
114 if (chars.at(i) >= 0x06F0 && chars.at(i) <= 0x06F9) { |
|
115 return chars.at(i); |
|
116 } |
|
117 } |
|
118 } |
|
119 } |
|
120 |
|
121 return 0; |
|
122 } |
|
123 |
|
124 /*! |
|
125 Returns true if the concept of "text case" can be applied to given input mode. |
|
126 For example Chinese and Japanese modes do not have text case. |
|
127 */ |
|
128 bool HbInputUtils::isCaseSensitiveMode(HbInputModeType inputMode) |
|
129 { |
|
130 if (isChineseInputMode(inputMode)) { |
|
131 return false; |
|
132 } |
|
133 |
|
134 return true; |
|
135 } |
|
136 |
|
137 /*! |
|
138 Lists all Qt library files in language database directory. May return |
|
139 files that are not language database plugins. languageDatabasePluginInstance() |
|
140 checks the validity of plugin files provided by this function. |
|
141 |
|
142 \sa languageDatabasePluginInstance |
|
143 */ |
|
144 void HbInputUtils::listAvailableLanguageDatabasePlugins(QStringList& result, const QString& subfolder) |
|
145 { |
|
146 QString path(HbInputSettingProxy::languageDatabasePath()); |
|
147 path += QDir::separator(); |
|
148 path += subfolder; |
|
149 |
|
150 QDir dir(path); |
|
151 |
|
152 for (unsigned int i = 0; i < dir.count(); i++) { |
|
153 if (QLibrary::isLibrary(dir[i])) { |
|
154 result.append(dir[i]); |
|
155 } |
|
156 } |
|
157 } |
|
158 |
|
159 /*! |
|
160 Creates an instance of given language database plugin, if valid. |
|
161 */ |
|
162 HbLanguageDatabaseInterface* HbInputUtils::languageDatabasePluginInstance(const QString& pluginFileName, const QString& subfolder) |
|
163 { |
|
164 if (!QLibrary::isLibrary(pluginFileName)) { |
|
165 qDebug("HbInputUtils::languageDatabasePluginInstance: Not a library!"); |
|
166 return NULL; |
|
167 } |
|
168 |
|
169 HbLanguageDatabaseInterface* res = NULL; |
|
170 |
|
171 QString fullName(HbInputSettingProxy::languageDatabasePath()); |
|
172 fullName += QDir::separator(); |
|
173 if (subfolder.length() > 0) { |
|
174 fullName += subfolder; |
|
175 fullName += QDir::separator(); |
|
176 } |
|
177 fullName += pluginFileName; |
|
178 |
|
179 QPluginLoader loader(fullName); |
|
180 QObject* plugin = loader.instance(); |
|
181 |
|
182 if (plugin) { |
|
183 res = qobject_cast<HbLanguageDatabaseInterface*>(plugin); |
|
184 } else { |
|
185 qDebug("HbInputUtils::languageDatabasePluginInstance: Unable to instantiate plugin"); |
|
186 } |
|
187 |
|
188 return res; |
|
189 } |
|
190 |
|
191 /*! |
|
192 Returns true if the given plugin is located to permanent (ROM) memory. |
|
193 This is only relevant for devices where plugins can be pre-installed as part |
|
194 of ROM-based firmware. In Windows and Unix environments this always returns false. |
|
195 */ |
|
196 bool HbInputUtils::isInputPluginInPermanentMemory(const QString& pluginFileName) |
|
197 { |
|
198 Q_UNUSED(pluginFileName) |
|
199 return false; |
|
200 } |
|
201 |
|
202 /*! |
|
203 Lists all the input languages that the set of available input methods supports. Excludes custom input methods. |
|
204 */ |
|
205 void HbInputUtils::listSupportedInputLanguages(QList<HbInputLanguage>& results) |
|
206 { |
|
207 results = HbInputModeCache::instance()->listInputLanguages(); |
|
208 } |
|
209 |
|
210 /*! |
|
211 This method creates an instance of QWidget and wraps given graphics widget inside it. |
|
212 It creates QGraphicsScene, adds given widget there and creates a view to the scene |
|
213 inside returned QWidget. This is utility method is mainly for internal use. |
|
214 */ |
|
215 QWidget* HbInputUtils::createWrapperWidget(QGraphicsWidget* graphicsWidget) |
|
216 { |
|
217 QWidget *ret = 0; |
|
218 |
|
219 if (graphicsWidget) { |
|
220 ret = new QWidget; |
|
221 ret->setContentsMargins(0, 0, 0, 0); |
|
222 QGraphicsScene *scene = new QGraphicsScene(ret); |
|
223 scene->addItem(graphicsWidget); |
|
224 QGraphicsView *view = new QGraphicsView(scene); |
|
225 view->setContentsMargins(0, 0, 0, 0); |
|
226 QGridLayout *layout = new QGridLayout; |
|
227 layout->setMargin(0); |
|
228 layout->setContentsMargins(0, 0, 0, 0); |
|
229 layout->addWidget(view); |
|
230 ret->setLayout(layout); |
|
231 } |
|
232 |
|
233 return ret; |
|
234 } |
|
235 |
|
236 /*! |
|
237 A convinience method that wraps given widget inside QGraphicsProxyWidget |
|
238 and returns it. This is utility method is mainly for internal use. |
|
239 */ |
|
240 QGraphicsWidget* HbInputUtils::createGraphicsProxyWidget(QWidget* widget) |
|
241 { |
|
242 |
|
243 QGraphicsProxyWidget *proxy = 0; |
|
244 |
|
245 if (widget) { |
|
246 proxy = new QGraphicsProxyWidget; |
|
247 proxy->setWidget(widget); |
|
248 } |
|
249 |
|
250 return proxy; |
|
251 } |
|
252 |
|
253 // End of file |
|
254 |