diff options
author | Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io> | 2017-08-02 11:38:10 +0200 |
---|---|---|
committer | Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io> | 2017-11-14 16:28:45 +0000 |
commit | ee2ad9df701b27790e2ab72e99111d255fde42ed (patch) | |
tree | 735593d1664b55b1fc2291aea740b364cc982a95 /src/gui/text/qfontmetrics.h | |
parent | 0f0726d36e36815fb2bbd1702fe35ae33d27b0bf (diff) |
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 <lars.knoll@qt.io>
Diffstat (limited to 'src/gui/text/qfontmetrics.h')
-rw-r--r-- | src/gui/text/qfontmetrics.h | 15 |
1 files changed, 13 insertions, 2 deletions
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; |