Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Toggle main menu visibility
Loading...
Searching...
No Matches
iconloader.cpp
Go to the documentation of this file.
1
// Copyright (C) 2016 The Qt Company Ltd.
2
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
3
// Qt-Security score:significant reason:default
4
5
#
include
"iconloader_p.h"
6
7
#
include
<
QtCore
/
qfile
.
h
>
8
#
include
<
QtCore
/
qoperatingsystemversion
.
h
>
9
10
#
include
<
QtGui
/
qcolor
.
h
>
11
#
include
<
QtGui
/
qguiapplication
.
h
>
12
#
include
<
QtGui
/
qicon
.
h
>
13
#
include
<
QtGui
/
qpalette
.
h
>
14
#
include
<
QtGui
/
qpixmap
.
h
>
15
#
include
<
QtGui
/
qstylehints
.
h
>
16
17
QT_BEGIN_NAMESPACE
18
19
using
namespace
Qt::StringLiterals;
20
21
namespace
qdesigner_internal
{
22
23
// Check for "Dark Mode", either system-wide or usage of a dark style
24
static
bool
isLight
(
const
QColor &textColor)
25
{
26
enum
:
int
{ DarkThreshold = 200 };
// Observed 239 on KDE/Dark
27
28
return
textColor.red() > DarkThreshold && textColor.green() > DarkThreshold
29
&& textColor.blue() > DarkThreshold;
30
}
31
32
QDESIGNER_SHARED_EXPORT
bool
isDarkMode
()
33
{
34
return
QGuiApplication::styleHints()->colorScheme() == Qt::ColorScheme::Dark
35
|| isLight(QGuiApplication::palette().color(QPalette::WindowText));
36
}
37
38
QDESIGNER_SHARED_EXPORT
QIcon
createIconSet
(
QIcon
::
ThemeIcon
themeIcon
,
39
QLatin1StringView
name
)
40
{
41
return
QOperatingSystemVersion
::
currentType
() !=
QOperatingSystemVersion
::
MacOS
42
&&
QIcon
::
hasThemeIcon
(
themeIcon
)
43
?
QIcon
::
fromTheme
(
themeIcon
) :
createIconSet
(
name
);
44
}
45
46
template
<
class
StringView>
47
static
inline
QIcon
createIconSetHelper
(StringView name)
48
{
49
constexpr
QLatin1StringView prefixes[] = {
50
":/qt-project.org/formeditor/images/"_L1
,
51
#
ifdef
Q_OS_MACOS
52
":/qt-project.org/formeditor/images/mac/"_L1
,
53
#
else
54
":/qt-project.org/formeditor/images/win/"_L1
,
55
#
endif
56
":/qt-project.org/formeditor/images/designer_"_L1
57
};
58
59
for
(QLatin1StringView prefix : prefixes) {
60
const
QString f = prefix + name;
61
if
(QFile::exists(f))
62
return
QIcon(f);
63
}
64
65
return
{};
66
}
67
68
QDESIGNER_SHARED_EXPORT
QIcon
createIconSet
(
QStringView
name
)
69
{
70
return
createIconSetHelper
(
name
);
71
}
72
73
QDESIGNER_SHARED_EXPORT
QIcon
createIconSet
(
QLatin1StringView
name
)
74
{
75
return
createIconSetHelper
(
name
);
76
}
77
78
QDESIGNER_SHARED_EXPORT
QIcon
emptyIcon
()
79
{
80
return
QIcon
(u":/qt-project.org/formeditor/images/emptyicon.png"_s);
81
}
82
83
static
QIcon
buildIcon
(
const
QString &prefix,
const
int
*sizes, size_t sizeCount)
84
{
85
QIcon result;
86
for
(size_t i = 0; i < sizeCount; ++i) {
87
const
QString size = QString::number(sizes[i]);
88
const
QPixmap pixmap(prefix + size +
'x'_L1
+ size +
".png"_L1
);
89
Q_ASSERT(!pixmap.size().isEmpty());
90
result.addPixmap(pixmap);
91
}
92
return
result;
93
}
94
95
QDESIGNER_SHARED_EXPORT
QIcon
qtLogoIcon
()
96
{
97
static
const
int
sizes
[] = {16, 24, 32, 64, 128};
98
static
const
QIcon
result
=
99
buildIcon
(u":/qt-project.org/formeditor/images/qtlogo"_s,
100
sizes
,
sizeof
(
sizes
) /
sizeof
(
sizes
[0]));
101
return
result
;
102
}
103
104
}
// namespace qdesigner_internal
105
106
QT_END_NAMESPACE
QT_BEGIN_NAMESPACE
Combined button and popup list for selecting options.
Definition
qsequentialanimationgroup.cpp:47
qdesigner_internal
Auxiliary methods to store/retrieve settings.
Definition
buddyeditor.cpp:67
qdesigner_internal::buildIcon
static QIcon buildIcon(const QString &prefix, const int *sizes, size_t sizeCount)
Definition
iconloader.cpp:83
qdesigner_internal::isDarkMode
QDESIGNER_SHARED_EXPORT bool isDarkMode()
Definition
iconloader.cpp:32
qdesigner_internal::createIconSetHelper
static QIcon createIconSetHelper(StringView name)
Definition
iconloader.cpp:47
qdesigner_internal::isLight
static bool isLight(const QColor &textColor)
Definition
iconloader.cpp:24
QDESIGNER_SHARED_EXPORT
#define QDESIGNER_SHARED_EXPORT
Definition
shared_global_p.h:33
qttools
src
designer
src
lib
shared
iconloader.cpp
Generated on
for Qt by
1.18.0