[qt] Add use available balance in send coins dialog
This commit is contained in:
parent
96ac26e566
commit
d052e3847c
5 changed files with 55 additions and 1 deletions
|
@ -163,7 +163,7 @@
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="2" column="1">
|
<item row="2" column="1">
|
||||||
<layout class="QHBoxLayout" name="horizontalLayoutAmount" stretch="0,1">
|
<layout class="QHBoxLayout" name="horizontalLayoutAmount" stretch="0,1,0">
|
||||||
<item>
|
<item>
|
||||||
<widget class="BitcoinAmountField" name="payAmount"/>
|
<widget class="BitcoinAmountField" name="payAmount"/>
|
||||||
</item>
|
</item>
|
||||||
|
@ -177,6 +177,13 @@
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QPushButton" name="useAvailableBalanceButton">
|
||||||
|
<property name="text">
|
||||||
|
<string>Use available balance</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</item>
|
</item>
|
||||||
<item row="3" column="0">
|
<item row="3" column="0">
|
||||||
|
|
|
@ -410,6 +410,7 @@ SendCoinsEntry *SendCoinsDialog::addEntry()
|
||||||
entry->setModel(model);
|
entry->setModel(model);
|
||||||
ui->entries->addWidget(entry);
|
ui->entries->addWidget(entry);
|
||||||
connect(entry, SIGNAL(removeEntry(SendCoinsEntry*)), this, SLOT(removeEntry(SendCoinsEntry*)));
|
connect(entry, SIGNAL(removeEntry(SendCoinsEntry*)), this, SLOT(removeEntry(SendCoinsEntry*)));
|
||||||
|
connect(entry, SIGNAL(useAvailableBalance(SendCoinsEntry*)), this, SLOT(useAvailableBalance(SendCoinsEntry*)));
|
||||||
connect(entry, SIGNAL(payAmountChanged()), this, SLOT(coinControlUpdateLabels()));
|
connect(entry, SIGNAL(payAmountChanged()), this, SLOT(coinControlUpdateLabels()));
|
||||||
connect(entry, SIGNAL(subtractFeeFromAmountChanged()), this, SLOT(coinControlUpdateLabels()));
|
connect(entry, SIGNAL(subtractFeeFromAmountChanged()), this, SLOT(coinControlUpdateLabels()));
|
||||||
|
|
||||||
|
@ -607,6 +608,31 @@ void SendCoinsDialog::on_buttonMinimizeFee_clicked()
|
||||||
minimizeFeeSection(true);
|
minimizeFeeSection(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SendCoinsDialog::useAvailableBalance(SendCoinsEntry* entry)
|
||||||
|
{
|
||||||
|
// Get CCoinControl instance if CoinControl is enabled or create a new one.
|
||||||
|
CCoinControl coin_control;
|
||||||
|
if (model->getOptionsModel()->getCoinControlFeatures()) {
|
||||||
|
coin_control = *CoinControlDialog::coinControl;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Calculate available amount to send.
|
||||||
|
CAmount amount = model->getBalance(&coin_control);
|
||||||
|
for (int i = 0; i < ui->entries->count(); ++i) {
|
||||||
|
SendCoinsEntry* e = qobject_cast<SendCoinsEntry*>(ui->entries->itemAt(i)->widget());
|
||||||
|
if (e && !e->isHidden() && e != entry) {
|
||||||
|
amount -= e->getValue().amount;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (amount > 0) {
|
||||||
|
entry->checkSubtractFeeFromAmount();
|
||||||
|
entry->setAmount(amount);
|
||||||
|
} else {
|
||||||
|
entry->setAmount(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void SendCoinsDialog::setMinimumFee()
|
void SendCoinsDialog::setMinimumFee()
|
||||||
{
|
{
|
||||||
ui->radioCustomPerKilobyte->setChecked(true);
|
ui->radioCustomPerKilobyte->setChecked(true);
|
||||||
|
|
|
@ -76,6 +76,7 @@ private Q_SLOTS:
|
||||||
void on_buttonChooseFee_clicked();
|
void on_buttonChooseFee_clicked();
|
||||||
void on_buttonMinimizeFee_clicked();
|
void on_buttonMinimizeFee_clicked();
|
||||||
void removeEntry(SendCoinsEntry* entry);
|
void removeEntry(SendCoinsEntry* entry);
|
||||||
|
void useAvailableBalance(SendCoinsEntry* entry);
|
||||||
void updateDisplayUnit();
|
void updateDisplayUnit();
|
||||||
void coinControlFeatureChanged(bool);
|
void coinControlFeatureChanged(bool);
|
||||||
void coinControlButtonClicked();
|
void coinControlButtonClicked();
|
||||||
|
|
|
@ -48,6 +48,7 @@ SendCoinsEntry::SendCoinsEntry(const PlatformStyle *_platformStyle, QWidget *par
|
||||||
connect(ui->deleteButton, SIGNAL(clicked()), this, SLOT(deleteClicked()));
|
connect(ui->deleteButton, SIGNAL(clicked()), this, SLOT(deleteClicked()));
|
||||||
connect(ui->deleteButton_is, SIGNAL(clicked()), this, SLOT(deleteClicked()));
|
connect(ui->deleteButton_is, SIGNAL(clicked()), this, SLOT(deleteClicked()));
|
||||||
connect(ui->deleteButton_s, SIGNAL(clicked()), this, SLOT(deleteClicked()));
|
connect(ui->deleteButton_s, SIGNAL(clicked()), this, SLOT(deleteClicked()));
|
||||||
|
connect(ui->useAvailableBalanceButton, SIGNAL(clicked()), this, SLOT(useAvailableBalanceClicked()));
|
||||||
}
|
}
|
||||||
|
|
||||||
SendCoinsEntry::~SendCoinsEntry()
|
SendCoinsEntry::~SendCoinsEntry()
|
||||||
|
@ -112,11 +113,21 @@ 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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SendCoinsEntry::useAvailableBalanceClicked()
|
||||||
|
{
|
||||||
|
Q_EMIT useAvailableBalance(this);
|
||||||
|
}
|
||||||
|
|
||||||
bool SendCoinsEntry::validate()
|
bool SendCoinsEntry::validate()
|
||||||
{
|
{
|
||||||
if (!model)
|
if (!model)
|
||||||
|
@ -228,6 +239,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,14 +49,17 @@ 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);
|
||||||
|
void useAvailableBalance(SendCoinsEntry* entry);
|
||||||
void payAmountChanged();
|
void payAmountChanged();
|
||||||
void subtractFeeFromAmountChanged();
|
void subtractFeeFromAmountChanged();
|
||||||
|
|
||||||
private Q_SLOTS:
|
private Q_SLOTS:
|
||||||
void deleteClicked();
|
void deleteClicked();
|
||||||
|
void useAvailableBalanceClicked();
|
||||||
void on_payTo_textChanged(const QString &address);
|
void on_payTo_textChanged(const QString &address);
|
||||||
void on_addressBookButton_clicked();
|
void on_addressBookButton_clicked();
|
||||||
void on_pasteButton_clicked();
|
void on_pasteButton_clicked();
|
||||||
|
|
Loading…
Reference in a new issue