move label dialogs; yet untested
authorKonrad Rosenbaum <konrad@silmor.de>
Mon, 16 Jan 2012 18:08:24 +0000 (19:08 +0100)
committerKonrad Rosenbaum <konrad@silmor.de>
Mon, 16 Jan 2012 18:08:24 +0000 (19:08 +0100)
src/dialogs/orderwin.cpp
src/dialogs/orderwin.h
src/templates/labeldlg.cpp
src/templates/labeldlg.h

index e1d3170..82fa970 100644 (file)
@@ -341,13 +341,10 @@ void MOrderWindow::printTickets(QList<MOTicket> ticketsin)
        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);
@@ -383,13 +380,10 @@ void MOrderWindow::printVouchers(QList<MOVoucher> vouchersin)
        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);
@@ -402,51 +396,6 @@ void MOrderWindow::printVouchers(QList<MOVoucher> vouchersin)
        }
 }
 
-/*
-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
index 446a801..02da7ac 100644 (file)
@@ -128,11 +128,6 @@ 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 0811de4..c6c44b8 100644 (file)
@@ -236,11 +236,20 @@ bool MLabelDialog::oneLabelPerPage() const
        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)
@@ -342,6 +351,7 @@ void MLabelDialog::saveSettings()
 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);
@@ -352,21 +362,25 @@ void MLabelConfig::configDialog(QWidget* parent)
        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;
@@ -380,17 +394,21 @@ void MLabelConfig::configDialog(QWidget* parent)
        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());
        });
@@ -405,8 +423,18 @@ void MLabelConfig::configDialog(QWidget* parent)
        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)
@@ -428,9 +456,9 @@ 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;
+               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);
@@ -439,11 +467,16 @@ bool MLabelConfig::selectPrinter(QPrinter& printer, bool force)
                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;
@@ -472,11 +505,10 @@ bool MLabelConfig::configurePrinter(QPrinter&prn ) const
        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());
@@ -497,12 +529,22 @@ void MLabelConfig::storePrinter(QPrinter& prn) const
 
 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);
 }
index b746b73..ff9537e 100644 (file)
@@ -66,6 +66,8 @@ class MLabelConfig
                
                ///whether to ask for a printer when printing labels
                enum PrintAskMode{
+                       //do not change the order of these entries!
+                       //their numerical value is used as index in configDialog()
                        ///always ask for a printer
                        PrintAskAlways=0,
                        ///only ask if the currently set printer is not known/connected
@@ -75,6 +77,8 @@ class MLabelConfig
                };
                ///whether to ask for the page layout when printing labels
                enum PageAskMode{
+                       //do not change the order of these entries!
+                       //their numerical value is used as index in configDialog()
                        ///always ask
                        PageAskAlways=0,
                        ///only ask if there are more than 1 labels on the page
@@ -94,7 +98,11 @@ class MLabelConfig
                static QString tr(const char*,const char*c=0);
                
                /// \internal helper to store printer settings for next time
-               void storePrinter(QPrinter&)const;
+               void storePrinter(QPrinter&);
+               /// \internal helper to store ask modes
+               void storeAskModes(PrintAskMode,PageAskMode);
+               /// \internal return the config group
+               QString cgroup()const;
 };
 
 ///dialog that allows to select which labels on a sheet of paper are used