Browse Source

[Qt] Improve single step in bitcoinamountfield

0.10
Cozz Lovan 11 years ago
parent
commit
b920148258
  1. 16
      src/qt/bitcoinamountfield.cpp
  2. 4
      src/qt/bitcoinamountfield.h
  3. 2
      src/qt/optionsdialog.cpp

16
src/qt/bitcoinamountfield.cpp

@ -19,12 +19,12 @@ BitcoinAmountField::BitcoinAmountField(QWidget *parent) :
amount(0), amount(0),
currentUnit(-1) currentUnit(-1)
{ {
nSingleStep = 100000; // satoshis
amount = new QDoubleSpinBox(this); amount = new QDoubleSpinBox(this);
amount->setLocale(QLocale::c()); amount->setLocale(QLocale::c());
amount->setDecimals(8);
amount->installEventFilter(this); amount->installEventFilter(this);
amount->setMaximumWidth(170); amount->setMaximumWidth(170);
amount->setSingleStep(0.001);
QHBoxLayout *layout = new QHBoxLayout(this); QHBoxLayout *layout = new QHBoxLayout(this);
layout->addWidget(amount); layout->addWidget(amount);
@ -159,11 +159,7 @@ void BitcoinAmountField::unitChanged(int idx)
// Set max length after retrieving the value, to prevent truncation // Set max length after retrieving the value, to prevent truncation
amount->setDecimals(BitcoinUnits::decimals(currentUnit)); amount->setDecimals(BitcoinUnits::decimals(currentUnit));
amount->setMaximum(qPow(10, BitcoinUnits::amountDigits(currentUnit)) - qPow(10, -amount->decimals())); amount->setMaximum(qPow(10, BitcoinUnits::amountDigits(currentUnit)) - qPow(10, -amount->decimals()));
amount->setSingleStep((double)nSingleStep / (double)BitcoinUnits::factor(currentUnit));
if (currentUnit == BitcoinUnits::uBTC)
amount->setSingleStep(0.01);
else
amount->setSingleStep(0.001);
if (valid) if (valid)
{ {
@ -182,3 +178,9 @@ void BitcoinAmountField::setDisplayUnit(int newUnit)
{ {
unit->setValue(newUnit); unit->setValue(newUnit);
} }
void BitcoinAmountField::setSingleStep(qint64 step)
{
nSingleStep = step;
unitChanged(unit->currentIndex());
}

4
src/qt/bitcoinamountfield.h

@ -26,6 +26,9 @@ public:
qint64 value(bool *valid=0) const; qint64 value(bool *valid=0) const;
void setValue(qint64 value); void setValue(qint64 value);
/** Set single step in satoshis **/
void setSingleStep(qint64 step);
/** Make read-only **/ /** Make read-only **/
void setReadOnly(bool fReadOnly); void setReadOnly(bool fReadOnly);
@ -56,6 +59,7 @@ private:
QDoubleSpinBox *amount; QDoubleSpinBox *amount;
QValueComboBox *unit; QValueComboBox *unit;
int currentUnit; int currentUnit;
qint64 nSingleStep;
void setText(const QString &text); void setText(const QString &text);
QString text() const; QString text() const;

2
src/qt/optionsdialog.cpp

@ -15,6 +15,7 @@
#include "optionsmodel.h" #include "optionsmodel.h"
#include "netbase.h" #include "netbase.h"
#include "main.h"
#include <QDir> #include <QDir>
#include <QIntValidator> #include <QIntValidator>
@ -93,6 +94,7 @@ OptionsDialog::OptionsDialog(QWidget *parent) :
} }
ui->unit->setModel(new BitcoinUnits(this)); ui->unit->setModel(new BitcoinUnits(this));
ui->transactionFee->setSingleStep(CTransaction::nMinTxFee);
/* Widget-to-option mapper */ /* Widget-to-option mapper */
mapper = new MonitoredDataMapper(this); mapper = new MonitoredDataMapper(this);

Loading…
Cancel
Save