8#include "QskFunctions.h"
9#include "QskLayoutElement.h"
10#include "QskPlatform.h"
11#include <qquickitem.h>
14#include <private/qquickitem_p.h>
15#include <private/qquickwindow_p.h>
16#include <private/qsgrenderer_p.h>
19#include <qpa/qplatforminputcontext.h>
20#include <qpa/qplatformintegration.h>
22QRhi* qskRenderingHardwareInterface(
const QQuickWindow* window )
24 if (
auto w =
const_cast< QQuickWindow*
>( window ) )
25 return QQuickWindowPrivate::get( w )->rhi;
30QRectF qskItemRect(
const QQuickItem* item )
32 auto d = QQuickItemPrivate::get( item );
33 return QRectF( 0, 0, d->width, d->height );
36QRectF qskItemGeometry(
const QQuickItem* item )
38 auto d = QQuickItemPrivate::get( item );
39 return QRectF( d->x, d->y, d->width, d->height );
42void qskSetItemGeometry( QQuickItem* item,
const QRectF& rect )
44 if (
auto control = qskControlCast( item ) )
46 control->setGeometry( rect );
50 item->setPosition( rect.topLeft() );
51 item->setSize( rect.size() );
55bool qskIsItemComplete(
const QQuickItem* item )
57 return QQuickItemPrivate::get( item )->componentComplete;
60bool qskIsItemInDestructor(
const QQuickItem* item )
62 auto d = QQuickItemPrivate::get( item );
64#if QT_VERSION >= QT_VERSION_CHECK( 6, 5, 0 )
65 return d->inDestructor;
71 return !d->componentComplete;
75bool qskIsAncestorOf(
const QQuickItem* item,
const QQuickItem* child )
77 if ( item ==
nullptr || child ==
nullptr )
80 return item->isAncestorOf( child );
83bool qskIsVisibleToParent(
const QQuickItem* item )
85 if ( item ==
nullptr )
88 return QQuickItemPrivate::get( item )->explicitVisible;
91bool qskIsVisibleTo(
const QQuickItem* item,
const QQuickItem* ancestor )
93 if ( item ==
nullptr )
96 if ( ancestor ==
nullptr )
97 return item->isVisible();
99 for (
auto it = item->parentItem();
100 it != ancestor; it = it->parentItem() )
105 if ( !QQuickItemPrivate::get( it )->explicitVisible )
112bool qskIsTabFence(
const QQuickItem* item )
114 if ( item ==
nullptr )
117 return QQuickItemPrivate::get( item )->isTabFence;
120bool qskIsPolishScheduled(
const QQuickItem* item )
123 return QQuickItemPrivate::get( item )->polishScheduled;
128bool qskIsShortcutScope(
const QQuickItem* item )
130 if ( item ==
nullptr )
143 return item->isFocusScope() && QQuickItemPrivate::get( item )->isTabFence;
146bool qskIsVisibleToLayout(
const QQuickItem* item )
151bool qskIsAdjustableByLayout(
const QQuickItem* item )
158 if (
auto control = qskControlCast( item ) )
159 return control->sizePolicy();
163 const QVariant v = item->property(
"sizePolicy" );
165 return qvariant_cast< QskSizePolicy >( v );
168 return QskSizePolicy( QskSizePolicy::Preferred, QskSizePolicy::Preferred );
171Qt::Alignment qskLayoutAlignmentHint(
const QQuickItem* item )
173 if (
auto control = qskControlCast( item ) )
174 return control->layoutAlignmentHint();
178 const QVariant v = item->property(
"layoutAlignmentHint" );
179 if ( v.canConvert< Qt::Alignment >() )
180 return v.value< Qt::Alignment >();
183 return Qt::Alignment();
188 if ( item ==
nullptr )
191 if (
auto control = qskControlCast( item ) )
193 control->setPlacementPolicy( policy );
197 item->setProperty(
"layoutPolicy", QVariant::fromValue( policy ) );
199 auto d = QQuickItemPrivate::get( item );
202 if ( ignore != d->isTransparentForPositioner() )
203 d->setTransparentForPositioner( ignore );
211 if ( item ==
nullptr )
214 if (
auto control = qskControlCast( item ) )
216 return control->placementPolicy();
222 const auto v = item->property(
"layoutPolicy" );
226 auto d = QQuickItemPrivate::get( item );
227 if ( d->isTransparentForPositioner() )
236 if ( item ==
nullptr )
239 const auto policy = qskPlacementPolicy( item );
241 if ( qskIsVisibleToParent( item ) )
247QQuickItem* qskNearestFocusScope(
const QQuickItem* item )
251 for (
auto scope = item->parentItem();
252 scope !=
nullptr; scope = scope->parentItem() )
254 if ( scope->isFocusScope() )
268void qskForceActiveFocus( QQuickItem* item, Qt::FocusReason reason )
275 if ( item ==
nullptr || item->window() ==
nullptr )
279#if QT_VERSION >= QT_VERSION_CHECK( 6, 1, 0 )
280 auto wp = QQuickItemPrivate::get( item )->deliveryAgentPrivate();
282 auto wp = QQuickWindowPrivate::get( item->window() );
284 while (
const auto scope = qskNearestFocusScope( item ) )
286 wp->setFocusInScope( scope, item, reason );
291void qskUpdateInputMethod(
const QQuickItem* item, Qt::InputMethodQueries queries )
293 if ( item ==
nullptr || !( item->flags() & QQuickItem::ItemAcceptsInputMethod ) )
296 static QPlatformInputContext* context =
nullptr;
297 static int methodId = -1;
305 auto inputContext = qskPlatformIntegration()->inputContext();
306 if ( inputContext ==
nullptr )
314 if ( inputContext != context )
316 context = inputContext;
317 methodId = inputContext->metaObject()->indexOfMethod(
318 "update(const QQuickItem*,Qt::InputMethodQueries)" );
330 const auto method = inputContext->metaObject()->method( methodId );
331 method.invoke( inputContext, Qt::DirectConnection,
332 Q_ARG(
const QQuickItem*, item ), Q_ARG( Qt::InputMethodQueries, queries ) );
336 QGuiApplication::inputMethod()->update( queries );
340void qskInputMethodSetVisible(
const QQuickItem* item,
bool on )
342 static QPlatformInputContext* context =
nullptr;
343 static int methodId = -1;
345 auto inputContext = qskPlatformIntegration()->inputContext();
346 if ( inputContext ==
nullptr )
354 if ( inputContext != context )
356 context = inputContext;
357 methodId = inputContext->metaObject()->indexOfMethod(
358 "setInputPanelVisible(const QQuickItem*,bool)" );
363 const auto method = inputContext->metaObject()->method( methodId );
364 method.invoke( inputContext, Qt::DirectConnection,
365 Q_ARG(
const QQuickItem*, item ), Q_ARG(
bool, on ) );
370 QGuiApplication::inputMethod()->show();
372 QGuiApplication::inputMethod()->hide();
376QList< QQuickItem* > qskPaintOrderChildItems(
const QQuickItem* item )
379 return QQuickItemPrivate::get( item )->paintOrderChildItems();
381 return QList< QQuickItem* >();
384const QSGTransformNode* qskItemNode(
const QQuickItem* item )
386 if ( item ==
nullptr )
389 return QQuickItemPrivate::get( item )->itemNodeInstance;
392const QSGNode* qskPaintNode(
const QQuickItem* item )
394 if ( item ==
nullptr )
397 return QQuickItemPrivate::get( item )->paintNode;
400const QSGRootNode* qskScenegraphAnchorNode(
const QQuickItem* item )
402 if ( item ==
nullptr )
405 return QQuickItemPrivate::get( item )->rootNode();
408const QSGRootNode* qskScenegraphAnchorNode(
const QQuickWindow* window )
410 if (
auto w =
const_cast< QQuickWindow*
>( window ) )
412 if (
auto renderer = QQuickWindowPrivate::get( w )->renderer )
413 return renderer->rootNode();
419void qskSetScenegraphAnchor( QQuickItem* item,
bool on )
434 auto d = QQuickItemPrivate::get( item );
436 d->refFromEffectItem(
false );
438 d->derefFromEffectItem(
false );
442QSizeF qskEffectiveSizeHint(
const QQuickItem* item,
443 Qt::SizeHint whichHint,
const QSizeF& constraint )
445 if (
auto control = qskControlCast( item ) )
446 return control->effectiveSizeHint( whichHint, constraint );
448 if ( constraint.width() >= 0.0 || constraint.height() >= 0.0 )
454 if ( item ==
nullptr )
467 static const char* properties[] =
474 const auto v = item->property( properties[ whichHint ] );
475 if ( v.canConvert< QSizeF >() )
478 if ( whichHint == Qt::PreferredSize )
480 if ( hint.width() < 0 )
481 hint.setWidth( item->implicitWidth() );
483 if ( hint.height() < 0 )
484 hint.setHeight( item->implicitHeight() );
490QSizeF qskSizeConstraint(
const QQuickItem* item,
491 Qt::SizeHint which,
const QSizeF& constraint )
493 if ( item ==
nullptr )
494 return QSizeF( 0, 0 );
497 return layoutElement.sizeConstraint( which, constraint );
500QSizeF qskConstrainedItemSize(
const QQuickItem* item,
const QSizeF& size )
502 if ( item ==
nullptr )
503 return QSizeF( 0.0, 0.0 );
506 return layoutElement.constrainedSize( size );
509QRectF qskConstrainedItemRect(
const QQuickItem* item,
510 const QRectF& rect, Qt::Alignment alignment )
512 const auto size = qskConstrainedItemSize( item, rect.size() );
513 return qskAlignedRectF( rect, size, alignment );
516void qskItemUpdateRecursive( QQuickItem* item )
518 if ( item ==
nullptr )
521 if ( item->flags() & QQuickItem::ItemHasContents )
524 const auto& children = QQuickItemPrivate::get( item )->childItems;
525 for (
auto child : children )
526 qskItemUpdateRecursive( child );
529#if QT_VERSION < QT_VERSION_CHECK( 6, 0, 0 )
531static const QQuickPointerTouchEvent* qskPointerPressEvent(
const QQuickWindowPrivate* wd )
533 for (
const auto event : std::as_const( wd->pointerEventInstances ) )
535 if (
auto touchEvent = event->asPointerTouchEvent() )
537 if ( touchEvent->isPressEvent() )
547bool qskGrabMouse( QQuickItem* item )
549 if ( item ==
nullptr || item->window() ==
nullptr )
552 if (
const auto mouseGrabber = item->window()->mouseGrabberItem() )
554 if ( mouseGrabber == item )
557 if ( mouseGrabber->keepMouseGrab() )
564 item->setKeepMouseGrab(
true );
566#if QT_VERSION < QT_VERSION_CHECK( 6, 0, 0 )
568 auto wd = QQuickWindowPrivate::get( item->window() );
569 if ( wd->touchMouseDevice ==
nullptr )
580 if (
const auto event = qskPointerPressEvent( wd ) )
582 if (
const auto p = event->point( 0 ) )
584 wd->touchMouseDevice =
event->device();
585 wd->touchMouseId = p->pointId();
589 wd->touchMouseDevice =
nullptr;
590 wd->touchMouseId = -1;
602void qskUngrabMouse( QQuickItem* item )
606 item->setKeepMouseGrab(
false );
608 if ( qskIsMouseGrabber( item ) )
613bool qskIsMouseGrabber(
const QQuickItem* item )
617 if (
const auto window = item->window() )
618 return window->mouseGrabberItem() == item;
Policy hiddenPolicy
Policy for the item, when being hidden ( to its parent )
Policy visiblePolicy
Policy for the item, when being visible ( to its parent )
void setVisiblePolicy(Policy) noexcept