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