From 1faa198020de343004a7f1db85a83e6bc0ef8b34 Mon Sep 17 00:00:00 2001 From: Gehad elrobey Date: Sun, 21 Jun 2015 06:13:22 +0200 Subject: Printing: print all dives if 'print selected' is unchecked User can choose either to print all dives or print selected dives only. Signed-off-by: Gehad elrobey Signed-off-by: Lubomir I. Ivanov --- templatelayout.cpp | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) (limited to 'templatelayout.cpp') diff --git a/templatelayout.cpp b/templatelayout.cpp index 5f47b64a2..81a4d5f03 100644 --- a/templatelayout.cpp +++ b/templatelayout.cpp @@ -4,11 +4,19 @@ #include "helpers.h" #include "display.h" -int getTotalWork() +int getTotalWork(print_options *printOptions) { - // return the correct number depending on all/selected dives - // but don't return 0 as we might divide by this number - return amount_selected ? amount_selected : 1; + if (printOptions->print_selected) { + // return the correct number depending on all/selected dives + // but don't return 0 as we might divide by this number + return amount_selected ? amount_selected : 1; + } + int dives = 0, i; + struct dive *dive; + for_each_dive (i, dive) { + dives++; + } + return dives; } TemplateLayout::TemplateLayout(print_options *PrintOptions) : @@ -25,7 +33,7 @@ TemplateLayout::~TemplateLayout() QString TemplateLayout::generate() { int progress = 0; - int totalWork = getTotalWork(); + int totalWork = getTotalWork(PrintOptions); QString templateName; QString htmlContent; @@ -45,7 +53,7 @@ QString TemplateLayout::generate() int i; for_each_dive (i, dive) { //TODO check for exporting selected dives only - if (!dive->selected) + if (!dive->selected && PrintOptions->print_selected) continue; Dive d(dive); diveList.append(QVariant::fromValue(d)); -- cgit v1.2.3-70-g09d2 From bc80fc8849a01ac156c5e54ba8ef3fe04e1aaee3 Mon Sep 17 00:00:00 2001 From: Gehad elrobey Date: Thu, 2 Jul 2015 22:26:31 +0200 Subject: Printing: pass the template_options struct to TemplateLayout The template_options struct needs to be passed to TemplateLayout constructor. Signed-off-by: Gehad elrobey Signed-off-by: Lubomir I. Ivanov --- printer.cpp | 5 +++-- printer.h | 4 +++- qt-ui/printdialog.cpp | 2 +- templatelayout.cpp | 5 ++++- templatelayout.h | 5 ++++- 5 files changed, 15 insertions(+), 6 deletions(-) (limited to 'templatelayout.cpp') diff --git a/printer.cpp b/printer.cpp index 5c93d2fed..83cc42d18 100644 --- a/printer.cpp +++ b/printer.cpp @@ -6,10 +6,11 @@ #include #include -Printer::Printer(QPrinter *printer, print_options *printOptions) +Printer::Printer(QPrinter *printer, print_options *printOptions, template_options *templateOptions) { this->printer = printer; this->printOptions = printOptions; + this->templateOptions = templateOptions; dpi = 0; done = 0; } @@ -116,7 +117,7 @@ void Printer::templateProgessUpdated(int value) void Printer::print() { - TemplateLayout t(printOptions); + TemplateLayout t(printOptions, templateOptions); webView = new QWebView(); connect(&t, SIGNAL(progressUpdated(int)), this, SLOT(templateProgessUpdated(int))); diff --git a/printer.h b/printer.h index cba82e607..4ab65834a 100644 --- a/printer.h +++ b/printer.h @@ -8,6 +8,7 @@ #include "profile/profilewidget2.h" #include "printoptions.h" +#include "templateedit.h" class Printer : public QObject { Q_OBJECT @@ -16,6 +17,7 @@ private: QPrinter *printer; QWebView *webView; print_options *printOptions; + template_options *templateOptions; QSize pageSize; int done; int dpi; @@ -26,7 +28,7 @@ private slots: void templateProgessUpdated(int value); public: - Printer(QPrinter *printer, print_options *printOptions); + Printer(QPrinter *printer, print_options *printOptions, template_options *templateOptions); void print(); signals: diff --git a/qt-ui/printdialog.cpp b/qt-ui/printdialog.cpp index 23c6f225e..9ff29e67b 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); + printer = new Printer(&qprinter, &printOptions, &templateOptions); QVBoxLayout *layout = new QVBoxLayout(this); setLayout(layout); diff --git a/templatelayout.cpp b/templatelayout.cpp index 81a4d5f03..2a5bb8ff7 100644 --- a/templatelayout.cpp +++ b/templatelayout.cpp @@ -19,10 +19,11 @@ int getTotalWork(print_options *printOptions) return dives; } -TemplateLayout::TemplateLayout(print_options *PrintOptions) : +TemplateLayout::TemplateLayout(print_options *PrintOptions, template_options *templateOptions) : m_engine(NULL) { this->PrintOptions = PrintOptions; + this->templateOptions = templateOptions; } TemplateLayout::~TemplateLayout() @@ -45,6 +46,7 @@ QString TemplateLayout::generate() m_engine->addTemplateLoader(m_templateLoader); Grantlee::registerMetaType(); + Grantlee::registerMetaType(); QVariantHash mapping; QVariantList diveList; @@ -61,6 +63,7 @@ QString TemplateLayout::generate() emit progressUpdated(progress * 100.0 / totalWork); } mapping.insert("dives", diveList); + mapping.insert("template_options", QVariant::fromValue(*templateOptions)); Grantlee::Context c(mapping); diff --git a/templatelayout.h b/templatelayout.h index 4637a7962..a894ce4ca 100644 --- a/templatelayout.h +++ b/templatelayout.h @@ -4,19 +4,21 @@ #include #include "mainwindow.h" #include "printoptions.h" +#include "templateedit.h" int getTotalWork(print_options *printOptions); class TemplateLayout : public QObject { Q_OBJECT public: - TemplateLayout(print_options *PrintOptions); + TemplateLayout(print_options *PrintOptions, template_options *templateOptions); ~TemplateLayout(); QString generate(); private: Grantlee::Engine *m_engine; print_options *PrintOptions; + template_options *templateOptions; signals: void progressUpdated(int value); @@ -75,6 +77,7 @@ public: }; Q_DECLARE_METATYPE(Dive) +Q_DECLARE_METATYPE(template_options) GRANTLEE_BEGIN_LOOKUP(Dive) if (property == "number") -- cgit v1.2.3-70-g09d2 From c35092f5c9ce30f2b8df4c554302a3e7c8716a07 Mon Sep 17 00:00:00 2001 From: Gehad elrobey Date: Sat, 4 Jul 2015 23:02:17 +0200 Subject: Printing: add custom options to the PrintDialog Add: -custom.html template -custom template to print_options struct -options to the options dialog Signed-off-by: Gehad elrobey Signed-off-by: Lubomir I. Ivanov --- printing_templates/custom.html | 50 ++++++++++++++++++++++++++++++++++++++++++ qt-ui/printoptions.cpp | 6 +++++ qt-ui/printoptions.h | 3 ++- qt-ui/printoptions.ui | 5 +++++ templatelayout.cpp | 2 ++ 5 files changed, 65 insertions(+), 1 deletion(-) create mode 100644 printing_templates/custom.html (limited to 'templatelayout.cpp') diff --git a/printing_templates/custom.html b/printing_templates/custom.html new file mode 100644 index 000000000..52fdb4b49 --- /dev/null +++ b/printing_templates/custom.html @@ -0,0 +1,50 @@ + + + + + +{% block main_rows %} + {% for dive in dives %} +
+
+

This template is empty

+ +
+
+ {% endfor %} +{% endblock %} + + diff --git a/qt-ui/printoptions.cpp b/qt-ui/printoptions.cpp index a7c520b21..cd38e3560 100644 --- a/qt-ui/printoptions.cpp +++ b/qt-ui/printoptions.cpp @@ -36,6 +36,9 @@ void PrintOptions::setup(struct print_options *printOpt) case print_options::TWO_DIVE: ui.printTemplate->setCurrentIndex(1); break; + case print_options::CUSTOM: + ui.printTemplate->setCurrentIndex(2); + break; } // general print option checkboxes @@ -97,6 +100,9 @@ void PrintOptions::on_printTemplate_currentIndexChanged(int index) case 1: printOptions->p_template = print_options::TWO_DIVE; break; + case 2: + printOptions->p_template = print_options::CUSTOM; + break; } } diff --git a/qt-ui/printoptions.h b/qt-ui/printoptions.h index 9bacd4e90..1d806b116 100644 --- a/qt-ui/printoptions.h +++ b/qt-ui/printoptions.h @@ -13,7 +13,8 @@ struct print_options { } type; enum print_template { ONE_DIVE, - TWO_DIVE + TWO_DIVE, + CUSTOM } p_template; bool print_selected; bool color_selected; diff --git a/qt-ui/printoptions.ui b/qt-ui/printoptions.ui index 632b9cdaf..7e66d4cb0 100644 --- a/qt-ui/printoptions.ui +++ b/qt-ui/printoptions.ui @@ -140,6 +140,11 @@ Two dives per page + + + Custom template + + diff --git a/templatelayout.cpp b/templatelayout.cpp index 2a5bb8ff7..fcdd22902 100644 --- a/templatelayout.cpp +++ b/templatelayout.cpp @@ -71,6 +71,8 @@ QString TemplateLayout::generate() templateName = "one_dive.html"; } else if (PrintOptions->p_template == print_options::TWO_DIVE) { templateName = "two_dives.html"; + } else if (PrintOptions->p_template == print_options::CUSTOM) { + templateName = "custom.html"; } Grantlee::Template t = m_engine->loadByName(templateName); if (!t || t->error()) { -- cgit v1.2.3-70-g09d2 From 605e1e2d93996f57b3e48f698d840f517d84a99d Mon Sep 17 00:00:00 2001 From: Gehad elrobey Date: Sun, 5 Jul 2015 06:21:39 +0200 Subject: Printing: add functions that read/write a template Read/write templates from files. Signed-off-by: Gehad elrobey Signed-off-by: Lubomir I. Ivanov --- templatelayout.cpp | 19 +++++++++++++++++++ templatelayout.h | 2 ++ 2 files changed, 21 insertions(+) (limited to 'templatelayout.cpp') diff --git a/templatelayout.cpp b/templatelayout.cpp index fcdd22902..9a9dc9656 100644 --- a/templatelayout.cpp +++ b/templatelayout.cpp @@ -89,6 +89,25 @@ QString TemplateLayout::generate() return htmlContent; } +QString TemplateLayout::readTemplate(QString template_name) +{ + QFile qfile(getSubsurfaceDataPath("printing_templates") + QDir::separator() + template_name); + if (qfile.open(QFile::ReadOnly | QFile::Text)) { + QTextStream in(&qfile); + return in.readAll(); + } + return ""; +} + +void TemplateLayout::writeTemplate(QString template_name, QString grantlee_template) +{ + QFile qfile(getSubsurfaceDataPath("printing_templates") + QDir::separator() + template_name); + if (qfile.open(QFile::ReadWrite | QFile::Text)) { + qfile.write(grantlee_template.toUtf8().data()); + qfile.close(); + } +} + Dive::Dive() : m_number(-1), dive(NULL) diff --git a/templatelayout.h b/templatelayout.h index 854a16259..3826c6c00 100644 --- a/templatelayout.h +++ b/templatelayout.h @@ -14,6 +14,8 @@ public: TemplateLayout(print_options *PrintOptions, template_options *templateOptions); ~TemplateLayout(); QString generate(); + static QString readTemplate(QString template_name); + static void writeTemplate(QString template_name, QString grantlee_template); private: Grantlee::Engine *m_engine; -- cgit v1.2.3-70-g09d2