src/hbwidgets/editors/hbabstractedit_p.cpp
changeset 7 923ff622b8b9
parent 6 c3690ec91ef8
child 21 4633027730f5
child 34 ed14f46c0e55
--- a/src/hbwidgets/editors/hbabstractedit_p.cpp	Wed Jun 23 18:33:25 2010 +0300
+++ b/src/hbwidgets/editors/hbabstractedit_p.cpp	Tue Jul 06 14:36:53 2010 +0300
@@ -39,7 +39,6 @@
 #include "hbstyleoption_p.h"
 #include "hbscrollarea.h"
 #include "hbvalidator.h"
-#include "hbmeshlayout_p.h"
 #include "hbmenu.h"
 #include "hbselectioncontrol_p.h"
 #include "hbcolorscheme.h"
@@ -48,6 +47,9 @@
 #include "hbfeaturemanager_r.h"
 #include "hbinputeditorinterface.h"
 #include "hbinputvkbhost.h"
+#include "hbinputmethod.h"
+#include "hbinputfocusobject.h"
+
 
 #include <QValidator>
 #include <QTextLayout>
@@ -95,6 +97,7 @@
 
     HbEditItem(HbAbstractEdit *parent) : HbWidget(parent), edit(parent)
     {
+    	setFlag(QGraphicsItem::ItemUsesExtendedStyleOption, true);
     };
 
     virtual ~HbEditItem() {};
@@ -377,7 +380,7 @@
     }
 
     cursor.setPosition(pos, mode);
-
+    ensureCursorVisible();
     cursorChanged(HbValidator::CursorChangeFromMouse);
 }
 
@@ -581,13 +584,11 @@
 
 void HbAbstractEditPrivate::setTextInteractionFlags(Qt::TextInteractionFlags flags)
 {
-    Q_Q(HbAbstractEdit);
-
     if (flags == interactionFlags)
         return;
     interactionFlags = flags;
 
-    if (q->hasFocus()) {
+    if (hasInputFocus()) {
         setBlinkingCursorEnabled(flags & Qt::TextEditable);
     }
 }
@@ -777,7 +778,7 @@
     if (cursor.hasSelection()) {
         QAbstractTextDocumentLayout::Selection selection;
         selection.cursor = cursor;
-        QPalette::ColorGroup cg = q->hasFocus() ? QPalette::Active : QPalette::Inactive;
+        QPalette::ColorGroup cg = hasInputFocus() ? QPalette::Active : QPalette::Inactive;
         selection.format.setBackground(ctx.palette.brush(cg, QPalette::Highlight));
         selection.format.setForeground(ctx.palette.brush(cg, QPalette::HighlightedText));
 
@@ -1078,16 +1079,24 @@
     } else {
         // Currently focused widget to listen to InputContext before updating the cursor position
         sendMouseEventToInputContext(point);
+
+        // translate the point to have the Y ccordinate inside the viewport
+        QPointF translatedPoint(point);
+        if(translatedPoint.y() < viewPortRect().top()) {
+            translatedPoint.setY(viewPortRect().top() + 1);
+        } else if(translatedPoint.y() > viewPortRect().bottom()){
+            translatedPoint.setY(viewPortRect().bottom() - 1);
+        }
+
         // need to get the cursor position again since input context can change the document
-        newCursorPos = hitTest(point, Qt::FuzzyHit);
+        newCursorPos = hitTest(translatedPoint, Qt::FuzzyHit);
         setCursorPosition(newCursorPos);
 
         if (interactionFlags & Qt::TextEditable) {
             updateCurrentCharFormat();
         }
-        cursorChanged(HbValidator::CursorChangeFromMouse);
 
-        QString anchor(q->anchorAt(point));
+        QString anchor(q->anchorAt(translatedPoint));
         if(!anchor.isEmpty()) {
             emit q->anchorTapped(anchor);
         }
@@ -1234,16 +1243,27 @@
     sendInputPanelEvent(QEvent::CloseSoftwareInputPanel);
 }
 
-#include "hbinputeditorinterface.h"
-#include "hbinputvkbhost.h"
-
-void HbAbstractEditPrivate::minimizeInputPanel()
+bool HbAbstractEditPrivate::hasInputFocus() const
 {
-    Q_Q(HbAbstractEdit);
+    Q_Q(const HbAbstractEdit);
+
+    HbInputMethod* inputMethod = HbInputMethod::activeInputMethod();
+    if (inputMethod && inputMethod->focusObject() &&
+        qobject_cast<HbAbstractEdit*>(inputMethod->focusObject()->object()) == q) {
+        return true;
+    }
+    return false;
+}
 
-    HbEditorInterface ei(q);
-    HbVkbHost* vkbHost = ei.vkbHost();
-    vkbHost->minimizeKeypad();
+void HbAbstractEditPrivate::setInputFocusEnabled(bool enable)
+{
+    QGraphicsItem *focusItem = focusPrimitive(HbWidget::FocusHighlightActive);
+    if (focusItem) {
+        focusItem->setVisible(enable);
+    }
+
+    setBlinkingCursorEnabled(enable);
+    repaintOldAndNewSelection(selectionCursor);
 }
 
 #include "moc_hbabstractedit.cpp"