subsurface/qt-ui/printoptions.cpp
Lubomir I. Ivanov 7ea728e95f Print: add the support to store margins and printer options
All the print options will be stored after the user closes
or "cancels" the print dialog.

There seems to be no good way to store the last
selected page size, because print dialogs are different and
some just list them as strings - A4, A3, etc.

The patch also applies the following changes:
- renames display.h's 'struct options' to 'struct print_options'
as these were really just for the print dialog
- the print_options dialog now stores more options as 'bool'
- demote PrintDialog's 'printOptions' to 'private'

Fixes #653

Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-11-13 15:05:11 -08:00

102 lines
2.6 KiB
C++

#include "printoptions.h"
#include "../display.h"
PrintOptions::PrintOptions(QWidget *parent, struct print_options *printOpt)
{
hasSetupSlots = false;
ui.setupUi(this);
if (parent)
setParent(parent);
if (!printOpt)
return;
setup(printOpt);
}
void PrintOptions::setup(struct print_options *printOpt)
{
printOptions = printOpt;
// print type radio buttons
switch (printOptions->type) {
case print_options::PRETTY:
ui.radioSixDives->setChecked(true);
break;
case print_options::TWOPERPAGE:
ui.radioTwoDives->setChecked(true);
break;
case print_options::ONEPERPAGE:
ui.radioOneDive->setChecked(true);
break;
case print_options::TABLE:
ui.radioTablePrint->setChecked(true);
break;
}
// general print option checkboxes
if (printOptions->color_selected)
ui.printInColor->setChecked(true);
if (printOptions->print_selected)
ui.printSelected->setChecked(true);
// ordering
if (printOptions->notes_up)
ui.notesOnTop->setChecked(true);
else
ui.profileOnTop->setChecked(true);
// connect slots only once
if (hasSetupSlots)
return;
connect(ui.radioSixDives, SIGNAL(clicked(bool)), this, SLOT(radioSixDivesClicked(bool)));
connect(ui.radioTwoDives, SIGNAL(clicked(bool)), this, SLOT(radioTwoDivesClicked(bool)));
connect(ui.radioOneDive, SIGNAL(clicked(bool)), this, SLOT(radioOneDiveClicked(bool)));
connect(ui.radioTablePrint, SIGNAL(clicked(bool)), this, SLOT(radioTablePrintClicked(bool)));
connect(ui.printInColor, SIGNAL(clicked(bool)), this, SLOT(printInColorClicked(bool)));
connect(ui.printSelected, SIGNAL(clicked(bool)), this, SLOT(printSelectedClicked(bool)));
connect(ui.notesOnTop, SIGNAL(clicked(bool)), this, SLOT(notesOnTopClicked(bool)));
connect(ui.profileOnTop, SIGNAL(clicked(bool)), this, SLOT(profileOnTopClicked(bool)));
hasSetupSlots = true;
}
// print type radio buttons
void PrintOptions::radioSixDivesClicked(bool check)
{
printOptions->type = print_options::PRETTY;
}
void PrintOptions::radioTwoDivesClicked(bool check)
{
printOptions->type = print_options::TWOPERPAGE;
}
void PrintOptions::radioOneDiveClicked(bool check)
{
printOptions->type = print_options::ONEPERPAGE;
}
void PrintOptions::radioTablePrintClicked(bool check)
{
printOptions->type = print_options::TABLE;
}
// general print option checkboxes
void PrintOptions::printInColorClicked(bool check)
{
printOptions->color_selected = check;
}
void PrintOptions::printSelectedClicked(bool check)
{
printOptions->print_selected = check;
}
// ordering
void PrintOptions::notesOnTopClicked(bool check)
{
printOptions->notes_up = true;
}
void PrintOptions::profileOnTopClicked(bool check)
{
printOptions->notes_up = false;
}