src/hbwidgets/editors/hblineedit.cpp
changeset 7 923ff622b8b9
parent 6 c3690ec91ef8
child 21 4633027730f5
child 34 ed14f46c0e55
--- a/src/hbwidgets/editors/hblineedit.cpp	Wed Jun 23 18:33:25 2010 +0300
+++ b/src/hbwidgets/editors/hblineedit.cpp	Tue Jul 06 14:36:53 2010 +0300
@@ -32,12 +32,14 @@
 #include "hbtextmeasurementutility_p.h"
 #include "hbfeaturemanager_r.h"
 #endif //HB_TEXT_MEASUREMENT_UTILITY
+#include "hbevent.h"
 
 #include <QFontMetrics>
 #include <QPainter>
 #include <QTextBlock>
 #include <QTextDocument>
 #include <QGraphicsSceneResizeEvent>
+#include <QGraphicsLinearLayout>
 
 /*!
  \class HbLineEdit
@@ -283,7 +285,8 @@
 {
     Q_D(HbLineEdit);
     
-    if(d->echoMode == HbLineEdit::PasswordEchoOnEdit && d->clearOnEdit) {
+    if((!e->commitString().isEmpty() || e->replacementLength()) &&
+         d->echoMode == HbLineEdit::PasswordEchoOnEdit && d->clearOnEdit) {
         d->doc->clear();
         d->passwordText.clear();
         d->clearOnEdit = false;
@@ -311,6 +314,21 @@
     HbAbstractEdit::inputMethodEvent(e);
 }
 
+
+/*!
+ \reimp
+*/
+QVariant HbLineEdit::inputMethodQuery(Qt::InputMethodQuery property) const
+{
+    switch(property) {
+    case Qt::ImMaximumTextLength:
+        return QVariant(maxLength());
+    default:
+        return HbAbstractEdit::inputMethodQuery(property);
+    }
+}
+
+
 /*!
  \reimp
 */
@@ -357,7 +375,7 @@
     Q_D(HbLineEdit);
 
     if (event->key() == Qt::Key_Enter || event->key() == Qt::Key_Return) {
-        emit editingFinished();
+        d->editingFinished();
     }
 
     if(d->forwardKeyEvent(event)) {
@@ -635,15 +653,7 @@
  */
 void HbLineEdit::focusOutEvent(QFocusEvent * event)
 {
-    Q_D(HbLineEdit);
-
-    if(echoMode() == HbLineEdit::PasswordEchoOnEdit) {
-        setPlainText(d->passwordString(d->passwordText));
-    }
-
-    HbAbstractEdit::focusOutEvent(event);
-
-    emit editingFinished();
+    HbAbstractEdit::focusOutEvent(event);  
 }
 
 /*!
@@ -651,13 +661,6 @@
  */
 void HbLineEdit::focusInEvent(QFocusEvent * event)
 {
-    Q_D(HbLineEdit);
-
-    if(echoMode() == HbLineEdit::PasswordEchoOnEdit) {
-        // we need to clear the editor when typing starts
-        d->clearOnEdit = true;
-    }
-
     HbAbstractEdit::focusInEvent(event);
 }
 
@@ -690,6 +693,29 @@
 }
 
 /*!
+    \reimp
+*/
+bool HbLineEdit::event(QEvent* event)
+{
+    Q_D(HbLineEdit);
+
+    if (event->type() == HbEvent::InputMethodFocusIn) {
+        if(echoMode() == HbLineEdit::PasswordEchoOnEdit) {
+            // we need to clear the editor when typing starts
+            d->clearOnEdit = true;
+        }
+        d->showCustomAutoCompPopup();
+    } else if (event->type() == HbEvent::InputMethodFocusOut) {
+        d->hideCustomAutoCompPopup();
+        d->editingFinished();
+    }
+
+    return HbAbstractEdit::event(event);
+}
+
+
+
+/*!
     @proto
 
     Returns true if vertical font streach mode is active.
@@ -715,3 +741,35 @@
     }
     return HbAbstractEdit::eventFilter(obj, event);
 }
+
+/*!
+    set content of custum auto-complate pupup.
+ */
+void HbLineEdit::setAutoCompleteContent(QGraphicsLayoutItem *content)
+{
+    Q_D(HbLineEdit);
+
+    if (!d->mCustomAutoCompPopup) {
+        d->createCustomAutoCompPopup();
+        repolish();
+    }
+
+    if (d->mCustomAutoCompContent!=content) {
+        if (d->mCustomAutoCompContent) {
+            delete d->mCustomAutoCompContent;
+        }
+
+        d->mCustomAutoCompContent = content;
+
+        if (content->isLayout()) {
+            d->mCustomAutoCompPopup->setLayout(static_cast<QGraphicsLayout *>(content));
+        } else {
+            QGraphicsLinearLayout *linLayout = new QGraphicsLinearLayout(Qt::Horizontal,
+                                                                         d->mCustomAutoCompPopup);
+            linLayout->addItem(content);
+        }
+        if (hasFocus()) {
+            d->showCustomAutoCompPopup();
+        }
+    }
+}