2017-10-17 17:29:02 +02:00
|
|
|
/******************************************************************************
|
|
|
|
* QSkinny - Copyright (C) 2016 Uwe Rathmann
|
|
|
|
* This file may be used under the terms of the QSkinny License, Version 1.0
|
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
#include "QskBoxBorderColors.h"
|
|
|
|
#include "QskRgbValue.h"
|
|
|
|
|
|
|
|
#include <qhashfunctions.h>
|
2018-07-19 14:10:48 +02:00
|
|
|
#include <qvariant.h>
|
2017-10-17 17:29:02 +02:00
|
|
|
|
|
|
|
static void qskRegisterBoxBorderColors()
|
|
|
|
{
|
|
|
|
qRegisterMetaType< QskBoxBorderColors >();
|
2020-10-30 07:29:43 +01:00
|
|
|
|
2022-03-30 18:30:22 +02:00
|
|
|
#if QT_VERSION < QT_VERSION_CHECK( 6, 0, 0 )
|
|
|
|
QMetaType::registerEqualsComparator< QskBoxBorderColors >();
|
|
|
|
#endif
|
|
|
|
|
2020-10-30 07:29:43 +01:00
|
|
|
QMetaType::registerConverter< QColor, QskBoxBorderColors >(
|
|
|
|
[]( const QColor& color ) { return QskBoxBorderColors( color ); } );
|
2022-02-04 16:11:11 +01:00
|
|
|
|
|
|
|
QMetaType::registerConverter< QskGradient, QskBoxBorderColors >(
|
|
|
|
[]( const QskGradient& gradient ) { return QskBoxBorderColors( gradient ); } );
|
2017-10-17 17:29:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Q_CONSTRUCTOR_FUNCTION( qskRegisterBoxBorderColors )
|
|
|
|
|
2022-02-04 16:11:11 +01:00
|
|
|
static inline void qskSetGradients( const QskGradient& gradient, QskGradient* gradients )
|
2017-10-17 17:29:02 +02:00
|
|
|
{
|
2022-02-04 16:11:11 +01:00
|
|
|
gradients[ 0 ] = gradients[ 1 ] = gradients[ 2 ] = gradients[ 3 ] = gradient;
|
2017-10-17 17:29:02 +02:00
|
|
|
}
|
|
|
|
|
2022-02-04 16:11:11 +01:00
|
|
|
static inline void qskSetGradients(
|
|
|
|
const QskGradient& left, const QskGradient& top,
|
|
|
|
const QskGradient& right, const QskGradient& bottom, QskGradient* gradients )
|
2017-10-17 17:29:02 +02:00
|
|
|
{
|
2022-02-04 16:11:11 +01:00
|
|
|
gradients[ Qsk::Left ] = left;
|
|
|
|
gradients[ Qsk::Top ] = top;
|
|
|
|
gradients[ Qsk::Right ] = right;
|
|
|
|
gradients[ Qsk::Bottom ] = bottom;
|
2017-10-17 17:29:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
QskBoxBorderColors::QskBoxBorderColors()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
QskBoxBorderColors::QskBoxBorderColors(
|
2022-02-04 16:11:11 +01:00
|
|
|
const QskGradient& left, const QskGradient& top,
|
|
|
|
const QskGradient& right, const QskGradient& bottom )
|
2017-10-17 17:29:02 +02:00
|
|
|
{
|
2022-02-04 16:11:11 +01:00
|
|
|
qskSetGradients( left, top, right, bottom, m_gradients );
|
2017-10-17 17:29:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
QskBoxBorderColors::QskBoxBorderColors( const QColor& color )
|
|
|
|
{
|
2022-02-04 16:11:11 +01:00
|
|
|
qskSetGradients( color, m_gradients );
|
|
|
|
}
|
|
|
|
|
|
|
|
QskBoxBorderColors::QskBoxBorderColors( const QskGradient& gradient )
|
|
|
|
{
|
|
|
|
qskSetGradients( gradient, m_gradients );
|
2017-10-17 17:29:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
QskBoxBorderColors::~QskBoxBorderColors()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
bool QskBoxBorderColors::operator==( const QskBoxBorderColors& other ) const
|
|
|
|
{
|
2022-02-04 16:11:11 +01:00
|
|
|
return ( m_gradients[ 0 ] == other.m_gradients[ 0 ] ) &&
|
|
|
|
( m_gradients[ 1 ] == other.m_gradients[ 1 ] ) &&
|
|
|
|
( m_gradients[ 2 ] == other.m_gradients[ 2 ] ) &&
|
|
|
|
( m_gradients[ 3 ] == other.m_gradients[ 3 ] );
|
2017-10-17 17:29:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void QskBoxBorderColors::setAlpha( int alpha )
|
|
|
|
{
|
|
|
|
for ( int i = 0; i < 4; i++ )
|
|
|
|
{
|
2022-02-04 16:11:11 +01:00
|
|
|
if ( m_gradients[ i ].isValid() )
|
|
|
|
m_gradients[ i ].setAlpha( alpha );
|
2017-10-17 17:29:02 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-04 16:11:11 +01:00
|
|
|
void QskBoxBorderColors::setGradients( const QskGradient& gradient )
|
2017-10-17 17:29:02 +02:00
|
|
|
{
|
2022-02-04 16:11:11 +01:00
|
|
|
qskSetGradients( gradient, m_gradients );
|
2017-10-17 17:29:02 +02:00
|
|
|
}
|
|
|
|
|
2022-02-04 16:11:11 +01:00
|
|
|
void QskBoxBorderColors::setGradients( const QskGradient& left, const QskGradient& top,
|
|
|
|
const QskGradient& right, const QskGradient& bottom )
|
2017-10-17 17:29:02 +02:00
|
|
|
{
|
2022-02-04 16:11:11 +01:00
|
|
|
qskSetGradients( left, top, right, bottom, m_gradients );
|
2017-10-17 17:29:02 +02:00
|
|
|
}
|
|
|
|
|
2022-02-04 16:11:11 +01:00
|
|
|
void QskBoxBorderColors::setGradient( Qsk::Position position, const QskGradient& gradient )
|
2017-10-17 17:29:02 +02:00
|
|
|
{
|
2022-02-04 16:11:11 +01:00
|
|
|
m_gradients[ position ] = gradient;
|
2017-10-17 17:29:02 +02:00
|
|
|
}
|
|
|
|
|
2022-02-04 16:11:11 +01:00
|
|
|
void QskBoxBorderColors::setGradientAt( Qt::Edges edges, const QskGradient& gradient )
|
2017-10-17 17:29:02 +02:00
|
|
|
{
|
|
|
|
if ( edges & Qt::TopEdge )
|
2022-02-04 16:11:11 +01:00
|
|
|
m_gradients[ Qsk::Top ] = gradient;
|
2017-10-17 17:29:02 +02:00
|
|
|
|
|
|
|
if ( edges & Qt::LeftEdge )
|
2022-02-04 16:11:11 +01:00
|
|
|
m_gradients[ Qsk::Left ] = gradient;
|
2017-10-17 17:29:02 +02:00
|
|
|
|
|
|
|
if ( edges & Qt::RightEdge )
|
2022-02-04 16:11:11 +01:00
|
|
|
m_gradients[ Qsk::Right ] = gradient;
|
2017-10-17 17:29:02 +02:00
|
|
|
|
|
|
|
if ( edges & Qt::BottomEdge )
|
2022-02-04 16:11:11 +01:00
|
|
|
m_gradients[ Qsk::Bottom ] = gradient;
|
2017-10-17 17:29:02 +02:00
|
|
|
}
|
|
|
|
|
2022-03-30 18:30:22 +02:00
|
|
|
void QskBoxBorderColors::setLeft( const QskGradient& gradient )
|
|
|
|
{
|
|
|
|
m_gradients[ Qsk::Left ] = gradient;
|
|
|
|
}
|
|
|
|
|
|
|
|
void QskBoxBorderColors::setTop( const QskGradient& gradient )
|
|
|
|
{
|
|
|
|
m_gradients[ Qsk::Top ] = gradient;
|
|
|
|
}
|
|
|
|
|
|
|
|
void QskBoxBorderColors::setRight( const QskGradient& gradient )
|
|
|
|
{
|
|
|
|
m_gradients[ Qsk::Right ] = gradient;
|
|
|
|
}
|
|
|
|
|
|
|
|
void QskBoxBorderColors::setBottom( const QskGradient& gradient )
|
|
|
|
{
|
|
|
|
m_gradients[ Qsk::Bottom ] = gradient;
|
|
|
|
}
|
|
|
|
|
2022-02-04 16:11:11 +01:00
|
|
|
const QskGradient& QskBoxBorderColors::gradientAt( Qt::Edge edge ) const
|
2017-10-17 17:29:02 +02:00
|
|
|
{
|
2018-08-03 08:15:28 +02:00
|
|
|
switch ( edge )
|
2017-10-17 17:29:02 +02:00
|
|
|
{
|
|
|
|
case Qt::TopEdge:
|
2022-02-04 16:11:11 +01:00
|
|
|
return m_gradients[ Qsk::Top ];
|
2017-10-17 17:29:02 +02:00
|
|
|
|
|
|
|
case Qt::LeftEdge:
|
2022-02-04 16:11:11 +01:00
|
|
|
return m_gradients[ Qsk::Left ];
|
2017-10-17 17:29:02 +02:00
|
|
|
|
|
|
|
case Qt::RightEdge:
|
2022-02-04 16:11:11 +01:00
|
|
|
return m_gradients[ Qsk::Right ];
|
2017-10-17 17:29:02 +02:00
|
|
|
|
|
|
|
case Qt::BottomEdge:
|
2022-02-04 16:11:11 +01:00
|
|
|
return m_gradients[ Qsk::Bottom ];
|
2017-10-17 17:29:02 +02:00
|
|
|
}
|
|
|
|
|
2022-02-04 16:11:11 +01:00
|
|
|
static QskGradient noGradient;
|
|
|
|
return noGradient;
|
2017-10-17 17:29:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool QskBoxBorderColors::isVisible() const
|
|
|
|
{
|
2022-02-04 16:11:11 +01:00
|
|
|
if ( m_gradients[ 0 ].isVisible() )
|
2017-10-17 17:29:02 +02:00
|
|
|
return true;
|
|
|
|
|
2022-02-04 16:11:11 +01:00
|
|
|
if ( m_gradients[ 1 ].isVisible() )
|
2017-10-17 17:29:02 +02:00
|
|
|
return true;
|
|
|
|
|
2022-02-04 16:11:11 +01:00
|
|
|
if ( m_gradients[ 2 ].isVisible() )
|
2017-10-17 17:29:02 +02:00
|
|
|
return true;
|
|
|
|
|
2022-02-04 16:11:11 +01:00
|
|
|
if ( m_gradients[ 3 ].isVisible() )
|
2017-10-17 17:29:02 +02:00
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool QskBoxBorderColors::isMonochrome() const
|
|
|
|
{
|
2022-02-04 16:11:11 +01:00
|
|
|
if ( m_gradients[ 1 ] != m_gradients[ 0 ] )
|
2017-10-17 17:29:02 +02:00
|
|
|
return false;
|
|
|
|
|
2022-02-04 16:11:11 +01:00
|
|
|
if ( m_gradients[ 2 ] != m_gradients[ 1 ] )
|
2017-10-17 17:29:02 +02:00
|
|
|
return false;
|
|
|
|
|
2022-02-04 16:11:11 +01:00
|
|
|
if ( m_gradients[ 3 ] != m_gradients[ 2 ] )
|
2017-10-17 17:29:02 +02:00
|
|
|
return false;
|
|
|
|
|
2022-02-04 16:11:11 +01:00
|
|
|
return m_gradients[ 0 ].isMonochrome()
|
|
|
|
&& m_gradients[ 1 ].isMonochrome()
|
|
|
|
&& m_gradients[ 2 ].isMonochrome()
|
|
|
|
&& m_gradients[ 3 ].isMonochrome();
|
2017-10-17 17:29:02 +02:00
|
|
|
}
|
|
|
|
|
2022-03-30 12:28:45 +02:00
|
|
|
bool QskBoxBorderColors::isValid() const
|
|
|
|
{
|
|
|
|
return m_gradients[ 0 ].isValid()
|
|
|
|
|| m_gradients[ 1 ].isValid()
|
|
|
|
|| m_gradients[ 2 ].isValid()
|
|
|
|
|| m_gradients[ 3 ].isValid();
|
|
|
|
}
|
|
|
|
|
2017-10-17 17:29:02 +02:00
|
|
|
QskBoxBorderColors QskBoxBorderColors::interpolated(
|
|
|
|
const QskBoxBorderColors& to, qreal ratio ) const
|
|
|
|
{
|
|
|
|
QskBoxBorderColors colors;
|
|
|
|
|
|
|
|
for ( size_t i = 0; i < 4; i++ )
|
|
|
|
{
|
2022-03-27 19:05:40 +02:00
|
|
|
#if 1
|
|
|
|
/*
|
|
|
|
When one border has a width of 0 we would prefer to ignore
|
|
|
|
the color and use always use the other color. TODO ...
|
|
|
|
*/
|
|
|
|
#endif
|
|
|
|
auto& gradient = colors.m_gradients[ i ];
|
|
|
|
gradient = gradient.interpolated( to.m_gradients[ i ], ratio );
|
2017-10-17 17:29:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return colors;
|
|
|
|
}
|
|
|
|
|
|
|
|
QVariant QskBoxBorderColors::interpolate(
|
|
|
|
const QskBoxBorderColors& from, const QskBoxBorderColors& to, qreal ratio )
|
|
|
|
{
|
|
|
|
return QVariant::fromValue( from.interpolated( to, ratio ) );
|
|
|
|
}
|
|
|
|
|
2022-03-25 10:28:06 +01:00
|
|
|
QskHashValue QskBoxBorderColors::hash( QskHashValue seed ) const
|
2017-10-17 17:29:02 +02:00
|
|
|
{
|
2022-03-25 10:28:06 +01:00
|
|
|
auto h = m_gradients[ 0 ].hash( seed );
|
2022-02-04 16:11:11 +01:00
|
|
|
h = m_gradients[ 1 ].hash( h );
|
|
|
|
h = m_gradients[ 2 ].hash( h );
|
|
|
|
h = m_gradients[ 3 ].hash( h );
|
2018-08-03 08:15:28 +02:00
|
|
|
|
2022-02-04 16:11:11 +01:00
|
|
|
return h;
|
2017-10-17 17:29:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifndef QT_NO_DEBUG_STREAM
|
|
|
|
|
2018-07-19 14:10:48 +02:00
|
|
|
#include <qdebug.h>
|
|
|
|
|
2017-10-17 17:29:02 +02:00
|
|
|
QDebug operator<<( QDebug debug, const QskBoxBorderColors& colors )
|
|
|
|
{
|
|
|
|
QDebugStateSaver saver( debug );
|
|
|
|
debug.nospace();
|
|
|
|
|
2022-03-30 12:28:45 +02:00
|
|
|
debug << "BoxBorderColors";
|
2017-10-17 17:29:02 +02:00
|
|
|
|
2022-03-30 12:28:45 +02:00
|
|
|
if ( !colors.isValid() )
|
|
|
|
{
|
|
|
|
debug << "()";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
debug << "( ";
|
|
|
|
|
|
|
|
if ( colors.isMonochrome() )
|
|
|
|
{
|
|
|
|
const auto& gradient = colors.gradient( Qsk::Left );
|
|
|
|
QskRgb::debugColor( debug, gradient.startColor() );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
const char prompts[] = { 'L', 'T', 'R', 'B' };
|
|
|
|
|
|
|
|
for ( int i = 0; i <= Qsk::Bottom; i++ )
|
|
|
|
{
|
|
|
|
if ( i != 0 )
|
|
|
|
debug << ", ";
|
|
|
|
|
|
|
|
const auto& gradient = colors.gradient(
|
|
|
|
static_cast< Qsk::Position >( i ) );
|
|
|
|
|
|
|
|
debug << prompts[ i ] << ": ";
|
|
|
|
|
|
|
|
if ( gradient.isValid() && gradient.isMonochrome() )
|
|
|
|
QskRgb::debugColor( debug, gradient.startColor() );
|
|
|
|
else
|
|
|
|
debug << gradient;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
debug << " )";
|
|
|
|
}
|
2017-10-17 17:29:02 +02:00
|
|
|
|
|
|
|
return debug;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|