1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 14:17:45 +00:00

Ladybird: Replace forward/back/reload SVGs with TVGs

Doing this removes the qt6-svg dependency and allows our rasterizer to
be used for these little icons (and happens to be a fair bit smaller
than the old SVGs).
This commit is contained in:
MacDue 2023-07-02 22:37:59 +01:00 committed by Jelle Raaijmakers
parent bb5db0835d
commit dfcd7b3ca5
10 changed files with 28 additions and 175 deletions

View file

@ -13,6 +13,7 @@
#include "Utilities.h"
#include <Browser/History.h>
#include <LibGfx/ImageFormats/BMPWriter.h>
#include <LibGfx/Painter.h>
#include <QClipboard>
#include <QCoreApplication>
#include <QCursor>
@ -27,30 +28,31 @@
#include <QPlainTextEdit>
#include <QPoint>
#include <QResizeEvent>
#include <QSvgRenderer>
extern DeprecatedString s_serenity_resource_root;
extern Browser::Settings* s_settings;
static QIcon render_svg_icon_with_theme_colors(QString name, QPalette const& palette)
static QIcon render_tvg_icon_with_theme_colors(QString name, QPalette const& palette)
{
auto path = QString(":/Icons/%1.svg").arg(name);
auto path = QString(":/Icons/%1.tvg").arg(name);
Gfx::IntSize icon_size(16, 16);
QSize icon_size(16, 16);
QFile icon_resource(path);
VERIFY(icon_resource.open(QIODeviceBase::ReadOnly));
auto icon_data = icon_resource.readAll();
ReadonlyBytes icon_bytes { icon_data.data(), static_cast<size_t>(icon_data.size()) };
auto icon_raster = MUST(Gfx::Bitmap::load_from_bytes(icon_bytes, icon_size));
QIcon icon;
auto render = [&](QColor color) -> QPixmap {
QImage image(icon_size, QImage::Format_ARGB32);
image.fill(Qt::transparent);
QPainter painter(&image);
QSvgRenderer renderer(path);
renderer.render(&painter);
painter.setBrush(color);
painter.setCompositionMode(QPainter::CompositionMode_SourceAtop);
painter.fillRect(image.rect(), color);
return QPixmap::fromImage(image);
auto image = MUST(Gfx::Bitmap::create(Gfx::BitmapFormat::BGRA8888, icon_size));
Gfx::Painter painter { image };
auto icon_color = Color::from_argb(color.rgba64().toArgb32());
painter.blit_filtered({ 0, 0 }, *icon_raster, icon_raster->rect(), [&](auto color) {
return icon_color.with_alpha((icon_color.alpha() * color.alpha()) / 255);
});
QImage qimage { image->scanline_u8(0), image->width(), image->height(), QImage::Format::Format_ARGB32 };
return QPixmap::fromImage(qimage);
};
icon.addPixmap(render(palette.color(QPalette::ColorGroup::Normal, QPalette::ColorRole::ButtonText)), QIcon::Mode::Normal);
@ -622,9 +624,9 @@ bool Tab::event(QEvent* event)
void Tab::rerender_toolbar_icons()
{
m_window->go_back_action().setIcon(render_svg_icon_with_theme_colors("back", palette()));
m_window->go_forward_action().setIcon(render_svg_icon_with_theme_colors("forward", palette()));
m_window->reload_action().setIcon(render_svg_icon_with_theme_colors("reload", palette()));
m_window->go_back_action().setIcon(render_tvg_icon_with_theme_colors("back", palette()));
m_window->go_forward_action().setIcon(render_tvg_icon_with_theme_colors("forward", palette()));
m_window->reload_action().setIcon(render_tvg_icon_with_theme_colors("reload", palette()));
}
void Tab::show_inspector_window(InspectorTarget inspector_target)