|
|
@ -3,6 +3,7 @@ |
|
|
|
#include "txtablemodel.h" |
|
|
|
#include "settings.h" |
|
|
|
#include "controller.h" |
|
|
|
#include "guiconstants.h" |
|
|
|
|
|
|
|
TxTableModel::TxTableModel(QObject *parent) |
|
|
|
: QAbstractTableModel(parent) { |
|
|
@ -87,6 +88,17 @@ QString TxTableModel::concatMultipleMemos(const TransactionItem& dat) const { |
|
|
|
}; |
|
|
|
|
|
|
|
QVariant TxTableModel::data(const QModelIndex &index, int role) const { |
|
|
|
|
|
|
|
// Get current theme name
|
|
|
|
QString theme_name = Settings::getInstance()->get_theme_name(); |
|
|
|
QBrush b; |
|
|
|
QColor color; |
|
|
|
if (theme_name == "Dark" || theme_name == "Midnight") { |
|
|
|
color = COLOR_WHITE; |
|
|
|
}else{ |
|
|
|
color = COLOR_BLACK; |
|
|
|
} |
|
|
|
|
|
|
|
// Align numeric columns (confirmations, amount) right
|
|
|
|
if (role == Qt::TextAlignmentRole && |
|
|
|
(index.column() == Column::Confirmations || index.column() == Column::Amount)) |
|
|
@ -95,14 +107,10 @@ QVariant TxTableModel::data(const QModelIndex &index, int role) const { |
|
|
|
auto dat = modeldata->at(index.row()); |
|
|
|
if (role == Qt::ForegroundRole) { |
|
|
|
if (dat.confirmations <= 0) { |
|
|
|
QBrush b; |
|
|
|
b.setColor(Qt::red); |
|
|
|
return b; |
|
|
|
} |
|
|
|
|
|
|
|
// Else, just return the default brush
|
|
|
|
QBrush b; |
|
|
|
b.setColor(Qt::black); |
|
|
|
b.setColor(color); |
|
|
|
return b; |
|
|
|
} |
|
|
|
|
|
|
@ -198,24 +206,25 @@ QVariant TxTableModel::data(const QModelIndex &index, int role) const { |
|
|
|
|
|
|
|
// If the memo is a Payment URI, then show a payment request icon
|
|
|
|
if (dat.items.length() == 1 && dat.items[0].memo.startsWith("hush:")) { |
|
|
|
QIcon icon(":/icons/res/paymentreq.gif"); |
|
|
|
QImage image = colorizeIcon(QIcon(":/icons/res/paymentreq.gif"), color); |
|
|
|
QIcon icon; |
|
|
|
icon.addPixmap(QPixmap::fromImage(image)); |
|
|
|
return QVariant(icon.pixmap(16, 16)); |
|
|
|
} else if (hasMemo) { |
|
|
|
// Return the info pixmap to indicate memo
|
|
|
|
QIcon icon(":/icons/res/mail.png"); |
|
|
|
return QVariant(icon.pixmap(16, 16)); |
|
|
|
} else { |
|
|
|
|
|
|
|
if (dat.type == "Receive"){ |
|
|
|
// Empty pixmap to make it align
|
|
|
|
QPixmap p(16, 16); |
|
|
|
QIcon icon = QApplication::style()->standardIcon(QStyle::SP_ArrowLeft); |
|
|
|
QImage image = colorizeIcon(QIcon(":/icons/res/tx_input.png"), color); |
|
|
|
QIcon icon; |
|
|
|
icon.addPixmap(QPixmap::fromImage(image)); |
|
|
|
return QVariant(icon.pixmap(16, 16)); |
|
|
|
} |
|
|
|
if (dat.type == "send"){ |
|
|
|
// Empty pixmap to make it align
|
|
|
|
QPixmap p(16, 16); |
|
|
|
QIcon icon = QApplication::style()->standardIcon(QStyle::SP_ArrowForward); |
|
|
|
QImage image = colorizeIcon(QIcon(":/icons/res/tx_output.png"), color); |
|
|
|
QIcon icon; |
|
|
|
icon.addPixmap(QPixmap::fromImage(image)); |
|
|
|
return QVariant(icon.pixmap(16, 16)); |
|
|
|
} |
|
|
|
} |
|
|
@ -278,3 +287,17 @@ QString TxTableModel::getAmt(int row) const { |
|
|
|
} |
|
|
|
return total.toDecimalString(); |
|
|
|
} |
|
|
|
|
|
|
|
QImage TxTableModel::colorizeIcon(QIcon icon, QColor color) const{ |
|
|
|
QImage img(icon.pixmap(16, 16).toImage()); |
|
|
|
img = img.convertToFormat(QImage::Format_ARGB32); |
|
|
|
for (int x = img.width(); x--; ) |
|
|
|
{ |
|
|
|
for (int y = img.height(); y--; ) |
|
|
|
{ |
|
|
|
const QRgb rgb = img.pixel(x, y); |
|
|
|
img.setPixel(x, y, qRgba(color.red(), color.green(), color.blue(), qAlpha(rgb))); |
|
|
|
} |
|
|
|
} |
|
|
|
return img; |
|
|
|
} |