Fix regression in metric calculation of text with mnemonics
Even when we do not intend to display the text, we still need to go through the processing of mnemonics to remove them from the text. Instead of capping the max underlines to 0, the TextDontPrint option now just saves adding the underline formats. Task-number: QTBUG-41593 Change-Id: I67790650dbed0092de2c63e5d5a9349dc02d5846 Reviewed-by: Friedemann Kleint <Friedemann.Kleint@digia.com> Reviewed-by: Robert Loehning <robert.loehning@digia.com> Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@digia.com>
This commit is contained in:
parent
f5f300ba82
commit
0175ad4d3f
@ -7442,10 +7442,6 @@ 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) {
|
||||
@ -7460,7 +7456,7 @@ start_lengthVariant:
|
||||
--l;
|
||||
if (!l)
|
||||
break;
|
||||
if (*cin != QLatin1Char('&') && !hidemnmemonic) {
|
||||
if (*cin != QLatin1Char('&') && !hidemnmemonic && !(tf & Qt::TextDontPrint)) {
|
||||
QTextLayout::FormatRange range;
|
||||
range.start = cout - cout0;
|
||||
range.length = 1;
|
||||
|
@ -64,6 +64,7 @@ private slots:
|
||||
void elidedMultiLengthF();
|
||||
void inFontUcs4();
|
||||
void lineWidth();
|
||||
void mnemonicTextWidth();
|
||||
};
|
||||
|
||||
tst_QFontMetrics::tst_QFontMetrics()
|
||||
@ -331,5 +332,16 @@ void tst_QFontMetrics::lineWidth()
|
||||
QVERIFY(smallFontMetrics.lineWidth() < bigFontMetrics.lineWidth());
|
||||
}
|
||||
|
||||
void tst_QFontMetrics::mnemonicTextWidth()
|
||||
{
|
||||
// QTBUG-41593
|
||||
QFont f;
|
||||
QFontMetrics fm(f);
|
||||
const QString f1 = "File";
|
||||
const QString f2 = "&File";
|
||||
|
||||
QCOMPARE(fm.size(Qt::TextShowMnemonic, f1), fm.size(Qt::TextShowMnemonic, f2));
|
||||
QCOMPARE(fm.size(Qt::TextHideMnemonic, f1), fm.size(Qt::TextHideMnemonic, f2));
|
||||
}
|
||||
QTEST_MAIN(tst_QFontMetrics)
|
||||
#include "tst_qfontmetrics.moc"
|
||||
|
Loading…
x
Reference in New Issue
Block a user