From 1c2dc79f51d407477de062c8f637ba7f556c99d2 Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Thu, 20 Oct 2022 10:27:03 +0800 Subject: [PATCH] Introduce color palettes for both dark, light themes This commit introduce color palettes from Primer and make use of it in various widgets. Primer system is chosen due to well designed and is highly rated on Github (in terms of Github stars). https://primer.style/ PR #17798. --- src/gui/CMakeLists.txt | 1 + src/gui/color.h | 72 +++++++++++++++++++++++++++++++++++ src/gui/gui.pri | 1 + src/gui/log/logmodel.cpp | 50 +++++++++++++++++++++--- src/gui/transferlistmodel.cpp | 27 +++++++------ 5 files changed, 134 insertions(+), 17 deletions(-) create mode 100644 src/gui/color.h diff --git a/src/gui/CMakeLists.txt b/src/gui/CMakeLists.txt index 9f2798636..eae9acf98 100644 --- a/src/gui/CMakeLists.txt +++ b/src/gui/CMakeLists.txt @@ -50,6 +50,7 @@ add_library(qbt_gui STATIC categoryfiltermodel.h categoryfilterproxymodel.h categoryfilterwidget.h + color.h cookiesdialog.h cookiesmodel.h deletionconfirmationdialog.h diff --git a/src/gui/color.h b/src/gui/color.h new file mode 100644 index 000000000..906ada454 --- /dev/null +++ b/src/gui/color.h @@ -0,0 +1,72 @@ +/* + * Bittorrent Client using Qt and libtorrent. + * Copyright (C) 2022 Mike Tzou (Chocobo1) + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * In addition, as a special exception, the copyright holders give permission to + * link this program with the OpenSSL project's "OpenSSL" library (or with + * modified versions of it that use the same license as the "OpenSSL" library), + * and distribute the linked executables. You must obey the GNU General Public + * License in all respects for all of the code used other than "OpenSSL". If you + * modify file(s), you may extend this exception to your version of the file(s), + * but you are not obligated to do so. If you do not wish to do so, delete this + * exception statement from your version. + */ + +#pragma once + +namespace Color +{ + /* + * Documentation: https://primer.style/primitives/colors + * Repository: https://github.com/primer/primitives + * Primer Primitives v7.9 + */ + namespace Primer + { + namespace Dark + { + // Functional variables + inline const QColor accentEmphasis = 0x1f6feb; + inline const QColor accentFg = 0x58a6ff; + inline const QColor dangerFg = 0xf85149; + inline const QColor fgMuted = 0x8b949e; + inline const QColor fgSubtle = 0x6e7681; + inline const QColor severeFg = 0xdb6d28; + inline const QColor successEmphasis = 0x238636; + inline const QColor successFg = 0x1a7f37; + // Scale variables + inline const QColor scaleBlue4 = 0x388bfd; + inline const QColor scaleYellow6 = 0x845306; + } + + namespace Light + { + // Functional variables + inline const QColor accentEmphasis = 0x0969da; + inline const QColor accentFg = 0x0969da; + inline const QColor dangerFg = 0xcf222e; + inline const QColor fgMuted = 0x57606a; + inline const QColor fgSubtle = 0x6e7781; + inline const QColor severeFg = 0xbc4c00; + inline const QColor successEmphasis = 0x2da44e; + inline const QColor successFg = 0x1a7f37; + // Scale variables + inline const QColor scaleBlue4 = 0x218bff; + inline const QColor scaleYellow6 = 0x7d4e00; + } + } +} diff --git a/src/gui/gui.pri b/src/gui/gui.pri index 3a636c878..85bde0b9e 100644 --- a/src/gui/gui.pri +++ b/src/gui/gui.pri @@ -9,6 +9,7 @@ HEADERS += \ $$PWD/categoryfiltermodel.h \ $$PWD/categoryfilterproxymodel.h \ $$PWD/categoryfilterwidget.h \ + $$PWD/color.h \ $$PWD/cookiesdialog.h \ $$PWD/cookiesmodel.h \ $$PWD/deletionconfirmationdialog.h \ diff --git a/src/gui/log/logmodel.cpp b/src/gui/log/logmodel.cpp index 363314583..5c205b351 100644 --- a/src/gui/log/logmodel.cpp +++ b/src/gui/log/logmodel.cpp @@ -35,11 +35,49 @@ #include #include "base/global.h" +#include "gui/color.h" #include "gui/uithememanager.h" +#include "gui/utils.h" namespace { const int MAX_VISIBLE_MESSAGES = 20000; + + QColor getTimestampColor() + { + return UIThemeManager::instance()->getColor(u"Log.TimeStamp"_qs + , (Utils::Gui::isDarkTheme() ? Color::Primer::Dark::fgSubtle : Color::Primer::Light::fgSubtle)); + } + + QColor getLogNormalColor() + { + return UIThemeManager::instance()->getColor(u"Log.Normal"_qs + , QApplication::palette().color(QPalette::Active, QPalette::WindowText)); + } + + QColor getLogInfoColor() + { + return UIThemeManager::instance()->getColor(u"Log.Info"_qs + , (Utils::Gui::isDarkTheme() ? Color::Primer::Dark::accentFg : Color::Primer::Light::accentFg)); + } + + QColor getLogWarningColor() + { + return UIThemeManager::instance()->getColor(u"Log.Warning"_qs + , (Utils::Gui::isDarkTheme() ? Color::Primer::Dark::severeFg : Color::Primer::Light::severeFg)); + } + + QColor getLogCriticalColor() + { + return UIThemeManager::instance()->getColor(u"Log.Critical"_qs + , (Utils::Gui::isDarkTheme() ? Color::Primer::Dark::dangerFg : Color::Primer::Light::dangerFg)); + } + + QColor getPeerBannedColor() + { + return UIThemeManager::instance()->getColor(u"Log.BannedPeer"_qs + , (Utils::Gui::isDarkTheme() ? Color::Primer::Dark::dangerFg : Color::Primer::Light::dangerFg)); + } } BaseLogModel::Message::Message(const QString &time, const QString &message, const QColor &foreground, const Log::MsgType type) @@ -73,7 +111,7 @@ QVariant BaseLogModel::Message::type() const BaseLogModel::BaseLogModel(QObject *parent) : QAbstractListModel(parent) , m_messages(MAX_VISIBLE_MESSAGES) - , m_timeForeground(UIThemeManager::instance()->getColor(u"Log.TimeStamp"_qs, Qt::darkGray)) + , m_timeForeground(getTimestampColor()) { } @@ -142,10 +180,10 @@ LogMessageModel::LogMessageModel(QObject *parent) : BaseLogModel(parent) , m_foregroundForMessageTypes { - {Log::NORMAL, UIThemeManager::instance()->getColor(u"Log.Normal"_qs, QApplication::palette().color(QPalette::WindowText))}, - {Log::INFO, UIThemeManager::instance()->getColor(u"Log.Info"_qs, Qt::blue)}, - {Log::WARNING, UIThemeManager::instance()->getColor(u"Log.Warning"_qs, QColor {255, 165, 0})}, // orange - {Log::CRITICAL, UIThemeManager::instance()->getColor(u"Log.Critical"_qs, Qt::red)} + {Log::NORMAL, getLogNormalColor()}, + {Log::INFO, getLogInfoColor()}, + {Log::WARNING, getLogWarningColor()}, + {Log::CRITICAL, getLogCriticalColor()} } { for (const Log::Msg &msg : asConst(Logger::instance()->getMessages())) @@ -164,7 +202,7 @@ void LogMessageModel::handleNewMessage(const Log::Msg &message) LogPeerModel::LogPeerModel(QObject *parent) : BaseLogModel(parent) - , m_bannedPeerForeground(UIThemeManager::instance()->getColor(u"Log.BannedPeer"_qs, Qt::red)) + , m_bannedPeerForeground(getPeerBannedColor()) { for (const Log::Peer &peer : asConst(Logger::instance()->getPeers())) handleNewMessage(peer); diff --git a/src/gui/transferlistmodel.cpp b/src/gui/transferlistmodel.cpp index e03d4f7a8..a1a372e30 100644 --- a/src/gui/transferlistmodel.cpp +++ b/src/gui/transferlistmodel.cpp @@ -32,7 +32,6 @@ #include #include #include -#include #include "base/bittorrent/infohash.h" #include "base/bittorrent/session.h" @@ -44,46 +43,52 @@ #include "base/utils/fs.h" #include "base/utils/misc.h" #include "base/utils/string.h" +#include "color.h" #include "uithememanager.h" +#include "utils.h" namespace { QColor getDefaultColorByState(const BitTorrent::TorrentState state) { + const bool isDarkTheme = Utils::Gui::isDarkTheme(); + switch (state) { case BitTorrent::TorrentState::Downloading: case BitTorrent::TorrentState::ForcedDownloading: case BitTorrent::TorrentState::DownloadingMetadata: case BitTorrent::TorrentState::ForcedDownloadingMetadata: - return QColorConstants::Svg::green; + return (isDarkTheme ? Color::Primer::Dark::successFg : Color::Primer::Light::successFg); case BitTorrent::TorrentState::StalledDownloading: - return QColorConstants::Svg::mediumseagreen; + return (isDarkTheme ? Color::Primer::Dark::successEmphasis : Color::Primer::Light::successEmphasis); case BitTorrent::TorrentState::StalledUploading: - return QColorConstants::Svg::cornflowerblue; + return (isDarkTheme ? Color::Primer::Dark::accentEmphasis : Color::Primer::Light::accentEmphasis); case BitTorrent::TorrentState::Uploading: case BitTorrent::TorrentState::ForcedUploading: - return QColorConstants::Svg::royalblue; + return (isDarkTheme ? Color::Primer::Dark::accentFg : Color::Primer::Light::accentFg); case BitTorrent::TorrentState::PausedDownloading: - return QColorConstants::Svg::grey; + return (isDarkTheme ? Color::Primer::Dark::fgMuted : Color::Primer::Light::fgMuted); case BitTorrent::TorrentState::PausedUploading: - return QColorConstants::Svg::darkslateblue; + return (isDarkTheme ? Color::Primer::Dark::scaleBlue4 : Color::Primer::Light::scaleBlue4); case BitTorrent::TorrentState::QueuedDownloading: case BitTorrent::TorrentState::QueuedUploading: - return QColorConstants::Svg::peru; + return (isDarkTheme ? Color::Primer::Dark::scaleYellow6 : Color::Primer::Light::scaleYellow6); case BitTorrent::TorrentState::CheckingDownloading: case BitTorrent::TorrentState::CheckingUploading: case BitTorrent::TorrentState::CheckingResumeData: case BitTorrent::TorrentState::Moving: - return QColorConstants::Svg::teal; + return (isDarkTheme ? Color::Primer::Dark::successFg : Color::Primer::Light::successFg); case BitTorrent::TorrentState::Error: case BitTorrent::TorrentState::MissingFiles: case BitTorrent::TorrentState::Unknown: - return QColorConstants::Svg::red; + return (isDarkTheme ? Color::Primer::Dark::dangerFg : Color::Primer::Light::dangerFg); default: Q_ASSERT(false); - return QColorConstants::Svg::red; + break; } + + return {}; } QHash torrentStateColorsFromUITheme()