20 #include <QApplication>
23 #include <QDialogButtonBox>
27 #include <QTreeWidget>
28 #include <QTreeWidgetItem>
42 QAction *copyAddressAction =
new QAction(tr(
"Copy address"),
this);
43 QAction *copyLabelAction =
new QAction(tr(
"Copy label"),
this);
44 QAction *copyAmountAction =
new QAction(tr(
"Copy amount"),
this);
46 lockAction =
new QAction(tr(
"Lock unspent"),
this);
60 connect(
ui->
treeWidget, SIGNAL(customContextMenuRequested(QPoint)),
this, SLOT(
showMenu(QPoint)));
61 connect(copyAddressAction, SIGNAL(triggered()),
this, SLOT(
copyAddress()));
62 connect(copyLabelAction, SIGNAL(triggered()),
this, SLOT(
copyLabel()));
63 connect(copyAmountAction, SIGNAL(triggered()),
this, SLOT(
copyAmount()));
69 QAction *clipboardQuantityAction =
new QAction(tr(
"Copy quantity"),
this);
70 QAction *clipboardAmountAction =
new QAction(tr(
"Copy amount"),
this);
71 QAction *clipboardFeeAction =
new QAction(tr(
"Copy fee"),
this);
72 QAction *clipboardAfterFeeAction =
new QAction(tr(
"Copy after fee"),
this);
73 QAction *clipboardBytesAction =
new QAction(tr(
"Copy bytes"),
this);
74 QAction *clipboardPriorityAction =
new QAction(tr(
"Copy priority"),
this);
75 QAction *clipboardLowOutputAction =
new QAction(tr(
"Copy low output"),
this);
76 QAction *clipboardChangeAction =
new QAction(tr(
"Copy change"),
this);
78 connect(clipboardQuantityAction, SIGNAL(triggered()),
this, SLOT(
clipboardQuantity()));
79 connect(clipboardAmountAction, SIGNAL(triggered()),
this, SLOT(
clipboardAmount()));
80 connect(clipboardFeeAction, SIGNAL(triggered()),
this, SLOT(
clipboardFee()));
81 connect(clipboardAfterFeeAction, SIGNAL(triggered()),
this, SLOT(
clipboardAfterFee()));
82 connect(clipboardBytesAction, SIGNAL(triggered()),
this, SLOT(
clipboardBytes()));
83 connect(clipboardPriorityAction, SIGNAL(triggered()),
this, SLOT(
clipboardPriority()));
84 connect(clipboardLowOutputAction, SIGNAL(triggered()),
this, SLOT(
clipboardLowOutput()));
85 connect(clipboardChangeAction, SIGNAL(triggered()),
this, SLOT(
clipboardChange()));
104 #if QT_VERSION < 0x050000
154 while (s.length() < nPadLength)
163 if (
ui->
buttonBox->buttonRole(button) == QDialogButtonBox::AcceptRole)
164 done(QDialog::Accepted);
170 Qt::CheckState state = Qt::Checked;
171 for (
int i = 0; i <
ui->
treeWidget->topLevelItemCount(); i++)
175 state = Qt::Unchecked;
180 for (
int i = 0; i <
ui->
treeWidget->topLevelItemCount(); i++)
184 if (state == Qt::Unchecked)
346 sortOrder = ((
sortOrder == Qt::AscendingOrder) ? Qt::DescendingOrder : Qt::AscendingOrder);
360 if (checked &&
model)
367 if (checked &&
model)
380 else if (item->isDisabled())
394 #if QT_VERSION >= 0x050000
408 if (
AllowFree(dPriority / 1000000))
return tr(
"highest");
409 else if (
AllowFree(dPriority / 100000))
return tr(
"higher");
410 else if (
AllowFree(dPriority / 10000))
return tr(
"high");
411 else if (
AllowFree(dPriority / 1000))
return tr(
"medium-high");
412 else return tr(
"medium");
416 if (
AllowFree(dPriority * 10))
return tr(
"low-medium");
417 else if (
AllowFree(dPriority * 100))
return tr(
"low");
418 else if (
AllowFree(dPriority * 1000))
return tr(
"lower");
419 else return tr(
"lowest");
426 vector<COutPoint> vOutpts;
428 if (vOutpts.size() > 0)
430 ui->
labelLocked->setText(tr(
"(%1 locked)").arg(vOutpts.size()));
442 qint64 nPayAmount = 0;
443 bool fLowOutput =
false;
448 nPayAmount += amount;
456 txDummy.
vout.push_back(txout);
462 QString sPriorityLabel = tr(
"none");
465 int64_t nAfterFee = 0;
467 unsigned int nBytes = 0;
468 unsigned int nBytesInputs = 0;
469 double dPriority = 0;
470 double dPriorityInputs = 0;
471 unsigned int nQuantity = 0;
472 int nQuantityUncompressed = 0;
474 vector<COutPoint> vCoinControl;
475 vector<COutput> vOutputs;
479 BOOST_FOREACH(
const COutput& out, vOutputs)
495 nAmount += out.
tx->
vout[out.
i].nValue;
498 dPriorityInputs += (double)out.
tx->
vout[out.
i].nValue * (out.
nDepth+1);
505 CKeyID *keyid = boost::get<CKeyID>(&address);
506 if (keyid && model->
getPubKey(*keyid, pubkey))
510 nQuantityUncompressed++;
515 else nBytesInputs += 148;
525 dPriority = dPriorityInputs / (nBytes - nBytesInputs + (nQuantityUncompressed * 29));
534 nPayFee = max(nFee, nMinFee);
538 nChange = nAmount - nPayFee - nPayAmount;
541 if (nPayFee < CTransaction::nMinTxFee && nChange > 0 && nChange < CENT)
556 if (nChange > 0 && nChange < CENT)
558 CTxOut txout(nChange, (
CScript)vector<unsigned char>(24, 0));
571 nAfterFee = nAmount - nPayFee;
581 QLabel *l1 = dialog->findChild<QLabel *>(
"labelCoinControlQuantity");
582 QLabel *l2 = dialog->findChild<QLabel *>(
"labelCoinControlAmount");
583 QLabel *l3 = dialog->findChild<QLabel *>(
"labelCoinControlFee");
584 QLabel *l4 = dialog->findChild<QLabel *>(
"labelCoinControlAfterFee");
585 QLabel *l5 = dialog->findChild<QLabel *>(
"labelCoinControlBytes");
586 QLabel *l6 = dialog->findChild<QLabel *>(
"labelCoinControlPriority");
587 QLabel *l7 = dialog->findChild<QLabel *>(
"labelCoinControlLowOutput");
588 QLabel *l8 = dialog->findChild<QLabel *>(
"labelCoinControlChange");
591 dialog->findChild<QLabel *>(
"labelCoinControlLowOutputText")->setEnabled(nPayAmount > 0);
592 dialog->findChild<QLabel *>(
"labelCoinControlLowOutput") ->setEnabled(nPayAmount > 0);
593 dialog->findChild<QLabel *>(
"labelCoinControlChangeText") ->setEnabled(nPayAmount > 0);
594 dialog->findChild<QLabel *>(
"labelCoinControlChange") ->setEnabled(nPayAmount > 0);
597 l1->setText(QString::number(nQuantity));
601 l5->setText(((nBytes > 0) ?
"~" :
"") + QString::number(nBytes));
602 l6->setText(sPriorityLabel);
603 l7->setText((fLowOutput ? (fDust ? tr(
"Dust") : tr(
"yes")) : tr(
"no")));
607 l5->setStyleSheet((nBytes >= 1000) ?
"color:red;" :
"");
608 l6->setStyleSheet((dPriority > 0 && !
AllowFree(dPriority)) ?
"color:red;" :
"");
609 l7->setStyleSheet((fLowOutput) ?
"color:red;" :
"");
610 l8->setStyleSheet((nChange > 0 && nChange < CENT) ?
"color:red;" :
"");
613 QString toolTip1 = tr(
"This label turns red, if the transaction size is greater than 1000 bytes.") +
"<br /><br />";
615 toolTip1 += tr(
"Can vary +/- 1 byte per input.");
617 QString toolTip2 = tr(
"Transactions with higher priority are more likely to get included into a block.") +
"<br /><br />";
618 toolTip2 += tr(
"This label turns red, if the priority is smaller than \"medium\".") +
"<br /><br />";
621 QString toolTip3 = tr(
"This label turns red, if any recipient receives an amount smaller than %1.").arg(
AnoncoinUnits::formatWithUnit(nDisplayUnit, CENT)) +
"<br /><br />";
623 toolTip3 += tr(
"Amounts below 0.546 times the minimum relay fee are shown as dust.");
625 QString toolTip4 = tr(
"This label turns red, if the change is smaller than %1.").arg(
AnoncoinUnits::formatWithUnit(nDisplayUnit, CENT)) +
"<br /><br />";
628 l5->setToolTip(toolTip1);
629 l6->setToolTip(toolTip2);
630 l7->setToolTip(toolTip3);
631 l8->setToolTip(toolTip4);
632 dialog->findChild<QLabel *>(
"labelCoinControlBytesText") ->setToolTip(l5->toolTip());
633 dialog->findChild<QLabel *>(
"labelCoinControlPriorityText") ->setToolTip(l6->toolTip());
634 dialog->findChild<QLabel *>(
"labelCoinControlLowOutputText")->setToolTip(l7->toolTip());
635 dialog->findChild<QLabel *>(
"labelCoinControlChangeText") ->setToolTip(l8->toolTip());
638 QLabel *label = dialog->findChild<QLabel *>(
"labelCoinControlInsuffFunds");
640 label->setVisible(nChange < 0);
653 QFlags<Qt::ItemFlag> flgCheckbox = Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsUserCheckable;
654 QFlags<Qt::ItemFlag> flgTristate = Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsUserCheckable | Qt::ItemIsTristate;
658 map<QString, vector<COutput> > mapCoins;
661 BOOST_FOREACH(
PAIRTYPE(QString, vector<COutput>) coins, mapCoins)
663 QTreeWidgetItem *itemWalletAddress =
new QTreeWidgetItem();
665 QString sWalletAddress = coins.first;
667 if (sWalletLabel.isEmpty())
668 sWalletLabel = tr(
"(no label)");
675 itemWalletAddress->setFlags(flgTristate);
686 double dPrioritySum = 0;
689 BOOST_FOREACH(
const COutput& out, coins.second)
692 nSum += out.
tx->
vout[out.
i].nValue;
695 QTreeWidgetItem *itemOutput;
696 if (treeMode) itemOutput =
new QTreeWidgetItem(itemWalletAddress);
698 itemOutput->setFlags(flgCheckbox);
703 QString sAddress =
"";
709 if (!treeMode || (!(sAddress == sWalletAddress)))
713 CKeyID *keyid = boost::get<CKeyID>(&outputAddress);
719 if (!(sAddress == sWalletAddress))
722 itemOutput->setToolTip(
COLUMN_LABEL, tr(
"change from %1 (%2)").arg(sWalletLabel).arg(sWalletAddress));
728 if (sLabel.isEmpty())
729 sLabel = tr(
"(no label)");
745 double dPriority = ((double)out.
tx->
vout[out.
i].nValue / (nInputSize + 78)) * (out.
nDepth+1);
748 dPrioritySum += (double)out.
tx->
vout[out.
i].nValue * (out.
nDepth+1);
749 nInputSum += nInputSize;
763 itemOutput->setDisabled(
true);
775 dPrioritySum = dPrioritySum / (nInputSum + 78);
776 itemWalletAddress->setText(
COLUMN_CHECKBOX,
"(" + QString::number(nChildren) +
")");
787 for (
int i = 0; i <
ui->
treeWidget->topLevelItemCount(); i++)
void viewItemChanged(QTreeWidgetItem *, int)
bool IsDust(int64_t nMinRelayTxFee) const
void getOutputs(const std::vector< COutPoint > &vOutpoints, std::vector< COutput > &vOutputs)
void lockCoin(COutPoint &output)
void buttonSelectAllClicked()
void clipboardLowOutput()
void headerSectionClicked(int)
static CCoinControl * coinControl
void copyTransactionHash()
int getMappedColumn(int column, bool fVisibleColumn=true)
QRadioButton * radioTreeMode
static QString formatWithUnit(int unit, qint64 amount, bool plussign=false)
Format as string (with unit)
void setupUi(QDialog *CoinControlDialog)
bool isLockedCoin(uint256 hash, unsigned int n) const
QString dateTimeStr(const QDateTime &date)
bool IsSelected(const uint256 &hash, unsigned int n) const
int64_t GetMinFee(const CTransaction &tx, unsigned int nBytes, bool fAllowFree, enum GetMinFee_mode mode)
bool AllowFree(double dPriority)
AddressTableModel * getAddressTableModel()
static int64_t nMinTxFee
Fees smaller than this (in satoshi) are considered zero fee (for transaction creation) ...
QLabel * labelCoinControlPriority
QLabel * labelCoinControlChange
QPushButton * pushButtonSelectAll
QAction * copyTransactionHashAction
static QString format(int unit, qint64 amount, bool plussign=false)
Format as string.
bool isSpent(const COutPoint &outpoint) const
Ui::CoinControlDialog * ui
void setClipboard(const QString &str)
std::vector< CTxOut > vout
CoinControlTreeWidget * treeWidget
An encapsulated public key.
bool getPubKey(const CKeyID &address, CPubKey &vchPubKeyOut) const
static QString getPriorityLabel(double)
base58-encoded Anoncoin addresses.
CoinControlDialog(QWidget *parent=0)
std::string ToString() const
static void updateLabels(WalletModel *, QDialog *)
An output of a transaction.
QLabel * labelCoinControlQuantity
An outpoint - a combination of a transaction hash and an index n into its vout.
std::string GetHex() const
QLabel * labelCoinControlLowOutput
int64_t GetTxTime() const
boost::variant< CNoDestination, CKeyID, CScriptID > CTxDestination
A txout script template with a specific destination.
bool IsCompressed() const
QLabel * labelCoinControlAmount
void setModel(WalletModel *model)
QTreeWidgetItem * contextMenuItem
QString labelForAddress(const QString &address) const
void listLockedCoins(std::vector< COutPoint > &vOutpts)
Serialized script, used inside transaction inputs and outputs.
Interface to Anoncoin wallet from Qt view code.
void Select(COutPoint &output)
void unlockCoin(COutPoint &output)
A reference to a CKey: the Hash160 of its serialized public key.
bool ExtractDestination(const CScript &scriptPubKey, CTxDestination &addressRet)
void sortView(int, Qt::SortOrder)
static QList< qint64 > payAmounts
static int64_t nMinRelayTxFee
Fees smaller than this (in satoshi) are considered zero fee (for relaying and mining) ...
QString strPad(QString, int, QString)
void ListSelected(std::vector< COutPoint > &vOutpoints)
void buttonBoxClicked(QAbstractButton *)
void UnSelect(COutPoint &output)
The basic transaction that is broadcasted on the network and contained in blocks. ...
QRadioButton * radioListMode
void showMenu(const QPoint &)
QDialogButtonBox * buttonBox
void listCoins(std::map< QString, std::vector< COutput > > &mapCoins) const
QLabel * labelCoinControlFee
QLabel * labelCoinControlAfterFee
QLabel * labelCoinControlBytes
OptionsModel * getOptionsModel()