qt: Use fixed-point arithmetic in amount spinbox

Fixes various issues and cleans up code

- Fixes issue #4500: Amount widget +/- has floating point rounding artifacts
- Amount box can now be emptied again, without clearing to 0

Also aligns the amount to the right, as in other places.
This commit is contained in:
Wladimir J. van der Laan
2014-07-18 16:31:13 +02:00
parent d5a3fd10e5
commit 91cce1732b
6 changed files with 187 additions and 113 deletions

View File

@@ -8,17 +8,18 @@
#include <QWidget>
QT_BEGIN_NAMESPACE
class QDoubleSpinBox;
class QValueComboBox;
QT_END_NAMESPACE
class AmountSpinBox;
/** Widget for entering bitcoin amounts.
*/
class BitcoinAmountField: public QWidget
{
Q_OBJECT
Q_PROPERTY(qint64 value READ value WRITE setValue NOTIFY textChanged USER true)
Q_PROPERTY(qint64 value READ value WRITE setValue NOTIFY valueChanged USER true)
public:
explicit BitcoinAmountField(QWidget *parent = 0);
@@ -49,20 +50,15 @@ public:
QWidget *setupTabChain(QWidget *prev);
signals:
void textChanged();
void valueChanged();
protected:
/** Intercept focus-in event and ',' key presses */
bool eventFilter(QObject *object, QEvent *event);
private:
QDoubleSpinBox *amount;
AmountSpinBox *amount;
QValueComboBox *unit;
int currentUnit;
qint64 nSingleStep;
void setText(const QString &text);
QString text() const;
private slots:
void unitChanged(int idx);