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
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
18
19using namespace Qt::StringLiterals;
20
21namespace qdesigner_internal {
22
23// Check for "Dark Mode", either system-wide or usage of a dark style
24static 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
33{
34 return QGuiApplication::styleHints()->colorScheme() == Qt::ColorScheme::Dark
35 || isLight(QGuiApplication::palette().color(QPalette::WindowText));
36}
37
45
46template <class StringView>
47static 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
72
77
79{
80 return QIcon(u":/qt-project.org/formeditor/images/emptyicon.png"_s);
81}
82
83static 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
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
106QT_END_NAMESPACE
Combined button and popup list for selecting options.
Auxiliary methods to store/retrieve settings.
static QIcon buildIcon(const QString &prefix, const int *sizes, size_t sizeCount)
QDESIGNER_SHARED_EXPORT bool isDarkMode()
static QIcon createIconSetHelper(StringView name)
static bool isLight(const QColor &textColor)
#define QDESIGNER_SHARED_EXPORT