Settings: balance display

This commit is contained in:
tobtoht 2021-05-22 16:12:39 +02:00
parent 50a77307f4
commit 43d9624f5c
No known key found for this signature in database
GPG key ID: 1CADD27F41F45C3C
6 changed files with 62 additions and 9 deletions

View file

@ -470,18 +470,27 @@ void MainWindow::onWalletOpened() {
void MainWindow::onBalanceUpdated(quint64 balance, quint64 spendable) {
qDebug() << Q_FUNC_INFO;
bool hide = config()->get(Config::hideBalance).toBool();
QString label_str = QString("Balance: %1 XMR").arg(WalletManager::displayAmount(spendable, false));
if (balance > spendable) {
label_str += QString(" (+%1 XMR unconfirmed)").arg(WalletManager::displayAmount(balance - spendable, false));
bool hide = config()->get(Config::hideBalance).toBool();
int displaySetting = config()->get(Config::balanceDisplay).toInt();
QString balance_str = "Balance: ";
if (hide) {
balance_str += "HIDDEN";
}
else if (displaySetting == Config::totalBalance) {
balance_str += QString("%1 XMR").arg(WalletManager::displayAmount(balance, false));
}
else if (displaySetting == Config::spendable || displaySetting == Config::spendablePlusUnconfirmed) {
balance_str += QString("%1 XMR").arg(WalletManager::displayAmount(spendable, false));
if (displaySetting == Config::spendablePlusUnconfirmed && balance > spendable) {
balance_str += QString(" (+%1 XMR unconfirmed)").arg(WalletManager::displayAmount(balance - spendable, false));
}
}
if (hide)
label_str = "Balance: HIDDEN";
m_statusLabelBalance->setToolTip("Click for details");
m_statusLabelBalance->setText(label_str);
m_statusLabelBalance->setText(balance_str);
m_balanceWidget->setHidden(hide);
}

View file

@ -74,7 +74,11 @@ Settings::Settings(QSharedPointer<AppContext> ctx, QWidget *parent)
connect(ui->comboBox_dateFormat, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &Settings::comboBox_dateFormatChanged);
connect(ui->comboBox_timeFormat, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &Settings::comboBox_timeFormatChanged);
// setup preferred fiat currency combobox
// Balance display combobox
ui->comboBox_balanceDisplay->setCurrentIndex(config()->get(Config::balanceDisplay).toInt());
connect(ui->comboBox_balanceDisplay, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &Settings::comboBox_balanceDisplayChanged);
// Preferred fiat currency combobox
QStringList fiatCurrencies;
for (int index = 0; index < ui->comboBox_fiatCurrency->count(); index++)
fiatCurrencies << ui->comboBox_fiatCurrency->itemText(index);
@ -155,6 +159,11 @@ void Settings::comboBox_timeFormatChanged(int pos) {
config()->set(Config::timeFormat, m_timeFormats.at(pos));
}
void Settings::comboBox_balanceDisplayChanged(int pos) {
config()->set(Config::balanceDisplay, pos);
m_ctx->updateBalance();
}
void Settings::copyToClipboard() {
ui->textLogs->copy();
}

View file

@ -40,6 +40,7 @@ public slots:
void comboBox_amountPrecisionChanged(int pos);
void comboBox_dateFormatChanged(int pos);
void comboBox_timeFormatChanged(int pos);
void comboBox_balanceDisplayChanged(int pos);
void comboBox_blockExplorerChanged(int pos);
void comboBox_redditFrontendChanged(int pos);

View file

@ -162,6 +162,32 @@
<item row="4" column="1">
<widget class="QComboBox" name="comboBox_timeFormat"/>
</item>
<item row="5" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Balance display:</string>
</property>
</widget>
</item>
<item row="5" column="1">
<widget class="QComboBox" name="comboBox_balanceDisplay">
<item>
<property name="text">
<string>Total balance</string>
</property>
</item>
<item>
<property name="text">
<string>Spendable balance (+ unconfirmed balance)</string>
</property>
</item>
<item>
<property name="text">
<string>Spendable balance</string>
</property>
</item>
</widget>
</item>
</layout>
</item>
<item>

View file

@ -57,6 +57,7 @@ static const QHash<Config::ConfigKey, ConfigDirective> configStrings = {
{Config::amountPrecision, {QS("amountPrecision"), 12}},
{Config::dateFormat, {QS("dateFormat"), "yyyy-MM-dd"}},
{Config::timeFormat, {QS("timeFormat"), "HH:mm"}},
{Config::balanceDisplay, {QS("balanceDisplay"), Config::BalanceDisplay::spendablePlusUnconfirmed}},
{Config::multiBroadcast, {QS("multiBroadcast"), true}},
{Config::warnOnExternalLink,{QS("warnOnExternalLink"), true}},

View file

@ -55,6 +55,7 @@ public:
amountPrecision,
dateFormat,
timeFormat,
balanceDisplay,
multiBroadcast,
warnOnExternalLink,
@ -78,6 +79,12 @@ public:
allTor
};
enum BalanceDisplay {
totalBalance = 0,
spendablePlusUnconfirmed,
spendable
};
~Config() override;
QVariant get(ConfigKey key);
QString getFileName();