From 18282aa30e191e1af0dda7261a692c8bb82dc139 Mon Sep 17 00:00:00 2001 From: Gehad elrobey Date: Sun, 12 Jul 2015 01:49:43 +0200 Subject: [PATCH] Printing: update preview on field changes - Trigger re-rendering on the QPixmap if fields changed. - Change template selection to custom if template text changed. Signed-off-by: Gehad elrobey Signed-off-by: Lubomir I. Ivanov --- qt-ui/templateedit.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/qt-ui/templateedit.cpp b/qt-ui/templateedit.cpp index bd4763107..8d216d998 100644 --- a/qt-ui/templateedit.cpp +++ b/qt-ui/templateedit.cpp @@ -43,7 +43,7 @@ void TemplateEdit::updatePreview() int height = ui->label->height(); QPixmap map(width * 2, height * 2); map.fill(QColor::fromRgb(255, 255, 255)); - Printer printer(&map, printOptions, templateOptions, Printer::PREVIEW); + Printer printer(&map, printOptions, &newTemplateOptions, Printer::PREVIEW); printer.previewOnePage(); ui->label->setPixmap(map.scaled(width, height, Qt::IgnoreAspectRatio)); } @@ -51,21 +51,25 @@ void TemplateEdit::updatePreview() void TemplateEdit::on_fontsize_valueChanged(int font_size) { newTemplateOptions.font_size = font_size; + updatePreview(); } void TemplateEdit::on_linespacing_valueChanged(double line_spacing) { newTemplateOptions.line_spacing = line_spacing; + updatePreview(); } void TemplateEdit::on_fontSelection_currentIndexChanged(int index) { newTemplateOptions.font_index = index; + updatePreview(); } void TemplateEdit::on_colorpalette_currentIndexChanged(int index) { newTemplateOptions.color_palette_index = index; + updatePreview(); } void TemplateEdit::saveSettings() @@ -77,8 +81,10 @@ void TemplateEdit::saveSettings() msgBox.setDefaultButton(QMessageBox::Discard); if (msgBox.exec() == QMessageBox::Save) { memcpy(templateOptions, &newTemplateOptions, sizeof(struct template_options)); - printOptions->p_template = print_options::CUSTOM; - TemplateLayout::writeTemplate("custom.html", ui->plainTextEdit->toPlainText()); + if (grantlee_template.compare(ui->plainTextEdit->toPlainText())) { + printOptions->p_template = print_options::CUSTOM; + TemplateLayout::writeTemplate("custom.html", ui->plainTextEdit->toPlainText()); + } } } }