From ee93306312f0a253ab6bf2af4f8b140fb0772c66 Mon Sep 17 00:00:00 2001 From: outfoxxed Date: Tue, 19 Nov 2024 02:57:04 -0800 Subject: [PATCH] widgets/wrapper: fix margin wrapper reactvity and margins Fixed reactivity of the paren't actual size not working before child had been assigned. Fixed incorrect margins when actual size is less than implicit size. --- src/widgets/marginwrapper.cpp | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/widgets/marginwrapper.cpp b/src/widgets/marginwrapper.cpp index b960a9f7..92de2935 100644 --- a/src/widgets/marginwrapper.cpp +++ b/src/widgets/marginwrapper.cpp @@ -20,6 +20,8 @@ MarginWrapperManager::MarginWrapperManager(QObject* parent): WrapperManager(pare } void MarginWrapperManager::componentComplete() { + this->WrapperManager::componentComplete(); + if (this->mWrapper) { QObject::connect( this->mWrapper, @@ -36,8 +38,6 @@ void MarginWrapperManager::componentComplete() { ); } - this->WrapperManager::componentComplete(); - if (!this->mChild) this->updateGeometry(); } @@ -97,12 +97,19 @@ qreal MarginWrapperManager::targetChildHeight() const { qreal MarginWrapperManager::targetChildX() const { if (this->mResizeChild) return this->mMargin; - else return this->mWrapper->width() / 2 - this->mChild->implicitWidth() / 2; + else { + return std::max(this->mMargin, this->mWrapper->width() / 2 - this->mChild->implicitWidth() / 2); + } } qreal MarginWrapperManager::targetChildY() const { if (this->mResizeChild) return this->mMargin; - else return this->mWrapper->height() / 2 - this->mChild->implicitHeight() / 2; + else { + return std::max( + this->mMargin, + this->mWrapper->height() / 2 - this->mChild->implicitHeight() / 2 + ); + } } void MarginWrapperManager::onWrapperWidthChanged() {