12#include <QApplication>
13#include <QAbstractSpinBox>
30 QAbstractSpinBox(parent)
32 setAlignment(Qt::AlignRight);
37 QValidator::State
validate(QString &text,
int &pos)
const override
40 return QValidator::Intermediate;
44 return valid ? QValidator::Intermediate : QValidator::Invalid;
47 void fixup(QString &input)
const override
57 val =
parse(input, &valid);
63 lineEdit()->setText(input);
69 return parse(text(), valid_out);
126 const QFontMetrics fm(fontMetrics());
127 int h = lineEdit()->minimumSizeHint().height();
131 QStyleOptionSpinBox opt;
132 initStyleOption(&opt);
135 opt.rect.setSize(hint + extra);
136 extra += hint - style()->subControlRect(QStyle::CC_SpinBox, &opt,
137 QStyle::SC_SpinBoxEditField,
this).size();
139 opt.rect.setSize(hint + extra);
140 extra += hint - style()->subControlRect(QStyle::CC_SpinBox, &opt,
141 QStyle::SC_SpinBoxEditField,
this).size();
176 return valid ? val : 0;
182 if (
event->type() == QEvent::KeyPress ||
event->type() == QEvent::KeyRelease)
184 QKeyEvent *keyEvent =
static_cast<QKeyEvent *
>(
event);
185 if (keyEvent->key() == Qt::Key_Comma)
188 QKeyEvent periodKeyEvent(
event->type(), Qt::Key_Period, keyEvent->modifiers(),
".", keyEvent->isAutoRepeat(), keyEvent->count());
189 return QAbstractSpinBox::event(&periodKeyEvent);
192 return QAbstractSpinBox::event(
event);
199 if (text().isEmpty())
200 return StepUpEnabled;
202 StepEnabled rv = StepNone;
207 rv |= StepDownEnabled;
218#include <qt/bitcoinamountfield.moc>
224 amount->setLocale(QLocale::c());
225 amount->installEventFilter(
this);
226 amount->setMaximumWidth(240);
228 QHBoxLayout *layout =
new QHBoxLayout(
this);
229 layout->addWidget(
amount);
232 layout->addWidget(
unit);
233 layout->addStretch(1);
234 layout->setContentsMargins(0,0,0,0);
238 setFocusPolicy(Qt::TabFocus);
252 unit->setCurrentIndex(0);
257 amount->setEnabled(fEnabled);
258 unit->setEnabled(fEnabled);
272 amount->setStyleSheet(
"");
279 if (event->type() == QEvent::FocusIn)
284 return QWidget::eventFilter(
object, event);
289 QWidget::setTabOrder(prev,
amount);
321 amount->setReadOnly(fReadOnly);
327 unit->setToolTip(
unit->itemData(idx, Qt::ToolTipRole).toString());
331 assert(new_unit.isValid());
int64_t CAmount
Amount in satoshis (Can be negative)
QSpinBox that uses fixed-point numbers internally and uses our own formatting/parsing functions.
void SetMinValue(const CAmount &value)
bool event(QEvent *event) override
void setSingleStep(const CAmount &step)
AmountSpinBox(QWidget *parent)
QValidator::State validate(QString &text, int &pos) const override
CAmount value(bool *valid_out=nullptr) const
StepEnabled stepEnabled() const override
QSize cachedMinimumSizeHint
void fixup(QString &input) const override
CAmount parse(const QString &text, bool *valid_out=nullptr) const
Parse a string into a number of base monetary units and return validity.
void stepBy(int steps) override
void SetMaxValue(const CAmount &value)
void setDisplayUnit(BitcoinUnit unit)
QSize minimumSizeHint() const override
void setValue(const CAmount &value)
void SetAllowEmpty(bool allow)
void setEnabled(bool fEnabled)
Enable/Disable.
void setDisplayUnit(BitcoinUnit new_unit)
Change unit used to display amount.
void SetMaxValue(const CAmount &value)
Set the maximum value in satoshis.
void setSingleStep(const CAmount &step)
Set single step in satoshis.
void SetMinValue(const CAmount &value)
Set the minimum 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 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 setValid(bool valid)
Mark current value as invalid in UI.
void setValue(const CAmount &value)
void SetAllowEmpty(bool allow)
If allow empty is set to false the field will be set to the minimum allowed value if left empty.
Bitcoin unit definitions.
@ UnitRole
Unit identifier.
static CAmount maxMoney()
Return maximum number of base units (Satoshis)
static QString format(Unit unit, const CAmount &amount, bool plussign=false, SeparatorStyle separators=SeparatorStyle::STANDARD, bool justify=false)
Format as string.
static bool parse(Unit unit, const QString &value, CAmount *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.