API Documentation
Loading...
Searching...
No Matches
QTIconManager.h
Go to the documentation of this file.
1/*--------------------------------------------------------------------------------------------
2Copyright (c) 2019, NDEVR LLC
3tyler.parke@ndevr.org
4 __ __ ____ _____ __ __ _______
5 | \ | | | __ \ | ___|\ \ / / | __ \
6 | \ | | | | \ \ | |___ \ \ / / | |__) |
7 | . \| | | |__/ / | |___ \ V / | _ /
8 | |\ |_|_____/__|_____|___\_/____| | \ \
9 |__| \__________________________________| \__\
10
11Subject to the terms of the Enterprise+ Agreement, NDEVR hereby grants
12Licensee a limited, non-exclusive, non-transferable, royalty-free license
13(without the right to sublicense) to use the API solely for the purpose of
14Licensee's internal development efforts to develop applications for which
15the API was provided.
16
17The above copyright notice and this permission notice shall be included in all
18copies or substantial portions of the Software.
19
20THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
21INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
22PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
23FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
24OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25DEALINGS IN THE SOFTWARE.
26
27Library: Widgets
28File: QTIconManager
29Included in API: True
30Author(s): Tyler Parke
31 *-----------------------------------------------------------------------------------------**/
32#pragma once
33#include "DLLInfo.h"
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/UUID.h>
43#include <qiconengine.h>
44#include <QTransform>
45#include <QIcon>
46#include <QPointer>
47class QImage;
48class QPixmap;
49class QIcon;
50class QWidget;
51namespace NDEVR
52{
53 class Log;
54 class HSBColor;
55 /**--------------------------------------------------------------------------------------------------
56 \brief Stores information for how to draw icons, when supported.
57 **/
75
76 /**--------------------------------------------------------------------------------------------------
77 \brief Used to render any icons or fetch any pixmaps within the software. More rendering engines
78 can be added to create QIcon or QPixmap objects for given resources.
79 **/
81 {
82 public:
84 : m_id(id)
85 {}
86 [[nodiscard]] virtual QIcon createIcon(const String& icon, const IconThemeSettings& theme, QIcon::Mode mode = QIcon::Mode::Normal) = 0;
87 [[nodiscard]] virtual bool canProcess(const String& icon, const IconThemeSettings& theme, QIcon::Mode mode) const = 0;
88 [[nodiscard]] UUID id() const { return m_id; }
89 private:
90 UUID m_id;
91 };
92 /**--------------------------------------------------------------------------------------------------
93 \brief Used to render any icons when they are needed. Resources will not be consumed until draw is called.
94 **/
95 class NDEVR_WIDGETS_API DeferredImageIconEngine : public QIconEngine
96 {
97 public:
98 DeferredImageIconEngine(const String& icon, QIcon::Mode mode = QIcon::Mode::Normal);
101 virtual void paint(QPainter* painter, const QRect& rect, QIcon::Mode mode, QIcon::State state) override;
102 virtual QPixmap pixmap(const QSize& size, QIcon::Mode mode, QIcon::State state) override;
103 virtual QIconEngine* clone(void) const override;
104 QSize actualSize(const QSize& size, QIcon::Mode mode, QIcon::State state) override;
105 public:
108 QIcon::Mode m_override_mode;
109 mutable QSize m_default_size;
110 };
111 /**--------------------------------------------------------------------------------------------------
112 \brief Base class for logic that can be used to resolve a Pixmap resource and turn it into a QPixmap
113 for use by the NDEVR API.
114 **/
116 {
117 public:
118 virtual bool canPotentiallyResolve(const String& pixmap_resource) = 0;
119 virtual QPixmap resolve(const String& pixmap_resource, QIcon::Mode mode, const QSize& requested_size, Dictionary<String, QPixmap>& pixmaps) = 0;
120 virtual UUID id() const = 0;
121 };
122 /**--------------------------------------------------------------------------------------------------
123 \brief Manages all Icons and Pixmaps used by the UI in the NDEVR Engine. Icons may be fetched remotely
124 so callbacks are used to specify the action to take when the resouce is retrieved.
125 **/
127 {
128 friend class NDEVRSVGIconEngine;
130 public:
131 //Used to set the user's icon theme. Will be saved to INI files for next session
132 static void SetLightingTheme(const IconThemeSettings& theme);
133 //Used to override the user's icon specified theme
135 static void GetIconResource(const std::function<void(const String&, const QIcon&)>& on_finished, const String& icon, QIcon::Mode mode = QIcon::Mode::Normal);
136 static void GetIconResource(const std::function<void(const String&, const QIcon&)>& on_finished, const String& icon, const IconThemeSettings& theme, QIcon::Mode mode = QIcon::Mode::Normal);
137 static void GetPixmapResource(const std::function<void(const String&, const QPixmap&)>& on_finished, const String& pixmap, QIcon::Mode mode = QIcon::Mode::Normal, const QSize& requested_size = QSize());
138
139 static QIcon GetIconResourceBlocking(const String& icon, QIcon::Mode mode = QIcon::Mode::Normal);
140 static QIcon GetIconResourceBlocking(const String& icon, const IconThemeSettings& theme, QIcon::Mode mode = QIcon::Mode::Normal);
141 static QPixmap LocalPixmapResource(const String& pixmap, QIcon::Mode mode = QIcon::Mode::Normal, const QSize& requested_size = QSize());
142 static void PostIconResourceLoad(const String& id);
143 static void SetWindowIcon(const String& s, QWidget* widget);
144 static void ClearWindowIcon(QWidget* widget);
145 static Buffer<std::pair<LABColor, LABColor>> ConvertColorPalette(const Buffer<std::pair<RGBColor, RGBColor>>& palette);
146 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);
147 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);
148 static void ConvertColorTheme(const Buffer<std::pair<LABColor, LABColor>>& color, QImage& image, bool preserve_brightness, bool preserve_alpha);
149 static QImage AutoCrop(const QImage& pixmap, int margin = 0, bool preserve_ratio = false);
150 static const QPixmap& disabledPixmap(const String& icon_name);
151 static QImage FillBackground(const QImage& pixmap, RGBColor color);
152 static QImage CleanupImageForIcon(const QImage& image);
154 static void addIconTheme(const IconThemeSettings& theme);
160 static constexpr const char* NDEVRThemeLocation() { return "NDEVR Icons/"; }
161 static void AddIconEngine(NDEVRIconEngine* engine);
162 static String GetSVGPath(const String& icon, const IconThemeSettings& theme);
163 static String IconCacheLocation(const String& icon, const IconThemeSettings& theme);
164 static String ImageCacheLocation(const String& icon);
165 static void AddResolver(PixmapResolver* resolver);
166 protected:
167 static File GetImagePath(const String& icon);
168 static QIcon icon(const String& icon, QIcon::Mode mode = QIcon::Mode::Normal);
169 static QIcon icon(const String& icon, const IconThemeSettings& theme, QIcon::Mode mode = QIcon::Mode::Normal);
170 static QPixmap pixmap(const String& pixmap, QIcon::Mode mode = QIcon::Mode::Normal, const QSize& requested_size = QSize());
171 private:
172 static Dictionary<UUID, PixmapResolver*> s_resolvers;
173 static Dictionary<QWidget*, String> s_window_registered;
174 static Dictionary<String, QIcon> s_icon_dictionary;
175 static Dictionary<String, QPixmap> s_pixmap_dictionary;
176 static Dictionary<String, QPixmap> s_disabled_pixmap_dictionary;
177 static Dictionary<UUID, NDEVRIconEngine*> s_icon_engines;
178 static Buffer<IconThemeSettings> s_icon_themes;
179 };
181}
#define NDEVR_WIDGETS_T_API
Definition DLLInfo.h:60
#define NDEVR_WIDGETS_API
Definition DLLInfo.h:59
The equivelent of std::vector but with a bit more control. The basic array unit of the library.
Definition Buffer.hpp:56
Used to render any icons when they are needed. Resources will not be consumed until draw is called.
Definition QTIconManager.h:96
QIcon::Mode m_override_mode
Definition QTIconManager.h:108
virtual QIconEngine * clone(void) const override
QSize actualSize(const QSize &size, QIcon::Mode mode, QIcon::State state) override
QSize m_default_size
Definition QTIconManager.h:109
void setIconTheme(const IconThemeSettings theme)
virtual void paint(QPainter *painter, const QRect &rect, QIcon::Mode mode, QIcon::State state) override
String m_icon
Definition QTIconManager.h:107
virtual QPixmap pixmap(const QSize &size, QIcon::Mode mode, QIcon::State state) override
DeferredImageIconEngine(const String &icon, QIcon::Mode mode=QIcon::Mode::Normal)
QPixmap m_cached_pixmap
Definition QTIconManager.h:106
A hash-based key-value store, useful for quick associative lookups. Key features include:
Definition Dictionary.h:61
Logic for reading or writing to a file as well as navigating filesystems.
Definition File.h:48
Serves as the primary program interface for processes to report issues and allows any number of LogSt...
Definition Log.h:48
Used to render any icons or fetch any pixmaps within the software. More rendering engines can be adde...
Definition QTIconManager.h:81
virtual QIcon createIcon(const String &icon, const IconThemeSettings &theme, QIcon::Mode mode=QIcon::Mode::Normal)=0
NDEVRIconEngine(const UUID &id)
Definition QTIconManager.h:83
UUID id() const
Definition QTIconManager.h:88
virtual bool canProcess(const String &icon, const IconThemeSettings &theme, QIcon::Mode mode) const =0
A QIconEngine used to render SVG icons.
Definition SVGIconManager.h:28
Base class for logic that can be used to resolve a Pixmap resource and turn it into a QPixmap for use...
Definition QTIconManager.h:116
virtual bool canPotentiallyResolve(const String &pixmap_resource)=0
virtual UUID id() const =0
virtual QPixmap resolve(const String &pixmap_resource, QIcon::Mode mode, const QSize &requested_size, Dictionary< String, QPixmap > &pixmaps)=0
Manages all Icons and Pixmaps used by the UI in the NDEVR Engine. Icons may be fetched remotely so ca...
Definition QTIconManager.h:127
static const Buffer< IconThemeSettings > & iconThemes()
static void GetIconResource(const std::function< void(const String &, const QIcon &)> &on_finished, const String &icon, QIcon::Mode mode=QIcon::Mode::Normal)
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)
static void PostIconResourceLoad(const String &id)
static String GetSVGPath(const String &icon, const IconThemeSettings &theme)
static QIcon GetIconResourceBlocking(const String &icon, QIcon::Mode mode=QIcon::Mode::Normal)
static String ImageCacheLocation(const String &icon)
static QImage CleanupImageForIcon(const QImage &image)
static void AddResolver(PixmapResolver *resolver)
static QIcon icon(const String &icon, QIcon::Mode mode=QIcon::Mode::Normal)
static IconThemeSettings OutlineIconTheme()
static void SetWindowIcon(const String &s, QWidget *widget)
static void addIconTheme(const IconThemeSettings &theme)
static QPixmap LocalPixmapResource(const String &pixmap, QIcon::Mode mode=QIcon::Mode::Normal, const QSize &requested_size=QSize())
static QImage AutoCrop(const QImage &pixmap, int margin=0, bool preserve_ratio=false)
static void ConvertColorTheme(const Buffer< std::pair< LABColor, LABColor > > &color, QImage &image, bool preserve_brightness, bool preserve_alpha)
static const IconThemeSettings & EffectiveIconTheme()
static Buffer< std::pair< LABColor, LABColor > > ConvertColorPalette(const Buffer< std::pair< RGBColor, RGBColor > > &palette)
static void ClearWindowIcon(QWidget *widget)
static File GetImagePath(const String &icon)
static Resource< IconThemeSettings * > s_overide_icon_theme
Definition QTIconManager.h:156
static void SetOverrideTheme(IconThemeSettings *theme)
static Resource< IconThemeSettings > s_icon_theme
Definition QTIconManager.h:157
static String IconCacheLocation(const String &icon, const IconThemeSettings &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)
static void AddIconEngine(NDEVRIconEngine *engine)
static QIcon GetIconResourceBlocking(const String &icon, const IconThemeSettings &theme, QIcon::Mode mode=QIcon::Mode::Normal)
static IconThemeSettings NDEVRIconTheme()
static const QPixmap & disabledPixmap(const String &icon_name)
static QIcon icon(const String &icon, const IconThemeSettings &theme, QIcon::Mode mode=QIcon::Mode::Normal)
static QPixmap pixmap(const String &pixmap, QIcon::Mode mode=QIcon::Mode::Normal, const QSize &requested_size=QSize())
static void GetIconResource(const std::function< void(const String &, const QIcon &)> &on_finished, const String &icon, const IconThemeSettings &theme, QIcon::Mode mode=QIcon::Mode::Normal)
static constexpr const char * NDEVRThemeLocation()
Definition QTIconManager.h:160
static void GetPixmapResource(const std::function< void(const String &, const QPixmap &)> &on_finished, const String &pixmap, QIcon::Mode mode=QIcon::Mode::Normal, const QSize &requested_size=QSize())
static void SetLightingTheme(const IconThemeSettings &theme)
static QImage FillBackground(const QImage &pixmap, RGBColor color)
Represents a color in the RGB space with optional alpha transparency.
Definition RGBColor.h:54
A core part of the engine, stores variables that can be listened to with ResourceListener which will ...
Definition Toggle.h:41
Software Services provide an interface for adding to or changing the software behavior via functional...
Definition SoftwareService.h:9
Software Service Managers take a Software service to modify the behavior of the software.
Definition SoftwareService.h:15
The core String class for the NDEVR API.
Definition String.h:69
Logic for reading or writing to a string or a user friendly, TranslatedString.
Definition StringStream.h:230
A universally unique identifier (UUID) is a 128-bit number used to identify information in computer s...
Definition UUID.h:60
Definition ACIColor.h:37
double fltp08
Defines an alias representing an 8 byte floating-point number.
Definition BaseValues.hpp:149
Stores information for how to draw icons, when supported.
Definition QTIconManager.h:59
RGBColor secondary_color
Definition QTIconManager.h:66
bool operator!=(const IconThemeSettings &settings) const
String theme_name
Definition QTIconManager.h:62
bool blend_color
Definition QTIconManager.h:71
fltp08 pixel_size
Definition QTIconManager.h:69
String theme_icon_location
Definition QTIconManager.h:63
String theme_icon
Definition QTIconManager.h:61
RGBColor primary_color
Definition QTIconManager.h:65
RGBColor highlight_color
Definition QTIconManager.h:64
bool colorize_svgs
Definition QTIconManager.h:70
bool operator==(const IconThemeSettings &settings) const
RGBColor accent_color
Definition QTIconManager.h:67
RGBColor outline_color
Definition QTIconManager.h:68