messagingapp/msgui/unifiededitor/src/msgunifiededitorlineedit.cpp
changeset 25 84d9eb65b26f
parent 23 238255e8b033
child 27 e4592d119491
--- a/messagingapp/msgui/unifiededitor/src/msgunifiededitorlineedit.cpp	Fri Apr 16 14:56:15 2010 +0300
+++ b/messagingapp/msgui/unifiededitor/src/msgunifiededitorlineedit.cpp	Mon May 03 12:29:07 2010 +0300
@@ -33,27 +33,30 @@
 MsgUnifiedEditorLineEdit::MsgUnifiedEditorLineEdit(const QString& label,QGraphicsItem *parent):
 HbLineEdit(parent),
 mSelectionStart(-1),
-mSelectionEnd(-1)
+mSelectionEnd(-1),
+mDefaultBehaviour(false)
 {
+    QString labelStr = label.trimmed();
+    
     QTextCursor cursor(this->textCursor());
     QTextCharFormat colorFormat(cursor.charFormat());
    
-    QColor fgColor = colorFormat.foreground().color();     
+    QColor fgColor = this->palette().color(QPalette::Text);     
     fgColor.setAlpha(fadedAlpha);
     colorFormat.setForeground(fgColor);
-    cursor.insertText(label , colorFormat);
+    cursor.insertText(labelStr , colorFormat);
 
     fgColor.setAlpha(solidAlpha);
     colorFormat.setForeground(fgColor);
 
     cursor.insertText(" ",colorFormat);    
 
-    mLabelExpr.setPattern(QString("^"+label+" $"));
-    mLabel = label+" ";
+    mLabelExpr.setPattern(QString("^"+labelStr+" $"));
+    mLabel = labelStr+" ";
 
     connect(this,SIGNAL(selectionChanged(QTextCursor,QTextCursor)),
             this,SLOT(selectionChanged(QTextCursor,QTextCursor)));
-    connect(this, SIGNAL(textChanged(QString)), this, SLOT(onTextChanged(QString)));
+    connect(this, SIGNAL(contentsChanged()), this, SLOT(onContentsChanged()));
 }
 
 MsgUnifiedEditorLineEdit::~MsgUnifiedEditorLineEdit()
@@ -62,6 +65,14 @@
 
 void MsgUnifiedEditorLineEdit::inputMethodEvent(QInputMethodEvent *event)
 {
+    //let it go in default way.
+    if(mDefaultBehaviour)
+    {
+        HbAbstractEdit::inputMethodEvent(event);
+        event->accept();
+        return;
+    }
+
     if (!event->commitString().isEmpty() || event->replacementLength())
     {
         if (event->commitString().contains(expr))
@@ -95,6 +106,12 @@
 
     if(event->key()== Qt::Key_Enter || event->key()== Qt::Key_Return)
     {
+        if(mDefaultBehaviour)
+        {
+            HbAbstractEdit::keyReleaseEvent(event);
+            event->accept();
+            return;
+        }
         if(this->text().isEmpty() || this->text().contains(sepAtEnd) || this->text().contains(mLabelExpr))
         {
             event->accept();
@@ -269,6 +286,12 @@
 
     if(!str.isEmpty())
     {
+        if(mDefaultBehaviour)
+        {
+            HbAbstractEdit::keyPressEvent(event);
+            event->accept();
+            return;
+        }
         if (str.contains(expr))
         {
             if(this->text().isEmpty() || this->text().contains(sepAtEnd) || this->text().contains(mLabelExpr))
@@ -337,39 +360,47 @@
 
 void MsgUnifiedEditorLineEdit::setText(const QString& text)
 {
-    QInputMethodEvent e;
-    //make sure previous text is complete.
-    e.setCommitString(";");
-    this->inputMethodEvent(&e);
-    this->setCursorPosition(this->text().length());
+
+    if(!mDefaultBehaviour)
+    {
+        QInputMethodEvent e;
+        //make sure previous text is complete.
+        e.setCommitString(";");
+        this->inputMethodEvent(&e);
+        this->setCursorPosition(this->text().length());
 
-    QTextCursor cursor(this->textCursor());
-    QTextCharFormat colorFormat(cursor.charFormat());
-    QColor fgColor = colorFormat.foreground().color();     
-    fgColor.setAlpha(fadedAlpha);
-    colorFormat.setUnderlineColor(fgColor);
+        QTextCursor cursor(this->textCursor());
+        QTextCharFormat colorFormat(cursor.charFormat());
+        QColor fgColor = colorFormat.foreground().color();
+        fgColor.setAlpha(fadedAlpha);
+        colorFormat.setUnderlineColor(fgColor);
 
-    colorFormat.setFontUnderline(true);  
-    cursor.insertText(text , colorFormat);
-    colorFormat.setFontUnderline(false);
-    
-    cursor.insertText(replacementStr,colorFormat);
+        colorFormat.setFontUnderline(true);
+        cursor.insertText(text , colorFormat);
+        colorFormat.setFontUnderline(false);
+
+        cursor.insertText(replacementStr,colorFormat);       
+    }
+    else
+    {
+       this->setCursorPosition(this->text().length());
+       QTextCursor cursor(this->textCursor());
+       cursor.insertText(text);
+    }
     
     this->setCursorVisibility(Hb::TextCursorHidden);
 }
 
 QStringList MsgUnifiedEditorLineEdit::addresses()
-{    
-    QString text = this->text();
-    text = text.remove(mLabel);
+{
+    QString text = this->content();
     QStringList list = text.split(replacementStr,QString::SkipEmptyParts);
-    //list.removeDuplicates();
     return list;
 }
 
 void MsgUnifiedEditorLineEdit::focusInEvent(QFocusEvent* event)
 {    
-    HbAbstractEdit::focusInEvent(event);
+    HbLineEdit::focusInEvent(event);
     this->setCursorVisibility(Hb::TextCursorVisible);
 }
 
@@ -432,16 +463,18 @@
         return;
     }
 
-    mSelectionStart  = newCursor.selectionStart();
-    mSelectionEnd    = newCursor.selectionEnd();
+    if(!mDefaultBehaviour)
+        {
+        mSelectionStart  = newCursor.selectionStart();
+        mSelectionEnd    = newCursor.selectionEnd();
 
-    if(mSelectionStart == mSelectionEnd )
-    {
-        return;
-    }
-
-    mSelectionSnapTimer.start(SNAP_DELAY,this);
-
+        if(mSelectionStart == mSelectionEnd )
+            {
+            return;
+            }
+    
+        mSelectionSnapTimer.start(SNAP_DELAY,this);
+        }
 }
 
 void MsgUnifiedEditorLineEdit::timerEvent(QTimerEvent *event)
@@ -478,10 +511,25 @@
     }
 }
 
-void MsgUnifiedEditorLineEdit::onTextChanged(const QString& text)
+void MsgUnifiedEditorLineEdit::setDefaultBehaviour(bool defaultBehaviour)
 {
-    const QString changedText = const_cast<QString&>(text).remove(mLabel);
-    emit addressTextChanged(changedText);
+    mDefaultBehaviour = defaultBehaviour;
+}
+
+QString MsgUnifiedEditorLineEdit::text() const
+{
+    return HbLineEdit::text();
 }
 
+QString MsgUnifiedEditorLineEdit::content() const
+{
+    QString text = this->text();
+    text.remove(mLabel);
+    return text;
+}
+
+void MsgUnifiedEditorLineEdit::onContentsChanged()
+{
+    emit contentsChanged(content());
+}
 // eof