aboutsummaryrefslogtreecommitdiff
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
parentUpdate wraps (diff)
downloadsmolbote-b5217fb4c9b89c0d0552644e95614f946e69359f.tar.xz
Add tabler-icons
Add rcc dependency to create dumps of svg files
-rw-r--r--.gitignore2
-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
-rw-r--r--subprojects/packagefiles/tabler-icons-1.34.0_patch.tar.xzbin0 -> 316 bytes
-rw-r--r--subprojects/rcc.wrap5
-rw-r--r--subprojects/tabler-icons.wrap7
8 files changed, 82 insertions, 30 deletions
diff --git a/.gitignore b/.gitignore
index 1d130a6..4fc3e3d 100644
--- a/.gitignore
+++ b/.gitignore
@@ -7,9 +7,9 @@ build*
subprojects/*
!subprojects/*.wrap
+!subprojects/packagefiles
lang/*.qm
-tools/src/crashhandler/defaults.go
.config
.config.old
compile_commands.json
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
diff --git a/subprojects/packagefiles/tabler-icons-1.34.0_patch.tar.xz b/subprojects/packagefiles/tabler-icons-1.34.0_patch.tar.xz
new file mode 100644
index 0000000..65933c3
--- /dev/null
+++ b/subprojects/packagefiles/tabler-icons-1.34.0_patch.tar.xz
Binary files differ
diff --git a/subprojects/rcc.wrap b/subprojects/rcc.wrap
new file mode 100644
index 0000000..c0986d2
--- /dev/null
+++ b/subprojects/rcc.wrap
@@ -0,0 +1,5 @@
+[wrap-file]
+directory = rcc-0.1.1
+source_url = https://neueland.iserlohn-fortress.net/cgit/rcc/snapshot/rcc-0.1.1.tar.xz
+source_filename = rcc-0.1.1.tar.xz
+source_hash = 6093e2a7a6634d3288834b88e7e1afc12d6583581bb3eadd29995990c1a20f6c
diff --git a/subprojects/tabler-icons.wrap b/subprojects/tabler-icons.wrap
new file mode 100644
index 0000000..5df4f83
--- /dev/null
+++ b/subprojects/tabler-icons.wrap
@@ -0,0 +1,7 @@
+[wrap-file]
+directory = tabler-icons-1.34.0
+source_url = https://github.com/tabler/tabler-icons/archive/v1.34.0.tar.gz
+source_filename = v1.34.0.tar.gz
+source_hash = bc74e5bd28531445f2e50df44f3688b1116397a25a0086e6944ab52260b70ffd
+patch_filename = tabler-icons-1.34.0_patch.tar.xz
+patch_hash = 5844ca9c3b69507abb50b50bebf23828fd60313a2c8c514d595e274a89a05456