Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
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
5
6#include <QtCore/qobject.h>
7#include <QtCore/qmetaobject.h>
8#include <QtQml/qqml.h>
9
11
13 : m_parent(parent),
14 m_slot(slot),
15 m_enabled(false)
16{
17 Q_ASSERT(slot != -1 && parent);
18}
19
21{
22 return m_enabled;
23}
24
26{
27 m_enabled = enabled;
28 if (m_enabled)
29 loadIcon();
30}
31
33{
34 const QIcon fallback = QPixmap::fromImage(image());
35 return QIcon::fromTheme(m_icon.name(), fallback);
36}
37
39{
40 return m_icon;
41}
42
44{
45 m_icon = icon;
46 if (m_enabled)
47 loadIcon();
48}
49
50void QQuickNativeIconLoader::loadIcon()
51{
52 if (m_icon.source().isEmpty()) {
53 clear(m_parent);
54 } else {
55 load(qmlEngine(m_parent), m_icon.source());
56 if (m_slot != -1 && isLoading()) {
57 connectFinished(m_parent, m_slot);
58 m_slot = -1;
59 }
60 }
61
62 if (!isLoading())
63 m_parent->metaObject()->method(m_slot).invoke(m_parent);
64}
65
The QIcon class provides scalable icons in different modes and states.
Definition qicon.h:20
static QIcon fromTheme(const QString &name)
Returns the QIcon corresponding to name in the \l{themeName()}{current icon theme}.
Definition qicon.cpp:1356
\inmodule QtCore
Definition qobject.h:103
static QPixmap fromImage(const QImage &image, Qt::ImageConversionFlags flags=Qt::AutoColor)
Converts the given image to a pixmap using the specified flags to control the conversion.
Definition qpixmap.cpp:1437
QString name
void setIcon(const QQuickIcon &icon)
QQuickNativeIconLoader(int slot, QObject *parent)
QImage image() const
void load(QQmlEngine *, const QUrl &)
bool isLoading() const
bool connectFinished(QObject *, const char *)
bool isEmpty() const
Returns true if the URL has no data; otherwise returns false.
Definition qurl.cpp:1896
Combined button and popup list for selecting options.
GLenum GLenum GLsizei const GLuint GLboolean enabled
QQmlEngine * qmlEngine(const QObject *obj)
Definition qqml.cpp:77
#define Q_ASSERT(cond)
Definition qrandom.cpp:47
#define enabled