Merge branch 'custom-print' of github.com:neolit123/subsurface

This commit is contained in:
Dirk Hohndel 2015-08-23 07:38:11 -07:00
commit 2f540b56a8
13 changed files with 479 additions and 133 deletions

View file

@ -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)));
}

View file

@ -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<QString>::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<QString>::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<QString>::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<QString>::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<QString>::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<QString>::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)
{
@ -70,15 +93,14 @@ 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();
}
}
@ -88,15 +110,14 @@ 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();
}
}

View file

@ -70,6 +70,7 @@ private:
struct print_options *printOptions;
struct template_options *templateOptions;
bool hasSetupSlots;
void setupTemplates();
private
slots:

View file

@ -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();
}
@ -125,8 +128,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;