From bf1318c4f954e14196ff7b4e72e252cdbce175db Mon Sep 17 00:00:00 2001 From: konrad Date: Sun, 7 Dec 2008 15:23:12 +0000 Subject: [PATCH] *few fixes for ticket rendering *make printer remember ticket and voucher print settings git-svn-id: https://silmor.de/svn/softmagic/smoke/trunk@208 6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33 --- src/orderwin.cpp | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ src/orderwin.h | 5 +++++ src/ticketrender.cpp | 2 ++ 3 files changed, 55 insertions(+), 0 deletions(-) diff --git a/src/orderwin.cpp b/src/orderwin.cpp index fd27ac8..b3e4d61 100644 --- a/src/orderwin.cpp +++ b/src/orderwin.cpp @@ -34,6 +34,7 @@ #include #include #include +#include #include #include #include @@ -266,8 +267,10 @@ void MOrderWindow::printTickets(QList ticketsin) } //get printer settings QPrinter printer; + restorePrinter(printer,"ticket"); 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)); @@ -305,8 +308,10 @@ void MOrderWindow::printVouchers(QList vouchersin) } //get printer settings QPrinter printer; + restorePrinter(printer,"voucher"); 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)); @@ -323,6 +328,49 @@ void MOrderWindow::printVouchers(QList vouchersin) } } +void MOrderWindow::restorePrinter(QPrinter&prn,QString key) +{ + QSettings set; + set.beginGroup(req->settingsGroup()+"/"+key); + if(!set.contains("name"))return; + prn.setPrinterName(set.value("name").toString()); +#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()); +} + +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 diff --git a/src/orderwin.h b/src/orderwin.h index 8574f98..f08e6ac 100644 --- a/src/orderwin.h +++ b/src/orderwin.h @@ -125,6 +125,11 @@ class MOrderWindow:public QMainWindow }printBuffer; void initPrintBuffer(); void donePrintBuffer(); + + //helper: fetches printer settings from registry + void restorePrinter(QPrinter&,QString); + //helper: stores printer settings in registry + void storePrinter(QPrinter&,QString); }; class MTicketRenderer; diff --git a/src/ticketrender.cpp b/src/ticketrender.cpp index aef8094..5eba63c 100644 --- a/src/ticketrender.cpp +++ b/src/ticketrender.cpp @@ -151,6 +151,7 @@ void MLabelRendererPrivate::prepare(QUnZip&temp) continue; } QBuffer buffer; + buffer.open(QBuffer::ReadWrite); temp.getCurrentFile(buffer); int fid=QFontDatabase::addApplicationFontFromData(buffer.data()); if(fid<0){ @@ -179,6 +180,7 @@ void MLabelRendererPrivate::prepare(QUnZip&temp) return; } QBuffer buffer; + buffer.open(QBuffer::ReadWrite); temp.getCurrentFile(buffer); QImage img; if(!img.loadFromData(buffer.data())){ -- 1.7.2.5