mirror of
https://github.com/feather-wallet/feather.git
synced 2024-12-22 19:49:28 +00:00
Merge pull request 'TickerWidget: Format fiat currency using locale' (#170) from tobtoht/feather:ticker_locale into master
Reviewed-on: https://git.wownero.com/feather/feather/pulls/170
This commit is contained in:
commit
edad1928ab
4 changed files with 21 additions and 13 deletions
|
@ -581,4 +581,19 @@ QString Utils::formatBytes(quint64 bytes)
|
|||
_data = 0;
|
||||
|
||||
return QString("%1 %2").arg(QString::number(_data, 'f', 1), sizes[i]);
|
||||
}
|
||||
|
||||
QString Utils::amountToCurrencyString(double amount, const QString ¤cyCode) {
|
||||
QLocale locale;
|
||||
QList<QLocale> allLocales = QLocale::matchingLocales(QLocale::AnyLanguage, QLocale::AnyScript, QLocale::AnyCountry);
|
||||
for (const auto& locale_: allLocales) {
|
||||
if (locale_.currencySymbol(QLocale::CurrencyIsoCode) == currencyCode) {
|
||||
locale = locale_;
|
||||
}
|
||||
}
|
||||
|
||||
if (currencyCode == "USD")
|
||||
return locale.toCurrencyString(amount, "$");
|
||||
|
||||
return locale.toCurrencyString(amount);
|
||||
}
|
|
@ -96,6 +96,7 @@ public:
|
|||
static QFont relativeFont(int delta);
|
||||
static double roundSignificant(double N, double n);
|
||||
static QString formatBytes(quint64 bytes);
|
||||
static QString amountToCurrencyString(double amount, const QString ¤cyCode);
|
||||
|
||||
static QStringList randomHTTPAgents;
|
||||
|
||||
|
|
|
@ -25,7 +25,7 @@ TickerWidget::TickerWidget(QWidget *parent, QString symbol, QString title, bool
|
|||
|
||||
this->setFontSizes();
|
||||
this->setPctText(defaultPct, true);
|
||||
this->setFiatText(defaultFiat, 0.0, true);
|
||||
this->setFiatText(defaultFiat, 0.0);
|
||||
|
||||
connect(AppContext::prices, &Prices::fiatPricesUpdated, this, &TickerWidget::init);
|
||||
connect(AppContext::prices, &Prices::cryptoPricesUpdated, this, &TickerWidget::init);
|
||||
|
@ -56,19 +56,11 @@ void TickerWidget::init() {
|
|||
auto pct24hText = QString::number(pct24h, 'f', 2);
|
||||
|
||||
this->setPctText(pct24hText, pct24h >= 0.0);
|
||||
this->setFiatText(fiatCurrency, conversion, true);
|
||||
this->setFiatText(fiatCurrency, conversion);
|
||||
}
|
||||
|
||||
void TickerWidget::setFiatText(QString &fiatCurrency, double amount, bool round) {
|
||||
QString number;
|
||||
if(round)
|
||||
number = QString::number(amount, 'f', 2);
|
||||
else
|
||||
number = QString::number(amount);
|
||||
|
||||
auto conversionText = QString("%1 %2")\
|
||||
.arg(number)
|
||||
.arg(fiatCurrency);
|
||||
void TickerWidget::setFiatText(QString &fiatCurrency, double amount) {
|
||||
QString conversionText = Utils::amountToCurrencyString(amount, fiatCurrency);
|
||||
ui->tickerFiat->setText(conversionText);
|
||||
}
|
||||
|
||||
|
|
|
@ -19,7 +19,7 @@ class TickerWidget : public QWidget
|
|||
public:
|
||||
explicit TickerWidget(QWidget *parent, QString symbol, QString title = "", bool convertBalance = false);
|
||||
void removePctContainer();
|
||||
void setFiatText(QString &fiatCurrency, double amount, bool round);
|
||||
void setFiatText(QString &fiatCurrency, double amount);
|
||||
void setPctText(QString &text, bool positive);
|
||||
void setFontSizes();
|
||||
~TickerWidget() override;
|
||||
|
|
Loading…
Reference in a new issue