mirror of
https://github.com/feather-wallet/feather.git
synced 2025-01-25 03:45:53 +00:00
Clean up calcwidget
This commit is contained in:
parent
1e23b0679e
commit
65e95f0e65
5 changed files with 39 additions and 169 deletions
|
@ -29,92 +29,48 @@ CalcWidget::CalcWidget(QWidget *parent)
|
||||||
ui->lineFrom->setValidator(dv);
|
ui->lineFrom->setValidator(dv);
|
||||||
ui->lineTo->setValidator(dv);
|
ui->lineTo->setValidator(dv);
|
||||||
|
|
||||||
connect(&appData()->prices, &Prices::fiatPricesUpdated, this, &CalcWidget::initFiat);
|
connect(&appData()->prices, &Prices::fiatPricesUpdated, this, &CalcWidget::initComboBox);
|
||||||
connect(&appData()->prices, &Prices::cryptoPricesUpdated, this, &CalcWidget::initCrypto);;
|
connect(&appData()->prices, &Prices::cryptoPricesUpdated, this, &CalcWidget::initComboBox);
|
||||||
|
|
||||||
|
connect(ui->lineFrom, &QLineEdit::textEdited, this, [this]{this->convert(false);});
|
||||||
|
connect(ui->lineTo, &QLineEdit::textEdited, this, [this]{this->convert(true);});
|
||||||
|
|
||||||
|
connect(ui->comboCalcFrom, QOverload<int>::of(&QComboBox::currentIndexChanged), [this]{this->convert(false);});
|
||||||
|
connect(ui->comboCalcTo, QOverload<int>::of(&QComboBox::currentIndexChanged), [this]{this->convert(true);});
|
||||||
}
|
}
|
||||||
|
|
||||||
void CalcWidget::fromChanged(const QString &data) {
|
void CalcWidget::convert(bool reverse) {
|
||||||
if(!this->m_comboBoxInit) return;
|
if (!m_comboBoxInit)
|
||||||
if(this->m_changing){
|
|
||||||
this->m_changing = false;
|
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
QString symbolFrom = ui->comboCalcFrom->itemText(ui->comboCalcFrom->currentIndex());
|
auto lineFrom = reverse ? ui->lineTo : ui->lineFrom;
|
||||||
QString symbolTo = ui->comboCalcTo->itemText(ui->comboCalcTo->currentIndex());
|
auto lineTo = reverse ? ui->lineFrom : ui->lineTo;
|
||||||
|
|
||||||
|
auto comboFrom = reverse ? ui->comboCalcTo : ui->comboCalcFrom;
|
||||||
|
auto comboTo = reverse ? ui->comboCalcFrom : ui->comboCalcTo;
|
||||||
|
|
||||||
|
QString symbolFrom = comboFrom->itemText(comboFrom->currentIndex());
|
||||||
|
QString symbolTo = comboTo->itemText(comboTo->currentIndex());
|
||||||
|
|
||||||
if (symbolFrom == symbolTo) {
|
if (symbolFrom == symbolTo) {
|
||||||
ui->lineTo->setText(data);
|
lineTo->setText(lineFrom->text());
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QString amount_str = ui->lineFrom->text();
|
QString amountStr = lineFrom->text();
|
||||||
if(amount_str.startsWith('.')){
|
double amount = amountStr.toDouble();
|
||||||
ui->lineFrom->setText(ui->lineTo->text());
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
double amount = amount_str.toDouble();
|
|
||||||
double result = appData()->prices.convert(symbolFrom, symbolTo, amount);
|
double result = appData()->prices.convert(symbolFrom, symbolTo, amount);
|
||||||
|
|
||||||
this->m_changing = true;
|
|
||||||
|
|
||||||
int precision = 10;
|
int precision = 10;
|
||||||
if (appData()->prices.rates.contains(symbolTo))
|
if (appData()->prices.rates.contains(symbolTo))
|
||||||
precision = 2;
|
precision = 2;
|
||||||
|
|
||||||
ui->lineTo->setText(QString::number(result, 'f', precision));
|
lineTo->setText(QString::number(result, 'f', precision));
|
||||||
}
|
|
||||||
|
|
||||||
void CalcWidget::toChanged(const QString &data) {
|
|
||||||
if(!this->m_comboBoxInit) return;
|
|
||||||
if(this->m_changing){
|
|
||||||
this->m_changing = false;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
QString symbolFrom = ui->comboCalcFrom->itemText(
|
|
||||||
ui->comboCalcFrom->currentIndex());
|
|
||||||
QString symbolTo = ui->comboCalcTo->itemText(
|
|
||||||
ui->comboCalcTo->currentIndex());
|
|
||||||
|
|
||||||
if(symbolFrom == symbolTo){
|
|
||||||
ui->lineTo->setText(ui->lineFrom->text());
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
QString amount_str = ui->lineTo->text();
|
|
||||||
if(amount_str.startsWith('.')){
|
|
||||||
ui->lineTo->setText("");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
double amount = amount_str.toDouble();
|
|
||||||
double result = appData()->prices.convert(symbolTo, symbolFrom, amount);
|
|
||||||
|
|
||||||
this->m_changing = true;
|
|
||||||
|
|
||||||
int precision = 10;
|
|
||||||
if(appData()->prices.rates.contains(symbolFrom))
|
|
||||||
precision = 2;
|
|
||||||
|
|
||||||
ui->lineFrom->setText(QString::number(result, 'f', precision));
|
|
||||||
}
|
|
||||||
|
|
||||||
void CalcWidget::toComboChanged(const QString &data) {
|
|
||||||
this->fromChanged(data);
|
|
||||||
}
|
|
||||||
|
|
||||||
void CalcWidget::initCrypto() {
|
|
||||||
this->initComboBox();
|
|
||||||
}
|
|
||||||
|
|
||||||
void CalcWidget::initFiat() {
|
|
||||||
this->initComboBox();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CalcWidget::initComboBox() {
|
void CalcWidget::initComboBox() {
|
||||||
if(m_comboBoxInit) return;
|
if (m_comboBoxInit)
|
||||||
|
return;
|
||||||
|
|
||||||
QList<QString> marketsKeys = appData()->prices.markets.keys();
|
QList<QString> marketsKeys = appData()->prices.markets.keys();
|
||||||
QList<QString> ratesKeys = appData()->prices.rates.keys();
|
QList<QString> ratesKeys = appData()->prices.rates.keys();
|
||||||
if(marketsKeys.count() <= 0 || ratesKeys.count() <= 0) return;
|
if(marketsKeys.count() <= 0 || ratesKeys.count() <= 0) return;
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
// SPDX-License-Identifier: BSD-3-Clause
|
// SPDX-License-Identifier: BSD-3-Clause
|
||||||
// Copyright (c) 2020-2021, The Monero Project.
|
// Copyright (c) 2020-2021, The Monero Project.
|
||||||
|
|
||||||
#ifndef CALC_H
|
#ifndef FEATHER_CALCWIDGET_H
|
||||||
#define CALC_H
|
#define FEATHER_CALCWIDGET_H
|
||||||
|
|
||||||
#include <QWidget>
|
#include <QWidget>
|
||||||
|
|
||||||
|
@ -18,23 +18,17 @@ public:
|
||||||
explicit CalcWidget(QWidget *parent = nullptr);
|
explicit CalcWidget(QWidget *parent = nullptr);
|
||||||
~CalcWidget() override;
|
~CalcWidget() override;
|
||||||
|
|
||||||
signals:
|
|
||||||
void closed();
|
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void fromChanged(const QString& data);
|
|
||||||
void toChanged(const QString& data);
|
|
||||||
void toComboChanged(const QString& data);
|
|
||||||
void initFiat();
|
|
||||||
void initCrypto();
|
|
||||||
void skinChanged();
|
void skinChanged();
|
||||||
|
|
||||||
private:
|
private slots:
|
||||||
Ui::CalcWidget *ui;
|
|
||||||
|
|
||||||
bool m_comboBoxInit = false;
|
|
||||||
void initComboBox();
|
void initComboBox();
|
||||||
bool m_changing = false;
|
|
||||||
|
private:
|
||||||
|
void convert(bool reverse);
|
||||||
|
|
||||||
|
Ui::CalcWidget *ui;
|
||||||
|
bool m_comboBoxInit = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // CALC_H
|
#endif // FEATHER_CALCWIDGET_H
|
||||||
|
|
|
@ -167,72 +167,7 @@
|
||||||
</customwidget>
|
</customwidget>
|
||||||
</customwidgets>
|
</customwidgets>
|
||||||
<resources/>
|
<resources/>
|
||||||
<connections>
|
<connections/>
|
||||||
<connection>
|
|
||||||
<sender>lineFrom</sender>
|
|
||||||
<signal>textChanged(QString)</signal>
|
|
||||||
<receiver>CalcWidget</receiver>
|
|
||||||
<slot>fromChanged(QString)</slot>
|
|
||||||
<hints>
|
|
||||||
<hint type="sourcelabel">
|
|
||||||
<x>119</x>
|
|
||||||
<y>77</y>
|
|
||||||
</hint>
|
|
||||||
<hint type="destinationlabel">
|
|
||||||
<x>427</x>
|
|
||||||
<y>-1</y>
|
|
||||||
</hint>
|
|
||||||
</hints>
|
|
||||||
</connection>
|
|
||||||
<connection>
|
|
||||||
<sender>lineTo</sender>
|
|
||||||
<signal>textChanged(QString)</signal>
|
|
||||||
<receiver>CalcWidget</receiver>
|
|
||||||
<slot>toChanged(QString)</slot>
|
|
||||||
<hints>
|
|
||||||
<hint type="sourcelabel">
|
|
||||||
<x>463</x>
|
|
||||||
<y>86</y>
|
|
||||||
</hint>
|
|
||||||
<hint type="destinationlabel">
|
|
||||||
<x>640</x>
|
|
||||||
<y>-4</y>
|
|
||||||
</hint>
|
|
||||||
</hints>
|
|
||||||
</connection>
|
|
||||||
<connection>
|
|
||||||
<sender>comboCalcFrom</sender>
|
|
||||||
<signal>currentIndexChanged(QString)</signal>
|
|
||||||
<receiver>CalcWidget</receiver>
|
|
||||||
<slot>fromChanged(QString)</slot>
|
|
||||||
<hints>
|
|
||||||
<hint type="sourcelabel">
|
|
||||||
<x>196</x>
|
|
||||||
<y>77</y>
|
|
||||||
</hint>
|
|
||||||
<hint type="destinationlabel">
|
|
||||||
<x>330</x>
|
|
||||||
<y>-9</y>
|
|
||||||
</hint>
|
|
||||||
</hints>
|
|
||||||
</connection>
|
|
||||||
<connection>
|
|
||||||
<sender>comboCalcTo</sender>
|
|
||||||
<signal>currentIndexChanged(QString)</signal>
|
|
||||||
<receiver>CalcWidget</receiver>
|
|
||||||
<slot>toComboChanged(QString)</slot>
|
|
||||||
<hints>
|
|
||||||
<hint type="sourcelabel">
|
|
||||||
<x>574</x>
|
|
||||||
<y>82</y>
|
|
||||||
</hint>
|
|
||||||
<hint type="destinationlabel">
|
|
||||||
<x>265</x>
|
|
||||||
<y>-5</y>
|
|
||||||
</hint>
|
|
||||||
</hints>
|
|
||||||
</connection>
|
|
||||||
</connections>
|
|
||||||
<slots>
|
<slots>
|
||||||
<slot>fromChanged(QString)</slot>
|
<slot>fromChanged(QString)</slot>
|
||||||
<slot>toChanged(QString)</slot>
|
<slot>toChanged(QString)</slot>
|
||||||
|
|
|
@ -17,17 +17,6 @@ CalcWindow::CalcWindow(QWidget *parent)
|
||||||
|
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
this->setWindowIcon(icons()->icon("gnome-calc.png"));
|
this->setWindowIcon(icons()->icon("gnome-calc.png"));
|
||||||
|
|
||||||
connect(&appData()->prices, &Prices::fiatPricesUpdated, this, &CalcWindow::initFiat);
|
|
||||||
connect(&appData()->prices, &Prices::cryptoPricesUpdated, this, &CalcWindow::initCrypto);
|
|
||||||
}
|
|
||||||
|
|
||||||
void CalcWindow::initFiat() {
|
|
||||||
this->ui->calcWidget->initFiat();
|
|
||||||
}
|
|
||||||
|
|
||||||
void CalcWindow::initCrypto() {
|
|
||||||
this->ui->calcWidget->initCrypto();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CalcWindow::closeEvent(QCloseEvent *foo) {
|
void CalcWindow::closeEvent(QCloseEvent *foo) {
|
||||||
|
|
|
@ -21,10 +21,6 @@ public:
|
||||||
signals:
|
signals:
|
||||||
void closed();
|
void closed();
|
||||||
|
|
||||||
public slots:
|
|
||||||
void initFiat();
|
|
||||||
void initCrypto();
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void closeEvent(QCloseEvent *bar) override;
|
void closeEvent(QCloseEvent *bar) override;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue