7 #include <QApplication> 8 #include <QAbstractSpinBox> 11 #include <QHBoxLayout> 22 QAbstractSpinBox(parent),
28 setAlignment(Qt::AlignRight);
30 connect(lineEdit(), SIGNAL(textEdited(QString)),
this, SIGNAL(
valueChanged()));
33 QValidator::State
validate(QString &text,
int &pos)
const 36 return QValidator::Intermediate;
40 return valid ? QValidator::Intermediate : QValidator::Invalid;
43 void fixup(QString &input)
const 46 int256_t val =
parse(input, &valid);
51 lineEdit()->setText(input);
55 int256_t
value(
bool *valid_out=0)
const 57 return parse(text(), valid_out);
70 int256_t val =
value(&valid);
109 int256_t
parse(
const QString &text,
bool *valid_out=0)
const 115 if(val < 0 || val > totalSupply)
120 return valid ? val : 0;
134 return a > b ? a :
b;
138 return a > b ? b :
a;
144 if (event->type() == QEvent::KeyPress ||
event->type() == QEvent::KeyRelease)
146 QKeyEvent *keyEvent =
static_cast<QKeyEvent *
>(
event);
147 if (keyEvent->key() == Qt::Key_Comma)
150 QKeyEvent periodKeyEvent(event->type(), Qt::Key_Period, keyEvent->modifiers(),
".", keyEvent->isAutoRepeat(), keyEvent->count());
151 return QAbstractSpinBox::event(&periodKeyEvent);
154 return QAbstractSpinBox::event(event);
161 if (text().isEmpty())
162 return StepUpEnabled;
166 int256_t val =
value(&valid);
170 rv |= StepDownEnabled;
171 if(val < totalSupply)
181 #include <tokenamountfield.moc> 189 amount->installEventFilter(
this);
191 QHBoxLayout *layout =
new QHBoxLayout(
this);
192 layout->addWidget(
amount);
194 layout->setContentsMargins(0,0,0,0);
207 amount->setEnabled(fEnabled);
221 amount->setStyleSheet(
"");
228 if (event->type() == QEvent::FocusIn)
233 return QWidget::eventFilter(
object, event);
248 amount->setReadOnly(fReadOnly);
273 return QString::fromStdString(
value().str());
void setDecimalUnits(int value)
void setTotalSupply(const int256_t &value)
void setTotalSupply(const int256_t &value)
#define SetObjectStyleSheet(object, name)
QSpinBox that uses fixed-point numbers internally and uses our own formatting/parsing functions...
QValidator::State validate(QString &text, int &pos) const
void setValue(const int256_t &value)
void setValue(const int256_t &value)
TokenAmountField(QWidget *parent=0)
StepEnabled stepEnabled() const
bool eventFilter(QObject *object, QEvent *event)
Intercept focus-in event and ',' key presses.
TokenAmountSpinBox * amount
int256_t parse(const QString &text, bool *valid_out=0) const
Parse a string into a number of base monetary units and return validity.
void clear()
Make field empty and ready for new input.
int256_t value(bool *valid_out=0) const
void setDecimalUnits(int value)
void setMinimum(const int256_t &min)
bool validate()
Perform input validation, mark field as invalid if entered value is not valid.
void setReadOnly(bool fReadOnly)
Make read-only.
int256_t getMin(int256_t a, int256_t b) const
void fixup(QString &input) const
void setMinimum(const int256_t &min)
void setValid(bool valid)
Mark current value as invalid in UI.
int256_t getMax(int256_t a, int256_t b) const
static QString formatToken(int decimal_units, const int256_t &amount, bool plussign=false, SeparatorStyle separators=separatorStandard)
Format token as string.
bool event(QEvent *event)
TokenAmountSpinBox(QWidget *parent)
static bool parseToken(int decimal_units, const QString &value, int256_t *val_out)
Parse string to token amount.
void setEnabled(bool fEnabled)
Enable/Disable.