}
//get printer settings
QPrinter printer;
- restorePrinter(printer,"ticket");
+ MLabelConfig lconf(MLabelConfig::Ticket);
+ lconf.selectPrinter(printer);
QPrintDialog pd(&printer,this);
if(pd.exec()!=QDialog::Accepted)return;
- storePrinter(printer,"ticket");
+// storePrinter(printer,"ticket");
//label arrangement
MTicketRenderer render(tf);
MLabelDialog ld(this,&printer,tickets.size(),render.labelSize(printer));
}
//get printer settings
QPrinter printer;
- restorePrinter(printer,"voucher");
+ MLabelConfig lconf(MLabelConfig::Voucher);
+ lconf.selectPrinter(printer);
QPrintDialog pd(&printer,this);
if(pd.exec()!=QDialog::Accepted)return;
- storePrinter(printer,"voucher");
+// storePrinter(printer,"voucher");
//label arrangement
MVoucherRenderer render(tf);
MLabelDialog ld(this,&printer,vouchers.size(),render.labelSize(printer));
}
}
+/*
void MOrderWindow::restorePrinter(QPrinter&prn,QString key)
{
#if !defined(Q_OS_WIN32) && !defined(Q_OS_WINCE)
set.setValue("papersize",prn.paperSize(QPrinter::Point));
set.setValue("resolution",prn.resolution());
}
+*/
void MOrderWindow::printBill()
{
#include "labeldlg.h"
#include "lambda.h"
+#include "msinterface.h"
+
#include <QBoxLayout>
#include <QCheckBox>
#include <QComboBox>
#include <QLineEdit>
#include <QPrintDialog>
#include <QPrinter>
+#include <QPrinterInfo>
#include <QPushButton>
#include <QScrollArea>
#include <QSettings>
v_pagmode->addItem(tr("Never ask for page layout"),PageAskNever);
QLabel*v_prn;QMap<QString,QVariant>v_prnset;
fl->addRow(tr("Printer:"),hl=new QHBoxLayout);
- hl->addWidget(t_prn=new QLabel("printer"),1);
+ hl->addWidget(v_prn=new QLabel("printer"),1);
hl->addWidget(p=new QToolButton);
p->setText("...");
MLambda setvprn([&]{
{
return QCoreApplication::translate("MLabelConfig",s,c);
}
+
+QString MLabelConfig::printerName() const
+{
+ QString key=m_type==Ticket?"ticket":"voucher";
+ QSettings set;
+ set.beginGroup(req->settingsGroup()+"/"+key);
+ if(!set.contains("name"))return QString();
+ return set.value("name").toString();
+}
+
+bool MLabelConfig::selectPrinter(QPrinter& printer, bool force)
+{
+ 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;
+ }
+ if(force){
+ QPrintDialog pd(&printer);
+ return pd.exec()==QDialog::Accepted;
+ }else
+ return gotit;
+}
+
+bool MLabelConfig::configurePrinter(QPrinter&prn ) const
+{
+ QString key=m_type==Ticket?"ticket":"voucher";
+ QSettings set;
+ set.beginGroup(req->settingsGroup()+"/"+key);
+ if(!set.contains("name"))return false;
+ QString pname=set.value("name").toString();
+ bool found=false;
+ for(QPrinterInfo &info : QPrinterInfo::availablePrinters()){
+ if(info.printerName()==pname){
+ found=true;
+ break;
+ }
+ }
+ if(!found)return false;
+ prn.setPrinterName(pname);
+#if !defined(Q_OS_WIN32) && !defined(Q_OS_WINCE)
+ prn.setPrinterSelectionOption(set.value("soption","").toString());
+#endif
+ 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());
+ return true;
+}
+
+void MLabelConfig::storePrinter(QPrinter& prn) const
+{
+ QString key=m_type==Ticket?"ticket":"voucher";
+ 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());
+}
+
+
+MLabelConfig::PageAskMode MLabelConfig::pageAskMode() const
+{
+ //TODO: implement
+ return PageAskAlways;
+}
+
+MLabelConfig::PrintAskMode MLabelConfig::printAskMode() const
+{
+ //TODO: implement
+ return PrintAskAlways;
+}
///configures the QPrinter object to the printer set for this label type;
///use selectPrinter if you want to fall back to a selection dialog
/// \returns true if the printer was successfully configured
- bool configurePrinter(QPrinter*)const;
+ bool configurePrinter(QPrinter&)const;
///configures the printer for this particular label type;
///whether the dialog is shown depends on settings and printer availability;
/// \param printer pointer to the QPrinter object to be configured
/// \param force if true: force showing the printer dialog
/// \returns true if the selection was successful
- bool selectPrinter(QPrinter*printer,bool force=false);
+ bool selectPrinter(QPrinter&printer,bool force=false);
///whether to ask for a printer when printing labels
enum PrintAskMode{
PageAskNever=2,
};
+ ///returns the policy for asking for a printer
+ PrintAskMode printAskMode()const;
+
+ ///returns the policy for asking for page layout
+ PageAskMode pageAskMode()const;
+
private:
LabelType m_type;
static QString tr(const char*,const char*c=0);
+
+ /// \internal helper to store printer settings for next time
+ void storePrinter(QPrinter&)const;
};
///dialog that allows to select which labels on a sheet of paper are used
/// \param printer pointer to the QPrinter object to be configured
/// \param force if true: force showing the printer dialog
/// \returns true if the selection was successful
- static inline bool selectPrinter(MLabelConfig::LabelType type, QPrinter*printer, bool force=false)
+ static inline bool selectPrinter(MLabelConfig::LabelType type, QPrinter&printer, bool force=false)
{return MLabelConfig(type).selectPrinter(printer,force);}
public slots: