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, QQmlEngine *engine)
14 : m_parent(parent),
15 m_engine(engine),
16 m_slot(slot),
17 m_enabled(false)
18{
19 Q_ASSERT(slot != -1 && parent && engine);
20}
21
23{
24 return m_enabled;
25}
26
28{
29 m_enabled = enabled;
30 if (m_enabled)
31 loadIcon();
32}
33
35{
36 const QIcon fallback = QPixmap::fromImage(image());
37 return QIcon::fromTheme(m_icon.name(), fallback);
38}
39
41{
42 return m_icon;
43}
44
45void QQuickNativeIconLoader::setIcon(const QQuickIcon &icon)
46{
47 m_icon = icon;
48 if (m_enabled)
49 loadIcon();
50}
51
52void QQuickNativeIconLoader::loadIcon()
53{
54 if (m_icon.source().isEmpty()) {
55 clear(m_parent);
56 } else {
57 load(m_engine, m_icon.source());
58 if (m_slot != -1 && isLoading()) {
59 connectFinished(m_parent, m_slot);
60 m_slot = -1;
61 }
62 }
63
64 if (!isLoading())
65 m_parent->metaObject()->method(m_slot).invoke(m_parent);
66}
67
68QT_END_NAMESPACE
void setIcon(const QQuickIcon &icon)
Combined button and popup list for selecting options.