allow multiple units in bitcoin amount widget (for example, for sending) using a...
[novacoin.git] / src / qt / bitcoinunits.h
1 #ifndef BITCOINUNITS_H
2 #define BITCOINUNITS_H
3
4 #include <QString>
5 #include <QAbstractListModel>
6
7 // Bitcoin unit definitions
8 class BitcoinUnits: public QAbstractListModel
9 {
10 public:
11     explicit BitcoinUnits(QObject *parent);
12
13     enum Unit
14     {
15         // Source: https://en.bitcoin.it/wiki/Units
16         // Please add only sensible ones
17         BTC,
18         mBTC,
19         uBTC
20     };
21
22     /// Static API
23     // Get list of units, for dropdown box
24     static QList<Unit> availableUnits();
25     // Short name
26     static QString name(int unit);
27     // Longer description
28     static QString description(int unit);
29     // Number of satoshis / unit
30     static qint64 factor(int unit);
31     // Number of amount digits (to represent max number of coins)
32     static int amountDigits(int unit);
33     // Number of decimals left
34     static int decimals(int unit);
35     // Format as string
36     static QString format(int unit, qint64 amount, bool plussign=false);
37     // Format as string (with unit)
38     static QString formatWithUnit(int unit, qint64 amount, bool plussign=false);
39     // Parse string to coin amount
40     static bool parse(int unit, const QString &value, qint64 *val_out);
41
42     /// AbstractListModel implementation
43     enum {
44         // Unit identifier
45         UnitRole = Qt::UserRole
46     } RoleIndex;
47     int rowCount(const QModelIndex &parent) const;
48     QVariant data(const QModelIndex &index, int role) const;
49 private:
50     QList<BitcoinUnits::Unit> unitlist;
51 };
52 typedef BitcoinUnits::Unit BitcoinUnit;
53
54 #endif // BITCOINUNITS_H