messagingapp/msgui/unifiedviewer/src/univiewertextitem.cpp
changeset 41 25fe1fe642e3
parent 38 4e4b6adb1024
child 46 b1f0785c289d
equal deleted inserted replaced
40:224522e33db9 41:25fe1fe642e3
    36 
    36 
    37 
    37 
    38 //consts
    38 //consts
    39 
    39 
    40 //regexp
    40 //regexp
    41 const QString NUMBER_PATTERN("(\\(?(\\+|\\d))((?:\\d)((?:[\\s-/.\\)\\(])*(?:(\\d+|\\))))*(?:\\d?|\\)))|((\\*#)(?:\\d+(\\*|#)(?:\\d+#)?))");
    41 const QString NUMBER_PATTERN("(\\(?(\\+|\\d))((?:\\d)((?:[\\s-/.\\)\\(])*(?:(\\d+|\\))))*(?:\\d?[^\\D]|\\)))|((\\*#)(?:\\d+(\\*|#)(?:\\d+#)?))");
    42 
    42 
    43 const QString EMAIL_PATTERN("[a-zA-Z0-9!#$%&'*+/=?^_`{|}~-]+(?:\\.[a-zA-Z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?\\.)+[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?");
    43 const QString EMAIL_PATTERN("[a-zA-Z0-9!#$%&'*+/=?^_`{|}~-]+(?:\\.[a-zA-Z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?\\.)+[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?");
    44 
    44 
    45 const QString URL_PATTERN("(((ht|f|rt)(tp|sp)(s?)\\:\\/\\/)|(www|wap)(?:\\.))(([-\\w]*[0-9a-zA-Z])+(:(0-9)*)*(\\/?)([a-zA-Z0-9\\-\\?\\,\'\\/\\\\+&%\\$#_=~]*)(\\.)([-\\w]*[0-9a-zA-Z])+(:(0-9)*)*(\\/?)([a-zA-Z0-9\\-\\?\\,\'\\/\\\\+&%\\$#_=~]*))+[a-zA-Z0-9/]");
    45 const QString URL_PATTERN("(((ht|f|rt)(tp|sp)(s?)\\:\\/\\/)|(www|wap)(?:\\.))(([-\\w]*[0-9a-zA-Z])+(:(0-9)*)*(\\/?)([a-zA-Z0-9\\-\\?\\,\'\\/\\\\+&%\\$#_=~]*)(\\.)([-\\w]*[0-9a-zA-Z])+(:(0-9)*)*(\\/?)([a-zA-Z0-9\\-\\?\\,\'\\/\\\\+&%\\$#_=~]*))+[a-zA-Z0-9/]");
    46 
    46 
    47 //rules
    47 //rules
    48 const QString NUMBER_RULE("NUMBER_RULE");
    48 const QString URL_RULE("0_URL_RULE");
    49 const QString EMAIL_RULE("EMAIL_RULE");
    49 const QString EMAIL_RULE("1_EMAIL_RULE");
    50 const QString URL_RULE("URL_RULE");
    50 const QString NUMBER_RULE("2_NUMBER_RULE");
       
    51 
    51 
    52 
    52 //localization
    53 //localization
    53 #define LOC_CONTACT_INFO hbTrId("txt_messaging_menu_contact_info")
    54 #define LOC_CONTACT_INFO hbTrId("txt_messaging_menu_contact_info")
    54 #define LOC_CALL              hbTrId("txt_common_menu_call_verb")
    55 #define LOC_CALL              hbTrId("txt_common_menu_call_verb")
    55 #define LOC_SEND_MESSAGE      hbTrId("txt_common_menu_send_message")
    56 #define LOC_SEND_MESSAGE      hbTrId("txt_common_menu_send_message")
   121 
   122 
   122         QTextCursor cursor = this->document()->find(ruleExp);
   123         QTextCursor cursor = this->document()->find(ruleExp);
   123 
   124 
   124         while(cursor.hasSelection())
   125         while(cursor.hasSelection())
   125         {
   126         {
   126             // Insert anchor in the document
   127             int p = cursor.position();
   127             QTextCharFormat f;
   128             QString  anchor = this->anchorAt(p-1);
   128             f.setFontUnderline(true);
   129             
   129             f.setForeground(palette().link());
   130             //not identified yet.
   130 
   131             if(anchor.isEmpty())
   131             //prepending rule name to identiy different fragment to which
   132             {
   132             //catagory it belongs to.
   133                 // Insert anchor in the document
   133             QString txt = cursor.selectedText().prepend(ruleName);
   134                 QTextCharFormat f;
   134 
   135                 f.setFontUnderline(true);
   135             if(ruleName == NUMBER_RULE)
   136                 f.setForeground(palette().link());
   136             {
   137 
   137                 //removing special char(s) from phone numbers.
   138                 //prepending rule name to identiy different fragment to which
   138                 QRegExp numberCharExp("[\\s-/.\\(\\)]");
   139                 //catagory it belongs to.
   139                 txt = txt.remove(numberCharExp);
   140                 QString txt = cursor.selectedText().prepend(ruleName);
       
   141 
       
   142                 if(ruleName == NUMBER_RULE)
       
   143                 {
       
   144                     //removing special char(s) from phone numbers.
       
   145                     QRegExp numberCharExp("[\\s-/.\\(\\)]");
       
   146                     txt = txt.remove(numberCharExp);
       
   147                 }
       
   148 
       
   149                 f.setAnchorHref(txt);
       
   150                 f.setAnchor(true);
       
   151                 cursor.mergeCharFormat(f);
   140             }
   152             }
   141 
       
   142             f.setAnchorHref(txt);
       
   143             f.setAnchor(true);
       
   144             cursor.mergeCharFormat(f);
       
   145 
   153 
   146             // Find next
   154             // Find next
   147             cursor = this->document()->find(ruleExp, cursor);
   155             cursor = this->document()->find(ruleExp, cursor);
   148         }
   156         }
   149     }
   157     }