20 ** |
20 ** |
21 ** If you have questions regarding the use of this file, please contact |
21 ** If you have questions regarding the use of this file, please contact |
22 ** Nokia at developer.feedback@nokia.com. |
22 ** Nokia at developer.feedback@nokia.com. |
23 ** |
23 ** |
24 ****************************************************************************/ |
24 ****************************************************************************/ |
|
25 #include "hbinpututils.h" |
|
26 |
25 #include <QObject> |
27 #include <QObject> |
26 #include <QLocale> |
28 #include <QLocale> |
27 #include <QDir> |
29 #include <QDir> |
28 #include <QPluginLoader> |
30 #include <QPluginLoader> |
29 #include <QInputContextPlugin> |
31 #include <QInputContextPlugin> |
38 #include "hbinputkeymapfactory.h" |
40 #include "hbinputkeymapfactory.h" |
39 #include "hbinputsettingproxy.h" |
41 #include "hbinputsettingproxy.h" |
40 #include "hbinputlanguagedatabase.h" |
42 #include "hbinputlanguagedatabase.h" |
41 #include "hbinputmodecache_p.h" |
43 #include "hbinputmodecache_p.h" |
42 #include "hbinputlanguage.h" |
44 #include "hbinputlanguage.h" |
43 #include "hbinpututils.h" |
45 |
44 |
46 #define HB_DIGIT_ARABIC_INDIC_START_VALUE 0x0660 |
45 #define HB_DIGIT_ARABIC_INDIC_START_VALUE 0x0660 |
47 #define HB_DIGIT_EASTERN_ARABIC_START_VALUE 0x06F0 |
46 |
48 |
47 |
|
48 /// @cond |
|
49 |
|
50 static bool usesLatinDigits(QLocale::Language language, HbInputDigitType digitType) |
|
51 { |
|
52 if (digitType == HbDigitTypeDevanagari) { |
|
53 return false; |
|
54 } |
|
55 if (language == QLocale::Urdu || language == QLocale::Persian) { |
|
56 // Latin digits are used in Persian and Urdu ITU-T keypads |
|
57 if (HbInputSettingProxy::instance()->activeKeyboard() == HbKeyboardVirtual12Key) { |
|
58 return true; |
|
59 } else { |
|
60 return false; |
|
61 } |
|
62 } |
|
63 if (language == QLocale::Arabic && digitType == HbDigitTypeArabicIndic) { |
|
64 return false; |
|
65 } |
|
66 |
|
67 return true; |
|
68 } |
|
69 |
|
70 /// @endcond |
|
71 |
49 |
72 /*! |
50 /*! |
73 \class HbInputUtils |
51 \class HbInputUtils |
74 \brief A collection input related utility methods. |
52 \brief A collection input related utility methods. |
75 |
53 |
76 This class contains a collection of static input related utility methods that do not |
54 This class contains a collection of static input related utility methods that do not |
77 naturally belong to any other scope. There are convenience methods for testing |
55 naturally belong to any other scope. There are convenience methods for testing |
78 attributes of keyboard and input mode types, instantiating plugins etc. |
56 attributes of keyboard and input mode types, instantiating plugins etc. |
79 |
57 |
80 \sa HbInputMethod |
58 \sa HbInputMethod |
81 \sa QInputContextPlugin |
59 \sa QInputContextPlugin |
82 */ |
60 */ |
83 |
61 |
84 /*! |
62 /*! |
85 Finds the fist number character bound to key using given mapping data. |
63 Finds the fist number character bound to key using given mapping data. |
86 @param keyboardType Type of the keyboard |
64 */ |
87 @param key Key code where to look for number character |
65 QChar HbInputUtils::findFirstNumberCharacterBoundToKey(const HbMappedKey *key, |
88 @param keymapData Pointer to keymap data where to look |
66 const HbInputLanguage language, |
89 @param digitType Type of digit if not latin |
67 const HbInputDigitType digitType) |
90 */ |
68 { |
91 QChar HbInputUtils::findFirstNumberCharacterBoundToKey(const HbMappedKey* key, |
69 Q_UNUSED(language); |
92 const HbInputLanguage language, |
70 |
93 const HbInputDigitType digitType) |
|
94 { |
|
95 if (key) { |
71 if (key) { |
96 QString chars = key->characters(HbModifierNone); |
72 QString chars = key->characters(HbModifierNone); |
97 if (usesLatinDigits(language.language(), digitType)) { |
73 if (digitType == HbDigitTypeLatin) { |
98 for (int i = 0; i < chars.length(); i++) { |
74 for (int i = 0; i < chars.length(); i++) { |
99 if (chars.at(i) >= '0' && chars.at(i) <= '9') { |
75 if (chars.at(i) >= '0' && chars.at(i) <= '9') { |
100 return chars.at(i); |
76 return chars.at(i); |
101 } |
77 } |
102 } |
78 } |
108 } |
84 } |
109 } else if (digitType == HbDigitTypeArabicIndic) { |
85 } else if (digitType == HbDigitTypeArabicIndic) { |
110 for (int i = 0; i < chars.length(); i++) { |
86 for (int i = 0; i < chars.length(); i++) { |
111 if (chars.at(i) >= '0' && chars.at(i) <= '9') { |
87 if (chars.at(i) >= '0' && chars.at(i) <= '9') { |
112 return HB_DIGIT_ARABIC_INDIC_START_VALUE + |
88 return HB_DIGIT_ARABIC_INDIC_START_VALUE + |
113 (chars.at(i).toAscii() - '0'); |
89 (chars.at(i).unicode() - '0'); |
114 } |
90 } |
115 } |
91 } |
116 } else if (digitType == HbDigitTypeEasternArabic) { |
92 } else if (digitType == HbDigitTypeEasternArabic) { |
117 for (int i = 0; i < chars.length(); i++) { |
93 for (int i = 0; i < chars.length(); i++) { |
118 if (chars.at(i) >= 0x06F0 && chars.at(i) <= 0x06F9) { |
94 if (chars.at(i) >= '0' && chars.at(i) <= '9') { |
119 return chars.at(i); |
95 return HB_DIGIT_EASTERN_ARABIC_START_VALUE + |
|
96 (chars.at(i).unicode() - '0'); |
120 } |
97 } |
121 } |
98 } |
122 } |
99 } |
123 } |
100 } |
124 |
101 |
143 files that are not language database plugins. languageDatabasePluginInstance() |
120 files that are not language database plugins. languageDatabasePluginInstance() |
144 checks the validity of plugin files provided by this function. |
121 checks the validity of plugin files provided by this function. |
145 |
122 |
146 \sa languageDatabasePluginInstance |
123 \sa languageDatabasePluginInstance |
147 */ |
124 */ |
148 void HbInputUtils::listAvailableLanguageDatabasePlugins(QStringList& result, const QString& subfolder) |
125 void HbInputUtils::listAvailableLanguageDatabasePlugins(QStringList &result, const QString &subfolder) |
149 { |
126 { |
150 QString path(HbInputSettingProxy::languageDatabasePath()); |
127 QString path(HbInputSettingProxy::languageDatabasePath()); |
151 path += QDir::separator(); |
128 path += QDir::separator(); |
152 path += subfolder; |
129 path += subfolder; |
153 |
130 |
161 } |
138 } |
162 |
139 |
163 /*! |
140 /*! |
164 Creates an instance of given language database plugin, if valid. |
141 Creates an instance of given language database plugin, if valid. |
165 */ |
142 */ |
166 HbLanguageDatabaseInterface* HbInputUtils::languageDatabasePluginInstance(const QString& pluginFileName, const QString& subfolder) |
143 HbLanguageDatabaseInterface *HbInputUtils::languageDatabasePluginInstance(const QString &pluginFileName, const QString &subfolder) |
167 { |
144 { |
168 if (!QLibrary::isLibrary(pluginFileName)) { |
145 if (!QLibrary::isLibrary(pluginFileName)) { |
169 qDebug("HbInputUtils::languageDatabasePluginInstance: Not a library!"); |
146 qDebug("HbInputUtils::languageDatabasePluginInstance: Not a library!"); |
170 return NULL; |
147 return NULL; |
171 } |
148 } |
172 |
149 |
173 HbLanguageDatabaseInterface* res = NULL; |
150 HbLanguageDatabaseInterface *res = NULL; |
174 |
151 |
175 QString fullName(HbInputSettingProxy::languageDatabasePath()); |
152 QString fullName(HbInputSettingProxy::languageDatabasePath()); |
176 fullName += QDir::separator(); |
153 fullName += QDir::separator(); |
177 if (subfolder.length() > 0) { |
154 if (subfolder.length() > 0) { |
178 fullName += subfolder; |
155 fullName += subfolder; |
179 fullName += QDir::separator(); |
156 fullName += QDir::separator(); |
180 } |
157 } |
181 fullName += pluginFileName; |
158 fullName += pluginFileName; |
182 |
159 |
183 QPluginLoader loader(fullName); |
160 QPluginLoader loader(fullName); |
184 QObject* plugin = loader.instance(); |
161 QObject *plugin = loader.instance(); |
185 |
162 |
186 if (plugin) { |
163 if (plugin) { |
187 res = qobject_cast<HbLanguageDatabaseInterface*>(plugin); |
164 res = qobject_cast<HbLanguageDatabaseInterface *>(plugin); |
188 } else { |
165 } else { |
189 qDebug("HbInputUtils::languageDatabasePluginInstance: Unable to instantiate plugin"); |
166 qDebug("HbInputUtils::languageDatabasePluginInstance: Unable to instantiate plugin"); |
190 } |
167 } |
191 |
168 |
192 return res; |
169 return res; |
203 /*! |
180 /*! |
204 This method creates an instance of QWidget and wraps given graphics widget inside it. |
181 This method creates an instance of QWidget and wraps given graphics widget inside it. |
205 It creates QGraphicsScene, adds given widget there and creates a view to the scene |
182 It creates QGraphicsScene, adds given widget there and creates a view to the scene |
206 inside returned QWidget. This is utility method is mainly for internal use. |
183 inside returned QWidget. This is utility method is mainly for internal use. |
207 */ |
184 */ |
208 QWidget* HbInputUtils::createWrapperWidget(QGraphicsWidget* graphicsWidget) |
185 QWidget *HbInputUtils::createWrapperWidget(QGraphicsWidget *graphicsWidget) |
209 { |
186 { |
210 QWidget *ret = 0; |
187 QWidget *ret = 0; |
211 |
188 |
212 if (graphicsWidget) { |
189 if (graphicsWidget) { |
213 ret = new QWidget; |
190 ret = new QWidget; |
250 HbInputDigitType HbInputUtils::inputDigitType(HbInputLanguage language) |
227 HbInputDigitType HbInputUtils::inputDigitType(HbInputLanguage language) |
251 { |
228 { |
252 HbInputDigitType digitType = HbDigitTypeNone; |
229 HbInputDigitType digitType = HbDigitTypeNone; |
253 |
230 |
254 switch (language.language()) { |
231 switch (language.language()) { |
255 case QLocale::Arabic: |
232 case QLocale::Arabic: |
256 digitType = HbDigitTypeArabicIndic; |
233 digitType = HbDigitTypeArabicIndic; |
257 break; |
234 break; |
258 default: |
235 case QLocale::Persian: |
259 digitType = HbDigitTypeLatin; |
236 case QLocale::Urdu: |
260 break; |
237 digitType = HbDigitTypeEasternArabic; |
|
238 break; |
|
239 case QLocale::Hindi: |
|
240 digitType = HbDigitTypeDevanagari; |
|
241 break; |
|
242 default: |
|
243 digitType = HbDigitTypeLatin; |
|
244 break; |
261 } |
245 } |
262 return digitType; |
246 return digitType; |
263 } |
247 } |
|
248 |
|
249 |
|
250 /*! |
|
251 Returns the proxy widget of the embedded widget in a graphics view ; |
|
252 if widget does not have the proxy widget then it returns the proxy widget of its window. |
|
253 otherwise returns 0. |
|
254 */ |
|
255 QGraphicsProxyWidget *HbInputUtils::graphicsProxyWidget(const QWidget *w) |
|
256 { |
|
257 QGraphicsProxyWidget *pw = w ? w->graphicsProxyWidget() : 0; |
|
258 if (w && !pw) { |
|
259 pw = w->window() ? w->window()->graphicsProxyWidget() : w->graphicsProxyWidget(); |
|
260 } |
|
261 return pw; |
|
262 } |
|
263 |
|
264 |
264 // End of file |
265 // End of file |
265 |
266 |