#include "transactionview.h"
-#include "transactionfilterproxy.h"
-#include "transactionrecord.h"
-#include "walletmodel.h"
#include "addresstablemodel.h"
-#include "transactiontablemodel.h"
#include "bitcoinunits.h"
#include "csvmodelwriter.h"
-#include "transactiondescdialog.h"
#include "editaddressdialog.h"
-#include "optionsmodel.h"
#include "guiutil.h"
+#include "optionsmodel.h"
+#include "transactiondescdialog.h"
+#include "transactionfilterproxy.h"
+#include "transactionrecord.h"
+#include "transactiontablemodel.h"
+#include "walletmodel.h"
+
#include "ui_interface.h"
-#include <QScrollBar>
#include <QComboBox>
+#include <QDateTimeEdit>
+#include <QDesktopServices>
#include <QDoubleValidator>
#include <QHBoxLayout>
-#include <QVBoxLayout>
-#include <QLineEdit>
-#include <QTableView>
#include <QHeaderView>
-#include <QPoint>
-#include <QMenu>
#include <QLabel>
-#include <QDateTimeEdit>
+#include <QLineEdit>
+#include <QMenu>
+#include <QPoint>
+#include <QScrollBar>
+#include <QSignalMapper>
+#include <QTableView>
+#include <QUrl>
+#include <QVBoxLayout>
TransactionView::TransactionView(QWidget *parent) :
QWidget(parent), model(0), transactionProxyModel(0),
hlayout->addSpacing(23);
#endif
+ watchOnlyWidget = new QComboBox(this);
+ watchOnlyWidget->setFixedWidth(24);
+ watchOnlyWidget->addItem("", TransactionFilterProxy::WatchOnlyFilter_All);
+ watchOnlyWidget->addItem(QIcon(":/icons/eye_plus"), "", TransactionFilterProxy::WatchOnlyFilter_Yes);
+ watchOnlyWidget->addItem(QIcon(":/icons/eye_minus"), "", TransactionFilterProxy::WatchOnlyFilter_No);
+ hlayout->addWidget(watchOnlyWidget);
+
dateWidget = new QComboBox(this);
#ifdef Q_OS_MAC
dateWidget->setFixedWidth(121);
addressWidget = new QLineEdit(this);
#if QT_VERSION >= 0x040700
- /* Do not move this to the XML file, Qt before 4.7 will choke on it */
addressWidget->setPlaceholderText(tr("Enter address or label to search"));
#endif
hlayout->addWidget(addressWidget);
amountWidget = new QLineEdit(this);
#if QT_VERSION >= 0x040700
- /* Do not move this to the XML file, Qt before 4.7 will choke on it */
amountWidget->setPlaceholderText(tr("Min amount"));
#endif
#ifdef Q_OS_MAC
view->setTabKeyNavigation(false);
view->setContextMenuPolicy(Qt::CustomContextMenu);
+ view->installEventFilter(this);
+
transactionView = view;
// Actions
contextMenu->addAction(editLabelAction);
contextMenu->addAction(showDetailsAction);
+ mapperThirdPartyTxUrls = new QSignalMapper(this);
+
// Connect actions
+ connect(mapperThirdPartyTxUrls, SIGNAL(mapped(QString)), this, SLOT(openThirdPartyTxUrl(QString)));
+
connect(dateWidget, SIGNAL(activated(int)), this, SLOT(chooseDate(int)));
connect(typeWidget, SIGNAL(activated(int)), this, SLOT(chooseType(int)));
+ connect(watchOnlyWidget, SIGNAL(activated(int)), this, SLOT(chooseWatchonly(int)));
connect(addressWidget, SIGNAL(textChanged(QString)), this, SLOT(changedPrefix(QString)));
connect(amountWidget, SIGNAL(textChanged(QString)), this, SLOT(changedAmount(QString)));
transactionProxyModel->setSortRole(Qt::EditRole);
+ transactionView->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
transactionView->setModel(transactionProxyModel);
transactionView->setAlternatingRowColors(true);
transactionView->setSelectionBehavior(QAbstractItemView::SelectRows);
transactionView->sortByColumn(TransactionTableModel::Status, Qt::DescendingOrder);
transactionView->verticalHeader()->hide();
- transactionView->horizontalHeader()->resizeSection(TransactionTableModel::Status, 23);
- transactionView->horizontalHeader()->resizeSection(TransactionTableModel::Date, 120);
- transactionView->horizontalHeader()->resizeSection(TransactionTableModel::Type, 120);
-#if QT_VERSION < 0x050000
- transactionView->horizontalHeader()->setResizeMode(TransactionTableModel::ToAddress, QHeaderView::Stretch);
-#else
- transactionView->horizontalHeader()->setSectionResizeMode(TransactionTableModel::ToAddress, QHeaderView::Stretch);
-#endif
- transactionView->horizontalHeader()->resizeSection(TransactionTableModel::Amount, 100);
+ transactionView->setColumnWidth(TransactionTableModel::Status, STATUS_COLUMN_WIDTH);
+ transactionView->setColumnWidth(TransactionTableModel::Watchonly, WATCHONLY_COLUMN_WIDTH);
+ transactionView->setColumnWidth(TransactionTableModel::Date, DATE_COLUMN_WIDTH);
+ transactionView->setColumnWidth(TransactionTableModel::Type, TYPE_COLUMN_WIDTH);
+ transactionView->setColumnWidth(TransactionTableModel::Amount, AMOUNT_MINIMUM_COLUMN_WIDTH);
+
+ columnResizingFixer = new GUIUtil::TableViewLastColumnResizingFixer(transactionView, AMOUNT_MINIMUM_COLUMN_WIDTH, MINIMUM_COLUMN_WIDTH);
+
+ if (model->getOptionsModel())
+ {
+ // Add third party transaction URLs to context menu
+ QStringList listUrls = model->getOptionsModel()->getThirdPartyTxUrls().split("|", QString::SkipEmptyParts);
+ for (int i = 0; i < listUrls.size(); ++i)
+ {
+ QString host = QUrl(listUrls[i].trimmed(), QUrl::StrictMode).host();
+ if (!host.isEmpty())
+ {
+ QAction *thirdPartyTxUrlAction = new QAction(host, this); // use host as menu item label
+ if (i == 0)
+ contextMenu->addSeparator();
+ contextMenu->addAction(thirdPartyTxUrlAction);
+ connect(thirdPartyTxUrlAction, SIGNAL(triggered()), mapperThirdPartyTxUrls, SLOT(map()));
+ mapperThirdPartyTxUrls->setMapping(thirdPartyTxUrlAction, listUrls[i].trimmed());
+ }
+ }
+ }
+
+ // show/hide column Watch-only
+ updateWatchOnlyColumn(model->haveWatchOnly());
+
+ // Watch-only signal
+ connect(model, SIGNAL(notifyWatchonlyChanged(bool)), this, SLOT(updateWatchOnlyColumn(bool)));
}
}
typeWidget->itemData(idx).toInt());
}
+void TransactionView::chooseWatchonly(int idx)
+{
+ if(!transactionProxyModel)
+ return;
+ transactionProxyModel->setWatchOnlyFilter(
+ (TransactionFilterProxy::WatchOnlyFilter)watchOnlyWidget->itemData(idx).toInt());
+}
+
void TransactionView::changedPrefix(const QString &prefix)
{
if(!transactionProxyModel)
// CSV is currently the only supported format
QString filename = GUIUtil::getSaveFileName(this,
tr("Export Transaction History"), QString(),
- tr("Comma separated file (*.csv)"));
+ tr("Comma separated file (*.csv)"), NULL);
if (filename.isNull())
return;
// name, column, role
writer.setModel(transactionProxyModel);
writer.addColumn(tr("Confirmed"), 0, TransactionTableModel::ConfirmedRole);
+ if (model && model->haveWatchOnly())
+ writer.addColumn(tr("Watchonly"), TransactionTableModel::Watchonly);
writer.addColumn(tr("Date"), 0, TransactionTableModel::DateRole);
writer.addColumn(tr("Type"), TransactionTableModel::Type, Qt::EditRole);
writer.addColumn(tr("Label"), 0, TransactionTableModel::LabelRole);
writer.addColumn(tr("Address"), 0, TransactionTableModel::AddressRole);
- writer.addColumn(tr("Amount"), 0, TransactionTableModel::FormattedAmountRole);
+ writer.addColumn(BitcoinUnits::getAmountColumnTitle(model->getOptionsModel()->getDisplayUnit()), 0, TransactionTableModel::FormattedAmountRole);
writer.addColumn(tr("ID"), 0, TransactionTableModel::TxIDRole);
if(!writer.write()) {
// Determine type of address, launch appropriate editor dialog type
QString type = modelIdx.data(AddressTableModel::TypeRole).toString();
- EditAddressDialog dlg(type==AddressTableModel::Receive
- ? EditAddressDialog::EditReceivingAddress
- : EditAddressDialog::EditSendingAddress,
- this);
+ EditAddressDialog dlg(
+ type == AddressTableModel::Receive
+ ? EditAddressDialog::EditReceivingAddress
+ : EditAddressDialog::EditSendingAddress, this);
dlg.setModel(addressBook);
dlg.loadRow(idx);
dlg.exec();
{
// Add sending address
EditAddressDialog dlg(EditAddressDialog::NewSendingAddress,
- this);
+ this);
dlg.setModel(addressBook);
dlg.setAddress(address);
dlg.exec();
}
}
+void TransactionView::openThirdPartyTxUrl(QString url)
+{
+ if(!transactionView || !transactionView->selectionModel())
+ return;
+ QModelIndexList selection = transactionView->selectionModel()->selectedRows(0);
+ if(!selection.isEmpty())
+ QDesktopServices::openUrl(QUrl::fromUserInput(url.replace("%s", selection.at(0).data(TransactionTableModel::TxHashRole).toString())));
+}
+
QWidget *TransactionView::createDateRangeWidget()
{
dateRangeWidget = new QFrame();
transactionView->setCurrentIndex(targetIdx);
transactionView->setFocus();
}
+
+// We override the virtual resizeEvent of the QWidget to adjust tables column
+// sizes as the tables width is proportional to the dialogs width.
+void TransactionView::resizeEvent(QResizeEvent* event)
+{
+ QWidget::resizeEvent(event);
+ columnResizingFixer->stretchColumnWidth(TransactionTableModel::ToAddress);
+}
+
+// Need to override default Ctrl+C action for amount as default behaviour is just to copy DisplayRole text
+bool TransactionView::eventFilter(QObject *obj, QEvent *event)
+{
+ if (event->type() == QEvent::KeyPress)
+ {
+ QKeyEvent *ke = static_cast<QKeyEvent *>(event);
+ if (ke->key() == Qt::Key_C && ke->modifiers().testFlag(Qt::ControlModifier))
+ {
+ QModelIndex i = this->transactionView->currentIndex();
+ if (i.isValid() && i.column() == TransactionTableModel::Amount)
+ {
+ GUIUtil::setClipboard(i.data(TransactionTableModel::FormattedAmountRole).toString());
+ return true;
+ }
+ }
+ }
+ return QWidget::eventFilter(obj, event);
+}
+
+// show/hide column Watch-only
+void TransactionView::updateWatchOnlyColumn(bool fHaveWatchOnly)
+{
+ watchOnlyWidget->setVisible(fHaveWatchOnly);
+ transactionView->setColumnHidden(TransactionTableModel::Watchonly, !fHaveWatchOnly);
+}