From 2c5ce25ca6727787149d3e839ab4ee817a66835b Mon Sep 17 00:00:00 2001 From: konrad Date: Sun, 5 Dec 2010 11:22:16 +0000 Subject: [PATCH] display layout of label editor git-svn-id: https://silmor.de/svn/softmagic/smoke/trunk@650 6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33 --- src/templates/templatedlg.cpp | 56 ++++------- src/templates/ticketedit.cpp | 216 +++++++++++++++++++++++++++++++++++++++-- src/templates/ticketedit.h | 8 +- 3 files changed, 234 insertions(+), 46 deletions(-) diff --git a/src/templates/templatedlg.cpp b/src/templates/templatedlg.cpp index 3fd5b21..5e70b96 100644 --- a/src/templates/templatedlg.cpp +++ b/src/templates/templatedlg.cpp @@ -29,6 +29,7 @@ MTemplateChoice::MTemplateChoice(const QString&cd,const QString&tname,const QStr :sgroup(sg),cachedir(cd) { setWindowTitle(tr("Chose Template")); + setSizeGripEnabled(true); QVBoxLayout *vl; setLayout(vl=new QVBoxLayout); vl->addWidget(new QLabel(tr("Please chose a variant of template %1:").arg(tname))); @@ -72,6 +73,7 @@ MTemplateEditor::MTemplateEditor(MTemplateStore*s) nochange=false; setWindowTitle(tr("Edit Template Directory")); + setSizeGripEnabled(true); QHBoxLayout*hl; QVBoxLayout*vl,*vl2; @@ -250,46 +252,28 @@ void MTemplateEditor::editItem() QString fn=model->data(bidx,NAMEROLE).toString(); qDebug()<<"editing base"<getTemplateByFile(fn); - MTemplate::Type tp=tmp.type(); - if(tp&MTemplate::OdfTemplateMask){ - QMessageBox::warning(this,"Sorry","Sorry, no ODF editor yet."); - }else - if(tp==MTemplate::LabelTemplate){ - MTicketEditor *ed=new MTicketEditor(this); - ed->loadFile(tmp.cacheFileName()); - ed->show(); - }else - if(tp==MTemplate::ZipTemplate){ - QMessageBox::warning(this,"Sorry","Sorry, no ZIP selection"); - }else{ - QMessageBox::warning(this,tr("Warning"),tr("Unknown template type, cannot edit it.")); - } + tmp=store->getTemplateByFile(fn); + tp=tmp.type(); }else{ + tp=MTemplate::legalTypes(base); } - /*QString ext=QFileInfo(fn).completeSuffix(); - if(!MTemplate::legalSuffixes(base).contains(ext)){ - QMessageBox::warning(this,tr("Warning"),tr("Files with this extension (%1) are not legal for this template.").arg(ext)); - return; - } - //get new variant name - QStringList lst; - for(int i=0;irowCount(pidx);i++){ - QStringList f=model->data(model->index(i,0,pidx),NAMEROLE).toString().split(","); - if(f.size()>1) - lst<loadFile(tmp.cacheFileName()); + ed->show(); + }else + if(tp==MTemplate::ZipTemplate){ + QMessageBox::warning(this,"Sorry","Sorry, no ZIP selection"); + }else{ + QMessageBox::warning(this,tr("Warning"),tr("Unknown template type, cannot edit it.")); } - //send up - if(store->setTemplate(base+"."+ext+","+nvar,fn)) - forceUpdate(); - else - QMessageBox::warning(this,tr("Warning"),tr("Unable to upload file."));*/ } void MTemplateEditor::saveItem() diff --git a/src/templates/ticketedit.cpp b/src/templates/ticketedit.cpp index b357367..08688ce 100644 --- a/src/templates/ticketedit.cpp +++ b/src/templates/ticketedit.cpp @@ -12,11 +12,63 @@ #include "ticketedit.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include #include #include -#include +#include +#include +#include +#include +#include #include -#include +#include +#include +#include + +class DPTR_CLASS_NAME(MTicketEditor) +{ + public: + //template file + QString mFileName; + //file contents + QMapmFiles; + QString mUnit; + QSizeF mSize; + enum Type{ + Unknown, + LoadFont, + Picture, + Text, + Barcode + }; + struct Line_s{ + Type type; + QSizeF size; + QPointF offset; + QString file; + bool smooth; + QString font; + double fontsize; + Qt::Alignment align; + }; + QListmLines; + //widgets + QDoubleSpinBox*labelwidth,*labelheight; + QComboBox*unitbox; + QTableView*itemtable,*filetable; + QStandardItemModel*itemmodel,*filemodel; + QWidget*labelpicture; +}; + +DEFINE_DPTR(MTicketEditor); MTicketEditor::MTicketEditor(QWidget* parent, Qt::WindowFlags f): QMainWindow(parent, f) { @@ -34,32 +86,146 @@ MTicketEditor::MTicketEditor(QWidget* parent, Qt::WindowFlags f): QMainWindow(pa m=mb->addMenu(tr("&Edit")); m->addAction(tr("Add Item")); m->addAction(tr("Delete Item")); + m->addSeparator(); + m->addAction(tr("Add File")); + m->addAction(tr("Delete File")); + + //central + QSplitter*central=new QSplitter(Qt::Vertical); + setCentralWidget(central); + QWidget*w=new QWidget; + central->addWidget(w); + QVBoxLayout*vl; + QHBoxLayout*hl; + w->setLayout(vl=new QVBoxLayout); + vl->addLayout(hl=new QHBoxLayout,0); + hl->addWidget(new QLabel(tr("Label Size:"))); + hl->addWidget(d->labelwidth=new QDoubleSpinBox); + hl->addWidget(new QLabel("x")); + hl->addWidget(d->labelheight=new QDoubleSpinBox); + hl->addWidget(d->unitbox=new QComboBox); + d->unitbox->addItem(tr("Millimeter"),"mm"); + d->unitbox->addItem(tr("Inch"),"in"); + hl->addStretch(1); + vl->addWidget(d->itemtable=new QTableView); + d->itemtable->setModel(d->itemmodel=new QStandardItemModel(this)); + d->itemtable->horizontalHeader()->show(); + d->itemtable->verticalHeader()->hide(); + QSplitter*split; + central->addWidget(split=new QSplitter); + split->addWidget(d->filetable=new QTableView); + d->filetable->setModel(d->filemodel=new QStandardItemModel(this)); + split->addWidget(d->labelpicture=new QWidget); + d->filetable->horizontalHeader()->show(); + d->filetable->verticalHeader()->hide(); //statusbar statusBar()->setSizeGripEnabled(true); setAttribute(Qt::WA_DeleteOnClose); } -void MTicketEditor::loadFile(QString ) +void MTicketEditor::loadFile(QString fn) +{ + //try to open the file + if(fn=="")return; + QFile fd(fn); + if(!fd.open(QIODevice::ReadOnly)){ + QMessageBox::warning(this, tr("Error"), tr("Unable to open file '%1' for reading.").arg(fn)); + return; + } + QUnZip unz; + if(!unz.open(&fd)){ + QMessageBox::warning(this, tr("Error"), tr("Unable to interpret file '%1'.").arg(fn)); + return; + } + //clear cache + d->mFiles.clear(); + d->mLines.clear(); + //read data + unz.gotoFirstFile(); + do{ + QString ifn; + unz.getCurrentFileInfo(ifn,0); + QBuffer buf;buf.open(QIODevice::ReadWrite); + unz.getCurrentFile(buf); + if(ifn=="template.xml") + parseTemplate(buf.data()); + else + d->mFiles.insert(ifn,buf.data()); + }while(unz.gotoNextFile()); + //update display + updateDisplay(); +} + +static inline QSizeF str2size(QString s) +{ + QStringList sl=s.trimmed().split(" "); + if(sl.size()!=2)return QSizeF(); + return QSizeF(sl[0].toDouble(),sl[1].toDouble()); +} + +static inline QPointF str2point(QString s) { + QStringList sl=s.trimmed().split(" "); + if(sl.size()!=2)return QPointF(); + return QPointF(sl[0].toDouble(),sl[1].toDouble()); +} +void MTicketEditor::parseTemplate(QByteArray bytes) +{ + QDomDocument doc; + if(!doc.setContent(bytes)){ + QMessageBox::warning(this,tr("Warning"),tr("Unable to interpret template data.")); + return; + } + QDomElement root=doc.documentElement(); + d->mSize=str2size(root.attribute("size")); + d->mUnit=root.attribute("unit","mm"); + QDomNodeList nl=root.childNodes(); + for(int i=0;imLines.append(line); + } } void MTicketEditor::openFile() { QString fn=QFileDialog::getOpenFileName(this,tr("Open Ticket Template")); if(fn!=""){ - mFileName=fn; + d->mFileName=fn; loadFile(fn); } } void MTicketEditor::saveFile() { - if(mFileName.left(2)==":/" || mFileName=="") + if(d->mFileName=="" || d->mFileName.left(2)==":/") saveFileAs(); else - saveFile(mFileName); + saveFile(d->mFileName); } void MTicketEditor::saveFile ( QString ) { @@ -67,9 +233,9 @@ void MTicketEditor::saveFile ( QString ) } void MTicketEditor::saveFileAs() { - QString fn=QFileDialog::getSaveFileName(this,tr("Save Ticket Template"),mFileName); + QString fn=QFileDialog::getSaveFileName(this,tr("Save Ticket Template"),d->mFileName); if(fn!=""){ - mFileName=fn; + d->mFileName=fn; saveFile(fn); } } @@ -82,6 +248,40 @@ void MTicketEditor::upload() } +void MTicketEditor::updateDisplay() +{ + if(d->mFileName=="") + setWindowTitle(tr("Label Template Editor")); + else + setWindowTitle(tr("Label Template Editor [%1]").arg(d->mFileName)); + //basics + d->labelwidth->setValue(d->mSize.width()); + d->labelheight->setValue(d->mSize.height()); + for(int i=0;iunitbox->count();i++) + if(d->unitbox->itemData(i).toString()==d->mUnit) + d->unitbox->setCurrentIndex(i); + //files + d->filemodel->clear(); + if(d->filemodel->columnCount()<2) + d->filemodel->insertColumns(0,2); + d->filemodel->setHorizontalHeaderLabels(QStringList()<itemmodel->clear(); + if(d->itemmodel->columnCount()==0) + d->itemmodel->insertColumns(0,5); + d->itemmodel->setHorizontalHeaderLabels(QStringList() + < +#include + +#include "dptr.h" /**An editor for ticket templates.*/ class MTicketEditor:public QMainWindow { Q_OBJECT + DECLARE_DPTR(d); public: ///instantiates the editor MTicketEditor(QWidget* parent = 0, Qt::WindowFlags f = 0); @@ -40,8 +44,8 @@ class MTicketEditor:public QMainWindow void upload(); private slots: void rerender(); - private: - QString mFileName; + void parseTemplate(QByteArray); + void updateDisplay(); }; #endif -- 1.7.2.5