# HG changeset patch # User Andre Heinecke # Date 1460372808 -7200 # Node ID 5acd601356ba7d9ce4c05c6310eb01d64377310f # Parent e5c5ebfa4205afb7a87353dfaaf8ce2362a2437d Make HTML work for QTextDocument diff -r e5c5ebfa4205 -r 5acd601356ba src/constants.h --- a/src/constants.h Mon Apr 11 11:24:17 2016 +0200 +++ b/src/constants.h Mon Apr 11 13:06:48 2016 +0200 @@ -47,7 +47,7 @@ #define COLUMN_CNT 3 /** * @brief The width of the columns in characters. */ -#define COLUMN_WIDTHS { 40, 20, 26 } +#define COLUMN_WIDTHS { 40, 18, 26 } /** * @brief Regular expression to define a question. @@ -81,4 +81,6 @@ #define HTML_WIDTH 960 +#define BAR_COLOR "#ff9933" + #endif // CONSTANTS_H diff -r e5c5ebfa4205 -r 5acd601356ba src/converter.cpp --- a/src/converter.cpp Mon Apr 11 11:24:17 2016 +0200 +++ b/src/converter.cpp Mon Apr 11 13:06:48 2016 +0200 @@ -12,6 +12,8 @@ #include #include #include +#include +#include #include "xlsxdocument.h" #include "xlsxconditionalformatting.h" @@ -61,23 +63,17 @@ mAnswerTextFmt.setHorizontalAlignment(Format::AlignLeft); mTitleStyle = QStringLiteral("%1"); - const QString questionBorders = QStringLiteral("style='border-bottom: 1pt solid black;" - "border-top: 1pt solid black;font-weight:" - "bold;font-size:11;'"); - mQuestionStyle = QStringLiteral("%1") + - QStringLiteral("").arg(questionBorders) + - QStringLiteral("").arg(questionBorders); - mAnswerChoiceStyle= QStringLiteral("Answer"); - mChoiceTextStyle= QStringLiteral("%1"); + "font-weight: bold; text-decoration:underline; font-size: 18pt;'>" + "%1"); + mQuestionStyle = QStringLiteral("
%1
"); + mAnswerChoiceStyle= QStringLiteral("Answer"); + mChoiceTextStyle= QStringLiteral("%1"); mChoiceVotesStyle = QStringLiteral("%1"); - mAnswerTextStyle = QStringLiteral("Answer"); - mFreeTextStyle = QStringLiteral("%1"); + "font-size:10pt;'%1"); + mAnswerTextStyle = QStringLiteral("Answer
"); + mFreeTextStyle = QStringLiteral("%1
"); mEmptyRow = QStringLiteral("").arg(CHOICE_ROW_HEIGHT); } @@ -115,10 +111,29 @@ convertToXSLX(instream, outfile); } -static void makeBar(QTextStream &html, double percent, QTextDocument &doc, bool forPDF) +static void makeBar(QTextStream &html, double percent, int width, QTextDocument &doc, bool forPDF) { - html << QStringLiteral("").arg(percent); + static int barCnt; + if (!forPDF) { + html << QStringLiteral("").arg(percent); + return; + } + QImage image(QSize(width, 25), QImage::Format_RGB32); + QPainter painter(&image); + QRect rect = image.rect(); + qDebug() << "Image of " << width; + rect.setRight(rect.right() / (100 / percent)); + painter.fillRect(rect, QColor(BAR_COLOR)); + qDebug() << "Filled " << rect << " with color"; + rect.setLeft(rect.right()); + rect.setRight(width); + painter.fillRect(rect, Qt::white); + qDebug() << "Filled " << rect << " with white"; + doc.addResource(QTextDocument::ImageResource, QUrl(QStringLiteral("internal://bar%1.png").arg(barCnt)), + QVariant(image)); + html << QStringLiteral("").arg(barCnt++); + image.save(QStringLiteral("/tmp/foo.png")); return; } @@ -151,13 +166,13 @@ xlsx.setColumnWidth(26, sum + 1); xlsx.setColumnHidden(26, true); + int row = 1; html << "" ""; + html << "
"; + html << ""; + html << ""; - int row = 1; - html << "
"; - html << ""; - html << ""; const QString title = mTitle.isEmpty() ? DEFAULT_TITLE : mTitle; // Set the title of the Questionaire xlsx.write(row++, 1, title, mTitleFmt); @@ -215,7 +230,7 @@ if (!ok) { mErrors << "Unparsable number in string: " + choiceMatch.captured(); } - makeBar(html, percent, doc, mFmt == Format_PDF); + makeBar(html, percent, col2Width, doc, mFmt == Format_PDF); xlsx.write(row, 2, percent); const QString numVotesString = QString("%1% | %2 Number of votes"). arg(choiceMatch.captured(3)).arg(choiceMatch.captured(2)); diff -r e5c5ebfa4205 -r 5acd601356ba src/l10n/main_de_DE.ts --- a/src/l10n/main_de_DE.ts Mon Apr 11 11:24:17 2016 +0200 +++ b/src/l10n/main_de_DE.ts Mon Apr 11 13:06:48 2016 +0200 @@ -4,32 +4,32 @@ Converter - + Failed to open standard input and no input file provided. Öffnen des Eingabekanals Fehlgeschlagen und keine Eingabedatei übergeben. - + Failed to open %1 for reading. Die Datei "%1" konnte nicht gelesen werden. - + Failed to open standard output and no output file provided. Öffnen des Ausgabekanals Fehlgeschlagen und keine Ausgabedatei übergeben. - + Failed to open %1 for writing. Die Datei "%1" konnte nicht geöffnet werden. - + Failed to parse input document. Fehler bei der verarbeitung des Eingabedokuments. - + Saving the XLSX document failed. Das erstellen des XLSX Dokuments ist fehlgeschlagen.