From c90d5b891df873a6a69f5da618d42af998b4620f Mon Sep 17 00:00:00 2001 From: Gehad elrobey Date: Tue, 7 Jul 2015 03:14:43 +0200 Subject: Printing: show confirmation message before overwriting the template Before overwriting the new template show confirmation message. Signed-off-by: Gehad elrobey Signed-off-by: Lubomir I. Ivanov --- qt-ui/templateedit.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'qt-ui/templateedit.cpp') diff --git a/qt-ui/templateedit.cpp b/qt-ui/templateedit.cpp index 82a71ea32..0a8c4ca92 100644 --- a/qt-ui/templateedit.cpp +++ b/qt-ui/templateedit.cpp @@ -2,6 +2,8 @@ #include "printoptions.h" #include "ui_templateedit.h" +#include + TemplateEdit::TemplateEdit(QWidget *parent, struct print_options *printOptions, struct template_options *templateOptions) : QDialog(parent), ui(new Ui::TemplateEdit) @@ -55,7 +57,13 @@ void TemplateEdit::on_colorpalette_currentIndexChanged(int 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()); + QMessageBox msgBox; + msgBox.setText("Do you want to save your changes?"); + msgBox.setStandardButtons(QMessageBox::Save | QMessageBox::Discard); + msgBox.setDefaultButton(QMessageBox::Discard); + if (msgBox.exec() == QMessageBox::Save) { + printOptions->p_template = print_options::CUSTOM; + TemplateLayout::writeTemplate("custom.html", ui->plainTextEdit->toPlainText()); + } } } -- cgit v1.2.3-70-g09d2 From d4382c7c4b802b030bab5e64de4b1641f603d543 Mon Sep 17 00:00:00 2001 From: Gehad elrobey Date: Fri, 10 Jul 2015 21:45:27 +0200 Subject: Printing: add preview to TemplateEdit dialog Show QPixmap in QLabel, Use Printer class to render the Preview on the QPixmap. Signed-off-by: Gehad elrobey Signed-off-by: Lubomir I. Ivanov --- printer.cpp | 15 +++++++++++++++ printer.h | 1 + qt-ui/templateedit.cpp | 9 +++++++++ qt-ui/templateedit.ui | 35 +++++++++++++---------------------- 4 files changed, 38 insertions(+), 22 deletions(-) (limited to 'qt-ui/templateedit.cpp') diff --git a/printer.cpp b/printer.cpp index c5867450f..7cef1104e 100644 --- a/printer.cpp +++ b/printer.cpp @@ -141,3 +141,18 @@ void Printer::print() 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); + } +} diff --git a/printer.h b/printer.h index dee9ba980..b4cf3ac2a 100644 --- a/printer.h +++ b/printer.h @@ -38,6 +38,7 @@ public: Printer(QPaintDevice *paintDevice, print_options *printOptions, template_options *templateOptions, PrintMode printMode); ~Printer(); void print(); + void previewOnePage(); signals: void progessUpdated(int value); diff --git a/qt-ui/templateedit.cpp b/qt-ui/templateedit.cpp index 0a8c4ca92..19f5db609 100644 --- a/qt-ui/templateedit.cpp +++ b/qt-ui/templateedit.cpp @@ -1,5 +1,6 @@ #include "templateedit.h" #include "printoptions.h" +#include "printer.h" #include "ui_templateedit.h" #include @@ -27,6 +28,14 @@ TemplateEdit::TemplateEdit(QWidget *parent, struct print_options *printOptions, } ui->plainTextEdit->setPlainText(grantlee_template); + + 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, templateOptions, Printer::PREVIEW); + printer.previewOnePage(); + ui->label->setPixmap(map.scaled(width, height, Qt::IgnoreAspectRatio)); } TemplateEdit::~TemplateEdit() diff --git a/qt-ui/templateedit.ui b/qt-ui/templateedit.ui index 26fe15926..fa27eb324 100644 --- a/qt-ui/templateedit.ui +++ b/qt-ui/templateedit.ui @@ -188,21 +188,6 @@ - - - - 20 - 60 - 251 - 311 - - - - - about:blank - - - @@ -216,14 +201,20 @@ Preview + + + + 50 + 70 + 211 + 291 + + + + + + - - - QWebView - QWidget -
QtWebKitWidgets/QWebView
-
-
-- cgit v1.2.3-70-g09d2 From 7ca311ae859199f1e07279bf78e1c36efc97768c Mon Sep 17 00:00:00 2001 From: Gehad elrobey Date: Sat, 11 Jul 2015 01:06:43 +0200 Subject: Printing: save only if data is changed in template_options Check if data is changed before saving the new settings. Signed-off-by: Gehad elrobey Signed-off-by: Lubomir I. Ivanov --- qt-ui/printoptions.h | 6 ++++++ qt-ui/templateedit.cpp | 12 +++++++----- qt-ui/templateedit.h | 1 + 3 files changed, 14 insertions(+), 5 deletions(-) (limited to 'qt-ui/templateedit.cpp') diff --git a/qt-ui/printoptions.h b/qt-ui/printoptions.h index d96b27a53..3a5c2b179 100644 --- a/qt-ui/printoptions.h +++ b/qt-ui/printoptions.h @@ -26,6 +26,12 @@ struct template_options { int color_palette_index; double font_size; double line_spacing; + 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; + } }; // should be based on a custom QPrintDialog class diff --git a/qt-ui/templateedit.cpp b/qt-ui/templateedit.cpp index 19f5db609..0354131ef 100644 --- a/qt-ui/templateedit.cpp +++ b/qt-ui/templateedit.cpp @@ -11,6 +11,7 @@ TemplateEdit::TemplateEdit(QWidget *parent, struct print_options *printOptions, { ui->setupUi(this); this->templateOptions = templateOptions; + newTemplateOptions = *templateOptions; this->printOptions = printOptions; // restore the settings and init the UI @@ -45,32 +46,33 @@ TemplateEdit::~TemplateEdit() void TemplateEdit::on_fontsize_valueChanged(int font_size) { - templateOptions->font_size = font_size; + newTemplateOptions.font_size = font_size; } void TemplateEdit::on_linespacing_valueChanged(double line_spacing) { - templateOptions->line_spacing = line_spacing; + newTemplateOptions.line_spacing = line_spacing; } void TemplateEdit::on_fontSelection_currentIndexChanged(int index) { - templateOptions->font_index = index; + newTemplateOptions.font_index = index; } void TemplateEdit::on_colorpalette_currentIndexChanged(int index) { - templateOptions->color_palette_index = index; + newTemplateOptions.color_palette_index = index; } void TemplateEdit::on_TemplateEdit_finished(int result) { - if (grantlee_template.compare(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::Discard); msgBox.setDefaultButton(QMessageBox::Discard); if (msgBox.exec() == QMessageBox::Save) { + memcpy(templateOptions, &newTemplateOptions, sizeof(struct template_options)); 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 index 296005652..325d7eef3 100644 --- a/qt-ui/templateedit.h +++ b/qt-ui/templateedit.h @@ -29,6 +29,7 @@ private slots: private: Ui::TemplateEdit *ui; struct template_options *templateOptions; + struct template_options newTemplateOptions; struct print_options *printOptions; QString grantlee_template; }; -- cgit v1.2.3-70-g09d2 From f1615e725c7a5562b5fcaac2cd0701dae61b89ca Mon Sep 17 00:00:00 2001 From: Gehad elrobey Date: Sat, 11 Jul 2015 01:37:27 +0200 Subject: Printing: add apply button to TemplateEdit class Add apply button to the dialog, Update the preview after applying the new settings. Signed-off-by: Gehad elrobey Signed-off-by: Lubomir I. Ivanov --- qt-ui/templateedit.cpp | 17 ++++++++++++++++- qt-ui/templateedit.h | 3 ++- qt-ui/templateedit.ui | 2 +- 3 files changed, 19 insertions(+), 3 deletions(-) (limited to 'qt-ui/templateedit.cpp') diff --git a/qt-ui/templateedit.cpp b/qt-ui/templateedit.cpp index 0354131ef..2d09cb947 100644 --- a/qt-ui/templateedit.cpp +++ b/qt-ui/templateedit.cpp @@ -64,7 +64,7 @@ void TemplateEdit::on_colorpalette_currentIndexChanged(int index) newTemplateOptions.color_palette_index = index; } -void TemplateEdit::on_TemplateEdit_finished(int result) +void TemplateEdit::saveSettings() { if ((*templateOptions) != newTemplateOptions || grantlee_template.compare(ui->plainTextEdit->toPlainText())) { QMessageBox msgBox; @@ -78,3 +78,18 @@ void TemplateEdit::on_TemplateEdit_finished(int result) } } } + +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(); + break; + } +} diff --git a/qt-ui/templateedit.h b/qt-ui/templateedit.h index 325d7eef3..9b6d9167f 100644 --- a/qt-ui/templateedit.h +++ b/qt-ui/templateedit.h @@ -24,7 +24,7 @@ private slots: void on_colorpalette_currentIndexChanged(int index); - void on_TemplateEdit_finished(int result); + void on_buttonBox_clicked(QAbstractButton *button); private: Ui::TemplateEdit *ui; @@ -32,6 +32,7 @@ private: struct template_options newTemplateOptions; struct print_options *printOptions; QString grantlee_template; + void saveSettings(); }; #endif // TEMPLATEEDIT_H diff --git a/qt-ui/templateedit.ui b/qt-ui/templateedit.ui index fa27eb324..de007c9b7 100644 --- a/qt-ui/templateedit.ui +++ b/qt-ui/templateedit.ui @@ -26,7 +26,7 @@ Qt::Horizontal - QDialogButtonBox::Cancel|QDialogButtonBox::Ok + QDialogButtonBox::Apply|QDialogButtonBox::Cancel|QDialogButtonBox::Ok -- cgit v1.2.3-70-g09d2 From d705cb34bb5a8d442b54784bb9105404bb304404 Mon Sep 17 00:00:00 2001 From: Gehad elrobey Date: Sat, 11 Jul 2015 12:50:14 +0200 Subject: Printing: update preview on apply settings On update call Printer to render on the QPixmap. Signed-off-by: Gehad elrobey Signed-off-by: Lubomir I. Ivanov --- qt-ui/templateedit.cpp | 15 ++++++++++----- qt-ui/templateedit.h | 2 ++ 2 files changed, 12 insertions(+), 5 deletions(-) (limited to 'qt-ui/templateedit.cpp') diff --git a/qt-ui/templateedit.cpp b/qt-ui/templateedit.cpp index 2d09cb947..bd4763107 100644 --- a/qt-ui/templateedit.cpp +++ b/qt-ui/templateedit.cpp @@ -29,7 +29,16 @@ TemplateEdit::TemplateEdit(QWidget *parent, struct print_options *printOptions, } ui->plainTextEdit->setPlainText(grantlee_template); + updatePreview(); +} + +TemplateEdit::~TemplateEdit() +{ + delete ui; +} +void TemplateEdit::updatePreview() +{ int width = ui->label->width(); int height = ui->label->height(); QPixmap map(width * 2, height * 2); @@ -39,11 +48,6 @@ TemplateEdit::TemplateEdit(QWidget *parent, struct print_options *printOptions, ui->label->setPixmap(map.scaled(width, height, Qt::IgnoreAspectRatio)); } -TemplateEdit::~TemplateEdit() -{ - delete ui; -} - void TemplateEdit::on_fontsize_valueChanged(int font_size) { newTemplateOptions.font_size = font_size; @@ -90,6 +94,7 @@ void TemplateEdit::on_buttonBox_clicked(QAbstractButton *button) break; case QDialogButtonBox::Apply: saveSettings(); + updatePreview(); break; } } diff --git a/qt-ui/templateedit.h b/qt-ui/templateedit.h index 9b6d9167f..21cbc0321 100644 --- a/qt-ui/templateedit.h +++ b/qt-ui/templateedit.h @@ -33,6 +33,8 @@ private: struct print_options *printOptions; QString grantlee_template; void saveSettings(); + void updatePreview(); + }; #endif // TEMPLATEEDIT_H -- cgit v1.2.3-70-g09d2 From 18282aa30e191e1af0dda7261a692c8bb82dc139 Mon Sep 17 00:00:00 2001 From: Gehad elrobey Date: Sun, 12 Jul 2015 01:49:43 +0200 Subject: Printing: update preview on field changes - Trigger re-rendering on the QPixmap if fields changed. - Change template selection to custom if template text changed. Signed-off-by: Gehad elrobey Signed-off-by: Lubomir I. Ivanov --- qt-ui/templateedit.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'qt-ui/templateedit.cpp') diff --git a/qt-ui/templateedit.cpp b/qt-ui/templateedit.cpp index bd4763107..8d216d998 100644 --- a/qt-ui/templateedit.cpp +++ b/qt-ui/templateedit.cpp @@ -43,7 +43,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, templateOptions, Printer::PREVIEW); + Printer printer(&map, printOptions, &newTemplateOptions, Printer::PREVIEW); printer.previewOnePage(); ui->label->setPixmap(map.scaled(width, height, Qt::IgnoreAspectRatio)); } @@ -51,21 +51,25 @@ void TemplateEdit::updatePreview() void TemplateEdit::on_fontsize_valueChanged(int font_size) { newTemplateOptions.font_size = font_size; + updatePreview(); } void TemplateEdit::on_linespacing_valueChanged(double line_spacing) { newTemplateOptions.line_spacing = line_spacing; + updatePreview(); } void TemplateEdit::on_fontSelection_currentIndexChanged(int index) { newTemplateOptions.font_index = index; + updatePreview(); } void TemplateEdit::on_colorpalette_currentIndexChanged(int index) { newTemplateOptions.color_palette_index = index; + updatePreview(); } void TemplateEdit::saveSettings() @@ -77,8 +81,10 @@ void TemplateEdit::saveSettings() msgBox.setDefaultButton(QMessageBox::Discard); if (msgBox.exec() == QMessageBox::Save) { memcpy(templateOptions, &newTemplateOptions, sizeof(struct template_options)); - printOptions->p_template = print_options::CUSTOM; - TemplateLayout::writeTemplate("custom.html", ui->plainTextEdit->toPlainText()); + if (grantlee_template.compare(ui->plainTextEdit->toPlainText())) { + printOptions->p_template = print_options::CUSTOM; + TemplateLayout::writeTemplate("custom.html", ui->plainTextEdit->toPlainText()); + } } } } -- cgit v1.2.3-70-g09d2 From ad531c25fbf4094f2cbfd54018fe74d710b547f1 Mon Sep 17 00:00:00 2001 From: Gehad elrobey Date: Sun, 12 Jul 2015 05:00:03 +0200 Subject: Printing: show colors in edit tab - Add default color struct - Init the color struct with default colors - Show color text in labels - Preview colors Signed-off-by: Gehad elrobey Signed-off-by: Lubomir I. Ivanov --- qt-ui/printdialog.cpp | 11 +++++++++++ qt-ui/printoptions.h | 21 +++++++++++++++++++-- qt-ui/templateedit.cpp | 14 ++++++++++++++ 3 files changed, 44 insertions(+), 2 deletions(-) (limited to 'qt-ui/templateedit.cpp') diff --git a/qt-ui/printdialog.cpp b/qt-ui/printdialog.cpp index 0a2c7898f..c999e8f25 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; + 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); @@ -41,6 +50,8 @@ PrintDialog::PrintDialog(QWidget *parent, Qt::WindowFlags f) : QDialog(parent, f templateOptions.line_spacing = s.value("line_spacing").toDouble(); } + templateOptions.color_palette = almond_colors; + // create a print options object and pass our options struct optionsWidget = new PrintOptions(this, &printOptions, &templateOptions); diff --git a/qt-ui/printoptions.h b/qt-ui/printoptions.h index 3a5c2b179..92064d223 100644 --- a/qt-ui/printoptions.h +++ b/qt-ui/printoptions.h @@ -26,13 +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.line_spacing != line_spacing + || other.color_palette != color_palette; } -}; + }; + +extern template_options::color_palette_struct almond_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 8d216d998..bb545392a 100644 --- a/qt-ui/templateedit.cpp +++ b/qt-ui/templateedit.cpp @@ -39,6 +39,7 @@ TemplateEdit::~TemplateEdit() void TemplateEdit::updatePreview() { + // update Qpixmap preview int width = ui->label->width(); int height = ui->label->height(); QPixmap map(width * 2, height * 2); @@ -46,6 +47,19 @@ void TemplateEdit::updatePreview() 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()); } void TemplateEdit::on_fontsize_valueChanged(int font_size) -- cgit v1.2.3-70-g09d2 From e1dda8df636058734ff8ab79ade210c08339b978 Mon Sep 17 00:00:00 2001 From: Gehad elrobey Date: Sun, 12 Jul 2015 05:54:00 +0200 Subject: Printing: implement edit buttons in color tab Add button group and attached edit buttons to it. Signed-off-by: Gehad elrobey Signed-off-by: Lubomir I. Ivanov --- qt-ui/templateedit.cpp | 39 +++++++++++++++++++++++++++++++++++++++ qt-ui/templateedit.h | 3 +++ 2 files changed, 42 insertions(+) (limited to 'qt-ui/templateedit.cpp') diff --git a/qt-ui/templateedit.cpp b/qt-ui/templateedit.cpp index bb545392a..3d84dd63b 100644 --- a/qt-ui/templateedit.cpp +++ b/qt-ui/templateedit.cpp @@ -4,6 +4,7 @@ #include "ui_templateedit.h" #include +#include TemplateEdit::TemplateEdit(QWidget *parent, struct print_options *printOptions, struct template_options *templateOptions) : QDialog(parent), @@ -28,12 +29,22 @@ 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; } @@ -118,3 +129,31 @@ void TemplateEdit::on_buttonBox_clicked(QAbstractButton *button) break; } } + +void TemplateEdit::colorSelect(QAbstractButton *button) +{ + 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; + } + updatePreview(); +} diff --git a/qt-ui/templateedit.h b/qt-ui/templateedit.h index 21cbc0321..15b717f78 100644 --- a/qt-ui/templateedit.h +++ b/qt-ui/templateedit.h @@ -26,8 +26,11 @@ private slots: 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; -- cgit v1.2.3-70-g09d2 From f8f645398857ca7cfb3c9496259e2ab638065642 Mon Sep 17 00:00:00 2001 From: Gehad elrobey Date: Mon, 13 Jul 2015 11:23:35 +0200 Subject: Printing: add custom color palette We can use custom color palette to edit current color palette. Signed-off-by: Gehad elrobey Signed-off-by: Lubomir I. Ivanov --- qt-ui/templateedit.cpp | 24 ++++++++++++++++++++++++ qt-ui/templateedit.ui | 5 +++++ 2 files changed, 29 insertions(+) (limited to 'qt-ui/templateedit.cpp') diff --git a/qt-ui/templateedit.cpp b/qt-ui/templateedit.cpp index 3d84dd63b..ff1c1b7ea 100644 --- a/qt-ui/templateedit.cpp +++ b/qt-ui/templateedit.cpp @@ -71,6 +71,9 @@ void TemplateEdit::updatePreview() 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) @@ -94,6 +97,14 @@ void TemplateEdit::on_fontSelection_currentIndexChanged(int index) void TemplateEdit::on_colorpalette_currentIndexChanged(int 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(); } @@ -110,6 +121,9 @@ void TemplateEdit::saveSettings() printOptions->p_template = print_options::CUSTOM; TemplateLayout::writeTemplate("custom.html", ui->plainTextEdit->toPlainText()); } + if (templateOptions->color_palette_index == 1) { + custom_colors = templateOptions->color_palette; + } } } } @@ -132,6 +146,15 @@ void TemplateEdit::on_buttonBox_clicked(QAbstractButton *button) 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: @@ -155,5 +178,6 @@ void TemplateEdit::colorSelect(QAbstractButton *button) newTemplateOptions.color_palette.color5 = color; break; } + newTemplateOptions.color_palette_index = 1; updatePreview(); } diff --git a/qt-ui/templateedit.ui b/qt-ui/templateedit.ui index 771fa90f8..4f9c9c2ed 100644 --- a/qt-ui/templateedit.ui +++ b/qt-ui/templateedit.ui @@ -132,6 +132,11 @@ Almond + + + Custom + + -- cgit v1.2.3-70-g09d2 From 7575bb169bd9285250df4ae88f3829dd504fe77f Mon Sep 17 00:00:00 2001 From: Gehad elrobey Date: Thu, 16 Jul 2015 04:52:38 +0200 Subject: Printing: change 'Discard' to 'Cancel' button Cancel button is more relevant to the dialog message. Signed-off-by: Gehad elrobey Signed-off-by: Lubomir I. Ivanov --- qt-ui/templateedit.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'qt-ui/templateedit.cpp') diff --git a/qt-ui/templateedit.cpp b/qt-ui/templateedit.cpp index ff1c1b7ea..de69f8cc6 100644 --- a/qt-ui/templateedit.cpp +++ b/qt-ui/templateedit.cpp @@ -113,8 +113,8 @@ void TemplateEdit::saveSettings() if ((*templateOptions) != newTemplateOptions || grantlee_template.compare(ui->plainTextEdit->toPlainText())) { QMessageBox msgBox; msgBox.setText("Do you want to save your changes?"); - msgBox.setStandardButtons(QMessageBox::Save | QMessageBox::Discard); - msgBox.setDefaultButton(QMessageBox::Discard); + 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())) { -- cgit v1.2.3-70-g09d2 From 1ae1a11c228a245b6befc6cb592d8a1cb4034206 Mon Sep 17 00:00:00 2001 From: Gehad elrobey Date: Sat, 18 Jul 2015 20:27:33 +0200 Subject: Printing: add default case to switch Add default case to fix switch warning. Signed-off-by: Gehad elrobey Signed-off-by: Lubomir I. Ivanov --- qt-ui/templateedit.cpp | 2 ++ 1 file changed, 2 insertions(+) (limited to 'qt-ui/templateedit.cpp') diff --git a/qt-ui/templateedit.cpp b/qt-ui/templateedit.cpp index de69f8cc6..6a6328f64 100644 --- a/qt-ui/templateedit.cpp +++ b/qt-ui/templateedit.cpp @@ -141,6 +141,8 @@ void TemplateEdit::on_buttonBox_clicked(QAbstractButton *button) saveSettings(); updatePreview(); break; + default: + ; } } -- cgit v1.2.3-70-g09d2