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
113
printer.cpp
113
printer.cpp
|
@ -6,13 +6,20 @@
|
|||
#include <QWebElementCollection>
|
||||
#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->templateOptions = templateOptions;
|
||||
this->printMode = printMode;
|
||||
dpi = 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)
|
||||
|
@ -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.
|
||||
QRect pos(x, y, profilePlaceholder.width(), profilePlaceholder.height());
|
||||
profile->plotDive(dive, true);
|
||||
profile->render(painter, pos);
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
QPointer<ProfileWidget2> profile = MainWindow::instance()->graphics();
|
||||
int profileFrameStyle = profile->frameStyle();
|
||||
|
@ -53,14 +65,14 @@ void Printer::render()
|
|||
// apply printing settings to profile
|
||||
profile->setFrameStyle(QFrame::NoFrame);
|
||||
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);
|
||||
prefs.animation_speed = 0;
|
||||
|
||||
// render the Qwebview
|
||||
QPainter painter;
|
||||
QRect viewPort(0, 0, pageSize.width(), pageSize.height());
|
||||
painter.begin(printer);
|
||||
painter.begin(paintDevice);
|
||||
painter.setRenderHint(QPainter::Antialiasing);
|
||||
painter.setRenderHint(QPainter::SmoothPixmapTransform);
|
||||
|
||||
|
@ -91,8 +103,8 @@ void Printer::render()
|
|||
|
||||
// rendering progress is 4/5 of total work
|
||||
emit(progessUpdated((i * 80.0 / Pages) + done));
|
||||
if (i < Pages - 1)
|
||||
printer->newPage();
|
||||
if (i < Pages - 1 && printMode == Printer::PRINT)
|
||||
static_cast<QPrinter*>(paintDevice)->newPage();
|
||||
}
|
||||
painter.end();
|
||||
|
||||
|
@ -117,15 +129,52 @@ void Printer::templateProgessUpdated(int value)
|
|||
|
||||
void Printer::print()
|
||||
{
|
||||
TemplateLayout t(printOptions, templateOptions);
|
||||
webView = new QWebView();
|
||||
connect(&t, SIGNAL(progressUpdated(int)), this, SLOT(templateProgessUpdated(int)));
|
||||
// we can only print if "PRINT" mode is selected
|
||||
if (printMode != Printer::PRINT) {
|
||||
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
|
||||
pageSize.setHeight(printer->pageLayout().paintRect(QPageLayout::Inch).height() * dpi);
|
||||
pageSize.setWidth(printer->pageLayout().paintRect(QPageLayout::Inch).width() * dpi);
|
||||
pageSize.setHeight(printerPtr->pageLayout().paintRect(QPageLayout::Inch).height() * dpi);
|
||||
pageSize.setWidth(printerPtr->pageLayout().paintRect(QPageLayout::Inch).width() * dpi);
|
||||
webView->page()->setViewportSize(pageSize);
|
||||
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 {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
enum PrintMode {
|
||||
PRINT,
|
||||
PREVIEW
|
||||
};
|
||||
|
||||
private:
|
||||
QPrinter *printer;
|
||||
QPaintDevice *paintDevice;
|
||||
QWebView *webView;
|
||||
print_options *printOptions;
|
||||
template_options *templateOptions;
|
||||
QSize pageSize;
|
||||
PrintMode printMode;
|
||||
int done;
|
||||
int dpi;
|
||||
void render();
|
||||
void render(int Pages);
|
||||
void putProfileImage(QRect box, QRect viewPort, QPainter *painter, struct dive *dive, QPointer<ProfileWidget2> profile);
|
||||
|
||||
private slots:
|
||||
void templateProgessUpdated(int value);
|
||||
|
||||
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 previewOnePage();
|
||||
|
||||
signals:
|
||||
void progessUpdated(int value);
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
<head>
|
||||
<style>
|
||||
body {
|
||||
background-color: white;
|
||||
{{ print_options.grayscale }};
|
||||
padding: 0;
|
||||
margin: 0;
|
||||
font-size: {{ template_options.font_size }}vw;
|
||||
|
@ -16,13 +16,21 @@
|
|||
}
|
||||
|
||||
table {
|
||||
-webkit-box-sizing: border-box; /* Safari/Chrome, other WebKit */
|
||||
-moz-box-sizing: border-box; /* Firefox, other Gecko */
|
||||
-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%;
|
||||
height: 100%;
|
||||
|
@ -45,8 +53,7 @@
|
|||
.diveDetails {
|
||||
width: 98%;
|
||||
height: 98%;
|
||||
-webkit-box-sizing: border-box; /* Safari/Chrome, other WebKit */
|
||||
-moz-box-sizing: border-box; /* Firefox, other Gecko */
|
||||
-webkit-box-sizing: border-box;
|
||||
box-sizing: border-box;
|
||||
border:max(1px, 0.1vw);
|
||||
border-style:solid;
|
||||
|
@ -54,45 +61,43 @@
|
|||
}
|
||||
|
||||
.diveProfile {
|
||||
width: 97%;
|
||||
width: 96%;
|
||||
height: 40%;
|
||||
margin: 1.5%;
|
||||
-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;
|
||||
margin: 2%;
|
||||
}
|
||||
|
||||
.dataSection {
|
||||
width: 97%;
|
||||
width: 98%;
|
||||
height: 40%;
|
||||
margin: 1.5%;
|
||||
margin: 1%;
|
||||
}
|
||||
|
||||
.fieldTitle {
|
||||
background-color: #CfC7C5;
|
||||
background-color: {{ template_options.color2 }};
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.table_class {
|
||||
float: left;
|
||||
margin: 1.5%;
|
||||
margin: 1%;
|
||||
width: 48%;
|
||||
}
|
||||
|
||||
.notes_table_class {
|
||||
overflow: hidden;
|
||||
width: 97%;
|
||||
margin: 1.5%;
|
||||
float: left;
|
||||
width: 98%;
|
||||
margin: 1%;
|
||||
}
|
||||
|
||||
.textArea {
|
||||
line-height: {{ template_options.line_spacing }};
|
||||
max-height: 19vh;
|
||||
overflow: hidden;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body data-numberofdives = 1>
|
||||
<div id="body_div">
|
||||
{% block main_rows %}
|
||||
{% for dive in dives %}
|
||||
<div class="mainContainer">
|
||||
|
@ -206,5 +211,6 @@
|
|||
</div>
|
||||
{% endfor %}
|
||||
{% endblock %}
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
<head>
|
||||
<style>
|
||||
body {
|
||||
background-color: white;
|
||||
{{ print_options.grayscale }};
|
||||
padding: 0px;
|
||||
margin: 0px;
|
||||
font-size: {{ template_options.font_size }}vw;
|
||||
|
@ -15,6 +15,10 @@
|
|||
float: left;
|
||||
}
|
||||
|
||||
#body_div {
|
||||
background-color: {{ template_options.color1 }};
|
||||
}
|
||||
|
||||
.mainContainer {
|
||||
width: 96%;
|
||||
height: 50%;
|
||||
|
@ -63,7 +67,7 @@
|
|||
}
|
||||
|
||||
.fieldTitle {
|
||||
background-color: #CfC7C5;
|
||||
background-color: {{ template_options.color2 }};
|
||||
overflow: hidden;
|
||||
padding:0;
|
||||
}
|
||||
|
@ -103,6 +107,7 @@
|
|||
</style>
|
||||
</head>
|
||||
<body data-numberofdives = 2>
|
||||
<div id="body_div">
|
||||
{% block main_rows %}
|
||||
{% for dive in dives %}
|
||||
<div class="mainContainer">
|
||||
|
@ -217,5 +222,6 @@
|
|||
{% endblock %}
|
||||
<div id="footer">
|
||||
<div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
@ -12,8 +12,17 @@
|
|||
|
||||
#define SETTINGS_GROUP "PrintDialog"
|
||||
|
||||
template_options::color_palette_struct almond_colors, custom_colors;
|
||||
|
||||
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.
|
||||
QSettings s;
|
||||
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.color_palette_index = 0;
|
||||
templateOptions.line_spacing = 1;
|
||||
custom_colors = almond_colors;
|
||||
} else {
|
||||
s.beginGroup(SETTINGS_GROUP);
|
||||
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.color_palette_index = s.value("color_palette").toInt();
|
||||
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
|
||||
optionsWidget = new PrintOptions(this, &printOptions, &templateOptions);
|
||||
|
||||
// create a new printer object
|
||||
printer = new Printer(&qprinter, &printOptions, &templateOptions);
|
||||
printer = new Printer(&qprinter, &printOptions, &templateOptions, Printer::PRINT);
|
||||
|
||||
QVBoxLayout *layout = new QVBoxLayout(this);
|
||||
setLayout(layout);
|
||||
|
@ -105,6 +129,13 @@ void PrintDialog::onFinished()
|
|||
s.setValue("font_size", templateOptions.font_size);
|
||||
s.setValue("color_palette", templateOptions.color_palette_index);
|
||||
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)
|
||||
|
|
|
@ -26,7 +26,30 @@ struct template_options {
|
|||
int color_palette_index;
|
||||
double font_size;
|
||||
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
|
||||
class PrintOptions : public QWidget {
|
||||
|
|
|
@ -1,13 +1,18 @@
|
|||
#include "templateedit.h"
|
||||
#include "printoptions.h"
|
||||
#include "printer.h"
|
||||
#include "ui_templateedit.h"
|
||||
|
||||
#include <QMessageBox>
|
||||
#include <QColorDialog>
|
||||
|
||||
TemplateEdit::TemplateEdit(QWidget *parent, struct print_options *printOptions, struct template_options *templateOptions) :
|
||||
QDialog(parent),
|
||||
ui(new Ui::TemplateEdit)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
this->templateOptions = templateOptions;
|
||||
newTemplateOptions = *templateOptions;
|
||||
this->printOptions = printOptions;
|
||||
|
||||
// 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");
|
||||
}
|
||||
|
||||
// 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);
|
||||
updatePreview();
|
||||
}
|
||||
|
||||
TemplateEdit::~TemplateEdit()
|
||||
{
|
||||
delete btnGroup;
|
||||
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)
|
||||
{
|
||||
templateOptions->font_size = font_size;
|
||||
newTemplateOptions.font_size = font_size;
|
||||
updatePreview();
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
templateOptions->font_index = index;
|
||||
newTemplateOptions.font_index = index;
|
||||
updatePreview();
|
||||
}
|
||||
|
||||
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 (grantlee_template.compare(ui->plainTextEdit->toPlainText())) {
|
||||
printOptions->p_template = print_options::CUSTOM;
|
||||
TemplateLayout::writeTemplate("custom.html", ui->plainTextEdit->toPlainText());
|
||||
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())) {
|
||||
printOptions->p_template = print_options::CUSTOM;
|
||||
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_TemplateEdit_finished(int result);
|
||||
void on_buttonBox_clicked(QAbstractButton *button);
|
||||
|
||||
void colorSelect(QAbstractButton *button);
|
||||
|
||||
private:
|
||||
Ui::TemplateEdit *ui;
|
||||
QButtonGroup *btnGroup;
|
||||
struct template_options *templateOptions;
|
||||
struct template_options newTemplateOptions;
|
||||
struct print_options *printOptions;
|
||||
QString grantlee_template;
|
||||
void saveSettings();
|
||||
void updatePreview();
|
||||
|
||||
};
|
||||
|
||||
#endif // TEMPLATEEDIT_H
|
||||
|
|
|
@ -26,7 +26,7 @@
|
|||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="standardButtons">
|
||||
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
|
||||
<set>QDialogButtonBox::Apply|QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QTabWidget" name="tabWidget">
|
||||
|
@ -39,7 +39,7 @@
|
|||
</rect>
|
||||
</property>
|
||||
<property name="currentIndex">
|
||||
<number>0</number>
|
||||
<number>2</number>
|
||||
</property>
|
||||
<widget class="QWidget" name="style">
|
||||
<attribute name="title">
|
||||
|
@ -132,6 +132,11 @@
|
|||
<string>Almond</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Custom</string>
|
||||
</property>
|
||||
</item>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
|
@ -187,21 +192,223 @@
|
|||
</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 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">
|
||||
|
@ -216,14 +423,20 @@
|
|||
<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>
|
||||
</widget>
|
||||
<customwidgets>
|
||||
<customwidget>
|
||||
<class>QWebView</class>
|
||||
<extends>QWidget</extends>
|
||||
<header>QtWebKitWidgets/QWebView</header>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<resources/>
|
||||
<connections>
|
||||
<connection>
|
||||
|
|
|
@ -47,6 +47,7 @@ QString TemplateLayout::generate()
|
|||
|
||||
Grantlee::registerMetaType<Dive>();
|
||||
Grantlee::registerMetaType<template_options>();
|
||||
Grantlee::registerMetaType<print_options>();
|
||||
|
||||
QVariantHash mapping;
|
||||
QVariantList diveList;
|
||||
|
@ -64,6 +65,7 @@ QString TemplateLayout::generate()
|
|||
}
|
||||
mapping.insert("dives", diveList);
|
||||
mapping.insert("template_options", QVariant::fromValue(*templateOptions));
|
||||
mapping.insert("print_options", QVariant::fromValue(*PrintOptions));
|
||||
|
||||
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);
|
||||
if (qfile.open(QFile::ReadWrite | QFile::Text)) {
|
||||
qfile.write(grantlee_template.toUtf8().data());
|
||||
qfile.resize(qfile.pos());
|
||||
qfile.close();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -79,6 +79,7 @@ public:
|
|||
|
||||
Q_DECLARE_METATYPE(Dive)
|
||||
Q_DECLARE_METATYPE(template_options)
|
||||
Q_DECLARE_METATYPE(print_options)
|
||||
|
||||
GRANTLEE_BEGIN_LOOKUP(Dive)
|
||||
if (property == "number")
|
||||
|
@ -123,6 +124,26 @@ if (property == "font") {
|
|||
return object.font_size / 9.0;
|
||||
} else if (property == "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
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue