37
|
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:
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
#include "msgunieditorlineedit.h"
|
|
19 |
#include <HbTapGesture>
|
|
20 |
#include <HbMenu>
|
|
21 |
#include <QApplication>
|
|
22 |
#include <QClipboard>
|
|
23 |
|
|
24 |
const QRegExp expr("[,;\n]$");
|
|
25 |
const QRegExp sepAtEnd("; $");
|
|
26 |
const QRegExp sepAtMiddle("; ");
|
|
27 |
|
|
28 |
const QString replacementStr("; ");
|
|
29 |
const QString labelSeperator(": ");
|
|
30 |
|
|
31 |
const int fadedAlpha(125);
|
|
32 |
const int solidAlpha(255);
|
|
33 |
|
|
34 |
const int SNAP_DELAY = 350;
|
|
35 |
|
|
36 |
//Localization
|
|
37 |
#define LOC_PASTE hbTrId("txt_common_menu_paste")
|
|
38 |
|
|
39 |
MsgUnifiedEditorLineEdit::MsgUnifiedEditorLineEdit(const QString& label,QGraphicsItem *parent):
|
|
40 |
HbLineEdit(parent),
|
|
41 |
mSelectionStart(-1),
|
|
42 |
mSelectionEnd(-1),
|
|
43 |
mDefaultBehaviour(false)
|
|
44 |
{
|
|
45 |
QString labelStr = label.trimmed();
|
|
46 |
|
|
47 |
QTextCursor cursor(this->textCursor());
|
|
48 |
QTextCharFormat colorFormat(cursor.charFormat());
|
|
49 |
|
|
50 |
QColor fgColor = this->palette().color(QPalette::Text);
|
|
51 |
fgColor.setAlpha(fadedAlpha);
|
|
52 |
colorFormat.setForeground(fgColor);
|
|
53 |
cursor.insertText(labelStr , colorFormat);
|
|
54 |
|
|
55 |
fgColor.setAlpha(solidAlpha);
|
|
56 |
colorFormat.setForeground(fgColor);
|
|
57 |
|
|
58 |
cursor.insertText(" ",colorFormat);
|
|
59 |
|
|
60 |
mLabelExpr.setPattern(QString("^"+labelStr+" $"));
|
|
61 |
mLabel = labelStr+" ";
|
|
62 |
|
|
63 |
moveCursor(QTextCursor::EndOfBlock);
|
|
64 |
|
|
65 |
connect(this,SIGNAL(selectionChanged(QTextCursor,QTextCursor)),
|
|
66 |
this,SLOT(selectionChanged(QTextCursor,QTextCursor)));
|
|
67 |
connect(this, SIGNAL(contentsChanged()), this, SLOT(onContentsChanged()));
|
|
68 |
|
|
69 |
connect(this,SIGNAL(aboutToShowContextMenu(HbMenu*,const QPointF &)),
|
|
70 |
this,SLOT(aboutToShowContextMenu(HbMenu*,const QPointF &)));
|
|
71 |
|
|
72 |
}
|
|
73 |
|
|
74 |
MsgUnifiedEditorLineEdit::~MsgUnifiedEditorLineEdit()
|
|
75 |
{
|
|
76 |
}
|
|
77 |
|
|
78 |
void MsgUnifiedEditorLineEdit::inputMethodEvent(QInputMethodEvent *event)
|
|
79 |
{
|
|
80 |
//let it go in default way.
|
|
81 |
if(mDefaultBehaviour)
|
|
82 |
{
|
|
83 |
HbAbstractEdit::inputMethodEvent(event);
|
|
84 |
event->accept();
|
|
85 |
return;
|
|
86 |
}
|
|
87 |
|
|
88 |
if (!event->commitString().isEmpty() || event->replacementLength())
|
|
89 |
{
|
|
90 |
if (event->commitString().contains(expr))
|
|
91 |
{
|
|
92 |
if(this->text().isEmpty() || this->text().contains(sepAtEnd) || this->text().contains(mLabelExpr))
|
|
93 |
{
|
|
94 |
event->accept();
|
|
95 |
return;
|
|
96 |
}
|
|
97 |
|
|
98 |
this->setCursorPosition(this->text().length());
|
|
99 |
|
|
100 |
QString str = event->commitString();
|
|
101 |
str.replace(expr, replacementStr);
|
|
102 |
|
|
103 |
event->setCommitString(str, event->replacementStart(), event->replacementLength());
|
|
104 |
}
|
|
105 |
else if(this->hasSelectedText())
|
|
106 |
{// all user inputs get appended at the end
|
|
107 |
this->setCursorPosition(this->text().length());
|
|
108 |
}
|
|
109 |
}
|
|
110 |
|
|
111 |
HbAbstractEdit::inputMethodEvent(event);
|
|
112 |
event->accept();
|
|
113 |
}
|
|
114 |
|
|
115 |
void MsgUnifiedEditorLineEdit::keyPressEvent(QKeyEvent *event)
|
|
116 |
{
|
|
117 |
QString str = event->text();
|
|
118 |
|
|
119 |
if(event->key()== Qt::Key_Enter || event->key()== Qt::Key_Return)
|
|
120 |
{
|
|
121 |
if(mDefaultBehaviour)
|
|
122 |
{
|
|
123 |
HbAbstractEdit::keyReleaseEvent(event);
|
|
124 |
event->accept();
|
|
125 |
return;
|
|
126 |
}
|
|
127 |
if(this->text().isEmpty() || this->text().contains(sepAtEnd) || this->text().contains(mLabelExpr))
|
|
128 |
{
|
|
129 |
event->accept();
|
|
130 |
return;
|
|
131 |
}
|
|
132 |
this->setCursorPosition(this->text().length());
|
|
133 |
str = replacementStr;
|
|
134 |
QKeyEvent eve(event->type(), Qt::Key_Any, event->modifiers(), str);
|
|
135 |
HbAbstractEdit::keyPressEvent(&eve);
|
|
136 |
event->accept();
|
|
137 |
return;
|
|
138 |
}
|
|
139 |
|
|
140 |
if(event->key() == Qt::Key_Backspace || event->key() == Qt::Key_Delete )
|
|
141 |
{
|
|
142 |
int pos = this->cursorPosition();
|
|
143 |
bool pbkContact = true;
|
|
144 |
|
|
145 |
if(!this->hasSelectedText())
|
|
146 |
{
|
|
147 |
this->setCursorPosition(pos-2);
|
|
148 |
pbkContact = this->textCursor().charFormat().fontUnderline();
|
|
149 |
this->setCursorPosition(pos);
|
|
150 |
}
|
|
151 |
|
|
152 |
QString text = this->text();
|
|
153 |
text = text.left(pos);
|
|
154 |
|
|
155 |
if(text.contains(mLabelExpr))
|
|
156 |
{
|
|
157 |
event->accept();
|
|
158 |
return;
|
|
159 |
}
|
|
160 |
|
|
161 |
if(pbkContact)
|
|
162 |
{
|
|
163 |
//if already selected delete it.
|
|
164 |
if(this->hasSelectedText())
|
|
165 |
{
|
|
166 |
// deleting phbkContact is an atomic operation
|
|
167 |
// ensure that the signal is emitted only once
|
|
168 |
disconnect(this, SIGNAL(contentsChanged()),
|
|
169 |
this, SLOT(onContentsChanged()));
|
|
170 |
HbLineEdit::keyPressEvent(event);
|
|
171 |
event->accept();
|
|
172 |
//delete seperator (i.e."; ").
|
|
173 |
QKeyEvent eve(event->type(), Qt::Key_Delete, Qt::NoModifier);
|
|
174 |
HbLineEdit::keyPressEvent(&eve);
|
|
175 |
HbLineEdit::keyPressEvent(&eve);
|
|
176 |
connect(this, SIGNAL(contentsChanged()),
|
|
177 |
this, SLOT(onContentsChanged()));
|
|
178 |
onContentsChanged();
|
|
179 |
}
|
|
180 |
else //make it selected
|
|
181 |
{
|
|
182 |
this->setCursorPosition(pos-3);
|
|
183 |
setHighlight(pos-3);
|
|
184 |
}
|
|
185 |
}
|
|
186 |
else
|
|
187 |
{
|
|
188 |
QString str = text.right(2);
|
|
189 |
if(str == replacementStr)
|
|
190 |
{
|
|
191 |
// deleting contact is an atomic operation
|
|
192 |
// ensure that the signal is emitted only once
|
|
193 |
disconnect(this, SIGNAL(contentsChanged()),
|
|
194 |
this, SLOT(onContentsChanged()));
|
|
195 |
//delete seperator (i.e."; ").
|
|
196 |
QKeyEvent eve(event->type(), Qt::Key_Backspace, Qt::NoModifier);
|
|
197 |
HbLineEdit::keyPressEvent(&eve);
|
|
198 |
HbLineEdit::keyPressEvent(&eve);
|
|
199 |
connect(this, SIGNAL(contentsChanged()),
|
|
200 |
this, SLOT(onContentsChanged()));
|
|
201 |
onContentsChanged();
|
|
202 |
}
|
|
203 |
else
|
|
204 |
{
|
|
205 |
HbLineEdit::keyPressEvent(event);
|
|
206 |
}
|
|
207 |
event->accept();
|
|
208 |
}
|
|
209 |
|
|
210 |
event->accept();
|
|
211 |
return;
|
|
212 |
}
|
|
213 |
|
|
214 |
if (event->key() == Qt::Key_Left )
|
|
215 |
{
|
|
216 |
bool selectedText = this->hasSelectedText();
|
|
217 |
|
|
218 |
//look ahead left.
|
|
219 |
int pos = this->cursorPosition();
|
|
220 |
|
|
221 |
QString text = this->text();
|
|
222 |
text = text.left(pos);
|
|
223 |
|
|
224 |
//no text other than label;
|
|
225 |
if(text.contains(mLabelExpr))
|
|
226 |
{
|
|
227 |
event->accept();
|
|
228 |
return;
|
|
229 |
}
|
|
230 |
|
|
231 |
//look for next seperator while going left.
|
|
232 |
int newPos = text.lastIndexOf(sepAtMiddle);
|
|
233 |
|
|
234 |
if(newPos < 0 && selectedText)
|
|
235 |
{
|
|
236 |
event->accept();
|
|
237 |
return;
|
|
238 |
}
|
|
239 |
|
|
240 |
bool pbkContact = true;
|
|
241 |
|
|
242 |
if(!selectedText)
|
|
243 |
{
|
|
244 |
this->setCursorPosition(pos-2);
|
|
245 |
pbkContact = this->textCursor().charFormat().fontUnderline();
|
|
246 |
this->setCursorPosition(pos);
|
|
247 |
}
|
|
248 |
else
|
|
249 |
{
|
|
250 |
this->setCursorPosition(newPos);
|
|
251 |
pbkContact = this->textCursor().charFormat().fontUnderline();
|
|
252 |
this->setCursorPosition(pos);
|
|
253 |
}
|
|
254 |
|
|
255 |
|
|
256 |
if(pbkContact && newPos >0)
|
|
257 |
{
|
|
258 |
|
|
259 |
setHighlight(newPos-1);
|
|
260 |
}
|
|
261 |
else
|
|
262 |
{
|
|
263 |
//move left, char by char. if seperator met jump over it.
|
|
264 |
if( (newPos > 0 && selectedText) || (pos-2 == newPos))
|
|
265 |
{
|
|
266 |
this->setCursorPosition(newPos+1);
|
|
267 |
}
|
|
268 |
|
|
269 |
HbLineEdit::keyPressEvent(event);
|
|
270 |
|
|
271 |
}
|
|
272 |
event->accept();
|
|
273 |
return;
|
|
274 |
}
|
|
275 |
|
|
276 |
if (event->key() == Qt::Key_Right)
|
|
277 |
{
|
|
278 |
bool selectedText = this->hasSelectedText();
|
|
279 |
|
|
280 |
//look ahead.
|
|
281 |
int pos = this->cursorPosition();
|
|
282 |
this->setCursorPosition(pos+3);
|
|
283 |
bool pbkContact = this->textCursor().charFormat().fontUnderline();
|
|
284 |
this->setCursorPosition(pos);
|
|
285 |
|
|
286 |
//look for next seperator.
|
|
287 |
QString text = this->text();
|
|
288 |
int newPos = text.indexOf(sepAtMiddle,pos+2);
|
|
289 |
|
|
290 |
if(pbkContact && newPos >0)
|
|
291 |
{
|
|
292 |
this->setCursorPosition(newPos-1);
|
|
293 |
setHighlight(newPos-1);
|
|
294 |
}
|
|
295 |
else
|
|
296 |
{
|
|
297 |
int seperatorPos = text.indexOf(sepAtMiddle,pos);
|
|
298 |
|
|
299 |
if(selectedText || seperatorPos == pos)
|
|
300 |
{
|
|
301 |
this->setCursorPosition(pos+1);
|
|
302 |
this->deselect();
|
|
303 |
}
|
|
304 |
HbAbstractEdit::keyPressEvent(event);
|
|
305 |
}
|
|
306 |
event->accept();
|
|
307 |
return;
|
|
308 |
}
|
|
309 |
|
|
310 |
if(!str.isEmpty())
|
|
311 |
{
|
|
312 |
if(mDefaultBehaviour)
|
|
313 |
{
|
|
314 |
HbAbstractEdit::keyPressEvent(event);
|
|
315 |
event->accept();
|
|
316 |
return;
|
|
317 |
}
|
|
318 |
if (str.contains(expr))
|
|
319 |
{
|
|
320 |
if(this->text().isEmpty() || this->text().contains(sepAtEnd) || this->text().contains(mLabelExpr))
|
|
321 |
{
|
|
322 |
event->accept();
|
|
323 |
return;
|
|
324 |
}
|
|
325 |
|
|
326 |
// auto-complete the last incomplete word
|
|
327 |
int contentLength = this->text().length();
|
|
328 |
int pos = this->cursorPosition();
|
|
329 |
QString incompleteWord(this->text().right(contentLength-(pos-1)));
|
|
330 |
if(!incompleteWord.contains(sepAtMiddle))
|
|
331 |
{
|
|
332 |
this->setCursorPosition(this->text().length());
|
|
333 |
}
|
|
334 |
|
|
335 |
str.replace(expr, replacementStr);
|
|
336 |
QKeyEvent eve(event->type(), event->key(), event->modifiers(), str);
|
|
337 |
HbAbstractEdit::keyPressEvent(&eve);
|
|
338 |
}
|
|
339 |
else
|
|
340 |
{
|
|
341 |
HbAbstractEdit::keyPressEvent(event);
|
|
342 |
event->accept();
|
|
343 |
return;
|
|
344 |
}
|
|
345 |
}
|
|
346 |
}
|
|
347 |
|
|
348 |
void MsgUnifiedEditorLineEdit::handleTap()
|
|
349 |
{
|
|
350 |
int currentPos = this->cursorPosition();
|
|
351 |
|
|
352 |
QString txt = this->text();
|
|
353 |
|
|
354 |
QString tempTxt = txt.left(currentPos+2);
|
|
355 |
int seperatorPos = tempTxt.lastIndexOf(sepAtMiddle,currentPos);
|
|
356 |
|
|
357 |
txt = txt.right(txt.length() - currentPos);
|
|
358 |
int labelPos = txt.indexOf(labelSeperator);
|
|
359 |
|
|
360 |
if(labelPos >= 0 )//pressed on label.
|
|
361 |
{
|
|
362 |
this->setCursorPosition(currentPos + labelPos + 2);
|
|
363 |
}
|
|
364 |
else if(seperatorPos == currentPos-1 || seperatorPos == currentPos)//pressed just on seperator.
|
|
365 |
{
|
|
366 |
this->setCursorPosition(seperatorPos+2);
|
|
367 |
}
|
|
368 |
else
|
|
369 |
{
|
|
370 |
this->setCursorPosition(currentPos+1);
|
|
371 |
bool pbkContact = this->textCursor().charFormat().fontUnderline();
|
|
372 |
if(pbkContact)
|
|
373 |
{
|
|
374 |
setHighlight(currentPos);
|
|
375 |
}
|
|
376 |
}
|
|
377 |
|
|
378 |
this->update();
|
|
379 |
}
|
|
380 |
|
|
381 |
void MsgUnifiedEditorLineEdit::gestureEvent(QGestureEvent* event)
|
|
382 |
{
|
|
383 |
//passing gesture event to base class.
|
|
384 |
HbLineEdit::gestureEvent(event);
|
|
385 |
|
|
386 |
|
|
387 |
if(HbTapGesture *tap = qobject_cast<HbTapGesture*>(event->gesture(Qt::TapGesture)))
|
|
388 |
{
|
|
389 |
//capturing gesture position, and map to local co-ordinates.
|
|
390 |
QPointF pos = mapFromScene(tap->scenePosition());
|
|
391 |
|
|
392 |
switch (tap->state())
|
|
393 |
{
|
|
394 |
case Qt::GestureFinished:
|
|
395 |
{
|
|
396 |
if (HbTapGesture::Tap == tap->tapStyleHint())
|
|
397 |
{
|
|
398 |
handleTap();
|
|
399 |
}
|
|
400 |
break;
|
|
401 |
}
|
|
402 |
default:
|
|
403 |
break;
|
|
404 |
}
|
|
405 |
event->accept();
|
|
406 |
}
|
|
407 |
else
|
|
408 |
{
|
|
409 |
event->ignore();
|
|
410 |
}
|
|
411 |
}
|
|
412 |
|
|
413 |
void MsgUnifiedEditorLineEdit::setText(const QString& text, bool underlined)
|
|
414 |
{
|
|
415 |
|
|
416 |
if(!mDefaultBehaviour)
|
|
417 |
{
|
|
418 |
// atomic operation, ensure one signal only at the end
|
|
419 |
disconnect(this, SIGNAL(contentsChanged()), this, SLOT(onContentsChanged()));
|
|
420 |
|
|
421 |
//make sure previous text is complete.
|
|
422 |
if(this->content().length() > 0)
|
|
423 |
{
|
|
424 |
QInputMethodEvent e;
|
|
425 |
e.setCommitString(";");
|
|
426 |
this->inputMethodEvent(&e);
|
|
427 |
}
|
|
428 |
this->setCursorPosition(this->text().length());
|
|
429 |
|
|
430 |
QTextCursor cursor(this->textCursor());
|
|
431 |
QTextCharFormat colorFormat(cursor.charFormat());
|
|
432 |
if(underlined)
|
|
433 |
{
|
|
434 |
QColor fgColor = colorFormat.foreground().color();
|
|
435 |
fgColor.setAlpha(fadedAlpha);
|
|
436 |
colorFormat.setUnderlineColor(fgColor);
|
|
437 |
colorFormat.setFontUnderline(true);
|
|
438 |
}
|
|
439 |
cursor.insertText(text , colorFormat);
|
|
440 |
colorFormat.setFontUnderline(false);
|
|
441 |
|
|
442 |
cursor.insertText(replacementStr,colorFormat);
|
|
443 |
connect(this, SIGNAL(contentsChanged()), this, SLOT(onContentsChanged()));
|
|
444 |
onContentsChanged();
|
|
445 |
}
|
|
446 |
else
|
|
447 |
{
|
|
448 |
this->setCursorPosition(this->text().length());
|
|
449 |
QTextCursor cursor(this->textCursor());
|
|
450 |
cursor.insertText(text);
|
|
451 |
}
|
|
452 |
|
|
453 |
moveCursor(QTextCursor::EndOfBlock);
|
|
454 |
}
|
|
455 |
|
|
456 |
QStringList MsgUnifiedEditorLineEdit::addresses()
|
|
457 |
{
|
|
458 |
QString text = this->content();
|
|
459 |
QStringList list = text.split(replacementStr,QString::SkipEmptyParts);
|
|
460 |
return list;
|
|
461 |
}
|
|
462 |
|
|
463 |
void MsgUnifiedEditorLineEdit::focusInEvent(QFocusEvent* event)
|
|
464 |
{
|
|
465 |
HbLineEdit::focusInEvent(event);
|
|
466 |
this->setCursorVisibility(Hb::TextCursorVisible);
|
|
467 |
}
|
|
468 |
|
|
469 |
void MsgUnifiedEditorLineEdit::focusOutEvent(QFocusEvent* event)
|
|
470 |
{
|
|
471 |
HbLineEdit::focusOutEvent(event);
|
|
472 |
this->setCursorVisibility(Hb::TextCursorHidden);
|
|
473 |
}
|
|
474 |
|
|
475 |
void MsgUnifiedEditorLineEdit::setHighlight(int currentPos)
|
|
476 |
{
|
|
477 |
QString txt = this->text();
|
|
478 |
|
|
479 |
int endPos = qMax(txt.indexOf(sepAtMiddle,currentPos),
|
|
480 |
txt.indexOf(labelSeperator,currentPos));
|
|
481 |
|
|
482 |
int startPos = qMax(txt.lastIndexOf(sepAtMiddle,currentPos),
|
|
483 |
txt.lastIndexOf(labelSeperator,currentPos));
|
|
484 |
|
|
485 |
disconnect(this,SIGNAL(selectionChanged(QTextCursor,QTextCursor)),
|
|
486 |
this,SLOT(selectionChanged(QTextCursor,QTextCursor)));
|
|
487 |
|
|
488 |
//highlight if pbk contact.
|
|
489 |
if(startPos > 0 && endPos > 0 && startPos != endPos)
|
|
490 |
{
|
|
491 |
this->setSelection(startPos + 2, endPos - startPos - 2);
|
|
492 |
this->update();
|
|
493 |
}
|
|
494 |
else
|
|
495 |
{
|
|
496 |
this->deselect();
|
|
497 |
}
|
|
498 |
|
|
499 |
this->update();
|
|
500 |
|
|
501 |
connect(this,SIGNAL(selectionChanged(QTextCursor,QTextCursor)),
|
|
502 |
this,SLOT(selectionChanged(QTextCursor,QTextCursor)));
|
|
503 |
}
|
|
504 |
|
|
505 |
void MsgUnifiedEditorLineEdit::selectionChanged(const QTextCursor &oldCursor, const QTextCursor& newCursor)
|
|
506 |
{
|
|
507 |
|
|
508 |
if(mSelectionSnapTimer.isActive())
|
|
509 |
{
|
|
510 |
mSelectionSnapTimer.stop();
|
|
511 |
}
|
|
512 |
|
|
513 |
if(newCursor.selectionStart() < mLabel.length())
|
|
514 |
{
|
|
515 |
this->setTextCursor(oldCursor);
|
|
516 |
return;
|
|
517 |
}
|
|
518 |
|
|
519 |
if(!mDefaultBehaviour)
|
|
520 |
{
|
|
521 |
mSelectionStart = newCursor.selectionStart();
|
|
522 |
mSelectionEnd = newCursor.selectionEnd();
|
|
523 |
|
|
524 |
if(mSelectionStart == mSelectionEnd )
|
|
525 |
{
|
|
526 |
return;
|
|
527 |
}
|
|
528 |
|
|
529 |
mSelectionSnapTimer.start(SNAP_DELAY,this);
|
|
530 |
}
|
|
531 |
}
|
|
532 |
|
|
533 |
void MsgUnifiedEditorLineEdit::timerEvent(QTimerEvent *event)
|
|
534 |
{
|
|
535 |
//passing event to base class.
|
|
536 |
HbLineEdit::timerEvent(event);
|
|
537 |
|
|
538 |
if (event->timerId() == mSelectionSnapTimer.timerId())
|
|
539 |
{
|
|
540 |
mSelectionSnapTimer.stop();
|
|
541 |
|
|
542 |
disconnect(this,SIGNAL(selectionChanged(QTextCursor,QTextCursor)),
|
|
543 |
this,SLOT(selectionChanged(QTextCursor,QTextCursor)));
|
|
544 |
|
|
545 |
QString txt = this->text();
|
|
546 |
|
|
547 |
int startPos = qMax(txt.lastIndexOf(sepAtMiddle,mSelectionStart),
|
|
548 |
txt.lastIndexOf(labelSeperator,mSelectionStart));
|
|
549 |
|
|
550 |
int endPos = qMax(txt.indexOf(sepAtMiddle,mSelectionEnd),
|
|
551 |
txt.indexOf(labelSeperator,mSelectionEnd));
|
|
552 |
|
|
553 |
if(endPos < 0 )
|
|
554 |
{
|
|
555 |
endPos = mSelectionEnd;
|
|
556 |
}
|
|
557 |
|
|
558 |
this->setSelection(startPos + 2, endPos - startPos - 2);
|
|
559 |
|
|
560 |
connect(this,SIGNAL(selectionChanged(QTextCursor,QTextCursor)),
|
|
561 |
this,SLOT(selectionChanged(QTextCursor,QTextCursor)));
|
|
562 |
|
|
563 |
event->accept();
|
|
564 |
}
|
|
565 |
}
|
|
566 |
|
|
567 |
void MsgUnifiedEditorLineEdit::setDefaultBehaviour(bool defaultBehaviour)
|
|
568 |
{
|
|
569 |
mDefaultBehaviour = defaultBehaviour;
|
|
570 |
}
|
|
571 |
|
|
572 |
QString MsgUnifiedEditorLineEdit::text() const
|
|
573 |
{
|
|
574 |
return HbLineEdit::text();
|
|
575 |
}
|
|
576 |
|
|
577 |
QString MsgUnifiedEditorLineEdit::content() const
|
|
578 |
{
|
|
579 |
QString text = this->text();
|
|
580 |
text.remove(mLabel);
|
|
581 |
return text;
|
|
582 |
}
|
|
583 |
|
|
584 |
void MsgUnifiedEditorLineEdit::clearContent()
|
|
585 |
{
|
|
586 |
// avoid getting updates during local editing
|
|
587 |
disconnect(this, SIGNAL(contentsChanged()), this, SLOT(onContentsChanged()));
|
|
588 |
|
|
589 |
int startPos = mLabel.length();
|
|
590 |
this->setSelection(startPos, content().length());
|
|
591 |
QKeyEvent eve(QEvent::KeyPress, Qt::Key_Backspace, Qt::NoModifier);
|
|
592 |
this->keyPressEvent(&eve);
|
|
593 |
this->deselect();
|
|
594 |
|
|
595 |
// re-connect signal to start getting updates
|
|
596 |
connect(this, SIGNAL(contentsChanged()), this, SLOT(onContentsChanged()));
|
|
597 |
}
|
|
598 |
|
|
599 |
void MsgUnifiedEditorLineEdit::onContentsChanged()
|
|
600 |
{
|
|
601 |
emit contentsChanged(content());
|
|
602 |
}
|
|
603 |
|
|
604 |
void MsgUnifiedEditorLineEdit::highlightInvalidString(QString invalidStr)
|
|
605 |
{
|
|
606 |
// for only address editor
|
|
607 |
if(!mDefaultBehaviour)
|
|
608 |
{
|
|
609 |
QString txtContent = this->text();
|
|
610 |
int searchStartPos = mLabel.length();
|
|
611 |
int startPos = txtContent.indexOf(invalidStr, searchStartPos);
|
|
612 |
disconnect(this,SIGNAL(selectionChanged(QTextCursor,QTextCursor)),
|
|
613 |
this,SLOT(selectionChanged(QTextCursor,QTextCursor)));
|
|
614 |
// if invalidStr found
|
|
615 |
if(startPos > 0)
|
|
616 |
{
|
|
617 |
this->setSelection(startPos, invalidStr.length());
|
|
618 |
}
|
|
619 |
connect(this,SIGNAL(selectionChanged(QTextCursor,QTextCursor)),
|
|
620 |
this,SLOT(selectionChanged(QTextCursor,QTextCursor)));
|
|
621 |
}
|
|
622 |
}
|
|
623 |
|
|
624 |
void MsgUnifiedEditorLineEdit::aboutToShowContextMenu(HbMenu *contextMenu, const QPointF &pos)
|
|
625 |
{
|
|
626 |
Q_UNUSED(pos)
|
|
627 |
//clear all menu actions.
|
|
628 |
contextMenu->clearActions();
|
|
629 |
|
|
630 |
const QMimeData *mimedata = QApplication::clipboard()->mimeData();
|
|
631 |
if(mimedata)
|
|
632 |
{
|
|
633 |
if(canInsertFromMimeData(mimedata))
|
|
634 |
{
|
|
635 |
contextMenu->addAction(LOC_PASTE,this,SLOT(paste()));
|
|
636 |
}
|
|
637 |
}
|
|
638 |
|
|
639 |
}
|
|
640 |
// eof
|