From de6ab7f7aa142bb96df37404925b03f23180e79f Mon Sep 17 00:00:00 2001 From: Uwe Rathmann Date: Sat, 24 Mar 2018 18:05:57 +0100 Subject: [PATCH] qskSetItemGeometry added --- src/controls/QskControl.cpp | 27 +++++++++++++++++++++------ src/controls/QskControl.h | 2 ++ src/controls/QskWindow.cpp | 8 +++----- src/layouts/QskLayoutItem.cpp | 3 +-- 4 files changed, 27 insertions(+), 13 deletions(-) diff --git a/src/controls/QskControl.cpp b/src/controls/QskControl.cpp index 0ec29ee4..bb023530 100644 --- a/src/controls/QskControl.cpp +++ b/src/controls/QskControl.cpp @@ -54,6 +54,19 @@ QRectF qskItemGeometry( const QQuickItem* item ) return QRectF( d->x, d->y, d->width, d->height ); } +void qskSetItemGeometry( QQuickItem* item, const QRectF& rect ) +{ + if ( auto control = qobject_cast< QskControl* >( item ) ) + { + control->setGeometry( rect ); + } + else + { + item->setPosition( rect.topLeft() ); + item->setSize( rect.size() ); + } +} + bool qskIsItemComplete( const QQuickItem* item ) { return QQuickItemPrivate::get( item )->componentComplete; @@ -270,7 +283,7 @@ Q_GLOBAL_STATIC( QskControlRegistry, qskRegistry ) class QskControlPrivate final : public QQuickItemPrivate { - Q_DECLARE_PUBLIC(QskControl) + Q_DECLARE_PUBLIC( QskControl ) public: QskControlPrivate(): @@ -309,7 +322,7 @@ public: } } - void mirrorChange() override + virtual void mirrorChange() override final { Q_Q( QskControl ); qskSendEventTo( q, QEvent::LayoutDirectionChange ); @@ -540,6 +553,11 @@ void QskControl::setGeometry( qreal x, qreal y, qreal width, qreal height ) if ( dirtyType & QQuickItemPrivate::Size ) d->dirty( QQuickItemPrivate::Size ); + /* + Unfortunately geometryChanged is protected and we can't implement + this code as qskSetItemGeometry - further hacking required: TODO ... + */ + geometryChanged( QRectF( d->x, d->y, d->width, d->height ), oldRect ); } } @@ -1419,10 +1437,7 @@ void QskControl::updatePolish() for ( auto child : children ) { if ( !QQuickItemPrivate::get( child )->isTransparentForPositioner() ) - { - child->setPosition( rect.topLeft() ); - child->setSize( rect.size() ); - } + qskSetItemGeometry( child, rect ); } } diff --git a/src/controls/QskControl.h b/src/controls/QskControl.h index b0d74a44..d7ccd23e 100644 --- a/src/controls/QskControl.h +++ b/src/controls/QskControl.h @@ -253,8 +253,10 @@ QSK_EXPORT bool qskIsAncestorOf( const QQuickItem* item, const QQuickItem *child QSK_EXPORT bool qskIsTransparentForPositioner( const QQuickItem* ); QSK_EXPORT bool qskIsTabFence( const QQuickItem* ); QSK_EXPORT bool qskIsShortcutScope( const QQuickItem* ); + QSK_EXPORT QRectF qskItemRect( const QQuickItem* ); QSK_EXPORT QRectF qskItemGeometry( const QQuickItem* ); +QSK_EXPORT void qskSetItemGeometry( QQuickItem*, const QRectF& ); QSK_EXPORT QQuickItem* qskNearestFocusScope( const QQuickItem* ); QSK_EXPORT QList qskPaintOrderChildItems( const QQuickItem* ); diff --git a/src/controls/QskWindow.cpp b/src/controls/QskWindow.cpp index e78043b3..ec13b6fb 100644 --- a/src/controls/QskWindow.cpp +++ b/src/controls/QskWindow.cpp @@ -73,6 +73,7 @@ namespace QCoreApplication::postEvent( window, new QEvent( QEvent::LayoutRequest ) ); } } + private: QQuickItem* m_item; }; @@ -423,16 +424,13 @@ void QskWindow::layoutItems() if ( !d->autoLayoutChildren ) return; - const QSizeF sz( contentItem()->width(), contentItem()->height() ); + const QRectF rect = qskItemGeometry( contentItem() ); const auto children = contentItem()->childItems(); for ( auto child : children ) { if ( !qskIsTransparentForPositioner( child ) ) - { - child->setPosition( contentItem()->position() ); - child->setSize( sz ); - } + qskSetItemGeometry( child, rect ); } } diff --git a/src/layouts/QskLayoutItem.cpp b/src/layouts/QskLayoutItem.cpp index df0450f8..8fba1204 100644 --- a/src/layouts/QskLayoutItem.cpp +++ b/src/layouts/QskLayoutItem.cpp @@ -168,8 +168,7 @@ void QskLayoutItem::setGeometry( const QRectF& rect ) } m_isGeometryDirty = false; - m_item->setPosition( rect.topLeft() ); - m_item->setSize( rect.size() ); + qskSetItemGeometry( m_item, rect ); } bool QskLayoutItem::hasDynamicConstraint() const