UI/color tweaks from SD

This commit is contained in:
fekt
2023-02-20 19:00:19 -05:00
parent 7dfce16b5f
commit 4969275156
9 changed files with 541 additions and 445 deletions

View File

@@ -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,15 +107,11 @@ 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);
return b;
b.setColor(color);
return b;
}
if (role == Qt::DisplayRole) {
@@ -195,29 +203,30 @@ QVariant TxTableModel::data(const QModelIndex &index, int role) const {
hasMemo = true;
}
}
// 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);
return QVariant(icon.pixmap(16, 16));
}
if (dat.type == "Receive"){
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);
return QVariant(icon.pixmap(16, 16));
}
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;
}