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 <gehadelrobey@gmail.com>
Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
This commit is contained in:
Gehad elrobey 2015-07-12 06:42:50 +02:00 committed by Lubomir I. Ivanov
parent e1dda8df63
commit ed09b80c12
2 changed files with 23 additions and 3 deletions

View file

@ -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)

View file

@ -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 {