34#include <NDEVR/SoftwareService.h>
35#include <NDEVR/Buffer.h>
36#include <NDEVR/String.h>
37#include <NDEVR/File.h>
38#include <NDEVR/Dictionary.h>
39#include <NDEVR/RGBColor.h>
40#include <NDEVR/LABColor.h>
41#include <NDEVR/Resource.h>
42#include <NDEVR/TranslatedString.h>
43#include <NDEVR/UUID.h>
44#include <NDEVR/Pointer.h>
45#include <qiconengine.h>
69 struct NDEVR_WIDGETS_API IconThemeSettings
89 UUID id = Constant<UUID>::Invalid;
98 bool operator==(
const IconThemeSettings& settings)
const;
99 bool operator!=(
const IconThemeSettings& settings)
const;
138 [[nodiscard]]
UUID id()
const {
return m_id; }
173 virtual void paint(QPainter* painter,
const QRect& rect, QIcon::Mode mode, QIcon::State state)
override;
181 virtual QPixmap
pixmap(
const QSize& size, QIcon::Mode mode, QIcon::State state)
override;
186 virtual QIconEngine*
clone(
void)
const override;
194 QSize
actualSize(
const QSize& size, QIcon::Mode mode, QIcon::State state)
override;
244 friend class NDEVRSVGIconEngine;
245 friend class DeferredImageIconEngine;
310 static bool RequestSet(
const StringView& pixmap_resource, QPixmap map, QIcon::Mode mode = QIcon::Mode::Normal);
352 static void ConvertColorTheme(
const Buffer<std::pair<RGBColor, RGBColor>>& colors,
const File& in_location,
const File& out_location,
bool preserve_brightness,
bool preserve_alpha,
Log* log =
nullptr);
360 static void ConvertColorTheme(
const Buffer<std::pair<LABColor, LABColor>>& color, QImage& image,
bool preserve_brightness,
bool preserve_alpha);
368 static QImage
AutoCrop(
const QImage&
pixmap,
int margin = 0,
bool preserve_ratio =
false);
479 static QPixmap
pixmap(
const StringView&
pixmap, QIcon::Mode mode = QIcon::Mode::Normal,
const QSize& requested_size = QSize());
The equivelent of std::vector but with a bit more control.
QPixmap m_cached_pixmap
Cached pixmap to avoid redundant rendering.
virtual QPixmap pixmap(const QSize &size, QIcon::Mode mode, QIcon::State state) override
Returns a pixmap for the icon at the specified size, mode, and state.
void setIcon(const StringView &icon)
Changes the icon resource identifier.
virtual QIconEngine * clone(void) const override
Creates a copy of this icon engine.
virtual void paint(QPainter *painter, const QRect &rect, QIcon::Mode mode, QIcon::State state) override
Paints the icon into the given rectangle using the specified painter.
String m_icon
The icon resource identifier.
DeferredImageIconEngine(const StringView &icon, QIcon::Mode mode=QIcon::Mode::Normal)
Constructs a deferred icon engine that delays resource loading until paint time.
QSize actualSize(const QSize &size, QIcon::Mode mode, QIcon::State state) override
Returns the actual rendered size for the given constraints.
void setIconTheme(const IconThemeSettings theme)
Sets the icon theme to use for rendering.
QIcon::Mode m_override_mode
The icon mode override for rendering.
QSize m_default_size
The default size determined from the icon resource.
A hash-based key-value store, useful for quick associative lookups.
Provides a modifiable pointer that has shared ownership of a dynamically allocated object.
Logic for reading or writing to a file as well as navigating filesystems or other common file operati...
A color defined by hue, saturation, and brightness components.
Serves as the primary program interface for processes to report issues and allows any number of LogSt...
Used to render any icons or fetch any pixmaps within the software.
virtual bool canProcess(const StringView &icon, const IconThemeSettings &theme, QIcon::Mode mode) const =0
Checks whether this engine can render the specified icon.
virtual QIcon createIcon(const StringView &icon, const IconThemeSettings &theme, QIcon::Mode mode=QIcon::Mode::Normal)=0
Creates a QIcon for the specified icon resource and theme.
UUID id() const
Returns the unique identifier for this icon engine.
NDEVRIconEngine(const UUID &id)
Constructs an icon engine with the given unique identifier.
Base class for logic that can be used to resolve a Pixmap resource and turn it into a QPixmap for use...
virtual UUID id() const =0
Returns the unique identifier for this resolver.
virtual QPixmap resolve(const StringView &pixmap_resource, QIcon::Mode mode, const QSize &requested_size, Dictionary< UUID, QPixmap > &pixmaps)=0
Resolves a pixmap resource identifier into a QPixmap.
virtual bool requestSet(const StringView &pixmap_resource, QPixmap map, QIcon::Mode mode)=0
Requests that a pixmap be stored for the given resource identifier.
virtual bool canPotentiallyResolve(const StringView &pixmap_resource)=0
Checks whether this resolver can potentially resolve the given pixmap resource.
Manages all Icons and Pixmaps used by the UI in the NDEVR Engine.
static const QPixmap & disabledPixmap(const StringView &icon_name)
Returns a cached disabled (grayed-out) version of the given icon.
static void ConvertColorTheme(const Buffer< std::pair< LABColor, LABColor > > &color, QImage &image, bool preserve_brightness, bool preserve_alpha)
Applies a LAB color theme conversion directly to a QImage.
static QImage AutoCrop(const QImage &pixmap, int margin=0, bool preserve_ratio=false)
Removes transparent borders from an image, optionally adding a margin.
static void SetLightingTheme(const IconThemeSettings &theme)
Sets the user's icon theme.
static void ConvertColorTheme(const Buffer< std::pair< RGBColor, RGBColor > > &colors, const Buffer< File > &in, const File &out_location, bool preserve_brightness, bool preserve_alpha, Log *log=nullptr)
Converts a set of icon files from one color theme to another.
static Resource< IconThemeSettings > s_icon_theme
Resource holding the user's selected icon theme.
static QImage FillBackground(const QImage &pixmap, RGBColor color)
Fills the transparent background of an image with the specified color.
static QIcon icon(const StringView &icon, const IconThemeSettings &theme, QIcon::Mode mode=QIcon::Mode::Normal)
Resolves an icon using a specific theme.
static void ConvertColorTheme(const Buffer< std::pair< RGBColor, RGBColor > > &colors, const File &in_location, const File &out_location, bool preserve_brightness, bool preserve_alpha, Log *log=nullptr)
Converts icon files at a given location from one color theme to another.
static String ImageCacheLocation(const StringView &icon)
Returns the cache file path for a rendered image.
static void AddResolver(PixmapResolver *resolver)
Registers a pixmap resolver for resolving custom pixmap resources.
static QIcon GetIconResourceBlocking(const StringView &icon, const IconThemeSettings &theme, QIcon::Mode mode=QIcon::Mode::Normal)
Synchronously fetches an icon resource using a specific theme.
static void SetOverrideTheme(IconThemeSettings *theme)
Sets a temporary override theme that takes precedence over the user's saved theme.
static void GetIconResource(const std::function< void(const StringView &, const QIcon &)> &on_finished, const StringView &icon, const IconThemeSettings &theme, QIcon::Mode mode=QIcon::Mode::Normal)
Asynchronously fetches an icon resource using a specific theme, invoking the callback when ready.
static Resource< IconThemeSettings * > s_overide_icon_theme
Resource holding the override icon theme pointer.
static QPixmap LocalPixmapResource(const StringView &pixmap, QIcon::Mode mode=QIcon::Mode::Normal, const QSize &requested_size=QSize())
Synchronously resolves a local pixmap resource.
static void SetWindowIcon(const StringView &s, QWidget *widget)
Sets the window icon for a widget to the specified icon resource.
static const IconThemeSettings & EffectiveIconTheme()
Returns the currently effective icon theme, accounting for any overrides.
static QPixmap pixmap(const StringView &pixmap, QIcon::Mode mode=QIcon::Mode::Normal, const QSize &requested_size=QSize())
Resolves a pixmap resource.
static void addIconTheme(const IconThemeSettings &theme)
Registers a new icon theme.
static const IconThemeSettings & NDEVRIconTheme()
Returns the default NDEVR icon theme.
static String GetSVGPath(const StringView &icon, const IconThemeSettings &theme)
Returns the file path to an SVG icon resource for the given theme.
static constexpr const char * NDEVRThemeLocation()
Returns the file path prefix for the default NDEVR icon theme resources.
static String IconCacheLocation(const StringView &icon, const IconThemeSettings &theme)
Returns the cache file path for a rendered icon.
static void ClearWindowIcon(QWidget *widget)
Clears the window icon previously set on a widget.
static QIcon icon(const StringView &icon, QIcon::Mode mode=QIcon::Mode::Normal)
Resolves an icon using the current theme.
static bool RequestSet(const StringView &pixmap_resource, QPixmap map, QIcon::Mode mode=QIcon::Mode::Normal)
Stores a pixmap for the given resource identifier in available resolvers.
static void GetPixmapResource(const std::function< void(const StringView &, const QPixmap &)> &on_finished, const StringView &pixmap, QIcon::Mode mode=QIcon::Mode::Normal, const QSize &requested_size=QSize())
Asynchronously fetches a pixmap resource, invoking the callback when ready.
static void PostIconResourceLoad(const StringView &id)
Notifies any pending callbacks that an icon resource has finished loading.
static void GetIconResource(const std::function< void(const StringView &, const QIcon &)> &on_finished, const StringView &icon, QIcon::Mode mode=QIcon::Mode::Normal)
Asynchronously fetches an icon resource using the current theme, invoking the callback when ready.
static QIcon GetIconResourceBlocking(const StringView &icon, QIcon::Mode mode=QIcon::Mode::Normal)
Synchronously fetches an icon resource using the current theme.
static const Buffer< IconThemeSettings > & iconThemes()
Returns all registered icon themes.
static File GetImagePath(const StringView &icon)
Returns the file path for an image resource.
static Buffer< std::pair< LABColor, LABColor > > ConvertColorPalette(const Buffer< std::pair< RGBColor, RGBColor > > &palette)
Converts an RGB color palette to LAB color space for perceptual color operations.
static const IconThemeSettings & OutlineIconTheme()
Returns the built-in outline icon theme.
static void AddIconEngine(NDEVRIconEngine *engine)
Registers an icon rendering engine.
static QImage CleanupImageForIcon(const QImage &image)
Cleans up an image to make it suitable for use as an icon.
Represents a color in the RGB space with optional alpha transparency.
A core part of the engine, stores variables that can be listened to with ResourceListener which will ...
Software Service Managers take a Software service to modify the behavior of the software.
Base interface for services that extend or modify software behavior through modules.
Logic for reading or writing to a string or a user friendly, TranslatedString.
The core String View class for the NDEVR API.
The core String class for the NDEVR API.
Any text displayed to the user should be defined as a TranslatedString which allows the program to lo...
A universally unique identifier (UUID) is a 128-bit number used to identify information in computer s...
The primary namespace for the NDEVR SDK.
double fltp08
Defines an alias representing an 8 byte floating-point number.
@ icon
Icon identifier for the object.
Stores display information for how to draw icons, when supported.
String theme_icon_location
The file or resource path where the theme icon is located.
TranslatedString theme_name
The user-facing translated name of the icon theme.
String theme_icon
The icon resource identifier for the theme preview.
Stores information for how to draw icons, when supported.
void setup(const TranslatedString &name, const StringView &theme_icon, const StringView &theme_icon_location)
Configures the display settings for this icon theme.
IconThemeDisplaySettings & displaySettings()
Returns a mutable reference to the display settings for this theme.
fltp08 pixel_size
Default pixel size for rendered icons.
RGBColor primary_color
Primary color applied to icon rendering.
bool blend_color
Whether to blend theme colors when colorizing icons.
RGBColor accent_color
Accent color for icon highlights and emphasis.
RGBColor outline_color
Color used for icon outlines and borders.
RGBColor highlight_color
Color used for highlighted or selected icon elements.
RGBColor secondary_color
Secondary color applied to icon rendering.
bool colorize_svgs
Whether to apply theme colors to SVG icons.
const IconThemeDisplaySettings & displaySettings() const
Returns a const reference to the display settings for this theme.