finish ticket editor
authorkonrad <konrad@6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33>
Fri, 10 Dec 2010 18:06:12 +0000 (18:06 +0000)
committerkonrad <konrad@6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33>
Fri, 10 Dec 2010 18:06:12 +0000 (18:06 +0000)
git-svn-id: https://silmor.de/svn/softmagic/smoke/trunk@652 6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33

src/images/arrowleft.png [new file with mode: 0644]
src/images/arrowup.png [new file with mode: 0644]
src/images/files.qrc
src/templates/ticketedit.cpp
src/templates/ticketedit.h
src/templates/ticketrender.cpp
src/wext/ticket.cpp
src/wext/ticket.h

diff --git a/src/images/arrowleft.png b/src/images/arrowleft.png
new file mode 100644 (file)
index 0000000..abe8720
Binary files /dev/null and b/src/images/arrowleft.png differ
diff --git a/src/images/arrowup.png b/src/images/arrowup.png
new file mode 100644 (file)
index 0000000..cfb4cdb
Binary files /dev/null and b/src/images/arrowup.png differ
index 4462340..5037087 100644 (file)
@@ -3,6 +3,8 @@
     <qresource>
         <file>icon.png</file>
         <file>arrowright.png</file>
+        <file>arrowleft.png</file>
+        <file>arrowup.png</file>
         <file>arrowdown.png</file>
         <file>arrowdiag.png</file>
     </qresource>
index 4275d16..54e9f7c 100644 (file)
 #include "ticketrender.h"
 
 #include "MOTicket"
-
-#include<QAction>
-#include<QBoxLayout>
-#include<QComboBox>
-#include<QCoreApplication>
-#include<QDateTimeEdit>
-#include<QDomDocument>
-#include<QDomElement>
-#include<QDoubleSpinBox>
-#include<QFileDialog>
-#include<QHeaderView>
-#include<QItemDelegate>
-#include<QLabel>
-#include<QLineEdit>
-#include<QMenu>
-#include<QMenuBar>
-#include<QMessageBox>
-#include<QPointF>
-#include<QSettings>
-#include<QSignalMapper>
-#include<QSizeF>
-#include<QSplitter>
-#include<QStandardItemModel>
-#include<QStatusBar>
-#include<QTableView>
-#include<QTemporaryFile>
-#include<QUnZip>
-#include<QZip>
+#include "MOVoucher"
+
+#include <QAction>
+#include <QBoxLayout>
+#include <QComboBox>
+#include <QCoreApplication>
+#include <QDateTimeEdit>
+#include <QDebug>
+#include <QDomDocument>
+#include <QDomElement>
+#include <QDoubleSpinBox>
+#include <QFileDialog>
+#include <QFontDatabase>
+#include <QHeaderView>
+#include <QInputDialog>
+#include <QItemDelegate>
+#include <QLabel>
+#include <QLineEdit>
+#include <QMenu>
+#include <QMenuBar>
+#include <QMessageBox>
+#include <QPointF>
+#include <QPushButton>
+#include <QScrollArea>
+#include <QSettings>
+#include <QSignalMapper>
+#include <QSizeF>
+#include <QSplitter>
+#include <QStandardItemModel>
+#include <QStatusBar>
+#include <QTableView>
+#include <QTemporaryFile>
+#include <QUnZip>
+#include <QZip>
 
 #define HRECT 1
 #define HFONT 2
@@ -97,17 +103,19 @@ class MTEExampleDelegate:public QItemDelegate
                {editor->setGeometry(option.rect);}
 };
 
-class MTENullDelegate:public QItemDelegate
+class MTELabelDelegate:public QItemDelegate
 {
+       MTicketEditor*mParent;
        public:
-               MTENullDelegate(QObject *parent = 0):QItemDelegate(parent) {}
+               MTELabelDelegate(MTicketEditor *parent):QItemDelegate(parent) 
+               {mParent=parent;}
                QWidget *createEditor(QWidget *, const QStyleOptionViewItem &,
-                       const QModelIndex &) const {return 0;}
-               void setEditorData(QWidget *, const QModelIndex &) const{}
+                       const QModelIndex &) const;
+               void setEditorData(QWidget *, const QModelIndex &) const;
                void setModelData(QWidget *, QAbstractItemModel *,
-                       const QModelIndex &) const {}
-               void updateEditorGeometry(QWidget *,const QStyleOptionViewItem &, 
-                         const QModelIndex &) const {}
+                       const QModelIndex &) const ;
+               void updateEditorGeometry(QWidget *editor,const QStyleOptionViewItem &option, 
+                         const QModelIndex &) const {editor->setGeometry(option.rect);}
 };
 
 class DPTR_CLASS_NAME(MTicketEditor)
@@ -127,6 +135,8 @@ class DPTR_CLASS_NAME(MTicketEditor)
                        Barcode=0x400|HRECT,
                };
                struct Line_s{
+                       Line_s(){type=Unknown;smooth=false;fontsize=0;align=Qt::AlignCenter;}
+                       Line_s(int t){type=(Type)t;smooth=false;fontsize=0;align=Qt::AlignCenter;}
                        Type type;
                        QSizeF size;
                        QPointF offset;
@@ -143,7 +153,8 @@ class DPTR_CLASS_NAME(MTicketEditor)
                QComboBox*unitbox;
                QTableView*itemtable,*filetable,*expltable;
                QStandardItemModel*itemmodel,*filemodel,*explmodel;
-               QWidget*ticketpicture,*voucherpicture;
+               QLabel*ticketpicture;
+               QSlider*zoomslide;
 };
 
 DEFINE_DPTR(MTicketEditor);
@@ -153,20 +164,19 @@ MTicketEditor::MTicketEditor(QWidget* parent, Qt::WindowFlags f): QMainWindow(pa
        //menu
        QMenuBar*mb=menuBar();
        QMenu*m=mb->addMenu(tr("&File"));
-       m->addAction(tr("&Open File..."),this,SLOT(openFile()));
-       m->addAction(tr("&Save"),this,SLOT(saveFile()));
+       m->addAction(tr("&Open File..."),this,SLOT(openFile()))
+        ->setShortcut(QKeySequence(Qt::Key_Control|Qt::Key_O));
+       m->addAction(tr("&Save"),this,SLOT(saveFile()))
+        ->setShortcut(QKeySequence(Qt::Key_Control|Qt::Key_S));
        m->addAction(tr("Save &as..."),this,SLOT(saveFileAs()));
        m->addSeparator();
-       m->addAction(tr("&Download from server..."),this,SLOT(download()));
-       m->addAction(tr("&Upload to server..."),this,SLOT(upload()));
-       m->addSeparator();
        m->addAction(tr("&Close"),this,SLOT(close()));
        m=mb->addMenu(tr("&Edit"));
        QMenu *aim=m->addMenu(tr("Add Item"));
-       m->addAction(tr("Delete Item"),this,SLOT(delItem()));
+       m->addAction(tr("Remove Item"),this,SLOT(delItem()));
        m->addSeparator();
        m->addAction(tr("Add File"),this,SLOT(addFile()));
-       m->addAction(tr("Delete File"),this,SLOT(delFile()));
+       m->addAction(tr("Remove File"),this,SLOT(delFile()));
        QSignalMapper*map=new QSignalMapper(this);
        map->setMapping(aim->addAction(tr("Add Text Item"),map,SLOT(map())),(int)Private::Text);
        map->setMapping(aim->addAction(tr("Add Picture Item"),map,SLOT(map())),(int)Private::Picture);
@@ -179,10 +189,12 @@ MTicketEditor::MTicketEditor(QWidget* parent, Qt::WindowFlags f): QMainWindow(pa
        setCentralWidget(central);
        QWidget*w=new QWidget;
        central->addWidget(w);
-       QVBoxLayout*vl;
-       QHBoxLayout*hl;
+       QVBoxLayout*vl,*vl2;
+       QHBoxLayout*hl,*hl2;
+       QPushButton*p;
        w->setLayout(vl=new QVBoxLayout);
        vl->addLayout(hl=new QHBoxLayout,0);
+       //basic data line
        hl->addWidget(new QLabel(tr("Label Size:")));
        hl->addWidget(d->labelwidth=new QDoubleSpinBox);
        hl->addWidget(new QLabel("x"));
@@ -191,21 +203,62 @@ MTicketEditor::MTicketEditor(QWidget* parent, Qt::WindowFlags f): QMainWindow(pa
        d->unitbox->addItem(tr("Millimeter"),"mm");
        d->unitbox->addItem(tr("Inch"),"in");
        hl->addStretch(1);
-       vl->addWidget(d->itemtable=new QTableView);
+       //item table
+       vl->addWidget(w=new QWidget);
+       w->setLayout(vl2=new QVBoxLayout);
+       vl2->addWidget(d->itemtable=new QTableView,1);
        d->itemtable->setModel(d->itemmodel=new QStandardItemModel(this));
        d->itemtable->horizontalHeader()->show();
        d->itemtable->verticalHeader()->hide();
+       d->itemtable->setItemDelegate(new MTELabelDelegate(this));
+       vl2->addLayout(hl2=new QHBoxLayout,0);
+       hl2->addStretch(1);
+       hl2->addWidget(p=new QPushButton(QIcon(":/arrowup.png"),tr("Move up")),0);
+       connect(p,SIGNAL(clicked()),this,SLOT(upItem()));
+       hl2->addWidget(p=new QPushButton(QIcon(":/arrowdown.png"),tr("Move down")),0);
+       connect(p,SIGNAL(clicked()),this,SLOT(downItem()));
+       hl2->addSpacing(10);
+       hl2->addWidget(p=new QPushButton(tr("Add Item")),0);
+       p->setMenu(aim);
+       hl2->addWidget(p=new QPushButton(tr("Remove Item")),0);
+       connect(p,SIGNAL(clicked()),this,SLOT(delItem()));
+       //bottom
        QSplitter*split;
        central->addWidget(split=new QSplitter);
-       split->addWidget(d->filetable=new QTableView);
+       //file table
+       split->addWidget(w=new QWidget);
+       w->setLayout(vl2=new QVBoxLayout);
+       vl2->addWidget(d->filetable=new QTableView,1);
        d->filetable->setModel(d->filemodel=new QStandardItemModel(this));
        d->filetable->horizontalHeader()->show();
        d->filetable->verticalHeader()->hide();
-       d->filetable->setItemDelegate(new MTENullDelegate(this));
+       d->filetable->setEditTriggers(QAbstractItemView::NoEditTriggers);
+       vl2->addLayout(hl2=new QHBoxLayout,0);
+       hl2->addStretch(1);
+       hl2->addWidget(p=new QPushButton(tr("Add File")),0);
+       connect(p,SIGNAL(clicked()),this,SLOT(addFile()));
+       hl2->addWidget(p=new QPushButton(tr("Remove File")),0);
+       connect(p,SIGNAL(clicked()),this,SLOT(delFile()));
+       //label display
        QTabWidget*tab;
        split->addWidget(tab=new QTabWidget);
-       tab->addTab(d->ticketpicture=new QWidget,tr("As Ticket"));
-       tab->addTab(d->voucherpicture=new QWidget,tr("As Voucher"));
+       tab->addTab(w=new QWidget,tr("As Label"));
+       w->setLayout(vl=new QVBoxLayout);
+       vl->addLayout(hl=new QHBoxLayout,0);
+       hl->addWidget(new QLabel(tr("Zoom:")),0);
+       hl->addWidget(d->zoomslide=new QSlider,1);
+       d->zoomslide->setOrientation(Qt::Horizontal);
+       d->zoomslide->setRange(-10,10);
+       d->zoomslide->setTickPosition(QSlider::TicksBothSides);
+       connect(d->zoomslide,SIGNAL(valueChanged(int)),this,SLOT(rerender()));
+       hl->addWidget(p=new QPushButton(tr("Refresh")),0);
+       connect(p,SIGNAL(clicked()),this,SLOT(rerender()));
+       QScrollArea*sa;
+       vl->addWidget(sa=new QScrollArea,1);
+       sa->setWidget(d->ticketpicture=new QLabel);
+       sa->setWidgetResizable(true);
+       d->ticketpicture->setScaledContents(false);
+       d->ticketpicture->setAlignment(Qt::AlignCenter);
        tab->addTab(d->expltable=new QTableView,tr("Example Data"));
        d->expltable->setModel(d->explmodel=new QStandardItemModel(this));
        d->expltable->setItemDelegate(new MTEExampleDelegate(this));
@@ -322,6 +375,25 @@ static inline QString align2str(Qt::Alignment a)
        }
 }
 
+static inline QString align2xml(Qt::Alignment a)
+{
+       switch(a){
+               case Qt::AlignTop:
+                       return "top";
+               case Qt::AlignBottom:
+                       return "bottom";
+               case Qt::AlignHCenter:
+               case Qt::AlignVCenter:
+                       return "center";
+               case Qt::AlignLeft:
+                       return "left";
+               case Qt::AlignRight:
+                       return "right";
+               default:
+                       return "";
+       }
+}
+
 void MTicketEditor::parseTemplate(QByteArray bytes)
 {
        QDomDocument doc;
@@ -379,9 +451,15 @@ void MTicketEditor::saveFile()
        else
                saveFile(d->mFileName);
 }
-void MTicketEditor::saveFile ( QString )
+void MTicketEditor::saveFile ( QString fn)
 {
-
+       QFile fd(fn);
+       if(!fd.open(QIODevice::ReadWrite|QIODevice::Truncate)){
+               QMessageBox::warning(this,tr("Warning"),tr("Unable to write to file %1").arg(fn));
+               return;
+       }
+       saveTemplate(fd);
+       fd.close();
 }
 void MTicketEditor::saveFileAs()
 {
@@ -391,14 +469,6 @@ void MTicketEditor::saveFileAs()
                saveFile(fn);
        }
 }
-void MTicketEditor::download()
-{
-
-}
-void MTicketEditor::upload()
-{
-
-}
 
 void MTicketEditor::updateDisplay()
 {
@@ -474,6 +544,188 @@ void MTicketEditor::updateDisplay()
        rerender();
 }
 
+QWidget* MTELabelDelegate::createEditor(QWidget* parent, const QStyleOptionViewItem& , const QModelIndex& index) const
+{
+       //get type
+       int tp=index.model()->data(index.model()->index(index.row(),0),Qt::UserRole).toInt();
+       switch(index.column()){
+               case 0:
+                       return 0;
+               case 1:case 2:
+                       if(tp&HRECT){
+                               QLineEdit*ed=new QLineEdit(parent);
+                               ed->setValidator(new QRegExpValidator(QRegExp("^(-?)[0-9\\.]+ (-?)[0-9\\.]+"),ed));
+                               return ed;
+                       }else return 0;
+               case 3:
+                       if(tp&HFONT || tp&HFILE)
+                               return new QComboBox(parent);
+                       else return 0;
+               case 4:
+                       if(tp&HFONT)
+                               return new QDoubleSpinBox(parent);
+                       else return 0;
+               case 5:
+                       if(tp&HSMOOTH)
+                               return new QComboBox(parent);
+                       else return 0;
+               case 6:case 7:
+                       if(tp&HALIGN)
+                               return new QComboBox(parent);
+                       else return 0;
+               case 8:
+                       if(tp&HCONTENT)
+                               return new QLineEdit(parent);
+                       else return 0;
+               default: return 0;
+       }
+}
+
+void MTELabelDelegate::setEditorData(QWidget* editor, const QModelIndex& index) const
+{
+       const QAbstractItemModel*model=index.model();
+       int tp=model->data(model->index(index.row(),0),Qt::UserRole).toInt();
+       int line=index.row();
+       QComboBox*cb;
+       switch(index.column()){
+               case 1:case 2:case 8:
+                       ((QLineEdit*)editor)->setText(model->data(index).toString());
+                       break;
+               case 3:{
+                       cb=(QComboBox*)editor;
+                       QStringList k=mParent->d->mFiles.keys();
+                       qSort(k);
+                       QString c=model->data(index).toString();
+                       if(tp&HFONT){
+                               for(int i=0;i<k.size();i++)
+                                       cb->addItem("@"+k[i]);
+                               k=QFontDatabase().families();
+                               qSort(k);
+                               cb->addItems(k);
+                               for(int i=0;i<cb->count();i++)
+                                       if(cb->itemText(i)==c)
+                                               cb->setCurrentIndex(i);
+                       }else{
+                               cb->addItems(k);
+                               for(int i=0;i<k.size();i++)
+                                       if(c==k[i])
+                                               cb->setCurrentIndex(i);
+                       }
+                       break;
+               }
+               case 4:
+                       ((QDoubleSpinBox*)editor)->setValue(model->data(index).toDouble());
+                       break;
+               case 5:
+                       cb=(QComboBox*)editor;
+                       cb->addItem(tr("edged"));
+                       cb->addItem(tr("smooth"));
+                       cb->setCurrentIndex(mParent->d->mLines[line].smooth?1:0);
+                       break;
+               case 6:
+                       cb=(QComboBox*)editor;
+                       cb->addItem(align2str(Qt::AlignLeft),Qt::AlignLeft);
+                       cb->addItem(align2str(Qt::AlignHCenter),Qt::AlignHCenter);
+                       cb->addItem(align2str(Qt::AlignRight),Qt::AlignRight);
+                       switch(mParent->d->mLines[line].align&Qt::AlignHorizontal_Mask){
+                               case Qt::AlignHCenter:cb->setCurrentIndex(1);break;
+                               case Qt::AlignRight:cb->setCurrentIndex(2);break;
+                               default:break;
+                       }
+                       break;
+               case 7:
+                       cb=(QComboBox*)editor;
+                       cb->addItem(align2str(Qt::AlignTop),Qt::AlignTop);
+                       cb->addItem(align2str(Qt::AlignVCenter),Qt::AlignVCenter);
+                       cb->addItem(align2str(Qt::AlignBottom),Qt::AlignBottom);
+                       switch(mParent->d->mLines[line].align&Qt::AlignVertical_Mask){
+                               case Qt::AlignVCenter:cb->setCurrentIndex(1);break;
+                               case Qt::AlignBottom:cb->setCurrentIndex(2);break;
+                               default:break;
+                       }
+                       break;
+               default:break;
+       }
+}
+
+void MTELabelDelegate::setModelData(QWidget* editor, QAbstractItemModel* model, const QModelIndex& index) const
+{
+       int tp=index.model()->data(index.model()->index(index.row(),0),Qt::UserRole).toInt();
+       QString s;
+       int line=index.row();
+       QComboBox*cb;
+       switch(index.column()){
+               case 1:
+                       s=((QLineEdit*)editor)->text();
+                       mParent->d->mLines[line].offset=str2point(s);
+                       model->setData(index,point2str(mParent->d->mLines[line].offset));
+                       break;
+               case 2:
+                       s=((QLineEdit*)editor)->text();
+                       mParent->d->mLines[line].size=str2size(s);
+                       model->setData(index,size2str(mParent->d->mLines[line].size));
+                       break;
+               case 3:
+                       cb=(QComboBox*)editor;
+                       if(tp&HFONT){
+                               mParent->d->mLines[line].font=cb->currentText();
+                       }else{
+                               mParent->d->mLines[line].file=cb->currentText();
+                       }
+                       model->setData(index,cb->currentText());
+                       break;
+               case 4:
+                       mParent->d->mLines[line].fontsize=((QDoubleSpinBox*)editor)->value();
+                       model->setData(index,mParent->d->mLines[line].fontsize);
+                       break;
+               case 5:
+                       mParent->d->mLines[line].smooth=((QComboBox*)editor)->currentIndex()!=0;
+                       model->setData(index,((QComboBox*)editor)->currentText());
+                       break;
+               case 6:
+                       cb=((QComboBox*)editor);
+                       mParent->d->mLines[line].align&=Qt::AlignVertical_Mask;
+                       mParent->d->mLines[line].align|=Qt::AlignmentFlag(cb->itemData(cb->currentIndex()).toInt());
+                       model->setData(index,cb->currentText());
+                       break;
+               case 7:
+                       cb=((QComboBox*)editor);
+                       mParent->d->mLines[line].align&=Qt::AlignHorizontal_Mask;
+                       mParent->d->mLines[line].align|=Qt::AlignmentFlag(cb->itemData(cb->currentIndex()).toInt());
+                       model->setData(index,cb->currentText());
+                       break;
+               case 8:
+                       s=((QLineEdit*)editor)->text();
+                       mParent->d->mLines[line].content=s;
+                       model->setData(index,s);
+                       break;
+               default:break;
+       }
+       mParent->rerender();
+}
+
+
+class MTELabel:public MLabel
+{
+       QMap<QString,QString>exdata;
+       public:
+               MTELabel(QMap<QString,QString>dt)
+               {
+                       exdata=dt;
+                       exdata.insert("TICKETID",dt["BARCODE"]);
+                       exdata.insert("VOUCHERID",dt["BARCODE"]);
+               }
+               QString getVariable(QString s)const
+               {
+                       QString ret=exdata.value(s);
+                       if(s=="PRICE"||s=="VALUE")
+                               ret=cent2str(str2cent(ret));
+                       else if(s=="DATETIME")
+                               ret=unix2dateTime(QDateTime::fromString(ret,Qt::ISODate).toTime_t());
+                       return ret;
+               }
+};
+
 void MTicketEditor::rerender()
 {
        QMap<QString,QString>exdata;
@@ -483,16 +735,28 @@ void MTicketEditor::rerender()
                        d->explmodel->data(d->explmodel->index(i,1)).toString()
                );
        }
+       MTELabel label(exdata);
+       //calculate scaling factor
+       int zfi=d->zoomslide->value();
+       qreal zff=1.0;
+       if(zfi!=0){
+               for(int i=0;i<zfi;i++)zff*=1.2;
+               for(int i=0;i>zfi;i--)zff/=1.2;
+       }
        //render ticket
-       MOTicket t;
-       t.setticketid(exdata.value("BARCODE"));
-       t.setprice(str2cent(exdata.value("PRICE")));
        QTemporaryFile tfile(QDir::tempPath()+"/templateXXXXXX.xtt");
        tfile.open();
        saveTemplate(tfile);
-       MTicketRenderer rend(tfile.fileName());
-       rend.render(t,*(d->ticketpicture));
-       //render voucher
+       MLabelRenderer rend(tfile.fileName());
+       QSize size(rend.labelSize(*d->ticketpicture).toSize());
+       QImage tick=QPixmap(size*zff).toImage();
+       tick.setDotsPerMeterX(tick.dotsPerMeterX()*zff);
+       tick.setDotsPerMeterY(tick.dotsPerMeterY()*zff);
+       tick.fill(0xffffffff);
+       if(!rend.render(label,tick))
+               qDebug("unable to render");
+       //scale and display
+       d->ticketpicture->setPixmap(QPixmap::fromImage(tick));
 }
 
 void MTicketEditor::saveTemplate(QFile& fd)
@@ -502,32 +766,133 @@ void MTicketEditor::saveTemplate(QFile& fd)
        {QBuffer buf;buf.open(QIODevice::ReadWrite);
        saveXmlPart(buf);buf.seek(0);
        zip.storeFile("template.xml",buf);}
+       QStringList k=d->mFiles.keys();
+       for(int i=0;i<k.size();i++){
+               QBuffer buf;
+               buf.open(QIODevice::ReadWrite);
+               buf.write(d->mFiles[k[i]]);
+               buf.seek(0);
+               zip.storeFile(k[i],buf);
+       }
        zip.close();
        fd.flush();
 }
 
 void MTicketEditor::saveXmlPart(QIODevice& fd)
 {
-
+       QDomDocument doc;
+       QDomElement root=doc.createElement("LabelTemplate");
+       root.setAttribute("size",size2str(d->mSize));
+       root.setAttribute("unit",d->mUnit);
+       for(int i=0;i<d->mLines.size();i++){
+               Private::Line_s ln=d->mLines[i];
+               QDomElement el;
+               switch(ln.type){
+                       case Private::LoadFont:el=doc.createElement("LoadFont");break;
+                       case Private::Picture:el=doc.createElement("Picture");break;
+                       case Private::Text:el=doc.createElement("Text");break;
+                       case Private::Barcode:el=doc.createElement("Barcode");break;
+                       default:continue;
+               }
+               if(ln.type&HRECT){
+                       el.setAttribute("size",size2str(ln.size));
+                       el.setAttribute("offset",point2str(ln.offset));
+               }
+               if(ln.type&HFILE)
+                       el.setAttribute("file",ln.file);
+               if(ln.type&HFONT){
+                       el.setAttribute("font",ln.font);
+                       el.setAttribute("fontsize",ln.fontsize);
+               }
+               if(ln.type&HSMOOTH)
+                       el.setAttribute("smooth",ln.smooth?"1":"0");
+               if(ln.type&HALIGN){
+                       el.setAttribute("align",align2xml(ln.align&Qt::AlignHorizontal_Mask));
+                       el.setAttribute("valign",align2xml(ln.align&Qt::AlignVertical_Mask));
+               }
+               if(ln.type&HCONTENT)
+                       el.appendChild(doc.createTextNode(ln.content));
+               root.appendChild(el);
+       }
+       doc.appendChild(root);
+       //save
+       fd.write(doc.toByteArray());
 }
 
 
 void MTicketEditor::addFile()
 {
-
+       QString fn=QFileDialog::getOpenFileName(this,tr("Add File to Label"));
+       if(fn=="")return;
+       //try to read it
+       QFile fd(fn);
+       if(!fd.open(QIODevice::ReadOnly)){
+               QMessageBox::warning(this,tr("Warning"),tr("Unable to read file %1").arg(fn));
+               return;
+       }
+       QByteArray fdata=fd.readAll();
+       fd.close();
+       //ask for internal name
+       fn=QFileInfo(fn).fileName();
+       fn=QInputDialog::getText(this,tr("File Name"),tr("Please enter the internal file name:"),QLineEdit::Normal,fn);
+       if(fn=="")return;
+       fn=QFileInfo(fn).fileName();
+       if(fn=="")return;
+       //append
+       d->mFiles.insert(fn,fdata);
+       updateDisplay();
 }
 
 void MTicketEditor::delFile()
 {
-
+       //get file name
+       QModelIndex idx=d->filetable->currentIndex();
+       if(!idx.isValid())return;
+       QString fn=d->filemodel->data(d->filemodel->index(idx.row(),0)).toString();
+       if(fn=="")return;
+       //ask
+       if(QMessageBox::question(this,tr("Really delete?"),tr("Really remove file '%1' from the label?").arg(fn),QMessageBox::No|QMessageBox::Yes)!=QMessageBox::Yes)
+               return;
+       //delete
+       d->mFiles.remove(fn);
+       updateDisplay();
 }
 
-void MTicketEditor::addItem(int )
+void MTicketEditor::addItem(int type)
 {
-
+       d->mLines.append(Private::Line_s(type));
+       updateDisplay();
 }
 
 void MTicketEditor::delItem()
 {
+       QModelIndex idx=d->itemtable->currentIndex();
+       if(!idx.isValid())return;
+       d->mLines.removeAt(idx.row());
+       updateDisplay();
+}
 
+void MTicketEditor::downItem()
+{
+       QModelIndex idx=d->itemtable->currentIndex();
+       if(!idx.isValid())return;
+       int r=idx.row();
+       if(r>=(d->mLines.size()-1))return;
+       Private::Line_s tmp=d->mLines[r];
+       d->mLines[r]=d->mLines[r+1];
+       d->mLines[r+1]=tmp;
+       updateDisplay();
+       d->itemtable->setCurrentIndex(d->itemmodel->index(r+1,idx.column()));
+}
+void MTicketEditor::upItem()
+{
+       QModelIndex idx=d->itemtable->currentIndex();
+       if(!idx.isValid())return;
+       int r=idx.row();
+       if(r<=0)return;
+       Private::Line_s tmp=d->mLines[r];
+       d->mLines[r]=d->mLines[r-1];
+       d->mLines[r-1]=tmp;
+       updateDisplay();
+       d->itemtable->setCurrentIndex(d->itemmodel->index(r-1,idx.column()));
 }
index 2fbb7a8..770b1c0 100644 (file)
@@ -25,6 +25,7 @@ class MTicketEditor:public QMainWindow
 {
        Q_OBJECT
        DECLARE_DPTR(d);
+       friend class MTELabelDelegate;
        public:
                ///instantiates the editor
                MTicketEditor(QWidget* parent = 0, Qt::WindowFlags f = 0);
@@ -40,20 +41,30 @@ class MTicketEditor:public QMainWindow
                void saveFileAs();
                ///helper for saveFile and upload
                void saveFile(QString);
-               ///downloads a file from the server
-               void download();
-               ///sends the file to the server
-               void upload();
        private slots:
+               ///renders the label
                void rerender();
+               ///parses the XML part of the template file and fills internal ressources
                void parseTemplate(QByteArray);
+               ///pushes all data from internal ressources to the display
                void updateDisplay();
+               ///add a specific kind of item line
                void addItem(int);
+               ///delete currently selected item line
                void delItem();
+               ///move selected item up
+               void upItem();
+               ///move selected item down
+               void downItem();
+               ///add a file (image/font) to the template
                void addFile();
+               ///delete the selected file from the template
                void delFile();
+               ///used by constructor to load example data for the example label
                void loadExampleData();
+               ///saves all data to the file (must be open ReadWrite)
                void saveTemplate(QFile&);
+               ///helper: saves the XML part of the template (device must be writable)
                void saveXmlPart(QIODevice&);
 };
 
index f0ed150..2cda087 100644 (file)
@@ -346,11 +346,12 @@ void MLabelRendererPrivate::render(QDomElement&sup, const MLabel&tick, QPaintDev
                        if(!canrender){
                                return;
                        }
-                       //TODO: make use of smooth
-//                     int smooth=el.attribute("smooth","1").toInt();
+                       //make use of smooth
+                       int smooth=el.attribute("smooth","1").toInt();
                        QString fname=el.attribute("file");
                        //paint
-                       paint->drawImage(QRectF(tonatural(pdev,off)+noff,tonatural(pdev,sz)),idb[fname]);
+                       QImage img=idb[fname].scaled(tonatural(pdev,sz).toSize(), Qt::IgnoreAspectRatio, smooth!=0?Qt::SmoothTransformation:Qt::FastTransformation);
+                       paint->drawImage(QRectF(tonatural(pdev,off)+noff,tonatural(pdev,sz)),img);
                }else
                if(enm=="Text"){
                        //get attributes
@@ -522,6 +523,8 @@ class MTicketLabel:public MLabel
                MOTicket tick;
 };
 
+
+//WARNING: if you add anything here, make sure you simulate it in ticketedit.cpp
 QString MTicketLabel::getVariable(QString var)const
 {
        if(var=="TICKETID"||var=="BARCODE")return tick.ticketid();
@@ -550,6 +553,7 @@ class MVoucherLabel:public MLabel
                MOVoucher vouc;
 };
 
+//WARNING: if you add anything here, make sure you simulate it in ticketedit.cpp
 QString MVoucherLabel::getVariable(QString var)const
 {
        if(var=="VOUCHERID"||var=="BARCODE")return vouc.voucherid();
index d442698..3a7b209 100644 (file)
@@ -38,6 +38,12 @@ MOEvent MOTicket::event()const
        return m_event;
 }
 
+void MOTicket::setEvent(const MOEvent& e)
+{
+       m_event=e;
+       seteventid(e.eventid());
+}
+
 QString MOTicket::priceCategoryName()const
 {
        return pricecategory().value().name();
index be9d99a..72812a1 100644 (file)
@@ -39,6 +39,9 @@ class MOTicket:public MOTicketAbstract
                
                /**returns the event that this ticket belongs to - does a roundtrip to the database the first time this is called!*/
                MOEvent event()const;
+               
+               /**used by label editor: sets the simulated event*/
+               void setEvent(const MOEvent&e);
        private:
                //this must be mutable, since event() is semantically and technically const
                mutable MOEvent m_event;