From c225767b9b50336432e39cd589637df4fe721d62 Mon Sep 17 00:00:00 2001 From: Olivier Goffart Date: Mon, 11 May 2009 12:45:51 +0200 Subject: Add the Qt::TextLongestVariant flag so QFontMetrics::size returns the size of the biggest string In case the strings contains multiple strings separated by \x9c Reviewed-by: Oswald Buddenhagen Task-number: QT-10 --- doc/src/classes/qnamespace.qdoc | 1 + src/corelib/global/qnamespace.h | 3 ++- src/gui/painting/qpainter.cpp | 3 ++- src/gui/text/qfontmetrics.cpp | 2 +- 4 files changed, 6 insertions(+), 3 deletions(-) diff --git a/doc/src/classes/qnamespace.qdoc b/doc/src/classes/qnamespace.qdoc index 18ecd7b..5872d04 100644 --- a/doc/src/classes/qnamespace.qdoc +++ b/doc/src/classes/qnamespace.qdoc @@ -490,6 +490,7 @@ \omitvalue WordBreak \omitvalue TextForceLeftToRight \omitvalue TextForceRightToLeft + \omitvalue TextLongestVariant Always use the longest variant when computing the size of a multi-variant string You can use as many modifier flags as you want, except that Qt::TextSingleLine and Qt::TextWordWrap cannot be combined. diff --git a/src/corelib/global/qnamespace.h b/src/corelib/global/qnamespace.h index f172d77..4024fce 100644 --- a/src/corelib/global/qnamespace.h +++ b/src/corelib/global/qnamespace.h @@ -233,7 +233,8 @@ public: TextHideMnemonic = 0x8000, TextJustificationForced = 0x10000, TextForceLeftToRight = 0x20000, - TextForceRightToLeft = 0x40000 + TextForceRightToLeft = 0x40000, + TextLongestVariant = 0x80000 #if defined(QT3_SUPPORT) && !defined(Q_MOC_RUN) ,SingleLine = TextSingleLine, diff --git a/src/gui/painting/qpainter.cpp b/src/gui/painting/qpainter.cpp index c3fc14b..4d9b43a 100644 --- a/src/gui/painting/qpainter.cpp +++ b/src/gui/painting/qpainter.cpp @@ -7642,7 +7642,8 @@ start_lenghtVariant: } } QRectF bounds = QRectF(r.x() + xoff, r.y() + yoff, width, height); - if (hasMoreLenghtVariants && !r.contains(bounds)) { + + if (hasMoreLenghtVariants && !(tf & Qt::TextLongestVariant) && !r.contains(bounds)) { offset = end - text.data() + 1; goto start_lenghtVariant; } diff --git a/src/gui/text/qfontmetrics.cpp b/src/gui/text/qfontmetrics.cpp index 012c0f6..47d3864 100644 --- a/src/gui/text/qfontmetrics.cpp +++ b/src/gui/text/qfontmetrics.cpp @@ -798,7 +798,7 @@ QRect QFontMetrics::boundingRect(const QRect &rect, int flags, const QString &te */ QSize QFontMetrics::size(int flags, const QString &text, int tabStops, int *tabArray) const { - return boundingRect(QRect(0,0,0,0), flags, text, tabStops, tabArray).size(); + return boundingRect(QRect(0,0,0,0), flags | Qt::TextLongestVariant, text, tabStops, tabArray).size(); } /*! -- cgit v0.12