aboutsummaryrefslogtreecommitdiffstats
path: root/qt-ui/printoptions.cpp
blob: a7c520b219a8fc2d3103ac0020b696c000cffcdc (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#include "printoptions.h"
#include "templateedit.h"
#include <QDebug>

PrintOptions::PrintOptions(QWidget *parent, struct print_options *printOpt, struct template_options *templateOpt)
{
	hasSetupSlots = false;
	ui.setupUi(this);
	if (parent)
		setParent(parent);
	if (!printOpt)
		return;
	setup(printOpt);
	templateOptions = templateOpt;
}

void PrintOptions::setup(struct print_options *printOpt)
{
	printOptions = printOpt;
	// print type radio buttons
	switch (printOptions->type) {
	case print_options::DIVELIST:
		ui.radioDiveListPrint->setChecked(true);
		break;
	case print_options::TABLE:
		ui.radioTablePrint->setChecked(true);
		break;
	case print_options::STATISTICS:
		ui.radioStatisticsPrint->setChecked(true);
		break;
	}
	switch (printOptions->p_template) {
	case print_options::ONE_DIVE:
		ui.printTemplate->setCurrentIndex(0);
		break;
	case print_options::TWO_DIVE:
		ui.printTemplate->setCurrentIndex(1);
		break;
	}

	// general print option checkboxes
	if (printOptions->color_selected)
		ui.printInColor->setChecked(true);
	if (printOptions->print_selected)
		ui.printSelected->setChecked(true);

	// connect slots only once
	if (hasSetupSlots)
		return;

	connect(ui.printInColor, SIGNAL(clicked(bool)), this, SLOT(printInColorClicked(bool)));
	connect(ui.printSelected, SIGNAL(clicked(bool)), this, SLOT(printSelectedClicked(bool)));

	hasSetupSlots = true;
}

// print type radio buttons
void PrintOptions::on_radioDiveListPrint_clicked(bool check)
{
	if (check) {
		printOptions->type = print_options::DIVELIST;
	}
}

void PrintOptions::on_radioTablePrint_clicked(bool check)
{
	if (check) {
		printOptions->type = print_options::TABLE;
	}
}

void PrintOptions::on_radioStatisticsPrint_clicked(bool check)
{
	if (check) {
		printOptions->type = print_options::STATISTICS;
	}
}

// general print option checkboxes
void PrintOptions::printInColorClicked(bool check)
{
	printOptions->color_selected = check;
}

void PrintOptions::printSelectedClicked(bool check)
{
	printOptions->print_selected = check;
}


void PrintOptions::on_printTemplate_currentIndexChanged(int index)
{
    switch(index){
	case 0:
		printOptions->p_template = print_options::ONE_DIVE;
	break;
	case 1:
		printOptions->p_template = print_options::TWO_DIVE;
	break;
    }
}

void PrintOptions::on_editButton_clicked()
{
	TemplateEdit te(this, templateOptions);
	te.exec();
}