author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Tue, 06 Jul 2010 14:12:40 +0300 | |
changeset 44 | 36f374c67aa8 |
parent 34 | 84197e66a4bd |
child 47 | 5b14749788d7 |
child 52 | 12db4185673b |
permissions | -rw-r--r-- |
31 | 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:Custom widget derived from HbTextEdit which provides rich text |
|
15 |
* processing |
|
16 |
* |
|
17 |
*/ |
|
18 |
||
19 |
#include "univieweraddresswidget.h" |
|
20 |
||
21 |
// SYSTEM INCLUDES |
|
22 |
#include <QTextCursor> |
|
23 |
#include <QTextBlock> |
|
24 |
#include <QApplication> |
|
34
84197e66a4bd
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
25 |
#include <QClipboard> |
84197e66a4bd
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
26 |
|
84197e66a4bd
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
27 |
#include <HbMenu> |
84197e66a4bd
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
28 |
#include <HbAction> |
84197e66a4bd
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
29 |
#include <HbTapGesture> |
84197e66a4bd
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
30 |
|
31 | 31 |
#include <xqservicerequest.h> |
32 |
#include <xqappmgr.h> |
|
33 |
#include <cntservicescontact.h> |
|
34 |
#include <qtcontacts.h> |
|
34
84197e66a4bd
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
35 |
#include <xqservicerequest.h> |
31 | 36 |
#include <xqaiwrequest.h> |
37 |
#include "msgcontacthandler.h" |
|
38 |
||
39 |
// LOCAL CONSTANTS |
|
40 |
const QString ADDRESS_SEPARATOR("; "); |
|
41 |
const QString ADDRESS_OPEN(" ("); |
|
42 |
const QString ADDRESS_CLOSE(")"); |
|
43 |
const QString SPACE(" "); |
|
44 |
||
45 |
//localization |
|
46 |
#define LOC_OPEN_CONTACT_INFO hbTrId("txt_messaging_menu_open_contact_info") |
|
47 |
#define LOC_CALL hbTrId("txt_common_menu_call_verb") |
|
48 |
#define LOC_SEND_MESSAGE hbTrId("txt_common_menu_send_message") |
|
49 |
#define LOC_SAVE_TO_CONTACTS hbTrId("txt_common_menu_save_to_contacts") |
|
50 |
#define LOC_COPY hbTrId("txt_common_menu_copy") |
|
51 |
||
52 |
const QString BG_FRAME_GRAPHICS("qtg_fr_lineedit_normal"); |
|
53 |
||
54 |
//--------------------------------------------------------------- |
|
55 |
// UniViewerAddressWidget::UniViewerAddressWidget |
|
56 |
// @see header file |
|
57 |
//--------------------------------------------------------------- |
|
58 |
UniViewerAddressWidget::UniViewerAddressWidget(QGraphicsItem * parent) : |
|
59 |
HbTextEdit(parent), |
|
60 |
mCursorPos(-1) |
|
61 |
{ |
|
34
84197e66a4bd
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
62 |
this->setReadOnly(true); |
31 | 63 |
this->setScrollable(false); |
34
84197e66a4bd
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
64 |
this->setFlag(QGraphicsItem::ItemIsFocusable,false); |
84197e66a4bd
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
65 |
this->setCursorVisibility(Hb::TextCursorHidden); |
84197e66a4bd
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
66 |
this->setBackgroundItem(0); |
31 | 67 |
|
68 |
HbFontSpec fontSpec(HbFontSpec::Secondary); |
|
69 |
QFont font = fontSpec.font(); |
|
70 |
this->setFont(font); |
|
71 |
||
72 |
mFormatNormal.setForeground(palette().link()); |
|
73 |
mFormatNormal.setBackground(Qt::transparent); |
|
74 |
||
75 |
mFormatHighlight.setBackground(palette().highlight()); |
|
76 |
mFormatHighlight.setForeground(palette().highlightedText()); |
|
77 |
||
78 |
connect(this, SIGNAL(aboutToShowContextMenu(HbMenu*,QPointF)), |
|
79 |
this, SLOT(aboutToShowContextMenu(HbMenu*,QPointF))); |
|
80 |
} |
|
81 |
||
82 |
//--------------------------------------------------------------- |
|
83 |
// UniViewerAddressWidget::~UniViewerAddressWidget |
|
84 |
// @see header file |
|
85 |
//--------------------------------------------------------------- |
|
86 |
UniViewerAddressWidget::~UniViewerAddressWidget() |
|
87 |
{ |
|
88 |
} |
|
89 |
||
90 |
//--------------------------------------------------------------- |
|
34
84197e66a4bd
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
91 |
//UniViewerAddressWidget :: gestureEvent |
31 | 92 |
// @see header file |
93 |
//--------------------------------------------------------------- |
|
34
84197e66a4bd
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
94 |
void UniViewerAddressWidget::gestureEvent(QGestureEvent* event) |
31 | 95 |
{ |
34
84197e66a4bd
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
96 |
//handle gesture to highlight and dehighlight find item. |
84197e66a4bd
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
97 |
|
84197e66a4bd
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
98 |
if(HbTapGesture *tap = qobject_cast<HbTapGesture*>(event->gesture(Qt::TapGesture))) |
84197e66a4bd
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
99 |
{ |
84197e66a4bd
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
100 |
//capturing gesture position, and map to local co-ordinates. |
84197e66a4bd
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
101 |
QPointF pos = mapFromScene(tap->scenePosition()); |
84197e66a4bd
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
102 |
|
84197e66a4bd
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
103 |
switch (tap->state()) |
84197e66a4bd
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
104 |
{ |
84197e66a4bd
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
105 |
case Qt::GestureStarted: |
84197e66a4bd
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
106 |
{ |
84197e66a4bd
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
107 |
//highlight find item. |
84197e66a4bd
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
108 |
QTextDocument* doc = this->document(); |
84197e66a4bd
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
109 |
mCursorPos = doc->documentLayout()->hitTest(pos, Qt::ExactHit); |
84197e66a4bd
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
110 |
highlightText(true); |
84197e66a4bd
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
111 |
break; |
84197e66a4bd
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
112 |
} |
84197e66a4bd
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
113 |
|
84197e66a4bd
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
114 |
case Qt::GestureFinished: |
84197e66a4bd
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
115 |
{ |
84197e66a4bd
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
116 |
if (HbTapGesture::Tap == tap->tapStyleHint()) |
84197e66a4bd
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
117 |
{ |
84197e66a4bd
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
118 |
//gesture is finshed dehighlight text. |
84197e66a4bd
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
119 |
highlightText(false); |
84197e66a4bd
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
120 |
|
84197e66a4bd
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
121 |
QString anchor = this->anchorAt(pos); |
84197e66a4bd
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
122 |
|
84197e66a4bd
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
123 |
//do short tap action. |
84197e66a4bd
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
124 |
if (!anchor.isEmpty() && !this->textCursor().hasSelection()) |
84197e66a4bd
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
125 |
{ |
84197e66a4bd
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
126 |
shortTapAction(anchor); |
84197e66a4bd
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
127 |
} |
84197e66a4bd
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
128 |
} |
84197e66a4bd
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
129 |
break; |
84197e66a4bd
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
130 |
} |
84197e66a4bd
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
131 |
|
84197e66a4bd
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
132 |
case Qt::GestureCanceled: |
84197e66a4bd
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
133 |
{ |
84197e66a4bd
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
134 |
//gesture is canceled due to pan or swipe, dehighlight text. |
84197e66a4bd
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
135 |
if (HbTapGesture::Tap == tap->tapStyleHint()) |
84197e66a4bd
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
136 |
{ |
84197e66a4bd
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
137 |
highlightText(false); |
84197e66a4bd
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
138 |
break; |
84197e66a4bd
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
139 |
} |
84197e66a4bd
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
140 |
} |
84197e66a4bd
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
141 |
default: |
84197e66a4bd
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
142 |
break; |
84197e66a4bd
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
143 |
} |
84197e66a4bd
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
144 |
|
84197e66a4bd
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
145 |
event->accept(); |
84197e66a4bd
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
146 |
} |
84197e66a4bd
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
147 |
else |
84197e66a4bd
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
148 |
{ |
84197e66a4bd
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
149 |
event->ignore(); |
84197e66a4bd
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
150 |
} |
84197e66a4bd
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
151 |
|
84197e66a4bd
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
152 |
//passing gesture event to base class. |
84197e66a4bd
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
153 |
HbTextEdit::gestureEvent(event); |
31 | 154 |
} |
155 |
||
156 |
||
157 |
//---------------------------------------------------------------------------- |
|
158 |
// UniViewerAddressWidget::populate |
|
159 |
// @see header file |
|
160 |
//---------------------------------------------------------------------------- |
|
161 |
void UniViewerAddressWidget::populate(const QString &label, |
|
162 |
const QString &address, |
|
163 |
const QString &alias) |
|
164 |
{ |
|
165 |
QString labelText = label; |
|
166 |
labelText.trimmed(); |
|
167 |
labelText += SPACE; |
|
168 |
||
169 |
//Font. |
|
170 |
HbFontSpec fontSpec(HbFontSpec::Secondary); |
|
171 |
qreal fontHeight = 0.0; |
|
172 |
style()->parameter("hb-param-text-height-tiny", fontHeight); |
|
173 |
fontSpec.setTextHeight(fontHeight); |
|
174 |
QFont font = fontSpec.font(); |
|
175 |
||
176 |
QTextCharFormat labelFormat; |
|
177 |
labelFormat.setFont(font); |
|
178 |
||
179 |
QTextCharFormat addressFormat; |
|
180 |
addressFormat.setForeground(palette().link()); |
|
181 |
addressFormat.setFontUnderline(true); |
|
182 |
||
183 |
// Insert the label then the addresses |
|
184 |
QTextCursor cursor(this->textCursor()); |
|
185 |
cursor.insertText(labelText,labelFormat); |
|
186 |
||
187 |
QString address1 = QString(); |
|
188 |
if (!(alias.isEmpty())) |
|
189 |
{ |
|
190 |
address1.append(alias); |
|
191 |
QString alias1 = QString(); |
|
192 |
||
193 |
int totalNumbers = 0; |
|
194 |
MsgContactHandler::resolveContactDisplayName( |
|
195 |
address, |
|
196 |
alias1, |
|
197 |
totalNumbers); |
|
198 |
if (totalNumbers > 1) |
|
199 |
{ |
|
200 |
address1.append(ADDRESS_OPEN); |
|
201 |
address1.append(address); |
|
202 |
address1.append(ADDRESS_CLOSE); |
|
203 |
} |
|
204 |
} |
|
205 |
else |
|
206 |
{ |
|
207 |
address1.append(address); |
|
208 |
} |
|
209 |
addressFormat.setAnchorHref(address); |
|
210 |
cursor.insertText(address1, addressFormat); |
|
211 |
} |
|
212 |
||
213 |
//---------------------------------------------------------------------------- |
|
214 |
// UniViewerAddressWidget::populate |
|
215 |
// @see header file |
|
216 |
//---------------------------------------------------------------------------- |
|
217 |
void UniViewerAddressWidget::populate(const QString &label, |
|
218 |
ConvergedMessageAddressList addressList) |
|
219 |
{ |
|
220 |
QString labelText = label; |
|
221 |
labelText.trimmed(); |
|
222 |
labelText += SPACE; |
|
223 |
||
224 |
//Font. |
|
225 |
HbFontSpec fontSpec(HbFontSpec::Secondary); |
|
226 |
qreal fontHeight = 0.0; |
|
227 |
style()->parameter("hb-param-text-height-tiny", fontHeight); |
|
228 |
fontSpec.setTextHeight(fontHeight); |
|
229 |
QFont font = fontSpec.font(); |
|
230 |
||
231 |
QTextCharFormat labelFormat; |
|
232 |
labelFormat.setFont(font); |
|
233 |
||
234 |
QTextCharFormat defaultFormat; |
|
235 |
defaultFormat.setForeground(palette().link()); |
|
236 |
||
237 |
QTextCharFormat addressFormat; |
|
238 |
addressFormat.setForeground(palette().link()); |
|
239 |
addressFormat.setFontUnderline(true); |
|
240 |
||
241 |
// Insert the label then the addresses |
|
242 |
QTextCursor cursor(this->document()); |
|
243 |
cursor.insertText(labelText,labelFormat); |
|
244 |
||
245 |
int addressCount = addressList.count(); |
|
246 |
||
247 |
for (int i = 0; i < addressCount; ++i) |
|
248 |
{ |
|
249 |
||
250 |
QString address = QString(); |
|
251 |
if (! (addressList[i]->alias().isEmpty())) |
|
252 |
{ |
|
253 |
address.append(addressList[i]->alias()); |
|
254 |
QString alias = QString(); |
|
255 |
||
256 |
int totalNumbers = 0; |
|
257 |
MsgContactHandler::resolveContactDisplayName( |
|
258 |
addressList[i]->address(), |
|
259 |
alias, |
|
260 |
totalNumbers); |
|
261 |
if (totalNumbers > 1) |
|
262 |
{ |
|
263 |
address.append(ADDRESS_OPEN); |
|
264 |
address.append(addressList[i]->address()); |
|
265 |
address.append(ADDRESS_CLOSE); |
|
266 |
} |
|
267 |
} |
|
268 |
else |
|
269 |
{ |
|
270 |
address.append(addressList[i]->address()); |
|
271 |
} |
|
272 |
||
273 |
addressFormat.setAnchorHref(addressList[i]->address()); |
|
274 |
cursor.insertText(address, addressFormat); |
|
275 |
||
276 |
if (addressCount - 1 != i) |
|
277 |
{ |
|
278 |
cursor.insertText(ADDRESS_SEPARATOR, defaultFormat); |
|
279 |
} |
|
280 |
||
281 |
} |
|
282 |
} |
|
283 |
||
284 |
//---------------------------------------------------------------------------- |
|
285 |
// UniViewerAddressWidget::clearContent |
|
286 |
// @see header file |
|
287 |
//---------------------------------------------------------------------------- |
|
288 |
void UniViewerAddressWidget::clearContent() |
|
289 |
{ |
|
290 |
this->document()->clear(); |
|
291 |
} |
|
292 |
||
293 |
//---------------------------------------------------------------------------- |
|
294 |
// UniViewerAddressWidget::menuClosed |
|
295 |
// @see header file |
|
296 |
//---------------------------------------------------------------------------- |
|
297 |
void UniViewerAddressWidget::menuClosed() |
|
298 |
{ |
|
299 |
highlightText(false); |
|
300 |
} |
|
301 |
||
302 |
//---------------------------------------------------------------------------- |
|
303 |
// UniViewerAddressWidget::highlightText |
|
304 |
// @see header file |
|
305 |
//---------------------------------------------------------------------------- |
|
306 |
void UniViewerAddressWidget::highlightText(bool highlight) |
|
307 |
{ |
|
308 |
QTextBlock textBlock = this->document()->findBlock(mCursorPos); |
|
309 |
||
310 |
QTextBlock::iterator it; |
|
311 |
||
312 |
for (it = textBlock.begin(); !(it.atEnd()); ++it) |
|
313 |
{ |
|
314 |
QTextFragment currentFragment = it.fragment(); |
|
315 |
||
316 |
if (currentFragment.isValid() && currentFragment.contains(mCursorPos) |
|
317 |
&& currentFragment.charFormat().fontUnderline()) |
|
318 |
{ |
|
319 |
int start = currentFragment.position(); |
|
320 |
int length = currentFragment.length(); |
|
321 |
||
322 |
QTextCursor cursor = this->textCursor(); |
|
323 |
cursor.clearSelection(); |
|
324 |
cursor.setPosition(start); |
|
325 |
cursor.setPosition(start + length,QTextCursor::KeepAnchor); |
|
326 |
||
327 |
if(highlight) |
|
328 |
{ |
|
329 |
cursor.mergeCharFormat(mFormatHighlight); |
|
330 |
} |
|
331 |
else |
|
332 |
{ |
|
333 |
cursor.mergeCharFormat(mFormatNormal); |
|
334 |
} |
|
335 |
||
336 |
cursor.clearSelection(); |
|
337 |
break; |
|
338 |
} |
|
339 |
} |
|
340 |
} |
|
341 |
||
342 |
void UniViewerAddressWidget::aboutToShowContextMenu(HbMenu *contextMenu, const QPointF &pos) |
|
343 |
{ |
|
344 |
//remove default actions. |
|
345 |
contextMenu->clearActions(); |
|
346 |
||
347 |
// Check if there is an anchor at this pos |
|
348 |
QString anchor = this->anchorAt(pos); |
|
349 |
||
350 |
if(!anchor.isEmpty() && !this->textCursor().hasSelection()) |
|
351 |
{ |
|
352 |
||
353 |
HbAction* action = NULL; |
|
354 |
||
355 |
action = contextMenu->addAction(LOC_OPEN_CONTACT_INFO, this, SLOT(openContactInfo())); |
|
356 |
action->setData(anchor); |
|
357 |
||
358 |
action = contextMenu->addAction(LOC_CALL, this, SLOT(call())); |
|
359 |
action->setData(anchor); |
|
360 |
||
361 |
action = contextMenu->addAction(LOC_SEND_MESSAGE, this, SLOT(sendMessage())); |
|
362 |
action->setData(anchor); |
|
363 |
||
364 |
action = contextMenu->addAction(LOC_SAVE_TO_CONTACTS, this, SLOT(saveToContacts())); |
|
365 |
action->setData(anchor); |
|
366 |
||
367 |
action = contextMenu->addAction(LOC_COPY, this, SLOT(copyToClipboard())); |
|
368 |
action->setData(anchor); |
|
369 |
||
370 |
} |
|
371 |
||
372 |
connect(contextMenu,SIGNAL(aboutToClose()),this,SLOT(menuClosed())); |
|
373 |
} |
|
374 |
||
375 |
void UniViewerAddressWidget::shortTapAction(QString anchor) |
|
376 |
{ |
|
377 |
HbAction action; |
|
378 |
action.setData(anchor); |
|
379 |
connect(&action,SIGNAL(triggered()),this,SLOT(openContactInfo())); |
|
380 |
action.trigger(); |
|
381 |
} |
|
382 |
||
383 |
void UniViewerAddressWidget::copyToClipboard() |
|
384 |
{ |
|
385 |
HbAction* action = qobject_cast<HbAction*>(sender()); |
|
386 |
||
387 |
if(action) |
|
388 |
{ |
|
389 |
QMimeData* data = new QMimeData(); |
|
390 |
QString str = action->data().toString(); |
|
391 |
data->setText(str); |
|
392 |
QApplication::clipboard()->setMimeData(data); |
|
393 |
} |
|
394 |
} |
|
395 |
||
396 |
void UniViewerAddressWidget::call() |
|
397 |
{ |
|
398 |
HbAction* action = qobject_cast<HbAction*>(sender()); |
|
399 |
||
400 |
if(action) |
|
401 |
{ |
|
402 |
QString phoneNumber = action->data().toString(); |
|
403 |
||
404 |
//invoke dialer service and pass phoneNumber. |
|
34
84197e66a4bd
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
405 |
QString serviceName("com.nokia.symbian.ICallDial"); |
31 | 406 |
QString operation("dial(QString)"); |
407 |
||
408 |
XQServiceRequest* serviceRequest = new XQServiceRequest(serviceName,operation,false); |
|
409 |
||
410 |
connect(serviceRequest, SIGNAL(requestCompleted(QVariant)), |
|
411 |
this, SLOT(onServiceRequestCompleted())); |
|
412 |
||
413 |
connect(serviceRequest, SIGNAL(requestError(int)), |
|
414 |
this, SLOT(onServiceRequestCompleted())); |
|
415 |
||
416 |
*serviceRequest << phoneNumber; |
|
417 |
serviceRequest->send(); |
|
418 |
} |
|
419 |
} |
|
420 |
||
421 |
void UniViewerAddressWidget::onServiceRequestCompleted() |
|
422 |
{ |
|
423 |
//service request is now complete. delete it. |
|
424 |
XQServiceRequest* request = qobject_cast<XQServiceRequest*>(sender()); |
|
425 |
||
426 |
if(request) |
|
427 |
{ |
|
428 |
delete request; |
|
429 |
} |
|
430 |
} |
|
431 |
||
432 |
||
433 |
void UniViewerAddressWidget::openContactInfo() |
|
434 |
{ |
|
435 |
HbAction* action = qobject_cast<HbAction*>(sender()); |
|
436 |
||
437 |
if(action) |
|
438 |
{ |
|
439 |
QList<QVariant> args; |
|
440 |
QString operation; |
|
441 |
||
442 |
QString data = action->data().toString(); |
|
443 |
||
444 |
int contactId = MsgContactHandler::resolveContactDisplayName( |
|
445 |
data, |
|
446 |
QContactPhoneNumber::DefinitionName, |
|
447 |
QContactPhoneNumber::FieldNumber); |
|
448 |
||
44
36f374c67aa8
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
34
diff
changeset
|
449 |
// if contact is unresolved on phone number field |
36f374c67aa8
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
34
diff
changeset
|
450 |
// then, try resolving it on email address field |
36f374c67aa8
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
34
diff
changeset
|
451 |
if(contactId <= 0) |
36f374c67aa8
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
34
diff
changeset
|
452 |
{ |
36f374c67aa8
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
34
diff
changeset
|
453 |
contactId = MsgContactHandler::resolveContactDisplayName( |
36f374c67aa8
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
34
diff
changeset
|
454 |
data, |
36f374c67aa8
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
34
diff
changeset
|
455 |
QContactEmailAddress::DefinitionName, |
36f374c67aa8
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
34
diff
changeset
|
456 |
QContactEmailAddress::FieldEmailAddress); |
36f374c67aa8
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
34
diff
changeset
|
457 |
} |
36f374c67aa8
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
34
diff
changeset
|
458 |
|
31 | 459 |
if(contactId > 0) |
460 |
{ |
|
461 |
//open contact card |
|
462 |
operation = QString("open(int)"); |
|
463 |
args << contactId; |
|
464 |
} |
|
465 |
else |
|
466 |
{ |
|
467 |
//save to contacts with phone number field prefilled. |
|
468 |
||
469 |
operation = QString("editCreateNew(QString,QString)"); |
|
470 |
QString type = QContactPhoneNumber::DefinitionName; |
|
471 |
||
472 |
args << type; |
|
473 |
args << data; |
|
474 |
} |
|
475 |
||
476 |
//service stuff. |
|
477 |
QString serviceName("com.nokia.services.phonebookservices"); |
|
478 |
||
479 |
XQAiwRequest* request; |
|
480 |
XQApplicationManager appManager; |
|
481 |
request = appManager.create(serviceName, "Fetch", operation, true); // embedded |
|
482 |
if ( request == NULL ) |
|
483 |
{ |
|
484 |
return; |
|
485 |
} |
|
486 |
||
487 |
// Result handlers |
|
488 |
connect (request, SIGNAL(requestOk(const QVariant&)), |
|
489 |
this, SLOT(handleOk(const QVariant&))); |
|
490 |
connect (request, SIGNAL(requestError(const QVariant&)), |
|
491 |
this, SLOT(handleError(const QVariant&))); |
|
492 |
||
493 |
request->setArguments(args); |
|
494 |
request->send(); |
|
495 |
delete request; |
|
496 |
} |
|
497 |
} |
|
498 |
||
499 |
void UniViewerAddressWidget::handleOk(const QVariant& result) |
|
500 |
{ |
|
501 |
Q_UNUSED(result) |
|
502 |
} |
|
503 |
||
504 |
void UniViewerAddressWidget::handleError(int errorCode, const QString& errorMessage) |
|
505 |
{ |
|
506 |
Q_UNUSED(errorMessage) |
|
507 |
Q_UNUSED(errorCode) |
|
508 |
} |
|
509 |
||
510 |
void UniViewerAddressWidget::saveToContacts() |
|
511 |
{ |
|
512 |
//handler for save to contacts. |
|
513 |
} |
|
514 |
||
515 |
void UniViewerAddressWidget::sendMessage() |
|
516 |
{ |
|
517 |
HbAction* action = qobject_cast<HbAction*>(sender()); |
|
518 |
||
519 |
if(action) |
|
520 |
{ |
|
521 |
QString phoneNumber = action->data().toString(); |
|
522 |
QString alias; |
|
523 |
||
524 |
QTextBlock textBlock = this->document()->findBlock(mCursorPos); |
|
525 |
||
526 |
QTextBlock::iterator it; |
|
527 |
||
528 |
for (it = textBlock.begin(); !(it.atEnd()); ++it) |
|
529 |
{ |
|
530 |
QTextFragment currentFragment = it.fragment(); |
|
531 |
||
532 |
if (currentFragment.isValid() && currentFragment.contains(mCursorPos) |
|
533 |
&& currentFragment.charFormat().fontUnderline()) |
|
534 |
{ |
|
535 |
QString txt = currentFragment.text(); |
|
536 |
if(txt != phoneNumber) |
|
537 |
{ |
|
538 |
alias = txt; |
|
539 |
} |
|
540 |
break; |
|
541 |
} |
|
542 |
} |
|
543 |
||
544 |
||
545 |
//invoke editor & pass phoneNumber. |
|
546 |
emit sendMessage(phoneNumber,alias); |
|
547 |
} |
|
548 |
} |
|
549 |
||
550 |
// EOF |