summaryrefslogtreecommitdiffstats
path: root/qt-ui
diff options
context:
space:
mode:
authorGravatar Dirk Hohndel <dirk@hohndel.org>2015-07-05 12:01:43 -0700
committerGravatar Dirk Hohndel <dirk@hohndel.org>2015-07-05 12:01:43 -0700
commit9c6a3a7ff387578ddede2e69d8b994a11cf8eaee (patch)
tree72a08592a24d8d3d1f4fc7d7713da8029bc80c3f /qt-ui
parent35dc81410518e6d39ba8b3f99348884778bedc5b (diff)
parentcc53dc7acf801f022612678f697e6d76c2443153 (diff)
downloadsubsurface-9c6a3a7ff387578ddede2e69d8b994a11cf8eaee.tar.gz
Merge branch 'custom-print' of github.com:neolit123/subsurface
Diffstat (limited to 'qt-ui')
-rw-r--r--qt-ui/printdialog.cpp45
-rw-r--r--qt-ui/printdialog.h2
-rw-r--r--qt-ui/printoptions.cpp25
-rw-r--r--qt-ui/printoptions.h16
-rw-r--r--qt-ui/printoptions.ui5
-rw-r--r--qt-ui/templateedit.cpp61
-rw-r--r--qt-ui/templateedit.h36
-rw-r--r--qt-ui/templateedit.ui262
8 files changed, 441 insertions, 11 deletions
diff --git a/qt-ui/printdialog.cpp b/qt-ui/printdialog.cpp
index 6f30f89f5..9ff29e67b 100644
--- a/qt-ui/printdialog.cpp
+++ b/qt-ui/printdialog.cpp
@@ -8,6 +8,7 @@
#include <QPrintDialog>
#include <QShortcut>
#include <QSettings>
+#include <QMessageBox>
#define SETTINGS_GROUP "PrintDialog"
@@ -22,6 +23,10 @@ PrintDialog::PrintDialog(QWidget *parent, Qt::WindowFlags f) : QDialog(parent, f
printOptions.landscape = false;
printOptions.p_template = print_options::ONE_DIVE;
printOptions.type = print_options::DIVELIST;
+ templateOptions.font_index = 0;
+ templateOptions.font_size = 9;
+ templateOptions.color_palette_index = 0;
+ templateOptions.line_spacing = 1;
} else {
s.beginGroup(SETTINGS_GROUP);
printOptions.type = (print_options::print_type)s.value("type").toInt();
@@ -30,13 +35,17 @@ PrintDialog::PrintDialog(QWidget *parent, Qt::WindowFlags f) : QDialog(parent, f
printOptions.landscape = s.value("landscape").toBool();
printOptions.p_template = (print_options::print_template)s.value("template_selected").toInt();
qprinter.setOrientation((QPrinter::Orientation)printOptions.landscape);
+ templateOptions.font_index = s.value("font").toInt();
+ templateOptions.font_size = s.value("font_size").toDouble();
+ templateOptions.color_palette_index = s.value("color_palette").toInt();
+ templateOptions.line_spacing = s.value("line_spacing").toDouble();
}
// create a print options object and pass our options struct
- optionsWidget = new PrintOptions(this, &printOptions);
+ optionsWidget = new PrintOptions(this, &printOptions, &templateOptions);
// create a new printer object
- printer = new Printer(&qprinter, &printOptions);
+ printer = new Printer(&qprinter, &printOptions, &templateOptions);
QVBoxLayout *layout = new QVBoxLayout(this);
setLayout(layout);
@@ -82,21 +91,47 @@ PrintDialog::PrintDialog(QWidget *parent, Qt::WindowFlags f) : QDialog(parent, f
void PrintDialog::onFinished()
{
- // save the settings
QSettings s;
s.beginGroup(SETTINGS_GROUP);
+
+ // save print paper settings
s.setValue("type", printOptions.type);
s.setValue("print_selected", printOptions.print_selected);
s.setValue("color_selected", printOptions.color_selected);
s.setValue("template_selected", printOptions.p_template);
+
+ // save template settings
+ s.setValue("font", templateOptions.font_index);
+ s.setValue("font_size", templateOptions.font_size);
+ s.setValue("color_palette", templateOptions.color_palette_index);
+ s.setValue("line_spacing", templateOptions.line_spacing);
}
void PrintDialog::previewClicked(void)
{
+ if (printOptions.type == print_options::TABLE || printOptions.type == print_options::STATISTICS) {
+ QMessageBox msgBox;
+ msgBox.setText("This feature is not implemented yet");
+ msgBox.exec();
+ return;
+ }
+
+ QPrintPreviewDialog previewDialog(&qprinter, this, Qt::Window
+ | Qt::CustomizeWindowHint | Qt::WindowCloseButtonHint
+ | Qt::WindowTitleHint);
+ connect(&previewDialog, SIGNAL(paintRequested(QPrinter *)), this, SLOT(onPaintRequested(QPrinter *)));
+ previewDialog.exec();
}
void PrintDialog::printClicked(void)
{
+ if (printOptions.type == print_options::TABLE || printOptions.type == print_options::STATISTICS) {
+ QMessageBox msgBox;
+ msgBox.setText("This feature is not implemented yet");
+ msgBox.exec();
+ return;
+ }
+
QPrintDialog printDialog(&qprinter, this);
if (printDialog.exec() == QDialog::Accepted) {
switch (printOptions.type) {
@@ -115,5 +150,9 @@ void PrintDialog::printClicked(void)
void PrintDialog::onPaintRequested(QPrinter *printerPtr)
{
+ connect(printer, SIGNAL(progessUpdated(int)), progressBar, SLOT(setValue(int)));
+ printer->print();
+ progressBar->setValue(0);
+ disconnect(printer, SIGNAL(progessUpdated(int)), progressBar, SLOT(setValue(int)));
}
#endif
diff --git a/qt-ui/printdialog.h b/qt-ui/printdialog.h
index a34037442..a00c4c5d9 100644
--- a/qt-ui/printdialog.h
+++ b/qt-ui/printdialog.h
@@ -6,6 +6,7 @@
#include <QPrinter>
#include "printoptions.h"
#include "printer.h"
+#include "templateedit.h"
class QProgressBar;
class PrintOptions;
@@ -24,6 +25,7 @@ private:
Printer *printer;
QPrinter qprinter;
struct print_options printOptions;
+ struct template_options templateOptions;
private
slots:
diff --git a/qt-ui/printoptions.cpp b/qt-ui/printoptions.cpp
index e2684b6ed..0e6a0b320 100644
--- a/qt-ui/printoptions.cpp
+++ b/qt-ui/printoptions.cpp
@@ -1,20 +1,22 @@
#include "printoptions.h"
+#include "templateedit.h"
#include <QDebug>
-PrintOptions::PrintOptions(QWidget *parent, struct print_options *printOpt)
+PrintOptions::PrintOptions(QWidget *parent, struct print_options *printOpt, struct template_options *templateOpt)
{
hasSetupSlots = false;
ui.setupUi(this);
if (parent)
setParent(parent);
- if (!printOpt)
+ if (!printOpt || !templateOpt)
return;
- setup(printOpt);
+ templateOptions = templateOpt;
+ printOptions = printOpt;
+ setup();
}
-void PrintOptions::setup(struct print_options *printOpt)
+void PrintOptions::setup()
{
- printOptions = printOpt;
// print type radio buttons
switch (printOptions->type) {
case print_options::DIVELIST:
@@ -34,6 +36,9 @@ void PrintOptions::setup(struct print_options *printOpt)
case print_options::TWO_DIVE:
ui.printTemplate->setCurrentIndex(1);
break;
+ case print_options::CUSTOM:
+ ui.printTemplate->setCurrentIndex(2);
+ break;
}
// general print option checkboxes
@@ -95,5 +100,15 @@ void PrintOptions::on_printTemplate_currentIndexChanged(int index)
case 1:
printOptions->p_template = print_options::TWO_DIVE;
break;
+ case 2:
+ printOptions->p_template = print_options::CUSTOM;
+ break;
}
}
+
+void PrintOptions::on_editButton_clicked()
+{
+ TemplateEdit te(this, printOptions, templateOptions);
+ te.exec();
+ setup();
+}
diff --git a/qt-ui/printoptions.h b/qt-ui/printoptions.h
index 13ef4e310..d96b27a53 100644
--- a/qt-ui/printoptions.h
+++ b/qt-ui/printoptions.h
@@ -13,24 +13,33 @@ struct print_options {
} type;
enum print_template {
ONE_DIVE,
- TWO_DIVE
+ TWO_DIVE,
+ CUSTOM
} p_template;
bool print_selected;
bool color_selected;
bool landscape;
};
+struct template_options {
+ int font_index;
+ int color_palette_index;
+ double font_size;
+ double line_spacing;
+};
+
// should be based on a custom QPrintDialog class
class PrintOptions : public QWidget {
Q_OBJECT
public:
- explicit PrintOptions(QWidget *parent = 0, struct print_options *printOpt = 0);
- void setup(struct print_options *printOpt);
+ explicit PrintOptions(QWidget *parent, struct print_options *printOpt, struct template_options *templateOpt);
+ void setup();
private:
Ui::PrintOptions ui;
struct print_options *printOptions;
+ struct template_options *templateOptions;
bool hasSetupSlots;
private
@@ -41,6 +50,7 @@ slots:
void on_radioTablePrint_clicked(bool check);
void on_radioDiveListPrint_clicked(bool check);
void on_printTemplate_currentIndexChanged(int index);
+ void on_editButton_clicked();
};
#endif // PRINTOPTIONS_H
diff --git a/qt-ui/printoptions.ui b/qt-ui/printoptions.ui
index 632b9cdaf..7e66d4cb0 100644
--- a/qt-ui/printoptions.ui
+++ b/qt-ui/printoptions.ui
@@ -140,6 +140,11 @@
<string>Two dives per page</string>
</property>
</item>
+ <item>
+ <property name="text">
+ <string>Custom template</string>
+ </property>
+ </item>
</widget>
</item>
<item>
diff --git a/qt-ui/templateedit.cpp b/qt-ui/templateedit.cpp
new file mode 100644
index 000000000..82a71ea32
--- /dev/null
+++ b/qt-ui/templateedit.cpp
@@ -0,0 +1,61 @@
+#include "templateedit.h"
+#include "printoptions.h"
+#include "ui_templateedit.h"
+
+TemplateEdit::TemplateEdit(QWidget *parent, struct print_options *printOptions, struct template_options *templateOptions) :
+ QDialog(parent),
+ ui(new Ui::TemplateEdit)
+{
+ ui->setupUi(this);
+ this->templateOptions = templateOptions;
+ this->printOptions = printOptions;
+
+ // restore the settings and init the UI
+ ui->fontSelection->setCurrentIndex(templateOptions->font_index);
+ ui->fontsize->setValue(templateOptions->font_size);
+ ui->colorpalette->setCurrentIndex(templateOptions->color_palette_index);
+ ui->linespacing->setValue(templateOptions->line_spacing);
+
+ if (printOptions->p_template == print_options::ONE_DIVE) {
+ grantlee_template = TemplateLayout::readTemplate("one_dive.html");
+ } else if (printOptions->p_template == print_options::TWO_DIVE) {
+ grantlee_template = TemplateLayout::readTemplate("two_dives.html");
+ } else if (printOptions->p_template == print_options::CUSTOM) {
+ grantlee_template = TemplateLayout::readTemplate("custom.html");
+ }
+
+ ui->plainTextEdit->setPlainText(grantlee_template);
+}
+
+TemplateEdit::~TemplateEdit()
+{
+ delete ui;
+}
+
+void TemplateEdit::on_fontsize_valueChanged(int font_size)
+{
+ templateOptions->font_size = font_size;
+}
+
+void TemplateEdit::on_linespacing_valueChanged(double line_spacing)
+{
+ templateOptions->line_spacing = line_spacing;
+}
+
+void TemplateEdit::on_fontSelection_currentIndexChanged(int index)
+{
+ templateOptions->font_index = index;
+}
+
+void TemplateEdit::on_colorpalette_currentIndexChanged(int index)
+{
+ templateOptions->color_palette_index = index;
+}
+
+void TemplateEdit::on_TemplateEdit_finished(int result)
+{
+ if (grantlee_template.compare(ui->plainTextEdit->toPlainText())) {
+ printOptions->p_template = print_options::CUSTOM;
+ TemplateLayout::writeTemplate("custom.html", ui->plainTextEdit->toPlainText());
+ }
+}
diff --git a/qt-ui/templateedit.h b/qt-ui/templateedit.h
new file mode 100644
index 000000000..296005652
--- /dev/null
+++ b/qt-ui/templateedit.h
@@ -0,0 +1,36 @@
+#ifndef TEMPLATEEDIT_H
+#define TEMPLATEEDIT_H
+
+#include <QDialog>
+#include "templatelayout.h"
+
+namespace Ui {
+class TemplateEdit;
+}
+
+class TemplateEdit : public QDialog
+{
+ Q_OBJECT
+
+public:
+ explicit TemplateEdit(QWidget *parent, struct print_options *printOptions, struct template_options *templateOptions);
+ ~TemplateEdit();
+private slots:
+ void on_fontsize_valueChanged(int font_size);
+
+ void on_linespacing_valueChanged(double line_spacing);
+
+ void on_fontSelection_currentIndexChanged(int index);
+
+ void on_colorpalette_currentIndexChanged(int index);
+
+ void on_TemplateEdit_finished(int result);
+
+private:
+ Ui::TemplateEdit *ui;
+ struct template_options *templateOptions;
+ struct print_options *printOptions;
+ QString grantlee_template;
+};
+
+#endif // TEMPLATEEDIT_H
diff --git a/qt-ui/templateedit.ui b/qt-ui/templateedit.ui
new file mode 100644
index 000000000..26fe15926
--- /dev/null
+++ b/qt-ui/templateedit.ui
@@ -0,0 +1,262 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>TemplateEdit</class>
+ <widget class="QDialog" name="TemplateEdit">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>774</width>
+ <height>433</height>
+ </rect>
+ </property>
+ <property name="windowTitle">
+ <string>Edit Template</string>
+ </property>
+ <widget class="QDialogButtonBox" name="buttonBox">
+ <property name="geometry">
+ <rect>
+ <x>400</x>
+ <y>380</y>
+ <width>341</width>
+ <height>32</height>
+ </rect>
+ </property>
+ <property name="orientation">
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <property name="standardButtons">
+ <set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
+ </property>
+ </widget>
+ <widget class="QTabWidget" name="tabWidget">
+ <property name="geometry">
+ <rect>
+ <x>300</x>
+ <y>30</y>
+ <width>441</width>
+ <height>331</height>
+ </rect>
+ </property>
+ <property name="currentIndex">
+ <number>0</number>
+ </property>
+ <widget class="QWidget" name="style">
+ <attribute name="title">
+ <string>Style</string>
+ </attribute>
+ <widget class="QWidget" name="verticalLayoutWidget">
+ <property name="geometry">
+ <rect>
+ <x>10</x>
+ <y>20</y>
+ <width>401</width>
+ <height>171</height>
+ </rect>
+ </property>
+ <layout class="QVBoxLayout" name="verticalLayout">
+ <item>
+ <layout class="QHBoxLayout" name="horizontalLayout_4">
+ <item>
+ <widget class="QLabel" name="fontselection_label">
+ <property name="text">
+ <string>Font</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QComboBox" name="fontSelection">
+ <item>
+ <property name="text">
+ <string>Arial</string>
+ </property>
+ </item>
+ <item>
+ <property name="text">
+ <string>Impact</string>
+ </property>
+ </item>
+ <item>
+ <property name="text">
+ <string>Georgia</string>
+ </property>
+ </item>
+ <item>
+ <property name="text">
+ <string>Courier</string>
+ </property>
+ </item>
+ <item>
+ <property name="text">
+ <string>Verdana</string>
+ </property>
+ </item>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ <item>
+ <layout class="QHBoxLayout" name="horizontalLayout_3">
+ <item>
+ <widget class="QLabel" name="fontsize_label">
+ <property name="text">
+ <string>Font size</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QSpinBox" name="fontsize">
+ <property name="minimum">
+ <number>9</number>
+ </property>
+ <property name="maximum">
+ <number>18</number>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ <item>
+ <layout class="QHBoxLayout" name="horizontalLayout">
+ <item>
+ <widget class="QLabel" name="colorpalette_label">
+ <property name="text">
+ <string>Color pallet</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QComboBox" name="colorpalette">
+ <item>
+ <property name="text">
+ <string>Almond</string>
+ </property>
+ </item>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ <item>
+ <layout class="QHBoxLayout" name="horizontalLayout_2">
+ <item>
+ <widget class="QLabel" name="linespacing_label">
+ <property name="text">
+ <string>Line spacing</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QDoubleSpinBox" name="linespacing">
+ <property name="minimum">
+ <double>1.000000000000000</double>
+ </property>
+ <property name="maximum">
+ <double>3.000000000000000</double>
+ </property>
+ <property name="singleStep">
+ <double>0.250000000000000</double>
+ </property>
+ <property name="value">
+ <double>1.250000000000000</double>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ </layout>
+ </widget>
+ </widget>
+ <widget class="QWidget" name="template_2">
+ <attribute name="title">
+ <string>Template</string>
+ </attribute>
+ <widget class="QPlainTextEdit" name="plainTextEdit">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>441</width>
+ <height>301</height>
+ </rect>
+ </property>
+ <property name="horizontalScrollBarPolicy">
+ <enum>Qt::ScrollBarAsNeeded</enum>
+ </property>
+ <property name="lineWrapMode">
+ <enum>QPlainTextEdit::NoWrap</enum>
+ </property>
+ </widget>
+ </widget>
+ </widget>
+ <widget class="QWebView" name="webView">
+ <property name="geometry">
+ <rect>
+ <x>20</x>
+ <y>60</y>
+ <width>251</width>
+ <height>311</height>
+ </rect>
+ </property>
+ <property name="url">
+ <url>
+ <string>about:blank</string>
+ </url>
+ </property>
+ </widget>
+ <widget class="QLabel" name="label_5">
+ <property name="geometry">
+ <rect>
+ <x>30</x>
+ <y>30</y>
+ <width>59</width>
+ <height>14</height>
+ </rect>
+ </property>
+ <property name="text">
+ <string>Preview</string>
+ </property>
+ </widget>
+ </widget>
+ <customwidgets>
+ <customwidget>
+ <class>QWebView</class>
+ <extends>QWidget</extends>
+ <header>QtWebKitWidgets/QWebView</header>
+ </customwidget>
+ </customwidgets>
+ <resources/>
+ <connections>
+ <connection>
+ <sender>buttonBox</sender>
+ <signal>accepted()</signal>
+ <receiver>TemplateEdit</receiver>
+ <slot>accept()</slot>
+ <hints>
+ <hint type="sourcelabel">
+ <x>248</x>
+ <y>254</y>
+ </hint>
+ <hint type="destinationlabel">
+ <x>157</x>
+ <y>274</y>
+ </hint>
+ </hints>
+ </connection>
+ <connection>
+ <sender>buttonBox</sender>
+ <signal>rejected()</signal>
+ <receiver>TemplateEdit</receiver>
+ <slot>reject()</slot>
+ <hints>
+ <hint type="sourcelabel">
+ <x>316</x>
+ <y>260</y>
+ </hint>
+ <hint type="destinationlabel">
+ <x>286</x>
+ <y>274</y>
+ </hint>
+ </hints>
+ </connection>
+ </connections>
+</ui>