Skip to content

Commit 8c56cf9

Browse files
committed
core: add searching custom file paths
1 parent a5431dd commit 8c56cf9

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

src/core/iconimageprovider.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
#include <qsize.h>
1010
#include <qstring.h>
1111

12+
constexpr std::array<QAnyStringView, 2> ICON_FILETYPES = {"png", "xpm"}; // currently cannot open svg file
13+
1214
QPixmap
1315
IconImageProvider::requestPixmap(const QString& id, QSize* size, const QSize& requestedSize) {
1416
QString iconName;
@@ -19,8 +21,7 @@ IconImageProvider::requestPixmap(const QString& id, QSize* size, const QSize& re
1921
if (splitIdx != -1) {
2022
iconName = id.sliced(0, splitIdx);
2123
path = id.sliced(splitIdx + 6);
22-
qWarning() << "Searching custom icon paths is not yet supported. Icon path will be ignored for"
23-
<< id;
24+
path = QString("/%1/%2").arg(path, iconName.sliced(iconName.lastIndexOf('/') + 1));
2425
} else {
2526
splitIdx = id.indexOf("?fallback=");
2627
if (splitIdx != -1) {
@@ -32,7 +33,13 @@ IconImageProvider::requestPixmap(const QString& id, QSize* size, const QSize& re
3233
}
3334

3435
auto icon = QIcon::fromTheme(iconName);
35-
if (icon.isNull()) icon = QIcon::fromTheme(fallbackName);
36+
if (icon.isNull() && !fallbackName.isEmpty()) icon = QIcon::fromTheme(fallbackName);
37+
if (icon.isNull() && !path.isEmpty()) {
38+
for (const auto& iconFiletype : ICON_FILETYPES){
39+
icon = QPixmap(QString("%1.%2").arg(path, iconFiletype));
40+
if (!icon.isNull()) break;
41+
}
42+
}
3643

3744
auto targetSize = requestedSize.isValid() ? requestedSize : QSize(100, 100);
3845
if (targetSize.width() == 0 || targetSize.height() == 0) targetSize = QSize(2, 2);

0 commit comments

Comments
 (0)