00001 #include "printdialog.h"
00002
00003 #include "../Models/exercisemodel.h"
00004 #include "../Models/accountmodel.h"
00005 #include "../Data/settings.h"
00006
00007 #include <QGraphicsScene>
00008 #include <QAbstractItemModel>
00009 #include <QGraphicsView>
00010 #include <QDialog>
00011 #include <QPrinter>
00012 #include <QPageSetupDialog>
00013 #include <QMessageBox>
00014 #include <QCloseEvent>
00015
00016 PrintDialog::PrintDialog(QPrinter *printer, Settings &settings, ExerciseModel *model, DataProject *project, AccountModel *table, QWidget *parent) : QDialog(parent)
00017 {
00018 setupUi(this);
00019 setAttribute(Qt::WA_DeleteOnClose, true);
00020 p_printer = printer;
00021 p_model = model;
00022 p_project = project;
00023 p_table = table;
00024 p_settings = &settings;
00025
00026 p_model->setPrintDialogUser(true);
00027
00028
00029 p_generalPrinter = new Printing(p_printer, settings, p_model, p_project, p_table);
00030
00031
00032 checkPrintIntroPage->setChecked(p_settings->introPage());
00033 checkNewPageSolution->setChecked(p_settings->newPageSolution());
00034 checkEmptySolution->setChecked(p_settings->emptySolution());
00035
00036 showExercises();
00037 showSmallPreview();
00038 contentChanged();
00039 graphicsViewPreview->ensureVisible(0,0,5,5);
00040 graphicsViewPreview->scale(0.6, 0.6);
00041
00042
00043 connect(spinBoxPages, SIGNAL(valueChanged(int)), this, SLOT(showSmallPreview()));
00044 connect(buttonClose, SIGNAL(clicked()), this, SLOT(closeDialog()));
00045 connect(buttonPrintPreview, SIGNAL(clicked()), this, SLOT(showPrintPreviewDialog()));
00046 connect(buttonPrint, SIGNAL(clicked()), this, SLOT(print()));
00047
00048 connect(p_model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(contentChanged()));
00049 connect(checkPrintIntroPage, SIGNAL(stateChanged(int)), this, SLOT(contentChanged()));
00050 connect(checkEmptySolution, SIGNAL(stateChanged(int)), this, SLOT(contentChanged()));
00051 connect(checkNewPageSolution, SIGNAL(stateChanged(int)), this, SLOT(contentChanged()));
00052 }
00053
00054 PrintDialog::~PrintDialog()
00055 {
00056 }
00057
00058 void PrintDialog::closeDialog()
00059 {
00060 p_model->setPrintDialogUser(false);
00061 done(0);
00062 }
00063
00064 void PrintDialog::closeEvent(QCloseEvent *event)
00065 {
00066 p_model->setPrintDialogUser(false);
00067 event->accept();
00068 }
00069
00070 void PrintDialog::showPrintPreviewDialog()
00071 {
00072 PrintPreviewDialog *dialog = new PrintPreviewDialog(p_generalPrinter, p_printer, this);
00073 dialog->show();
00074 }
00075
00076 void PrintDialog::print()
00077 {
00078 p_generalPrinter->print();
00079 }
00080
00081 void PrintDialog::showSmallPreview()
00082 {
00083 graphicsViewPreview->setScene(p_generalPrinter->pageScene(spinBoxPages->value()-1));
00084 }
00085
00086 void PrintDialog::showExercises()
00087 {
00088 treeViewExercises->setModel(p_model);
00089 }
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101 void PrintDialog::contentChanged()
00102 {
00103 p_settings->setIntroPage(checkPrintIntroPage->isChecked());
00104 p_settings->setNewPageSolution(checkNewPageSolution->isChecked());
00105 p_settings->setEmptySolution(checkEmptySolution->isChecked());
00106
00107 p_generalPrinter->paintPage(checkEmptySolution->isChecked(), checkNewPageSolution->isChecked());
00108 if(checkPrintIntroPage->isChecked())
00109 {
00110 p_generalPrinter->paintIntroPage();
00111 }
00112
00113 p_generalPrinter->paintFooter();
00114 setupSpinBox();
00115 showSmallPreview();
00116 }
00117
00118 void PrintDialog::setupSpinBox()
00119 {
00120 spinBoxPages->setMinimum(1);
00121 spinBoxPages->setMaximum(p_generalPrinter->pageCount());
00122 }