UI/Qt: Stop using TVG icons
Draw the remaining Qt chrome icons through the existing generated icon path instead of loading TinyVG resources. Add generated folder and chevron icons for menus, the bookmarks bar, and find-in-page controls, and use the generated globe icon for bookmarks without favicons. Remove the Qt TinyVG icon engine and drop the unused TVG resources from the Qt resource file.
This commit is contained in:
parent
1516560bc6
commit
2ace898858
24 changed files with 47 additions and 242 deletions
|
|
@ -285,19 +285,19 @@
|
|||
</div>
|
||||
|
||||
<script type="module">
|
||||
// SVG export of UI/Icons/folder.tvg
|
||||
// Inline folder icon.
|
||||
const FOLDER_SVG = `
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
|
||||
<path d="M 1.96875 5.273438 C 1.523438 5.367188 1.101562 5.695312 0.890625 6.117188 L 0.773438 6.351562 L 0.773438 19.148438 L 0.914062 19.40625 C 1.054688 19.710938 1.3125 19.96875 1.640625 20.109375 L 1.851562 20.226562 L 11.179688 20.226562 C 20.390625 20.25 20.53125 20.25 20.742188 20.15625 C 21.140625 20.015625 21.46875 19.710938 21.632812 19.3125 L 21.75 19.054688 L 21.75 8.648438 L 21.609375 8.390625 C 21.46875 8.0625 21.210938 7.804688 20.90625 7.664062 L 20.648438 7.546875 L 15.960938 7.523438 L 11.25 7.5 L 10.101562 6.375 L 8.976562 5.25 L 5.554688 5.25 C 3.679688 5.25 2.0625 5.273438 1.96875 5.273438 "/>
|
||||
</svg>`;
|
||||
|
||||
// SVG export of UI/Icons/down.tvg
|
||||
// Inline expanded-folder indicator.
|
||||
const FOLDER_ARROW_DOWN_SVG = `
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor">
|
||||
<path d="M 4.5 6 L 12 13.5 L 19.5 6 L 21 9 L 12 18 L 3 9 Z M 4.5 6 "/>
|
||||
</svg>`;
|
||||
|
||||
// SVG export of UI/Icons/globe.tvg
|
||||
// Inline bookmark icon.
|
||||
const BOOKMARK_SVG = `
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor">
|
||||
<path d="M 10.96875 1.40625 C 9.234375 1.570312 7.546875 2.179688 6.09375 3.140625 C 5.507812 3.539062 4.945312 3.984375 4.453125 4.5 C 2.835938 6.117188 1.804688 8.15625 1.453125 10.476562 C 1.359375 11.132812 1.359375 12.867188 1.453125 13.523438 C 1.898438 16.523438 3.585938 19.195312 6.117188 20.882812 C 7.335938 21.703125 8.90625 22.3125 10.453125 22.546875 C 11.15625 22.640625 12.84375 22.640625 13.546875 22.546875 C 15.421875 22.265625 17.203125 21.46875 18.679688 20.296875 C 19.265625 19.804688 19.804688 19.265625 20.296875 18.679688 C 21.492188 17.203125 22.265625 15.421875 22.546875 13.546875 C 22.640625 12.84375 22.640625 11.132812 22.546875 10.453125 C 22.21875 8.203125 21.164062 6.117188 19.546875 4.5 C 19.265625 4.21875 18.984375 3.960938 18.679688 3.703125 C 17.179688 2.53125 15.398438 1.757812 13.523438 1.453125 C 13.03125 1.382812 11.460938 1.335938 10.96875 1.40625 M 12.515625 3.304688 C 12.703125 3.398438 12.867188 3.539062 13.007812 3.679688 C 14.203125 4.875 15.023438 7.476562 15.257812 10.757812 L 15.28125 11.109375 L 8.71875 11.109375 L 8.742188 10.757812 C 8.90625 8.414062 9.328125 6.539062 10.03125 5.109375 C 10.546875 4.054688 11.085938 3.421875 11.671875 3.210938 C 11.90625 3.140625 12.257812 3.164062 12.515625 3.304688 M 8.484375 4.171875 C 7.640625 5.8125 7.078125 8.25 6.9375 10.640625 L 6.914062 11.109375 L 3.1875 11.109375 L 3.210938 10.898438 C 3.304688 10.195312 3.515625 9.421875 3.796875 8.71875 C 4.242188 7.570312 4.828125 6.679688 5.765625 5.765625 C 6.328125 5.179688 6.796875 4.804688 7.453125 4.40625 C 7.828125 4.171875 8.507812 3.84375 8.601562 3.84375 C 8.625 3.84375 8.578125 3.960938 8.484375 4.171875 M 15.796875 4.007812 C 16.335938 4.265625 16.851562 4.570312 17.320312 4.921875 C 17.8125 5.296875 18.703125 6.1875 19.078125 6.679688 C 19.992188 7.921875 20.578125 9.375 20.789062 10.898438 L 20.8125 11.109375 L 17.085938 11.109375 L 17.0625 10.640625 C 16.921875 8.25 16.335938 5.8125 15.515625 4.171875 C 15.421875 3.984375 15.375 3.84375 15.398438 3.84375 C 15.421875 3.84375 15.609375 3.914062 15.796875 4.007812 M 6.9375 13.382812 C 7.078125 15.773438 7.664062 18.1875 8.484375 19.828125 C 8.578125 20.015625 8.648438 20.15625 8.648438 20.179688 C 8.648438 20.226562 7.875 19.851562 7.5 19.617188 C 6.867188 19.242188 6.28125 18.773438 5.765625 18.234375 C 5.460938 17.953125 5.179688 17.648438 4.921875 17.320312 C 4.007812 16.078125 3.421875 14.648438 3.210938 13.101562 L 3.1875 12.914062 L 6.914062 12.914062 L 6.9375 13.382812 M 15.257812 13.265625 C 15.09375 15.679688 14.625 17.671875 13.875 19.078125 C 13.289062 20.203125 12.609375 20.835938 12 20.835938 C 11.039062 20.835938 9.9375 19.265625 9.304688 16.945312 C 9.023438 15.914062 8.835938 14.671875 8.742188 13.265625 L 8.71875 12.914062 L 15.28125 12.914062 L 15.257812 13.265625 M 20.789062 13.101562 C 20.578125 14.625 19.992188 16.078125 19.078125 17.320312 C 18.914062 17.53125 18.539062 17.953125 18.234375 18.234375 C 17.71875 18.773438 17.132812 19.242188 16.5 19.617188 C 16.125 19.851562 15.351562 20.226562 15.351562 20.179688 C 15.351562 20.15625 15.421875 20.015625 15.515625 19.828125 C 16.335938 18.210938 16.921875 15.773438 17.0625 13.382812 L 17.085938 12.914062 L 20.8125 12.914062 L 20.789062 13.101562 "/>
|
||||
|
|
|
|||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
UI/Icons/up.tvg
BIN
UI/Icons/up.tvg
Binary file not shown.
|
|
@ -255,7 +255,7 @@ void BookmarksBar::rebuild()
|
|||
install_menu_event_filter(this, submenu);
|
||||
|
||||
auto* action = new QAction(title, this);
|
||||
action->setIcon(create_tvg_icon_with_theme_colors("folder", palette()));
|
||||
action->setIcon(create_chrome_icon(ChromeIcon::Folder, palette()));
|
||||
action->setProperty("id", submenu->property("id"));
|
||||
action->setProperty("type", submenu->property("type"));
|
||||
action->setProperty("target_folder_id", submenu->property("target_folder_id"));
|
||||
|
|
|
|||
|
|
@ -20,7 +20,6 @@ target_sources(ladybird PRIVATE
|
|||
StringUtils.cpp
|
||||
Tab.cpp
|
||||
TabBar.cpp
|
||||
TVGIconEngine.cpp
|
||||
WebContentView.cpp
|
||||
WindowControlButton.cpp
|
||||
ladybird.qrc
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ FindInPageWidget::FindInPageWidget(Tab* tab, WebContentView* content_view)
|
|||
|
||||
m_previous_button = new QPushButton(this);
|
||||
m_previous_button->setFixedWidth(30);
|
||||
m_previous_button->setIcon(create_tvg_icon_with_theme_colors("up", palette()));
|
||||
m_previous_button->setIcon(create_chrome_icon(ChromeIcon::ChevronUp, palette()));
|
||||
m_previous_button->setToolTip("Find Previous Match");
|
||||
m_previous_button->setFlat(true);
|
||||
connect(m_previous_button, &QPushButton::clicked, this, [this] {
|
||||
|
|
@ -51,7 +51,7 @@ FindInPageWidget::FindInPageWidget(Tab* tab, WebContentView* content_view)
|
|||
|
||||
m_next_button = new QPushButton(this);
|
||||
m_next_button->setFixedWidth(30);
|
||||
m_next_button->setIcon(create_tvg_icon_with_theme_colors("down", palette()));
|
||||
m_next_button->setIcon(create_chrome_icon(ChromeIcon::ChevronDown, palette()));
|
||||
m_next_button->setToolTip("Find Next Match");
|
||||
m_next_button->setFlat(true);
|
||||
connect(m_next_button, &QPushButton::clicked, this, [this] {
|
||||
|
|
@ -60,7 +60,7 @@ FindInPageWidget::FindInPageWidget(Tab* tab, WebContentView* content_view)
|
|||
|
||||
m_exit_button = new QPushButton(this);
|
||||
m_exit_button->setFixedWidth(30);
|
||||
m_exit_button->setIcon(create_tvg_icon_with_theme_colors("close", palette()));
|
||||
m_exit_button->setIcon(create_chrome_icon(ChromeIcon::Close, palette()));
|
||||
m_exit_button->setToolTip("Close Search Bar");
|
||||
m_exit_button->setFlat(true);
|
||||
connect(m_exit_button, &QPushButton::clicked, this, [this] {
|
||||
|
|
@ -97,9 +97,9 @@ bool FindInPageWidget::event(QEvent* event)
|
|||
{
|
||||
if (event->type() == QEvent::PaletteChange) {
|
||||
update_chrome_style();
|
||||
m_previous_button->setIcon(create_tvg_icon_with_theme_colors("up", palette()));
|
||||
m_next_button->setIcon(create_tvg_icon_with_theme_colors("down", palette()));
|
||||
m_exit_button->setIcon(create_tvg_icon_with_theme_colors("close", palette()));
|
||||
m_previous_button->setIcon(create_chrome_icon(ChromeIcon::ChevronUp, palette()));
|
||||
m_next_button->setIcon(create_chrome_icon(ChromeIcon::ChevronDown, palette()));
|
||||
m_exit_button->setIcon(create_chrome_icon(ChromeIcon::Close, palette()));
|
||||
}
|
||||
|
||||
return QWidget::event(event);
|
||||
|
|
|
|||
|
|
@ -8,7 +8,6 @@
|
|||
#include <UI/Qt/ChromeStyle.h>
|
||||
#include <UI/Qt/Icon.h>
|
||||
#include <UI/Qt/StringUtils.h>
|
||||
#include <UI/Qt/TVGIconEngine.h>
|
||||
|
||||
#include <QPainter>
|
||||
#include <QPainterPath>
|
||||
|
|
@ -29,32 +28,6 @@ QIcon load_icon_from_uri(StringView uri)
|
|||
return QIcon { path };
|
||||
}
|
||||
|
||||
static QIcon create_tvg_icon_with_theme_colors(QString const& name, QPalette const& palette, int normal_alpha, int disabled_alpha, int active_alpha, int selected_alpha)
|
||||
{
|
||||
auto path = QString(":/Icons/%1.tvg").arg(name);
|
||||
|
||||
auto* icon_engine = TVGIconEngine::from_file(path);
|
||||
VERIFY(icon_engine);
|
||||
|
||||
auto icon_filter = [](QColor color, int alpha) {
|
||||
color.setAlpha((color.alpha() * alpha) / 255);
|
||||
return [color = Color::from_bgra(color.rgba64().toArgb32())](Gfx::Color icon_color) {
|
||||
return color.with_alpha((icon_color.alpha() * color.alpha()) / 255);
|
||||
};
|
||||
};
|
||||
icon_engine->add_filter(QIcon::Mode::Normal, icon_filter(palette.color(QPalette::ColorGroup::Normal, QPalette::ColorRole::ButtonText), normal_alpha));
|
||||
icon_engine->add_filter(QIcon::Mode::Disabled, icon_filter(palette.color(QPalette::ColorGroup::Disabled, QPalette::ColorRole::ButtonText), disabled_alpha));
|
||||
icon_engine->add_filter(QIcon::Mode::Active, icon_filter(palette.color(QPalette::ColorGroup::Active, QPalette::ColorRole::ButtonText), active_alpha));
|
||||
icon_engine->add_filter(QIcon::Mode::Selected, icon_filter(palette.color(QPalette::ColorGroup::Normal, QPalette::ColorRole::ButtonText), selected_alpha));
|
||||
|
||||
return QIcon(icon_engine);
|
||||
}
|
||||
|
||||
QIcon create_tvg_icon_with_theme_colors(QString const& name, QPalette const& palette)
|
||||
{
|
||||
return create_tvg_icon_with_theme_colors(name, palette, 255, 255, 255, 255);
|
||||
}
|
||||
|
||||
static QPen chrome_icon_pen(QColor const& color, qreal width)
|
||||
{
|
||||
return QPen(color, width, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin);
|
||||
|
|
@ -187,6 +160,35 @@ static QPixmap create_chrome_icon_pixmap(ChromeIcon icon, QColor color, qreal de
|
|||
painter.drawEllipse(QRectF(4.4, 4.4, 11.2, 11.2));
|
||||
painter.drawLine(QPointF(5.5, 10.0), QPointF(14.5, 10.0));
|
||||
painter.drawArc(QRectF(7.1, 4.4, 5.8, 11.2), 90 * 16, 180 * 16);
|
||||
painter.drawArc(QRectF(7.1, 4.4, 5.8, 11.2), 270 * 16, 180 * 16);
|
||||
break;
|
||||
case ChromeIcon::Folder: {
|
||||
painter.setPen(chrome_icon_pen(color, 1.6));
|
||||
QPainterPath path;
|
||||
path.moveTo(2.8, 6.1);
|
||||
path.lineTo(7.6, 6.1);
|
||||
path.lineTo(9.2, 8.0);
|
||||
path.lineTo(17.2, 8.0);
|
||||
path.quadTo(18.0, 8.0, 18.0, 8.8);
|
||||
path.lineTo(18.0, 15.1);
|
||||
path.quadTo(18.0, 15.9, 17.2, 15.9);
|
||||
path.lineTo(2.8, 15.9);
|
||||
path.quadTo(2.0, 15.9, 2.0, 15.1);
|
||||
path.lineTo(2.0, 6.9);
|
||||
path.quadTo(2.0, 6.1, 2.8, 6.1);
|
||||
path.closeSubpath();
|
||||
painter.drawPath(path);
|
||||
break;
|
||||
}
|
||||
case ChromeIcon::ChevronUp:
|
||||
painter.setPen(chrome_icon_pen(color, 1.85));
|
||||
painter.drawLine(QPointF(5.0, 12.4), QPointF(10.0, 7.4));
|
||||
painter.drawLine(QPointF(10.0, 7.4), QPointF(15.0, 12.4));
|
||||
break;
|
||||
case ChromeIcon::ChevronDown:
|
||||
painter.setPen(chrome_icon_pen(color, 1.85));
|
||||
painter.drawLine(QPointF(5.0, 7.6), QPointF(10.0, 12.6));
|
||||
painter.drawLine(QPointF(10.0, 12.6), QPointF(15.0, 7.6));
|
||||
break;
|
||||
case ChromeIcon::WindowMinimize:
|
||||
painter.setPen(chrome_icon_pen(color, 1.65));
|
||||
|
|
@ -238,22 +240,14 @@ static QIcon create_y_offset_icon(QIcon const& source, int y_offset)
|
|||
|
||||
QIcon create_chrome_icon(ChromeIcon icon, QPalette const& palette)
|
||||
{
|
||||
auto chrome_palette = palette;
|
||||
chrome_palette.setColor(QPalette::Normal, QPalette::ButtonText, ChromeStyle::chrome_button_text(palette));
|
||||
chrome_palette.setColor(QPalette::Active, QPalette::ButtonText, ChromeStyle::chrome_button_text(palette));
|
||||
chrome_palette.setColor(QPalette::Disabled, QPalette::ButtonText, ChromeStyle::chrome_muted_text(palette));
|
||||
|
||||
if (icon == ChromeIcon::Reload)
|
||||
return create_y_offset_icon(create_tvg_icon_with_theme_colors("reload", chrome_palette), 1);
|
||||
if (icon == ChromeIcon::Globe)
|
||||
return create_y_offset_icon(create_tvg_icon_with_theme_colors("globe", chrome_palette, 202, 96, 236, 236), 1);
|
||||
|
||||
auto normal = ChromeStyle::chrome_button_text(palette);
|
||||
auto normal_alpha = 216;
|
||||
if (icon == ChromeIcon::Close)
|
||||
normal_alpha = 172;
|
||||
else if (icon == ChromeIcon::Star)
|
||||
normal_alpha = 204;
|
||||
else if (icon == ChromeIcon::Globe || icon == ChromeIcon::Search || icon == ChromeIcon::Menu)
|
||||
normal_alpha = 196;
|
||||
normal.setAlpha(normal_alpha);
|
||||
|
||||
auto active = ChromeStyle::chrome_button_text(palette);
|
||||
|
|
|
|||
|
|
@ -28,6 +28,9 @@ enum class ChromeIcon {
|
|||
StarFilled,
|
||||
Search,
|
||||
Globe,
|
||||
Folder,
|
||||
ChevronUp,
|
||||
ChevronDown,
|
||||
WindowMinimize,
|
||||
WindowMaximize,
|
||||
WindowRestore,
|
||||
|
|
@ -37,7 +40,6 @@ enum class ChromeIcon {
|
|||
constexpr inline auto ICON_DEVICE_PIXEL_RATIOS = to_array({ 1, 2, 3 });
|
||||
|
||||
QIcon load_icon_from_uri(StringView);
|
||||
QIcon create_tvg_icon_with_theme_colors(QString const& name, QPalette const& palette);
|
||||
QIcon create_chrome_icon(ChromeIcon, QPalette const&);
|
||||
QIcon loading_spinner_icon(QPalette const& palette, int frame);
|
||||
|
||||
|
|
|
|||
|
|
@ -196,7 +196,7 @@ static void initialize_native_control(WebView::Action& action, QAction& qaction,
|
|||
if (auto icon = action.base64_png_icon(); icon.has_value())
|
||||
qaction.setIcon(icon_from_base64_png(*icon));
|
||||
else
|
||||
qaction.setIcon(create_tvg_icon_with_theme_colors("globe", palette));
|
||||
qaction.setIcon(create_chrome_icon(ChromeIcon::Globe, palette));
|
||||
break;
|
||||
|
||||
case WebView::ActionID::OpenProcessesPage:
|
||||
|
|
@ -260,7 +260,7 @@ static void add_items_to_menu(QMenu& qmenu, QWidget& parent, WebView::Menu& menu
|
|||
add_items_to_menu(*qsubmenu, parent, submenu);
|
||||
|
||||
if (submenu->render_group_icon())
|
||||
qsubmenu->setIcon(create_tvg_icon_with_theme_colors("folder", parent.palette()));
|
||||
qsubmenu->setIcon(create_chrome_icon(ChromeIcon::Folder, parent.palette()));
|
||||
|
||||
add_properties(*qsubmenu, *submenu);
|
||||
qmenu.addMenu(qsubmenu);
|
||||
|
|
|
|||
|
|
@ -1,108 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2023, MacDue <macdue@dueutil.tech>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include <AK/MemoryStream.h>
|
||||
#include <AK/String.h>
|
||||
#include <LibGfx/Rect.h>
|
||||
#include <UI/Qt/Icon.h>
|
||||
#include <UI/Qt/StringUtils.h>
|
||||
#include <UI/Qt/TVGIconEngine.h>
|
||||
|
||||
#include <QFile>
|
||||
#include <QImage>
|
||||
#include <QPainter>
|
||||
#include <QPixmapCache>
|
||||
|
||||
namespace Ladybird {
|
||||
|
||||
void TVGIconEngine::paint(QPainter* qpainter, QRect const& rect, QIcon::Mode mode, QIcon::State state)
|
||||
{
|
||||
auto device_pixel_ratio = qpainter->device() ? qpainter->device()->devicePixelRatioF() : 1.0;
|
||||
auto physical_size = physical_size_for_device_pixel_ratio(rect.size(), device_pixel_ratio);
|
||||
qpainter->drawPixmap(rect, render_pixmap(physical_size, device_pixel_ratio, mode, state));
|
||||
}
|
||||
|
||||
QIconEngine* TVGIconEngine::clone() const
|
||||
{
|
||||
return new TVGIconEngine(*this);
|
||||
}
|
||||
|
||||
QPixmap TVGIconEngine::pixmap(QSize const& size, QIcon::Mode mode, QIcon::State state)
|
||||
{
|
||||
return render_pixmap(size, 1.0, mode, state);
|
||||
}
|
||||
|
||||
QPixmap TVGIconEngine::scaledPixmap(QSize const& size, QIcon::Mode mode, QIcon::State state, qreal scale)
|
||||
{
|
||||
auto device_pixel_ratio = scale > 0.0 ? scale : 1.0;
|
||||
#if QT_VERSION < QT_VERSION_CHECK(6, 8, 0)
|
||||
auto physical_size = size;
|
||||
#else
|
||||
auto physical_size = physical_size_for_device_pixel_ratio(size, device_pixel_ratio);
|
||||
#endif
|
||||
return render_pixmap(physical_size, device_pixel_ratio, mode, state);
|
||||
}
|
||||
|
||||
QPixmap TVGIconEngine::render_pixmap(QSize physical_size, qreal device_pixel_ratio, QIcon::Mode mode, QIcon::State state)
|
||||
{
|
||||
QPixmap pixmap;
|
||||
auto key = pixmap_cache_key(physical_size, device_pixel_ratio, mode, state);
|
||||
if (QPixmapCache::find(key, &pixmap))
|
||||
return pixmap;
|
||||
auto bitmap = MUST(m_image_data->bitmap({ physical_size.width(), physical_size.height() }));
|
||||
|
||||
for (auto const& filter : m_filters) {
|
||||
if (filter->mode() == mode) {
|
||||
for (int y = 0; y < bitmap->height(); ++y) {
|
||||
for (int x = 0; x < bitmap->width(); ++x) {
|
||||
auto original_color = bitmap->get_pixel(x, y);
|
||||
auto filtered_color = filter->function()(original_color);
|
||||
bitmap->set_pixel(x, y, filtered_color);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
QImage qimage(
|
||||
bitmap->scanline_u8(0),
|
||||
bitmap->width(),
|
||||
bitmap->height(),
|
||||
static_cast<qsizetype>(bitmap->pitch()),
|
||||
QImage::Format::Format_ARGB32);
|
||||
|
||||
pixmap = QPixmap::fromImage(qimage);
|
||||
pixmap.setDevicePixelRatio(device_pixel_ratio);
|
||||
if (!pixmap.isNull())
|
||||
QPixmapCache::insert(key, pixmap);
|
||||
return pixmap;
|
||||
}
|
||||
|
||||
QString TVGIconEngine::pixmap_cache_key(QSize physical_size, qreal device_pixel_ratio, QIcon::Mode mode, QIcon::State state)
|
||||
{
|
||||
return qformatted("$sernity_tvgicon_{}_{}x{}_dpr{}_{}_{}",
|
||||
m_cache_id, physical_size.width(), physical_size.height(), static_cast<int>(device_pixel_ratio * 1000), to_underlying(mode), to_underlying(state));
|
||||
}
|
||||
|
||||
void TVGIconEngine::add_filter(QIcon::Mode mode, Function<Color(Color)> filter)
|
||||
{
|
||||
m_filters.empend(adopt_ref(*new Filter(mode, move(filter))));
|
||||
invalidate_cache();
|
||||
}
|
||||
|
||||
TVGIconEngine* TVGIconEngine::from_file(QString const& path)
|
||||
{
|
||||
QFile icon_resource(path);
|
||||
if (!icon_resource.open(QIODeviceBase::ReadOnly))
|
||||
return nullptr;
|
||||
auto icon_data = icon_resource.readAll();
|
||||
FixedMemoryStream icon_bytes { ReadonlyBytes { icon_data.data(), static_cast<size_t>(icon_data.size()) } };
|
||||
if (auto tvg = Gfx::TinyVGDecodedImageData::decode(icon_bytes); !tvg.is_error())
|
||||
return new TVGIconEngine(tvg.release_value());
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,69 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2023, MacDue <macdue@dueutil.tech>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <AK/Function.h>
|
||||
#include <AK/RefCounted.h>
|
||||
#include <AK/Vector.h>
|
||||
#include <LibGfx/ImageFormats/TinyVGLoader.h>
|
||||
|
||||
#include <QIconEngine>
|
||||
|
||||
namespace Ladybird {
|
||||
|
||||
class TVGIconEngine : public QIconEngine {
|
||||
public:
|
||||
TVGIconEngine(Gfx::TinyVGDecodedImageData const& image_data)
|
||||
: m_image_data(image_data)
|
||||
{
|
||||
}
|
||||
|
||||
static TVGIconEngine* from_file(QString const& path);
|
||||
|
||||
void paint(QPainter* painter, QRect const& rect, QIcon::Mode mode, QIcon::State state) override;
|
||||
QIconEngine* clone() const override;
|
||||
QPixmap pixmap(QSize const& size, QIcon::Mode mode, QIcon::State state) override;
|
||||
QPixmap scaledPixmap(QSize const& size, QIcon::Mode mode, QIcon::State state, qreal scale) override;
|
||||
|
||||
void add_filter(QIcon::Mode mode, Function<Color(Color)> filter);
|
||||
|
||||
private:
|
||||
static unsigned next_cache_id()
|
||||
{
|
||||
static unsigned cache_id = 0;
|
||||
return cache_id++;
|
||||
}
|
||||
|
||||
void invalidate_cache()
|
||||
{
|
||||
m_cache_id = next_cache_id();
|
||||
}
|
||||
|
||||
class Filter : public RefCounted<Filter> {
|
||||
public:
|
||||
Filter(QIcon::Mode mode, Function<Color(Color)> function)
|
||||
: m_mode(mode)
|
||||
, m_function(move(function))
|
||||
{
|
||||
}
|
||||
QIcon::Mode mode() const { return m_mode; }
|
||||
Function<Color(Color)> const& function() const { return m_function; }
|
||||
|
||||
private:
|
||||
QIcon::Mode m_mode;
|
||||
Function<Color(Color)> m_function;
|
||||
};
|
||||
|
||||
QPixmap render_pixmap(QSize physical_size, qreal device_pixel_ratio, QIcon::Mode mode, QIcon::State state);
|
||||
QString pixmap_cache_key(QSize physical_size, qreal device_pixel_ratio, QIcon::Mode mode, QIcon::State state);
|
||||
|
||||
Vector<NonnullRefPtr<Filter>> m_filters;
|
||||
NonnullRefPtr<Gfx::TinyVGDecodedImageData const> m_image_data;
|
||||
unsigned m_cache_id { next_cache_id() };
|
||||
};
|
||||
|
||||
}
|
||||
|
|
@ -151,7 +151,7 @@ Tab::Tab(BrowserWindow* window, RefPtr<WebView::WebContentClient> parent_client,
|
|||
m_hamburger_button = new HamburgerButton(m_toolbar);
|
||||
m_hamburger_button->setText("Show &Menu");
|
||||
m_hamburger_button->setToolTip("Show Menu");
|
||||
m_hamburger_button->setIcon(create_tvg_icon_with_theme_colors("hamburger", palette()));
|
||||
m_hamburger_button->setIcon(create_chrome_icon(ChromeIcon::Menu, palette()));
|
||||
m_hamburger_button->setIconSize({ 20, 20 });
|
||||
m_hamburger_button->setFixedSize(36, 36);
|
||||
m_hamburger_button->setAutoRaise(true);
|
||||
|
|
|
|||
|
|
@ -1,18 +1,5 @@
|
|||
<!DOCTYPE RCC><RCC version="1.0">
|
||||
<qresource>
|
||||
<file>../Icons/ladybird.png</file>
|
||||
<file>../Icons/back.tvg</file>
|
||||
<file>../Icons/close.tvg</file>
|
||||
<file>../Icons/folder.tvg</file>
|
||||
<file>../Icons/forward.tvg</file>
|
||||
<file>../Icons/globe.tvg</file>
|
||||
<file>../Icons/hamburger.tvg</file>
|
||||
<file>../Icons/new_tab.tvg</file>
|
||||
<file>../Icons/reload.tvg</file>
|
||||
<file>../Icons/search.tvg</file>
|
||||
<file>../Icons/star-countour.tvg</file>
|
||||
<file>../Icons/star-filled.tvg</file>
|
||||
<file>../Icons/up.tvg</file>
|
||||
<file>../Icons/down.tvg</file>
|
||||
</qresource>
|
||||
</RCC>
|
||||
|
|
|
|||
Loading…
Reference in a new issue