diff --git a/src/common/QskTextColors.cpp b/src/common/QskTextColors.cpp new file mode 100644 index 00000000..ebda60ec --- /dev/null +++ b/src/common/QskTextColors.cpp @@ -0,0 +1,77 @@ +/****************************************************************************** + * QSkinny - Copyright (C) 2016 Uwe Rathmann + * This file may be used under the terms of the QSkinny License, Version 1.0 + *****************************************************************************/ + +#include "QskTextColors.h" +#include "QskRgbValue.h" + +#include +#include +#include + +uint QskTextColors::hash( uint seed ) const +{ + const QRgb rgb[] = + { + textColor.rgba(), + styleColor.rgba(), + linkColor.rgba() + }; + + return qHashBits( rgb, sizeof( rgb ), seed ); +} + +QskTextColors QskTextColors::interpolated( + const QskTextColors& to, qreal ratio ) const +{ + QskTextColors colors; + colors.textColor = QskRgbValue::interpolated( textColor, to.textColor, ratio ); + colors.styleColor = QskRgbValue::interpolated( styleColor, to.styleColor, ratio ); + colors.linkColor = QskRgbValue::interpolated( linkColor, to.linkColor, ratio ); + + return colors; + +} + +QVariant QskTextColors::interpolate( const QskTextColors& from, + const QskTextColors& to, qreal ratio ) +{ + return QVariant::fromValue( from.interpolated( to, ratio ) ); +} + +#ifndef QT_NO_DEBUG_STREAM + +static inline void qskDebugColor( QDebug debug, const QColor& c ) +{ + debug << '(' + << c.red() << ',' + << c.green() << ',' + << c.blue() << ',' + << c.alpha() << ')'; +} + +QDebug operator<<( QDebug debug, const QskTextColors& colors ) +{ + QDebugStateSaver saver( debug ); + debug.nospace(); + + debug << "TextColors" << '('; + + debug << " T"; + qskDebugColor( debug, colors.textColor ); + + debug << ", S"; + qskDebugColor( debug, colors.styleColor ); + + debug << ", L"; + qskDebugColor( debug, colors.linkColor ); + + debug << " )"; + + return debug; +} + +#endif + + diff --git a/src/common/QskTextColors.h b/src/common/QskTextColors.h new file mode 100644 index 00000000..3344e2bf --- /dev/null +++ b/src/common/QskTextColors.h @@ -0,0 +1,50 @@ +/****************************************************************************** + * QSkinny - Copyright (C) 2016 Uwe Rathmann + * This file may be used under the terms of the QSkinny License, Version 1.0 + *****************************************************************************/ + +#ifndef QSK_TEXT_COLORS_H +#define QSK_TEXT_COLORS_H + +#include "QskGlobal.h" +#include +#include + +class QDebug; +class QVariant; + +class QSK_EXPORT QskTextColors +{ +public: + QskTextColors( const QColor& text = QColor(), + const QColor& style = QColor(), const QColor& link = QColor() ); + + QskTextColors interpolated( const QskTextColors&, qreal value ) const; + + static QVariant interpolate( const QskTextColors&, + const QskTextColors&, qreal ratio ); + + uint hash( uint seed = 0 ) const; + + QColor textColor; + QColor styleColor; + QColor linkColor; +}; + +inline QskTextColors::QskTextColors( + const QColor& text, const QColor& style, const QColor& link ): + textColor( text ), + styleColor( style ), + linkColor( link ) +{ +} + +#ifndef QT_NO_DEBUG_STREAM + +QSK_EXPORT QDebug operator<<( QDebug, const QskTextColors& ); + +#endif + +Q_DECLARE_METATYPE( QskTextColors ) + +#endif