From c6116b0269c6ec8adee2832f1812d1cf8f8e6e70 Mon Sep 17 00:00:00 2001 From: Gehad elrobey Date: Thu, 23 Jul 2015 15:19:53 +0200 Subject: [PATCH 01/21] Printing: add a "Table" template The "Table" template shows a simple table of user dives. The fields shown are: Dive number, Date, Time, Depth, Duration, Master and Location. Other fields can be added by the user. Signed-off-by: Gehad elrobey Signed-off-by: Lubomir I. Ivanov --- printing_templates/table.html | 83 +++++++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 printing_templates/table.html diff --git a/printing_templates/table.html b/printing_templates/table.html new file mode 100644 index 000000000..c97267405 --- /dev/null +++ b/printing_templates/table.html @@ -0,0 +1,83 @@ + + + + + +
+ + + + + + + + + + +{% block main_rows %} + {% for dive in dives %} + + + + + + + + + + {% endfor %} +{% endblock %} +
Dive #DateTimeDepthDurationMasterLocation
{{ dive.number }}{{ dive.date }}{{ dive.time }}{{ dive.depth }}{{ dive.duration }}{{ dive.divemaster }}{{ dive.location }}
+
+ + From 9fd5221666f94c9a95537b2f07a28a1c02f6bb24 Mon Sep 17 00:00:00 2001 From: Gehad elrobey Date: Thu, 23 Jul 2015 15:20:09 +0200 Subject: [PATCH 02/21] Printing: get the number of pages from the full resolution When we calculate the number of pages to print we need to check if the template doesn't define the number of dives per one page, then render as much dives as we can fit in one page. A dive can be broken into many pages. Signed-off-by: Gehad elrobey Signed-off-by: Lubomir I. Ivanov --- printer.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/printer.cpp b/printer.cpp index 5b1995501..10942865a 100644 --- a/printer.cpp +++ b/printer.cpp @@ -160,7 +160,12 @@ void Printer::print() 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); + int Pages; + if (divesPerPage == 0) { + Pages = ceil(webView->page()->mainFrame()->contentsSize().height() / (float)pageSize.height()); + } else { + Pages = ceil(getTotalWork(printOptions) / (float)divesPerPage); + } render(Pages); } From 0b085f79b12ee2ca60278c324e419f47f47ae100 Mon Sep 17 00:00:00 2001 From: Gehad elrobey Date: Thu, 23 Jul 2015 15:20:48 +0200 Subject: [PATCH 03/21] Printing: set the default tab to the correct one The first tab is the default tab. Signed-off-by: Gehad elrobey Signed-off-by: Lubomir I. Ivanov --- qt-ui/templateedit.ui | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/qt-ui/templateedit.ui b/qt-ui/templateedit.ui index 4f9c9c2ed..7e636f0ee 100644 --- a/qt-ui/templateedit.ui +++ b/qt-ui/templateedit.ui @@ -39,7 +39,7 @@ - 2 + 0 From f76ebe3b9d2e7e4dcd2de3b3bab6994bfa254c44 Mon Sep 17 00:00:00 2001 From: Gehad elrobey Date: Fri, 24 Jul 2015 09:26:25 +0200 Subject: [PATCH 04/21] Printing: search for grantlee templates in the templates directory We need to dynamically look up for all the existing templates in the template directory. A grantlee template can be named any name but we ignore files ending with '~'. Signed-off-by: Gehad elrobey Signed-off-by: Lubomir I. Ivanov --- qt-ui/mainwindow.cpp | 3 +++ templatelayout.cpp | 14 ++++++++++++++ templatelayout.h | 3 +++ 3 files changed, 20 insertions(+) diff --git a/qt-ui/mainwindow.cpp b/qt-ui/mainwindow.cpp index ed7c62c62..b6459d3c2 100644 --- a/qt-ui/mainwindow.cpp +++ b/qt-ui/mainwindow.cpp @@ -199,6 +199,9 @@ MainWindow::MainWindow() : QMainWindow(), ReverseGeoLookupThread *geoLookup = ReverseGeoLookupThread::instance(); connect(geoLookup, SIGNAL(started()),information(), SLOT(disableGeoLookupEdition())); connect(geoLookup, SIGNAL(finished()), information(), SLOT(enableGeoLookupEdition())); +#ifndef NO_PRINTING + find_all_templates(); +#endif } MainWindow::~MainWindow() diff --git a/templatelayout.cpp b/templatelayout.cpp index fec57cb2a..9caf773d0 100644 --- a/templatelayout.cpp +++ b/templatelayout.cpp @@ -4,6 +4,8 @@ #include "helpers.h" #include "display.h" +QList grantlee_templates; + int getTotalWork(print_options *printOptions) { if (printOptions->print_selected) { @@ -19,6 +21,18 @@ int getTotalWork(print_options *printOptions) return dives; } +void find_all_templates() +{ + QDir dir(getSubsurfaceDataPath("printing_templates")); + QFileInfoList list = dir.entryInfoList(QDir::Files | QDir::NoDotAndDotDot); + foreach (QFileInfo finfo, list) { + QString filename = finfo.fileName(); + if (filename.at(filename.size() - 1) != '~') { + grantlee_templates.append(finfo.fileName()); + } + } +} + TemplateLayout::TemplateLayout(print_options *PrintOptions, template_options *templateOptions) : m_engine(NULL) { diff --git a/templatelayout.h b/templatelayout.h index e37e9e868..5f4678923 100644 --- a/templatelayout.h +++ b/templatelayout.h @@ -6,6 +6,9 @@ #include "printoptions.h" int getTotalWork(print_options *printOptions); +void find_all_templates(); + +extern QList grantlee_templates; class TemplateLayout : public QObject { Q_OBJECT From c95358c4b9c39016d08c234fb7e5db4958ff381e Mon Sep 17 00:00:00 2001 From: Gehad elrobey Date: Fri, 24 Jul 2015 09:47:26 +0200 Subject: [PATCH 05/21] Printing: remove existing values in print template combobox We don't need static template names anymore. Signed-off-by: Gehad elrobey Signed-off-by: Lubomir I. Ivanov --- qt-ui/printoptions.ui | 18 +----------------- 1 file changed, 1 insertion(+), 17 deletions(-) diff --git a/qt-ui/printoptions.ui b/qt-ui/printoptions.ui index 7e66d4cb0..6bd271bbe 100644 --- a/qt-ui/printoptions.ui +++ b/qt-ui/printoptions.ui @@ -129,23 +129,7 @@ - - - - One dive per page - - - - - Two dives per page - - - - - Custom template - - - + From 2b2c506cb7e5e1659ad68818eca46d14d7840ecd Mon Sep 17 00:00:00 2001 From: Gehad elrobey Date: Fri, 24 Jul 2015 09:53:07 +0200 Subject: [PATCH 06/21] Printing: use grantlee templates from the current existing template list We use templates from the grantlee templates list created and dynamically. So we don't need static templates anymore. Signed-off-by: Gehad elrobey Signed-off-by: Lubomir I. Ivanov --- qt-ui/printdialog.cpp | 2 -- qt-ui/printoptions.cpp | 28 +++++++--------------------- qt-ui/printoptions.h | 6 +----- qt-ui/templateedit.cpp | 10 ++-------- templatelayout.cpp | 10 +--------- 5 files changed, 11 insertions(+), 45 deletions(-) diff --git a/qt-ui/printdialog.cpp b/qt-ui/printdialog.cpp index 31ec354c8..bb6643b31 100644 --- a/qt-ui/printdialog.cpp +++ b/qt-ui/printdialog.cpp @@ -30,7 +30,6 @@ PrintDialog::PrintDialog(QWidget *parent, Qt::WindowFlags f) : QDialog(parent, f printOptions.print_selected = true; printOptions.color_selected = true; printOptions.landscape = false; - printOptions.p_template = print_options::ONE_DIVE; printOptions.type = print_options::DIVELIST; templateOptions.font_index = 0; templateOptions.font_size = 9; @@ -43,7 +42,6 @@ PrintDialog::PrintDialog(QWidget *parent, Qt::WindowFlags f) : QDialog(parent, f printOptions.print_selected = s.value("print_selected").toBool(); printOptions.color_selected = s.value("color_selected").toBool(); 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(); diff --git a/qt-ui/printoptions.cpp b/qt-ui/printoptions.cpp index 0e6a0b320..3ed3edf11 100644 --- a/qt-ui/printoptions.cpp +++ b/qt-ui/printoptions.cpp @@ -29,16 +29,12 @@ void PrintOptions::setup() ui.radioStatisticsPrint->setChecked(true); break; } - switch (printOptions->p_template) { - case print_options::ONE_DIVE: - ui.printTemplate->setCurrentIndex(0); - break; - case print_options::TWO_DIVE: - ui.printTemplate->setCurrentIndex(1); - break; - case print_options::CUSTOM: - ui.printTemplate->setCurrentIndex(2); - break; + + // insert existing templates in the UI + ui.printTemplate->clear(); + qSort(grantlee_templates); + for (QList::iterator i = grantlee_templates.begin(); i != grantlee_templates.end(); ++i) { + ui.printTemplate->addItem((*i).split('.')[0], QVariant::fromValue(*i)); } // general print option checkboxes @@ -93,17 +89,7 @@ void PrintOptions::printSelectedClicked(bool check) void PrintOptions::on_printTemplate_currentIndexChanged(int index) { - switch(index){ - case 0: - printOptions->p_template = print_options::ONE_DIVE; - break; - case 1: - printOptions->p_template = print_options::TWO_DIVE; - break; - case 2: - printOptions->p_template = print_options::CUSTOM; - break; - } + printOptions->p_template = ui.printTemplate->itemData(index).toString(); } void PrintOptions::on_editButton_clicked() diff --git a/qt-ui/printoptions.h b/qt-ui/printoptions.h index 3a55c6994..3ece6b64c 100644 --- a/qt-ui/printoptions.h +++ b/qt-ui/printoptions.h @@ -11,11 +11,7 @@ struct print_options { TABLE, STATISTICS } type; - enum print_template { - ONE_DIVE, - TWO_DIVE, - CUSTOM - } p_template; + QString p_template; bool print_selected; bool color_selected; bool landscape; diff --git a/qt-ui/templateedit.cpp b/qt-ui/templateedit.cpp index 6a6328f64..de280f7a8 100644 --- a/qt-ui/templateedit.cpp +++ b/qt-ui/templateedit.cpp @@ -21,13 +21,7 @@ TemplateEdit::TemplateEdit(QWidget *parent, struct print_options *printOptions, 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"); - } + grantlee_template = TemplateLayout::readTemplate(printOptions->p_template); // gui btnGroup = new QButtonGroup; @@ -118,7 +112,7 @@ void TemplateEdit::saveSettings() if (msgBox.exec() == QMessageBox::Save) { memcpy(templateOptions, &newTemplateOptions, sizeof(struct template_options)); if (grantlee_template.compare(ui->plainTextEdit->toPlainText())) { - printOptions->p_template = print_options::CUSTOM; + printOptions->p_template = "custom.html"; TemplateLayout::writeTemplate("custom.html", ui->plainTextEdit->toPlainText()); } if (templateOptions->color_palette_index == 1) { diff --git a/templatelayout.cpp b/templatelayout.cpp index 9caf773d0..8a03956f3 100644 --- a/templatelayout.cpp +++ b/templatelayout.cpp @@ -49,7 +49,6 @@ QString TemplateLayout::generate() { int progress = 0; int totalWork = getTotalWork(PrintOptions); - QString templateName; QString htmlContent; m_engine = new Grantlee::Engine(this); @@ -83,14 +82,7 @@ QString TemplateLayout::generate() Grantlee::Context c(mapping); - if (PrintOptions->p_template == print_options::ONE_DIVE) { - 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); + Grantlee::Template t = m_engine->loadByName(PrintOptions->p_template); if (!t || t->error()) { qDebug() << "Can't load template"; return htmlContent; From 2a85be91b1bc3ae80a75e5508ffdfc7b7e4c1daa Mon Sep 17 00:00:00 2001 From: Gehad elrobey Date: Fri, 24 Jul 2015 14:27:33 +0200 Subject: [PATCH 07/21] Printing: save/load selected template by QSettings We save the selected template name on closing the printDialog, We also load the last selected template from QSettings when initializing the dialog. Signed-off-by: Gehad elrobey Signed-off-by: Lubomir I. Ivanov --- qt-ui/printdialog.cpp | 2 ++ qt-ui/printoptions.cpp | 12 ++++++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/qt-ui/printdialog.cpp b/qt-ui/printdialog.cpp index bb6643b31..c7ce327f5 100644 --- a/qt-ui/printdialog.cpp +++ b/qt-ui/printdialog.cpp @@ -30,6 +30,7 @@ PrintDialog::PrintDialog(QWidget *parent, Qt::WindowFlags f) : QDialog(parent, f printOptions.print_selected = true; printOptions.color_selected = true; printOptions.landscape = false; + printOptions.p_template = "one_dive.html"; printOptions.type = print_options::DIVELIST; templateOptions.font_index = 0; templateOptions.font_size = 9; @@ -42,6 +43,7 @@ PrintDialog::PrintDialog(QWidget *parent, Qt::WindowFlags f) : QDialog(parent, f printOptions.print_selected = s.value("print_selected").toBool(); printOptions.color_selected = s.value("color_selected").toBool(); printOptions.landscape = s.value("landscape").toBool(); + printOptions.p_template = s.value("template_selected").toString(); qprinter.setOrientation((QPrinter::Orientation)printOptions.landscape); templateOptions.font_index = s.value("font").toInt(); templateOptions.font_size = s.value("font_size").toDouble(); diff --git a/qt-ui/printoptions.cpp b/qt-ui/printoptions.cpp index 3ed3edf11..df49694ee 100644 --- a/qt-ui/printoptions.cpp +++ b/qt-ui/printoptions.cpp @@ -30,12 +30,20 @@ void PrintOptions::setup() break; } - // insert existing templates in the UI - ui.printTemplate->clear(); + // insert existing templates in the UI and select the current template qSort(grantlee_templates); + int current_index = 0; + for (QList::iterator i = grantlee_templates.begin(); i != grantlee_templates.end(); ++i) { + if ((*i).compare(printOptions->p_template) == 0) { + break; + } + current_index++; + } + ui.printTemplate->clear(); for (QList::iterator i = grantlee_templates.begin(); i != grantlee_templates.end(); ++i) { ui.printTemplate->addItem((*i).split('.')[0], QVariant::fromValue(*i)); } + ui.printTemplate->setCurrentIndex(current_index); // general print option checkboxes if (printOptions->color_selected) From 7f8d20c09d531a65dd8864e86b33766d49c0b04b Mon Sep 17 00:00:00 2001 From: Gehad elrobey Date: Fri, 24 Jul 2015 16:23:50 +0200 Subject: [PATCH 08/21] Printing: fix issue with old QSettings group As I am using the same old QSettings group name, some variables may not be correctly initialized, so we need to check for incorrect values before we start. Signed-off-by: Gehad elrobey Signed-off-by: Lubomir I. Ivanov --- qt-ui/printdialog.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/qt-ui/printdialog.cpp b/qt-ui/printdialog.cpp index c7ce327f5..c42ec6fb9 100644 --- a/qt-ui/printdialog.cpp +++ b/qt-ui/printdialog.cpp @@ -56,6 +56,14 @@ PrintDialog::PrintDialog(QWidget *parent, Qt::WindowFlags f) : QDialog(parent, f custom_colors.color5 = QColor(s.value("custom_color_5").toString()); } + // handle cases from old QSettings group + if (templateOptions.font_size < 9) { + templateOptions.font_size = 9; + } + if (templateOptions.line_spacing < 1) { + templateOptions.line_spacing = 1; + } + switch (templateOptions.color_palette_index) { case 0: // almond templateOptions.color_palette = almond_colors; From e8ad4b0c97c011f9cc89943252a69a8008bbb749 Mon Sep 17 00:00:00 2001 From: Gehad elrobey Date: Sun, 26 Jul 2015 00:31:37 +0200 Subject: [PATCH 09/21] Printing: remove "Table" option from print options radio group "Table" print is now a template, so remove the radio button. Signed-off-by: Gehad elrobey Signed-off-by: Lubomir I. Ivanov --- qt-ui/printdialog.cpp | 6 ++---- qt-ui/printoptions.cpp | 10 ---------- qt-ui/printoptions.h | 2 -- qt-ui/printoptions.ui | 27 --------------------------- 4 files changed, 2 insertions(+), 43 deletions(-) diff --git a/qt-ui/printdialog.cpp b/qt-ui/printdialog.cpp index c42ec6fb9..8717766a1 100644 --- a/qt-ui/printdialog.cpp +++ b/qt-ui/printdialog.cpp @@ -148,7 +148,7 @@ void PrintDialog::onFinished() void PrintDialog::previewClicked(void) { - if (printOptions.type == print_options::TABLE || printOptions.type == print_options::STATISTICS) { + if (printOptions.type == print_options::STATISTICS) { QMessageBox msgBox; msgBox.setText("This feature is not implemented yet"); msgBox.exec(); @@ -164,7 +164,7 @@ void PrintDialog::previewClicked(void) void PrintDialog::printClicked(void) { - if (printOptions.type == print_options::TABLE || printOptions.type == print_options::STATISTICS) { + if (printOptions.type == print_options::STATISTICS) { QMessageBox msgBox; msgBox.setText("This feature is not implemented yet"); msgBox.exec(); @@ -178,8 +178,6 @@ void PrintDialog::printClicked(void) connect(printer, SIGNAL(progessUpdated(int)), progressBar, SLOT(setValue(int))); printer->print(); break; - case print_options::TABLE: - break; case print_options::STATISTICS: break; } diff --git a/qt-ui/printoptions.cpp b/qt-ui/printoptions.cpp index df49694ee..223dfab93 100644 --- a/qt-ui/printoptions.cpp +++ b/qt-ui/printoptions.cpp @@ -22,9 +22,6 @@ void PrintOptions::setup() case print_options::DIVELIST: ui.radioDiveListPrint->setChecked(true); break; - case print_options::TABLE: - ui.radioTablePrint->setChecked(true); - break; case print_options::STATISTICS: ui.radioStatisticsPrint->setChecked(true); break; @@ -69,13 +66,6 @@ void PrintOptions::on_radioDiveListPrint_clicked(bool check) } } -void PrintOptions::on_radioTablePrint_clicked(bool check) -{ - if (check) { - printOptions->type = print_options::TABLE; - } -} - void PrintOptions::on_radioStatisticsPrint_clicked(bool check) { if (check) { diff --git a/qt-ui/printoptions.h b/qt-ui/printoptions.h index 3ece6b64c..326935b8c 100644 --- a/qt-ui/printoptions.h +++ b/qt-ui/printoptions.h @@ -8,7 +8,6 @@ struct print_options { enum print_type { DIVELIST, - TABLE, STATISTICS } type; QString p_template; @@ -66,7 +65,6 @@ slots: void printInColorClicked(bool check); void printSelectedClicked(bool check); void on_radioStatisticsPrint_clicked(bool check); - void on_radioTablePrint_clicked(bool check); void on_radioDiveListPrint_clicked(bool check); void on_printTemplate_currentIndexChanged(int index); void on_editButton_clicked(); diff --git a/qt-ui/printoptions.ui b/qt-ui/printoptions.ui index 6bd271bbe..b2daefd0b 100644 --- a/qt-ui/printoptions.ui +++ b/qt-ui/printoptions.ui @@ -46,19 +46,6 @@ - - - - 0 - 0 - - - - &Table print - - - - @@ -71,19 +58,6 @@ - - - - Qt::Vertical - - - - 20 - 40 - - - - @@ -151,7 +125,6 @@ radioDiveListPrint - radioStatisticsPrint printSelected printInColor From 61a8ac09b03a47cc728834765f6c652a20ce8a3f Mon Sep 17 00:00:00 2001 From: Gehad elrobey Date: Sun, 26 Jul 2015 08:34:32 +0200 Subject: [PATCH 10/21] Printing: fix TemplateEdit layout Make the TemplateEdit dialog resizable. Signed-off-by: Gehad elrobey Signed-off-by: Lubomir I. Ivanov --- qt-ui/templateedit.ui | 894 ++++++++++++++++++++++-------------------- 1 file changed, 473 insertions(+), 421 deletions(-) diff --git a/qt-ui/templateedit.ui b/qt-ui/templateedit.ui index 7e636f0ee..073db237b 100644 --- a/qt-ui/templateedit.ui +++ b/qt-ui/templateedit.ui @@ -6,436 +6,488 @@ 0 0 - 774 + 770 433 Edit Template - - - - 400 - 380 - 341 - 32 - - - - Qt::Horizontal - - - QDialogButtonBox::Apply|QDialogButtonBox::Cancel|QDialogButtonBox::Ok - - - - - - 300 - 30 - 441 - 331 - - - - 0 - - - - Style - - - - - 10 - 20 - 401 - 171 - + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + Preview + + + + + + + + 0 + 0 + + + + + 180 + 240 + + + + + 180 + 254 + + + + + + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + false + + + 0 + + + + Style + + + + + + + + + + Font + + + + + + + + Arial + + + + + Impact + + + + + Georgia + + + + + Courier + + + + + Verdana + + + + + + + + + + + + Font size + + + + + + + 9 + + + 18 + + + + + + + + + + + Color pallet + + + + + + + + Almond + + + + + Custom + + + + + + + + + + + + Line spacing + + + + + + + 1.000000000000000 + + + 3.000000000000000 + + + 0.250000000000000 + + + 1.250000000000000 + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + + Template + + + + + + Qt::ScrollBarAsNeeded + + + QPlainTextEdit::NoWrap + + + + + + + + + 16777215 + 16777215 + + + + Colors + + + + + + + + + + + 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 + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + + + + + + + Qt::Horizontal - - - - - - - Font - - - - - - - - Arial - - - - - Impact - - - - - Georgia - - - - - Courier - - - - - Verdana - - - - - - - - - - - - Font size - - - - - - - 9 - - - 18 - - - - - - - - - - - Color pallet - - - - - - - - Almond - - - - - Custom - - - - - - - - - - - - Line spacing - - - - - - - 1.000000000000000 - - - 3.000000000000000 - - - 0.250000000000000 - - - 1.250000000000000 - - - - - - - - - - - Template - - - - - 0 - 0 - 441 - 301 - - - - Qt::ScrollBarAsNeeded - - - QPlainTextEdit::NoWrap + + QDialogButtonBox::Apply|QDialogButtonBox::Cancel|QDialogButtonBox::Ok - - - - 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 - - - - - - - - - - - - - 30 - 30 - 59 - 14 - - - - Preview - - - - - - 50 - 70 - 211 - 291 - - - - - - + + From b37498d35515ba981fe0de1f19f048f5e3dbb975 Mon Sep 17 00:00:00 2001 From: Gehad elrobey Date: Sun, 26 Jul 2015 14:59:59 +0200 Subject: [PATCH 11/21] Printing: add member function to print options Get the currently selected template. Signed-off-by: Gehad elrobey Signed-off-by: Lubomir I. Ivanov --- qt-ui/printoptions.cpp | 5 +++++ qt-ui/printoptions.h | 1 + 2 files changed, 6 insertions(+) diff --git a/qt-ui/printoptions.cpp b/qt-ui/printoptions.cpp index 223dfab93..6cfbed481 100644 --- a/qt-ui/printoptions.cpp +++ b/qt-ui/printoptions.cpp @@ -96,3 +96,8 @@ void PrintOptions::on_editButton_clicked() te.exec(); setup(); } + +QString PrintOptions::getSelectedTemplate() +{ + return ui.printTemplate->currentData().toString(); +} diff --git a/qt-ui/printoptions.h b/qt-ui/printoptions.h index 326935b8c..b9912d2ed 100644 --- a/qt-ui/printoptions.h +++ b/qt-ui/printoptions.h @@ -53,6 +53,7 @@ class PrintOptions : public QWidget { public: explicit PrintOptions(QWidget *parent, struct print_options *printOpt, struct template_options *templateOpt); void setup(); + QString getSelectedTemplate(); private: Ui::PrintOptions ui; From fc9cba692eb0e5a570854e2b10c38dbddcdfce83 Mon Sep 17 00:00:00 2001 From: Gehad elrobey Date: Tue, 28 Jul 2015 08:53:37 +0200 Subject: [PATCH 12/21] Printing: add "Import", "Export" and "Delete" buttons for templates Use the button group to import, export or delete a template from the printing_templates directory. Signed-off-by: Gehad elrobey Signed-off-by: Lubomir I. Ivanov --- qt-ui/printoptions.ui | 63 +++++++++++++++++++++++++++++++++---------- 1 file changed, 49 insertions(+), 14 deletions(-) diff --git a/qt-ui/printoptions.ui b/qt-ui/printoptions.ui index b2daefd0b..1c2523d39 100644 --- a/qt-ui/printoptions.ui +++ b/qt-ui/printoptions.ui @@ -103,20 +103,55 @@ - - - - - - - 106 - 26 - - - - Edit - - + + + + + + + + + + + 0 + 0 + + + + + 16777215 + 16777215 + + + + Edit + + + + + + + Delete + + + + + + + Export + + + + + + + Import + + + + + + From 1dd2518624cc001afacead74caed854ac78a5b6a Mon Sep 17 00:00:00 2001 From: Gehad elrobey Date: Tue, 28 Jul 2015 09:05:58 +0200 Subject: [PATCH 13/21] Printing: support importing/exporting of templates Implement 'import/export' features, so it's easier to share customized printing templates. Also support deleting existing templates. Signed-off-by: Gehad elrobey Signed-off-by: Lubomir I. Ivanov --- qt-ui/printoptions.cpp | 37 +++++++++++++++++++++++++++++++++++++ qt-ui/printoptions.h | 3 +++ 2 files changed, 40 insertions(+) diff --git a/qt-ui/printoptions.cpp b/qt-ui/printoptions.cpp index 6cfbed481..916d9d696 100644 --- a/qt-ui/printoptions.cpp +++ b/qt-ui/printoptions.cpp @@ -1,6 +1,10 @@ #include "printoptions.h" #include "templateedit.h" +#include "helpers.h" + #include +#include +#include PrintOptions::PrintOptions(QWidget *parent, struct print_options *printOpt, struct template_options *templateOpt) { @@ -97,6 +101,39 @@ void PrintOptions::on_editButton_clicked() setup(); } +void PrintOptions::on_importButton_clicked() +{ + QString filename = QFileDialog::getOpenFileName(this, tr("Import Template file"), "", + tr("HTML files (*.html)")); + QFileInfo fileInfo(filename); + QFile::copy(filename, getSubsurfaceDataPath("printing_templates") + QDir::separator() + fileInfo.fileName()); + find_all_templates(); + setup(); +} + +void PrintOptions::on_exportButton_clicked() +{ + QString filename = QFileDialog::getSaveFileName(this, tr("Export Template files as"), "", + tr("HTML files (*.html)")); + QFile::copy(getSubsurfaceDataPath("printing_templates") + QDir::separator() + getSelectedTemplate(), filename); +} + +void PrintOptions::on_deleteButton_clicked() +{ + QString templateName = getSelectedTemplate(); + QMessageBox msgBox; + msgBox.setText("This action cannot be undone!"); + msgBox.setInformativeText("Delete '" + templateName + "' template?"); + msgBox.setStandardButtons(QMessageBox::Ok | QMessageBox::Cancel); + msgBox.setDefaultButton(QMessageBox::Cancel); + if (msgBox.exec() == QMessageBox::Ok) { + QFile f(getSubsurfaceDataPath("printing_templates") + QDir::separator() + templateName); + f.remove(); + find_all_templates(); + setup(); + } +} + QString PrintOptions::getSelectedTemplate() { return ui.printTemplate->currentData().toString(); diff --git a/qt-ui/printoptions.h b/qt-ui/printoptions.h index b9912d2ed..528c5ed4d 100644 --- a/qt-ui/printoptions.h +++ b/qt-ui/printoptions.h @@ -69,6 +69,9 @@ slots: void on_radioDiveListPrint_clicked(bool check); void on_printTemplate_currentIndexChanged(int index); void on_editButton_clicked(); + void on_importButton_clicked(); + void on_exportButton_clicked(); + void on_deleteButton_clicked(); }; #endif // PRINTOPTIONS_H From 858796af09cb78eb844947b8e71153b6c61a045d Mon Sep 17 00:00:00 2001 From: Gehad elrobey Date: Sun, 26 Jul 2015 15:58:00 +0200 Subject: [PATCH 14/21] Printing: clear all templates before insterting the new templates 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 8a03956f3..30919891a 100644 --- a/templatelayout.cpp +++ b/templatelayout.cpp @@ -23,6 +23,7 @@ int getTotalWork(print_options *printOptions) void find_all_templates() { + grantlee_templates.clear(); QDir dir(getSubsurfaceDataPath("printing_templates")); QFileInfoList list = dir.entryInfoList(QDir::Files | QDir::NoDotAndDotDot); foreach (QFileInfo finfo, list) { From 6319f0efba30d0c6a3831f5bb9a072aede4690ab Mon Sep 17 00:00:00 2001 From: Gehad elrobey Date: Sun, 26 Jul 2015 17:43:20 +0200 Subject: [PATCH 15/21] Printing: add a "Flow" layout Print dives successively and fit as many as we can in the smallest number of pages. Some dives may be broken between pages. Signed-off-by: Gehad elrobey Signed-off-by: Lubomir I. Ivanov --- printing_templates/flowlayout.html | 204 +++++++++++++++++++++++++++++ 1 file changed, 204 insertions(+) create mode 100644 printing_templates/flowlayout.html diff --git a/printing_templates/flowlayout.html b/printing_templates/flowlayout.html new file mode 100644 index 000000000..a3f7951d9 --- /dev/null +++ b/printing_templates/flowlayout.html @@ -0,0 +1,204 @@ + + + + + +
+{% block main_rows %} + {% for dive in dives %} +
+
+
+
+ + + + + + + + + + + + + + + + + + + + + +
+

Dive No.

+
+

{{ dive.number }}

+
+

Date

+

{{ dive.date }}

+
+

Location

+
+

{{ dive.location }}

+
+

Max depth

+
+

{{ dive.depth }}

+
+

Duration

+
+

{{ dive.duration }}

+
+ + + + + + + + + + + + + + + + + + + + + + +
+

Time.

+
+

{{ dive.time }}

+
+

Air Temp.

+

{{ dive.airTemp }}

+
+

Water Temp.

+
+

{{ dive.waterTemp }}

+
+

Buddy

+
+

{{ dive.buddy }}

+
+

Dive Master

+
+

{{ dive.divemaster }}

+
+ + + + + + + + + +
+

Notes

+
+
+

{{ dive.notes }}

+
+
+
+
+
+
+ {% endfor %} +{% endblock %} +
+ + From d41d79b549cdfb0ff3c785eae09a504a46fb4b96 Mon Sep 17 00:00:00 2001 From: Gehad elrobey Date: Sun, 26 Jul 2015 19:13:23 +0200 Subject: [PATCH 16/21] Printing: add the "Shades of blue" color theme Signed-off-by: Gehad elrobey Signed-off-by: Lubomir I. Ivanov --- qt-ui/printdialog.cpp | 12 ++++++++++-- qt-ui/printoptions.h | 2 +- qt-ui/templateedit.cpp | 13 ++++++++++--- qt-ui/templateedit.ui | 5 +++++ 4 files changed, 26 insertions(+), 6 deletions(-) diff --git a/qt-ui/printdialog.cpp b/qt-ui/printdialog.cpp index 8717766a1..d5a16df11 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, custom_colors; +template_options::color_palette_struct almond_colors, blueshades_colors, custom_colors; PrintDialog::PrintDialog(QWidget *parent, Qt::WindowFlags f) : QDialog(parent, f) { @@ -22,6 +22,11 @@ PrintDialog::PrintDialog(QWidget *parent, Qt::WindowFlags f) : QDialog(parent, f almond_colors.color3 = QColor::fromRgb(136, 160, 150); almond_colors.color4 = QColor::fromRgb(187, 171, 139); almond_colors.color5 = QColor::fromRgb(239, 130, 117); + blueshades_colors.color1 = QColor::fromRgb(182, 192, 206); + blueshades_colors.color2 = QColor::fromRgb(142, 152, 166); + blueshades_colors.color3 = QColor::fromRgb(31, 49, 75); + blueshades_colors.color4 = QColor::fromRgb(21, 45, 84); + blueshades_colors.color5 = QColor::fromRgb(5, 25, 56); // check if the options were previously stored in the settings; if not use some defaults. QSettings s; @@ -68,7 +73,10 @@ PrintDialog::PrintDialog(QWidget *parent, Qt::WindowFlags f) : QDialog(parent, f case 0: // almond templateOptions.color_palette = almond_colors; break; - case 1: // custom + case 1: // blueshades + templateOptions.color_palette = blueshades_colors; + break; + case 2: // custom templateOptions.color_palette = custom_colors; break; } diff --git a/qt-ui/printoptions.h b/qt-ui/printoptions.h index 528c5ed4d..5a4ca3504 100644 --- a/qt-ui/printoptions.h +++ b/qt-ui/printoptions.h @@ -44,7 +44,7 @@ struct template_options { } }; -extern template_options::color_palette_struct almond_colors, custom_colors; +extern template_options::color_palette_struct almond_colors, blueshades_colors, custom_colors; // should be based on a custom QPrintDialog class class PrintOptions : public QWidget { diff --git a/qt-ui/templateedit.cpp b/qt-ui/templateedit.cpp index de280f7a8..c26740506 100644 --- a/qt-ui/templateedit.cpp +++ b/qt-ui/templateedit.cpp @@ -95,7 +95,10 @@ void TemplateEdit::on_colorpalette_currentIndexChanged(int index) case 0: // almond newTemplateOptions.color_palette = almond_colors; break; - case 1: // custom + case 1: // blueshades + newTemplateOptions.color_palette = blueshades_colors; + break; + case 2: // custom newTemplateOptions.color_palette = custom_colors; break; } @@ -115,7 +118,7 @@ void TemplateEdit::saveSettings() printOptions->p_template = "custom.html"; TemplateLayout::writeTemplate("custom.html", ui->plainTextEdit->toPlainText()); } - if (templateOptions->color_palette_index == 1) { + if (templateOptions->color_palette_index == 2) { custom_colors = templateOptions->color_palette; } } @@ -148,6 +151,10 @@ void TemplateEdit::colorSelect(QAbstractButton *button) newTemplateOptions.color_palette = almond_colors; custom_colors = newTemplateOptions.color_palette; break; + case 1: // blueshades + newTemplateOptions.color_palette = blueshades_colors; + custom_colors = newTemplateOptions.color_palette; + break; } //change selected color @@ -174,6 +181,6 @@ void TemplateEdit::colorSelect(QAbstractButton *button) newTemplateOptions.color_palette.color5 = color; break; } - newTemplateOptions.color_palette_index = 1; + newTemplateOptions.color_palette_index = 2; updatePreview(); } diff --git a/qt-ui/templateedit.ui b/qt-ui/templateedit.ui index 073db237b..1442954cf 100644 --- a/qt-ui/templateedit.ui +++ b/qt-ui/templateedit.ui @@ -173,6 +173,11 @@ Almond + + + Shades of blue + + Custom From ed5afc510ed4d0756aadbadd57d8b58f37857ef1 Mon Sep 17 00:00:00 2001 From: Gehad elrobey Date: Sun, 26 Jul 2015 19:57:57 +0200 Subject: [PATCH 17/21] Printing: don't name color templates with confusing numbers Use the color_palette enum instead. Signed-off-by: Gehad elrobey Signed-off-by: Lubomir I. Ivanov --- qt-ui/printdialog.cpp | 8 ++++---- qt-ui/printoptions.h | 6 ++++++ qt-ui/templateedit.cpp | 12 ++++++------ 3 files changed, 16 insertions(+), 10 deletions(-) diff --git a/qt-ui/printdialog.cpp b/qt-ui/printdialog.cpp index d5a16df11..25c102201 100644 --- a/qt-ui/printdialog.cpp +++ b/qt-ui/printdialog.cpp @@ -39,7 +39,7 @@ PrintDialog::PrintDialog(QWidget *parent, Qt::WindowFlags f) : QDialog(parent, f printOptions.type = print_options::DIVELIST; templateOptions.font_index = 0; templateOptions.font_size = 9; - templateOptions.color_palette_index = 0; + templateOptions.color_palette_index = ALMOND; templateOptions.line_spacing = 1; custom_colors = almond_colors; } else { @@ -70,13 +70,13 @@ PrintDialog::PrintDialog(QWidget *parent, Qt::WindowFlags f) : QDialog(parent, f } switch (templateOptions.color_palette_index) { - case 0: // almond + case ALMOND: // almond templateOptions.color_palette = almond_colors; break; - case 1: // blueshades + case BLUESHADES: // blueshades templateOptions.color_palette = blueshades_colors; break; - case 2: // custom + case CUSTOM: // custom templateOptions.color_palette = custom_colors; break; } diff --git a/qt-ui/printoptions.h b/qt-ui/printoptions.h index 5a4ca3504..2e2e2a9f4 100644 --- a/qt-ui/printoptions.h +++ b/qt-ui/printoptions.h @@ -46,6 +46,12 @@ struct template_options { extern template_options::color_palette_struct almond_colors, blueshades_colors, custom_colors; +enum color_palette { + ALMOND, + BLUESHADES, + CUSTOM +}; + // 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 c26740506..6df11ea79 100644 --- a/qt-ui/templateedit.cpp +++ b/qt-ui/templateedit.cpp @@ -92,13 +92,13 @@ void TemplateEdit::on_colorpalette_currentIndexChanged(int index) { newTemplateOptions.color_palette_index = index; switch (newTemplateOptions.color_palette_index) { - case 0: // almond + case ALMOND: // almond newTemplateOptions.color_palette = almond_colors; break; - case 1: // blueshades + case BLUESHADES: // blueshades newTemplateOptions.color_palette = blueshades_colors; break; - case 2: // custom + case CUSTOM: // custom newTemplateOptions.color_palette = custom_colors; break; } @@ -147,11 +147,11 @@ void TemplateEdit::colorSelect(QAbstractButton *button) { // reset custom colors palette switch (newTemplateOptions.color_palette_index) { - case 0: // almond + case ALMOND: // almond newTemplateOptions.color_palette = almond_colors; custom_colors = newTemplateOptions.color_palette; break; - case 1: // blueshades + case BLUESHADES: // blueshades newTemplateOptions.color_palette = blueshades_colors; custom_colors = newTemplateOptions.color_palette; break; @@ -181,6 +181,6 @@ void TemplateEdit::colorSelect(QAbstractButton *button) newTemplateOptions.color_palette.color5 = color; break; } - newTemplateOptions.color_palette_index = 2; + newTemplateOptions.color_palette_index = CUSTOM; updatePreview(); } From f8378927b503c51bfaca456e0f511d0e567fafee Mon Sep 17 00:00:00 2001 From: Gehad elrobey Date: Mon, 27 Jul 2015 13:12:59 +0200 Subject: [PATCH 18/21] Printing: choose first template if selected template is not found If user selected template is not found, we choose the first template as a default choice. Signed-off-by: Gehad elrobey Signed-off-by: Lubomir I. Ivanov --- qt-ui/printoptions.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/qt-ui/printoptions.cpp b/qt-ui/printoptions.cpp index 916d9d696..b143e49d0 100644 --- a/qt-ui/printoptions.cpp +++ b/qt-ui/printoptions.cpp @@ -33,12 +33,13 @@ void PrintOptions::setup() // insert existing templates in the UI and select the current template qSort(grantlee_templates); - int current_index = 0; + int current_index = 0, index = 0; for (QList::iterator i = grantlee_templates.begin(); i != grantlee_templates.end(); ++i) { if ((*i).compare(printOptions->p_template) == 0) { + current_index = index; break; } - current_index++; + index++; } ui.printTemplate->clear(); for (QList::iterator i = grantlee_templates.begin(); i != grantlee_templates.end(); ++i) { From 39ec9f8a52766f6ed2fb8395dc511bcfd7bf1539 Mon Sep 17 00:00:00 2001 From: Gehad elrobey Date: Tue, 28 Jul 2015 09:16:17 +0200 Subject: [PATCH 19/21] Printing: select current template upon importing When importing a template, make it the user currently selected template. Signed-off-by: Gehad elrobey Signed-off-by: Lubomir I. Ivanov --- qt-ui/printoptions.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/qt-ui/printoptions.cpp b/qt-ui/printoptions.cpp index b143e49d0..48489bae5 100644 --- a/qt-ui/printoptions.cpp +++ b/qt-ui/printoptions.cpp @@ -108,6 +108,7 @@ void PrintOptions::on_importButton_clicked() tr("HTML files (*.html)")); QFileInfo fileInfo(filename); QFile::copy(filename, getSubsurfaceDataPath("printing_templates") + QDir::separator() + fileInfo.fileName()); + printOptions->p_template = fileInfo.fileName(); find_all_templates(); setup(); } From ccddcc3952fec5195690c154f736690093e544d2 Mon Sep 17 00:00:00 2001 From: Gehad elrobey Date: Tue, 28 Jul 2015 09:24:24 +0200 Subject: [PATCH 20/21] Printing: rename templates to have spaces and capitalization This is easier to have user friendly names for the bundled templates. Signed-off-by: Gehad elrobey Signed-off-by: Lubomir I. Ivanov --- printing_templates/{custom.html => Custom.html} | 0 printing_templates/{flowlayout.html => Flowlayout.html} | 0 printing_templates/{one_dive.html => One Dive.html} | 0 printing_templates/{table.html => Table.html} | 0 printing_templates/{two_dives.html => Two Dives.html} | 0 5 files changed, 0 insertions(+), 0 deletions(-) rename printing_templates/{custom.html => Custom.html} (100%) rename printing_templates/{flowlayout.html => Flowlayout.html} (100%) rename printing_templates/{one_dive.html => One Dive.html} (100%) rename printing_templates/{table.html => Table.html} (100%) rename printing_templates/{two_dives.html => Two Dives.html} (100%) diff --git a/printing_templates/custom.html b/printing_templates/Custom.html similarity index 100% rename from printing_templates/custom.html rename to printing_templates/Custom.html diff --git a/printing_templates/flowlayout.html b/printing_templates/Flowlayout.html similarity index 100% rename from printing_templates/flowlayout.html rename to printing_templates/Flowlayout.html diff --git a/printing_templates/one_dive.html b/printing_templates/One Dive.html similarity index 100% rename from printing_templates/one_dive.html rename to printing_templates/One Dive.html diff --git a/printing_templates/table.html b/printing_templates/Table.html similarity index 100% rename from printing_templates/table.html rename to printing_templates/Table.html diff --git a/printing_templates/two_dives.html b/printing_templates/Two Dives.html similarity index 100% rename from printing_templates/two_dives.html rename to printing_templates/Two Dives.html From 01645d64b91b29878d6927dcf7cd5c2381e0bfaa Mon Sep 17 00:00:00 2001 From: "Lubomir I. Ivanov" Date: Tue, 28 Jul 2015 11:26:41 +0300 Subject: [PATCH 21/21] Printing: safer Template->Import|Export handling Check if the file string is empty and return, else process it. Signed-off-by: Lubomir I. Ivanov --- qt-ui/printoptions.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/qt-ui/printoptions.cpp b/qt-ui/printoptions.cpp index 48489bae5..1da95a94d 100644 --- a/qt-ui/printoptions.cpp +++ b/qt-ui/printoptions.cpp @@ -106,6 +106,8 @@ void PrintOptions::on_importButton_clicked() { QString filename = QFileDialog::getOpenFileName(this, tr("Import Template file"), "", tr("HTML files (*.html)")); + if (filename.isEmpty()) + return; QFileInfo fileInfo(filename); QFile::copy(filename, getSubsurfaceDataPath("printing_templates") + QDir::separator() + fileInfo.fileName()); printOptions->p_template = fileInfo.fileName(); @@ -117,6 +119,8 @@ void PrintOptions::on_exportButton_clicked() { QString filename = QFileDialog::getSaveFileName(this, tr("Export Template files as"), "", tr("HTML files (*.html)")); + if (filename.isEmpty()) + return; QFile::copy(getSubsurfaceDataPath("printing_templates") + QDir::separator() + getSelectedTemplate(), filename); }