22 #include "ktexthtmlbuilder.h"
24 #include <QTextDocument>
27 class KTextHTMLBuilderPrivate
34 QList<QTextListFormat::Style> currentListItemStyles;
48 KTextHTMLBuilder::~KTextHTMLBuilder()
56 d->m_text.append(
"<strong>");
62 d->m_text.append(
"</strong>");
68 d->m_text.append(
"<em>");
74 d->m_text.append(
"</em>");
80 d->m_text.append(
"<u>");
86 d->m_text.append(
"</u>");
92 d->m_text.append(
"<s>");
98 d->m_text.append(
"</s>");
104 d->m_text.append(QString(
"<span style=\"color:%1;\">").arg(brush.color().name()));
110 d->m_text.append(
"</span>");
116 d->m_text.append(QString(
"<span style=\"background-color:%1;\">").arg(brush.color().name()));
122 d->m_text.append(
"</span>");
128 if (!href.isEmpty()) {
129 if (!name.isEmpty()) {
130 d->m_text.append(QString(
"<a href=\"%1\" name=\"%2\">").arg(href).arg(name));
132 d->m_text.append(QString(
"<a href=\"%1\">").arg(href));
135 if (!name.isEmpty()) {
136 d->m_text.append(QString(
"<a name=\"%1\">").arg(name));
144 d->m_text.append(
"</a>");
150 d->m_text.append(QString(
"<span style=\"font-family:%1;\">").arg(family));
156 d->m_text.append(
"</span>");
162 d->m_text.append(QString(
"<span style=\"font-size:%1pt;\">").arg(QString::number(size)));
168 d->m_text.append(
"</span>");
178 if (topMargin != 0) {
179 styleString.append(QString(
"margin-top:%1;").arg(topMargin));
181 if (bottomMargin != 0) {
182 styleString.append(QString(
"margin-bottom:%1;").arg(bottomMargin));
184 if (leftMargin != 0) {
185 styleString.append(QString(
"margin-left:%1;").arg(leftMargin));
187 if (rightMargin != 0) {
188 styleString.append(QString(
"margin-right:%1;").arg(rightMargin));
193 if (al & Qt::AlignRight) {
194 d->m_text.append(
"<p align=\"right\" ");
195 }
else if (al & Qt::AlignHCenter) {
196 d->m_text.append(
"<p align=\"center\" ");
197 }
else if (al & Qt::AlignJustify) {
198 d->m_text.append(
"<p align=\"justify\" ");
199 }
else if (al & Qt::AlignLeft) {
200 d->m_text.append(
"<p");
202 d->m_text.append(
"<p");
205 if (!styleString.isEmpty()) {
206 d->m_text.append(
" \"" + styleString +
"\"");
208 d->m_text.append(
">");
217 d->m_text.append(
"<h1>");
220 d->m_text.append(
"<h2>");
223 d->m_text.append(
"<h3>");
226 d->m_text.append(
"<h4>");
229 d->m_text.append(
"<h5>");
232 d->m_text.append(
"<h6>");
244 d->m_text.append(
"</h1>");
247 d->m_text.append(
"</h2>");
250 d->m_text.append(
"</h3>");
253 d->m_text.append(
"</h4>");
256 d->m_text.append(
"</h5>");
259 d->m_text.append(
"</h6>");
269 d->m_text.append(
"</p>\n");
275 d->m_text.append(
"<br />\n");
282 d->m_text.append(QString(
"<hr width=\"%1\" />\n").arg(width));
284 d->m_text.append(
"<hr />\n");
290 d->m_text.append(QString(
"<img src=\"%1\" ").arg(src));
291 if (width != 0) d->m_text.append(QString(
"width=\"%2\" ").arg(width));
292 if (height != 0) d->m_text.append(QString(
"height=\"%2\" ").arg(height));
293 d->m_text.append(
"/>");
299 d->currentListItemStyles.append(type);
301 case QTextListFormat::ListDisc:
302 d->m_text.append(
"<ul type=\"disc\">\n");
304 case QTextListFormat::ListCircle:
305 d->m_text.append(
"\n<ul type=\"circle\">\n");
307 case QTextListFormat::ListSquare:
308 d->m_text.append(
"\n<ul type=\"square\">\n");
310 case QTextListFormat::ListDecimal:
311 d->m_text.append(
"\n<ol type=\"1\">\n");
313 case QTextListFormat::ListLowerAlpha:
314 d->m_text.append(
"\n<ol type=\"a\">\n");
316 case QTextListFormat::ListUpperAlpha:
317 d->m_text.append(
"\n<ol type=\"A\">\n");
326 switch (d->currentListItemStyles.last()) {
327 case QTextListFormat::ListDisc:
328 case QTextListFormat::ListCircle:
329 case QTextListFormat::ListSquare:
330 d->m_text.append(
"</ul>\n");
332 case QTextListFormat::ListDecimal:
333 case QTextListFormat::ListLowerAlpha:
334 case QTextListFormat::ListUpperAlpha:
335 d->m_text.append(
"</ol>\n");
340 d->currentListItemStyles.removeLast();
345 d->m_text.append(
"<li>");
351 d->m_text.append(
"</li>\n");
357 d->m_text.append(
"<sup>");
363 d->m_text.append(
"</sup>");
369 d->m_text.append(
"<sub>");
375 d->m_text.append(
"</sub>");
382 d->m_text.append(QString(
"<table cellpadding=\"%1\" cellspacing=\"%2\" width=\"%3\" border=\"1\">")
391 d->m_text.append(
"<tr>");
397 d->m_text.append(QString(
"<th width=\"%1\" colspan=\"%2\" rowspan=\"%3\">").arg(width).arg(colspan).arg(rowspan));
403 d->m_text.append(QString(
"<td width=\"%1\" colspan=\"%2\" rowspan=\"%3\">").arg(width).arg(colspan).arg(rowspan));
409 d->m_text.append(
"</table>");
415 d->m_text.append(
"</tr>");
421 d->m_text.append(
"</th>");
427 d->m_text.append(
"</td>");
434 d->m_text.append(Qt::escape(text));