From bc0b443afd73e0bc7c18b293d051aa01bf82d99f Mon Sep 17 00:00:00 2001 From: Gehad elrobey Date: Sun, 21 Jun 2015 04:59:15 +0200 Subject: Printing: add QPrintPreviewDialog to main dialog Add preview dialog that shows the printer contents before printing. Signed-off-by: Gehad elrobey Signed-off-by: Lubomir I. Ivanov --- qt-ui/printdialog.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'qt-ui') diff --git a/qt-ui/printdialog.cpp b/qt-ui/printdialog.cpp index 6f30f89f5..9949b104d 100644 --- a/qt-ui/printdialog.cpp +++ b/qt-ui/printdialog.cpp @@ -93,6 +93,11 @@ void PrintDialog::onFinished() void PrintDialog::previewClicked(void) { + QPrintPreviewDialog previewDialog(&qprinter, this, Qt::Window + | Qt::CustomizeWindowHint | Qt::WindowCloseButtonHint + | Qt::WindowTitleHint); + connect(&previewDialog, SIGNAL(paintRequested(QPrinter *)), this, SLOT(onPaintRequested(QPrinter *))); + previewDialog.exec(); } void PrintDialog::printClicked(void) @@ -115,5 +120,9 @@ void PrintDialog::printClicked(void) void PrintDialog::onPaintRequested(QPrinter *printerPtr) { + connect(printer, SIGNAL(progessUpdated(int)), progressBar, SLOT(setValue(int))); + printer->print(); + progressBar->setValue(0); + disconnect(printer, SIGNAL(progessUpdated(int)), progressBar, SLOT(setValue(int))); } #endif -- cgit v1.2.3-70-g09d2 From ce3d2abd83717abb1b4b5c8a8eecc04ab1d45e66 Mon Sep 17 00:00:00 2001 From: Gehad elrobey Date: Wed, 24 Jun 2015 05:12:45 +0200 Subject: Printing: show warning message for WIP features Show warning message before proceeding to print 'Table' or 'Statistics' print layout. This should be used during the development phase only. Signed-off-by: Gehad elrobey Signed-off-by: Lubomir I. Ivanov --- qt-ui/printdialog.cpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'qt-ui') diff --git a/qt-ui/printdialog.cpp b/qt-ui/printdialog.cpp index 9949b104d..6e193d9bd 100644 --- a/qt-ui/printdialog.cpp +++ b/qt-ui/printdialog.cpp @@ -8,6 +8,7 @@ #include #include #include +#include #define SETTINGS_GROUP "PrintDialog" @@ -93,6 +94,13 @@ void PrintDialog::onFinished() void PrintDialog::previewClicked(void) { + if (printOptions.type == print_options::TABLE || printOptions.type == print_options::STATISTICS) { + QMessageBox msgBox; + msgBox.setText("This feature is not implemented yet"); + msgBox.exec(); + return; + } + QPrintPreviewDialog previewDialog(&qprinter, this, Qt::Window | Qt::CustomizeWindowHint | Qt::WindowCloseButtonHint | Qt::WindowTitleHint); @@ -102,6 +110,13 @@ void PrintDialog::previewClicked(void) void PrintDialog::printClicked(void) { + if (printOptions.type == print_options::TABLE || printOptions.type == print_options::STATISTICS) { + QMessageBox msgBox; + msgBox.setText("This feature is not implemented yet"); + msgBox.exec(); + return; + } + QPrintDialog printDialog(&qprinter, this); if (printDialog.exec() == QDialog::Accepted) { switch (printOptions.type) { -- cgit v1.2.3-70-g09d2 From 963e09ad7b01d99537b59037e2cd1fbedf480261 Mon Sep 17 00:00:00 2001 From: Gehad elrobey Date: Fri, 26 Jun 2015 04:21:03 +0200 Subject: Printing: add TemplateEdit form to source tree The TemplateEdit class works to customize the tempalate before printing, User can select the font-size, font-type, color-palette, linespacing and editing the template HTML code. Signed-off-by: Gehad elrobey Signed-off-by: Lubomir I. Ivanov --- CMakeLists.txt | 1 + qt-ui/templateedit.cpp | 15 +++ qt-ui/templateedit.h | 22 +++++ qt-ui/templateedit.ui | 262 +++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 300 insertions(+) create mode 100644 qt-ui/templateedit.cpp create mode 100644 qt-ui/templateedit.h create mode 100644 qt-ui/templateedit.ui (limited to 'qt-ui') diff --git a/CMakeLists.txt b/CMakeLists.txt index 534e8e2b6..f4f49f805 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -118,6 +118,7 @@ else() set(SUBSURFACE_PRINTING_SRCS printer.cpp templatelayout.cpp + qt-ui/templateedit.cpp ) set(PRINTING_PKG PrintSupport) set(PRINTING_LIB Qt5::PrintSupport) diff --git a/qt-ui/templateedit.cpp b/qt-ui/templateedit.cpp new file mode 100644 index 000000000..1db62b619 --- /dev/null +++ b/qt-ui/templateedit.cpp @@ -0,0 +1,15 @@ +#include "templateedit.h" +#include "ui_templateedit.h" + +TemplateEdit::TemplateEdit(QWidget *parent) : + QDialog(parent), + ui(new Ui::TemplateEdit) +{ + ui->setupUi(this); + this->templateOptions = templateOptions; +} + +TemplateEdit::~TemplateEdit() +{ + delete ui; +} diff --git a/qt-ui/templateedit.h b/qt-ui/templateedit.h new file mode 100644 index 000000000..f1003e461 --- /dev/null +++ b/qt-ui/templateedit.h @@ -0,0 +1,22 @@ +#ifndef TEMPLATEEDIT_H +#define TEMPLATEEDIT_H + +#include + +namespace Ui { +class TemplateEdit; +} + +class TemplateEdit : public QDialog +{ + Q_OBJECT + +public: + explicit TemplateEdit(QWidget *parent = 0); + ~TemplateEdit(); + +private: + Ui::TemplateEdit *ui; +}; + +#endif // TEMPLATEEDIT_H diff --git a/qt-ui/templateedit.ui b/qt-ui/templateedit.ui new file mode 100644 index 000000000..26fe15926 --- /dev/null +++ b/qt-ui/templateedit.ui @@ -0,0 +1,262 @@ + + + TemplateEdit + + + + 0 + 0 + 774 + 433 + + + + Edit Template + + + + + 400 + 380 + 341 + 32 + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + 300 + 30 + 441 + 331 + + + + 0 + + + + Style + + + + + 10 + 20 + 401 + 171 + + + + + + + + + Font + + + + + + + + Arial + + + + + Impact + + + + + Georgia + + + + + Courier + + + + + Verdana + + + + + + + + + + + + Font size + + + + + + + 9 + + + 18 + + + + + + + + + + + Color pallet + + + + + + + + Almond + + + + + + + + + + + + Line spacing + + + + + + + 1.000000000000000 + + + 3.000000000000000 + + + 0.250000000000000 + + + 1.250000000000000 + + + + + + + + + + + Template + + + + + 0 + 0 + 441 + 301 + + + + Qt::ScrollBarAsNeeded + + + QPlainTextEdit::NoWrap + + + + + + + + 20 + 60 + 251 + 311 + + + + + about:blank + + + + + + + 30 + 30 + 59 + 14 + + + + Preview + + + + + + QWebView + QWidget +
QtWebKitWidgets/QWebView
+
+
+ + + + buttonBox + accepted() + TemplateEdit + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + TemplateEdit + reject() + + + 316 + 260 + + + 286 + 274 + + + + +
-- cgit v1.2.3-70-g09d2 From ff594c65e3597f53164302f79df05c0b5e70980c Mon Sep 17 00:00:00 2001 From: Gehad elrobey Date: Fri, 26 Jun 2015 04:21:31 +0200 Subject: Printing: call TemplateEdit when edit is triggered Edit button should open TemplateEdit dialog. Signed-off-by: Gehad elrobey Signed-off-by: Lubomir I. Ivanov --- qt-ui/printoptions.cpp | 7 +++++++ qt-ui/printoptions.h | 1 + 2 files changed, 8 insertions(+) (limited to 'qt-ui') diff --git a/qt-ui/printoptions.cpp b/qt-ui/printoptions.cpp index e2684b6ed..0609b2b13 100644 --- a/qt-ui/printoptions.cpp +++ b/qt-ui/printoptions.cpp @@ -1,4 +1,5 @@ #include "printoptions.h" +#include "templateedit.h" #include PrintOptions::PrintOptions(QWidget *parent, struct print_options *printOpt) @@ -97,3 +98,9 @@ void PrintOptions::on_printTemplate_currentIndexChanged(int index) break; } } + +void PrintOptions::on_editButton_clicked() +{ + TemplateEdit te; + te.exec(); +} diff --git a/qt-ui/printoptions.h b/qt-ui/printoptions.h index 13ef4e310..324697762 100644 --- a/qt-ui/printoptions.h +++ b/qt-ui/printoptions.h @@ -41,6 +41,7 @@ slots: void on_radioTablePrint_clicked(bool check); void on_radioDiveListPrint_clicked(bool check); void on_printTemplate_currentIndexChanged(int index); + void on_editButton_clicked(); }; #endif // PRINTOPTIONS_H -- cgit v1.2.3-70-g09d2 From a600ea5201f55a3182cb24a0553d02aefad2c51b Mon Sep 17 00:00:00 2001 From: Gehad elrobey Date: Mon, 29 Jun 2015 03:16:19 +0200 Subject: Printing: add template_options struct that contains template The template_options struct holds the settings variables in the code. Signed-off-by: Gehad elrobey Signed-off-by: Lubomir I. Ivanov --- qt-ui/printdialog.cpp | 2 +- qt-ui/printdialog.h | 2 ++ qt-ui/printoptions.cpp | 5 +++-- qt-ui/printoptions.h | 3 ++- qt-ui/templateedit.cpp | 2 +- qt-ui/templateedit.h | 11 +++++++++-- 6 files changed, 18 insertions(+), 7 deletions(-) (limited to 'qt-ui') diff --git a/qt-ui/printdialog.cpp b/qt-ui/printdialog.cpp index 6e193d9bd..341a84083 100644 --- a/qt-ui/printdialog.cpp +++ b/qt-ui/printdialog.cpp @@ -34,7 +34,7 @@ PrintDialog::PrintDialog(QWidget *parent, Qt::WindowFlags f) : QDialog(parent, f } // create a print options object and pass our options struct - optionsWidget = new PrintOptions(this, &printOptions); + optionsWidget = new PrintOptions(this, &printOptions, &templateOptions); // create a new printer object printer = new Printer(&qprinter, &printOptions); diff --git a/qt-ui/printdialog.h b/qt-ui/printdialog.h index a34037442..a00c4c5d9 100644 --- a/qt-ui/printdialog.h +++ b/qt-ui/printdialog.h @@ -6,6 +6,7 @@ #include #include "printoptions.h" #include "printer.h" +#include "templateedit.h" class QProgressBar; class PrintOptions; @@ -24,6 +25,7 @@ private: Printer *printer; QPrinter qprinter; struct print_options printOptions; + struct template_options templateOptions; private slots: diff --git a/qt-ui/printoptions.cpp b/qt-ui/printoptions.cpp index 0609b2b13..a7c520b21 100644 --- a/qt-ui/printoptions.cpp +++ b/qt-ui/printoptions.cpp @@ -2,7 +2,7 @@ #include "templateedit.h" #include -PrintOptions::PrintOptions(QWidget *parent, struct print_options *printOpt) +PrintOptions::PrintOptions(QWidget *parent, struct print_options *printOpt, struct template_options *templateOpt) { hasSetupSlots = false; ui.setupUi(this); @@ -11,6 +11,7 @@ PrintOptions::PrintOptions(QWidget *parent, struct print_options *printOpt) if (!printOpt) return; setup(printOpt); + templateOptions = templateOpt; } void PrintOptions::setup(struct print_options *printOpt) @@ -101,6 +102,6 @@ void PrintOptions::on_printTemplate_currentIndexChanged(int index) void PrintOptions::on_editButton_clicked() { - TemplateEdit te; + TemplateEdit te(this, templateOptions); te.exec(); } diff --git a/qt-ui/printoptions.h b/qt-ui/printoptions.h index 324697762..9bacd4e90 100644 --- a/qt-ui/printoptions.h +++ b/qt-ui/printoptions.h @@ -25,12 +25,13 @@ class PrintOptions : public QWidget { Q_OBJECT public: - explicit PrintOptions(QWidget *parent = 0, struct print_options *printOpt = 0); + explicit PrintOptions(QWidget *parent, struct print_options *printOpt, struct template_options *templateOpt); void setup(struct print_options *printOpt); private: Ui::PrintOptions ui; struct print_options *printOptions; + struct template_options *templateOptions; bool hasSetupSlots; private diff --git a/qt-ui/templateedit.cpp b/qt-ui/templateedit.cpp index 1db62b619..40e14c221 100644 --- a/qt-ui/templateedit.cpp +++ b/qt-ui/templateedit.cpp @@ -1,7 +1,7 @@ #include "templateedit.h" #include "ui_templateedit.h" -TemplateEdit::TemplateEdit(QWidget *parent) : +TemplateEdit::TemplateEdit(QWidget *parent, struct template_options *templateOptions) : QDialog(parent), ui(new Ui::TemplateEdit) { diff --git a/qt-ui/templateedit.h b/qt-ui/templateedit.h index f1003e461..2790c619b 100644 --- a/qt-ui/templateedit.h +++ b/qt-ui/templateedit.h @@ -3,6 +3,13 @@ #include +struct template_options { + int font_index; + int color_palette_index; + double font_size; + double line_spacing; +}; + namespace Ui { class TemplateEdit; } @@ -12,11 +19,11 @@ class TemplateEdit : public QDialog Q_OBJECT public: - explicit TemplateEdit(QWidget *parent = 0); + explicit TemplateEdit(QWidget *parent, struct template_options *templateOptions); ~TemplateEdit(); - private: Ui::TemplateEdit *ui; + struct template_options *templateOptions; }; #endif // TEMPLATEEDIT_H -- cgit v1.2.3-70-g09d2 From 71561e720dbfd85b3cb724dd1eb509b0d230d5db Mon Sep 17 00:00:00 2001 From: Gehad elrobey Date: Mon, 29 Jun 2015 03:24:29 +0200 Subject: Printing: add QSettings for TemplateEdit class TemplateOptions struct must be saved to QSettings after the window is closed, also it must be recalled when initializing the window. Signed-off-by: Gehad elrobey Signed-off-by: Lubomir I. Ivanov --- qt-ui/printdialog.cpp | 17 ++++++++++++++++- qt-ui/templateedit.cpp | 26 ++++++++++++++++++++++++++ qt-ui/templateedit.h | 9 +++++++++ 3 files changed, 51 insertions(+), 1 deletion(-) (limited to 'qt-ui') diff --git a/qt-ui/printdialog.cpp b/qt-ui/printdialog.cpp index 341a84083..23c6f225e 100644 --- a/qt-ui/printdialog.cpp +++ b/qt-ui/printdialog.cpp @@ -23,6 +23,10 @@ PrintDialog::PrintDialog(QWidget *parent, Qt::WindowFlags f) : QDialog(parent, f printOptions.landscape = false; printOptions.p_template = print_options::ONE_DIVE; printOptions.type = print_options::DIVELIST; + templateOptions.font_index = 0; + templateOptions.font_size = 9; + templateOptions.color_palette_index = 0; + templateOptions.line_spacing = 1; } else { s.beginGroup(SETTINGS_GROUP); printOptions.type = (print_options::print_type)s.value("type").toInt(); @@ -31,6 +35,10 @@ PrintDialog::PrintDialog(QWidget *parent, Qt::WindowFlags f) : QDialog(parent, f printOptions.landscape = s.value("landscape").toBool(); printOptions.p_template = (print_options::print_template)s.value("template_selected").toInt(); qprinter.setOrientation((QPrinter::Orientation)printOptions.landscape); + templateOptions.font_index = s.value("font").toInt(); + 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(); } // create a print options object and pass our options struct @@ -83,13 +91,20 @@ PrintDialog::PrintDialog(QWidget *parent, Qt::WindowFlags f) : QDialog(parent, f void PrintDialog::onFinished() { - // save the settings QSettings s; s.beginGroup(SETTINGS_GROUP); + + // save print paper settings s.setValue("type", printOptions.type); s.setValue("print_selected", printOptions.print_selected); s.setValue("color_selected", printOptions.color_selected); s.setValue("template_selected", printOptions.p_template); + + // save template settings + s.setValue("font", templateOptions.font_index); + s.setValue("font_size", templateOptions.font_size); + s.setValue("color_palette", templateOptions.color_palette_index); + s.setValue("line_spacing", templateOptions.line_spacing); } void PrintDialog::previewClicked(void) diff --git a/qt-ui/templateedit.cpp b/qt-ui/templateedit.cpp index 40e14c221..a4236d036 100644 --- a/qt-ui/templateedit.cpp +++ b/qt-ui/templateedit.cpp @@ -7,9 +7,35 @@ TemplateEdit::TemplateEdit(QWidget *parent, struct template_options *templateOpt { ui->setupUi(this); this->templateOptions = templateOptions; + + // restore the settings and init the UI + ui->fontSelection->setCurrentIndex(templateOptions->font_index); + ui->fontsize->setValue(templateOptions->font_size); + ui->colorpalette->setCurrentIndex(templateOptions->color_palette_index); + ui->linespacing->setValue(templateOptions->line_spacing); } TemplateEdit::~TemplateEdit() { delete ui; } + +void TemplateEdit::on_fontsize_valueChanged(int font_size) +{ + templateOptions->font_size = font_size; +} + +void TemplateEdit::on_linespacing_valueChanged(double line_spacing) +{ + templateOptions->line_spacing = line_spacing; +} + +void TemplateEdit::on_fontSelection_currentIndexChanged(int index) +{ + templateOptions->font_index = index; +} + +void TemplateEdit::on_colorpalette_currentIndexChanged(int index) +{ + templateOptions->color_palette_index = index; +} diff --git a/qt-ui/templateedit.h b/qt-ui/templateedit.h index 2790c619b..73a5e9fbb 100644 --- a/qt-ui/templateedit.h +++ b/qt-ui/templateedit.h @@ -21,6 +21,15 @@ class TemplateEdit : public QDialog public: explicit TemplateEdit(QWidget *parent, struct template_options *templateOptions); ~TemplateEdit(); +private slots: + void on_fontsize_valueChanged(int font_size); + + void on_linespacing_valueChanged(double line_spacing); + + void on_fontSelection_currentIndexChanged(int index); + + void on_colorpalette_currentIndexChanged(int index); + private: Ui::TemplateEdit *ui; struct template_options *templateOptions; -- 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 'qt-ui') 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 'qt-ui') 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 a70cea95e8c67805945eda8e874a12f67daebe9f Mon Sep 17 00:00:00 2001 From: Gehad elrobey Date: Sun, 5 Jul 2015 06:28:23 +0200 Subject: Printing: refactor the print options class -Remove unneeded parameter to member variable -Check if template_options struct is valid Signed-off-by: Gehad elrobey Signed-off-by: Lubomir I. Ivanov --- qt-ui/printoptions.cpp | 8 ++++---- qt-ui/printoptions.h | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) (limited to 'qt-ui') diff --git a/qt-ui/printoptions.cpp b/qt-ui/printoptions.cpp index cd38e3560..08be76588 100644 --- a/qt-ui/printoptions.cpp +++ b/qt-ui/printoptions.cpp @@ -8,15 +8,15 @@ PrintOptions::PrintOptions(QWidget *parent, struct print_options *printOpt, stru ui.setupUi(this); if (parent) setParent(parent); - if (!printOpt) + if (!printOpt || !templateOpt) return; - setup(printOpt); templateOptions = templateOpt; + printOptions = printOpt; + setup(); } -void PrintOptions::setup(struct print_options *printOpt) +void PrintOptions::setup() { - printOptions = printOpt; // print type radio buttons switch (printOptions->type) { case print_options::DIVELIST: diff --git a/qt-ui/printoptions.h b/qt-ui/printoptions.h index 1d806b116..c33addc83 100644 --- a/qt-ui/printoptions.h +++ b/qt-ui/printoptions.h @@ -27,7 +27,7 @@ class PrintOptions : public QWidget { public: explicit PrintOptions(QWidget *parent, struct print_options *printOpt, struct template_options *templateOpt); - void setup(struct print_options *printOpt); + void setup(); private: Ui::PrintOptions ui; -- 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 'qt-ui') 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 From cc53dc7acf801f022612678f697e6d76c2443153 Mon Sep 17 00:00:00 2001 From: Gehad elrobey Date: Sun, 5 Jul 2015 07:29:46 +0200 Subject: Printing: implement QPlainTextEdit in TemplateEdit This is the main area to edit the templates inside Subsurface. Whenever the user edits a template the edited template is saved in custom.html and custom.html is considered the selected printing template. Signed-off-by: Gehad elrobey Signed-off-by: Lubomir I. Ivanov --- qt-ui/printoptions.cpp | 1 + qt-ui/templateedit.cpp | 18 ++++++++++++++++++ qt-ui/templateedit.h | 4 ++++ 3 files changed, 23 insertions(+) (limited to 'qt-ui') diff --git a/qt-ui/printoptions.cpp b/qt-ui/printoptions.cpp index f3c6eb14c..0e6a0b320 100644 --- a/qt-ui/printoptions.cpp +++ b/qt-ui/printoptions.cpp @@ -110,4 +110,5 @@ void PrintOptions::on_editButton_clicked() { TemplateEdit te(this, printOptions, templateOptions); te.exec(); + setup(); } diff --git a/qt-ui/templateedit.cpp b/qt-ui/templateedit.cpp index aecfdc434..82a71ea32 100644 --- a/qt-ui/templateedit.cpp +++ b/qt-ui/templateedit.cpp @@ -15,6 +15,16 @@ TemplateEdit::TemplateEdit(QWidget *parent, struct print_options *printOptions, ui->fontsize->setValue(templateOptions->font_size); ui->colorpalette->setCurrentIndex(templateOptions->color_palette_index); ui->linespacing->setValue(templateOptions->line_spacing); + + if (printOptions->p_template == print_options::ONE_DIVE) { + grantlee_template = TemplateLayout::readTemplate("one_dive.html"); + } else if (printOptions->p_template == print_options::TWO_DIVE) { + grantlee_template = TemplateLayout::readTemplate("two_dives.html"); + } else if (printOptions->p_template == print_options::CUSTOM) { + grantlee_template = TemplateLayout::readTemplate("custom.html"); + } + + ui->plainTextEdit->setPlainText(grantlee_template); } TemplateEdit::~TemplateEdit() @@ -41,3 +51,11 @@ void TemplateEdit::on_colorpalette_currentIndexChanged(int index) { templateOptions->color_palette_index = 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()); + } +} diff --git a/qt-ui/templateedit.h b/qt-ui/templateedit.h index dc38d11fc..296005652 100644 --- a/qt-ui/templateedit.h +++ b/qt-ui/templateedit.h @@ -2,6 +2,7 @@ #define TEMPLATEEDIT_H #include +#include "templatelayout.h" namespace Ui { class TemplateEdit; @@ -23,10 +24,13 @@ private slots: void on_colorpalette_currentIndexChanged(int index); + void on_TemplateEdit_finished(int result); + private: Ui::TemplateEdit *ui; struct template_options *templateOptions; struct print_options *printOptions; + QString grantlee_template; }; #endif // TEMPLATEEDIT_H -- cgit v1.2.3-70-g09d2