2023-11-05 12:45:43 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2023, Tim Flynn <trflynn89@serenityos.org>
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <LibCore/Resource.h>
|
2024-11-09 17:50:33 +00:00
|
|
|
#include <UI/Qt/Icon.h>
|
|
|
|
#include <UI/Qt/StringUtils.h>
|
|
|
|
#include <UI/Qt/TVGIconEngine.h>
|
|
|
|
|
2024-04-03 01:35:07 +00:00
|
|
|
#include <QPalette>
|
2023-11-05 12:45:43 +00:00
|
|
|
|
|
|
|
namespace Ladybird {
|
|
|
|
|
|
|
|
QIcon load_icon_from_uri(StringView uri)
|
|
|
|
{
|
|
|
|
auto resource = MUST(Core::Resource::load_from_uri(uri));
|
|
|
|
auto path = qstring_from_ak_string(resource->filesystem_path());
|
|
|
|
|
|
|
|
return QIcon { path };
|
|
|
|
}
|
|
|
|
|
2024-04-03 01:35:07 +00:00
|
|
|
QIcon create_tvg_icon_with_theme_colors(QString const& name, QPalette const& palette)
|
|
|
|
{
|
|
|
|
auto path = QString(":/Icons/%1.tvg").arg(name);
|
|
|
|
|
|
|
|
auto* icon_engine = TVGIconEngine::from_file(path);
|
|
|
|
VERIFY(icon_engine);
|
|
|
|
|
|
|
|
auto icon_filter = [](QColor color) {
|
|
|
|
return [color = Color::from_argb(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)));
|
|
|
|
icon_engine->add_filter(QIcon::Mode::Disabled, icon_filter(palette.color(QPalette::ColorGroup::Disabled, QPalette::ColorRole::ButtonText)));
|
2024-07-22 16:39:41 +00:00
|
|
|
icon_engine->add_filter(QIcon::Mode::Active, icon_filter(palette.color(QPalette::ColorGroup::Active, QPalette::ColorRole::ButtonText)));
|
|
|
|
icon_engine->add_filter(QIcon::Mode::Selected, icon_filter(palette.color(QPalette::ColorGroup::Normal, QPalette::ColorRole::ButtonText)));
|
2024-04-03 01:35:07 +00:00
|
|
|
|
|
|
|
return QIcon(icon_engine);
|
|
|
|
}
|
|
|
|
|
2023-11-05 12:45:43 +00:00
|
|
|
}
|