Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qwindowsiconengine.cpp
Go to the documentation of this file.
1// Copyright (C) 2023 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
5
6#ifndef QT_NO_ICON
7
8#include <QtCore/qoperatingsystemversion.h>
9#include <QtGui/qguiapplication.h>
10#include <QtGui/qpainter.h>
11#include <QtGui/qpalette.h>
12
14
15using namespace Qt::StringLiterals;
16
17static QString getGlyphs(QStringView iconName)
18{
19 static constexpr std::pair<QLatin1StringView, QStringView> glyphMap[] = {
20 {"address-book-new"_L1, u"\ue780"},
21 {"application-exit"_L1, u"\ue8bb"},
22 {"appointment-new"_L1, u"\ue878"},
23 {"call-start"_L1, u"\uf715"},
24 {"call-stop"_L1, u"\uf405"},
25 {"contact-new"_L1, u"\ue8fa"},
26 {"document-new"_L1, u"\ue8a5"},
27 {"document-open"_L1, u"\ue8e5"},
28 {"document-open-recent"_L1, u"\ue823"},
29 {"document-page-setup"_L1, u"\ue7c3"},
30 {"document-print"_L1, u"\ue749"},
31 {"document-print-preview"_L1, u"\ue956"},
32 {"document-properties"_L1, u"\ue90f"},
33 {"document-revert"_L1, u"\ue7a7"}, // ?
34 {"document-save"_L1, u"\ue74e"}, // or e78c?
35 {"document-save-as"_L1, u"\ue792"},
36 {"document-send"_L1, u"\ue724"},
37 {"edit-clear"_L1, u"\ue894"},
38 {"edit-copy"_L1, u"\ue8c8"},
39 {"edit-cut"_L1, u"\ue8c6"},
40 {"edit-delete"_L1, u"\ue74d"},
41 {"edit-find"_L1, u"\ue721"},
42 //{"edit-find-replace"_L1, u"\u"},
43 {"edit-paste"_L1, u"\ue77f"},
44 {"edit-redo"_L1, u"\ue7a6"},
45 {"edit-select-all"_L1, u"\ue8b3"},
46 {"edit-undo"_L1, u"\ue7a7"},
47 {"folder-new"_L1, u"\ue8f4"},
48 //{"format-indent-less"_L1, u"\u"},
49 //{"format-indent-more"_L1, u"\u"},
50 {"format-justify-center"_L1, u"\ue8e3"},
51 //{"format-justify-fill"_L1, u"\ue235"},
52 {"format-justify-left"_L1, u"\ue8e4"},
53 {"format-justify-right"_L1, u"\ue8e2"},
54 {"format-text-direction-ltr"_L1, u"\ue9aa"},
55 {"format-text-direction-rtl"_L1, u"\ue9ab"},
56 {"format-text-bold"_L1, u"\ue8dd"},
57 {"format-text-italic"_L1, u"\ue8db"},
58 {"format-text-underline"_L1, u"\ue8dc"},
59 {"format-text-strikethrough"_L1, u"\uede0"},
60 //{"go-bottom"_L1,u"\ue258"},
61 {"go-down"_L1,u"\ue74b"},
62 //{"go-first"_L1, u"\ue5dc"},
63 {"go-home"_L1, u"\ue80f"},
64 // {"go-jump"_L1, u"\uf719"},
65 //{"go-last"_L1, u"\ue5dd"},
66 {"go-next"_L1, u"\ue893"},
67 {"go-previous"_L1, u"\ue892"},
68 //{"go-top"_L1, u"\ue25a"},
69 {"go-up"_L1, u"\ue74a"},
70 {"help-about"_L1, u"\ue946"},
71 //{"help-contents"_L1, u"\ue8de"},
72 {"help-faq"_L1, u"\ue897"},
73 {"insert-image"_L1, u"\ue946"},
74 {"insert-link"_L1, u"\ue71b"},
75 //{"insert-object"_L1, u"\u"},
76 //{"insert-text"_L1, u"\uf827"},
77 {"list-add"_L1, u"\ue710"},
78 {"list-remove"_L1, u"\ue738"},
79 {"mail-forward"_L1, u"\ue89c"},
80 //{"mail-mark-important"_L1, u"\ue937"},
81 //{"mail-mark-junk"_L1, u"\u"},
82 //{"mail-mark-notjunk"_L1, u"\u"},
83 {"mail-mark-read"_L1, u"\ue8c3"},
84 //{"mail-mark-unread"_L1, u"\ue9bc"},
85 {"mail-message-new"_L1, u"\ue70f"},
86 {"mail-reply-all"_L1, u"\ue8c2"},
87 {"mail-reply-sender"_L1, u"\ue8ca"},
88 {"mail-send"_L1, u"\ue724"},
89 //{"mail-send-receive"_L1, u"\u"},
90 {"media-eject"_L1, u"\uf847"},
91 {"media-playback-pause"_L1, u"\ue769"},
92 {"media-playback-start"_L1, u"\ue768"},
93 {"media-playback-stop"_L1, u"\ue71a"},
94 {"media-record"_L1, u"\ue7c8"},
95 {"media-seek-backward"_L1, u"\ueb9e"},
96 {"media-seek-forward"_L1, u"\ueb9d"},
97 {"media-skip-backward"_L1, u"\ue892"},
98 {"media-skip-forward"_L1, u"\ue893"},
99 //{"object-flip-horizontal"_L1, u"\u"},
100 //{"object-flip-vertical"_L1, u"\u"},
101 {"object-rotate-left"_L1, u"\ue80c"},
102 {"object-rotate-right"_L1, u"\ue80d"},
103 //{"process-stop"_L1, u"\ue5c9"},
104 {"system-lock-screen"_L1, u"\uee3f"},
105 {"system-log-out"_L1, u"\uf3b1"},
106 //{"system-run"_L1, u"\u"},
107 {"system-search"_L1, u"\ue721"},
108 {"system-reboot"_L1, u"\ue777"}, // unsure?
109 {"system-shutdown"_L1, u"\ue7e8"},
110 {"tools-check-spelling"_L1, u"\uf87b"},
111 {"view-fullscreen"_L1, u"\ue740"},
112 {"view-refresh"_L1, u"\ue72c"},
113 {"view-restore"_L1, u"\ue777"},
114 //{"view-sort-ascending"_L1, u"\ue25a"},
115 //{"view-sort-descending"_L1, u"\ue258"},
116 {"window-close"_L1, u"\ue8bb"},
117 {"window-new"_L1, u"\ue78b"},
118 {"zoom-fit-best"_L1, u"\ue9a6"},
119 {"zoom-in"_L1, u"\ue8a3"},
120 {"zoom-original"_L1, u"\ue71e"},
121 {"zoom-out"_L1, u"\ue71f"},
122
123 {"process-working"_L1, u"\ue9f3"},
124
125 {"accessories-calculator"_L1, u"\ue8ef"},
126 {"accessories-character-map"_L1, u"\uf2b7"},
127 {"accessories-dictionary"_L1, u"\ue82d"},
128 //{"accessories-text-editor"_L1, u"\ue262"},
129 {"help-browser"_L1, u"\ue897"},
130 {"multimedia-volume-control"_L1, u"\ue767"},
131 {"preferences-desktop-accessibility"_L1, u"\ue776"},
132 {"preferences-desktop-font"_L1, u"\ue8d2"},
133 {"preferences-desktop-keyboard"_L1, u"\ue765"},
134 {"preferences-desktop-locale"_L1, u"\uf2b7"},
135 //{"preferences-desktop-multimedia"_L1, u"\uea75"},
136 {"preferences-desktop-screensaver"_L1, u"\uf182"},
137 //{"preferences-desktop-theme"_L1, u"\uf560"},
138 //{"preferences-desktop-wallpaper"_L1, u"\ue1bc"},
139 {"system-file-manager"_L1, u"\uec50"},
140 //{"system-software-install"_L1, u"\ueb71"},
141 {"system-software-update"_L1, u"\uecc5"},
142 {"utilities-system-monitor"_L1, u"\ue7f4"},
143 {"utilities-terminal"_L1, u"\ue756"},
144
145 //{"applications-accessories"_L1, u"\u"},
146 {"applications-development"_L1, u"\uec7a"},
147 //{"applications-engineering"_L1, u"\uea3d"},
148 {"applications-games"_L1, u"\ue7fc"},
149 //{"applications-graphics"_L1, u"\u"},
150 {"applications-internet"_L1, u"\ue774"},
151 {"applications-multimedia"_L1, u"\uea69"},
152 //{"applications-office"_L1, u"\u"},
153 //{"applications-other"_L1, u"\u"},
154 //{"applications-science"_L1, u"\uea4b"},
155 {"applications-system"_L1, u"\ue770"},
156 //{"applications-utilities"_L1, u"\u"},
157 //{"preferences-desktop"_L1, u"\ueb97"},
158 //{"preferences-desktop-peripherals"_L1, u"\u"},
159 //{"preferences-desktop-personal"_L1, u"\uf835"},
160 //{"preferences-other"_L1, u"\u"},
161 //{"preferences-system"_L1, u"\ue8b8"},
162 //{"preferences-system-network"_L1, u"\ue894"},
163 {"system-help"_L1, u"\ue946"},
164
165 {"audio-card"_L1, u"\ue8d6"},
166 {"audio-input-microphone"_L1, u"\ue720"},
167 {"battery"_L1, u"\ue83f"},
168 {"camera-photo"_L1, u"\ue722"},
169 {"camera-video"_L1, u"\ue714"},
170 {"camera-web"_L1, u"\ue8b8"},
171 {"computer"_L1, u"\ue7f8"}, // or e7fb?
172 {"drive-harddisk"_L1, u"\ueda2"},
173 {"drive-optical"_L1, u"\ue958"},
174 //{"drive-removable-media"_L1, u"\u"},
175 //{"input-gaming"_L1, u"\u"},
176 {"input-keyboard"_L1, u"\ue92e"},
177 {"input-mouse"_L1, u"\ue962"},
178 {"input-tablet"_L1, u"\ue70a"},
179 {"media-flash"_L1, u"\ue88e"},
180 //{"media-floppy"_L1, u"\u"},
181 {"media-optical"_L1, u"\ue958"},
182 {"media-tape"_L1, u"\ue96a"},
183 //{"modem"_L1, u"\u"},
184 //{"multimedia-player"_L1, u"\u"},
185 {"network-wired"_L1, u"\ue968"},
186 {"network-wireless"_L1, u"\ue701"},
187 //{"pda"_L1, u"\u"},
188 {"phone"_L1, u"\ue717"},
189 {"printer"_L1, u"\ue749"},
190 {"scanner"_L1, u"\ue8fe"},
191 //{"video-display"_L1, u"\uf06a"},
192
193 {"emblem-default"_L1, u"\uf56d"},
194 {"emblem-documents"_L1, u"\ue8a5"},
195 {"emblem-downloads"_L1, u"\ue896"},
196 {"emblem-favorite"_L1, u"\ue734"},
197 {"emblem-important"_L1, u"\ue8c9"},
198 {"emblem-mail"_L1, u"\ue715"},
199 {"emblem-photos"_L1, u"\ue91b"},
200 //{"emblem-readonly"_L1, u"\u"},
201 {"emblem-shared"_L1, u"\ue902"},
202 {"emblem-symbolic-link"_L1, u"\ue71b"},
203 {"emblem-synchronized"_L1, u"\uedab"},
204 {"emblem-system"_L1, u"\ue770"},
205 //{"emblem-unreadable"_L1, u"\u"},
206
207 {"folder"_L1, u"\ue8b7"},
208 //{"folder-remote"_L1, u"\u"},
209 //{"network-server"_L1, u"\ue875"},
210 //{"network-workgroup"_L1, u"\ue1a0"},
211 {"start-here"_L1, u"\ue8fc"}, // unsure
212 {"user-bookmarks"_L1, u"\ue8a4"},
213 //{"user-desktop"_L1, u"\ue30a"},
214 {"user-home"_L1, u"\ue80f"},
215 {"user-trash"_L1, u"\ue74d"},
216
217 //{"appointment-missed"_L1, u"\ue615"},
218 //{"appointment-soon"_L1, u"\uf540"},
219 {"audio-volume-high"_L1, u"\ue995"},
220 {"audio-volume-low"_L1, u"\ue993"},
221 {"audio-volume-medium"_L1, u"\ue994"},
222 {"audio-volume-muted"_L1, u"\ue992"},
223 //{"battery-caution"_L1, u"\ue19c"},
224 {"battery-low"_L1, u"\ue851"}, // ?
225 {"dialog-error"_L1, u"\ue783"},
226 {"dialog-information"_L1, u"\ue946"},
227 //{"dialog-password"_L1, u"\uf042"},
228 {"dialog-question"_L1, u"\uf142"}, // unsure
229 {"dialog-warning"_L1, u"\ue7ba"},
230 //{"folder-drag-accept"_L1, @u"\ue9a3"},
231 {"folder-open"_L1, u"\ue838"},
232 //{"folder-visiting"_L1, u"\ue8a7"},
233 //{"image-loading"_L1, u"\ue41a"},
234 //{"image-missing"_L1, u"\ue3ad"},
235 {"mail-attachment"_L1, u"\ue723"},
236 //{"mail-unread"_L1, u"\uf18a"},
237 //{"mail-read"_L1, u"\uf18c"},
238 {"mail-replied"_L1, u"\ue8ca"},
239 //{"mail-signed"_L1, u"\u"},
240 //{"mail-signed-verified"_L1, u"\u"},
241 {"media-playlist-repeat"_L1, u"\ue8ee"},
242 {"media-playlist-shuffle"_L1, u"\ue8b1"},
243 //{"network-error"_L1, u"\uead9"},
244 //{"network-idle"_L1, u"\ue51f"},
245 {"network-offline"_L1, u"\uf384"},
246 //{"network-receive"_L1, u"\ue2c0"},
247 //{"network-transmit"_L1, u"\ue2c3"},
248 //{"network-transmit-receive"_L1, u"\uca18"},
249 //{"printer-error"_L1, u"\uf7a0"},
250 //{"printer-printing"_L1, u"\uf7a1"},
251 //{"security-high"_L1, u"\ue32a"},
252 //{"security-medium"_L1, u"\ue9e0"},
253 //{"security-low"_L1, u"\uf012"},
254 //{"software-update-available"_L1, u"\ue923"},
255 //{"software-update-urgent"_L1, u"\uf05a"},
256 {"sync-error"_L1, u"\uea6a"},
257 {"sync-synchronizing"_L1, u"\ue895"},
258 //{"task-due"_L1, u"\u"},
259 //{"task-past-due"_L1, u"\u"},
260 {"user-available"_L1, u"\ue8cf"},
261 //{"user-away"_L1, u"\ue510"},
262 //{"user-idle"_L1, u"\u"},
263 //{"user-offline"_L1, u"\uf7b3"},
264 //{"user-trash-full"_L1, u"\ue872"}, //delete
265 //{"user-trash-full"_L1, u"\ue92b"}, //delete_forever
266 {"weather-clear"_L1, u"\ue706"},
267 //{"weather-clear-night"_L1, u"\uf159"},
268 //{"weather-few-clouds"_L1, u"\uf172"},
269 //{"weather-few-clouds-night"_L1, u"\uf174"},
270 //{"weather-fog"_L1, u"\ue818"},
271 {"weather-overcast"_L1, u"\ue753"},
272 //{"weather-severe-alert"_L1, u"\ue002"}, //warning
273 //{"weather-showers"_L1, u"\uf176"},
274 //{"weather-showers-scattered"_L1, u"\u"},
275 //{"weather-snow"_L1, u"\ue80f"}, //snowing
276 //{"weather-storm"_L1, u"\uf070"},
277 };
278
279 const auto it = std::find_if(std::begin(glyphMap),
280 std::end(glyphMap), [iconName](const auto &c){
281 return c.first == iconName;
282 });
283
284 return it != std::end(glyphMap) ? it->second.toString()
285 : (iconName.length() == 1 ? iconName.toString() : QString());
286}
287
288namespace {
289static auto iconFont()
290{
291 static const bool isWindows11 = QOperatingSystemVersion::current() >= QOperatingSystemVersion::Windows11;
292 QFont font(isWindows11 ? u"Segoe Fluent Icons"_s
293 : u"Segoe MDL2 Assets"_s);
294 font.setStyleStrategy(QFont::NoFontMerging);
295 return font;
296}
297}
298
299QWindowsIconEngine::QWindowsIconEngine(const QString &iconName)
300 : QFontIconEngine(iconName, iconFont())
301 , m_glyphs(getGlyphs(iconName))
302{
303}
304
305QWindowsIconEngine::~QWindowsIconEngine()
306{}
307
308QString QWindowsIconEngine::key() const
309{
310 return u"QWindowsIconEngine"_s;
311}
312
313QIconEngine *QWindowsIconEngine::clone() const
314{
315 QWindowsIconEngine *that = const_cast<QWindowsIconEngine *>(this);
316 return new QWindowsIconEngine(that->iconName());
317}
318
319QString QWindowsIconEngine::string() const
320{
321 return m_glyphs;
322}
323
324QT_END_NAMESPACE
325
326#endif //QT_NO_ICON
static QString getGlyphs(QStringView iconName)