From f5de9d4249527ef5db1c99f1c7b5f7facf8faf34 Mon Sep 17 00:00:00 2001 From: Uwe Rathmann Date: Thu, 5 Oct 2023 16:05:40 +0200 Subject: [PATCH] using autoLayoutChildren instead of setting a contentItem explicitly --- examples/gallery/main.cpp | 9 ++++--- src/controls/QskDrawer.cpp | 48 ++++---------------------------------- src/controls/QskDrawer.h | 6 +---- 3 files changed, 11 insertions(+), 52 deletions(-) diff --git a/examples/gallery/main.cpp b/examples/gallery/main.cpp index 2978469d..88df97a9 100644 --- a/examples/gallery/main.cpp +++ b/examples/gallery/main.cpp @@ -62,7 +62,12 @@ namespace Drawer( QQuickItem* parent = nullptr ) : QskDrawer( parent ) { - auto box = new QskLinearBox( Qt::Vertical ); +#if 1 + setOverlay( true ); +#endif + + auto box = new QskLinearBox( Qt::Vertical, this ); + box->setSection( QskAspect::Header ); box->setPanel( true ); box->setPaddingHint( QskBox::Panel, 20 ); @@ -75,8 +80,6 @@ namespace auto btn = new QskPushButton( "Close", box ); connect( btn, &QskPushButton::clicked, this, &QskDrawer::close ); - - setContent( box ); } }; diff --git a/src/controls/QskDrawer.cpp b/src/controls/QskDrawer.cpp index dc0ccdcc..9ebe6045 100644 --- a/src/controls/QskDrawer.cpp +++ b/src/controls/QskDrawer.cpp @@ -13,8 +13,8 @@ QSK_QT_PRIVATE_BEGIN #include QSK_QT_PRIVATE_END +// we need a skinlet to draw the panel TODO ... QSK_SUBCONTROL( QskDrawer, Panel ) -QSK_SUBCONTROL( QskDrawer, Overlay ) static QRectF qskDrawerRect( const QRectF& rect, Qt::Edge edge, qreal pos, const QSizeF& size ) @@ -82,9 +82,7 @@ namespace class QskDrawer::PrivateData { public: - QskControl* content = nullptr; Qt::Edge edge = Qt::LeftEdge; - GeometryListener* listener = nullptr; }; @@ -94,10 +92,9 @@ QskDrawer::QskDrawer( QQuickItem* parentItem ) { setZ( 1 ); + setAutoLayoutChildren( true ); + setPopupFlag( PopupFlag::CloseOnPressOutside, true ); - - setSubcontrolProxy( Inherited::Overlay, Overlay ); - setFaderAspect( Panel | QskAspect::Position | QskAspect::Metric ); connect( this, &QskDrawer::closed, @@ -133,40 +130,6 @@ void QskDrawer::setEdge( Qt::Edge edge ) edgeChanged( edge ); } -void QskDrawer::setContent( QskControl* content ) -{ - if ( content == m_data->content ) - return; - - if ( m_data->content ) - { - if ( m_data->content->parent() == this ) - delete m_data->content; - else - m_data->content->setParentItem( nullptr ); - } - - if ( content ) - { - content->setParentItem( this ); - if ( content->parent() == nullptr ) - content->setParent( this ); - } - - m_data->content = content; - polish(); -} - -QSizeF QskDrawer::layoutSizeHint( - Qt::SizeHint which, const QSizeF& constraint ) const -{ - // we need to handle QEvent::LayoutRequest - if ( m_data->content ) - return m_data->content->effectiveSizeHint( which, constraint ); - - return Inherited::layoutSizeHint( which, constraint ); -} - QRectF QskDrawer::layoutRectForSize( const QSizeF& size ) const { return Inherited::layoutRectForSize( size ); @@ -177,16 +140,13 @@ void QskDrawer::updateLayout() if ( !( isOpen() || isFading() ) ) return; - if ( m_data->content == nullptr ) - return; - const auto targetRect = qskItemRect( parentItem() ); const auto size = qskConstrainedItemSize( this, targetRect.size() ); const auto rect = qskDrawerRect( targetRect, m_data->edge, metric( faderAspect() ), size ); - qskSetItemGeometry( m_data->content, rect ); + qskSetItemGeometry( this, rect ); Inherited::updateLayout(); } diff --git a/src/controls/QskDrawer.h b/src/controls/QskDrawer.h index b2495991..b5b26447 100644 --- a/src/controls/QskDrawer.h +++ b/src/controls/QskDrawer.h @@ -18,7 +18,7 @@ class QSK_EXPORT QskDrawer : public QskPopup Q_PROPERTY( Qt::Edge edge READ edge WRITE setEdge NOTIFY edgeChanged ) public: - QSK_SUBCONTROLS( Panel, Overlay ) + QSK_SUBCONTROLS( Panel ) QskDrawer( QQuickItem* = nullptr ); ~QskDrawer() override; @@ -29,8 +29,6 @@ class QSK_EXPORT QskDrawer : public QskPopup QRectF layoutRectForSize( const QSizeF& ) const override; void updateLayout() override; - void setContent( QskControl* ); - Q_SIGNALS: void edgeChanged( Qt::Edge ); @@ -38,8 +36,6 @@ class QSK_EXPORT QskDrawer : public QskPopup void aboutToShow() override; void itemChange( ItemChange, const ItemChangeData& ) override; - QSizeF layoutSizeHint( Qt::SizeHint, const QSizeF& ) const override; - private: void startFading( bool );