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-12 03:54:00 +00:00
|
|
|
#include <QColorDialog>
|
2015-07-07 01:14:43 +00:00
|
|
|
|
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-10 23:06:43 +00:00
|
|
|
newTemplateOptions = *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
|
|
|
|
2015-07-24 07:53:07 +00:00
|
|
|
grantlee_template = TemplateLayout::readTemplate(printOptions->p_template);
|
2015-07-05 05:29:46 +00:00
|
|
|
|
2015-07-12 03:54:00 +00:00
|
|
|
// gui
|
|
|
|
btnGroup = new QButtonGroup;
|
|
|
|
btnGroup->addButton(ui->editButton1, 1);
|
|
|
|
btnGroup->addButton(ui->editButton2, 2);
|
|
|
|
btnGroup->addButton(ui->editButton3, 3);
|
|
|
|
btnGroup->addButton(ui->editButton4, 4);
|
|
|
|
btnGroup->addButton(ui->editButton5, 5);
|
|
|
|
connect(btnGroup, SIGNAL(buttonClicked(QAbstractButton*)), this, SLOT(colorSelect(QAbstractButton*)));
|
|
|
|
|
2015-07-05 05:29:46 +00:00
|
|
|
ui->plainTextEdit->setPlainText(grantlee_template);
|
2015-07-29 17:49:50 +00:00
|
|
|
editingCustomColors = false;
|
2015-07-11 10:50:14 +00:00
|
|
|
updatePreview();
|
|
|
|
}
|
|
|
|
|
|
|
|
TemplateEdit::~TemplateEdit()
|
|
|
|
{
|
2015-07-12 03:54:00 +00:00
|
|
|
delete btnGroup;
|
2015-07-11 10:50:14 +00:00
|
|
|
delete ui;
|
|
|
|
}
|
2015-07-10 19:45:27 +00:00
|
|
|
|
2015-07-11 10:50:14 +00:00
|
|
|
void TemplateEdit::updatePreview()
|
|
|
|
{
|
2015-07-12 03:00:03 +00:00
|
|
|
// update Qpixmap preview
|
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));
|
2015-07-11 23:49:43 +00:00
|
|
|
Printer printer(&map, printOptions, &newTemplateOptions, Printer::PREVIEW);
|
2015-07-10 19:45:27 +00:00
|
|
|
printer.previewOnePage();
|
|
|
|
ui->label->setPixmap(map.scaled(width, height, Qt::IgnoreAspectRatio));
|
2015-07-12 03:00:03 +00:00
|
|
|
|
|
|
|
// update colors tab
|
|
|
|
ui->colorLable1->setStyleSheet("QLabel { background-color : \"" + newTemplateOptions.color_palette.color1.name() + "\";}");
|
|
|
|
ui->colorLable2->setStyleSheet("QLabel { background-color : \"" + newTemplateOptions.color_palette.color2.name() + "\";}");
|
|
|
|
ui->colorLable3->setStyleSheet("QLabel { background-color : \"" + newTemplateOptions.color_palette.color3.name() + "\";}");
|
|
|
|
ui->colorLable4->setStyleSheet("QLabel { background-color : \"" + newTemplateOptions.color_palette.color4.name() + "\";}");
|
|
|
|
ui->colorLable5->setStyleSheet("QLabel { background-color : \"" + newTemplateOptions.color_palette.color5.name() + "\";}");
|
|
|
|
|
|
|
|
ui->colorLable1->setText(newTemplateOptions.color_palette.color1.name());
|
|
|
|
ui->colorLable2->setText(newTemplateOptions.color_palette.color2.name());
|
|
|
|
ui->colorLable3->setText(newTemplateOptions.color_palette.color3.name());
|
|
|
|
ui->colorLable4->setText(newTemplateOptions.color_palette.color4.name());
|
|
|
|
ui->colorLable5->setText(newTemplateOptions.color_palette.color5.name());
|
2015-07-13 09:23:35 +00:00
|
|
|
|
|
|
|
// update critical UI elements
|
|
|
|
ui->colorpalette->setCurrentIndex(newTemplateOptions.color_palette_index);
|
2015-06-26 02:21:03 +00:00
|
|
|
}
|
|
|
|
|
2015-06-29 01:24:29 +00:00
|
|
|
void TemplateEdit::on_fontsize_valueChanged(int font_size)
|
|
|
|
{
|
2015-07-10 23:06:43 +00:00
|
|
|
newTemplateOptions.font_size = font_size;
|
2015-07-11 23:49:43 +00:00
|
|
|
updatePreview();
|
2015-06-29 01:24:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void TemplateEdit::on_linespacing_valueChanged(double line_spacing)
|
|
|
|
{
|
2015-07-10 23:06:43 +00:00
|
|
|
newTemplateOptions.line_spacing = line_spacing;
|
2015-07-11 23:49:43 +00:00
|
|
|
updatePreview();
|
2015-06-29 01:24:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void TemplateEdit::on_fontSelection_currentIndexChanged(int index)
|
|
|
|
{
|
2015-07-10 23:06:43 +00:00
|
|
|
newTemplateOptions.font_index = index;
|
2015-07-11 23:49:43 +00:00
|
|
|
updatePreview();
|
2015-06-29 01:24:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void TemplateEdit::on_colorpalette_currentIndexChanged(int index)
|
|
|
|
{
|
2015-07-10 23:06:43 +00:00
|
|
|
newTemplateOptions.color_palette_index = index;
|
2015-07-13 09:23:35 +00:00
|
|
|
switch (newTemplateOptions.color_palette_index) {
|
2015-07-28 17:48:29 +00:00
|
|
|
case SSRF_COLORS: // subsurface derived default colors
|
|
|
|
newTemplateOptions.color_palette = ssrf_colors;
|
|
|
|
break;
|
2015-07-26 17:57:57 +00:00
|
|
|
case ALMOND: // almond
|
2015-07-13 09:23:35 +00:00
|
|
|
newTemplateOptions.color_palette = almond_colors;
|
|
|
|
break;
|
2015-07-26 17:57:57 +00:00
|
|
|
case BLUESHADES: // blueshades
|
2015-07-26 17:13:23 +00:00
|
|
|
newTemplateOptions.color_palette = blueshades_colors;
|
|
|
|
break;
|
2015-07-26 17:57:57 +00:00
|
|
|
case CUSTOM: // custom
|
2015-07-29 17:49:50 +00:00
|
|
|
if (!editingCustomColors)
|
|
|
|
newTemplateOptions.color_palette = custom_colors;
|
|
|
|
else
|
|
|
|
editingCustomColors = false;
|
2015-07-13 09:23:35 +00:00
|
|
|
break;
|
|
|
|
}
|
2015-07-11 23:49:43 +00:00
|
|
|
updatePreview();
|
2015-06-29 01:24:29 +00:00
|
|
|
}
|
2015-07-05 05:29:46 +00:00
|
|
|
|
2015-07-10 23:37:27 +00:00
|
|
|
void TemplateEdit::saveSettings()
|
2015-07-05 05:29:46 +00:00
|
|
|
{
|
2015-07-10 23:06:43 +00:00
|
|
|
if ((*templateOptions) != newTemplateOptions || 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?");
|
2015-07-16 02:52:38 +00:00
|
|
|
msgBox.setStandardButtons(QMessageBox::Save | QMessageBox::Cancel);
|
|
|
|
msgBox.setDefaultButton(QMessageBox::Cancel);
|
2015-07-07 01:14:43 +00:00
|
|
|
if (msgBox.exec() == QMessageBox::Save) {
|
2015-07-10 23:06:43 +00:00
|
|
|
memcpy(templateOptions, &newTemplateOptions, sizeof(struct template_options));
|
2015-07-11 23:49:43 +00:00
|
|
|
if (grantlee_template.compare(ui->plainTextEdit->toPlainText())) {
|
2015-07-24 07:53:07 +00:00
|
|
|
printOptions->p_template = "custom.html";
|
2015-07-11 23:49:43 +00:00
|
|
|
TemplateLayout::writeTemplate("custom.html", ui->plainTextEdit->toPlainText());
|
|
|
|
}
|
2015-07-29 17:35:08 +00:00
|
|
|
if (templateOptions->color_palette_index == CUSTOM) {
|
2015-07-13 09:23:35 +00:00
|
|
|
custom_colors = templateOptions->color_palette;
|
|
|
|
}
|
2015-07-07 01:14:43 +00:00
|
|
|
}
|
2015-07-05 05:29:46 +00:00
|
|
|
}
|
|
|
|
}
|
2015-07-10 23:37:27 +00:00
|
|
|
|
|
|
|
void TemplateEdit::on_buttonBox_clicked(QAbstractButton *button)
|
|
|
|
{
|
|
|
|
QDialogButtonBox::StandardButton standardButton = ui->buttonBox->standardButton(button);
|
|
|
|
switch (standardButton) {
|
|
|
|
case QDialogButtonBox::Ok:
|
|
|
|
saveSettings();
|
|
|
|
break;
|
|
|
|
case QDialogButtonBox::Cancel:
|
|
|
|
break;
|
|
|
|
case QDialogButtonBox::Apply:
|
|
|
|
saveSettings();
|
2015-07-11 10:50:14 +00:00
|
|
|
updatePreview();
|
2015-07-10 23:37:27 +00:00
|
|
|
break;
|
2015-07-18 18:27:33 +00:00
|
|
|
default:
|
|
|
|
;
|
2015-07-10 23:37:27 +00:00
|
|
|
}
|
|
|
|
}
|
2015-07-12 03:54:00 +00:00
|
|
|
|
|
|
|
void TemplateEdit::colorSelect(QAbstractButton *button)
|
|
|
|
{
|
2015-07-29 17:49:50 +00:00
|
|
|
editingCustomColors = true;
|
2015-07-13 09:23:35 +00:00
|
|
|
// reset custom colors palette
|
|
|
|
switch (newTemplateOptions.color_palette_index) {
|
2015-07-28 17:48:29 +00:00
|
|
|
case SSRF_COLORS: // subsurface derived default colors
|
|
|
|
newTemplateOptions.color_palette = ssrf_colors;
|
|
|
|
break;
|
2015-07-26 17:57:57 +00:00
|
|
|
case ALMOND: // almond
|
2015-07-13 09:23:35 +00:00
|
|
|
newTemplateOptions.color_palette = almond_colors;
|
|
|
|
break;
|
2015-07-26 17:57:57 +00:00
|
|
|
case BLUESHADES: // blueshades
|
2015-07-26 17:13:23 +00:00
|
|
|
newTemplateOptions.color_palette = blueshades_colors;
|
2015-07-29 17:49:50 +00:00
|
|
|
break;
|
|
|
|
default:
|
2015-07-26 17:13:23 +00:00
|
|
|
break;
|
2015-07-13 09:23:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//change selected color
|
2015-07-12 03:54:00 +00:00
|
|
|
QColor color;
|
|
|
|
switch (btnGroup->id(button)) {
|
|
|
|
case 1:
|
|
|
|
color = QColorDialog::getColor(newTemplateOptions.color_palette.color1, this);
|
2015-07-28 19:55:23 +00:00
|
|
|
if (color.isValid()) {
|
|
|
|
newTemplateOptions.color_palette.color1 = color;
|
|
|
|
}
|
2015-07-12 03:54:00 +00:00
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
color = QColorDialog::getColor(newTemplateOptions.color_palette.color2, this);
|
2015-07-28 19:55:23 +00:00
|
|
|
if (color.isValid()) {
|
|
|
|
newTemplateOptions.color_palette.color2 = color;
|
|
|
|
} break;
|
2015-07-12 03:54:00 +00:00
|
|
|
case 3:
|
|
|
|
color = QColorDialog::getColor(newTemplateOptions.color_palette.color3, this);
|
2015-07-28 19:55:23 +00:00
|
|
|
if (color.isValid()) {
|
|
|
|
newTemplateOptions.color_palette.color3 = color;
|
|
|
|
} break;
|
2015-07-12 03:54:00 +00:00
|
|
|
case 4:
|
|
|
|
color = QColorDialog::getColor(newTemplateOptions.color_palette.color4, this);
|
2015-07-28 19:55:23 +00:00
|
|
|
if (color.isValid()) {
|
|
|
|
newTemplateOptions.color_palette.color4 = color;
|
|
|
|
} break;
|
2015-07-12 03:54:00 +00:00
|
|
|
case 5:
|
|
|
|
color = QColorDialog::getColor(newTemplateOptions.color_palette.color5, this);
|
2015-07-28 19:55:23 +00:00
|
|
|
if (color.isValid()) {
|
|
|
|
newTemplateOptions.color_palette.color5 = color;
|
|
|
|
} break;
|
2015-07-12 03:54:00 +00:00
|
|
|
}
|
2015-07-26 17:57:57 +00:00
|
|
|
newTemplateOptions.color_palette_index = CUSTOM;
|
2015-07-12 03:54:00 +00:00
|
|
|
updatePreview();
|
|
|
|
}
|