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.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'templatelayout.h') diff --git a/templatelayout.h b/templatelayout.h index 21eae1b80..4637a7962 100644 --- a/templatelayout.h +++ b/templatelayout.h @@ -5,7 +5,7 @@ #include "mainwindow.h" #include "printoptions.h" -int getTotalWork(); +int getTotalWork(print_options *printOptions); class TemplateLayout : public QObject { Q_OBJECT -- 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.h') 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 4a98d92489b3c404ae1d7320c27cadd9446fa5bf Mon Sep 17 00:00:00 2001 From: Gehad elrobey Date: Thu, 2 Jul 2015 22:37:14 +0200 Subject: Printing: export template_options struct to Grantlee engine Add template_options to Grantlee lookup section and export the struct fields. -font: is the font type used, must be selcted from 5 different types. -font-size: is a user selection from 9 - 18 then it is scaled to a range from 1 to 2 of the displaying view port. -color-palette: is the colors used in the template, all used colors must be referenced from here.(not yet implemented) -line-spacing: is the distance between two consecutive lines in the dive notes text. Signed-off-by: Gehad elrobey Signed-off-by: Lubomir I. Ivanov --- templatelayout.h | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'templatelayout.h') diff --git a/templatelayout.h b/templatelayout.h index a894ce4ca..854a16259 100644 --- a/templatelayout.h +++ b/templatelayout.h @@ -104,4 +104,25 @@ else if (property == "notes") return object.notes(); GRANTLEE_END_LOOKUP +GRANTLEE_BEGIN_LOOKUP(template_options) +if (property == "font") { + switch (object.font_index) { + case 0: + return "Arial, Helvetica, sans-serif"; + case 1: + return "Impact, Charcoal, sans-serif"; + case 2: + return "Georgia, serif"; + case 3: + return "Courier, monospace"; + case 4: + return "Verdana, Geneva, sans-serif"; + } +} else if (property == "font_size") { + return object.font_size / 9.0; +} else if (property == "line_spacing") { + return object.line_spacing; +} +GRANTLEE_END_LOOKUP + #endif -- 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.h') 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 From c44496e23d3e16ec6b5622eea73ae39d991e27bf Mon Sep 17 00:00:00 2001 From: Gehad elrobey Date: Sun, 5 Jul 2015 07:26:39 +0200 Subject: Printing: move template_options to print_options.h Signed-off-by: Gehad elrobey Signed-off-by: Lubomir I. Ivanov --- qt-ui/printoptions.cpp | 2 +- qt-ui/printoptions.h | 7 +++++++ qt-ui/templateedit.cpp | 4 +++- qt-ui/templateedit.h | 10 ++-------- templatelayout.h | 1 - 5 files changed, 13 insertions(+), 11 deletions(-) (limited to 'templatelayout.h') diff --git a/qt-ui/printoptions.cpp b/qt-ui/printoptions.cpp index 08be76588..f3c6eb14c 100644 --- a/qt-ui/printoptions.cpp +++ b/qt-ui/printoptions.cpp @@ -108,6 +108,6 @@ void PrintOptions::on_printTemplate_currentIndexChanged(int index) void PrintOptions::on_editButton_clicked() { - TemplateEdit te(this, templateOptions); + TemplateEdit te(this, printOptions, templateOptions); te.exec(); } diff --git a/qt-ui/printoptions.h b/qt-ui/printoptions.h index c33addc83..d96b27a53 100644 --- a/qt-ui/printoptions.h +++ b/qt-ui/printoptions.h @@ -21,6 +21,13 @@ struct print_options { bool landscape; }; +struct template_options { + int font_index; + int color_palette_index; + double font_size; + double line_spacing; +}; + // should be based on a custom QPrintDialog class class PrintOptions : public QWidget { Q_OBJECT diff --git a/qt-ui/templateedit.cpp b/qt-ui/templateedit.cpp index a4236d036..aecfdc434 100644 --- a/qt-ui/templateedit.cpp +++ b/qt-ui/templateedit.cpp @@ -1,12 +1,14 @@ #include "templateedit.h" +#include "printoptions.h" #include "ui_templateedit.h" -TemplateEdit::TemplateEdit(QWidget *parent, struct template_options *templateOptions) : +TemplateEdit::TemplateEdit(QWidget *parent, struct print_options *printOptions, struct template_options *templateOptions) : QDialog(parent), ui(new Ui::TemplateEdit) { ui->setupUi(this); this->templateOptions = templateOptions; + this->printOptions = printOptions; // restore the settings and init the UI ui->fontSelection->setCurrentIndex(templateOptions->font_index); diff --git a/qt-ui/templateedit.h b/qt-ui/templateedit.h index 73a5e9fbb..dc38d11fc 100644 --- a/qt-ui/templateedit.h +++ b/qt-ui/templateedit.h @@ -3,13 +3,6 @@ #include -struct template_options { - int font_index; - int color_palette_index; - double font_size; - double line_spacing; -}; - namespace Ui { class TemplateEdit; } @@ -19,7 +12,7 @@ class TemplateEdit : public QDialog Q_OBJECT public: - explicit TemplateEdit(QWidget *parent, struct template_options *templateOptions); + explicit TemplateEdit(QWidget *parent, struct print_options *printOptions, struct template_options *templateOptions); ~TemplateEdit(); private slots: void on_fontsize_valueChanged(int font_size); @@ -33,6 +26,7 @@ private slots: private: Ui::TemplateEdit *ui; struct template_options *templateOptions; + struct print_options *printOptions; }; #endif // TEMPLATEEDIT_H diff --git a/templatelayout.h b/templatelayout.h index 3826c6c00..622f7d7a0 100644 --- a/templatelayout.h +++ b/templatelayout.h @@ -4,7 +4,6 @@ #include #include "mainwindow.h" #include "printoptions.h" -#include "templateedit.h" int getTotalWork(print_options *printOptions); -- cgit v1.2.3-70-g09d2