src/hbcore/inputfw/hbinpututils.cpp
changeset 5 627c4a0fd0e7
parent 2 06ff229162e9
child 6 c3690ec91ef8
equal deleted inserted replaced
3:11d3954df52a 5:627c4a0fd0e7
    40 #include "hbinputlanguagedatabase.h"
    40 #include "hbinputlanguagedatabase.h"
    41 #include "hbinputmodecache_p.h"
    41 #include "hbinputmodecache_p.h"
    42 #include "hbinputlanguage.h"
    42 #include "hbinputlanguage.h"
    43 #include "hbinpututils.h"
    43 #include "hbinpututils.h"
    44 
    44 
    45 #define HB_DIGIT_ARABIC_INDIC_START_VALUE 0x0660
    45 #define HB_DIGIT_ARABIC_INDIC_START_VALUE   0x0660
    46 
    46 #define HB_DIGIT_EASTERN_ARABIC_START_VALUE 0x06F0
    47 
    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 
    48 
    72 /*!
    49 /*!
    73 \class HbInputUtils
    50 \class HbInputUtils
    74 \brief A collection input related utility methods.
    51 \brief A collection input related utility methods.
    75 
    52 
    90 */
    67 */
    91 QChar HbInputUtils::findFirstNumberCharacterBoundToKey(const HbMappedKey* key,
    68 QChar HbInputUtils::findFirstNumberCharacterBoundToKey(const HbMappedKey* key,
    92                                                        const HbInputLanguage language,
    69                                                        const HbInputLanguage language,
    93                                                        const HbInputDigitType digitType)
    70                                                        const HbInputDigitType digitType)
    94 {
    71 {
       
    72     Q_UNUSED(language);
       
    73 	
    95     if (key) {
    74     if (key) {
    96         QString chars = key->characters(HbModifierNone);
    75         QString chars = key->characters(HbModifierNone);
    97         if (usesLatinDigits(language.language(), digitType)) {
    76         if (digitType == HbDigitTypeLatin) {
    98             for (int i = 0; i < chars.length(); i++) {
    77             for (int i = 0; i < chars.length(); i++) {
    99                 if (chars.at(i) >= '0' && chars.at(i) <= '9') {
    78                 if (chars.at(i) >= '0' && chars.at(i) <= '9') {
   100                     return chars.at(i);
    79                     return chars.at(i);
   101                 }
    80                 }
   102             }
    81             }
   108             }
    87             }
   109         } else if (digitType == HbDigitTypeArabicIndic) {
    88         } else if (digitType == HbDigitTypeArabicIndic) {
   110             for (int i = 0; i < chars.length(); i++) {
    89             for (int i = 0; i < chars.length(); i++) {
   111                 if (chars.at(i) >= '0' && chars.at(i) <= '9') {
    90                 if (chars.at(i) >= '0' && chars.at(i) <= '9') {
   112                     return HB_DIGIT_ARABIC_INDIC_START_VALUE +
    91                     return HB_DIGIT_ARABIC_INDIC_START_VALUE +
   113 						(chars.at(i).toAscii() - '0');
    92 						(chars.at(i).unicode() - '0');
   114                 }
    93                 }
   115             }
    94             }
   116         } else if (digitType == HbDigitTypeEasternArabic) {
    95         } else if (digitType == HbDigitTypeEasternArabic) {
   117             for (int i = 0; i < chars.length(); i++) {
    96             for (int i = 0; i < chars.length(); i++) {
   118                 if (chars.at(i) >= 0x06F0 && chars.at(i) <= 0x06F9) {
    97                 if (chars.at(i) >= '0' && chars.at(i) <= '9') {
   119                     return chars.at(i);
    98                     return HB_DIGIT_EASTERN_ARABIC_START_VALUE +
       
    99 						(chars.at(i).unicode() - '0');
   120                 }
   100                 }
   121             }
   101             }
   122         }
   102         }
   123     }
   103     }
   124 
   104 
   253 
   233 
   254     switch (language.language()) {
   234     switch (language.language()) {
   255         case QLocale::Arabic:
   235         case QLocale::Arabic:
   256             digitType = HbDigitTypeArabicIndic;
   236             digitType = HbDigitTypeArabicIndic;
   257             break;
   237             break;
       
   238         case QLocale::Persian:
       
   239 		case QLocale::Urdu:	
       
   240             digitType = HbDigitTypeEasternArabic;
       
   241             break;
       
   242         case QLocale::Hindi:
       
   243 			digitType = HbDigitTypeDevanagari;
       
   244 			break;
   258         default:
   245         default:
   259             digitType = HbDigitTypeLatin;
   246             digitType = HbDigitTypeLatin;
   260 			break;		
   247 			break;		
   261     }
   248     }
   262     return digitType;
   249     return digitType;
   263 }
   250 }
       
   251 
       
   252 
       
   253 /*!
       
   254 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.
       
   256  otherwise returns 0.
       
   257 */
       
   258 QGraphicsProxyWidget* HbInputUtils::graphicsProxyWidget(const QWidget* w)
       
   259 {
       
   260     QGraphicsProxyWidget *pw = w ? w->graphicsProxyWidget() : 0;
       
   261     if (w && !pw) {
       
   262         pw = w->window() ? w->window()->graphicsProxyWidget() : w->graphicsProxyWidget();
       
   263     }
       
   264     return pw;
       
   265 }
       
   266 
       
   267 
   264 // End of file
   268 // End of file
   265 
   269