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
qquickicon.cpp
Go to the documentation of this file.
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// Qt-Security score:significant reason:default
4
5#include "qquickicon_p.h"
6
7#include <private/qqmlcontextdata_p.h>
8#include <private/qqmldata_p.h>
9
11
13{
14public:
15 // This is based on QFont's resolve_mask.
25 int resolveMask = 0;
26
30 int width = 0;
31 int height = 0;
33 bool cache = true;
34};
35
36QQuickIcon::QQuickIcon()
37 : d(new QQuickIconPrivate)
38{
39}
40
41QQuickIcon::QQuickIcon(const QQuickIcon &other)
42 : d(other.d)
43{
44}
45
46QQuickIcon::~QQuickIcon()
47{
48}
49
50QQuickIcon &QQuickIcon::operator=(const QQuickIcon &other)
51{
52 d = other.d;
53 return *this;
54}
55
56bool QQuickIcon::operator==(const QQuickIcon &other) const
57{
58 return d == other.d || (d->name == other.d->name
59 && d->source == other.d->source
60 && d->resolvedSource == other.d->resolvedSource
61 && d->width == other.d->width
62 && d->height == other.d->height
63 && d->color == other.d->color
64 && d->cache == other.d->cache);
65}
66
67bool QQuickIcon::operator!=(const QQuickIcon &other) const
68{
69 return !(*this == other);
70}
71
72bool QQuickIcon::isEmpty() const
73{
74 return d->name.isEmpty() && d->source.isEmpty();
75}
76
77QString QQuickIcon::name() const
78{
79 return d->name;
80}
81
82void QQuickIcon::setName(const QString &name)
83{
84 if ((d->resolveMask & QQuickIconPrivate::NameResolved) && d->name == name)
85 return;
86
87 d.detach();
88 d->name = name;
89 d->resolveMask |= QQuickIconPrivate::NameResolved;
90}
91
92void QQuickIcon::resetName()
93{
94 d.detach();
95 d->name = QString();
96 d->resolveMask &= ~QQuickIconPrivate::NameResolved;
97}
98
99QUrl QQuickIcon::source() const
100{
101 return d->source;
102}
103
104void QQuickIcon::setSource(const QUrl &source)
105{
106 if ((d->resolveMask & QQuickIconPrivate::SourceResolved) && d->source == source)
107 return;
108
109 d.detach();
110 d->source = source;
111 d->resolvedSource.clear();
112 d->resolveMask |= QQuickIconPrivate::SourceResolved;
113}
114
115void QQuickIcon::resetSource()
116{
117 d.detach();
118 d->source = QString();
119 d->resolvedSource.clear();
120 d->resolveMask &= ~QQuickIconPrivate::SourceResolved;
121}
122
123QUrl QQuickIcon::resolvedSource() const
124{
125 return d->resolvedSource.isEmpty() ? d->source : d->resolvedSource;
126}
127
128// must be called by the property owner (e.g. Button) prior to emitting changed signal.
129void QQuickIcon::ensureRelativeSourceResolved(const QObject *owner)
130{
131 if (d->source.isEmpty())
132 return;
133 if (!d->resolvedSource.isEmpty())
134 return; // already resolved relative to (possibly) different owner
135 const QQmlData *data = QQmlData::get(owner);
136 if (!data || !data->outerContext)
137 return;
138 d.detach();
139 d->resolvedSource = data->outerContext->resolvedUrl(d->source);
140}
141
142int QQuickIcon::width() const
143{
144 return d->width;
145}
146
147void QQuickIcon::setWidth(int width)
148{
149 if ((d->resolveMask & QQuickIconPrivate::WidthResolved) && d->width == width)
150 return;
151
152 d.detach();
153 d->width = width;
154 d->resolveMask |= QQuickIconPrivate::WidthResolved;
155}
156
157void QQuickIcon::resetWidth()
158{
159 d.detach();
160 d->width = 0;
161 d->resolveMask &= ~QQuickIconPrivate::WidthResolved;
162}
163
164int QQuickIcon::height() const
165{
166 return d->height;
167}
168
169void QQuickIcon::setHeight(int height)
170{
171 if ((d->resolveMask & QQuickIconPrivate::HeightResolved) && d->height == height)
172 return;
173
174 d.detach();
175 d->height = height;
176 d->resolveMask |= QQuickIconPrivate::HeightResolved;
177}
178
179void QQuickIcon::resetHeight()
180{
181 d.detach();
182 d->height = 0;
183 d->resolveMask &= ~QQuickIconPrivate::HeightResolved;
184}
185
186QColor QQuickIcon::color() const
187{
188 return d->color;
189}
190
191void QQuickIcon::setColor(const QColor &color)
192{
193 if ((d->resolveMask & QQuickIconPrivate::ColorResolved) && d->color == color)
194 return;
195
196 d.detach();
197 d->color = color;
198 d->resolveMask |= QQuickIconPrivate::ColorResolved;
199}
200
201void QQuickIcon::resetColor()
202{
203 d.detach();
204 d->color = Qt::transparent;
205 d->resolveMask &= ~QQuickIconPrivate::ColorResolved;
206}
207
208bool QQuickIcon::cache() const
209{
210 return d->cache;
211}
212
213void QQuickIcon::setCache(bool cache)
214{
215 if ((d->resolveMask & QQuickIconPrivate::CacheResolved) && d->cache == cache)
216 return;
217
218 d.detach();
219 d->cache = cache;
220 d->resolveMask |= QQuickIconPrivate::CacheResolved;
221}
222
223void QQuickIcon::resetCache()
224{
225 d.detach();
226 d->cache = true;
227 d->resolveMask &= ~QQuickIconPrivate::CacheResolved;
228}
229
230QQuickIcon QQuickIcon::resolve(const QQuickIcon &other) const
231{
232 QQuickIcon resolved = *this;
233 resolved.d.detach();
234
235 if (!(d->resolveMask & QQuickIconPrivate::NameResolved))
236 resolved.d->name = other.d->name;
237
238 if (!(d->resolveMask & QQuickIconPrivate::SourceResolved)) {
239 resolved.d->source = other.d->source;
240 resolved.d->resolvedSource = other.d->resolvedSource;
241 }
242
243 if (!(d->resolveMask & QQuickIconPrivate::WidthResolved))
244 resolved.d->width = other.d->width;
245
246 if (!(d->resolveMask & QQuickIconPrivate::HeightResolved))
247 resolved.d->height = other.d->height;
248
249 if (!(d->resolveMask & QQuickIconPrivate::ColorResolved))
250 resolved.d->color = other.d->color;
251
252 if (!(d->resolveMask & QQuickIconPrivate::CacheResolved))
253 resolved.d->cache = other.d->cache;
254
255 return resolved;
256}
257
258QT_END_NAMESPACE
259
260#include "moc_qquickicon_p.cpp"