1 // Copyright (c) 2011-2016 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.
5 #ifndef BITCOIN_QT_BITCOINUNITS_H
6 #define BITCOIN_QT_BITCOINUNITS_H
10 #include <QAbstractListModel>
13 // U+2009 THIN SPACE = UTF-8 E2 80 89
14 #define REAL_THIN_SP_CP 0x2009
15 #define REAL_THIN_SP_UTF8 "\xE2\x80\x89"
16 #define REAL_THIN_SP_HTML " "
18 // U+200A HAIR SPACE = UTF-8 E2 80 8A
19 #define HAIR_SP_CP 0x200A
20 #define HAIR_SP_UTF8 "\xE2\x80\x8A"
21 #define HAIR_SP_HTML " "
23 // U+2006 SIX-PER-EM SPACE = UTF-8 E2 80 86
24 #define SIXPEREM_SP_CP 0x2006
25 #define SIXPEREM_SP_UTF8 "\xE2\x80\x86"
26 #define SIXPEREM_SP_HTML " "
28 // U+2007 FIGURE SPACE = UTF-8 E2 80 87
29 #define FIGURE_SP_CP 0x2007
30 #define FIGURE_SP_UTF8 "\xE2\x80\x87"
31 #define FIGURE_SP_HTML " "
33 // QMessageBox seems to have a bug whereby it doesn't display thin/hair spaces
34 // correctly. Workaround is to display a space in a small font. If you
35 // change this, please test that it doesn't cause the parent span to start
37 #define HTML_HACK_SP "<span style='white-space: nowrap; font-size: 6pt'> </span>"
39 // Define THIN_SP_* variables to be our preferred type of thin space
40 #define THIN_SP_CP REAL_THIN_SP_CP
41 #define THIN_SP_UTF8 REAL_THIN_SP_UTF8
42 #define THIN_SP_HTML HTML_HACK_SP
44 /** Bitcoin unit definitions. Encapsulates parsing and formatting
45 and serves as list model for drop-down selection boxes.
47 class BitcoinUnits
: public QAbstractListModel
52 explicit BitcoinUnits(QObject
*parent
);
55 @note Source: https://en.bitcoin.it/wiki/Units . Please add only sensible ones
72 //! Unit conversion and formatting
75 //! Get list of units, for drop-down box
76 static QList
<Unit
> availableUnits();
78 static bool valid(int unit
);
80 static QString
name(int unit
);
81 //! Longer description
82 static QString
description(int unit
);
83 //! Number of Satoshis (1e-8) per unit
84 static qint64
factor(int unit
);
85 //! Number of decimals left
86 static int decimals(int unit
);
88 static QString
format(int unit
, const CAmount
& amount
, bool plussign
=false, SeparatorStyle separators
=separatorStandard
);
89 //! Format as string (with unit)
90 static QString
formatWithUnit(int unit
, const CAmount
& amount
, bool plussign
=false, SeparatorStyle separators
=separatorStandard
);
91 //! Format as HTML string (with unit)
92 static QString
formatHtmlWithUnit(int unit
, const CAmount
& amount
, bool plussign
=false, SeparatorStyle separators
=separatorStandard
);
93 //! Parse string to coin amount
94 static bool parse(int unit
, const QString
&value
, CAmount
*val_out
);
95 //! Gets title for amount column including current display unit if optionsModel reference available */
96 static QString
getAmountColumnTitle(int unit
);
99 //! @name AbstractListModel implementation
100 //! List model for unit drop-down selection box.
103 /** Unit identifier */
104 UnitRole
= Qt::UserRole
106 int rowCount(const QModelIndex
&parent
) const;
107 QVariant
data(const QModelIndex
&index
, int role
) const;
110 static QString
removeSpaces(QString text
)
113 text
.remove(QChar(THIN_SP_CP
));
114 #if (THIN_SP_CP != REAL_THIN_SP_CP)
115 text
.remove(QChar(REAL_THIN_SP_CP
));
120 //! Return maximum number of base units (Satoshis)
121 static CAmount
maxMoney();
124 QList
<BitcoinUnits::Unit
> unitlist
;
126 typedef BitcoinUnits::Unit BitcoinUnit
;
128 #endif // BITCOIN_QT_BITCOINUNITS_H