1// Copyright (C) 2017 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
4#include "qquicklabsplatformiconloader_p.h"
5
6#include <QtCore/qobject.h>
7#include <QtCore/qmetaobject.h>
8#include <QtQml/qqml.h>
9
10QT_BEGIN_NAMESPACE
11
12QQuickLabsPlatformIconLoader::QQuickLabsPlatformIconLoader(int slot, QObject *parent)
13 : m_parent(parent),
14 m_slot(slot),
15 m_enabled(false)
16{
17 Q_ASSERT(slot != -1 && parent);
18}
19
20bool QQuickLabsPlatformIconLoader::isEnabled() const
21{
22 return m_enabled;
23}
24
25void QQuickLabsPlatformIconLoader::setEnabled(bool enabled)
26{
27 m_enabled = enabled;
28 if (m_enabled)
29 loadIcon();
30}
31
32QIcon QQuickLabsPlatformIconLoader::toQIcon() const
33{
34 QIcon fallback = QPixmap::fromImage(image: image());
35 QIcon icon = QIcon::fromTheme(name: m_icon.name(), fallback);
36 icon.setIsMask(m_icon.isMask());
37 return icon;
38}
39
40QQuickLabsPlatformIcon QQuickLabsPlatformIconLoader::icon() const
41{
42 return m_icon;
43}
44
45void QQuickLabsPlatformIconLoader::setIcon(const QQuickLabsPlatformIcon& icon)
46{
47 m_icon = icon;
48 if (m_enabled)
49 loadIcon();
50}
51
52void QQuickLabsPlatformIconLoader::loadIcon()
53{
54 if (m_icon.source().isEmpty()) {
55 clear(m_parent);
56 } else {
57 load(qmlEngine(m_parent), 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(index: m_slot).invoke(obj: m_parent);
66}
67
68QT_END_NAMESPACE
69

source code of qtdeclarative/src/labs/platform/qquicklabsplatformiconloader.cpp