From 90852e114c37897971d528c90be8350e494eb8cb Mon Sep 17 00:00:00 2001 From: Gehad elrobey Date: Mon, 17 Aug 2015 19:44:11 +0200 Subject: Printing: fix typo in template name Template names was capitalized, so change the file name to "Custom.html" instead of "custom.html" Signed-off-by: Lubomir I. Ivanov Signed-off-by: Gehad elrobey --- qt-ui/templateedit.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'qt-ui') diff --git a/qt-ui/templateedit.cpp b/qt-ui/templateedit.cpp index e4e6453ac..3315b12ef 100644 --- a/qt-ui/templateedit.cpp +++ b/qt-ui/templateedit.cpp @@ -125,8 +125,8 @@ 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 = "custom.html"; - TemplateLayout::writeTemplate("custom.html", ui->plainTextEdit->toPlainText()); + printOptions->p_template = "Custom.html"; + TemplateLayout::writeTemplate("Custom.html", ui->plainTextEdit->toPlainText()); } if (templateOptions->color_palette_index == CUSTOM) { custom_colors = templateOptions->color_palette; -- cgit v1.2.3-70-g09d2 From 6a692495c024876d74145df8b67734323ec348b6 Mon Sep 17 00:00:00 2001 From: Gehad elrobey Date: Fri, 21 Aug 2015 18:07:30 +0200 Subject: Printing: add statistics templates to the dialog Show the existing templates based on the print type selected by the user. Signed-off-by: Lubomir I. Ivanov Signed-off-by: Gehad elrobey --- qt-ui/printoptions.cpp | 57 +++++++++++++++++++++++++++++++++++++------------- qt-ui/printoptions.h | 1 + 2 files changed, 43 insertions(+), 15 deletions(-) (limited to 'qt-ui') diff --git a/qt-ui/printoptions.cpp b/qt-ui/printoptions.cpp index 419098cf8..70cd89711 100644 --- a/qt-ui/printoptions.cpp +++ b/qt-ui/printoptions.cpp @@ -31,21 +31,7 @@ void PrintOptions::setup() break; } - // insert existing templates in the UI and select the current template - qSort(grantlee_templates); - 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; - } - 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); + setupTemplates(); // general print option checkboxes if (printOptions->color_selected) @@ -63,6 +49,43 @@ void PrintOptions::setup() hasSetupSlots = true; } +void PrintOptions::setupTemplates() +{ + if (printOptions->type == print_options::DIVELIST) { + // insert dive list templates in the UI and select the current template + qSort(grantlee_templates); + 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; + } + 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); + } else if (printOptions->type == print_options::STATISTICS) { + // insert statistics templates in the UI and select the current template + qSort(grantlee_statistics_templates); + int current_index = 0, index = 0; + for (QList::iterator i = grantlee_statistics_templates.begin(); i != grantlee_statistics_templates.end(); ++i) { + if ((*i).compare(printOptions->p_template) == 0) { + current_index = index; + break; + } + index++; + } + ui.printTemplate->clear(); + for (QList::iterator i = grantlee_statistics_templates.begin(); i != grantlee_statistics_templates.end(); ++i) { + ui.printTemplate->addItem((*i).split('.')[0], QVariant::fromValue(*i)); + } + ui.printTemplate->setCurrentIndex(current_index); + } +} + // print type radio buttons void PrintOptions::on_radioDiveListPrint_toggled(bool check) { @@ -79,6 +102,8 @@ void PrintOptions::on_radioDiveListPrint_toggled(bool check) ui.exportButton->setEnabled(true); ui.importButton->setEnabled(true); ui.printTemplate->setEnabled(true); + + setupTemplates(); } } @@ -97,6 +122,8 @@ void PrintOptions::on_radioStatisticsPrint_toggled(bool check) ui.exportButton->setEnabled(false); ui.importButton->setEnabled(false); ui.printTemplate->setEnabled(false); + + setupTemplates(); } } diff --git a/qt-ui/printoptions.h b/qt-ui/printoptions.h index 6d7ffffee..9c50b10f3 100644 --- a/qt-ui/printoptions.h +++ b/qt-ui/printoptions.h @@ -70,6 +70,7 @@ private: struct print_options *printOptions; struct template_options *templateOptions; bool hasSetupSlots; + void setupTemplates(); private slots: -- cgit v1.2.3-70-g09d2 From 69f2921ffa856e93acb9bc920f3f761db2831880 Mon Sep 17 00:00:00 2001 From: Gehad elrobey Date: Fri, 21 Aug 2015 19:12:33 +0200 Subject: Printing: use the same code for both statistics and divelist print - use the same generic code for both types of templates - check for the printing type before generating the template - remove unused printStatistics() method Signed-off-by: Lubomir I. Ivanov Signed-off-by: Gehad elrobey --- printer.cpp | 66 ++++++++------------------------------------------- printer.h | 1 - qt-ui/printdialog.cpp | 20 +++------------- 3 files changed, 13 insertions(+), 74 deletions(-) (limited to 'qt-ui') diff --git a/printer.cpp b/printer.cpp index 66fed7cf3..3068a6fef 100644 --- a/printer.cpp +++ b/printer.cpp @@ -213,7 +213,11 @@ void Printer::print() webView->page()->mainFrame()->setScrollBarPolicy(Qt::Vertical, Qt::ScrollBarAlwaysOff); // export border width with at least 1 pixel templateOptions->border_width = std::max(1, pageSize.width() / 1000); - webView->setHtml(t.generate()); + if (printOptions->type == print_options::DIVELIST) { + webView->setHtml(t.generate()); + } else if (printOptions->type == print_options::STATISTICS ) { + webView->setHtml(t.generateStatistics()); + } if (printOptions->color_selected && printerPtr->colorMode()) { printerPtr->setColorMode(QPrinter::Color); } else { @@ -238,60 +242,6 @@ void Printer::print() } } -void Printer::print_statistics() -{ - QPrinter *printerPtr; - printerPtr = static_cast(paintDevice); - stats_t total_stats; - - total_stats.selection_size = 0; - total_stats.total_time.seconds = 0; - - QString html; - html += ""; - html += ""; - html += ""; - html += ""; - html += ""; - html += ""; - html += ""; - html += ""; - html += ""; - html += ""; - html += ""; - html += ""; - html += ""; - html += ""; - html += ""; - html += ""; - html += ""; - int i = 0; - while (stats_yearly != NULL && stats_yearly[i].period) { - html += ""; - html += ""; - html += ""; - html += ""; - html += ""; - html += ""; - html += ""; - html += ""; - html += ""; - html += ""; - html += ""; - html += ""; - html += ""; - html += ""; - html += ""; - html += ""; - total_stats.selection_size += stats_yearly[i].selection_size; - total_stats.total_time.seconds += stats_yearly[i].total_time.seconds; - i++; - } - html += "
YearDivesTotal TimeAvg TimeShortest TimeLongest TimeAvg DepthMin DepthMax DepthAvg SACMin SACMax SACMin TempMax Temp
" + QString::number(stats_yearly[i].period) + "" + QString::number(stats_yearly[i].selection_size) + "" + QString::fromUtf8(get_time_string(stats_yearly[i].total_time.seconds, 0)) + "" + QString::fromUtf8(get_minutes(stats_yearly[i].total_time.seconds / stats_yearly[i].selection_size)) + "" + QString::fromUtf8(get_minutes(stats_yearly[i].shortest_time.seconds)) + "" + QString::fromUtf8(get_minutes(stats_yearly[i].longest_time.seconds)) + "" + get_depth_string(stats_yearly[i].avg_depth) + "" + get_depth_string(stats_yearly[i].min_depth) + "" + get_depth_string(stats_yearly[i].max_depth) + "" + get_volume_string(stats_yearly[i].avg_sac) + "" + get_volume_string(stats_yearly[i].min_sac) + "" + get_volume_string(stats_yearly[i].max_sac) + "" + QString::number(stats_yearly[i].min_temp == 0 ? 0 : get_temp_units(stats_yearly[i].min_temp, NULL)) + "" + QString::number(stats_yearly[i].max_temp == 0 ? 0 : get_temp_units(stats_yearly[i].max_temp, NULL)) + "
"; - webView->setHtml(html); - webView->print(printerPtr); -} - void Printer::previewOnePage() { if (printMode == PREVIEW) { @@ -302,7 +252,11 @@ void Printer::previewOnePage() webView->page()->setViewportSize(pageSize); // initialize the border settings templateOptions->border_width = std::max(1, pageSize.width() / 1000); - webView->setHtml(t.generate()); + if (printOptions->type == print_options::DIVELIST) { + webView->setHtml(t.generate()); + } else if (printOptions->type == print_options::STATISTICS ) { + webView->setHtml(t.generateStatistics()); + } bool ok; int divesPerPage = webView->page()->mainFrame()->findFirstElement("body").attribute("data-numberofdives").toInt(&ok); diff --git a/printer.h b/printer.h index 5c7652a8d..979cacd6a 100644 --- a/printer.h +++ b/printer.h @@ -39,7 +39,6 @@ public: Printer(QPaintDevice *paintDevice, print_options *printOptions, template_options *templateOptions, PrintMode printMode); ~Printer(); void print(); - void print_statistics(); void previewOnePage(); signals: diff --git a/qt-ui/printdialog.cpp b/qt-ui/printdialog.cpp index 002f9b9f4..cf08062d2 100644 --- a/qt-ui/printdialog.cpp +++ b/qt-ui/printdialog.cpp @@ -178,15 +178,8 @@ void PrintDialog::printClicked(void) { QPrintDialog printDialog(&qprinter, this); if (printDialog.exec() == QDialog::Accepted) { - switch (printOptions.type) { - case print_options::DIVELIST: - connect(printer, SIGNAL(progessUpdated(int)), progressBar, SLOT(setValue(int))); - printer->print(); - break; - case print_options::STATISTICS: - printer->print_statistics(); - break; - } + connect(printer, SIGNAL(progessUpdated(int)), progressBar, SLOT(setValue(int))); + printer->print(); close(); } } @@ -194,14 +187,7 @@ void PrintDialog::printClicked(void) void PrintDialog::onPaintRequested(QPrinter *printerPtr) { connect(printer, SIGNAL(progessUpdated(int)), progressBar, SLOT(setValue(int))); - switch (printOptions.type) { - case print_options::DIVELIST: - printer->print(); - break; - case print_options::STATISTICS: - printer->print_statistics(); - break; - } + printer->print(); progressBar->setValue(0); disconnect(printer, SIGNAL(progessUpdated(int)), progressBar, SLOT(setValue(int))); } -- cgit v1.2.3-70-g09d2 From b6d373520457d702f47d6026cea1c8c57c6528c5 Mon Sep 17 00:00:00 2001 From: Gehad elrobey Date: Fri, 21 Aug 2015 19:13:20 +0200 Subject: Printing: enable UI elements that now can be used The new statistics code, enable the editing of colors, font, and other template options. This patch enables the UI elements for these features. Signed-off-by: Lubomir I. Ivanov Signed-off-by: Gehad elrobey --- qt-ui/printoptions.cpp | 6 ------ 1 file changed, 6 deletions(-) (limited to 'qt-ui') diff --git a/qt-ui/printoptions.cpp b/qt-ui/printoptions.cpp index 70cd89711..cb944f9d7 100644 --- a/qt-ui/printoptions.cpp +++ b/qt-ui/printoptions.cpp @@ -93,15 +93,12 @@ void PrintOptions::on_radioDiveListPrint_toggled(bool check) printOptions->type = print_options::DIVELIST; // print options - ui.printInColor->setEnabled(true); ui.printSelected->setEnabled(true); // print template ui.deleteButton->setEnabled(true); - ui.editButton->setEnabled(true); ui.exportButton->setEnabled(true); ui.importButton->setEnabled(true); - ui.printTemplate->setEnabled(true); setupTemplates(); } @@ -113,15 +110,12 @@ void PrintOptions::on_radioStatisticsPrint_toggled(bool check) printOptions->type = print_options::STATISTICS; // print options - ui.printInColor->setEnabled(false); ui.printSelected->setEnabled(false); // print template ui.deleteButton->setEnabled(false); - ui.editButton->setEnabled(false); ui.exportButton->setEnabled(false); ui.importButton->setEnabled(false); - ui.printTemplate->setEnabled(false); setupTemplates(); } -- cgit v1.2.3-70-g09d2 From f45fdc8660f912845f37809cae41e2f3b02bc800 Mon Sep 17 00:00:00 2001 From: Gehad elrobey Date: Fri, 21 Aug 2015 19:20:43 +0200 Subject: Printing: disable template editing for statistics templates Editing statistics templates is not supported now, as there is no custom template for statistics printing, so disable the template edit area. Signed-off-by: Lubomir I. Ivanov Signed-off-by: Gehad elrobey --- qt-ui/templateedit.cpp | 3 +++ 1 file changed, 3 insertions(+) (limited to 'qt-ui') diff --git a/qt-ui/templateedit.cpp b/qt-ui/templateedit.cpp index 3315b12ef..b50338090 100644 --- a/qt-ui/templateedit.cpp +++ b/qt-ui/templateedit.cpp @@ -35,6 +35,9 @@ TemplateEdit::TemplateEdit(QWidget *parent, struct print_options *printOptions, ui->plainTextEdit->setPlainText(grantlee_template); editingCustomColors = false; + if (printOptions->type == print_options::STATISTICS) { + ui->plainTextEdit->setEnabled(false); + } updatePreview(); } -- cgit v1.2.3-70-g09d2