summaryrefslogtreecommitdiffstats
path: root/src/declarative/graphicsitems/qdeclarativetextinput.cpp
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/declarative/graphicsitems/qdeclarativetextinput.cpp
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/declarative/graphicsitems/qdeclarativetextinput.cpp')
-rw-r--r--src/declarative/graphicsitems/qdeclarativetextinput.cpp31
1 files changed, 16 insertions, 15 deletions
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){