if(ld.labelNeedsPageTurn(i)){
printer.newPage();
}
- render.render(tickets[i],printer,&painter,p);
+ render.render(tickets[i],printer,&painter,p,lconf.printMode()==MLabelConfig::PrintPixmap);
}
}
if(ld.labelNeedsPageTurn(i)){
printer.newPage();
}
- render.render(vouchers[i],printer,&painter,p);
+ render.render(vouchers[i],printer,&painter,p,lconf.printMode()==MLabelConfig::PrintPixmap);
}
}
void changeInvAddr();
///change the delivery address
void changeDelAddr();
- ///view/change customer data
- void changeCustData();
+ ///view/change customer data
+ void changeCustData();
/**cancel the order*/
void cancelOrder();
d.setLayout(fl=new QFormLayout);
fl->addRow(new QLabel(tr("Ticket Labels:")));
//each one: ask printer mode, ask label-page mode, printer/settings
- QComboBox*t_prnmode,*t_pagmode;
+ QComboBox*t_prnmode,*t_pagmode,*t_prnbufmode;
fl->addRow(tr("Print Dialog:"),t_prnmode=new QComboBox);
t_prnmode->addItem(tr("Always ask for printer"),PrintAskAlways);
t_prnmode->addItem(tr("Ask if unknown or not present"),PrintAskIfUnknown);
t_prn->setText(t_printer.printerName());
};
d.connect(p,&QToolButton::clicked,settprn);
+ fl->addRow(tr("Print Mode:"),t_prnbufmode=new QComboBox);
+ t_prnbufmode->addItem(tr("Direct Print"));
+ t_prnbufmode->addItem(tr("Use Buffer Pixmap"));
+ t_prnbufmode->setCurrentIndex((int)ticket.printMode());
QFrame*frm;
fl->addRow(frm=new QFrame);
frm->setFrameStyle(QFrame::HLine|QFrame::Sunken);
//Vouchers...
fl->addRow(new QLabel(tr("Voucher Labels:")));
//each one: ask printer mode, ask label-page mode, printer/settings
- QComboBox*v_prnmode,*v_pagmode;
+ QComboBox*v_prnmode,*v_pagmode,*v_prnbufmode;
fl->addRow(tr("Print Dialog:"),v_prnmode=new QComboBox);
v_prnmode->addItem(tr("Always ask for printer"),PrintAskAlways);
v_prnmode->addItem(tr("Ask if unknown or not present"),PrintAskIfUnknown);
v_prn->setText(v_printer.printerName());
};
d.connect(p,&QToolButton::clicked,setvprn);
+ fl->addRow(tr("Print Mode:"),v_prnbufmode=new QComboBox);
+ v_prnbufmode->addItem(tr("Direct Print"));
+ v_prnbufmode->addItem(tr("Use Buffer Pixmap"));
+ v_prnbufmode->setCurrentIndex((int)voucher.printMode());
//button...
fl->addRow(new QLabel(" "));
fl->addRow(hl=new QHBoxLayout);
(MLabelConfig::PrintAskMode)t_prnmode->currentIndex(),
(MLabelConfig::PageAskMode)t_pagmode->currentIndex()
);
+ ticket.storePrintMode((MLabelConfig::PrintMode)t_prnbufmode->currentIndex());
voucher.storePrinter(v_printer);
voucher.storeAskModes(
(MLabelConfig::PrintAskMode)v_prnmode->currentIndex(),
(MLabelConfig::PageAskMode)v_pagmode->currentIndex()
);
+ voucher.storePrintMode((MLabelConfig::PrintMode)v_prnbufmode->currentIndex());
}
QString MLabelConfig::tr(const char* s, const char* c)
set.setValue("pageAskMode",(int)pgm);
}
+MLabelConfig::PrintMode MLabelConfig::printMode() const
+{
+ QSettings set;
+ set.beginGroup(cgroup());
+ return PrintMode(set.value("printBufMode",PrintDirect).toInt());
+}
+
+void MLabelConfig::storePrintMode ( MLabelConfig::PrintMode pm )
+{
+ QSettings set;
+ set.beginGroup(cgroup());
+ set.setValue("printBufMode",(int)pm);
+}
+
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
struct Paper_s {
///returns the policy for asking for page layout
PageAskMode pageAskMode()const;
+
+ ///how to send data to the printer
+ enum PrintMode{
+ //do not change the order of these entries!
+ //their numerical value is used as index in configDialog()
+ ///print directly through the printer driver
+ PrintDirect=0,
+ ///use a buffer pixmap to render fonts/graphics in memory first
+ PrintPixmap=1
+ };
+
+ ///returns how to send data to the printer
+ PrintMode printMode()const;
private:
LabelType m_type;
void storePrinter(QPrinter&);
/// \internal helper to store ask modes
void storeAskModes(PrintAskMode,PageAskMode);
+ /// \internal helper to store print mode
+ void storePrintMode(PrintMode);
/// \internal return the config group
QString cgroup()const;
};
+///Dialog that allows to configure details on how to print a label.
class MLabelPrintDialog:public QDialog
{
Q_OBJECT
//converts a size to "natural" coordinates
QSizeF tonatural(const QPaintDevice&,QSizeF);
+
+ //converts a size to "natural" coordinates
+ QSizeF tonatural(int dpi,QSizeF);
//returns a system font name
QString getfont(QString);
QFontDatabase::removeApplicationFont(fdb[i]);
}
-bool MLabelRenderer::render(const MLabel&ticket,QPaintDevice&pdev,QPainter*painter,QPointF offset)
+bool MLabelRenderer::render(const MLabel&label,QPaintDevice&pdev,QPainter*painter,QPointF offset,bool usePixmap)
{
- return d->render(ticket,pdev,painter,offset);
+ bool success=false;
+ if(usePixmap){
+ // create pixmap (assume 600 DPI)
+ QSizeF sz=d->tonatural(600,d->tsize);
+ QImage map(sz.toSize(),QImage::Format_RGB32);
+ map.setDotsPerMeterX(23622);
+ map.setDotsPerMeterY(23622);
+ map.fill(Qt::white);
+ // render to pixmap
+ success=d->render(label,map,nullptr,QPointF());
+ // render to pdev
+ if(success){
+ QPainter*paint=painter;
+ if(!painter)paint=new QPainter(&pdev);
+ QSizeF nsize=d->tonatural(pdev,d->tsize);
+ paint->setClipRect(QRectF(offset,nsize));
+ paint->drawImage(QRectF(offset,nsize).toRect(),map,QRectF(QPointF(),map.size()));
+ if(!painter)delete paint;
+ }
+ }else
+ success=d->render(label,pdev,painter,offset);
+ return success;
}
-bool MLabelRendererPrivate::render(const MLabel&ticket,QPaintDevice&pdev,QPainter*painter,QPointF offset)
+bool MLabelRendererPrivate::render(const MLabel&label,QPaintDevice&pdev,QPainter*painter,QPointF offset)
{
//sanity check
if(!canrender){
}
//actually render
QDomElement el=txml.documentElement();
- render(el,ticket,pdev,painter,offset);
+ render(el,label,pdev,painter,offset);
//return result (canrender may be changed by renderer
return canrender;
}
return s;
}
+QSizeF MLabelRendererPrivate::tonatural(int dpi,QSizeF s)
+{
+ double fac;
+ if(unit=="mm")fac=25.4;
+ else fac=1.0;
+ s.setWidth(s.width()*dpi/fac);
+ s.setHeight(s.height()*dpi/fac);
+ return s;
+}
+
void MLabelRendererPrivate::render(QDomElement&sup, const MLabel&tick, QPaintDevice&pdev, QPainter*painter, QPointF noff)
{
//initialize painter
}
MTicketRenderer::MTicketRenderer(MTemplate f):MLabelRenderer(f){}
-bool MTicketRenderer::render(const MOTicket&label,QPaintDevice&pdev,QPainter*painter,QPointF offset)
+bool MTicketRenderer::render(const MOTicket&label,QPaintDevice&pdev,QPainter*painter,QPointF offset,bool usePixmap)
{
- return MLabelRenderer::render(MTicketLabel(label),pdev,painter,offset);
+ return MLabelRenderer::render(MTicketLabel(label),pdev,painter,offset,usePixmap);
}
class MVoucherLabel:public MLabel
}
MVoucherRenderer::MVoucherRenderer(MTemplate f):MLabelRenderer(f){}
-bool MVoucherRenderer::render(const MOVoucher&label,QPaintDevice&pdev,QPainter*painter,QPointF offset)
+bool MVoucherRenderer::render(const MOVoucher&label,QPaintDevice&pdev,QPainter*painter,QPointF offset,bool usePixmap)
{
- return MLabelRenderer::render(MVoucherLabel(label),pdev,painter,offset);
+ return MLabelRenderer::render(MVoucherLabel(label),pdev,painter,offset,usePixmap);
}
virtual ~MLabelRenderer();
/**renders the ticket; returns whether the rendering was successful*/
- virtual bool render(const MLabel&label,QPaintDevice&pdev,QPainter*painter=0,QPointF offset=QPointF());
+ virtual bool render(const MLabel&label,QPaintDevice&pdev,QPainter*painter=0,QPointF offset=QPointF(),bool usePixmap=false);
/**returns the size of the ticket in the coordinates of the specified paint device (used for preview)*/
virtual QSizeF labelSize(const QPaintDevice&);
{
public:
MVoucherRenderer(MTemplate f);
- bool render(const MOVoucher&label,QPaintDevice&pdev,QPainter*painter=0,QPointF offset=QPointF());
+ bool render(const MOVoucher&label,QPaintDevice&pdev,QPainter*painter=0,QPointF offset=QPointF(),bool usePixmap=false);
};
/**convenience class: renders vouchers directly*/
{
public:
MTicketRenderer(MTemplate f);
- bool render(const MOTicket&label,QPaintDevice&pdev,QPainter*painter=0,QPointF offset=QPointF());
+ bool render(const MOTicket&label,QPaintDevice&pdev,QPainter*painter=0,QPointF offset=QPointF(),bool usePixmap=false);
};