messagingapp/msgui/unifiedviewer/src/univiewertextitem.cpp
changeset 34 84197e66a4bd
parent 31 ebfee66fde93
child 43 35b64624a9e7
equal deleted inserted replaced
31:ebfee66fde93 34:84197e66a4bd
    19 
    19 
    20 #include "univiewertextitem.h"
    20 #include "univiewertextitem.h"
    21 #include "msgcontacthandler.h"
    21 #include "msgcontacthandler.h"
    22 
    22 
    23 #include <QRegExp>
    23 #include <QRegExp>
    24 #include <QGraphicsSceneMouseEvent>
       
    25 #include <QApplication>
    24 #include <QApplication>
    26 #include <QClipboard>
    25 #include <QClipboard>
    27 #include <QTextBlock>
    26 #include <QTextBlock>
    28 
    27 
       
    28 #include <HbTapGesture>
    29 #include <HbMenu>
    29 #include <HbMenu>
    30 #include <HbAction>
    30 #include <HbAction>
    31 #include <HbFrameItem>
       
    32 #include <cntservicescontact.h>
    31 #include <cntservicescontact.h>
    33 #include <XQServiceRequest.h>
    32 #include <xqservicerequest.h>
    34 #include <xqaiwrequest.h>
    33 #include <xqaiwrequest.h>
    35 #include <xqappmgr.h>
    34 #include <xqappmgr.h>
    36 
    35 
    37 
    36 
    38 //consts
    37 //consts
    65 mFindOn(true),
    64 mFindOn(true),
    66 mCursorPos(-1)
    65 mCursorPos(-1)
    67 {
    66 {
    68     this->setReadOnly(true);
    67     this->setReadOnly(true);
    69     this->setScrollable(false);
    68     this->setScrollable(false);
       
    69     this->setSmileysEnabled(true);
    70     this->setCursorVisibility(Hb::TextCursorHidden);
    70     this->setCursorVisibility(Hb::TextCursorHidden);
       
    71     this->setFlag(QGraphicsItem::ItemIsFocusable,false);
    71     this->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
    72     this->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
    72     HbFrameItem *noBackground = new HbFrameItem(this);
    73     this->setBackgroundItem(0);   
    73     this->setBackgroundItem(noBackground);
       
    74 
    74 
    75     //inserting rules and patterns to map.
    75     //inserting rules and patterns to map.
    76     mRules.insert(NUMBER_RULE,NUMBER_PATTERN);
    76     mRules.insert(NUMBER_RULE,NUMBER_PATTERN);
    77     mRules.insert(EMAIL_RULE,EMAIL_PATTERN);
    77     mRules.insert(EMAIL_RULE,EMAIL_PATTERN);
    78     mRules.insert(URL_RULE,URL_PATTERN);
    78     mRules.insert(URL_RULE,URL_PATTERN);
   115     for (i = mRules.constBegin(); i != mRules.constEnd(); ++i)
   115     for (i = mRules.constBegin(); i != mRules.constEnd(); ++i)
   116     {
   116     {
   117         QString ruleName = i.key();
   117         QString ruleName = i.key();
   118         QString rule = i.value();
   118         QString rule = i.value();
   119         QRegExp ruleExp(rule);
   119         QRegExp ruleExp(rule);
       
   120         ruleExp.setCaseSensitivity(Qt::CaseInsensitive);
   120 
   121 
   121         QTextCursor cursor = this->document()->find(ruleExp);
   122         QTextCursor cursor = this->document()->find(ruleExp);
   122 
   123 
   123         while(cursor.hasSelection())
   124         while(cursor.hasSelection())
   124         {
   125         {
   175 
   176 
   176     connect(contextMenu,SIGNAL(aboutToClose()),this,SLOT(menuClosed()));
   177     connect(contextMenu,SIGNAL(aboutToClose()),this,SLOT(menuClosed()));
   177     
   178     
   178 }
   179 }
   179 
   180 
   180 
   181 void UniViewerTextItem::gestureEvent(QGestureEvent* event)
   181 void UniViewerTextItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
   182 {
   182 {
   183     //handle gesture to highlight and dehighlight find item.
   183     HbTextEdit::mouseReleaseEvent(event);
   184     
   184 
   185     if(HbTapGesture *tap = qobject_cast<HbTapGesture*>(event->gesture(Qt::TapGesture)))
   185     highlightText(false);
   186     {
   186 
   187         //capturing gesture position, and map to local co-ordinates.
   187     QString anchor = this->anchorAt(event->pos());
   188         QPointF pos = mapFromScene(tap->scenePosition());
   188 
   189         
   189     if(!anchor.isEmpty() && !this->textCursor().hasSelection())
   190         switch (tap->state()) 
   190     {
   191         {
   191         shortTapAction(anchor);
   192             case Qt::GestureStarted:
   192     }
   193             {
   193 }
   194                 //highlight find item.
   194 
   195                 QTextDocument* doc = this->document();
   195 void UniViewerTextItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
   196                 mCursorPos = doc->documentLayout()->hitTest(pos, Qt::ExactHit);
   196 {
   197                 highlightText(true);
   197     HbTextEdit::mousePressEvent(event);
   198                 break;
   198 
   199             }  
   199     QTextDocument* doc = this->document();
   200             
   200 
   201             case Qt::GestureFinished:
   201     mCursorPos = doc->documentLayout()->hitTest(event->pos(), Qt::ExactHit);
   202             {
   202 
   203                 if (HbTapGesture::Tap == tap->tapStyleHint()) 
   203     highlightText(true);
   204                 {
       
   205                     //gesture is finshed dehighlight text.
       
   206                     highlightText(false);
       
   207                     
       
   208                     QString anchor = this->anchorAt(pos);
       
   209                     
       
   210                     //do short tap action.
       
   211                     if (!anchor.isEmpty() && !this->textCursor().hasSelection())
       
   212                     {
       
   213                         shortTapAction(anchor);
       
   214                     }
       
   215                 }
       
   216                 break;
       
   217             }
       
   218             
       
   219             case Qt::GestureCanceled:
       
   220             {
       
   221                 //gesture is canceled due to pan or swipe, dehighlight text.
       
   222                 if (HbTapGesture::Tap == tap->tapStyleHint()) 
       
   223                 {
       
   224                 highlightText(false);
       
   225                 break;
       
   226                 }
       
   227             }
       
   228             default:
       
   229                 break;
       
   230         }
       
   231         event->accept();
       
   232     }
       
   233     else
       
   234     {
       
   235         event->ignore();
       
   236     }
       
   237     
       
   238     //passing gesture event to base class.
       
   239     HbTextEdit::gestureEvent(event);
   204 }
   240 }
   205 
   241 
   206 void UniViewerTextItem::addNumberMenu(HbMenu* contextMenu,const QString& data)
   242 void UniViewerTextItem::addNumberMenu(HbMenu* contextMenu,const QString& data)
   207 {
   243 {
   208     HbAction* action = NULL;
   244     HbAction* action = NULL;
   306     {
   342     {
   307         QString phoneNumber = action->data().toString();
   343         QString phoneNumber = action->data().toString();
   308         phoneNumber.remove(NUMBER_RULE);
   344         phoneNumber.remove(NUMBER_RULE);
   309         
   345         
   310         //invoke dialer service and pass phoneNumber.        
   346         //invoke dialer service and pass phoneNumber.        
   311         QString serviceName("com.nokia.services.telephony");
   347         QString serviceName("com.nokia.symbian.ICallDial");
   312         QString operation("dial(QString)");
   348         QString operation("dial(QString)");
   313         
   349         
   314         XQServiceRequest* serviceRequest = new XQServiceRequest(serviceName,operation,false);
   350         XQServiceRequest* serviceRequest = new XQServiceRequest(serviceName,operation,false);
   315         
   351         
   316         connect(serviceRequest, SIGNAL(requestCompleted(QVariant)),
   352         connect(serviceRequest, SIGNAL(requestCompleted(QVariant)),
   346     {
   382     {
   347         QString emailId = action->data().toString();
   383         QString emailId = action->data().toString();
   348         emailId.remove(EMAIL_RULE);
   384         emailId.remove(EMAIL_RULE);
   349 
   385 
   350         // Launch email editor
   386         // Launch email editor
   351         QString serviceName("com.nokia.services.commonemail");
   387         QString interfaceName("com.nokia.symbian.IEmailMessageSend");
   352         QString interfaceName("imessage.send");
       
   353         QString operation("send(QVariant)");
   388         QString operation("send(QVariant)");
   354         XQApplicationManager appManager;
   389         XQApplicationManager appManager;
   355         XQAiwRequest* request = appManager.create(serviceName, interfaceName, 
   390         XQAiwRequest* request = appManager.create(interfaceName, 
   356 			operation, true); 
   391 			operation, true); 
   357         if ( request == NULL )
   392         if ( request == NULL )
   358             {
   393             {
   359             return;       
   394             return;       
   360             }
   395             }