Commit 8977ceb6 authored by Laurent Montel's avatar Laurent Montel 😁
Browse files

Add margin

parent 42757745
......@@ -45,7 +45,7 @@ void TextHTMLBuilderTest::testHtmlWithTab()
auto result = hb->getResult();
auto regex = QRegularExpression(
QStringLiteral("^<p>&nbsp;<p>&nbsp;&nbsp;&nbsp; foo</p>\\n$"));
QStringLiteral("^<p>&nbsp;<p style=\"margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;\">&nbsp;&nbsp;&nbsp; foo</p>\\n$"));
const bool regexpHasResult = regex.match(result).hasMatch();
if (!regexpHasResult) {
......@@ -63,9 +63,9 @@ void TextHTMLBuilderTest::testHtmlText_data()
QTest::addColumn<QString>("text");
QTest::addColumn<QString>("regexpText");
QTest::addColumn<bool>("htmlFormat");
QTest::newRow("link") << QStringLiteral("A <a href=\"http://www.kde.org\">link</a> to KDE.") << QStringLiteral("^<p>A <a href=\"http://www.kde.org\">link</a>&nbsp;to KDE.</p>\\n$") << true;
QTest::newRow("text with espace") << QStringLiteral(" foo") << QStringLiteral("^<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; foo</p>\\n$") << false;
QTest::newRow("text with espace at begin") << QStringLiteral(" foo") << QStringLiteral("^<p>&nbsp;foo</p>\\n$") << false;
QTest::newRow("link") << QStringLiteral("A <a href=\"http://www.kde.org\">link</a> to KDE.") << QStringLiteral("^<p style=\"margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;\">A <a href=\"http://www.kde.org\">link</a>&nbsp;to KDE.</p>\\n$") << true;
QTest::newRow("text with espace") << QStringLiteral(" foo") << QStringLiteral("^<p style=\"margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; foo</p>\\n$") << false;
QTest::newRow("text with espace at begin") << QStringLiteral(" foo") << QStringLiteral("^<p style=\"margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;\">&nbsp;foo</p>\\n$") << false;
}
void TextHTMLBuilderTest::testHtmlText()
......
......@@ -183,18 +183,10 @@ void TextHTMLBuilder::beginParagraph(Qt::Alignment al, qreal topMargin,
// if (currentListItemStyles.size() != 0)
// {
QString styleString;
if (topMargin != 0) {
styleString.append(QStringLiteral("margin-top:%1;").arg(topMargin));
}
if (bottomMargin != 0) {
styleString.append(QStringLiteral("margin-bottom:%1;").arg(bottomMargin));
}
if (leftMargin != 0) {
styleString.append(QStringLiteral("margin-left:%1;").arg(leftMargin));
}
if (rightMargin != 0) {
styleString.append(QStringLiteral("margin-right:%1;").arg(rightMargin));
}
styleString.append(QStringLiteral("margin-top:%1;").arg(topMargin));
styleString.append(QStringLiteral("margin-bottom:%1;").arg(bottomMargin));
styleString.append(QStringLiteral("margin-left:%1;").arg(leftMargin));
styleString.append(QStringLiteral("margin-right:%1;").arg(rightMargin));
// Using == doesn't work here.
// Using bitwise comparison because an alignment can contain a vertical and
......@@ -213,7 +205,7 @@ void TextHTMLBuilder::beginParagraph(Qt::Alignment al, qreal topMargin,
}
if (!styleString.isEmpty()) {
d->m_text.append(QStringLiteral(" \"") + styleString + QLatin1Char('"'));
d->m_text.append(QStringLiteral(" style=\"") + styleString + QLatin1Char('"'));
}
d->m_text.append(QLatin1Char('>'));
// }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment