Allow specifying icon for an override directly
This commit is contained in:
parent
0add8e8f91
commit
34aacf236b
|
@ -13,7 +13,8 @@ namespace QtForkAwesome {
|
||||||
|
|
||||||
/// \cond
|
/// \cond
|
||||||
|
|
||||||
struct ThemeOverride {
|
struct IconOverride {
|
||||||
|
void setIcon(const QIcon &icon);
|
||||||
void addIconName(const QString &iconName);
|
void addIconName(const QString &iconName);
|
||||||
const QIcon &locateIcon();
|
const QIcon &locateIcon();
|
||||||
|
|
||||||
|
@ -22,7 +23,13 @@ private:
|
||||||
QIcon cachedIcon;
|
QIcon cachedIcon;
|
||||||
};
|
};
|
||||||
|
|
||||||
void ThemeOverride::addIconName(const QString &iconName)
|
void IconOverride::setIcon(const QIcon &icon)
|
||||||
|
{
|
||||||
|
iconNames.clear();
|
||||||
|
cachedIcon = icon;
|
||||||
|
}
|
||||||
|
|
||||||
|
void IconOverride::addIconName(const QString &iconName)
|
||||||
{
|
{
|
||||||
iconNames.append(iconName);
|
iconNames.append(iconName);
|
||||||
if (!cachedIcon.isNull()) {
|
if (!cachedIcon.isNull()) {
|
||||||
|
@ -30,7 +37,7 @@ void ThemeOverride::addIconName(const QString &iconName)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const QIcon &ThemeOverride::locateIcon()
|
const QIcon &IconOverride::locateIcon()
|
||||||
{
|
{
|
||||||
if (!cachedIcon.isNull()) {
|
if (!cachedIcon.isNull()) {
|
||||||
return cachedIcon;
|
return cachedIcon;
|
||||||
|
@ -50,7 +57,7 @@ struct Renderer::InternalData {
|
||||||
|
|
||||||
int id;
|
int id;
|
||||||
QStringList fontFamilies;
|
QStringList fontFamilies;
|
||||||
QHash<QChar, ThemeOverride> themeOverrides;
|
QHash<QChar, IconOverride> overrides;
|
||||||
};
|
};
|
||||||
|
|
||||||
Renderer::InternalData::InternalData(int id)
|
Renderer::InternalData::InternalData(int id)
|
||||||
|
@ -120,8 +127,8 @@ static void renderInternally(QChar character, QPainter *painter, QFont &&font, c
|
||||||
*/
|
*/
|
||||||
void QtForkAwesome::Renderer::render(QChar character, QPainter *painter, const QRect &rect, const QColor &color) const
|
void QtForkAwesome::Renderer::render(QChar character, QPainter *painter, const QRect &rect, const QColor &color) const
|
||||||
{
|
{
|
||||||
if (auto themeOverride = m_d->themeOverrides.find(character); themeOverride != m_d->themeOverrides.end()) {
|
if (auto override = m_d->overrides.find(character); override != m_d->overrides.end()) {
|
||||||
if (const auto &icon = themeOverride->locateIcon(); !icon.isNull()) {
|
if (const auto &icon = override->locateIcon(); !icon.isNull()) {
|
||||||
painter->drawPixmap(rect, icon.pixmap(rect.size(), QIcon::Normal, QIcon::On));
|
painter->drawPixmap(rect, icon.pixmap(rect.size(), QIcon::Normal, QIcon::On));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -136,8 +143,8 @@ void QtForkAwesome::Renderer::render(QChar character, QPainter *painter, const Q
|
||||||
*/
|
*/
|
||||||
QPixmap QtForkAwesome::Renderer::pixmap(QChar icon, const QSize &size, const QColor &color) const
|
QPixmap QtForkAwesome::Renderer::pixmap(QChar icon, const QSize &size, const QColor &color) const
|
||||||
{
|
{
|
||||||
if (auto themeOverride = m_d->themeOverrides.find(icon); themeOverride != m_d->themeOverrides.end()) {
|
if (auto override = m_d->overrides.find(icon); override != m_d->overrides.end()) {
|
||||||
if (const auto &icon = themeOverride->locateIcon(); !icon.isNull()) {
|
if (const auto &icon = override->locateIcon(); !icon.isNull()) {
|
||||||
return icon.pixmap(size, QIcon::Normal, QIcon::On);
|
return icon.pixmap(size, QIcon::Normal, QIcon::On);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -171,7 +178,15 @@ QPixmap Renderer::pixmap(Icon icon, const QSize &size, const QColor &color) cons
|
||||||
*/
|
*/
|
||||||
void Renderer::addThemeOverride(QChar character, const QString &iconNameInTheme)
|
void Renderer::addThemeOverride(QChar character, const QString &iconNameInTheme)
|
||||||
{
|
{
|
||||||
m_d->themeOverrides[character].addIconName(iconNameInTheme);
|
m_d->overrides[character].addIconName(iconNameInTheme);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* \brief Uses the specified \a override icon for \a character if it is not null.
|
||||||
|
*/
|
||||||
|
void Renderer::addOverride(QChar character, const QIcon &override)
|
||||||
|
{
|
||||||
|
m_d->overrides[character].setIcon(override);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
|
|
|
@ -35,6 +35,8 @@ public:
|
||||||
|
|
||||||
void addThemeOverride(QChar character, const QString &iconNameInTheme);
|
void addThemeOverride(QChar character, const QString &iconNameInTheme);
|
||||||
void addThemeOverride(Icon icon, const QString &iconNameInTheme);
|
void addThemeOverride(Icon icon, const QString &iconNameInTheme);
|
||||||
|
void addOverride(QChar character, const QIcon &override);
|
||||||
|
void addOverride(Icon icon, const QIcon &override);
|
||||||
|
|
||||||
static Renderer &global();
|
static Renderer &global();
|
||||||
|
|
||||||
|
@ -58,6 +60,14 @@ inline void Renderer::addThemeOverride(Icon icon, const QString &iconNameInTheme
|
||||||
addThemeOverride(QChar(static_cast<IconBaseType>(icon)), iconNameInTheme);
|
addThemeOverride(QChar(static_cast<IconBaseType>(icon)), iconNameInTheme);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* \brief Uses the specified \a override icon for \a icon if it is not null.
|
||||||
|
*/
|
||||||
|
inline void Renderer::addOverride(Icon icon, const QIcon &override)
|
||||||
|
{
|
||||||
|
addOverride(QChar(static_cast<IconBaseType>(icon)), override);
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace QtForkAwesome
|
} // namespace QtForkAwesome
|
||||||
|
|
||||||
#endif // QT_FORK_AWESOME_RENDERER
|
#endif // QT_FORK_AWESOME_RENDERER
|
||||||
|
|
Loading…
Reference in New Issue