src/hbwidgets/editors/hblineedit.cpp
changeset 0 16d8024aca5e
child 1 f7ac710697a9
equal deleted inserted replaced
-1:000000000000 0:16d8024aca5e
       
     1 /****************************************************************************
       
     2 **
       
     3 ** Copyright (C) 2008-2010 Nokia Corporation and/or its subsidiary(-ies).
       
     4 ** All rights reserved.
       
     5 ** Contact: Nokia Corporation (developer.feedback@nokia.com)
       
     6 **
       
     7 ** This file is part of the HbWidgets module of the UI Extensions for Mobile.
       
     8 **
       
     9 ** GNU Lesser General Public License Usage
       
    10 ** This file may be used under the terms of the GNU Lesser General Public
       
    11 ** License version 2.1 as published by the Free Software Foundation and
       
    12 ** appearing in the file LICENSE.LGPL included in the packaging of this file.
       
    13 ** Please review the following information to ensure the GNU Lesser General
       
    14 ** Public License version 2.1 requirements will be met:
       
    15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
       
    16 **
       
    17 ** In addition, as a special exception, Nokia gives you certain additional
       
    18 ** rights.  These rights are described in the Nokia Qt LGPL Exception
       
    19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
       
    20 **
       
    21 ** If you have questions regarding the use of this file, please contact
       
    22 ** Nokia at developer.feedback@nokia.com.
       
    23 **
       
    24 ****************************************************************************/
       
    25 
       
    26 #include "hblineedit.h"
       
    27 #include "hblineedit_p.h"
       
    28 
       
    29 #include "hbstyleoption.h"
       
    30 #include "hbscrollarea.h"
       
    31 #ifdef HB_TEXT_MEASUREMENT_UTILITY
       
    32 #include "hbtextmeasurementutility_p.h"
       
    33 #include "hbfeaturemanager_p.h"
       
    34 #endif //HB_TEXT_MEASUREMENT_UTILITY
       
    35 
       
    36 #include <QFontMetrics>
       
    37 #include <QGraphicsSceneMouseEvent>
       
    38 #include <QPainter>
       
    39 #include <QTextBlock>
       
    40 #include <QTextDocument>
       
    41 
       
    42 /*!
       
    43  \class HbLineEdit
       
    44  \brief HbLineEdit is a one line text editor widget
       
    45  @alpha
       
    46  @hbwidgets
       
    47 
       
    48  A line edit allows the user to enter and edit a single paragraph of plain text.
       
    49  The length of the text can be constrained to maxLength().
       
    50  You can change the text with setText(). The text is retrieved with text().
       
    51 
       
    52  The content in \ref HbLineEdit can be split visually into several lines. 
       
    53  In other words the content of the editor can be seen in several lines but it 
       
    54  does not contain any linefeeds (e.g. a number of email recipients separated with semicolon). 
       
    55  In the API there is a group of methods to support this. 
       
    56  
       
    57  If maxRows() is greater than minRows() the
       
    58  editor is expandable and it changes its size based on the content between min and max values. 
       
    59  Editor expandability can be checked with isExpandable().
       
    60 
       
    61  When the text changes the textChanged() signal is emitted.
       
    62  When the cursor is moved the cursorPositionChanged() signal is emitted.
       
    63  When editing is finished, either because the line edit lost focus or Return/Enter is pressed
       
    64  the editingFinished() signal is emitted.
       
    65 
       
    66   Echo mode controls how input to editors is shown in the screen. It is by default \b Normal. 
       
    67   Other possible modes are \b NoEcho, \b Password, and \b PasswordEchoOnEdit. 
       
    68 
       
    69  The frame can be styled using "P_LineEdit_frame" primitive in HbStyle. Text item is not
       
    70   replaceable but it can be styled.
       
    71  */
       
    72 
       
    73 /*!
       
    74  \fn void HbLineEdit::editingFinished()
       
    75 
       
    76  This signal is emitted when the line edit loses focus or Return/Enter is pressed.
       
    77  */
       
    78 
       
    79 /*!
       
    80     \fn void HbLineEdit::textChanged(const QString &text)
       
    81 
       
    82     This signal is emitted whenever the text changes. The text argument is the new text.
       
    83     This signal is also emitted when the text is changed programmatically, for example,
       
    84     by calling setText().
       
    85 
       
    86     Note: this signal is not emitted when the editor is in any of password modes, \sa echoMode()
       
    87 */
       
    88 
       
    89 /*!
       
    90     \fn void void HbLineEdit::selectionChanged()
       
    91     This signal is emitted when selection changes.
       
    92 */
       
    93 
       
    94 /*!
       
    95  Constructs an empty HbLineEdit with parent \a parent.
       
    96  */
       
    97 HbLineEdit::HbLineEdit (QGraphicsItem *parent) :
       
    98     HbAbstractEdit(*new HbLineEditPrivate, parent)
       
    99 {
       
   100     Q_D(HbLineEdit);
       
   101     d->q_ptr = this;
       
   102 
       
   103     d->init();
       
   104 }
       
   105 
       
   106 /*!
       
   107  Constructs a HbLineEdit with parent \a parent.
       
   108  The text edit will display the text \a text.
       
   109  The text is interpreted as plain text.
       
   110  */
       
   111 HbLineEdit::HbLineEdit (const QString &text, QGraphicsItem *parent) :
       
   112     HbAbstractEdit(*new HbLineEditPrivate, parent)
       
   113 {
       
   114     Q_D(HbLineEdit);
       
   115     d->q_ptr = this;
       
   116 
       
   117     d->init();
       
   118 
       
   119     if ( !text.isEmpty() ) {
       
   120         setText(text);
       
   121     }
       
   122 }
       
   123 
       
   124 /*!
       
   125  Constructs a HbLineEdit with parent \a parent.
       
   126  The text edit will use given private implementation \a dd.
       
   127  */
       
   128 HbLineEdit::HbLineEdit (HbLineEditPrivate &dd, QGraphicsItem *parent) :
       
   129     HbAbstractEdit(dd, parent)
       
   130 {
       
   131     Q_D(HbLineEdit);
       
   132     d->q_ptr = this;
       
   133 
       
   134     d->init();
       
   135 }
       
   136 
       
   137 /*!
       
   138  Destructor.
       
   139  */
       
   140 HbLineEdit::~HbLineEdit ()
       
   141 {
       
   142 }
       
   143 
       
   144 /*!
       
   145  Returns current maximum character length in edit.
       
   146 
       
   147  \sa setMaxLength
       
   148  */
       
   149 int HbLineEdit::maxLength () const
       
   150 {
       
   151     Q_D(const HbLineEdit);
       
   152     return d->maxLength;
       
   153 }
       
   154 
       
   155 /*!
       
   156  Sets edit maximum character length to \a length.
       
   157 
       
   158  If the text is too long, it is truncated at the limit.
       
   159  If truncation occurs any selected text will be unselected.
       
   160  By default, this property contains a value of -1 (unlimited).
       
   161  */
       
   162 void HbLineEdit::setMaxLength (int length)
       
   163 {
       
   164     Q_D(HbLineEdit);
       
   165     if (length < -1) return; // not allowed.
       
   166 
       
   167     if (d->maxLength != length) {
       
   168         d->maxLength = length;
       
   169         d->validateMaxLength();
       
   170     }
       
   171 }
       
   172 
       
   173 /*!
       
   174  Sets the minimum number of editor rows.
       
   175 
       
   176  \sa minRows
       
   177  */
       
   178 void HbLineEdit::setMinRows (int rows)
       
   179 {
       
   180     Q_D(HbLineEdit);
       
   181     d->setApiProtectionFlag(HbWidgetBasePrivate::AC_TextLinesMin, true);
       
   182 
       
   183     if (rows > 0) {
       
   184         d->minimumRows = rows;
       
   185 
       
   186         if (d->minimumRows > d->maximumRows) {
       
   187             d->maximumRows = d->minimumRows;
       
   188         }
       
   189         d->expandable = isExpandable();
       
   190 
       
   191         d->updateWrappingMode();
       
   192 
       
   193         updateGeometry();
       
   194     }
       
   195 }
       
   196 
       
   197 /*!
       
   198  Returns the minimum number of editor rows.
       
   199 
       
   200  \sa setMinRows
       
   201  */
       
   202 int HbLineEdit::minRows () const
       
   203 {
       
   204     Q_D(const HbLineEdit);
       
   205 
       
   206     return d->minimumRows;
       
   207 }
       
   208 
       
   209 /*!
       
   210  .Tells whether the editor is expandable or fixed.
       
   211  */
       
   212 bool HbLineEdit::isExpandable () const
       
   213 {
       
   214     Q_D(const HbLineEdit);
       
   215 
       
   216     return d->maximumRows > d->minimumRows;
       
   217 }
       
   218 
       
   219 /*!
       
   220  Sets the maximum number of editor rows to \a rows.
       
   221 
       
   222  \sa maxRows
       
   223 */
       
   224 void HbLineEdit::setMaxRows (int rows)
       
   225 {
       
   226     Q_D(HbLineEdit);
       
   227     d->setApiProtectionFlag(HbWidgetBasePrivate::AC_TextLinesMax, true);
       
   228 
       
   229     if (rows > 0) {
       
   230         d->maximumRows = rows;
       
   231 
       
   232         if (d->maximumRows  < d->minimumRows) {
       
   233             d->minimumRows = d->maximumRows;
       
   234         }
       
   235 
       
   236         d->expandable = isExpandable();
       
   237 
       
   238         d->updateWrappingMode();
       
   239 
       
   240         updateGeometry();
       
   241 
       
   242 #ifdef HB_TEXT_MEASUREMENT_UTILITY
       
   243         if ( HbFeatureManager::instance()->featureStatus( HbFeatureManager::TextMeasurement ) ) {
       
   244             setProperty( HbTextMeasurementUtilityNameSpace::textMaxLines, d->maximumRows );
       
   245         }
       
   246 #endif
       
   247     }
       
   248 }
       
   249 
       
   250 /*!
       
   251  Returns the maximum number of editor rows.
       
   252 
       
   253  \sa setMaxRows
       
   254  */
       
   255 int HbLineEdit::maxRows () const
       
   256 {
       
   257     Q_D(const HbLineEdit);
       
   258 
       
   259     return d->maximumRows;
       
   260 }
       
   261 
       
   262 /*!
       
   263  \reimp
       
   264  */
       
   265 void HbLineEdit::inputMethodEvent(QInputMethodEvent *e)
       
   266 {
       
   267     Q_D(HbLineEdit);
       
   268     
       
   269     if(d->echoMode == HbLineEdit::PasswordEchoOnEdit && d->clearOnEdit) {
       
   270         d->doc->clear();
       
   271         d->passwordText.clear();
       
   272         d->clearOnEdit = false;
       
   273     }
       
   274 
       
   275     if (e->commitString().contains("\n")) {
       
   276         QString str = e->commitString();
       
   277         str.replace("\n", " ");
       
   278         e->setCommitString(str, e->replacementStart(), e->replacementLength());
       
   279     }
       
   280     
       
   281     if (!e->commitString().isEmpty() || e->replacementLength()) {
       
   282         // change the commit string and update the password string in case we are in password mode
       
   283         if(d->echoMode == HbLineEdit::Password) {
       
   284             d->passwordText.replace(cursorPosition()+e->replacementStart(), e->replacementLength(), e->commitString());
       
   285             e->setCommitString(d->passwordString(e->commitString()), e->replacementStart(), e->replacementLength());
       
   286         } else if(d->echoMode == HbLineEdit::NoEcho) {
       
   287             d->passwordText.append(e->commitString());
       
   288             e->setCommitString("");
       
   289         } else if(d->echoMode == HbLineEdit::PasswordEchoOnEdit) {
       
   290             // in PasswordEchoOnEdit we still can see what we are typing
       
   291             d->passwordText.replace(cursorPosition()+e->replacementStart(), e->replacementLength(), e->commitString());
       
   292         }
       
   293     }
       
   294     HbAbstractEdit::inputMethodEvent(e);
       
   295 }
       
   296 
       
   297 /*!
       
   298  \reimp
       
   299 */
       
   300 
       
   301 void HbLineEdit::keyPressEvent (QKeyEvent *event)
       
   302 {
       
   303     Q_D(HbLineEdit);
       
   304 
       
   305     if(d->echoMode == HbLineEdit::PasswordEchoOnEdit && d->clearOnEdit) {
       
   306         d->doc->clear();
       
   307         d->passwordText.clear();
       
   308         d->clearOnEdit = false;
       
   309     }
       
   310 
       
   311     if(d->forwardKeyEvent(event)) {
       
   312         HbAbstractEdit::keyPressEvent(event);
       
   313     } else if (d->echoMode == HbLineEdit::Password || d->echoMode == HbLineEdit::NoEcho){
       
   314         // Keep doc and passwordText in sync
       
   315         bool update = false;
       
   316         if (event->key() == Qt::Key_Backspace && !(event->modifiers() & ~Qt::ShiftModifier)) {
       
   317             update = true;
       
   318             d->passwordText.remove(d->passwordText.length()-1,1);
       
   319         } else if (!event->text().isEmpty() && event->text().at(0).isPrint()) {
       
   320             update = true;
       
   321             d->passwordText.append(event->text());
       
   322         }
       
   323 
       
   324         if (update) {
       
   325             setPlainText(((d->echoMode == HbLineEdit::Password)?d->passwordString(d->passwordText):""));
       
   326         }
       
   327         setCursorPosition(d->passwordText.length());
       
   328     }
       
   329     if (d->echoMode == HbLineEdit::PasswordEchoOnEdit) {
       
   330         // Keep doc and passwordText in sync
       
   331         d->passwordText = toPlainText();
       
   332     }    
       
   333 }
       
   334 
       
   335 /*!
       
   336  \reimp
       
   337  */
       
   338 void HbLineEdit::keyReleaseEvent (QKeyEvent *event)
       
   339 {
       
   340     Q_D(HbLineEdit);
       
   341 
       
   342     if (event->key() == Qt::Key_Enter || event->key() == Qt::Key_Return) {
       
   343         emit editingFinished();
       
   344     }
       
   345 
       
   346     if(d->forwardKeyEvent(event)) {
       
   347         HbAbstractEdit::keyReleaseEvent(event);
       
   348     }
       
   349 }
       
   350 
       
   351 /*!
       
   352  \reimp
       
   353  */
       
   354 int HbLineEdit::type () const
       
   355 {
       
   356     return Type;
       
   357 }
       
   358 
       
   359 /*!
       
   360     Returns the edit's contents as plain text. If smiley recognition is enabled
       
   361     all the smiley images will be replaced by their textual representations.
       
   362 
       
   363     \sa setText() HbAbstractEdit::setSmileysEnabled()
       
   364 */
       
   365 QString HbLineEdit::text() const
       
   366 {
       
   367     Q_D(const HbLineEdit);
       
   368     if(d->isPasswordMode()) {
       
   369         return d->passwordText;
       
   370     }
       
   371     return toPlainText();
       
   372 }
       
   373 
       
   374 /*!
       
   375     This property holds the displayed text.
       
   376     If echoMode is Normal this returns the same as text(); if EchoMode is Password or PasswordEchoOnEdit it
       
   377     returns a string of asterisks text().length() characters long, e.g. "******";
       
   378     if EchoMode is NoEcho returns an empty string, "".
       
   379 
       
   380     By default, this property contains an empty string.
       
   381 
       
   382     \sa text()
       
   383 */
       
   384 QString HbLineEdit::displayText() const
       
   385 {
       
   386     return toPlainText();
       
   387 }
       
   388 
       
   389 /*!
       
   390   Returns true if there is any text section selected in the line edit.
       
   391   Otherwise returns false.
       
   392 
       
   393   \sa setSelection
       
   394  */
       
   395 bool HbLineEdit::hasSelectedText() const
       
   396 {
       
   397     return textCursor().hasSelection();
       
   398 }
       
   399 
       
   400 /*!
       
   401  Returns the text that is selected in the line edit.
       
   402  If no text section is selected, returns an empty string.
       
   403  */
       
   404 QString HbLineEdit::selectedText() const
       
   405 {
       
   406     return textCursor().selectedText();
       
   407 }
       
   408 
       
   409 /*!
       
   410   Returns the index of the first selected character in the line
       
   411   edit or -1 if no text is selected.
       
   412  */
       
   413 int HbLineEdit::selectionStart () const
       
   414 {
       
   415     if (hasSelectedText()) {
       
   416         return textCursor().selectionStart();
       
   417     } else {
       
   418         return -1;
       
   419     }
       
   420 }
       
   421 
       
   422 /*!
       
   423  Selects text from position \a start and for \a length characters.
       
   424  Negative lengths are allowed. Setting the selection fails if
       
   425  start position is negative or out of the range of line edit text.
       
   426 
       
   427  \sa hasSelectedText
       
   428  */
       
   429 void HbLineEdit::setSelection(int start, int length)
       
   430 {
       
   431     int textLength = text().count();
       
   432     QString test = text();
       
   433     Q_UNUSED(test)
       
   434     if (start < 0 || start > textLength) {
       
   435         return;
       
   436     }
       
   437 
       
   438     int end(start+length);
       
   439     if (end > textLength) {
       
   440         end = textLength;
       
   441     } else if (end < 0) {
       
   442         end = 0;
       
   443     }
       
   444 
       
   445     QTextCursor cursor = textCursor();
       
   446     cursor.setPosition(start, QTextCursor::MoveAnchor);
       
   447     cursor.setPosition(end, QTextCursor::KeepAnchor);
       
   448     setTextCursor(cursor);
       
   449 
       
   450 }
       
   451 
       
   452 /*!
       
   453     Sets cursor position to \a pos.
       
   454 
       
   455     \sa cursorPosition
       
   456  */
       
   457 void HbLineEdit::setCursorPosition (int pos)
       
   458 {
       
   459     int length = document()->begin().length();
       
   460 
       
   461     if (pos >= length) {
       
   462         pos = length-1;
       
   463     } else if (pos < 0) {
       
   464         pos = 0;
       
   465     }
       
   466     HbAbstractEdit::setCursorPosition(pos);
       
   467 }
       
   468 
       
   469 
       
   470 /*!
       
   471     \property HbLineEdit::echoMode
       
   472     \brief the line edit's echo mode
       
   473 
       
   474     The echo mode determines how the text entered in the line edit is
       
   475     displayed (or echoed) to the user.
       
   476 
       
   477     The most common setting is \l Normal, in which the text entered by the
       
   478     user is displayed verbatim, but HbLineEdit also supports modes that allow
       
   479     the entered text to be suppressed or obscured: these include \l NoEcho,
       
   480     \l Password and \l PasswordEchoOnEdit.
       
   481 
       
   482     The widget's display and the ability to copy or drag the text is
       
   483     affected by this setting.
       
   484 
       
   485     By default, this property is set to \l Normal.
       
   486 
       
   487     \sa setEchoMode()
       
   488 */
       
   489 
       
   490 HbLineEdit::EchoMode HbLineEdit::echoMode() const
       
   491 {
       
   492     Q_D(const HbLineEdit);
       
   493     return (EchoMode) d->echoMode;
       
   494 }
       
   495 
       
   496 void HbLineEdit::setEchoMode(EchoMode mode)
       
   497 {
       
   498     Q_D(HbLineEdit);
       
   499     if (mode == (EchoMode)d->echoMode)
       
   500         return;
       
   501     d->setEchoMode(mode);
       
   502 #if QT_VERSION >= 0x040600
       
   503     Qt::InputMethodHints hints = inputMethodHints();
       
   504     if(mode != Normal) {
       
   505         hints |= Qt::ImhNoPredictiveText|Qt::ImhHiddenText;
       
   506     } else {
       
   507         hints &= ~Qt::ImhNoPredictiveText & ~Qt::ImhHiddenText;
       
   508     }
       
   509     setInputMethodHints(hints);
       
   510 #endif // QT_VERSION
       
   511     // Clear the selection if any
       
   512     d->cursor.clearSelection();
       
   513     d->selectionChanged();
       
   514     update();
       
   515 }
       
   516 
       
   517 
       
   518 /*!
       
   519  Sets the current capitalization type of editor text.
       
   520 
       
   521  \sa capitalization QTextCharFormat::fontCapitalization
       
   522  */
       
   523 void HbLineEdit::setCapitalization ( QFont::Capitalization caps )
       
   524 {
       
   525     Q_D(HbLineEdit);
       
   526 
       
   527     d->setCapitalization(caps);
       
   528 }
       
   529 
       
   530 /*!
       
   531  Returns the current capitalization type of editor text.
       
   532 
       
   533  \sa setCapitalization QTextCharFormat::setFontCapitalization
       
   534  */
       
   535 QFont::Capitalization HbLineEdit::capitalization () const
       
   536 {
       
   537     Q_D(const HbLineEdit);
       
   538     return d->capitalization();
       
   539 }
       
   540 
       
   541 
       
   542 /*!
       
   543  Sets the text edit's text. The text is interpreted as plain text.
       
   544  If smiley recognition is enabled the textual smiley patterns are replaced
       
   545  with the corresponding image from the active smiley theme.
       
   546 
       
   547  \sa text HbAbstractEdit::setSmileysEnabled()
       
   548  */
       
   549 void HbLineEdit::setText(const QString &text)
       
   550 {
       
   551     Q_D(HbLineEdit);
       
   552 
       
   553     QString txt( text );
       
   554 
       
   555 #ifdef HB_TEXT_MEASUREMENT_UTILITY
       
   556     if ( HbFeatureManager::instance()->featureStatus( HbFeatureManager::TextMeasurement ) ) {
       
   557         if (text.endsWith(QChar(LOC_TEST_END))) {
       
   558             int index = text.indexOf(QChar(LOC_TEST_START));
       
   559             setProperty( HbTextMeasurementUtilityNameSpace::textIdPropertyName,  text.mid(index + 1, text.indexOf(QChar(LOC_TEST_END)) - index - 1) );
       
   560             setProperty( HbTextMeasurementUtilityNameSpace::textMaxLines, d->maximumRows );
       
   561             txt = text.left(index);
       
   562         } else {
       
   563             setProperty( HbTextMeasurementUtilityNameSpace::textIdPropertyName,  QVariant::Invalid );
       
   564         }
       
   565     }
       
   566 #endif //HB_TEXT_MEASUREMENT_UTILITY
       
   567 
       
   568     if(d->isPasswordMode()) {
       
   569         d->passwordText = txt;
       
   570     }
       
   571     setPlainText(d->echoString(txt));
       
   572     moveCursor(QTextCursor::EndOfBlock);
       
   573 }
       
   574 
       
   575 /*!
       
   576     \reimp
       
   577  */
       
   578 void HbLineEdit::resizeEvent(QGraphicsSceneResizeEvent *event)
       
   579 {
       
   580     HbAbstractEdit::resizeEvent(event);
       
   581 
       
   582     document()->setTextWidth(primitive(HbStyle::P_Edit_text)->boundingRect().width());
       
   583 }
       
   584 
       
   585 /*!
       
   586     \reimp
       
   587  */
       
   588 bool HbLineEdit::canInsertFromMimeData(const QMimeData *source) const
       
   589 {
       
   590     return source->hasText() && !source->text().isEmpty();
       
   591 }
       
   592 
       
   593 /*!
       
   594     \reimp
       
   595  */
       
   596 void HbLineEdit::insertFromMimeData(const QMimeData *source)
       
   597 {
       
   598     Q_D(HbLineEdit);
       
   599     if (!(d->interactionFlags & Qt::TextEditable) || !source)
       
   600         return;
       
   601 
       
   602     QString txt = source->text().replace(QString("\n"),QString(" "));
       
   603 
       
   604     if (!txt.isNull()) {
       
   605 
       
   606         if(d->isPasswordMode()) {
       
   607             d->passwordText = txt;
       
   608         }
       
   609 
       
   610         QTextDocumentFragment fragment = QTextDocumentFragment::fromPlainText(d->echoString(txt));
       
   611         d->cursor.insertFragment(fragment);
       
   612     }
       
   613 
       
   614     d->ensureCursorVisible();
       
   615 }
       
   616 
       
   617 /*!
       
   618     \reimp
       
   619  */
       
   620 void HbLineEdit::focusOutEvent(QFocusEvent * event)
       
   621 {
       
   622     Q_D(HbLineEdit);
       
   623     setBackgroundItem(HbStyle::P_LineEdit_frame_normal);
       
   624 
       
   625     if(echoMode() == HbLineEdit::PasswordEchoOnEdit) {
       
   626         setPlainText(d->passwordString(d->passwordText));
       
   627     }
       
   628 
       
   629     HbAbstractEdit::focusOutEvent(event);
       
   630 
       
   631     emit editingFinished();
       
   632 }
       
   633 
       
   634 /*!
       
   635     \reimp
       
   636  */
       
   637 void HbLineEdit::focusInEvent(QFocusEvent * event)
       
   638 {
       
   639     Q_D(HbLineEdit);
       
   640     setBackgroundItem(HbStyle::P_LineEdit_frame_highlight);
       
   641 
       
   642     if(echoMode() == HbLineEdit::PasswordEchoOnEdit) {
       
   643         // we need to clear the editor when typing starts
       
   644         d->clearOnEdit = true;
       
   645     }
       
   646 
       
   647     HbAbstractEdit::focusInEvent(event);
       
   648 }