mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 15:40:19 +00:00
391beef707
This will help a lot with developing chromes for different UI frameworks where we can see which helper classes and processes are really using Qt vs just using it to get at helper data. As a bonus, remove Qt dependency from WebDriver.
68 lines
1.7 KiB
C++
68 lines
1.7 KiB
C++
/*
|
|
* 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;
|
|
|
|
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;
|
|
};
|
|
|
|
QString pixmap_cache_key(QSize const& size, QIcon::Mode mode, QIcon::State state);
|
|
|
|
Vector<NonnullRefPtr<Filter>> m_filters;
|
|
NonnullRefPtr<Gfx::TinyVGDecodedImageData> m_image_data;
|
|
unsigned m_cache_id { next_cache_id() };
|
|
};
|
|
|
|
}
|