Add global renderer instance to allow accessing renderer of icon engine

This commit is contained in:
Martchus 2022-09-18 14:51:23 +02:00
parent 45dc4c7291
commit 2fcc5debcd
3 changed files with 12 additions and 4 deletions

View File

@ -22,14 +22,11 @@ class QT_FORK_AWESOME_ICON_ENGINE_EXPORT ForkAwesomeIconEnginePlugin : public QI
public:
QIconEngine *create(const QString &filename = QString()) override;
private:
const Renderer m_renderer;
};
QIconEngine *ForkAwesomeIconEnginePlugin::create(const QString &file)
{
auto *const engine = new IconEngine(m_renderer);
auto *const engine = new IconEngine(Renderer::global());
if (!file.isNull()) {
engine->addFile(file, QSize(), QIcon::Normal, QIcon::Off);
}

View File

@ -113,4 +113,13 @@ QPixmap Renderer::pixmap(Icon icon, const QSize &size, const QColor &color) cons
return pixmap(QChar(static_cast<IconBaseType>(icon)), size, color);
}
/*!
* \brief Returns the global instance (which is so far only used by the icon engine plugin).
*/
Renderer &Renderer::global()
{
static auto globalRenderer = Renderer();
return globalRenderer;
}
} // namespace QtForkAwesome

View File

@ -33,6 +33,8 @@ public:
QPixmap pixmap(QChar icon, const QSize &size, const QColor &color) const;
QPixmap pixmap(Icon icon, const QSize &size, const QColor &color) const;
static Renderer &global();
private:
std::unique_ptr<Renderer::InternalData> m_d;
};