summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIlija Ristevski <ilija.ristevski@seavus.com>2015-10-28 18:24:55 +0100
committerKonstantin Ritt <ritt.ks@gmail.com>2015-11-30 02:24:32 +0000
commit6302fb07e763a3a59458dab38445a22ba7833d7e (patch)
tree177797a687f37f0173aba4a5612f9385e02b7386
parentaab21bce86f3cf5c520c99bdd73fcca5bb453130 (diff)
QTextOdfWriter: Added support for hyperlinks.
Hyperlink added in QTextDocument becomes "<span>" tag after exporting the document to ODF with QTextDocumentWriter. Fixed by adding "<a>" tag around it with attribute "href" pointing to hyperlink location. Task-number: QTBUG-48853 Change-Id: I2bd689a88c9d0a5b14369777718b9cb36e4cfa19 Reviewed-by: Konstantin Ritt <ritt.ks@gmail.com> Reviewed-by: Lars Knoll <lars.knoll@theqtcompany.com>
-rw-r--r--src/gui/text/qtextodfwriter.cpp9
1 files changed, 9 insertions, 0 deletions
diff --git a/src/gui/text/qtextodfwriter.cpp b/src/gui/text/qtextodfwriter.cpp
index 429e910f18..1fd20cfbef 100644
--- a/src/gui/text/qtextodfwriter.cpp
+++ b/src/gui/text/qtextodfwriter.cpp
@@ -279,6 +279,12 @@ void QTextOdfWriter::writeBlock(QXmlStreamWriter &writer, const QTextBlock &bloc
writer.writeAttribute(textNS, QString::fromLatin1("style-name"), QString::fromLatin1("p%1")
.arg(block.blockFormatIndex()));
for (QTextBlock::Iterator frag = block.begin(); !frag.atEnd(); ++frag) {
+ bool isHyperlink = frag.fragment().charFormat().hasProperty(QTextFormat::AnchorHref);
+ if (isHyperlink) {
+ QString value = frag.fragment().charFormat().property(QTextFormat::AnchorHref).toString();
+ writer.writeStartElement(textNS, QString::fromLatin1("a"));
+ writer.writeAttribute(xlinkNS, QString::fromLatin1("href"), value);
+ }
writer.writeCharacters(QString()); // Trick to make sure that the span gets no linefeed in front of it.
writer.writeStartElement(textNS, QString::fromLatin1("span"));
@@ -335,6 +341,9 @@ void QTextOdfWriter::writeBlock(QXmlStreamWriter &writer, const QTextBlock &bloc
writer.writeCharacters(fragmentText.mid(exportedIndex));
writer.writeEndElement(); // span
+ writer.writeCharacters(QString()); // Trick to make sure that the span gets no linefeed behind it.
+ if (isHyperlink)
+ writer.writeEndElement(); // a
}
writer.writeCharacters(QString()); // Trick to make sure that the span gets no linefeed behind it.
writer.writeEndElement(); // p