From c56b1c1114015c6b83852ecdcdb21b03f41e594b Mon Sep 17 00:00:00 2001 From: Gehad elrobey Date: Tue, 7 Jul 2015 03:12:36 +0200 Subject: Printing: overwrite the old custom template file Change the new file size after inserting the new template to overwrite the old one. Signed-off-by: Gehad elrobey Signed-off-by: Lubomir I. Ivanov --- templatelayout.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/templatelayout.cpp b/templatelayout.cpp index 9a9dc9656..79508d6db 100644 --- a/templatelayout.cpp +++ b/templatelayout.cpp @@ -104,6 +104,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(); } } -- cgit v1.2.3-70-g09d2 From c90d5b891df873a6a69f5da618d42af998b4620f Mon Sep 17 00:00:00 2001 From: Gehad elrobey Date: Tue, 7 Jul 2015 03:14:43 +0200 Subject: Printing: show confirmation message before overwriting the template Before overwriting the new template show confirmation message. Signed-off-by: Gehad elrobey Signed-off-by: Lubomir I. Ivanov --- qt-ui/templateedit.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/qt-ui/templateedit.cpp b/qt-ui/templateedit.cpp index 82a71ea32..0a8c4ca92 100644 --- a/qt-ui/templateedit.cpp +++ b/qt-ui/templateedit.cpp @@ -2,6 +2,8 @@ #include "printoptions.h" #include "ui_templateedit.h" +#include + TemplateEdit::TemplateEdit(QWidget *parent, struct print_options *printOptions, struct template_options *templateOptions) : QDialog(parent), ui(new Ui::TemplateEdit) @@ -55,7 +57,13 @@ void TemplateEdit::on_colorpalette_currentIndexChanged(int index) void TemplateEdit::on_TemplateEdit_finished(int result) { if (grantlee_template.compare(ui->plainTextEdit->toPlainText())) { - printOptions->p_template = print_options::CUSTOM; - TemplateLayout::writeTemplate("custom.html", ui->plainTextEdit->toPlainText()); + QMessageBox msgBox; + msgBox.setText("Do you want to save your changes?"); + msgBox.setStandardButtons(QMessageBox::Save | QMessageBox::Discard); + msgBox.setDefaultButton(QMessageBox::Discard); + if (msgBox.exec() == QMessageBox::Save) { + printOptions->p_template = print_options::CUSTOM; + TemplateLayout::writeTemplate("custom.html", ui->plainTextEdit->toPlainText()); + } } } -- cgit v1.2.3-70-g09d2 From 85bce0fa0da575040b6e4ef04750475b9a9ae223 Mon Sep 17 00:00:00 2001 From: Gehad elrobey Date: Fri, 10 Jul 2015 14:02:13 +0200 Subject: Printing: enhance the one_dive per page template - fix the layout - prevent the notes from expanding - don't overflow the text Signed-off-by: Gehad elrobey Signed-off-by: Lubomir I. Ivanov --- printing_templates/one_dive.html | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/printing_templates/one_dive.html b/printing_templates/one_dive.html index d7ae8d477..52b8097c9 100644 --- a/printing_templates/one_dive.html +++ b/printing_templates/one_dive.html @@ -16,13 +16,17 @@ } 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; + } + .mainContainer { width: 96%; height: 100%; @@ -45,8 +49,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,20 +57,15 @@ } .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 { @@ -77,18 +75,20 @@ .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; } -- cgit v1.2.3-70-g09d2 From 51e36fa15805fdf64d68113ef66910f3f6c8eede Mon Sep 17 00:00:00 2001 From: Gehad elrobey Date: Fri, 10 Jul 2015 14:59:56 +0200 Subject: Printing: handle memory leak in printer class Don't initialize new webview each time we print. Delete the QWebView object in the destructor. Signed-off-by: Gehad elrobey Signed-off-by: Lubomir I. Ivanov --- printer.cpp | 7 ++++++- printer.h | 1 + 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/printer.cpp b/printer.cpp index f8a90f96d..446a5c29d 100644 --- a/printer.cpp +++ b/printer.cpp @@ -13,6 +13,12 @@ Printer::Printer(QPrinter *printer, print_options *printOptions, template_option this->templateOptions = templateOptions; dpi = 0; done = 0; + webView = new QWebView(); +} + +Printer::~Printer() +{ + delete webView; } void Printer::putProfileImage(QRect profilePlaceholder, QRect viewPort, QPainter *painter, struct dive *dive, QPointer profile) @@ -118,7 +124,6 @@ void Printer::templateProgessUpdated(int value) void Printer::print() { TemplateLayout t(printOptions, templateOptions); - webView = new QWebView(); connect(&t, SIGNAL(progressUpdated(int)), this, SLOT(templateProgessUpdated(int))); dpi = printer->resolution(); diff --git a/printer.h b/printer.h index 4ab65834a..73368a669 100644 --- a/printer.h +++ b/printer.h @@ -29,6 +29,7 @@ private slots: public: Printer(QPrinter *printer, print_options *printOptions, template_options *templateOptions); + ~Printer(); void print(); signals: -- cgit v1.2.3-70-g09d2 From 4e1a5d954b3cceafce3fb2e4534d7e5c9bd5c770 Mon Sep 17 00:00:00 2001 From: Gehad elrobey Date: Fri, 10 Jul 2015 16:20:14 +0200 Subject: Printing: refactoring printer class - Render specific number of pages only. - Move printer related code to print(). Signed-off-by: Gehad elrobey Signed-off-by: Lubomir I. Ivanov --- printer.cpp | 39 +++++++++++++++++++-------------------- printer.h | 2 +- 2 files changed, 20 insertions(+), 21 deletions(-) diff --git a/printer.cpp b/printer.cpp index 446a5c29d..e1179319e 100644 --- a/printer.cpp +++ b/printer.cpp @@ -31,25 +31,8 @@ void Printer::putProfileImage(QRect profilePlaceholder, QRect viewPort, QPainter profile->render(painter, pos); } -void Printer::render() +void Printer::render(int Pages = 0) { - // apply user settings - int divesPerPage; - if (printOptions->color_selected && printer->colorMode()) { - printer->setColorMode(QPrinter::Color); - } else { - printer->setColorMode(QPrinter::GrayScale); - } - - // 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); - // keep original preferences QPointer profile = MainWindow::instance()->graphics(); int profileFrameStyle = profile->frameStyle(); @@ -59,7 +42,7 @@ 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; @@ -132,5 +115,21 @@ void Printer::print() pageSize.setWidth(printer->pageLayout().paintRect(QPageLayout::Inch).width() * dpi); webView->page()->setViewportSize(pageSize); webView->setHtml(t.generate()); - render(); + if (printOptions->color_selected && printer->colorMode()) { + printer->setColorMode(QPrinter::Color); + } else { + printer->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); } diff --git a/printer.h b/printer.h index 73368a669..6c826aa0a 100644 --- a/printer.h +++ b/printer.h @@ -21,7 +21,7 @@ private: QSize pageSize; int done; int dpi; - void render(); + void render(int Pages); void putProfileImage(QRect box, QRect viewPort, QPainter *painter, struct dive *dive, QPointer profile); private slots: -- cgit v1.2.3-70-g09d2 From 142fd950c8d69dc4d4aad4034fe65ca400d37783 Mon Sep 17 00:00:00 2001 From: Gehad elrobey Date: Fri, 10 Jul 2015 20:34:25 +0200 Subject: Printing: change QPrinter to parent class QPaintDevice Use general class QPaintDevice to be used for printing and previewing instances, printing uses a QPrinter object while previewing uses a QPixmap instance. We use static_cast to use the needed object. Signed-off-by: Gehad elrobey Signed-off-by: Lubomir I. Ivanov --- printer.cpp | 24 +++++++++++++----------- printer.h | 4 ++-- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/printer.cpp b/printer.cpp index e1179319e..da5d5142d 100644 --- a/printer.cpp +++ b/printer.cpp @@ -6,9 +6,9 @@ #include #include -Printer::Printer(QPrinter *printer, print_options *printOptions, template_options *templateOptions) +Printer::Printer(QPaintDevice *paintDevice, print_options *printOptions, template_options *templateOptions) { - this->printer = printer; + this->paintDevice = paintDevice; this->printOptions = printOptions; this->templateOptions = templateOptions; dpi = 0; @@ -49,7 +49,7 @@ void Printer::render(int Pages = 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); @@ -81,7 +81,7 @@ void Printer::render(int Pages = 0) // rendering progress is 4/5 of total work emit(progessUpdated((i * 80.0 / Pages) + done)); if (i < Pages - 1) - printer->newPage(); + static_cast(paintDevice)->newPage(); } painter.end(); @@ -106,19 +106,21 @@ void Printer::templateProgessUpdated(int value) void Printer::print() { + QPrinter *printerPtr; + printerPtr = static_cast(paintDevice); + TemplateLayout t(printOptions, templateOptions); 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()); - if (printOptions->color_selected && printer->colorMode()) { - printer->setColorMode(QPrinter::Color); + if (printOptions->color_selected && printerPtr->colorMode()) { + printerPtr->setColorMode(QPrinter::Color); } else { - printer->setColorMode(QPrinter::GrayScale); + printerPtr->setColorMode(QPrinter::GrayScale); } // apply user settings int divesPerPage; diff --git a/printer.h b/printer.h index 6c826aa0a..caeb14a1f 100644 --- a/printer.h +++ b/printer.h @@ -14,7 +14,7 @@ class Printer : public QObject { Q_OBJECT private: - QPrinter *printer; + QPaintDevice *paintDevice; QWebView *webView; print_options *printOptions; template_options *templateOptions; @@ -28,7 +28,7 @@ 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); ~Printer(); void print(); -- cgit v1.2.3-70-g09d2 From 3a6963836682aa0e0e2825db4eaac7ea48a9939b Mon Sep 17 00:00:00 2001 From: Gehad elrobey Date: Fri, 10 Jul 2015 21:30:18 +0200 Subject: Printing: check for different printing modes Add PRINT/PREVIEW print modes, check for printing modes before casting. We must pass a QPaintDevice with type QPixmap for previewing and with type QPrinter for actual printing. Signed-off-by: Gehad elrobey Signed-off-by: Lubomir I. Ivanov --- printer.cpp | 10 ++++++++-- printer.h | 9 ++++++++- qt-ui/printdialog.cpp | 2 +- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/printer.cpp b/printer.cpp index da5d5142d..c5867450f 100644 --- a/printer.cpp +++ b/printer.cpp @@ -6,11 +6,12 @@ #include #include -Printer::Printer(QPaintDevice *paintDevice, print_options *printOptions, template_options *templateOptions) +Printer::Printer(QPaintDevice *paintDevice, print_options *printOptions, template_options *templateOptions, PrintMode printMode) { this->paintDevice = paintDevice; this->printOptions = printOptions; this->templateOptions = templateOptions; + this->printMode = printMode; dpi = 0; done = 0; webView = new QWebView(); @@ -80,7 +81,7 @@ void Printer::render(int Pages = 0) // rendering progress is 4/5 of total work emit(progessUpdated((i * 80.0 / Pages) + done)); - if (i < Pages - 1) + if (i < Pages - 1 && printMode == Printer::PRINT) static_cast(paintDevice)->newPage(); } painter.end(); @@ -106,6 +107,11 @@ 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(paintDevice); diff --git a/printer.h b/printer.h index caeb14a1f..dee9ba980 100644 --- a/printer.h +++ b/printer.h @@ -13,12 +13,19 @@ class Printer : public QObject { Q_OBJECT +public: + enum PrintMode { + PRINT, + PREVIEW + }; + private: QPaintDevice *paintDevice; QWebView *webView; print_options *printOptions; template_options *templateOptions; QSize pageSize; + PrintMode printMode; int done; int dpi; void render(int Pages); @@ -28,7 +35,7 @@ private slots: void templateProgessUpdated(int value); public: - Printer(QPaintDevice *paintDevice, print_options *printOptions, template_options *templateOptions); + Printer(QPaintDevice *paintDevice, print_options *printOptions, template_options *templateOptions, PrintMode printMode); ~Printer(); void print(); diff --git a/qt-ui/printdialog.cpp b/qt-ui/printdialog.cpp index 9ff29e67b..0a2c7898f 100644 --- a/qt-ui/printdialog.cpp +++ b/qt-ui/printdialog.cpp @@ -45,7 +45,7 @@ PrintDialog::PrintDialog(QWidget *parent, Qt::WindowFlags f) : QDialog(parent, f 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); -- cgit v1.2.3-70-g09d2 From d4382c7c4b802b030bab5e64de4b1641f603d543 Mon Sep 17 00:00:00 2001 From: Gehad elrobey Date: Fri, 10 Jul 2015 21:45:27 +0200 Subject: Printing: add preview to TemplateEdit dialog Show QPixmap in QLabel, Use Printer class to render the Preview on the QPixmap. Signed-off-by: Gehad elrobey Signed-off-by: Lubomir I. Ivanov --- printer.cpp | 15 +++++++++++++++ printer.h | 1 + qt-ui/templateedit.cpp | 9 +++++++++ qt-ui/templateedit.ui | 35 +++++++++++++---------------------- 4 files changed, 38 insertions(+), 22 deletions(-) diff --git a/printer.cpp b/printer.cpp index c5867450f..7cef1104e 100644 --- a/printer.cpp +++ b/printer.cpp @@ -141,3 +141,18 @@ void Printer::print() 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); + } +} diff --git a/printer.h b/printer.h index dee9ba980..b4cf3ac2a 100644 --- a/printer.h +++ b/printer.h @@ -38,6 +38,7 @@ public: Printer(QPaintDevice *paintDevice, print_options *printOptions, template_options *templateOptions, PrintMode printMode); ~Printer(); void print(); + void previewOnePage(); signals: void progessUpdated(int value); diff --git a/qt-ui/templateedit.cpp b/qt-ui/templateedit.cpp index 0a8c4ca92..19f5db609 100644 --- a/qt-ui/templateedit.cpp +++ b/qt-ui/templateedit.cpp @@ -1,5 +1,6 @@ #include "templateedit.h" #include "printoptions.h" +#include "printer.h" #include "ui_templateedit.h" #include @@ -27,6 +28,14 @@ TemplateEdit::TemplateEdit(QWidget *parent, struct print_options *printOptions, } ui->plainTextEdit->setPlainText(grantlee_template); + + 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, templateOptions, Printer::PREVIEW); + printer.previewOnePage(); + ui->label->setPixmap(map.scaled(width, height, Qt::IgnoreAspectRatio)); } TemplateEdit::~TemplateEdit() diff --git a/qt-ui/templateedit.ui b/qt-ui/templateedit.ui index 26fe15926..fa27eb324 100644 --- a/qt-ui/templateedit.ui +++ b/qt-ui/templateedit.ui @@ -188,21 +188,6 @@ - - - - 20 - 60 - 251 - 311 - - - - - about:blank - - - @@ -216,14 +201,20 @@ Preview + + + + 50 + 70 + 211 + 291 + + + + + + - - - QWebView - QWidget -
QtWebKitWidgets/QWebView
-
-
-- cgit v1.2.3-70-g09d2 From 7ca311ae859199f1e07279bf78e1c36efc97768c Mon Sep 17 00:00:00 2001 From: Gehad elrobey Date: Sat, 11 Jul 2015 01:06:43 +0200 Subject: Printing: save only if data is changed in template_options Check if data is changed before saving the new settings. Signed-off-by: Gehad elrobey Signed-off-by: Lubomir I. Ivanov --- qt-ui/printoptions.h | 6 ++++++ qt-ui/templateedit.cpp | 12 +++++++----- qt-ui/templateedit.h | 1 + 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/qt-ui/printoptions.h b/qt-ui/printoptions.h index d96b27a53..3a5c2b179 100644 --- a/qt-ui/printoptions.h +++ b/qt-ui/printoptions.h @@ -26,6 +26,12 @@ struct template_options { int color_palette_index; double font_size; double line_spacing; + 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; + } }; // should be based on a custom QPrintDialog class diff --git a/qt-ui/templateedit.cpp b/qt-ui/templateedit.cpp index 19f5db609..0354131ef 100644 --- a/qt-ui/templateedit.cpp +++ b/qt-ui/templateedit.cpp @@ -11,6 +11,7 @@ TemplateEdit::TemplateEdit(QWidget *parent, struct print_options *printOptions, { ui->setupUi(this); this->templateOptions = templateOptions; + newTemplateOptions = *templateOptions; this->printOptions = printOptions; // restore the settings and init the UI @@ -45,32 +46,33 @@ TemplateEdit::~TemplateEdit() void TemplateEdit::on_fontsize_valueChanged(int font_size) { - templateOptions->font_size = font_size; + newTemplateOptions.font_size = font_size; } void TemplateEdit::on_linespacing_valueChanged(double line_spacing) { - templateOptions->line_spacing = line_spacing; + newTemplateOptions.line_spacing = line_spacing; } void TemplateEdit::on_fontSelection_currentIndexChanged(int index) { - templateOptions->font_index = index; + newTemplateOptions.font_index = index; } void TemplateEdit::on_colorpalette_currentIndexChanged(int index) { - templateOptions->color_palette_index = index; + newTemplateOptions.color_palette_index = index; } void TemplateEdit::on_TemplateEdit_finished(int result) { - if (grantlee_template.compare(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::Discard); msgBox.setDefaultButton(QMessageBox::Discard); if (msgBox.exec() == QMessageBox::Save) { + memcpy(templateOptions, &newTemplateOptions, sizeof(struct template_options)); printOptions->p_template = print_options::CUSTOM; TemplateLayout::writeTemplate("custom.html", ui->plainTextEdit->toPlainText()); } diff --git a/qt-ui/templateedit.h b/qt-ui/templateedit.h index 296005652..325d7eef3 100644 --- a/qt-ui/templateedit.h +++ b/qt-ui/templateedit.h @@ -29,6 +29,7 @@ private slots: private: Ui::TemplateEdit *ui; struct template_options *templateOptions; + struct template_options newTemplateOptions; struct print_options *printOptions; QString grantlee_template; }; -- cgit v1.2.3-70-g09d2 From f1615e725c7a5562b5fcaac2cd0701dae61b89ca Mon Sep 17 00:00:00 2001 From: Gehad elrobey Date: Sat, 11 Jul 2015 01:37:27 +0200 Subject: Printing: add apply button to TemplateEdit class Add apply button to the dialog, Update the preview after applying the new settings. Signed-off-by: Gehad elrobey Signed-off-by: Lubomir I. Ivanov --- qt-ui/templateedit.cpp | 17 ++++++++++++++++- qt-ui/templateedit.h | 3 ++- qt-ui/templateedit.ui | 2 +- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/qt-ui/templateedit.cpp b/qt-ui/templateedit.cpp index 0354131ef..2d09cb947 100644 --- a/qt-ui/templateedit.cpp +++ b/qt-ui/templateedit.cpp @@ -64,7 +64,7 @@ void TemplateEdit::on_colorpalette_currentIndexChanged(int index) newTemplateOptions.color_palette_index = index; } -void TemplateEdit::on_TemplateEdit_finished(int result) +void TemplateEdit::saveSettings() { if ((*templateOptions) != newTemplateOptions || grantlee_template.compare(ui->plainTextEdit->toPlainText())) { QMessageBox msgBox; @@ -78,3 +78,18 @@ void TemplateEdit::on_TemplateEdit_finished(int result) } } } + +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(); + break; + } +} diff --git a/qt-ui/templateedit.h b/qt-ui/templateedit.h index 325d7eef3..9b6d9167f 100644 --- a/qt-ui/templateedit.h +++ b/qt-ui/templateedit.h @@ -24,7 +24,7 @@ private slots: void on_colorpalette_currentIndexChanged(int index); - void on_TemplateEdit_finished(int result); + void on_buttonBox_clicked(QAbstractButton *button); private: Ui::TemplateEdit *ui; @@ -32,6 +32,7 @@ private: struct template_options newTemplateOptions; struct print_options *printOptions; QString grantlee_template; + void saveSettings(); }; #endif // TEMPLATEEDIT_H diff --git a/qt-ui/templateedit.ui b/qt-ui/templateedit.ui index fa27eb324..de007c9b7 100644 --- a/qt-ui/templateedit.ui +++ b/qt-ui/templateedit.ui @@ -26,7 +26,7 @@ Qt::Horizontal - QDialogButtonBox::Cancel|QDialogButtonBox::Ok + QDialogButtonBox::Apply|QDialogButtonBox::Cancel|QDialogButtonBox::Ok -- cgit v1.2.3-70-g09d2 From d705cb34bb5a8d442b54784bb9105404bb304404 Mon Sep 17 00:00:00 2001 From: Gehad elrobey Date: Sat, 11 Jul 2015 12:50:14 +0200 Subject: Printing: update preview on apply settings On update call Printer to render on the QPixmap. Signed-off-by: Gehad elrobey Signed-off-by: Lubomir I. Ivanov --- qt-ui/templateedit.cpp | 15 ++++++++++----- qt-ui/templateedit.h | 2 ++ 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/qt-ui/templateedit.cpp b/qt-ui/templateedit.cpp index 2d09cb947..bd4763107 100644 --- a/qt-ui/templateedit.cpp +++ b/qt-ui/templateedit.cpp @@ -29,7 +29,16 @@ TemplateEdit::TemplateEdit(QWidget *parent, struct print_options *printOptions, } ui->plainTextEdit->setPlainText(grantlee_template); + updatePreview(); +} + +TemplateEdit::~TemplateEdit() +{ + delete ui; +} +void TemplateEdit::updatePreview() +{ int width = ui->label->width(); int height = ui->label->height(); QPixmap map(width * 2, height * 2); @@ -39,11 +48,6 @@ TemplateEdit::TemplateEdit(QWidget *parent, struct print_options *printOptions, ui->label->setPixmap(map.scaled(width, height, Qt::IgnoreAspectRatio)); } -TemplateEdit::~TemplateEdit() -{ - delete ui; -} - void TemplateEdit::on_fontsize_valueChanged(int font_size) { newTemplateOptions.font_size = font_size; @@ -90,6 +94,7 @@ void TemplateEdit::on_buttonBox_clicked(QAbstractButton *button) break; case QDialogButtonBox::Apply: saveSettings(); + updatePreview(); break; } } diff --git a/qt-ui/templateedit.h b/qt-ui/templateedit.h index 9b6d9167f..21cbc0321 100644 --- a/qt-ui/templateedit.h +++ b/qt-ui/templateedit.h @@ -33,6 +33,8 @@ private: struct print_options *printOptions; QString grantlee_template; void saveSettings(); + void updatePreview(); + }; #endif // TEMPLATEEDIT_H -- cgit v1.2.3-70-g09d2 From 18282aa30e191e1af0dda7261a692c8bb82dc139 Mon Sep 17 00:00:00 2001 From: Gehad elrobey Date: Sun, 12 Jul 2015 01:49:43 +0200 Subject: Printing: update preview on field changes - Trigger re-rendering on the QPixmap if fields changed. - Change template selection to custom if template text changed. Signed-off-by: Gehad elrobey Signed-off-by: Lubomir I. Ivanov --- qt-ui/templateedit.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/qt-ui/templateedit.cpp b/qt-ui/templateedit.cpp index bd4763107..8d216d998 100644 --- a/qt-ui/templateedit.cpp +++ b/qt-ui/templateedit.cpp @@ -43,7 +43,7 @@ void TemplateEdit::updatePreview() int height = ui->label->height(); QPixmap map(width * 2, height * 2); map.fill(QColor::fromRgb(255, 255, 255)); - Printer printer(&map, printOptions, templateOptions, Printer::PREVIEW); + Printer printer(&map, printOptions, &newTemplateOptions, Printer::PREVIEW); printer.previewOnePage(); ui->label->setPixmap(map.scaled(width, height, Qt::IgnoreAspectRatio)); } @@ -51,21 +51,25 @@ void TemplateEdit::updatePreview() void TemplateEdit::on_fontsize_valueChanged(int font_size) { newTemplateOptions.font_size = font_size; + updatePreview(); } void TemplateEdit::on_linespacing_valueChanged(double line_spacing) { newTemplateOptions.line_spacing = line_spacing; + updatePreview(); } void TemplateEdit::on_fontSelection_currentIndexChanged(int index) { newTemplateOptions.font_index = index; + updatePreview(); } void TemplateEdit::on_colorpalette_currentIndexChanged(int index) { newTemplateOptions.color_palette_index = index; + updatePreview(); } void TemplateEdit::saveSettings() @@ -77,8 +81,10 @@ void TemplateEdit::saveSettings() msgBox.setDefaultButton(QMessageBox::Discard); if (msgBox.exec() == QMessageBox::Save) { memcpy(templateOptions, &newTemplateOptions, sizeof(struct template_options)); - printOptions->p_template = print_options::CUSTOM; - TemplateLayout::writeTemplate("custom.html", ui->plainTextEdit->toPlainText()); + if (grantlee_template.compare(ui->plainTextEdit->toPlainText())) { + printOptions->p_template = print_options::CUSTOM; + TemplateLayout::writeTemplate("custom.html", ui->plainTextEdit->toPlainText()); + } } } } -- cgit v1.2.3-70-g09d2 From dcedc8ebea5a686f87d51daefa83728696d26b1a Mon Sep 17 00:00:00 2001 From: Gehad elrobey Date: Sun, 12 Jul 2015 04:49:16 +0200 Subject: Printing: add colors tab to edit window Select custom colors for print templates, by default there are five colors that can be used dynamically in prints. Signed-off-by: Gehad elrobey Signed-off-by: Lubomir I. Ivanov --- qt-ui/templateedit.ui | 219 +++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 218 insertions(+), 1 deletion(-) diff --git a/qt-ui/templateedit.ui b/qt-ui/templateedit.ui index de007c9b7..771fa90f8 100644 --- a/qt-ui/templateedit.ui +++ b/qt-ui/templateedit.ui @@ -39,7 +39,7 @@ - 0 + 2 @@ -187,6 +187,223 @@ + + + Colors + + + + + 10 + 30 + 411 + 171 + + + + + + + + + + 0 + 0 + + + + Background + + + + + + + + 0 + 0 + + + + color1 + + + Qt::AlignCenter + + + + + + + Edit + + + + + + + + + + + + 0 + 0 + + + + Table cells + + + + + + + + 0 + 0 + + + + color2 + + + Qt::AlignCenter + + + + + + + Edit + + + + + + + + + + + + 0 + 0 + + + + Text 1 + + + + + + + + 0 + 0 + + + + color3 + + + Qt::AlignCenter + + + + + + + Edit + + + + + + + + + + + + 0 + 0 + + + + Text 2 + + + + + + + + 0 + 0 + + + + color4 + + + Qt::AlignCenter + + + + + + + Edit + + + + + + + + + + + + 0 + 0 + + + + Borders + + + + + + + + 0 + 0 + + + + color5 + + + Qt::AlignCenter + + + + + + + Edit + + + + + + + + -- cgit v1.2.3-70-g09d2 From ad531c25fbf4094f2cbfd54018fe74d710b547f1 Mon Sep 17 00:00:00 2001 From: Gehad elrobey Date: Sun, 12 Jul 2015 05:00:03 +0200 Subject: Printing: show colors in edit tab - Add default color struct - Init the color struct with default colors - Show color text in labels - Preview colors Signed-off-by: Gehad elrobey Signed-off-by: Lubomir I. Ivanov --- qt-ui/printdialog.cpp | 11 +++++++++++ qt-ui/printoptions.h | 21 +++++++++++++++++++-- qt-ui/templateedit.cpp | 14 ++++++++++++++ 3 files changed, 44 insertions(+), 2 deletions(-) diff --git a/qt-ui/printdialog.cpp b/qt-ui/printdialog.cpp index 0a2c7898f..c999e8f25 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; + 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); @@ -41,6 +50,8 @@ PrintDialog::PrintDialog(QWidget *parent, Qt::WindowFlags f) : QDialog(parent, f templateOptions.line_spacing = s.value("line_spacing").toDouble(); } + templateOptions.color_palette = almond_colors; + // create a print options object and pass our options struct optionsWidget = new PrintOptions(this, &printOptions, &templateOptions); diff --git a/qt-ui/printoptions.h b/qt-ui/printoptions.h index 3a5c2b179..92064d223 100644 --- a/qt-ui/printoptions.h +++ b/qt-ui/printoptions.h @@ -26,13 +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.line_spacing != line_spacing + || other.color_palette != color_palette; } -}; + }; + +extern template_options::color_palette_struct almond_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 8d216d998..bb545392a 100644 --- a/qt-ui/templateedit.cpp +++ b/qt-ui/templateedit.cpp @@ -39,6 +39,7 @@ TemplateEdit::~TemplateEdit() void TemplateEdit::updatePreview() { + // update Qpixmap preview int width = ui->label->width(); int height = ui->label->height(); QPixmap map(width * 2, height * 2); @@ -46,6 +47,19 @@ void TemplateEdit::updatePreview() 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()); } void TemplateEdit::on_fontsize_valueChanged(int font_size) -- cgit v1.2.3-70-g09d2 From e1dda8df636058734ff8ab79ade210c08339b978 Mon Sep 17 00:00:00 2001 From: Gehad elrobey Date: Sun, 12 Jul 2015 05:54:00 +0200 Subject: Printing: implement edit buttons in color tab Add button group and attached edit buttons to it. Signed-off-by: Gehad elrobey Signed-off-by: Lubomir I. Ivanov --- qt-ui/templateedit.cpp | 39 +++++++++++++++++++++++++++++++++++++++ qt-ui/templateedit.h | 3 +++ 2 files changed, 42 insertions(+) diff --git a/qt-ui/templateedit.cpp b/qt-ui/templateedit.cpp index bb545392a..3d84dd63b 100644 --- a/qt-ui/templateedit.cpp +++ b/qt-ui/templateedit.cpp @@ -4,6 +4,7 @@ #include "ui_templateedit.h" #include +#include TemplateEdit::TemplateEdit(QWidget *parent, struct print_options *printOptions, struct template_options *templateOptions) : QDialog(parent), @@ -28,12 +29,22 @@ 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; } @@ -118,3 +129,31 @@ void TemplateEdit::on_buttonBox_clicked(QAbstractButton *button) break; } } + +void TemplateEdit::colorSelect(QAbstractButton *button) +{ + 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; + } + updatePreview(); +} diff --git a/qt-ui/templateedit.h b/qt-ui/templateedit.h index 21cbc0321..15b717f78 100644 --- a/qt-ui/templateedit.h +++ b/qt-ui/templateedit.h @@ -26,8 +26,11 @@ private slots: 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; -- cgit v1.2.3-70-g09d2 From ed09b80c121764aba5e26b798b09f80f7abdd228 Mon Sep 17 00:00:00 2001 From: Gehad elrobey Date: Sun, 12 Jul 2015 06:42:50 +0200 Subject: Printing: save custom color palette to QSettings - save custom colors to QSettings. - load custom colors from QSettings. - set almond color palette as default palette. Signed-off-by: Gehad elrobey Signed-off-by: Lubomir I. Ivanov --- qt-ui/printdialog.cpp | 24 ++++++++++++++++++++++-- qt-ui/printoptions.h | 2 +- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/qt-ui/printdialog.cpp b/qt-ui/printdialog.cpp index c999e8f25..31ec354c8 100644 --- a/qt-ui/printdialog.cpp +++ b/qt-ui/printdialog.cpp @@ -12,7 +12,7 @@ #define SETTINGS_GROUP "PrintDialog" -template_options::color_palette_struct almond_colors; +template_options::color_palette_struct almond_colors, custom_colors; PrintDialog::PrintDialog(QWidget *parent, Qt::WindowFlags f) : QDialog(parent, f) { @@ -36,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(); @@ -48,9 +49,21 @@ 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()); } - templateOptions.color_palette = almond_colors; + 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); @@ -116,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 92064d223..3a55c6994 100644 --- a/qt-ui/printoptions.h +++ b/qt-ui/printoptions.h @@ -49,7 +49,7 @@ struct template_options { } }; -extern template_options::color_palette_struct almond_colors; +extern template_options::color_palette_struct almond_colors, custom_colors; // should be based on a custom QPrintDialog class class PrintOptions : public QWidget { -- cgit v1.2.3-70-g09d2 From b67e06ee7b059ccf401a8f6a441ed455260adda1 Mon Sep 17 00:00:00 2001 From: Gehad elrobey Date: Mon, 13 Jul 2015 11:19:03 +0200 Subject: Printing: export color settings to grantlee Export color palette selected to grantlee backend. Signed-off-by: Gehad elrobey Signed-off-by: Lubomir I. Ivanov --- templatelayout.h | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/templatelayout.h b/templatelayout.h index 622f7d7a0..85a4699da 100644 --- a/templatelayout.h +++ b/templatelayout.h @@ -123,6 +123,16 @@ 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 -- cgit v1.2.3-70-g09d2 From c18e5ec795c309f4ca0993db86a6bf17f000270d Mon Sep 17 00:00:00 2001 From: Gehad elrobey Date: Mon, 13 Jul 2015 11:19:35 +0200 Subject: Printing: make templates support custom colors Use template_options colors instead of static colors. Signed-off-by: Gehad elrobey Signed-off-by: Lubomir I. Ivanov --- printing_templates/one_dive.html | 4 ++-- printing_templates/two_dives.html | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/printing_templates/one_dive.html b/printing_templates/one_dive.html index 52b8097c9..ce58b3847 100644 --- a/printing_templates/one_dive.html +++ b/printing_templates/one_dive.html @@ -2,7 +2,7 @@ +
{% block main_rows %} {% for dive in dives %}
@@ -206,5 +211,6 @@
{% endfor %} {% endblock %} +
diff --git a/printing_templates/two_dives.html b/printing_templates/two_dives.html index 8a9df0094..0c8eec14c 100644 --- a/printing_templates/two_dives.html +++ b/printing_templates/two_dives.html @@ -2,7 +2,7 @@ +
{% block main_rows %} {% for dive in dives %}
@@ -217,5 +222,6 @@ {% endblock %}