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
qquicknativeiconloader.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// Qt-Security score:significant reason:default
4
6
7#include <QtCore/qobject.h>
8#include <QtCore/qmetaobject.h>
9#include <QtQml/qqml.h>
10
12
13QQuickNativeIconLoader::QQuickNativeIconLoader(int slot, QObject *parent)
14 : m_parent(parent),
15 m_slot(slot),
16 m_enabled(false)
17{
18 Q_ASSERT(slot != -1 && parent);
19}
20
22{
23 return m_enabled;
24}
25
27{
28 m_enabled = enabled;
29 if (m_enabled)
30 loadIcon();
31}
32
34{
35 const QIcon fallback = QPixmap::fromImage(image());
36 return QIcon::fromTheme(m_icon.name(), fallback);
37}
38
40{
41 return m_icon;
42}
43
44void QQuickNativeIconLoader::setIcon(const QQuickIcon &icon)
45{
46 m_icon = icon;
47 if (m_enabled)
48 loadIcon();
49}
50
51void QQuickNativeIconLoader::loadIcon()
52{
53 if (m_icon.source().isEmpty()) {
54 clear(m_parent);
55 } else {
56 load(qmlEngine(m_parent), m_icon.source());
57 if (m_slot != -1 && isLoading()) {
58 connectFinished(m_parent, m_slot);
59 m_slot = -1;
60 }
61 }
62
63 if (!isLoading())
64 m_parent->metaObject()->method(m_slot).invoke(m_parent);
65}
66
67QT_END_NAMESPACE
void setIcon(const QQuickIcon &icon)