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.
This commit is contained in:
Uwe Rathmann 2022-11-18 13:20:21 +01:00
parent c5ace32bf2
commit 912d768a61
9 changed files with 41 additions and 98 deletions

View File

@ -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()
*/
/*!

View File

@ -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 ]

View File

@ -19,6 +19,8 @@
#include <qlocale.h>
#include <qvector.h>
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

View File

@ -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;

View File

@ -157,7 +157,6 @@ QskControlPrivate::QskControlPrivate()
, layoutAlignmentHint( 0 )
, explicitLocale( false )
, explicitSection( false )
, autoFillBackground( false )
, autoLayoutChildren( false )
, focusPolicy( Qt::NoFocus )
, isWheelEnabled( false )

View File

@ -59,7 +59,6 @@ class QskControlPrivate : public QskQuickItemPrivate
bool explicitLocale : 1;
bool explicitSection : 1;
bool autoFillBackground : 1;
bool autoLayoutChildren : 1;
uint focusPolicy : 4;

View File

@ -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()

View File

@ -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 ) )
{

View File

@ -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 );