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
e3a8ff7493
11 changed files with 583 additions and 91 deletions
111
printer.cpp
111
printer.cpp
|
@ -6,13 +6,20 @@
|
||||||
#include <QWebElementCollection>
|
#include <QWebElementCollection>
|
||||||
#include <QWebElement>
|
#include <QWebElement>
|
||||||
|
|
||||||
Printer::Printer(QPrinter *printer, print_options *printOptions, template_options *templateOptions)
|
Printer::Printer(QPaintDevice *paintDevice, print_options *printOptions, template_options *templateOptions, PrintMode printMode)
|
||||||
{
|
{
|
||||||
this->printer = printer;
|
this->paintDevice = paintDevice;
|
||||||
this->printOptions = printOptions;
|
this->printOptions = printOptions;
|
||||||
this->templateOptions = templateOptions;
|
this->templateOptions = templateOptions;
|
||||||
|
this->printMode = printMode;
|
||||||
dpi = 0;
|
dpi = 0;
|
||||||
done = 0;
|
done = 0;
|
||||||
|
webView = new QWebView();
|
||||||
|
}
|
||||||
|
|
||||||
|
Printer::~Printer()
|
||||||
|
{
|
||||||
|
delete webView;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Printer::putProfileImage(QRect profilePlaceholder, QRect viewPort, QPainter *painter, struct dive *dive, QPointer<ProfileWidget2> profile)
|
void Printer::putProfileImage(QRect profilePlaceholder, QRect viewPort, QPainter *painter, struct dive *dive, QPointer<ProfileWidget2> profile)
|
||||||
|
@ -22,28 +29,33 @@ void Printer::putProfileImage(QRect profilePlaceholder, QRect viewPort, QPainter
|
||||||
// use the placeHolder and the viewPort position to calculate the relative position of the dive profile.
|
// use the placeHolder and the viewPort position to calculate the relative position of the dive profile.
|
||||||
QRect pos(x, y, profilePlaceholder.width(), profilePlaceholder.height());
|
QRect pos(x, y, profilePlaceholder.width(), profilePlaceholder.height());
|
||||||
profile->plotDive(dive, true);
|
profile->plotDive(dive, true);
|
||||||
|
|
||||||
|
if (!printOptions->color_selected) {
|
||||||
|
QImage image(pos.width(), pos.height(), QImage::Format_ARGB32);
|
||||||
|
QPainter imgPainter(&image);
|
||||||
|
imgPainter.setRenderHint(QPainter::Antialiasing);
|
||||||
|
imgPainter.setRenderHint(QPainter::SmoothPixmapTransform);
|
||||||
|
profile->render(&imgPainter, QRect(0, 0, pos.width(), pos.height()));
|
||||||
|
imgPainter.end();
|
||||||
|
|
||||||
|
// convert QImage to grayscale before rendering
|
||||||
|
for (int i = 0; i < image.height(); i++) {
|
||||||
|
QRgb *pixel = reinterpret_cast<QRgb *>(image.scanLine(i));
|
||||||
|
QRgb *end = pixel + image.width();
|
||||||
|
for (; pixel != end; pixel++) {
|
||||||
|
int gray_val = qGray(*pixel);
|
||||||
|
*pixel = QColor(gray_val, gray_val, gray_val).rgb();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
painter->drawImage(pos, image);
|
||||||
|
} else {
|
||||||
profile->render(painter, pos);
|
profile->render(painter, pos);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void Printer::render()
|
void Printer::render(int Pages = 0)
|
||||||
{
|
{
|
||||||
// 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();
|
QPointer<ProfileWidget2> profile = MainWindow::instance()->graphics();
|
||||||
int profileFrameStyle = profile->frameStyle();
|
int profileFrameStyle = profile->frameStyle();
|
||||||
|
@ -53,14 +65,14 @@ 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(printer->pageLayout().paintRect(QPageLayout::Inch).width() * dpi * 0.001);
|
profile->setFontPrintScale(pageSize.width() * 0.001);
|
||||||
profile->setToolTipVisibile(false);
|
profile->setToolTipVisibile(false);
|
||||||
prefs.animation_speed = 0;
|
prefs.animation_speed = 0;
|
||||||
|
|
||||||
// render the Qwebview
|
// render the Qwebview
|
||||||
QPainter painter;
|
QPainter painter;
|
||||||
QRect viewPort(0, 0, pageSize.width(), pageSize.height());
|
QRect viewPort(0, 0, pageSize.width(), pageSize.height());
|
||||||
painter.begin(printer);
|
painter.begin(paintDevice);
|
||||||
painter.setRenderHint(QPainter::Antialiasing);
|
painter.setRenderHint(QPainter::Antialiasing);
|
||||||
painter.setRenderHint(QPainter::SmoothPixmapTransform);
|
painter.setRenderHint(QPainter::SmoothPixmapTransform);
|
||||||
|
|
||||||
|
@ -91,8 +103,8 @@ void Printer::render()
|
||||||
|
|
||||||
// rendering progress is 4/5 of total work
|
// rendering progress is 4/5 of total work
|
||||||
emit(progessUpdated((i * 80.0 / Pages) + done));
|
emit(progessUpdated((i * 80.0 / Pages) + done));
|
||||||
if (i < Pages - 1)
|
if (i < Pages - 1 && printMode == Printer::PRINT)
|
||||||
printer->newPage();
|
static_cast<QPrinter*>(paintDevice)->newPage();
|
||||||
}
|
}
|
||||||
painter.end();
|
painter.end();
|
||||||
|
|
||||||
|
@ -117,15 +129,52 @@ void Printer::templateProgessUpdated(int value)
|
||||||
|
|
||||||
void Printer::print()
|
void Printer::print()
|
||||||
{
|
{
|
||||||
TemplateLayout t(printOptions, templateOptions);
|
// we can only print if "PRINT" mode is selected
|
||||||
webView = new QWebView();
|
if (printMode != Printer::PRINT) {
|
||||||
connect(&t, SIGNAL(progressUpdated(int)), this, SLOT(templateProgessUpdated(int)));
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
dpi = printer->resolution();
|
QPrinter *printerPtr;
|
||||||
|
printerPtr = static_cast<QPrinter*>(paintDevice);
|
||||||
|
|
||||||
|
TemplateLayout t(printOptions, templateOptions);
|
||||||
|
connect(&t, SIGNAL(progressUpdated(int)), this, SLOT(templateProgessUpdated(int)));
|
||||||
|
dpi = printerPtr->resolution();
|
||||||
//rendering resolution = selected paper size in inchs * printer dpi
|
//rendering resolution = selected paper size in inchs * printer dpi
|
||||||
pageSize.setHeight(printer->pageLayout().paintRect(QPageLayout::Inch).height() * dpi);
|
pageSize.setHeight(printerPtr->pageLayout().paintRect(QPageLayout::Inch).height() * dpi);
|
||||||
pageSize.setWidth(printer->pageLayout().paintRect(QPageLayout::Inch).width() * dpi);
|
pageSize.setWidth(printerPtr->pageLayout().paintRect(QPageLayout::Inch).width() * dpi);
|
||||||
webView->page()->setViewportSize(pageSize);
|
webView->page()->setViewportSize(pageSize);
|
||||||
webView->setHtml(t.generate());
|
webView->setHtml(t.generate());
|
||||||
render();
|
if (printOptions->color_selected && printerPtr->colorMode()) {
|
||||||
|
printerPtr->setColorMode(QPrinter::Color);
|
||||||
|
} else {
|
||||||
|
printerPtr->setColorMode(QPrinter::GrayScale);
|
||||||
|
}
|
||||||
|
// apply user settings
|
||||||
|
int divesPerPage;
|
||||||
|
|
||||||
|
// 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);
|
||||||
|
render(Pages);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Printer::previewOnePage()
|
||||||
|
{
|
||||||
|
if (printMode == PREVIEW) {
|
||||||
|
TemplateLayout t(printOptions, templateOptions);
|
||||||
|
|
||||||
|
pageSize.setHeight(paintDevice->height());
|
||||||
|
pageSize.setWidth(paintDevice->width());
|
||||||
|
webView->page()->setViewportSize(pageSize);
|
||||||
|
webView->setHtml(t.generate());
|
||||||
|
|
||||||
|
// render only one page
|
||||||
|
render(1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
15
printer.h
15
printer.h
|
@ -13,23 +13,32 @@
|
||||||
class Printer : public QObject {
|
class Printer : public QObject {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
enum PrintMode {
|
||||||
|
PRINT,
|
||||||
|
PREVIEW
|
||||||
|
};
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QPrinter *printer;
|
QPaintDevice *paintDevice;
|
||||||
QWebView *webView;
|
QWebView *webView;
|
||||||
print_options *printOptions;
|
print_options *printOptions;
|
||||||
template_options *templateOptions;
|
template_options *templateOptions;
|
||||||
QSize pageSize;
|
QSize pageSize;
|
||||||
|
PrintMode printMode;
|
||||||
int done;
|
int done;
|
||||||
int dpi;
|
int dpi;
|
||||||
void render();
|
void render(int Pages);
|
||||||
void putProfileImage(QRect box, QRect viewPort, QPainter *painter, struct dive *dive, QPointer<ProfileWidget2> profile);
|
void putProfileImage(QRect box, QRect viewPort, QPainter *painter, struct dive *dive, QPointer<ProfileWidget2> profile);
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void templateProgessUpdated(int value);
|
void templateProgessUpdated(int value);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Printer(QPrinter *printer, print_options *printOptions, template_options *templateOptions);
|
Printer(QPaintDevice *paintDevice, print_options *printOptions, template_options *templateOptions, PrintMode printMode);
|
||||||
|
~Printer();
|
||||||
void print();
|
void print();
|
||||||
|
void previewOnePage();
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void progessUpdated(int value);
|
void progessUpdated(int value);
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
<head>
|
<head>
|
||||||
<style>
|
<style>
|
||||||
body {
|
body {
|
||||||
background-color: white;
|
{{ print_options.grayscale }};
|
||||||
padding: 0;
|
padding: 0;
|
||||||
margin: 0;
|
margin: 0;
|
||||||
font-size: {{ template_options.font_size }}vw;
|
font-size: {{ template_options.font_size }}vw;
|
||||||
|
@ -16,13 +16,21 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
table {
|
table {
|
||||||
-webkit-box-sizing: border-box; /* Safari/Chrome, other WebKit */
|
-webkit-box-sizing: border-box;
|
||||||
-moz-box-sizing: border-box; /* Firefox, other Gecko */
|
|
||||||
box-sizing: border-box;
|
box-sizing: border-box;
|
||||||
border:max(1px, 0.1vw);
|
border:max(1px, 0.1vw);
|
||||||
border-style:solid;
|
border-style:solid;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
td {
|
||||||
|
padding-left: 0.5vw;
|
||||||
|
padding-right: 0.5vw;
|
||||||
|
}
|
||||||
|
|
||||||
|
#body_div {
|
||||||
|
background-color: {{ template_options.color1 }};
|
||||||
|
}
|
||||||
|
|
||||||
.mainContainer {
|
.mainContainer {
|
||||||
width: 96%;
|
width: 96%;
|
||||||
height: 100%;
|
height: 100%;
|
||||||
|
@ -45,8 +53,7 @@
|
||||||
.diveDetails {
|
.diveDetails {
|
||||||
width: 98%;
|
width: 98%;
|
||||||
height: 98%;
|
height: 98%;
|
||||||
-webkit-box-sizing: border-box; /* Safari/Chrome, other WebKit */
|
-webkit-box-sizing: border-box;
|
||||||
-moz-box-sizing: border-box; /* Firefox, other Gecko */
|
|
||||||
box-sizing: border-box;
|
box-sizing: border-box;
|
||||||
border:max(1px, 0.1vw);
|
border:max(1px, 0.1vw);
|
||||||
border-style:solid;
|
border-style:solid;
|
||||||
|
@ -54,45 +61,43 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
.diveProfile {
|
.diveProfile {
|
||||||
width: 97%;
|
width: 96%;
|
||||||
height: 40%;
|
height: 40%;
|
||||||
margin: 1.5%;
|
margin: 2%;
|
||||||
-webkit-box-sizing: border-box; /* Safari/Chrome, other WebKit */
|
|
||||||
-moz-box-sizing: border-box; /* Firefox, other Gecko */
|
|
||||||
box-sizing: border-box;
|
|
||||||
border:max(1px, 0.1vw);
|
|
||||||
border-style:solid;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.dataSection {
|
.dataSection {
|
||||||
width: 97%;
|
width: 98%;
|
||||||
height: 40%;
|
height: 40%;
|
||||||
margin: 1.5%;
|
margin: 1%;
|
||||||
}
|
}
|
||||||
|
|
||||||
.fieldTitle {
|
.fieldTitle {
|
||||||
background-color: #CfC7C5;
|
background-color: {{ template_options.color2 }};
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
}
|
}
|
||||||
|
|
||||||
.table_class {
|
.table_class {
|
||||||
float: left;
|
float: left;
|
||||||
margin: 1.5%;
|
margin: 1%;
|
||||||
|
width: 48%;
|
||||||
}
|
}
|
||||||
|
|
||||||
.notes_table_class {
|
.notes_table_class {
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
width: 97%;
|
width: 98%;
|
||||||
margin: 1.5%;
|
margin: 1%;
|
||||||
float: left;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.textArea {
|
.textArea {
|
||||||
line-height: {{ template_options.line_spacing }};
|
line-height: {{ template_options.line_spacing }};
|
||||||
|
max-height: 19vh;
|
||||||
|
overflow: hidden;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
</head>
|
</head>
|
||||||
<body data-numberofdives = 1>
|
<body data-numberofdives = 1>
|
||||||
|
<div id="body_div">
|
||||||
{% block main_rows %}
|
{% block main_rows %}
|
||||||
{% for dive in dives %}
|
{% for dive in dives %}
|
||||||
<div class="mainContainer">
|
<div class="mainContainer">
|
||||||
|
@ -206,5 +211,6 @@
|
||||||
</div>
|
</div>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
</div>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
<head>
|
<head>
|
||||||
<style>
|
<style>
|
||||||
body {
|
body {
|
||||||
background-color: white;
|
{{ print_options.grayscale }};
|
||||||
padding: 0px;
|
padding: 0px;
|
||||||
margin: 0px;
|
margin: 0px;
|
||||||
font-size: {{ template_options.font_size }}vw;
|
font-size: {{ template_options.font_size }}vw;
|
||||||
|
@ -15,6 +15,10 @@
|
||||||
float: left;
|
float: left;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#body_div {
|
||||||
|
background-color: {{ template_options.color1 }};
|
||||||
|
}
|
||||||
|
|
||||||
.mainContainer {
|
.mainContainer {
|
||||||
width: 96%;
|
width: 96%;
|
||||||
height: 50%;
|
height: 50%;
|
||||||
|
@ -63,7 +67,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
.fieldTitle {
|
.fieldTitle {
|
||||||
background-color: #CfC7C5;
|
background-color: {{ template_options.color2 }};
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
padding:0;
|
padding:0;
|
||||||
}
|
}
|
||||||
|
@ -103,6 +107,7 @@
|
||||||
</style>
|
</style>
|
||||||
</head>
|
</head>
|
||||||
<body data-numberofdives = 2>
|
<body data-numberofdives = 2>
|
||||||
|
<div id="body_div">
|
||||||
{% block main_rows %}
|
{% block main_rows %}
|
||||||
{% for dive in dives %}
|
{% for dive in dives %}
|
||||||
<div class="mainContainer">
|
<div class="mainContainer">
|
||||||
|
@ -217,5 +222,6 @@
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
<div id="footer">
|
<div id="footer">
|
||||||
<div>
|
<div>
|
||||||
|
</div>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
|
@ -12,8 +12,17 @@
|
||||||
|
|
||||||
#define SETTINGS_GROUP "PrintDialog"
|
#define SETTINGS_GROUP "PrintDialog"
|
||||||
|
|
||||||
|
template_options::color_palette_struct almond_colors, custom_colors;
|
||||||
|
|
||||||
PrintDialog::PrintDialog(QWidget *parent, Qt::WindowFlags f) : QDialog(parent, f)
|
PrintDialog::PrintDialog(QWidget *parent, Qt::WindowFlags f) : QDialog(parent, f)
|
||||||
{
|
{
|
||||||
|
// initialize const colors
|
||||||
|
almond_colors.color1 = QColor::fromRgb(243, 234, 207);
|
||||||
|
almond_colors.color2 = QColor::fromRgb(253, 204, 156);
|
||||||
|
almond_colors.color3 = QColor::fromRgb(136, 160, 150);
|
||||||
|
almond_colors.color4 = QColor::fromRgb(187, 171, 139);
|
||||||
|
almond_colors.color5 = QColor::fromRgb(239, 130, 117);
|
||||||
|
|
||||||
// check if the options were previously stored in the settings; if not use some defaults.
|
// check if the options were previously stored in the settings; if not use some defaults.
|
||||||
QSettings s;
|
QSettings s;
|
||||||
bool stored = s.childGroups().contains(SETTINGS_GROUP);
|
bool stored = s.childGroups().contains(SETTINGS_GROUP);
|
||||||
|
@ -27,6 +36,7 @@ PrintDialog::PrintDialog(QWidget *parent, Qt::WindowFlags f) : QDialog(parent, f
|
||||||
templateOptions.font_size = 9;
|
templateOptions.font_size = 9;
|
||||||
templateOptions.color_palette_index = 0;
|
templateOptions.color_palette_index = 0;
|
||||||
templateOptions.line_spacing = 1;
|
templateOptions.line_spacing = 1;
|
||||||
|
custom_colors = almond_colors;
|
||||||
} 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();
|
||||||
|
@ -39,13 +49,27 @@ PrintDialog::PrintDialog(QWidget *parent, Qt::WindowFlags f) : QDialog(parent, f
|
||||||
templateOptions.font_size = s.value("font_size").toDouble();
|
templateOptions.font_size = s.value("font_size").toDouble();
|
||||||
templateOptions.color_palette_index = s.value("color_palette").toInt();
|
templateOptions.color_palette_index = s.value("color_palette").toInt();
|
||||||
templateOptions.line_spacing = s.value("line_spacing").toDouble();
|
templateOptions.line_spacing = s.value("line_spacing").toDouble();
|
||||||
|
custom_colors.color1 = QColor(s.value("custom_color_1").toString());
|
||||||
|
custom_colors.color2 = QColor(s.value("custom_color_2").toString());
|
||||||
|
custom_colors.color3 = QColor(s.value("custom_color_3").toString());
|
||||||
|
custom_colors.color4 = QColor(s.value("custom_color_4").toString());
|
||||||
|
custom_colors.color5 = QColor(s.value("custom_color_5").toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (templateOptions.color_palette_index) {
|
||||||
|
case 0: // almond
|
||||||
|
templateOptions.color_palette = almond_colors;
|
||||||
|
break;
|
||||||
|
case 1: // custom
|
||||||
|
templateOptions.color_palette = custom_colors;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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, &templateOptions);
|
optionsWidget = new PrintOptions(this, &printOptions, &templateOptions);
|
||||||
|
|
||||||
// create a new printer object
|
// create a new printer object
|
||||||
printer = new Printer(&qprinter, &printOptions, &templateOptions);
|
printer = new Printer(&qprinter, &printOptions, &templateOptions, Printer::PRINT);
|
||||||
|
|
||||||
QVBoxLayout *layout = new QVBoxLayout(this);
|
QVBoxLayout *layout = new QVBoxLayout(this);
|
||||||
setLayout(layout);
|
setLayout(layout);
|
||||||
|
@ -105,6 +129,13 @@ void PrintDialog::onFinished()
|
||||||
s.setValue("font_size", templateOptions.font_size);
|
s.setValue("font_size", templateOptions.font_size);
|
||||||
s.setValue("color_palette", templateOptions.color_palette_index);
|
s.setValue("color_palette", templateOptions.color_palette_index);
|
||||||
s.setValue("line_spacing", templateOptions.line_spacing);
|
s.setValue("line_spacing", templateOptions.line_spacing);
|
||||||
|
|
||||||
|
// save custom colors
|
||||||
|
s.setValue("custom_color_1", custom_colors.color1.name());
|
||||||
|
s.setValue("custom_color_2", custom_colors.color2.name());
|
||||||
|
s.setValue("custom_color_3", custom_colors.color3.name());
|
||||||
|
s.setValue("custom_color_4", custom_colors.color4.name());
|
||||||
|
s.setValue("custom_color_5", custom_colors.color5.name());
|
||||||
}
|
}
|
||||||
|
|
||||||
void PrintDialog::previewClicked(void)
|
void PrintDialog::previewClicked(void)
|
||||||
|
|
|
@ -26,8 +26,31 @@ struct template_options {
|
||||||
int color_palette_index;
|
int color_palette_index;
|
||||||
double font_size;
|
double font_size;
|
||||||
double line_spacing;
|
double line_spacing;
|
||||||
|
struct color_palette_struct {
|
||||||
|
QColor color1;
|
||||||
|
QColor color2;
|
||||||
|
QColor color3;
|
||||||
|
QColor color4;
|
||||||
|
QColor color5;
|
||||||
|
bool operator!=(const color_palette_struct &other) const {
|
||||||
|
return other.color1 != color1
|
||||||
|
|| other.color2 != color2
|
||||||
|
|| other.color3 != color3
|
||||||
|
|| other.color4 != color4
|
||||||
|
|| other.color5 != color5;
|
||||||
|
}
|
||||||
|
} color_palette;
|
||||||
|
bool operator!=(const template_options &other) const {
|
||||||
|
return other.font_index != font_index
|
||||||
|
|| other.color_palette_index != color_palette_index
|
||||||
|
|| other.font_size != font_size
|
||||||
|
|| other.line_spacing != line_spacing
|
||||||
|
|| other.color_palette != color_palette;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
extern template_options::color_palette_struct almond_colors, custom_colors;
|
||||||
|
|
||||||
// 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
|
||||||
|
|
|
@ -1,13 +1,18 @@
|
||||||
#include "templateedit.h"
|
#include "templateedit.h"
|
||||||
#include "printoptions.h"
|
#include "printoptions.h"
|
||||||
|
#include "printer.h"
|
||||||
#include "ui_templateedit.h"
|
#include "ui_templateedit.h"
|
||||||
|
|
||||||
|
#include <QMessageBox>
|
||||||
|
#include <QColorDialog>
|
||||||
|
|
||||||
TemplateEdit::TemplateEdit(QWidget *parent, struct print_options *printOptions, struct template_options *templateOptions) :
|
TemplateEdit::TemplateEdit(QWidget *parent, struct print_options *printOptions, struct template_options *templateOptions) :
|
||||||
QDialog(parent),
|
QDialog(parent),
|
||||||
ui(new Ui::TemplateEdit)
|
ui(new Ui::TemplateEdit)
|
||||||
{
|
{
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
this->templateOptions = templateOptions;
|
this->templateOptions = templateOptions;
|
||||||
|
newTemplateOptions = *templateOptions;
|
||||||
this->printOptions = printOptions;
|
this->printOptions = printOptions;
|
||||||
|
|
||||||
// restore the settings and init the UI
|
// restore the settings and init the UI
|
||||||
|
@ -24,38 +29,157 @@ TemplateEdit::TemplateEdit(QWidget *parent, struct print_options *printOptions,
|
||||||
grantlee_template = TemplateLayout::readTemplate("custom.html");
|
grantlee_template = TemplateLayout::readTemplate("custom.html");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 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*)));
|
||||||
|
|
||||||
ui->plainTextEdit->setPlainText(grantlee_template);
|
ui->plainTextEdit->setPlainText(grantlee_template);
|
||||||
|
updatePreview();
|
||||||
}
|
}
|
||||||
|
|
||||||
TemplateEdit::~TemplateEdit()
|
TemplateEdit::~TemplateEdit()
|
||||||
{
|
{
|
||||||
|
delete btnGroup;
|
||||||
delete ui;
|
delete ui;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TemplateEdit::updatePreview()
|
||||||
|
{
|
||||||
|
// update Qpixmap preview
|
||||||
|
int width = ui->label->width();
|
||||||
|
int height = ui->label->height();
|
||||||
|
QPixmap map(width * 2, height * 2);
|
||||||
|
map.fill(QColor::fromRgb(255, 255, 255));
|
||||||
|
Printer printer(&map, printOptions, &newTemplateOptions, Printer::PREVIEW);
|
||||||
|
printer.previewOnePage();
|
||||||
|
ui->label->setPixmap(map.scaled(width, height, Qt::IgnoreAspectRatio));
|
||||||
|
|
||||||
|
// 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());
|
||||||
|
|
||||||
|
// update critical UI elements
|
||||||
|
ui->colorpalette->setCurrentIndex(newTemplateOptions.color_palette_index);
|
||||||
|
}
|
||||||
|
|
||||||
void TemplateEdit::on_fontsize_valueChanged(int font_size)
|
void TemplateEdit::on_fontsize_valueChanged(int font_size)
|
||||||
{
|
{
|
||||||
templateOptions->font_size = font_size;
|
newTemplateOptions.font_size = font_size;
|
||||||
|
updatePreview();
|
||||||
}
|
}
|
||||||
|
|
||||||
void TemplateEdit::on_linespacing_valueChanged(double line_spacing)
|
void TemplateEdit::on_linespacing_valueChanged(double line_spacing)
|
||||||
{
|
{
|
||||||
templateOptions->line_spacing = line_spacing;
|
newTemplateOptions.line_spacing = line_spacing;
|
||||||
|
updatePreview();
|
||||||
}
|
}
|
||||||
|
|
||||||
void TemplateEdit::on_fontSelection_currentIndexChanged(int index)
|
void TemplateEdit::on_fontSelection_currentIndexChanged(int index)
|
||||||
{
|
{
|
||||||
templateOptions->font_index = index;
|
newTemplateOptions.font_index = index;
|
||||||
|
updatePreview();
|
||||||
}
|
}
|
||||||
|
|
||||||
void TemplateEdit::on_colorpalette_currentIndexChanged(int index)
|
void TemplateEdit::on_colorpalette_currentIndexChanged(int index)
|
||||||
{
|
{
|
||||||
templateOptions->color_palette_index = index;
|
newTemplateOptions.color_palette_index = index;
|
||||||
|
switch (newTemplateOptions.color_palette_index) {
|
||||||
|
case 0: // almond
|
||||||
|
newTemplateOptions.color_palette = almond_colors;
|
||||||
|
break;
|
||||||
|
case 1: // custom
|
||||||
|
newTemplateOptions.color_palette = custom_colors;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
updatePreview();
|
||||||
}
|
}
|
||||||
|
|
||||||
void TemplateEdit::on_TemplateEdit_finished(int result)
|
void TemplateEdit::saveSettings()
|
||||||
{
|
{
|
||||||
|
if ((*templateOptions) != newTemplateOptions || grantlee_template.compare(ui->plainTextEdit->toPlainText())) {
|
||||||
|
QMessageBox msgBox;
|
||||||
|
msgBox.setText("Do you want to save your changes?");
|
||||||
|
msgBox.setStandardButtons(QMessageBox::Save | QMessageBox::Cancel);
|
||||||
|
msgBox.setDefaultButton(QMessageBox::Cancel);
|
||||||
|
if (msgBox.exec() == QMessageBox::Save) {
|
||||||
|
memcpy(templateOptions, &newTemplateOptions, sizeof(struct template_options));
|
||||||
if (grantlee_template.compare(ui->plainTextEdit->toPlainText())) {
|
if (grantlee_template.compare(ui->plainTextEdit->toPlainText())) {
|
||||||
printOptions->p_template = print_options::CUSTOM;
|
printOptions->p_template = print_options::CUSTOM;
|
||||||
TemplateLayout::writeTemplate("custom.html", ui->plainTextEdit->toPlainText());
|
TemplateLayout::writeTemplate("custom.html", ui->plainTextEdit->toPlainText());
|
||||||
}
|
}
|
||||||
|
if (templateOptions->color_palette_index == 1) {
|
||||||
|
custom_colors = templateOptions->color_palette;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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();
|
||||||
|
updatePreview();
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void TemplateEdit::colorSelect(QAbstractButton *button)
|
||||||
|
{
|
||||||
|
// reset custom colors palette
|
||||||
|
switch (newTemplateOptions.color_palette_index) {
|
||||||
|
case 0: // almond
|
||||||
|
newTemplateOptions.color_palette = almond_colors;
|
||||||
|
custom_colors = newTemplateOptions.color_palette;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
//change selected color
|
||||||
|
QColor color;
|
||||||
|
switch (btnGroup->id(button)) {
|
||||||
|
case 1:
|
||||||
|
color = QColorDialog::getColor(newTemplateOptions.color_palette.color1, this);
|
||||||
|
newTemplateOptions.color_palette.color1 = color;
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
color = QColorDialog::getColor(newTemplateOptions.color_palette.color2, this);
|
||||||
|
newTemplateOptions.color_palette.color2 = color;
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
color = QColorDialog::getColor(newTemplateOptions.color_palette.color3, this);
|
||||||
|
newTemplateOptions.color_palette.color3 = color;
|
||||||
|
break;
|
||||||
|
case 4:
|
||||||
|
color = QColorDialog::getColor(newTemplateOptions.color_palette.color4, this);
|
||||||
|
newTemplateOptions.color_palette.color4 = color;
|
||||||
|
break;
|
||||||
|
case 5:
|
||||||
|
color = QColorDialog::getColor(newTemplateOptions.color_palette.color5, this);
|
||||||
|
newTemplateOptions.color_palette.color5 = color;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
newTemplateOptions.color_palette_index = 1;
|
||||||
|
updatePreview();
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,13 +24,20 @@ private slots:
|
||||||
|
|
||||||
void on_colorpalette_currentIndexChanged(int index);
|
void on_colorpalette_currentIndexChanged(int index);
|
||||||
|
|
||||||
void on_TemplateEdit_finished(int result);
|
void on_buttonBox_clicked(QAbstractButton *button);
|
||||||
|
|
||||||
|
void colorSelect(QAbstractButton *button);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Ui::TemplateEdit *ui;
|
Ui::TemplateEdit *ui;
|
||||||
|
QButtonGroup *btnGroup;
|
||||||
struct template_options *templateOptions;
|
struct template_options *templateOptions;
|
||||||
|
struct template_options newTemplateOptions;
|
||||||
struct print_options *printOptions;
|
struct print_options *printOptions;
|
||||||
QString grantlee_template;
|
QString grantlee_template;
|
||||||
|
void saveSettings();
|
||||||
|
void updatePreview();
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // TEMPLATEEDIT_H
|
#endif // TEMPLATEEDIT_H
|
||||||
|
|
|
@ -26,7 +26,7 @@
|
||||||
<enum>Qt::Horizontal</enum>
|
<enum>Qt::Horizontal</enum>
|
||||||
</property>
|
</property>
|
||||||
<property name="standardButtons">
|
<property name="standardButtons">
|
||||||
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
|
<set>QDialogButtonBox::Apply|QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
<widget class="QTabWidget" name="tabWidget">
|
<widget class="QTabWidget" name="tabWidget">
|
||||||
|
@ -39,7 +39,7 @@
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<property name="currentIndex">
|
<property name="currentIndex">
|
||||||
<number>0</number>
|
<number>2</number>
|
||||||
</property>
|
</property>
|
||||||
<widget class="QWidget" name="style">
|
<widget class="QWidget" name="style">
|
||||||
<attribute name="title">
|
<attribute name="title">
|
||||||
|
@ -132,6 +132,11 @@
|
||||||
<string>Almond</string>
|
<string>Almond</string>
|
||||||
</property>
|
</property>
|
||||||
</item>
|
</item>
|
||||||
|
<item>
|
||||||
|
<property name="text">
|
||||||
|
<string>Custom</string>
|
||||||
|
</property>
|
||||||
|
</item>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
|
@ -187,21 +192,223 @@
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</widget>
|
</widget>
|
||||||
</widget>
|
<widget class="QWidget" name="color_tab">
|
||||||
<widget class="QWebView" name="webView">
|
<attribute name="title">
|
||||||
|
<string>Colors</string>
|
||||||
|
</attribute>
|
||||||
|
<widget class="QWidget" name="verticalLayoutWidget_2">
|
||||||
<property name="geometry">
|
<property name="geometry">
|
||||||
<rect>
|
<rect>
|
||||||
<x>20</x>
|
<x>10</x>
|
||||||
<y>60</y>
|
<y>30</y>
|
||||||
<width>251</width>
|
<width>411</width>
|
||||||
<height>311</height>
|
<height>171</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<property name="url">
|
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||||
<url>
|
<item>
|
||||||
<string>about:blank</string>
|
<layout class="QHBoxLayout" name="horizontalLayout_5">
|
||||||
</url>
|
<item>
|
||||||
|
<widget class="QLabel" name="label_3">
|
||||||
|
<property name="sizePolicy">
|
||||||
|
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred">
|
||||||
|
<horstretch>0</horstretch>
|
||||||
|
<verstretch>0</verstretch>
|
||||||
|
</sizepolicy>
|
||||||
</property>
|
</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>
|
||||||
<widget class="QLabel" name="label_5">
|
<widget class="QLabel" name="label_5">
|
||||||
<property name="geometry">
|
<property name="geometry">
|
||||||
|
@ -216,14 +423,20 @@
|
||||||
<string>Preview</string>
|
<string>Preview</string>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</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>
|
||||||
</widget>
|
</widget>
|
||||||
<customwidgets>
|
|
||||||
<customwidget>
|
|
||||||
<class>QWebView</class>
|
|
||||||
<extends>QWidget</extends>
|
|
||||||
<header>QtWebKitWidgets/QWebView</header>
|
|
||||||
</customwidget>
|
|
||||||
</customwidgets>
|
|
||||||
<resources/>
|
<resources/>
|
||||||
<connections>
|
<connections>
|
||||||
<connection>
|
<connection>
|
||||||
|
|
|
@ -47,6 +47,7 @@ QString TemplateLayout::generate()
|
||||||
|
|
||||||
Grantlee::registerMetaType<Dive>();
|
Grantlee::registerMetaType<Dive>();
|
||||||
Grantlee::registerMetaType<template_options>();
|
Grantlee::registerMetaType<template_options>();
|
||||||
|
Grantlee::registerMetaType<print_options>();
|
||||||
|
|
||||||
QVariantHash mapping;
|
QVariantHash mapping;
|
||||||
QVariantList diveList;
|
QVariantList diveList;
|
||||||
|
@ -64,6 +65,7 @@ QString TemplateLayout::generate()
|
||||||
}
|
}
|
||||||
mapping.insert("dives", diveList);
|
mapping.insert("dives", diveList);
|
||||||
mapping.insert("template_options", QVariant::fromValue(*templateOptions));
|
mapping.insert("template_options", QVariant::fromValue(*templateOptions));
|
||||||
|
mapping.insert("print_options", QVariant::fromValue(*PrintOptions));
|
||||||
|
|
||||||
Grantlee::Context c(mapping);
|
Grantlee::Context c(mapping);
|
||||||
|
|
||||||
|
@ -104,6 +106,7 @@ void TemplateLayout::writeTemplate(QString template_name, QString grantlee_templ
|
||||||
QFile qfile(getSubsurfaceDataPath("printing_templates") + QDir::separator() + template_name);
|
QFile qfile(getSubsurfaceDataPath("printing_templates") + QDir::separator() + template_name);
|
||||||
if (qfile.open(QFile::ReadWrite | QFile::Text)) {
|
if (qfile.open(QFile::ReadWrite | QFile::Text)) {
|
||||||
qfile.write(grantlee_template.toUtf8().data());
|
qfile.write(grantlee_template.toUtf8().data());
|
||||||
|
qfile.resize(qfile.pos());
|
||||||
qfile.close();
|
qfile.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -79,6 +79,7 @@ public:
|
||||||
|
|
||||||
Q_DECLARE_METATYPE(Dive)
|
Q_DECLARE_METATYPE(Dive)
|
||||||
Q_DECLARE_METATYPE(template_options)
|
Q_DECLARE_METATYPE(template_options)
|
||||||
|
Q_DECLARE_METATYPE(print_options)
|
||||||
|
|
||||||
GRANTLEE_BEGIN_LOOKUP(Dive)
|
GRANTLEE_BEGIN_LOOKUP(Dive)
|
||||||
if (property == "number")
|
if (property == "number")
|
||||||
|
@ -123,6 +124,26 @@ if (property == "font") {
|
||||||
return object.font_size / 9.0;
|
return object.font_size / 9.0;
|
||||||
} else if (property == "line_spacing") {
|
} else if (property == "line_spacing") {
|
||||||
return object.line_spacing;
|
return object.line_spacing;
|
||||||
|
} else if (property == "color1") {
|
||||||
|
return object.color_palette.color1.name();
|
||||||
|
} else if (property == "color2") {
|
||||||
|
return object.color_palette.color2.name();
|
||||||
|
} else if (property == "color3") {
|
||||||
|
return object.color_palette.color3.name();
|
||||||
|
} else if (property == "color4") {
|
||||||
|
return object.color_palette.color4.name();
|
||||||
|
} else if (property == "color5") {
|
||||||
|
return object.color_palette.color5.name();
|
||||||
|
}
|
||||||
|
GRANTLEE_END_LOOKUP
|
||||||
|
|
||||||
|
GRANTLEE_BEGIN_LOOKUP(print_options)
|
||||||
|
if (property == "grayscale") {
|
||||||
|
if (object.color_selected) {
|
||||||
|
return "";
|
||||||
|
} else {
|
||||||
|
return "-webkit-filter: grayscale(100%)";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
GRANTLEE_END_LOOKUP
|
GRANTLEE_END_LOOKUP
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue