From 569a1748de7cfc538c0b6bcb1df200d8d2b623d4 Mon Sep 17 00:00:00 2001 From: CodeIsTheKey Date: Sun, 18 Aug 2024 09:18:10 -0600 Subject: [PATCH] Prevent escape from "closing" a dialog, introducing a blank window. (#394) --- src/qt/assetsdialog.cpp | 9 +++++++++ src/qt/assetsdialog.h | 3 +++ src/qt/createassetsdialog.cpp | 8 ++++++++ src/qt/createassetsdialog.h | 3 +++ src/qt/updateassetsdialog.cpp | 34 +++++++++++++++++++++------------- src/qt/updateassetsdialog.h | 3 +++ 6 files changed, 47 insertions(+), 13 deletions(-) diff --git a/src/qt/assetsdialog.cpp b/src/qt/assetsdialog.cpp index 34ce1e6b0..589591675 100644 --- a/src/qt/assetsdialog.cpp +++ b/src/qt/assetsdialog.cpp @@ -33,6 +33,7 @@ #include #include #include +#include template class CAssetListWidgetItem : public QTableWidgetItem { @@ -114,6 +115,14 @@ void AssetsDialog::setModel(WalletModel *model) { balanceChanged = true; } +void AssetsDialog::keyPressEvent(QKeyEvent* evt) +{ + // Escape hides the dialog, which leaves us with an empty window + if (evt->key() == Qt::Key_Escape) + return; + QDialog::keyPressEvent(evt); +} + void AssetsDialog::showContextMenuAsset(const QPoint &point) { QTableWidgetItem *item = ui->tableWidgetAssets->itemAt(point); if (item) contextMenuAsset->exec(QCursor::pos()); diff --git a/src/qt/assetsdialog.h b/src/qt/assetsdialog.h index e9e51a0bb..4d5d1936f 100644 --- a/src/qt/assetsdialog.h +++ b/src/qt/assetsdialog.h @@ -56,6 +56,9 @@ class AssetsDialog : public QDialog { void assetUpdateClicked(const std::string &assetName); +protected: + void keyPressEvent(QKeyEvent *e) override; + private: QMenu *contextMenuAsset; QImage currentRefImage; diff --git a/src/qt/createassetsdialog.cpp b/src/qt/createassetsdialog.cpp index 6aeb1290e..6e2896c71 100644 --- a/src/qt/createassetsdialog.cpp +++ b/src/qt/createassetsdialog.cpp @@ -280,6 +280,14 @@ static QString GetDistributionType(int t) { return "invalid"; } +void CreateAssetsDialog::keyPressEvent(QKeyEvent* evt) +{ + // Escape hides the dialog, which leaves us with an empty window + if (evt->key() == Qt::Key_Escape) + return; + QDialog::keyPressEvent(evt); +} + void CreateAssetsDialog::on_createAssetButton_clicked() { if (!model || !model->getOptionsModel() || !validateInputs()) return; diff --git a/src/qt/createassetsdialog.h b/src/qt/createassetsdialog.h index 49387f32e..5e0bc6e01 100644 --- a/src/qt/createassetsdialog.h +++ b/src/qt/createassetsdialog.h @@ -59,6 +59,9 @@ public const uint256 &txid ); +protected: + void keyPressEvent(QKeyEvent *e) override; + private: Ui::CreateAssetsDialog *ui; ClientModel *clientModel; diff --git a/src/qt/updateassetsdialog.cpp b/src/qt/updateassetsdialog.cpp index 0b88b48cf..16ede24ad 100644 --- a/src/qt/updateassetsdialog.cpp +++ b/src/qt/updateassetsdialog.cpp @@ -278,7 +278,7 @@ void UpdateAssetsDialog::updateAsset() { msgBox.setText(QString::fromStdString("Error: This asset cannot be updated")); msgBox.setStandardButtons(QMessageBox::Ok); msgBox.exec(); - return; + return; } //check on mempool if have a mint/update tx for this asset @@ -319,17 +319,17 @@ void UpdateAssetsDialog::updateAsset() { assetTx.amount = ui->quantitySpinBox->value() * COIN; else assetTx.amount = assetData.amount; - + //maxMintCount need to be equal to or greater than current mintCount if (ui->quantitySpinBox->value() >= assetData.mintCount) assetTx.maxMintCount = ui->maxmintSpinBox->value(); else assetTx.maxMintCount = assetData.maxMintCount; - + if (ui->IssueFrequencyBox->value() > 0) assetTx.issueFrequency = ui->IssueFrequencyBox->value(); else - assetTx.issueFrequency = assetData.issueFrequency; + assetTx.issueFrequency = assetData.issueFrequency; assetTx.updatable = ui->updatableBox->isChecked(); @@ -381,11 +381,11 @@ void UpdateAssetsDialog::updateAsset() { msgBox.exec(); return; } - + m_coin_control->destChange = CNoDestination(); m_coin_control->UnSelectAll(); - QString questionString = tr("Updating asset: %1
").arg(QString::fromStdString(assetData.name)); + QString questionString = tr("Updating asset: %1
").arg(QString::fromStdString(assetData.name)); questionString.append("
"); if (assetTx.ownerAddress != assetData.ownerAddress) { questionString.append(tr("transfer ownership from: %1
").arg(QString::fromStdString(EncodeDestination(assetData.ownerAddress)))); @@ -393,25 +393,25 @@ void UpdateAssetsDialog::updateAsset() { } else { if (assetTx.updatable != assetData.updatable) questionString.append(tr("Updatable: %1
").arg(assetTx.updatable ? "true": "false")); - + if (assetTx.referenceHash != assetData.referenceHash) questionString.append(tr("ReferenceHash: %1
").arg(QString::fromStdString(assetTx.referenceHash))); - + if (assetTx.targetAddress != assetData.targetAddress) questionString.append(tr("Target: %1
").arg(QString::fromStdString(EncodeDestination(assetTx.targetAddress)))); if (assetTx.type != assetData.type) questionString.append(tr("Distribution Type: %1
").arg(GetDistributionType(assetTx.type))); - + if (assetTx.amount != assetData.amount) questionString.append(tr("Amount: %1
").arg(QString::number(assetTx.amount / COIN))); - + if (assetTx.maxMintCount != assetData.maxMintCount) questionString.append(tr("MaxMintCount: %1
").arg(QString::number(assetTx.maxMintCount))); if (assetTx.issueFrequency != assetData.issueFrequency) questionString.append(tr("IssueFrequency: %1
").arg(QString::number(assetTx.issueFrequency))); - + } // Display message box nFee += assetTx.fee * COIN; @@ -452,7 +452,7 @@ bool UpdateAssetsDialog::validateInputs() { ui->targetaddressText->setValid(false); retval = false; } - + if (ui->maxmintSpinBox->value() < 0 || ui->maxmintSpinBox->value() > 65535){ ui->maxmintSpinBox->setStyleSheet(GUIUtil::getThemedStyleQString(GUIUtil::ThemedStyle::TS_INVALID)); retval = false; @@ -476,7 +476,7 @@ void UpdateAssetsDialog::clear() { ui->maxmintSpinBox->setValue(1); ui->IssueFrequencyBox->setValue(0); ui->updatableBox->setChecked(false); - + updateTabsAndLabels(); } @@ -651,6 +651,14 @@ void UpdateAssetsDialog::updateAssetList() { } } +void UpdateAssetsDialog::keyPressEvent(QKeyEvent* evt) +{ + // Escape hides the dialog, which leaves us with an empty window + if (evt->key() == Qt::Key_Escape) + return; + QDialog::keyPressEvent(evt); +} + void UpdateAssetsDialog::focusAsset(const std::string assetId) { int index = ui->assetList->findText(QString::fromStdString(assetId)); if (index >= 0) { diff --git a/src/qt/updateassetsdialog.h b/src/qt/updateassetsdialog.h index 23a881117..ea5abf047 100644 --- a/src/qt/updateassetsdialog.h +++ b/src/qt/updateassetsdialog.h @@ -56,6 +56,9 @@ class UpdateAssetsDialog : public QDialog { QCompleter *completer; QString prevName = ""; +protected: + void keyPressEvent(QKeyEvent *e) override; + public Q_SLOTS: void clear();