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 #include <QUrl> |
|
28 #include <QDesktopServices> |
|
29 #include <HbTapGesture> |
29 #include <HbMenu> |
30 #include <HbMenu> |
30 #include <HbAction> |
31 #include <HbAction> |
31 #include <HbFrameItem> |
|
32 #include <cntservicescontact.h> |
32 #include <cntservicescontact.h> |
33 #include <XQServiceRequest.h> |
33 #include <xqservicerequest.h> |
34 #include <xqaiwrequest.h> |
34 #include <xqaiwrequest.h> |
35 #include <xqappmgr.h> |
35 #include <xqappmgr.h> |
36 |
36 |
37 |
37 |
38 //consts |
38 //consts |
39 |
39 |
40 //regexp |
40 //regexp |
41 const QString NUMBER_PATTERN("(\\(|\\+|\\d)((?:\\d{2,})((?:[\\s-/.\\)\\()])*(?:(\\d+|\\))))*)|((\\*#)(?:\\d+(\\*|#)(?:\\d+#)?))"); |
41 const QString NUMBER_PATTERN("(\\(?(\\+|\\d))((?:\\d)((?:[\\s-/.\\)\\(])*(?:(\\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\\-\\?\\,\'\\/\\\\+&%\\$#_=~]*))+"); |
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 NUMBER_RULE("NUMBER_RULE"); |
49 const QString EMAIL_RULE("EMAIL_RULE"); |
49 const QString EMAIL_RULE("EMAIL_RULE"); |
50 const QString URL_RULE("URL_RULE"); |
50 const QString URL_RULE("URL_RULE"); |
51 |
51 |
52 //localization |
52 //localization |
53 #define LOC_OPEN_CONTACT_INFO hbTrId("txt_messaging_menu_open_contact_info") |
53 #define LOC_CONTACT_INFO hbTrId("txt_messaging_menu_contact_info") |
54 #define LOC_CALL hbTrId("txt_common_menu_call_verb") |
54 #define LOC_CALL hbTrId("txt_common_menu_call_verb") |
55 #define LOC_SEND_MESSAGE hbTrId("txt_common_menu_send_message") |
55 #define LOC_SEND_MESSAGE hbTrId("txt_common_menu_send_message") |
56 #define LOC_SAVE_TO_CONTACTS hbTrId("txt_common_menu_save_to_contacts") |
56 #define LOC_SAVE_TO_CONTACTS hbTrId("txt_common_menu_save_to_contacts") |
57 #define LOC_COPY hbTrId("txt_common_menu_copy") |
57 #define LOC_COPY hbTrId("txt_common_menu_copy") |
58 #define LOC_CREATE_EMAIL hbTrId("txt_messaging_menu_create_mail") |
58 #define LOC_CREATE_EMAIL hbTrId("txt_messaging_menu_create_mail") |
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 handleShortTap(anchor,tap->scenePosition()); |
|
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; |
209 |
245 |
210 action = contextMenu->addAction(LOC_OPEN_CONTACT_INFO, this, SLOT(openContactInfo())); |
246 QString number = data; |
211 action->setData(data); |
247 number.remove(NUMBER_RULE); |
|
248 int contactId = MsgContactHandler::resolveContactDisplayName( |
|
249 number, |
|
250 QContactPhoneNumber::DefinitionName, |
|
251 QContactPhoneNumber::FieldNumber); |
|
252 |
|
253 if(contactId > 0) |
|
254 { |
|
255 action = contextMenu->addAction(LOC_CONTACT_INFO, this, SLOT(openContactInfo())); |
|
256 action->setData(data); |
|
257 } |
|
258 else |
|
259 { |
|
260 action = contextMenu->addAction(LOC_SAVE_TO_CONTACTS, this, SLOT(saveToContacts())); |
|
261 action->setData(data); |
|
262 } |
212 |
263 |
213 action = contextMenu->addAction(LOC_CALL, this, SLOT(call())); |
264 action = contextMenu->addAction(LOC_CALL, this, SLOT(call())); |
214 action->setData(data); |
265 action->setData(data); |
215 |
266 |
216 action = contextMenu->addAction(LOC_SEND_MESSAGE, this, SLOT(sendMessage())); |
267 action = contextMenu->addAction(LOC_SEND_MESSAGE, this, SLOT(sendMessage())); |
217 action->setData(data); |
268 action->setData(data); |
218 |
269 |
|
270 action = contextMenu->addAction(LOC_COPY, this, SLOT(copyToClipboard())); |
|
271 action->setData(data); |
|
272 } |
|
273 |
|
274 void UniViewerTextItem::addEmailMenu(HbMenu* contextMenu,const QString& data) |
|
275 { |
|
276 HbAction* action = NULL; |
|
277 |
|
278 action = contextMenu->addAction(LOC_CREATE_EMAIL, this, SLOT(createEmail())); |
|
279 action->setData(data); |
|
280 |
|
281 action = contextMenu->addAction(LOC_CONTACT_INFO, this, SLOT(openContactInfo())); |
|
282 action->setData(data); |
|
283 |
219 action = contextMenu->addAction(LOC_SAVE_TO_CONTACTS, this, SLOT(saveToContacts())); |
284 action = contextMenu->addAction(LOC_SAVE_TO_CONTACTS, this, SLOT(saveToContacts())); |
220 action->setData(data); |
285 action->setData(data); |
221 |
286 |
222 action = contextMenu->addAction(LOC_COPY, this, SLOT(copyToClipboard())); |
287 action = contextMenu->addAction(LOC_COPY, this, SLOT(copyToClipboard())); |
223 action->setData(data); |
288 action->setData(data); |
224 } |
289 } |
225 |
290 |
226 void UniViewerTextItem::addEmailMenu(HbMenu* contextMenu,const QString& data) |
291 void UniViewerTextItem::addUrlMenu(HbMenu* contextMenu,const QString& data) |
227 { |
292 { |
228 HbAction* action = NULL; |
293 HbAction* action = NULL; |
229 |
294 |
230 action = contextMenu->addAction(LOC_CREATE_EMAIL, this, SLOT(createEmail())); |
|
231 action->setData(data); |
|
232 |
|
233 action = contextMenu->addAction(LOC_OPEN_CONTACT_INFO, this, SLOT(openContactInfo())); |
|
234 action->setData(data); |
|
235 |
|
236 action = contextMenu->addAction(LOC_SAVE_TO_CONTACTS, this, SLOT(saveToContacts())); |
|
237 action->setData(data); |
|
238 |
|
239 action = contextMenu->addAction(LOC_COPY, this, SLOT(copyToClipboard())); |
|
240 action->setData(data); |
|
241 } |
|
242 |
|
243 void UniViewerTextItem::addUrlMenu(HbMenu* contextMenu,const QString& data) |
|
244 { |
|
245 HbAction* action = NULL; |
|
246 |
|
247 action = contextMenu->addAction(LOC_OPEN_LINK, this, SLOT(openLink())); |
295 action = contextMenu->addAction(LOC_OPEN_LINK, this, SLOT(openLink())); |
248 action->setData(data); |
296 action->setData(data); |
249 |
297 |
250 action = contextMenu->addAction(LOC_ADD_TO_BOOKMARKS, this, SLOT(addToBookmarks())); |
298 action = contextMenu->addAction(LOC_ADD_TO_BOOKMARKS, this, SLOT(addToBookmarks())); |
251 action->setData(data); |
299 action->setData(data); |
252 |
300 |
253 action = contextMenu->addAction(LOC_COPY_LINK, this, SLOT(copyToClipboard())); |
301 action = contextMenu->addAction(LOC_COPY_LINK, this, SLOT(copyToClipboard())); |
254 action->setData(data); |
302 action->setData(data); |
255 } |
303 } |
256 |
304 |
257 void UniViewerTextItem::shortTapAction(QString anchor) |
305 void UniViewerTextItem::handleShortTap(QString anchor,const QPointF& pos) |
258 { |
306 { |
259 HbAction action; |
307 HbAction action; |
260 action.setData(anchor); |
308 action.setData(anchor); |
261 |
309 |
262 if(anchor.contains(NUMBER_RULE)) |
310 if(anchor.contains(NUMBER_RULE)) |
263 { |
311 { |
264 //open vcard template. |
312 QString data = anchor; |
265 connect(&action,SIGNAL(triggered()),this,SLOT(openContactInfo())); |
313 data.remove(NUMBER_RULE); |
|
314 int contactId = MsgContactHandler::resolveContactDisplayName( |
|
315 data, |
|
316 QContactPhoneNumber::DefinitionName, |
|
317 QContactPhoneNumber::FieldNumber); |
|
318 |
|
319 if(contactId > 0 ) |
|
320 { |
|
321 //if resolved conatct open contact card |
|
322 connect(&action,SIGNAL(triggered()),this,SLOT(openContactInfo())); |
|
323 } |
|
324 else |
|
325 { |
|
326 //unresolved contact show popup. |
|
327 highlightText(true); |
|
328 |
|
329 HbMenu* contextMenu = new HbMenu(); |
|
330 contextMenu->setDismissPolicy(HbPopup::TapAnywhere); |
|
331 contextMenu->setAttribute(Qt::WA_DeleteOnClose, true); |
|
332 contextMenu->setPreferredPos(pos); |
|
333 connect(contextMenu,SIGNAL(aboutToClose()),this,SLOT(menuClosed())); |
|
334 |
|
335 addNumberMenu(contextMenu,anchor); |
|
336 |
|
337 contextMenu->show(); |
|
338 } |
266 } |
339 } |
267 else if(anchor.contains(EMAIL_RULE)) |
340 else if(anchor.contains(EMAIL_RULE)) |
268 { |
341 { |
269 //Create email |
342 //Create email |
270 connect(&action,SIGNAL(triggered()),this,SLOT(createEmail())); |
343 connect(&action,SIGNAL(triggered()),this,SLOT(createEmail())); |