From ee2ad9df701b27790e2ab72e99111d255fde42ed Mon Sep 17 00:00:00 2001 From: Eskil Abrahamsen Blomfeldt Date: Wed, 2 Aug 2017 11:38:10 +0200 Subject: Add QFontMetrics(F)::horizontalAdvance() function A source of constant confusion is the QFontMetrics::width() function, which does not return the bounding width of the text, but the advance width. We deprecate this and add horizontalAdvance() instead, to avoid the confusion in the future. Note that there was an internal width() overload which was only there for the purpose of supporting the Qt::TextBypassShaping flag. This flag has already been replaced by public API, so no such overload is added. Instead, we deprecate the TextBypassShaping flag as well, which makes sense, since a replacement has been made. Also note that there was a consistency problem with QFontMetrics and QFontMetricsF, which are supposed to be interchangeable. The QFontMetrics::width() functions for strings took an optional int length argument, while the floating point version did not. This error is corrected in the advance() functions. [ChangeLog][QtGui][Text] Added QFontMetrics::horizontalAdvance() and QFontMetricsF::horizontalAdvance() to replace the confusingly named width() function. The latter has now been deprecated. Change-Id: I0dfda43aa65c8235be32c62fade82cae05b29c79 Reviewed-by: Lars Knoll --- src/gui/text/qfontmetrics.h | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'src/gui/text/qfontmetrics.h') diff --git a/src/gui/text/qfontmetrics.h b/src/gui/text/qfontmetrics.h index 25e708be29..b6167a1d47 100644 --- a/src/gui/text/qfontmetrics.h +++ b/src/gui/text/qfontmetrics.h @@ -90,10 +90,16 @@ public: int leftBearing(QChar) const; int rightBearing(QChar) const; + +#if QT_DEPRECATED_SINCE(5, 11) int width(const QString &, int len = -1) const; int width(const QString &, int len, int flags) const; - int width(QChar) const; +#endif + + int horizontalAdvance(const QString &, int len = -1) const; + int horizontalAdvance(QChar) const; + #if QT_VERSION < QT_VERSION_CHECK(6,0,0) QT_DEPRECATED int charWidth(const QString &str, int pos) const; #endif @@ -164,9 +170,14 @@ public: qreal leftBearing(QChar) const; qreal rightBearing(QChar) const; - qreal width(const QString &string) const; +#if QT_DEPRECATED_SINCE(5, 11) + qreal width(const QString &string) const; qreal width(QChar) const; +#endif + + qreal horizontalAdvance(const QString &string, int length = -1) const; + qreal horizontalAdvance(QChar) const; QRectF boundingRect(const QString &string) const; QRectF boundingRect(QChar) const; -- cgit v1.2.3