aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAqua-sama <aqua@iserlohn-fortress.net>2020-11-02 17:30:45 +0200
committerAqua-sama <aqua@iserlohn-fortress.net>2020-11-02 17:30:45 +0200
commitb5217fb4c9b89c0d0552644e95614f946e69359f (patch)
treed81529264e8d8f016092811f856628daa173e49d /src
parentUpdate wraps (diff)
downloadsmolbote-b5217fb4c9b89c0d0552644e95614f946e69359f.tar.xz
Add tabler-icons
Add rcc dependency to create dumps of svg files
Diffstat (limited to 'src')
-rw-r--r--src/mainwindow/widgets/navigationbar.cpp12
-rw-r--r--src/meson.build11
-rw-r--r--src/util.cpp21
-rw-r--r--src/util.h54
4 files changed, 69 insertions, 29 deletions
diff --git a/src/mainwindow/widgets/navigationbar.cpp b/src/mainwindow/widgets/navigationbar.cpp
index 799ebec..0338bb7 100644
--- a/src/mainwindow/widgets/navigationbar.cpp
+++ b/src/mainwindow/widgets/navigationbar.cpp
@@ -28,7 +28,7 @@ NavigationBar::NavigationBar(QWidget *parent)
Configuration config;
// Back button
- backAction = addAction(Util::icon(QStyle::SP_ArrowBack), tr("Back"));
+ backAction = addAction(Util::icon<QStyle::SP_ArrowBack>(), tr("Back"));
config.shortcut<QAction>(*backAction, "shortcuts.navigation.back");
connect(backAction, &QAction::triggered, this, [this]() {
m_view->history()->back();
@@ -56,7 +56,7 @@ NavigationBar::NavigationBar(QWidget *parent)
});
// Forward button
- forwardAction = addAction(Util::icon(QStyle::SP_ArrowForward), tr("Forward"));
+ forwardAction = addAction(Util::icon<QStyle::SP_ArrowForward>(), tr("Forward"));
config.shortcut<QAction>(*forwardAction, "shortcuts.navigation.forward");
connect(forwardAction, &QAction::triggered, this, [this]() {
m_view->history()->forward();
@@ -84,7 +84,7 @@ NavigationBar::NavigationBar(QWidget *parent)
});
// Stop/Refresh button
- stopReloadAction = addAction(Util::icon(QStyle::SP_BrowserReload), tr("Refresh"));
+ stopReloadAction = addAction(Util::icon<QStyle::SP_BrowserReload>(), tr("Refresh"));
config.shortcut<QAction>(*stopReloadAction, "shortcuts.navigation.refresh");
connect(stopReloadAction, &QAction::triggered, this, [this]() {
if(m_view->isLoaded())
@@ -99,7 +99,7 @@ NavigationBar::NavigationBar(QWidget *parent)
});
// Home button
- homeAction = addAction(Util::icon(QStyle::SP_DirHomeIcon), tr("Home"));
+ homeAction = addAction(Util::icon<QStyle::SP_DirHomeIcon>(), tr("Home"));
config.shortcut<QAction>(*homeAction, "shortcuts.navigation.home");
connect(homeAction, &QAction::triggered, this, [this]() {
m_view->load(m_view->profile()->homepage());
@@ -138,12 +138,12 @@ void NavigationBar::update_loadStarted()
{
backAction->setEnabled(m_view->history()->canGoForward());
forwardAction->setEnabled(m_view->history()->canGoForward());
- stopReloadAction->setIcon(Util::icon(QStyle::SP_BrowserStop));
+ stopReloadAction->setIcon(Util::icon<QStyle::SP_BrowserStop>());
}
void NavigationBar::update_loadFinished()
{
backAction->setEnabled(m_view->history()->canGoBack());
forwardAction->setEnabled(m_view->history()->canGoForward());
- stopReloadAction->setIcon(Util::icon(QStyle::SP_BrowserReload));
+ stopReloadAction->setIcon(Util::icon<QStyle::SP_BrowserReload>());
}
diff --git a/src/meson.build b/src/meson.build
index aa98d61..062dae4 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -1,12 +1,21 @@
python = import('python')
python3 = python.find_installation('python3')
+rcc_exe = subproject('rcc').get_variable('rcc_exe')
+icons = subproject('tabler-icons').get_variable('smolbote_icons')
+
poi_settings_h = custom_target('default_config_value',
input: files('../scripts/gen-default-cfg.py', '../Kconfig', '..'/host_machine.system()/'.config', 'settings.h.in'),
output: 'settings.h',
command: [ python3, '@INPUT0@', '--kconfig=@INPUT1@', '--dotconfig=@INPUT2@', '--input=@INPUT3@', '--output=@OUTPUT@' ]
)
+poi_icons_h = custom_target('poi_icons_h',
+ input: icons,
+ output: 'icons.h',
+ command: [ python3, rcc_exe, '-o=@OUTPUT@', 'dump', '-ns=icons', '@INPUT@' ]
+)
+
subdir('about')
subdir('webengine')
@@ -48,6 +57,6 @@ poi_sourceset.add(files(
'subwindow/subwindow.cpp',
'subwindow/tabwidget.cpp',
),
- version_h, poi_settings_h
+ version_h, poi_settings_h, poi_icons_h
)
diff --git a/src/util.cpp b/src/util.cpp
index fe74175..3dc5f8d 100644
--- a/src/util.cpp
+++ b/src/util.cpp
@@ -7,9 +7,9 @@
*/
#include "util.h"
+#include <QApplication>
#include <QDir>
#include <QFileInfo>
-#include <QApplication>
#include <spdlog/spdlog.h>
#define ListSeparator QLatin1String(";")
@@ -47,22 +47,3 @@ const QStringList Util::files(const QString &location, const QStringList &nameFi
return filelist;
}
-// icon names: https://specifications.freedesktop.org/icon-naming-spec/icon-naming-spec-latest.html
-QIcon Util::icon(QStyle::StandardPixmap id) {
- switch(id) {
- case QStyle::SP_ArrowBack:
- return QIcon::fromTheme("go-previous", qApp->style()->standardIcon(id));
- case QStyle::SP_ArrowForward:
- return QIcon::fromTheme("go-next", qApp->style()->standardIcon(id));
- case QStyle::SP_BrowserStop:
- return QIcon::fromTheme("process-stop", qApp->style()->standardIcon(id));
- case QStyle::SP_BrowserReload:
- return QIcon::fromTheme("view-refresh", qApp->style()->standardIcon(id));
- case QStyle::SP_DirHomeIcon:
- return QIcon::fromTheme("go-home", qApp->style()->standardIcon(id));
-
- default:
- spdlog::warn("FIXME: unhandled StandardPixmap {}", id);
- return qApp->style()->standardIcon(id);
- }
-}
diff --git a/src/util.h b/src/util.h
index d96dc19..6882854 100644
--- a/src/util.h
+++ b/src/util.h
@@ -9,15 +9,65 @@
#ifndef SMOLBOTE_UTIL_H
#define SMOLBOTE_UTIL_H
-#include <QStringList>
+#include "icons.h"
#include <QIcon>
+#include <QPainter>
+#include <QStringList>
#include <QStyle>
+#include <QSvgRenderer>
namespace Util {
const QStringList files(const QString &location, const QStringList &nameFilters = QStringList());
-[[nodiscard]] QIcon icon(QStyle::StandardPixmap id);
+template <QStyle::StandardPixmap id>
+inline QIcon icon()
+{
+ using namespace std::literals;
+
+ 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.
+
+ QSvgRenderer renderer;
+ 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 }) {
+ renderer.load(arr.replace("currentColor", (toggle == QIcon::On ? "black" : "gray")));
+
+ QPixmap pm(renderer.defaultSize());
+ pm.fill(Qt::transparent);
+
+ QPainter painter(&pm);
+ painter.setBrush(Qt::green);
+ painter.setPen(Qt::green);
+ renderer.render(&painter, pm.rect());
+
+ m.addPixmap(pm, mode, toggle);
+ }
+ }
+ return m;
}
+} // namespace Util
#endif // SMOLBOTE_UTIL_H