Merge branch 'custom-print' of github.com:neolit123/subsurface

This commit is contained in:
Dirk Hohndel 2015-08-15 05:22:07 -07:00
commit 2455a5dec7
16 changed files with 720 additions and 201 deletions

View file

@ -17,21 +17,24 @@ template_options::color_palette_struct ssrf_colors, almond_colors, blueshades_co
PrintDialog::PrintDialog(QWidget *parent, Qt::WindowFlags f) : QDialog(parent, f)
{
// initialize const colors
ssrf_colors.color1 = QColor::fromRgb(0xef, 0xf7, 0xff);
ssrf_colors.color1 = QColor::fromRgb(0xff, 0xff, 0xff);
ssrf_colors.color2 = QColor::fromRgb(0xa6, 0xbc, 0xd7);
ssrf_colors.color3 = QColor::fromRgb(0x34, 0x65, 0xa4);
ssrf_colors.color4 = QColor::fromRgb(0x20, 0x4a, 0x87);
ssrf_colors.color5 = QColor::fromRgb(0x17, 0x37, 0x64);
almond_colors.color1 = QColor::fromRgb(243, 234, 207);
ssrf_colors.color3 = QColor::fromRgb(0xef, 0xf7, 0xff);
ssrf_colors.color4 = QColor::fromRgb(0x34, 0x65, 0xa4);
ssrf_colors.color5 = QColor::fromRgb(0x20, 0x4a, 0x87);
ssrf_colors.color6 = QColor::fromRgb(0x17, 0x37, 0x64);
almond_colors.color1 = QColor::fromRgb(255, 255, 255);
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);
blueshades_colors.color1 = QColor::fromRgb(182, 192, 206);
almond_colors.color3 = QColor::fromRgb(243, 234, 207);
almond_colors.color4 = QColor::fromRgb(136, 160, 150);
almond_colors.color5 = QColor::fromRgb(187, 171, 139);
almond_colors.color6 = QColor::fromRgb(0, 0, 0);
blueshades_colors.color1 = QColor::fromRgb(255, 255, 255);
blueshades_colors.color2 = QColor::fromRgb(142, 152, 166);
blueshades_colors.color3 = QColor::fromRgb(31, 49, 75);
blueshades_colors.color4 = QColor::fromRgb(21, 45, 84);
blueshades_colors.color5 = QColor::fromRgb(5, 25, 56);
blueshades_colors.color3 = QColor::fromRgb(182, 192, 206);
blueshades_colors.color4 = QColor::fromRgb(31, 49, 75);
blueshades_colors.color5 = QColor::fromRgb(21, 45, 84);
blueshades_colors.color6 = QColor::fromRgb(0, 0, 0);
// check if the options were previously stored in the settings; if not use some defaults.
QSettings s;
@ -164,13 +167,6 @@ void PrintDialog::onFinished()
void PrintDialog::previewClicked(void)
{
if (printOptions.type == print_options::STATISTICS) {
QMessageBox msgBox;
msgBox.setText("This feature is not implemented yet");
msgBox.exec();
return;
}
QPrintPreviewDialog previewDialog(&qprinter, this, Qt::Window
| Qt::CustomizeWindowHint | Qt::WindowCloseButtonHint
| Qt::WindowTitleHint);
@ -180,13 +176,6 @@ void PrintDialog::previewClicked(void)
void PrintDialog::printClicked(void)
{
if (printOptions.type == print_options::STATISTICS) {
QMessageBox msgBox;
msgBox.setText("This feature is not implemented yet");
msgBox.exec();
return;
}
QPrintDialog printDialog(&qprinter, this);
if (printDialog.exec() == QDialog::Accepted) {
switch (printOptions.type) {
@ -195,6 +184,7 @@ void PrintDialog::printClicked(void)
printer->print();
break;
case print_options::STATISTICS:
printer->print_statistics();
break;
}
close();
@ -204,7 +194,14 @@ void PrintDialog::printClicked(void)
void PrintDialog::onPaintRequested(QPrinter *printerPtr)
{
connect(printer, SIGNAL(progessUpdated(int)), progressBar, SLOT(setValue(int)));
printer->print();
switch (printOptions.type) {
case print_options::DIVELIST:
printer->print();
break;
case print_options::STATISTICS:
printer->print_statistics();
break;
}
progressBar->setValue(0);
disconnect(printer, SIGNAL(progessUpdated(int)), progressBar, SLOT(setValue(int)));
}

View file

@ -64,17 +64,39 @@ void PrintOptions::setup()
}
// print type radio buttons
void PrintOptions::on_radioDiveListPrint_clicked(bool check)
void PrintOptions::on_radioDiveListPrint_toggled(bool check)
{
if (check) {
printOptions->type = print_options::DIVELIST;
// print options
ui.printInColor->setEnabled(true);
ui.printSelected->setEnabled(true);
// print template
ui.deleteButton->setEnabled(true);
ui.editButton->setEnabled(true);
ui.exportButton->setEnabled(true);
ui.importButton->setEnabled(true);
ui.printTemplate->setEnabled(true);
}
}
void PrintOptions::on_radioStatisticsPrint_clicked(bool check)
void PrintOptions::on_radioStatisticsPrint_toggled(bool check)
{
if (check) {
printOptions->type = print_options::STATISTICS;
// print options
ui.printInColor->setEnabled(false);
ui.printSelected->setEnabled(false);
// print template
ui.deleteButton->setEnabled(false);
ui.editButton->setEnabled(false);
ui.exportButton->setEnabled(false);
ui.importButton->setEnabled(false);
ui.printTemplate->setEnabled(false);
}
}

View file

@ -19,6 +19,7 @@ struct print_options {
struct template_options {
int font_index;
int color_palette_index;
int border_width;
double font_size;
double line_spacing;
struct color_palette_struct {
@ -27,12 +28,14 @@ struct template_options {
QColor color3;
QColor color4;
QColor color5;
QColor color6;
bool operator!=(const color_palette_struct &other) const {
return other.color1 != color1
|| other.color2 != color2
|| other.color3 != color3
|| other.color4 != color4
|| other.color5 != color5;
|| other.color5 != color5
|| other.color6 != color6;
}
} color_palette;
bool operator!=(const template_options &other) const {
@ -72,8 +75,8 @@ private
slots:
void printInColorClicked(bool check);
void printSelectedClicked(bool check);
void on_radioStatisticsPrint_clicked(bool check);
void on_radioDiveListPrint_clicked(bool check);
void on_radioStatisticsPrint_toggled(bool check);
void on_radioDiveListPrint_toggled(bool check);
void on_printTemplate_currentIndexChanged(int index);
void on_editButton_clicked();
void on_importButton_clicked();

View file

@ -627,6 +627,17 @@ void ProfileWidget2::plotDive(struct dive *d, bool force)
eventItems.clear();
struct event *event = currentdc->events;
while (event) {
// if print mode is selected only draw headings, SP change, gas events or bookmark event
if (printMode) {
if (same_string(event->name, "") ||
!(strcmp(event->name, "heading") == 0 ||
(same_string(event->name, "SP change") && event->time.seconds == 0) ||
event_is_gaschange(event) ||
event->type == SAMPLE_EVENT_BOOKMARK)) {
event = event->next;
continue;
}
}
DiveEventItem *item = new DiveEventItem();
item->setHorizontalAxis(timeAxis);
item->setVerticalAxis(profileYAxis);

View file

@ -30,9 +30,11 @@ TemplateEdit::TemplateEdit(QWidget *parent, struct print_options *printOptions,
btnGroup->addButton(ui->editButton3, 3);
btnGroup->addButton(ui->editButton4, 4);
btnGroup->addButton(ui->editButton5, 5);
btnGroup->addButton(ui->editButton6, 6);
connect(btnGroup, SIGNAL(buttonClicked(QAbstractButton*)), this, SLOT(colorSelect(QAbstractButton*)));
ui->plainTextEdit->setPlainText(grantlee_template);
editingCustomColors = false;
updatePreview();
}
@ -59,12 +61,14 @@ void TemplateEdit::updatePreview()
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->colorLable6->setStyleSheet("QLabel { background-color : \"" + newTemplateOptions.color_palette.color6.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());
ui->colorLable6->setText(newTemplateOptions.color_palette.color6.name());
// update critical UI elements
ui->colorpalette->setCurrentIndex(newTemplateOptions.color_palette_index);
@ -102,7 +106,10 @@ void TemplateEdit::on_colorpalette_currentIndexChanged(int index)
newTemplateOptions.color_palette = blueshades_colors;
break;
case CUSTOM: // custom
newTemplateOptions.color_palette = custom_colors;
if (!editingCustomColors)
newTemplateOptions.color_palette = custom_colors;
else
editingCustomColors = false;
break;
}
updatePreview();
@ -121,7 +128,7 @@ void TemplateEdit::saveSettings()
printOptions->p_template = "custom.html";
TemplateLayout::writeTemplate("custom.html", ui->plainTextEdit->toPlainText());
}
if (templateOptions->color_palette_index == 2) {
if (templateOptions->color_palette_index == CUSTOM) {
custom_colors = templateOptions->color_palette;
}
}
@ -148,6 +155,7 @@ void TemplateEdit::on_buttonBox_clicked(QAbstractButton *button)
void TemplateEdit::colorSelect(QAbstractButton *button)
{
editingCustomColors = true;
// reset custom colors palette
switch (newTemplateOptions.color_palette_index) {
case SSRF_COLORS: // subsurface derived default colors
@ -155,11 +163,11 @@ void TemplateEdit::colorSelect(QAbstractButton *button)
break;
case ALMOND: // almond
newTemplateOptions.color_palette = almond_colors;
custom_colors = newTemplateOptions.color_palette;
break;
case BLUESHADES: // blueshades
newTemplateOptions.color_palette = blueshades_colors;
custom_colors = newTemplateOptions.color_palette;
break;
default:
break;
}
@ -168,24 +176,35 @@ void TemplateEdit::colorSelect(QAbstractButton *button)
switch (btnGroup->id(button)) {
case 1:
color = QColorDialog::getColor(newTemplateOptions.color_palette.color1, this);
newTemplateOptions.color_palette.color1 = color;
if (color.isValid()) {
newTemplateOptions.color_palette.color1 = color;
}
break;
case 2:
color = QColorDialog::getColor(newTemplateOptions.color_palette.color2, this);
newTemplateOptions.color_palette.color2 = color;
break;
if (color.isValid()) {
newTemplateOptions.color_palette.color2 = color;
} break;
case 3:
color = QColorDialog::getColor(newTemplateOptions.color_palette.color3, this);
newTemplateOptions.color_palette.color3 = color;
break;
if (color.isValid()) {
newTemplateOptions.color_palette.color3 = color;
} break;
case 4:
color = QColorDialog::getColor(newTemplateOptions.color_palette.color4, this);
newTemplateOptions.color_palette.color4 = color;
break;
if (color.isValid()) {
newTemplateOptions.color_palette.color4 = color;
} break;
case 5:
color = QColorDialog::getColor(newTemplateOptions.color_palette.color5, this);
newTemplateOptions.color_palette.color5 = color;
break;
if (color.isValid()) {
newTemplateOptions.color_palette.color5 = color;
} break;
case 6:
color = QColorDialog::getColor(newTemplateOptions.color_palette.color6, this);
if (color.isValid()) {
newTemplateOptions.color_palette.color6 = color;
} break;
}
newTemplateOptions.color_palette_index = CUSTOM;
updatePreview();

View file

@ -31,6 +31,7 @@ private slots:
private:
Ui::TemplateEdit *ui;
QButtonGroup *btnGroup;
bool editingCustomColors;
struct template_options *templateOptions;
struct template_options newTemplateOptions;
struct print_options *printOptions;

View file

@ -317,7 +317,7 @@
</sizepolicy>
</property>
<property name="text">
<string>Table cells</string>
<string>Table cells 1</string>
</property>
</widget>
</item>
@ -347,9 +347,9 @@
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_7">
<layout class="QHBoxLayout" name="horizontalLayout_13">
<item>
<widget class="QLabel" name="label_7">
<widget class="QLabel" name="label_6">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred">
<horstretch>0</horstretch>
@ -357,7 +357,7 @@
</sizepolicy>
</property>
<property name="text">
<string>Text 1</string>
<string>Table cells 2</string>
</property>
</widget>
</item>
@ -387,9 +387,9 @@
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_9">
<layout class="QHBoxLayout" name="horizontalLayout_7">
<item>
<widget class="QLabel" name="label_11">
<widget class="QLabel" name="label_7">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred">
<horstretch>0</horstretch>
@ -397,7 +397,7 @@
</sizepolicy>
</property>
<property name="text">
<string>Text 2</string>
<string>Text 1</string>
</property>
</widget>
</item>
@ -427,9 +427,9 @@
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_6">
<layout class="QHBoxLayout" name="horizontalLayout_9">
<item>
<widget class="QLabel" name="label_4">
<widget class="QLabel" name="label_11">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred">
<horstretch>0</horstretch>
@ -437,7 +437,7 @@
</sizepolicy>
</property>
<property name="text">
<string>Borders</string>
<string>Text 2</string>
</property>
</widget>
</item>
@ -466,6 +466,46 @@
</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="colorLable6">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>color6</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="editButton6">
<property name="text">
<string>Edit</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<spacer name="verticalSpacer_2">
<property name="orientation">