Allow rendering any `QChar` so `Renderer` could also be used for other fonts
This commit is contained in:
parent
02a56eebfd
commit
56fdef53cd
18
renderer.cpp
18
renderer.cpp
|
@ -30,7 +30,7 @@ Renderer::InternalData::InternalData(int id)
|
|||
/*!
|
||||
*
|
||||
* \class QtForkAwesome::Renderer
|
||||
* \brief Allows rendering a QtForkAwesome::Icon.
|
||||
* \brief Allows rendering a QtForkAwesome::Icon (or an arbitrary QChar using an arbitrary font file).
|
||||
*/
|
||||
|
||||
/*!
|
||||
|
@ -72,7 +72,7 @@ Renderer::operator bool() const
|
|||
/*!
|
||||
* \brief Renders the specified \a icon using the specified \a painter.
|
||||
*/
|
||||
void Renderer::render(Icon icon, QPainter *painter, const QRect &rect, const QColor &color)
|
||||
void QtForkAwesome::Renderer::render(QChar character, QPainter *painter, const QRect &rect, const QColor &color)
|
||||
{
|
||||
if (!*this) {
|
||||
return;
|
||||
|
@ -82,14 +82,14 @@ void Renderer::render(Icon icon, QPainter *painter, const QRect &rect, const QCo
|
|||
painter->save();
|
||||
painter->setFont(font);
|
||||
painter->setPen(color);
|
||||
painter->drawText(rect, QString(QChar(static_cast<IconBaseType>(icon))), QTextOption(Qt::AlignCenter));
|
||||
painter->drawText(rect, QString(character), QTextOption(Qt::AlignCenter));
|
||||
painter->restore();
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Renders the specified \a icon as pixmap of the specified \a size.
|
||||
* \brief Renders the specified \a character as pixmap of the specified \a size.
|
||||
*/
|
||||
QPixmap QtForkAwesome::Renderer::pixmap(Icon icon, const QSize &size, const QColor &color)
|
||||
QPixmap QtForkAwesome::Renderer::pixmap(QChar icon, const QSize &size, const QColor &color)
|
||||
{
|
||||
const auto scaleFactor =
|
||||
#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
|
||||
|
@ -105,4 +105,12 @@ QPixmap QtForkAwesome::Renderer::pixmap(Icon icon, const QSize &size, const QCol
|
|||
return pm;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Renders the specified \a icon as pixmap of the specified \a size.
|
||||
*/
|
||||
QPixmap Renderer::pixmap(Icon icon, const QSize &size, const QColor &color)
|
||||
{
|
||||
return pixmap(QChar(static_cast<IconBaseType>(icon)), size, color);
|
||||
}
|
||||
|
||||
} // namespace QtForkAwesome
|
||||
|
|
11
renderer.h
11
renderer.h
|
@ -27,13 +27,24 @@ public:
|
|||
~Renderer();
|
||||
|
||||
operator bool() const;
|
||||
void render(QChar character, QPainter *painter, const QRect &rect, const QColor &color);
|
||||
void render(Icon icon, QPainter *painter, const QRect &rect, const QColor &color);
|
||||
|
||||
QPixmap pixmap(QChar icon, const QSize &size, const QColor &color);
|
||||
QPixmap pixmap(Icon icon, const QSize &size, const QColor &color);
|
||||
|
||||
private:
|
||||
std::unique_ptr<Renderer::InternalData> m_d;
|
||||
};
|
||||
|
||||
/*!
|
||||
* \brief Renders the specified \a icon using the specified \a painter.
|
||||
*/
|
||||
inline void Renderer::render(Icon icon, QPainter *painter, const QRect &rect, const QColor &color)
|
||||
{
|
||||
render(QChar(static_cast<IconBaseType>(icon)), painter, rect, color);
|
||||
}
|
||||
|
||||
} // namespace QtForkAwesome
|
||||
|
||||
#endif // QT_FORK_AWESOME_RENDERER
|
||||
|
|
Loading…
Reference in New Issue