31 const int SNAP_DELAY = 350; |
31 const int SNAP_DELAY = 350; |
32 |
32 |
33 MsgUnifiedEditorLineEdit::MsgUnifiedEditorLineEdit(const QString& label,QGraphicsItem *parent): |
33 MsgUnifiedEditorLineEdit::MsgUnifiedEditorLineEdit(const QString& label,QGraphicsItem *parent): |
34 HbLineEdit(parent), |
34 HbLineEdit(parent), |
35 mSelectionStart(-1), |
35 mSelectionStart(-1), |
36 mSelectionEnd(-1) |
36 mSelectionEnd(-1), |
37 { |
37 mDefaultBehaviour(false) |
|
38 { |
|
39 QString labelStr = label.trimmed(); |
|
40 |
38 QTextCursor cursor(this->textCursor()); |
41 QTextCursor cursor(this->textCursor()); |
39 QTextCharFormat colorFormat(cursor.charFormat()); |
42 QTextCharFormat colorFormat(cursor.charFormat()); |
40 |
43 |
41 QColor fgColor = colorFormat.foreground().color(); |
44 QColor fgColor = this->palette().color(QPalette::Text); |
42 fgColor.setAlpha(fadedAlpha); |
45 fgColor.setAlpha(fadedAlpha); |
43 colorFormat.setForeground(fgColor); |
46 colorFormat.setForeground(fgColor); |
44 cursor.insertText(label , colorFormat); |
47 cursor.insertText(labelStr , colorFormat); |
45 |
48 |
46 fgColor.setAlpha(solidAlpha); |
49 fgColor.setAlpha(solidAlpha); |
47 colorFormat.setForeground(fgColor); |
50 colorFormat.setForeground(fgColor); |
48 |
51 |
49 cursor.insertText(" ",colorFormat); |
52 cursor.insertText(" ",colorFormat); |
50 |
53 |
51 mLabelExpr.setPattern(QString("^"+label+" $")); |
54 mLabelExpr.setPattern(QString("^"+labelStr+" $")); |
52 mLabel = label+" "; |
55 mLabel = labelStr+" "; |
53 |
56 |
54 connect(this,SIGNAL(selectionChanged(QTextCursor,QTextCursor)), |
57 connect(this,SIGNAL(selectionChanged(QTextCursor,QTextCursor)), |
55 this,SLOT(selectionChanged(QTextCursor,QTextCursor))); |
58 this,SLOT(selectionChanged(QTextCursor,QTextCursor))); |
56 connect(this, SIGNAL(textChanged(QString)), this, SLOT(onTextChanged(QString))); |
59 connect(this, SIGNAL(contentsChanged()), this, SLOT(onContentsChanged())); |
57 } |
60 } |
58 |
61 |
59 MsgUnifiedEditorLineEdit::~MsgUnifiedEditorLineEdit() |
62 MsgUnifiedEditorLineEdit::~MsgUnifiedEditorLineEdit() |
60 { |
63 { |
61 } |
64 } |
62 |
65 |
63 void MsgUnifiedEditorLineEdit::inputMethodEvent(QInputMethodEvent *event) |
66 void MsgUnifiedEditorLineEdit::inputMethodEvent(QInputMethodEvent *event) |
64 { |
67 { |
|
68 //let it go in default way. |
|
69 if(mDefaultBehaviour) |
|
70 { |
|
71 HbAbstractEdit::inputMethodEvent(event); |
|
72 event->accept(); |
|
73 return; |
|
74 } |
|
75 |
65 if (!event->commitString().isEmpty() || event->replacementLength()) |
76 if (!event->commitString().isEmpty() || event->replacementLength()) |
66 { |
77 { |
67 if (event->commitString().contains(expr)) |
78 if (event->commitString().contains(expr)) |
68 { |
79 { |
69 if(this->text().isEmpty() || this->text().contains(sepAtEnd) || this->text().contains(mLabelExpr)) |
80 if(this->text().isEmpty() || this->text().contains(sepAtEnd) || this->text().contains(mLabelExpr)) |
335 event->accept(); |
358 event->accept(); |
336 } |
359 } |
337 |
360 |
338 void MsgUnifiedEditorLineEdit::setText(const QString& text) |
361 void MsgUnifiedEditorLineEdit::setText(const QString& text) |
339 { |
362 { |
340 QInputMethodEvent e; |
363 |
341 //make sure previous text is complete. |
364 if(!mDefaultBehaviour) |
342 e.setCommitString(";"); |
365 { |
343 this->inputMethodEvent(&e); |
366 QInputMethodEvent e; |
344 this->setCursorPosition(this->text().length()); |
367 //make sure previous text is complete. |
345 |
368 e.setCommitString(";"); |
346 QTextCursor cursor(this->textCursor()); |
369 this->inputMethodEvent(&e); |
347 QTextCharFormat colorFormat(cursor.charFormat()); |
370 this->setCursorPosition(this->text().length()); |
348 QColor fgColor = colorFormat.foreground().color(); |
371 |
349 fgColor.setAlpha(fadedAlpha); |
372 QTextCursor cursor(this->textCursor()); |
350 colorFormat.setUnderlineColor(fgColor); |
373 QTextCharFormat colorFormat(cursor.charFormat()); |
351 |
374 QColor fgColor = colorFormat.foreground().color(); |
352 colorFormat.setFontUnderline(true); |
375 fgColor.setAlpha(fadedAlpha); |
353 cursor.insertText(text , colorFormat); |
376 colorFormat.setUnderlineColor(fgColor); |
354 colorFormat.setFontUnderline(false); |
377 |
355 |
378 colorFormat.setFontUnderline(true); |
356 cursor.insertText(replacementStr,colorFormat); |
379 cursor.insertText(text , colorFormat); |
|
380 colorFormat.setFontUnderline(false); |
|
381 |
|
382 cursor.insertText(replacementStr,colorFormat); |
|
383 } |
|
384 else |
|
385 { |
|
386 this->setCursorPosition(this->text().length()); |
|
387 QTextCursor cursor(this->textCursor()); |
|
388 cursor.insertText(text); |
|
389 } |
357 |
390 |
358 this->setCursorVisibility(Hb::TextCursorHidden); |
391 this->setCursorVisibility(Hb::TextCursorHidden); |
359 } |
392 } |
360 |
393 |
361 QStringList MsgUnifiedEditorLineEdit::addresses() |
394 QStringList MsgUnifiedEditorLineEdit::addresses() |
362 { |
395 { |
363 QString text = this->text(); |
396 QString text = this->content(); |
364 text = text.remove(mLabel); |
|
365 QStringList list = text.split(replacementStr,QString::SkipEmptyParts); |
397 QStringList list = text.split(replacementStr,QString::SkipEmptyParts); |
366 //list.removeDuplicates(); |
|
367 return list; |
398 return list; |
368 } |
399 } |
369 |
400 |
370 void MsgUnifiedEditorLineEdit::focusInEvent(QFocusEvent* event) |
401 void MsgUnifiedEditorLineEdit::focusInEvent(QFocusEvent* event) |
371 { |
402 { |
372 HbAbstractEdit::focusInEvent(event); |
403 HbLineEdit::focusInEvent(event); |
373 this->setCursorVisibility(Hb::TextCursorVisible); |
404 this->setCursorVisibility(Hb::TextCursorVisible); |
374 } |
405 } |
375 |
406 |
376 void MsgUnifiedEditorLineEdit::setHighlight(int currentPos) |
407 void MsgUnifiedEditorLineEdit::setHighlight(int currentPos) |
377 { |
408 { |
430 { |
461 { |
431 this->setTextCursor(oldCursor); |
462 this->setTextCursor(oldCursor); |
432 return; |
463 return; |
433 } |
464 } |
434 |
465 |
435 mSelectionStart = newCursor.selectionStart(); |
466 if(!mDefaultBehaviour) |
436 mSelectionEnd = newCursor.selectionEnd(); |
467 { |
437 |
468 mSelectionStart = newCursor.selectionStart(); |
438 if(mSelectionStart == mSelectionEnd ) |
469 mSelectionEnd = newCursor.selectionEnd(); |
439 { |
470 |
440 return; |
471 if(mSelectionStart == mSelectionEnd ) |
441 } |
472 { |
442 |
473 return; |
443 mSelectionSnapTimer.start(SNAP_DELAY,this); |
474 } |
444 |
475 |
|
476 mSelectionSnapTimer.start(SNAP_DELAY,this); |
|
477 } |
445 } |
478 } |
446 |
479 |
447 void MsgUnifiedEditorLineEdit::timerEvent(QTimerEvent *event) |
480 void MsgUnifiedEditorLineEdit::timerEvent(QTimerEvent *event) |
448 { |
481 { |
449 //passing event to base class. |
482 //passing event to base class. |