mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
Merge branch 'custom-print' of github.com:neolit123/subsurface
This commit is contained in:
commit
9c6a3a7ff3
16 changed files with 615 additions and 52 deletions
|
@ -118,6 +118,7 @@ else()
|
||||||
set(SUBSURFACE_PRINTING_SRCS
|
set(SUBSURFACE_PRINTING_SRCS
|
||||||
printer.cpp
|
printer.cpp
|
||||||
templatelayout.cpp
|
templatelayout.cpp
|
||||||
|
qt-ui/templateedit.cpp
|
||||||
)
|
)
|
||||||
set(PRINTING_PKG PrintSupport)
|
set(PRINTING_PKG PrintSupport)
|
||||||
set(PRINTING_LIB Qt5::PrintSupport)
|
set(PRINTING_LIB Qt5::PrintSupport)
|
||||||
|
|
36
printer.cpp
36
printer.cpp
|
@ -6,10 +6,11 @@
|
||||||
#include <QWebElementCollection>
|
#include <QWebElementCollection>
|
||||||
#include <QWebElement>
|
#include <QWebElement>
|
||||||
|
|
||||||
Printer::Printer(QPrinter *printer, print_options *printOptions)
|
Printer::Printer(QPrinter *printer, print_options *printOptions, template_options *templateOptions)
|
||||||
{
|
{
|
||||||
this->printer = printer;
|
this->printer = printer;
|
||||||
this->printOptions = printOptions;
|
this->printOptions = printOptions;
|
||||||
|
this->templateOptions = templateOptions;
|
||||||
dpi = 0;
|
dpi = 0;
|
||||||
done = 0;
|
done = 0;
|
||||||
}
|
}
|
||||||
|
@ -26,9 +27,25 @@ void Printer::putProfileImage(QRect profilePlaceholder, QRect viewPort, QPainter
|
||||||
|
|
||||||
void Printer::render()
|
void Printer::render()
|
||||||
{
|
{
|
||||||
QPointer<ProfileWidget2> profile = MainWindow::instance()->graphics();
|
// apply user settings
|
||||||
|
int divesPerPage;
|
||||||
|
if (printOptions->color_selected && printer->colorMode()) {
|
||||||
|
printer->setColorMode(QPrinter::Color);
|
||||||
|
} else {
|
||||||
|
printer->setColorMode(QPrinter::GrayScale);
|
||||||
|
}
|
||||||
|
|
||||||
|
// get number of dives per page from data-numberofdives attribute in the body of the selected template
|
||||||
|
bool ok;
|
||||||
|
divesPerPage = webView->page()->mainFrame()->findFirstElement("body").attribute("data-numberofdives").toInt(&ok);
|
||||||
|
if (!ok) {
|
||||||
|
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);
|
||||||
|
|
||||||
// keep original preferences
|
// keep original preferences
|
||||||
|
QPointer<ProfileWidget2> profile = MainWindow::instance()->graphics();
|
||||||
int profileFrameStyle = profile->frameStyle();
|
int profileFrameStyle = profile->frameStyle();
|
||||||
int animationOriginal = prefs.animation_speed;
|
int animationOriginal = prefs.animation_speed;
|
||||||
double fontScale = profile->getFontPrintScale();
|
double fontScale = profile->getFontPrintScale();
|
||||||
|
@ -36,7 +53,7 @@ void Printer::render()
|
||||||
// apply printing settings to profile
|
// apply printing settings to profile
|
||||||
profile->setFrameStyle(QFrame::NoFrame);
|
profile->setFrameStyle(QFrame::NoFrame);
|
||||||
profile->setPrintMode(true, !printOptions->color_selected);
|
profile->setPrintMode(true, !printOptions->color_selected);
|
||||||
profile->setFontPrintScale(0.6);
|
profile->setFontPrintScale(printer->pageLayout().paintRect(QPageLayout::Inch).width() * dpi * 0.001);
|
||||||
profile->setToolTipVisibile(false);
|
profile->setToolTipVisibile(false);
|
||||||
prefs.animation_speed = 0;
|
prefs.animation_speed = 0;
|
||||||
|
|
||||||
|
@ -47,17 +64,6 @@ void Printer::render()
|
||||||
painter.setRenderHint(QPainter::Antialiasing);
|
painter.setRenderHint(QPainter::Antialiasing);
|
||||||
painter.setRenderHint(QPainter::SmoothPixmapTransform);
|
painter.setRenderHint(QPainter::SmoothPixmapTransform);
|
||||||
|
|
||||||
int divesPerPage;
|
|
||||||
switch (printOptions->p_template) {
|
|
||||||
case print_options::ONE_DIVE:
|
|
||||||
divesPerPage = 1;
|
|
||||||
break;
|
|
||||||
case print_options::TWO_DIVE:
|
|
||||||
divesPerPage = 2;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
int Pages = ceil(getTotalWork() / (float)divesPerPage);
|
|
||||||
|
|
||||||
// get all refereces to diveprofile class in the Html template
|
// get all refereces to diveprofile class in the Html template
|
||||||
QWebElementCollection collection = webView->page()->mainFrame()->findAllElements(".diveprofile");
|
QWebElementCollection collection = webView->page()->mainFrame()->findAllElements(".diveprofile");
|
||||||
|
|
||||||
|
@ -111,7 +117,7 @@ void Printer::templateProgessUpdated(int value)
|
||||||
|
|
||||||
void Printer::print()
|
void Printer::print()
|
||||||
{
|
{
|
||||||
TemplateLayout t(printOptions);
|
TemplateLayout t(printOptions, templateOptions);
|
||||||
webView = new QWebView();
|
webView = new QWebView();
|
||||||
connect(&t, SIGNAL(progressUpdated(int)), this, SLOT(templateProgessUpdated(int)));
|
connect(&t, SIGNAL(progressUpdated(int)), this, SLOT(templateProgessUpdated(int)));
|
||||||
|
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
|
|
||||||
#include "profile/profilewidget2.h"
|
#include "profile/profilewidget2.h"
|
||||||
#include "printoptions.h"
|
#include "printoptions.h"
|
||||||
|
#include "templateedit.h"
|
||||||
|
|
||||||
class Printer : public QObject {
|
class Printer : public QObject {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
@ -16,6 +17,7 @@ private:
|
||||||
QPrinter *printer;
|
QPrinter *printer;
|
||||||
QWebView *webView;
|
QWebView *webView;
|
||||||
print_options *printOptions;
|
print_options *printOptions;
|
||||||
|
template_options *templateOptions;
|
||||||
QSize pageSize;
|
QSize pageSize;
|
||||||
int done;
|
int done;
|
||||||
int dpi;
|
int dpi;
|
||||||
|
@ -26,7 +28,7 @@ private slots:
|
||||||
void templateProgessUpdated(int value);
|
void templateProgessUpdated(int value);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Printer(QPrinter *printer, print_options *printOptions);
|
Printer(QPrinter *printer, print_options *printOptions, template_options *templateOptions);
|
||||||
void print();
|
void print();
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
|
|
50
printing_templates/custom.html
Normal file
50
printing_templates/custom.html
Normal file
|
@ -0,0 +1,50 @@
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<style>
|
||||||
|
body {
|
||||||
|
background-color: white;
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
.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;
|
||||||
|
}
|
||||||
|
|
||||||
|
.innerContainer {
|
||||||
|
width: 98%;
|
||||||
|
height: 98%;
|
||||||
|
padding: 1%;
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body data-numberofdives = 1>
|
||||||
|
{% block main_rows %}
|
||||||
|
{% for dive in dives %}
|
||||||
|
<div class="mainContainer">
|
||||||
|
<div class="innerContainer">
|
||||||
|
<h1>This template is empty</h1>
|
||||||
|
<!-- Template must be filled -->
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{% endfor %}
|
||||||
|
{% endblock %}
|
||||||
|
</body>
|
||||||
|
</html>
|
|
@ -5,12 +5,14 @@
|
||||||
background-color: white;
|
background-color: white;
|
||||||
padding: 0;
|
padding: 0;
|
||||||
margin: 0;
|
margin: 0;
|
||||||
font-size: 1.2vw;
|
font-size: {{ template_options.font_size }}vw;
|
||||||
|
line-height: {{ template_options.line_spacing }};
|
||||||
|
font-family: {{ template_options.font }};
|
||||||
}
|
}
|
||||||
|
|
||||||
h1 {
|
h1 {
|
||||||
font-size: 1.2vw;
|
|
||||||
float: left;
|
float: left;
|
||||||
|
font-size: {{ template_options.font_size }}vw;
|
||||||
}
|
}
|
||||||
|
|
||||||
table {
|
table {
|
||||||
|
@ -84,9 +86,13 @@
|
||||||
margin: 1.5%;
|
margin: 1.5%;
|
||||||
float: left;
|
float: left;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.textArea {
|
||||||
|
line-height: {{ template_options.line_spacing }};
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body data-numberofdives = 1>
|
||||||
{% block main_rows %}
|
{% block main_rows %}
|
||||||
{% for dive in dives %}
|
{% for dive in dives %}
|
||||||
<div class="mainContainer">
|
<div class="mainContainer">
|
||||||
|
|
|
@ -5,10 +5,13 @@
|
||||||
background-color: white;
|
background-color: white;
|
||||||
padding: 0px;
|
padding: 0px;
|
||||||
margin: 0px;
|
margin: 0px;
|
||||||
|
font-size: {{ template_options.font_size }}vw;
|
||||||
|
line-height: {{ template_options.line_spacing }};
|
||||||
|
font-family: {{ template_options.font }};
|
||||||
}
|
}
|
||||||
|
|
||||||
h1 {
|
h1 {
|
||||||
font-size: 0.9cm;
|
font-size: {{ template_options.font_size }}vw;
|
||||||
float: left;
|
float: left;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -20,49 +23,56 @@
|
||||||
margin-top: 0;
|
margin-top: 0;
|
||||||
margin-bottom: 0;
|
margin-bottom: 0;
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
border-width: 0px;
|
|
||||||
page-break-inside: avoid;
|
page-break-inside: avoid;
|
||||||
}
|
}
|
||||||
|
|
||||||
.innerContainer {
|
.innerContainer {
|
||||||
height: 85%;
|
height: 85%;
|
||||||
border-style: solid;
|
|
||||||
padding: 0.5%;
|
padding: 0.5%;
|
||||||
margin-top: 1%;
|
margin-top: 1%;
|
||||||
margin-bottom: 1%;
|
margin-bottom: 1%;
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
|
-webkit-box-sizing: border-box;
|
||||||
|
box-sizing: border-box;
|
||||||
|
border:max(0.1vw, 1px);
|
||||||
|
border-style:solid;
|
||||||
}
|
}
|
||||||
|
|
||||||
.table_class {
|
.table_class {
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
max-width: 25%;
|
max-width: 25%;
|
||||||
min-width: 25%;
|
min-width: 25%;
|
||||||
box-shadow: 5px 5px 5px #888888;
|
|
||||||
margin: 1.5%;
|
margin: 1.5%;
|
||||||
float: left;
|
float: left;
|
||||||
|
-webkit-box-sizing: border-box;
|
||||||
|
box-sizing: border-box;
|
||||||
|
border:max(0.1vw, 1px);
|
||||||
|
border-style:solid;
|
||||||
}
|
}
|
||||||
|
|
||||||
.notes_table_class {
|
.notes_table_class {
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
max-width: 100%;
|
max-width: 100%;
|
||||||
min-width: 100%;
|
min-width: 100%;
|
||||||
box-shadow: 5px 5px 5px #888888;
|
|
||||||
margin: 1.5%;
|
margin: 1.5%;
|
||||||
float: left;
|
float: left;
|
||||||
|
-webkit-box-sizing: border-box;
|
||||||
|
box-sizing: border-box;
|
||||||
|
border:max(0.1vw, 1px);
|
||||||
|
border-style:solid;
|
||||||
}
|
}
|
||||||
|
|
||||||
.fieldTitle {
|
.fieldTitle {
|
||||||
background-color: #CfC7C5;
|
background-color: #CfC7C5;
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
|
padding:0;
|
||||||
}
|
}
|
||||||
|
|
||||||
.diveProfile {
|
.diveProfile {
|
||||||
width: 37%;
|
width: 37%;
|
||||||
height: 70%;
|
height: 95%;
|
||||||
margin: 1.5%;
|
margin: 1.5%;
|
||||||
float: right;
|
float: right;
|
||||||
border-style: solid;
|
|
||||||
padding: 3mm;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.diveDetails {
|
.diveDetails {
|
||||||
|
@ -80,9 +90,10 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
.textArea {
|
.textArea {
|
||||||
max-height: 43ex;
|
|
||||||
overflow: hidden !important;
|
overflow: hidden !important;
|
||||||
text-overflow: ellipsis;
|
text-overflow: ellipsis;
|
||||||
|
max-height: 10.3vw;
|
||||||
|
line-height: {{ template_options.line_spacing }};
|
||||||
}
|
}
|
||||||
|
|
||||||
#footer {
|
#footer {
|
||||||
|
@ -91,14 +102,14 @@
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body data-numberofdives = 2>
|
||||||
{% block main_rows %}
|
{% block main_rows %}
|
||||||
{% for dive in dives %}
|
{% for dive in dives %}
|
||||||
<div class="mainContainer">
|
<div class="mainContainer">
|
||||||
<div class="innerContainer">
|
<div class="innerContainer">
|
||||||
<div class="diveDetails">
|
<div class="diveDetails">
|
||||||
<div class="dataPart">
|
<div class="dataPart">
|
||||||
<table class="table_class" border="1">
|
<table class="table_class">
|
||||||
<tbody><tr>
|
<tbody><tr>
|
||||||
<td class="fieldTitle">
|
<td class="fieldTitle">
|
||||||
<h1> Dive No. </h1>
|
<h1> Dive No. </h1>
|
||||||
|
@ -139,7 +150,7 @@
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
</tbody></table>
|
</tbody></table>
|
||||||
<table class="table_class" border="1">
|
<table class="table_class">
|
||||||
<tbody><tr>
|
<tbody><tr>
|
||||||
<td class="fieldTitle">
|
<td class="fieldTitle">
|
||||||
<h1> Time. </h1>
|
<h1> Time. </h1>
|
||||||
|
@ -184,7 +195,7 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="notesPart">
|
<div class="notesPart">
|
||||||
<table class="notes_table_class" border="1">
|
<table class="notes_table_class">
|
||||||
<tbody><tr>
|
<tbody><tr>
|
||||||
<td class="fieldTitle">
|
<td class="fieldTitle">
|
||||||
<h1> Notes </h1>
|
<h1> Notes </h1>
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
#include <QPrintDialog>
|
#include <QPrintDialog>
|
||||||
#include <QShortcut>
|
#include <QShortcut>
|
||||||
#include <QSettings>
|
#include <QSettings>
|
||||||
|
#include <QMessageBox>
|
||||||
|
|
||||||
#define SETTINGS_GROUP "PrintDialog"
|
#define SETTINGS_GROUP "PrintDialog"
|
||||||
|
|
||||||
|
@ -22,6 +23,10 @@ PrintDialog::PrintDialog(QWidget *parent, Qt::WindowFlags f) : QDialog(parent, f
|
||||||
printOptions.landscape = false;
|
printOptions.landscape = false;
|
||||||
printOptions.p_template = print_options::ONE_DIVE;
|
printOptions.p_template = print_options::ONE_DIVE;
|
||||||
printOptions.type = print_options::DIVELIST;
|
printOptions.type = print_options::DIVELIST;
|
||||||
|
templateOptions.font_index = 0;
|
||||||
|
templateOptions.font_size = 9;
|
||||||
|
templateOptions.color_palette_index = 0;
|
||||||
|
templateOptions.line_spacing = 1;
|
||||||
} else {
|
} else {
|
||||||
s.beginGroup(SETTINGS_GROUP);
|
s.beginGroup(SETTINGS_GROUP);
|
||||||
printOptions.type = (print_options::print_type)s.value("type").toInt();
|
printOptions.type = (print_options::print_type)s.value("type").toInt();
|
||||||
|
@ -30,13 +35,17 @@ PrintDialog::PrintDialog(QWidget *parent, Qt::WindowFlags f) : QDialog(parent, f
|
||||||
printOptions.landscape = s.value("landscape").toBool();
|
printOptions.landscape = s.value("landscape").toBool();
|
||||||
printOptions.p_template = (print_options::print_template)s.value("template_selected").toInt();
|
printOptions.p_template = (print_options::print_template)s.value("template_selected").toInt();
|
||||||
qprinter.setOrientation((QPrinter::Orientation)printOptions.landscape);
|
qprinter.setOrientation((QPrinter::Orientation)printOptions.landscape);
|
||||||
|
templateOptions.font_index = s.value("font").toInt();
|
||||||
|
templateOptions.font_size = s.value("font_size").toDouble();
|
||||||
|
templateOptions.color_palette_index = s.value("color_palette").toInt();
|
||||||
|
templateOptions.line_spacing = s.value("line_spacing").toDouble();
|
||||||
}
|
}
|
||||||
|
|
||||||
// create a print options object and pass our options struct
|
// create a print options object and pass our options struct
|
||||||
optionsWidget = new PrintOptions(this, &printOptions);
|
optionsWidget = new PrintOptions(this, &printOptions, &templateOptions);
|
||||||
|
|
||||||
// create a new printer object
|
// create a new printer object
|
||||||
printer = new Printer(&qprinter, &printOptions);
|
printer = new Printer(&qprinter, &printOptions, &templateOptions);
|
||||||
|
|
||||||
QVBoxLayout *layout = new QVBoxLayout(this);
|
QVBoxLayout *layout = new QVBoxLayout(this);
|
||||||
setLayout(layout);
|
setLayout(layout);
|
||||||
|
@ -82,21 +91,47 @@ PrintDialog::PrintDialog(QWidget *parent, Qt::WindowFlags f) : QDialog(parent, f
|
||||||
|
|
||||||
void PrintDialog::onFinished()
|
void PrintDialog::onFinished()
|
||||||
{
|
{
|
||||||
// save the settings
|
|
||||||
QSettings s;
|
QSettings s;
|
||||||
s.beginGroup(SETTINGS_GROUP);
|
s.beginGroup(SETTINGS_GROUP);
|
||||||
|
|
||||||
|
// save print paper settings
|
||||||
s.setValue("type", printOptions.type);
|
s.setValue("type", printOptions.type);
|
||||||
s.setValue("print_selected", printOptions.print_selected);
|
s.setValue("print_selected", printOptions.print_selected);
|
||||||
s.setValue("color_selected", printOptions.color_selected);
|
s.setValue("color_selected", printOptions.color_selected);
|
||||||
s.setValue("template_selected", printOptions.p_template);
|
s.setValue("template_selected", printOptions.p_template);
|
||||||
|
|
||||||
|
// save template settings
|
||||||
|
s.setValue("font", templateOptions.font_index);
|
||||||
|
s.setValue("font_size", templateOptions.font_size);
|
||||||
|
s.setValue("color_palette", templateOptions.color_palette_index);
|
||||||
|
s.setValue("line_spacing", templateOptions.line_spacing);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PrintDialog::previewClicked(void)
|
void PrintDialog::previewClicked(void)
|
||||||
{
|
{
|
||||||
|
if (printOptions.type == print_options::TABLE || printOptions.type == print_options::STATISTICS) {
|
||||||
|
QMessageBox msgBox;
|
||||||
|
msgBox.setText("This feature is not implemented yet");
|
||||||
|
msgBox.exec();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
QPrintPreviewDialog previewDialog(&qprinter, this, Qt::Window
|
||||||
|
| Qt::CustomizeWindowHint | Qt::WindowCloseButtonHint
|
||||||
|
| Qt::WindowTitleHint);
|
||||||
|
connect(&previewDialog, SIGNAL(paintRequested(QPrinter *)), this, SLOT(onPaintRequested(QPrinter *)));
|
||||||
|
previewDialog.exec();
|
||||||
}
|
}
|
||||||
|
|
||||||
void PrintDialog::printClicked(void)
|
void PrintDialog::printClicked(void)
|
||||||
{
|
{
|
||||||
|
if (printOptions.type == print_options::TABLE || printOptions.type == print_options::STATISTICS) {
|
||||||
|
QMessageBox msgBox;
|
||||||
|
msgBox.setText("This feature is not implemented yet");
|
||||||
|
msgBox.exec();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
QPrintDialog printDialog(&qprinter, this);
|
QPrintDialog printDialog(&qprinter, this);
|
||||||
if (printDialog.exec() == QDialog::Accepted) {
|
if (printDialog.exec() == QDialog::Accepted) {
|
||||||
switch (printOptions.type) {
|
switch (printOptions.type) {
|
||||||
|
@ -115,5 +150,9 @@ void PrintDialog::printClicked(void)
|
||||||
|
|
||||||
void PrintDialog::onPaintRequested(QPrinter *printerPtr)
|
void PrintDialog::onPaintRequested(QPrinter *printerPtr)
|
||||||
{
|
{
|
||||||
|
connect(printer, SIGNAL(progessUpdated(int)), progressBar, SLOT(setValue(int)));
|
||||||
|
printer->print();
|
||||||
|
progressBar->setValue(0);
|
||||||
|
disconnect(printer, SIGNAL(progessUpdated(int)), progressBar, SLOT(setValue(int)));
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
#include <QPrinter>
|
#include <QPrinter>
|
||||||
#include "printoptions.h"
|
#include "printoptions.h"
|
||||||
#include "printer.h"
|
#include "printer.h"
|
||||||
|
#include "templateedit.h"
|
||||||
|
|
||||||
class QProgressBar;
|
class QProgressBar;
|
||||||
class PrintOptions;
|
class PrintOptions;
|
||||||
|
@ -24,6 +25,7 @@ private:
|
||||||
Printer *printer;
|
Printer *printer;
|
||||||
QPrinter qprinter;
|
QPrinter qprinter;
|
||||||
struct print_options printOptions;
|
struct print_options printOptions;
|
||||||
|
struct template_options templateOptions;
|
||||||
|
|
||||||
private
|
private
|
||||||
slots:
|
slots:
|
||||||
|
|
|
@ -1,20 +1,22 @@
|
||||||
#include "printoptions.h"
|
#include "printoptions.h"
|
||||||
|
#include "templateedit.h"
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
|
||||||
PrintOptions::PrintOptions(QWidget *parent, struct print_options *printOpt)
|
PrintOptions::PrintOptions(QWidget *parent, struct print_options *printOpt, struct template_options *templateOpt)
|
||||||
{
|
{
|
||||||
hasSetupSlots = false;
|
hasSetupSlots = false;
|
||||||
ui.setupUi(this);
|
ui.setupUi(this);
|
||||||
if (parent)
|
if (parent)
|
||||||
setParent(parent);
|
setParent(parent);
|
||||||
if (!printOpt)
|
if (!printOpt || !templateOpt)
|
||||||
return;
|
return;
|
||||||
setup(printOpt);
|
templateOptions = templateOpt;
|
||||||
|
printOptions = printOpt;
|
||||||
|
setup();
|
||||||
}
|
}
|
||||||
|
|
||||||
void PrintOptions::setup(struct print_options *printOpt)
|
void PrintOptions::setup()
|
||||||
{
|
{
|
||||||
printOptions = printOpt;
|
|
||||||
// print type radio buttons
|
// print type radio buttons
|
||||||
switch (printOptions->type) {
|
switch (printOptions->type) {
|
||||||
case print_options::DIVELIST:
|
case print_options::DIVELIST:
|
||||||
|
@ -34,6 +36,9 @@ void PrintOptions::setup(struct print_options *printOpt)
|
||||||
case print_options::TWO_DIVE:
|
case print_options::TWO_DIVE:
|
||||||
ui.printTemplate->setCurrentIndex(1);
|
ui.printTemplate->setCurrentIndex(1);
|
||||||
break;
|
break;
|
||||||
|
case print_options::CUSTOM:
|
||||||
|
ui.printTemplate->setCurrentIndex(2);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// general print option checkboxes
|
// general print option checkboxes
|
||||||
|
@ -95,5 +100,15 @@ void PrintOptions::on_printTemplate_currentIndexChanged(int index)
|
||||||
case 1:
|
case 1:
|
||||||
printOptions->p_template = print_options::TWO_DIVE;
|
printOptions->p_template = print_options::TWO_DIVE;
|
||||||
break;
|
break;
|
||||||
|
case 2:
|
||||||
|
printOptions->p_template = print_options::CUSTOM;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void PrintOptions::on_editButton_clicked()
|
||||||
|
{
|
||||||
|
TemplateEdit te(this, printOptions, templateOptions);
|
||||||
|
te.exec();
|
||||||
|
setup();
|
||||||
|
}
|
||||||
|
|
|
@ -13,24 +13,33 @@ struct print_options {
|
||||||
} type;
|
} type;
|
||||||
enum print_template {
|
enum print_template {
|
||||||
ONE_DIVE,
|
ONE_DIVE,
|
||||||
TWO_DIVE
|
TWO_DIVE,
|
||||||
|
CUSTOM
|
||||||
} p_template;
|
} p_template;
|
||||||
bool print_selected;
|
bool print_selected;
|
||||||
bool color_selected;
|
bool color_selected;
|
||||||
bool landscape;
|
bool landscape;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct template_options {
|
||||||
|
int font_index;
|
||||||
|
int color_palette_index;
|
||||||
|
double font_size;
|
||||||
|
double line_spacing;
|
||||||
|
};
|
||||||
|
|
||||||
// should be based on a custom QPrintDialog class
|
// should be based on a custom QPrintDialog class
|
||||||
class PrintOptions : public QWidget {
|
class PrintOptions : public QWidget {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit PrintOptions(QWidget *parent = 0, struct print_options *printOpt = 0);
|
explicit PrintOptions(QWidget *parent, struct print_options *printOpt, struct template_options *templateOpt);
|
||||||
void setup(struct print_options *printOpt);
|
void setup();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Ui::PrintOptions ui;
|
Ui::PrintOptions ui;
|
||||||
struct print_options *printOptions;
|
struct print_options *printOptions;
|
||||||
|
struct template_options *templateOptions;
|
||||||
bool hasSetupSlots;
|
bool hasSetupSlots;
|
||||||
|
|
||||||
private
|
private
|
||||||
|
@ -41,6 +50,7 @@ slots:
|
||||||
void on_radioTablePrint_clicked(bool check);
|
void on_radioTablePrint_clicked(bool check);
|
||||||
void on_radioDiveListPrint_clicked(bool check);
|
void on_radioDiveListPrint_clicked(bool check);
|
||||||
void on_printTemplate_currentIndexChanged(int index);
|
void on_printTemplate_currentIndexChanged(int index);
|
||||||
|
void on_editButton_clicked();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // PRINTOPTIONS_H
|
#endif // PRINTOPTIONS_H
|
||||||
|
|
|
@ -140,6 +140,11 @@
|
||||||
<string>Two dives per page</string>
|
<string>Two dives per page</string>
|
||||||
</property>
|
</property>
|
||||||
</item>
|
</item>
|
||||||
|
<item>
|
||||||
|
<property name="text">
|
||||||
|
<string>Custom template</string>
|
||||||
|
</property>
|
||||||
|
</item>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
|
|
61
qt-ui/templateedit.cpp
Normal file
61
qt-ui/templateedit.cpp
Normal file
|
@ -0,0 +1,61 @@
|
||||||
|
#include "templateedit.h"
|
||||||
|
#include "printoptions.h"
|
||||||
|
#include "ui_templateedit.h"
|
||||||
|
|
||||||
|
TemplateEdit::TemplateEdit(QWidget *parent, struct print_options *printOptions, struct template_options *templateOptions) :
|
||||||
|
QDialog(parent),
|
||||||
|
ui(new Ui::TemplateEdit)
|
||||||
|
{
|
||||||
|
ui->setupUi(this);
|
||||||
|
this->templateOptions = templateOptions;
|
||||||
|
this->printOptions = printOptions;
|
||||||
|
|
||||||
|
// 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);
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
TemplateEdit::~TemplateEdit()
|
||||||
|
{
|
||||||
|
delete ui;
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
void TemplateEdit::on_TemplateEdit_finished(int result)
|
||||||
|
{
|
||||||
|
if (grantlee_template.compare(ui->plainTextEdit->toPlainText())) {
|
||||||
|
printOptions->p_template = print_options::CUSTOM;
|
||||||
|
TemplateLayout::writeTemplate("custom.html", ui->plainTextEdit->toPlainText());
|
||||||
|
}
|
||||||
|
}
|
36
qt-ui/templateedit.h
Normal file
36
qt-ui/templateedit.h
Normal file
|
@ -0,0 +1,36 @@
|
||||||
|
#ifndef TEMPLATEEDIT_H
|
||||||
|
#define TEMPLATEEDIT_H
|
||||||
|
|
||||||
|
#include <QDialog>
|
||||||
|
#include "templatelayout.h"
|
||||||
|
|
||||||
|
namespace Ui {
|
||||||
|
class TemplateEdit;
|
||||||
|
}
|
||||||
|
|
||||||
|
class TemplateEdit : public QDialog
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit TemplateEdit(QWidget *parent, struct print_options *printOptions, struct template_options *templateOptions);
|
||||||
|
~TemplateEdit();
|
||||||
|
private slots:
|
||||||
|
void on_fontsize_valueChanged(int font_size);
|
||||||
|
|
||||||
|
void on_linespacing_valueChanged(double line_spacing);
|
||||||
|
|
||||||
|
void on_fontSelection_currentIndexChanged(int index);
|
||||||
|
|
||||||
|
void on_colorpalette_currentIndexChanged(int index);
|
||||||
|
|
||||||
|
void on_TemplateEdit_finished(int result);
|
||||||
|
|
||||||
|
private:
|
||||||
|
Ui::TemplateEdit *ui;
|
||||||
|
struct template_options *templateOptions;
|
||||||
|
struct print_options *printOptions;
|
||||||
|
QString grantlee_template;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // TEMPLATEEDIT_H
|
262
qt-ui/templateedit.ui
Normal file
262
qt-ui/templateedit.ui
Normal file
|
@ -0,0 +1,262 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<ui version="4.0">
|
||||||
|
<class>TemplateEdit</class>
|
||||||
|
<widget class="QDialog" name="TemplateEdit">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>0</x>
|
||||||
|
<y>0</y>
|
||||||
|
<width>774</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::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>0</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>
|
||||||
|
</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>
|
||||||
|
</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>
|
||||||
|
</widget>
|
||||||
|
</widget>
|
||||||
|
</widget>
|
||||||
|
<widget class="QWebView" name="webView">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>20</x>
|
||||||
|
<y>60</y>
|
||||||
|
<width>251</width>
|
||||||
|
<height>311</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<property name="url">
|
||||||
|
<url>
|
||||||
|
<string>about:blank</string>
|
||||||
|
</url>
|
||||||
|
</property>
|
||||||
|
</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>
|
||||||
|
<customwidgets>
|
||||||
|
<customwidget>
|
||||||
|
<class>QWebView</class>
|
||||||
|
<extends>QWidget</extends>
|
||||||
|
<header>QtWebKitWidgets/QWebView</header>
|
||||||
|
</customwidget>
|
||||||
|
</customwidgets>
|
||||||
|
<resources/>
|
||||||
|
<connections>
|
||||||
|
<connection>
|
||||||
|
<sender>buttonBox</sender>
|
||||||
|
<signal>accepted()</signal>
|
||||||
|
<receiver>TemplateEdit</receiver>
|
||||||
|
<slot>accept()</slot>
|
||||||
|
<hints>
|
||||||
|
<hint type="sourcelabel">
|
||||||
|
<x>248</x>
|
||||||
|
<y>254</y>
|
||||||
|
</hint>
|
||||||
|
<hint type="destinationlabel">
|
||||||
|
<x>157</x>
|
||||||
|
<y>274</y>
|
||||||
|
</hint>
|
||||||
|
</hints>
|
||||||
|
</connection>
|
||||||
|
<connection>
|
||||||
|
<sender>buttonBox</sender>
|
||||||
|
<signal>rejected()</signal>
|
||||||
|
<receiver>TemplateEdit</receiver>
|
||||||
|
<slot>reject()</slot>
|
||||||
|
<hints>
|
||||||
|
<hint type="sourcelabel">
|
||||||
|
<x>316</x>
|
||||||
|
<y>260</y>
|
||||||
|
</hint>
|
||||||
|
<hint type="destinationlabel">
|
||||||
|
<x>286</x>
|
||||||
|
<y>274</y>
|
||||||
|
</hint>
|
||||||
|
</hints>
|
||||||
|
</connection>
|
||||||
|
</connections>
|
||||||
|
</ui>
|
|
@ -4,17 +4,26 @@
|
||||||
#include "helpers.h"
|
#include "helpers.h"
|
||||||
#include "display.h"
|
#include "display.h"
|
||||||
|
|
||||||
int getTotalWork()
|
int getTotalWork(print_options *printOptions)
|
||||||
{
|
{
|
||||||
// return the correct number depending on all/selected dives
|
if (printOptions->print_selected) {
|
||||||
// but don't return 0 as we might divide by this number
|
// return the correct number depending on all/selected dives
|
||||||
return amount_selected ? amount_selected : 1;
|
// but don't return 0 as we might divide by this number
|
||||||
|
return amount_selected ? amount_selected : 1;
|
||||||
|
}
|
||||||
|
int dives = 0, i;
|
||||||
|
struct dive *dive;
|
||||||
|
for_each_dive (i, dive) {
|
||||||
|
dives++;
|
||||||
|
}
|
||||||
|
return dives;
|
||||||
}
|
}
|
||||||
|
|
||||||
TemplateLayout::TemplateLayout(print_options *PrintOptions) :
|
TemplateLayout::TemplateLayout(print_options *PrintOptions, template_options *templateOptions) :
|
||||||
m_engine(NULL)
|
m_engine(NULL)
|
||||||
{
|
{
|
||||||
this->PrintOptions = PrintOptions;
|
this->PrintOptions = PrintOptions;
|
||||||
|
this->templateOptions = templateOptions;
|
||||||
}
|
}
|
||||||
|
|
||||||
TemplateLayout::~TemplateLayout()
|
TemplateLayout::~TemplateLayout()
|
||||||
|
@ -25,7 +34,7 @@ TemplateLayout::~TemplateLayout()
|
||||||
QString TemplateLayout::generate()
|
QString TemplateLayout::generate()
|
||||||
{
|
{
|
||||||
int progress = 0;
|
int progress = 0;
|
||||||
int totalWork = getTotalWork();
|
int totalWork = getTotalWork(PrintOptions);
|
||||||
QString templateName;
|
QString templateName;
|
||||||
|
|
||||||
QString htmlContent;
|
QString htmlContent;
|
||||||
|
@ -37,6 +46,7 @@ QString TemplateLayout::generate()
|
||||||
m_engine->addTemplateLoader(m_templateLoader);
|
m_engine->addTemplateLoader(m_templateLoader);
|
||||||
|
|
||||||
Grantlee::registerMetaType<Dive>();
|
Grantlee::registerMetaType<Dive>();
|
||||||
|
Grantlee::registerMetaType<template_options>();
|
||||||
|
|
||||||
QVariantHash mapping;
|
QVariantHash mapping;
|
||||||
QVariantList diveList;
|
QVariantList diveList;
|
||||||
|
@ -45,7 +55,7 @@ QString TemplateLayout::generate()
|
||||||
int i;
|
int i;
|
||||||
for_each_dive (i, dive) {
|
for_each_dive (i, dive) {
|
||||||
//TODO check for exporting selected dives only
|
//TODO check for exporting selected dives only
|
||||||
if (!dive->selected)
|
if (!dive->selected && PrintOptions->print_selected)
|
||||||
continue;
|
continue;
|
||||||
Dive d(dive);
|
Dive d(dive);
|
||||||
diveList.append(QVariant::fromValue(d));
|
diveList.append(QVariant::fromValue(d));
|
||||||
|
@ -53,6 +63,7 @@ QString TemplateLayout::generate()
|
||||||
emit progressUpdated(progress * 100.0 / totalWork);
|
emit progressUpdated(progress * 100.0 / totalWork);
|
||||||
}
|
}
|
||||||
mapping.insert("dives", diveList);
|
mapping.insert("dives", diveList);
|
||||||
|
mapping.insert("template_options", QVariant::fromValue(*templateOptions));
|
||||||
|
|
||||||
Grantlee::Context c(mapping);
|
Grantlee::Context c(mapping);
|
||||||
|
|
||||||
|
@ -60,6 +71,8 @@ QString TemplateLayout::generate()
|
||||||
templateName = "one_dive.html";
|
templateName = "one_dive.html";
|
||||||
} else if (PrintOptions->p_template == print_options::TWO_DIVE) {
|
} else if (PrintOptions->p_template == print_options::TWO_DIVE) {
|
||||||
templateName = "two_dives.html";
|
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(templateName);
|
||||||
if (!t || t->error()) {
|
if (!t || t->error()) {
|
||||||
|
@ -76,6 +89,25 @@ QString TemplateLayout::generate()
|
||||||
return htmlContent;
|
return htmlContent;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString TemplateLayout::readTemplate(QString template_name)
|
||||||
|
{
|
||||||
|
QFile qfile(getSubsurfaceDataPath("printing_templates") + QDir::separator() + template_name);
|
||||||
|
if (qfile.open(QFile::ReadOnly | QFile::Text)) {
|
||||||
|
QTextStream in(&qfile);
|
||||||
|
return in.readAll();
|
||||||
|
}
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
void TemplateLayout::writeTemplate(QString template_name, QString grantlee_template)
|
||||||
|
{
|
||||||
|
QFile qfile(getSubsurfaceDataPath("printing_templates") + QDir::separator() + template_name);
|
||||||
|
if (qfile.open(QFile::ReadWrite | QFile::Text)) {
|
||||||
|
qfile.write(grantlee_template.toUtf8().data());
|
||||||
|
qfile.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Dive::Dive() :
|
Dive::Dive() :
|
||||||
m_number(-1),
|
m_number(-1),
|
||||||
dive(NULL)
|
dive(NULL)
|
||||||
|
|
|
@ -5,18 +5,21 @@
|
||||||
#include "mainwindow.h"
|
#include "mainwindow.h"
|
||||||
#include "printoptions.h"
|
#include "printoptions.h"
|
||||||
|
|
||||||
int getTotalWork();
|
int getTotalWork(print_options *printOptions);
|
||||||
|
|
||||||
class TemplateLayout : public QObject {
|
class TemplateLayout : public QObject {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
TemplateLayout(print_options *PrintOptions);
|
TemplateLayout(print_options *PrintOptions, template_options *templateOptions);
|
||||||
~TemplateLayout();
|
~TemplateLayout();
|
||||||
QString generate();
|
QString generate();
|
||||||
|
static QString readTemplate(QString template_name);
|
||||||
|
static void writeTemplate(QString template_name, QString grantlee_template);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Grantlee::Engine *m_engine;
|
Grantlee::Engine *m_engine;
|
||||||
print_options *PrintOptions;
|
print_options *PrintOptions;
|
||||||
|
template_options *templateOptions;
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void progressUpdated(int value);
|
void progressUpdated(int value);
|
||||||
|
@ -75,6 +78,7 @@ public:
|
||||||
};
|
};
|
||||||
|
|
||||||
Q_DECLARE_METATYPE(Dive)
|
Q_DECLARE_METATYPE(Dive)
|
||||||
|
Q_DECLARE_METATYPE(template_options)
|
||||||
|
|
||||||
GRANTLEE_BEGIN_LOOKUP(Dive)
|
GRANTLEE_BEGIN_LOOKUP(Dive)
|
||||||
if (property == "number")
|
if (property == "number")
|
||||||
|
@ -101,4 +105,25 @@ else if (property == "notes")
|
||||||
return object.notes();
|
return object.notes();
|
||||||
GRANTLEE_END_LOOKUP
|
GRANTLEE_END_LOOKUP
|
||||||
|
|
||||||
|
GRANTLEE_BEGIN_LOOKUP(template_options)
|
||||||
|
if (property == "font") {
|
||||||
|
switch (object.font_index) {
|
||||||
|
case 0:
|
||||||
|
return "Arial, Helvetica, sans-serif";
|
||||||
|
case 1:
|
||||||
|
return "Impact, Charcoal, sans-serif";
|
||||||
|
case 2:
|
||||||
|
return "Georgia, serif";
|
||||||
|
case 3:
|
||||||
|
return "Courier, monospace";
|
||||||
|
case 4:
|
||||||
|
return "Verdana, Geneva, sans-serif";
|
||||||
|
}
|
||||||
|
} else if (property == "font_size") {
|
||||||
|
return object.font_size / 9.0;
|
||||||
|
} else if (property == "line_spacing") {
|
||||||
|
return object.line_spacing;
|
||||||
|
}
|
||||||
|
GRANTLEE_END_LOOKUP
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Add table
Reference in a new issue