mirror of
https://github.com/subsurface/subsurface.git
synced 2025-01-19 14:25:27 +00:00
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>
This commit is contained in:
parent
b2077dc9c0
commit
7ea728e95f
7 changed files with 83 additions and 30 deletions
10
display.h
10
display.h
|
@ -35,16 +35,18 @@ typedef enum {
|
|||
|
||||
extern struct divecomputer *select_dc(struct dive *);
|
||||
|
||||
struct options {
|
||||
enum {
|
||||
struct print_options {
|
||||
enum print_type {
|
||||
PRETTY,
|
||||
TABLE,
|
||||
TWOPERPAGE,
|
||||
ONEPERPAGE
|
||||
} type;
|
||||
int print_selected;
|
||||
int color_selected;
|
||||
bool print_selected;
|
||||
bool color_selected;
|
||||
bool notes_up;
|
||||
bool landscape;
|
||||
int margins[4]; // left, top, right, bottom
|
||||
};
|
||||
|
||||
extern unsigned int dc_number;
|
||||
|
|
|
@ -13,12 +13,42 @@
|
|||
#include <QShortcut>
|
||||
#include <QPrinterInfo>
|
||||
#include <QMessageBox>
|
||||
#include <QSettings>
|
||||
#include <QMarginsF>
|
||||
|
||||
#define SETTINGS_GROUP "PrintDialog"
|
||||
|
||||
PrintDialog::PrintDialog(QWidget *parent, Qt::WindowFlags f) : QDialog(parent, f)
|
||||
{
|
||||
// options template (are we storing these in the settings?)
|
||||
struct options tempOptions = { options::PRETTY, 1, 2, false };
|
||||
printOptions = tempOptions;
|
||||
// check if the options were previously stored in the settings; if not use some defaults.
|
||||
QSettings s;
|
||||
bool stored = s.childGroups().contains(SETTINGS_GROUP);
|
||||
if (!stored) {
|
||||
printOptions.type = print_options::PRETTY;
|
||||
printOptions.print_selected = true;
|
||||
printOptions.color_selected = true;
|
||||
printOptions.notes_up = false;
|
||||
printOptions.landscape = false;
|
||||
memset(printOptions.margins, 0, sizeof(printOptions.margins));
|
||||
} else {
|
||||
s.beginGroup(SETTINGS_GROUP);
|
||||
printOptions.type = (print_options::print_type)s.value("type").toInt();
|
||||
printOptions.print_selected = s.value("print_selected").toBool();
|
||||
printOptions.color_selected = s.value("color_selected").toBool();
|
||||
printOptions.notes_up = s.value("notes_up").toBool();
|
||||
printOptions.landscape = s.value("landscape").toBool();
|
||||
printOptions.margins[0] = s.value("margin_left").toInt();
|
||||
printOptions.margins[1] = s.value("margin_top").toInt();
|
||||
printOptions.margins[2] = s.value("margin_right").toInt();
|
||||
printOptions.margins[3] = s.value("margin_bottom").toInt();
|
||||
printer.setOrientation((QPrinter::Orientation)printOptions.landscape);
|
||||
QMarginsF margins;
|
||||
margins.setLeft(printOptions.margins[0]);
|
||||
margins.setRight(printOptions.margins[1]);
|
||||
margins.setTop(printOptions.margins[2]);
|
||||
margins.setBottom(printOptions.margins[3]);
|
||||
printer.setPageMargins(margins, QPageLayout::Millimeter);
|
||||
}
|
||||
|
||||
// create a print layout and pass the printer and options
|
||||
printLayout = new PrintLayout(this, &printer, &printOptions);
|
||||
|
@ -64,6 +94,26 @@ PrintDialog::PrintDialog(QWidget *parent, Qt::WindowFlags f) : QDialog(parent, f
|
|||
connect(close, SIGNAL(activated()), this, SLOT(close()));
|
||||
QShortcut *quit = new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_Q), this);
|
||||
connect(quit, SIGNAL(activated()), parent, SLOT(close()));
|
||||
|
||||
// seems to be the most reliable way to track for all sorts of dialog disposal.
|
||||
connect(this, SIGNAL(finished(int)), this, SLOT(onFinished()));
|
||||
}
|
||||
|
||||
void PrintDialog::onFinished()
|
||||
{
|
||||
// save the settings
|
||||
QSettings s;
|
||||
s.beginGroup(SETTINGS_GROUP);
|
||||
s.setValue("type", printOptions.type);
|
||||
s.setValue("print_selected", printOptions.print_selected);
|
||||
s.setValue("color_selected", printOptions.color_selected);
|
||||
s.setValue("notes_up", printOptions.notes_up);
|
||||
s.setValue("landscape", (bool)printer.pageLayout().orientation());
|
||||
QMarginsF margins = printer.pageLayout().margins(QPageLayout::Millimeter);
|
||||
s.setValue("margin_left", margins.left());
|
||||
s.setValue("margin_right", margins.top());
|
||||
s.setValue("margin_top", margins.right());
|
||||
s.setValue("margin_bottom", margins.bottom());
|
||||
}
|
||||
|
||||
void PrintDialog::previewClicked(void)
|
||||
|
|
|
@ -14,7 +14,6 @@ class PrintDialog : public QDialog {
|
|||
Q_OBJECT
|
||||
|
||||
public:
|
||||
struct options printOptions;
|
||||
explicit PrintDialog(QWidget *parent = 0, Qt::WindowFlags f = 0);
|
||||
|
||||
private:
|
||||
|
@ -22,9 +21,11 @@ private:
|
|||
PrintLayout *printLayout;
|
||||
QProgressBar *progressBar;
|
||||
QPrinter printer;
|
||||
struct print_options printOptions;
|
||||
|
||||
private
|
||||
slots:
|
||||
void onFinished();
|
||||
void previewClicked();
|
||||
void printClicked();
|
||||
void onPaintRequested(QPrinter *);
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
#include "models.h"
|
||||
#include "modeldelegates.h"
|
||||
|
||||
PrintLayout::PrintLayout(PrintDialog *dialogPtr, QPrinter *printerPtr, struct options *optionsPtr)
|
||||
PrintLayout::PrintLayout(PrintDialog *dialogPtr, QPrinter *printerPtr, struct print_options *optionsPtr)
|
||||
{
|
||||
dialog = dialogPtr;
|
||||
printer = printerPtr;
|
||||
|
@ -74,16 +74,16 @@ void PrintLayout::print()
|
|||
return;
|
||||
}
|
||||
switch (printOptions->type) {
|
||||
case options::PRETTY:
|
||||
case print_options::PRETTY:
|
||||
printProfileDives(3, 2);
|
||||
break;
|
||||
case options::ONEPERPAGE:
|
||||
case print_options::ONEPERPAGE:
|
||||
printProfileDives(1, 1);
|
||||
break;
|
||||
case options::TWOPERPAGE:
|
||||
case print_options::TWOPERPAGE:
|
||||
printProfileDives(2, 1);
|
||||
break;
|
||||
case options::TABLE:
|
||||
case print_options::TABLE:
|
||||
printTable();
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -17,13 +17,13 @@ class PrintLayout : public QObject {
|
|||
Q_OBJECT
|
||||
|
||||
public:
|
||||
PrintLayout(PrintDialog *, QPrinter *, struct options *);
|
||||
PrintLayout(PrintDialog *, QPrinter *, struct print_options *);
|
||||
void print();
|
||||
|
||||
private:
|
||||
PrintDialog *dialog;
|
||||
QPrinter *printer;
|
||||
struct options *printOptions;
|
||||
struct print_options *printOptions;
|
||||
|
||||
int screenDpiX, screenDpiY, printerDpi, pageW, pageH;
|
||||
QRect pageRect;
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#include "printoptions.h"
|
||||
#include "../display.h"
|
||||
|
||||
PrintOptions::PrintOptions(QWidget *parent, struct options *printOpt)
|
||||
PrintOptions::PrintOptions(QWidget *parent, struct print_options *printOpt)
|
||||
{
|
||||
hasSetupSlots = false;
|
||||
ui.setupUi(this);
|
||||
|
@ -12,21 +12,21 @@ PrintOptions::PrintOptions(QWidget *parent, struct options *printOpt)
|
|||
setup(printOpt);
|
||||
}
|
||||
|
||||
void PrintOptions::setup(struct options *printOpt)
|
||||
void PrintOptions::setup(struct print_options *printOpt)
|
||||
{
|
||||
printOptions = printOpt;
|
||||
// print type radio buttons
|
||||
switch (printOptions->type) {
|
||||
case options::PRETTY:
|
||||
case print_options::PRETTY:
|
||||
ui.radioSixDives->setChecked(true);
|
||||
break;
|
||||
case options::TWOPERPAGE:
|
||||
case print_options::TWOPERPAGE:
|
||||
ui.radioTwoDives->setChecked(true);
|
||||
break;
|
||||
case options::ONEPERPAGE:
|
||||
case print_options::ONEPERPAGE:
|
||||
ui.radioOneDive->setChecked(true);
|
||||
break;
|
||||
case options::TABLE:
|
||||
case print_options::TABLE:
|
||||
ui.radioTablePrint->setChecked(true);
|
||||
break;
|
||||
}
|
||||
|
@ -61,33 +61,33 @@ void PrintOptions::setup(struct options *printOpt)
|
|||
// print type radio buttons
|
||||
void PrintOptions::radioSixDivesClicked(bool check)
|
||||
{
|
||||
printOptions->type = options::PRETTY;
|
||||
printOptions->type = print_options::PRETTY;
|
||||
}
|
||||
|
||||
void PrintOptions::radioTwoDivesClicked(bool check)
|
||||
{
|
||||
printOptions->type = options::TWOPERPAGE;
|
||||
printOptions->type = print_options::TWOPERPAGE;
|
||||
}
|
||||
|
||||
void PrintOptions::radioOneDiveClicked(bool check)
|
||||
{
|
||||
printOptions->type = options::ONEPERPAGE;
|
||||
printOptions->type = print_options::ONEPERPAGE;
|
||||
}
|
||||
|
||||
void PrintOptions::radioTablePrintClicked(bool check)
|
||||
{
|
||||
printOptions->type = options::TABLE;
|
||||
printOptions->type = print_options::TABLE;
|
||||
}
|
||||
|
||||
// general print option checkboxes
|
||||
void PrintOptions::printInColorClicked(bool check)
|
||||
{
|
||||
printOptions->color_selected = (int)check;
|
||||
printOptions->color_selected = check;
|
||||
}
|
||||
|
||||
void PrintOptions::printSelectedClicked(bool check)
|
||||
{
|
||||
printOptions->print_selected = (int)check;
|
||||
printOptions->print_selected = check;
|
||||
}
|
||||
|
||||
// ordering
|
||||
|
|
|
@ -10,12 +10,12 @@ class PrintOptions : public QWidget {
|
|||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit PrintOptions(QWidget *parent = 0, struct options *printOpt = 0);
|
||||
void setup(struct options *printOpt);
|
||||
explicit PrintOptions(QWidget *parent = 0, struct print_options *printOpt = 0);
|
||||
void setup(struct print_options *printOpt);
|
||||
|
||||
private:
|
||||
Ui::PrintOptions ui;
|
||||
struct options *printOptions;
|
||||
struct print_options *printOptions;
|
||||
bool hasSetupSlots;
|
||||
|
||||
private
|
||||
|
|
Loading…
Add table
Reference in a new issue