-
-
Notifications
You must be signed in to change notification settings - Fork 4k
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
Optimise status colours and icons. Closes #6174. #6186
Closed
Closed
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
adee0ee
Follow project coding style. Issue #2192.
magao 1b9a368
Invert status icons [PR#6186]
LordNyriox 5dbe301
Torrent list and transfer filter icons follow status colour.
magao 2c9153d
Detect themes change and update status icons.
magao 85312f3
Preference option to display large status icons.
magao 058ecc1
Change paused and stalled colours. Closes #6174.
magao beb94e9
Move status icons to own directory.
magao 4a571de
Torrent state text always neutral (black or grey).
magao File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
/* | ||
* Bittorrent Client using Qt and libtorrent. | ||
* Copyright (C) 2017 Tim Delaney <[email protected]> | ||
* Copyright (C) 2015 Vladimir Golovnev <[email protected]> | ||
* Copyright (C) 2011 Christophe Dumez <[email protected]> | ||
* | ||
|
@@ -27,23 +28,37 @@ | |
* exception statement from your version. | ||
*/ | ||
|
||
#include "guiiconprovider.h" | ||
#include "base/bittorrent/torrenthandle.h" | ||
#include "base/preferences.h" | ||
#include "guiiconprovider.h" | ||
#include "torrentmodel.h" | ||
|
||
#include <QApplication> | ||
#include <QBitmap> | ||
#include <QDebug> | ||
#include <QHash> | ||
#include <QIcon> | ||
#include <QPair> | ||
#include <QPalette> | ||
#include <QPixmap> | ||
|
||
#if (defined(Q_OS_UNIX) && !defined(Q_OS_MAC)) | ||
#include <QDir> | ||
#include <QFile> | ||
#endif | ||
|
||
GuiIconProvider::GuiIconProvider(QObject *parent) | ||
: IconProvider(parent) | ||
, m_iconCache(new QHash<QPair<QString, BitTorrent::TorrentState>, QIcon>) | ||
{ | ||
configure(); | ||
configure(true); | ||
connect(Preferences::instance(), SIGNAL(changed()), SLOT(configure())); | ||
} | ||
|
||
GuiIconProvider::~GuiIconProvider() {} | ||
GuiIconProvider::~GuiIconProvider() | ||
{ | ||
delete m_iconCache; | ||
} | ||
|
||
void GuiIconProvider::initInstance() | ||
{ | ||
|
@@ -64,7 +79,7 @@ QIcon GuiIconProvider::getIcon(const QString &iconId) | |
QIcon GuiIconProvider::getIcon(const QString &iconId, const QString &fallback) | ||
{ | ||
#if (defined(Q_OS_UNIX) && !defined(Q_OS_MAC)) | ||
if (m_useSystemTheme) { | ||
if (m_themeFlags & SystemTheme) { | ||
QIcon icon = QIcon::fromTheme(iconId); | ||
if (icon.name() != iconId) | ||
icon = QIcon::fromTheme(fallback, QIcon(IconProvider::getIconPath(iconId))); | ||
|
@@ -117,12 +132,13 @@ QIcon GuiIconProvider::generateDifferentSizes(const QIcon &icon) | |
|
||
return newIcon; | ||
} | ||
|
||
#endif | ||
|
||
QString GuiIconProvider::getIconPath(const QString &iconId) | ||
{ | ||
#if (defined(Q_OS_UNIX) && !defined(Q_OS_MAC)) | ||
if (m_useSystemTheme) { | ||
if (m_themeFlags & SystemTheme) { | ||
QString path = QDir::temp().absoluteFilePath(iconId + ".png"); | ||
if (!QFile::exists(path)) { | ||
const QIcon icon = QIcon::fromTheme(iconId); | ||
|
@@ -138,10 +154,90 @@ QString GuiIconProvider::getIconPath(const QString &iconId) | |
return IconProvider::getIconPath(iconId); | ||
} | ||
|
||
void GuiIconProvider::updateTheme() | ||
{ | ||
configure(); | ||
} | ||
|
||
void GuiIconProvider::configure() | ||
void GuiIconProvider::configure(bool firstRun) | ||
{ | ||
ThemeFlags themeFlags = 0; | ||
|
||
#if (defined(Q_OS_UNIX) && !defined(Q_OS_MAC)) | ||
m_useSystemTheme = Preferences::instance()->useSystemIconTheme(); | ||
if (Preferences::instance()->useSystemIconTheme()) | ||
themeFlags |= SystemTheme; | ||
#endif | ||
|
||
// QPalette::Base is used for the background of widgets like list and tree views | ||
QPalette pal = QApplication::palette(); | ||
QColor color = pal.color(QPalette::Active, QPalette::Base); | ||
bool darkTheme = (color.lightness() < 127); | ||
|
||
if (darkTheme) | ||
themeFlags |= DarkTheme; | ||
|
||
const Preferences *const pref = Preferences::instance(); | ||
|
||
if (pref->useLargeStatusIcons()) | ||
themeFlags |= LargeStatusIcons; | ||
|
||
if (firstRun || (themeFlags != m_themeFlags)) { | ||
qDebug().nospace() << "Changing status icon theme to " << ((themeFlags & DarkTheme) ? "dark" : "light") | ||
<< ", " << ((themeFlags & LargeStatusIcons) ? "large" : "small") << " icons"; | ||
m_iconCache->clear(); | ||
m_themeFlags = themeFlags; | ||
emit themeChanged(); | ||
} | ||
} | ||
|
||
GuiIconProvider::ThemeFlags GuiIconProvider::getThemeFlags() | ||
{ | ||
return m_themeFlags; | ||
} | ||
|
||
QIcon GuiIconProvider::getStatusIcon(const QString &iconId) | ||
{ | ||
return getStatusIcon(iconId, BitTorrent::TorrentState::Unknown, true); | ||
} | ||
|
||
QIcon GuiIconProvider::getStatusIcon(const QString &iconId, const BitTorrent::TorrentState &state) | ||
{ | ||
return getStatusIcon(iconId, state, false); | ||
} | ||
|
||
QIcon GuiIconProvider::getStatusIcon(const QString &iconId, const BitTorrent::TorrentState &state, bool ignoreState) | ||
{ | ||
QString path(":/icons/status/" + iconId + ".png"); | ||
QPair<QString, BitTorrent::TorrentState> key(path, state); | ||
QIcon icon((*m_iconCache)[key]); | ||
|
||
if (!icon.isNull()) | ||
return icon; | ||
|
||
QPixmap pixmap(path); | ||
|
||
if (!ignoreState) { | ||
QPixmap colored(pixmap.size()); | ||
colored.fill(TorrentModel::getIconColorByState(state)); | ||
colored.setMask(pixmap.createMaskFromColor(Qt::transparent)); | ||
pixmap = colored; | ||
} | ||
|
||
if (m_themeFlags & LargeStatusIcons) { | ||
// The icon files have a fair amount of whitespace that we can crop off | ||
int wInset = pixmap.width() / 8; | ||
int hInset = pixmap.height() / 8; | ||
QRect rect(wInset, hInset, pixmap.width() - (wInset * 2), pixmap.height() - (hInset * 2)); | ||
qDebug() << "Resizing icon" << pixmap.rect() << "->" << rect; | ||
pixmap = pixmap.copy(rect); | ||
} | ||
|
||
#if (defined(Q_OS_UNIX) && !defined(Q_OS_MAC)) | ||
icon = generateDifferentSizes(QIcon(pixmap)); | ||
#else | ||
icon = QIcon(pixmap); | ||
#endif | ||
|
||
(*m_iconCache)[key] = icon; | ||
return icon; | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
= default
too?