Browse Source

GUI tweaks for dark themes

pull/112/head
fekt 2 years ago
parent
commit
eb42261908
  1. 2
      res/css/dark.css
  2. 2
      res/css/light.css
  3. 2
      res/css/midnight.css
  4. 1
      silentdragon.pro
  5. 23
      src/balancestablemodel.cpp
  6. 32
      src/connection.ui
  7. 10
      src/guiconstants.h
  8. 2
      src/mainwindow.cpp
  9. 10
      src/mobileappconnector.ui
  10. 38
      src/peerstablemodel.cpp
  11. 6
      src/rpc.cpp
  12. 74
      src/txtablemodel.cpp
  13. 5
      src/txtablemodel.h

2
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; background-color: #303335;
color: #ffffff; color: #ffffff;

2
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; background-color: #dadada;
color: #000000; color: #000000;

2
res/css/midnight.css

@ -9,7 +9,7 @@ Website: https://www.csharpe.me
License: https://opensource.org/licenses/MIT 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; background-color: #111;
color: #fff; color: #fff;

1
silentdragon.pro

@ -66,6 +66,7 @@ SOURCES += \
src/viewalladdresses.cpp src/viewalladdresses.cpp
HEADERS += \ HEADERS += \
src/guiconstants.h \
src/mainwindow.h \ src/mainwindow.h \
src/precompiled.h \ src/precompiled.h \
src/rpc.h \ src/rpc.h \

23
src/balancestablemodel.cpp

@ -3,6 +3,7 @@
#include "balancestablemodel.h" #include "balancestablemodel.h"
#include "addressbook.h" #include "addressbook.h"
#include "settings.h" #include "settings.h"
#include "guiconstants.h"
BalancesTableModel::BalancesTableModel(QObject *parent) BalancesTableModel::BalancesTableModel(QObject *parent)
@ -60,6 +61,10 @@ int BalancesTableModel::columnCount(const QModelIndex&) const
QVariant BalancesTableModel::data(const QModelIndex &index, int role) 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 (loading) {
if (role == Qt::DisplayRole) if (role == Qt::DisplayRole)
return "Loading..."; 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::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 // 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())); const auto& addr = std::get<0>(modeldata->at(index.row()));
for (auto utxo : *utxos) { for (auto utxo : *utxos) {
if (utxo.address == addr && utxo.confirmations == 0) { if (utxo.address == addr && utxo.confirmations == 0) {
QBrush b; b.setColor(COLOR_UNCONFIRMED_TX);
b.setColor(Qt::red);
return b; return b;
} }
} }
if (theme_name == "dark" || theme_name == "midnight") {
// Else, just return the default brush b.setColor(COLOR_WHITE);
QBrush b; return b;
b.setColor(Qt::black); }else{
return b; b.setColor(COLOR_BLACK);
return b;
}
return b;
} }
if (role == Qt::DisplayRole) { if (role == Qt::DisplayRole) {

32
src/connection.ui

@ -9,10 +9,28 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>513</width> <width>512</width>
<height>513</height> <height>512</height>
</rect> </rect>
</property> </property>
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>512</width>
<height>512</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>512</width>
<height>512</height>
</size>
</property>
<property name="windowTitle"> <property name="windowTitle">
<string>SilentDragon</string> <string>SilentDragon</string>
</property> </property>
@ -20,6 +38,9 @@
<bool>true</bool> <bool>true</bool>
</property> </property>
<layout class="QVBoxLayout" name="verticalLayout"> <layout class="QVBoxLayout" name="verticalLayout">
<property name="sizeConstraint">
<enum>QLayout::SetFixedSize</enum>
</property>
<property name="leftMargin"> <property name="leftMargin">
<number>0</number> <number>0</number>
</property> </property>
@ -84,13 +105,6 @@
</item> </item>
</layout> </layout>
</widget> </widget>
<customwidgets>
<customwidget>
<class>FilledIconLabel</class>
<extends>QLabel</extends>
<header>fillediconlabel.h</header>
</customwidget>
</customwidgets>
<resources/> <resources/>
<connections/> <connections/>
</ui> </ui>

10
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

2
src/mainwindow.cpp

@ -2122,7 +2122,7 @@ void MainWindow::rescanButtonClicked(int number) {
if (dialog.exec() == QDialog::Accepted) { if (dialog.exec() == QDialog::Accepted) {
// Show message in status bar // Show message in status bar
ui->statusBar->showMessage(tr("Rescanning"), 3 * 1000); ui->statusBar->showMessage(tr("Rescanning..."), 3 * 1000);
// Close settings // Close settings
QWidget *modalWidget = QApplication::activeModalWidget(); QWidget *modalWidget = QApplication::activeModalWidget();

10
src/mobileappconnector.ui

@ -62,14 +62,20 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="0" column="0"> <item row="0" column="0" alignment="Qt::AlignHCenter">
<widget class="QRCodeLabel" name="qrcode"> <widget class="QRCodeLabel" name="qrcode">
<property name="sizePolicy"> <property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="MinimumExpanding"> <sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch> <horstretch>0</horstretch>
<verstretch>0</verstretch> <verstretch>0</verstretch>
</sizepolicy> </sizepolicy>
</property> </property>
<property name="minimumSize">
<size>
<width>228</width>
<height>228</height>
</size>
</property>
<property name="styleSheet"> <property name="styleSheet">
<string notr="true">background-color: #fff</string> <string notr="true">background-color: #fff</string>
</property> </property>

38
src/peerstablemodel.cpp

@ -3,6 +3,7 @@
#include "peerstablemodel.h" #include "peerstablemodel.h"
#include "settings.h" #include "settings.h"
#include "rpc.h" #include "rpc.h"
#include "guiconstants.h"
PeersTableModel::PeersTableModel(QObject *parent) PeersTableModel::PeersTableModel(QObject *parent)
: QAbstractTableModel(parent) { : QAbstractTableModel(parent) {
@ -52,23 +53,26 @@ int PeersTableModel::columnCount(const QModelIndex&) const
} }
QVariant PeersTableModel::data(const QModelIndex &index, int role) const QVariant PeersTableModel::data(const QModelIndex &index, int role) const
{ {
// Align column 4 (amount) right // Get current theme name
//if (role == Qt::TextAlignmentRole && index.column() == 3) return QVariant(Qt::AlignRight | Qt::AlignVCenter); QString theme_name = Settings::getInstance()->get_theme_name();
QBrush b;
if (role == Qt::ForegroundRole) { if (role == Qt::ForegroundRole) {
// peers with banscore >=50 will likely be banned soon, color them red // peers with banscore >=50 will likely be banned soon, color them red
if (modeldata->at(index.row()).banscore >= 50) { if (modeldata->at(index.row()).banscore >= 50) {
QBrush b; b.setColor(COLOR_UNCONFIRMED_TX);
b.setColor(Qt::red);
return b; return b;
} }
if (theme_name == "dark" || theme_name == "midnight") {
// Else, just return the default brush b.setColor(COLOR_WHITE);
QBrush b; return b;
b.setColor(Qt::black); }else{
return b; b.setColor(COLOR_BLACK);
return b;
}
return b;
} }
auto dat = modeldata->at(index.row()); auto dat = modeldata->at(index.row());
@ -86,7 +90,7 @@ int PeersTableModel::columnCount(const QModelIndex&) const
case 9: return dat.bytes_received; case 9: return dat.bytes_received;
case 10: return dat.bytes_sent; case 10: return dat.bytes_sent;
} }
} }
if (role == Qt::ToolTipRole) { if (role == Qt::ToolTipRole) {
switch (index.column()) { switch (index.column()) {
@ -101,12 +105,12 @@ int PeersTableModel::columnCount(const QModelIndex&) const
case 8: return "Banscore"; case 8: return "Banscore";
case 9: return "Bytes received"; case 9: return "Bytes received";
case 10: return "Bytes sent"; case 10: return "Bytes sent";
} }
} }
//TODO: show different icons for IP vs Tor vs other kinds of connections //TODO: show different icons for IP vs Tor vs other kinds of connections
/* /*
if (role == Qt::DecorationRole && index.column() == 0) { if (role == Qt::DecorationRole && index.column() == 0) {
if (!dat.memo.isEmpty()) { if (!dat.memo.isEmpty()) {
// If the memo is a Payment URI, then show a payment request icon // 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)); return QVariant(icon.pixmap(16, 16));
} else { } else {
// Return the info pixmap to indicate memo // 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)); return QVariant(icon.pixmap(16, 16));
} }
} else { } else {
@ -128,7 +132,7 @@ int PeersTableModel::columnCount(const QModelIndex&) const
*/ */
return QVariant(); return QVariant();
} }
QVariant PeersTableModel::headerData(int section, Qt::Orientation orientation, int role) const QVariant PeersTableModel::headerData(int section, Qt::Orientation orientation, int role) const

6
src/rpc.cpp

@ -1035,8 +1035,7 @@ void RPC::refreshTransactions() {
return noConnection(); return noConnection();
// Show statusBar message // Show statusBar message
QString message = QObject::tr("Transaction data is loading..."); ui->statusBar->showMessage(QObject::tr("Transaction data is loading..."));
ui->statusBar->showMessage(message);
getTransactions([=] (QJsonValue reply) { getTransactions([=] (QJsonValue reply) {
QList<TransactionItem> txdata; QList<TransactionItem> txdata;
@ -1068,8 +1067,7 @@ void RPC::refreshTransactions() {
transactionsTableModel->addTData(txdata); transactionsTableModel->addTData(txdata);
// Update statusBar message // Update statusBar message
QString message = QObject::tr("Transaction data loaded"); ui->statusBar->showMessage(QObject::tr("Transaction data loaded"), 3 * 1000);
ui->statusBar->showMessage(message, 3 * 1000);
}); });
} }

74
src/txtablemodel.cpp

@ -3,6 +3,7 @@
#include "txtablemodel.h" #include "txtablemodel.h"
#include "settings.h" #include "settings.h"
#include "rpc.h" #include "rpc.h"
#include "guiconstants.h"
TxTableModel::TxTableModel(QObject *parent) TxTableModel::TxTableModel(QObject *parent)
: QAbstractTableModel(parent) { : QAbstractTableModel(parent) {
@ -56,7 +57,7 @@ bool TxTableModel::exportToCsv(QString fileName) const {
out << "\"" << headers[i] << "\","; out << "\"" << headers[i] << "\",";
} }
out << "\"Memo\""; out << "\"Memo\"";
out << endl; out << Qt::endl;
// Write out each row // Write out each row
for (int row = 0; row < modeldata->length(); row++) { for (int row = 0; row < modeldata->length(); row++) {
@ -65,7 +66,7 @@ bool TxTableModel::exportToCsv(QString fileName) const {
} }
// Memo // Memo
out << "\"" << modeldata->at(row).memo << "\""; out << "\"" << modeldata->at(row).memo << "\"";
out << endl; out << Qt::endl;
} }
file.close(); file.close();
@ -92,33 +93,61 @@ void TxTableModel::updateAllData() {
layoutChanged(); 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; if (modeldata == nullptr) return 0;
return modeldata->size(); return modeldata->size();
} }
int TxTableModel::columnCount(const QModelIndex&) const int TxTableModel::columnCount(const QModelIndex&) const
{ {
return headers.size(); return headers.size();
} }
QVariant TxTableModel::data(const QModelIndex &index, int role) const 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::TextAlignmentRole && index.column() == 3) return QVariant(Qt::AlignRight | Qt::AlignVCenter);
if (role == Qt::ForegroundRole) { if (role == Qt::ForegroundRole) {
if (modeldata->at(index.row()).confirmations == 0) { if (modeldata->at(index.row()).confirmations == 0) {
QBrush b; b.setColor(COLOR_UNCONFIRMED_TX);
b.setColor(Qt::red); return b;
}
if (theme_name == "dark" || theme_name == "midnight") {
b.setColor(color);
return b;
}else{
b.setColor(color);
return b; return b;
} }
// Else, just return the default brush
QBrush b;
b.setColor(Qt::black);
return b; return b;
} }
@ -180,19 +209,26 @@ void TxTableModel::updateAllData() {
// Send // Send
if(this->getType(index.row()) == "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)); return QVariant(icon.pixmap(16, 16));
} }
// Send T->Z - Untested // Send T->Z - Untested
if(this->getType(index.row()) == "send" && !this->getFromAddr(index.row()).startsWith("zs1")){ if(this->getType(index.row()) == "send" && !this->getFromAddr(index.row()).startsWith("zs1")){
QIcon icon(":/icons/res/lock_closed.png"); QImage image = colorizeIcon(QIcon(":/icons/res/lock_closed.png"), color);
QIcon icon;
icon.addPixmap(QPixmap::fromImage(image));
return QVariant(icon.pixmap(16, 16)); return QVariant(icon.pixmap(16, 16));
} }
// Receive // Receive
if(this->getType(index.row()) == "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)); return QVariant(icon.pixmap(16, 16));
} }

5
src/txtablemodel.h

@ -10,12 +10,12 @@ struct TransactionItem;
class TxTableModel: public QAbstractTableModel class TxTableModel: public QAbstractTableModel
{ {
public: public:
TxTableModel(QObject* parent); TxTableModel(QObject* parent);
~TxTableModel(); ~TxTableModel();
void addTData (const QList<TransactionItem>& data); void addTData (const QList<TransactionItem>& data);
void addZSentData(const QList<TransactionItem>& data); void addZSentData(const QList<TransactionItem>& data);
void addZRecvData(const QList<TransactionItem>& data); void addZRecvData(const QList<TransactionItem>& data);
QString getTxId(int row) const; QString getTxId(int row) const;
QString getMemo(int row) const; QString getMemo(int row) const;
@ -32,6 +32,7 @@ public:
int columnCount(const QModelIndex &parent) const; int columnCount(const QModelIndex &parent) const;
QVariant data(const QModelIndex &index, int role) const; QVariant data(const QModelIndex &index, int role) const;
QVariant headerData(int section, Qt::Orientation orientation, int role) const; QVariant headerData(int section, Qt::Orientation orientation, int role) const;
QImage colorizeIcon(const QIcon icon, const QColor color) const;
private: private:
void updateAllData(); void updateAllData();

Loading…
Cancel
Save