Provide QCss with the correct font for <pre> blocks

Labels would use a statically defined font for <pre> blocks.
Use the one defined by the QPlatformTheme instead, through
QFontDatabase::systemFont(FixedFont)

Task-number: QTBUG-50564
Change-Id: I5491bd0defce651bdf809bcbc6a529a900f4959b
Reviewed-by: Milian Wolff <milian.wolff@kdab.com>
bb10
Aleix Pol 2016-01-20 17:45:00 +01:00 committed by Aleix Pol Gonzalez
parent 22c262d2d7
commit 8b4ac65e29
2 changed files with 27 additions and 7 deletions

View File

@ -1926,13 +1926,7 @@ QVector<QCss::Declaration> standardDeclarationForNode(const QTextHtmlParserNode
decl.d->propertyId = QCss::FontFamily;
QVector<QCss::Value> values;
val.type = QCss::Value::String;
val.variant = QLatin1String("Courier New");
values << val;
val.type = QCss::Value::TermOperatorComma;
val.variant = QVariant();
values << val;
val.type = QCss::Value::String;
val.variant = QLatin1String("courier");
val.variant = QFontDatabase::systemFont(QFontDatabase::FixedFont).family();
values << val;
decl.d->values = values;
decl.d->inheritable = true;

View File

@ -95,6 +95,8 @@ private slots:
void task240325();
void preFont();
void stylesheetFont_data();
void stylesheetFont();
@ -675,6 +677,30 @@ void tst_QTextDocument::stylesheetFont()
QCOMPARE(actualFont.pixelSize(), font.pixelSize());
}
void tst_QTextDocument::preFont()
{
const QFont font = QFontDatabase::systemFont(QFontDatabase::FixedFont);
const QString html = QString::fromLatin1( "<html>"
"<body>"
"<pre>"
"Foobar"
"</pre>"
"</body>"
"</html>");
doc->setHtml(html);
QCOMPARE(doc->blockCount(), 1);
// First and only block
QTextBlock block = doc->firstBlock();
QString text = block.text();
QCOMPARE(text, QString::fromLatin1("Foobar"));
QFont actualFont = block.charFormat().font();
QCOMPARE(actualFont.family(), font.family());
}
void tst_QTextDocument::noundo_moreIsModified()
{
doc->setUndoRedoEnabled(false);