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" |
|
44 |
45 |
45 #define HB_DIGIT_ARABIC_INDIC_START_VALUE 0x0660 |
46 #define HB_DIGIT_ARABIC_INDIC_START_VALUE 0x0660 |
46 #define HB_DIGIT_EASTERN_ARABIC_START_VALUE 0x06F0 |
47 #define HB_DIGIT_EASTERN_ARABIC_START_VALUE 0x06F0 |
47 |
48 |
48 |
49 |
49 /*! |
50 /*! |
50 \class HbInputUtils |
51 \class HbInputUtils |
51 \brief A collection input related utility methods. |
52 \brief A collection input related utility methods. |
52 |
53 |
53 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 |
54 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 |
55 attributes of keyboard and input mode types, instantiating plugins etc. |
56 attributes of keyboard and input mode types, instantiating plugins etc. |
56 |
57 |
57 \sa HbInputMethod |
58 \sa HbInputMethod |
58 \sa QInputContextPlugin |
59 \sa QInputContextPlugin |
59 */ |
60 */ |
60 |
61 |
61 /*! |
62 /*! |
62 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. |
63 @param keyboardType Type of the keyboard |
64 */ |
64 @param key Key code where to look for number character |
65 QChar HbInputUtils::findFirstNumberCharacterBoundToKey(const HbMappedKey *key, |
65 @param keymapData Pointer to keymap data where to look |
66 const HbInputLanguage language, |
66 @param digitType Type of digit if not latin |
67 const HbInputDigitType digitType) |
67 */ |
|
68 QChar HbInputUtils::findFirstNumberCharacterBoundToKey(const HbMappedKey* key, |
|
69 const HbInputLanguage language, |
|
70 const HbInputDigitType digitType) |
|
71 { |
68 { |
72 Q_UNUSED(language); |
69 Q_UNUSED(language); |
73 |
70 |
74 if (key) { |
71 if (key) { |
75 QString chars = key->characters(HbModifierNone); |
72 QString chars = key->characters(HbModifierNone); |
76 if (digitType == HbDigitTypeLatin) { |
73 if (digitType == HbDigitTypeLatin) { |
77 for (int i = 0; i < chars.length(); i++) { |
74 for (int i = 0; i < chars.length(); i++) { |
78 if (chars.at(i) >= '0' && chars.at(i) <= '9') { |
75 if (chars.at(i) >= '0' && chars.at(i) <= '9') { |
87 } |
84 } |
88 } else if (digitType == HbDigitTypeArabicIndic) { |
85 } else if (digitType == HbDigitTypeArabicIndic) { |
89 for (int i = 0; i < chars.length(); i++) { |
86 for (int i = 0; i < chars.length(); i++) { |
90 if (chars.at(i) >= '0' && chars.at(i) <= '9') { |
87 if (chars.at(i) >= '0' && chars.at(i) <= '9') { |
91 return HB_DIGIT_ARABIC_INDIC_START_VALUE + |
88 return HB_DIGIT_ARABIC_INDIC_START_VALUE + |
92 (chars.at(i).unicode() - '0'); |
89 (chars.at(i).unicode() - '0'); |
93 } |
90 } |
94 } |
91 } |
95 } else if (digitType == HbDigitTypeEasternArabic) { |
92 } else if (digitType == HbDigitTypeEasternArabic) { |
96 for (int i = 0; i < chars.length(); i++) { |
93 for (int i = 0; i < chars.length(); i++) { |
97 if (chars.at(i) >= '0' && chars.at(i) <= '9') { |
94 if (chars.at(i) >= '0' && chars.at(i) <= '9') { |
98 return HB_DIGIT_EASTERN_ARABIC_START_VALUE + |
95 return HB_DIGIT_EASTERN_ARABIC_START_VALUE + |
99 (chars.at(i).unicode() - '0'); |
96 (chars.at(i).unicode() - '0'); |
100 } |
97 } |
101 } |
98 } |
102 } |
99 } |
103 } |
100 } |
104 |
101 |
123 files that are not language database plugins. languageDatabasePluginInstance() |
120 files that are not language database plugins. languageDatabasePluginInstance() |
124 checks the validity of plugin files provided by this function. |
121 checks the validity of plugin files provided by this function. |
125 |
122 |
126 \sa languageDatabasePluginInstance |
123 \sa languageDatabasePluginInstance |
127 */ |
124 */ |
128 void HbInputUtils::listAvailableLanguageDatabasePlugins(QStringList& result, const QString& subfolder) |
125 void HbInputUtils::listAvailableLanguageDatabasePlugins(QStringList &result, const QString &subfolder) |
129 { |
126 { |
130 QString path(HbInputSettingProxy::languageDatabasePath()); |
127 QString path(HbInputSettingProxy::languageDatabasePath()); |
131 path += QDir::separator(); |
128 path += QDir::separator(); |
132 path += subfolder; |
129 path += subfolder; |
133 |
130 |
141 } |
138 } |
142 |
139 |
143 /*! |
140 /*! |
144 Creates an instance of given language database plugin, if valid. |
141 Creates an instance of given language database plugin, if valid. |
145 */ |
142 */ |
146 HbLanguageDatabaseInterface* HbInputUtils::languageDatabasePluginInstance(const QString& pluginFileName, const QString& subfolder) |
143 HbLanguageDatabaseInterface *HbInputUtils::languageDatabasePluginInstance(const QString &pluginFileName, const QString &subfolder) |
147 { |
144 { |
148 if (!QLibrary::isLibrary(pluginFileName)) { |
145 if (!QLibrary::isLibrary(pluginFileName)) { |
149 qDebug("HbInputUtils::languageDatabasePluginInstance: Not a library!"); |
146 qDebug("HbInputUtils::languageDatabasePluginInstance: Not a library!"); |
150 return NULL; |
147 return NULL; |
151 } |
148 } |
152 |
149 |
153 HbLanguageDatabaseInterface* res = NULL; |
150 HbLanguageDatabaseInterface *res = NULL; |
154 |
151 |
155 QString fullName(HbInputSettingProxy::languageDatabasePath()); |
152 QString fullName(HbInputSettingProxy::languageDatabasePath()); |
156 fullName += QDir::separator(); |
153 fullName += QDir::separator(); |
157 if (subfolder.length() > 0) { |
154 if (subfolder.length() > 0) { |
158 fullName += subfolder; |
155 fullName += subfolder; |
159 fullName += QDir::separator(); |
156 fullName += QDir::separator(); |
160 } |
157 } |
161 fullName += pluginFileName; |
158 fullName += pluginFileName; |
162 |
159 |
163 QPluginLoader loader(fullName); |
160 QPluginLoader loader(fullName); |
164 QObject* plugin = loader.instance(); |
161 QObject *plugin = loader.instance(); |
165 |
162 |
166 if (plugin) { |
163 if (plugin) { |
167 res = qobject_cast<HbLanguageDatabaseInterface*>(plugin); |
164 res = qobject_cast<HbLanguageDatabaseInterface *>(plugin); |
168 } else { |
165 } else { |
169 qDebug("HbInputUtils::languageDatabasePluginInstance: Unable to instantiate plugin"); |
166 qDebug("HbInputUtils::languageDatabasePluginInstance: Unable to instantiate plugin"); |
170 } |
167 } |
171 |
168 |
172 return res; |
169 return res; |
183 /*! |
180 /*! |
184 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. |
185 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 |
186 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. |
187 */ |
184 */ |
188 QWidget* HbInputUtils::createWrapperWidget(QGraphicsWidget* graphicsWidget) |
185 QWidget *HbInputUtils::createWrapperWidget(QGraphicsWidget *graphicsWidget) |
189 { |
186 { |
190 QWidget *ret = 0; |
187 QWidget *ret = 0; |
191 |
188 |
192 if (graphicsWidget) { |
189 if (graphicsWidget) { |
193 ret = new QWidget; |
190 ret = new QWidget; |
230 HbInputDigitType HbInputUtils::inputDigitType(HbInputLanguage language) |
227 HbInputDigitType HbInputUtils::inputDigitType(HbInputLanguage language) |
231 { |
228 { |
232 HbInputDigitType digitType = HbDigitTypeNone; |
229 HbInputDigitType digitType = HbDigitTypeNone; |
233 |
230 |
234 switch (language.language()) { |
231 switch (language.language()) { |
235 case QLocale::Arabic: |
232 case QLocale::Arabic: |
236 digitType = HbDigitTypeArabicIndic; |
233 digitType = HbDigitTypeArabicIndic; |
237 break; |
234 break; |
238 case QLocale::Persian: |
235 case QLocale::Persian: |
239 case QLocale::Urdu: |
236 case QLocale::Urdu: |
240 digitType = HbDigitTypeEasternArabic; |
237 digitType = HbDigitTypeEasternArabic; |
241 break; |
238 break; |
242 case QLocale::Hindi: |
239 case QLocale::Hindi: |
243 digitType = HbDigitTypeDevanagari; |
240 digitType = HbDigitTypeDevanagari; |
244 break; |
241 break; |
245 default: |
242 default: |
246 digitType = HbDigitTypeLatin; |
243 digitType = HbDigitTypeLatin; |
247 break; |
244 break; |
248 } |
245 } |
249 return digitType; |
246 return digitType; |
250 } |
247 } |
251 |
248 |
252 |
249 |
253 /*! |
250 /*! |
254 Returns the proxy widget of the embedded widget in a graphics view ; |
251 Returns the proxy widget of the embedded widget in a graphics view ; |
255 if widget does not have the proxy widget then it returns the proxy widget of its window. |
252 if widget does not have the proxy widget then it returns the proxy widget of its window. |
256 otherwise returns 0. |
253 otherwise returns 0. |
257 */ |
254 */ |
258 QGraphicsProxyWidget* HbInputUtils::graphicsProxyWidget(const QWidget* w) |
255 QGraphicsProxyWidget *HbInputUtils::graphicsProxyWidget(const QWidget *w) |
259 { |
256 { |
260 QGraphicsProxyWidget *pw = w ? w->graphicsProxyWidget() : 0; |
257 QGraphicsProxyWidget *pw = w ? w->graphicsProxyWidget() : 0; |
261 if (w && !pw) { |
258 if (w && !pw) { |
262 pw = w->window() ? w->window()->graphicsProxyWidget() : w->graphicsProxyWidget(); |
259 pw = w->window() ? w->window()->graphicsProxyWidget() : w->graphicsProxyWidget(); |
263 } |
260 } |