QskColorFilter::mask
This commit is contained in:
parent
90fec17a60
commit
6618c91479
@ -1336,47 +1336,25 @@ void QskMaterial3Skin::setupFonts()
|
||||
setFont( M3LabelLarge, createFont( "Roboto Medium", 20_dp, 14_dp, 0.1, QFont::Medium ) );
|
||||
}
|
||||
|
||||
void QskMaterial3Skin::setGraphicColor( GraphicRole role, QRgb rgb )
|
||||
{
|
||||
QskColorFilter colorFilter;
|
||||
colorFilter.setMask( QskRgb::RGBAMask );
|
||||
colorFilter.addColorSubstitution( QskRgb::White, rgb );
|
||||
|
||||
setGraphicFilter( role, colorFilter );
|
||||
}
|
||||
|
||||
void QskMaterial3Skin::setupGraphicFilters( const QskMaterial3Theme& palette )
|
||||
{
|
||||
QskColorFilter onPrimaryFilter;
|
||||
onPrimaryFilter.setSubstituteAlphaValue( true );
|
||||
onPrimaryFilter.addColorSubstitution( Qt::white, palette.onPrimary );
|
||||
setGraphicFilter( GraphicRoleOnPrimary, onPrimaryFilter );
|
||||
|
||||
QskColorFilter onSecondaryContainerFilter;
|
||||
onSecondaryContainerFilter.setSubstituteAlphaValue( true );
|
||||
onSecondaryContainerFilter.addColorSubstitution( Qt::white, palette.onSecondaryContainer );
|
||||
setGraphicFilter( GraphicRoleOnSecondaryContainer, onSecondaryContainerFilter );
|
||||
|
||||
QskColorFilter onErrorFilter;
|
||||
onErrorFilter.setSubstituteAlphaValue( true );
|
||||
onErrorFilter.addColorSubstitution( Qt::white, palette.onError );
|
||||
setGraphicFilter( GraphicRoleOnError, onErrorFilter );
|
||||
|
||||
QskColorFilter onSurfaceFilter;
|
||||
onSurfaceFilter.setSubstituteAlphaValue( true );
|
||||
onSurfaceFilter.addColorSubstitution( Qt::white, palette.onSurface );
|
||||
setGraphicFilter( GraphicRoleOnSurface, onSurfaceFilter );
|
||||
|
||||
QskColorFilter onSurfaceFilter38;
|
||||
onSurfaceFilter38.setSubstituteAlphaValue( true );
|
||||
onSurfaceFilter38.addColorSubstitution( Qt::white, palette.onSurface38 );
|
||||
setGraphicFilter( GraphicRoleOnSurface38, onSurfaceFilter38 );
|
||||
|
||||
QskColorFilter onSurfaceVariantFilter;
|
||||
onSurfaceVariantFilter.setSubstituteAlphaValue( true );
|
||||
onSurfaceVariantFilter.addColorSubstitution( Qt::white, palette.onSurfaceVariant );
|
||||
setGraphicFilter( GraphicRoleOnSurfaceVariant, onSurfaceVariantFilter );
|
||||
|
||||
QskColorFilter primaryFilter;
|
||||
primaryFilter.setSubstituteAlphaValue( true );
|
||||
primaryFilter.addColorSubstitution( Qt::white, palette.primary );
|
||||
setGraphicFilter( GraphicRolePrimary, primaryFilter );
|
||||
|
||||
QskColorFilter surfaceFilter;
|
||||
surfaceFilter.setSubstituteAlphaValue( true );
|
||||
surfaceFilter.addColorSubstitution( Qt::white, palette.surface );
|
||||
setGraphicFilter( GraphicRoleSurface, surfaceFilter );
|
||||
setGraphicColor( GraphicRoleOnPrimary, palette.onPrimary );
|
||||
setGraphicColor( GraphicRoleOnSecondaryContainer, palette.onSecondaryContainer );
|
||||
setGraphicColor( GraphicRoleOnError, palette.onError );
|
||||
setGraphicColor( GraphicRoleOnSurface, palette.onSurface );
|
||||
setGraphicColor( GraphicRoleOnSurface38, palette.onSurface38 );
|
||||
setGraphicColor( GraphicRoleOnSurfaceVariant, palette.onSurfaceVariant );
|
||||
setGraphicColor( GraphicRolePrimary, palette.primary );
|
||||
setGraphicColor( GraphicRoleSurface, palette.surface );
|
||||
}
|
||||
|
||||
#include "moc_QskMaterial3Skin.cpp"
|
||||
|
@ -157,6 +157,7 @@ class QSK_MATERIAL3_EXPORT QskMaterial3Skin : public QskSkin
|
||||
private:
|
||||
void setupFonts();
|
||||
void setupGraphicFilters( const QskMaterial3Theme& palette );
|
||||
void setGraphicColor( GraphicRole, QRgb );
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -11,35 +11,31 @@
|
||||
#include <qvariant.h>
|
||||
|
||||
static inline QRgb qskSubstitutedRgb(
|
||||
const QVector< QPair< QRgb, QRgb > >& substitions, QRgb rgba, bool substituteAlpha )
|
||||
const QVector< QPair< QRgb, QRgb > >& substitions, QRgb rgba, QRgb mask )
|
||||
{
|
||||
// usually we have 2-3 substitutions, so we can simply iterate
|
||||
// and don't need to introduce some sort of sorting or search index
|
||||
|
||||
const QRgb rgb = substituteAlpha ? rgba : ( rgba | QskRgb::AlphaMask );
|
||||
const QRgb rgb = rgba | ~mask;
|
||||
|
||||
for ( const auto& s : substitions )
|
||||
{
|
||||
if ( rgb == s.first )
|
||||
{
|
||||
const auto ret = substituteAlpha ? s.second
|
||||
: ( s.second & QskRgb::ColorMask )
|
||||
| ( rgba & QskRgb::AlphaMask );
|
||||
return ret;
|
||||
}
|
||||
if ( rgb == ( s.first | ~mask ) )
|
||||
return ( s.second & mask ) | ( rgba & ~mask );
|
||||
}
|
||||
|
||||
return rgba;
|
||||
}
|
||||
|
||||
static inline QColor qskSubstitutedColor(
|
||||
const QVector< QPair< QRgb, QRgb > >& substitions, const QColor& color, bool substituteAlpha )
|
||||
const QVector< QPair< QRgb, QRgb > >& substitions,
|
||||
const QColor& color, QRgb mask )
|
||||
{
|
||||
return QColor::fromRgba( qskSubstitutedRgb( substitions, color.rgba(), substituteAlpha ) );
|
||||
return QColor::fromRgba( qskSubstitutedRgb( substitions, color.rgba(), mask ) );
|
||||
}
|
||||
|
||||
static inline QBrush qskSubstitutedBrush(
|
||||
const QVector< QPair< QRgb, QRgb > >& substitions, const QBrush& brush, bool substituteAlpha )
|
||||
const QVector< QPair< QRgb, QRgb > >& substitions, const QBrush& brush, QRgb mask )
|
||||
{
|
||||
QBrush newBrush;
|
||||
|
||||
@ -50,7 +46,7 @@ static inline QBrush qskSubstitutedBrush(
|
||||
auto stops = gradient->stops();
|
||||
for ( auto& stop : stops )
|
||||
{
|
||||
const QColor c = qskSubstitutedColor( substitions, stop.second, substituteAlpha );
|
||||
const QColor c = qskSubstitutedColor( substitions, stop.second, mask );
|
||||
if ( c != stop.second )
|
||||
{
|
||||
stop.second = c;
|
||||
@ -68,7 +64,7 @@ static inline QBrush qskSubstitutedBrush(
|
||||
}
|
||||
else
|
||||
{
|
||||
const QColor c = qskSubstitutedColor( substitions, brush.color(), substituteAlpha );
|
||||
const QColor c = qskSubstitutedColor( substitions, brush.color(), mask );
|
||||
if ( c != brush.color() )
|
||||
{
|
||||
newBrush = brush;
|
||||
@ -168,7 +164,7 @@ QPen QskColorFilter::substituted( const QPen& pen ) const
|
||||
if ( m_substitutions.isEmpty() || pen.style() == Qt::NoPen )
|
||||
return pen;
|
||||
|
||||
const auto newBrush = qskSubstitutedBrush( m_substitutions, pen.brush(), m_substituteAlphaValue );
|
||||
const auto newBrush = qskSubstitutedBrush( m_substitutions, pen.brush(), m_mask );
|
||||
if ( newBrush.style() == Qt::NoBrush )
|
||||
return pen;
|
||||
|
||||
@ -182,28 +178,18 @@ QBrush QskColorFilter::substituted( const QBrush& brush ) const
|
||||
if ( m_substitutions.isEmpty() || brush.style() == Qt::NoBrush )
|
||||
return brush;
|
||||
|
||||
const auto newBrush = qskSubstitutedBrush( m_substitutions, brush, m_substituteAlphaValue );
|
||||
const auto newBrush = qskSubstitutedBrush( m_substitutions, brush, m_mask );
|
||||
return ( newBrush.style() != Qt::NoBrush ) ? newBrush : brush;
|
||||
}
|
||||
|
||||
QColor QskColorFilter::substituted( const QColor& color ) const
|
||||
{
|
||||
return qskSubstitutedColor( m_substitutions, color, m_substituteAlphaValue );
|
||||
return qskSubstitutedColor( m_substitutions, color, m_mask );
|
||||
}
|
||||
|
||||
QRgb QskColorFilter::substituted( const QRgb& rgb ) const
|
||||
{
|
||||
return qskSubstitutedRgb( m_substitutions, rgb, m_substituteAlphaValue );
|
||||
}
|
||||
|
||||
bool QskColorFilter::substituteAlphaValue() const noexcept
|
||||
{
|
||||
return m_substituteAlphaValue;
|
||||
}
|
||||
|
||||
void QskColorFilter::setSubstituteAlphaValue( bool on )
|
||||
{
|
||||
m_substituteAlphaValue = on;
|
||||
return qskSubstitutedRgb( m_substitutions, rgb, m_mask );
|
||||
}
|
||||
|
||||
QskColorFilter QskColorFilter::interpolated(
|
||||
@ -227,7 +213,7 @@ QDebug operator<<( QDebug debug, const QskColorFilter& filter )
|
||||
QDebugStateSaver saver( debug );
|
||||
debug.nospace();
|
||||
|
||||
debug << "Filter" << '(';
|
||||
debug << "Filter" << '[' << filter.mask() << ']' << '(';
|
||||
for ( const auto& s : filter.substitutions() )
|
||||
debug << '[' << s.first << "->" << s.second << "]";
|
||||
debug << ')';
|
||||
|
@ -20,7 +20,7 @@ class QVariant;
|
||||
class QSK_EXPORT QskColorFilter
|
||||
{
|
||||
public:
|
||||
QskColorFilter() noexcept = default;
|
||||
QskColorFilter( QRgb mask = 0x00ffffff ) noexcept;
|
||||
|
||||
void addColorSubstitution( QRgb from, QRgb to );
|
||||
void addColorSubstitution( Qt::GlobalColor, QRgb );
|
||||
@ -37,8 +37,9 @@ class QSK_EXPORT QskColorFilter
|
||||
|
||||
bool isIdentity() const noexcept;
|
||||
|
||||
bool substituteAlphaValue() const noexcept;
|
||||
void setSubstituteAlphaValue( bool );
|
||||
// the bits to be replaced
|
||||
QRgb mask() const noexcept;
|
||||
void setMask( QRgb ) noexcept;
|
||||
|
||||
bool operator==( const QskColorFilter& other ) const noexcept;
|
||||
bool operator!=( const QskColorFilter& other ) const noexcept;
|
||||
@ -53,10 +54,15 @@ class QSK_EXPORT QskColorFilter
|
||||
const QskColorFilter&, const QskColorFilter&, qreal progress );
|
||||
|
||||
private:
|
||||
QRgb m_mask;
|
||||
QVector< QPair< QRgb, QRgb > > m_substitutions;
|
||||
bool m_substituteAlphaValue = false;
|
||||
};
|
||||
|
||||
inline QskColorFilter::QskColorFilter( QRgb mask ) noexcept
|
||||
: m_mask( mask )
|
||||
{
|
||||
}
|
||||
|
||||
inline bool QskColorFilter::isIdentity() const noexcept
|
||||
{
|
||||
return m_substitutions.isEmpty();
|
||||
@ -97,6 +103,16 @@ inline void QskColorFilter::addColorSubstitution(
|
||||
addColorSubstitution( QColor( from ).rgb(), QColor( to ).rgb() );
|
||||
}
|
||||
|
||||
inline void QskColorFilter::setMask( QRgb mask ) noexcept
|
||||
{
|
||||
m_mask = mask;
|
||||
}
|
||||
|
||||
inline QRgb QskColorFilter::mask() const noexcept
|
||||
{
|
||||
return m_mask;
|
||||
}
|
||||
|
||||
Q_DECLARE_METATYPE( QskColorFilter )
|
||||
|
||||
#ifndef QT_NO_DEBUG_STREAM
|
||||
|
Loading…
x
Reference in New Issue
Block a user