diff options
author | Allan Sandfeld Jensen <allan.jensen@digia.com> | 2014-09-16 14:18:36 +0200 |
---|---|---|
committer | Allan Sandfeld Jensen <allan.jensen@digia.com> | 2014-09-18 00:13:28 +0200 |
commit | 9b556afc5a2507077dff54c18a2b19c7df3c4575 (patch) | |
tree | c64534b406f6856ae5a3061a676af9285b248be0 /src/gui/painting/qpainter.cpp | |
parent | 82dbea55a746b5ba58316186b201dc6505782d17 (diff) |
Fix menu mnemonic inside ligatures
The code to draw underlines on specific characters in widget menu could
not handle ligatures. Instead of using special code to handle this case
this patch changes the mnemonic underlines to use normal format-ranges
making the text engine deal with splitting ligatures as necessary.
Task-number: QTBUG-20960
Change-Id: I6159110eae7aa8c819af16ba4a393d758871e2e0
Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@digia.com>
Diffstat (limited to 'src/gui/painting/qpainter.cpp')
-rw-r--r-- | src/gui/painting/qpainter.cpp | 25 |
1 files changed, 13 insertions, 12 deletions
diff --git a/src/gui/painting/qpainter.cpp b/src/gui/painting/qpainter.cpp index 5d046caaa4..159acf40c6 100644 --- a/src/gui/painting/qpainter.cpp +++ b/src/gui/painting/qpainter.cpp @@ -7418,8 +7418,6 @@ void qt_format_text(const QFont &fnt, const QRectF &_r, tf |= Qt::TextDontPrint; uint maxUnderlines = 0; - int numUnderlines = 0; - QVarLengthArray<int, 32> underlinePositions(1); QFontMetricsF fm(fnt); QString text = str; @@ -7450,10 +7448,13 @@ start_lengthVariant: } } + // no need to do extra work for underlines if we don't paint + if (tf & Qt::TextDontPrint) + maxUnderlines = 0; + + QList<QTextLayout::FormatRange> underlineFormats; int length = offset - old_offset; if ((hidemnmemonic || showmnemonic) && maxUnderlines > 0) { - underlinePositions.resize(maxUnderlines + 1); - QChar *cout = text.data() + old_offset; QChar *cout0 = cout; QChar *cin = cout; @@ -7465,8 +7466,13 @@ start_lengthVariant: --l; if (!l) break; - if (*cin != QLatin1Char('&') && !hidemnmemonic) - underlinePositions[numUnderlines++] = cout - cout0; + if (*cin != QLatin1Char('&') && !hidemnmemonic) { + QTextLayout::FormatRange range; + range.start = cout - cout0; + range.length = 1; + range.format.setFontUnderline(true); + underlineFormats.append(range); + } } else if (hidemnmemonic && *cin == QLatin1Char('(') && l >= 4 && cin[1] == QLatin1Char('&') && cin[2] != QLatin1Char('&') && cin[3] == QLatin1Char(')')) { @@ -7486,11 +7492,6 @@ start_lengthVariant: } } - // no need to do extra work for underlines if we don't paint - if (tf & Qt::TextDontPrint) - numUnderlines = 0; - - underlinePositions[numUnderlines] = -1; qreal height = 0; qreal width = 0; @@ -7523,7 +7524,7 @@ start_lengthVariant: engine.forceJustification = true; QTextLayout textLayout(&engine); textLayout.setCacheEnabled(true); - textLayout.engine()->underlinePositions = underlinePositions.data(); + textLayout.setAdditionalFormats(underlineFormats); if (finalText.isEmpty()) { height = fm.height(); |