src/hbwidgets/editors/hbabstractedit_p.cpp
changeset 21 4633027730f5
parent 7 923ff622b8b9
child 23 e6ad4ef83b23
--- a/src/hbwidgets/editors/hbabstractedit_p.cpp	Tue Jul 06 14:36:53 2010 +0300
+++ b/src/hbwidgets/editors/hbabstractedit_p.cpp	Wed Aug 18 10:05:37 2010 +0300
@@ -43,7 +43,7 @@
 #include "hbselectioncontrol_p.h"
 #include "hbcolorscheme.h"
 #include "hbsmileyengine_p.h"
-#include "hbtextmeasurementutility_p.h"
+#include "hbtextmeasurementutility_r_p.h"
 #include "hbfeaturemanager_r.h"
 #include "hbinputeditorinterface.h"
 #include "hbinputvkbhost.h"
@@ -91,6 +91,24 @@
     return r;
 }
 
+
+class HbEditScrollArea: public HbScrollArea
+{
+public:
+    explicit HbEditScrollArea(HbAbstractEdit* edit, QGraphicsItem* parent = 0):HbScrollArea(parent), mEdit(edit) {}
+    virtual ~HbEditScrollArea() {}
+
+    void resizeEvent(QGraphicsSceneResizeEvent *event)
+    {
+        HbScrollArea::resizeEvent(event);
+        mEdit->updatePrimitives();
+    }
+
+private:
+    HbAbstractEdit* mEdit;
+};
+
+
 class HbEditItem : public HbWidget
 {
 public:
@@ -227,7 +245,7 @@
 
     updatePaletteFromTheme();
 
-    scrollArea = new HbScrollArea(q);
+    scrollArea = new HbEditScrollArea(q,q);
     scrollArea->setClampingStyle(HbScrollArea::StrictClamping);
     scrollArea->setFrictionEnabled(true);
     scrollArea->setScrollDirections(Qt::Vertical);
@@ -563,6 +581,8 @@
 
 void HbAbstractEditPrivate::ensurePositionVisible(int position)
 {
+    Q_Q(HbAbstractEdit);
+
     if (scrollArea && scrollable) {
         QRectF rect = rectForPositionInCanvasCoords(position, QTextLine::Leading);
         rect.adjust(0, -doc->documentMargin(), 0, doc->documentMargin());
@@ -570,6 +590,14 @@
         //       in its content coordinates. Probably it should use viewport
         //       coordinates i.e. its own item coordinate system
         //QRectF recScroll = canvas->mapToItem(scrollArea, rect).boundingRect();
+        const QTextBlock block = doc->findBlock(position);
+        if (block.isValid()) {
+            const QTextLayout *layout = block.layout();
+            if(layout->preeditAreaText().length()) {
+                // Adjust cursor rect so that predictive text will be also visible
+                rect.adjust(0,0,q->boundingRect().width()/2,0);
+            }
+        }
         scrollArea->ensureVisible(rect.center(), rect.width(), rect.height()/2);
     }
 }
@@ -902,10 +930,6 @@
         r = QRectF(layoutPos.x(), layoutPos.y(), cursorWidth, 10); // #### correct height
     }
 
-    if(layout->preeditAreaText().length()) {
-        r.adjust(0,0,q->blockBoundingRect(block).width()/2,0);
-    }
-
     return r;
 }