Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Toggle main menu visibility
Loading...
Searching...
No Matches
qquickitemspy.cpp
Go to the documentation of this file.
1
// Copyright (C) 2025 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
"qquickitemspy_p.h"
5
6
#
include
<
QtQuick
/
private
/
qquickitem_p
.
h
>
7
#
include
<
QtGui
/
rhi
/
qrhi
.
h
>
8
9
QT_BEGIN_NAMESPACE
10
11
/*!
12
\qmltype ItemSpy
13
\inqmlmodule QtQuick.VectorImage.Helpers
14
\brief Provides a way to track the world size of an item and bind to it.
15
\since 6.11
16
17
This type is used by VectorImage. It enables adjusting a post-processing effect's texture
18
size to automatically match the on-screen size of an item subtree.
19
*/
20
QQuickItemSpy::QQuickItemSpy(QQuickItem *parent)
21
: QQuickItem(parent)
22
{
23
setFlag(ItemObservesViewport);
24
}
25
26
QQuickItemSpy::~QQuickItemSpy()
27
{
28
}
29
30
/*!
31
\qmlproperty size QtQuick.VectorImage.Helpers::ItemSpy::requiredTextureSize
32
33
The texture size needed to render this item's width and height without scaling artifacts.
34
This accounts for the current transform as well as high-dpi scaling.
35
36
\note The returned size will never exceed the maximum supported texture size, and it will
37
never be smaller than \c{1x1}.
38
*/
39
QSizeF QQuickItemSpy::requiredTextureSize()
const
40
{
41
QSizeF sz = mapRectToScene(QRectF(0, 0, width(), height())).size();
42
43
const
qreal dpr = window() !=
nullptr
? window()->devicePixelRatio() : 1.0;
44
45
const
qreal mappedWidth = sz.width() * dpr;
46
const
qreal mappedHeight = sz.height() * dpr;
47
sz.setWidth(qIsFinite(mappedWidth) ? std::max(1.0, mappedWidth) : 1.0);
48
sz.setHeight(qIsFinite(mappedHeight) ? std::max(1.0, mappedHeight) : 1.0);
49
50
if
(window() !=
nullptr
&& window()->rhi() !=
nullptr
) {
51
QRhi *rhi = window()->rhi();
52
const
int
textureSizeMax = rhi->resourceLimit(QRhi::TextureSizeMax);
53
54
if
(sz.width() > textureSizeMax || sz.height() > textureSizeMax) {
55
if
(sz.width() > sz.height())
56
sz = QSizeF(textureSizeMax, sz.height() * (textureSizeMax / sz.width()));
57
else
58
sz = QSizeF(sz.width() * (textureSizeMax / sz.height()), textureSizeMax);
59
}
60
}
61
62
return
sz;
63
}
64
65
void
QQuickItemSpy::itemChange(ItemChange change,
const
ItemChangeData &value)
66
{
67
if
(change == ItemTransformHasChanged || change == ItemDevicePixelRatioHasChanged)
68
emit requiredTextureSizeChanged();
69
70
QQuickItem::itemChange(change, value);
71
}
72
73
74
QT_END_NAMESPACE
QT_BEGIN_NAMESPACE
Combined button and popup list for selecting options.
Definition
qsequentialanimationgroup.cpp:47
qtdeclarative
src
quickvectorimage
helpers
qquickitemspy.cpp
Generated on
for Qt by
1.18.0