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

Map Icons with IDs #10948

Closed
wants to merge 36 commits into from
Closed

Conversation

jagannatharjun
Copy link
Member

@jagannatharjun jagannatharjun commented Jul 19, 2019

  • Map icons in qbt-theme folder
  • Map icons in skins folder
  • Make System Icon theme work

Copy link
Member Author

@jagannatharjun jagannatharjun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

...

src/icons/icons.json Outdated Show resolved Hide resolved
src/icons/icons.qrc Outdated Show resolved Hide resolved
@glassez glassez changed the title [WIP] Map Icons with IDs in gui [WIP] Map Icons with IDs Jul 20, 2019
@glassez glassez self-assigned this Jul 20, 2019
@glassez glassez added the GUI GUI-related issues/changes label Jul 20, 2019
@glassez glassez added this to the 4.2.0 milestone Jul 20, 2019
@jagannatharjun jagannatharjun changed the title [WIP] Map Icons with IDs Map Icons with IDs Jul 25, 2019
@LordNyriox
Copy link
Contributor

LordNyriox commented Jul 25, 2019

@jagannatharjun: Thanks for all your work on this feature. :}

After this PR is finalized and merged, would you be willing to post a template theme (including icons) for qBittorrent?

@jagannatharjun
Copy link
Member Author

@LordNyriox yes

Copy link
Member

@glassez glassez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, congratulations, good job 👍
Now it's time to fine tune it.
We should have such names that they are as obvious as possible, but without excesses in them.
I will review them as soon as I have time and make my suggestions and corrections.

@@ -45,7 +45,7 @@ AboutDialog::AboutDialog(QWidget *parent)
// Title
m_ui->labelName->setText(QString("<b><h2>qBittorrent " QBT_VERSION " (%1-bit)</h2></b>").arg(QT_POINTER_SIZE * 8));

m_ui->logo->setPixmap(Utils::Gui::scaledPixmapSvg(":/icons/skin/qbittorrent-tray.svg", this, 32));
m_ui->logo->setPixmap(Utils::Gui::scaledPixmapSvg("QBittorrent.Logo", this, 32));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would use "AboutDialog.Logo".

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@glassez: It is my understanding that the same icon is used in multiple places (including the system tray).

Do you really want to name the icon based on only one of those components?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@LordNyriox, if you had followed #10903, you might have understood my intentions...
#10903 (comment)

@jagannatharjun
Copy link
Member Author

Should I fall back to the default icon mapping if the icon path can't be resolved with custom iconconfig.json . May be provide an option

I am thinking to replace the current selection method with something like this.
With the current setup, It seems more natural.

@glassez
Copy link
Member

glassez commented Aug 6, 2019

My main suggestions for naming are the following:
ID should contain two main parts.
First part (actually last part of ID) is "common semantic" (e.g. "AddAction" or "Logo").
The second part is "scope" of particular ID, possible multilevel (e.g. "AddTorrentDialog.TorrentContentView").
"Scope" can be omitted in icon mapping (partially or fully) by replacing with "*" character. It allows the theme creator to achieve any desired detail. E.g. someone can set different icons for each particular ID but someone else can create very reduced theme (by having only entries like "*.AddAction", i.e. set the same icon for all similar places).
We should avoid any "internals" in ID parts. I.e. "ContentTree" is not so good, IMO (due to "Tree" in it). It should just point to some widget (or view) that shows content of torrent (regardless of the particular type of this widget), so "TorrentContentView" is better name.
We can avoid too much detail in ID scopes, but only if it is not likely to be needed in the future (because we will not be able to change existing IDs without breaking existing themes).

@glassez
Copy link
Member

glassez commented Aug 7, 2019

Should I fall back to the default icon mapping if the icon path can't be resolved with custom iconconfig.json

What do you mean exactly?

If there is no such ID (or appropriate generic ID that matches it) in theme then you should use built-in icon (and cache it for this ID). This situation can occur when some new qBittorrent version introduces new ID so there is no matches in existing themes. You also should indicate this event in some way (maybe show message box about missing icons or some less annoying way). Or maybe don't fallback and just show some predefined icon placeholder?

If the theme contains some ID but mapped path is invalid then it's real bug in theme and you shouldn't fallback to correct icon.

src/gui/uithememanager.cpp Outdated Show resolved Hide resolved
src/gui/uithememanager.cpp Outdated Show resolved Hide resolved
src/gui/uithememanager.cpp Outdated Show resolved Hide resolved
src/gui/uithememanager.cpp Outdated Show resolved Hide resolved
src/gui/uithememanager.cpp Outdated Show resolved Hide resolved
@@ -140,5 +156,41 @@ QString UIThemeManager::getIconPath(const QString &iconId) const
return path;
}
#endif
return IconProvider::instance()->getIconPath(iconId);

const auto iter = m_iconMap.find(iconId);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems this method has logical errors. I need to get a fresh look at it.

@jagannatharjun
Copy link
Member Author

jagannatharjun commented Aug 27, 2019

image

Here is a theme if anyone wants to try out.
https://github.com/jagannatharjun/qbt-theme/blob/master/material-white/material.qbtheme
@glassez update?

@glassez
Copy link
Member

glassez commented Aug 28, 2019

@glassez update?

I'm sorry, I just can't get around to it for lack of free time. It's on my to-do list, so I'll be back here as soon as I can.

Copy link
Member

@glassez glassez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getIconPath() is still unchecked...

src/gui/uithememanager.cpp Outdated Show resolved Hide resolved
src/gui/uithememanager.cpp Show resolved Hide resolved
src/gui/uithememanager.cpp Outdated Show resolved Hide resolved
src/gui/uithememanager.cpp Outdated Show resolved Hide resolved
src/gui/uithememanager.cpp Outdated Show resolved Hide resolved

m_iconsDir = useCustomUITheme ? ":uitheme/icons/" : ":icons/";

QFile iconJsonMap(m_iconsDir + iconConfigFile);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure that's right... Does it make sense to override mapping for "system theme" icons in a custom theme? Shouldn't there just be a three-state option (default-system-custom)? @Chocobo1?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it make sense to override mapping for "system theme" icons in a custom theme?

I think not.

Shouldn't there just be a three-state option (default-system-custom)?

I agree although I haven't checked how the GUI should look like.

src/gui/uithememanager.cpp Outdated Show resolved Hide resolved
src/gui/aboutdialog.cpp Outdated Show resolved Hide resolved
if (icon.name() != iconId)
icon = QIcon::fromTheme(fallback, QIcon(IconProvider::instance()->getIconPath(iconId)));
icon = QIcon::fromTheme(fallback, QIcon(getIconPath(iconId)));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also how do you suppose to provide fallback icon now? It seems that it should come from (system theme) icon mapping now.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I now have changed the fallback to fallbackSysThemeIcon

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should I add separate icon id for fallback as well? I think there are only like 4 instances where fallback is actually used.

Well, It does make sense to add IconIds for fallbacks as well. Will replace direct references with Icon ids.

src/gui/uithememanager.cpp Outdated Show resolved Hide resolved
@jagannatharjun
Copy link
Member Author

image

ubuntu icon theme - link

src/gui/uithememanager.cpp Outdated Show resolved Hide resolved
src/gui/iconconfig.cpp Outdated Show resolved Hide resolved
src/gui/uithememanager.cpp Outdated Show resolved Hide resolved
src/gui/uithememanager.cpp Outdated Show resolved Hide resolved
@@ -32,6 +32,7 @@

#include "base/unicodestrings.h"
#include "base/utils/misc.h"
#include "gui/uithememanager.h"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't use "gui/" when include in sibling files.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are actually only two such reference one is this one you mention and other is src\gui\rss\articlelistwidget.cpp. should I don't use this prefix even in gui\rss folder?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just follow other include names style in the same file.

{
static const QHash<QString, QString> iconConfig = {
{"AboutDialog.Logo", ":icons/skin/qbittorrent-tray.svg"},
{"AddNewTorrentDialog.TorrentContentView.RenameAction", ":icons/qbt-theme/edit-rename.svg"},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we shouldn't add "Action" suffix? Now it seems superfluous. What do you think?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm yes It does seem superfluous.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should recheck all IDs at last step.

src/gui/uithememanager.cpp Outdated Show resolved Hide resolved
src/gui/uithememanager.cpp Outdated Show resolved Hide resolved
src/gui/uithememanager.cpp Outdated Show resolved Hide resolved
src/gui/uithememanager.cpp Outdated Show resolved Hide resolved
@@ -95,50 +601,74 @@ QIcon UIThemeManager::getIcon(const QString &iconId) const
return getIcon(iconId, iconId);
}

QIcon UIThemeManager::getIcon(const QString &iconId, const QString &fallback) const
QIcon UIThemeManager::getIcon(const QString &iconId, const QString &fallbackSysThemeIcon) const
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method interface is still contradicts the implemented model. As I said before fallback should be a part of mapping. Client just want to call getIcon("SomeIconId"). Which icon is really used is determined by the current configuration.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What shall be the name?
MainMenu.Fallback.ConfigureAction ,
Fallback.MainMenu.ConfigureAction,
MainMenu.ConfigureAction.Fallback,
MainMenu.ConfigureAction2

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What shall be the name?

Sorry, don't understand you.
There is only one name for each IconID. But there should be the way to assign several mappings to it. You can use either "multi map" for system icon config or map each id to list of values.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am thinking to use "multi map".
it should only be limited to the system icon config?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Of course. In case of custom icon theme author should provide truly existed files so no fallback is needed.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since system icon config is internal mapping does it make sense to not do pattern based searching here.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not doing pattern-based searching for system icon map.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, at a first glance.
But I need to look at the whole algorithm to answer exactly.

@@ -98,7 +99,7 @@ void ArticleListWidget::handleArticleRead(RSS::Article *rssArticle)
if (!item) return;

item->setData(Qt::ForegroundRole, QPalette().color(QPalette::Inactive, QPalette::WindowText));
item->setData(Qt::DecorationRole, QIcon(":/icons/sphere.png"));
item->setData(Qt::DecorationRole, UIThemeManager::instance()->getIcon("RSS.ReadArticle"));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would use something like "RSSView" instead of "RSS".

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

May be RSSTab?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tabs is just a way to organise Views/Widgets in container (Main window in this case).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They're actually used in RSS Feed List so may be RSSFeedList, but RSSView seems good to

}
else {
icon = UIThemeManager::instance()->getIcon("inode-directory");
icon = UIThemeManager::instance()->getIcon("RSS");
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where it is actually used? I mean I can't able to understand in which context this icon is actually used thats why such a weird name.

@sledgehammer999 sledgehammer999 modified the milestones: 4.2.0, 4.2.1 Dec 3, 2019
@DoomsDay007 DoomsDay007 mentioned this pull request Dec 4, 2019
@sledgehammer999 sledgehammer999 modified the milestones: 4.2.1, 4.2.2 Dec 19, 2019
@sledgehammer999 sledgehammer999 modified the milestones: 4.2.2, 4.2.3 Mar 24, 2020
@glassez glassez modified the milestones: 4.2.3, 4.2.4 Apr 4, 2020
@sledgehammer999 sledgehammer999 modified the milestones: 4.2.4, 4.2.5, 4.2.6 Apr 22, 2020
@glassez
Copy link
Member

glassez commented Jun 3, 2020

Superseded by #12861.

@glassez glassez closed this Jun 3, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
GUI GUI-related issues/changes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants