From 44da2da96432d5fac1fca622f2f47f2a4b46f2e7 Mon Sep 17 00:00:00 2001 From: firstcryptoman Date: Thu, 13 Jun 2024 19:36:30 +0400 Subject: [PATCH] Update dynamic scaling and resolve #1391 with migration warning adjustment --- src/qt/masternodelist.cpp | 5 +- src/qt/overviewpage.cpp | 108 +++++++++++++++++++++------------- src/qt/overviewpage.h | 4 +- src/qt/receivecoinsdialog.cpp | 5 +- src/qt/sendcoinsdialog.cpp | 21 ++++--- src/qt/sendcoinsentry.cpp | 6 +- src/qt/transactionview.cpp | 5 +- 7 files changed, 100 insertions(+), 54 deletions(-) diff --git a/src/qt/masternodelist.cpp b/src/qt/masternodelist.cpp index dbd89e3565..5f4e4b3f65 100644 --- a/src/qt/masternodelist.cpp +++ b/src/qt/masternodelist.cpp @@ -397,7 +397,10 @@ void MasternodeList::resizeEvent(QResizeEvent* event) } void MasternodeList::adjustTextSize(int width,int height){ - int fontSize = std::max(12, std::min(width, height) / 70); + const double fontSizeScalingFactor = 70.0; + int baseFontSize = std::min(width, height) / fontSizeScalingFactor; + int fontSize = std::max(12, baseFontSize); + QFont font = this->font(); font.setPointSize(fontSize); diff --git a/src/qt/overviewpage.cpp b/src/qt/overviewpage.cpp index 8bd40b8969..8bb56b9208 100644 --- a/src/qt/overviewpage.cpp +++ b/src/qt/overviewpage.cpp @@ -19,6 +19,7 @@ #include "transactiontablemodel.h" #include "walletmodel.h" #include "validation.h" +#include "askpassphrasedialog.h" #ifdef WIN32 #include @@ -380,14 +381,18 @@ void OverviewPage::onRefreshClicked() { auto privateBalance = walletModel->getLelantusModel()->getPrivateBalance(); auto lGracefulPeriod = ::Params().GetConsensus().nLelantusGracefulPeriod; + int heightDifference = lGracefulPeriod - chainActive.Height(); + const int approxBlocksPerDay = 570; + int daysUntilMigrationCloses = heightDifference / approxBlocksPerDay; + if(privateBalance.first > 0 && chainActive.Height() < lGracefulPeriod && spark::IsSparkAllowed()) { ui->warningFrame->show(); - lelantusGracefulPeriod = QString::fromStdString(std::to_string(lGracefulPeriod)); - currentBlock = QString::fromStdString(std::to_string(chainActive.Height())); + migrationWindowClosesIn = QString::fromStdString(std::to_string(daysUntilMigrationCloses)); + blocksRemaining = QString::fromStdString(std::to_string(heightDifference)); migrateAmount = "" + BitcoinUnits::formatHtmlWithUnit(walletModel->getOptionsModel()->getDisplayUnit(), privateBalance.first); migrateAmount.append(""); - ui->textWarning1->setText(tr("Firo is migrating to Spark. Redemption of coins in Lelantus will be disabled at block %1. Current block is %2.").arg(lelantusGracefulPeriod, currentBlock)); - ui->textWarning2->setText(tr("to migrate %1 from Lelantus.").arg(migrateAmount)); + ui->textWarning1->setText(tr("We have detected Lelantus coins that have not been migrated to Spark. Migration window will close in %1 blocks (~ %2 days).").arg(blocksRemaining , migrationWindowClosesIn)); + ui->textWarning2->setText(tr("to migrate %1 ").arg(migrateAmount)); QFont qFont = ui->migrateButton->font(); qFont.setUnderline(true); ui->migrateButton->setFont(qFont); @@ -398,8 +403,25 @@ void OverviewPage::onRefreshClicked() void OverviewPage::migrateClicked() { - if(walletModel->getAvailableLelantusCoins() && spark::IsSparkAllowed() && chainActive.Height() < ::Params().GetConsensus().nLelantusGracefulPeriod){ - MigrateLelantusToSparkDialog migrate(walletModel); + WalletModel::EncryptionStatus status = walletModel->getEncryptionStatus(); + auto privateBalance = walletModel->getLelantusModel()->getPrivateBalance(); + auto lGracefulPeriod = ::Params().GetConsensus().nLelantusGracefulPeriod; + migrateAmount = "" + BitcoinUnits::formatHtmlWithUnit(walletModel->getOptionsModel()->getDisplayUnit(), privateBalance.first); + migrateAmount.append(""); + QString info = tr("Your wallet needs to be unlocked to migrate your funds to Spark."); + + if(status == WalletModel::Locked) { + + AskPassphraseDialog dlg(AskPassphraseDialog::Unlock, this, info); + dlg.setModel(walletModel); + dlg.exec(); + ui->textWarning2->setText(tr("To complete the migration of %1").arg(migrateAmount)); + ui->textWarning1->hide(); + ui->warningFrame->show(); + } else { + if(walletModel->getAvailableLelantusCoins() && spark::IsSparkAllowed() && chainActive.Height() < ::Params().GetConsensus().nLelantusGracefulPeriod){ + MigrateLelantusToSparkDialog migrate(walletModel); + } } } @@ -476,6 +498,7 @@ bool MigrateLelantusToSparkDialog::getClickedButton() { return clickedButton; } + void OverviewPage::resizeEvent(QResizeEvent* event) { QWidget::resizeEvent(event); @@ -484,6 +507,7 @@ void OverviewPage::resizeEvent(QResizeEvent* event) const int newWidth = event->size().width(); const int newHeight = event->size().height(); adjustTextSize(newWidth, newHeight); + // Determine widths for specific widgets as percentages of total width int labelWidth = static_cast(newWidth * 0.5); int labelMinWidth = static_cast(newWidth * 0.15); @@ -528,47 +552,51 @@ void OverviewPage::resizeEvent(QResizeEvent* event) ui->labelPrivate->setMinimumWidth(labelMinWidth); ui->label_4->setMinimumWidth(labelMinWidth); } + void OverviewPage::adjustTextSize(int width, int height){ - int baseFontSize = std::max(12, std::min(width, height) / 70); + const double fontSizeScalingFactor = 133.0; + int baseFontSize = width / fontSizeScalingFactor; + int fontSize = std::max(12, baseFontSize); - // Font for regular text components + // Font for regular text components (not bold) QFont textFont = ui->labelBalance->font(); - textFont.setPointSize(baseFontSize); + textFont.setPointSize(fontSize); + textFont.setBold(false); - // Font for labels, smaller than the text font size - QFont labelFont = font(); - labelFont.setPointSize(int(baseFontSize * 0.9)); + // Font for text components that should be bold + QFont labelFont = textFont; + labelFont.setBold(true); - ui->textWarning1->setFont(labelFont); - ui->textWarning2->setFont(labelFont); - ui->labelWalletStatus->setFont(labelFont); - ui->anonymizeButton->setFont(labelFont); + ui->textWarning1->setFont(textFont); + ui->textWarning2->setFont(textFont); + ui->labelWalletStatus->setFont(textFont); + ui->anonymizeButton->setFont(textFont); // Apply label font to all label components - ui->labelAlerts->setFont(textFont); - ui->label_5->setFont(textFont); - ui->labelAnonymizableText->setFont(labelFont); - ui->label->setFont(textFont); - ui->labelAnonymizable->setFont(textFont); - ui->labelWatchPending->setFont(textFont); - ui->labelBalance->setFont(textFont); - ui->labelSpendable->setFont(textFont); - ui->labelWatchAvailable->setFont(textFont); - ui->labelPendingText->setFont(labelFont); - ui->labelUnconfirmedPrivate->setFont(textFont); - ui->labelUnconfirmedPrivateText->setFont(labelFont); - ui->labelTotalText->setFont(labelFont); - ui->labelWatchonly->setFont(textFont); - ui->labelBalanceText->setFont(labelFont); - ui->labelTotal->setFont(textFont); - ui->labelWatchTotal->setFont(textFont); - ui->labelUnconfirmed->setFont(textFont); - ui->labelImmatureText->setFont(labelFont); - ui->labelImmature->setFont(textFont); - ui->labelWatchImmature->setFont(textFont); - ui->labelPrivateText->setFont(labelFont); - ui->labelPrivate->setFont(textFont); - ui->label_4->setFont(textFont); + ui->labelAlerts->setFont(labelFont); + ui->label_5->setFont(labelFont); + ui->labelAnonymizableText->setFont(textFont); + ui->label->setFont(labelFont); + ui->labelAnonymizable->setFont(labelFont); + ui->labelWatchPending->setFont(labelFont); + ui->labelBalance->setFont(labelFont); + ui->labelSpendable->setFont(labelFont); + ui->labelWatchAvailable->setFont(labelFont); + ui->labelPendingText->setFont(textFont); + ui->labelUnconfirmedPrivate->setFont(labelFont); + ui->labelUnconfirmedPrivateText->setFont(textFont); + ui->labelTotalText->setFont(textFont); + ui->labelWatchonly->setFont(labelFont); + ui->labelBalanceText->setFont(textFont); + ui->labelTotal->setFont(labelFont); + ui->labelWatchTotal->setFont(labelFont); + ui->labelUnconfirmed->setFont(labelFont); + ui->labelImmatureText->setFont(textFont); + ui->labelImmature->setFont(labelFont); + ui->labelWatchImmature->setFont(labelFont); + ui->labelPrivateText->setFont(textFont); + ui->labelPrivate->setFont(labelFont); + ui->label_4->setFont(labelFont); } \ No newline at end of file diff --git a/src/qt/overviewpage.h b/src/qt/overviewpage.h index a6e97b27f2..53a75aa594 100644 --- a/src/qt/overviewpage.h +++ b/src/qt/overviewpage.h @@ -89,8 +89,8 @@ public Q_SLOTS: QTimer countDownTimer; int secDelay; - QString lelantusGracefulPeriod; - QString currentBlock; + QString migrationWindowClosesIn; + QString blocksRemaining; QString migrateAmount; void adjustTextSize(int width,int height); private Q_SLOTS: diff --git a/src/qt/receivecoinsdialog.cpp b/src/qt/receivecoinsdialog.cpp index f523c19fed..8f33132398 100644 --- a/src/qt/receivecoinsdialog.cpp +++ b/src/qt/receivecoinsdialog.cpp @@ -430,7 +430,10 @@ void ReceiveCoinsDialog::resizeEvent(QResizeEvent* event) } void ReceiveCoinsDialog::adjustTextSize(int width,int height){ - int fontSize = std::max(12, std::min(width, height) / 70); + const double fontSizeScalingFactor = 70.0; + int baseFontSize = std::min(width, height) / fontSizeScalingFactor; + int fontSize = std::max(12, baseFontSize); + QFont font = this->font(); font.setPointSize(fontSize); diff --git a/src/qt/sendcoinsdialog.cpp b/src/qt/sendcoinsdialog.cpp index 844b786070..f7304f585c 100644 --- a/src/qt/sendcoinsdialog.cpp +++ b/src/qt/sendcoinsdialog.cpp @@ -1410,7 +1410,6 @@ void SendCoinsDialog::resizeEvent(QResizeEvent* event) { // Retrieve new dimensions from the resize event const int newWidth = event->size().width(); const int newHeight = event->size().height(); - const int labelMinWidth = static_cast(newWidth * 0.15); // Resize and adjust components @@ -1420,24 +1419,31 @@ void SendCoinsDialog::resizeEvent(QResizeEvent* event) { ui->buttonChooseFee->setMinimumWidth(labelMinWidth); ui->buttonMinimizeFee->setMinimumWidth(labelMinWidth); ui->switchFundButton->setMinimumWidth(labelMinWidth); - + ui->pushButtonCoinControl->setMinimumWidth(labelMinWidth); // Dynamically adjust text sizes based on the new dimensions adjustTextSize(newWidth, newHeight); } void SendCoinsDialog::adjustTextSize(int width, int height) { - int baseFontSize = std::max(12, std::min(width, height) / 70); - QFont font = this->font(); - font.setPointSize(baseFontSize); + + const double fontSizeScalingFactor = 131.3; + int baseFontSize = width / fontSizeScalingFactor; + int fontSize = std::max(12, baseFontSize); + + QFont font = ui->labelBalance->font(); + font.setPointSize(fontSize); + + QFont textFont = font; + textFont.setBold(true); // Set font size for all labels ui->labelBalance->setFont(font); - ui->labelCoinControlAmount->setFont(font); + ui->lineEditCoinControlChange->setFont(font); ui->labelFeeEstimation->setFont(font); ui->labelFeeHeadline->setFont(font); - ui->labelCoinControlFeatures->setFont(font); + ui->labelCoinControlFeatures->setFont(textFont); ui->labelCoinControlAutomaticallySelected->setFont(font); ui->labelCoinControlInsuffFunds->setFont(font); ui->labelCoinControlQuantity->setFont(font); @@ -1472,6 +1478,7 @@ void SendCoinsDialog::adjustTextSize(int width, int height) { ui->fallbackFeeWarningLabel->setFont(font); ui->checkBoxMinimumFee->setFont(font); ui->checkBoxCoinControlChange->setFont(font); + ui->confirmationTargetLabel->setFont(font); // Adjust font for all buttons ui->sendButton->setFont(font); diff --git a/src/qt/sendcoinsentry.cpp b/src/qt/sendcoinsentry.cpp index 1825191da3..a996ebcf58 100644 --- a/src/qt/sendcoinsentry.cpp +++ b/src/qt/sendcoinsentry.cpp @@ -277,10 +277,12 @@ void SendCoinsEntry::resizeEvent(QResizeEvent* event) { void SendCoinsEntry::adjustTextSize(int width, int height) { - int baseFontSize = std::max(14, width / 120); + const double fontSizeScalingFactor = 130.0; + int baseFontSize = width / fontSizeScalingFactor; + int fontSize = std::max(12,baseFontSize); QFont font = this->font(); - font.setPointSize(baseFontSize); + font.setPointSize(fontSize); ui->payToLabel->setFont(font); ui->labellLabel->setFont(font); diff --git a/src/qt/transactionview.cpp b/src/qt/transactionview.cpp index 2a268ab47d..34524b5fed 100644 --- a/src/qt/transactionview.cpp +++ b/src/qt/transactionview.cpp @@ -755,7 +755,10 @@ void TransactionView::resizeEvent(QResizeEvent* event) } void TransactionView::adjustTextSize(int width,int height){ - int fontSize = std::max(12, std::min(width, height) / 70); + const double fontSizeScalingFactor = 65.0; + int baseFontSize = std::min(width, height) / fontSizeScalingFactor; + int fontSize = std::max(12, baseFontSize); + QFont font = this->font(); font.setPointSize(fontSize);