Skip to content

Commit

Permalink
Update dynamic scaling and resolve #1391 with migration warning adjus…
Browse files Browse the repository at this point in the history
…tment
  • Loading branch information
firstcryptoman committed Jun 13, 2024
1 parent a7fa4c9 commit 44da2da
Show file tree
Hide file tree
Showing 7 changed files with 100 additions and 54 deletions.
5 changes: 4 additions & 1 deletion src/qt/masternodelist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
108 changes: 68 additions & 40 deletions src/qt/overviewpage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "transactiontablemodel.h"
#include "walletmodel.h"
#include "validation.h"
#include "askpassphrasedialog.h"

#ifdef WIN32
#include <string.h>
Expand Down Expand Up @@ -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 = "<b>" + BitcoinUnits::formatHtmlWithUnit(walletModel->getOptionsModel()->getDisplayUnit(), privateBalance.first);
migrateAmount.append("</b>");
ui->textWarning1->setText(tr("Firo is migrating to Spark. Redemption of coins in Lelantus will be disabled at block %1. <i>Current block is %2</i>.").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);
Expand All @@ -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 = "<b>" + BitcoinUnits::formatHtmlWithUnit(walletModel->getOptionsModel()->getDisplayUnit(), privateBalance.first);
migrateAmount.append("</b>");
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);
}
}
}

Expand Down Expand Up @@ -476,6 +498,7 @@ bool MigrateLelantusToSparkDialog::getClickedButton()
{
return clickedButton;
}

void OverviewPage::resizeEvent(QResizeEvent* event)
{
QWidget::resizeEvent(event);
Expand All @@ -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<int>(newWidth * 0.5);
int labelMinWidth = static_cast<int>(newWidth * 0.15);
Expand Down Expand Up @@ -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);

}
4 changes: 2 additions & 2 deletions src/qt/overviewpage.h
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
5 changes: 4 additions & 1 deletion src/qt/receivecoinsdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
21 changes: 14 additions & 7 deletions src/qt/sendcoinsdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<int>(newWidth * 0.15);

// Resize and adjust components
Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
6 changes: 4 additions & 2 deletions src/qt/sendcoinsentry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
5 changes: 4 additions & 1 deletion src/qt/transactionview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit 44da2da

Please sign in to comment.