Browse Source

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.
adaptive-webui-19844
Chocobo1 2 years ago committed by GitHub
parent
commit
1c2dc79f51
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      src/gui/CMakeLists.txt
  2. 72
      src/gui/color.h
  3. 1
      src/gui/gui.pri
  4. 50
      src/gui/log/logmodel.cpp
  5. 27
      src/gui/transferlistmodel.cpp

1
src/gui/CMakeLists.txt

@ -50,6 +50,7 @@ add_library(qbt_gui STATIC
categoryfiltermodel.h categoryfiltermodel.h
categoryfilterproxymodel.h categoryfilterproxymodel.h
categoryfilterwidget.h categoryfilterwidget.h
color.h
cookiesdialog.h cookiesdialog.h
cookiesmodel.h cookiesmodel.h
deletionconfirmationdialog.h deletionconfirmationdialog.h

72
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;
}
}
}

1
src/gui/gui.pri

@ -9,6 +9,7 @@ HEADERS += \
$$PWD/categoryfiltermodel.h \ $$PWD/categoryfiltermodel.h \
$$PWD/categoryfilterproxymodel.h \ $$PWD/categoryfilterproxymodel.h \
$$PWD/categoryfilterwidget.h \ $$PWD/categoryfilterwidget.h \
$$PWD/color.h \
$$PWD/cookiesdialog.h \ $$PWD/cookiesdialog.h \
$$PWD/cookiesmodel.h \ $$PWD/cookiesmodel.h \
$$PWD/deletionconfirmationdialog.h \ $$PWD/deletionconfirmationdialog.h \

50
src/gui/log/logmodel.cpp

@ -35,11 +35,49 @@
#include <QPalette> #include <QPalette>
#include "base/global.h" #include "base/global.h"
#include "gui/color.h"
#include "gui/uithememanager.h" #include "gui/uithememanager.h"
#include "gui/utils.h"
namespace namespace
{ {
const int MAX_VISIBLE_MESSAGES = 20000; 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) 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) BaseLogModel::BaseLogModel(QObject *parent)
: QAbstractListModel(parent) : QAbstractListModel(parent)
, m_messages(MAX_VISIBLE_MESSAGES) , 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) : BaseLogModel(parent)
, m_foregroundForMessageTypes , m_foregroundForMessageTypes
{ {
{Log::NORMAL, UIThemeManager::instance()->getColor(u"Log.Normal"_qs, QApplication::palette().color(QPalette::WindowText))}, {Log::NORMAL, getLogNormalColor()},
{Log::INFO, UIThemeManager::instance()->getColor(u"Log.Info"_qs, Qt::blue)}, {Log::INFO, getLogInfoColor()},
{Log::WARNING, UIThemeManager::instance()->getColor(u"Log.Warning"_qs, QColor {255, 165, 0})}, // orange {Log::WARNING, getLogWarningColor()},
{Log::CRITICAL, UIThemeManager::instance()->getColor(u"Log.Critical"_qs, Qt::red)} {Log::CRITICAL, getLogCriticalColor()}
} }
{ {
for (const Log::Msg &msg : asConst(Logger::instance()->getMessages())) for (const Log::Msg &msg : asConst(Logger::instance()->getMessages()))
@ -164,7 +202,7 @@ void LogMessageModel::handleNewMessage(const Log::Msg &message)
LogPeerModel::LogPeerModel(QObject *parent) LogPeerModel::LogPeerModel(QObject *parent)
: BaseLogModel(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())) for (const Log::Peer &peer : asConst(Logger::instance()->getPeers()))
handleNewMessage(peer); handleNewMessage(peer);

27
src/gui/transferlistmodel.cpp

@ -32,7 +32,6 @@
#include <QApplication> #include <QApplication>
#include <QDateTime> #include <QDateTime>
#include <QDebug> #include <QDebug>
#include <QPalette>
#include "base/bittorrent/infohash.h" #include "base/bittorrent/infohash.h"
#include "base/bittorrent/session.h" #include "base/bittorrent/session.h"
@ -44,46 +43,52 @@
#include "base/utils/fs.h" #include "base/utils/fs.h"
#include "base/utils/misc.h" #include "base/utils/misc.h"
#include "base/utils/string.h" #include "base/utils/string.h"
#include "color.h"
#include "uithememanager.h" #include "uithememanager.h"
#include "utils.h"
namespace namespace
{ {
QColor getDefaultColorByState(const BitTorrent::TorrentState state) QColor getDefaultColorByState(const BitTorrent::TorrentState state)
{ {
const bool isDarkTheme = Utils::Gui::isDarkTheme();
switch (state) switch (state)
{ {
case BitTorrent::TorrentState::Downloading: case BitTorrent::TorrentState::Downloading:
case BitTorrent::TorrentState::ForcedDownloading: case BitTorrent::TorrentState::ForcedDownloading:
case BitTorrent::TorrentState::DownloadingMetadata: case BitTorrent::TorrentState::DownloadingMetadata:
case BitTorrent::TorrentState::ForcedDownloadingMetadata: case BitTorrent::TorrentState::ForcedDownloadingMetadata:
return QColorConstants::Svg::green; return (isDarkTheme ? Color::Primer::Dark::successFg : Color::Primer::Light::successFg);
case BitTorrent::TorrentState::StalledDownloading: case BitTorrent::TorrentState::StalledDownloading:
return QColorConstants::Svg::mediumseagreen; return (isDarkTheme ? Color::Primer::Dark::successEmphasis : Color::Primer::Light::successEmphasis);
case BitTorrent::TorrentState::StalledUploading: 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::Uploading:
case BitTorrent::TorrentState::ForcedUploading: case BitTorrent::TorrentState::ForcedUploading:
return QColorConstants::Svg::royalblue; return (isDarkTheme ? Color::Primer::Dark::accentFg : Color::Primer::Light::accentFg);
case BitTorrent::TorrentState::PausedDownloading: case BitTorrent::TorrentState::PausedDownloading:
return QColorConstants::Svg::grey; return (isDarkTheme ? Color::Primer::Dark::fgMuted : Color::Primer::Light::fgMuted);
case BitTorrent::TorrentState::PausedUploading: 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::QueuedDownloading:
case BitTorrent::TorrentState::QueuedUploading: 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::CheckingDownloading:
case BitTorrent::TorrentState::CheckingUploading: case BitTorrent::TorrentState::CheckingUploading:
case BitTorrent::TorrentState::CheckingResumeData: case BitTorrent::TorrentState::CheckingResumeData:
case BitTorrent::TorrentState::Moving: 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::Error:
case BitTorrent::TorrentState::MissingFiles: case BitTorrent::TorrentState::MissingFiles:
case BitTorrent::TorrentState::Unknown: case BitTorrent::TorrentState::Unknown:
return QColorConstants::Svg::red; return (isDarkTheme ? Color::Primer::Dark::dangerFg : Color::Primer::Light::dangerFg);
default: default:
Q_ASSERT(false); Q_ASSERT(false);
return QColorConstants::Svg::red; break;
} }
return {};
} }
QHash<BitTorrent::TorrentState, QColor> torrentStateColorsFromUITheme() QHash<BitTorrent::TorrentState, QColor> torrentStateColorsFromUITheme()

Loading…
Cancel
Save