aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/webengine/CMakeLists.txt3
-rw-r--r--lib/webengine/webviewcontextmenu.cpp9
-rw-r--r--src/autogen/CMakeLists.txt4
-rw-r--r--src/autogen/applicationstyle.cpp91
-rw-r--r--src/autogen/applicationstyle.h26
-rw-r--r--src/autogen/util.h83
-rw-r--r--src/browser.cpp9
-rw-r--r--src/mainwindow/widgets/navigationbar.cpp12
8 files changed, 134 insertions, 103 deletions
diff --git a/lib/webengine/CMakeLists.txt b/lib/webengine/CMakeLists.txt
index ba3017f..3e5fa71 100644
--- a/lib/webengine/CMakeLists.txt
+++ b/lib/webengine/CMakeLists.txt
@@ -4,8 +4,7 @@ add_library(webengine STATIC
webview.h webview.cpp webviewcontextmenu.h webviewcontextmenu.cpp
urlinterceptor.h urlinterceptor.cpp)
target_include_directories(webengine PUBLIC ${CMAKE_SOURCE_DIR}/include ${CMAKE_CURRENT_SOURCE_DIR})
-# autogen: required for context menu icons; TODO: move context menu to src/
-target_link_libraries(webengine PUBLIC Qt5::WebEngineWidgets autogen fmt)
+target_link_libraries(webengine PUBLIC Qt5::WebEngineWidgets fmt)
# tests
add_executable(profile_test test/profile.cpp)
diff --git a/lib/webengine/webviewcontextmenu.cpp b/lib/webengine/webviewcontextmenu.cpp
index c9d809f..83bad3b 100644
--- a/lib/webengine/webviewcontextmenu.cpp
+++ b/lib/webengine/webviewcontextmenu.cpp
@@ -9,7 +9,6 @@
#include "webviewcontextmenu.h"
#include "webprofilemanager.h"
#include "webview.h"
-#include "util.h"
#include <QContextMenuEvent>
#include <QDialog>
#include <QMenu>
@@ -54,7 +53,7 @@ WebViewContextMenu::WebViewContextMenu(WebView *view)
auto *backButton = new QToolButton(this);
backButton->setMinimumSize(button_size);
backButton->setEnabled(view->history()->canGoBack());
- backButton->setIcon(Util::icon<QStyle::SP_ArrowBack>());
+ backButton->setIcon(style()->standardIcon(QStyle::SP_ArrowBack));
connect(backButton, &QToolButton::clicked, view, [this, view]() {
view->back();
this->close();
@@ -64,7 +63,7 @@ WebViewContextMenu::WebViewContextMenu(WebView *view)
auto *forwardButton = new QToolButton(this);
forwardButton->setMinimumSize(button_size);
forwardButton->setEnabled(view->history()->canGoForward());
- forwardButton->setIcon(Util::icon<QStyle::SP_ArrowForward>());
+ forwardButton->setIcon(style()->standardIcon(QStyle::SP_ArrowForward));
connect(forwardButton, &QToolButton::clicked, view, [this, view]() {
view->forward();
this->close();
@@ -73,7 +72,7 @@ WebViewContextMenu::WebViewContextMenu(WebView *view)
auto *refreshButton = new QToolButton(this);
refreshButton->setMinimumSize(button_size);
- refreshButton->setIcon(Util::icon<QStyle::SP_BrowserReload>());
+ refreshButton->setIcon(style()->standardIcon(QStyle::SP_BrowserReload));
connect(refreshButton, &QToolButton::clicked, view, [view, this]() {
view->reload();
this->close();
@@ -86,7 +85,7 @@ WebViewContextMenu::WebViewContextMenu(WebView *view)
muteButton->setMinimumSize(button_size);
muteButton->setCheckable(true);
muteButton->setChecked(view->page()->isAudioMuted());
- muteButton->setIcon(Util::icon<QStyle::SP_MediaVolume>());
+ muteButton->setIcon(style()->standardIcon(QStyle::SP_MediaVolume));
connect(muteButton, &QToolButton::clicked, view, [view, this](bool checked) {
view->page()->setAudioMuted(checked);
this->close();
diff --git a/src/autogen/CMakeLists.txt b/src/autogen/CMakeLists.txt
index c5c7614..f97526f 100644
--- a/src/autogen/CMakeLists.txt
+++ b/src/autogen/CMakeLists.txt
@@ -29,7 +29,7 @@ add_custom_command(OUTPUT poi_icons.h DEPENDS ${poi_icons}
add_custom_target(py_autogen DEPENDS settings.h poi_logos.h poi_icons.h)
add_library(autogen INTERFACE)
-target_sources(autogen INTERFACE util.h util.cpp)
+target_sources(autogen INTERFACE util.h util.cpp applicationstyle.h applicationstyle.cpp)
target_include_directories(autogen INTERFACE ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR})
-target_link_libraries(autogen INTERFACE Qt5::Svg)
+target_link_libraries(autogen INTERFACE fmt Qt5::Svg)
add_dependencies(autogen py_autogen)
diff --git a/src/autogen/applicationstyle.cpp b/src/autogen/applicationstyle.cpp
new file mode 100644
index 0000000..40c93d3
--- /dev/null
+++ b/src/autogen/applicationstyle.cpp
@@ -0,0 +1,91 @@
+/*
+ * This file is part of smolbote. It's copyrighted by the contributors recorded
+ * in the version control history of the file, available from its original
+ * location: https://neueland.iserlohn-fortress.net/cgit/smolbote
+ *
+ * SPDX-License-Identifier: GPL-3.0
+ */
+
+#include "applicationstyle.h"
+#include "poi_icons.h"
+#include "poi_logos.h"
+#include <QPainter>
+#include <QStyleFactory>
+#include <QSvgRenderer>
+#include <spdlog/spdlog.h>
+
+[[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;
+}
+
+ApplicationStyle::ApplicationStyle()
+ : QProxyStyle(QStyleFactory::create("fusion"))
+{
+}
+
+QIcon ApplicationStyle::standardIcon(QStyle::StandardPixmap standardPixmap, const QStyleOption *opt, const QWidget *w) const
+{
+ using namespace std::literals;
+
+ if(standardPixmap == 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;
+ }
+
+ const auto id = [standardPixmap]() {
+ switch(standardPixmap) {
+ 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;
+ }
+ }();
+
+ const auto *const data = std::find_if(icons::entries.begin(), icons::entries.end(), [id](const auto &tuple) -> bool {
+ return std::get<0>(tuple) == id;
+ });
+
+ if(data == icons::entries.end()) {
+ spdlog::error("fixme: getting default fusion icon for StandardPixmap({})", standardPixmap);
+ return QStyleFactory::create("fusion")->standardIcon(standardPixmap, opt, w);
+ }
+
+ const auto d = std::get<1>(*data);
+ return QIcon(render(d));
+}
+
+QIcon ApplicationStyle::applicationIcon()
+{
+ using namespace std::literals;
+ constexpr auto d = logos::get([]{ return "poi.svg"sv; });
+ return QIcon(render(d));
+}
+
+QIcon ApplicationStyle::windowIcon()
+{
+ using namespace std::literals;
+ constexpr auto d = logos::get([]{ return "poi_window.svg"sv; });
+ return QIcon(render(d));
+}
diff --git a/src/autogen/applicationstyle.h b/src/autogen/applicationstyle.h
new file mode 100644
index 0000000..f9bf1bd
--- /dev/null
+++ b/src/autogen/applicationstyle.h
@@ -0,0 +1,26 @@
+/*
+ * This file is part of smolbote. It's copyrighted by the contributors recorded
+ * in the version control history of the file, available from its original
+ * location: https://neueland.iserlohn-fortress.net/cgit/smolbote
+ *
+ * SPDX-License-Identifier: GPL-3.0
+ */
+
+#ifndef SMOLBOTE_APPLICATION_STYLE_H
+#define SMOLBOTE_APPLICATION_STYLE_H
+
+#include <QProxyStyle>
+
+class ApplicationStyle : public QProxyStyle
+{
+public:
+ ApplicationStyle();
+ ~ApplicationStyle() override = default;
+
+ QIcon standardIcon(QStyle::StandardPixmap standardPixmap, const QStyleOption *opt, const QWidget *widget) const override;
+
+ static QIcon applicationIcon();
+ static QIcon windowIcon();
+};
+
+#endif \ No newline at end of file
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
diff --git a/src/browser.cpp b/src/browser.cpp
index 000fd3a..232af59 100644
--- a/src/browser.cpp
+++ b/src/browser.cpp
@@ -8,6 +8,7 @@
#include "browser.h"
#include "applicationmenu.h"
+#include "applicationstyle.h"
#include "bookmarks/bookmarkswidget.h"
#include "configuration.h"
#include "downloadswidget.h"
@@ -18,7 +19,6 @@
#include "settings.h"
#include "util.h"
#include "webprofile.h"
-#include <QAction>
#include <QLibraryInfo>
#include <QPluginLoader>
#include <QTimer>
@@ -30,8 +30,9 @@
Browser::Browser(int &argc, char *argv[], bool allowSecondary)
: SingleApplication(argc, argv, allowSecondary, SingleApplication::User | SingleApplication::SecondaryNotification | SingleApplication::ExcludeAppVersion)
{
+ QApplication::setStyle(new ApplicationStyle);
setApplicationName(POI_NAME);
- setWindowIcon(Util::icon<Util::AppWindowIcon>());
+ setWindowIcon(ApplicationStyle::windowIcon());
setApplicationVersion(POI_SHORT_VERSION);
}
@@ -50,9 +51,7 @@ Browser::~Browser()
void Browser::loadConfiguration(const QString &path)
{
auto ctx = init_conf(path.toStdString());
- spdlog::info("Using configuration [{}]: {}",
- (ctx.path ? ctx.path->c_str() : "none"),
- ctx.ptr->make_global() ? "okay" : "failed");
+ spdlog::info("Using configuration [{}]: {}", (ctx.path ? ctx.path->c_str() : "none"), ctx.ptr->make_global() ? "okay" : "failed");
m_conf = std::move(ctx.ptr);
if(const auto _translation = m_conf->value<QString>("browser.translation")) {
diff --git a/src/mainwindow/widgets/navigationbar.cpp b/src/mainwindow/widgets/navigationbar.cpp
index dcb845c..f76d348 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(style()->standardIcon(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(style()->standardIcon(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(style()->standardIcon(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(style()->standardIcon(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(style()->standardIcon(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(style()->standardIcon(QStyle::SP_BrowserReload));
}