diff options
-rw-r--r-- | desktop-widgets/printdialog.cpp | 4 | ||||
-rw-r--r-- | desktop-widgets/printer.cpp | 51 | ||||
-rw-r--r-- | desktop-widgets/printer.h | 6 | ||||
-rw-r--r-- | desktop-widgets/printoptions.cpp | 36 | ||||
-rw-r--r-- | desktop-widgets/printoptions.h | 6 | ||||
-rw-r--r-- | desktop-widgets/templateedit.cpp | 62 | ||||
-rw-r--r-- | desktop-widgets/templateedit.h | 12 | ||||
-rw-r--r-- | desktop-widgets/templatelayout.cpp | 23 | ||||
-rw-r--r-- | desktop-widgets/templatelayout.h | 10 |
9 files changed, 98 insertions, 112 deletions
diff --git a/desktop-widgets/printdialog.cpp b/desktop-widgets/printdialog.cpp index 87507c197..29cf4fe54 100644 --- a/desktop-widgets/printdialog.cpp +++ b/desktop-widgets/printdialog.cpp @@ -87,7 +87,7 @@ PrintDialog::PrintDialog(QWidget *parent) : } // create a print options object and pass our options struct - optionsWidget = new PrintOptions(this, &printOptions, &templateOptions); + optionsWidget = new PrintOptions(this, printOptions, templateOptions); QVBoxLayout *layout = new QVBoxLayout(this); setLayout(layout); @@ -175,7 +175,7 @@ void PrintDialog::createPrinterObj() qprinter = new QPrinter(); qprinter->setResolution(printOptions.resolution); qprinter->setOrientation((QPrinter::Orientation)printOptions.landscape); - printer = new Printer(qprinter, &printOptions, &templateOptions, Printer::PRINT); + printer = new Printer(qprinter, printOptions, templateOptions, Printer::PRINT); } } diff --git a/desktop-widgets/printer.cpp b/desktop-widgets/printer.cpp index cd7c11345..05f82d688 100644 --- a/desktop-widgets/printer.cpp +++ b/desktop-widgets/printer.cpp @@ -12,15 +12,15 @@ #include <QWebElement> #include "profile-widget/profilewidget2.h" -Printer::Printer(QPaintDevice *paintDevice, print_options *printOptions, template_options *templateOptions, PrintMode printMode) +Printer::Printer(QPaintDevice *paintDevice, const print_options &printOptions, const template_options &templateOptions, PrintMode printMode) : + paintDevice(paintDevice), + webView(new QWebView), + printOptions(printOptions), + templateOptions(templateOptions), + printMode(printMode), + done(0), + dpi(0) { - this->paintDevice = paintDevice; - this->printOptions = printOptions; - this->templateOptions = templateOptions; - this->printMode = printMode; - dpi = 0; - done = 0; - webView = new QWebView(); } Printer::~Printer() @@ -36,7 +36,7 @@ void Printer::putProfileImage(QRect profilePlaceholder, QRect viewPort, QPainter QRect pos(x, y, profilePlaceholder.width(), profilePlaceholder.height()); profile->plotDive(dive, true, true); - if (!printOptions->color_selected) { + if (!printOptions.color_selected) { QImage image(pos.width(), pos.height(), QImage::Format_ARGB32); QPainter imgPainter(&image); imgPainter.setRenderHint(QPainter::Antialiasing); @@ -85,7 +85,7 @@ void Printer::flowRender() } else { // fill the page with background color QRect fullPage(0, 0, pageSize.width(), pageSize.height()); - QBrush fillBrush(templateOptions->color_palette.color1); + QBrush fillBrush(templateOptions.color_palette.color1); painter.fillRect(fullPage, fillBrush); QRegion reigon(0, 0, pageSize.width(), end - start); viewPort.setRect(0, start, pageSize.width(), end - start); @@ -111,7 +111,7 @@ void Printer::flowRender() } // render the remianing page QRect fullPage(0, 0, pageSize.width(), pageSize.height()); - QBrush fillBrush(templateOptions->color_palette.color1); + QBrush fillBrush(templateOptions.color_palette.color1); painter.fillRect(fullPage, fillBrush); QRegion reigon(0, 0, pageSize.width(), end - start); webView->page()->mainFrame()->render(&painter, QWebFrame::ContentsLayer, reigon); @@ -130,7 +130,7 @@ void Printer::render(int Pages = 0) // apply printing settings to profile profile->setFrameStyle(QFrame::NoFrame); - profile->setPrintMode(true, !printOptions->color_selected); + profile->setPrintMode(true, !printOptions.color_selected); profile->setToolTipVisibile(false); qPrefDisplay::set_animation_speed(0); @@ -195,16 +195,16 @@ void Printer::templateProgessUpdated(int value) emit progessUpdated(done); } -QString Printer::exportHtml() { +QString Printer::exportHtml() +{ TemplateLayout t(printOptions, templateOptions); connect(&t, SIGNAL(progressUpdated(int)), this, SLOT(templateProgessUpdated(int))); QString html; - if (printOptions->type == print_options::DIVELIST) { + if (printOptions.type == print_options::DIVELIST) html = t.generate(); - } else if (printOptions->type == print_options::STATISTICS ) { + else if (printOptions.type == print_options::STATISTICS ) html = t.generateStatistics(); - } // TODO: write html to file return html; @@ -231,17 +231,15 @@ void Printer::print() webView->page()->mainFrame()->setScrollBarPolicy(Qt::Vertical, Qt::ScrollBarAlwaysOff); // export border width with at least 1 pixel - // templateOptions->borderwidth = std::max(1, pageSize.width() / 1000); - if (printOptions->type == print_options::DIVELIST) { + // templateOptions.borderwidth = std::max(1, pageSize.width() / 1000); + if (printOptions.type == print_options::DIVELIST) webView->setHtml(t.generate()); - } else if (printOptions->type == print_options::STATISTICS ) { + else if (printOptions.type == print_options::STATISTICS ) webView->setHtml(t.generateStatistics()); - } - if (printOptions->color_selected && printerPtr->colorMode()) { + if (printOptions.color_selected && printerPtr->colorMode()) printerPtr->setColorMode(QPrinter::Color); - } else { + else printerPtr->setColorMode(QPrinter::GrayScale); - } // apply user settings int divesPerPage; @@ -270,12 +268,11 @@ void Printer::previewOnePage() pageSize.setWidth(paintDevice->width()); webView->page()->setViewportSize(pageSize); // initialize the border settings - // templateOptions->border_width = std::max(1, pageSize.width() / 1000); - if (printOptions->type == print_options::DIVELIST) { + // templateOptions.border_width = std::max(1, pageSize.width() / 1000); + if (printOptions.type == print_options::DIVELIST) webView->setHtml(t.generate()); - } else if (printOptions->type == print_options::STATISTICS ) { + else if (printOptions.type == print_options::STATISTICS ) webView->setHtml(t.generateStatistics()); - } bool ok; int divesPerPage = webView->page()->mainFrame()->findFirstElement("body").attribute("data-numberofdives").toInt(&ok); if (!ok) { diff --git a/desktop-widgets/printer.h b/desktop-widgets/printer.h index cdc0acf09..c95700684 100644 --- a/desktop-widgets/printer.h +++ b/desktop-widgets/printer.h @@ -22,8 +22,8 @@ public: private: QPaintDevice *paintDevice; QWebView *webView; - print_options *printOptions; - template_options *templateOptions; + const print_options &printOptions; + const template_options &templateOptions; QSize pageSize; PrintMode printMode; int done; @@ -36,7 +36,7 @@ private slots: void templateProgessUpdated(int value); public: - Printer(QPaintDevice *paintDevice, print_options *printOptions, template_options *templateOptions, PrintMode printMode); + Printer(QPaintDevice *paintDevice, const print_options &printOptions, const template_options &templateOptions, PrintMode printMode); ~Printer(); void print(); void previewOnePage(); diff --git a/desktop-widgets/printoptions.cpp b/desktop-widgets/printoptions.cpp index 215762db5..bebfb732f 100644 --- a/desktop-widgets/printoptions.cpp +++ b/desktop-widgets/printoptions.cpp @@ -7,23 +7,21 @@ #include <QFileDialog> #include <QMessageBox> -PrintOptions::PrintOptions(QWidget *parent, struct print_options *printOpt, struct template_options *templateOpt) +PrintOptions::PrintOptions(QWidget *parent, print_options &printOpt, template_options &templateOpt) : + printOptions(printOpt), + templateOptions(templateOpt) { hasSetupSlots = false; ui.setupUi(this); if (parent) setParent(parent); - if (!printOpt || !templateOpt) - return; - templateOptions = templateOpt; - printOptions = printOpt; setup(); } void PrintOptions::setup() { // print type radio buttons - switch (printOptions->type) { + switch (printOptions.type) { case print_options::DIVELIST: ui.radioDiveListPrint->setChecked(true); break; @@ -35,11 +33,11 @@ void PrintOptions::setup() setupTemplates(); // general print option checkboxes - ui.printInColor->setChecked(printOptions->color_selected); - ui.printSelected->setChecked(printOptions->print_selected); + ui.printInColor->setChecked(printOptions.color_selected); + ui.printSelected->setChecked(printOptions.print_selected); // resolution - ui.resolution->setValue(printOptions->resolution); + ui.resolution->setValue(printOptions.resolution); // connect slots only once if (hasSetupSlots) @@ -48,19 +46,19 @@ void PrintOptions::setup() connect(ui.printInColor, SIGNAL(clicked(bool)), this, SLOT(printInColorClicked(bool))); connect(ui.printSelected, SIGNAL(clicked(bool)), this, SLOT(printSelectedClicked(bool))); connect(ui.resolution, QOverload<int>::of(&QSpinBox::valueChanged), [this](int value) { - printOptions->resolution = value; + printOptions.resolution = value; }); hasSetupSlots = true; } void PrintOptions::setupTemplates() { - QStringList currList = printOptions->type == print_options::DIVELIST ? + QStringList currList = printOptions.type == print_options::DIVELIST ? grantlee_templates : grantlee_statistics_templates; // temp. store the template from options, as addItem() updates it via: // on_printTemplate_currentIndexChanged() - QString storedTemplate = printOptions->p_template; + QString storedTemplate = printOptions.p_template; currList.sort(); int current_index = 0; ui.printTemplate->clear(); @@ -78,7 +76,7 @@ void PrintOptions::setupTemplates() void PrintOptions::on_radioDiveListPrint_toggled(bool check) { if (check) { - printOptions->type = print_options::DIVELIST; + printOptions.type = print_options::DIVELIST; // print options ui.printSelected->setEnabled(true); @@ -95,7 +93,7 @@ void PrintOptions::on_radioDiveListPrint_toggled(bool check) void PrintOptions::on_radioStatisticsPrint_toggled(bool check) { if (check) { - printOptions->type = print_options::STATISTICS; + printOptions.type = print_options::STATISTICS; // print options ui.printSelected->setEnabled(false); @@ -112,24 +110,24 @@ void PrintOptions::on_radioStatisticsPrint_toggled(bool check) // general print option checkboxes void PrintOptions::printInColorClicked(bool check) { - printOptions->color_selected = check; + printOptions.color_selected = check; } void PrintOptions::printSelectedClicked(bool check) { - printOptions->print_selected = check; + printOptions.print_selected = check; } void PrintOptions::on_printTemplate_currentIndexChanged(int index) { - printOptions->p_template = ui.printTemplate->itemData(index).toString(); + printOptions.p_template = ui.printTemplate->itemData(index).toString(); } void PrintOptions::on_editButton_clicked() { QString templateName = getSelectedTemplate(); - QString prefix = (printOptions->type == print_options::STATISTICS) ? "statistics/" : ""; + QString prefix = (printOptions.type == print_options::STATISTICS) ? "statistics/" : ""; QFile f(getPrintingTemplatePathUser() + QDir::separator() + prefix + templateName); if (!f.open(QFile::ReadWrite | QFile::Text)) { QMessageBox msgBox(this); @@ -172,7 +170,7 @@ void PrintOptions::on_importButton_clicked() } QFile::copy(filename, dest); - printOptions->p_template = fileInfo.fileName(); + printOptions.p_template = fileInfo.fileName(); lastImportExportTemplate = fileInfo.fileName(); find_all_templates(); setup(); diff --git a/desktop-widgets/printoptions.h b/desktop-widgets/printoptions.h index 35fb824fe..d155c899d 100644 --- a/desktop-widgets/printoptions.h +++ b/desktop-widgets/printoptions.h @@ -64,14 +64,14 @@ class PrintOptions : public QWidget { Q_OBJECT public: - explicit PrintOptions(QWidget *parent, struct print_options *printOpt, struct template_options *templateOpt); + explicit PrintOptions(QWidget *parent, print_options &printOpt, template_options &templateOpt); void setup(); QString getSelectedTemplate(); private: Ui::PrintOptions ui; - struct print_options *printOptions = nullptr; - struct template_options *templateOptions = nullptr; + print_options &printOptions; + template_options &templateOptions; bool hasSetupSlots; QString lastImportExportTemplate; void setupTemplates(); diff --git a/desktop-widgets/templateedit.cpp b/desktop-widgets/templateedit.cpp index 36af4c994..d96ebdeef 100644 --- a/desktop-widgets/templateedit.cpp +++ b/desktop-widgets/templateedit.cpp @@ -8,27 +8,27 @@ #include <QButtonGroup> #include <QColorDialog> -TemplateEdit::TemplateEdit(QWidget *parent, struct print_options *printOptions, struct template_options *templateOptions) : +TemplateEdit::TemplateEdit(QWidget *parent, const print_options &printOptions, template_options &templateOptions) : QDialog(parent), - ui(new Ui::TemplateEdit) + ui(new Ui::TemplateEdit), + printOptions(printOptions), + templateOptions(templateOptions) { ui->setupUi(this); - this->templateOptions = templateOptions; - newTemplateOptions = *templateOptions; - this->printOptions = printOptions; + newTemplateOptions = templateOptions; // restore the settings and init the UI - ui->fontSelection->setCurrentIndex(templateOptions->font_index); - ui->fontsize->setValue(lrint(templateOptions->font_size)); - ui->colorpalette->setCurrentIndex(templateOptions->color_palette_index); - ui->linespacing->setValue(templateOptions->line_spacing); - ui->borderwidth->setValue(templateOptions->border_width); - - grantlee_template = TemplateLayout::readTemplate(printOptions->p_template); - if (printOptions->type == print_options::DIVELIST) - grantlee_template = TemplateLayout::readTemplate(printOptions->p_template); - else if (printOptions->type == print_options::STATISTICS) - grantlee_template = TemplateLayout::readTemplate(QString::fromUtf8("statistics") + QDir::separator() + printOptions->p_template); + ui->fontSelection->setCurrentIndex(templateOptions.font_index); + ui->fontsize->setValue(lrint(templateOptions.font_size)); + ui->colorpalette->setCurrentIndex(templateOptions.color_palette_index); + ui->linespacing->setValue(templateOptions.line_spacing); + ui->borderwidth->setValue(templateOptions.border_width); + + grantlee_template = TemplateLayout::readTemplate(printOptions.p_template); + if (printOptions.type == print_options::DIVELIST) + grantlee_template = TemplateLayout::readTemplate(printOptions.p_template); + else if (printOptions.type == print_options::STATISTICS) + grantlee_template = TemplateLayout::readTemplate(QString::fromUtf8("statistics") + QDir::separator() + printOptions.p_template); // gui btnGroup = new QButtonGroup; @@ -58,7 +58,7 @@ void TemplateEdit::updatePreview() 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 printer(&map, printOptions, newTemplateOptions, Printer::PREVIEW); printer.previewOnePage(); ui->label->setPixmap(map.scaled(width, height, Qt::IgnoreAspectRatio)); @@ -81,11 +81,11 @@ void TemplateEdit::updatePreview() ui->colorpalette->setCurrentIndex(newTemplateOptions.color_palette_index); // update grantlee template string - grantlee_template = TemplateLayout::readTemplate(printOptions->p_template); - if (printOptions->type == print_options::DIVELIST) - grantlee_template = TemplateLayout::readTemplate(printOptions->p_template); - else if (printOptions->type == print_options::STATISTICS) - grantlee_template = TemplateLayout::readTemplate(QString::fromUtf8("statistics") + QDir::separator() + printOptions->p_template); + grantlee_template = TemplateLayout::readTemplate(printOptions.p_template); + if (printOptions.type == print_options::DIVELIST) + grantlee_template = TemplateLayout::readTemplate(printOptions.p_template); + else if (printOptions.type == print_options::STATISTICS) + grantlee_template = TemplateLayout::readTemplate(QString::fromUtf8("statistics") + QDir::separator() + printOptions.p_template); } void TemplateEdit::on_fontsize_valueChanged(int font_size) @@ -137,7 +137,7 @@ void TemplateEdit::on_colorpalette_currentIndexChanged(int index) void TemplateEdit::saveSettings() { - if ((*templateOptions) != newTemplateOptions || grantlee_template.compare(ui->plainTextEdit->toPlainText())) { + if (templateOptions != newTemplateOptions || grantlee_template.compare(ui->plainTextEdit->toPlainText())) { QMessageBox msgBox(this); QString message = tr("Do you want to save your changes?"); bool templateChanged = false; @@ -147,16 +147,16 @@ void TemplateEdit::saveSettings() msgBox.setStandardButtons(QMessageBox::Save | QMessageBox::Cancel); msgBox.setDefaultButton(QMessageBox::Cancel); if (msgBox.exec() == QMessageBox::Save) { - *templateOptions = newTemplateOptions; + templateOptions = newTemplateOptions; if (templateChanged) { - TemplateLayout::writeTemplate(printOptions->p_template, ui->plainTextEdit->toPlainText()); - if (printOptions->type == print_options::DIVELIST) - TemplateLayout::writeTemplate(printOptions->p_template, ui->plainTextEdit->toPlainText()); - else if (printOptions->type == print_options::STATISTICS) - TemplateLayout::writeTemplate(QString::fromUtf8("statistics") + QDir::separator() + printOptions->p_template, ui->plainTextEdit->toPlainText()); + TemplateLayout::writeTemplate(printOptions.p_template, ui->plainTextEdit->toPlainText()); + if (printOptions.type == print_options::DIVELIST) + TemplateLayout::writeTemplate(printOptions.p_template, ui->plainTextEdit->toPlainText()); + else if (printOptions.type == print_options::STATISTICS) + TemplateLayout::writeTemplate(QString::fromUtf8("statistics") + QDir::separator() + printOptions.p_template, ui->plainTextEdit->toPlainText()); } - if (templateOptions->color_palette_index == CUSTOM) - custom_colors = templateOptions->color_palette; + if (templateOptions.color_palette_index == CUSTOM) + custom_colors = templateOptions.color_palette; } } } diff --git a/desktop-widgets/templateedit.h b/desktop-widgets/templateedit.h index 5ed416a61..5c4c7cd96 100644 --- a/desktop-widgets/templateedit.h +++ b/desktop-widgets/templateedit.h @@ -14,30 +14,24 @@ class TemplateEdit : public QDialog Q_OBJECT public: - explicit TemplateEdit(QWidget *parent, struct print_options *printOptions, struct template_options *templateOptions); + explicit TemplateEdit(QWidget *parent, const print_options &printOptions, template_options &templateOptions); ~TemplateEdit(); private slots: void on_fontsize_valueChanged(int font_size); - void on_linespacing_valueChanged(double line_spacing); - void on_borderwidth_valueChanged(double border_width); - void on_fontSelection_currentIndexChanged(int index); - void on_colorpalette_currentIndexChanged(int index); - void on_buttonBox_clicked(QAbstractButton *button); - void colorSelect(QAbstractButton *button); private: Ui::TemplateEdit *ui; QButtonGroup *btnGroup; bool editingCustomColors; - struct template_options *templateOptions; + const print_options &printOptions; + template_options &templateOptions; struct template_options newTemplateOptions; - struct print_options *printOptions; QString grantlee_template; void saveSettings(); void updatePreview(); diff --git a/desktop-widgets/templatelayout.cpp b/desktop-widgets/templatelayout.cpp index 10907767b..9ed5a35cf 100644 --- a/desktop-widgets/templatelayout.cpp +++ b/desktop-widgets/templatelayout.cpp @@ -9,9 +9,9 @@ QList<QString> grantlee_templates, grantlee_statistics_templates; -int getTotalWork(print_options *printOptions) +int getTotalWork(const print_options &printOptions) { - if (printOptions->print_selected) { + if (printOptions.print_selected) { // return the correct number depending on all/selected dives // but don't return 0 as we might divide by this number return amount_selected && !in_planner() ? amount_selected : 1; @@ -94,10 +94,9 @@ void copy_bundled_templates(QString src, QString dst, QStringList *templateBacku } } -TemplateLayout::TemplateLayout(print_options *printOptions, template_options *templateOptions) +TemplateLayout::TemplateLayout(const print_options &printOptions, const template_options &templateOptions) : + printOptions(printOptions), templateOptions(templateOptions) { - this->printOptions = printOptions; - this->templateOptions = templateOptions; } QString TemplateLayout::generate() @@ -117,7 +116,7 @@ QString TemplateLayout::generate() int i; for_each_dive (i, dive) { //TODO check for exporting selected dives only - if (!dive->selected && printOptions->print_selected) + if (!dive->selected && printOptions.print_selected) continue; diveList.append(QVariant::fromValue(DiveObjectHelperGrantlee(dive))); progress++; @@ -125,11 +124,11 @@ QString TemplateLayout::generate() } } - QString templateContents = readTemplate(printOptions->p_template); + QString templateContents = readTemplate(printOptions.p_template); QHash<QString, QVariant> options; - options["print_options"] = QVariant::fromValue(*printOptions); - options["template_options"] = QVariant::fromValue(*templateOptions); + options["print_options"] = QVariant::fromValue(printOptions); + options["template_options"] = QVariant::fromValue(templateOptions); options["dives"] = QVariant::fromValue(diveList); QList<token> tokens = lexer(templateContents); QString buffer; @@ -154,12 +153,12 @@ QString TemplateLayout::generateStatistics() i++; } - QString templateFile = QString("statistics") + QDir::separator() + printOptions->p_template; + QString templateFile = QString("statistics") + QDir::separator() + printOptions.p_template; QString templateContents = readTemplate(templateFile); QHash<QString, QVariant> options; - options["print_options"] = QVariant::fromValue(*printOptions); - options["template_options"] = QVariant::fromValue(*templateOptions); + options["print_options"] = QVariant::fromValue(printOptions); + options["template_options"] = QVariant::fromValue(templateOptions); options["years"] = QVariant::fromValue(years); QList<token> tokens = lexer(templateContents); QString buffer; diff --git a/desktop-widgets/templatelayout.h b/desktop-widgets/templatelayout.h index cf295e5ed..b59679285 100644 --- a/desktop-widgets/templatelayout.h +++ b/desktop-widgets/templatelayout.h @@ -10,7 +10,7 @@ #include "core/subsurface-qt/diveobjecthelper.h" #include "core/subsurface-qt/cylinderobjecthelper.h" // TODO: remove once grantlee supports Q_GADGET objects -int getTotalWork(print_options *printOptions); +int getTotalWork(const print_options &printOptions); void find_all_templates(); void set_bundled_templates_as_read_only(); void copy_bundled_templates(QString src, QString dst, QStringList *templateBackupList); @@ -27,22 +27,20 @@ extern QList<QString> grantlee_templates, grantlee_statistics_templates; class TemplateLayout : public QObject { Q_OBJECT public: - TemplateLayout(print_options *printOptions, template_options *templateOptions); + TemplateLayout(const print_options &printOptions, const template_options &templateOptions); QString generate(); QString generateStatistics(); static QString readTemplate(QString template_name); static void writeTemplate(QString template_name, QString grantlee_template); private: - print_options *printOptions; - template_options *templateOptions; + const print_options &printOptions; + const template_options &templateOptions; QList<token> lexer(QString input); void parser(QList<token> tokenList, int &pos, QTextStream &out, QHash<QString, QVariant> options); QVariant getValue(QString list, QString property, QVariant option); QString translate(QString s, QHash<QString, QVariant> options); - - signals: void progressUpdated(int value); }; |