Skip to content

Commit

Permalink
Prevent escape from "closing" a dialog, introducing a blank window. (R…
Browse files Browse the repository at this point in the history
  • Loading branch information
CodeIsTheKey authored Aug 18, 2024
1 parent 03642dc commit 569a174
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 13 deletions.
9 changes: 9 additions & 0 deletions src/qt/assetsdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include <QApplication>
#include <QDesktopWidget>
#include <QScreen>
#include <QKeyEvent>

template<typename T>
class CAssetListWidgetItem : public QTableWidgetItem {
Expand Down Expand Up @@ -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());
Expand Down
3 changes: 3 additions & 0 deletions src/qt/assetsdialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
8 changes: 8 additions & 0 deletions src/qt/createassetsdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions src/qt/createassetsdialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ public
const uint256 &txid
);

protected:
void keyPressEvent(QKeyEvent *e) override;

private:
Ui::CreateAssetsDialog *ui;
ClientModel *clientModel;
Expand Down
34 changes: 21 additions & 13 deletions src/qt/updateassetsdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -381,37 +381,37 @@ void UpdateAssetsDialog::updateAsset() {
msgBox.exec();
return;
}

m_coin_control->destChange = CNoDestination();
m_coin_control->UnSelectAll();

QString questionString = tr("Updating asset: %1<br>").arg(QString::fromStdString(assetData.name));
QString questionString = tr("Updating asset: %1<br>").arg(QString::fromStdString(assetData.name));
questionString.append("<hr />");
if (assetTx.ownerAddress != assetData.ownerAddress) {
questionString.append(tr("transfer ownership from: %1 <br>").arg(QString::fromStdString(EncodeDestination(assetData.ownerAddress))));
questionString.append(tr("To: %1 <hr />").arg(QString::fromStdString(EncodeDestination(assetTx.ownerAddress))));
} else {
if (assetTx.updatable != assetData.updatable)
questionString.append(tr("Updatable: %1 <br>").arg(assetTx.updatable ? "true": "false"));

if (assetTx.referenceHash != assetData.referenceHash)
questionString.append(tr("ReferenceHash: %1 <br>").arg(QString::fromStdString(assetTx.referenceHash)));

if (assetTx.targetAddress != assetData.targetAddress)
questionString.append(tr("Target: %1 <br>").arg(QString::fromStdString(EncodeDestination(assetTx.targetAddress))));

if (assetTx.type != assetData.type)
questionString.append(tr("Distribution Type: %1 <br>").arg(GetDistributionType(assetTx.type)));

if (assetTx.amount != assetData.amount)
questionString.append(tr("Amount: %1 <br>").arg(QString::number(assetTx.amount / COIN)));

if (assetTx.maxMintCount != assetData.maxMintCount)
questionString.append(tr("MaxMintCount: %1 <br>").arg(QString::number(assetTx.maxMintCount)));

if (assetTx.issueFrequency != assetData.issueFrequency)
questionString.append(tr("IssueFrequency: %1 <br>").arg(QString::number(assetTx.issueFrequency)));

}
// Display message box
nFee += assetTx.fee * COIN;
Expand Down Expand Up @@ -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;
Expand All @@ -476,7 +476,7 @@ void UpdateAssetsDialog::clear() {
ui->maxmintSpinBox->setValue(1);
ui->IssueFrequencyBox->setValue(0);
ui->updatableBox->setChecked(false);

updateTabsAndLabels();
}

Expand Down Expand Up @@ -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) {
Expand Down
3 changes: 3 additions & 0 deletions src/qt/updateassetsdialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ class UpdateAssetsDialog : public QDialog {
QCompleter *completer;
QString prevName = "";

protected:
void keyPressEvent(QKeyEvent *e) override;

public
Q_SLOTS:
void clear();
Expand Down

0 comments on commit 569a174

Please sign in to comment.