From 624f13b2d94fb8a8881338dc43bc876d13784962 Mon Sep 17 00:00:00 2001 From: dsc Date: Fri, 14 May 2021 03:36:33 +0200 Subject: [PATCH] Custom SuchWow donation tip amount --- src/mainwindow.cpp | 5 ++++- src/sendwidget.cpp | 2 -- src/utils/config.cpp | 3 ++- src/utils/config.h | 3 ++- src/widgets/suchwowwidget.cpp | 28 +++++++++++++++++++++++++ src/widgets/suchwowwidget.h | 3 +++ src/widgets/suchwowwidget.ui | 39 +++++++++++++++++++++-------------- 7 files changed, 63 insertions(+), 20 deletions(-) diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 110b78e..9ddffa7 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -274,6 +274,7 @@ MainWindow::MainWindow(AppContext *ctx, QWidget *parent) : // settings connects connect(m_windowSettings, &Settings::preferredFiatCurrencyChanged, this, &MainWindow::onUpdateFiatBalanceWidget); connect(m_windowSettings, &Settings::preferredFiatCurrencyChanged, m_ctx, &AppContext::onPreferredFiatCurrencyChanged); + connect(m_windowSettings, &Settings::preferredFiatCurrencyChanged, ui->suchWowWidget, &SuchWowWidget::onPreferredFiatCurrencyChanged); connect(m_windowSettings, &Settings::preferredFiatCurrencyChanged, ui->sendWidget, QOverload<>::of(&SendWidget::onPreferredFiatCurrencyChanged)); // Skin @@ -1078,7 +1079,9 @@ void MainWindow::showSendScreen(const CCSEntry &entry) { } void MainWindow::suchDonate(const QString address) { - double donation = AppContext::prices->convert("EUR", "WOW", 2); + double tipAmount = config()->get(Config::suchWowTipAmount).toDouble(); + QString preferredCurrency = config()->get(Config::preferredFiatCurrency).toString(); + double donation = AppContext::prices->convert(preferredCurrency, "WOW", tipAmount); ui->sendWidget->fill(address, "SuchWow contribution :-)", donation); ui->tabWidget->setCurrentIndex(Tabs::SEND); } diff --git a/src/sendwidget.cpp b/src/sendwidget.cpp index 20be2e2..4abce16 100644 --- a/src/sendwidget.cpp +++ b/src/sendwidget.cpp @@ -64,8 +64,6 @@ void SendWidget::addressEdited() { if (outputs.size() > 0) { ui->lineAmount->setText(WalletManager::displayAmount(ui->lineAddress->getTotal())); ui->comboCurrencySelection->setCurrentIndex(0); - } else { - ui->lineAmount->setText(""); } ui->btn_openAlias->setVisible(ui->lineAddress->isOpenAlias()); diff --git a/src/utils/config.cpp b/src/utils/config.cpp index c58cdd7..49f0bb0 100644 --- a/src/utils/config.cpp +++ b/src/utils/config.cpp @@ -48,8 +48,9 @@ static const QHash configStrings = { {Config::hideBalance, {QS("hideBalance"), false}}, {Config::hideFiatBalance, {QS("hideFiatBalance"), false}}, {Config::redditFrontend, {QS("redditFrontend"), "old.reddit.com"}}, + {Config::showHistorySyncNotice, {QS("showHistorySyncNotice"), true}}, {Config::ignoreUpdateWarning, {QS("ignoreUpdateWarning"), ""}}, - {Config::showHistorySyncNotice, {QS("showHistorySyncNotice"), true}} + {Config::suchWowTipAmount, {QS("suchWowTipAmount"), 0.75}} }; diff --git a/src/utils/config.h b/src/utils/config.h index 639baab..c8d4882 100644 --- a/src/utils/config.h +++ b/src/utils/config.h @@ -51,7 +51,8 @@ public: hideFiatBalance, redditFrontend, showHistorySyncNotice, - ignoreUpdateWarning + ignoreUpdateWarning, + suchWowTipAmount }; ~Config() override; diff --git a/src/widgets/suchwowwidget.cpp b/src/widgets/suchwowwidget.cpp index f34ae5f..a8a2322 100644 --- a/src/widgets/suchwowwidget.cpp +++ b/src/widgets/suchwowwidget.cpp @@ -47,6 +47,16 @@ SuchWowWidget::SuchWowWidget(QWidget *parent) : m_contextMenu->addAction("Donate", this, &SuchWowWidget::suchDonate); connect(ui->listWidget, &QListWidget::customContextMenuRequested, this, &SuchWowWidget::showContextMenu); + + // tip amount slider + ui->slider_tipAmount->setMinimum(1); + ui->slider_tipAmount->setMaximum(60); + ui->slider_tipAmount->setTickInterval(1); + ui->slider_tipAmount->setSingleStep(1); + double tipAmount = config()->get(Config::suchWowTipAmount).toDouble(); + ui->slider_tipAmount->setValue((int)(tipAmount * 10)); + connect(ui->slider_tipAmount, &QSlider::valueChanged, this, &SuchWowWidget::onTipSliderChanged); + this->setTipAmountLabel(); } void SuchWowWidget::setupTable() { @@ -136,6 +146,24 @@ SuchWowPost *SuchWowWidget::itemToPost() { return nullptr; } +void SuchWowWidget::setTipAmountLabel(double tipAmount) { + if(tipAmount == 0.0) + tipAmount = config()->get(Config::suchWowTipAmount).toDouble(); + + QString amount_fmt = Utils::amountToCurrencyString(tipAmount, config()->get(Config::preferredFiatCurrency).toString()); + ui->label_tipAmount->setText(QString("Default tip amount (%1)").arg(amount_fmt)); +} + +void SuchWowWidget::onTipSliderChanged(int value) { + double amount = (double)value / 10; + config()->set(Config::suchWowTipAmount, amount); + setTipAmountLabel(amount); +} + +void SuchWowWidget::onPreferredFiatCurrencyChanged(const QString &symbol) { + this->setTipAmountLabel(); +} + SuchWowWidget::~SuchWowWidget() { delete ui; } diff --git a/src/widgets/suchwowwidget.h b/src/widgets/suchwowwidget.h index 3db6648..8e9de35 100644 --- a/src/widgets/suchwowwidget.h +++ b/src/widgets/suchwowwidget.h @@ -76,10 +76,12 @@ public: public slots: void onWS(QJsonArray such_data); + void onPreferredFiatCurrencyChanged(const QString &symbol); private slots: void addThumb(SuchWowPost *post); void showImage(SuchWowPost *post); + void onTipSliderChanged(int value); signals: void donate(QString donate); @@ -89,6 +91,7 @@ private: void setupTable(); void suchDonate(); void suchImage(); + void setTipAmountLabel(double tipAmount = 0.0); SuchWowPost* itemToPost(); void showContextMenu(const QPoint &pos); diff --git a/src/widgets/suchwowwidget.ui b/src/widgets/suchwowwidget.ui index de985ec..887b0cd 100644 --- a/src/widgets/suchwowwidget.ui +++ b/src/widgets/suchwowwidget.ui @@ -14,24 +14,33 @@ Form - - 4 - - - 0 - - - 0 - - - 0 - - - 0 - + + + + + + Default tip amount + + + + + + + + 280 + 16777215 + + + + Qt::Horizontal + + + + +