Albert
Loading...
Searching...
No Matches
icon.h
1// SPDX-FileCopyrightText: 2025 Manuel Schneider
2// SPDX-License-Identifier: MIT
3
4#pragma once
5#include <QString>
6#include <albert/export.h>
7#include <memory>
8#include <filesystem>
9class QBrush;
10class QIcon;
11class QPainter;
12class QPixmap;
13class QRect;
14class QSize;
15class QString;
16
17namespace albert
18{
19
25class ALBERT_EXPORT Icon
26{
27public:
28
30 virtual ~Icon();
31
33 virtual std::unique_ptr<Icon> clone() const = 0;
34
41 virtual QSize actualSize(const QSize &device_independent_size, double device_pixel_ratio);
42
48 virtual QPixmap pixmap(const QSize &device_independent_size, double device_pixel_ratio);
49
51 virtual void paint(QPainter *painter, const QRect &rect) = 0;
52
58 virtual bool isNull();
59
61 virtual QString toUrl() const = 0;
62
68 virtual QString cacheKey();
69
71 static QIcon qIcon(std::unique_ptr<albert::Icon> icon);
72
74 static std::unique_ptr<Icon> iconFromUrl(const QString &url);
75
77 static std::unique_ptr<Icon> iconFromUrls(const QStringList &urls);
78
81
83 static std::unique_ptr<Icon> image(const QString &path);
84
86 static std::unique_ptr<Icon> image(const std::filesystem::path &path);
87
89
92
94 static std::unique_ptr<Icon> fileType(const QString &path);
95
97 static std::unique_ptr<Icon> fileType(const std::filesystem::path &path);
98
100
103
105 static std::unique_ptr<Icon> theme(const QString &icon_name);
106
108
117 {
118 TitleBarMinButton = 1,
119 TitleBarMenuButton = 0,
120 TitleBarMaxButton = 2,
121 TitleBarCloseButton = 3,
122 TitleBarNormalButton = 4,
123 TitleBarShadeButton = 5,
124 TitleBarUnshadeButton = 6,
125 TitleBarContextHelpButton = 7,
126 MessageBoxInformation = 9,
127 MessageBoxWarning = 10,
128 MessageBoxCritical = 11,
129 MessageBoxQuestion = 12,
130 DesktopIcon = 13,
131 TrashIcon = 14,
132 ComputerIcon = 15,
133 DriveFDIcon = 16,
134 DriveHDIcon = 17,
135 DriveCDIcon = 18,
136 DriveDVDIcon = 19,
137 DriveNetIcon = 20,
138 DirHomeIcon = 56,
139 DirOpenIcon = 21,
140 DirClosedIcon = 22,
141 DirIcon = 38,
142 DirLinkIcon = 23,
143 DirLinkOpenIcon = 24,
144 FileIcon = 25,
145 FileLinkIcon = 26,
146 FileDialogStart = 29,
147 FileDialogEnd = 30,
148 FileDialogToParent = 31,
149 FileDialogNewFolder = 32,
150 FileDialogDetailedView = 33,
151 FileDialogInfoView = 34,
152 FileDialogContentsView = 35,
153 FileDialogListView = 36,
154 FileDialogBack = 37,
155 DockWidgetCloseButton = 8,
156 ToolBarHorizontalExtensionButton = 27,
157 ToolBarVerticalExtensionButton = 28,
158 DialogOkButton = 39,
159 DialogCancelButton = 40,
160 DialogHelpButton = 41,
161 DialogOpenButton = 42,
162 DialogSaveButton = 43,
163 DialogCloseButton = 44,
164 DialogApplyButton = 45,
165 DialogResetButton = 46,
166 DialogDiscardButton = 47,
167 DialogYesButton = 48,
168 DialogNoButton = 49,
169 ArrowUp = 50,
170 ArrowDown = 51,
171 ArrowLeft = 52,
172 ArrowRight = 53,
173 ArrowBack = 54,
174 ArrowForward = 55,
175 CommandLink = 57,
176 VistaShield = 58,
177 BrowserReload = 59,
178 BrowserStop = 60,
179 MediaPlay = 61,
180 MediaStop = 62,
181 MediaPause = 63,
182 MediaSkipForward = 64,
183 MediaSkipBackward = 65,
184 MediaSeekForward = 66,
185 MediaSeekBackward = 67,
186 MediaVolume = 68,
187 MediaVolumeMuted = 69,
188 LineEditClearButton = 70,
189 DialogYesToAllButton = 71,
190 DialogNoToAllButton = 72,
191 DialogSaveAllButton = 73,
192 DialogAbortButton = 74,
193 DialogRetryButton = 75,
194 DialogIgnoreButton = 76,
195 RestoreDefaultsButton = 77,
196 TabCloseButton = 78,
197 };
199 static std::unique_ptr<Icon> standard(StandardIconType type);
201
204
206 static QBrush graphemeDefaultBrush();
207
209 static std::unique_ptr<Icon> grapheme(const QString &grapheme, double scalar = 1.0);
210
212 static std::unique_ptr<Icon> grapheme(const QString &grapheme,
213 double scalar,
214 const QBrush &brush);
215
217
220
222 static const QBrush &iconifiedDefaultBackgroundBrush();
223
225 static const QBrush &iconifiedDefaultBorderBrush();
226
233 static std::unique_ptr<Icon> iconified(
234 std::unique_ptr<Icon> icon,
235 const QBrush &background_brush = iconifiedDefaultBackgroundBrush(),
236 double border_radius = 1.0,
237 int border_width = 1,
238 const QBrush &border_color = iconifiedDefaultBorderBrush());
239
241
244
251 static std::unique_ptr<Icon> composed(std::unique_ptr<Icon> icon1,
252 std::unique_ptr<Icon> icon2,
253 double size1 = 0.7,
254 double size2 = 0.7,
255 double x1 = 0.0,
256 double y1 = 0.0,
257 double x2 = 1.0,
258 double y2 = 1.0);
259
261
262};
263
264} // namespace albert
Abstract icon engine.
Definition icon.h:26
static std::unique_ptr< Icon > fileType(const std::filesystem::path &path)
Returns an icon representing the file type of the file at path.
static std::unique_ptr< Icon > theme(const QString &icon_name)
Returns an icon from the current icon theme with the given icon_name.
static QBrush graphemeDefaultBrush()
Returns the window text color of the current application palette.
virtual void paint(QPainter *painter, const QRect &rect)=0
Uses the given painter to paint the icon into the rectangle rect.
virtual QPixmap pixmap(const QSize &device_independent_size, double device_pixel_ratio)
Returns a pixmap for the requested device_independent_size and device_pixel_ratio.
static const QBrush & iconifiedDefaultBackgroundBrush()
Returns the default background brush (a top down gradient from white to some darker white).
virtual QString cacheKey()
Returns the cache key of the icon.
virtual QString toUrl() const =0
Returns a URL representation of the icon.
virtual std::unique_ptr< Icon > clone() const =0
Returns a clone of this icon.
static std::unique_ptr< Icon > fileType(const QString &path)
Returns an icon representing the file type of the file at path.
static std::unique_ptr< Icon > grapheme(const QString &grapheme, double scalar=1.0)
Returns an icon rendering the given grapheme with graphemeDefaultBrush, scaled by scalar.
static QIcon qIcon(std::unique_ptr< albert::Icon > icon)
Returns a QIcon using icon as icon engine.
virtual QSize actualSize(const QSize &device_independent_size, double device_pixel_ratio)
Returns the device independent size of the available icon for the given device_independent_size and d...
static std::unique_ptr< Icon > iconFromUrls(const QStringList &urls)
Returns a built-in icon for the given urls.
StandardIconType
Definition icon.h:117
static std::unique_ptr< Icon > iconified(std::unique_ptr< Icon > icon, const QBrush &background_brush=iconifiedDefaultBackgroundBrush(), double border_radius=1.0, int border_width=1, const QBrush &border_color=iconifiedDefaultBorderBrush())
Returns iconified icon.
static std::unique_ptr< Icon > image(const QString &path)
Returns an icon from an image file at path.
static const QBrush & iconifiedDefaultBorderBrush()
Returns the default border color (a gradient slightly darker than the default background).
virtual bool isNull()
Returns true if the icon is valid; otherwise returns false.
static std::unique_ptr< Icon > iconFromUrl(const QString &url)
Returns a built-in icon for the given url.
static std::unique_ptr< Icon > grapheme(const QString &grapheme, double scalar, const QBrush &brush)
Returns an icon rendering the given grapheme, scaled by scalar and colored with brush.
static std::unique_ptr< Icon > image(const std::filesystem::path &path)
Returns an icon from an image file at path.
static std::unique_ptr< Icon > composed(std::unique_ptr< Icon > icon1, std::unique_ptr< Icon > icon2, double size1=0.7, double size2=0.7, double x1=0.0, double y1=0.0, double x2=1.0, double y2=1.0)
Returns a composed icon from icon1 and icon2.
static std::unique_ptr< Icon > standard(StandardIconType type)
Returns a standard icon for the given type.
virtual ~Icon()
Destructs the icon.
The Albert namespace.
Definition app.h:55