Skip to content

Commit

Permalink
Fix toggle lock button
Browse files Browse the repository at this point in the history
  • Loading branch information
panleone committed May 7, 2023
1 parent aca81a1 commit 6840431
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 22 deletions.
59 changes: 37 additions & 22 deletions src/qt/coincontroldialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/qt/coincontroldialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 6840431

Please sign in to comment.