TickerWidget: don't show percentage on balance

This commit is contained in:
tobtoht 2020-12-14 20:17:03 +01:00
parent b6459d1b64
commit 041c11f618
No known key found for this signature in database
GPG key ID: 1CADD27F41F45C3C
4 changed files with 10 additions and 12 deletions

View file

@ -162,7 +162,7 @@ MainWindow::MainWindow(AppContext *ctx, QWidget *parent) :
ui->tickerLayout->addWidget(tickerWidget);
}
m_balanceWidget = new TickerWidget(this, "XMR", "Balance", true);
m_balanceWidget = new TickerWidget(this, "XMR", "Balance", true, true);
ui->fiatTickerLayout->addWidget(m_balanceWidget);
// Send widget

View file

@ -43,7 +43,7 @@
<item row="1" column="0">
<widget class="QTabWidget" name="tabWidget">
<property name="currentIndex">
<number>7</number>
<number>0</number>
</property>
<property name="iconSize">
<size>

View file

@ -8,11 +8,12 @@
#include "utils/config.h"
#include "mainwindow.h"
TickerWidget::TickerWidget(QWidget *parent, QString symbol, QString title, bool convertBalance) :
TickerWidget::TickerWidget(QWidget *parent, QString symbol, QString title, bool convertBalance, bool hidePercent) :
QWidget(parent),
ui(new Ui::TickerWidget),
m_symbol(std::move(symbol)),
m_convertBalance(convertBalance)
m_convertBalance(convertBalance),
m_hidePercent(hidePercent)
{
ui->setupUi(this);
m_ctx = MainWindow::getContext();
@ -27,6 +28,8 @@ TickerWidget::TickerWidget(QWidget *parent, QString symbol, QString title, bool
this->setPctText(defaultPct, true);
this->setFiatText(defaultFiat, 0.0);
ui->tickerPct->setHidden(hidePercent);
connect(AppContext::prices, &Prices::fiatPricesUpdated, this, &TickerWidget::init);
connect(AppContext::prices, &Prices::cryptoPricesUpdated, this, &TickerWidget::init);
if (convertBalance)
@ -47,7 +50,7 @@ void TickerWidget::init() {
double amount = m_convertBalance ? AppContext::balance : 1.0;
double conversion = AppContext::prices->convert(m_symbol, fiatCurrency, amount);
if (conversion < 0) return;
setPercentHidden(conversion == 0);
ui->tickerPct->setHidden(conversion == 0 || m_hidePercent);
auto markets = AppContext::prices->markets;
if(!markets.contains(m_symbol)) return;
@ -85,10 +88,6 @@ void TickerWidget::removePctContainer() {
ui->tickerPct->deleteLater();
}
void TickerWidget::setPercentHidden(bool hidden) {
ui->tickerPct->setVisible(!hidden);
}
TickerWidget::~TickerWidget() {
delete ui;
}

View file

@ -17,7 +17,7 @@ class TickerWidget : public QWidget
Q_OBJECT
public:
explicit TickerWidget(QWidget *parent, QString symbol, QString title = "", bool convertBalance = false);
explicit TickerWidget(QWidget *parent, QString symbol, QString title = "", bool convertBalance = false, bool hidePercent = false);
void removePctContainer();
void setFiatText(QString &fiatCurrency, double amount);
void setPctText(QString &text, bool positive);
@ -29,11 +29,10 @@ public slots:
void init();
private:
void setPercentHidden(bool hidden);
Ui::TickerWidget *ui;
QString m_symbol;
bool m_convertBalance;
bool m_hidePercent;
AppContext *m_ctx;
};