Print: add a class for print layouting

PrintLayout is a class that will handle the layouting part
of dive profiles, text, tables depending on the settings
of a QPrinter and the PrinterDialog and PrintOptions
instances.

Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
This commit is contained in:
Lubomir I. Ivanov 2013-07-10 15:34:57 +03:00
parent 74f989bc46
commit 41bad7695e
6 changed files with 91 additions and 1 deletions

View file

@ -55,6 +55,7 @@ HEADERS = \
qt-ui/graphicsview-common.h \
qt-ui/printdialog.h \
qt-ui/printoptions.h \
qt-ui/printlayout.h \
SOURCES = \
@ -98,6 +99,7 @@ SOURCES = \
qt-ui/graphicsview-common.cpp \
qt-ui/printdialog.cpp \
qt-ui/printoptions.cpp \
qt-ui/printlayout.cpp \
$(RESFILE)

View file

@ -16,6 +16,10 @@ PrintDialog::PrintDialog(QWidget *parent, Qt::WindowFlags f)
// options template (are we storing these in the settings?)
struct options tempOptions = {options::PRETTY, 0, 2, false, 65, 15, 12};
printOptions = tempOptions;
// create a print layout and pass the printer and options
printLayout = new PrintLayout(this, &printer, &printOptions);
/* temporary.
* add the PrintOptions widget and a Print button for testing purposes. */
optionsWidget = new PrintOptions(this, &printOptions);
@ -40,4 +44,5 @@ void PrintDialog::runDialog()
void PrintDialog::printClicked(void)
{
// nop for now
printLayout->print();
}

View file

@ -2,8 +2,10 @@
#define PRINTDIALOG_H
#include <QDialog>
#include <QPrinter>
#include "../display.h"
#include "printoptions.h"
#include "printlayout.h"
// should be based on a custom QPrintDialog class
class PrintDialog : public QDialog {
@ -17,6 +19,8 @@ public:
private:
explicit PrintDialog(QWidget *parent = 0, Qt::WindowFlags f = 0);
PrintOptions *optionsWidget;
PrintLayout *printLayout;
QPrinter printer;
private slots:
void printClicked();

50
qt-ui/printlayout.cpp Normal file
View file

@ -0,0 +1,50 @@
#include <QPainter>
#include "mainwindow.h"
#include "printlayout.h"
/*
struct options {
enum { PRETTY, TABLE, TWOPERPAGE } type;
int print_selected;
int color_selected;
bool notes_up;
int profile_height, notes_height, tanks_height;
};
*/
PrintLayout::PrintLayout(PrintDialog *dialogPtr, QPrinter *printerPtr, struct options *optionsPtr)
{
dialog = dialogPtr;
printer = printerPtr;
printOptions = optionsPtr;
}
void PrintLayout::print()
{
switch (printOptions->type) {
case options::PRETTY:
printSixDives();
break;
case options::TWOPERPAGE:
printTwoDives();
break;
case options::TABLE:
printTable();
break;
}
}
void PrintLayout::printSixDives()
{
// nop
}
void PrintLayout::printTwoDives()
{
// nop
}
void PrintLayout::printTable()
{
// nop
}

29
qt-ui/printlayout.h Normal file
View file

@ -0,0 +1,29 @@
#ifndef PRINTLAYOUT_H
#define PRINTLAYOUT_H
#include <QPrinter>
#include <QPainter>
#include "../display.h"
class PrintDialog;
class PrintLayout : public QObject {
Q_OBJECT
public:
PrintLayout(PrintDialog *, QPrinter *, struct options *);
void print();
private:
PrintDialog *dialog;
QPrinter *printer;
struct options *printOptions;
QPainter painter;
void printSixDives();
void printTwoDives();
void printTable();
};
#endif

View file

@ -21,7 +21,7 @@ void PrintOptions::setup(struct options *printOpt)
initSliderWithLabel(ui->sliderOHeight, ui->valueOHeight, printOptions->notes_height);
initSliderWithLabel(ui->sliderNHeight, ui->valueNHeight, printOptions->tanks_height);
// print type radio buttons
switch (printOptions->type) {
switch (printOptions->type) {
case options::PRETTY:
ui->radioSixDives->setChecked(true);
break;