10 #include <QAbstractItemDelegate> 11 #include <QStandardItem> 12 #include <QStandardItemModel> 13 #include <QSortFilterProxyModel> 14 #include <QSizePolicy> 18 #define SYMBOL_WIDTH 60 26 QAbstractItemDelegate(parent),
30 void paint(QPainter *painter,
const QStyleOptionViewItem &option,
31 const QModelIndex &index)
const 39 QRect mainRect = option.rect;
41 bool selected = option.state & QStyle::State_Selected;
44 painter->fillRect(mainRect,QColor(
"#009ee5"));
48 painter->fillRect(mainRect,QColor(
"#383938"));
51 QRect hLineRect(mainRect.left(), mainRect.bottom(), mainRect.width(), 1);
52 painter->fillRect(hLineRect, QColor(
"#2e2e2e"));
54 QColor foreground(
"#dddddd");
55 painter->setPen(foreground);
57 QFont font = option.font;
58 font.setPointSizeF(option.font.pointSizeF() * 1.1);
60 painter->setFont(font);
61 QColor amountColor(
"#ffffff");
62 painter->setPen(amountColor);
64 QFontMetrics fmName(option.font);
65 QString clippedSymbol = fmName.elidedText(tokenSymbol, Qt::ElideRight,
SYMBOL_WIDTH);
67 painter->drawText(tokenSymbolRect, Qt::AlignLeft|Qt::AlignVCenter, clippedSymbol);
69 int amountWidth = (mainRect.width() - 4 *
MARGIN - tokenSymbolRect.width());
70 QFontMetrics fmAmount(font);
71 QString clippedAmount = fmAmount.elidedText(tokenBalance, Qt::ElideRight, amountWidth);
72 QRect tokenBalanceRect(tokenSymbolRect.right() + 2 *
MARGIN, tokenSymbolRect.top(), amountWidth, tokenSymbolRect.height());
73 painter->drawText(tokenBalanceRect, Qt::AlignLeft|Qt::AlignVCenter, clippedAmount);
75 QFont addressFont = option.font;
76 addressFont.setPointSizeF(option.font.pointSizeF() * 0.8);
77 painter->setFont(addressFont);
78 painter->setPen(foreground);
79 QRect receiveAddressRect(mainRect.left() +
MARGIN, tokenSymbolRect.bottom(), mainRect.width() - 2 *
MARGIN, mainRect.height() / 2 - 2 *
MARGIN);
80 painter->drawText(receiveAddressRect, Qt::AlignLeft|Qt::AlignVCenter, receiveAddress);
85 QSize
sizeHint(
const QStyleOptionViewItem &option,
const QModelIndex &index)
const 100 m_tokenTransactionView(0)
123 ui->
tokensList->setContextMenuPolicy(Qt::CustomContextMenu);
124 ui->
tokensList->setAttribute(Qt::WA_MacShowFocusRect,
false);
126 QAction *copySenderAction =
new QAction(tr(
"Copy receive address"),
this);
127 QAction *copyTokenBalanceAction =
new QAction(tr(
"Copy token balance"),
this);
128 QAction *copyTokenNameAction =
new QAction(tr(
"Copy token name"),
this);
129 QAction *copyTokenAddressAction =
new QAction(tr(
"Copy contract address"),
this);
130 QAction *removeTokenAction =
new QAction(tr(
"Remove token"),
this);
139 connect(copyTokenAddressAction, SIGNAL(triggered(
bool)),
this, SLOT(
copyTokenAddress()));
140 connect(copyTokenBalanceAction, SIGNAL(triggered(
bool)),
this, SLOT(
copyTokenBalance()));
141 connect(copyTokenNameAction, SIGNAL(triggered(
bool)),
this, SLOT(
copyTokenName()));
142 connect(copySenderAction, SIGNAL(triggered(
bool)),
this, SLOT(
copySenderAddress()));
143 connect(removeTokenAction, SIGNAL(triggered(
bool)),
this, SLOT(
removeToken()));
165 QSortFilterProxyModel *proxyModel =
new QSortFilterProxyModel(
this);
167 proxyModel->setSourceModel(tokenModel);
168 proxyModel->sort(1, Qt::AscendingOrder);
173 connect(
ui->
tokensList->selectionModel(), SIGNAL(currentChanged(QModelIndex,QModelIndex)),
this, SLOT(
on_currentChanged(QModelIndex,QModelIndex)));
176 connect(
m_tokenModel, SIGNAL(dataChanged(QModelIndex,QModelIndex,QVector<int>)), SLOT(
on_dataChanged(QModelIndex,QModelIndex,QVector<int>)));
242 Q_UNUSED(bottomRight);
280 QModelIndexList selection =
ui->
tokensList->selectionModel()->selectedIndexes();
281 if (selection.empty())
312 QMessageBox::StandardButton btnRetVal = QMessageBox::question(
this, tr(
"Confirm token remove"), tr(
"The selected token will be removed from the list. Are you sure?"),
313 QMessageBox::Yes | QMessageBox::Cancel, QMessageBox::Cancel);
315 if(btnRetVal == QMessageBox::Yes)
317 QModelIndexList selection =
ui->
tokensList->selectionModel()->selectedIndexes();
318 if (selection.empty() && !
m_model)
321 QModelIndex index = selection[0];
void setModel(WalletModel *model)
struct evm_uint256be balance(struct evm_env *env, struct evm_uint160be address)
AddTokenPage * m_addTokenPage
void setClientModel(ClientModel *clientModel)
QRCToken(const PlatformStyle *platformStyle, QWidget *parent=0)
void copyEntryDataFromList(QAbstractItemView *view, int role)
Copy a field of the currently selected entry of a view to the clipboard.
void contextualMenu(const QPoint &)
void on_currentChanged(QModelIndex current, QModelIndex previous)
QStackedWidget * stackedWidgetToken
void setTokenData(std::string address, std::string sender, std::string symbol, int8_t decimals, std::string balance)
void setClientModel(ClientModel *clientModel)
TokenTransactionView * m_tokenTransactionView
void on_goToReceiveTokenPage()
TokenViewDelegate * m_tokenDelegate
void setModel(WalletModel *_model)
ClientModel * m_clientModel
void setAddress(QString address)
const PlatformStyle * platformStyle
QVBoxLayout * tokenViewLayout
void on_goToSendTokenPage()
QAbstractItemModel * m_tokenModel
TokenItemModel * getTokenItemModel()
TokenViewDelegate(const PlatformStyle *_platformStyle, QObject *parent)
void on_dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector< int > &roles=QVector< int >())
SendTokenPage * m_sendTokenPage
Model for Fabcoin network client.
void setSymbol(QString symbol)
void setModel(WalletModel *_model)
void on_rowsInserted(QModelIndex index, int first, int last)
Interface to Fabcoin wallet from Qt view code.
QString m_selectedTokenHash
bool removeTokenEntry(const std::string &sHash)
void on_currentTokenChanged(QModelIndex index)
const PlatformStyle * m_platformStyle
ReceiveTokenPage * m_receiveTokenPage
struct evm_uint160be address(struct evm_env *env)
void setModel(WalletModel *_model)
void setClientModel(ClientModel *clientModel)
QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const
void setupUi(QWidget *QRCToken)
void on_goToAddTokenPage()
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const