6#include <QtQuick3D/private/qquick3dnode_p_p.h>
7#include <QtQuick/private/qquickrectangle_p.h>
15 Q_DECLARE_PUBLIC(QQuick3DXrItem)
73 if (m_automaticHeightConnection && ((m_contentItem ==
nullptr) || !m_automaticHeight)) {
74 QObject::disconnect(m_automaticHeightConnection);
75 m_automaticHeightConnection = {};
78 m_automaticHeightConnection = QObject::connect(m_contentItem, &QQuickItem::heightChanged, q, [
this, q](){
79 qreal newHeight = m_contentItem->height()/m_pixelsPerUnit;
80 if (m_height != newHeight) {
82 emit q->heightChanged();
92 if (m_automaticWidthConnection && ((m_contentItem ==
nullptr) || !m_automaticHeight)) {
93 QObject::disconnect(m_automaticWidthConnection);
94 m_automaticWidthConnection = {};
98 m_automaticWidthConnection = QObject::connect(m_contentItem, &QQuickItem::widthChanged, q, [
this, q](){
99 qreal newWidth = m_contentItem->width()/m_pixelsPerUnit;
100 if (m_width != newWidth) {
102 emit q->widthChanged();
126 return (diagonal > 0) ? std::sqrt((pxWidth * pxWidth) + (pxHeight * pxHeight)) / diagonal : 1.0;
131 if (!componentComplete)
135 m_containerItem->setColor(m_color);
137 if (Q_UNLIKELY(m_manualPixelsPerUnit && m_pixelsPerUnit < 0)) {
138 qWarning() <<
"XrItem invalid pixelPerUnit" << m_pixelsPerUnit;
143 newScale = 1.0 / m_pixelsPerUnit;
146 qreal diagonal = std::sqrt((m_width * m_width) + (m_height * m_height));
147 qreal ppu = calculatePPU(m_contentItem->width(), m_contentItem->height(), diagonal);
150 q->setPixelsPerUnit(ppu);
151 newScale = 1.0 / ppu;
153 QSizeF newSize(m_width / newScale, m_height / newScale);
154 m_containerItem->setSize(newSize);
155 m_containerItem->setScale(newScale);
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
190 : QQuick3DNode(*(
new QQuick3DXrItemPrivate()), parent)
198 d->m_XrView->unregisterXrItem(
this);
204 QQuick3DNode::componentComplete();
206 auto findView = [
this]() -> QQuick3DXrView * {
207 QQuick3DNode *parent = parentNode();
209 if (
auto *xrView = qobject_cast<QQuick3DXrView*>(parent))
211 parent = parent->parentNode();
215 d->m_XrView = findView();
217 d->m_XrView->registerXrItem(
this);
219 qWarning(
"Could not find XrView for XrItem");
224
225
226
227
228
229
230
233 Q_D(
const QQuick3DXrItem);
234 return d->m_contentItem;
240 if (d->m_contentItem == newContentItem)
243 d->setContentItem(newContentItem);
244 emit contentItemChanged();
248
249
250
251
252
253
254
255
256
257
260 Q_D(
const QQuick3DXrItem);
261 return d->m_pixelsPerUnit;
267 if (qFuzzyCompare(d->m_pixelsPerUnit, newPixelsPerUnit))
270 d->m_pixelsPerUnit = newPixelsPerUnit;
272 if (d->m_manualPixelsPerUnit)
275 emit pixelsPerUnitChanged();
279
280
281
282
283
284
285
286
287
291 Q_D(
const QQuick3DXrItem);
292 return d->m_manualPixelsPerUnit;
298 if (d->m_manualPixelsPerUnit == newManualPixelsPerUnit)
300 d->m_manualPixelsPerUnit = newManualPixelsPerUnit;
302 emit manualPixelsPerUnitChanged();
306
307
308
309
310
314 Q_D(
const QQuick3DXrItem);
321 if ((d->m_width == newWidth) || d->m_automaticWidth)
323 d->m_width = newWidth;
330
331
332
333
334
338 Q_D(
const QQuick3DXrItem);
345 if ((d->m_height == newHeight) || d->m_automaticHeight)
347 d->m_height = newHeight;
348 emit heightChanged();
354
355
356
357
358
359
363 Q_D(
const QQuick3DXrItem);
370 if (d->m_color == newColor)
372 d->m_color = newColor;
378
379
380
381
382
383
384
388 Q_D(
const QQuick3DXrItem);
389 return d->m_automaticHeight;
395 if (d->m_automaticHeight == newAutomaticHeight) {
399 d->m_automaticHeight = newAutomaticHeight;
400 d->setAutomaticHeightConnection();
402 emit automaticHeightChanged();
406
407
408
409
410
411
412
416 Q_D(
const QQuick3DXrItem);
417 return d->m_automaticWidth;
423 if (d->m_automaticWidth == newAutomaticWidth)
426 d->m_automaticWidth = newAutomaticWidth;
427 d->setAutomaticWidthConnection();
429 emit automaticWidthChanged();
QQuickItem * m_contentItem
QPointer< QQuick3DXrView > m_XrView
QQuickRectangle * m_containerItem
QMetaObject::Connection m_automaticHeightConnection
QMetaObject::Connection m_contentItemDestroyedConnection
void setAutomaticHeightConnection()
void setAutomaticWidthConnection()
QMetaObject::Connection m_automaticWidthConnection
bool m_manualPixelsPerUnit
bool manualPixelsPerUnit() const
\qmlproperty bool XrItem::manualPixelsPerUnit
void setAutomaticWidth(bool newAutomaticHeight)
void setWidth(qreal newWidth)
qreal width() const
\qmlproperty real XrItem::width
void setColor(const QColor &newColor)
void setManualPixelsPerUnit(bool newManualPixelsPerUnit)
void setPixelsPerUnit(qreal newPixelsPerUnit)
QColor color() const
\qmlproperty color XrItem::color
qreal height() const
\qmlproperty real XrItem::height
bool automaticHeight() const
\qmlproperty bool XrItem::automaticHeight
bool automaticWidth() const
\qmlproperty bool XrItem::automaticWidth
QQuickItem * contentItem() const
\qmlproperty Item XrItem::contentItem
void setHeight(qreal newHeight)
~QQuick3DXrItem() override
qreal pixelsPerUnit() const
\qmlproperty real XrItem::pixelsPerUnit
void setAutomaticHeight(bool newAutomaticHeight)
void setContentItem(QQuickItem *newContentItem)
void componentComplete() override
Invoked after the root component that caused this instantiation has completed construction.
Combined button and popup list for selecting options.
static qreal calculatePPU(qreal pxWidth, qreal pxHeight, qreal diagonal)