Changeset View
Changeset View
Standalone View
Standalone View
src/qt/bitcoinamountfield.cpp
Show First 20 Lines • Show All 46 Lines • ▼ Show 20 Lines | void fixup(QString &input) const override { | ||||
Amount val = parse(input, &valid); | Amount val = parse(input, &valid); | ||||
if (valid) { | if (valid) { | ||||
input = BitcoinUnits::format(currentUnit, val, false, | input = BitcoinUnits::format(currentUnit, val, false, | ||||
BitcoinUnits::separatorAlways); | BitcoinUnits::separatorAlways); | ||||
lineEdit()->setText(input); | lineEdit()->setText(input); | ||||
} | } | ||||
} | } | ||||
Amount value(bool *valid_out = 0) const { return parse(text(), valid_out); } | Amount value(bool *valid_out = nullptr) const { | ||||
return parse(text(), valid_out); | |||||
} | |||||
void setValue(const Amount value) { | void setValue(const Amount value) { | ||||
lineEdit()->setText(BitcoinUnits::format( | lineEdit()->setText(BitcoinUnits::format( | ||||
currentUnit, value, false, BitcoinUnits::separatorAlways)); | currentUnit, value, false, BitcoinUnits::separatorAlways)); | ||||
Q_EMIT valueChanged(); | Q_EMIT valueChanged(); | ||||
} | } | ||||
void stepBy(int steps) override { | void stepBy(int steps) override { | ||||
▲ Show 20 Lines • Show All 65 Lines • ▼ Show 20 Lines | private: | ||||
Amount singleStep; | Amount singleStep; | ||||
mutable QSize cachedMinimumSizeHint; | mutable QSize cachedMinimumSizeHint; | ||||
/** | /** | ||||
* Parse a string into a number of base monetary units and | * Parse a string into a number of base monetary units and | ||||
* return validity. | * return validity. | ||||
* @note Must return 0 if !valid. | * @note Must return 0 if !valid. | ||||
*/ | */ | ||||
Amount parse(const QString &text, bool *valid_out = 0) const { | Amount parse(const QString &text, bool *valid_out = nullptr) const { | ||||
Amount val = Amount::zero(); | Amount val = Amount::zero(); | ||||
bool valid = BitcoinUnits::parse(currentUnit, text, &val); | bool valid = BitcoinUnits::parse(currentUnit, text, &val); | ||||
if (valid) { | if (valid) { | ||||
if (val < Amount::zero() || val > BitcoinUnits::maxMoney()) { | if (val < Amount::zero() || val > BitcoinUnits::maxMoney()) { | ||||
valid = false; | valid = false; | ||||
} | } | ||||
} | } | ||||
if (valid_out) { | if (valid_out) { | ||||
Show All 23 Lines | StepEnabled stepEnabled() const override { | ||||
// Disable steps when AmountSpinBox is read-only. | // Disable steps when AmountSpinBox is read-only. | ||||
return StepNone; | return StepNone; | ||||
} | } | ||||
if (text().isEmpty()) { | if (text().isEmpty()) { | ||||
// Allow step-up with empty field. | // Allow step-up with empty field. | ||||
return StepUpEnabled; | return StepUpEnabled; | ||||
} | } | ||||
StepEnabled rv = 0; | StepEnabled rv = StepNone; | ||||
bool valid = false; | bool valid = false; | ||||
Amount val = value(&valid); | Amount val = value(&valid); | ||||
if (valid) { | if (valid) { | ||||
if (val > Amount::zero()) { | if (val > Amount::zero()) { | ||||
rv |= StepDownEnabled; | rv |= StepDownEnabled; | ||||
} | } | ||||
if (val < BitcoinUnits::maxMoney()) { | if (val < BitcoinUnits::maxMoney()) { | ||||
rv |= StepUpEnabled; | rv |= StepUpEnabled; | ||||
} | } | ||||
} | } | ||||
return rv; | return rv; | ||||
} | } | ||||
Q_SIGNALS: | Q_SIGNALS: | ||||
void valueChanged(); | void valueChanged(); | ||||
}; | }; | ||||
#include <qt/bitcoinamountfield.moc> | #include <qt/bitcoinamountfield.moc> | ||||
BitcoinAmountField::BitcoinAmountField(QWidget *parent) | BitcoinAmountField::BitcoinAmountField(QWidget *parent) | ||||
: QWidget(parent), amount(0) { | : QWidget(parent), amount(nullptr) { | ||||
amount = new AmountSpinBox(this); | amount = new AmountSpinBox(this); | ||||
amount->setLocale(QLocale::c()); | amount->setLocale(QLocale::c()); | ||||
amount->installEventFilter(this); | amount->installEventFilter(this); | ||||
amount->setMaximumWidth(240); | amount->setMaximumWidth(240); | ||||
QHBoxLayout *layout = new QHBoxLayout(this); | QHBoxLayout *layout = new QHBoxLayout(this); | ||||
layout->addWidget(amount); | layout->addWidget(amount); | ||||
unit = new QValueComboBox(this); | unit = new QValueComboBox(this); | ||||
▲ Show 20 Lines • Show All 90 Lines • Show Last 20 Lines |