From 3a6963836682aa0e0e2825db4eaac7ea48a9939b Mon Sep 17 00:00:00 2001 From: Gehad elrobey Date: Fri, 10 Jul 2015 21:30:18 +0200 Subject: Printing: check for different printing modes Add PRINT/PREVIEW print modes, check for printing modes before casting. We must pass a QPaintDevice with type QPixmap for previewing and with type QPrinter for actual printing. Signed-off-by: Gehad elrobey Signed-off-by: Lubomir I. Ivanov --- qt-ui/printdialog.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'qt-ui/printdialog.cpp') diff --git a/qt-ui/printdialog.cpp b/qt-ui/printdialog.cpp index 9ff29e67b..0a2c7898f 100644 --- a/qt-ui/printdialog.cpp +++ b/qt-ui/printdialog.cpp @@ -45,7 +45,7 @@ PrintDialog::PrintDialog(QWidget *parent, Qt::WindowFlags f) : QDialog(parent, f 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); -- 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/printdialog.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 ed09b80c121764aba5e26b798b09f80f7abdd228 Mon Sep 17 00:00:00 2001 From: Gehad elrobey Date: Sun, 12 Jul 2015 06:42:50 +0200 Subject: Printing: save custom color palette to QSettings - save custom colors to QSettings. - load custom colors from QSettings. - set almond color palette as default palette. Signed-off-by: Gehad elrobey Signed-off-by: Lubomir I. Ivanov --- qt-ui/printdialog.cpp | 24 ++++++++++++++++++++++-- qt-ui/printoptions.h | 2 +- 2 files changed, 23 insertions(+), 3 deletions(-) (limited to 'qt-ui/printdialog.cpp') diff --git a/qt-ui/printdialog.cpp b/qt-ui/printdialog.cpp index c999e8f25..31ec354c8 100644 --- a/qt-ui/printdialog.cpp +++ b/qt-ui/printdialog.cpp @@ -12,7 +12,7 @@ #define SETTINGS_GROUP "PrintDialog" -template_options::color_palette_struct almond_colors; +template_options::color_palette_struct almond_colors, custom_colors; PrintDialog::PrintDialog(QWidget *parent, Qt::WindowFlags f) : QDialog(parent, f) { @@ -36,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(); @@ -48,9 +49,21 @@ 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()); } - templateOptions.color_palette = almond_colors; + 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); @@ -116,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 92064d223..3a55c6994 100644 --- a/qt-ui/printoptions.h +++ b/qt-ui/printoptions.h @@ -49,7 +49,7 @@ struct template_options { } }; -extern template_options::color_palette_struct almond_colors; +extern template_options::color_palette_struct almond_colors, custom_colors; // should be based on a custom QPrintDialog class class PrintOptions : public QWidget { -- cgit v1.2.3-70-g09d2