Changeset View
Changeset View
Standalone View
Standalone View
src/qt/bitcoinamountfield.cpp
Show First 20 Lines • Show All 50 Lines • ▼ Show 20 Lines | void fixup(QString &input) const override { | ||||
} else { | } else { | ||||
valid = false; | valid = false; | ||||
val = parse(input, &valid); | val = parse(input, &valid); | ||||
} | } | ||||
if (valid) { | if (valid) { | ||||
val = qBound(m_min_amount, val, m_max_amount); | val = qBound(m_min_amount, val, m_max_amount); | ||||
input = BitcoinUnits::format(currentUnit, val, false, | input = BitcoinUnits::format(currentUnit, val, false, | ||||
BitcoinUnits::separatorAlways); | BitcoinUnits::SeparatorStyle::ALWAYS); | ||||
lineEdit()->setText(input); | lineEdit()->setText(input); | ||||
} | } | ||||
} | } | ||||
Amount value(bool *valid_out = nullptr) const { | Amount value(bool *valid_out = nullptr) const { | ||||
return parse(text(), valid_out); | 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::SeparatorStyle::ALWAYS)); | ||||
Q_EMIT valueChanged(); | Q_EMIT valueChanged(); | ||||
} | } | ||||
void SetAllowEmpty(bool allow) { m_allow_empty = allow; } | void SetAllowEmpty(bool allow) { m_allow_empty = allow; } | ||||
void SetMinValue(const Amount &value) { m_min_amount = value; } | void SetMinValue(const Amount &value) { m_min_amount = value; } | ||||
void SetMaxValue(const Amount &value) { m_max_amount = value; } | void SetMaxValue(const Amount &value) { m_max_amount = value; } | ||||
void stepBy(int steps) override { | void stepBy(int steps) override { | ||||
bool valid = false; | bool valid = false; | ||||
Amount val = value(&valid); | Amount val = value(&valid); | ||||
val = val + steps * singleStep; | val = val + steps * singleStep; | ||||
val = qBound(m_min_amount, val, m_max_amount); | val = qBound(m_min_amount, val, m_max_amount); | ||||
setValue(val); | setValue(val); | ||||
} | } | ||||
void setDisplayUnit(int unit) { | void setDisplayUnit(int unit) { | ||||
bool valid = false; | bool valid = false; | ||||
Amount val(value(&valid)); | Amount val(value(&valid)); | ||||
currentUnit = unit; | currentUnit = unit; | ||||
lineEdit()->setPlaceholderText(BitcoinUnits::format( | lineEdit()->setPlaceholderText( | ||||
currentUnit, m_min_amount, false, BitcoinUnits::separatorAlways)); | BitcoinUnits::format(currentUnit, m_min_amount, false, | ||||
BitcoinUnits::SeparatorStyle::ALWAYS)); | |||||
if (valid) { | if (valid) { | ||||
setValue(val); | setValue(val); | ||||
} else { | } else { | ||||
clear(); | clear(); | ||||
} | } | ||||
} | } | ||||
void setSingleStep(const Amount step) { singleStep = step; } | void setSingleStep(const Amount step) { singleStep = step; } | ||||
QSize minimumSizeHint() const override { | QSize minimumSizeHint() const override { | ||||
if (cachedMinimumSizeHint.isEmpty()) { | if (cachedMinimumSizeHint.isEmpty()) { | ||||
ensurePolished(); | ensurePolished(); | ||||
const QFontMetrics fm(fontMetrics()); | const QFontMetrics fm(fontMetrics()); | ||||
int h = lineEdit()->minimumSizeHint().height(); | int h = lineEdit()->minimumSizeHint().height(); | ||||
int w = GUIUtil::TextWidth( | int w = GUIUtil::TextWidth( | ||||
fm, BitcoinUnits::format(BitcoinUnits::base, | fm, BitcoinUnits::format(BitcoinUnits::base, | ||||
BitcoinUnits::maxMoney(), false, | BitcoinUnits::maxMoney(), false, | ||||
BitcoinUnits::separatorAlways)); | BitcoinUnits::SeparatorStyle::ALWAYS)); | ||||
// Cursor blinking space. | // Cursor blinking space. | ||||
w += 2; | w += 2; | ||||
QStyleOptionSpinBox opt; | QStyleOptionSpinBox opt; | ||||
initStyleOption(&opt); | initStyleOption(&opt); | ||||
QSize hint(w, h); | QSize hint(w, h); | ||||
QSize extra(35, 6); | QSize extra(35, 6); | ||||
opt.rect.setSize(hint + extra); | opt.rect.setSize(hint + extra); | ||||
▲ Show 20 Lines • Show All 209 Lines • Show Last 20 Lines |