summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/declarative/graphicsitems/qdeclarativetext.cpp2
-rw-r--r--src/declarative/graphicsitems/qdeclarativetextedit.cpp15
-rw-r--r--src/declarative/graphicsitems/qdeclarativetextinput.cpp31
-rw-r--r--src/declarative/graphicsitems/qdeclarativetextinput_p.h2
-rw-r--r--tests/auto/declarative/qdeclarativetextedit/tst_qdeclarativetextedit.cpp34
-rw-r--r--tests/auto/declarative/qdeclarativetextinput/tst_qdeclarativetextinput.cpp47
6 files changed, 78 insertions, 53 deletions
diff --git a/src/declarative/graphicsitems/qdeclarativetext.cpp b/src/declarative/graphicsitems/qdeclarativetext.cpp
index a7e2ed0..200a680 100644
--- a/src/declarative/graphicsitems/qdeclarativetext.cpp
+++ b/src/declarative/graphicsitems/qdeclarativetext.cpp
@@ -711,6 +711,8 @@ QRectF QDeclarativeText::boundingRect() const
int x = 0;
int y = 0;
+ // Could include font max left/right bearings to either side of rectangle.
+
if (d->cache || d->style != Normal) {
switch (d->hAlign) {
case AlignLeft:
diff --git a/src/declarative/graphicsitems/qdeclarativetextedit.cpp b/src/declarative/graphicsitems/qdeclarativetextedit.cpp
index 5b4d80b..f3eef23 100644
--- a/src/declarative/graphicsitems/qdeclarativetextedit.cpp
+++ b/src/declarative/graphicsitems/qdeclarativetextedit.cpp
@@ -1341,6 +1341,15 @@ QRectF QDeclarativeTextEdit::boundingRect() const
{
Q_D(const QDeclarativeTextEdit);
QRectF r = QDeclarativePaintedItem::boundingRect();
+ int cursorWidth = 1;
+ if(d->cursor)
+ cursorWidth = d->cursor->width();
+ if(!d->document->isEmpty())
+ cursorWidth += 3;// ### Need a better way of accounting for space between char and cursor
+
+ // Could include font max left/right bearings to either side of rectangle.
+
+ r.setRight(r.right() + cursorWidth);
return r.translated(0,d->yoff);
}
@@ -1380,12 +1389,6 @@ void QDeclarativeTextEdit::updateSize()
int newWidth = qCeil(d->document->idealWidth());
if (!widthValid() && d->document->textWidth() != newWidth)
d->document->setTextWidth(newWidth); // ### Text does not align if width is not set (QTextDoc bug)
- int cursorWidth = 1;
- if(d->cursor)
- cursorWidth = d->cursor->width();
- newWidth += cursorWidth;
- if(!d->document->isEmpty())
- newWidth += 3;// ### Need a better way of accounting for space between char and cursor
// ### Setting the implicitWidth triggers another updateSize(), and unless there are bindings nothing has changed.
setImplicitWidth(newWidth);
qreal newHeight = d->document->isEmpty() ? fm.height() : (int)d->document->size().height();
diff --git a/src/declarative/graphicsitems/qdeclarativetextinput.cpp b/src/declarative/graphicsitems/qdeclarativetextinput.cpp
index c2eea6e..5325f25 100644
--- a/src/declarative/graphicsitems/qdeclarativetextinput.cpp
+++ b/src/declarative/graphicsitems/qdeclarativetextinput.cpp
@@ -824,7 +824,7 @@ void QDeclarativeTextInput::createCursor()
QDeclarative_setParent_noEvent(d->cursorItem, this);
d->cursorItem->setParentItem(this);
d->cursorItem->setX(d->control->cursorToX());
- d->cursorItem->setHeight(d->control->height());
+ d->cursorItem->setHeight(d->control->height()-1); // -1 to counter QLineControl's +1 which is not consistent with Text.
}
void QDeclarativeTextInput::moveCursor()
@@ -1029,19 +1029,7 @@ void QDeclarativeTextInput::geometryChanged(const QRectF &newGeometry,
int QDeclarativeTextInputPrivate::calculateTextWidth()
{
- int cursorWidth = control->cursorWidth();
- if(cursorItem)
- cursorWidth = cursorItem->width();
-
- QFontMetrics fm = QFontMetrics(font);
- int leftBearing = 0;
- int rightBearing = 0;
- if (!control->text().isEmpty()) {
- leftBearing = qMax(0, -fm.leftBearing(control->text().at(0)));
- rightBearing = qMax(0, -fm.rightBearing(control->text().at(control->text().count()-1)));
- }
-
- return qRound(control->naturalTextWidth()) + qMax(cursorWidth, leftBearing) + rightBearing;
+ return qRound(control->naturalTextWidth());
}
void QDeclarativeTextInputPrivate::updateHorizontalScroll()
@@ -1481,12 +1469,25 @@ void QDeclarativeTextInput::updateRect(const QRect &r)
update();
}
+QRectF QDeclarativeTextInput::boundingRect() const
+{
+ Q_D(const QDeclarativeTextInput);
+ QRectF r = QDeclarativePaintedItem::boundingRect();
+
+ int cursorWidth = d->cursorItem ? d->cursorItem->width() : d->control->cursorWidth();
+
+ // Could include font max left/right bearings to either side of rectangle.
+
+ r.setRight(r.right() + cursorWidth);
+ return r;
+}
+
void QDeclarativeTextInput::updateSize(bool needsRedraw)
{
Q_D(QDeclarativeTextInput);
int w = width();
int h = height();
- setImplicitHeight(d->control->height());
+ setImplicitHeight(d->control->height()-1); // -1 to counter QLineControl's +1 which is not consistent with Text.
setImplicitWidth(d->calculateTextWidth());
setContentsSize(QSize(width(), height()));//Repaints if changed
if(w==width() && h==height() && needsRedraw){
diff --git a/src/declarative/graphicsitems/qdeclarativetextinput_p.h b/src/declarative/graphicsitems/qdeclarativetextinput_p.h
index bacd041..ded0d09 100644
--- a/src/declarative/graphicsitems/qdeclarativetextinput_p.h
+++ b/src/declarative/graphicsitems/qdeclarativetextinput_p.h
@@ -187,6 +187,8 @@ public:
void drawContents(QPainter *p,const QRect &r);
QVariant inputMethodQuery(Qt::InputMethodQuery property) const;
+ QRectF boundingRect() const;
+
Q_SIGNALS:
void textChanged();
void cursorPositionChanged();
diff --git a/tests/auto/declarative/qdeclarativetextedit/tst_qdeclarativetextedit.cpp b/tests/auto/declarative/qdeclarativetextedit/tst_qdeclarativetextedit.cpp
index 2025504..5a81881 100644
--- a/tests/auto/declarative/qdeclarativetextedit/tst_qdeclarativetextedit.cpp
+++ b/tests/auto/declarative/qdeclarativetextedit/tst_qdeclarativetextedit.cpp
@@ -64,6 +64,23 @@
#define SRCDIR "."
#endif
+QString createExpectedFileIfNotFound(const QString& filebasename, const QImage& actual)
+{
+ // XXX This will be replaced by some clever persistent platform image store.
+ QString persistent_dir = SRCDIR "/data";
+ QString arch = "unknown-architecture"; // QTest needs to help with this.
+
+ QString expectfile = persistent_dir + QDir::separator() + filebasename + "-" + arch + ".png";
+
+ if (!QFile::exists(expectfile)) {
+ actual.save(expectfile);
+ qWarning() << "created" << expectfile;
+ }
+
+ return expectfile;
+}
+
+
class tst_qdeclarativetextedit : public QObject
{
@@ -209,7 +226,7 @@ void tst_qdeclarativetextedit::width()
QDeclarativeTextEdit *textEditObject = qobject_cast<QDeclarativeTextEdit*>(texteditComponent.create());
QVERIFY(textEditObject != 0);
- QCOMPARE(textEditObject->width(), 1.);//+1 for cursor
+ QCOMPARE(textEditObject->width(), 0.0);
}
for (int i = 0; i < standard.size(); i++)
@@ -225,7 +242,7 @@ void tst_qdeclarativetextedit::width()
QDeclarativeTextEdit *textEditObject = qobject_cast<QDeclarativeTextEdit*>(texteditComponent.create());
QVERIFY(textEditObject != 0);
- QCOMPARE(textEditObject->width(), qreal(metricWidth + 1 + 3));//+3 is the current way of accounting for space between cursor and last character.
+ QCOMPARE(textEditObject->width(), qreal(metricWidth));
}
for (int i = 0; i < richText.size(); i++)
@@ -242,7 +259,7 @@ void tst_qdeclarativetextedit::width()
QDeclarativeTextEdit *textEditObject = qobject_cast<QDeclarativeTextEdit*>(texteditComponent.create());
QVERIFY(textEditObject != 0);
- QCOMPARE(textEditObject->width(), qreal(documentWidth + 1 + 3));
+ QCOMPARE(textEditObject->width(), qreal(documentWidth));
}
}
@@ -345,16 +362,7 @@ void tst_qdeclarativetextedit::alignments()
QPainter p(&actual);
canvas->render(&p);
- // XXX This will be replaced by some clever persistent platform image store.
- QString persistent_dir = SRCDIR "/data";
- QString arch = "unknown-architecture"; // QTest needs to help with this.
-
- expectfile = persistent_dir + QDir::separator() + expectfile + "-" + arch + ".png";
-
- if (!QFile::exists(expectfile)) {
- actual.save(expectfile);
- qWarning() << "created" << expectfile;
- }
+ expectfile = createExpectedFileIfNotFound(expectfile, actual);
QImage expect(expectfile);
diff --git a/tests/auto/declarative/qdeclarativetextinput/tst_qdeclarativetextinput.cpp b/tests/auto/declarative/qdeclarativetextinput/tst_qdeclarativetextinput.cpp
index 5354f42..9ae7c99 100644
--- a/tests/auto/declarative/qdeclarativetextinput/tst_qdeclarativetextinput.cpp
+++ b/tests/auto/declarative/qdeclarativetextinput/tst_qdeclarativetextinput.cpp
@@ -47,6 +47,7 @@
#include <private/qdeclarativetextinput_p.h>
#include <private/qdeclarativetextinput_p_p.h>
#include <QDebug>
+#include <QDir>
#include <QStyle>
#include <QInputContext>
#include <private/qapplication_p.h>
@@ -56,6 +57,22 @@
#define SRCDIR "."
#endif
+QString createExpectedFileIfNotFound(const QString& filebasename, const QImage& actual)
+{
+ // XXX This will be replaced by some clever persistent platform image store.
+ QString persistent_dir = SRCDIR "/data";
+ QString arch = "unknown-architecture"; // QTest needs to help with this.
+
+ QString expectfile = persistent_dir + QDir::separator() + filebasename + "-" + arch + ".png";
+
+ if (!QFile::exists(expectfile)) {
+ actual.save(expectfile);
+ qWarning() << "created" << expectfile;
+ }
+
+ return expectfile;
+}
+
class tst_qdeclarativetextinput : public QObject
{
@@ -158,7 +175,7 @@ void tst_qdeclarativetextinput::width()
QDeclarativeTextInput *textinputObject = qobject_cast<QDeclarativeTextInput*>(textinputComponent.create());
QVERIFY(textinputObject != 0);
- QCOMPARE(textinputObject->width(), 1.); // 1 for the cursor
+ QCOMPARE(textinputObject->width(), 0.0);
delete textinputObject;
}
@@ -381,9 +398,9 @@ void tst_qdeclarativetextinput::horizontalAlignment_data()
QTest::addColumn<int>("hAlign");
QTest::addColumn<QString>("expectfile");
- QTest::newRow("L") << int(Qt::AlignLeft) << SRCDIR "/data/halign_left.png";
- QTest::newRow("R") << int(Qt::AlignRight) << SRCDIR "/data/halign_right.png";
- QTest::newRow("C") << int(Qt::AlignHCenter) << SRCDIR "/data/halign_center.png";
+ QTest::newRow("L") << int(Qt::AlignLeft) << "halign_left";
+ QTest::newRow("R") << int(Qt::AlignRight) << "halign_right";
+ QTest::newRow("C") << int(Qt::AlignHCenter) << "halign_center";
}
void tst_qdeclarativetextinput::horizontalAlignment()
@@ -391,13 +408,6 @@ void tst_qdeclarativetextinput::horizontalAlignment()
QFETCH(int, hAlign);
QFETCH(QString, expectfile);
-#ifdef Q_WS_X11
- // Font-specific, but not likely platform-specific, so only test on one platform
- QFont fn;
- fn.setRawName("-misc-fixed-medium-r-*-*-8-*-*-*-*-*-*-*");
- QApplication::setFont(fn);
-#endif
-
QDeclarativeView *canvas = createView(SRCDIR "/data/horizontalAlignment.qml");
canvas->show();
@@ -409,17 +419,16 @@ void tst_qdeclarativetextinput::horizontalAlignment()
ob->setProperty("horizontalAlignment",hAlign);
QImage actual(canvas->width(), canvas->height(), QImage::Format_RGB32);
actual.fill(qRgb(255,255,255));
- QPainter p(&actual);
- canvas->render(&p);
+ {
+ QPainter p(&actual);
+ canvas->render(&p);
+ }
+
+ expectfile = createExpectedFileIfNotFound(expectfile, actual);
QImage expect(expectfile);
-#ifdef Q_WS_X11
- // Font-specific, but not likely platform-specific, so only test on one platform
- if (QApplicationPrivate::graphics_system_name == "raster" || QApplicationPrivate::graphics_system_name == "") {
- QCOMPARE(actual,expect);
- }
-#endif
+ QCOMPARE(actual,expect);
}
void tst_qdeclarativetextinput::positionAt()