12 #include <QApplication> 13 #include <QAbstractSpinBox> 14 #include <QHBoxLayout> 27 QAbstractSpinBox(parent)
29 setAlignment(Qt::AlignRight);
37 return QValidator::Intermediate;
41 return valid ? QValidator::Intermediate : QValidator::Invalid;
44 void fixup(QString &input)
const override 54 val =
parse(input, &valid);
60 lineEdit()->setText(input);
66 return parse(text(), valid_out);
123 const QFontMetrics fm(fontMetrics());
124 int h = lineEdit()->minimumSizeHint().height();
128 QStyleOptionSpinBox opt;
129 initStyleOption(&opt);
132 opt.rect.setSize(hint + extra);
133 extra += hint - style()->subControlRect(QStyle::CC_SpinBox, &opt,
134 QStyle::SC_SpinBoxEditField,
this).size();
136 opt.rect.setSize(hint + extra);
137 extra += hint - style()->subControlRect(QStyle::CC_SpinBox, &opt,
138 QStyle::SC_SpinBoxEditField,
this).size();
145 .expandedTo(QApplication::globalStrut());
174 return valid ? val : 0;
180 if (event->type() == QEvent::KeyPress ||
event->type() == QEvent::KeyRelease)
182 QKeyEvent *keyEvent =
static_cast<QKeyEvent *
>(
event);
183 if (keyEvent->key() == Qt::Key_Comma)
186 QKeyEvent periodKeyEvent(event->type(), Qt::Key_Period, keyEvent->modifiers(),
".", keyEvent->isAutoRepeat(), keyEvent->count());
187 return QAbstractSpinBox::event(&periodKeyEvent);
190 return QAbstractSpinBox::event(event);
197 if (text().isEmpty())
198 return StepUpEnabled;
200 StepEnabled rv = StepNone;
205 rv |= StepDownEnabled;
216 #include <qt/bitcoinamountfield.moc> 223 amount->setLocale(QLocale::c());
224 amount->installEventFilter(
this);
225 amount->setMaximumWidth(240);
227 QHBoxLayout *layout =
new QHBoxLayout(
this);
228 layout->addWidget(
amount);
231 layout->addWidget(
unit);
232 layout->addStretch(1);
233 layout->setContentsMargins(0,0,0,0);
237 setFocusPolicy(Qt::TabFocus);
251 unit->setCurrentIndex(0);
256 amount->setEnabled(fEnabled);
257 unit->setEnabled(fEnabled);
271 amount->setStyleSheet(
"");
278 if (event->type() == QEvent::FocusIn)
283 return QWidget::eventFilter(
object, event);
288 QWidget::setTabOrder(prev,
amount);
320 amount->setReadOnly(fReadOnly);
326 unit->setToolTip(
unit->itemData(idx, Qt::ToolTipRole).toString());
bool validate()
Perform input validation, mark field as invalid if entered value is not valid.
Bitcoin unit definitions.
void setReadOnly(bool fReadOnly)
Make read-only.
QSpinBox that uses fixed-point numbers internally and uses our own formatting/parsing functions...
int TextWidth(const QFontMetrics &fm, const QString &text)
Returns the distance in pixels appropriate for drawing a subsequent character after text...
void SetAllowEmpty(bool allow)
static QString format(int unit, const CAmount &amount, bool plussign=false, SeparatorStyle separators=SeparatorStyle::STANDARD, bool justify=false)
Format as string.
QSize minimumSizeHint() const override
AmountSpinBox(QWidget *parent)
QWidget * setupTabChain(QWidget *prev)
Qt messes up the tab chain by default in some cases (issue https://bugreports.qt-project.org/browse/QTBUG-10907), in these cases we have to set it up manually.
StepEnabled stepEnabled() const override
void setDisplayUnit(int unit)
State
The various states a (txhash,peer) pair can be in.
CAmount value(bool *valid_out=nullptr) const
void fixup(QString &input) const override
QSize cachedMinimumSizeHint
static bool parse(int unit, const QString &value, CAmount *val_out)
Parse string to coin amount.
disconnectpool queuedTx clear()
BitcoinAmountField(QWidget *parent=nullptr)
QValidator::State validate(QString &text, int &pos) const override
void setValue(const CAmount &value)
int64_t CAmount
Amount in satoshis (Can be negative)
void setEnabled(bool fEnabled)
Enable/Disable.
bool event(QEvent *event) override
void unitChanged(int idx)
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 setSingleStep(const CAmount &step)
Set single step in satoshis.
void setValue(const QVariant &value)
void SetMaxValue(const CAmount &value)
void clear()
Make field empty and ready for new input.
void setValid(bool valid)
Mark current value as invalid in UI.
void setSingleStep(const CAmount &step)
void SetMaxValue(const CAmount &value)
Set the maximum value in satoshis.
void SetMinValue(const CAmount &value)
void stepBy(int steps) 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 setDisplayUnit(int unit)
Change unit used to display amount.
void setValue(const CAmount &value)
static CAmount maxMoney()
Return maximum number of base units (Satoshis)
void SetAllowEmpty(bool allow)
If allow empty is set to false the field will be set to the minimum allowed value if left empty...