1 // Copyright (c) 2011-present The Bitcoin Core developers
2 // Distributed under the MIT software license, see the accompanying
3 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
4 5 #ifndef BITCOIN_QT_BITCOINAMOUNTFIELD_H
6 #define BITCOIN_QT_BITCOINAMOUNTFIELD_H
7 8 #include <consensus/amount.h>
9 #include <qt/bitcoinunits.h>
10 11 #include <QWidget>
12 13 class AmountSpinBox;
14 15 QT_BEGIN_NAMESPACE
16 class QValueComboBox;
17 QT_END_NAMESPACE
18 19 /** Widget for entering bitcoin amounts.
20 */
21 class BitcoinAmountField: public QWidget
22 {
23 Q_OBJECT
24 25 // ugly hack: for some unknown reason CAmount (instead of qint64) does not work here as expected
26 // discussion: https://github.com/bitcoin/bitcoin/pull/5117
27 Q_PROPERTY(qint64 value READ value WRITE setValue NOTIFY valueChanged USER true)
28 29 public:
30 explicit BitcoinAmountField(QWidget *parent = nullptr);
31 32 CAmount value(bool *value=nullptr) const;
33 void setValue(const CAmount& value);
34 35 /** If allow empty is set to false the field will be set to the minimum allowed value if left empty. **/
36 void SetAllowEmpty(bool allow);
37 38 /** Set the minimum value in satoshis **/
39 void SetMinValue(const CAmount& value);
40 41 /** Set the maximum value in satoshis **/
42 void SetMaxValue(const CAmount& value);
43 44 /** Set single step in satoshis **/
45 void setSingleStep(const CAmount& step);
46 47 /** Make read-only **/
48 void setReadOnly(bool fReadOnly);
49 50 /** Mark current value as invalid in UI. */
51 void setValid(bool valid);
52 /** Perform input validation, mark field as invalid if entered value is not valid. */
53 bool validate();
54 55 /** Change unit used to display amount. */
56 void setDisplayUnit(BitcoinUnit new_unit);
57 58 /** Make field empty and ready for new input. */
59 void clear();
60 61 /** Enable/Disable. */
62 void setEnabled(bool fEnabled);
63 64 /** Qt messes up the tab chain by default in some cases (issue https://bugreports.qt-project.org/browse/QTBUG-10907),
65 in these cases we have to set it up manually.
66 */
67 QWidget *setupTabChain(QWidget *prev);
68 69 Q_SIGNALS:
70 void valueChanged();
71 72 protected:
73 /** Intercept focus-in event and ',' key presses */
74 bool eventFilter(QObject *object, QEvent *event) override;
75 76 private:
77 AmountSpinBox* amount{nullptr};
78 QValueComboBox *unit;
79 80 private Q_SLOTS:
81 void unitChanged(int idx);
82 83 };
84 85 #endif // BITCOIN_QT_BITCOINAMOUNTFIELD_H
86