11 #include <QApplication> 12 #include <QAbstractSpinBox> 13 #include <QHBoxLayout> 26 QAbstractSpinBox(parent),
31 setAlignment(Qt::AlignRight);
33 connect(lineEdit(), SIGNAL(textEdited(QString)),
this, SIGNAL(
valueChanged()));
36 QValidator::State
validate(QString &text,
int &pos)
const 39 return QValidator::Intermediate;
43 return valid ? QValidator::Intermediate : QValidator::Invalid;
46 void fixup(QString &input)
const 54 lineEdit()->setText(input);
60 return parse(text(), valid_out);
103 const QFontMetrics fm(fontMetrics());
104 int h = lineEdit()->minimumSizeHint().height();
108 QStyleOptionSpinBox opt;
109 initStyleOption(&opt);
112 opt.rect.setSize(hint + extra);
113 extra += hint - style()->subControlRect(QStyle::CC_SpinBox, &opt,
114 QStyle::SC_SpinBoxEditField,
this).size();
116 opt.rect.setSize(hint + extra);
117 extra += hint - style()->subControlRect(QStyle::CC_SpinBox, &opt,
118 QStyle::SC_SpinBoxEditField,
this).size();
125 .expandedTo(QApplication::globalStrut());
164 return valid ? val : 0;
170 if (event->type() == QEvent::KeyPress ||
event->type() == QEvent::KeyRelease)
172 QKeyEvent *keyEvent =
static_cast<QKeyEvent *
>(
event);
173 if (keyEvent->key() == Qt::Key_Comma)
176 QKeyEvent periodKeyEvent(event->type(), Qt::Key_Period, keyEvent->modifiers(),
".", keyEvent->isAutoRepeat(), keyEvent->count());
177 return QAbstractSpinBox::event(&periodKeyEvent);
180 return QAbstractSpinBox::event(event);
187 if (text().isEmpty())
188 return StepUpEnabled;
196 rv |= StepDownEnabled;
207 #include <fabcoinamountfield.moc> 215 amount->installEventFilter(
this);
216 amount->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
218 QHBoxLayout *layout =
new QHBoxLayout(
this);
219 layout->addWidget(
amount);
222 unit->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
223 unit->setMinimumWidth(120);
224 layout->addWidget(
unit);
225 layout->setContentsMargins(0,0,0,0);
229 setFocusPolicy(Qt::TabFocus);
234 connect(
unit, SIGNAL(currentIndexChanged(
int)),
this, SLOT(
unitChanged(
int)));
243 unit->setCurrentIndex(0);
248 amount->setEnabled(fEnabled);
249 unit->setEnabled(fEnabled);
263 amount->setStyleSheet(
"");
270 if (event->type() == QEvent::FocusIn)
275 return QWidget::eventFilter(
object, event);
280 QWidget::setTabOrder(prev,
amount);
297 amount->setReadOnly(fReadOnly);
303 unit->setToolTip(
unit->itemData(idx, Qt::ToolTipRole).toString());
CAmount parse(const QString &text, bool *valid_out=0) const
Parse a string into a number of base monetary units and return validity.
bool eventFilter(QObject *object, QEvent *event)
Intercept focus-in event and ',' key presses.
#define SetObjectStyleSheet(object, name)
FabcoinAmountField(QWidget *parent=0)
QSpinBox that uses fixed-point numbers internally and uses our own formatting/parsing functions...
bool validate()
Perform input validation, mark field as invalid if entered value is not valid.
AmountSpinBox(QWidget *parent)
void setSingleStep(const CAmount &step)
Set single step in satoshis.
static bool parse(int unit, const QString &value, CAmount *val_out)
Parse string to coin amount.
void setDisplayUnit(int unit)
void setReadOnly(bool fReadOnly)
Make read-only.
QSize cachedMinimumSizeHint
void setValue(const CAmount &value)
int64_t CAmount
Amount in lius (Can be negative)
void fixup(QString &input) const
QSize minimumSizeHint() const
static QString format(int unit, const CAmount &amount, bool plussign=false, SeparatorStyle separators=separatorStandard)
Format as string.
QValidator::State validate(QString &text, int &pos) const
void setValid(bool valid)
Mark current value as invalid in UI.
static CAmount maxMoney()
Return maximum number of base units (Satoshis)
bool event(QEvent *event)
void setEnabled(bool fEnabled)
Enable/Disable.
void setValue(const QVariant &value)
void setValue(const CAmount &value)
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 setSingleStep(const CAmount &step)
StepEnabled stepEnabled() const
void setMinimum(const CAmount &min)
Fabcoin unit definitions.
void setMinimum(const CAmount &min)
void unitChanged(int idx)
void setDisplayUnit(int unit)
Change unit used to display amount.
void clear()
Make field empty and ready for new input.
CAmount value(bool *valid_out=0) const