diff --git a/renderer.cpp b/renderer.cpp index a88aeda..c952ce1 100644 --- a/renderer.cpp +++ b/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(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(icon)), size, color); +} + } // namespace QtForkAwesome diff --git a/renderer.h b/renderer.h index f47c73e..1778770 100644 --- a/renderer.h +++ b/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 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(icon)), painter, rect, color); +} + } // namespace QtForkAwesome #endif // QT_FORK_AWESOME_RENDERER