41 #include "hbvalidator.h" |
41 #include "hbvalidator.h" |
42 #include "hbmenu.h" |
42 #include "hbmenu.h" |
43 #include "hbselectioncontrol_p.h" |
43 #include "hbselectioncontrol_p.h" |
44 #include "hbcolorscheme.h" |
44 #include "hbcolorscheme.h" |
45 #include "hbsmileyengine_p.h" |
45 #include "hbsmileyengine_p.h" |
46 #include "hbtextmeasurementutility_p.h" |
46 #include "hbtextmeasurementutility_r_p.h" |
47 #include "hbfeaturemanager_r.h" |
47 #include "hbfeaturemanager_r.h" |
48 #include "hbinputeditorinterface.h" |
48 #include "hbinputeditorinterface.h" |
49 #include "hbinputvkbhost.h" |
49 #include "hbinputvkbhost.h" |
50 #include "hbinputmethod.h" |
50 #include "hbinputmethod.h" |
51 #include "hbinputfocusobject.h" |
51 #include "hbinputfocusobject.h" |
88 if ((*it)->frameFormat().position() != QTextFrameFormat::InFlow) |
88 if ((*it)->frameFormat().position() != QTextFrameFormat::InFlow) |
89 r |= frame->document()->documentLayout()->frameBoundingRect(*it); |
89 r |= frame->document()->documentLayout()->frameBoundingRect(*it); |
90 } |
90 } |
91 return r; |
91 return r; |
92 } |
92 } |
|
93 |
|
94 |
|
95 class HbEditScrollArea: public HbScrollArea |
|
96 { |
|
97 public: |
|
98 explicit HbEditScrollArea(HbAbstractEdit* edit, QGraphicsItem* parent = 0):HbScrollArea(parent), mEdit(edit) {} |
|
99 virtual ~HbEditScrollArea() {} |
|
100 |
|
101 void resizeEvent(QGraphicsSceneResizeEvent *event) |
|
102 { |
|
103 HbScrollArea::resizeEvent(event); |
|
104 mEdit->updatePrimitives(); |
|
105 } |
|
106 |
|
107 private: |
|
108 HbAbstractEdit* mEdit; |
|
109 }; |
|
110 |
93 |
111 |
94 class HbEditItem : public HbWidget |
112 class HbEditItem : public HbWidget |
95 { |
113 { |
96 public: |
114 public: |
97 |
115 |
225 doc->setDefaultTextOption(textOption); |
243 doc->setDefaultTextOption(textOption); |
226 doc->setUndoRedoEnabled(interactionFlags & Qt::TextEditable); |
244 doc->setUndoRedoEnabled(interactionFlags & Qt::TextEditable); |
227 |
245 |
228 updatePaletteFromTheme(); |
246 updatePaletteFromTheme(); |
229 |
247 |
230 scrollArea = new HbScrollArea(q); |
248 scrollArea = new HbEditScrollArea(q,q); |
231 scrollArea->setClampingStyle(HbScrollArea::StrictClamping); |
249 scrollArea->setClampingStyle(HbScrollArea::StrictClamping); |
232 scrollArea->setFrictionEnabled(true); |
250 scrollArea->setFrictionEnabled(true); |
233 scrollArea->setScrollDirections(Qt::Vertical); |
251 scrollArea->setScrollDirections(Qt::Vertical); |
234 scrollArea->setVerticalScrollBarPolicy(HbScrollArea::ScrollBarAlwaysOff); |
252 scrollArea->setVerticalScrollBarPolicy(HbScrollArea::ScrollBarAlwaysOff); |
235 scrollArea->setContentWidget(canvas); |
253 scrollArea->setContentWidget(canvas); |
561 canvas->update(cursorRectPlusUnicodeDirectionMarkers(cursor.position())); |
579 canvas->update(cursorRectPlusUnicodeDirectionMarkers(cursor.position())); |
562 } |
580 } |
563 |
581 |
564 void HbAbstractEditPrivate::ensurePositionVisible(int position) |
582 void HbAbstractEditPrivate::ensurePositionVisible(int position) |
565 { |
583 { |
|
584 Q_Q(HbAbstractEdit); |
|
585 |
566 if (scrollArea && scrollable) { |
586 if (scrollArea && scrollable) { |
567 QRectF rect = rectForPositionInCanvasCoords(position, QTextLine::Leading); |
587 QRectF rect = rectForPositionInCanvasCoords(position, QTextLine::Leading); |
568 rect.adjust(0, -doc->documentMargin(), 0, doc->documentMargin()); |
588 rect.adjust(0, -doc->documentMargin(), 0, doc->documentMargin()); |
569 // TODO: it seems that scrollArea->ensureVisible() expects the point |
589 // TODO: it seems that scrollArea->ensureVisible() expects the point |
570 // in its content coordinates. Probably it should use viewport |
590 // in its content coordinates. Probably it should use viewport |
571 // coordinates i.e. its own item coordinate system |
591 // coordinates i.e. its own item coordinate system |
572 //QRectF recScroll = canvas->mapToItem(scrollArea, rect).boundingRect(); |
592 //QRectF recScroll = canvas->mapToItem(scrollArea, rect).boundingRect(); |
|
593 const QTextBlock block = doc->findBlock(position); |
|
594 if (block.isValid()) { |
|
595 const QTextLayout *layout = block.layout(); |
|
596 if(layout->preeditAreaText().length()) { |
|
597 // Adjust cursor rect so that predictive text will be also visible |
|
598 rect.adjust(0,0,q->boundingRect().width()/2,0); |
|
599 } |
|
600 } |
573 scrollArea->ensureVisible(rect.center(), rect.width(), rect.height()/2); |
601 scrollArea->ensureVisible(rect.center(), rect.width(), rect.height()/2); |
574 } |
602 } |
575 } |
603 } |
576 |
604 |
577 void HbAbstractEditPrivate::ensureCursorVisible() |
605 void HbAbstractEditPrivate::ensureCursorVisible() |
900 cursorWidth + w, line.height()); |
928 cursorWidth + w, line.height()); |
901 } else { |
929 } else { |
902 r = QRectF(layoutPos.x(), layoutPos.y(), cursorWidth, 10); // #### correct height |
930 r = QRectF(layoutPos.x(), layoutPos.y(), cursorWidth, 10); // #### correct height |
903 } |
931 } |
904 |
932 |
905 if(layout->preeditAreaText().length()) { |
|
906 r.adjust(0,0,q->blockBoundingRect(block).width()/2,0); |
|
907 } |
|
908 |
|
909 return r; |
933 return r; |
910 } |
934 } |
911 |
935 |
912 /* |
936 /* |
913 Returns the viewport rectangle in editor coordinate system. |
937 Returns the viewport rectangle in editor coordinate system. |