QPrinter printer;
MLabelConfig lconf(MLabelConfig::Ticket);
lconf.selectPrinter(printer);
- QPrintDialog pd(&printer,this);
- if(pd.exec()!=QDialog::Accepted)return;
-// storePrinter(printer,"ticket");
//label arrangement
MTicketRenderer render(tf);
MLabelDialog ld(this,&printer,tickets.size(),render.labelSize(printer));
- if(ld.exec()!=QDialog::Accepted)
+ if(!ld.conditionalExec(MLabelConfig::Ticket))
return;
//print
QPainter painter(&printer);
QPrinter printer;
MLabelConfig lconf(MLabelConfig::Voucher);
lconf.selectPrinter(printer);
- QPrintDialog pd(&printer,this);
- if(pd.exec()!=QDialog::Accepted)return;
-// storePrinter(printer,"voucher");
//label arrangement
MVoucherRenderer render(tf);
MLabelDialog ld(this,&printer,vouchers.size(),render.labelSize(printer));
- if(ld.exec()!=QDialog::Accepted)
+ if(!ld.conditionalExec(MLabelConfig::Voucher))
return;
//print
QPainter painter(&printer);
}
}
-/*
-void MOrderWindow::restorePrinter(QPrinter&prn,QString key)
-{
-#if !defined(Q_OS_WIN32) && !defined(Q_OS_WINCE)
- QSettings set;
- set.beginGroup(req->settingsGroup()+"/"+key);
- if(!set.contains("name"))return;
- prn.setPrinterName(set.value("name").toString());
- prn.setPrinterSelectionOption(set.value("soption","").toString());
- prn.setPaperSize(QPrinter::PageSize(set.value("paper",QPrinter::Custom).toInt()));
- prn.setPaperSize(set.value("papersize").toSizeF(),QPrinter::Point);
- qreal ml,mr,mt,mb;
- ml=set.value("marginLeft").toDouble();
- mr=set.value("marginRight").toDouble();
- mb=set.value("marginBottom").toDouble();
- mt=set.value("marginTop").toDouble();
- prn.setPageMargins(ml,mr,mb,mt,QPrinter::Point);
- prn.setDuplex(QPrinter::DuplexMode(set.value("duplex",QPrinter::DuplexAuto).toInt()));
- prn.setOrientation((set.value("orientation","portrait").toString()=="portrait")?QPrinter::Portrait:QPrinter::Landscape);
- prn.setResolution(set.value("resolution").toInt());
-#endif
-}
-
-void MOrderWindow::storePrinter(QPrinter&prn,QString key)
-{
- QSettings set;
- set.beginGroup(req->settingsGroup()+"/"+key);
- set.setValue("name",prn.printerName());
-#if !defined(Q_OS_WIN32) && !defined(Q_OS_WINCE)
- set.setValue("soption",prn.printerSelectionOption());
-#endif
- qreal ml,mr,mt,mb;
- prn.getPageMargins(&ml,&mr,&mb,&mt,QPrinter::Point);
- set.setValue("marginLeft",ml);
- set.setValue("marginRight",mr);
- set.setValue("marginBottom",mb);
- set.setValue("marginTop",mt);
- set.setValue("duplex",(int)prn.duplex());
- set.setValue("orientation",prn.orientation()==QPrinter::Portrait?"portrait":"landscape");
- set.setValue("paper",(int)prn.paperSize());
- set.setValue("papersize",prn.paperSize(QPrinter::Point));
- set.setValue("resolution",prn.resolution());
-}
-*/
-
void MOrderWindow::printBill()
{
//get template
return maxrows<=1 && maxcols<=1;
}
-bool MLabelDialog::conditionalExec(MLabelConfig::LabelType)
+bool MLabelDialog::conditionalExec(MLabelConfig::LabelType lt)
{
- //TODO: check config
- if(oneLabelPerPage())return true;
- return exec()==Accepted;
+ //check config
+ bool doexec=false;
+ switch(MLabelConfig(lt).pageAskMode()){
+ case MLabelConfig::PageAskAlways:doexec=true;break;
+ case MLabelConfig::PageAskIfNeeded:doexec=!oneLabelPerPage();break;
+ case MLabelConfig::PageAskNever:return true;
+ }
+ //execute, or not
+ if(doexec)
+ return exec()==Accepted;
+ else
+ return true;
}
void MLabelDialog::toggleRow(int r)
void MLabelConfig::configDialog(QWidget* parent)
{
QDialog d(parent);
+ MLabelConfig ticket(MLabelConfig::Ticket),voucher(MLabelConfig::Voucher);
d.setWindowTitle(tr("Label Configuration"));
QFormLayout*fl;
d.setLayout(fl=new QFormLayout);
t_prnmode->addItem(tr("Always ask for printer"),PrintAskAlways);
t_prnmode->addItem(tr("Ask if unknown or not present"),PrintAskIfUnknown);
t_prnmode->addItem(tr("Never ask for printer"),PrintAskNever);
+ t_prnmode->setCurrentIndex(ticket.printAskMode());
fl->addRow(tr("Page Dialog:"),t_pagmode=new QComboBox);
t_pagmode->addItem(tr("Always ask for page layout"),PageAskAlways);
t_pagmode->addItem(tr("Ask if more than one label per page"),PageAskIfNeeded);
t_pagmode->addItem(tr("Never ask for page layout"),PageAskNever);
+ t_pagmode->setCurrentIndex(ticket.pageAskMode());
QHBoxLayout*hl;
QLabel*t_prn;QMap<QString,QVariant>t_prnset;
QToolButton*p;
+ QPrinter t_printer;
+ ticket.configurePrinter(t_printer);
fl->addRow(tr("Printer:"),hl=new QHBoxLayout);
- hl->addWidget(t_prn=new QLabel("printer"),1);
+ hl->addWidget(t_prn=new QLabel(ticket.printerName()),1);
hl->addWidget(p=new QToolButton);
p->setText("...");
MLambda settprn([&]{
- QPrintDialog pd(&d);
+ QPrintDialog pd(&t_printer,&d);
if(pd.exec()!=QDialog::Accepted)return;
- t_prn->setText(pd.printer()->printerName());
+ t_prn->setText(t_printer.printerName());
});
d.connect(p,SIGNAL(clicked()),&settprn,SLOT(call()));
QFrame*frm;
v_prnmode->addItem(tr("Always ask for printer"),PrintAskAlways);
v_prnmode->addItem(tr("Ask if unknown or not present"),PrintAskIfUnknown);
v_prnmode->addItem(tr("Never ask for printer"),PrintAskNever);
+ v_prnmode->setCurrentIndex(voucher.printAskMode());
fl->addRow(tr("Page Dialog:"),v_pagmode=new QComboBox);
v_pagmode->addItem(tr("Always ask for page layout"),PageAskAlways);
v_pagmode->addItem(tr("Ask if more than one label per page"),PageAskIfNeeded);
v_pagmode->addItem(tr("Never ask for page layout"),PageAskNever);
+ v_pagmode->setCurrentIndex(voucher.pageAskMode());
QLabel*v_prn;QMap<QString,QVariant>v_prnset;
+ QPrinter v_printer;
+ voucher.configurePrinter(v_printer);
fl->addRow(tr("Printer:"),hl=new QHBoxLayout);
- hl->addWidget(v_prn=new QLabel("printer"),1);
+ hl->addWidget(v_prn=new QLabel(voucher.printerName()),1);
hl->addWidget(p=new QToolButton);
p->setText("...");
MLambda setvprn([&]{
- QPrintDialog pd(&d);
+ QPrintDialog pd(&v_printer,&d);
if(pd.exec()!=QDialog::Accepted)return;
v_prn->setText(pd.printer()->printerName());
});
hl->addWidget(b=new QPushButton(tr("Cancel")));
d.connect(b,SIGNAL(clicked()),&d,SLOT(reject()));
//show dialog
- d.exec();
- //TODO: save settings
+ if(d.exec()!=QDialog::Accepted)return;
+ //save settings
+ ticket.storePrinter(t_printer);
+ ticket.storeAskModes(
+ (MLabelConfig::PrintAskMode)t_prnmode->currentIndex(),
+ (MLabelConfig::PageAskMode)t_pagmode->currentIndex()
+ );
+ voucher.storePrinter(v_printer);
+ voucher.storeAskModes(
+ (MLabelConfig::PrintAskMode)v_prnmode->currentIndex(),
+ (MLabelConfig::PageAskMode)v_pagmode->currentIndex()
+ );
}
QString MLabelConfig::tr(const char* s, const char* c)
bool gotit=configurePrinter(printer);
if(!force)
switch(printAskMode()){
- case PageAskAlways:force=true;break;
- case PageAskIfNeeded:if(!gotit)force=true;break;
- case PageAskNever:/*do not override the force*/ break;
+ case PrintAskAlways:force=true;break;
+ case PrintAskIfUnknown:if(!gotit)force=true;break;
+ case PrintAskNever:/*do not override the force*/ break;
}
if(force){
QPrintDialog pd(&printer);
return gotit;
}
-bool MLabelConfig::configurePrinter(QPrinter&prn ) const
+QString MLabelConfig::cgroup() const
{
QString key=m_type==Ticket?"ticket":"voucher";
+ return req->settingsGroup()+"/"+key;
+}
+
+bool MLabelConfig::configurePrinter(QPrinter&prn ) const
+{
QSettings set;
- set.beginGroup(req->settingsGroup()+"/"+key);
+ set.beginGroup(cgroup());
if(!set.contains("name"))return false;
QString pname=set.value("name").toString();
bool found=false;
return true;
}
-void MLabelConfig::storePrinter(QPrinter& prn) const
+void MLabelConfig::storePrinter(QPrinter& prn)
{
- QString key=m_type==Ticket?"ticket":"voucher";
QSettings set;
- set.beginGroup(req->settingsGroup()+"/"+key);
+ set.beginGroup(cgroup());
set.setValue("name",prn.printerName());
#if !defined(Q_OS_WIN32) && !defined(Q_OS_WINCE)
set.setValue("soption",prn.printerSelectionOption());
MLabelConfig::PageAskMode MLabelConfig::pageAskMode() const
{
- //TODO: implement
- return PageAskAlways;
+ QSettings set;
+ set.beginGroup(cgroup());
+ return PageAskMode(set.value("pageAskMode",PageAskIfNeeded).toInt());
}
MLabelConfig::PrintAskMode MLabelConfig::printAskMode() const
{
- //TODO: implement
- return PrintAskAlways;
+ QSettings set;
+ set.beginGroup(cgroup());
+ return PrintAskMode(set.value("printAskMode",PrintAskIfUnknown).toInt());
+}
+
+void MLabelConfig::storeAskModes(MLabelConfig::PrintAskMode prm, MLabelConfig::PageAskMode pgm)
+{
+ QSettings set;
+ set.beginGroup(cgroup());
+ set.setValue("printAskMode",(int)prm);
+ set.setValue("pageAskMode",(int)pgm);
}