From 66d97831b50af569036ccd2bc40fddd0b6b1de48 Mon Sep 17 00:00:00 2001 From: Uwe Rathmann Date: Mon, 9 Dec 2024 12:01:16 +0100 Subject: [PATCH] QskTextColors is a Q_GADGET now --- playground/plots/QskPlotViewSkinlet.cpp | 12 ++-- src/common/QskTextColors.cpp | 51 +++++++++++++--- src/common/QskTextColors.h | 79 +++++++++++++++++++++++-- src/controls/QskSkinlet.cpp | 14 ++--- src/nodes/QskPlainTextRenderer.cpp | 4 +- src/nodes/QskRichTextRenderer.cpp | 6 +- 6 files changed, 131 insertions(+), 35 deletions(-) diff --git a/playground/plots/QskPlotViewSkinlet.cpp b/playground/plots/QskPlotViewSkinlet.cpp index 08eb396b..9dab7d54 100644 --- a/playground/plots/QskPlotViewSkinlet.cpp +++ b/playground/plots/QskPlotViewSkinlet.cpp @@ -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 ) diff --git a/src/common/QskTextColors.cpp b/src/common/QskTextColors.cpp index 4130cf8c..c74a7637 100644 --- a/src/common/QskTextColors.cpp +++ b/src/common/QskTextColors.cpp @@ -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" diff --git a/src/common/QskTextColors.h b/src/common/QskTextColors.h index 02cb4975..b01b5c46 100644 --- a/src/common/QskTextColors.h +++ b/src/common/QskTextColors.h @@ -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& ); diff --git a/src/controls/QskSkinlet.cpp b/src/controls/QskSkinlet.cpp index b7add39f..9119f696 100644 --- a/src/controls/QskSkinlet.cpp +++ b/src/controls/QskSkinlet.cpp @@ -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 ); diff --git a/src/nodes/QskPlainTextRenderer.cpp b/src/nodes/QskPlainTextRenderer.cpp index 6a4b3053..59322fa5 100644 --- a/src/nodes/QskPlainTextRenderer.cpp +++ b/src/nodes/QskPlainTextRenderer.cpp @@ -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( diff --git a/src/nodes/QskRichTextRenderer.cpp b/src/nodes/QskRichTextRenderer.cpp index e6cbd248..35fcfdf6 100644 --- a/src/nodes/QskRichTextRenderer.cpp +++ b/src/nodes/QskRichTextRenderer.cpp @@ -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 );