From 1132c7f878f4053beed564c559cafe328c85c7c4 Mon Sep 17 00:00:00 2001 From: Uwe Rathmann Date: Thu, 5 Oct 2023 15:24:17 +0200 Subject: [PATCH] internal QskBox eliminated --- src/controls/QskDrawer.cpp | 66 +++++++++++++++++++------------------- src/controls/QskDrawer.h | 5 +++ 2 files changed, 38 insertions(+), 33 deletions(-) diff --git a/src/controls/QskDrawer.cpp b/src/controls/QskDrawer.cpp index bc3ebe30..dc0ccdcc 100644 --- a/src/controls/QskDrawer.cpp +++ b/src/controls/QskDrawer.cpp @@ -1,11 +1,12 @@ +/****************************************************************************** + * QSkinny - Copyright (C) 2016 Uwe Rathmann + * SPDX-License-Identifier: BSD-3-Clause + *****************************************************************************/ + #include "QskDrawer.h" #include "QskAspect.h" -#include "QskControl.h" - -#include -#include -#include -#include +#include "QskAnimationHint.h" +#include "QskQuick.h" QSK_QT_PRIVATE_BEGIN #include @@ -76,32 +77,12 @@ namespace private: QskDrawer* m_drawer = nullptr; }; - - class Box : public QskBox - { - using Inherited = QskBox; - - public: - Box( QskDrawer* drawer ) - : QskBox( drawer ) - { - setSubcontrolProxy( QskBox::Panel, Panel ); - setPanel( true ); - setAutoLayoutChildren( true ); - -#if 0 - setBackgroundColor( Qt::darkCyan ); - setMargins( 20 ); -#endif - } - }; } class QskDrawer::PrivateData { public: QskControl* content = nullptr; - Box* contentBox = nullptr; Qt::Edge edge = Qt::LeftEdge; GeometryListener* listener = nullptr; @@ -115,8 +96,6 @@ QskDrawer::QskDrawer( QQuickItem* parentItem ) setPopupFlag( PopupFlag::CloseOnPressOutside, true ); - m_data->contentBox = new Box(this); - setSubcontrolProxy( Inherited::Overlay, Overlay ); setFaderAspect( Panel | QskAspect::Position | QskAspect::Metric ); @@ -156,18 +135,36 @@ void QskDrawer::setEdge( Qt::Edge edge ) void QskDrawer::setContent( QskControl* content ) { - content->setParentItem( m_data->contentBox ); - if ( content->parent() == nullptr ) - content->setParent( m_data->contentBox ); + 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 - return m_data->contentBox->effectiveSizeHint( which, constraint ); + if ( m_data->content ) + return m_data->content->effectiveSizeHint( which, constraint ); + + return Inherited::layoutSizeHint( which, constraint ); } QRectF QskDrawer::layoutRectForSize( const QSizeF& size ) const @@ -180,13 +177,16 @@ 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->contentBox, rect ); + qskSetItemGeometry( m_data->content, rect ); Inherited::updateLayout(); } diff --git a/src/controls/QskDrawer.h b/src/controls/QskDrawer.h index 313760d5..b2495991 100644 --- a/src/controls/QskDrawer.h +++ b/src/controls/QskDrawer.h @@ -1,3 +1,8 @@ +/****************************************************************************** + * QSkinny - Copyright (C) 2016 Uwe Rathmann + * SPDX-License-Identifier: BSD-3-Clause + *****************************************************************************/ + #ifndef QSK_DRAWER_H #define QSK_DRAWER_H