diff --git a/share/qtcreator/lua-plugins/luatests/tst_markdownbrowser.lua b/share/qtcreator/lua-plugins/luatests/tst_markdownbrowser.lua index 49eaaf6ccef..8e4db01d03b 100644 --- a/share/qtcreator/lua-plugins/luatests/tst_markdownbrowser.lua +++ b/share/qtcreator/lua-plugins/luatests/tst_markdownbrowser.lua @@ -22,6 +22,11 @@ int main() { * [Is this a link to the Qt website?](https://www.qt.io) * [Is this an anchor link that scrolls up to the top?](#markdown-browser-test) +## Icons + +* Is the Home icon visible? ![You should see the home icon here](icon://HOME "Home Icon") +* Is this seek forward theme icon visible? ![You should see a seek forward icon here](theme://media-seek-forward "Seek Forward Icon") + ]] local mb = G.MarkdownBrowser { diff --git a/src/libs/utils/markdownbrowser.cpp b/src/libs/utils/markdownbrowser.cpp index 04cc98fed4f..b07bb7b2111 100644 --- a/src/libs/utils/markdownbrowser.cpp +++ b/src/libs/utils/markdownbrowser.cpp @@ -332,12 +332,39 @@ public: Q_UNUSED(document); Q_UNUSED(posInDocument); - Entry::Pointer *entryPtr = m_entries.object(format.toImageFormat().name()); + const QString name = format.toImageFormat().name(); + Entry::Pointer *entryPtr = m_entries.object(name); + + if (!entryPtr) { + constexpr QStringView themeScheme(u"theme://"); + constexpr QStringView iconScheme(u"icon://"); + + QVariant resource = document->resource(QTextDocument::ImageResource, name); + if (resource.isValid()) { + const QImage img = qvariant_cast(resource); + if (!img.isNull()) { + painter->drawImage(rect, img); + return; + } + } else if (name.startsWith(themeScheme)) { + const QIcon icon = QIcon::fromTheme(name.mid(themeScheme.length())); + if (!icon.isNull()) { + painter->drawPixmap( + rect.toRect(), + icon.pixmap(rect.size().toSize(), painter->device()->devicePixelRatioF())); + return; + } + } else if (name.startsWith(iconScheme)) { + std::optional icon = Icons::fromString(name.mid(iconScheme.length())); + if (icon) { + painter->drawPixmap(rect.toRect(), icon->pixmap()); + return; + } + } - if (!entryPtr) painter->drawPixmap( rect.toRect(), Utils::Icons::UNKNOWN_FILE.icon().pixmap(rect.size().toSize())); - else if (!(*entryPtr)->movie.isValid()) + } else if (!(*entryPtr)->movie.isValid()) painter->drawPixmap(rect.toRect(), m_brokenImage.pixmap(rect.size().toSize())); else painter->drawImage(rect, (*entryPtr)->movie.currentImage()); @@ -418,9 +445,16 @@ public: }; const auto isLocalUrl = [this, isRemoteUrl](const QUrl &url) { + QVariant res = this->resource(QTextDocument::ImageResource, url); + if (res.isValid()) + return false; + if (url.scheme() == "qrc") return true; + if (!url.scheme().isEmpty()) + return false; + if (!m_basePath.isEmpty() && !isRemoteUrl(url)) return true;