[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:
CryptAxe 2017-08-19 22:04:56 -07:00
parent 262167393d
commit 89e9edacbf
No known key found for this signature in database
GPG key ID: 91F0858CBB9B6574
5 changed files with 48 additions and 0 deletions

View file

@ -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">

View file

@ -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);

View file

@ -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);

View file

@ -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();

View file

@ -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);