Allow associating a paint device with the renderer for device-pixel-ratio

This commit is contained in:
Martchus 2024-02-22 00:43:22 +01:00
parent ce8e535d0e
commit 44776c210e
2 changed files with 14 additions and 0 deletions

View File

@ -7,6 +7,7 @@
#include <QHash> #include <QHash>
#include <QIcon> #include <QIcon>
#include <QPainter> #include <QPainter>
#include <QPaintDevice>
/// \brief Contains classes provided by the QtForkAwesome library. /// \brief Contains classes provided by the QtForkAwesome library.
namespace QtForkAwesome { namespace QtForkAwesome {
@ -58,11 +59,13 @@ struct Renderer::InternalData {
int id; int id;
QStringList fontFamilies; QStringList fontFamilies;
QHash<QChar, IconOverride> overrides; QHash<QChar, IconOverride> overrides;
QPaintDevice *paintDevice;
}; };
Renderer::InternalData::InternalData(int id) Renderer::InternalData::InternalData(int id)
: id(id) : id(id)
, fontFamilies(id != invalidId ? QFontDatabase::applicationFontFamilies(id) : QStringList()) , fontFamilies(id != invalidId ? QFontDatabase::applicationFontFamilies(id) : QStringList())
, paintDevice(nullptr)
{ {
} }
@ -197,6 +200,15 @@ void Renderer::clearOverrides()
m_d->overrides.clear(); m_d->overrides.clear();
} }
/*!
* \brief Sets the associated \a paintDevice.
* \remarks The device-pixel-ratio of the specified device will be used when rendering pixmaps.
*/
void Renderer::setAssociatedPaintDevice(QPaintDevice *paintDevice)
{
m_d->paintDevice = paintDevice;
}
/*! /*!
* \brief Returns the global instance (which is so far only used by the icon engine plugin). * \brief Returns the global instance (which is so far only used by the icon engine plugin).
*/ */

View File

@ -13,6 +13,7 @@ QT_FORWARD_DECLARE_CLASS(QColor)
QT_FORWARD_DECLARE_CLASS(QPainter) QT_FORWARD_DECLARE_CLASS(QPainter)
QT_FORWARD_DECLARE_CLASS(QRect) QT_FORWARD_DECLARE_CLASS(QRect)
QT_FORWARD_DECLARE_CLASS(QSize) QT_FORWARD_DECLARE_CLASS(QSize)
QT_FORWARD_DECLARE_CLASS(QPaintDevice)
QT_FORWARD_DECLARE_CLASS(QPixmap) QT_FORWARD_DECLARE_CLASS(QPixmap)
QT_FORWARD_DECLARE_CLASS(QIcon) QT_FORWARD_DECLARE_CLASS(QIcon)
@ -37,6 +38,7 @@ public:
void addThemeOverride(Icon icon, const QString &iconNameInTheme); void addThemeOverride(Icon icon, const QString &iconNameInTheme);
void addOverride(QChar character, const QIcon &override); void addOverride(QChar character, const QIcon &override);
void addOverride(Icon icon, const QIcon &override); void addOverride(Icon icon, const QIcon &override);
void setAssociatedPaintDevice(QPaintDevice *paintDevice);
void clearOverrides(); void clearOverrides();
static Renderer &global(); static Renderer &global();