messagingapp/msgui/unifiedviewer/src/univiewertextitem.cpp
branchRCL_3
changeset 57 ebe688cedc25
equal deleted inserted replaced
54:fa1df4b99609 57:ebe688cedc25
       
     1 /*
       
     2  * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3  * All rights reserved.
       
     4  * This component and the accompanying materials are made available
       
     5  * under the terms of "Eclipse Public License v1.0"
       
     6  * which accompanies this distribution, and is available
       
     7  * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8  *
       
     9  * Initial Contributors:
       
    10  * Nokia Corporation - initial contribution.
       
    11  *
       
    12  * Contributors:
       
    13  *
       
    14  * Description:
       
    15  * Message body preview class.
       
    16  * has in built logic for finding phone number, email, url.
       
    17  *
       
    18  */
       
    19 
       
    20 #include "univiewertextitem.h"
       
    21 #include "msgcontacthandler.h"
       
    22 
       
    23 #include <QRegExp>
       
    24 #include <QApplication>
       
    25 #include <QClipboard>
       
    26 #include <QTextBlock>
       
    27 #include <QUrl>
       
    28 #include <QDesktopServices>
       
    29 #include <HbTapGesture>
       
    30 #include <HbMenu>
       
    31 #include <HbAction>
       
    32 #include <cntservicescontact.h>
       
    33 #include <xqservicerequest.h>
       
    34 #include <xqaiwrequest.h>
       
    35 #include <xqappmgr.h>
       
    36 
       
    37 
       
    38 //consts
       
    39 
       
    40 //regexp
       
    41 const QString NUMBER_PATTERN("(\\(?(\\+|\\d))((?:\\d)((?:[\\s-/.\\)\\(])*(?:(\\d+|\\))))*(?:\\d?[^\\D]|\\)))|((\\*#)(?:\\d+(\\*|#)(?:\\d+#)?))");
       
    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])?");
       
    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\\-\\?\'\\/\\\\+&amp;%\\$#_=~]*)(\\.)([-\\w]*[0-9a-zA-Z])+(:(0-9)*)*(\\/?)([a-zA-Z0-9\\-\\?\'\\/\\\\+&amp;%\\$#_=~]*))+[a-zA-Z0-9/]");
       
    46 
       
    47 //rules
       
    48 const QString URL_RULE("0_URL_RULE");
       
    49 const QString EMAIL_RULE("1_EMAIL_RULE");
       
    50 const QString NUMBER_RULE("2_NUMBER_RULE");
       
    51 
       
    52 
       
    53 //localization
       
    54 #define LOC_CONTACT_INFO hbTrId("txt_messaging_menu_contact_info")
       
    55 #define LOC_CALL              hbTrId("txt_common_menu_call_verb")
       
    56 #define LOC_SEND_MESSAGE      hbTrId("txt_common_menu_send_message")
       
    57 #define LOC_SAVE_TO_CONTACTS  hbTrId("txt_common_menu_save_to_contacts")
       
    58 #define LOC_COPY              hbTrId("txt_common_menu_copy")
       
    59 #define LOC_CREATE_EMAIL      hbTrId("txt_messaging_menu_create_mail")
       
    60 #define LOC_OPEN_LINK         hbTrId("txt_messaging_menu_open_link")
       
    61 #define LOC_ADD_TO_BOOKMARKS  hbTrId("txt_messaging_menu_add_to_bookmarks")
       
    62 #define LOC_COPY_LINK         hbTrId("txt_messaging_menu_copy_link")
       
    63 
       
    64 UniViewerTextItem::UniViewerTextItem(QGraphicsItem* parent):
       
    65 HbTextEdit(parent),
       
    66 mFindOn(true),
       
    67 mCursorPos(-1)
       
    68 {
       
    69     this->setReadOnly(true);
       
    70     this->setScrollable(false);
       
    71     this->setCursorVisibility(Hb::TextCursorHidden);
       
    72     this->setFlag(QGraphicsItem::ItemIsFocusable,false);
       
    73     this->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
       
    74     this->setBackgroundItem(0);   
       
    75 
       
    76     //inserting rules and patterns to map.
       
    77     mRules.insert(NUMBER_RULE,NUMBER_PATTERN);
       
    78     mRules.insert(EMAIL_RULE,EMAIL_PATTERN);
       
    79     mRules.insert(URL_RULE,URL_PATTERN);
       
    80 
       
    81     mFormatNormal.setForeground(palette().link());
       
    82     mFormatNormal.setBackground(Qt::transparent);
       
    83 
       
    84     mFormatHighlight.setBackground(palette().highlight());
       
    85     mFormatHighlight.setForeground(palette().highlightedText());
       
    86 
       
    87     connect(this, SIGNAL(aboutToShowContextMenu(HbMenu*,QPointF)),
       
    88             this, SLOT(aboutToShowContextMenu(HbMenu*,QPointF)));
       
    89 }
       
    90 
       
    91 UniViewerTextItem::~UniViewerTextItem()
       
    92     {
       
    93     }
       
    94 
       
    95 void UniViewerTextItem::setFindOn(bool on)
       
    96 {
       
    97     mFindOn = on;   
       
    98 }
       
    99 
       
   100 void UniViewerTextItem::setText(const QString& text)
       
   101 {
       
   102     
       
   103     this->setPlainText(text);
       
   104     applyRule();
       
   105 }
       
   106 
       
   107 void UniViewerTextItem::applyRule()
       
   108 {
       
   109 
       
   110     if(mFindOn == false)
       
   111     {
       
   112         return;
       
   113     }
       
   114 
       
   115     QMap<QString, QString>::const_iterator i;
       
   116     for (i = mRules.constBegin(); i != mRules.constEnd(); ++i)
       
   117     {
       
   118         QString ruleName = i.key();
       
   119         QString rule = i.value();
       
   120         QRegExp ruleExp(rule);
       
   121         ruleExp.setCaseSensitivity(Qt::CaseInsensitive);
       
   122 
       
   123         QTextCursor cursor = this->document()->find(ruleExp);
       
   124 
       
   125         while(cursor.hasSelection())
       
   126         {
       
   127             int p = cursor.position();
       
   128             QString  anchor = this->anchorAt(p-1);
       
   129             
       
   130             //not identified yet.
       
   131             if(anchor.isEmpty())
       
   132             {
       
   133                 // Insert anchor in the document
       
   134                 QTextCharFormat f;
       
   135                 f.setFontUnderline(true);
       
   136                 f.setForeground(palette().link());
       
   137 
       
   138                 //prepending rule name to identiy different fragment to which
       
   139                 //catagory it belongs to.
       
   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);
       
   152             }
       
   153 
       
   154             // Find next
       
   155             cursor = this->document()->find(ruleExp, cursor);
       
   156         }
       
   157     }
       
   158 }
       
   159 
       
   160 
       
   161 void UniViewerTextItem::aboutToShowContextMenu(HbMenu *contextMenu, const QPointF &pos)
       
   162 {
       
   163     // Check if there is an anchor at this pos
       
   164     QString  anchor = this->anchorAt(pos);
       
   165 
       
   166     if(!anchor.isEmpty() && !this->textCursor().hasSelection())
       
   167     {
       
   168         //remove default actions.
       
   169         contextMenu->clearActions();
       
   170 
       
   171         if(anchor.contains(QRegExp("^"+NUMBER_RULE)))
       
   172         {
       
   173             addNumberMenu(contextMenu,anchor);
       
   174         }
       
   175         else if(anchor.contains(QRegExp("^"+EMAIL_RULE)))
       
   176         {
       
   177             addEmailMenu(contextMenu,anchor);
       
   178         }
       
   179         else if(anchor.contains(QRegExp("^"+URL_RULE)))
       
   180         {
       
   181             addUrlMenu(contextMenu,anchor);
       
   182         }
       
   183     }
       
   184 
       
   185     connect(contextMenu,SIGNAL(aboutToClose()),this,SLOT(menuClosed()));
       
   186     
       
   187 }
       
   188 
       
   189 void UniViewerTextItem::gestureEvent(QGestureEvent* event)
       
   190 {
       
   191     //handle gesture to highlight and dehighlight find item.
       
   192     
       
   193     if(HbTapGesture *tap = qobject_cast<HbTapGesture*>(event->gesture(Qt::TapGesture)))
       
   194     {
       
   195         //capturing gesture position, and map to local co-ordinates.
       
   196         QPointF pos = mapFromScene(tap->scenePosition());
       
   197         
       
   198         switch (tap->state()) 
       
   199         {
       
   200             case Qt::GestureStarted:
       
   201             {
       
   202                 //highlight find item.
       
   203                 QTextDocument* doc = this->document();
       
   204                 mCursorPos = doc->documentLayout()->hitTest(pos, Qt::ExactHit);
       
   205                 highlightText(true);
       
   206                 break;
       
   207             }  
       
   208             
       
   209             case Qt::GestureFinished:
       
   210             {
       
   211                 if (HbTapGesture::Tap == tap->tapStyleHint()) 
       
   212                 {
       
   213                     //gesture is finshed dehighlight text.
       
   214                     highlightText(false);
       
   215                     
       
   216                     QString anchor = this->anchorAt(pos);
       
   217                     
       
   218                     //do short tap action.
       
   219                     if (!anchor.isEmpty() && !this->textCursor().hasSelection())
       
   220                     {
       
   221                         handleShortTap(anchor,tap->scenePosition());
       
   222                     }
       
   223                 }
       
   224                 break;
       
   225             }
       
   226             
       
   227             case Qt::GestureCanceled:
       
   228             {
       
   229                 //gesture is canceled due to pan or swipe, dehighlight text.
       
   230                 if (HbTapGesture::Tap == tap->tapStyleHint()) 
       
   231                 {
       
   232                 highlightText(false);
       
   233                 break;
       
   234                 }
       
   235             }
       
   236             default:
       
   237                 break;
       
   238         }
       
   239         event->accept();
       
   240     }
       
   241     else
       
   242     {
       
   243         event->ignore();
       
   244     }
       
   245     
       
   246     //passing gesture event to base class.
       
   247     HbTextEdit::gestureEvent(event);
       
   248 }
       
   249 
       
   250 void UniViewerTextItem::addNumberMenu(HbMenu* contextMenu,const QString& data)
       
   251 {
       
   252     HbAction* action = NULL;
       
   253 
       
   254     QString number = data;
       
   255     number.remove(NUMBER_RULE);
       
   256     int contactId = MsgContactHandler::resolveContactDisplayName(
       
   257                                  number, 
       
   258                                  QContactPhoneNumber::DefinitionName,
       
   259                                  QContactPhoneNumber::FieldNumber); 
       
   260     
       
   261     if(contactId > 0)
       
   262     {
       
   263         action = contextMenu->addAction(LOC_CONTACT_INFO, this, SLOT(openContactInfo()));
       
   264         action->setData(data);
       
   265     }
       
   266     else
       
   267     {
       
   268         action = contextMenu->addAction(LOC_SAVE_TO_CONTACTS, this, SLOT(saveToContacts()));
       
   269         action->setData(data);  
       
   270     }
       
   271 
       
   272     action = contextMenu->addAction(LOC_CALL, this, SLOT(call()));
       
   273     action->setData(data);
       
   274 
       
   275     action = contextMenu->addAction(LOC_SEND_MESSAGE, this, SLOT(sendMessage()));
       
   276     action->setData(data);
       
   277 
       
   278     action = contextMenu->addAction(LOC_COPY, this, SLOT(copyToClipboard()));
       
   279     action->setData(data);
       
   280 }
       
   281 
       
   282 void UniViewerTextItem::addEmailMenu(HbMenu* contextMenu,const QString& data)
       
   283 {
       
   284     HbAction* action = NULL;
       
   285     
       
   286     action = contextMenu->addAction(LOC_CREATE_EMAIL, this, SLOT(createEmail()));
       
   287     action->setData(data);
       
   288     
       
   289     action = contextMenu->addAction(LOC_CONTACT_INFO, this, SLOT(openContactInfo()));
       
   290     action->setData(data);
       
   291 
       
   292     action = contextMenu->addAction(LOC_SAVE_TO_CONTACTS, this, SLOT(saveToContacts()));
       
   293     action->setData(data);
       
   294 
       
   295     action = contextMenu->addAction(LOC_COPY, this, SLOT(copyToClipboard()));
       
   296     action->setData(data);
       
   297 }
       
   298 
       
   299 void UniViewerTextItem::addUrlMenu(HbMenu* contextMenu,const QString& data)
       
   300 {
       
   301     HbAction* action = NULL;
       
   302     
       
   303     action = contextMenu->addAction(LOC_OPEN_LINK, this, SLOT(openLink()));
       
   304     action->setData(data);
       
   305 
       
   306     action = contextMenu->addAction(LOC_ADD_TO_BOOKMARKS, this, SLOT(addToBookmarks()));
       
   307     action->setData(data);
       
   308 
       
   309     action = contextMenu->addAction(LOC_COPY_LINK, this, SLOT(copyToClipboard()));
       
   310     action->setData(data);
       
   311 }
       
   312 
       
   313 void UniViewerTextItem::handleShortTap(QString anchor,const QPointF& pos)
       
   314 {
       
   315     HbAction action;
       
   316     action.setData(anchor);
       
   317 
       
   318     if(anchor.contains(NUMBER_RULE))
       
   319     {
       
   320         QString data = anchor;
       
   321         data.remove(NUMBER_RULE);
       
   322         int contactId = MsgContactHandler::resolveContactDisplayName(
       
   323                                      data, 
       
   324                                      QContactPhoneNumber::DefinitionName,
       
   325                                      QContactPhoneNumber::FieldNumber);        
       
   326        
       
   327         if(contactId > 0 )
       
   328         {
       
   329             //if resolved conatct open contact card 
       
   330             connect(&action,SIGNAL(triggered()),this,SLOT(openContactInfo()));
       
   331         }
       
   332         else
       
   333         {
       
   334             //unresolved contact show popup.  
       
   335             highlightText(true);
       
   336 
       
   337             HbMenu* contextMenu = new HbMenu();
       
   338             contextMenu->setDismissPolicy(HbPopup::TapAnywhere);
       
   339             contextMenu->setAttribute(Qt::WA_DeleteOnClose, true);
       
   340             contextMenu->setPreferredPos(pos); 
       
   341             connect(contextMenu,SIGNAL(aboutToClose()),this,SLOT(menuClosed()));
       
   342             
       
   343             addNumberMenu(contextMenu,anchor);
       
   344             
       
   345             contextMenu->show();
       
   346         }
       
   347     }
       
   348     else if(anchor.contains(EMAIL_RULE))
       
   349     {
       
   350         //Create email
       
   351         connect(&action,SIGNAL(triggered()),this,SLOT(createEmail()));
       
   352     }
       
   353     else if(anchor.contains(URL_RULE))
       
   354     {
       
   355         //Open link in the browser
       
   356         connect(&action,SIGNAL(triggered()),this,SLOT(openLink()));
       
   357     }
       
   358     
       
   359     action.trigger();
       
   360 }
       
   361 
       
   362 
       
   363 void UniViewerTextItem::copyToClipboard()
       
   364 {
       
   365     HbAction* action = qobject_cast<HbAction*>(sender());
       
   366 
       
   367     if(action)
       
   368     {
       
   369         QMimeData* data = new QMimeData();
       
   370         QString str = action->data().toString();
       
   371 
       
   372         //removing rule name before setting it to clipboard.
       
   373         str.remove(QRegExp("^"+NUMBER_RULE));
       
   374         str.remove(QRegExp("^"+EMAIL_RULE));
       
   375         str.remove(QRegExp("^"+URL_RULE));
       
   376 
       
   377         data->setText(str);
       
   378         QApplication::clipboard()->setMimeData(data);
       
   379     }
       
   380 }
       
   381 
       
   382 void UniViewerTextItem::call()
       
   383 {
       
   384     HbAction* action = qobject_cast<HbAction*>(sender());
       
   385 
       
   386     if(action)
       
   387     {
       
   388         QString phoneNumber = action->data().toString();
       
   389         phoneNumber.remove(NUMBER_RULE);
       
   390         
       
   391         //invoke dialer service and pass phoneNumber.        
       
   392         QString serviceName("com.nokia.symbian.ICallDial");
       
   393         QString operation("dial(QString)");
       
   394         
       
   395         XQServiceRequest* serviceRequest = new XQServiceRequest(serviceName,operation,false);
       
   396         
       
   397         connect(serviceRequest, SIGNAL(requestCompleted(QVariant)),
       
   398                 this, SLOT(onServiceRequestCompleted()));
       
   399         
       
   400         connect(serviceRequest, SIGNAL(requestError(int)),
       
   401                 this, SLOT(onServiceRequestCompleted()));
       
   402         
       
   403         *serviceRequest << phoneNumber;
       
   404         serviceRequest->send();
       
   405     }
       
   406 }
       
   407 
       
   408 void UniViewerTextItem::sendMessage()
       
   409 {
       
   410     HbAction* action = qobject_cast<HbAction*>(sender());
       
   411 
       
   412     if(action)
       
   413     {
       
   414         QString phoneNumber = action->data().toString();
       
   415         phoneNumber.remove(NUMBER_RULE);
       
   416         
       
   417         //invoke editor & pass phoneNumber.
       
   418         emit sendMessage(phoneNumber);
       
   419     }
       
   420 }
       
   421 
       
   422 void UniViewerTextItem::createEmail()
       
   423 {
       
   424     HbAction* action = qobject_cast<HbAction*>(sender());
       
   425 
       
   426     if ( action )
       
   427     {
       
   428         QString emailId = action->data().toString();
       
   429         emailId.remove(EMAIL_RULE);
       
   430 
       
   431         // Launch email editor
       
   432         QString interfaceName("com.nokia.symbian.IEmailMessageSend");
       
   433         QString operation("send(QVariant)");
       
   434         XQApplicationManager appManager;
       
   435         XQAiwRequest* request = appManager.create(interfaceName, 
       
   436 			operation, true); 
       
   437         if ( request == NULL )
       
   438             {
       
   439             return;       
       
   440             }
       
   441     
       
   442         // Fill args
       
   443         QStringList recipients;
       
   444         recipients.append(emailId);
       
   445     
       
   446         QMap<QString,QVariant> map;
       
   447         map.insert(QString("to"),recipients);
       
   448     
       
   449         QList<QVariant> args;
       
   450         args.append(map);
       
   451         
       
   452         // Result handlers
       
   453         connect (request, SIGNAL(requestOk(const QVariant&)), 
       
   454          this, SLOT(handleOk(const QVariant&)));
       
   455         connect (request, SIGNAL(requestError(const QVariant&)), 
       
   456              this, SLOT(handleError(const QVariant&)));
       
   457         
       
   458         request->setArguments(args);
       
   459         request->send();
       
   460         delete request;       
       
   461     }
       
   462 }
       
   463 
       
   464 void UniViewerTextItem::openLink()
       
   465 {
       
   466     HbAction* action = qobject_cast<HbAction*>(sender());
       
   467 
       
   468     if(action)
       
   469     {
       
   470         QString url = action->data().toString();
       
   471         url.remove(URL_RULE);
       
   472         //invoke browser service  & pass url.
       
   473         QUrl uri(url);
       
   474         QDesktopServices::openUrl(uri);
       
   475     }
       
   476 }
       
   477 
       
   478 void UniViewerTextItem::addToBookmarks()
       
   479 {
       
   480     HbAction* action = qobject_cast<HbAction*>(sender());
       
   481 
       
   482     if(action)
       
   483     {
       
   484         QString url = action->data().toString();
       
   485         url.remove(URL_RULE);
       
   486         //invoke browser service to save url.
       
   487     }
       
   488 }
       
   489 
       
   490 void UniViewerTextItem::openContactInfo()
       
   491 {
       
   492     HbAction* action = qobject_cast<HbAction*>(sender());
       
   493     
       
   494     if(action)
       
   495     {
       
   496         QList<QVariant> args;
       
   497         QString operation;
       
   498         
       
   499         QString data = action->data().toString();
       
   500         
       
   501         if(data.contains(QRegExp("^"+NUMBER_RULE)))
       
   502         {
       
   503             data.remove(NUMBER_RULE);
       
   504     
       
   505             int contactId = MsgContactHandler::resolveContactDisplayName(
       
   506                                          data, 
       
   507                                          QContactPhoneNumber::DefinitionName,
       
   508                                          QContactPhoneNumber::FieldNumber);
       
   509     
       
   510             if(contactId > 0)
       
   511                 {
       
   512                 //open contact card
       
   513                 operation = QString("open(int)");
       
   514                 args << contactId;
       
   515                 }
       
   516             else
       
   517                 {
       
   518                 //save to contacts with phone number field prefilled.
       
   519         
       
   520                 operation = QString("editCreateNew(QString,QString)");
       
   521                 QString type = QContactPhoneNumber::DefinitionName;
       
   522         
       
   523                 args << type;
       
   524                 args << data;
       
   525                 }
       
   526         }
       
   527         else if(data.contains(QRegExp("^"+EMAIL_RULE)))
       
   528         {
       
   529             data.remove(EMAIL_RULE);
       
   530     
       
   531             int contactId = MsgContactHandler::resolveContactDisplayName(
       
   532                     data,
       
   533                     QContactEmailAddress::DefinitionName,
       
   534                     QContactEmailAddress::FieldEmailAddress);
       
   535             
       
   536             if(contactId > 0)
       
   537                 {
       
   538                 //open contact card
       
   539                 operation = QString("open(int)");
       
   540                 args << contactId;
       
   541                 }
       
   542             else
       
   543                 {
       
   544                 //save to contacts with e-mail field prefilled.
       
   545         
       
   546                 operation = QString("editCreateNew(QString,QString)");                
       
   547                 
       
   548                 QString type = QContactEmailAddress::DefinitionName;
       
   549         
       
   550                 args << type;
       
   551                 args << data;
       
   552                 }
       
   553         }
       
   554         
       
   555         //service stuff.
       
   556         QString serviceName("com.nokia.services.phonebookservices");
       
   557      
       
   558         XQAiwRequest* request;
       
   559         XQApplicationManager appManager;
       
   560         request = appManager.create(serviceName, "Fetch", operation, true); // embedded
       
   561         if ( request == NULL )
       
   562             {
       
   563             return;       
       
   564             }
       
   565 
       
   566         // Result handlers
       
   567         connect (request, SIGNAL(requestOk(const QVariant&)), 
       
   568 			this, SLOT(handleOk(const QVariant&)));
       
   569         connect (request, SIGNAL(requestError(const QVariant&)), 
       
   570 			this, SLOT(handleError(const QVariant&)));
       
   571         
       
   572         request->setArguments(args);
       
   573         request->send();
       
   574         delete request;
       
   575     }
       
   576 }
       
   577 
       
   578 
       
   579 void UniViewerTextItem::saveToContacts()
       
   580 {
       
   581      openContactInfo();
       
   582 }
       
   583 
       
   584 void UniViewerTextItem::onServiceRequestCompleted()
       
   585     {
       
   586     //service request is now complete. delete it.
       
   587     
       
   588     XQServiceRequest* request = qobject_cast<XQServiceRequest*>(sender());
       
   589     
       
   590     if(request)
       
   591         {
       
   592         delete request;
       
   593         }
       
   594     }
       
   595 
       
   596 void UniViewerTextItem::menuClosed()
       
   597 {
       
   598     highlightText(false);
       
   599 }
       
   600 
       
   601 void UniViewerTextItem::highlightText(bool highlight)
       
   602 {
       
   603     QTextBlock textBlock = this->document()->findBlock(mCursorPos);
       
   604 
       
   605     QTextBlock::iterator it;
       
   606 
       
   607     for (it = textBlock.begin(); !(it.atEnd()); ++it)
       
   608     {
       
   609         QTextFragment currentFragment = it.fragment();
       
   610         
       
   611         if (currentFragment.isValid() && currentFragment.contains(mCursorPos)
       
   612             && currentFragment.charFormat().fontUnderline())
       
   613         {
       
   614             int start = currentFragment.position();
       
   615             int length = currentFragment.length();
       
   616 
       
   617             QTextCursor cursor = this->textCursor();
       
   618             cursor.clearSelection();
       
   619             cursor.setPosition(start);
       
   620             cursor.setPosition(start + length,QTextCursor::KeepAnchor);
       
   621 
       
   622             if(highlight)
       
   623             {
       
   624                 cursor.mergeCharFormat(mFormatHighlight);
       
   625             }
       
   626             else
       
   627             {
       
   628                 cursor.mergeCharFormat(mFormatNormal);
       
   629             }
       
   630 
       
   631             cursor.clearSelection();
       
   632             break;
       
   633         }
       
   634     }
       
   635 }
       
   636 
       
   637 //---------------------------------------------------------------
       
   638 // UniViewerTextItem::handleOk
       
   639 //
       
   640 //---------------------------------------------------------------
       
   641 void UniViewerTextItem::handleOk(const QVariant& result)
       
   642     {
       
   643     Q_UNUSED(result)
       
   644     }
       
   645 
       
   646 //---------------------------------------------------------------
       
   647 // UniViewerTextItem::handleError
       
   648 // 
       
   649 //---------------------------------------------------------------
       
   650 void UniViewerTextItem::handleError(int errorCode, const QString& errorMessage)
       
   651     {
       
   652     Q_UNUSED(errorMessage)
       
   653     Q_UNUSED(errorCode)
       
   654     }