mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-01-10 20:03:34 -03:00
[Qt] Add spend all button to the SendCoinsDialog
Get the balance of the wallet (with CoinControl if enabled). Then divide the amount available by all of the SendCoinEntry(s) and check the subtract fee from amount checkbox for all SendCoinEntry(s).
This commit is contained in:
parent
262167393d
commit
89e9edacbf
5 changed files with 48 additions and 0 deletions
|
@ -1223,6 +1223,13 @@
|
|||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="buttonSendAll">
|
||||
<property name="text">
|
||||
<string>Send All</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||
<property name="spacing">
|
||||
|
|
|
@ -607,6 +607,34 @@ void SendCoinsDialog::on_buttonMinimizeFee_clicked()
|
|||
minimizeFeeSection(true);
|
||||
}
|
||||
|
||||
void SendCoinsDialog::on_buttonSendAll_clicked()
|
||||
{
|
||||
// Get CCoinControl instance if CoinControl is enabled or create a new one
|
||||
CCoinControl coinControl;
|
||||
if (model->getOptionsModel()->getCoinControlFeatures())
|
||||
coinControl = *CoinControlDialog::coinControl;
|
||||
|
||||
// Calculate total amount to spend
|
||||
CAmount nTotalAmount = model->getBalance(&coinControl);
|
||||
|
||||
// Calculate amount per entry
|
||||
int nEntries = ui->entries->count();
|
||||
CAmount nAmountPerEntry = (nEntries ? (nTotalAmount / nEntries) : nTotalAmount);
|
||||
|
||||
for(int i = 0; i < nEntries; ++i)
|
||||
{
|
||||
SendCoinsEntry *entry = qobject_cast<SendCoinsEntry*>(ui->entries->itemAt(i)->widget());
|
||||
if(entry)
|
||||
{
|
||||
// Check subtract fee from amount checkbox
|
||||
entry->checkSubtractFeeFromAmount();
|
||||
|
||||
// Set new amount for entry
|
||||
entry->setAmount(nAmountPerEntry);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void SendCoinsDialog::setMinimumFee()
|
||||
{
|
||||
ui->radioCustomPerKilobyte->setChecked(true);
|
||||
|
|
|
@ -75,6 +75,7 @@ private Q_SLOTS:
|
|||
void on_sendButton_clicked();
|
||||
void on_buttonChooseFee_clicked();
|
||||
void on_buttonMinimizeFee_clicked();
|
||||
void on_buttonSendAll_clicked();
|
||||
void removeEntry(SendCoinsEntry* entry);
|
||||
void updateDisplayUnit();
|
||||
void coinControlFeatureChanged(bool);
|
||||
|
|
|
@ -112,6 +112,11 @@ void SendCoinsEntry::clear()
|
|||
updateDisplayUnit();
|
||||
}
|
||||
|
||||
void SendCoinsEntry::checkSubtractFeeFromAmount()
|
||||
{
|
||||
ui->checkboxSubtractFeeFromAmount->setChecked(true);
|
||||
}
|
||||
|
||||
void SendCoinsEntry::deleteClicked()
|
||||
{
|
||||
Q_EMIT removeEntry(this);
|
||||
|
@ -228,6 +233,11 @@ void SendCoinsEntry::setAddress(const QString &address)
|
|||
ui->payAmount->setFocus();
|
||||
}
|
||||
|
||||
void SendCoinsEntry::setAmount(const CAmount &amount)
|
||||
{
|
||||
ui->payAmount->setValue(amount);
|
||||
}
|
||||
|
||||
bool SendCoinsEntry::isClear()
|
||||
{
|
||||
return ui->payTo->text().isEmpty() && ui->payTo_is->text().isEmpty() && ui->payTo_s->text().isEmpty();
|
||||
|
|
|
@ -38,6 +38,7 @@ public:
|
|||
|
||||
void setValue(const SendCoinsRecipient &value);
|
||||
void setAddress(const QString &address);
|
||||
void setAmount(const CAmount &amount);
|
||||
|
||||
/** Set up the tab chain manually, as Qt messes up the tab chain by default in some cases
|
||||
* (issue https://bugreports.qt-project.org/browse/QTBUG-10907).
|
||||
|
@ -48,6 +49,7 @@ public:
|
|||
|
||||
public Q_SLOTS:
|
||||
void clear();
|
||||
void checkSubtractFeeFromAmount();
|
||||
|
||||
Q_SIGNALS:
|
||||
void removeEntry(SendCoinsEntry *entry);
|
||||
|
|
Loading…
Reference in a new issue