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
4#include "iconloader_p.h"
5
6#include <QtCore/qfile.h>
7#include <QtCore/qoperatingsystemversion.h>
8
9#include <QtGui/qcolor.h>
10#include <QtGui/qguiapplication.h>
11#include <QtGui/qicon.h>
12#include <QtGui/qpalette.h>
13#include <QtGui/qpixmap.h>
14#include <QtGui/qstylehints.h>
15
17
18using namespace Qt::StringLiterals;
19
20namespace qdesigner_internal {
21
22// Check for "Dark Mode", either system-wide or usage of a dark style
23static bool isLight(const QColor &textColor)
24{
25 enum : int { DarkThreshold = 200 }; // Observed 239 on KDE/Dark
26
27 return textColor.red() > DarkThreshold && textColor.green() > DarkThreshold
28 && textColor.blue() > DarkThreshold;
29}
30
32{
33 return QGuiApplication::styleHints()->colorScheme() == Qt::ColorScheme::Dark
34 || isLight(QGuiApplication::palette().color(QPalette::WindowText));
35}
36
44
45template <class StringView>
46static inline QIcon createIconSetHelper(StringView name)
47{
48 constexpr QLatin1StringView prefixes[] = {
49 ":/qt-project.org/formeditor/images/"_L1,
50#ifdef Q_OS_MACOS
51 ":/qt-project.org/formeditor/images/mac/"_L1,
52#else
53 ":/qt-project.org/formeditor/images/win/"_L1,
54#endif
55 ":/qt-project.org/formeditor/images/designer_"_L1
56 };
57
58 for (QLatin1StringView prefix : prefixes) {
59 const QString f = prefix + name;
60 if (QFile::exists(f))
61 return QIcon(f);
62 }
63
64 return {};
65}
66
71
76
78{
79 return QIcon(u":/qt-project.org/formeditor/images/emptyicon.png"_s);
80}
81
82static QIcon buildIcon(const QString &prefix, const int *sizes, size_t sizeCount)
83{
84 QIcon result;
85 for (size_t i = 0; i < sizeCount; ++i) {
86 const QString size = QString::number(sizes[i]);
87 const QPixmap pixmap(prefix + size + 'x'_L1 + size + ".png"_L1);
88 Q_ASSERT(!pixmap.size().isEmpty());
89 result.addPixmap(pixmap);
90 }
91 return result;
92}
93
95{
96 static const int sizes[] = {16, 24, 32, 64, 128};
97 static const QIcon result =
98 buildIcon(u":/qt-project.org/formeditor/images/qtlogo"_s,
99 sizes, sizeof(sizes) / sizeof(sizes[0]));
100 return result;
101}
102
103} // namespace qdesigner_internal
104
105QT_END_NAMESPACE
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