2015-06-26 02:21:03 +00:00
|
|
|
#include "templateedit.h"
|
2015-07-05 05:26:39 +00:00
|
|
|
#include "printoptions.h"
|
2015-07-10 19:45:27 +00:00
|
|
|
#include "printer.h"
|
2015-06-26 02:21:03 +00:00
|
|
|
#include "ui_templateedit.h"
|
|
|
|
|
2015-07-07 01:14:43 +00:00
|
|
|
#include <QMessageBox>
|
|
|
|
|
2015-07-05 05:26:39 +00:00
|
|
|
TemplateEdit::TemplateEdit(QWidget *parent, struct print_options *printOptions, struct template_options *templateOptions) :
|
2015-06-26 02:21:03 +00:00
|
|
|
QDialog(parent),
|
|
|
|
ui(new Ui::TemplateEdit)
|
|
|
|
{
|
|
|
|
ui->setupUi(this);
|
|
|
|
this->templateOptions = templateOptions;
|
2015-07-05 05:26:39 +00:00
|
|
|
this->printOptions = printOptions;
|
2015-06-29 01:24:29 +00:00
|
|
|
|
|
|
|
// 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);
|
2015-07-05 05:29:46 +00:00
|
|
|
|
|
|
|
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);
|
2015-07-10 19:45:27 +00:00
|
|
|
|
|
|
|
int width = ui->label->width();
|
|
|
|
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.previewOnePage();
|
|
|
|
ui->label->setPixmap(map.scaled(width, height, Qt::IgnoreAspectRatio));
|
2015-06-26 02:21:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TemplateEdit::~TemplateEdit()
|
|
|
|
{
|
|
|
|
delete ui;
|
|
|
|
}
|
2015-06-29 01:24:29 +00:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
2015-07-05 05:29:46 +00:00
|
|
|
|
|
|
|
void TemplateEdit::on_TemplateEdit_finished(int result)
|
|
|
|
{
|
|
|
|
if (grantlee_template.compare(ui->plainTextEdit->toPlainText())) {
|
2015-07-07 01:14:43 +00:00
|
|
|
QMessageBox msgBox;
|
|
|
|
msgBox.setText("Do you want to save your changes?");
|
|
|
|
msgBox.setStandardButtons(QMessageBox::Save | QMessageBox::Discard);
|
|
|
|
msgBox.setDefaultButton(QMessageBox::Discard);
|
|
|
|
if (msgBox.exec() == QMessageBox::Save) {
|
|
|
|
printOptions->p_template = print_options::CUSTOM;
|
|
|
|
TemplateLayout::writeTemplate("custom.html", ui->plainTextEdit->toPlainText());
|
|
|
|
}
|
2015-07-05 05:29:46 +00:00
|
|
|
}
|
|
|
|
}
|