14 #include <QApplication> 15 #include <QAbstractSpinBox> 16 #include <QHBoxLayout> 29 QAbstractSpinBox(parent),
34 setAlignment(Qt::AlignRight);
36 connect(lineEdit(), SIGNAL(textEdited(QString)),
this, SIGNAL(
valueChanged()));
39 QValidator::State
validate(QString &text,
int &pos)
const 42 return QValidator::Intermediate;
46 return valid ? QValidator::Intermediate : QValidator::Invalid;
49 void fixup(QString &input)
const 56 lineEdit()->setText(input);
62 return parse(text(), valid_out);
120 const QFontMetrics fm(fontMetrics());
121 int h = lineEdit()->minimumSizeHint().height();
125 QStyleOptionSpinBox opt;
126 initStyleOption(&opt);
129 opt.rect.setSize(hint + extra);
130 extra += hint - style()->subControlRect(QStyle::CC_SpinBox, &opt,
131 QStyle::SC_SpinBoxEditField,
this).size();
133 opt.rect.setSize(hint + extra);
134 extra += hint - style()->subControlRect(QStyle::CC_SpinBox, &opt,
135 QStyle::SC_SpinBoxEditField,
this).size();
142 .expandedTo(QApplication::globalStrut());
164 if (assetUnit >= 0) {
177 return valid ? val : 0;
183 if (event->type() == QEvent::KeyPress ||
event->type() == QEvent::KeyRelease)
185 QKeyEvent *keyEvent =
static_cast<QKeyEvent *
>(
event);
186 if (keyEvent->key() == Qt::Key_Comma)
189 QKeyEvent periodKeyEvent(event->type(), Qt::Key_Period, keyEvent->modifiers(),
".", keyEvent->isAutoRepeat(), keyEvent->count());
190 return QAbstractSpinBox::event(&periodKeyEvent);
193 return QAbstractSpinBox::event(event);
200 if (text().isEmpty())
201 return StepUpEnabled;
209 rv |= StepDownEnabled;
220 #include "ravenamountfield.moc" 227 amount->setLocale(QLocale::c());
228 amount->installEventFilter(
this);
229 amount->setMaximumWidth(170);
231 QHBoxLayout *layout =
new QHBoxLayout(
this);
232 layout->addWidget(
amount);
235 layout->addWidget(
unit);
236 layout->addStretch(1);
237 layout->setContentsMargins(0,0,0,0);
241 setFocusPolicy(Qt::TabFocus);
246 connect(
unit, SIGNAL(currentIndexChanged(
int)),
this, SLOT(
unitChanged(
int)));
256 unit->setCurrentIndex(0);
261 amount->setEnabled(fEnabled);
262 unit->setEnabled(fEnabled);
276 amount->setStyleSheet(
"");
284 if (event->type() == QEvent::FocusIn)
289 return QWidget::eventFilter(
object, event);
294 QWidget::setTabOrder(prev,
amount);
311 amount->setReadOnly(fReadOnly);
317 unit->setToolTip(
unit->itemData(idx, Qt::ToolTipRole).toString());
340 amount->setLocale(QLocale::c());
341 amount->installEventFilter(
this);
342 amount->setMaximumWidth(170);
344 QHBoxLayout *layout =
new QHBoxLayout(
this);
345 layout->addWidget(
amount);
346 layout->addStretch(1);
347 layout->setContentsMargins(0,0,0,0);
351 setFocusPolicy(Qt::TabFocus);
369 amount->setEnabled(fEnabled);
383 amount->setStyleSheet(
"");
391 if (event->type() == QEvent::FocusIn)
396 return QWidget::eventFilter(
object, event);
411 amount->setReadOnly(fReadOnly);
static QString format(int unit, const CAmount &amount, bool plussign=false, SeparatorStyle separators=separatorStandard, const int nAssetUnit=MIN_ASSET_UNITS - 1)
Format as string.
static bool assetParse(int assetUnit, const QString &value, CAmount *val_out)
bool validate()
Perform input validation, mark field as invalid if entered value is not valid.
void setEnabled(bool fEnabled)
Enable/Disable.
void unitChanged(int idx)
void setEnabled(bool fEnabled)
Enable/Disable.
QSpinBox that uses fixed-point numbers internally and uses our own formatting/parsing functions...
void setValid(bool valid)
Mark current value as invalid in UI.
AmountSpinBox(QWidget *parent)
CAmount value(bool *valid_out=0) const
StepEnabled stepEnabled() const
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.
void setDisplayUnit(int unit)
QSize minimumSizeHint() const
RavenAmountField(QWidget *parent=0)
AssetAmountField(QWidget *parent=0)
void setSingleStep(const CAmount &step)
Set single step in satoshis.
QSize cachedMinimumSizeHint
static bool parse(int unit, const QString &value, CAmount *val_out)
Parse string to coin amount.
QValidator::State validate(QString &text, int &pos) const
void setValue(const CAmount &value)
void setSingleStep(const CAmount &step)
Set single step in satoshis.
int64_t CAmount
Amount in corbies (Can be negative)
void setValue(const CAmount &value)
bool eventFilter(QObject *object, QEvent *event)
Intercept focus-in event and ',' key presses.
bool eventFilter(QObject *object, QEvent *event)
Intercept focus-in event and ',' key presses.
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.
void setDisplayUnit(int unit)
Change unit used to display amount.
CAmount parse(const QString &text, bool *valid_out=0) const
Parse a string into a number of base monetary units and return validity.
void setReadOnly(bool fReadOnly)
Make read-only.
bool event(QEvent *event)
void setReadOnly(bool fReadOnly)
Make read-only.
void setValue(const QVariant &value)
void clear()
Make field empty and ready for new input.
static qint64 factorAsset(int unit)
Number of Satoshis (1e-8) per unit for assets.
void setSingleStep(const CAmount &step)
void setValue(const CAmount &value)
void fixup(QString &input) const
void setAssetUnit(int unit)
void setValid(bool valid)
Mark current value as invalid in UI.
static CAmount maxMoney()
Return maximum number of base units (Satoshis)