2013-07-09 12:37:53 +00:00
|
|
|
#include "printdialog.h"
|
2013-12-04 13:44:31 +00:00
|
|
|
#include "printoptions.h"
|
|
|
|
#include "printlayout.h"
|
2013-11-30 17:18:04 +00:00
|
|
|
#include "mainwindow.h"
|
2013-07-09 12:37:53 +00:00
|
|
|
|
|
|
|
#include <QDebug>
|
|
|
|
#include <QPushButton>
|
2013-12-04 11:41:19 +00:00
|
|
|
#include <QProgressBar>
|
2013-07-09 12:37:53 +00:00
|
|
|
#include <QVBoxLayout>
|
2013-12-04 11:41:19 +00:00
|
|
|
#include <QHBoxLayout>
|
2013-07-10 16:27:10 +00:00
|
|
|
#include <QPrintPreviewDialog>
|
2013-12-04 11:51:34 +00:00
|
|
|
#include <QPrintDialog>
|
2013-07-09 12:37:53 +00:00
|
|
|
|
2014-02-12 14:26:25 +00:00
|
|
|
PrintDialog::PrintDialog(QWidget *parent, Qt::WindowFlags f) : QDialog(parent, f)
|
2013-07-09 12:37:53 +00:00
|
|
|
{
|
|
|
|
// options template (are we storing these in the settings?)
|
|
|
|
struct options tempOptions = {options::PRETTY, 0, 2, false, 65, 15, 12};
|
|
|
|
printOptions = tempOptions;
|
2013-07-10 12:34:57 +00:00
|
|
|
|
|
|
|
// create a print layout and pass the printer and options
|
|
|
|
printLayout = new PrintLayout(this, &printer, &printOptions);
|
|
|
|
|
2013-12-04 11:46:08 +00:00
|
|
|
// create a print options object and pass our options struct
|
2013-07-09 20:43:21 +00:00
|
|
|
optionsWidget = new PrintOptions(this, &printOptions);
|
|
|
|
|
2013-07-09 12:37:53 +00:00
|
|
|
QVBoxLayout *layout = new QVBoxLayout(this);
|
|
|
|
setLayout(layout);
|
|
|
|
|
2013-12-04 11:51:34 +00:00
|
|
|
QHBoxLayout *hLayout = new QHBoxLayout();
|
|
|
|
layout->addLayout(hLayout);
|
|
|
|
|
|
|
|
QPushButton *previewButton = new QPushButton(tr("&Preview"));
|
|
|
|
connect(previewButton, SIGNAL(clicked(bool)), this, SLOT(previewClicked()));
|
|
|
|
hLayout->addWidget(previewButton);
|
|
|
|
|
2013-12-04 12:14:04 +00:00
|
|
|
QPushButton *printButton = new QPushButton(tr("P&rint"));
|
2013-07-09 12:37:53 +00:00
|
|
|
connect(printButton, SIGNAL(clicked(bool)), this, SLOT(printClicked()));
|
2013-12-04 11:51:34 +00:00
|
|
|
hLayout->addWidget(printButton);
|
2013-07-09 12:37:53 +00:00
|
|
|
|
2013-12-04 12:14:04 +00:00
|
|
|
QPushButton *closeButton = new QPushButton(tr("&Close"));
|
2014-02-08 23:13:58 +00:00
|
|
|
connect(closeButton, SIGNAL(clicked(bool)), this, SLOT(accept()));
|
2013-12-04 12:14:04 +00:00
|
|
|
hLayout->addWidget(closeButton);
|
|
|
|
|
2013-12-04 13:51:01 +00:00
|
|
|
progressBar = new QProgressBar();
|
2013-12-04 11:41:19 +00:00
|
|
|
connect(printLayout, SIGNAL(signalProgress(int)), progressBar, SLOT(setValue(int)));
|
|
|
|
progressBar->setMinimum(0);
|
|
|
|
progressBar->setMaximum(100);
|
2014-02-08 19:12:13 +00:00
|
|
|
progressBar->setValue(0);
|
2013-12-04 11:41:19 +00:00
|
|
|
progressBar->setTextVisible(false);
|
|
|
|
layout->addWidget(progressBar);
|
|
|
|
|
2013-11-30 16:43:40 +00:00
|
|
|
layout->addWidget(optionsWidget);
|
|
|
|
|
2013-12-04 11:55:30 +00:00
|
|
|
setFixedSize(520, 350);
|
2013-11-30 16:54:28 +00:00
|
|
|
setWindowTitle(tr("Print"));
|
|
|
|
setWindowIcon(QIcon(":subsurface-icon"));
|
2013-07-09 12:37:53 +00:00
|
|
|
}
|
|
|
|
|
2013-12-04 11:51:34 +00:00
|
|
|
void PrintDialog::previewClicked(void)
|
2013-07-09 12:37:53 +00:00
|
|
|
{
|
2013-07-10 16:27:10 +00:00
|
|
|
QPrintPreviewDialog previewDialog(&printer, this);
|
2014-02-08 23:13:58 +00:00
|
|
|
connect(&previewDialog, SIGNAL(paintRequested(QPrinter *)), this, SLOT(onPaintRequested(QPrinter *)));
|
2013-12-04 11:51:34 +00:00
|
|
|
previewDialog.exec();
|
|
|
|
}
|
|
|
|
|
|
|
|
void PrintDialog::printClicked(void)
|
|
|
|
{
|
|
|
|
QPrintDialog printDialog(&printer, this);
|
|
|
|
if (printDialog.exec() == QDialog::Accepted)
|
|
|
|
printLayout->print();
|
2013-07-10 16:27:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void PrintDialog::onPaintRequested(QPrinter *printerPtr)
|
|
|
|
{
|
2013-07-10 12:34:57 +00:00
|
|
|
printLayout->print();
|
2013-07-09 12:37:53 +00:00
|
|
|
}
|