diff --git a/src/common/QskBoxBorderColors.cpp b/src/common/QskBoxBorderColors.cpp index cbb12e5d..9a201d51 100644 --- a/src/common/QskBoxBorderColors.cpp +++ b/src/common/QskBoxBorderColors.cpp @@ -165,6 +165,14 @@ bool QskBoxBorderColors::isMonochrome() const && m_gradients[ 3 ].isMonochrome(); } +bool QskBoxBorderColors::isValid() const +{ + return m_gradients[ 0 ].isValid() + || m_gradients[ 1 ].isValid() + || m_gradients[ 2 ].isValid() + || m_gradients[ 3 ].isValid(); +} + QskBoxBorderColors QskBoxBorderColors::interpolated( const QskBoxBorderColors& to, qreal ratio ) const { @@ -210,14 +218,44 @@ QDebug operator<<( QDebug debug, const QskBoxBorderColors& colors ) QDebugStateSaver saver( debug ); debug.nospace(); - debug << "BoxBorderColors" << '('; + debug << "BoxBorderColors"; - debug << " L" << colors.gradient( Qsk::Left ); - debug << ", T" << colors.gradient( Qsk::Top ); - debug << ", R" << colors.gradient( Qsk::Right ); - debug << ", B" << colors.gradient( Qsk::Bottom ); + if ( !colors.isValid() ) + { + debug << "()"; + } + else + { + debug << "( "; - 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 << " )"; + } return debug; } diff --git a/src/common/QskBoxBorderColors.h b/src/common/QskBoxBorderColors.h index b6ca4b68..df670810 100644 --- a/src/common/QskBoxBorderColors.h +++ b/src/common/QskBoxBorderColors.h @@ -12,8 +12,6 @@ #include #include -class QDebug; - class QSK_EXPORT QskBoxBorderColors { public: @@ -53,6 +51,7 @@ class QSK_EXPORT QskBoxBorderColors bool isMonochrome() const; bool isVisible() const; + bool isValid() const; private: QskGradient m_gradients[ 4 ]; @@ -80,6 +79,7 @@ inline const QskGradient& QskBoxBorderColors::gradient( Qsk::Position position ) #ifndef QT_NO_DEBUG_STREAM +class QDebug; QSK_EXPORT QDebug operator<<( QDebug, const QskBoxBorderColors& ); #endif diff --git a/src/common/QskBoxBorderMetrics.cpp b/src/common/QskBoxBorderMetrics.cpp index 25de9fe6..3e9040bc 100644 --- a/src/common/QskBoxBorderMetrics.cpp +++ b/src/common/QskBoxBorderMetrics.cpp @@ -109,9 +109,24 @@ QDebug operator<<( QDebug debug, const QskBoxBorderMetrics& metrics ) QDebugStateSaver saver( debug ); debug.nospace(); - debug << "BoxBorder" << '('; - debug << metrics.sizeMode() << ',' << metrics.widths(); - debug << ')'; + debug << "BoxBorder" << "( "; + + if ( metrics.sizeMode() != Qt::AbsoluteSize ) + debug << metrics.sizeMode() << ", "; + + const auto& w = metrics.widths(); + + if ( metrics.isEquidistant() ) + { + debug << w.left(); + } + else + { + const char s[] = ", "; + debug << w.left() << s << w.top() << s << w.right() << s << w.bottom(); + } + + debug << " )"; return debug; } diff --git a/src/common/QskBoxBorderMetrics.h b/src/common/QskBoxBorderMetrics.h index 10b7961c..802d2c75 100644 --- a/src/common/QskBoxBorderMetrics.h +++ b/src/common/QskBoxBorderMetrics.h @@ -60,6 +60,8 @@ class QSK_EXPORT QskBoxBorderMetrics static QVariant interpolate( const QskBoxBorderMetrics&, const QskBoxBorderMetrics&, qreal progress ); + constexpr bool isEquidistant() const noexcept; + private: QskMargins m_widths; Qt::SizeMode m_sizeMode; @@ -115,6 +117,11 @@ inline constexpr bool QskBoxBorderMetrics::isNull() const noexcept return m_widths.isNull(); } +inline constexpr bool QskBoxBorderMetrics::isEquidistant() const noexcept +{ + return m_widths.isEquidistant(); +} + inline constexpr const QskMargins& QskBoxBorderMetrics::widths() const noexcept { return m_widths; diff --git a/src/common/QskGradient.cpp b/src/common/QskGradient.cpp index 1b1415b8..49be2f78 100644 --- a/src/common/QskGradient.cpp +++ b/src/common/QskGradient.cpp @@ -229,6 +229,11 @@ QskGradient::QskGradient( Orientation orientation, const QskGradientStops& stops setStops( stops ); } +QskGradient::QskGradient( Qt::Orientation orientation, QGradient::Preset preset ) + : QskGradient( qskOrientation( orientation ), preset ) +{ +} + QskGradient::QskGradient( Orientation orientation, QGradient::Preset preset ) : QskGradient( orientation ) { @@ -632,7 +637,49 @@ void QskGradient::updateStatusBits() const QDebug operator<<( QDebug debug, const QskGradient& gradient ) { - debug << "GR:" << gradient.orientation() << gradient.stops().count(); + QDebugStateSaver saver( debug ); + debug.nospace(); + + debug << "Gradient"; + + if ( !gradient.isValid() ) + { + debug << "()"; + } + else + { + debug << "( "; + + if ( gradient.isMonochrome() ) + { + QskRgb::debugColor( debug, gradient.startColor() ); + } + else + { + const char o[] = { 'H', 'V', 'D' }; + debug << o[ gradient.orientation() ] << ", "; + + if ( gradient.stops().count() == 2 ) + { + QskRgb::debugColor( debug, gradient.startColor() ); + debug << ", "; + QskRgb::debugColor( debug, gradient.endColor() ); + } + else + { + const auto& s = gradient.stops(); + for ( int i = 0; i < s.count(); i++ ) + { + if ( i != 0 ) + debug << ", "; + + debug << s[i]; + } + } + } + debug << " )"; + } + return debug; } diff --git a/src/common/QskGradient.h b/src/common/QskGradient.h index 75005926..be90ad5a 100644 --- a/src/common/QskGradient.h +++ b/src/common/QskGradient.h @@ -52,6 +52,7 @@ class QSK_EXPORT QskGradient QskGradient( Qt::Orientation, const QVector< QskGradientStop >& ); QskGradient( Qt::Orientation, const QColor&, const QColor& ); + QskGradient( Qt::Orientation, QGradient::Preset ); QskGradient( Orientation, const QVector< QskGradientStop >& ); QskGradient( Orientation, const QColor&, const QColor& ); diff --git a/src/common/QskGradientStop.cpp b/src/common/QskGradientStop.cpp index 530a2a1d..ffef7d97 100644 --- a/src/common/QskGradientStop.cpp +++ b/src/common/QskGradientStop.cpp @@ -78,7 +78,12 @@ QColor QskGradientStop::interpolated( QDebug operator<<( QDebug debug, const QskGradientStop& stop ) { - debug << stop.position() << ": " << stop.color(); + QDebugStateSaver saver( debug ); + debug.nospace(); + + debug << stop.position() << ": "; + QskRgb::debugColor( debug, stop.color() ); + return debug; } diff --git a/src/common/QskMargins.h b/src/common/QskMargins.h index e90c9338..3a3bb962 100644 --- a/src/common/QskMargins.h +++ b/src/common/QskMargins.h @@ -61,6 +61,7 @@ class QSK_EXPORT QskMargins : public QMarginsF QskMargins interpolated( const QskMargins&, qreal progress ) const noexcept; constexpr bool isExpanding() const noexcept; + constexpr bool isEquidistant() const noexcept; static QVariant interpolate( const QskMargins&, const QskMargins&, qreal progress ) noexcept; @@ -181,6 +182,11 @@ constexpr inline qreal QskMargins::height() const noexcept return top() + bottom(); } +inline constexpr bool QskMargins::isEquidistant() const noexcept +{ + return ( left() == top() ) && ( left() == right() ) && ( left() == bottom() ); +} + Q_DECLARE_TYPEINFO( QskMargins, Q_MOVABLE_TYPE ); Q_DECLARE_METATYPE( QskMargins ) diff --git a/src/common/QskRgbValue.cpp b/src/common/QskRgbValue.cpp index 49a87f96..7b4c0b8c 100644 --- a/src/common/QskRgbValue.cpp +++ b/src/common/QskRgbValue.cpp @@ -172,3 +172,29 @@ QRgb QskRgb::darker( QRgb rgb, int factor ) noexcept return QColor::fromRgba( rgb ).darker( factor ).rgba(); } +#ifndef QT_NO_DEBUG_STREAM + +#include + +void QskRgb::debugColor( QDebug debug, const QColor& color ) +{ + debugColor( debug, color.rgba() ); +} + +void QskRgb::debugColor( QDebug debug, QRgb rgb ) +{ + QDebugStateSaver saver( debug ); + debug.nospace(); + + debug << '['; + + debug << qRed( rgb ) << "r," << qGreen( rgb ) << "g," + << qBlue( rgb ) << 'b'; + + if ( qAlpha( rgb ) != 255 ) + debug << ',' << qAlpha( rgb ) << 'a'; + + debug << ']'; +} + +#endif diff --git a/src/common/QskRgbValue.h b/src/common/QskRgbValue.h index 9f7a3d9b..8a6059de 100644 --- a/src/common/QskRgbValue.h +++ b/src/common/QskRgbValue.h @@ -480,4 +480,16 @@ namespace QskRgb QSK_EXPORT QRgb darker( QRgb, int factor = 200 ) noexcept; } +#ifndef QT_NO_DEBUG_STREAM + +class QDebug; + +namespace QskRgb +{ + QSK_EXPORT void debugColor( QDebug, const QColor& ); + QSK_EXPORT void debugColor( QDebug, QRgb ); +} + +#endif + #endif