author | hgs |
Thu, 14 Oct 2010 17:33:43 +0300 | |
changeset 76 | 38bf5461e270 |
parent 74 | 6c59112cfd31 |
permissions | -rw-r--r-- |
18
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
1 |
/* |
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
2 |
* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
3 |
* All rights reserved. |
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
4 |
* This component and the accompanying materials are made available |
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
5 |
* under the terms of "Eclipse Public License v1.0" |
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
6 |
* which accompanies this distribution, and is available |
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html". |
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
8 |
* |
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
9 |
* Initial Contributors: |
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
10 |
* Nokia Corporation - initial contribution. |
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
11 |
* |
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
12 |
* Contributors: |
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
13 |
* |
74 | 14 |
* Description: implementation of recipient field (to, cc, bcc) line editor |
15 |
* |
|
18
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
16 |
*/ |
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
17 |
|
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
18 |
#include "nmailuiwidgetsheaders.h" |
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
19 |
|
74 | 20 |
static const QString NmRecipientLineEditSemicolon(";"); |
21 |
static const QString NmRecipientLineEditDelimiter("; "); |
|
22 |
static const QRegExp NmRecipientLineEditCommaOrSemicolon("[,;]"); |
|
23 |
||
24 |
static const int NmRecipientLineEditFadedAlpha(125); |
|
18
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
25 |
|
74 | 26 |
static const int NmRecipientLineEditForegroundZValue(200); |
27 |
static const int NmRecipientLineEditBackgroundZValue(0); |
|
18
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
28 |
|
74 | 29 |
static const QString FILE_PATH_WIDGETML = ":nmrecipientlineedit.widgetml"; |
30 |
static const QString FILE_PATH_CSS = ":nmrecipientlineedit.css"; |
|
31 |
static const QString FILE_PATH_AUTOFILL_DOCML = ":nmautofilllistview.docml"; |
|
32 |
static const QString FILE_PATH_AUTOFILLITEM_WIDGETML = ":nmautofilllistviewitem.widgetml"; |
|
33 |
static const QString FILE_PATH_AUTOFILLITEM_CSS = ":nmautofilllistviewitem.css"; |
|
18
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
34 |
/*! |
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
35 |
Constructor |
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
36 |
*/ |
74 | 37 |
NmRecipientLineEdit::NmRecipientLineEdit(QGraphicsItem *parent) |
18
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
38 |
: NmHtmlLineEdit(parent), |
74 | 39 |
mNeedToGenerateEmailAddressList(true), |
40 |
mContactHistoryModel(NULL), |
|
41 |
mAutoFillPopup(NULL), |
|
42 |
mAutofillListView(NULL), |
|
43 |
mAutofillListViewItem(NULL), |
|
44 |
mPopupBackground(NULL) |
|
18
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
45 |
{ |
43 | 46 |
NM_FUNCTION; |
74 | 47 |
|
48 |
HbStyleLoader::registerFilePath(FILE_PATH_WIDGETML); |
|
49 |
HbStyleLoader::registerFilePath(FILE_PATH_CSS); |
|
50 |
HbStyleLoader::registerFilePath(FILE_PATH_AUTOFILLITEM_WIDGETML); |
|
51 |
HbStyleLoader::registerFilePath(FILE_PATH_AUTOFILLITEM_CSS); |
|
52 |
||
53 |
createAutofillComponents(); |
|
54 |
||
20
ecc8def7944a
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
55 |
connect(this, SIGNAL(textChanged(QString)), this, SLOT(handleTextChanged(QString))); |
18
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
56 |
} |
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
57 |
|
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
58 |
/*! |
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
59 |
Destructor |
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
60 |
*/ |
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
61 |
NmRecipientLineEdit::~NmRecipientLineEdit() |
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
62 |
{ |
43 | 63 |
NM_FUNCTION; |
74 | 64 |
delete mPopupBackground; |
65 |
delete mContactHistoryModel; |
|
66 |
delete mAutofillListView; |
|
67 |
||
68 |
HbStyleLoader::unregisterFilePath(FILE_PATH_WIDGETML); |
|
69 |
HbStyleLoader::unregisterFilePath(FILE_PATH_CSS); |
|
70 |
HbStyleLoader::unregisterFilePath(FILE_PATH_AUTOFILLITEM_WIDGETML); |
|
71 |
HbStyleLoader::unregisterFilePath(FILE_PATH_AUTOFILLITEM_CSS); |
|
18
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
72 |
} |
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
73 |
|
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
74 |
/*! |
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
75 |
Get the emailaddress list generated from the content of the lineedit. |
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
76 |
*/ |
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
77 |
QList<NmAddress> NmRecipientLineEdit::emailAddressList() |
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
78 |
{ |
43 | 79 |
NM_FUNCTION; |
74 | 80 |
|
18
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
81 |
if (mNeedToGenerateEmailAddressList) { |
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
82 |
// Empty mEmailAddressList. |
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
83 |
mEmailAddressList.clear(); |
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
84 |
// Generate mEmailAddressList from the lineedit content. |
74 | 85 |
generateEmailAddressList(); |
18
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
86 |
mNeedToGenerateEmailAddressList = false; |
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
87 |
} |
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
88 |
|
74 | 89 |
return mEmailAddressList; |
18
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
90 |
} |
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
91 |
|
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
92 |
/*! |
74 | 93 |
This Slot appends the selected contacts to the end of the lineedit content. |
18
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
94 |
*/ |
47 | 95 |
void NmRecipientLineEdit::addSelectedContacts(const QVariant &selectedContacts) |
18
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
96 |
{ |
43 | 97 |
NM_FUNCTION; |
74 | 98 |
|
47 | 99 |
// If user selected contact |
74 | 100 |
if (!selectedContacts.isNull()) { |
47 | 101 |
|
102 |
// If the lineedit is not empty and if there is no ";" or "; " at the end, |
|
103 |
// add a delimiter("; ") at the end. |
|
74 | 104 |
if (text().length() != 0 && !(text().endsWith(NmRecipientLineEditSemicolon)) && |
105 |
!(text().endsWith(NmRecipientLineEditDelimiter))){ |
|
106 |
||
47 | 107 |
// Move cursor to the end of the lineedit. |
74 | 108 |
setCursorPosition(text().length()); |
47 | 109 |
QTextCursor textCursor(this->textCursor()); |
110 |
// Append delimiter("; ") to the end of the lineedit |
|
74 | 111 |
textCursor.insertText(NmRecipientLineEditDelimiter); |
47 | 112 |
} |
74 | 113 |
|
47 | 114 |
CntServicesContactList contactList = qVariantValue<CntServicesContactList>(selectedContacts); |
18
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
115 |
|
23
2dc6caa42ec3
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
20
diff
changeset
|
116 |
// Loop through all the selected contacts. |
2dc6caa42ec3
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
20
diff
changeset
|
117 |
for (int i = 0; i < contactList.count(); ++i) { |
47 | 118 |
QString contactName = contactList[i].mDisplayName; |
23
2dc6caa42ec3
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
20
diff
changeset
|
119 |
QString contactEmailAddress = contactList[i].mEmailAddress; |
74 | 120 |
|
47 | 121 |
// If this contact has no name, use it's emailaddress as the display name |
74 | 122 |
if (contactName.isEmpty()) { |
47 | 123 |
// Move cursor to the end of the lineedit. |
74 | 124 |
setCursorPosition(text().length()); |
125 |
insertContactText(contactEmailAddress); |
|
18
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
126 |
} |
47 | 127 |
// If this contact has name, use the name as the display name |
18
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
128 |
else { |
43 | 129 |
// Handle a rare case: there are contacts has same name but different emailaddress. |
130 |
for (int i = 0; i != mRecipientsAddedFromContacts.count(); ++i) { |
|
131 |
if (mRecipientsAddedFromContacts.at(i).displayName() == contactName && |
|
132 |
mRecipientsAddedFromContacts.at(i).address() != contactEmailAddress) { |
|
133 |
// Differentiate this contact by supplying it's emailaddress |
|
134 |
contactName.append("<"); |
|
135 |
contactName.append(contactEmailAddress); |
|
136 |
contactName.append(">"); |
|
20
ecc8def7944a
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
137 |
} |
ecc8def7944a
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
138 |
} |
74 | 139 |
|
47 | 140 |
// Move cursor to the end of the lineedit. |
74 | 141 |
setCursorPosition(text().length()); |
142 |
insertContactText(contactName); |
|
18
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
143 |
} |
74 | 144 |
|
145 |
// Form the contact into NmAddress format. |
|
18
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
146 |
NmAddress contact; |
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
147 |
contact.setAddress(contactEmailAddress); |
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
148 |
contact.setDisplayName(contactName); |
74 | 149 |
|
43 | 150 |
// Add this NmAddress formated contact into mRecipientsAddedFromContacts. |
151 |
mRecipientsAddedFromContacts.append(contact); |
|
74 | 152 |
} |
18
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
153 |
} |
20
ecc8def7944a
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
154 |
else { |
74 | 155 |
//Request returned NULL |
43 | 156 |
NM_COMMENT("ContactsPicker request returned NULL."); |
20
ecc8def7944a
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
157 |
} |
18
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
158 |
} |
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
159 |
|
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
160 |
Q_IMPLEMENT_USER_METATYPE(CntServicesContact) |
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
161 |
Q_IMPLEMENT_USER_METATYPE_NO_OPERATORS(CntServicesContactList) |
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
162 |
|
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
163 |
/*! |
74 | 164 |
keyPressEvent handles different keypress events, and reacts to them |
18
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
165 |
*/ |
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
166 |
void NmRecipientLineEdit::keyPressEvent(QKeyEvent *keyEvent) |
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
167 |
{ |
43 | 168 |
NM_FUNCTION; |
74 | 169 |
|
18
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
170 |
if (keyEvent) { |
74 | 171 |
switch (keyEvent->key()) { |
18
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
172 |
case Qt::Key_Comma: |
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
173 |
case Qt::Key_Semicolon: |
74 | 174 |
keyPressEventSemicolon(keyEvent); |
175 |
break; |
|
176 |
||
177 |
case Qt::Key_Backspace: |
|
178 |
case Qt::Key_Delete: |
|
179 |
keyPressEventDelete(keyEvent); |
|
180 |
break; |
|
181 |
||
182 |
case Qt::Key_Left: |
|
183 |
keyPressEventLeft(keyEvent); |
|
184 |
break; |
|
185 |
||
186 |
case Qt::Key_Right: |
|
187 |
keyPressEventRight(keyEvent); |
|
20
ecc8def7944a
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
188 |
break; |
18
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
189 |
|
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
190 |
default: |
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
191 |
NmHtmlLineEdit::keyPressEvent(keyEvent); |
74 | 192 |
break; |
193 |
} // switch |
|
194 |
keyEvent->accept(); |
|
195 |
} |
|
196 |
} |
|
197 |
||
198 |
/*! |
|
199 |
* subroutine of keyPressEvent that handles semicolon and comma key presses |
|
200 |
*/ |
|
201 |
void NmRecipientLineEdit::keyPressEventSemicolon(QKeyEvent *event) |
|
202 |
{ |
|
203 |
NM_FUNCTION; |
|
204 |
QString textBeforeCursor = (text()).left(cursorPosition()); |
|
205 |
||
206 |
// No action when the lineedit is empty or cursor is after a Delimiter("; ") |
|
207 |
// or a Semicolon (";"). |
|
208 |
if ((text()).isEmpty() || textBeforeCursor.endsWith(NmRecipientLineEditDelimiter) |
|
209 |
|| textBeforeCursor.endsWith(NmRecipientLineEditSemicolon)) { |
|
210 |
event->ignore(); |
|
211 |
} |
|
212 |
else { |
|
213 |
// Generate custom keyevent for Delimiter("; ") and |
|
214 |
// forward to the base class to handle. |
|
215 |
QKeyEvent delimiterKeyEvent(event->type(), event->key(), |
|
216 |
event->modifiers(), NmRecipientLineEditDelimiter); |
|
217 |
NmHtmlLineEdit::keyPressEvent(&delimiterKeyEvent); |
|
18
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
218 |
} |
74 | 219 |
} |
220 |
||
221 |
/*! |
|
222 |
* subroutine of keyPressEvent that handles delete and backspace key presses |
|
223 |
*/ |
|
224 |
void NmRecipientLineEdit::keyPressEventDelete(QKeyEvent *event) |
|
225 |
{ |
|
226 |
NM_FUNCTION; |
|
227 |
int pos = cursorPosition(); |
|
228 |
||
229 |
// 1) if selection exists, delete it |
|
230 |
if (hasSelectedText()) { |
|
231 |
// if already selected delete it |
|
232 |
disconnect(this, SIGNAL(textChanged(QString)), |
|
233 |
this, SLOT(handleTextChanged(QString))); |
|
234 |
QKeyEvent eve(event->type(), Qt::Key_Delete, Qt::NoModifier); |
|
235 |
HbLineEdit::keyPressEvent(&eve); |
|
236 |
connect(this, SIGNAL(textChanged(QString)), |
|
237 |
this, SLOT(handleTextChanged(QString))); |
|
238 |
setCursorPosition(text().length()); |
|
239 |
handleTextChanged(text()); |
|
240 |
} else { // no selection.. |
|
241 |
// peek if earlier chars are underlined |
|
242 |
setCursorPosition(pos-2); |
|
243 |
bool isContact(textCursor().charFormat().fontUnderline()); |
|
244 |
setCursorPosition(pos); |
|
245 |
if (isContact) { |
|
246 |
// contact |
|
247 |
setCursorPosition(pos-3); |
|
248 |
setHighlight(pos-3); // creates a selection for the current contact |
|
249 |
} else { |
|
250 |
// plain text |
|
251 |
HbLineEdit::keyPressEvent(event); |
|
252 |
} |
|
18
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
253 |
} |
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
254 |
} |
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
255 |
|
74 | 256 |
/*! |
257 |
* subroutine of keyPressEvent that handles left key presses |
|
258 |
*/ |
|
259 |
void NmRecipientLineEdit::keyPressEventLeft(QKeyEvent *event) |
|
260 |
{ |
|
261 |
NM_FUNCTION; |
|
262 |
//look ahead left. |
|
263 |
int pos = cursorPosition(); |
|
264 |
QString text = this->text(); |
|
265 |
text = text.left(pos); |
|
266 |
||
267 |
//look for next seperator while going left. |
|
268 |
int semicolonPos = text.lastIndexOf(NmRecipientLineEditSemicolon); |
|
269 |
bool selectedText = hasSelectedText(); |
|
270 |
||
271 |
if (selectedText) { |
|
272 |
int selectionStart = textCursor().selectionStart(); |
|
273 |
if (selectionStart>=2) { |
|
274 |
setCursorPosition(selectionStart-2); |
|
275 |
} |
|
276 |
else { |
|
277 |
setCursorPosition(0); |
|
278 |
} |
|
279 |
textCursor().clearSelection(); |
|
280 |
} |
|
281 |
else { // not selected |
|
282 |
||
283 |
setCursorPosition(pos-2); |
|
284 |
bool isContact = textCursor().charFormat().fontUnderline(); |
|
285 |
setCursorPosition(pos); |
|
286 |
||
287 |
if (isContact) { |
|
288 |
setHighlight(pos-3); |
|
289 |
} |
|
290 |
else { |
|
291 |
if (pos-2 == semicolonPos) { |
|
292 |
setCursorPosition(pos-1); // jump over one extra char |
|
293 |
} |
|
294 |
HbLineEdit::keyPressEvent(event); |
|
295 |
} |
|
296 |
} |
|
297 |
} |
|
298 |
||
299 |
/*! |
|
300 |
* subroutine of keyPressEvent that handles right key presses |
|
301 |
*/ |
|
302 |
void NmRecipientLineEdit::keyPressEventRight(QKeyEvent *event) |
|
303 |
{ |
|
304 |
NM_FUNCTION; |
|
305 |
bool selectedText = hasSelectedText(); |
|
306 |
||
307 |
if (selectedText) { |
|
308 |
int selectionEnd = textCursor().selectionEnd(); |
|
309 |
setCursorPosition(selectionEnd+1); |
|
310 |
textCursor().clearSelection(); |
|
311 |
} |
|
312 |
else { |
|
313 |
int pos = cursorPosition(); |
|
314 |
||
315 |
//look ahead |
|
316 |
setCursorPosition(pos+3); |
|
317 |
bool isContact = textCursor().charFormat().fontUnderline(); |
|
318 |
setCursorPosition(pos); |
|
319 |
||
320 |
if (isContact) { |
|
321 |
setHighlight(pos+3); |
|
322 |
} |
|
323 |
else { |
|
324 |
int nextSemicolon = text().indexOf(NmRecipientLineEditSemicolon,pos); |
|
325 |
if (nextSemicolon==pos) { |
|
326 |
setCursorPosition(pos+1); // jump over one extra char |
|
327 |
} |
|
328 |
HbLineEdit::keyPressEvent(event); |
|
329 |
} |
|
330 |
} |
|
331 |
} |
|
18
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
332 |
|
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
333 |
/*! |
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
334 |
inputMethodEvent handles replacing user inputs "," or ";" from virtual keyboard with "; ". |
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
335 |
P.S. keyPressEvent can only catch QKeyEvent "," or ";" typed from physical keyboard |
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
336 |
*/ |
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
337 |
void NmRecipientLineEdit::inputMethodEvent(QInputMethodEvent *event) |
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
338 |
{ |
43 | 339 |
NM_FUNCTION; |
74 | 340 |
|
341 |
bool eventHandled(false); |
|
342 |
||
18
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
343 |
if (event) { |
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
344 |
QString eventText = event->commitString(); |
20
ecc8def7944a
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
345 |
|
18
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
346 |
if (!eventText.isEmpty() || event->replacementLength()) { |
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
347 |
// If typed charater from virtual keyboard is "," or ";" |
74 | 348 |
if (eventText.contains(NmRecipientLineEditCommaOrSemicolon)) { |
349 |
QString textBeforeCursor = text().left(cursorPosition()); |
|
350 |
||
351 |
// No action when the lineedit is empty or cursor is after a Delimiter("; ") |
|
18
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
352 |
// or Semicolon (";"). |
74 | 353 |
if (text().isEmpty() || textBeforeCursor.endsWith(NmRecipientLineEditDelimiter) || textBeforeCursor.endsWith(NmRecipientLineEditSemicolon)) { |
18
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
354 |
event->ignore(); |
20
ecc8def7944a
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
355 |
eventHandled = true; |
18
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
356 |
} |
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
357 |
else { |
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
358 |
// Modify event with Delimiter("; ") and forward to the base class to handle. |
74 | 359 |
event->setCommitString(NmRecipientLineEditDelimiter, event->replacementStart(), |
360 |
event->replacementLength()); |
|
18
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
361 |
NmHtmlLineEdit::inputMethodEvent(event); |
20
ecc8def7944a
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
362 |
eventHandled = true; |
18
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
363 |
} |
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
364 |
} |
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
365 |
} |
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
366 |
} |
20
ecc8def7944a
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
367 |
|
ecc8def7944a
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
368 |
// If event is not handled, forward to the base class to handle. |
ecc8def7944a
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
369 |
if (!eventHandled) { |
18
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
370 |
NmHtmlLineEdit::inputMethodEvent(event); |
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
371 |
} |
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
372 |
} |
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
373 |
|
74 | 374 |
/*! |
375 |
signal received from user screen input |
|
376 |
*/ |
|
377 |
void NmRecipientLineEdit::gestureEvent(QGestureEvent* event) |
|
378 |
{ |
|
379 |
//passing gesture event to base class. |
|
380 |
HbLineEdit::gestureEvent(event); |
|
381 |
||
382 |
if (HbTapGesture *tap = qobject_cast<HbTapGesture*>(event->gesture(Qt::TapGesture))) { |
|
383 |
||
384 |
switch (tap->state()) { |
|
385 |
case Qt::GestureFinished: |
|
386 |
if (HbTapGesture::Tap == tap->tapStyleHint()) { |
|
387 |
handleTap(); |
|
388 |
} |
|
389 |
break; |
|
390 |
default: |
|
391 |
break; |
|
392 |
} |
|
393 |
event->accept(); |
|
394 |
} |
|
395 |
else { |
|
396 |
event->ignore(); |
|
397 |
} |
|
398 |
} |
|
399 |
||
400 |
/*! |
|
401 |
user has tapped the recipient field on the screen |
|
402 |
*/ |
|
403 |
void NmRecipientLineEdit::handleTap() |
|
404 |
{ |
|
405 |
int currentPos = cursorPosition(); |
|
406 |
QString txt = text(); |
|
407 |
||
76 | 408 |
QString leftTxt = txt.left(currentPos+2); //recipient items delimeter takes 2 characters |
74 | 409 |
int previousSemicolonIndex = leftTxt.lastIndexOf(NmRecipientLineEditSemicolon,currentPos); |
410 |
if ((currentPos>0) && |
|
411 |
(currentPos==previousSemicolonIndex || currentPos==previousSemicolonIndex+1)) { |
|
76 | 412 |
//do we really need this? currentPos==previousSemicolonIndex |
74 | 413 |
//pressed just on seperator |
414 |
setCursorPosition(previousSemicolonIndex+2); |
|
415 |
} |
|
76 | 416 |
else { |
74 | 417 |
// pressed in middle of an address |
418 |
if (textCursor().charFormat().fontUnderline()) { |
|
419 |
// This entry is a "contact" |
|
76 | 420 |
setHighlight(currentPos); |
74 | 421 |
} |
422 |
} |
|
423 |
} |
|
424 |
||
18
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
425 |
/*! |
43 | 426 |
Generate a list of all the email addresses from the content of the lineedit. |
18
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
427 |
*/ |
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
428 |
void NmRecipientLineEdit::generateEmailAddressList() |
74 | 429 |
{ |
43 | 430 |
NM_FUNCTION; |
74 | 431 |
|
432 |
// Remove whitespace from the start and the end of the lineedit content. |
|
433 |
QString contentOfLineedit = text().trimmed(); |
|
434 |
||
43 | 435 |
// Split the lineedit content by semicolon(";"). |
74 | 436 |
QStringList itemsOfLineeditContent = contentOfLineedit.split(NmRecipientLineEditSemicolon, QString::SkipEmptyParts); |
437 |
||
43 | 438 |
// Loop through all the items of the lineedit content. |
18
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
439 |
for (int i = 0; i != itemsOfLineeditContent.count(); ++i) { |
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
440 |
// Remove whitespace from the start and the end of the item. |
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
441 |
QString itemInLineedit = itemsOfLineeditContent.at(i).trimmed(); |
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
442 |
|
43 | 443 |
// Get the count of the recipients added from Contacts. |
444 |
int countOfRecipientsAddedFromContacts = mRecipientsAddedFromContacts.count(); |
|
74 | 445 |
|
43 | 446 |
// If there is recipient added from Contacts. |
447 |
if (countOfRecipientsAddedFromContacts > 0) { |
|
448 |
QStringList listOfAddedContactsName; |
|
449 |
QStringList listOfAddedContactsAddress; |
|
74 | 450 |
|
43 | 451 |
// Loop through all the recipients added from Contacts. |
452 |
for (int j = 0; j != countOfRecipientsAddedFromContacts; ++j) { |
|
74 | 453 |
NmAddress contact = mRecipientsAddedFromContacts.at(j); |
43 | 454 |
listOfAddedContactsName.append(contact.displayName()); |
455 |
listOfAddedContactsAddress.append(contact.address()); |
|
456 |
} |
|
74 | 457 |
|
43 | 458 |
int indexInAddedContactsName = listOfAddedContactsName.indexOf(itemInLineedit); |
459 |
int indexInAddedContactsAddress = listOfAddedContactsAddress.indexOf(itemInLineedit); |
|
74 | 460 |
|
43 | 461 |
// If this itemInLineedit matches the name of one added contact. |
462 |
if (indexInAddedContactsName >= 0) { |
|
463 |
// Add the recipient into mEmailAddressList. |
|
74 | 464 |
mEmailAddressList.append(mRecipientsAddedFromContacts.at(indexInAddedContactsName)); |
43 | 465 |
} |
466 |
// If this itemInLineedit matches the emailaddress of one added contact. |
|
74 | 467 |
else if (indexInAddedContactsAddress >= 0) { |
43 | 468 |
// Add the recipient into mEmailAddressList. |
74 | 469 |
mEmailAddressList.append(mRecipientsAddedFromContacts.at(indexInAddedContactsAddress)); |
43 | 470 |
} |
471 |
// This itemInLineedit is not added from Contacts |
|
74 | 472 |
else { |
43 | 473 |
// Form the item into NmAddress format. |
474 |
NmAddress recipient; |
|
475 |
recipient.setAddress(itemInLineedit); |
|
476 |
// There is no display name info available, so leave display name empty. |
|
74 | 477 |
recipient.setDisplayName(QString()); |
43 | 478 |
// Add this NmAddress formated lineedit item into mEmailAddressList. |
74 | 479 |
mEmailAddressList.append(recipient); |
18
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
480 |
} |
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
481 |
} |
43 | 482 |
else { // There is no recipient is added from Contacts |
483 |
// Form the item into NmAddress format. |
|
18
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
484 |
NmAddress recipient; |
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
485 |
recipient.setAddress(itemInLineedit); |
43 | 486 |
// There is no display name info available, so leave display name emapty. |
74 | 487 |
recipient.setDisplayName(QString()); |
18
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
488 |
// Add this NmAddress formated lineedit item into mEmailAddressList. |
74 | 489 |
mEmailAddressList.append(recipient); |
18
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
490 |
} |
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
491 |
} |
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
492 |
} |
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
493 |
|
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
494 |
|
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
495 |
/*! |
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
496 |
This Slot is called when the lineedit text changes. |
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
497 |
*/ |
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
498 |
void NmRecipientLineEdit::handleTextChanged(const QString &text) |
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
499 |
{ |
43 | 500 |
NM_FUNCTION; |
74 | 501 |
|
18
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
502 |
mNeedToGenerateEmailAddressList = true; |
74 | 503 |
|
504 |
//if there is no text, hide popup already |
|
505 |
if (document()->isEmpty()) { |
|
506 |
hideAutofillPopup(); |
|
76 | 507 |
return; //no need to continue |
74 | 508 |
} |
509 |
||
76 | 510 |
int startPos(-1), length(-1); |
511 |
currentTextPart(startPos, length); |
|
512 |
QString t = text.mid(startPos, length); |
|
513 |
if (t.length()) { |
|
514 |
mContactHistoryModel->query(t); |
|
74 | 515 |
} |
18
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
516 |
} |
68 | 517 |
|
74 | 518 |
/*! |
519 |
If recipient is added from Contacts by Contacts, we need to add it to the list. |
|
68 | 520 |
*/ |
521 |
void NmRecipientLineEdit::addContacts(QList<NmAddress *> contacts) |
|
522 |
{ |
|
523 |
foreach (NmAddress *nmContact,contacts) { |
|
524 |
if (nmContact && nmContact->displayName().length() > 0) { |
|
525 |
mRecipientsAddedFromContacts.append(*nmContact); |
|
526 |
mNeedToGenerateEmailAddressList = true; |
|
527 |
} |
|
528 |
} |
|
529 |
} |
|
74 | 530 |
|
531 |
/*! |
|
532 |
This Slot appends the selected contact to the end of the lineedit content. |
|
533 |
*/ |
|
534 |
void NmRecipientLineEdit::addSelectedContactFromHistory(const QModelIndex &modelIndex) |
|
535 |
{ |
|
536 |
NM_FUNCTION; |
|
537 |
||
538 |
// ignore text changes during handling of text |
|
539 |
disconnect(this, SIGNAL(textChanged(QString)), |
|
540 |
this, SLOT(handleTextChanged(QString))); |
|
541 |
||
542 |
// Get address from contact history model |
|
543 |
NmAddress contact; |
|
544 |
getChosenAddressFromModel(modelIndex, contact); |
|
545 |
||
546 |
if (!contact.address().isEmpty()) { |
|
547 |
// Add the recipient to internal list of addresses |
|
548 |
mRecipientsAddedFromContacts.append(contact); |
|
549 |
||
550 |
// Find the text part to be replaced |
|
551 |
int startPos(-1), length(-1); |
|
552 |
currentTextPart(startPos, length); |
|
553 |
||
554 |
// delete currently entered characters before adding replacement |
|
555 |
QTextCursor cursor(textCursor()); |
|
556 |
cursor.setPosition(startPos); |
|
557 |
for(int i=0; i<length; i++) { |
|
558 |
cursor.deleteChar(); |
|
559 |
} |
|
560 |
||
561 |
// Insert replacement text |
|
562 |
if (contact.displayName().isEmpty()) { |
|
563 |
insertContactText(contact.address()); |
|
564 |
} |
|
565 |
else { |
|
566 |
insertContactText(contact.displayName()); |
|
567 |
} |
|
568 |
} |
|
569 |
// Continue accepting text changes.. |
|
570 |
connect(this, SIGNAL(textChanged(QString)), |
|
571 |
this, SLOT(handleTextChanged(QString))); |
|
572 |
||
573 |
//hide popup |
|
574 |
hideAutofillPopup(); |
|
575 |
} |
|
576 |
/*! |
|
577 |
reads the chosen data from contact history model |
|
578 |
*/ |
|
579 |
void NmRecipientLineEdit::getChosenAddressFromModel(const QModelIndex &modelIndex, NmAddress &address) |
|
580 |
{ |
|
581 |
NM_FUNCTION; |
|
582 |
// Dig out the chosen contact data |
|
583 |
// Get the activated item with given modelIndex |
|
584 |
NmContactHistoryModelItem item = mContactHistoryModel->data(modelIndex, Qt::DisplayRole).value<NmContactHistoryModelItem>(); |
|
585 |
if (item.subItemCount()) { |
|
586 |
QList<NmContactHistoryModelSubItem> itemlist = item.subEntries(); |
|
587 |
if (itemlist.count() == 2) { |
|
76 | 588 |
address.setDisplayName(itemlist[0].mItemText.trimmed()); |
589 |
address.setAddress(itemlist[1].mItemText.trimmed()); |
|
74 | 590 |
} else if (itemlist.count() == 1) { |
591 |
// only emailaddress found (no display name) |
|
76 | 592 |
address.setAddress(itemlist[0].mItemText.trimmed()); |
74 | 593 |
} |
594 |
} |
|
595 |
} |
|
596 |
||
597 |
/*! |
|
598 |
finds the current "entry" (startindex+length) based on current cursor position. |
|
599 |
Excludes possible trailing delimiter |
|
600 |
*/ |
|
601 |
void NmRecipientLineEdit::currentTextPart(int &startIndex, int &length) |
|
602 |
{ |
|
603 |
NM_FUNCTION; |
|
604 |
||
605 |
// Get current cursor position in the text |
|
606 |
int currentPos = textCursor().position(); |
|
607 |
||
608 |
QString tmp_debug = text(); |
|
609 |
startIndex = qMax(text().lastIndexOf(NmRecipientLineEditSemicolon,currentPos-1), 0); |
|
610 |
if (startIndex>0) { |
|
611 |
startIndex+=2; // in case entry is not the first, advance the start index by amount of "; ". |
|
612 |
} |
|
613 |
||
614 |
||
615 |
int nextDelimiterIndex=text().indexOf(NmRecipientLineEditDelimiter,currentPos); |
|
616 |
if (nextDelimiterIndex==-1) { |
|
617 |
// no delim after current pos |
|
618 |
length=text().length()-startIndex; |
|
619 |
} |
|
620 |
else { |
|
621 |
// delim after current pos found |
|
622 |
length=nextDelimiterIndex-startIndex; |
|
623 |
} |
|
624 |
} |
|
625 |
||
626 |
/*! |
|
627 |
Helper function for creating autofill component. |
|
628 |
*/ |
|
629 |
void NmRecipientLineEdit::createAutofillComponents() |
|
630 |
{ |
|
631 |
NM_FUNCTION; |
|
632 |
||
633 |
//create model |
|
634 |
mContactHistoryModel = new NmContactHistoryModel(EmailAddressModel); |
|
635 |
connect(mContactHistoryModel,SIGNAL(modelCompleted(int)),this,SLOT(modelCompleted(int))); |
|
636 |
||
637 |
//create popup list components |
|
638 |
HbDocumentLoader loader; |
|
639 |
bool loadingOk(false); |
|
640 |
loader.load(FILE_PATH_AUTOFILL_DOCML, &loadingOk); |
|
641 |
if (loadingOk){ |
|
642 |
mAutofillListView = dynamic_cast<HbListView*>(loader.findWidget("listview")); |
|
643 |
} |
|
644 |
else { |
|
645 |
NM_COMMENT("mAutofillListView loading from docML failed."); |
|
646 |
return; |
|
647 |
} |
|
648 |
||
649 |
connect(mAutofillListView, SIGNAL(activated(const QModelIndex &)), |
|
650 |
this, SLOT(addSelectedContactFromHistory(const QModelIndex &))); |
|
651 |
||
652 |
mAutofillListViewItem = new NmAutoFillListViewItem(); |
|
653 |
mAutofillListView->setModel(static_cast<QAbstractListModel*>(mContactHistoryModel),mAutofillListViewItem); |
|
654 |
||
655 |
//create popup |
|
656 |
createAutoFillPopup(); |
|
657 |
||
658 |
//set layout for popup |
|
659 |
QGraphicsLinearLayout *linLayout = new QGraphicsLinearLayout(Qt::Horizontal, |
|
660 |
mAutoFillPopup); |
|
661 |
linLayout->addItem(mAutofillListView); |
|
662 |
||
663 |
} |
|
664 |
||
665 |
/*! |
|
666 |
Helper function for creating popup component. |
|
667 |
*/ |
|
668 |
void NmRecipientLineEdit::createAutoFillPopup() |
|
669 |
{ |
|
670 |
NM_FUNCTION; |
|
671 |
mAutoFillPopup = new HbPopup(this); |
|
672 |
mAutoFillPopup->setVisible(false); |
|
673 |
mAutoFillPopup->setFlag(QGraphicsItem::ItemIsPanel, true); |
|
674 |
mAutoFillPopup->setActive(false); |
|
675 |
mAutoFillPopup->setFocusPolicy(Qt::NoFocus); |
|
676 |
mAutoFillPopup->setBackgroundFaded(false); |
|
677 |
mAutoFillPopup->setDismissPolicy(HbPopup::TapOutside); |
|
678 |
mAutoFillPopup->setTimeout(HbPopup::NoTimeout); |
|
679 |
mAutoFillPopup->setFrameType(HbPopup::Weak); //uses qtg_fr_popup_secondary graphics |
|
680 |
HbStyle::setItemName(mAutoFillPopup, QString("autoFillPopup")); |
|
681 |
||
682 |
mPopupBackground = new NmPopupBackground(mAutoFillPopup, this); |
|
683 |
mPopupBackground->setVisible(false); |
|
684 |
mPopupBackground->setZValue(mAutoFillPopup->zValue() - 1); |
|
685 |
} |
|
686 |
||
687 |
/*! |
|
688 |
Helper function for showing autofill popup. |
|
689 |
*/ |
|
690 |
void NmRecipientLineEdit::showAutofillPopup() |
|
691 |
{ |
|
692 |
NM_FUNCTION; |
|
693 |
if (!mAutoFillPopup->isVisible()) { |
|
694 |
parentItem()->setZValue(NmRecipientLineEditForegroundZValue); |
|
695 |
mAutoFillPopup->show(); |
|
696 |
mPopupBackground->setVisible(true); |
|
697 |
} |
|
698 |
} |
|
699 |
||
700 |
/*! |
|
701 |
Helper function for hiding autofill popup. |
|
702 |
*/ |
|
703 |
void NmRecipientLineEdit::hideAutofillPopup() |
|
704 |
{ |
|
705 |
NM_FUNCTION; |
|
706 |
if (mAutoFillPopup->isVisible()) { |
|
707 |
mPopupBackground->setVisible(false); |
|
708 |
parentItem()->setZValue(NmRecipientLineEditBackgroundZValue); |
|
709 |
mAutoFillPopup->hide(); |
|
710 |
} |
|
711 |
} |
|
712 |
||
713 |
/*! |
|
714 |
Slot for listening when model is ready with a new data. |
|
715 |
*/ |
|
716 |
void NmRecipientLineEdit::modelCompleted(int err) |
|
717 |
{ |
|
718 |
NM_FUNCTION; |
|
719 |
if (err == 0) { |
|
720 |
//show model if there was findings |
|
721 |
int count = mContactHistoryModel->rowCount(QModelIndex()); |
|
722 |
||
723 |
if (count > 0) { |
|
724 |
showAutofillPopup(); |
|
725 |
} else { |
|
726 |
hideAutofillPopup(); |
|
727 |
} |
|
728 |
} |
|
729 |
} |
|
730 |
||
731 |
/*! |
|
732 |
finds the current "entry" in the editor field based on current cursor position and creates a selection of it. |
|
733 |
Includes possible trailing delimiter |
|
734 |
*/ |
|
735 |
void NmRecipientLineEdit::setHighlight(int currentPos) |
|
736 |
{ |
|
737 |
QString txt = text(); |
|
738 |
||
739 |
int startPos = qMax(txt.lastIndexOf(NmRecipientLineEditDelimiter,currentPos), 0); |
|
740 |
if (startPos) { |
|
741 |
startPos+=2; // in case entry is not the first, advance the start index by amount of "; " |
|
742 |
} |
|
743 |
int endPos = qMax(txt.indexOf(NmRecipientLineEditDelimiter,currentPos), currentPos); |
|
744 |
||
745 |
if (startPos >= 0 && endPos >= 0 && startPos != endPos) { |
|
746 |
setSelection(startPos, endPos - startPos + 2); |
|
747 |
} |
|
748 |
else { |
|
749 |
deselect(); |
|
750 |
} |
|
76 | 751 |
|
752 |
||
74 | 753 |
} |
754 |
||
755 |
/*! |
|
756 |
inserts a new contact text (underlined) + trailing delimiter to current cursor position in editor field |
|
757 |
*/ |
|
758 |
void NmRecipientLineEdit::insertContactText(const QString &text) |
|
759 |
{ |
|
760 |
NM_FUNCTION; |
|
761 |
||
762 |
// Insert contact text as underlined |
|
763 |
QTextCharFormat colorFormat(textCursor().charFormat()); |
|
764 |
QColor fgColor = colorFormat.foreground().color(); |
|
765 |
fgColor.setAlpha(NmRecipientLineEditFadedAlpha); |
|
766 |
colorFormat.setUnderlineColor(fgColor); |
|
767 |
colorFormat.setFontUnderline(true); |
|
768 |
textCursor().insertText(text, colorFormat); |
|
769 |
||
770 |
// Insert delimiter (not underlined) |
|
771 |
colorFormat.setFontUnderline(false); |
|
772 |
textCursor().insertText(NmRecipientLineEditDelimiter,colorFormat); |
|
773 |
} |
|
774 |
||
775 |
/*! |
|
776 |
Popup's background item. Used to close properly popup if clicked to outside of the popup. |
|
777 |
*/ |
|
778 |
NmPopupBackground::NmPopupBackground(HbPopup * popup, QGraphicsItem *parent) : |
|
779 |
QGraphicsItem(parent), |
|
780 |
mPopup(popup) |
|
781 |
{ |
|
782 |
// This is needed to be able to block moving the focus to items behind background item by |
|
783 |
// clicking on them. |
|
784 |
setFlag(QGraphicsItem::ItemIsFocusable); |
|
785 |
setFlag(QGraphicsItem::ItemIsPanel); |
|
786 |
} |
|
787 |
||
788 |
/*! |
|
789 |
Paint. Not used but since this is pure virtual it must be here. |
|
790 |
*/ |
|
791 |
void NmPopupBackground::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget ) |
|
792 |
{ |
|
793 |
Q_UNUSED(option) |
|
794 |
Q_UNUSED(widget); |
|
795 |
Q_UNUSED(painter); |
|
796 |
} |
|
797 |
||
798 |
/*! |
|
799 |
Mouse press events are checked here. If background is clicked, popup must be closed. |
|
800 |
*/ |
|
801 |
bool NmPopupBackground::sceneEvent(QEvent *event) |
|
802 |
{ |
|
803 |
if (event->type() == QEvent::GraphicsSceneMousePress) { |
|
804 |
mPopup->close(); |
|
805 |
setVisible(false); |
|
806 |
event->accept(); |
|
807 |
return true; |
|
808 |
} |
|
809 |
else { |
|
810 |
event->ignore(); |
|
811 |
return QGraphicsItem::sceneEvent(event); |
|
812 |
} |
|
813 |
} |