From 2a85be91b1bc3ae80a75e5508ffdfc7b7e4c1daa Mon Sep 17 00:00:00 2001 From: Gehad elrobey Date: Fri, 24 Jul 2015 14:27:33 +0200 Subject: 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(-) (limited to 'qt-ui') 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) -- cgit v1.2.3-70-g09d2