summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorWarwick Allison <warwick.allison@nokia.com>2010-07-07 04:09:49 (GMT)
committerWarwick Allison <warwick.allison@nokia.com>2010-07-07 04:09:49 (GMT)
commit628159323c60c434a202b036ecbaf5e433c703e8 (patch)
tree008ade0cdb2bf5d44e6995c9f1240f336a13ce63 /src
parentbe19c343000ffc7099474663c66a13226fa5253c (diff)
downloadQt-628159323c60c434a202b036ecbaf5e433c703e8.zip
Qt-628159323c60c434a202b036ecbaf5e433c703e8.tar.gz
Qt-628159323c60c434a202b036ecbaf5e433c703e8.tar.bz2
Make Text, TextInput, and TextEdit all have the same size for the same text.
This may mean that the cursor is to the right of the width, so components should cater for that with a margin if they are boxed / clipped. TextInput used to try to account for right bearing (and left bearing incorrectly since it added it on the right). This is removed. Potentially this means that for some fonts the text repaints incorrectly on the left or right, but if that is the case Text and TextEdit already had such a problem (undetected), and all will need fixing. Task-number: QTBUG-11983
Diffstat (limited to 'src')
-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
4 files changed, 29 insertions, 21 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();