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

This commit is contained in:
Dirk Hohndel 2015-07-28 07:27:30 -07:00
commit f2e2be0f67
15 changed files with 951 additions and 546 deletions

View file

@ -160,7 +160,12 @@ void Printer::print()
divesPerPage = 1; // print each dive in a single page if the attribute is missing or malformed
//TODO: show warning
}
int Pages = ceil(getTotalWork(printOptions) / (float)divesPerPage);
int Pages;
if (divesPerPage == 0) {
Pages = ceil(webView->page()->mainFrame()->contentsSize().height() / (float)pageSize.height());
} else {
Pages = ceil(getTotalWork(printOptions) / (float)divesPerPage);
}
render(Pages);
}

View file

@ -0,0 +1,204 @@
<html>
<head>
<style>
body {
{{ print_options.grayscale }};
padding: 0;
margin: 0;
font-size: {{ template_options.font_size }}vw;
line-height: {{ template_options.line_spacing }};
font-family: {{ template_options.font }};
}
h1 {
float: left;
font-size: {{ template_options.font_size }}vw;
}
table {
-webkit-box-sizing: border-box;
box-sizing: border-box;
border:max(1px, 0.1vw);
border-style:solid;
}
td {
padding-left: 0.5vw;
padding-right: 0.5vw;
}
#body_div {
background-color: {{ template_options.color1 }};
}
.mainContainer {
width: 96%;
margin-left: 2%;
margin-right: 2%;
margin-top: 0%;
margin-bottom: 0%;
overflow: hidden;
border-width: 0;
page-break-inside: avoid;
}
.innerContainer {
width: 98%;
padding: 1%;
overflow: hidden;
}
.diveDetails {
width: 98%;
-webkit-box-sizing: border-box;
box-sizing: border-box;
border:max(1px, 0.1vw);
border-style:solid;
float: left;
}
.dataSection {
width: 98%;
margin: 1%;
}
.fieldTitle {
background-color: {{ template_options.color2 }};
overflow: hidden;
}
.table_class {
float: left;
margin: 1%;
width: 48%;
}
.notes_table_class {
overflow: hidden;
width: 98%;
margin: 1%;
}
.textArea {
line-height: {{ template_options.line_spacing }};
max-height: 19vh;
overflow: hidden;
}
</style>
</head>
<body data-numberofdives = 0>
<div id="body_div">
{% block main_rows %}
{% for dive in dives %}
<div class="mainContainer">
<div class="innerContainer">
<div class="diveDetails">
<div class="dataSection">
<table class="table_class">
<tbody><tr>
<td class="fieldTitle">
<h1> Dive No. </h1>
</td>
<td>
<h1> {{ dive.number }} </h1>
</td>
</tr>
<tr>
<td class="fieldTitle">
<h1> Date </h1>
</td>
<td><h1> {{ dive.date }} </h1>
</td>
</tr>
<tr>
<td class="fieldTitle">
<h1> Location </h1>
</td>
<td>
<h1> {{ dive.location }} </h1>
</td>
</tr>
<tr>
<td class="fieldTitle">
<h1> Max depth </h1>
</td>
<td>
<h1> {{ dive.depth }} </h1>
</td>
</tr>
<tr>
<td class="fieldTitle">
<h1> Duration </h1>
</td>
<td>
<h1> {{ dive.duration }} </h1>
</td>
</tr>
</tbody></table>
<table class="table_class">
<tbody><tr>
<td class="fieldTitle">
<h1> Time. </h1>
</td>
<td>
<h1> {{ dive.time }} </h1>
</td>
</tr>
<tr>
<td class="fieldTitle">
<h1> Air Temp. </h1>
</td>
<td><h1> {{ dive.airTemp }} </h1>
</td>
</tr>
<tr>
<td class="fieldTitle">
<h1> Water Temp. </h1>
</td>
<td>
<h1> {{ dive.waterTemp }} </h1>
</td>
</tr>
<tr>
<td class="fieldTitle">
<h1> Buddy </h1>
</td>
<td>
<h1> {{ dive.buddy }} </h1>
</td>
</tr>
<tr>
<td class="fieldTitle">
<h1> Dive Master </h1>
</td>
<td>
<h1> {{ dive.divemaster }} </h1>
</td>
</tr>
</tbody>
</table>
<table class="notes_table_class">
<tbody>
<tr>
<td class="fieldTitle">
<h1> Notes </h1>
</td>
</tr>
<tr>
<td>
<div class="textArea">
<h1> {{ dive.notes }} </h1>
</div>
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
{% endfor %}
{% endblock %}
</div>
</body>
</html>

View file

@ -0,0 +1,83 @@
<html>
<head>
<style>
body {
{{ print_options.grayscale }};
padding: 0;
margin: 0;
font-size: {{ template_options.font_size }}vw;
line-height: {{ template_options.line_spacing }};
font-family: {{ template_options.font }};
}
h1 {
float: left;
font-size: {{ template_options.font_size }}vw;
}
th {
font-size: {{ template_options.font_size }}vw;
page-break-inside: avoid;
-webkit-column-break-inside: avoid;
padding-top: 1vh;
padding-bottom: 1vh;
}
#body_div {
background-color: {{ template_options.color1 }};
}
.mainContainer {
width: 96%;
height: 100%;
margin-left: 2%;
margin-right: 2%;
margin-top: 0%;
margin-bottom: 0%;
overflow: hidden;
border-width: 0;
page-break-inside: avoid;
}
.table_class {
overflow: hidden;
width: 97%;
margin: 1.5%;
-webkit-box-sizing: border-box;
box-sizing: border-box;
border:max(0.1vw, 1px);
border-style:solid;
border-color: color: {{ template_options.color5 }};
}
</style>
</head>
<body data-numberofdives = 0>
<div id="body_div">
<table class="table_class">
<tr style="background-color: {{ template_options.color2 }}; color: {{ template_options.color3 }}">
<th>Dive #</th>
<th>Date</th>
<th>Time</th>
<th>Depth</th>
<th>Duration</th>
<th>Master</th>
<th>Location</th>
</tr>
{% block main_rows %}
{% for dive in dives %}
<tr style="color: {{ template_options.color4 }}">
<th>{{ dive.number }}</th>
<th>{{ dive.date }}</th>
<th>{{ dive.time }}</th>
<th>{{ dive.depth }}</th>
<th>{{ dive.duration }}</th>
<th>{{ dive.divemaster }}</th>
<th>{{ dive.location }}</th>
</tr>
{% endfor %}
{% endblock %}
</table>
</div>
</body>
</html>

View file

@ -199,6 +199,9 @@ MainWindow::MainWindow() : QMainWindow(),
ReverseGeoLookupThread *geoLookup = ReverseGeoLookupThread::instance();
connect(geoLookup, SIGNAL(started()),information(), SLOT(disableGeoLookupEdition()));
connect(geoLookup, SIGNAL(finished()), information(), SLOT(enableGeoLookupEdition()));
#ifndef NO_PRINTING
find_all_templates();
#endif
}
MainWindow::~MainWindow()

View file

@ -12,7 +12,7 @@
#define SETTINGS_GROUP "PrintDialog"
template_options::color_palette_struct almond_colors, custom_colors;
template_options::color_palette_struct almond_colors, blueshades_colors, custom_colors;
PrintDialog::PrintDialog(QWidget *parent, Qt::WindowFlags f) : QDialog(parent, f)
{
@ -22,6 +22,11 @@ PrintDialog::PrintDialog(QWidget *parent, Qt::WindowFlags f) : QDialog(parent, f
almond_colors.color3 = QColor::fromRgb(136, 160, 150);
almond_colors.color4 = QColor::fromRgb(187, 171, 139);
almond_colors.color5 = QColor::fromRgb(239, 130, 117);
blueshades_colors.color1 = QColor::fromRgb(182, 192, 206);
blueshades_colors.color2 = QColor::fromRgb(142, 152, 166);
blueshades_colors.color3 = QColor::fromRgb(31, 49, 75);
blueshades_colors.color4 = QColor::fromRgb(21, 45, 84);
blueshades_colors.color5 = QColor::fromRgb(5, 25, 56);
// check if the options were previously stored in the settings; if not use some defaults.
QSettings s;
@ -30,11 +35,11 @@ PrintDialog::PrintDialog(QWidget *parent, Qt::WindowFlags f) : QDialog(parent, f
printOptions.print_selected = true;
printOptions.color_selected = true;
printOptions.landscape = false;
printOptions.p_template = print_options::ONE_DIVE;
printOptions.p_template = "one_dive.html";
printOptions.type = print_options::DIVELIST;
templateOptions.font_index = 0;
templateOptions.font_size = 9;
templateOptions.color_palette_index = 0;
templateOptions.color_palette_index = ALMOND;
templateOptions.line_spacing = 1;
custom_colors = almond_colors;
} else {
@ -43,7 +48,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 = (print_options::print_template)s.value("template_selected").toInt();
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();
@ -56,11 +61,22 @@ PrintDialog::PrintDialog(QWidget *parent, Qt::WindowFlags f) : QDialog(parent, f
custom_colors.color5 = QColor(s.value("custom_color_5").toString());
}
// handle cases from old QSettings group
if (templateOptions.font_size < 9) {
templateOptions.font_size = 9;
}
if (templateOptions.line_spacing < 1) {
templateOptions.line_spacing = 1;
}
switch (templateOptions.color_palette_index) {
case 0: // almond
case ALMOND: // almond
templateOptions.color_palette = almond_colors;
break;
case 1: // custom
case BLUESHADES: // blueshades
templateOptions.color_palette = blueshades_colors;
break;
case CUSTOM: // custom
templateOptions.color_palette = custom_colors;
break;
}
@ -140,7 +156,7 @@ void PrintDialog::onFinished()
void PrintDialog::previewClicked(void)
{
if (printOptions.type == print_options::TABLE || printOptions.type == print_options::STATISTICS) {
if (printOptions.type == print_options::STATISTICS) {
QMessageBox msgBox;
msgBox.setText("This feature is not implemented yet");
msgBox.exec();
@ -156,7 +172,7 @@ void PrintDialog::previewClicked(void)
void PrintDialog::printClicked(void)
{
if (printOptions.type == print_options::TABLE || printOptions.type == print_options::STATISTICS) {
if (printOptions.type == print_options::STATISTICS) {
QMessageBox msgBox;
msgBox.setText("This feature is not implemented yet");
msgBox.exec();
@ -170,8 +186,6 @@ void PrintDialog::printClicked(void)
connect(printer, SIGNAL(progessUpdated(int)), progressBar, SLOT(setValue(int)));
printer->print();
break;
case print_options::TABLE:
break;
case print_options::STATISTICS:
break;
}

View file

@ -1,6 +1,10 @@
#include "printoptions.h"
#include "templateedit.h"
#include "helpers.h"
#include <QDebug>
#include <QFileDialog>
#include <QMessageBox>
PrintOptions::PrintOptions(QWidget *parent, struct print_options *printOpt, struct template_options *templateOpt)
{
@ -22,24 +26,26 @@ void PrintOptions::setup()
case print_options::DIVELIST:
ui.radioDiveListPrint->setChecked(true);
break;
case print_options::TABLE:
ui.radioTablePrint->setChecked(true);
break;
case print_options::STATISTICS:
ui.radioStatisticsPrint->setChecked(true);
break;
}
switch (printOptions->p_template) {
case print_options::ONE_DIVE:
ui.printTemplate->setCurrentIndex(0);
break;
case print_options::TWO_DIVE:
ui.printTemplate->setCurrentIndex(1);
break;
case print_options::CUSTOM:
ui.printTemplate->setCurrentIndex(2);
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);
// general print option checkboxes
if (printOptions->color_selected)
@ -65,13 +71,6 @@ void PrintOptions::on_radioDiveListPrint_clicked(bool check)
}
}
void PrintOptions::on_radioTablePrint_clicked(bool check)
{
if (check) {
printOptions->type = print_options::TABLE;
}
}
void PrintOptions::on_radioStatisticsPrint_clicked(bool check)
{
if (check) {
@ -93,17 +92,7 @@ void PrintOptions::printSelectedClicked(bool check)
void PrintOptions::on_printTemplate_currentIndexChanged(int index)
{
switch(index){
case 0:
printOptions->p_template = print_options::ONE_DIVE;
break;
case 1:
printOptions->p_template = print_options::TWO_DIVE;
break;
case 2:
printOptions->p_template = print_options::CUSTOM;
break;
}
printOptions->p_template = ui.printTemplate->itemData(index).toString();
}
void PrintOptions::on_editButton_clicked()
@ -112,3 +101,46 @@ void PrintOptions::on_editButton_clicked()
te.exec();
setup();
}
void PrintOptions::on_importButton_clicked()
{
QString filename = QFileDialog::getOpenFileName(this, tr("Import Template file"), "",
tr("HTML files (*.html)"));
if (filename.isEmpty())
return;
QFileInfo fileInfo(filename);
QFile::copy(filename, getSubsurfaceDataPath("printing_templates") + QDir::separator() + fileInfo.fileName());
printOptions->p_template = fileInfo.fileName();
find_all_templates();
setup();
}
void PrintOptions::on_exportButton_clicked()
{
QString filename = QFileDialog::getSaveFileName(this, tr("Export Template files as"), "",
tr("HTML files (*.html)"));
if (filename.isEmpty())
return;
QFile::copy(getSubsurfaceDataPath("printing_templates") + QDir::separator() + getSelectedTemplate(), filename);
}
void PrintOptions::on_deleteButton_clicked()
{
QString templateName = getSelectedTemplate();
QMessageBox msgBox;
msgBox.setText("This action cannot be undone!");
msgBox.setInformativeText("Delete '" + templateName + "' template?");
msgBox.setStandardButtons(QMessageBox::Ok | QMessageBox::Cancel);
msgBox.setDefaultButton(QMessageBox::Cancel);
if (msgBox.exec() == QMessageBox::Ok) {
QFile f(getSubsurfaceDataPath("printing_templates") + QDir::separator() + templateName);
f.remove();
find_all_templates();
setup();
}
}
QString PrintOptions::getSelectedTemplate()
{
return ui.printTemplate->currentData().toString();
}

View file

@ -8,14 +8,9 @@
struct print_options {
enum print_type {
DIVELIST,
TABLE,
STATISTICS
} type;
enum print_template {
ONE_DIVE,
TWO_DIVE,
CUSTOM
} p_template;
QString p_template;
bool print_selected;
bool color_selected;
bool landscape;
@ -49,7 +44,13 @@ struct template_options {
}
};
extern template_options::color_palette_struct almond_colors, custom_colors;
extern template_options::color_palette_struct almond_colors, blueshades_colors, custom_colors;
enum color_palette {
ALMOND,
BLUESHADES,
CUSTOM
};
// should be based on a custom QPrintDialog class
class PrintOptions : public QWidget {
@ -58,6 +59,7 @@ class PrintOptions : public QWidget {
public:
explicit PrintOptions(QWidget *parent, struct print_options *printOpt, struct template_options *templateOpt);
void setup();
QString getSelectedTemplate();
private:
Ui::PrintOptions ui;
@ -70,10 +72,12 @@ slots:
void printInColorClicked(bool check);
void printSelectedClicked(bool check);
void on_radioStatisticsPrint_clicked(bool check);
void on_radioTablePrint_clicked(bool check);
void on_radioDiveListPrint_clicked(bool check);
void on_printTemplate_currentIndexChanged(int index);
void on_editButton_clicked();
void on_importButton_clicked();
void on_exportButton_clicked();
void on_deleteButton_clicked();
};
#endif // PRINTOPTIONS_H

View file

@ -46,19 +46,6 @@
</widget>
</item>
<item row="2" column="0">
<widget class="QRadioButton" name="radioTablePrint">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>&amp;Table print</string>
</property>
</widget>
</item>
<item row="3" column="0" colspan="2">
<widget class="QRadioButton" name="radioStatisticsPrint">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
@ -71,19 +58,6 @@
</property>
</widget>
</item>
<item row="2" column="2" rowspan="2">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</item>
@ -129,36 +103,55 @@
</property>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QComboBox" name="printTemplate">
<layout class="QVBoxLayout" name="verticalLayout_4">
<item>
<property name="text">
<string>One dive per page</string>
</property>
<widget class="QComboBox" name="printTemplate"/>
</item>
<item>
<property name="text">
<string>Two dives per page</string>
</property>
<layout class="QGridLayout" name="gridLayout_2">
<item row="1" column="0">
<widget class="QPushButton" name="editButton">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="maximumSize">
<size>
<width>16777215</width>
<height>16777215</height>
</size>
</property>
<property name="text">
<string>Edit</string>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QPushButton" name="deleteButton">
<property name="text">
<string>Delete</string>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QPushButton" name="exportButton">
<property name="text">
<string>Export</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QPushButton" name="importButton">
<property name="text">
<string>Import</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<property name="text">
<string>Custom template</string>
</property>
</item>
</widget>
</item>
<item>
<widget class="QPushButton" name="editButton">
<property name="maximumSize">
<size>
<width>106</width>
<height>26</height>
</size>
</property>
<property name="text">
<string>Edit</string>
</property>
</widget>
</layout>
</item>
</layout>
</widget>
@ -167,7 +160,6 @@
</widget>
<tabstops>
<tabstop>radioDiveListPrint</tabstop>
<tabstop>radioStatisticsPrint</tabstop>
<tabstop>printSelected</tabstop>
<tabstop>printInColor</tabstop>
</tabstops>

View file

@ -21,13 +21,7 @@ TemplateEdit::TemplateEdit(QWidget *parent, struct print_options *printOptions,
ui->colorpalette->setCurrentIndex(templateOptions->color_palette_index);
ui->linespacing->setValue(templateOptions->line_spacing);
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");
}
grantlee_template = TemplateLayout::readTemplate(printOptions->p_template);
// gui
btnGroup = new QButtonGroup;
@ -98,10 +92,13 @@ void TemplateEdit::on_colorpalette_currentIndexChanged(int index)
{
newTemplateOptions.color_palette_index = index;
switch (newTemplateOptions.color_palette_index) {
case 0: // almond
case ALMOND: // almond
newTemplateOptions.color_palette = almond_colors;
break;
case 1: // custom
case BLUESHADES: // blueshades
newTemplateOptions.color_palette = blueshades_colors;
break;
case CUSTOM: // custom
newTemplateOptions.color_palette = custom_colors;
break;
}
@ -118,10 +115,10 @@ 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 = print_options::CUSTOM;
printOptions->p_template = "custom.html";
TemplateLayout::writeTemplate("custom.html", ui->plainTextEdit->toPlainText());
}
if (templateOptions->color_palette_index == 1) {
if (templateOptions->color_palette_index == 2) {
custom_colors = templateOptions->color_palette;
}
}
@ -150,10 +147,14 @@ void TemplateEdit::colorSelect(QAbstractButton *button)
{
// reset custom colors palette
switch (newTemplateOptions.color_palette_index) {
case 0: // almond
case ALMOND: // almond
newTemplateOptions.color_palette = almond_colors;
custom_colors = newTemplateOptions.color_palette;
break;
case BLUESHADES: // blueshades
newTemplateOptions.color_palette = blueshades_colors;
custom_colors = newTemplateOptions.color_palette;
break;
}
//change selected color
@ -180,6 +181,6 @@ void TemplateEdit::colorSelect(QAbstractButton *button)
newTemplateOptions.color_palette.color5 = color;
break;
}
newTemplateOptions.color_palette_index = 1;
newTemplateOptions.color_palette_index = CUSTOM;
updatePreview();
}

View file

@ -6,436 +6,493 @@
<rect>
<x>0</x>
<y>0</y>
<width>774</width>
<width>770</width>
<height>433</height>
</rect>
</property>
<property name="windowTitle">
<string>Edit Template</string>
</property>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="geometry">
<rect>
<x>400</x>
<y>380</y>
<width>341</width>
<height>32</height>
</rect>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Apply|QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
<widget class="QTabWidget" name="tabWidget">
<property name="geometry">
<rect>
<x>300</x>
<y>30</y>
<width>441</width>
<height>331</height>
</rect>
</property>
<property name="currentIndex">
<number>2</number>
</property>
<widget class="QWidget" name="style">
<attribute name="title">
<string>Style</string>
</attribute>
<widget class="QWidget" name="verticalLayoutWidget">
<property name="geometry">
<rect>
<x>10</x>
<y>20</y>
<width>401</width>
<height>171</height>
</rect>
<layout class="QVBoxLayout" name="verticalLayout_8">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_10">
<item>
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
<spacer name="verticalSpacer_4">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QLabel" name="label_2">
<property name="text">
<string>Preview</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>180</width>
<height>240</height>
</size>
</property>
<property name="baseSize">
<size>
<width>180</width>
<height>254</height>
</size>
</property>
<property name="styleSheet">
<string notr="true"/>
</property>
<property name="text">
<string/>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer_3">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
<widget class="QTabWidget" name="tabWidget">
<property name="autoFillBackground">
<bool>false</bool>
</property>
<property name="currentIndex">
<number>0</number>
</property>
<widget class="QWidget" name="style">
<attribute name="title">
<string>Style</string>
</attribute>
<layout class="QHBoxLayout" name="horizontalLayout_11">
<item>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_4">
<item>
<widget class="QLabel" name="fontselection_label">
<property name="text">
<string>Font</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="fontSelection">
<item>
<property name="text">
<string>Arial</string>
</property>
</item>
<item>
<property name="text">
<string>Impact</string>
</property>
</item>
<item>
<property name="text">
<string>Georgia</string>
</property>
</item>
<item>
<property name="text">
<string>Courier</string>
</property>
</item>
<item>
<property name="text">
<string>Verdana</string>
</property>
</item>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<widget class="QLabel" name="fontsize_label">
<property name="text">
<string>Font size</string>
</property>
</widget>
</item>
<item>
<widget class="QSpinBox" name="fontsize">
<property name="minimum">
<number>9</number>
</property>
<property name="maximum">
<number>18</number>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLabel" name="colorpalette_label">
<property name="text">
<string>Color pallet</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="colorpalette">
<item>
<property name="text">
<string>Almond</string>
</property>
</item>
<item>
<property name="text">
<string>Shades of blue</string>
</property>
</item>
<item>
<property name="text">
<string>Custom</string>
</property>
</item>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QLabel" name="linespacing_label">
<property name="text">
<string>Line spacing</string>
</property>
</widget>
</item>
<item>
<widget class="QDoubleSpinBox" name="linespacing">
<property name="minimum">
<double>1.000000000000000</double>
</property>
<property name="maximum">
<double>3.000000000000000</double>
</property>
<property name="singleStep">
<double>0.250000000000000</double>
</property>
<property name="value">
<double>1.250000000000000</double>
</property>
</widget>
</item>
</layout>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
</layout>
</widget>
<widget class="QWidget" name="template_2">
<attribute name="title">
<string>Template</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout_4">
<item>
<widget class="QPlainTextEdit" name="plainTextEdit">
<property name="horizontalScrollBarPolicy">
<enum>Qt::ScrollBarAsNeeded</enum>
</property>
<property name="lineWrapMode">
<enum>QPlainTextEdit::NoWrap</enum>
</property>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="color_tab">
<property name="maximumSize">
<size>
<width>16777215</width>
<height>16777215</height>
</size>
</property>
<attribute name="title">
<string>Colors</string>
</attribute>
<layout class="QHBoxLayout" name="horizontalLayout_12">
<item>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_5">
<item>
<widget class="QLabel" name="label_3">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Background</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="colorLable1">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>color1</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="editButton1">
<property name="text">
<string>Edit</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_8">
<item>
<widget class="QLabel" name="label_9">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Table cells</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="colorLable2">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>color2</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="editButton2">
<property name="text">
<string>Edit</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_7">
<item>
<widget class="QLabel" name="label_7">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Text 1</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="colorLable3">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>color3</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="editButton3">
<property name="text">
<string>Edit</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_9">
<item>
<widget class="QLabel" name="label_11">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Text 2</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="colorLable4">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>color4</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="editButton4">
<property name="text">
<string>Edit</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_6">
<item>
<widget class="QLabel" name="label_4">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Borders</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="colorLable5">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>color5</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="editButton5">
<property name="text">
<string>Edit</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<spacer name="verticalSpacer_2">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
</layout>
</widget>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_4">
<item>
<widget class="QLabel" name="fontselection_label">
<property name="text">
<string>Font</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="fontSelection">
<item>
<property name="text">
<string>Arial</string>
</property>
</item>
<item>
<property name="text">
<string>Impact</string>
</property>
</item>
<item>
<property name="text">
<string>Georgia</string>
</property>
</item>
<item>
<property name="text">
<string>Courier</string>
</property>
</item>
<item>
<property name="text">
<string>Verdana</string>
</property>
</item>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<widget class="QLabel" name="fontsize_label">
<property name="text">
<string>Font size</string>
</property>
</widget>
</item>
<item>
<widget class="QSpinBox" name="fontsize">
<property name="minimum">
<number>9</number>
</property>
<property name="maximum">
<number>18</number>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLabel" name="colorpalette_label">
<property name="text">
<string>Color pallet</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="colorpalette">
<item>
<property name="text">
<string>Almond</string>
</property>
</item>
<item>
<property name="text">
<string>Custom</string>
</property>
</item>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QLabel" name="linespacing_label">
<property name="text">
<string>Line spacing</string>
</property>
</widget>
</item>
<item>
<widget class="QDoubleSpinBox" name="linespacing">
<property name="minimum">
<double>1.000000000000000</double>
</property>
<property name="maximum">
<double>3.000000000000000</double>
</property>
<property name="singleStep">
<double>0.250000000000000</double>
</property>
<property name="value">
<double>1.250000000000000</double>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</widget>
<widget class="QWidget" name="template_2">
<attribute name="title">
<string>Template</string>
</attribute>
<widget class="QPlainTextEdit" name="plainTextEdit">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>441</width>
<height>301</height>
</rect>
</property>
<property name="horizontalScrollBarPolicy">
<enum>Qt::ScrollBarAsNeeded</enum>
</property>
<property name="lineWrapMode">
<enum>QPlainTextEdit::NoWrap</enum>
<property name="standardButtons">
<set>QDialogButtonBox::Apply|QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</widget>
<widget class="QWidget" name="color_tab">
<attribute name="title">
<string>Colors</string>
</attribute>
<widget class="QWidget" name="verticalLayoutWidget_2">
<property name="geometry">
<rect>
<x>10</x>
<y>30</y>
<width>411</width>
<height>171</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_5">
<item>
<widget class="QLabel" name="label_3">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Background</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="colorLable1">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>color1</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="editButton1">
<property name="text">
<string>Edit</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_8">
<item>
<widget class="QLabel" name="label_9">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Table cells</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="colorLable2">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>color2</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="editButton2">
<property name="text">
<string>Edit</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_7">
<item>
<widget class="QLabel" name="label_7">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Text 1</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="colorLable3">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>color3</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="editButton3">
<property name="text">
<string>Edit</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_9">
<item>
<widget class="QLabel" name="label_11">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Text 2</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="colorLable4">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>color4</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="editButton4">
<property name="text">
<string>Edit</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_6">
<item>
<widget class="QLabel" name="label_4">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Borders</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="colorLable5">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>color5</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="editButton5">
<property name="text">
<string>Edit</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</widget>
</widget>
<widget class="QLabel" name="label_5">
<property name="geometry">
<rect>
<x>30</x>
<y>30</y>
<width>59</width>
<height>14</height>
</rect>
</property>
<property name="text">
<string>Preview</string>
</property>
</widget>
<widget class="QLabel" name="label">
<property name="geometry">
<rect>
<x>50</x>
<y>70</y>
<width>211</width>
<height>291</height>
</rect>
</property>
<property name="text">
<string/>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections>

View file

@ -4,6 +4,8 @@
#include "helpers.h"
#include "display.h"
QList<QString> grantlee_templates;
int getTotalWork(print_options *printOptions)
{
if (printOptions->print_selected) {
@ -19,6 +21,19 @@ int getTotalWork(print_options *printOptions)
return dives;
}
void find_all_templates()
{
grantlee_templates.clear();
QDir dir(getSubsurfaceDataPath("printing_templates"));
QFileInfoList list = dir.entryInfoList(QDir::Files | QDir::NoDotAndDotDot);
foreach (QFileInfo finfo, list) {
QString filename = finfo.fileName();
if (filename.at(filename.size() - 1) != '~') {
grantlee_templates.append(finfo.fileName());
}
}
}
TemplateLayout::TemplateLayout(print_options *PrintOptions, template_options *templateOptions) :
m_engine(NULL)
{
@ -35,7 +50,6 @@ QString TemplateLayout::generate()
{
int progress = 0;
int totalWork = getTotalWork(PrintOptions);
QString templateName;
QString htmlContent;
m_engine = new Grantlee::Engine(this);
@ -69,14 +83,7 @@ QString TemplateLayout::generate()
Grantlee::Context c(mapping);
if (PrintOptions->p_template == print_options::ONE_DIVE) {
templateName = "one_dive.html";
} else if (PrintOptions->p_template == print_options::TWO_DIVE) {
templateName = "two_dives.html";
} else if (PrintOptions->p_template == print_options::CUSTOM) {
templateName = "custom.html";
}
Grantlee::Template t = m_engine->loadByName(templateName);
Grantlee::Template t = m_engine->loadByName(PrintOptions->p_template);
if (!t || t->error()) {
qDebug() << "Can't load template";
return htmlContent;

View file

@ -6,6 +6,9 @@
#include "printoptions.h"
int getTotalWork(print_options *printOptions);
void find_all_templates();
extern QList<QString> grantlee_templates;
class TemplateLayout : public QObject {
Q_OBJECT