PageRenderTime 37ms CodeModel.GetById 16ms app.highlight 17ms RepoModel.GetById 1ms app.codeStats 0ms

/safeFatPrinter/branch/src/startdlg.cpp

http://cupsfilter.googlecode.com/
C++ | 194 lines | 142 code | 37 blank | 15 comment | 11 complexity | 401e323f6be614cb413429c94b1c3c90 MD5 | raw file
  1#include "startdlg.h"
  2#include "ui_startdlg.h"
  3
  4StartDlg::StartDlg(QWidget *parent) :
  5    QDialog(parent),
  6    ui(new Ui::StartDlg)
  7{
  8    ui->setupUi(this);
  9
 10    askDlg = new AskTheUser(this);
 11    wrkDlg = new workReport(this);
 12    templViewer = new View(this);
 13    //templViewer->hide();
 14    connectStep=false;
 15    convertStep=false;
 16
 17    control = new dController(this);
 18    signalMapper = new QSignalMapper(this);
 19    createConnection();
 20    rabbitHole();
 21    control->connect2Demon();
 22
 23    QString msg;
 24    if (control->isUser_Mandat()){
 25	msg= QObject::trUtf8("??????? ???????? ??? ???????????? ? ??? ??????");
 26	getMandatUserStep=true;
 27
 28    }else{
 29	getMandatUserStep=false;
 30	msg= QObject::trUtf8("?????? ????????? ????? ???????????? ??? ??? ???????");
 31    }
 32    this->printToLog(msg);
 33
 34}
 35
 36
 37void StartDlg::convertToPDF(QString &filename)
 38{
 39    control->convert2PDF(filename);
 40    QString msg;
 41    msg=QObject::trUtf8("???? %1 ????????? ?? ???????????").arg(filename);
 42    this->printToLog(msg);
 43}
 44
 45//************************************      SLOTS     *********************************************
 46
 47
 48
 49
 50// --------------------------------------------------------------- private slots --------------------------------------------------------------------------------
 51
 52
 53void StartDlg::fill_docCard4Print(int Mode)
 54{  // ??????? ?????? ????? ??? ?????? ??????
 55    askDlg->setWorkMode(Mode);
 56    askDlg->setModel(control->document_model());
 57    askDlg->setStampModel(control->stamp_model());
 58    askDlg->setTemplatesPath(control->glob_templates());
 59
 60    int ret = askDlg->exec();
 61    if (ret ==QDialog::Accepted){
 62
 63	QString in =control->mainPDF;
 64	QString bg_file="d:\\compl_teml2.pdf";
 65	QString out_file="d:\\out.pdf";
 66	 control->mergeTwoPDF(in,bg_file,out_file);
 67
 68	switch (Mode){
 69	    case 0:
 70		if (askDlg->isCheckedPAO()){
 71		    control->printWithTemplate(1);
 72		    QString in =control->mainPDF;
 73		    QString bg_file="d:\\compl_teml2.pdf";
 74		    QString out_file="d:\\out.pdf";
 75		     control->mergeTwoPDF(in,bg_file,out_file);
 76		    //emit saveModelToBase(askDlg->getCurrentModelIndex());
 77
 78		}else{
 79		    //emit PrintOutSideMark(askDlg->getCurrentModelIndex());
 80		    control->printOverSide(1);
 81		}
 82		break;
 83	    case 1:
 84
 85		break;
 86	    case 2:
 87		break;
 88	}
 89	// ??????? ??????????? ??????
 90	wrkDlg->exec();
 91
 92    }else{
 93	// clearModel
 94    }
 95}
 96
 97void StartDlg::enableGUI(steps_t step,QString &message)
 98{
 99    if (step==CONN_STEP){
100
101	connectStep=true;
102    }else  if (step==CONVERT_STEP){
103	convertStep=true;
104    }
105    if (connectStep && convertStep && getMandatUserStep){
106	ui->printerCBox->addItems(control->printers_list());
107	ui->printerCBox->setEnabled(true);
108	ui->printOnMarkPaperBtn->setEnabled(true);
109	ui->printWithAutoMarkPaperBtn->setEnabled(true);
110	ui->markPaperBtn->setEnabled(true);
111    }
112     this->printToLog(message);
113}
114
115void StartDlg::showErrorInfo()
116{
117
118    QMessageBox msgBox(this);
119     QPushButton *abortButton;
120    msgBox.setObjectName("crit_msg_box");
121    msgBox.setIcon(QMessageBox::Critical);
122
123    QString msg=QObject::trUtf8("??? ???????????? %1 ??? ????????? ?????????. ").arg("sva");
124    msgBox.setInformativeText(QObject::trUtf8("??? ??????? ???? ???????? ?????????? ? ?????????????? ????????????!"));
125    abortButton=msgBox.addButton(QObject::trUtf8("?????"), QMessageBox::RejectRole);
126    msgBox.setText(msg);
127    msgBox.exec();
128    if (msgBox.clickedButton()==abortButton){
129	QCoreApplication::quit();
130    }
131}
132
133void StartDlg::do_showTemplatesEditor()
134{
135
136    askDlg->hide();
137    templViewer->exec();
138}
139
140StartDlg::~StartDlg()
141{
142    delete ui;
143}
144//************************************ END SLOTS *********************************************
145
146// --------------------------------------------------------------- protected function-------------------------------------------------------------------------
147void StartDlg::rabbitHole()
148{
149    // ??????? ?? ???????????
150    // ?????? ?????????
151    connect (control, SIGNAL(init_done(steps_t,QString &)), this, SLOT(enableGUI(steps_t,QString &)));
152    connect (control,SIGNAL(printersNotFound()),this,SLOT(showErrorInfo()));
153    connect (control,SIGNAL(mbNumberExist(int)),askDlg,SLOT(do_mbExist(int)));
154    connect (control,SIGNAL(mbNumberNotExist()),askDlg,SLOT(do_mbNumberNotExist()));
155    // ??????? ?? ??????????
156    connect (askDlg,SIGNAL(needCheckMB(QString )),control,SLOT(checkMB(QString )));
157    connect (askDlg,SIGNAL(showTemplatesEditor()),this,SLOT(do_showTemplatesEditor()));
158    // ??????? ?? ???????_??????????? ?????
159    // ??????? ?? ????????? ????????
160
161}
162
163void StartDlg::printToLog(QString & log_mes)
164{
165    ui->logList->addItem(QString("%1: %2").arg(QDateTime::currentDateTime ().toString("dd.MM.yyyy hh:mm:ss")).arg(log_mes));
166    ui->logList->update();
167}
168
169
170
171void StartDlg::createConnection()
172{
173    // ??????? ????????
174     connect(ui->markPaperBtn, SIGNAL(clicked()), signalMapper, SLOT(map()));
175     connect(ui->printOnMarkPaperBtn, SIGNAL(clicked()), signalMapper, SLOT(map()));
176     connect(ui->printWithAutoMarkPaperBtn, SIGNAL(clicked()), signalMapper, SLOT(map()));
177     signalMapper->setMapping(ui->markPaperBtn,0 );
178     signalMapper->setMapping(ui->printOnMarkPaperBtn,1);
179     signalMapper->setMapping(ui->printWithAutoMarkPaperBtn,2 );
180     connect(signalMapper, SIGNAL(mapped(int)),  this, SLOT(fill_docCard4Print(int)));
181
182}
183
184void StartDlg::changeEvent(QEvent *e)
185{
186    QDialog::changeEvent(e);
187    switch (e->type()) {
188    case QEvent::LanguageChange:
189        ui->retranslateUi(this);
190        break;
191    default:
192        break;
193    }
194}