mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-08-03 22:33:43 +02: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:
@@ -1223,6 +1223,13 @@
|
|||||||
</property>
|
</property>
|
||||||
</spacer>
|
</spacer>
|
||||||
</item>
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QPushButton" name="buttonSendAll">
|
||||||
|
<property name="text">
|
||||||
|
<string>Send All</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||||
<property name="spacing">
|
<property name="spacing">
|
||||||
|
@@ -607,6 +607,34 @@ void SendCoinsDialog::on_buttonMinimizeFee_clicked()
|
|||||||
minimizeFeeSection(true);
|
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()
|
void SendCoinsDialog::setMinimumFee()
|
||||||
{
|
{
|
||||||
ui->radioCustomPerKilobyte->setChecked(true);
|
ui->radioCustomPerKilobyte->setChecked(true);
|
||||||
|
@@ -75,6 +75,7 @@ private Q_SLOTS:
|
|||||||
void on_sendButton_clicked();
|
void on_sendButton_clicked();
|
||||||
void on_buttonChooseFee_clicked();
|
void on_buttonChooseFee_clicked();
|
||||||
void on_buttonMinimizeFee_clicked();
|
void on_buttonMinimizeFee_clicked();
|
||||||
|
void on_buttonSendAll_clicked();
|
||||||
void removeEntry(SendCoinsEntry* entry);
|
void removeEntry(SendCoinsEntry* entry);
|
||||||
void updateDisplayUnit();
|
void updateDisplayUnit();
|
||||||
void coinControlFeatureChanged(bool);
|
void coinControlFeatureChanged(bool);
|
||||||
|
@@ -112,6 +112,11 @@ void SendCoinsEntry::clear()
|
|||||||
updateDisplayUnit();
|
updateDisplayUnit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SendCoinsEntry::checkSubtractFeeFromAmount()
|
||||||
|
{
|
||||||
|
ui->checkboxSubtractFeeFromAmount->setChecked(true);
|
||||||
|
}
|
||||||
|
|
||||||
void SendCoinsEntry::deleteClicked()
|
void SendCoinsEntry::deleteClicked()
|
||||||
{
|
{
|
||||||
Q_EMIT removeEntry(this);
|
Q_EMIT removeEntry(this);
|
||||||
@@ -228,6 +233,11 @@ void SendCoinsEntry::setAddress(const QString &address)
|
|||||||
ui->payAmount->setFocus();
|
ui->payAmount->setFocus();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SendCoinsEntry::setAmount(const CAmount &amount)
|
||||||
|
{
|
||||||
|
ui->payAmount->setValue(amount);
|
||||||
|
}
|
||||||
|
|
||||||
bool SendCoinsEntry::isClear()
|
bool SendCoinsEntry::isClear()
|
||||||
{
|
{
|
||||||
return ui->payTo->text().isEmpty() && ui->payTo_is->text().isEmpty() && ui->payTo_s->text().isEmpty();
|
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 setValue(const SendCoinsRecipient &value);
|
||||||
void setAddress(const QString &address);
|
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
|
/** 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).
|
* (issue https://bugreports.qt-project.org/browse/QTBUG-10907).
|
||||||
@@ -48,6 +49,7 @@ public:
|
|||||||
|
|
||||||
public Q_SLOTS:
|
public Q_SLOTS:
|
||||||
void clear();
|
void clear();
|
||||||
|
void checkSubtractFeeFromAmount();
|
||||||
|
|
||||||
Q_SIGNALS:
|
Q_SIGNALS:
|
||||||
void removeEntry(SendCoinsEntry *entry);
|
void removeEntry(SendCoinsEntry *entry);
|
||||||
|
Reference in New Issue
Block a user