Fabcoin Core  0.16.2
P2P Digital Currency
fabcoinunits.h
Go to the documentation of this file.
1 // Copyright (c) 2011-2017 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 FABCOIN_QT_FABCOINUNITS_H
6 #define FABCOIN_QT_FABCOINUNITS_H
7 
8 #include <amount.h>
9 
10 #include <QAbstractListModel>
11 #include <QString>
12 #include <boost/multiprecision/cpp_int.hpp>
13 using namespace boost::multiprecision;
14 
15 // U+2009 THIN SPACE = UTF-8 E2 80 89
16 #define REAL_THIN_SP_CP 0x2009
17 #define REAL_THIN_SP_UTF8 "\xE2\x80\x89"
18 #define REAL_THIN_SP_HTML "&thinsp;"
19 
20 // U+200A HAIR SPACE = UTF-8 E2 80 8A
21 #define HAIR_SP_CP 0x200A
22 #define HAIR_SP_UTF8 "\xE2\x80\x8A"
23 #define HAIR_SP_HTML "&#8202;"
24 
25 // U+2006 SIX-PER-EM SPACE = UTF-8 E2 80 86
26 #define SIXPEREM_SP_CP 0x2006
27 #define SIXPEREM_SP_UTF8 "\xE2\x80\x86"
28 #define SIXPEREM_SP_HTML "&#8198;"
29 
30 // U+2007 FIGURE SPACE = UTF-8 E2 80 87
31 #define FIGURE_SP_CP 0x2007
32 #define FIGURE_SP_UTF8 "\xE2\x80\x87"
33 #define FIGURE_SP_HTML "&#8199;"
34 
35 // QMessageBox seems to have a bug whereby it doesn't display thin/hair spaces
36 // correctly. Workaround is to display a space in a small font. If you
37 // change this, please test that it doesn't cause the parent span to start
38 // wrapping.
39 #define HTML_HACK_SP "<span style='white-space: nowrap; font-size: 6pt'> </span>"
40 
41 // Define THIN_SP_* variables to be our preferred type of thin space
42 #define THIN_SP_CP REAL_THIN_SP_CP
43 #define THIN_SP_UTF8 REAL_THIN_SP_UTF8
44 #define THIN_SP_HTML HTML_HACK_SP
45 
49 class FabcoinUnits: public QAbstractListModel
50 {
51  Q_OBJECT
52 
53 public:
54  explicit FabcoinUnits(QObject *parent);
55 
59  enum Unit
60  {
61  FAB,
63  uFAB
64  };
65 
67  {
70  separatorAlways
71  };
72 
76 
78  static QList<Unit> availableUnits();
80  static bool valid(int unit);
82  static QString name(int unit);
84  static QString description(int unit);
86  static qint64 factor(int unit);
88  static int256_t tokenFactor(int unit);
90  static int decimals(int unit);
92  static QString format(int unit, const CAmount& amount, bool plussign=false, SeparatorStyle separators=separatorStandard);
94  static QString formatWithUnit(int unit, const CAmount& amount, bool plussign=false, SeparatorStyle separators=separatorStandard);
96  static QString formatHtmlWithUnit(int unit, const CAmount& amount, bool plussign=false, SeparatorStyle separators=separatorStandard);
98  static bool parse(int unit, const QString &value, CAmount *val_out);
100  static QString getAmountColumnTitle(int unit);
102  static bool parseToken(int decimal_units, const QString &value, int256_t *val_out);
104  static QString formatToken(int decimal_units, const int256_t& amount, bool plussign=false, SeparatorStyle separators=separatorStandard);
105  static QString formatTokenWithUnit(const QString unit, int decimals, const int256_t& amount, bool plussign=false, SeparatorStyle separators=separatorStandard);
108 
112  enum RoleIndex {
114  UnitRole = Qt::UserRole
115  };
116  int rowCount(const QModelIndex &parent) const;
117  QVariant data(const QModelIndex &index, int role) const;
119 
120  static QString removeSpaces(QString text)
121  {
122  text.remove(' ');
123  text.remove(QChar(THIN_SP_CP));
124 #if (THIN_SP_CP != REAL_THIN_SP_CP)
125  text.remove(QChar(REAL_THIN_SP_CP));
126 #endif
127  return text;
128  }
129 
131  static CAmount maxMoney();
132 
133 private:
134  QList<FabcoinUnits::Unit> unitlist;
135 };
137 
138 #endif // FABCOIN_QT_FABCOINUNITS_H
#define THIN_SP_CP
Definition: fabcoinunits.h:42
FabcoinUnits::Unit FabcoinUnit
Definition: fabcoinunits.h:136
int64_t CAmount
Amount in lius (Can be negative)
Definition: amount.h:15
const char * name
Definition: rest.cpp:36
Unit
Fabcoin units.
Definition: fabcoinunits.h:59
QList< FabcoinUnits::Unit > unitlist
Definition: fabcoinunits.h:134
#define REAL_THIN_SP_CP
Definition: fabcoinunits.h:16
static QString removeSpaces(QString text)
Definition: fabcoinunits.h:120
uint8_t format
Fabcoin unit definitions.
Definition: fabcoinunits.h:49
uint8_t const * data
Definition: sha3.h:19