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
|
|
|
|
|
|
|
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-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
|
|
|
}
|
|
|
|
|
|
|
|
QskBoxBorderColors QskBoxBorderColors::interpolated(
|
|
|
|
const QskBoxBorderColors& to, qreal ratio ) const
|
|
|
|
{
|
|
|
|
QskBoxBorderColors colors;
|
|
|
|
|
|
|
|
for ( size_t i = 0; i < 4; i++ )
|
|
|
|
{
|
2022-02-04 16:11:11 +01:00
|
|
|
colors.m_gradients[ i ] = colors.m_gradients[ i ].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 ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
uint QskBoxBorderColors::hash( uint seed ) const
|
|
|
|
{
|
2022-02-04 16:11:11 +01:00
|
|
|
uint h = m_gradients[ 0 ].hash( seed );
|
|
|
|
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();
|
|
|
|
|
|
|
|
debug << "BoxBorderColors" << '(';
|
|
|
|
|
2022-02-04 16:11:11 +01:00
|
|
|
debug << " L" << colors.gradient( Qsk::Left );
|
2017-10-17 17:29:02 +02:00
|
|
|
|
2022-02-04 16:11:11 +01:00
|
|
|
debug << ", T" << colors.gradient( Qsk::Top );
|
2017-10-17 17:29:02 +02:00
|
|
|
|
2022-02-04 16:11:11 +01:00
|
|
|
debug << ", R" << colors.gradient( Qsk::Right );
|
2017-10-17 17:29:02 +02:00
|
|
|
|
2022-02-04 16:11:11 +01:00
|
|
|
debug << ", B" << colors.gradient( Qsk::Bottom );
|
2017-10-17 17:29:02 +02:00
|
|
|
|
|
|
|
debug << " )";
|
|
|
|
|
|
|
|
return debug;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|