qskinny/src/common/QskTextColors.cpp

100 lines
2.3 KiB
C++
Raw Normal View History

2017-10-20 18:26:14 +00:00
/******************************************************************************
2024-01-17 13:31:45 +00:00
* QSkinny - Copyright (C) The authors
2023-04-06 07:23:37 +00:00
* SPDX-License-Identifier: BSD-3-Clause
2017-10-20 18:26:14 +00:00
*****************************************************************************/
#include "QskTextColors.h"
#include "QskRgbValue.h"
#include <qhashfunctions.h>
2018-08-03 06:15:28 +00:00
#include <qvariant.h>
2017-10-20 18:26:14 +00:00
2022-03-25 10:21:32 +00:00
QskHashValue QskTextColors::hash( QskHashValue seed ) const noexcept
2017-10-20 18:26:14 +00:00
{
2024-12-09 11:01:16 +00:00
const QRgb rgb[] =
{
m_textColor.rgba(),
m_styleColor.isValid() ? m_styleColor.rgba() : m_textColor.rgba(),
m_linkColor.isValid() ? m_linkColor.rgba() : m_textColor.rgba()
};
2017-10-20 18:26:14 +00:00
return qHashBits( rgb, sizeof( rgb ), seed );
}
2024-12-09 11:01:16 +00:00
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;
}
2017-10-20 18:26:14 +00:00
QskTextColors QskTextColors::interpolated(
const QskTextColors& to, qreal ratio ) const
{
QskTextColors colors;
2024-12-09 11:01:16 +00:00
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 );
2017-10-20 18:26:14 +00:00
return colors;
}
2018-08-03 06:15:28 +00:00
QVariant QskTextColors::interpolate(
const QskTextColors& from, const QskTextColors& to, qreal ratio )
2017-10-20 18:26:14 +00:00
{
return QVariant::fromValue( from.interpolated( to, ratio ) );
}
#ifndef QT_NO_DEBUG_STREAM
2018-07-19 12:10:48 +00:00
#include <qdebug.h>
2017-10-20 18:26:14 +00:00
static inline void qskDebugColor( QDebug debug, const QColor& c )
{
debug << '(' << c.red() << ',' << c.green() << ','
<< c.blue() << ',' << c.alpha() << ')';
2017-10-20 18:26:14 +00:00
}
QDebug operator<<( QDebug debug, const QskTextColors& colors )
{
QDebugStateSaver saver( debug );
debug.nospace();
debug << "TextColors" << '(';
debug << " T";
2024-12-09 11:01:16 +00:00
if ( colors.textColor().isValid() )
qskDebugColor( debug, colors.textColor() );
else
debug << "(invalid)";
if ( colors.styleColor().isValid() )
{
debug << ", S";
qskDebugColor( debug, colors.styleColor() );
}
2017-10-20 18:26:14 +00:00
2024-12-09 11:01:16 +00:00
if ( colors.linkColor().isValid() )
{
debug << ", L";
qskDebugColor( debug, colors.linkColor() );
}
2017-10-20 18:26:14 +00:00
debug << " )";
return debug;
}
#endif
2024-12-09 11:01:16 +00:00
#include "moc_QskTextColors.cpp"