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;
QskTextColors c;
c.textColor = skinnable->color( aspect | A::TextColor, &status );
auto textColor = skinnable->color( aspect | A::TextColor, &status );
if ( status.aspect.subControl() != aspect.subControl() )
{
// 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 );
c.linkColor = skinnable->color( aspect | A::LinkColor );
return c;
return QskTextColors( textColor,
skinnable->color( aspect | A::StyleColor ),
skinnable->color( aspect | A::LinkColor ) );
}
static inline QskAspect qskAxisAspect( QskPlot::Axis axis )

View File

@ -11,17 +11,38 @@
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 );
}
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(
const QskTextColors& to, qreal ratio ) const
{
QskTextColors colors;
colors.textColor = QskRgb::interpolated( textColor, to.textColor, ratio );
colors.styleColor = QskRgb::interpolated( styleColor, to.styleColor, ratio );
colors.linkColor = QskRgb::interpolated( linkColor, to.linkColor, ratio );
colors.m_textColor = QskRgb::interpolated( m_textColor, to.m_textColor, ratio );
colors.m_styleColor = QskRgb::interpolated( m_styleColor, to.m_styleColor, ratio );
colors.m_linkColor = QskRgb::interpolated( m_linkColor, to.m_linkColor, ratio );
return colors;
}
@ -50,13 +71,23 @@ QDebug operator<<( QDebug debug, const QskTextColors& colors )
debug << "TextColors" << '(';
debug << " T";
qskDebugColor( debug, colors.textColor );
debug << ", S";
qskDebugColor( debug, colors.styleColor );
if ( colors.textColor().isValid() )
qskDebugColor( debug, colors.textColor() );
else
debug << "(invalid)";
debug << ", L";
qskDebugColor( debug, colors.linkColor );
if ( colors.styleColor().isValid() )
{
debug << ", S";
qskDebugColor( debug, colors.styleColor() );
}
if ( colors.linkColor().isValid() )
{
debug << ", L";
qskDebugColor( debug, colors.linkColor() );
}
debug << " )";
@ -64,3 +95,5 @@ QDebug operator<<( QDebug debug, const QskTextColors& colors )
}
#endif
#include "moc_QskTextColors.cpp"

View File

@ -16,10 +16,31 @@ class QVariant;
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:
QskTextColors( const QColor& text = 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;
static QVariant interpolate( const QskTextColors&,
@ -27,19 +48,65 @@ class QSK_EXPORT QskTextColors
QskHashValue hash( QskHashValue seed = 0 ) const noexcept;
QColor textColor;
QColor styleColor;
QColor linkColor;
private:
QColor m_textColor;
QColor m_styleColor;
QColor m_linkColor;
};
inline QskTextColors::QskTextColors(
const QColor& text, const QColor& style, const QColor& link )
: textColor( text )
, styleColor( style )
, linkColor( link )
: m_textColor( text )
, m_styleColor( style )
, 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
QSK_EXPORT QDebug operator<<( QDebug, const QskTextColors& );

View File

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

View File

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

View File

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