2013-07-09 15:37:53 +03:00
|
|
|
#include "printoptions.h"
|
2015-06-26 04:21:31 +02:00
|
|
|
#include "templateedit.h"
|
2015-06-11 20:13:10 +02:00
|
|
|
#include <QDebug>
|
2013-07-09 15:37:53 +03:00
|
|
|
|
2015-06-29 03:16:19 +02:00
|
|
|
PrintOptions::PrintOptions(QWidget *parent, struct print_options *printOpt, struct template_options *templateOpt)
|
2013-07-09 15:37:53 +03:00
|
|
|
{
|
2013-07-10 10:54:25 +03:00
|
|
|
hasSetupSlots = false;
|
2013-10-03 11:54:25 -07:00
|
|
|
ui.setupUi(this);
|
2013-07-09 23:43:21 +03:00
|
|
|
if (parent)
|
|
|
|
setParent(parent);
|
2015-07-05 06:28:23 +02:00
|
|
|
if (!printOpt || !templateOpt)
|
2013-07-09 23:43:21 +03:00
|
|
|
return;
|
2015-06-29 03:16:19 +02:00
|
|
|
templateOptions = templateOpt;
|
2015-07-05 06:28:23 +02:00
|
|
|
printOptions = printOpt;
|
|
|
|
setup();
|
2013-07-10 10:54:25 +03:00
|
|
|
}
|
|
|
|
|
2015-07-05 06:28:23 +02:00
|
|
|
void PrintOptions::setup()
|
2013-07-10 10:54:25 +03:00
|
|
|
{
|
|
|
|
// print type radio buttons
|
2013-07-10 15:34:57 +03:00
|
|
|
switch (printOptions->type) {
|
2015-05-30 13:10:31 +02:00
|
|
|
case print_options::DIVELIST:
|
|
|
|
ui.radioDiveListPrint->setChecked(true);
|
2014-07-24 10:56:39 -07:00
|
|
|
break;
|
2014-11-14 00:57:42 +02:00
|
|
|
case print_options::TABLE:
|
2013-10-03 11:54:25 -07:00
|
|
|
ui.radioTablePrint->setChecked(true);
|
2013-07-10 10:54:25 +03:00
|
|
|
break;
|
2015-05-30 13:10:31 +02:00
|
|
|
case print_options::STATISTICS:
|
|
|
|
ui.radioStatisticsPrint->setChecked(true);
|
|
|
|
break;
|
2013-07-10 10:54:25 +03:00
|
|
|
}
|
2015-07-24 09:53:07 +02:00
|
|
|
|
2015-07-24 14:27:33 +02:00
|
|
|
// insert existing templates in the UI and select the current template
|
2015-07-24 09:53:07 +02:00
|
|
|
qSort(grantlee_templates);
|
2015-07-24 14:27:33 +02:00
|
|
|
int current_index = 0;
|
|
|
|
for (QList<QString>::iterator i = grantlee_templates.begin(); i != grantlee_templates.end(); ++i) {
|
|
|
|
if ((*i).compare(printOptions->p_template) == 0) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
current_index++;
|
|
|
|
}
|
|
|
|
ui.printTemplate->clear();
|
2015-07-24 09:53:07 +02:00
|
|
|
for (QList<QString>::iterator i = grantlee_templates.begin(); i != grantlee_templates.end(); ++i) {
|
|
|
|
ui.printTemplate->addItem((*i).split('.')[0], QVariant::fromValue(*i));
|
2015-06-11 20:13:10 +02:00
|
|
|
}
|
2015-07-24 14:27:33 +02:00
|
|
|
ui.printTemplate->setCurrentIndex(current_index);
|
2015-05-30 13:10:31 +02:00
|
|
|
|
2013-07-10 10:54:25 +03:00
|
|
|
// general print option checkboxes
|
|
|
|
if (printOptions->color_selected)
|
2013-10-03 11:54:25 -07:00
|
|
|
ui.printInColor->setChecked(true);
|
2013-07-10 10:54:25 +03:00
|
|
|
if (printOptions->print_selected)
|
2013-10-03 11:54:25 -07:00
|
|
|
ui.printSelected->setChecked(true);
|
2013-07-10 10:54:25 +03:00
|
|
|
|
|
|
|
// connect slots only once
|
|
|
|
if (hasSetupSlots)
|
|
|
|
return;
|
|
|
|
|
2013-10-03 11:54:25 -07:00
|
|
|
connect(ui.printInColor, SIGNAL(clicked(bool)), this, SLOT(printInColorClicked(bool)));
|
|
|
|
connect(ui.printSelected, SIGNAL(clicked(bool)), this, SLOT(printSelectedClicked(bool)));
|
2013-07-10 10:54:25 +03:00
|
|
|
|
|
|
|
hasSetupSlots = true;
|
2013-07-09 15:37:53 +03:00
|
|
|
}
|
|
|
|
|
2013-07-10 10:54:25 +03:00
|
|
|
// print type radio buttons
|
2015-05-30 13:10:31 +02:00
|
|
|
void PrintOptions::on_radioDiveListPrint_clicked(bool check)
|
2013-07-10 10:54:25 +03:00
|
|
|
{
|
2015-05-30 13:10:31 +02:00
|
|
|
if (check) {
|
|
|
|
printOptions->type = print_options::DIVELIST;
|
|
|
|
}
|
2013-07-10 10:54:25 +03:00
|
|
|
}
|
|
|
|
|
2015-05-30 13:10:31 +02:00
|
|
|
void PrintOptions::on_radioTablePrint_clicked(bool check)
|
2014-07-24 10:56:39 -07:00
|
|
|
{
|
2015-05-30 13:10:31 +02:00
|
|
|
if (check) {
|
|
|
|
printOptions->type = print_options::TABLE;
|
|
|
|
}
|
2014-07-24 10:56:39 -07:00
|
|
|
}
|
|
|
|
|
2015-05-30 13:10:31 +02:00
|
|
|
void PrintOptions::on_radioStatisticsPrint_clicked(bool check)
|
2013-07-10 10:54:25 +03:00
|
|
|
{
|
2015-05-30 13:10:31 +02:00
|
|
|
if (check) {
|
|
|
|
printOptions->type = print_options::STATISTICS;
|
|
|
|
}
|
2013-07-10 10:54:25 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// general print option checkboxes
|
|
|
|
void PrintOptions::printInColorClicked(bool check)
|
|
|
|
{
|
2014-11-14 00:57:42 +02:00
|
|
|
printOptions->color_selected = check;
|
2013-07-10 10:54:25 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void PrintOptions::printSelectedClicked(bool check)
|
|
|
|
{
|
2014-11-14 00:57:42 +02:00
|
|
|
printOptions->print_selected = check;
|
2013-07-10 10:54:25 +03:00
|
|
|
}
|
2015-06-11 20:13:10 +02:00
|
|
|
|
|
|
|
|
|
|
|
void PrintOptions::on_printTemplate_currentIndexChanged(int index)
|
|
|
|
{
|
2015-07-24 09:53:07 +02:00
|
|
|
printOptions->p_template = ui.printTemplate->itemData(index).toString();
|
2015-06-11 20:13:10 +02:00
|
|
|
}
|
2015-06-26 04:21:31 +02:00
|
|
|
|
|
|
|
void PrintOptions::on_editButton_clicked()
|
|
|
|
{
|
2015-07-05 07:26:39 +02:00
|
|
|
TemplateEdit te(this, printOptions, templateOptions);
|
2015-06-26 04:21:31 +02:00
|
|
|
te.exec();
|
2015-07-05 07:29:46 +02:00
|
|
|
setup();
|
2015-06-26 04:21:31 +02:00
|
|
|
}
|