8#include "QskFunctions.h"
9#include "QskLayoutElement.h"
10#include "QskPlatform.h"
11#include "QskInternalMacros.h"
13#include <qquickitem.h>
16#include <private/qquickitem_p.h>
17#include <private/qquickwindow_p.h>
18#include <private/qsgrenderer_p.h>
21#include <qpa/qplatforminputcontext.h>
22#include <qpa/qplatformintegration.h>
24QRhi* qskRenderingHardwareInterface(
const QQuickWindow* window )
26 if (
auto w =
const_cast< QQuickWindow*
>( window ) )
27 return QQuickWindowPrivate::get( w )->rhi;
32QRectF qskItemRect(
const QQuickItem* item )
34 auto d = QQuickItemPrivate::get( item );
35 return QRectF( 0, 0, d->width, d->height );
38QRectF qskItemGeometry(
const QQuickItem* item )
40 auto d = QQuickItemPrivate::get( item );
41 return QRectF( d->x, d->y, d->width, d->height );
44void qskSetItemGeometry( QQuickItem* item,
const QRectF& rect )
46 if (
auto control = qskControlCast( item ) )
48 control->setGeometry( rect );
52 item->setPosition( rect.topLeft() );
53 item->setSize( rect.size() );
57bool qskIsItemComplete(
const QQuickItem* item )
59 return QQuickItemPrivate::get( item )->componentComplete;
62bool qskIsItemInDestructor(
const QQuickItem* item )
64 if ( item ==
nullptr )
67 auto d = QQuickItemPrivate::get( item );
69#if QT_VERSION >= QT_VERSION_CHECK( 6, 5, 0 )
70 return d->inDestructor;
76 return !d->componentComplete;
80bool qskIsAncestorOf(
const QQuickItem* item,
const QQuickItem* child )
82 if ( item ==
nullptr || child ==
nullptr )
85 return item->isAncestorOf( child );
88bool qskIsVisibleToParent(
const QQuickItem* item )
90 if ( item ==
nullptr )
93 return QQuickItemPrivate::get( item )->explicitVisible;
96bool qskIsVisibleTo(
const QQuickItem* item,
const QQuickItem* ancestor )
98 if ( item ==
nullptr )
101 if ( ancestor ==
nullptr )
102 return item->isVisible();
104 for (
auto it = item->parentItem();
105 it != ancestor; it = it->parentItem() )
110 if ( !QQuickItemPrivate::get( it )->explicitVisible )
117bool qskIsTabFence(
const QQuickItem* item )
119 if ( item ==
nullptr )
122 return QQuickItemPrivate::get( item )->isTabFence;
125bool qskIsPolishScheduled(
const QQuickItem* item )
128 return QQuickItemPrivate::get( item )->polishScheduled;
133bool qskIsShortcutScope(
const QQuickItem* item )
135 if ( item ==
nullptr )
148 return item->isFocusScope() && QQuickItemPrivate::get( item )->isTabFence;
151bool qskIsVisibleToLayout(
const QQuickItem* item )
156bool qskIsAdjustableByLayout(
const QQuickItem* item )
163 if (
auto control = qskControlCast( item ) )
164 return control->sizePolicy();
168 const QVariant v = item->property(
"sizePolicy" );
170 return qvariant_cast< QskSizePolicy >( v );
173 return QskSizePolicy( QskSizePolicy::Preferred, QskSizePolicy::Preferred );
176Qt::Alignment qskLayoutAlignmentHint(
const QQuickItem* item )
178 if (
auto control = qskControlCast( item ) )
179 return control->layoutAlignmentHint();
183 const QVariant v = item->property(
"layoutAlignmentHint" );
184 if ( v.canConvert< Qt::Alignment >() )
185 return v.value< Qt::Alignment >();
188 return Qt::Alignment();
193 if ( item ==
nullptr )
196 if (
auto control = qskControlCast( item ) )
198 control->setPlacementPolicy( policy );
202 item->setProperty(
"layoutPolicy", QVariant::fromValue( policy ) );
204 auto d = QQuickItemPrivate::get( item );
207 if ( ignore != d->isTransparentForPositioner() )
208 d->setTransparentForPositioner( ignore );
216 if ( item ==
nullptr )
219 if (
auto control = qskControlCast( item ) )
221 return control->placementPolicy();
227 const auto v = item->property(
"layoutPolicy" );
231 auto d = QQuickItemPrivate::get( item );
232 if ( d->isTransparentForPositioner() )
241 if ( item ==
nullptr )
244 const auto policy = qskPlacementPolicy( item );
246 if ( qskIsVisibleToParent( item ) )
252QQuickItem* qskNearestFocusScope(
const QQuickItem* item )
256 for (
auto scope = item->parentItem();
257 scope !=
nullptr; scope = scope->parentItem() )
259 if ( scope->isFocusScope() )
273void qskForceActiveFocus( QQuickItem* item, Qt::FocusReason reason )
280 if ( item ==
nullptr || item->window() ==
nullptr )
284#if QT_VERSION >= QT_VERSION_CHECK( 6, 1, 0 )
285 auto wp = QQuickItemPrivate::get( item )->deliveryAgentPrivate();
287 auto wp = QQuickWindowPrivate::get( item->window() );
289 while (
const auto scope = qskNearestFocusScope( item ) )
291 wp->setFocusInScope( scope, item, reason );
296void qskUpdateInputMethod(
const QQuickItem* item, Qt::InputMethodQueries queries )
298 if ( item ==
nullptr || !( item->flags() & QQuickItem::ItemAcceptsInputMethod ) )
301 static QPlatformInputContext* context =
nullptr;
302 static int methodId = -1;
310 auto inputContext = qskPlatformIntegration()->inputContext();
311 if ( inputContext ==
nullptr )
319 if ( inputContext != context )
321 context = inputContext;
322 methodId = inputContext->metaObject()->indexOfMethod(
323 "update(const QQuickItem*,Qt::InputMethodQueries)" );
335 const auto method = inputContext->metaObject()->method( methodId );
336 method.invoke( inputContext, Qt::DirectConnection,
337 Q_ARG(
const QQuickItem*, item ), Q_ARG( Qt::InputMethodQueries, queries ) );
341 QGuiApplication::inputMethod()->update( queries );
345void qskInputMethodSetVisible(
const QQuickItem* item,
bool on )
347 static QPlatformInputContext* context =
nullptr;
348 static int methodId = -1;
350 auto inputContext = qskPlatformIntegration()->inputContext();
351 if ( inputContext ==
nullptr )
359 if ( inputContext != context )
361 context = inputContext;
362 methodId = inputContext->metaObject()->indexOfMethod(
363 "setInputPanelVisible(const QQuickItem*,bool)" );
368 const auto method = inputContext->metaObject()->method( methodId );
369 method.invoke( inputContext, Qt::DirectConnection,
370 Q_ARG(
const QQuickItem*, item ), Q_ARG(
bool, on ) );
375 QGuiApplication::inputMethod()->show();
377 QGuiApplication::inputMethod()->hide();
381QList< QQuickItem* > qskPaintOrderChildItems(
const QQuickItem* item )
384 return QQuickItemPrivate::get( item )->paintOrderChildItems();
386 return QList< QQuickItem* >();
389const QSGTransformNode* qskItemNode(
const QQuickItem* item )
391 if ( item ==
nullptr )
394 return QQuickItemPrivate::get( item )->itemNodeInstance;
397const QSGNode* qskPaintNode(
const QQuickItem* item )
399 if ( item ==
nullptr )
402 return QQuickItemPrivate::get( item )->paintNode;
405const QSGRootNode* qskScenegraphAnchorNode(
const QQuickItem* item )
407 if ( item ==
nullptr )
410 return QQuickItemPrivate::get( item )->rootNode();
413const QSGRootNode* qskScenegraphAnchorNode(
const QQuickWindow* window )
415 if (
auto w =
const_cast< QQuickWindow*
>( window ) )
417 if (
auto renderer = QQuickWindowPrivate::get( w )->renderer )
418 return renderer->rootNode();
424void qskSetScenegraphAnchor( QQuickItem* item,
bool on )
439 auto d = QQuickItemPrivate::get( item );
441 d->refFromEffectItem(
false );
443 d->derefFromEffectItem(
false );
447QSizeF qskEffectiveSizeHint(
const QQuickItem* item,
448 Qt::SizeHint whichHint,
const QSizeF& constraint )
450 if (
auto control = qskControlCast( item ) )
451 return control->effectiveSizeHint( whichHint, constraint );
453 if ( constraint.width() >= 0.0 || constraint.height() >= 0.0 )
459 if ( item ==
nullptr )
472 static const char* properties[] =
479 const auto v = item->property( properties[ whichHint ] );
480 if ( v.canConvert< QSizeF >() )
483 if ( whichHint == Qt::PreferredSize )
485 if ( hint.width() < 0 )
486 hint.setWidth( item->implicitWidth() );
488 if ( hint.height() < 0 )
489 hint.setHeight( item->implicitHeight() );
495QSizeF qskSizeConstraint(
const QQuickItem* item,
496 Qt::SizeHint which,
const QSizeF& constraint )
498 if ( item ==
nullptr )
499 return QSizeF( 0, 0 );
502 return layoutElement.sizeConstraint( which, constraint );
505QSizeF qskConstrainedItemSize(
const QQuickItem* item,
const QSizeF& size )
507 if ( item ==
nullptr )
508 return QSizeF( 0.0, 0.0 );
511 return layoutElement.constrainedSize( size );
514QRectF qskConstrainedItemRect(
const QQuickItem* item,
515 const QRectF& rect, Qt::Alignment alignment )
517 const auto size = qskConstrainedItemSize( item, rect.size() );
518 return qskAlignedRectF( rect, size, alignment );
521void qskItemUpdateRecursive( QQuickItem* item )
523 if ( item ==
nullptr )
526 if ( item->flags() & QQuickItem::ItemHasContents )
529 const auto& children = QQuickItemPrivate::get( item )->childItems;
530 for (
auto child : children )
531 qskItemUpdateRecursive( child );
534#if QT_VERSION < QT_VERSION_CHECK( 6, 0, 0 )
536static const QQuickPointerTouchEvent* qskPointerPressEvent(
const QQuickWindowPrivate* wd )
538 for (
const auto event : std::as_const( wd->pointerEventInstances ) )
540 if (
auto touchEvent = event->asPointerTouchEvent() )
542 if ( touchEvent->isPressEvent() )
552bool qskGrabMouse( QQuickItem* item )
554 if ( item ==
nullptr || item->window() ==
nullptr )
557 if (
const auto mouseGrabber = item->window()->mouseGrabberItem() )
559 if ( mouseGrabber == item )
562 if ( mouseGrabber->keepMouseGrab() )
569 item->setKeepMouseGrab(
true );
571#if QT_VERSION < QT_VERSION_CHECK( 6, 0, 0 )
573 auto wd = QQuickWindowPrivate::get( item->window() );
574 if ( wd->touchMouseDevice ==
nullptr )
585 if (
const auto event = qskPointerPressEvent( wd ) )
587 if (
const auto p = event->point( 0 ) )
589 wd->touchMouseDevice =
event->device();
590 wd->touchMouseId = p->pointId();
594 wd->touchMouseDevice =
nullptr;
595 wd->touchMouseId = -1;
607void qskUngrabMouse( QQuickItem* item )
611 item->setKeepMouseGrab(
false );
613 if ( qskIsMouseGrabber( item ) )
618bool qskIsMouseGrabber(
const QQuickItem* item )
622 if (
const auto window = item->window() )
623 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