12 #include <QApplication>
13 #include <QDoubleSpinBox>
14 #include <QHBoxLayout>
25 amount =
new QDoubleSpinBox(
this);
26 amount->setLocale(QLocale::c());
27 amount->installEventFilter(
this);
28 amount->setMaximumWidth(170);
30 QHBoxLayout *layout =
new QHBoxLayout(
this);
34 layout->addWidget(
unit);
35 layout->addStretch(1);
36 layout->setContentsMargins(0,0,0,0);
40 setFocusPolicy(Qt::TabFocus);
45 connect(
unit, SIGNAL(currentIndexChanged(
int)),
this, SLOT(
unitChanged(
int)));
56 amount->setValue(text.toDouble());
62 unit->setCurrentIndex(0);
68 if (
amount->value() == 0.0)
90 if (
amount->text().isEmpty())
98 if (event->type() == QEvent::FocusIn)
103 else if (event->type() == QEvent::KeyPress ||
event->type() == QEvent::KeyRelease)
105 QKeyEvent *keyEvent =
static_cast<QKeyEvent *
>(event);
106 if (keyEvent->key() == Qt::Key_Comma)
109 QKeyEvent periodKeyEvent(event->type(), Qt::Key_Period, keyEvent->modifiers(),
".", keyEvent->isAutoRepeat(), keyEvent->count());
110 QApplication::sendEvent(
object, &periodKeyEvent);
114 return QWidget::eventFilter(
object, event);
119 QWidget::setTabOrder(prev,
amount);
142 amount->setReadOnly(fReadOnly);
143 unit->setEnabled(!fReadOnly);
149 unit->setToolTip(
unit->itemData(idx, Qt::ToolTipRole).toString());
156 qint64 currentValue =
value(&valid);
void setText(const QString &text)
void setDisplayUnit(int unit)
Change unit used to display amount.
Anoncoin unit definitions.
void setValue(qint64 value)
void setValid(bool valid)
Mark current value as invalid in UI.
bool validate()
Perform input validation, mark field as invalid if entered value is not valid.
static bool parse(int unit, const QString &value, qint64 *val_out)
Parse string to coin amount.
static qint64 maxAmount(int unit)
Max amount per unit.
void unitChanged(int idx)
static qint64 factor(int unit)
Number of Satoshis (1e-8) per unit.
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.
static QString format(int unit, qint64 amount, bool plussign=false)
Format as string.
static int amountDigits(int unit)
Number of amount digits (to represent max number of coins)
void clear()
Make field empty and ready for new input.
void setValue(const QVariant &value)
bool eventFilter(QObject *object, QEvent *event)
Intercept focus-in event and ',' key presses.
void setSingleStep(qint64 step)
Set single step in satoshis.
void setReadOnly(bool fReadOnly)
Make read-only.
static int decimals(int unit)
Number of decimals left.
AnoncoinAmountField(QWidget *parent=0)