messagingapp/msgui/unifiedviewer/src/univieweraddresswidget.cpp
changeset 52 12db4185673b
parent 44 36f374c67aa8
child 70 a15d9966050f
equal deleted inserted replaced
44:36f374c67aa8 52:12db4185673b
    41 const QString ADDRESS_OPEN(" (");
    41 const QString ADDRESS_OPEN(" (");
    42 const QString ADDRESS_CLOSE(")");
    42 const QString ADDRESS_CLOSE(")");
    43 const QString SPACE(" ");
    43 const QString SPACE(" ");
    44 
    44 
    45 //localization
    45 //localization
    46 #define LOC_OPEN_CONTACT_INFO hbTrId("txt_messaging_menu_open_contact_info")
    46 #define LOC_CONTACT_INFO      hbTrId("txt_messaging_menu_contact_info")
    47 #define LOC_CALL              hbTrId("txt_common_menu_call_verb")
    47 #define LOC_CALL              hbTrId("txt_common_menu_call_verb")
    48 #define LOC_SEND_MESSAGE      hbTrId("txt_common_menu_send_message")
    48 #define LOC_SEND_MESSAGE      hbTrId("txt_common_menu_send_message")
    49 #define LOC_SAVE_TO_CONTACTS  hbTrId("txt_common_menu_save_to_contacts")
    49 #define LOC_SAVE_TO_CONTACTS  hbTrId("txt_common_menu_save_to_contacts")
    50 #define LOC_COPY              hbTrId("txt_common_menu_copy")
    50 #define LOC_COPY              hbTrId("txt_common_menu_copy")
    51 
    51 
   121                     QString anchor = this->anchorAt(pos);
   121                     QString anchor = this->anchorAt(pos);
   122                     
   122                     
   123                     //do short tap action.
   123                     //do short tap action.
   124                     if (!anchor.isEmpty() && !this->textCursor().hasSelection())
   124                     if (!anchor.isEmpty() && !this->textCursor().hasSelection())
   125                     {
   125                     {
   126                         shortTapAction(anchor);
   126                         shortTapAction(anchor,tap->scenePosition());
   127                     }
   127                     }
   128                 }
   128                 }
   129                 break;
   129                 break;
   130             }
   130             }
   131             
   131             
   347     // Check if there is an anchor at this pos
   347     // Check if there is an anchor at this pos
   348     QString  anchor = this->anchorAt(pos);
   348     QString  anchor = this->anchorAt(pos);
   349 
   349 
   350     if(!anchor.isEmpty() && !this->textCursor().hasSelection())
   350     if(!anchor.isEmpty() && !this->textCursor().hasSelection())
   351     {
   351     {
   352 
   352         populateMenu(contextMenu,anchor);
   353         HbAction* action = NULL;
   353     }
   354 
   354 }
   355         action = contextMenu->addAction(LOC_OPEN_CONTACT_INFO, this, SLOT(openContactInfo()));
   355 
   356         action->setData(anchor);
   356 void UniViewerAddressWidget::populateMenu(HbMenu* contextMenu,const QString& data)
   357 
   357 {
   358         action = contextMenu->addAction(LOC_CALL, this, SLOT(call()));
   358     HbAction* action = NULL;
   359         action->setData(anchor);
   359 
   360 
   360     int contactId = MsgContactHandler::resolveContactDisplayName(
   361         action = contextMenu->addAction(LOC_SEND_MESSAGE, this, SLOT(sendMessage()));
   361                                  data, 
   362         action->setData(anchor);
   362                                  QContactPhoneNumber::DefinitionName,
   363 
   363                                  QContactPhoneNumber::FieldNumber); 
       
   364     
       
   365     if(contactId > 0)
       
   366     {
       
   367         action = contextMenu->addAction(LOC_CONTACT_INFO, this, SLOT(openContactInfo()));
       
   368         action->setData(data);
       
   369     }
       
   370     else
       
   371     {
   364         action = contextMenu->addAction(LOC_SAVE_TO_CONTACTS, this, SLOT(saveToContacts()));
   372         action = contextMenu->addAction(LOC_SAVE_TO_CONTACTS, this, SLOT(saveToContacts()));
   365         action->setData(anchor);
   373         action->setData(data);  
   366 
   374     }
   367         action = contextMenu->addAction(LOC_COPY, this, SLOT(copyToClipboard()));
   375 
   368         action->setData(anchor);
   376     action = contextMenu->addAction(LOC_CALL, this, SLOT(call()));
   369 
   377     action->setData(data);
   370     }
   378 
   371 
   379     action = contextMenu->addAction(LOC_SEND_MESSAGE, this, SLOT(sendMessage()));
   372     connect(contextMenu,SIGNAL(aboutToClose()),this,SLOT(menuClosed()));    
   380     action->setData(data);
   373 }
   381 
   374 
   382     action = contextMenu->addAction(LOC_COPY, this, SLOT(copyToClipboard()));
   375 void UniViewerAddressWidget::shortTapAction(QString anchor)
   383     action->setData(data);
       
   384     
       
   385     connect(contextMenu,SIGNAL(aboutToClose()),this,SLOT(menuClosed())); 
       
   386 }
       
   387 
       
   388 void UniViewerAddressWidget::shortTapAction(QString anchor,const QPointF& pos)
   376 {
   389 {
   377     HbAction action;
   390     HbAction action;
   378     action.setData(anchor);
   391     action.setData(anchor);
   379     connect(&action,SIGNAL(triggered()),this,SLOT(openContactInfo()));
   392 
       
   393 
       
   394     int contactId = MsgContactHandler::resolveContactDisplayName(
       
   395         anchor, 
       
   396         QContactPhoneNumber::DefinitionName,
       
   397         QContactPhoneNumber::FieldNumber);        
       
   398 
       
   399     if(contactId > 0 )
       
   400     {
       
   401         //if resolved conatct open contact card 
       
   402         connect(&action,SIGNAL(triggered()),this,SLOT(openContactInfo()));
       
   403     }
       
   404     else
       
   405     {
       
   406         //unresolved contact show popup.  
       
   407         highlightText(true);
       
   408 
       
   409         HbMenu* contextMenu = new HbMenu();
       
   410         contextMenu->setDismissPolicy(HbPopup::TapAnywhere);
       
   411         contextMenu->setAttribute(Qt::WA_DeleteOnClose, true);
       
   412         contextMenu->setPreferredPos(pos); 
       
   413 
       
   414         populateMenu(contextMenu,anchor);
       
   415         
       
   416         contextMenu->show();
       
   417     }
       
   418 
   380     action.trigger();
   419     action.trigger();
   381 }
   420 }
   382 
   421 
   383 void UniViewerAddressWidget::copyToClipboard()
   422 void UniViewerAddressWidget::copyToClipboard()
   384 {
   423 {
   507     Q_UNUSED(errorCode)
   546     Q_UNUSED(errorCode)
   508     }
   547     }
   509 
   548 
   510 void UniViewerAddressWidget::saveToContacts()
   549 void UniViewerAddressWidget::saveToContacts()
   511 {
   550 {
   512     //handler for save to contacts.
   551     openContactInfo();
   513 }
   552 }
   514 
   553 
   515 void UniViewerAddressWidget::sendMessage()
   554 void UniViewerAddressWidget::sendMessage()
   516 {
   555 {
   517     HbAction* action = qobject_cast<HbAction*>(sender());
   556     HbAction* action = qobject_cast<HbAction*>(sender());