--- /dev/null
+//
+// C++ Implementation: centbox
+//
+// Description:
+//
+//
+// Author: Konrad Rosenbaum <konrad@silmor.de>, (C) 2008
+//
+// Copyright: See README/COPYING files that come with this distribution
+//
+//
+
+#include "centbox.h"
+#include "misc.h"
+
+#include <QBoxLayout>
+#include <QLabel>
+#include <QLineEdit>
+#include <QPushButton>
+
+MCentSpinBox::MCentSpinBox(QWidget*parent,int value,int maxValue)
+ :QAbstractSpinBox(parent),mvalid(priceRegExp(),this)
+{
+ mmin=0;
+ mmax=maxValue;
+ if(mmin>mmax)mmin=mmax;
+ mval=value;
+ if(mval<mmin)mval=mmin;
+ if(mval>mmax)mval=mmax;
+
+ setButtonSymbols(UpDownArrows);
+ lineEdit()->setText(cent2str(mval));
+ connect(this,SIGNAL(editingFinished()),this,SLOT(fixup()));
+}
+
+int MCentSpinBox::value()const
+{
+ qDebug("current value: %i",mval);
+ return mval;
+}
+
+void MCentSpinBox::setValue(int m)
+{
+ if(m>mmax)m=mmax;
+ if(m<mmin)m=mmin;
+ if(mval==m)return;
+ qDebug("setval %i",m);
+ mval=m;
+ lineEdit()->setText(cent2str(m));
+ emit valueChanged(m);
+}
+
+MCentSpinBox::StepEnabled MCentSpinBox::stepEnabled () const
+{
+ return (mval>mmin?StepDownEnabled:StepNone)|(mval<mmax?StepUpEnabled:StepNone);
+}
+
+void MCentSpinBox::setRange(int mi,int ma)
+{
+ if(mi>ma)return;
+ mmin=mi;
+ mmax=ma;
+ if(mval>mmax){
+ setValue(mmax);
+ }else
+ if(mval<mmin){
+ setValue(mmin);
+ }
+}
+
+int MCentSpinBox::minimumValue()const{return mmin;}
+int MCentSpinBox::maximumValue()const{return mmax;}
+
+void MCentSpinBox::stepBy(int x)
+{
+ int m=mval+x;
+ setValue(m);
+}
+
+QValidator::State MCentSpinBox::validate(QString &input, int &pos) const
+{
+ return mvalid.validate(input,pos);
+}
+
+void MCentSpinBox::fixup()
+{
+ int m=str2cent(text());
+ setValue(m);
+}
+
+/*****************************************************/
+
+MCentDialog::MCentDialog(QWidget*parent,QString title,QString label,int val,int maxValue)
+ :QDialog(parent)
+{
+ setWindowTitle(title);
+ QVBoxLayout*vl;
+ setLayout(vl=new QVBoxLayout);
+ vl->addWidget(new QLabel(label));
+ vl->addWidget(box=new MCentSpinBox(this,val,maxValue));
+ QHBoxLayout *hl;
+ vl->addLayout(hl=new QHBoxLayout);
+ hl->addStretch(10);
+ QPushButton*p;
+ hl->addWidget(p=new QPushButton(tr("OK")));
+ p->setDefault(true);
+ connect(p,SIGNAL(clicked()),this,SLOT(accept()));
+ hl->addWidget(p=new QPushButton(tr("Cancel")));
+ connect(p,SIGNAL(clicked()),this,SLOT(reject()));
+}
+
+int MCentDialog::value()const
+{
+ return box->value();
+}
+
+int MCentDialog::getCents(QWidget*parent,QString title,QString label,int val,int maxValue,bool*ok)
+{
+ MCentDialog d(parent,title,label,val,maxValue);
+ bool b=d.exec()==QDialog::Accepted;
+ if(ok)*ok=b;
+ if(b)
+ return d.value();
+ else
+ return 0;
+}
--- /dev/null
+//
+// C++ Interface: centbox
+//
+// Description:
+//
+//
+// Author: Konrad Rosenbaum <konrad@silmor.de>, (C) 2008
+//
+// Copyright: See README/COPYING files that come with this distribution
+//
+//
+
+#ifndef MAGICSMOKE_CENTBOX_H
+#define MAGICSMOKE_CENTBOX_H
+
+#include <QAbstractSpinBox>
+#include <QDialog>
+#include <QRegExpValidator>
+
+class MCentSpinBox:public QAbstractSpinBox
+{
+ Q_OBJECT
+ public:
+ MCentSpinBox(QWidget*parent=0,int value=0,int maxValue=2147483647);
+
+ virtual int value()const;
+ virtual void setValue(int);
+
+ virtual void setRange(int,int);
+
+ virtual int minimumValue()const;
+ virtual int maximumValue()const;
+
+ void stepBy(int);
+ protected:
+ virtual QValidator::State validate(QString &input, int &pos) const;
+ virtual StepEnabled stepEnabled () const;
+ signals:
+ void valueChanged(int);
+ private slots:
+ void fixup();
+ private:
+ int mval,mmax,mmin;
+ QRegExpValidator mvalid;
+};
+
+class MCentDialog:public QDialog
+{
+ public:
+ MCentDialog(QWidget*parent=0,QString title=QString(),QString label=QString(),int value=0,int maxValue=2147483647);
+
+ virtual int value()const;
+
+ static int getCents(QWidget*parent=0,QString title=QString(),QString label=QString(),int value=0,int maxValue=2147483647,bool *ok=0);
+ private:
+ MCentSpinBox*box;
+};
+
+#endif
int str2cent(QString s,bool localize)
{
+ //convert local decimal dot by international decimal dot
if(localize)s=s.replace(QCoreApplication::translate("misc",".","decimal dot in price"),".");
- double c=s.toDouble()*100.;
- return int(c);
+ //calculate price
+ //pp->price part euro/dollar/...; pc->price part cent; pm=multiplier for cent; md->mode
+ int pp=0,pc=0,pm=10,md=0;
+ for(int i=0;i<s.size();i++){
+ QChar c=s[i];
+ if(c.isDigit()){
+ if(md==0){//mode==0 -> before the dot
+ pp*=10;
+ pp+=c.digitValue();
+ }else{//mode==1 -> after the dot
+ pc+=c.digitValue()*pm;
+ if(pm==1)break;
+ pm=1;
+ }
+ }else
+ if(c=='.')md=1;//reached the dot, switch mode
+ //ignore everything else
+ }
+ //return result
+ return pp*100+pc;
}
QRegExp priceRegExp(bool localize)
//
//
+#include "centbox.h"
#include "event.h"
#include "labeldlg.h"
#include "misc.h"
if(!m_order.isValid())return;
//get value
bool ok;
- double rt=QInputDialog::getDouble(this,tr("Enter Payment"),tr("Please enter the amount that has been paid:"),m_order.amountToPay()/100.0,0,m_order.amountToPay()/100.0,2,&ok);
+ int pay=MCentDialog::getCents(this,tr("Enter Payment"),tr("Please enter the amount that has been paid:"),m_order.amountToPay(),m_order.amountToPay(),&ok);
if(!ok)return;
- int pay=int(rt*100.0);
if(pay<=0)return;
//submit
QByteArray rq=QByteArray::number(m_order.orderID())+" "+QByteArray::number(pay);
if(!m_order.isValid())return;
//get value
bool ok;
- double rt=QInputDialog::getDouble(this,tr("Enter Refund"),tr("Please enter the amount that will be refunded:"),m_order.amountToRefund()/100.0,0,m_order.amountToRefund()/100.0,2,&ok);
+ int pay=MCentDialog::getCents(this,tr("Enter Refund"),tr("Please enter the amount that will be refunded:"),m_order.amountToRefund(),m_order.amountToRefund(),&ok);
if(!ok)return;
- int pay=int(rt*100.0);
if(pay<=0)return;
//submit
QByteArray rq=QByteArray::number(m_order.orderID())+" "+QByteArray::number(pay);
if(!tick.isValid())return;
//get value
bool ok;
- double rt=QInputDialog::getDouble(this,tr("Enter Price"),tr("Please enter the new price for the ticket:"),tick.price()/100.0,0,1000000,2,&ok);
+ int pay=MCentDialog::getCents(this,tr("Enter Price"),tr("Please enter the new price for the ticket:"),tick.price(),100000000,&ok);
if(!ok)return;
- int pay=int(rt*100.0);
if(pay<0)return;
//submit
m_order.updateTicketPrice(tick.ticketID(),pay);
gl->addWidget(new QLabel(tr("Method:")),0,0);
gl->addWidget(opt=new QComboBox,0,1);
gl->addWidget(new QLabel(tr("Price:")),1,0);
- gl->addWidget(prc=new QDoubleSpinBox,1,1);
+ gl->addWidget(prc=new MCentSpinBox,1,1);
gl->setRowMinimumHeight(2,15);
gl->setRowStretch(2,1);
QHBoxLayout*hl;
hl->addWidget(p=new QPushButton(tr("Cancel")));
connect(p,SIGNAL(clicked()),this,SLOT(reject()));
- prc->setRange(0.,1.0e9);//hmm, even in Yen this should be big enough
- prc->setDecimals(2);
- prc->setValue(s.price()/100.);
+ prc->setRange(0,1000000000);//hmm, even in Yen this should be big enough
+ prc->setValue(s.price());
prc->setEnabled(req->hasRole("orderchangeshipping"));
opt->addItem(tr("(None)","shipping method"));
int MShippingChange::price()const
{
- return int(prc->value()*100.);
+ return prc->value();
}
void MShippingChange::changeItem(int cid)
{
if(cid==0)prc->setValue(0);
- else prc->setValue(double(all[cid-1].price())/100.0);
+ else prc->setValue(all[cid-1].price());
}
MVoucherRenderer*vrender;
};
-class QDoubleSpinBox;
+class MCentSpinBox;
class QComboBox;
/**helper class: allows to change the shipping option*/
MWebRequest*req;
QList<MShipping> all;
QComboBox*opt;
- QDoubleSpinBox*prc;
+ MCentSpinBox*prc;
};
#endif
#include "misc.h"
#include "shipping.h"
#include "webrequest.h"
+#include "centbox.h"
#include <QApplication>
#include <QDomDocument>
MShipping s=all[idx.row()];
//get new value
bool b;
- double r=QInputDialog::getDouble(this,tr("Shipping Option Price"),tr("Please select a new price for this shipping option:"),s.price()/100.,0,1e9,2,&b);
+ int r=MCentDialog::getCents(this,tr("Shipping Option Price"),tr("Please select a new price for this shipping option:"),s.price(),1000000000,&b);
if(!b)return;
- s.setPrice(int(r*100.));
+ s.setPrice(r);
if(!s.save()){
QMessageBox::warning(this,tr("Warning"),tr("Could not store the changes."));
return;
QString dsc=QInputDialog::getText(this,tr("Shipping Option Description"),tr("Please select a new description for this new shipping option:"));
if(dsc=="")return;
bool b;
- double prc=QInputDialog::getDouble(this,tr("Shipping Option Price"),tr("Please select a new price for this new shipping option:"),0.,0,1e9,2,&b);
+ int prc=MCentDialog::getCents(this,tr("Shipping Option Price"),tr("Please select a new price for this new shipping option:"),0,1000000000,&b);
if(!b)return;
QStringList opt;
opt<<tr("None")<<tr("Web Interface")<<tr("Any User")<<tr("Any User + Web Interface");
//create the option
MShipping s(req);
s.setDescription(dsc);
- s.setPrice(int(prc*100.));
+ s.setPrice(prc);
int cav=4;
for(int i=0;i<opt.size();i++)if(avl==opt[i])cav=i;
s.setWebUsable(cav&1);
version.cpp \
templates.cpp \
templatedlg.cpp \
- office.cpp
+ office.cpp \
+ centbox.cpp
HEADERS = \
keygen.h \
misc.h \
templates.h \
templatedlg.h \
- office.h
+ office.h \
+ centbox.h
#some PHP files are listed in this file to scan them for translatable items
#use genphpscan.sh to regenerate it.