mirror of
				https://git.wownero.com/wowlet/wowlet.git
				synced 2024-08-15 01:03:14 +00:00 
			
		
		
		
	Improve color scheme
This commit is contained in:
		
							parent
							
								
									68a5469b97
								
							
						
					
					
						commit
						f05435d694
					
				
					 11 changed files with 165 additions and 21 deletions
				
			
		| 
						 | 
				
			
			@ -8,6 +8,7 @@
 | 
			
		|||
#include "libwalletqt/Transfer.h"
 | 
			
		||||
#include "libwalletqt/Input.h"
 | 
			
		||||
#include "model/ModelUtils.h"
 | 
			
		||||
#include "utils/ColorScheme.h"
 | 
			
		||||
 | 
			
		||||
#include <QFileDialog>
 | 
			
		||||
#include <QMessageBox>
 | 
			
		||||
| 
						 | 
				
			
			@ -52,7 +53,7 @@ void TxConfAdvDialog::setTransaction(PendingTransaction *tx) {
 | 
			
		|||
 | 
			
		||||
    m_tx = tx;
 | 
			
		||||
    m_tx->refresh();
 | 
			
		||||
    PendingTransactionInfo *ptx = m_tx->transaction(0);
 | 
			
		||||
    PendingTransactionInfo *ptx = m_tx->transaction(0); //Todo: support split transactions
 | 
			
		||||
 | 
			
		||||
    ui->txid->setText(tx->txid().first());
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -102,12 +103,16 @@ void TxConfAdvDialog::setupConstructionData(ConstructionInfo *ci) {
 | 
			
		|||
    ui->inputs->setText(inputs_str);
 | 
			
		||||
    ui->label_inputs->setText(QString("Inputs (%1)").arg(QString::number(inputs.size())));
 | 
			
		||||
 | 
			
		||||
    QString outputs_str;
 | 
			
		||||
    auto outputs = ci->outputs();
 | 
			
		||||
 | 
			
		||||
    QTextCursor cursor = ui->outputs->textCursor();
 | 
			
		||||
    for (const auto& o: outputs) {
 | 
			
		||||
        outputs_str += QString("%1 %2\n").arg(o->address(), WalletManager::displayAmount(o->amount()));
 | 
			
		||||
        auto address = o->address();
 | 
			
		||||
        auto amount = WalletManager::displayAmount(o->amount());
 | 
			
		||||
        cursor.insertText(address, textFormat(address));
 | 
			
		||||
        cursor.insertText(QString(" %1").arg(amount), QTextCharFormat());
 | 
			
		||||
        cursor.insertBlock();
 | 
			
		||||
    }
 | 
			
		||||
    ui->outputs->setText(outputs_str);
 | 
			
		||||
    ui->label_outputs->setText(QString("Outputs (%1)").arg(QString::number(outputs.size())));
 | 
			
		||||
 | 
			
		||||
    ui->label_ringSize->setText(QString("Ring size: %1").arg(QString::number(ci->minMixinCount() + 1)));
 | 
			
		||||
| 
						 | 
				
			
			@ -178,6 +183,23 @@ void TxConfAdvDialog::closeDialog() {
 | 
			
		|||
    QDialog::reject();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
QTextCharFormat TxConfAdvDialog::textFormat(const QString &address) {
 | 
			
		||||
    auto index = m_ctx->currentWallet->subaddressIndex(address);
 | 
			
		||||
    if (index.first == 0 && index.second == 0) {
 | 
			
		||||
        QTextCharFormat rec;
 | 
			
		||||
        rec.setBackground(QBrush(ColorScheme::YELLOW.asColor(true)));
 | 
			
		||||
        rec.setToolTip("Wallet change/primary address");
 | 
			
		||||
        return rec;
 | 
			
		||||
    }
 | 
			
		||||
    if (index.first >= 0) {
 | 
			
		||||
        QTextCharFormat rec;
 | 
			
		||||
        rec.setBackground(QBrush(ColorScheme::GREEN.asColor(true)));
 | 
			
		||||
        rec.setToolTip("Wallet receive address");
 | 
			
		||||
        return rec;
 | 
			
		||||
    }
 | 
			
		||||
    return QTextCharFormat();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
TxConfAdvDialog::~TxConfAdvDialog() {
 | 
			
		||||
    delete ui;
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -8,6 +8,7 @@
 | 
			
		|||
#include <QStandardItemModel>
 | 
			
		||||
#include <QAbstractButton>
 | 
			
		||||
#include <QMenu>
 | 
			
		||||
#include <QTextCharFormat>
 | 
			
		||||
 | 
			
		||||
#include "libwalletqt/PendingTransaction.h"
 | 
			
		||||
#include "appcontext.h"
 | 
			
		||||
| 
						 | 
				
			
			@ -41,6 +42,8 @@ private:
 | 
			
		|||
    void signedQrCode();
 | 
			
		||||
    void signedSaveFile();
 | 
			
		||||
 | 
			
		||||
    QTextCharFormat textFormat(const QString &address);
 | 
			
		||||
 | 
			
		||||
    Ui::TxConfAdvDialog *ui;
 | 
			
		||||
    AppContext *m_ctx;
 | 
			
		||||
    PendingTransaction *m_tx = nullptr;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -6,6 +6,7 @@
 | 
			
		|||
#include "model/ModelUtils.h"
 | 
			
		||||
#include "txconfadvdialog.h"
 | 
			
		||||
#include "globals.h"
 | 
			
		||||
#include "utils/ColorScheme.h"
 | 
			
		||||
 | 
			
		||||
#include <QMessageBox>
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -42,21 +43,33 @@ TxConfDialog::TxConfDialog(AppContext *ctx, PendingTransaction *tx, const QStrin
 | 
			
		|||
    int maxLengthFiat = Utils::maxLength(amounts_fiat);
 | 
			
		||||
    std::for_each(amounts_fiat.begin(), amounts_fiat.end(), [maxLengthFiat](QString& amount){amount = amount.rightJustified(maxLengthFiat, ' ');});
 | 
			
		||||
 | 
			
		||||
    ui->label_amount->setFont(ModelUtils::getMonospaceFont());
 | 
			
		||||
    ui->label_fee->setFont(ModelUtils::getMonospaceFont());
 | 
			
		||||
    ui->label_total->setFont(ModelUtils::getMonospaceFont());
 | 
			
		||||
 | 
			
		||||
    ui->label_amount->setText(QString("%1 (%2 %3)").arg(amounts[0], amounts_fiat[0], preferredCur));
 | 
			
		||||
    ui->label_fee->setText(QString("%1 (%2 %3)").arg(amounts[1], amounts_fiat[1], preferredCur));
 | 
			
		||||
    ui->label_total->setText(QString("%1 (%2 %3)").arg(amounts[2], amounts_fiat[2], preferredCur));
 | 
			
		||||
 | 
			
		||||
    auto subaddressIndex = m_ctx->currentWallet->subaddressIndex(address);
 | 
			
		||||
    QString addressExtra;
 | 
			
		||||
    if (subaddressIndex.first >= 0) {
 | 
			
		||||
        ui->label_note->setText("Note: this is a churn transaction.");
 | 
			
		||||
        ui->label_note->show();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    ui->label_address->setText(ModelUtils::displayAddress(address, 2));
 | 
			
		||||
    ui->label_address->setFont(ModelUtils::getMonospaceFont());
 | 
			
		||||
    ui->label_address->setToolTip(address);
 | 
			
		||||
 | 
			
		||||
    if (subaddressIndex.first >= 0) {
 | 
			
		||||
        ui->label_note->setText("Note: this is a churn transaction.");
 | 
			
		||||
        ui->label_note->show();
 | 
			
		||||
        ui->label_address->setStyleSheet(ColorScheme::GREEN.asStylesheet(true));
 | 
			
		||||
        ui->label_address->setToolTip("Wallet receive address");
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if (subaddressIndex.first == 0 && subaddressIndex.second == 0) {
 | 
			
		||||
        ui->label_address->setStyleSheet(ColorScheme::YELLOW.asStylesheet(true));
 | 
			
		||||
        ui->label_address->setToolTip("Wallet change/primary address");
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    ui->buttonBox->button(QDialogButtonBox::Ok)->setText("Send");
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -22,6 +22,7 @@
 | 
			
		|||
#include "dialog/WalletCacheDebugDialog.h"
 | 
			
		||||
#include "ui_mainwindow.h"
 | 
			
		||||
#include "globals.h"
 | 
			
		||||
#include "utils/ColorScheme.h"
 | 
			
		||||
 | 
			
		||||
// libwalletqt
 | 
			
		||||
#include "libwalletqt/AddressBook.h"
 | 
			
		||||
| 
						 | 
				
			
			@ -365,6 +366,7 @@ MainWindow::MainWindow(AppContext *ctx, QWidget *parent) :
 | 
			
		|||
    this->initMenu();
 | 
			
		||||
 | 
			
		||||
    connect(&m_updateBytes, &QTimer::timeout, this, &MainWindow::updateNetStats);
 | 
			
		||||
    ColorScheme::updateFromWidget(this);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void MainWindow::initMain() {
 | 
			
		||||
| 
						 | 
				
			
			@ -1041,6 +1043,7 @@ void MainWindow::skinChanged(const QString &skinName) {
 | 
			
		|||
    config()->set(Config::skin, skinName);
 | 
			
		||||
    qApp->setStyleSheet(m_skins[skinName]);
 | 
			
		||||
    qDebug() << QString("Skin changed to %1").arg(skinName);
 | 
			
		||||
    ColorScheme::updateFromWidget(this);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void MainWindow::closeEvent(QCloseEvent *event) {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -6,6 +6,7 @@
 | 
			
		|||
#include "Coins.h"
 | 
			
		||||
#include "ModelUtils.h"
 | 
			
		||||
#include "globals.h"
 | 
			
		||||
#include "utils/ColorScheme.h"
 | 
			
		||||
 | 
			
		||||
#include <QBrush>
 | 
			
		||||
#include <QFont>
 | 
			
		||||
| 
						 | 
				
			
			@ -67,13 +68,13 @@ QVariant CoinsModel::data(const QModelIndex &index, int role) const
 | 
			
		|||
        }
 | 
			
		||||
        else if (role == Qt::BackgroundRole) {
 | 
			
		||||
            if (cInfo.spent()) {
 | 
			
		||||
                result = QBrush(QColor(255, 100, 100));
 | 
			
		||||
                result = QBrush(ColorScheme::RED.asColor(true));
 | 
			
		||||
            }
 | 
			
		||||
            else if (cInfo.frozen()) {
 | 
			
		||||
                result = QBrush(QColor(173, 216, 230));
 | 
			
		||||
                result = QBrush(ColorScheme::BLUE.asColor(true));
 | 
			
		||||
            }
 | 
			
		||||
            else if (!cInfo.unlocked()) {
 | 
			
		||||
                result = QBrush(QColor("#60993E"));
 | 
			
		||||
                result = QBrush(ColorScheme::YELLOW.asColor(true));
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        else if (role == Qt::TextAlignmentRole) {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -2,7 +2,8 @@
 | 
			
		|||
// Copyright (c) 2020-2021, The Monero Project.
 | 
			
		||||
 | 
			
		||||
#include "NodeModel.h"
 | 
			
		||||
#include <utils/nodes.h>
 | 
			
		||||
#include "utils/nodes.h"
 | 
			
		||||
#include "utils/ColorScheme.h"
 | 
			
		||||
 | 
			
		||||
NodeModel::NodeModel(int nodeSource, QObject *parent)
 | 
			
		||||
        : QAbstractTableModel(parent)
 | 
			
		||||
| 
						 | 
				
			
			@ -69,9 +70,9 @@ QVariant NodeModel::data(const QModelIndex &index, int role) const {
 | 
			
		|||
    }
 | 
			
		||||
    else if(role == Qt::BackgroundRole) {
 | 
			
		||||
        if (node.isConnecting)
 | 
			
		||||
            return QBrush(QColor("#A9DEF9"));
 | 
			
		||||
            return QBrush(ColorScheme::YELLOW.asColor(true));
 | 
			
		||||
        else if (node.isActive)
 | 
			
		||||
            return QBrush(QColor("#78BC61"));
 | 
			
		||||
            return QBrush(ColorScheme::GREEN.asColor(true));
 | 
			
		||||
    }
 | 
			
		||||
    return QVariant();
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -4,6 +4,7 @@
 | 
			
		|||
#include "SubaddressModel.h"
 | 
			
		||||
#include "Subaddress.h"
 | 
			
		||||
#include "ModelUtils.h"
 | 
			
		||||
#include "utils/ColorScheme.h"
 | 
			
		||||
 | 
			
		||||
#include <QPoint>
 | 
			
		||||
#include <QColor>
 | 
			
		||||
| 
						 | 
				
			
			@ -56,8 +57,13 @@ QVariant SubaddressModel::data(const QModelIndex &index, int role) const
 | 
			
		|||
            result = parseSubaddressRow(subaddress, index, role);
 | 
			
		||||
        }
 | 
			
		||||
        else if (role == Qt::BackgroundRole) {
 | 
			
		||||
            if (subaddress.isUsed()) {
 | 
			
		||||
                result = QBrush(QColor(255,100,100));
 | 
			
		||||
            switch(index.column()) {
 | 
			
		||||
                case Address:
 | 
			
		||||
                {
 | 
			
		||||
                    if (subaddress.isUsed()) {
 | 
			
		||||
                        result = QBrush(ColorScheme::RED.asColor(true));
 | 
			
		||||
                    }
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        else if (role == Qt::FontRole) {
 | 
			
		||||
| 
						 | 
				
			
			@ -68,6 +74,16 @@ QVariant SubaddressModel::data(const QModelIndex &index, int role) const
 | 
			
		|||
                }
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        else if (role == Qt::ToolTipRole) {
 | 
			
		||||
            switch(index.column()) {
 | 
			
		||||
                case Address:
 | 
			
		||||
                {
 | 
			
		||||
                    if (subaddress.isUsed()) {
 | 
			
		||||
                        result = "This address is used.";
 | 
			
		||||
                    }
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    if (!found)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -5,6 +5,7 @@
 | 
			
		|||
#include "TransactionHistory.h"
 | 
			
		||||
#include "TransactionInfo.h"
 | 
			
		||||
#include "globals.h"
 | 
			
		||||
#include "utils/ColorScheme.h"
 | 
			
		||||
 | 
			
		||||
TransactionHistoryModel::TransactionHistoryModel(QObject *parent)
 | 
			
		||||
    : QAbstractTableModel(parent),
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -4,6 +4,7 @@
 | 
			
		|||
#include "XmrToModel.h"
 | 
			
		||||
#include "model/ModelUtils.h"
 | 
			
		||||
#include "utils/xmrto.h"
 | 
			
		||||
#include "utils/ColorScheme.h"
 | 
			
		||||
 | 
			
		||||
XmrToModel::XmrToModel(QList<XmrToOrder*> *orders, QObject *parent)
 | 
			
		||||
        : QAbstractTableModel(parent),
 | 
			
		||||
| 
						 | 
				
			
			@ -61,15 +62,15 @@ QVariant XmrToModel::data(const QModelIndex &index, int role) const {
 | 
			
		|||
    else if(role == Qt::BackgroundRole) {
 | 
			
		||||
        if (_col == 0) {
 | 
			
		||||
            if (order->state == OrderState::Status_OrderPaid || order->state == OrderState::Status_OrderPaidUnconfirmed)
 | 
			
		||||
                return QBrush(Qt::darkGreen);
 | 
			
		||||
                return QBrush(ColorScheme::GREEN.asColor(true));
 | 
			
		||||
            else if (order->state == OrderState::Status_OrderCreating || order->state == OrderState::Status_OrderToBeCreated)
 | 
			
		||||
                return QBrush(Qt::yellow);
 | 
			
		||||
                return QBrush(ColorScheme::YELLOW.asColor(true));
 | 
			
		||||
            else if (order->state == OrderState::Status_OrderUnpaid)
 | 
			
		||||
                return QBrush(Qt::cyan);
 | 
			
		||||
                return QBrush(ColorScheme::YELLOW.asColor(true));
 | 
			
		||||
            else if (order->state == OrderState::Status_OrderBTCSent)
 | 
			
		||||
                return QBrush(Qt::green);
 | 
			
		||||
                return QBrush(ColorScheme::GREEN.asColor(true));
 | 
			
		||||
            else if (order->state == OrderState::Status_OrderFailed || order->state == OrderState::Status_OrderTimedOut)
 | 
			
		||||
                return QBrush(QColor(191, 255, 0)); // lime
 | 
			
		||||
                return QBrush(ColorScheme::RED.asColor(true));
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    else if (role == Qt::FontRole) {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										39
									
								
								src/utils/ColorScheme.cpp
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										39
									
								
								src/utils/ColorScheme.cpp
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,39 @@
 | 
			
		|||
// SPDX-License-Identifier: BSD-3-Clause
 | 
			
		||||
// Copyright (c) 2020-2021, The Monero Project.
 | 
			
		||||
// Copyright (c) 2012 thomasv@gitorious
 | 
			
		||||
 | 
			
		||||
#include "ColorScheme.h"
 | 
			
		||||
 | 
			
		||||
bool ColorScheme::darkScheme = false;
 | 
			
		||||
ColorSchemeItem ColorScheme::GREEN   = ColorSchemeItem("#117c11", "#8af296");
 | 
			
		||||
ColorSchemeItem ColorScheme::YELLOW  = ColorSchemeItem("#897b2a", "#ffff00");
 | 
			
		||||
ColorSchemeItem ColorScheme::RED     = ColorSchemeItem("#7c1111", "#f18c8c");
 | 
			
		||||
ColorSchemeItem ColorScheme::BLUE    = ColorSchemeItem("#123b7c", "#8cb3f2");
 | 
			
		||||
ColorSchemeItem ColorScheme::DEFAULT = ColorSchemeItem("black", "white");
 | 
			
		||||
ColorSchemeItem ColorScheme::GRAY    = ColorSchemeItem("gray", "gray");
 | 
			
		||||
 | 
			
		||||
bool ColorScheme::hasDarkBackground(QWidget *widget) {
 | 
			
		||||
    int r, g, b;
 | 
			
		||||
    widget->palette().color(QPalette::Background).getRgb(&r, &g, &b);
 | 
			
		||||
    auto brightness = r + g + b;
 | 
			
		||||
    return brightness < (255*3/2);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void ColorScheme::updateFromWidget(QWidget *widget, bool forceDark) {
 | 
			
		||||
    darkScheme = forceDark or ColorScheme::hasDarkBackground(widget);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
QString ColorSchemeItem::asStylesheet(bool background) {
 | 
			
		||||
    auto cssPrefix = background ? "background-" : "";
 | 
			
		||||
    auto color = this->getColor(background);
 | 
			
		||||
    return QString("QWidget { %1color : %2; }").arg(cssPrefix, color);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
QColor ColorSchemeItem::asColor(bool background) {
 | 
			
		||||
    auto color = this->getColor(background);
 | 
			
		||||
    return QColor(color);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
QString ColorSchemeItem::getColor(bool background) {
 | 
			
		||||
    return m_colors[(int(background) + int(ColorScheme::darkScheme)) % 2];
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										44
									
								
								src/utils/ColorScheme.h
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										44
									
								
								src/utils/ColorScheme.h
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,44 @@
 | 
			
		|||
// SPDX-License-Identifier: BSD-3-Clause
 | 
			
		||||
// Copyright (c) 2020-2021, The Monero Project.
 | 
			
		||||
// Copyright (c) 2012 thomasv@gitorious
 | 
			
		||||
 | 
			
		||||
#ifndef FEATHER_COLORSCHEME_H
 | 
			
		||||
#define FEATHER_COLORSCHEME_H
 | 
			
		||||
 | 
			
		||||
#include <QString>
 | 
			
		||||
#include <QVector>
 | 
			
		||||
#include <QColor>
 | 
			
		||||
#include <QWidget>
 | 
			
		||||
 | 
			
		||||
class ColorSchemeItem {
 | 
			
		||||
 | 
			
		||||
public:
 | 
			
		||||
    explicit ColorSchemeItem(const QString &fgColor, const QString &bgColor)
 | 
			
		||||
            : m_colors({fgColor, bgColor}) {}
 | 
			
		||||
 | 
			
		||||
    QString asStylesheet(bool background = false);
 | 
			
		||||
    QColor asColor(bool background = false);
 | 
			
		||||
 | 
			
		||||
private:
 | 
			
		||||
    QString getColor(bool background);
 | 
			
		||||
    QVector<QString> m_colors;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class ColorScheme {
 | 
			
		||||
public:
 | 
			
		||||
    static bool darkScheme;
 | 
			
		||||
 | 
			
		||||
    static ColorSchemeItem GREEN;
 | 
			
		||||
    static ColorSchemeItem YELLOW;
 | 
			
		||||
    static ColorSchemeItem RED;
 | 
			
		||||
    static ColorSchemeItem BLUE;
 | 
			
		||||
    static ColorSchemeItem DEFAULT;
 | 
			
		||||
    static ColorSchemeItem GRAY;
 | 
			
		||||
 | 
			
		||||
    static bool hasDarkBackground(QWidget *widget);
 | 
			
		||||
    static void updateFromWidget(QWidget *widget, bool forceDark = false);
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
#endif //FEATHER_COLORSCHEME_H
 | 
			
		||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue