12#include <QAbstractSpinBox>
13#include <QApplication>
35 return QValidator::Intermediate;
41 return valid ? QValidator::Intermediate : QValidator::Invalid;
53 val =
parse(input, &valid);
109 int h =
lineEdit()->minimumSizeHint().height();
124 ->subControlRect(QStyle::CC_SpinBox, &
opt,
125 QStyle::SC_SpinBoxEditField,
this)
131 ->subControlRect(QStyle::CC_SpinBox, &
opt,
132 QStyle::SC_SpinBoxEditField,
this)
141 ->sizeFromContents(QStyle::CT_SpinBox, &
opt,
hint,
this)
142 .expandedTo(QApplication::globalStrut());
176 if (
event->type() == QEvent::KeyPress ||
177 event->type() == QEvent::KeyRelease) {
179 if (
keyEvent->key() == Qt::Key_Comma) {
187 return QAbstractSpinBox::event(
event);
195 if (text().isEmpty()) {
218#include <qt/bitcoinamountfield.moc>
221 : QWidget(parent), amount(
nullptr) {
223 amount->setLocale(QLocale::c());
224 amount->installEventFilter(
this);
225 amount->setMaximumWidth(240);
233 layout->setContentsMargins(0, 0, 0, 0);
245 static_cast<void (QComboBox::*)(
int)
>(&QComboBox::currentIndexChanged),
254 unit->setCurrentIndex(0);
271 amount->setStyleSheet(
"");
278 if (event->type() == QEvent::FocusIn) {
282 return QWidget::eventFilter(
object, event);
311 amount->setReadOnly(fReadOnly);
316 unit->setToolTip(
unit->itemData(idx, Qt::ToolTipRole).toString());
static constexpr Amount SATOSHI
QSpinBox that uses fixed-point numbers internally and uses our own formatting/parsing functions.
void SetMinValue(const Amount &value)
bool event(QEvent *event) override
void setValue(const Amount value)
AmountSpinBox(QWidget *parent)
QValidator::State validate(QString &text, int &pos) const override
StepEnabled stepEnabled() const override
QSize cachedMinimumSizeHint
void fixup(QString &input) const override
void setSingleStep(const Amount step)
void stepBy(int steps) override
QSize minimumSizeHint() const override
Amount value(bool *valid_out=nullptr) const
void SetAllowEmpty(bool allow)
void SetMaxValue(const Amount &value)
void setDisplayUnit(int unit)
Amount parse(const QString &text, bool *valid_out=nullptr) const
Parse a string into a number of base monetary units and return validity.
void setEnabled(bool fEnabled)
Enable/Disable.
void SetMaxValue(const Amount &value)
Set the maximum value in satoshis.
bool eventFilter(QObject *object, QEvent *event) override
Intercept focus-in event and ',' key presses.
void setReadOnly(bool fReadOnly)
Make read-only.
BitcoinAmountField(QWidget *parent=nullptr)
void unitChanged(int idx)
void setDisplayUnit(int unit)
Change unit used to display amount.
void clear()
Make field empty and ready for new input.
bool validate()
Perform input validation, mark field as invalid if entered value is not valid.
QWidget * setupTabChain(QWidget *prev)
Qt messes up the tab chain by default in some cases (issue https://bugreports.qt-project....
void setValue(const Amount value)
void setValid(bool valid)
Mark current value as invalid in UI.
void SetAllowEmpty(bool allow)
If allow empty is set to false the field will be set to the minimum allowed value if left empty.
void setSingleStep(const Amount step)
Set single step in satoshis.
void SetMinValue(const Amount &value)
Set the minimum value in satoshis.
Bitcoin unit definitions.
@ UnitRole
Unit identifier.
static Amount maxMoney()
Return maximum number of base units (Satoshis)
static QString format(int unit, const Amount amount, bool plussign=false, SeparatorStyle separators=SeparatorStyle::STANDARD, bool justify=false)
Format as string.
static bool parse(int unit, const QString &value, Amount *val_out)
Parse string to coin amount.
void setValue(const QVariant &value)
int TextWidth(const QFontMetrics &fm, const QString &text)
Returns the distance in pixels appropriate for drawing a subsequent character after text.
T GetRand(T nMax=std::numeric_limits< T >::max()) noexcept
Generate a uniform random integer of type T in the range [0..nMax) nMax defaults to std::numeric_limi...
static constexpr Amount zero() noexcept