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:
parent
c5ace32bf2
commit
912d768a61
|
@ -56,18 +56,6 @@
|
||||||
\accessors locale(), setLocale(), resetLocale(), localeChanged()
|
\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
|
\property bool QskControl::autoLayoutChildren
|
||||||
|
|
||||||
|
@ -223,11 +211,8 @@
|
||||||
|
|
||||||
Sets the margins around the contents of the control
|
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
|
\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()
|
\sa contentsRect(), margins(), QskSkinnable::setMarginHint()
|
||||||
*/
|
*/
|
||||||
|
@ -235,15 +220,14 @@
|
||||||
/*!
|
/*!
|
||||||
\fn QskControl::setMargins( qreal, qreal, qreal, qreal )
|
\fn QskControl::setMargins( qreal, qreal, qreal, qreal )
|
||||||
|
|
||||||
The value is stored in the local hint table for the aspect:
|
Sets the margins around the contents of the control
|
||||||
QskControl::Control | QskAspect::Metric | QskAspect::Margin
|
|
||||||
|
|
||||||
\param left Left margin
|
\param left Left margin
|
||||||
\param top Top margin
|
\param top Top margin
|
||||||
\param right Right margin
|
\param right Right margin
|
||||||
\param bottom Bottom margin
|
\param bottom Bottom margin
|
||||||
|
|
||||||
\aspect QskControl::Control | QskAspect::Metric | QskAspect::Margin
|
\aspect QskControl::Background | QskAspect::Metric | QskAspect::Padding
|
||||||
|
|
||||||
\sa contentsRect(), margins(), QskSkinnable::setMarginHint()
|
\sa contentsRect(), margins(), QskSkinnable::setMarginHint()
|
||||||
*/
|
*/
|
||||||
|
@ -254,7 +238,7 @@
|
||||||
Sets the margins around the contents of the control
|
Sets the margins around the contents of the control
|
||||||
|
|
||||||
\param margins Margins
|
\param margins Margins
|
||||||
\aspect QskControl::Control | QskAspect::Metric | QskAspect::Margin
|
\aspect QskControl::Background | QskAspect::Metric | QskAspect::Padding
|
||||||
|
|
||||||
\sa contentsRect(), margins()
|
\sa contentsRect(), margins()
|
||||||
\saqt QEvent::ContentsRectChange
|
\saqt QEvent::ContentsRectChange
|
||||||
|
@ -265,7 +249,7 @@
|
||||||
|
|
||||||
Reset the margins to the default value provided from the skin
|
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()
|
\sa contentsRect(), setMargins(), margins()
|
||||||
\saqt QEvent::ContentsRectChange
|
\saqt QEvent::ContentsRectChange
|
||||||
|
@ -275,7 +259,7 @@
|
||||||
\fn QskControl::margins() const
|
\fn QskControl::margins() const
|
||||||
|
|
||||||
\return margins around the contents of the control
|
\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()
|
\sa contentsRect(), setMargins()
|
||||||
\saqt QEvent::ContentsRectChange
|
\saqt QEvent::ContentsRectChange
|
||||||
|
@ -284,11 +268,12 @@
|
||||||
/*!
|
/*!
|
||||||
\fn QskControl::setBackgroundColor
|
\fn QskControl::setBackgroundColor
|
||||||
|
|
||||||
A conveninece method that enables the \ref autoFillBackground property
|
A conveninece method for setting a monochrome gradient as background. Often used
|
||||||
and sets a solid color as background. Usually used for debugging
|
for debugging layout problems.
|
||||||
layout problems.
|
|
||||||
|
|
||||||
\sa setBackground(), setAutoFillBackground()
|
\aspect QskControl::Background | QskAspect::Color
|
||||||
|
|
||||||
|
\sa setBackground()
|
||||||
\sa QskQuickItem::DebugForceBackground
|
\sa QskQuickItem::DebugForceBackground
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@ -296,10 +281,9 @@
|
||||||
\fn QskControl::setBackground
|
\fn QskControl::setBackground
|
||||||
|
|
||||||
Set the gradient that is used to fill the background,
|
Set the gradient that is used to fill the background,
|
||||||
when \ref autoFillBackground is enabled.
|
|
||||||
|
|
||||||
\aspect QskControl::Control | QskAspect::Color
|
\aspect QskControl::Background | QskAspect::Color
|
||||||
\sa resetBackground(), background(), autoFillBackground()
|
\sa resetBackground(), background(), setBackgroundColor
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
|
@ -307,18 +291,17 @@
|
||||||
|
|
||||||
Reset the background gradient to the default colors from the skin
|
Reset the background gradient to the default colors from the skin
|
||||||
|
|
||||||
\aspect QskControl::Control | QskAspect::Color
|
\aspect QskControl::Background | QskAspect::Color
|
||||||
\sa setBackground(), background(), autoFillBackground()
|
\sa setBackground(), setBackgroundColor(), background()
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\fn QskControl::background() const
|
\fn QskControl::background() const
|
||||||
|
|
||||||
\return Gradient that is used to fill the background,
|
\return Gradient that is used to fill the background
|
||||||
when autoFillBackground is enabled.
|
|
||||||
|
|
||||||
\aspect QskControl::Control | QskAspect::Color
|
\aspect QskControl::Background | QskAspect::Color
|
||||||
\sa setBackground(), resetBackground(), autoFillBackground()
|
\sa setBackground(), setBackgroundColor(), resetBackground()
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
|
@ -329,6 +312,8 @@
|
||||||
contentsRect() is a rectangle being used for laying out scene graph nodes,
|
contentsRect() is a rectangle being used for laying out scene graph nodes,
|
||||||
while layoutRect() is used for child items.
|
while layoutRect() is used for child items.
|
||||||
|
|
||||||
|
\aspect QskControl::Background | QskAspect::Metric | QskAspect::Padding
|
||||||
|
|
||||||
\sa margins(), setMargins(), layoutRect()
|
\sa margins(), setMargins(), layoutRect()
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@ -440,25 +425,11 @@
|
||||||
\sa QskSkinnable::subControlContentsRect
|
\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
|
\fn QskControl::setAutoLayoutChildren
|
||||||
|
|
||||||
Set or clear the autoLayoutChildren property
|
Set or clear the autoLayoutChildren property
|
||||||
\sa autoFillBackground()
|
\sa autoLayoutChildren()
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
|
|
|
@ -7,8 +7,6 @@ GridBox
|
||||||
//margins: 10 // only possible with Qt <= 6.1
|
//margins: 10 // only possible with Qt <= 6.1
|
||||||
margins { left: 10; top: 10; right: 10; bottom: 10 }
|
margins { left: 10; top: 10; right: 10; bottom: 10 }
|
||||||
|
|
||||||
autoFillBackground : true
|
|
||||||
|
|
||||||
background
|
background
|
||||||
{
|
{
|
||||||
linear: [ 0.0, 0.0, 1.0, 0.0 ]
|
linear: [ 0.0, 0.0, 1.0, 0.0 ]
|
||||||
|
|
|
@ -19,6 +19,8 @@
|
||||||
#include <qlocale.h>
|
#include <qlocale.h>
|
||||||
#include <qvector.h>
|
#include <qvector.h>
|
||||||
|
|
||||||
|
QSK_SUBCONTROL( QskControl, Background )
|
||||||
|
|
||||||
QSK_SYSTEM_STATE( QskControl, Disabled, QskAspect::FirstSystemState )
|
QSK_SYSTEM_STATE( QskControl, Disabled, QskAspect::FirstSystemState )
|
||||||
QSK_SYSTEM_STATE( QskControl, Hovered, QskAspect::LastSystemState >> 1 )
|
QSK_SYSTEM_STATE( QskControl, Hovered, QskAspect::LastSystemState >> 1 )
|
||||||
QSK_SYSTEM_STATE( QskControl, Focused, QskAspect::LastSystemState )
|
QSK_SYSTEM_STATE( QskControl, Focused, QskAspect::LastSystemState )
|
||||||
|
@ -57,21 +59,6 @@ QskControl::~QskControl()
|
||||||
#endif
|
#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 )
|
void QskControl::setAutoLayoutChildren( bool on )
|
||||||
{
|
{
|
||||||
Q_D( QskControl );
|
Q_D( QskControl );
|
||||||
|
@ -139,25 +126,24 @@ Qt::FocusPolicy QskControl::focusPolicy() const
|
||||||
|
|
||||||
void QskControl::setBackgroundColor( const QColor& color )
|
void QskControl::setBackgroundColor( const QColor& color )
|
||||||
{
|
{
|
||||||
setAutoFillBackground( true );
|
|
||||||
setBackground( QskGradient( color ) );
|
setBackground( QskGradient( color ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
void QskControl::setBackground( const QskGradient& gradient )
|
void QskControl::setBackground( const QskGradient& gradient )
|
||||||
{
|
{
|
||||||
if ( setGradientHint( QskAspect::NoSubcontrol, gradient ) )
|
if ( setGradientHint( QskControl::Background, gradient ) )
|
||||||
Q_EMIT backgroundChanged();
|
Q_EMIT backgroundChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
void QskControl::resetBackground()
|
void QskControl::resetBackground()
|
||||||
{
|
{
|
||||||
if ( resetColor( QskAspect::NoSubcontrol ) )
|
if ( resetColor( QskControl::Background ) )
|
||||||
Q_EMIT backgroundChanged();
|
Q_EMIT backgroundChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
QskGradient QskControl::background() const
|
QskGradient QskControl::background() const
|
||||||
{
|
{
|
||||||
return gradientHint( QskAspect::NoSubcontrol );
|
return gradientHint( QskControl::Background );
|
||||||
}
|
}
|
||||||
|
|
||||||
void QskControl::setMargins( qreal margin )
|
void QskControl::setMargins( qreal margin )
|
||||||
|
@ -174,7 +160,7 @@ void QskControl::setMargins( const QMarginsF& margins )
|
||||||
{
|
{
|
||||||
const auto m = QskMargins().expandedTo( margins );
|
const auto m = QskMargins().expandedTo( margins );
|
||||||
|
|
||||||
if ( setMarginHint( QskAspect::NoSubcontrol, m ) )
|
if ( setPaddingHint( QskControl::Background, m ) )
|
||||||
{
|
{
|
||||||
qskSendEventTo( this, QEvent::ContentsRectChange );
|
qskSendEventTo( this, QEvent::ContentsRectChange );
|
||||||
Q_EMIT marginsChanged( m );
|
Q_EMIT marginsChanged( m );
|
||||||
|
@ -183,7 +169,7 @@ void QskControl::setMargins( const QMarginsF& margins )
|
||||||
|
|
||||||
void QskControl::resetMargins()
|
void QskControl::resetMargins()
|
||||||
{
|
{
|
||||||
if ( resetMarginHint( QskAspect::NoSubcontrol ) )
|
if ( resetPaddingHint( QskControl::Background ) )
|
||||||
{
|
{
|
||||||
qskSendEventTo( this, QEvent::ContentsRectChange );
|
qskSendEventTo( this, QEvent::ContentsRectChange );
|
||||||
Q_EMIT marginsChanged( margins() );
|
Q_EMIT marginsChanged( margins() );
|
||||||
|
@ -192,7 +178,7 @@ void QskControl::resetMargins()
|
||||||
|
|
||||||
QMarginsF QskControl::margins() const
|
QMarginsF QskControl::margins() const
|
||||||
{
|
{
|
||||||
return marginHint( QskAspect::NoSubcontrol );
|
return paddingHint( QskControl::Background );
|
||||||
}
|
}
|
||||||
|
|
||||||
QRectF QskControl::contentsRect() const
|
QRectF QskControl::contentsRect() const
|
||||||
|
|
|
@ -29,9 +29,6 @@ class QSK_EXPORT QskControl : public QskQuickItem, public QskSkinnable
|
||||||
Q_PROPERTY( QskAspect::Section section READ section
|
Q_PROPERTY( QskAspect::Section section READ section
|
||||||
WRITE setSection RESET resetSection NOTIFY sectionChanged )
|
WRITE setSection RESET resetSection NOTIFY sectionChanged )
|
||||||
|
|
||||||
Q_PROPERTY( bool autoFillBackground READ autoFillBackground
|
|
||||||
WRITE setAutoFillBackground )
|
|
||||||
|
|
||||||
Q_PROPERTY( bool autoLayoutChildren READ autoLayoutChildren
|
Q_PROPERTY( bool autoLayoutChildren READ autoLayoutChildren
|
||||||
WRITE setAutoLayoutChildren )
|
WRITE setAutoLayoutChildren )
|
||||||
|
|
||||||
|
@ -61,6 +58,7 @@ class QSK_EXPORT QskControl : public QskQuickItem, public QskSkinnable
|
||||||
using Inherited = QskQuickItem;
|
using Inherited = QskQuickItem;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
QSK_SUBCONTROLS( Background )
|
||||||
QSK_STATES( Disabled, Hovered, Focused )
|
QSK_STATES( Disabled, Hovered, Focused )
|
||||||
|
|
||||||
QskControl( QQuickItem* parent = nullptr );
|
QskControl( QQuickItem* parent = nullptr );
|
||||||
|
@ -72,12 +70,12 @@ class QSK_EXPORT QskControl : public QskQuickItem, public QskSkinnable
|
||||||
void resetMargins();
|
void resetMargins();
|
||||||
QMarginsF margins() const;
|
QMarginsF margins() const;
|
||||||
|
|
||||||
void setBackgroundColor( const QColor& );
|
|
||||||
|
|
||||||
void setBackground( const QskGradient& );
|
void setBackground( const QskGradient& );
|
||||||
void resetBackground();
|
void resetBackground();
|
||||||
QskGradient background() const;
|
QskGradient background() const;
|
||||||
|
|
||||||
|
void setBackgroundColor( const QColor& );
|
||||||
|
|
||||||
QRectF contentsRect() const;
|
QRectF contentsRect() const;
|
||||||
QRectF layoutRect() const;
|
QRectF layoutRect() const;
|
||||||
|
|
||||||
|
@ -95,9 +93,6 @@ class QSK_EXPORT QskControl : public QskQuickItem, public QskSkinnable
|
||||||
QRectF subControlContentsRect( QskAspect::Subcontrol ) const;
|
QRectF subControlContentsRect( QskAspect::Subcontrol ) const;
|
||||||
QRectF subControlContentsRect( const QSizeF&, QskAspect::Subcontrol ) const;
|
QRectF subControlContentsRect( const QSizeF&, QskAspect::Subcontrol ) const;
|
||||||
|
|
||||||
void setAutoFillBackground( bool );
|
|
||||||
bool autoFillBackground() const;
|
|
||||||
|
|
||||||
void setAutoLayoutChildren( bool );
|
void setAutoLayoutChildren( bool );
|
||||||
bool autoLayoutChildren() const;
|
bool autoLayoutChildren() const;
|
||||||
|
|
||||||
|
|
|
@ -157,7 +157,6 @@ QskControlPrivate::QskControlPrivate()
|
||||||
, layoutAlignmentHint( 0 )
|
, layoutAlignmentHint( 0 )
|
||||||
, explicitLocale( false )
|
, explicitLocale( false )
|
||||||
, explicitSection( false )
|
, explicitSection( false )
|
||||||
, autoFillBackground( false )
|
|
||||||
, autoLayoutChildren( false )
|
, autoLayoutChildren( false )
|
||||||
, focusPolicy( Qt::NoFocus )
|
, focusPolicy( Qt::NoFocus )
|
||||||
, isWheelEnabled( false )
|
, isWheelEnabled( false )
|
||||||
|
|
|
@ -59,7 +59,6 @@ class QskControlPrivate : public QskQuickItemPrivate
|
||||||
bool explicitLocale : 1;
|
bool explicitLocale : 1;
|
||||||
bool explicitSection : 1;
|
bool explicitSection : 1;
|
||||||
|
|
||||||
bool autoFillBackground : 1;
|
|
||||||
bool autoLayoutChildren : 1;
|
bool autoLayoutChildren : 1;
|
||||||
|
|
||||||
uint focusPolicy : 4;
|
uint focusPolicy : 4;
|
||||||
|
|
|
@ -174,15 +174,21 @@ QskSkin::QskSkin( QObject* parent )
|
||||||
const QFont font = QGuiApplication::font();
|
const QFont font = QGuiApplication::font();
|
||||||
setupFonts( font.family(), font.weight(), font.italic() );
|
setupFonts( font.family(), font.weight(), font.italic() );
|
||||||
|
|
||||||
|
const auto noMargins = QVariant::fromValue( QskMargins( 0 ) );
|
||||||
|
|
||||||
{
|
{
|
||||||
// some defaults
|
// some defaults
|
||||||
const auto noMargins = QVariant::fromValue( QskMargins( 0 ) );
|
|
||||||
const auto aspect = QskAspect::NoSubcontrol | QskAspect::Metric;
|
const auto aspect = QskAspect::NoSubcontrol | QskAspect::Metric;
|
||||||
|
|
||||||
setSkinHint( aspect | QskAspect::Margin, noMargins );
|
setSkinHint( aspect | QskAspect::Margin, noMargins );
|
||||||
setSkinHint( aspect | QskAspect::Padding, noMargins );
|
setSkinHint( aspect | QskAspect::Padding, noMargins );
|
||||||
setSkinHint( aspect | QskAspect::Spacing, 0 );
|
setSkinHint( aspect | QskAspect::Spacing, 0 );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setSkinHint( QskControl::Background | QskAspect::Metric | QskAspect::Padding, noMargins );
|
||||||
|
|
||||||
|
setSkinHint( QskControl::Background | QskAspect::Color,
|
||||||
|
QVariant::fromValue( QskGradient() ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
QskSkin::~QskSkin()
|
QskSkin::~QskSkin()
|
||||||
|
|
|
@ -416,15 +416,7 @@ inline bool WindowAnimator::isControlAffected( const QskControl* control,
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( subControl == QskAspect::NoSubcontrol )
|
if ( subControl != QskAspect::NoSubcontrol )
|
||||||
{
|
|
||||||
if ( !control->autoFillBackground() )
|
|
||||||
{
|
|
||||||
// no need to animate the background unless we show it
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
if ( !subControls.contains( subControl ) )
|
if ( !subControls.contains( subControl ) )
|
||||||
{
|
{
|
||||||
|
|
|
@ -313,10 +313,7 @@ void QskSkinlet::updateNode( QskSkinnable* skinnable, QSGNode* parentNode ) cons
|
||||||
// background
|
// background
|
||||||
|
|
||||||
oldNode = findChildNode( parentNode, BackgroundRole );
|
oldNode = findChildNode( parentNode, BackgroundRole );
|
||||||
|
newNode = updateBackgroundNode( control, oldNode );
|
||||||
newNode = nullptr;
|
|
||||||
if ( control->autoFillBackground() )
|
|
||||||
newNode = updateBackgroundNode( control, oldNode );
|
|
||||||
|
|
||||||
replaceChildNode( BackgroundRole, parentNode, oldNode, newNode );
|
replaceChildNode( BackgroundRole, parentNode, oldNode, newNode );
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue