This repository has been archived on 2020-04-08. You can view files and clone it, but cannot push or open issues or pull requests.
Files
YASMIN/ui/Icons.h
kazu 075d8bb633 a lot!!! of changes
added main menu
added debug display
many debug widgets for plotting live data
worked on android live sensors
added offline-data sensor feeding
some dummy data sensors
worked on the map display
added ui debug for grid-points, particles and weights
added a cool dude to display the estimation
added real filtering based on the Indoor components
c++11 fixes for android compilation
online and offline filtering support
new resampling technique for testing
map loading via dialog
2016-09-16 19:30:04 +02:00

91 lines
1.8 KiB
C++

#ifndef ICONS_H
#define ICONS_H
#include "../misc/fixc11.h"
#include <QIcon>
#include <QImage>
#include <QPainter>
#include <QRgb>
#include <QtSvg/QSvgRenderer>
#include <unordered_map>
class Icons {
public:
static const QPixmap& getPixmap(const std::string& name, const int size = 32) {
// caching
static std::unordered_map<std::string, QPixmap> cache;
// try to get the image from the cache
const std::string cacheKey = std::to_string(size) + name;
auto it = cache.find(cacheKey);
// not in cache?
if (it == cache.end()) {
// build
const QColor fill = Qt::transparent;
const std::string file = "://res/icons/" + name + ".svg";
QSvgRenderer renderer(QString(file.c_str()));
QPixmap pm(size, size);
pm.fill(fill);
QPainter painter(&pm);
renderer.render(&painter, pm.rect());
// add to cache
cache[cacheKey] = pm;
}
// done
return cache[cacheKey];
}
static const QPixmap& getPixmapColored(const std::string& name, const QColor color, const int size = 32) {
// caching
static std::unordered_map<std::string, QPixmap> cache;
// try to get the image from the cache
const QString hex = color.name();
const std::string cacheKey = hex.toStdString() + "_" + std::to_string(size) + "_" + name;
auto it = cache.find(cacheKey);
// not in cache?
if (it == cache.end()) {
// copy
QPixmap colored = getPixmap(name, size);
QPainter painter(&colored);
painter.setCompositionMode(QPainter::CompositionMode_SourceIn);
painter.fillRect(colored.rect(), color);
painter.end();
// add to cache
cache[cacheKey] = colored;
}
// done
return cache[cacheKey];
}
static QIcon getIcon(const std::string& name, const int size = 32) {
return QIcon(getPixmap(name, size));
}
};
#endif // ICONS_H