mirror of
https://github.com/subsurface/subsurface.git
synced 2025-01-19 14:25:27 +00:00
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 <gehadelrobey@gmail.com> Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
This commit is contained in:
parent
dcedc8ebea
commit
ad531c25fb
3 changed files with 44 additions and 2 deletions
|
@ -12,8 +12,17 @@
|
||||||
|
|
||||||
#define SETTINGS_GROUP "PrintDialog"
|
#define SETTINGS_GROUP "PrintDialog"
|
||||||
|
|
||||||
|
template_options::color_palette_struct almond_colors;
|
||||||
|
|
||||||
PrintDialog::PrintDialog(QWidget *parent, Qt::WindowFlags f) : QDialog(parent, f)
|
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.
|
// check if the options were previously stored in the settings; if not use some defaults.
|
||||||
QSettings s;
|
QSettings s;
|
||||||
bool stored = s.childGroups().contains(SETTINGS_GROUP);
|
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.line_spacing = s.value("line_spacing").toDouble();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
templateOptions.color_palette = almond_colors;
|
||||||
|
|
||||||
// create a print options object and pass our options struct
|
// create a print options object and pass our options struct
|
||||||
optionsWidget = new PrintOptions(this, &printOptions, &templateOptions);
|
optionsWidget = new PrintOptions(this, &printOptions, &templateOptions);
|
||||||
|
|
||||||
|
|
|
@ -26,13 +26,30 @@ struct template_options {
|
||||||
int color_palette_index;
|
int color_palette_index;
|
||||||
double font_size;
|
double font_size;
|
||||||
double line_spacing;
|
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 {
|
bool operator!=(const template_options &other) const {
|
||||||
return other.font_index != font_index
|
return other.font_index != font_index
|
||||||
|| other.color_palette_index != color_palette_index
|
|| other.color_palette_index != color_palette_index
|
||||||
|| other.font_size != font_size
|
|| 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
|
// should be based on a custom QPrintDialog class
|
||||||
class PrintOptions : public QWidget {
|
class PrintOptions : public QWidget {
|
||||||
|
|
|
@ -39,6 +39,7 @@ TemplateEdit::~TemplateEdit()
|
||||||
|
|
||||||
void TemplateEdit::updatePreview()
|
void TemplateEdit::updatePreview()
|
||||||
{
|
{
|
||||||
|
// update Qpixmap preview
|
||||||
int width = ui->label->width();
|
int width = ui->label->width();
|
||||||
int height = ui->label->height();
|
int height = ui->label->height();
|
||||||
QPixmap map(width * 2, height * 2);
|
QPixmap map(width * 2, height * 2);
|
||||||
|
@ -46,6 +47,19 @@ void TemplateEdit::updatePreview()
|
||||||
Printer printer(&map, printOptions, &newTemplateOptions, Printer::PREVIEW);
|
Printer printer(&map, printOptions, &newTemplateOptions, Printer::PREVIEW);
|
||||||
printer.previewOnePage();
|
printer.previewOnePage();
|
||||||
ui->label->setPixmap(map.scaled(width, height, Qt::IgnoreAspectRatio));
|
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)
|
void TemplateEdit::on_fontsize_valueChanged(int font_size)
|
||||||
|
|
Loading…
Add table
Reference in a new issue