aboutsummaryrefslogtreecommitdiff
path: root/src/autogen/util.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/autogen/util.h')
-rw-r--r--src/autogen/util.h83
1 files changed, 0 insertions, 83 deletions
diff --git a/src/autogen/util.h b/src/autogen/util.h
index 822794a..aa3e954 100644
--- a/src/autogen/util.h
+++ b/src/autogen/util.h
@@ -9,95 +9,12 @@
#ifndef SMOLBOTE_UTIL_H
#define SMOLBOTE_UTIL_H
-#include "poi_icons.h"
-#include "poi_logos.h"
-#include <QIcon>
-#include <QPainter>
#include <QStringList>
-#include <QStyle>
-#include <QSvgRenderer>
namespace Util {
const QStringList files(const QString &location, const QStringList &nameFilters = QStringList());
-constexpr auto AppIcon = QStyle::SP_CustomBase + 1;
-constexpr auto AppWindowIcon = QStyle::SP_CustomBase + 2;
-
-[[nodiscard]] inline QPixmap render(const auto &data, const QSize size = QSize())
-{
- QSvgRenderer renderer;
- renderer.load(QByteArray(data.data(), static_cast<int>(data.size())));
-
- QPixmap pm(size.isValid() ? size : renderer.defaultSize());
- pm.fill(Qt::transparent);
-
- QPainter painter(&pm);
- renderer.render(&painter, pm.rect());
-
- return pm;
-}
-
-template </*QStyle::StandardPixmap*/ unsigned int id>
-inline QIcon icon()
-{
- using namespace std::literals;
-
- if constexpr(id == QStyle::SP_MediaVolume) {
- auto on = render(icons::get([] { return "volume-3.svg"sv; }));
- auto off = render(icons::get([] { return "volume.svg"sv; }));
- QIcon m;
- m.addPixmap(on, QIcon::Normal, QIcon::On);
- m.addPixmap(off, QIcon::Normal, QIcon::Off);
- return m;
-
- } else if constexpr(id >= QStyle::SP_CustomBase) {
- constexpr auto data = logos::get([] {
- switch(id) {
- case AppIcon:
- return "poi.svg"sv;
- case AppWindowIcon:
- return "poi_window.svg"sv;
- default:
- return "__unknown__"sv;
- }
- });
- return QIcon(render(data));
- } else {
-
- constexpr auto data = icons::get([] {
- switch(id) {
- case QStyle::SP_ArrowBack:
- return "arrow-left.svg"sv;
- case QStyle::SP_ArrowForward:
- return "arrow-right.svg"sv;
- case QStyle::SP_BrowserStop:
- return "circle-x.svg"sv;
- case QStyle::SP_BrowserReload:
- return "refresh.svg"sv;
- case QStyle::SP_DirHomeIcon:
- return "home.svg"sv;
- default:
- return "__unknown__"sv;
- }
- });
-
- QIcon m;
- // This is a horrible hack that will one day be hopefully fixed:
- // When rendering an svg, you can't actually pick a stroke color through
- // QPainter::setBrush or QPainter::setPen. So instead, replace the stroke
- // color in the data (stroke="currentColor") and then rerender it.
-
- QByteArray arr(data.data(), data.size());
- for(const auto mode : { QIcon::Normal /*, QIcon::Disabled, QIcon::Active, QIcon::Selected*/ }) {
- for(const auto toggle : { QIcon::On, QIcon::Off }) {
- const auto pm = render(arr.replace("currentColor", (toggle == QIcon::On ? "black" : "gray")));
- m.addPixmap(pm, mode, toggle);
- }
- }
- return m;
- }
-}
} // namespace Util
#endif // SMOLBOTE_UTIL_H