using autoLayoutChildren instead of setting a contentItem explicitly

This commit is contained in:
Uwe Rathmann 2023-10-05 16:05:40 +02:00
parent 1132c7f878
commit f5de9d4249
3 changed files with 11 additions and 52 deletions

View File

@ -62,7 +62,12 @@ namespace
Drawer( QQuickItem* parent = nullptr ) Drawer( QQuickItem* parent = nullptr )
: QskDrawer( parent ) : 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->setSection( QskAspect::Header );
box->setPanel( true ); box->setPanel( true );
box->setPaddingHint( QskBox::Panel, 20 ); box->setPaddingHint( QskBox::Panel, 20 );
@ -75,8 +80,6 @@ namespace
auto btn = new QskPushButton( "Close", box ); auto btn = new QskPushButton( "Close", box );
connect( btn, &QskPushButton::clicked, this, &QskDrawer::close ); connect( btn, &QskPushButton::clicked, this, &QskDrawer::close );
setContent( box );
} }
}; };

View File

@ -13,8 +13,8 @@ QSK_QT_PRIVATE_BEGIN
#include <private/qquickitemchangelistener_p.h> #include <private/qquickitemchangelistener_p.h>
QSK_QT_PRIVATE_END QSK_QT_PRIVATE_END
// we need a skinlet to draw the panel TODO ...
QSK_SUBCONTROL( QskDrawer, Panel ) QSK_SUBCONTROL( QskDrawer, Panel )
QSK_SUBCONTROL( QskDrawer, Overlay )
static QRectF qskDrawerRect( const QRectF& rect, static QRectF qskDrawerRect( const QRectF& rect,
Qt::Edge edge, qreal pos, const QSizeF& size ) Qt::Edge edge, qreal pos, const QSizeF& size )
@ -82,9 +82,7 @@ namespace
class QskDrawer::PrivateData class QskDrawer::PrivateData
{ {
public: public:
QskControl* content = nullptr;
Qt::Edge edge = Qt::LeftEdge; Qt::Edge edge = Qt::LeftEdge;
GeometryListener* listener = nullptr; GeometryListener* listener = nullptr;
}; };
@ -94,10 +92,9 @@ QskDrawer::QskDrawer( QQuickItem* parentItem )
{ {
setZ( 1 ); setZ( 1 );
setAutoLayoutChildren( true );
setPopupFlag( PopupFlag::CloseOnPressOutside, true ); setPopupFlag( PopupFlag::CloseOnPressOutside, true );
setSubcontrolProxy( Inherited::Overlay, Overlay );
setFaderAspect( Panel | QskAspect::Position | QskAspect::Metric ); setFaderAspect( Panel | QskAspect::Position | QskAspect::Metric );
connect( this, &QskDrawer::closed, connect( this, &QskDrawer::closed,
@ -133,40 +130,6 @@ void QskDrawer::setEdge( Qt::Edge edge )
edgeChanged( 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 QRectF QskDrawer::layoutRectForSize( const QSizeF& size ) const
{ {
return Inherited::layoutRectForSize( size ); return Inherited::layoutRectForSize( size );
@ -177,16 +140,13 @@ void QskDrawer::updateLayout()
if ( !( isOpen() || isFading() ) ) if ( !( isOpen() || isFading() ) )
return; return;
if ( m_data->content == nullptr )
return;
const auto targetRect = qskItemRect( parentItem() ); const auto targetRect = qskItemRect( parentItem() );
const auto size = qskConstrainedItemSize( this, targetRect.size() ); const auto size = qskConstrainedItemSize( this, targetRect.size() );
const auto rect = qskDrawerRect( targetRect, const auto rect = qskDrawerRect( targetRect,
m_data->edge, metric( faderAspect() ), size ); m_data->edge, metric( faderAspect() ), size );
qskSetItemGeometry( m_data->content, rect ); qskSetItemGeometry( this, rect );
Inherited::updateLayout(); Inherited::updateLayout();
} }

View File

@ -18,7 +18,7 @@ class QSK_EXPORT QskDrawer : public QskPopup
Q_PROPERTY( Qt::Edge edge READ edge WRITE setEdge NOTIFY edgeChanged ) Q_PROPERTY( Qt::Edge edge READ edge WRITE setEdge NOTIFY edgeChanged )
public: public:
QSK_SUBCONTROLS( Panel, Overlay ) QSK_SUBCONTROLS( Panel )
QskDrawer( QQuickItem* = nullptr ); QskDrawer( QQuickItem* = nullptr );
~QskDrawer() override; ~QskDrawer() override;
@ -29,8 +29,6 @@ class QSK_EXPORT QskDrawer : public QskPopup
QRectF layoutRectForSize( const QSizeF& ) const override; QRectF layoutRectForSize( const QSizeF& ) const override;
void updateLayout() override; void updateLayout() override;
void setContent( QskControl* );
Q_SIGNALS: Q_SIGNALS:
void edgeChanged( Qt::Edge ); void edgeChanged( Qt::Edge );
@ -38,8 +36,6 @@ class QSK_EXPORT QskDrawer : public QskPopup
void aboutToShow() override; void aboutToShow() override;
void itemChange( ItemChange, const ItemChangeData& ) override; void itemChange( ItemChange, const ItemChangeData& ) override;
QSizeF layoutSizeHint( Qt::SizeHint, const QSizeF& ) const override;
private: private:
void startFading( bool ); void startFading( bool );