messagingapp/msgui/unifiededitor/src/msgunifiededitorlineedit.cpp
changeset 27 e4592d119491
parent 25 84d9eb65b26f
equal deleted inserted replaced
25:84d9eb65b26f 27:e4592d119491
   149         if(pbkContact)
   149         if(pbkContact)
   150         {
   150         {
   151             //if already selected delete it.
   151             //if already selected delete it.
   152             if(this->hasSelectedText())
   152             if(this->hasSelectedText())
   153             {
   153             {
       
   154                 // deleting phbkContact is an atomic operation
       
   155                 // ensure that the signal is emitted only once
       
   156                 disconnect(this, SIGNAL(contentsChanged()), 
       
   157                         this, SLOT(onContentsChanged()));
   154                 HbLineEdit::keyPressEvent(event);
   158                 HbLineEdit::keyPressEvent(event);
   155                 event->accept();
   159                 event->accept();
   156 
       
   157                 //delete seperator (i.e."; ").
   160                 //delete seperator (i.e."; ").
   158                 QKeyEvent eve(event->type(), Qt::Key_Delete, Qt::NoModifier);
   161                 QKeyEvent eve(event->type(), Qt::Key_Delete, Qt::NoModifier);
   159                 HbLineEdit::keyPressEvent(&eve);
   162                 HbLineEdit::keyPressEvent(&eve);
   160                 HbLineEdit::keyPressEvent(&eve);
   163                 HbLineEdit::keyPressEvent(&eve);
   161 
   164                 connect(this, SIGNAL(contentsChanged()), 
       
   165                         this, SLOT(onContentsChanged()));
       
   166                 onContentsChanged();
   162             }
   167             }
   163             else //make it selected
   168             else //make it selected
   164             {                
   169             {                
   165                 this->setCursorPosition(pos-3);
   170                 this->setCursorPosition(pos-3);
   166                 setHighlight(pos-3);
   171                 setHighlight(pos-3);
   169         else
   174         else
   170         {
   175         {
   171             QString str = text.right(2);
   176             QString str = text.right(2);
   172             if(str == replacementStr)
   177             if(str == replacementStr)
   173             {
   178             {
       
   179                 // deleting contact is an atomic operation
       
   180                 // ensure that the signal is emitted only once
       
   181                 disconnect(this, SIGNAL(contentsChanged()), 
       
   182                         this, SLOT(onContentsChanged()));
   174                 //delete seperator (i.e."; ").
   183                 //delete seperator (i.e."; ").
   175                 QKeyEvent eve(event->type(), Qt::Key_Backspace, Qt::NoModifier);
   184                 QKeyEvent eve(event->type(), Qt::Key_Backspace, Qt::NoModifier);
   176                 HbLineEdit::keyPressEvent(&eve);
   185                 HbLineEdit::keyPressEvent(&eve);
   177                 HbLineEdit::keyPressEvent(&eve);
   186                 HbLineEdit::keyPressEvent(&eve);
       
   187                 connect(this, SIGNAL(contentsChanged()), 
       
   188                         this, SLOT(onContentsChanged()));
       
   189                 onContentsChanged();
   178             }
   190             }
   179             else
   191             else
   180             {
   192             {
   181                 HbLineEdit::keyPressEvent(event);
   193                 HbLineEdit::keyPressEvent(event);
   182             }
   194             }
   183             event->accept();
   195             event->accept();
   184         }
   196         }
   185         
   197         
   186         event->accept();
   198         event->accept();
   187         return;
   199         return;
   188 
       
   189     }
   200     }
   190 
   201 
   191     if (event->key() == Qt::Key_Left )
   202     if (event->key() == Qt::Key_Left )
   192     {
   203     {
   193         bool selectedText = this->hasSelectedText();
   204         bool selectedText = this->hasSelectedText();
   356 
   367 
   357     this->update();
   368     this->update();
   358     event->accept();
   369     event->accept();
   359 }
   370 }
   360 
   371 
   361 void MsgUnifiedEditorLineEdit::setText(const QString& text)
   372 void MsgUnifiedEditorLineEdit::setText(const QString& text, bool underlined)
   362 {
   373 {
   363 
   374 
   364     if(!mDefaultBehaviour)
   375     if(!mDefaultBehaviour)
   365     {
   376     {
   366         QInputMethodEvent e;
   377         // atomic operation, ensure one signal only at the end
       
   378         disconnect(this, SIGNAL(contentsChanged()), this, SLOT(onContentsChanged()));
       
   379 
   367         //make sure previous text is complete.
   380         //make sure previous text is complete.
   368         e.setCommitString(";");
   381         if(this->content().length() > 0)
   369         this->inputMethodEvent(&e);
   382         {
       
   383             QInputMethodEvent e;
       
   384             e.setCommitString(";");
       
   385             this->inputMethodEvent(&e);
       
   386         }
   370         this->setCursorPosition(this->text().length());
   387         this->setCursorPosition(this->text().length());
   371 
   388 
   372         QTextCursor cursor(this->textCursor());
   389         QTextCursor cursor(this->textCursor());
   373         QTextCharFormat colorFormat(cursor.charFormat());
   390         QTextCharFormat colorFormat(cursor.charFormat());
   374         QColor fgColor = colorFormat.foreground().color();
   391         if(underlined)
   375         fgColor.setAlpha(fadedAlpha);
   392         {
   376         colorFormat.setUnderlineColor(fgColor);
   393             QColor fgColor = colorFormat.foreground().color();
   377 
   394             fgColor.setAlpha(fadedAlpha);
   378         colorFormat.setFontUnderline(true);
   395             colorFormat.setUnderlineColor(fgColor);
       
   396             colorFormat.setFontUnderline(true);        
       
   397         }
   379         cursor.insertText(text , colorFormat);
   398         cursor.insertText(text , colorFormat);
   380         colorFormat.setFontUnderline(false);
   399         colorFormat.setFontUnderline(false);
   381 
   400 
   382         cursor.insertText(replacementStr,colorFormat);       
   401         cursor.insertText(replacementStr,colorFormat);
       
   402         connect(this, SIGNAL(contentsChanged()), this, SLOT(onContentsChanged()));
       
   403         onContentsChanged();
   383     }
   404     }
   384     else
   405     else
   385     {
   406     {
   386        this->setCursorPosition(this->text().length());
   407        this->setCursorPosition(this->text().length());
   387        QTextCursor cursor(this->textCursor());
   408        QTextCursor cursor(this->textCursor());
   388        cursor.insertText(text);
   409        cursor.insertText(text);
   389     }
   410     }
   390     
       
   391     this->setCursorVisibility(Hb::TextCursorHidden);
       
   392 }
   411 }
   393 
   412 
   394 QStringList MsgUnifiedEditorLineEdit::addresses()
   413 QStringList MsgUnifiedEditorLineEdit::addresses()
   395 {
   414 {
   396     QString text = this->content();
   415     QString text = this->content();
   400 
   419 
   401 void MsgUnifiedEditorLineEdit::focusInEvent(QFocusEvent* event)
   420 void MsgUnifiedEditorLineEdit::focusInEvent(QFocusEvent* event)
   402 {    
   421 {    
   403     HbLineEdit::focusInEvent(event);
   422     HbLineEdit::focusInEvent(event);
   404     this->setCursorVisibility(Hb::TextCursorVisible);
   423     this->setCursorVisibility(Hb::TextCursorVisible);
       
   424 }
       
   425 
       
   426 void MsgUnifiedEditorLineEdit::focusOutEvent(QFocusEvent* event)
       
   427 {    
       
   428     HbLineEdit::focusOutEvent(event);
       
   429     this->setCursorVisibility(Hb::TextCursorHidden);
   405 }
   430 }
   406 
   431 
   407 void MsgUnifiedEditorLineEdit::setHighlight(int currentPos)
   432 void MsgUnifiedEditorLineEdit::setHighlight(int currentPos)
   408 {
   433 {
   409     QString txt = this->text();    
   434     QString txt = this->text();    
   526     QString text = this->text();
   551     QString text = this->text();
   527     text.remove(mLabel);
   552     text.remove(mLabel);
   528     return text;
   553     return text;
   529 }
   554 }
   530 
   555 
       
   556 void MsgUnifiedEditorLineEdit::clearContent()
       
   557 {
       
   558     // avoid getting updates during local editing
       
   559     disconnect(this, SIGNAL(contentsChanged()), this, SLOT(onContentsChanged()));
       
   560     
       
   561     int startPos = mLabel.length();
       
   562     this->setSelection(startPos, content().length());
       
   563     QKeyEvent eve(QEvent::KeyPress, Qt::Key_Backspace, Qt::NoModifier);
       
   564     this->keyPressEvent(&eve);
       
   565     this->deselect();
       
   566 
       
   567     // re-connect signal to start getting updates
       
   568     connect(this, SIGNAL(contentsChanged()), this, SLOT(onContentsChanged()));
       
   569 }
       
   570 
   531 void MsgUnifiedEditorLineEdit::onContentsChanged()
   571 void MsgUnifiedEditorLineEdit::onContentsChanged()
   532 {
   572 {
   533     emit contentsChanged(content());
   573     emit contentsChanged(content());
   534 }
   574 }
       
   575 
       
   576 void MsgUnifiedEditorLineEdit::highlightInvalidString(QString invalidStr)
       
   577 {
       
   578     // for only address editor
       
   579     if(!mDefaultBehaviour)
       
   580     {
       
   581         QString txtContent = this->text();
       
   582         int searchStartPos = mLabel.length();
       
   583         int startPos = txtContent.indexOf(invalidStr, searchStartPos);
       
   584         disconnect(this,SIGNAL(selectionChanged(QTextCursor,QTextCursor)),
       
   585                    this,SLOT(selectionChanged(QTextCursor,QTextCursor)));
       
   586         // if invalidStr found
       
   587         if(startPos > 0)
       
   588         {
       
   589             this->setSelection(startPos, invalidStr.length());
       
   590         }
       
   591         connect(this,SIGNAL(selectionChanged(QTextCursor,QTextCursor)),
       
   592                 this,SLOT(selectionChanged(QTextCursor,QTextCursor)));
       
   593     }
       
   594 }
       
   595 
   535 // eof
   596 // eof