Use QWidgetTextControl in the QtQuick1 TextEdit.
authorAndrew den Exter <andrew.den-exter@nokia.com>
Tue, 29 Nov 2011 05:33:56 +0000 (15:33 +1000)
committerQt by Nokia <qt-info@nokia.com>
Fri, 2 Dec 2011 08:05:05 +0000 (09:05 +0100)
QDeclarative1TextEdit and QTextEdit have the same compatbility
requirements so it makes sense they continue sharing the same line
control implementation.  This allows the QtQuick 2 TextInput to diverge
without creating a third variation of QTextControl,

Task-number: QTBUG-22627
Change-Id: Id4a8f6a17aeb756c3385cf8fca3de61b8c4be757
Reviewed-by: Martin Jones <martin.jones@nokia.com>
src/qtquick1/graphicsitems/qdeclarativetextedit.cpp
src/qtquick1/graphicsitems/qdeclarativetextedit_p_p.h
tests/auto/qtquick1/qdeclarativetextedit/tst_qdeclarativetextedit.cpp

index 27ef543..fc799a2 100644 (file)
@@ -58,7 +58,7 @@
 #include <QPainter>
 #include <QtGui/QInputPanel>
 
-#include <private/qtextcontrol_p.h>
+#include <private/qwidgettextcontrol_p.h>
 
 QT_BEGIN_NAMESPACE
 
@@ -555,7 +555,10 @@ bool QDeclarative1TextEditPrivate::determineHorizontalAlignment()
     if (hAlignImplicit && q->isComponentComplete()) {
         bool alignToRight;
         if (text.isEmpty()) {
-            const QString preeditText = control->textCursor().block().layout()->preeditAreaText();
+            QTextCursor cursor = control->textCursor();
+            const QString preeditText = cursor.block().isValid()
+                    ? control->textCursor().block().layout()->preeditAreaText()
+                    : QString();
             alignToRight = preeditText.isEmpty()
                     ? QApplication::keyboardInputDirection() == Qt::RightToLeft
                     : preeditText.isRightToLeft();
@@ -1545,12 +1548,12 @@ void QDeclarative1TextEditPrivate::init()
     q->setFlag(QGraphicsItem::ItemHasNoContents, false);
     q->setFlag(QGraphicsItem::ItemAcceptsInputMethod);
 
-    control = new QTextControl(q);
+    control = new QWidgetTextControl(q);
     control->setIgnoreUnusedNavigationEvents(true);
     control->setTextInteractionFlags(Qt::TextInteractionFlags(Qt::LinksAccessibleByMouse | Qt::TextSelectableByKeyboard | Qt::TextEditable));
     control->setDragEnabled(false);
 
-    // QTextControl follows the default text color
+    // QWidgetTextControl follows the default text color
     // defined by the platform, declarative text
     // should be black by default
     QPalette pal = control->palette();
index ed75a97..f747b49 100644 (file)
@@ -62,7 +62,7 @@ QT_BEGIN_NAMESPACE
 
 class QTextLayout;
 class QTextDocument;
-class QTextControl;
+class QWidgetTextControl;
 class QDeclarative1TextEditPrivate : public QDeclarative1ImplicitSizePaintedItemPrivate
 {
     Q_DECLARE_PUBLIC(QDeclarative1TextEdit)
@@ -125,7 +125,7 @@ public:
     QDeclarativeItem* cursor;
     QDeclarative1TextEdit::TextFormat format;
     QTextDocument *document;
-    QTextControl *control;
+    QWidgetTextControl *control;
     QDeclarative1TextEdit::WrapMode wrapMode;
     QDeclarative1TextEdit::SelectionMode mouseSelectionMode;
     int lineCount;
index f64688e..621c175 100644 (file)
@@ -58,7 +58,7 @@
 #include <QClipboard>
 #include <QMimeData>
 #include <private/qapplication_p.h>
-#include <private/qtextcontrol_p.h>
+#include <private/qwidgettextcontrol_p.h>
 
 Q_DECLARE_METATYPE(QDeclarative1TextEdit::SelectionMode)
 
@@ -1977,7 +1977,7 @@ void tst_qdeclarativetextedit::canPaste() {
     QVERIFY(textEdit != 0);
 
     // check initial value - QTBUG-17765
-    QTextControl tc;
+    QWidgetTextControl tc;
     QCOMPARE(textEdit->canPaste(), tc.canPaste());
 
 #endif
@@ -1995,7 +1995,7 @@ void tst_qdeclarativetextedit::canPasteEmpty() {
     QVERIFY(textEdit != 0);
 
     // check initial value - QTBUG-17765
-    QTextControl tc;
+    QWidgetTextControl tc;
     QCOMPARE(textEdit->canPaste(), tc.canPaste());
 
 #endif