From 7965f73b64018bbac155c4e2c3208350dae69954 Mon Sep 17 00:00:00 2001 From: Aqua-sama Date: Fri, 6 Nov 2020 20:44:12 +0200 Subject: Remove data/resources.qrc --- src/about/aboutdialog.cpp | 17 ++------ src/browser.cpp | 6 +-- src/meson.build | 13 ++++--- src/util.h | 98 +++++++++++++++++++++++++++++------------------ 4 files changed, 74 insertions(+), 60 deletions(-) (limited to 'src') diff --git a/src/about/aboutdialog.cpp b/src/about/aboutdialog.cpp index 894b1ec..f42d551 100644 --- a/src/about/aboutdialog.cpp +++ b/src/about/aboutdialog.cpp @@ -7,6 +7,7 @@ */ #include "aboutdialog.h" +#include "../poi_logos.h" #include "ui_aboutdialog.h" #include @@ -26,18 +27,11 @@ AboutDialog::AboutDialog(QWidget *parent) : QDialog(parent) , ui(new Ui::AboutDialog) { - //setAttribute(Qt::WA_DeleteOnClose, true); + setAttribute(Qt::WA_DeleteOnClose, true); ui->setupUi(this); - const QByteArray icon_svg = R"SVG( - - - - - - -)SVG"; - ui->appIcon_svg->load(icon_svg); + constexpr auto icon_svg = logos::get([] { return std::string_view("poi_window.svg"); }); + ui->appIcon_svg->load(QByteArray(icon_svg.data(), icon_svg.size())); ui->appName_label->setText(qApp->applicationName()); ui->appVersion_label->setText(qApp->applicationVersion()); @@ -66,9 +60,6 @@ AboutDialog::AboutDialog(QWidget *parent) "
  • spdlog
  • " "
  • args.hxx
  • " "
  • SingleApplication
  • " -#ifdef CONFIG_USEBREAKPAD - "
  • Breakpad
  • " -#endif "

    ")); } diff --git a/src/browser.cpp b/src/browser.cpp index a04f87d..aec3ad1 100644 --- a/src/browser.cpp +++ b/src/browser.cpp @@ -38,7 +38,7 @@ Browser::Browser(int &argc, char *argv[], bool allowSecondary) Configuration conf; setApplicationName(conf.value("poi.name").value()); - setWindowIcon(QIcon(conf.value("poi.icon").value())); + setWindowIcon(Util::icon()); setApplicationVersion(QVersionNumber::fromString(QLatin1String(poi_Version)).toString()); if(const auto _translation = conf.value("browser.translation")) { @@ -128,8 +128,8 @@ Browser::~Browser() void Browser::about() { - auto *dlg = new AboutDialog; - dlg->exec(); + auto *dlg = new AboutDialog(activeWindow()); + dlg->show(); } void Browser::aboutPlugins() diff --git a/src/meson.build b/src/meson.build index 062dae4..f3ef381 100644 --- a/src/meson.build +++ b/src/meson.build @@ -10,11 +10,14 @@ poi_settings_h = custom_target('default_config_value', command: [ python3, '@INPUT0@', '--kconfig=@INPUT1@', '--dotconfig=@INPUT2@', '--input=@INPUT3@', '--output=@OUTPUT@' ] ) +poi_logos_h = custom_target('poi_logos_h', + input: files('../data/poi.svg', '../data/poi_window.svg'), + output: 'poi_logos.h', + command: [ python3, rcc_exe, '-o=@OUTPUT@', 'dump', '-ns=logos', '@INPUT@' ]) poi_icons_h = custom_target('poi_icons_h', input: icons, - output: 'icons.h', - command: [ python3, rcc_exe, '-o=@OUTPUT@', 'dump', '-ns=icons', '@INPUT@' ] -) + output: 'poi_icons.h', + command: [ python3, rcc_exe, '-o=@OUTPUT@', 'dump', '-ns=icons', '@INPUT@' ]) subdir('about') subdir('webengine') @@ -29,8 +32,6 @@ poi_sourceset.add(mod_qt5.preprocess( 'mainwindow/addressbar.ui', 'mainwindow/widgets/searchform.ui', 'bookmarks/bookmarksform.ui', 'bookmarks/editbookmarkdialog.ui', 'session/savesessiondialog.ui', 'session/sessiondialog.ui' ], - qresources: '../data/resources.qrc', - rcc_extra_arguments: ['--format-version=1'], dependencies: dep_qt5 )) @@ -57,6 +58,6 @@ poi_sourceset.add(files( 'subwindow/subwindow.cpp', 'subwindow/tabwidget.cpp', ), - version_h, poi_settings_h, poi_icons_h + version_h, poi_settings_h, poi_icons_h, poi_logos_h ) diff --git a/src/util.h b/src/util.h index 6882854..8431a5b 100644 --- a/src/util.h +++ b/src/util.h @@ -9,7 +9,8 @@ #ifndef SMOLBOTE_UTIL_H #define SMOLBOTE_UTIL_H -#include "icons.h" +#include "poi_icons.h" +#include "poi_logos.h" #include #include #include @@ -20,53 +21,74 @@ namespace Util { const QStringList files(const QString &location, const QStringList &nameFilters = QStringList()); -template -inline QIcon icon() +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()) { - using namespace std::literals; + QSvgRenderer renderer; + renderer.load(QByteArray(data.data(), static_cast(data.size()))); - 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; - } - }); + QPixmap pm(size.isValid() ? size : renderer.defaultSize()); + pm.fill(Qt::transparent); - QIcon m; + QPainter painter(&pm); + renderer.render(&painter, pm.rect()); - // 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. + return pm; +} - 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"))); +template +inline QIcon icon() +{ + using namespace std::literals; + + 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 { - QPixmap pm(renderer.defaultSize()); - pm.fill(Qt::transparent); + 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; + } + }); - QPainter painter(&pm); - painter.setBrush(Qt::green); - painter.setPen(Qt::green); - renderer.render(&painter, pm.rect()); + 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. - m.addPixmap(pm, mode, toggle); + 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; } - return m; } } // namespace Util -- cgit v1.2.1