Skip to content

Commit

Permalink
fix: non dci icon not found
Browse files Browse the repository at this point in the history
non dci icon fallback to provider
  • Loading branch information
kegechen committed Jul 25, 2024
1 parent 518732a commit c9bf08c
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 11 deletions.
38 changes: 31 additions & 7 deletions src/private/dquickdciiconimage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,19 @@ void DQuickDciIconImageItemPrivate::maybeUpdateUrl()
return DQuickIconImagePrivate::maybeUpdateUrl();
}

QString iconPath = findDciIconPath(parentPriv->imageItem->name(), appIconThemeName());
if (iconPath.isEmpty()) {
QUrl url;
url.setScheme(QLatin1String("image"));
url.setHost(QLatin1String("dtk.dci.icon"));
QUrlQuery query = getUrlQuery();
// alread find dci and failed...
query.addQueryItem(QLatin1String("_d_ignore_dci"), "true");
url.setQuery(query);
q_func()->setSource(url);
return;
}

updatePlayer();

if (player)
Expand Down Expand Up @@ -109,6 +122,20 @@ QUrlQuery DQuickDciIconImageItemPrivate::getUrlQuery()
return query;
}

void DQuickDciIconImageItemPrivate::updatePlayerIconSize()
{
if (!player)
return;

int boundingSize = qMax(q_func()->sourceSize().width(), q_func()->sourceSize().height());
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
if (qApp->testAttribute(Qt::AA_UseHighDpiPixmaps))
#endif
boundingSize = qRound(boundingSize / devicePixelRatio);
player->setIconSize(boundingSize);

}

void DQuickDciIconImageItemPrivate::updatePlayer()
{
if (!player) {
Expand All @@ -117,6 +144,9 @@ void DQuickDciIconImageItemPrivate::updatePlayer()
QObject::connect(player, &DDciIconPlayer::updated, parentPriv->imageItem, [this](){
parentPriv->imageItem->setImage(player->currentImage());
});
QObject::connect(parentPriv->imageItem, &DQuickIconImage::sourceSizeChanged, player, [this](){
updatePlayerIconSize();
});
}

QString iconPath = findDciIconPath(parentPriv->imageItem->name(), appIconThemeName());
Expand All @@ -138,13 +168,7 @@ void DQuickDciIconImageItemPrivate::updatePlayer()

player->setPalette(palette);

int boundingSize = qMax(q_func()->sourceSize().width(), q_func()->sourceSize().height());
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
if (qApp->testAttribute(Qt::AA_UseHighDpiPixmaps))
#endif
boundingSize = qRound(boundingSize / devicePixelRatio);

player->setIconSize(boundingSize);
updatePlayerIconSize();

player->setDevicePixelRatio(devicePixelRatio);
}
Expand Down
1 change: 1 addition & 0 deletions src/private/dquickdciiconimage_p_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class DQuickDciIconImageItemPrivate : public DQuickIconImagePrivate
QUrlQuery getUrlQuery();

void updatePlayer();
void updatePlayerIconSize();
private:
DQuickDciIconImagePrivate *parentPriv;
DDciIconPlayer *player = nullptr;
Expand Down
10 changes: 6 additions & 4 deletions src/private/dquickimageprovider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,10 +160,12 @@ QImage DQuickDciIconProvider::requestImage(const QString &id, QSize *size, const

const QString themeName = urlQuery.queryItemValue("themeName");
QString iconPath;
if (auto cached = DIconTheme::cached()) {
iconPath = cached->findDciIconFile(name, themeName);
} else {
iconPath = DIconTheme::findDciIconFile(name, themeName);
if (!urlQuery.hasQueryItem("_d_ignore_dci")) {
if (auto cached = DIconTheme::cached()) {
iconPath = cached->findDciIconFile(name, themeName);
} else {
iconPath = DIconTheme::findDciIconFile(name, themeName);
}
}

const bool fallbackToQIcon = urlQuery.queryItemValue("fallbackToQIcon").toInt();
Expand Down

0 comments on commit c9bf08c

Please sign in to comment.