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