diff options
author | Dirk Hohndel <dirk@hohndel.org> | 2015-07-20 06:14:19 -0700 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2015-07-20 06:14:19 -0700 |
commit | e3a8ff74934c8f5a11ee962650e889464da55522 (patch) | |
tree | 6bd206e1df040c4b504e00f5c71e295b8d17b6bd | |
parent | 7baa18db5fe33f5797e4603a4c2efafc6b474bd0 (diff) | |
parent | 599920c6cfd87a213634097045e29f592390438b (diff) | |
download | subsurface-e3a8ff74934c8f5a11ee962650e889464da55522.tar.gz |
Merge branch 'custom-print' of github.com:neolit123/subsurface
-rw-r--r-- | printer.cpp | 109 | ||||
-rw-r--r-- | printer.h | 15 | ||||
-rw-r--r-- | printing_templates/one_dive.html | 44 | ||||
-rw-r--r-- | printing_templates/two_dives.html | 10 | ||||
-rw-r--r-- | qt-ui/printdialog.cpp | 33 | ||||
-rw-r--r-- | qt-ui/printoptions.h | 25 | ||||
-rw-r--r-- | qt-ui/templateedit.cpp | 140 | ||||
-rw-r--r-- | qt-ui/templateedit.h | 9 | ||||
-rw-r--r-- | qt-ui/templateedit.ui | 261 | ||||
-rw-r--r-- | templatelayout.cpp | 3 | ||||
-rw-r--r-- | templatelayout.h | 21 |
11 files changed, 581 insertions, 89 deletions
diff --git a/printer.cpp b/printer.cpp index f8a90f96d..5b1995501 100644 --- a/printer.cpp +++ b/printer.cpp @@ -6,13 +6,20 @@ #include <QWebElementCollection> #include <QWebElement> -Printer::Printer(QPrinter *printer, print_options *printOptions, template_options *templateOptions) +Printer::Printer(QPaintDevice *paintDevice, print_options *printOptions, template_options *templateOptions, PrintMode printMode) { - this->printer = printer; + this->paintDevice = paintDevice; this->printOptions = printOptions; this->templateOptions = templateOptions; + this->printMode = printMode; dpi = 0; done = 0; + webView = new QWebView(); +} + +Printer::~Printer() +{ + delete webView; } void Printer::putProfileImage(QRect profilePlaceholder, QRect viewPort, QPainter *painter, struct dive *dive, QPointer<ProfileWidget2> profile) @@ -22,28 +29,33 @@ void Printer::putProfileImage(QRect profilePlaceholder, QRect viewPort, QPainter // use the placeHolder and the viewPort position to calculate the relative position of the dive profile. QRect pos(x, y, profilePlaceholder.width(), profilePlaceholder.height()); profile->plotDive(dive, true); - profile->render(painter, pos); -} -void Printer::render() -{ - // apply user settings - int divesPerPage; - if (printOptions->color_selected && printer->colorMode()) { - printer->setColorMode(QPrinter::Color); - } else { - printer->setColorMode(QPrinter::GrayScale); - } + if (!printOptions->color_selected) { + QImage image(pos.width(), pos.height(), QImage::Format_ARGB32); + QPainter imgPainter(&image); + imgPainter.setRenderHint(QPainter::Antialiasing); + imgPainter.setRenderHint(QPainter::SmoothPixmapTransform); + profile->render(&imgPainter, QRect(0, 0, pos.width(), pos.height())); + imgPainter.end(); + + // convert QImage to grayscale before rendering + for (int i = 0; i < image.height(); i++) { + QRgb *pixel = reinterpret_cast<QRgb *>(image.scanLine(i)); + QRgb *end = pixel + image.width(); + for (; pixel != end; pixel++) { + int gray_val = qGray(*pixel); + *pixel = QColor(gray_val, gray_val, gray_val).rgb(); + } + } - // get number of dives per page from data-numberofdives attribute in the body of the selected template - bool ok; - divesPerPage = webView->page()->mainFrame()->findFirstElement("body").attribute("data-numberofdives").toInt(&ok); - if (!ok) { - divesPerPage = 1; // print each dive in a single page if the attribute is missing or malformed - //TODO: show warning + painter->drawImage(pos, image); + } else { + profile->render(painter, pos); } - int Pages = ceil(getTotalWork(printOptions) / (float)divesPerPage); +} +void Printer::render(int Pages = 0) +{ // keep original preferences QPointer<ProfileWidget2> profile = MainWindow::instance()->graphics(); int profileFrameStyle = profile->frameStyle(); @@ -53,14 +65,14 @@ void Printer::render() // apply printing settings to profile profile->setFrameStyle(QFrame::NoFrame); profile->setPrintMode(true, !printOptions->color_selected); - profile->setFontPrintScale(printer->pageLayout().paintRect(QPageLayout::Inch).width() * dpi * 0.001); + profile->setFontPrintScale(pageSize.width() * 0.001); profile->setToolTipVisibile(false); prefs.animation_speed = 0; // render the Qwebview QPainter painter; QRect viewPort(0, 0, pageSize.width(), pageSize.height()); - painter.begin(printer); + painter.begin(paintDevice); painter.setRenderHint(QPainter::Antialiasing); painter.setRenderHint(QPainter::SmoothPixmapTransform); @@ -91,8 +103,8 @@ void Printer::render() // rendering progress is 4/5 of total work emit(progessUpdated((i * 80.0 / Pages) + done)); - if (i < Pages - 1) - printer->newPage(); + if (i < Pages - 1 && printMode == Printer::PRINT) + static_cast<QPrinter*>(paintDevice)->newPage(); } painter.end(); @@ -117,15 +129,52 @@ void Printer::templateProgessUpdated(int value) void Printer::print() { + // we can only print if "PRINT" mode is selected + if (printMode != Printer::PRINT) { + return; + } + + QPrinter *printerPtr; + printerPtr = static_cast<QPrinter*>(paintDevice); + TemplateLayout t(printOptions, templateOptions); - webView = new QWebView(); connect(&t, SIGNAL(progressUpdated(int)), this, SLOT(templateProgessUpdated(int))); - - dpi = printer->resolution(); + dpi = printerPtr->resolution(); //rendering resolution = selected paper size in inchs * printer dpi - pageSize.setHeight(printer->pageLayout().paintRect(QPageLayout::Inch).height() * dpi); - pageSize.setWidth(printer->pageLayout().paintRect(QPageLayout::Inch).width() * dpi); + pageSize.setHeight(printerPtr->pageLayout().paintRect(QPageLayout::Inch).height() * dpi); + pageSize.setWidth(printerPtr->pageLayout().paintRect(QPageLayout::Inch).width() * dpi); webView->page()->setViewportSize(pageSize); webView->setHtml(t.generate()); - render(); + if (printOptions->color_selected && printerPtr->colorMode()) { + printerPtr->setColorMode(QPrinter::Color); + } else { + printerPtr->setColorMode(QPrinter::GrayScale); + } + // apply user settings + int divesPerPage; + + // get number of dives per page from data-numberofdives attribute in the body of the selected template + bool ok; + divesPerPage = webView->page()->mainFrame()->findFirstElement("body").attribute("data-numberofdives").toInt(&ok); + if (!ok) { + divesPerPage = 1; // print each dive in a single page if the attribute is missing or malformed + //TODO: show warning + } + int Pages = ceil(getTotalWork(printOptions) / (float)divesPerPage); + render(Pages); +} + +void Printer::previewOnePage() +{ + if (printMode == PREVIEW) { + TemplateLayout t(printOptions, templateOptions); + + pageSize.setHeight(paintDevice->height()); + pageSize.setWidth(paintDevice->width()); + webView->page()->setViewportSize(pageSize); + webView->setHtml(t.generate()); + + // render only one page + render(1); + } } @@ -13,23 +13,32 @@ class Printer : public QObject { Q_OBJECT +public: + enum PrintMode { + PRINT, + PREVIEW + }; + private: - QPrinter *printer; + QPaintDevice *paintDevice; QWebView *webView; print_options *printOptions; template_options *templateOptions; QSize pageSize; + PrintMode printMode; int done; int dpi; - void render(); + void render(int Pages); void putProfileImage(QRect box, QRect viewPort, QPainter *painter, struct dive *dive, QPointer<ProfileWidget2> profile); private slots: void templateProgessUpdated(int value); public: - Printer(QPrinter *printer, print_options *printOptions, template_options *templateOptions); + Printer(QPaintDevice *paintDevice, print_options *printOptions, template_options *templateOptions, PrintMode printMode); + ~Printer(); void print(); + void previewOnePage(); signals: void progessUpdated(int value); diff --git a/printing_templates/one_dive.html b/printing_templates/one_dive.html index d7ae8d477..9f4d30a61 100644 --- a/printing_templates/one_dive.html +++ b/printing_templates/one_dive.html @@ -2,7 +2,7 @@ <head> <style> body { - background-color: white; + {{ print_options.grayscale }}; padding: 0; margin: 0; font-size: {{ template_options.font_size }}vw; @@ -16,13 +16,21 @@ } table { - -webkit-box-sizing: border-box; /* Safari/Chrome, other WebKit */ - -moz-box-sizing: border-box; /* Firefox, other Gecko */ + -webkit-box-sizing: border-box; box-sizing: border-box; border:max(1px, 0.1vw); border-style:solid; } + td { + padding-left: 0.5vw; + padding-right: 0.5vw; + } + + #body_div { + background-color: {{ template_options.color1 }}; + } + .mainContainer { width: 96%; height: 100%; @@ -45,8 +53,7 @@ .diveDetails { width: 98%; height: 98%; - -webkit-box-sizing: border-box; /* Safari/Chrome, other WebKit */ - -moz-box-sizing: border-box; /* Firefox, other Gecko */ + -webkit-box-sizing: border-box; box-sizing: border-box; border:max(1px, 0.1vw); border-style:solid; @@ -54,45 +61,43 @@ } .diveProfile { - width: 97%; + width: 96%; height: 40%; - margin: 1.5%; - -webkit-box-sizing: border-box; /* Safari/Chrome, other WebKit */ - -moz-box-sizing: border-box; /* Firefox, other Gecko */ - box-sizing: border-box; - border:max(1px, 0.1vw); - border-style:solid; + margin: 2%; } .dataSection { - width: 97%; + width: 98%; height: 40%; - margin: 1.5%; + margin: 1%; } .fieldTitle { - background-color: #CfC7C5; + background-color: {{ template_options.color2 }}; overflow: hidden; } .table_class { float: left; - margin: 1.5%; + margin: 1%; + width: 48%; } .notes_table_class { overflow: hidden; - width: 97%; - margin: 1.5%; - float: left; + width: 98%; + margin: 1%; } .textArea { line-height: {{ template_options.line_spacing }}; + max-height: 19vh; + overflow: hidden; } </style> </head> <body data-numberofdives = 1> +<div id="body_div"> {% block main_rows %} {% for dive in dives %} <div class="mainContainer"> @@ -206,5 +211,6 @@ </div> {% endfor %} {% endblock %} +</div> </body> </html> diff --git a/printing_templates/two_dives.html b/printing_templates/two_dives.html index 62502272b..0c8eec14c 100644 --- a/printing_templates/two_dives.html +++ b/printing_templates/two_dives.html @@ -2,7 +2,7 @@ <head> <style> body { - background-color: white; + {{ print_options.grayscale }}; padding: 0px; margin: 0px; font-size: {{ template_options.font_size }}vw; @@ -15,6 +15,10 @@ float: left; } + #body_div { + background-color: {{ template_options.color1 }}; + } + .mainContainer { width: 96%; height: 50%; @@ -63,7 +67,7 @@ } .fieldTitle { - background-color: #CfC7C5; + background-color: {{ template_options.color2 }}; overflow: hidden; padding:0; } @@ -103,6 +107,7 @@ </style> </head> <body data-numberofdives = 2> +<div id="body_div"> {% block main_rows %} {% for dive in dives %} <div class="mainContainer"> @@ -217,5 +222,6 @@ {% endblock %} <div id="footer"> <div> +</div> </body> </html> diff --git a/qt-ui/printdialog.cpp b/qt-ui/printdialog.cpp index 9ff29e67b..31ec354c8 100644 --- a/qt-ui/printdialog.cpp +++ b/qt-ui/printdialog.cpp @@ -12,8 +12,17 @@ #define SETTINGS_GROUP "PrintDialog" +template_options::color_palette_struct almond_colors, custom_colors; + PrintDialog::PrintDialog(QWidget *parent, Qt::WindowFlags f) : QDialog(parent, f) { + // initialize const colors + almond_colors.color1 = QColor::fromRgb(243, 234, 207); + almond_colors.color2 = QColor::fromRgb(253, 204, 156); + almond_colors.color3 = QColor::fromRgb(136, 160, 150); + almond_colors.color4 = QColor::fromRgb(187, 171, 139); + almond_colors.color5 = QColor::fromRgb(239, 130, 117); + // check if the options were previously stored in the settings; if not use some defaults. QSettings s; bool stored = s.childGroups().contains(SETTINGS_GROUP); @@ -27,6 +36,7 @@ PrintDialog::PrintDialog(QWidget *parent, Qt::WindowFlags f) : QDialog(parent, f templateOptions.font_size = 9; templateOptions.color_palette_index = 0; templateOptions.line_spacing = 1; + custom_colors = almond_colors; } else { s.beginGroup(SETTINGS_GROUP); printOptions.type = (print_options::print_type)s.value("type").toInt(); @@ -39,13 +49,27 @@ PrintDialog::PrintDialog(QWidget *parent, Qt::WindowFlags f) : QDialog(parent, f templateOptions.font_size = s.value("font_size").toDouble(); templateOptions.color_palette_index = s.value("color_palette").toInt(); templateOptions.line_spacing = s.value("line_spacing").toDouble(); + custom_colors.color1 = QColor(s.value("custom_color_1").toString()); + custom_colors.color2 = QColor(s.value("custom_color_2").toString()); + custom_colors.color3 = QColor(s.value("custom_color_3").toString()); + custom_colors.color4 = QColor(s.value("custom_color_4").toString()); + custom_colors.color5 = QColor(s.value("custom_color_5").toString()); + } + + switch (templateOptions.color_palette_index) { + case 0: // almond + templateOptions.color_palette = almond_colors; + break; + case 1: // custom + templateOptions.color_palette = custom_colors; + break; } // create a print options object and pass our options struct optionsWidget = new PrintOptions(this, &printOptions, &templateOptions); // create a new printer object - printer = new Printer(&qprinter, &printOptions, &templateOptions); + printer = new Printer(&qprinter, &printOptions, &templateOptions, Printer::PRINT); QVBoxLayout *layout = new QVBoxLayout(this); setLayout(layout); @@ -105,6 +129,13 @@ void PrintDialog::onFinished() s.setValue("font_size", templateOptions.font_size); s.setValue("color_palette", templateOptions.color_palette_index); s.setValue("line_spacing", templateOptions.line_spacing); + + // save custom colors + s.setValue("custom_color_1", custom_colors.color1.name()); + s.setValue("custom_color_2", custom_colors.color2.name()); + s.setValue("custom_color_3", custom_colors.color3.name()); + s.setValue("custom_color_4", custom_colors.color4.name()); + s.setValue("custom_color_5", custom_colors.color5.name()); } void PrintDialog::previewClicked(void) diff --git a/qt-ui/printoptions.h b/qt-ui/printoptions.h index d96b27a53..3a55c6994 100644 --- a/qt-ui/printoptions.h +++ b/qt-ui/printoptions.h @@ -26,7 +26,30 @@ struct template_options { int color_palette_index; double font_size; double line_spacing; -}; + struct color_palette_struct { + QColor color1; + QColor color2; + QColor color3; + QColor color4; + QColor color5; + bool operator!=(const color_palette_struct &other) const { + return other.color1 != color1 + || other.color2 != color2 + || other.color3 != color3 + || other.color4 != color4 + || other.color5 != color5; + } + } color_palette; + bool operator!=(const template_options &other) const { + return other.font_index != font_index + || other.color_palette_index != color_palette_index + || other.font_size != font_size + || other.line_spacing != line_spacing + || other.color_palette != color_palette; + } + }; + +extern template_options::color_palette_struct almond_colors, custom_colors; // should be based on a custom QPrintDialog class class PrintOptions : public QWidget { diff --git a/qt-ui/templateedit.cpp b/qt-ui/templateedit.cpp index 82a71ea32..6a6328f64 100644 --- a/qt-ui/templateedit.cpp +++ b/qt-ui/templateedit.cpp @@ -1,13 +1,18 @@ #include "templateedit.h" #include "printoptions.h" +#include "printer.h" #include "ui_templateedit.h" +#include <QMessageBox> +#include <QColorDialog> + TemplateEdit::TemplateEdit(QWidget *parent, struct print_options *printOptions, struct template_options *templateOptions) : QDialog(parent), ui(new Ui::TemplateEdit) { ui->setupUi(this); this->templateOptions = templateOptions; + newTemplateOptions = *templateOptions; this->printOptions = printOptions; // restore the settings and init the UI @@ -24,38 +29,157 @@ TemplateEdit::TemplateEdit(QWidget *parent, struct print_options *printOptions, grantlee_template = TemplateLayout::readTemplate("custom.html"); } + // gui + btnGroup = new QButtonGroup; + btnGroup->addButton(ui->editButton1, 1); + btnGroup->addButton(ui->editButton2, 2); + btnGroup->addButton(ui->editButton3, 3); + btnGroup->addButton(ui->editButton4, 4); + btnGroup->addButton(ui->editButton5, 5); + connect(btnGroup, SIGNAL(buttonClicked(QAbstractButton*)), this, SLOT(colorSelect(QAbstractButton*))); + ui->plainTextEdit->setPlainText(grantlee_template); + updatePreview(); } TemplateEdit::~TemplateEdit() { + delete btnGroup; delete ui; } +void TemplateEdit::updatePreview() +{ + // update Qpixmap preview + int width = ui->label->width(); + int height = ui->label->height(); + QPixmap map(width * 2, height * 2); + map.fill(QColor::fromRgb(255, 255, 255)); + Printer printer(&map, printOptions, &newTemplateOptions, Printer::PREVIEW); + printer.previewOnePage(); + ui->label->setPixmap(map.scaled(width, height, Qt::IgnoreAspectRatio)); + + // update colors tab + ui->colorLable1->setStyleSheet("QLabel { background-color : \"" + newTemplateOptions.color_palette.color1.name() + "\";}"); + ui->colorLable2->setStyleSheet("QLabel { background-color : \"" + newTemplateOptions.color_palette.color2.name() + "\";}"); + ui->colorLable3->setStyleSheet("QLabel { background-color : \"" + newTemplateOptions.color_palette.color3.name() + "\";}"); + ui->colorLable4->setStyleSheet("QLabel { background-color : \"" + newTemplateOptions.color_palette.color4.name() + "\";}"); + ui->colorLable5->setStyleSheet("QLabel { background-color : \"" + newTemplateOptions.color_palette.color5.name() + "\";}"); + + ui->colorLable1->setText(newTemplateOptions.color_palette.color1.name()); + ui->colorLable2->setText(newTemplateOptions.color_palette.color2.name()); + ui->colorLable3->setText(newTemplateOptions.color_palette.color3.name()); + ui->colorLable4->setText(newTemplateOptions.color_palette.color4.name()); + ui->colorLable5->setText(newTemplateOptions.color_palette.color5.name()); + + // update critical UI elements + ui->colorpalette->setCurrentIndex(newTemplateOptions.color_palette_index); +} + void TemplateEdit::on_fontsize_valueChanged(int font_size) { - templateOptions->font_size = font_size; + newTemplateOptions.font_size = font_size; + updatePreview(); } void TemplateEdit::on_linespacing_valueChanged(double line_spacing) { - templateOptions->line_spacing = line_spacing; + newTemplateOptions.line_spacing = line_spacing; + updatePreview(); } void TemplateEdit::on_fontSelection_currentIndexChanged(int index) { - templateOptions->font_index = index; + newTemplateOptions.font_index = index; + updatePreview(); } void TemplateEdit::on_colorpalette_currentIndexChanged(int index) { - templateOptions->color_palette_index = index; + newTemplateOptions.color_palette_index = index; + switch (newTemplateOptions.color_palette_index) { + case 0: // almond + newTemplateOptions.color_palette = almond_colors; + break; + case 1: // custom + newTemplateOptions.color_palette = custom_colors; + break; + } + updatePreview(); } -void TemplateEdit::on_TemplateEdit_finished(int result) +void TemplateEdit::saveSettings() { - if (grantlee_template.compare(ui->plainTextEdit->toPlainText())) { - printOptions->p_template = print_options::CUSTOM; - TemplateLayout::writeTemplate("custom.html", ui->plainTextEdit->toPlainText()); + if ((*templateOptions) != newTemplateOptions || grantlee_template.compare(ui->plainTextEdit->toPlainText())) { + QMessageBox msgBox; + msgBox.setText("Do you want to save your changes?"); + msgBox.setStandardButtons(QMessageBox::Save | QMessageBox::Cancel); + msgBox.setDefaultButton(QMessageBox::Cancel); + if (msgBox.exec() == QMessageBox::Save) { + memcpy(templateOptions, &newTemplateOptions, sizeof(struct template_options)); + if (grantlee_template.compare(ui->plainTextEdit->toPlainText())) { + printOptions->p_template = print_options::CUSTOM; + TemplateLayout::writeTemplate("custom.html", ui->plainTextEdit->toPlainText()); + } + if (templateOptions->color_palette_index == 1) { + custom_colors = templateOptions->color_palette; + } + } + } +} + +void TemplateEdit::on_buttonBox_clicked(QAbstractButton *button) +{ + QDialogButtonBox::StandardButton standardButton = ui->buttonBox->standardButton(button); + switch (standardButton) { + case QDialogButtonBox::Ok: + saveSettings(); + break; + case QDialogButtonBox::Cancel: + break; + case QDialogButtonBox::Apply: + saveSettings(); + updatePreview(); + break; + default: + ; + } +} + +void TemplateEdit::colorSelect(QAbstractButton *button) +{ + // reset custom colors palette + switch (newTemplateOptions.color_palette_index) { + case 0: // almond + newTemplateOptions.color_palette = almond_colors; + custom_colors = newTemplateOptions.color_palette; + break; + } + + //change selected color + QColor color; + switch (btnGroup->id(button)) { + case 1: + color = QColorDialog::getColor(newTemplateOptions.color_palette.color1, this); + newTemplateOptions.color_palette.color1 = color; + break; + case 2: + color = QColorDialog::getColor(newTemplateOptions.color_palette.color2, this); + newTemplateOptions.color_palette.color2 = color; + break; + case 3: + color = QColorDialog::getColor(newTemplateOptions.color_palette.color3, this); + newTemplateOptions.color_palette.color3 = color; + break; + case 4: + color = QColorDialog::getColor(newTemplateOptions.color_palette.color4, this); + newTemplateOptions.color_palette.color4 = color; + break; + case 5: + color = QColorDialog::getColor(newTemplateOptions.color_palette.color5, this); + newTemplateOptions.color_palette.color5 = color; + break; } + newTemplateOptions.color_palette_index = 1; + updatePreview(); } diff --git a/qt-ui/templateedit.h b/qt-ui/templateedit.h index 296005652..15b717f78 100644 --- a/qt-ui/templateedit.h +++ b/qt-ui/templateedit.h @@ -24,13 +24,20 @@ private slots: void on_colorpalette_currentIndexChanged(int index); - void on_TemplateEdit_finished(int result); + void on_buttonBox_clicked(QAbstractButton *button); + + void colorSelect(QAbstractButton *button); private: Ui::TemplateEdit *ui; + QButtonGroup *btnGroup; struct template_options *templateOptions; + struct template_options newTemplateOptions; struct print_options *printOptions; QString grantlee_template; + void saveSettings(); + void updatePreview(); + }; #endif // TEMPLATEEDIT_H diff --git a/qt-ui/templateedit.ui b/qt-ui/templateedit.ui index 26fe15926..4f9c9c2ed 100644 --- a/qt-ui/templateedit.ui +++ b/qt-ui/templateedit.ui @@ -26,7 +26,7 @@ <enum>Qt::Horizontal</enum> </property> <property name="standardButtons"> - <set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set> + <set>QDialogButtonBox::Apply|QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set> </property> </widget> <widget class="QTabWidget" name="tabWidget"> @@ -39,7 +39,7 @@ </rect> </property> <property name="currentIndex"> - <number>0</number> + <number>2</number> </property> <widget class="QWidget" name="style"> <attribute name="title"> @@ -132,6 +132,11 @@ <string>Almond</string> </property> </item> + <item> + <property name="text"> + <string>Custom</string> + </property> + </item> </widget> </item> </layout> @@ -187,21 +192,223 @@ </property> </widget> </widget> - </widget> - <widget class="QWebView" name="webView"> - <property name="geometry"> - <rect> - <x>20</x> - <y>60</y> - <width>251</width> - <height>311</height> - </rect> - </property> - <property name="url"> - <url> - <string>about:blank</string> - </url> - </property> + <widget class="QWidget" name="color_tab"> + <attribute name="title"> + <string>Colors</string> + </attribute> + <widget class="QWidget" name="verticalLayoutWidget_2"> + <property name="geometry"> + <rect> + <x>10</x> + <y>30</y> + <width>411</width> + <height>171</height> + </rect> + </property> + <layout class="QVBoxLayout" name="verticalLayout_2"> + <item> + <layout class="QHBoxLayout" name="horizontalLayout_5"> + <item> + <widget class="QLabel" name="label_3"> + <property name="sizePolicy"> + <sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string>Background</string> + </property> + </widget> + </item> + <item> + <widget class="QLabel" name="colorLable1"> + <property name="sizePolicy"> + <sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string>color1</string> + </property> + <property name="alignment"> + <set>Qt::AlignCenter</set> + </property> + </widget> + </item> + <item> + <widget class="QPushButton" name="editButton1"> + <property name="text"> + <string>Edit</string> + </property> + </widget> + </item> + </layout> + </item> + <item> + <layout class="QHBoxLayout" name="horizontalLayout_8"> + <item> + <widget class="QLabel" name="label_9"> + <property name="sizePolicy"> + <sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string>Table cells</string> + </property> + </widget> + </item> + <item> + <widget class="QLabel" name="colorLable2"> + <property name="sizePolicy"> + <sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string>color2</string> + </property> + <property name="alignment"> + <set>Qt::AlignCenter</set> + </property> + </widget> + </item> + <item> + <widget class="QPushButton" name="editButton2"> + <property name="text"> + <string>Edit</string> + </property> + </widget> + </item> + </layout> + </item> + <item> + <layout class="QHBoxLayout" name="horizontalLayout_7"> + <item> + <widget class="QLabel" name="label_7"> + <property name="sizePolicy"> + <sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string>Text 1</string> + </property> + </widget> + </item> + <item> + <widget class="QLabel" name="colorLable3"> + <property name="sizePolicy"> + <sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string>color3</string> + </property> + <property name="alignment"> + <set>Qt::AlignCenter</set> + </property> + </widget> + </item> + <item> + <widget class="QPushButton" name="editButton3"> + <property name="text"> + <string>Edit</string> + </property> + </widget> + </item> + </layout> + </item> + <item> + <layout class="QHBoxLayout" name="horizontalLayout_9"> + <item> + <widget class="QLabel" name="label_11"> + <property name="sizePolicy"> + <sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string>Text 2</string> + </property> + </widget> + </item> + <item> + <widget class="QLabel" name="colorLable4"> + <property name="sizePolicy"> + <sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string>color4</string> + </property> + <property name="alignment"> + <set>Qt::AlignCenter</set> + </property> + </widget> + </item> + <item> + <widget class="QPushButton" name="editButton4"> + <property name="text"> + <string>Edit</string> + </property> + </widget> + </item> + </layout> + </item> + <item> + <layout class="QHBoxLayout" name="horizontalLayout_6"> + <item> + <widget class="QLabel" name="label_4"> + <property name="sizePolicy"> + <sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string>Borders</string> + </property> + </widget> + </item> + <item> + <widget class="QLabel" name="colorLable5"> + <property name="sizePolicy"> + <sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string>color5</string> + </property> + <property name="alignment"> + <set>Qt::AlignCenter</set> + </property> + </widget> + </item> + <item> + <widget class="QPushButton" name="editButton5"> + <property name="text"> + <string>Edit</string> + </property> + </widget> + </item> + </layout> + </item> + </layout> + </widget> + </widget> </widget> <widget class="QLabel" name="label_5"> <property name="geometry"> @@ -216,14 +423,20 @@ <string>Preview</string> </property> </widget> + <widget class="QLabel" name="label"> + <property name="geometry"> + <rect> + <x>50</x> + <y>70</y> + <width>211</width> + <height>291</height> + </rect> + </property> + <property name="text"> + <string/> + </property> + </widget> </widget> - <customwidgets> - <customwidget> - <class>QWebView</class> - <extends>QWidget</extends> - <header>QtWebKitWidgets/QWebView</header> - </customwidget> - </customwidgets> <resources/> <connections> <connection> diff --git a/templatelayout.cpp b/templatelayout.cpp index 9a9dc9656..fec57cb2a 100644 --- a/templatelayout.cpp +++ b/templatelayout.cpp @@ -47,6 +47,7 @@ QString TemplateLayout::generate() Grantlee::registerMetaType<Dive>(); Grantlee::registerMetaType<template_options>(); + Grantlee::registerMetaType<print_options>(); QVariantHash mapping; QVariantList diveList; @@ -64,6 +65,7 @@ QString TemplateLayout::generate() } mapping.insert("dives", diveList); mapping.insert("template_options", QVariant::fromValue(*templateOptions)); + mapping.insert("print_options", QVariant::fromValue(*PrintOptions)); Grantlee::Context c(mapping); @@ -104,6 +106,7 @@ void TemplateLayout::writeTemplate(QString template_name, QString grantlee_templ QFile qfile(getSubsurfaceDataPath("printing_templates") + QDir::separator() + template_name); if (qfile.open(QFile::ReadWrite | QFile::Text)) { qfile.write(grantlee_template.toUtf8().data()); + qfile.resize(qfile.pos()); qfile.close(); } } diff --git a/templatelayout.h b/templatelayout.h index 622f7d7a0..e37e9e868 100644 --- a/templatelayout.h +++ b/templatelayout.h @@ -79,6 +79,7 @@ public: Q_DECLARE_METATYPE(Dive) Q_DECLARE_METATYPE(template_options) +Q_DECLARE_METATYPE(print_options) GRANTLEE_BEGIN_LOOKUP(Dive) if (property == "number") @@ -123,6 +124,26 @@ if (property == "font") { return object.font_size / 9.0; } else if (property == "line_spacing") { return object.line_spacing; +} else if (property == "color1") { + return object.color_palette.color1.name(); +} else if (property == "color2") { + return object.color_palette.color2.name(); +} else if (property == "color3") { + return object.color_palette.color3.name(); +} else if (property == "color4") { + return object.color_palette.color4.name(); +} else if (property == "color5") { + return object.color_palette.color5.name(); +} +GRANTLEE_END_LOOKUP + +GRANTLEE_BEGIN_LOOKUP(print_options) +if (property == "grayscale") { + if (object.color_selected) { + return ""; + } else { + return "-webkit-filter: grayscale(100%)"; + } } GRANTLEE_END_LOOKUP |