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