diff options
-rw-r--r-- | display.h | 10 | ||||
-rw-r--r-- | qt-ui/printdialog.cpp | 56 | ||||
-rw-r--r-- | qt-ui/printdialog.h | 3 | ||||
-rw-r--r-- | qt-ui/printlayout.cpp | 10 | ||||
-rw-r--r-- | qt-ui/printlayout.h | 4 | ||||
-rw-r--r-- | qt-ui/printoptions.cpp | 24 | ||||
-rw-r--r-- | qt-ui/printoptions.h | 6 |
7 files changed, 83 insertions, 30 deletions
@@ -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; diff --git a/qt-ui/printdialog.cpp b/qt-ui/printdialog.cpp index a65078bf2..204f8a5c0 100644 --- a/qt-ui/printdialog.cpp +++ b/qt-ui/printdialog.cpp @@ -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) diff --git a/qt-ui/printdialog.h b/qt-ui/printdialog.h index 32069a278..b42102d1e 100644 --- a/qt-ui/printdialog.h +++ b/qt-ui/printdialog.h @@ -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 *); diff --git a/qt-ui/printlayout.cpp b/qt-ui/printlayout.cpp index f9b71d9b3..63819ad48 100644 --- a/qt-ui/printlayout.cpp +++ b/qt-ui/printlayout.cpp @@ -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; } diff --git a/qt-ui/printlayout.h b/qt-ui/printlayout.h index 9a816a3c1..d8c730a50 100644 --- a/qt-ui/printlayout.h +++ b/qt-ui/printlayout.h @@ -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; diff --git a/qt-ui/printoptions.cpp b/qt-ui/printoptions.cpp index 818e89c33..21e299930 100644 --- a/qt-ui/printoptions.cpp +++ b/qt-ui/printoptions.cpp @@ -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 diff --git a/qt-ui/printoptions.h b/qt-ui/printoptions.h index e14ae46a1..658e7ec1d 100644 --- a/qt-ui/printoptions.h +++ b/qt-ui/printoptions.h @@ -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 |