diff --git a/src/gui/text/qtextdocument.cpp b/src/gui/text/qtextdocument.cpp index 094403d..8a07820 100644 --- a/src/gui/text/qtextdocument.cpp +++ b/src/gui/text/qtextdocument.cpp @@ -2422,44 +2422,84 @@ void QTextHtmlExporter::emitFragment(const QTextFragment &fragment) QString txt = fragment.text(); const bool isObject = txt.contains(QChar::ObjectReplacementCharacter); - const bool isImage = isObject && format.isImageFormat(); + //const bool isImage = isObject && format.isImageFormat(); QLatin1String styleTag(""); else html.chop(qstrlen(styleTag.latin1())); if (isObject) { - for (int i = 0; isImage && i < txt.length(); ++i) { - QTextImageFormat imgFmt = format.toImageFormat(); + for (int i = 0; i < txt.length(); ++i) { + if (format.isImageFormat()) { + QTextImageFormat imgFmt = format.toImageFormat(); - html += QLatin1String("(doc->objectForFormat(imgFmt))) - emitFloatStyle(imageFrame->frameFormat().position()); + if (QTextFrame *imageFrame = qobject_cast(doc->objectForFormat(imgFmt))) + emitFloatStyle(imageFrame->frameFormat().position()); - html += QLatin1String(" />"); + html += QLatin1String(" />"); + } + else if (txt.at(i) == QChar::ObjectReplacementCharacter) { + + QMap pm = format.properties(); + + html += QLatin1String("::iterator it = pm.begin(); it!= pm.end(); ++it) + if (it.key() >= QTextFormat::UserProperty || it.key() == QTextFormat::ObjectType) { + emitAttribute("type", QString::number(it.key())); + emitAttribute("value", it.value().toString()); + } + + html += QLatin1String(" />"); + } + else + html += Qt::escape(txt.at(i)); } + } else { Q_ASSERT(!txt.contains(QChar::ObjectReplacementCharacter)); diff --git a/src/gui/text/qtextdocumentfragment.cpp b/src/gui/text/qtextdocumentfragment.cpp index d415b61..e0196ad 100644 --- a/src/gui/text/qtextdocumentfragment.cpp +++ b/src/gui/text/qtextdocumentfragment.cpp @@ -750,6 +750,24 @@ QTextHtmlImporter::ProcessNodeResult QTextHtmlImporter::processSpecialNodes() return ContinueWithNextNode; } + case Html_qproperty:{ + QTextCharFormat char_format = currentNode->charFormat; + if (char_format.hasProperty(QTextFormat::ObjectType)) + { + cursor.insertText(QString(QChar::ObjectReplacementCharacter), char_format); + compressNextWhitespace = CollapseWhiteSpace; + hasBlock = false; + return ContinueWithNextNode; + } + else { + cursor.movePosition(QTextCursor::Left, QTextCursor::KeepAnchor); + cursor.mergeCharFormat(currentNode->charFormat); + cursor.movePosition(QTextCursor::Right); + return ContinueWithNextNode; + } + } + + default: break; } return ContinueWithCurrentNode; diff --git a/src/gui/text/qtexthtmlparser.cpp b/src/gui/text/qtexthtmlparser.cpp index 75fdc16..6f68432 100644 --- a/src/gui/text/qtexthtmlparser.cpp +++ b/src/gui/text/qtexthtmlparser.cpp @@ -418,6 +418,7 @@ static const QTextHtmlElement elements[Html_NumElements]= { { "ol", Html_ol, QTextHtmlElement::DisplayBlock }, { "p", Html_p, QTextHtmlElement::DisplayBlock }, { "pre", Html_pre, QTextHtmlElement::DisplayBlock }, + { "qproperty", Html_qproperty, QTextHtmlElement::DisplayInline }, { "qt", Html_body /*deliberate mapping*/, QTextHtmlElement::DisplayBlock }, { "s", Html_s, QTextHtmlElement::DisplayInline }, { "samp", Html_samp, QTextHtmlElement::DisplayInline }, @@ -1504,6 +1505,8 @@ void QTextHtmlParser::applyAttributes(const QStringList &attributes) bool seenQt3Richtext = false; QString linkHref; QString linkType; + int proptype; + QString propvalue; if (attributes.count() % 2 == 1) return; @@ -1646,6 +1649,31 @@ void QTextHtmlParser::applyAttributes(const QStringList &attributes) else if (key == QLatin1String("type")) linkType = value; break; + case Html_qproperty: + if (key == QLatin1String("type")) + proptype = value.toInt(); + + if (key == QLatin1String("value")) + propvalue = value; + + if (key == QLatin1String("valign")) { + value = value.toLower(); + if (value == QLatin1String("middle")) + node->charFormat.setVerticalAlignment(QTextCharFormat::AlignMiddle); + else if (value == QLatin1String("descent")) + node->charFormat.setVerticalAlignment(QTextCharFormat::AlignDescent); + } + + if (!propvalue.isEmpty()) + if (proptype >= QTextFormat::UserProperty) + { + node->charFormat.setProperty(proptype, propvalue); + } + else if (proptype == QTextFormat::ObjectType) + { + node->charFormat.setProperty(proptype, propvalue.toInt()); + } + break; default: break; } diff --git a/src/gui/text/qtexthtmlparser_p.h b/src/gui/text/qtexthtmlparser_p.h index f77a04d..63f42b3 100644 --- a/src/gui/text/qtexthtmlparser_p.h +++ b/src/gui/text/qtexthtmlparser_p.h @@ -133,6 +133,9 @@ enum QTextHTMLElements { Html_tfoot, Html_caption, + // inline object + Html_qproperty, + // misc... Html_html, Html_style,