From 912d768a616546628fd8c991bf716c4c43c1a7e7 Mon Sep 17 00:00:00 2001 From: Uwe Rathmann Date: Fri, 18 Nov 2022 13:20:21 +0100 Subject: [PATCH] QskControl::Background subcontrol introduced allowing to have a default setting for all backgrounds ( color, padding ) without changing the overall fallback settings. This made it possible to remove the confusing autoFillBackground property. --- doc/classes/QskControl.dox | 71 +++++++++--------------------- examples/layouts/layouts.qml | 2 - src/controls/QskControl.cpp | 30 ++++--------- src/controls/QskControl.h | 11 ++--- src/controls/QskControlPrivate.cpp | 1 - src/controls/QskControlPrivate.h | 1 - src/controls/QskSkin.cpp | 8 +++- src/controls/QskSkinTransition.cpp | 10 +---- src/controls/QskSkinlet.cpp | 5 +-- 9 files changed, 41 insertions(+), 98 deletions(-) diff --git a/doc/classes/QskControl.dox b/doc/classes/QskControl.dox index 0a578f59..04c57754 100644 --- a/doc/classes/QskControl.dox +++ b/doc/classes/QskControl.dox @@ -56,18 +56,6 @@ \accessors locale(), setLocale(), resetLocale(), localeChanged() */ -/*! - \property bool QskControl::autoFillBackground - - This property holds whether the background is filled automatically - with the background gradient. - - \accessors autoFillBackground(), setAutoFillBackground() - - \sa background() - \saqt QWidget::autoFillBackground -*/ - /*! \property bool QskControl::autoLayoutChildren @@ -223,11 +211,8 @@ Sets the margins around the contents of the control - The value is stored in the local hint table for the aspect: - QskControl::Control | QskAspect::Metric | QskAspect::Margin - \param margin Margin for all sides - \aspect QskControl::Control | QskAspect::Metric | QskAspect::Margin + \aspect QskControl::Background | QskAspect::Metric | QskAspect::Padding \sa contentsRect(), margins(), QskSkinnable::setMarginHint() */ @@ -235,15 +220,14 @@ /*! \fn QskControl::setMargins( qreal, qreal, qreal, qreal ) - The value is stored in the local hint table for the aspect: - QskControl::Control | QskAspect::Metric | QskAspect::Margin + Sets the margins around the contents of the control \param left Left margin \param top Top margin \param right Right margin \param bottom Bottom margin - \aspect QskControl::Control | QskAspect::Metric | QskAspect::Margin + \aspect QskControl::Background | QskAspect::Metric | QskAspect::Padding \sa contentsRect(), margins(), QskSkinnable::setMarginHint() */ @@ -254,7 +238,7 @@ Sets the margins around the contents of the control \param margins Margins - \aspect QskControl::Control | QskAspect::Metric | QskAspect::Margin + \aspect QskControl::Background | QskAspect::Metric | QskAspect::Padding \sa contentsRect(), margins() \saqt QEvent::ContentsRectChange @@ -265,7 +249,7 @@ Reset the margins to the default value provided from the skin - \aspect QskControl::Control | QskAspect::Metric | QskAspect::Margin + \aspect QskControl::Background | QskAspect::Metric | QskAspect::Padding \sa contentsRect(), setMargins(), margins() \saqt QEvent::ContentsRectChange @@ -275,7 +259,7 @@ \fn QskControl::margins() const \return margins around the contents of the control - \aspect QskControl::Control | QskAspect::Metric | QskAspect::Margin + \aspect QskControl::Background | QskAspect::Metric | QskAspect::Padding \sa contentsRect(), setMargins() \saqt QEvent::ContentsRectChange @@ -284,11 +268,12 @@ /*! \fn QskControl::setBackgroundColor - A conveninece method that enables the \ref autoFillBackground property - and sets a solid color as background. Usually used for debugging - layout problems. + A conveninece method for setting a monochrome gradient as background. Often used + for debugging layout problems. - \sa setBackground(), setAutoFillBackground() + \aspect QskControl::Background | QskAspect::Color + + \sa setBackground() \sa QskQuickItem::DebugForceBackground */ @@ -296,10 +281,9 @@ \fn QskControl::setBackground Set the gradient that is used to fill the background, - when \ref autoFillBackground is enabled. - \aspect QskControl::Control | QskAspect::Color - \sa resetBackground(), background(), autoFillBackground() + \aspect QskControl::Background | QskAspect::Color + \sa resetBackground(), background(), setBackgroundColor */ /*! @@ -307,18 +291,17 @@ Reset the background gradient to the default colors from the skin - \aspect QskControl::Control | QskAspect::Color - \sa setBackground(), background(), autoFillBackground() + \aspect QskControl::Background | QskAspect::Color + \sa setBackground(), setBackgroundColor(), background() */ /*! \fn QskControl::background() const - \return Gradient that is used to fill the background, - when autoFillBackground is enabled. + \return Gradient that is used to fill the background - \aspect QskControl::Control | QskAspect::Color - \sa setBackground(), resetBackground(), autoFillBackground() + \aspect QskControl::Background | QskAspect::Color + \sa setBackground(), setBackgroundColor(), resetBackground() */ /*! @@ -329,6 +312,8 @@ contentsRect() is a rectangle being used for laying out scene graph nodes, while layoutRect() is used for child items. + \aspect QskControl::Background | QskAspect::Metric | QskAspect::Padding + \sa margins(), setMargins(), layoutRect() */ @@ -440,25 +425,11 @@ \sa QskSkinnable::subControlContentsRect */ -/*! - \fn QskControl::setAutoFillBackground - - Set or clear the \ref autoFillBackground property - \sa autoFillBackground() -*/ - -/*! - \fn QskControl::autoFillBackground() const - - \return Value of the \ref autoFillBackground property - \sa setAutoFillBackground() -*/ - /*! \fn QskControl::setAutoLayoutChildren Set or clear the autoLayoutChildren property - \sa autoFillBackground() + \sa autoLayoutChildren() */ /*! diff --git a/examples/layouts/layouts.qml b/examples/layouts/layouts.qml index 51950179..08a8bb1c 100644 --- a/examples/layouts/layouts.qml +++ b/examples/layouts/layouts.qml @@ -7,8 +7,6 @@ GridBox //margins: 10 // only possible with Qt <= 6.1 margins { left: 10; top: 10; right: 10; bottom: 10 } - autoFillBackground : true - background { linear: [ 0.0, 0.0, 1.0, 0.0 ] diff --git a/src/controls/QskControl.cpp b/src/controls/QskControl.cpp index 59aaaf35..f2be97bc 100644 --- a/src/controls/QskControl.cpp +++ b/src/controls/QskControl.cpp @@ -19,6 +19,8 @@ #include #include +QSK_SUBCONTROL( QskControl, Background ) + QSK_SYSTEM_STATE( QskControl, Disabled, QskAspect::FirstSystemState ) QSK_SYSTEM_STATE( QskControl, Hovered, QskAspect::LastSystemState >> 1 ) QSK_SYSTEM_STATE( QskControl, Focused, QskAspect::LastSystemState ) @@ -57,21 +59,6 @@ QskControl::~QskControl() #endif } -void QskControl::setAutoFillBackground( bool on ) -{ - Q_D( QskControl ); - if ( on != d->autoFillBackground ) - { - d->autoFillBackground = on; - update(); - } -} - -bool QskControl::autoFillBackground() const -{ - return d_func()->autoFillBackground; -} - void QskControl::setAutoLayoutChildren( bool on ) { Q_D( QskControl ); @@ -139,25 +126,24 @@ Qt::FocusPolicy QskControl::focusPolicy() const void QskControl::setBackgroundColor( const QColor& color ) { - setAutoFillBackground( true ); setBackground( QskGradient( color ) ); } void QskControl::setBackground( const QskGradient& gradient ) { - if ( setGradientHint( QskAspect::NoSubcontrol, gradient ) ) + if ( setGradientHint( QskControl::Background, gradient ) ) Q_EMIT backgroundChanged(); } void QskControl::resetBackground() { - if ( resetColor( QskAspect::NoSubcontrol ) ) + if ( resetColor( QskControl::Background ) ) Q_EMIT backgroundChanged(); } QskGradient QskControl::background() const { - return gradientHint( QskAspect::NoSubcontrol ); + return gradientHint( QskControl::Background ); } void QskControl::setMargins( qreal margin ) @@ -174,7 +160,7 @@ void QskControl::setMargins( const QMarginsF& margins ) { const auto m = QskMargins().expandedTo( margins ); - if ( setMarginHint( QskAspect::NoSubcontrol, m ) ) + if ( setPaddingHint( QskControl::Background, m ) ) { qskSendEventTo( this, QEvent::ContentsRectChange ); Q_EMIT marginsChanged( m ); @@ -183,7 +169,7 @@ void QskControl::setMargins( const QMarginsF& margins ) void QskControl::resetMargins() { - if ( resetMarginHint( QskAspect::NoSubcontrol ) ) + if ( resetPaddingHint( QskControl::Background ) ) { qskSendEventTo( this, QEvent::ContentsRectChange ); Q_EMIT marginsChanged( margins() ); @@ -192,7 +178,7 @@ void QskControl::resetMargins() QMarginsF QskControl::margins() const { - return marginHint( QskAspect::NoSubcontrol ); + return paddingHint( QskControl::Background ); } QRectF QskControl::contentsRect() const diff --git a/src/controls/QskControl.h b/src/controls/QskControl.h index 01387f59..49915072 100644 --- a/src/controls/QskControl.h +++ b/src/controls/QskControl.h @@ -29,9 +29,6 @@ class QSK_EXPORT QskControl : public QskQuickItem, public QskSkinnable Q_PROPERTY( QskAspect::Section section READ section WRITE setSection RESET resetSection NOTIFY sectionChanged ) - Q_PROPERTY( bool autoFillBackground READ autoFillBackground - WRITE setAutoFillBackground ) - Q_PROPERTY( bool autoLayoutChildren READ autoLayoutChildren WRITE setAutoLayoutChildren ) @@ -61,6 +58,7 @@ class QSK_EXPORT QskControl : public QskQuickItem, public QskSkinnable using Inherited = QskQuickItem; public: + QSK_SUBCONTROLS( Background ) QSK_STATES( Disabled, Hovered, Focused ) QskControl( QQuickItem* parent = nullptr ); @@ -72,12 +70,12 @@ class QSK_EXPORT QskControl : public QskQuickItem, public QskSkinnable void resetMargins(); QMarginsF margins() const; - void setBackgroundColor( const QColor& ); - void setBackground( const QskGradient& ); void resetBackground(); QskGradient background() const; + void setBackgroundColor( const QColor& ); + QRectF contentsRect() const; QRectF layoutRect() const; @@ -95,9 +93,6 @@ class QSK_EXPORT QskControl : public QskQuickItem, public QskSkinnable QRectF subControlContentsRect( QskAspect::Subcontrol ) const; QRectF subControlContentsRect( const QSizeF&, QskAspect::Subcontrol ) const; - void setAutoFillBackground( bool ); - bool autoFillBackground() const; - void setAutoLayoutChildren( bool ); bool autoLayoutChildren() const; diff --git a/src/controls/QskControlPrivate.cpp b/src/controls/QskControlPrivate.cpp index bcdd6f1e..bda8777d 100644 --- a/src/controls/QskControlPrivate.cpp +++ b/src/controls/QskControlPrivate.cpp @@ -157,7 +157,6 @@ QskControlPrivate::QskControlPrivate() , layoutAlignmentHint( 0 ) , explicitLocale( false ) , explicitSection( false ) - , autoFillBackground( false ) , autoLayoutChildren( false ) , focusPolicy( Qt::NoFocus ) , isWheelEnabled( false ) diff --git a/src/controls/QskControlPrivate.h b/src/controls/QskControlPrivate.h index d1854d8e..8c74a36a 100644 --- a/src/controls/QskControlPrivate.h +++ b/src/controls/QskControlPrivate.h @@ -59,7 +59,6 @@ class QskControlPrivate : public QskQuickItemPrivate bool explicitLocale : 1; bool explicitSection : 1; - bool autoFillBackground : 1; bool autoLayoutChildren : 1; uint focusPolicy : 4; diff --git a/src/controls/QskSkin.cpp b/src/controls/QskSkin.cpp index 172031b2..b97308e3 100644 --- a/src/controls/QskSkin.cpp +++ b/src/controls/QskSkin.cpp @@ -174,15 +174,21 @@ QskSkin::QskSkin( QObject* parent ) const QFont font = QGuiApplication::font(); setupFonts( font.family(), font.weight(), font.italic() ); + const auto noMargins = QVariant::fromValue( QskMargins( 0 ) ); + { // some defaults - const auto noMargins = QVariant::fromValue( QskMargins( 0 ) ); const auto aspect = QskAspect::NoSubcontrol | QskAspect::Metric; setSkinHint( aspect | QskAspect::Margin, noMargins ); setSkinHint( aspect | QskAspect::Padding, noMargins ); setSkinHint( aspect | QskAspect::Spacing, 0 ); } + + setSkinHint( QskControl::Background | QskAspect::Metric | QskAspect::Padding, noMargins ); + + setSkinHint( QskControl::Background | QskAspect::Color, + QVariant::fromValue( QskGradient() ) ); } QskSkin::~QskSkin() diff --git a/src/controls/QskSkinTransition.cpp b/src/controls/QskSkinTransition.cpp index c46642aa..8ca0158b 100644 --- a/src/controls/QskSkinTransition.cpp +++ b/src/controls/QskSkinTransition.cpp @@ -416,15 +416,7 @@ inline bool WindowAnimator::isControlAffected( const QskControl* control, return false; } - if ( subControl == QskAspect::NoSubcontrol ) - { - if ( !control->autoFillBackground() ) - { - // no need to animate the background unless we show it - return false; - } - } - else + if ( subControl != QskAspect::NoSubcontrol ) { if ( !subControls.contains( subControl ) ) { diff --git a/src/controls/QskSkinlet.cpp b/src/controls/QskSkinlet.cpp index 3279bdf1..94caa691 100644 --- a/src/controls/QskSkinlet.cpp +++ b/src/controls/QskSkinlet.cpp @@ -313,10 +313,7 @@ void QskSkinlet::updateNode( QskSkinnable* skinnable, QSGNode* parentNode ) cons // background oldNode = findChildNode( parentNode, BackgroundRole ); - - newNode = nullptr; - if ( control->autoFillBackground() ) - newNode = updateBackgroundNode( control, oldNode ); + newNode = updateBackgroundNode( control, oldNode ); replaceChildNode( BackgroundRole, parentNode, oldNode, newNode );