summaryrefslogtreecommitdiffstats
path: root/qt-ui
diff options
context:
space:
mode:
authorGravatar Dirk Hohndel <dirk@hohndel.org>2015-07-20 06:14:19 -0700
committerGravatar Dirk Hohndel <dirk@hohndel.org>2015-07-20 06:14:19 -0700
commite3a8ff74934c8f5a11ee962650e889464da55522 (patch)
tree6bd206e1df040c4b504e00f5c71e295b8d17b6bd /qt-ui
parent7baa18db5fe33f5797e4603a4c2efafc6b474bd0 (diff)
parent599920c6cfd87a213634097045e29f592390438b (diff)
downloadsubsurface-e3a8ff74934c8f5a11ee962650e889464da55522.tar.gz
Merge branch 'custom-print' of github.com:neolit123/subsurface
Diffstat (limited to 'qt-ui')
-rw-r--r--qt-ui/printdialog.cpp33
-rw-r--r--qt-ui/printoptions.h25
-rw-r--r--qt-ui/templateedit.cpp140
-rw-r--r--qt-ui/templateedit.h9
-rw-r--r--qt-ui/templateedit.ui261
5 files changed, 433 insertions, 35 deletions
diff --git a/qt-ui/printdialog.cpp b/qt-ui/printdialog.cpp
index 9ff29e67b..31ec354c8 100644
--- a/qt-ui/printdialog.cpp
+++ b/qt-ui/printdialog.cpp
@@ -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)
diff --git a/qt-ui/printoptions.h b/qt-ui/printoptions.h
index d96b27a53..3a55c6994 100644
--- a/qt-ui/printoptions.h
+++ b/qt-ui/printoptions.h
@@ -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 {
diff --git a/qt-ui/templateedit.cpp b/qt-ui/templateedit.cpp
index 82a71ea32..6a6328f64 100644
--- a/qt-ui/templateedit.cpp
+++ b/qt-ui/templateedit.cpp
@@ -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();
}
diff --git a/qt-ui/templateedit.h b/qt-ui/templateedit.h
index 296005652..15b717f78 100644
--- a/qt-ui/templateedit.h
+++ b/qt-ui/templateedit.h
@@ -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
diff --git a/qt-ui/templateedit.ui b/qt-ui/templateedit.ui
index 26fe15926..4f9c9c2ed 100644
--- a/qt-ui/templateedit.ui
+++ b/qt-ui/templateedit.ui
@@ -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>