diff --git a/src/qt/coincontroldialog.cpp b/src/qt/coincontroldialog.cpp index fde1ec293c06ce..68ab35ce87fb0b 100644 --- a/src/qt/coincontroldialog.cpp +++ b/src/qt/coincontroldialog.cpp @@ -228,36 +228,46 @@ void CoinControlDialog::buttonSelectAllClicked() updateLabels(); } +void CoinControlDialog::toggleCoinLock() +{ + QTreeWidgetItem* item; + for (int i = 0; i < ui->treeWidget->topLevelItemCount(); i++) { + item = ui->treeWidget->topLevelItem(i); + + COutPoint outpt(uint256S(item->text(COLUMN_TXHASH).toStdString()), item->text(COLUMN_VOUT_INDEX).toUInt()); + if (model->isLockedCoin(uint256S(item->text(COLUMN_TXHASH).toStdString()), item->text(COLUMN_VOUT_INDEX).toUInt())) { + model->unlockCoin(outpt); + item->setDisabled(false); + // restore cold-stake snowflake icon for P2CS which were previously locked + if (item->data(COLUMN_CHECKBOX, Qt::UserRole) == QString("Delegated")) + item->setIcon(COLUMN_CHECKBOX, QIcon("://ic-check-cold-staking-off")); + else + item->setIcon(COLUMN_CHECKBOX, QIcon()); + } else { + model->lockCoin(outpt); + item->setDisabled(true); + item->setIcon(COLUMN_CHECKBOX, QIcon(":/icons/lock_closed")); + } + updateLabelLocked(); + } +} + // Toggle lock state void CoinControlDialog::buttonToggleLockClicked() { - if (!fSelectTransparent) return; // todo: implement locked notes - QTreeWidgetItem* item; + if (!fSelectTransparent) { // todo: implement locked notes + ui->pushButtonToggleLock->setChecked(false); + return; + } + // Works in list-mode only if (ui->radioListMode->isChecked()) { ui->treeWidget->setEnabled(false); - for (int i = 0; i < ui->treeWidget->topLevelItemCount(); i++) { - item = ui->treeWidget->topLevelItem(i); - - COutPoint outpt(uint256S(item->text(COLUMN_TXHASH).toStdString()), item->text(COLUMN_VOUT_INDEX).toUInt()); - if (model->isLockedCoin(uint256S(item->text(COLUMN_TXHASH).toStdString()), item->text(COLUMN_VOUT_INDEX).toUInt())) { - model->unlockCoin(outpt); - item->setDisabled(false); - // restore cold-stake snowflake icon for P2CS which were previously locked - if (item->data(COLUMN_CHECKBOX, Qt::UserRole) == QString("Delegated")) - item->setIcon(COLUMN_CHECKBOX, QIcon("://ic-check-cold-staking-off")); - else - item->setIcon(COLUMN_CHECKBOX, QIcon()); - } else { - model->lockCoin(outpt); - item->setDisabled(true); - item->setIcon(COLUMN_CHECKBOX, QIcon(":/icons/lock_closed")); - } - updateLabelLocked(); - } + toggleCoinLock(); ui->treeWidget->setEnabled(true); updateLabels(); } else { + ui->pushButtonToggleLock->setChecked(false); QMessageBox msgBox; msgBox.setObjectName("lockMessageBox"); msgBox.setStyleSheet(GUIUtil::loadStyleSheet()); @@ -431,8 +441,13 @@ void CoinControlDialog::headerSectionClicked(int logicalIndex) // toggle tree mode void CoinControlDialog::radioTreeMode(bool checked) { - if (checked && model) + if (checked && model) { + if (ui->pushButtonToggleLock->isChecked() && fSelectTransparent) { + ui->pushButtonToggleLock->setChecked(false); + toggleCoinLock(); + } updateView(); + } } // toggle list mode diff --git a/src/qt/coincontroldialog.h b/src/qt/coincontroldialog.h index 2d5a61c40b2a11..be9b4bd7c3fd2f 100644 --- a/src/qt/coincontroldialog.h +++ b/src/qt/coincontroldialog.h @@ -93,6 +93,7 @@ class CoinControlDialog : public QDialog void updatePushButtonSelectAll(bool checked); void sortView(int, Qt::SortOrder); void inform(const QString& text); + void toggleCoinLock(); // Load a row with coin's data void loadAvailableCoin(bool treeMode,