Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Colour and font themes part 2 #9283

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/app/application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@
#endif // Q_OS_MAC
#include "addnewtorrentdialog.h"
#include "gui/guiiconprovider.h"
#include "gui/theme/colorproviders.h"
#include "gui/theme/fontproviders.h"
#include "gui/theme/themeprovider.h"
#include "mainwindow.h"
#include "shutdownconfirmdialog.h"
#else // DISABLE_GUI
Expand Down Expand Up @@ -488,9 +491,14 @@ int Application::exec(const QStringList &params)
{
Net::ProxyConfigurationManager::initInstance();
Net::DownloadManager::initInstance();

#ifdef DISABLE_GUI
IconProvider::initInstance();
#else
Theme::Serialization::registerColorProviders();
Theme::Serialization::registerFontProviders();
Theme::ThemeProvider::initInstance();

GuiIconProvider::initInstance();
#endif

Expand Down
2 changes: 1 addition & 1 deletion src/base/logger.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const int MAX_LOG_MESSAGES = 20000;

namespace Log
{
enum MsgType
enum MsgType: int
{
ALL = -1,
NORMAL = 0x1,
Expand Down
72 changes: 47 additions & 25 deletions src/base/preferences.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include "preferences.h"

#include <QCryptographicHash>
#include <QDebug>
#include <QDir>
#include <QLocale>
#include <QMutableListIterator>
Expand Down Expand Up @@ -89,17 +90,40 @@ void Preferences::setValue(const QString &key, const QVariant &value)
SettingsStorage::instance()->storeValue(key, value);
}

// General options
// Appearance/Language options
QString Preferences::getLocale() const
{
return value("Preferences/General/Locale", QLocale::system().name()).toString();
return value("Appearance/Locale", QLocale::system().name()).toString();
}

void Preferences::setLocale(const QString &locale)
{
setValue("Preferences/General/Locale", locale);
setValue("Appearance/Locale", locale);
}

#if (defined(Q_OS_UNIX) && !defined(Q_OS_MAC))
bool Preferences::useSystemIconTheme() const
{
return value("Appearance/useSystemIconTheme", true).toBool();
}

void Preferences::setSystemIconTheme(bool enabled)
{
setValue("Appearance/useSystemIconTheme", enabled);
}
#endif

bool Preferences::useAlternatingRowColors() const
{
return value("Appearance/AlternatingRowColors", true).toBool();
}

void Preferences::setAlternatingRowColors(bool b)
{
setValue("Appearance/AlternatingRowColors", b);
}

// General options
bool Preferences::deleteTorrentFilesAsDefault() const
{
return value("Preferences/General/DeleteTorrentsFilesAsDefault", false).toBool();
Expand Down Expand Up @@ -130,16 +154,6 @@ void Preferences::showSpeedInTitleBar(bool show)
setValue("Preferences/General/SpeedInTitleBar", show);
}

bool Preferences::useAlternatingRowColors() const
{
return value("Preferences/General/AlternatingRowColors", true).toBool();
}

void Preferences::setAlternatingRowColors(bool b)
{
setValue("Preferences/General/AlternatingRowColors", b);
}

bool Preferences::getHideZeroValues() const
{
return value("Preferences/General/HideZeroValues", false).toBool();
Expand Down Expand Up @@ -825,18 +839,6 @@ void Preferences::resolvePeerHostNames(bool resolve)
setValue("Preferences/Connection/ResolvePeerHostNames", resolve);
}

#if (defined(Q_OS_UNIX) && !defined(Q_OS_MAC))
bool Preferences::useSystemIconTheme() const
{
return value("Preferences/Advanced/useSystemIconTheme", true).toBool();
}

void Preferences::useSystemIconTheme(bool enabled)
{
setValue("Preferences/Advanced/useSystemIconTheme", enabled);
}
#endif

bool Preferences::recursiveDownloadDisabled() const
{
return value("Preferences/Advanced/DisableRecursiveDownload", false).toBool();
Expand Down Expand Up @@ -1552,6 +1554,26 @@ void Preferences::setSpeedWidgetGraphEnable(int id, const bool enable)

void Preferences::upgrade()
{
// Migrate single-value prefs to new section/name
QList<QPair<QString, QString>> prefsToMigrate = {
{ "Preferences/General/Locale", "Appearance/Locale" },
{ "Preferences/General/AlternatingRowColors", "Appearance/AlternatingRowColors" },
{ "Preferences/Advanced/useSystemIconTheme", "Appearance/useSystemIconTheme" },
};

for (auto iter = prefsToMigrate.begin(); iter != prefsToMigrate.end(); ++iter) {
QString pre(iter->first);
QString post(iter->second);

QVariant preValue = value(pre);

if (!preValue.isNull()) {
qDebug() << "Migrating preference" << pre << "->" << post;
setValue(post, preValue);
SettingsStorage::instance()->removeValue(pre);
}
}

QStringList labels = value("TransferListFilters/customLabels").toStringList();
if (!labels.isEmpty()) {
QVariantMap categories = value("BitTorrent/Session/Categories").toMap();
Expand Down
16 changes: 9 additions & 7 deletions src/base/preferences.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,17 +100,23 @@ class Preferences : public QObject
static void freeInstance();
static Preferences *instance();

// General options
// Appearance options
QString getLocale() const;
void setLocale(const QString &locale);
bool useAlternatingRowColors() const;
void setAlternatingRowColors(bool b);
#if (defined(Q_OS_UNIX) && !defined(Q_OS_MAC))
bool useSystemIconTheme() const;
void setSystemIconTheme(bool enabled);
#endif

// General options
bool deleteTorrentFilesAsDefault() const;
void setDeleteTorrentFilesAsDefault(bool del);
bool confirmOnExit() const;
void setConfirmOnExit(bool confirm);
bool speedInTitleBar() const;
void showSpeedInTitleBar(bool show);
bool useAlternatingRowColors() const;
void setAlternatingRowColors(bool b);
bool getHideZeroValues() const;
void setHideZeroValues(bool b);
int getHideZeroComboValues() const;
Expand Down Expand Up @@ -250,10 +256,6 @@ class Preferences : public QObject
void resolvePeerCountries(bool resolve);
bool resolvePeerHostNames() const;
void resolvePeerHostNames(bool resolve);
#if (defined(Q_OS_UNIX) && !defined(Q_OS_MAC))
bool useSystemIconTheme() const;
void useSystemIconTheme(bool enabled);
#endif
bool recursiveDownloadDisabled() const;
void disableRecursiveDownload(bool disable = true);
#ifdef Q_OS_WIN
Expand Down
27 changes: 27 additions & 0 deletions src/gui/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,20 @@ transferlistsortmodel.h
transferlistwidget.h
updownratiodialog.h
utils.h
theme/colorprovider_p.h
theme/colorproviders.h
theme/colortheme.h
theme/colortheme_impl.h
theme/fontprovider_p.h
theme/fontproviders.h
theme/fonttheme.h
theme/fonttheme_impl.h
theme/provider_p.h
theme/serializabletheme.h
theme/themecommon.h
theme/themeexceptions.h
theme/themeinfo.h
theme/themeprovider.h

# sources
addnewtorrentdialog.cpp
Expand Down Expand Up @@ -106,6 +120,18 @@ transferlistsortmodel.cpp
transferlistwidget.cpp
updownratiodialog.cpp
utils.cpp
theme/colorprovider_p.cpp
theme/colorproviders.cpp
theme/colortheme.cpp
theme/fonttheme.cpp
theme/fontprovider_p.cpp
theme/fontproviders.cpp
theme/provider_p.cpp
theme/serializabletheme.cpp
theme/themecommon.cpp
theme/themeexceptions.cpp
theme/themeinfo.cpp
theme/themeprovider.cpp

# forms
aboutdialog.ui
Expand Down Expand Up @@ -135,6 +161,7 @@ target_link_libraries(qbt_gui
qbt_base
QtSingleApplication::QtSingleApplication
)
qbt_target_sources(qBittorrent PRIVATE about.qrc theme/builtinthemes.qrc)

target_include_directories(qbt_gui
PRIVATE ../app
Expand Down
12 changes: 0 additions & 12 deletions src/gui/advancedsettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,6 @@ enum AdvSettingsRows
CONFIRM_REMOVE_ALL_TAGS,
DOWNLOAD_TRACKER_FAVICON,
SAVE_PATH_HISTORY_LENGTH,
#if (defined(Q_OS_UNIX) && !defined(Q_OS_MAC))
USE_ICON_THEME,
#endif

// libtorrent section
LIBTORRENT_HEADER,
Expand Down Expand Up @@ -229,13 +226,8 @@ void AdvancedSettings::saveAdvancedSettings()

#if defined(Q_OS_WIN) || defined(Q_OS_MAC)
pref->setUpdateCheckEnabled(checkBoxUpdateCheck.isChecked());
#endif
// Icon theme
#if (defined(Q_OS_UNIX) && !defined(Q_OS_MAC))
pref->useSystemIconTheme(checkBoxUseIconTheme.isChecked());
#endif
pref->setConfirmTorrentRecheck(checkBoxConfirmTorrentRecheck.isChecked());

pref->setConfirmRemoveAllTags(checkBoxConfirmRemoveAllTags.isChecked());

session->setAnnounceToAllTrackers(checkBoxAnnounceAllTrackers.isChecked());
Expand Down Expand Up @@ -487,10 +479,6 @@ void AdvancedSettings::loadAdvancedSettings()
#if defined(Q_OS_WIN) || defined(Q_OS_MAC)
checkBoxUpdateCheck.setChecked(pref->isUpdateCheckEnabled());
addRow(UPDATE_CHECK, tr("Check for software updates"), &checkBoxUpdateCheck);
#endif
#if (defined(Q_OS_UNIX) && !defined(Q_OS_MAC))
checkBoxUseIconTheme.setChecked(pref->useSystemIconTheme());
addRow(USE_ICON_THEME, tr("Use system icon theme"), &checkBoxUseIconTheme);
#endif
// Torrent recheck confirmation
checkBoxConfirmTorrentRecheck.setChecked(pref->confirmTorrentRecheck());
Expand Down
4 changes: 0 additions & 4 deletions src/gui/advancedsettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,6 @@ private slots:
#if defined(Q_OS_WIN) || defined(Q_OS_MAC)
QCheckBox checkBoxUpdateCheck;
#endif

#if (defined(Q_OS_UNIX) && !defined(Q_OS_MAC))
QCheckBox checkBoxUseIconTheme;
#endif
};

#endif // ADVANCEDSETTINGS_H
47 changes: 24 additions & 23 deletions src/gui/executionlogwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@

#include "guiiconprovider.h"
#include "loglistwidget.h"
#include "theme/colortheme.h"

#include "ui_executionlogwidget.h"

ExecutionLogWidget::ExecutionLogWidget(QWidget *parent, const Log::MsgTypes &types)
Expand Down Expand Up @@ -72,40 +74,39 @@ void ExecutionLogWidget::showMsgTypes(const Log::MsgTypes &types)
m_msgList->showMsgTypes(types);
}

void ExecutionLogWidget::addLogMessage(const Log::Msg &msg)
namespace
{
QString text;
QDateTime time = QDateTime::fromMSecsSinceEpoch(msg.timestamp);
QColor color;

switch (msg.type) {
case Log::INFO:
color.setNamedColor("blue");
break;
case Log::WARNING:
color.setNamedColor("orange");
break;
case Log::CRITICAL:
color.setNamedColor("red");
break;
default:
color = QApplication::palette().color(QPalette::WindowText);
QString coloredString(const QString &str, const QColor &color)
{
return QString(QLatin1String("<font color='%1'>%2</font>"))
.arg(color.name(), str);
}
}

void ExecutionLogWidget::addLogMessage(const Log::Msg &msg)
{
const QDateTime time = QDateTime::fromMSecsSinceEpoch(msg.timestamp);
const QColor messageColor = Theme::ColorTheme::current().logMessageColor(msg.type);
const QColor neutralColor = QPalette().color(QPalette::Inactive, QPalette::WindowText);

text = "<font color='grey'>" + time.toString(Qt::SystemLocaleShortDate) + "</font> - <font color='" + color.name() + "'>" + msg.message + "</font>";
QString text = coloredString(time.toString(Qt::SystemLocaleShortDate), neutralColor)
+ QLatin1String(" - ")
+ coloredString(msg.message, messageColor);
m_msgList->appendLine(text, msg.type);
}

void ExecutionLogWidget::addPeerMessage(const Log::Peer &peer)
{
QString text;
QDateTime time = QDateTime::fromMSecsSinceEpoch(peer.timestamp);
const QDateTime time = QDateTime::fromMSecsSinceEpoch(peer.timestamp);
const QColor IPColor = Theme::ColorTheme::current().logMessageColor(Log::MsgType::CRITICAL);
const QColor neutralColor = QPalette().color(QPalette::Inactive, QPalette::WindowText);

QString text = coloredString(time.toString(Qt::SystemLocaleShortDate), neutralColor)
+ QLatin1String(" - ") + coloredString(peer.ip, IPColor) + QLatin1Char(' ');
if (peer.blocked)
text = "<font color='grey'>" + time.toString(Qt::SystemLocaleShortDate) + "</font> - "
+ tr("<font color='red'>%1</font> was blocked %2", "x.y.z.w was blocked").arg(peer.ip, peer.reason);
text += tr("was blocked %1", "x.y.z.w was blocked").arg(peer.reason);
else
text = "<font color='grey'>" + time.toString(Qt::SystemLocaleShortDate) + "</font> - " + tr("<font color='red'>%1</font> was banned", "x.y.z.w was banned").arg(peer.ip);
text += tr("was banned", "x.y.z.w was banned");

m_peerList->appendLine(text, Log::NORMAL);
}
Loading