diff options
Diffstat (limited to 'src/labs/platform/qquicklabsplatformiconloader.cpp')
-rw-r--r-- | src/labs/platform/qquicklabsplatformiconloader.cpp | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/src/labs/platform/qquicklabsplatformiconloader.cpp b/src/labs/platform/qquicklabsplatformiconloader.cpp new file mode 100644 index 0000000000..d96694c892 --- /dev/null +++ b/src/labs/platform/qquicklabsplatformiconloader.cpp @@ -0,0 +1,68 @@ +// Copyright (C) 2017 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only + +#include "qquicklabsplatformiconloader_p.h" + +#include <QtCore/qobject.h> +#include <QtCore/qmetaobject.h> +#include <QtQml/qqml.h> + +QT_BEGIN_NAMESPACE + +QQuickLabsPlatformIconLoader::QQuickLabsPlatformIconLoader(int slot, QObject *parent) + : m_parent(parent), + m_slot(slot), + m_enabled(false) +{ + Q_ASSERT(slot != -1 && parent); +} + +bool QQuickLabsPlatformIconLoader::isEnabled() const +{ + return m_enabled; +} + +void QQuickLabsPlatformIconLoader::setEnabled(bool enabled) +{ + m_enabled = enabled; + if (m_enabled) + loadIcon(); +} + +QIcon QQuickLabsPlatformIconLoader::toQIcon() const +{ + QIcon fallback = QPixmap::fromImage(image()); + QIcon icon = QIcon::fromTheme(m_icon.name(), fallback); + icon.setIsMask(m_icon.isMask()); + return icon; +} + +QQuickLabsPlatformIcon QQuickLabsPlatformIconLoader::icon() const +{ + return m_icon; +} + +void QQuickLabsPlatformIconLoader::setIcon(const QQuickLabsPlatformIcon& icon) +{ + m_icon = icon; + if (m_enabled) + loadIcon(); +} + +void QQuickLabsPlatformIconLoader::loadIcon() +{ + if (m_icon.source().isEmpty()) { + clear(m_parent); + } else { + load(qmlEngine(m_parent), m_icon.source()); + if (m_slot != -1 && isLoading()) { + connectFinished(m_parent, m_slot); + m_slot = -1; + } + } + + if (!isLoading()) + m_parent->metaObject()->method(m_slot).invoke(m_parent); +} + +QT_END_NAMESPACE |