13 #include <QApplication>
15 #include <QIconEngine>
18 #include <QSvgRenderer>
60 class icon_engine :
public QIconEngine {
62 explicit icon_engine(
const QString &path) : path(path) {}
64 icon_engine *clone()
const override {
return new icon_engine(path); }
66 void paint(QPainter *painter,
const QRect &rect, QIcon::Mode mode,
67 QIcon::State state)
override
73 if (rect.width() <= 0 || rect.height() <= 0) {
77 auto col = QApplication::palette().color(QPalette::ButtonText);
78 if (
auto widget =
dynamic_cast<QWidget *
>(painter->device()); widget) {
79 col = widget->palette().color(QPalette::ButtonText);
81 QString key = path +
"-" + QString::number(rect.width()) +
"-"
82 + QString::number(rect.height()) +
"-" + col.name();
84 if (!QPixmapCache::find(key, &pix)) {
85 pix = QPixmap(rect.width(), rect.height());
86 pix.fill(Qt::transparent);
87 if (!path.isEmpty()) {
88 QSvgRenderer renderer;
91 if (f.open(QIODevice::ReadOnly)) {
94 if (!bytes.isEmpty()) {
95 bytes.replace(
"\"#000\"",
96 QStringLiteral(
"\"%1\"").arg(col.name()).toLatin1());
100 renderer.render(&p, QRect(0, 0, rect.width(), rect.height()));
102 QPixmapCache::insert(key, pix);
104 painter->drawPixmap(rect, pix);
107 QPixmap pixmap(
const QSize &
size, QIcon::Mode mode,
108 QIcon::State state)
override
111 pix.fill(Qt::transparent);
112 QPainter painter(&pix);
113 paint(&painter, QRect(QPoint(0, 0),
size), mode, state);
133 QStringLiteral(
"themes/%1/%2.svg").arg(
current_theme,
id))));
134 if (!icon.isNull()) {
141 qUtf8Printable(QStringLiteral(
"themes/icons/%1.svg").arg(
id)));
142 if (!path.isEmpty()) {
144 return QIcon(
new icon_engine(path));
151 QStringLiteral(
"themes/%1/%2.png").arg(
current_theme,
id))));
152 if (!icon.isNull()) {
158 qUtf8Printable(QStringLiteral(
"themes/icons/%1.png").arg(
id))));
171 QByteArray png_bytes;
174 if (QPixmapCache::find(
id, pm)) {
177 str = QStringLiteral(
"themes/");
178 png_bytes = QString(str +
current_theme +
"/" +
id +
".png").toLocal8Bit();
182 str = str +
"icons/";
183 png_bytes = QString(str +
id +
".png").toLocal8Bit();
186 QPixmapCache::insert(
id, *pm);
197 QByteArray png_bytes;
199 str = QStringLiteral(
"themes/icons/");
200 png_bytes = QString(str +
id +
".png").toLocal8Bit();
222 hash.insert(QStringLiteral(
"prodplus"),
224 hash.insert(QStringLiteral(
"foodplus"),
226 hash.insert(QStringLiteral(
"tradeplus"),
228 hash.insert(QStringLiteral(
"gold"),
230 hash.insert(QStringLiteral(
"science"),
232 hash.insert(QStringLiteral(
"resize"),
QIcon getIcon(const QString &id)
Returns icon by given name.
QPixmap * getPixmap(const QString &id)
Returns pixmap by given name, pixmap needs to be deleted by someone else.
static fcIcons * m_instance
QString getPath(const QString &id)
Returns path for icon.
static fcIcons * instance()
Returns instance of fc_icons.
fcIcons()
Icon provider constructor.
static void drop()
Deletes fc_icons instance.
QHash< QString, QIcon > hash
static hIcon * m_instance
QIcon get(const QString &id)
const QStringList & get_data_dirs()
Returns a list of data directory paths, in the order in which they should be searched.
QString fileinfoname(const QStringList &dirs, const QString &filename)
Returns a filename to access the specified file from a directory by searching all specified directori...