*few fixes for ticket rendering
authorkonrad <konrad@6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33>
Sun, 7 Dec 2008 15:23:12 +0000 (15:23 +0000)
committerkonrad <konrad@6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33>
Sun, 7 Dec 2008 15:23:12 +0000 (15:23 +0000)
*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
src/orderwin.h
src/ticketrender.cpp

index fd27ac8..b3e4d61 100644 (file)
@@ -34,6 +34,7 @@
 #include <QPrintDialog>
 #include <QPrinter>
 #include <QPushButton>
+#include <QSettings>
 #include <QStandardItemModel>
 #include <QTableView>
 #include <QTextEdit>
@@ -266,8 +267,10 @@ void MOrderWindow::printTickets(QList<MTicket> 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<MVoucher> 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<MVoucher> 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
index 8574f98..f08e6ac 100644 (file)
@@ -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;
index aef8094..5eba63c 100644 (file)
@@ -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())){