QskTextColors is a Q_GADGET now

This commit is contained in:
Uwe Rathmann 2024-12-09 12:01:16 +01:00
parent 4ad28e6076
commit 66d97831b5
6 changed files with 131 additions and 35 deletions

View File

@ -22,19 +22,17 @@ static inline QskTextColors qskTextColors(
QskSkinHintStatus status; QskSkinHintStatus status;
QskTextColors c; auto textColor = skinnable->color( aspect | A::TextColor, &status );
c.textColor = skinnable->color( aspect | A::TextColor, &status );
if ( status.aspect.subControl() != aspect.subControl() ) if ( status.aspect.subControl() != aspect.subControl() )
{ {
// using the same color as the one for the ticks // using the same color as the one for the ticks
c.textColor = skinnable->color( aspect ); textColor = skinnable->color( aspect );
} }
c.styleColor = skinnable->color( aspect | A::StyleColor ); return QskTextColors( textColor,
c.linkColor = skinnable->color( aspect | A::LinkColor ); skinnable->color( aspect | A::StyleColor ),
skinnable->color( aspect | A::LinkColor ) );
return c;
} }
static inline QskAspect qskAxisAspect( QskPlot::Axis axis ) static inline QskAspect qskAxisAspect( QskPlot::Axis axis )

View File

@ -11,17 +11,38 @@
QskHashValue QskTextColors::hash( QskHashValue seed ) const noexcept QskHashValue QskTextColors::hash( QskHashValue seed ) const noexcept
{ {
const QRgb rgb[] = { textColor.rgba(), styleColor.rgba(), linkColor.rgba() }; const QRgb rgb[] =
{
m_textColor.rgba(),
m_styleColor.isValid() ? m_styleColor.rgba() : m_textColor.rgba(),
m_linkColor.isValid() ? m_linkColor.rgba() : m_textColor.rgba()
};
return qHashBits( rgb, sizeof( rgb ), seed ); return qHashBits( rgb, sizeof( rgb ), seed );
} }
void QskTextColors::setTextColor( const QColor& color )
{
m_textColor = color;
}
void QskTextColors::setStyleColor( const QColor& color )
{
m_styleColor = color;
}
void QskTextColors::setLinkColor( const QColor& color )
{
m_linkColor = color;
}
QskTextColors QskTextColors::interpolated( QskTextColors QskTextColors::interpolated(
const QskTextColors& to, qreal ratio ) const const QskTextColors& to, qreal ratio ) const
{ {
QskTextColors colors; QskTextColors colors;
colors.textColor = QskRgb::interpolated( textColor, to.textColor, ratio ); colors.m_textColor = QskRgb::interpolated( m_textColor, to.m_textColor, ratio );
colors.styleColor = QskRgb::interpolated( styleColor, to.styleColor, ratio ); colors.m_styleColor = QskRgb::interpolated( m_styleColor, to.m_styleColor, ratio );
colors.linkColor = QskRgb::interpolated( linkColor, to.linkColor, ratio ); colors.m_linkColor = QskRgb::interpolated( m_linkColor, to.m_linkColor, ratio );
return colors; return colors;
} }
@ -50,13 +71,23 @@ QDebug operator<<( QDebug debug, const QskTextColors& colors )
debug << "TextColors" << '('; debug << "TextColors" << '(';
debug << " T"; debug << " T";
qskDebugColor( debug, colors.textColor );
debug << ", S"; if ( colors.textColor().isValid() )
qskDebugColor( debug, colors.styleColor ); qskDebugColor( debug, colors.textColor() );
else
debug << "(invalid)";
debug << ", L"; if ( colors.styleColor().isValid() )
qskDebugColor( debug, colors.linkColor ); {
debug << ", S";
qskDebugColor( debug, colors.styleColor() );
}
if ( colors.linkColor().isValid() )
{
debug << ", L";
qskDebugColor( debug, colors.linkColor() );
}
debug << " )"; debug << " )";
@ -64,3 +95,5 @@ QDebug operator<<( QDebug debug, const QskTextColors& colors )
} }
#endif #endif
#include "moc_QskTextColors.cpp"

View File

@ -16,10 +16,31 @@ class QVariant;
class QSK_EXPORT QskTextColors class QSK_EXPORT QskTextColors
{ {
Q_GADGET
Q_PROPERTY( QColor textColor READ textColor WRITE setTextColor )
Q_PROPERTY( QColor styleColor READ styleColor WRITE setStyleColor )
Q_PROPERTY( QColor linkColor READ linkColor WRITE setLinkColor )
public: public:
QskTextColors( const QColor& text = QColor(), QskTextColors( const QColor& text = QColor(),
const QColor& style = QColor(), const QColor& link = QColor() ); const QColor& style = QColor(), const QColor& link = QColor() );
QColor textColor() const;
void setTextColor( const QColor& );
void setTextColor( QRgb );
void setTextColor( Qt::GlobalColor );
QColor styleColor() const;
void setStyleColor( const QColor& );
void setStyleColor( QRgb );
void setStyleColor( Qt::GlobalColor );
QColor linkColor() const;
void setLinkColor( const QColor& );
void setLinkColor( QRgb );
void setLinkColor( Qt::GlobalColor );
QskTextColors interpolated( const QskTextColors&, qreal value ) const; QskTextColors interpolated( const QskTextColors&, qreal value ) const;
static QVariant interpolate( const QskTextColors&, static QVariant interpolate( const QskTextColors&,
@ -27,19 +48,65 @@ class QSK_EXPORT QskTextColors
QskHashValue hash( QskHashValue seed = 0 ) const noexcept; QskHashValue hash( QskHashValue seed = 0 ) const noexcept;
QColor textColor; private:
QColor styleColor; QColor m_textColor;
QColor linkColor; QColor m_styleColor;
QColor m_linkColor;
}; };
inline QskTextColors::QskTextColors( inline QskTextColors::QskTextColors(
const QColor& text, const QColor& style, const QColor& link ) const QColor& text, const QColor& style, const QColor& link )
: textColor( text ) : m_textColor( text )
, styleColor( style ) , m_styleColor( style )
, linkColor( link ) , m_linkColor( link )
{ {
} }
inline QColor QskTextColors::textColor() const
{
return m_textColor;
}
inline QColor QskTextColors::linkColor() const
{
return m_linkColor;
}
inline QColor QskTextColors::styleColor() const
{
return m_styleColor;
}
inline void QskTextColors::setTextColor( QRgb rgb )
{
setTextColor( QColor::fromRgba( rgb ) );
}
inline void QskTextColors::setTextColor( Qt::GlobalColor color )
{
setTextColor( QColor( color ) );
}
inline void QskTextColors::setStyleColor( QRgb rgb )
{
setStyleColor( QColor::fromRgba( rgb ) );
}
inline void QskTextColors::setStyleColor( Qt::GlobalColor color )
{
setStyleColor( QColor( color ) );
}
inline void QskTextColors::setLinkColor( QRgb rgb )
{
setLinkColor( QColor::fromRgba( rgb ) );
}
inline void QskTextColors::setLinkColor( Qt::GlobalColor color )
{
setLinkColor( QColor( color ) );
}
#ifndef QT_NO_DEBUG_STREAM #ifndef QT_NO_DEBUG_STREAM
QSK_EXPORT QDebug operator<<( QDebug, const QskTextColors& ); QSK_EXPORT QDebug operator<<( QDebug, const QskTextColors& );

View File

@ -183,17 +183,15 @@ static inline QskTextColors qskTextColors(
QskSkinHintStatus status; QskSkinHintStatus status;
QskTextColors c; auto textColor = skinnable->color( subControl, &status );
c.textColor = skinnable->color( subControl, &status );
#if 1 #if 1
if ( !status.isValid() ) if ( !status.isValid() )
c.textColor = skinnable->color( subControl | QskAspect::TextColor ); textColor = skinnable->color( subControl | QskAspect::TextColor );
#endif #endif
c.styleColor = skinnable->color( subControl | QskAspect::StyleColor ); return QskTextColors( textColor,
c.linkColor = skinnable->color( subControl | QskAspect::LinkColor ); skinnable->color( subControl | QskAspect::StyleColor ),
skinnable->color( subControl | QskAspect::LinkColor ) );
return c;
} }
static inline QQuickWindow* qskWindowOfSkinnable( const QskSkinnable* skinnable ) static inline QQuickWindow* qskWindowOfSkinnable( const QskSkinnable* skinnable )
@ -686,7 +684,7 @@ QSGNode* QskSkinlet::updateTextNode(
const auto textOptions = skinnable->textOptionsHint( subControl ); const auto textOptions = skinnable->textOptionsHint( subControl );
auto textStyle = Qsk::Normal; auto textStyle = Qsk::Normal;
if ( textColors.styleColor.alpha() == 0 ) if ( textColors.styleColor().alpha() == 0 )
{ {
textStyle = skinnable->flagHint< Qsk::TextStyle >( textStyle = skinnable->flagHint< Qsk::TextStyle >(
subControl | QskAspect::Style, Qsk::Normal ); subControl | QskAspect::Style, Qsk::Normal );

View File

@ -240,8 +240,8 @@ void QskPlainTextRenderer::updateNode( const QString& text,
qskRenderText( qskRenderText(
const_cast< QQuickItem* >( item ), node, layout, yBaseline, const_cast< QQuickItem* >( item ), node, layout, yBaseline,
colors.textColor, static_cast< QQuickText::TextStyle >( style ), colors.textColor(), static_cast< QQuickText::TextStyle >( style ),
colors.styleColor ); colors.styleColor() );
} }
void QskPlainTextRenderer::updateNodeColor( void QskPlainTextRenderer::updateNodeColor(

View File

@ -257,10 +257,10 @@ void QskRichTextRenderer::updateNode(
textItem.setOptions( options ); textItem.setOptions( options );
textItem.setAlignment( alignment ); textItem.setAlignment( alignment );
textItem.setColor( colors.textColor ); textItem.setColor( colors.textColor() );
textItem.setStyle( static_cast< QQuickText::TextStyle >( style ) ); textItem.setStyle( static_cast< QQuickText::TextStyle >( style ) );
textItem.setStyleColor( colors.styleColor ); textItem.setStyleColor( colors.styleColor() );
textItem.setLinkColor( colors.linkColor ); textItem.setLinkColor( colors.linkColor() );
textItem.setText( text ); textItem.setText( text );