From eb42261908ac4e6bcd10e9615acf4b1fb8b7a289 Mon Sep 17 00:00:00 2001 From: fekt Date: Thu, 13 Oct 2022 15:08:42 -0400 Subject: [PATCH] GUI tweaks for dark themes --- res/css/dark.css | 2 +- res/css/light.css | 2 +- res/css/midnight.css | 2 +- silentdragon.pro | 1 + src/balancestablemodel.cpp | 23 +++++++----- src/connection.ui | 32 ++++++++++++----- src/guiconstants.h | 10 ++++++ src/mainwindow.cpp | 2 +- src/mobileappconnector.ui | 10 ++++-- src/peerstablemodel.cpp | 38 +++++++++++--------- src/rpc.cpp | 6 ++-- src/txtablemodel.cpp | 74 ++++++++++++++++++++++++++++---------- src/txtablemodel.h | 5 +-- 13 files changed, 142 insertions(+), 65 deletions(-) create mode 100644 src/guiconstants.h diff --git a/res/css/dark.css b/res/css/dark.css index 7846b25..9a30723 100644 --- a/res/css/dark.css +++ b/res/css/dark.css @@ -1,5 +1,5 @@ -QWidget, QMainWindow, QMenuBar, QMenu, QDialog, QTabWidget, QTableView, QTableView::item, QScrollArea, QGroupBox, QPlainTextEdit, QLineEdit, QLabel, MainWindow +QWidget, QMainWindow, QMenuBar, QMenu, QDialog, QTabWidget, QTableView, QScrollArea, QGroupBox, QPlainTextEdit, QLineEdit, QLabel, MainWindow { background-color: #303335; color: #ffffff; diff --git a/res/css/light.css b/res/css/light.css index 16b9a0b..fce0c1b 100644 --- a/res/css/light.css +++ b/res/css/light.css @@ -1,4 +1,4 @@ -QWidget, QMainWindow, QMenuBar, QMenu, QDialog, QTabWidget, QTableView, QTableView::item, QScrollArea, QGroupBox, QWidget, QPlainTextEdit, QLineEdit, QLabel, MainWindow +QWidget, QMainWindow, QMenuBar, QMenu, QDialog, QTabWidget, QTableView, QScrollArea, QGroupBox, QWidget, QPlainTextEdit, QLineEdit, QLabel, MainWindow { background-color: #dadada; color: #000000; diff --git a/res/css/midnight.css b/res/css/midnight.css index 754fbc6..f48a1b4 100644 --- a/res/css/midnight.css +++ b/res/css/midnight.css @@ -9,7 +9,7 @@ Website: https://www.csharpe.me License: https://opensource.org/licenses/MIT */ -QWidget, QMainWindow, QMenuBar, QMenu, QDialog, QTabWidget, QTableView, QTableView::item, QScrollArea, QGroupBox, QPlainTextEdit, QLineEdit, QLabel, MainWindow, QPixmap, QHBoxLayout, QVBoxLayout, QGridLayout, QAbstractItemView, QFrame +QWidget, QMainWindow, QMenuBar, QMenu, QDialog, QTabWidget, QTableView, QScrollArea, QGroupBox, QPlainTextEdit, QLineEdit, QLabel, MainWindow, QPixmap, QHBoxLayout, QVBoxLayout, QGridLayout, QAbstractItemView, QFrame { background-color: #111; color: #fff; diff --git a/silentdragon.pro b/silentdragon.pro index e324021..0ccc417 100644 --- a/silentdragon.pro +++ b/silentdragon.pro @@ -66,6 +66,7 @@ SOURCES += \ src/viewalladdresses.cpp HEADERS += \ + src/guiconstants.h \ src/mainwindow.h \ src/precompiled.h \ src/rpc.h \ diff --git a/src/balancestablemodel.cpp b/src/balancestablemodel.cpp index b26bfaa..0ca75ed 100644 --- a/src/balancestablemodel.cpp +++ b/src/balancestablemodel.cpp @@ -3,6 +3,7 @@ #include "balancestablemodel.h" #include "addressbook.h" #include "settings.h" +#include "guiconstants.h" BalancesTableModel::BalancesTableModel(QObject *parent) @@ -60,6 +61,10 @@ int BalancesTableModel::columnCount(const QModelIndex&) const QVariant BalancesTableModel::data(const QModelIndex &index, int role) const { + // Get current theme name + QString theme_name = Settings::getInstance()->get_theme_name(); + QBrush b; + if (loading) { if (role == Qt::DisplayRole) return "Loading..."; @@ -69,21 +74,23 @@ QVariant BalancesTableModel::data(const QModelIndex &index, int role) const if (role == Qt::TextAlignmentRole && index.column() == 1) return QVariant(Qt::AlignRight | Qt::AlignVCenter); - if (role == Qt::ForegroundRole) { + if (role == Qt::ForegroundRole) { // If any of the UTXOs for this address has zero confirmations, paint it in red const auto& addr = std::get<0>(modeldata->at(index.row())); for (auto utxo : *utxos) { if (utxo.address == addr && utxo.confirmations == 0) { - QBrush b; - b.setColor(Qt::red); + b.setColor(COLOR_UNCONFIRMED_TX); return b; } } - - // Else, just return the default brush - QBrush b; - b.setColor(Qt::black); - return b; + if (theme_name == "dark" || theme_name == "midnight") { + b.setColor(COLOR_WHITE); + return b; + }else{ + b.setColor(COLOR_BLACK); + return b; + } + return b; } if (role == Qt::DisplayRole) { diff --git a/src/connection.ui b/src/connection.ui index 70082d2..e70e076 100644 --- a/src/connection.ui +++ b/src/connection.ui @@ -9,10 +9,28 @@ 0 0 - 513 - 513 + 512 + 512 + + + 0 + 0 + + + + + 512 + 512 + + + + + 512 + 512 + + SilentDragon @@ -20,6 +38,9 @@ true + + QLayout::SetFixedSize + 0 @@ -84,13 +105,6 @@ - - - FilledIconLabel - QLabel -
fillediconlabel.h
-
-
diff --git a/src/guiconstants.h b/src/guiconstants.h new file mode 100644 index 0000000..ac025a3 --- /dev/null +++ b/src/guiconstants.h @@ -0,0 +1,10 @@ +// Copyright 2019-2022 The Hush developers +// Released under the GPLv3 +#ifndef GUICONSTANTS_H +#define GUICONSTANTS_H + +#define COLOR_BLACK QColor(0, 0, 0) +#define COLOR_WHITE QColor(255, 255, 255) +#define COLOR_UNCONFIRMED_TX QColor(255, 0, 0) + +#endif // GUICONSTANTS_H diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index e32e7e8..810e9b4 100755 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -2122,7 +2122,7 @@ void MainWindow::rescanButtonClicked(int number) { if (dialog.exec() == QDialog::Accepted) { // Show message in status bar - ui->statusBar->showMessage(tr("Rescanning"), 3 * 1000); + ui->statusBar->showMessage(tr("Rescanning..."), 3 * 1000); // Close settings QWidget *modalWidget = QApplication::activeModalWidget(); diff --git a/src/mobileappconnector.ui b/src/mobileappconnector.ui index bf09f36..2ddc598 100644 --- a/src/mobileappconnector.ui +++ b/src/mobileappconnector.ui @@ -62,14 +62,20 @@ - + - + 0 0 + + + 228 + 228 + + background-color: #fff diff --git a/src/peerstablemodel.cpp b/src/peerstablemodel.cpp index bc2c5c8..39ce258 100644 --- a/src/peerstablemodel.cpp +++ b/src/peerstablemodel.cpp @@ -3,6 +3,7 @@ #include "peerstablemodel.h" #include "settings.h" #include "rpc.h" +#include "guiconstants.h" PeersTableModel::PeersTableModel(QObject *parent) : QAbstractTableModel(parent) { @@ -52,23 +53,26 @@ int PeersTableModel::columnCount(const QModelIndex&) const } - QVariant PeersTableModel::data(const QModelIndex &index, int role) const - { - // Align column 4 (amount) right - //if (role == Qt::TextAlignmentRole && index.column() == 3) return QVariant(Qt::AlignRight | Qt::AlignVCenter); - +QVariant PeersTableModel::data(const QModelIndex &index, int role) const +{ + // Get current theme name + QString theme_name = Settings::getInstance()->get_theme_name(); + QBrush b; + if (role == Qt::ForegroundRole) { // peers with banscore >=50 will likely be banned soon, color them red if (modeldata->at(index.row()).banscore >= 50) { - QBrush b; - b.setColor(Qt::red); + b.setColor(COLOR_UNCONFIRMED_TX); return b; } - - // Else, just return the default brush - QBrush b; - b.setColor(Qt::black); - return b; + if (theme_name == "dark" || theme_name == "midnight") { + b.setColor(COLOR_WHITE); + return b; + }else{ + b.setColor(COLOR_BLACK); + return b; + } + return b; } auto dat = modeldata->at(index.row()); @@ -86,7 +90,7 @@ int PeersTableModel::columnCount(const QModelIndex&) const case 9: return dat.bytes_received; case 10: return dat.bytes_sent; } - } + } if (role == Qt::ToolTipRole) { switch (index.column()) { @@ -101,12 +105,12 @@ int PeersTableModel::columnCount(const QModelIndex&) const case 8: return "Banscore"; case 9: return "Bytes received"; case 10: return "Bytes sent"; - } + } } //TODO: show different icons for IP vs Tor vs other kinds of connections - /* + /* if (role == Qt::DecorationRole && index.column() == 0) { if (!dat.memo.isEmpty()) { // If the memo is a Payment URI, then show a payment request icon @@ -115,7 +119,7 @@ int PeersTableModel::columnCount(const QModelIndex&) const return QVariant(icon.pixmap(16, 16)); } else { // Return the info pixmap to indicate memo - QIcon icon = QApplication::style()->standardIcon(QStyle::SP_MessageBoxInformation); + QIcon icon = QApplication::style()->standardIcon(QStyle::SP_MessageBoxInformation); return QVariant(icon.pixmap(16, 16)); } } else { @@ -128,7 +132,7 @@ int PeersTableModel::columnCount(const QModelIndex&) const */ return QVariant(); - } +} QVariant PeersTableModel::headerData(int section, Qt::Orientation orientation, int role) const diff --git a/src/rpc.cpp b/src/rpc.cpp index c0e8115..3ec4998 100644 --- a/src/rpc.cpp +++ b/src/rpc.cpp @@ -1035,8 +1035,7 @@ void RPC::refreshTransactions() { return noConnection(); // Show statusBar message - QString message = QObject::tr("Transaction data is loading..."); - ui->statusBar->showMessage(message); + ui->statusBar->showMessage(QObject::tr("Transaction data is loading...")); getTransactions([=] (QJsonValue reply) { QList txdata; @@ -1068,8 +1067,7 @@ void RPC::refreshTransactions() { transactionsTableModel->addTData(txdata); // Update statusBar message - QString message = QObject::tr("Transaction data loaded"); - ui->statusBar->showMessage(message, 3 * 1000); + ui->statusBar->showMessage(QObject::tr("Transaction data loaded"), 3 * 1000); }); } diff --git a/src/txtablemodel.cpp b/src/txtablemodel.cpp index 6a4da88..c59b0c0 100644 --- a/src/txtablemodel.cpp +++ b/src/txtablemodel.cpp @@ -3,6 +3,7 @@ #include "txtablemodel.h" #include "settings.h" #include "rpc.h" +#include "guiconstants.h" TxTableModel::TxTableModel(QObject *parent) : QAbstractTableModel(parent) { @@ -56,7 +57,7 @@ bool TxTableModel::exportToCsv(QString fileName) const { out << "\"" << headers[i] << "\","; } out << "\"Memo\""; - out << endl; + out << Qt::endl; // Write out each row for (int row = 0; row < modeldata->length(); row++) { @@ -65,7 +66,7 @@ bool TxTableModel::exportToCsv(QString fileName) const { } // Memo out << "\"" << modeldata->at(row).memo << "\""; - out << endl; + out << Qt::endl; } file.close(); @@ -92,33 +93,61 @@ void TxTableModel::updateAllData() { layoutChanged(); } - int TxTableModel::rowCount(const QModelIndex&) const - { + +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; +} + + +int TxTableModel::rowCount(const QModelIndex&) const +{ if (modeldata == nullptr) return 0; return modeldata->size(); - } +} - int TxTableModel::columnCount(const QModelIndex&) const - { +int TxTableModel::columnCount(const QModelIndex&) const +{ return headers.size(); - } +} QVariant TxTableModel::data(const QModelIndex &index, int role) const { - // Align column 4 (amount) right + // 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 column 4 (amount) right if (role == Qt::TextAlignmentRole && index.column() == 3) return QVariant(Qt::AlignRight | Qt::AlignVCenter); if (role == Qt::ForegroundRole) { if (modeldata->at(index.row()).confirmations == 0) { - QBrush b; - b.setColor(Qt::red); + b.setColor(COLOR_UNCONFIRMED_TX); + return b; + } + if (theme_name == "dark" || theme_name == "midnight") { + b.setColor(color); + return b; + }else{ + b.setColor(color); return b; } - - // Else, just return the default brush - QBrush b; - b.setColor(Qt::black); return b; } @@ -180,19 +209,26 @@ void TxTableModel::updateAllData() { // Send if(this->getType(index.row()) == "send"){ - QIcon icon(":/icons/res/tx_output.png"); + QImage image = colorizeIcon(QIcon(":/icons/res/tx_output.png"), color); + QIcon icon; + icon.addPixmap(QPixmap::fromImage(image)); return QVariant(icon.pixmap(16, 16)); + } // Send T->Z - Untested - if(this->getType(index.row()) == "send" && !this->getFromAddr(index.row()).startsWith("zs1")){ - QIcon icon(":/icons/res/lock_closed.png"); + if(this->getType(index.row()) == "send" && !this->getFromAddr(index.row()).startsWith("zs1")){ + QImage image = colorizeIcon(QIcon(":/icons/res/lock_closed.png"), color); + QIcon icon; + icon.addPixmap(QPixmap::fromImage(image)); return QVariant(icon.pixmap(16, 16)); } // Receive if(this->getType(index.row()) == "receive"){ - QIcon icon(":/icons/res/tx_input.png"); + QImage image = colorizeIcon(QIcon(":/icons/res/tx_input.png"), color); + QIcon icon; + icon.addPixmap(QPixmap::fromImage(image)); return QVariant(icon.pixmap(16, 16)); } diff --git a/src/txtablemodel.h b/src/txtablemodel.h index 9e2d02d..c7e05a4 100644 --- a/src/txtablemodel.h +++ b/src/txtablemodel.h @@ -10,12 +10,12 @@ struct TransactionItem; class TxTableModel: public QAbstractTableModel { public: - TxTableModel(QObject* parent); + TxTableModel(QObject* parent); ~TxTableModel(); void addTData (const QList& data); void addZSentData(const QList& data); - void addZRecvData(const QList& data); + void addZRecvData(const QList& data); QString getTxId(int row) const; QString getMemo(int row) const; @@ -32,6 +32,7 @@ public: int columnCount(const QModelIndex &parent) const; QVariant data(const QModelIndex &index, int role) const; QVariant headerData(int section, Qt::Orientation orientation, int role) const; + QImage colorizeIcon(const QIcon icon, const QColor color) const; private: void updateAllData();