6#include "QskBoxBorderColors.h"
7#include "QskRgbValue.h"
9#include <qhashfunctions.h>
12static void qskRegisterBoxBorderColors()
14 qRegisterMetaType< QskBoxBorderColors >();
16#if QT_VERSION < QT_VERSION_CHECK( 6, 0, 0 )
17 QMetaType::registerEqualsComparator< QskBoxBorderColors >();
20 QMetaType::registerConverter< QColor, QskBoxBorderColors >(
23 QMetaType::registerConverter< QskGradient, QskBoxBorderColors >(
27Q_CONSTRUCTOR_FUNCTION( qskRegisterBoxBorderColors )
29QskBoxBorderColors::QskBoxBorderColors()
33QskBoxBorderColors::QskBoxBorderColors(
36 : m_gradients { top, left, right, bottom }
40QskBoxBorderColors::QskBoxBorderColors(
const QskGradient& gradient )
41 : m_gradients { gradient, gradient, gradient, gradient }
45QskBoxBorderColors::~QskBoxBorderColors()
51 return ( m_gradients[ 0 ] == other.m_gradients[ 0 ] ) &&
52 ( m_gradients[ 1 ] == other.m_gradients[ 1 ] ) &&
53 ( m_gradients[ 2 ] == other.m_gradients[ 2 ] ) &&
54 ( m_gradients[ 3 ] == other.m_gradients[ 3 ] );
57void QskBoxBorderColors::setAlpha(
int alpha )
59 for (
int i = 0; i < 4; i++ )
61 if ( m_gradients[ i ].isValid() )
62 m_gradients[ i ].setAlpha( alpha );
66void QskBoxBorderColors::setGradients(
const QskGradient& gradient )
68 m_gradients[ 0 ] = m_gradients[ 1 ] = m_gradients[ 2 ] = m_gradients[ 3 ] = gradient;
74 m_gradients[ Top ] = top;
75 m_gradients[ Left ] = left;
76 m_gradients[ Right ] = right;
77 m_gradients[ Bottom ] = bottom;
80void QskBoxBorderColors::setGradientAt( Qt::Edges edges,
const QskGradient& gradient )
82 if ( edges & Qt::TopEdge )
83 m_gradients[ Top ] = gradient;
85 if ( edges & Qt::LeftEdge )
86 m_gradients[ Left ] = gradient;
88 if ( edges & Qt::RightEdge )
89 m_gradients[ Right ] = gradient;
91 if ( edges & Qt::BottomEdge )
92 m_gradients[ Bottom ] = gradient;
95void QskBoxBorderColors::setLeft(
const QskGradient& gradient )
97 m_gradients[ Left ] = gradient;
100void QskBoxBorderColors::setTop(
const QskGradient& gradient )
102 m_gradients[ Top ] = gradient;
105void QskBoxBorderColors::setRight(
const QskGradient& gradient )
107 m_gradients[ Right ] = gradient;
110void QskBoxBorderColors::setBottom(
const QskGradient& gradient )
112 m_gradients[ Bottom ] = gradient;
115const QskGradient& QskBoxBorderColors::gradientAt( Qt::Edge edge )
const
120 return m_gradients[ Top ];
123 return m_gradients[ Left ];
126 return m_gradients[ Right ];
129 return m_gradients[ Bottom ];
136bool QskBoxBorderColors::isVisible()
const
140 if ( m_gradients[ 0 ].isVisible() )
143 if ( m_gradients[ 1 ].isVisible() )
146 if ( m_gradients[ 2 ].isVisible() )
149 if ( m_gradients[ 3 ].isVisible() )
156bool QskBoxBorderColors::isMonochrome()
const
158 if ( m_gradients[ 0 ].isMonochrome()
159 && m_gradients[ 1 ].isMonochrome()
160 && m_gradients[ 2 ].isMonochrome()
161 && m_gradients[ 3 ].isMonochrome() )
163 if ( m_gradients[ 1 ].rgbStart() != m_gradients[ 0 ].rgbStart() )
166 if ( m_gradients[ 2 ].rgbStart() != m_gradients[ 1 ].rgbStart() )
169 if ( m_gradients[ 3 ].rgbStart() != m_gradients[ 2 ].rgbStart() )
178bool QskBoxBorderColors::isValid()
const
180 return m_gradients[ 0 ].isValid()
181 && m_gradients[ 1 ].isValid()
182 && m_gradients[ 2 ].isValid()
183 && m_gradients[ 3 ].isValid();
191 for (
size_t i = 0; i < 4; i++ )
199 colors.m_gradients[ i ] =
200 m_gradients[ i ].interpolated( to.m_gradients[ i ], ratio );
206QVariant QskBoxBorderColors::interpolate(
209 return QVariant::fromValue( from.interpolated( to, ratio ) );
212QskHashValue QskBoxBorderColors::hash( QskHashValue seed )
const
214 auto h = m_gradients[ 0 ].hash( seed );
215 h = m_gradients[ 1 ].hash( h );
216 h = m_gradients[ 2 ].hash( h );
217 h = m_gradients[ 3 ].hash( h );
222#ifndef QT_NO_DEBUG_STREAM
228 QDebugStateSaver saver( debug );
231 debug <<
"BoxBorderColors";
233 if ( !colors.isValid() )
241 if ( colors.isMonochrome() )
243 const auto& gradient = colors.gradientAt( Qt::LeftEdge );
244 QskRgb::debugColor( debug, gradient.rgbStart() );
250 const char prompts[] = {
'L',
'T',
'R',
'B' };
251 const Edge edges[] = { LeftEdge, TopEdge, RightEdge, BottomEdge };
253 for (
int i = 0; i < 4; i++ )
258 const auto& gradient = colors.gradientAt( edges[i] );
260 debug << prompts[ i ] <<
": ";
262 if ( gradient.isValid() && gradient.isMonochrome() )
263 QskRgb::debugColor( debug, gradient.rgbStart() );
277#include "moc_QskBoxBorderColors.cpp"