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