Qt ForkAwesome: renderer.h Source File

Qt ForkAwesome 0.3.4 Library that bundles ForkAwesome for use within Qt applications

Loading...
Searching...
No Matches
renderer.h
Go to the documentation of this file.
1#ifndef QT_FORK_AWESOME_RENDERER
2#define QT_FORK_AWESOME_RENDERER
3
4#include "./global.h"
5#include "./iconfwd.h"
6
7#include <QString>
8
9#include <memory>
10
11QT_FORWARD_DECLARE_CLASS(QByteArray)
12QT_FORWARD_DECLARE_CLASS(QColor)
13QT_FORWARD_DECLARE_CLASS(QPainter)
14QT_FORWARD_DECLARE_CLASS(QRect)
15QT_FORWARD_DECLARE_CLASS(QSize)
16QT_FORWARD_DECLARE_CLASS(QPaintDevice)
17QT_FORWARD_DECLARE_CLASS(QPixmap)
18QT_FORWARD_DECLARE_CLASS(QIcon)
19
20namespace QtForkAwesome {
21
22 class QT_FORK_AWESOME_EXPORT Renderer {
23 struct InternalData;
24
25public:
26 explicit Renderer(const QString &fontFileName = QString());
27 explicit Renderer(const QByteArray &fontData);
28 ~Renderer();
29
30 const QString &fontFilePath() const;
31 void warnIfInvalid() const;
32 operator bool() const;
33 void render(QChar character, QPainter *painter, const QRect &rect, const QColor &color) const;
34 void render(Icon icon, QPainter *painter, const QRect &rect, const QColor &color) const;
35
36 QPixmap pixmap(QChar icon, const QSize &size, const QColor &color, qreal scaleFactor) const;
37 QPixmap pixmap(Icon icon, const QSize &size, const QColor &color, qreal scaleFactor) const;
38 QPixmap pixmap(QChar icon, const QSize &size, const QColor &color) const;
39 QPixmap pixmap(Icon icon, const QSize &size, const QColor &color) const;
40
41 void addThemeOverride(QChar character, const QString &iconNameInTheme);
42 void addThemeOverride(Icon icon, const QString &iconNameInTheme);
43 void addOverride(QChar character, const QIcon &override);
44 void addOverride(Icon icon, const QIcon &override);
45 void setAssociatedPaintDevice(QPaintDevice *paintDevice);
46 void clearOverrides();
47
48 static Renderer &global();
49
50private:
51 std::unique_ptr<Renderer::InternalData> m_d;
52};
53
57 inline void Renderer::render(Icon icon, QPainter *painter, const QRect &rect, const QColor &color) const
58{
59 render(QChar(static_cast<IconBaseType>(icon)), painter, rect, color);
60}
61
65 inline void Renderer::addThemeOverride(Icon icon, const QString &iconNameInTheme)
66{
67 addThemeOverride(QChar(static_cast<IconBaseType>(icon)), iconNameInTheme);
68}
69
73 inline void Renderer::addOverride(Icon icon, const QIcon &override)
74{
75 addOverride(QChar(static_cast<IconBaseType>(icon)), override);
76}
77
78} // namespace QtForkAwesome
79
80#endif // QT_FORK_AWESOME_RENDERER
QtForkAwesome::Renderer::Renderer
Renderer(const QString &fontFileName=QString())
Constructs a new renderer with the given fontFileName.
Definition renderer.cpp:96
QtForkAwesome::Renderer::global
static Renderer & global()
Returns the global instance (which is currently only used by the icon engine plugin).
Definition renderer.cpp:306
QtForkAwesome::Renderer::fontFilePath
const QString & fontFilePath() const
Returns the path of the font file.
Definition renderer.cpp:120
QtForkAwesome::Renderer::clearOverrides
void clearOverrides()
Clears all overrides added via addThemeOverride() or addOverride().
Definition renderer.cpp:287
QtForkAwesome::Renderer::addThemeOverride
void addThemeOverride(QChar character, const QString &iconNameInTheme)
Uses the icon from the current icon theme obtained via QIcon::fromTheme() for character if it exists.
Definition renderer.cpp:271
QtForkAwesome::Renderer::warnIfInvalid
void warnIfInvalid() const
Prints a warning using qWarning() if no font could be loaded.
Definition renderer.cpp:128
QtForkAwesome::Renderer::addOverride
void addOverride(QChar character, const QIcon &override)
Uses the specified override icon for character if it is not null.
Definition renderer.cpp:279
QtForkAwesome::Renderer::pixmap
QPixmap pixmap(QChar icon, const QSize &size, const QColor &color, qreal scaleFactor) const
Renders the specified character as pixmap of the specified size.
Definition renderer.cpp:204
QtForkAwesome::Renderer::setAssociatedPaintDevice
void setAssociatedPaintDevice(QPaintDevice *paintDevice)
Sets the associated paintDevice.
Definition renderer.cpp:298
QtForkAwesome::Renderer::render
void render(QChar character, QPainter *painter, const QRect &rect, const QColor &color) const
Renders the specified icon using the specified painter.
Definition renderer.cpp:188
global.h
QT_FORK_AWESOME_EXPORT
#define QT_FORK_AWESOME_EXPORT
Marks the symbol to be exported by the qtforkawesome library.
Definition global.h:14
iconfwd.h
QtForkAwesome
Contains classes provided by the QtForkAwesome library.
Definition renderer.h:20
QtForkAwesome::Icon
Icon
The Icon enum specifies a ForkAwesome icon for use with QtForkAwesome::Renderer::render().
Definition icon.h:11
QtForkAwesome::IconBaseType
std::remove_reference_t< decltype(QChar().unicode())> IconBaseType
Definition iconfwd.h:10