diff --git a/playground/shapes/Gradient.cpp b/playground/shapes/Gradient.cpp deleted file mode 100644 index 70b701d6..00000000 --- a/playground/shapes/Gradient.cpp +++ /dev/null @@ -1,247 +0,0 @@ -/****************************************************************************** - * QSkinny - Copyright (C) 2016 Uwe Rathmann - * This file may be used under the terms of the 3-clause BSD License - *****************************************************************************/ - -#include "Gradient.h" -#include - -Gradient::Gradient( const Gradient& other ) noexcept - : m_stops( other.m_stops ) - , m_values{ other.m_values[0], other.m_values[1], - other.m_values[2], other.m_values[3], } - , m_type( other.m_type ) - , m_spread( other.m_spread ) -{ -} - -Gradient& Gradient::operator=( const Gradient& other ) noexcept -{ - m_type = other.m_type; - m_spread = other.m_spread; - m_stops = other.m_stops; - - m_values[0] = other.m_values[0]; - m_values[1] = other.m_values[1]; - m_values[2] = other.m_values[2]; - m_values[3] = other.m_values[3]; - - return *this; -} - -bool Gradient::operator==( const Gradient& other ) const noexcept -{ - if ( m_type != other.m_type ) - return false; - -#if 0 - if ( m_type == QGradient::NoGradient ) - return true; -#endif - - return ( m_spread == other.m_spread ) - && ( m_values[0] == other.m_values[0] ) - && ( m_values[1] == other.m_values[1] ) - && ( m_values[2] == other.m_values[2] ) - && ( m_values[3] == other.m_values[3] ) - && ( m_stops == other.m_stops ); -} - -void Gradient::setStops( QGradient::Preset preset ) -{ - setStops( QGradient( preset ).stops() ); -} - -void Gradient::setStops( const QGradientStops &stops ) -{ - m_stops.resize( stops.count() ); - - for ( int i = 0; i < stops.count(); i++ ) - m_stops[i] = { stops[i].first, stops[i].second }; -} - -void Gradient::setStops( const QVector< QskGradientStop >& stops ) -{ - m_stops = stops; -} - -void Gradient::setStops( const QColor& c1, const QColor& c2 ) -{ - m_stops.resize( 2 ); - m_stops[0] = QskGradientStop( 0.0, c1 ); - m_stops[1] = QskGradientStop( 1.0, c2 ); -} - -QGradientStops Gradient::qtStops() const -{ - QGradientStops qstops; - qstops.reserve( m_stops.count() ); - - for ( const auto& stop : m_stops ) - qstops += { stop.position(), stop.color() }; - - return qstops; -} - -void Gradient::setSpread( QGradient::Spread spread ) -{ - m_spread = spread; -} - -bool Gradient::isMonochrome() const -{ - if ( m_type != QGradient::NoGradient ) - { - for ( int i = 1; i < m_stops.size(); i++ ) - { - if ( m_stops[ i ].color() != m_stops[ 0 ].color() ) - return false; - } - } - - return true; -} - -bool Gradient::isVisible() const -{ - if ( m_type != QGradient::NoGradient ) - { - for ( const auto& stop : m_stops ) - { - const auto& c = stop.color(); - if ( c.isValid() && c.alpha() > 0 ) - return true; - } - } - - return false; -} - -#ifndef QT_NO_DEBUG_STREAM - -#include - -QDebug operator<<( QDebug debug, const Gradient& gradient ) -{ - QDebugStateSaver saver( debug ); - debug.nospace(); - - debug << "Gradient"; - - if ( !gradient.isValid() ) - { - debug << "()"; - } - else - { - debug << "( "; - - debug << gradient.type(); - // ... - - debug << " )"; - } - - return debug; -} - -#endif - -LinearGradient& Gradient::asLinearGradient() -{ - assert( m_type == QGradient::LinearGradient ); - return *reinterpret_cast< LinearGradient* >( this ); -} - -const LinearGradient& Gradient::asLinearGradient() const -{ - assert( m_type == QGradient::LinearGradient ); - return *reinterpret_cast< const LinearGradient* >( this ); -} - -RadialGradient& Gradient::asRadialGradient() -{ - assert( m_type == QGradient::RadialGradient ); - return *reinterpret_cast< RadialGradient* >( this ); -} - -const RadialGradient& Gradient::asRadialGradient() const -{ - assert( m_type == QGradient::RadialGradient ); - return *reinterpret_cast< const RadialGradient* >( this ); -} - -ConicGradient& Gradient::asConicGradient() -{ - assert( m_type == QGradient::ConicalGradient ); - return *reinterpret_cast< ConicGradient* >( this ); -} - -const ConicGradient& Gradient::asConicGradient() const -{ - assert( m_type == QGradient::ConicalGradient ); - return *reinterpret_cast< const ConicGradient* >( this ); -} - -void LinearGradient::setStart( const QPointF& pos ) noexcept -{ - m_values[0] = pos.x(); - m_values[1] = pos.y(); -} - -void LinearGradient::setStart( qreal x, qreal y ) noexcept -{ - m_values[0] = x; - m_values[1] = y; -} - -void LinearGradient::setStop( const QPointF& pos ) noexcept -{ - m_values[2] = pos.x(); - m_values[3] = pos.y(); -} - -void LinearGradient::setStop( qreal x, qreal y ) noexcept -{ - m_values[2] = x; - m_values[3] = y; -} - -void RadialGradient::setCenter( const QPointF& center ) noexcept -{ - m_values[0] = center.x(); - m_values[1] = center.y(); -} - -void RadialGradient::setCenter( qreal x, qreal y ) noexcept -{ - m_values[0] = x; - m_values[1] = y; -} - -void RadialGradient::setRadius( qreal radius ) noexcept -{ - m_values[2] = radius; -} - -void ConicGradient::setCenter( const QPointF& center ) noexcept -{ - m_values[0] = center.x(); - m_values[1] = center.y(); -} - -void ConicGradient::setCenter( qreal x, qreal y ) noexcept -{ - m_values[0] = x; - m_values[1] = y; -} - -void ConicGradient::setStartAngle( qreal degrees ) noexcept -{ - m_values[2] = degrees; -} - -void ConicGradient::setSpanAngle( qreal degrees ) noexcept -{ - m_values[3] = qBound( -360.0, degrees, 360.0 ); -} diff --git a/playground/shapes/Gradient.h b/playground/shapes/Gradient.h deleted file mode 100644 index 3b1d40f7..00000000 --- a/playground/shapes/Gradient.h +++ /dev/null @@ -1,264 +0,0 @@ -/****************************************************************************** - * QSkinny - Copyright (C) 2016 Uwe Rathmann - * This file may be used under the terms of the 3-clause BSD License - *****************************************************************************/ - -#pragma once - -/* - These definitions will be somehow adjusted and merged with QskGradient - and moved to the lib then. - */ - -#include -#include -#include -#include - -class LinearGradient; -class RadialGradient; -class ConicGradient; - -class Gradient -{ - public: - Gradient() noexcept = default; - Gradient( const Gradient& ) noexcept; - - Gradient& operator=( const Gradient& ) noexcept; - - bool operator==( const Gradient& ) const noexcept; - bool operator!=( const Gradient& ) const noexcept; - - QGradient::Type type() const noexcept; - - bool isValid() const noexcept; - - bool isMonochrome() const; - bool isVisible() const; - - void setStops( const QskGradientStops& ); - const QskGradientStops& stops() const noexcept; - - void setStops( QGradient::Preset ); - void setStops( const QGradientStops& ); - void setStops( const QColor&, const QColor& ); - QGradientStops qtStops() const; - - void setSpread( QGradient::Spread ); - QGradient::Spread spread() const noexcept; - - LinearGradient& asLinearGradient(); - const LinearGradient& asLinearGradient() const; - - RadialGradient& asRadialGradient(); - const RadialGradient& asRadialGradient() const; - - ConicGradient& asConicGradient(); - const ConicGradient& asConicGradient() const; - - private: - friend class LinearGradient; - friend class RadialGradient; - friend class ConicGradient; - - Gradient( QGradient::Type ) noexcept; - Gradient( QGradient::Type, qreal, qreal, qreal, qreal ) noexcept; - - QskGradientStops m_stops; - - /* - Linear: x1, y1, x2, y2 - Radial: centerX, centerY, radius, n/a - Conic: centerX, centerY, startAngle, spanAngle - */ - qreal m_values[4] = {}; - - QGradient::Type m_type = QGradient::NoGradient; - QGradient::Spread m_spread = QGradient::PadSpread; -}; - -#ifndef QT_NO_DEBUG_STREAM - -class QDebug; -QDebug operator<<( QDebug, const QskGradient& ); - -#endif - -class LinearGradient : public Gradient -{ - public: - LinearGradient() noexcept; - LinearGradient( const QPointF&, const QPointF& ) noexcept; - LinearGradient( qreal x1, qreal y1, qreal x2, qreal y2 ) noexcept; - - void setStart(const QPointF& start) noexcept; - void setStart( qreal x, qreal y ) noexcept; - - void setStop(const QPointF& start) noexcept; - void setStop( qreal x, qreal y ) noexcept; - - QPointF start() const noexcept; - QPointF stop() const noexcept; -}; - -class RadialGradient : public Gradient -{ - public: - RadialGradient() noexcept; - - RadialGradient( const QPointF& center, qreal radius ) noexcept; - RadialGradient( qreal cx, qreal cy, qreal radius ) noexcept; - - QPointF center() const noexcept; - void setCenter(const QPointF& center) noexcept; - void setCenter(qreal x, qreal y) noexcept; - - qreal radius() const noexcept; - void setRadius( qreal radius ) noexcept; -}; - -class ConicGradient : public Gradient -{ - public: - ConicGradient() noexcept; - - ConicGradient( const QPointF&, - qreal startAngle = 0.0, qreal spanAngle = 360.0 ) noexcept; - - ConicGradient( qreal cx, qreal cy, - qreal startAngle = 0.0, qreal spanAngle = 360.0 ) noexcept; - - QPointF center() const noexcept; - void setCenter(const QPointF& center) noexcept; - void setCenter(qreal x, qreal y) noexcept; - - qreal startAngle() const noexcept; - void setStartAngle( qreal ) noexcept; - - qreal spanAngle() const noexcept; - void setSpanAngle( qreal ) noexcept; -}; - -inline Gradient::Gradient( QGradient::Type type ) noexcept - : m_type( type ) -{ -} - -inline Gradient::Gradient( QGradient::Type type, - qreal v1, qreal v2, qreal v3, qreal v4 ) noexcept - : m_values{ v1, v2, v3, v4 } - , m_type( type ) -{ -} - -inline bool Gradient::operator!=( const Gradient& other ) const noexcept -{ - return !( *this == other ); -} - -inline QGradient::Type Gradient::type() const noexcept -{ - return m_type; -} - -inline bool Gradient::isValid() const noexcept -{ - return m_type != QGradient::NoGradient; -} - -inline const QskGradientStops& Gradient::stops() const noexcept -{ - return m_stops; -} - -inline QGradient::Spread Gradient::spread() const noexcept -{ - return m_spread; -} - -inline LinearGradient::LinearGradient() noexcept - : Gradient( QGradient::LinearGradient, 0.0, 0.0, 1.0, 1.0 ) -{ -} - -inline LinearGradient::LinearGradient( - const QPointF& start, const QPointF& stop ) noexcept - : LinearGradient( start.x(), start.y(), stop.x(), stop.y() ) -{ -} - -inline LinearGradient::LinearGradient( - qreal x1, qreal y1, qreal x2, qreal y2 ) noexcept - : Gradient( QGradient::LinearGradient, x1, y1, x2, y2 ) -{ -} - -inline QPointF LinearGradient::start() const noexcept -{ - return QPointF( m_values[0], m_values[1] ); -} - -inline QPointF LinearGradient::stop() const noexcept -{ - return QPointF( m_values[2], m_values[3] ); -} - -inline RadialGradient::RadialGradient() noexcept - : Gradient( QGradient::RadialGradient, 0.5, 0.5, 0.5, 0.0 ) -{ -} - -inline RadialGradient::RadialGradient( - const QPointF& center, qreal radius ) noexcept - : RadialGradient( center.x(), center.y(), radius ) -{ -} - -inline RadialGradient::RadialGradient( - qreal cx, qreal cy, qreal radius ) noexcept - : Gradient( QGradient::RadialGradient, cx, cy, radius, 0.0 ) -{ -} - -inline QPointF RadialGradient::center() const noexcept -{ - return QPointF( m_values[0], m_values[1] ); -} - -inline qreal RadialGradient::radius() const noexcept -{ - return m_values[2]; -} - -inline ConicGradient::ConicGradient() noexcept - : Gradient( QGradient::ConicalGradient, 0.0, 0.0, 0.0, 0.0 ) -{ -} - -inline ConicGradient::ConicGradient( - const QPointF& center, qreal startAngle, qreal spanAngle ) noexcept - : ConicGradient( center.x(), center.y(), startAngle, spanAngle ) -{ -} - -inline ConicGradient::ConicGradient( - qreal cx, qreal cy, qreal startAngle, qreal spanAngle ) noexcept - : Gradient( QGradient::ConicalGradient, cx, cy, startAngle, spanAngle ) -{ -} - -inline QPointF ConicGradient::center() const noexcept -{ - return QPointF( m_values[0], m_values[1] ); -} - -inline qreal ConicGradient::startAngle() const noexcept -{ - return m_values[2]; -} - -inline qreal ConicGradient::spanAngle() const noexcept -{ - return m_values[3]; -} diff --git a/src/common/QskConicGradient.cpp b/src/common/QskConicGradient.cpp new file mode 100644 index 00000000..8f221e34 --- /dev/null +++ b/src/common/QskConicGradient.cpp @@ -0,0 +1,52 @@ +/****************************************************************************** + * QSkinny - Copyright (C) 2016 Uwe Rathmann + * This file may be used under the terms of the QSkinny License, Version 1.0 + *****************************************************************************/ + +#include "QskConicGradient.h" + +QskConicGradient::QskConicGradient( qreal cx, qreal cy, qreal startAngle, + const QColor& color1, const QColor& color2 ) + : QskConicGradient( cx, cy, startAngle ) +{ + setStops( color1, color2 ); +} + +QskConicGradient::QskConicGradient( qreal cx, qreal cy, + qreal startAngle, QGradient::Preset preset ) + : QskConicGradient( cx, cy, startAngle ) +{ + setStops( preset ); +} + +QskConicGradient::QskConicGradient( qreal cx, qreal cy, + qreal startAngle, const QVector< QskGradientStop >& stops ) + : QskConicGradient( cx, cy, startAngle ) +{ + setStops( stops ); +} + +inline void QskConicGradient::setCenter( const QPointF& center ) noexcept +{ + m_values[0] = center.x(); + m_values[1] = center.y(); +} + +inline void QskConicGradient::setCenter( qreal x, qreal y ) noexcept +{ + m_values[0] = x; + m_values[1] = y; +} + +inline void QskConicGradient::setStartAngle( qreal degrees ) noexcept +{ + m_values[2] = degrees; +} + +inline void QskConicGradient::setSpanAngle( qreal degrees ) noexcept +{ + m_values[3] = qBound( -360.0, degrees, 360.0 ); +} + +#include "moc_QskConicGradient.cpp" + diff --git a/src/common/QskConicGradient.h b/src/common/QskConicGradient.h new file mode 100644 index 00000000..99a7a5f8 --- /dev/null +++ b/src/common/QskConicGradient.h @@ -0,0 +1,110 @@ +/****************************************************************************** + * QSkinny - Copyright (C) 2016 Uwe Rathmann + * This file may be used under the terms of the QSkinny License, Version 1.0 + *****************************************************************************/ + +#ifndef QSK_CONIC_GRADIENT_H +#define QSK_CONIC_GRADIENT_H + +#include "QskGradient.h" + +class QSK_EXPORT QskConicGradient : public QskGradient +{ + Q_GADGET + + Q_PROPERTY( QPointF center READ center WRITE setCenter ) + Q_PROPERTY( qreal startAngle READ startAngle WRITE setStartAngle ) + Q_PROPERTY( qreal spanAngle READ spanAngle WRITE setSpanAngle ) + + public: + // counter-clockwise + QskConicGradient() noexcept; + + QskConicGradient( const QColor&, const QColor& ); + QskConicGradient( QGradient::Preset ); + QskConicGradient( const QVector< QskGradientStop >& ); + + QskConicGradient( const QPointF&, + qreal startAngle = 0.0, qreal spanAngle = 360.0 ) noexcept; + + QskConicGradient( qreal cx, qreal cy, + qreal startAngle = 0.0, qreal spanAngle = 360.0 ) noexcept; + + QskConicGradient( qreal cx, qreal cy, qreal startAngle, + const QColor&, const QColor& ); + + QskConicGradient( const QPointF&, qreal startAngle, + const QColor&, const QColor& ); + + QskConicGradient( qreal cx, qreal cy, qreal startAngle, QGradient::Preset ); + + QskConicGradient( const QPointF&, qreal startAngle, QGradient::Preset ); + + QskConicGradient( qreal cx, qreal cy, qreal startAngle, + const QVector< QskGradientStop >& ); + + QskConicGradient( const QPointF&, qreal startAngle, + const QVector< QskGradientStop >& ); + + QPointF center() const noexcept; + void setCenter(const QPointF& center) noexcept; + void setCenter(qreal x, qreal y) noexcept; + + qreal startAngle() const noexcept; + void setStartAngle( qreal ) noexcept; + + qreal spanAngle() const noexcept; + void setSpanAngle( qreal ) noexcept; +}; + +inline QskConicGradient::QskConicGradient() noexcept + : QskConicGradient( Conic, 0.5, 0.5, 0.0, 360.0 ) +{ +} + +inline QskConicGradient::QskConicGradient( + const QPointF& center, qreal startAngle, qreal spanAngle ) noexcept + : QskConicGradient( center.x(), center.y(), startAngle, spanAngle ) +{ +} + +inline QskConicGradient::QskConicGradient( + qreal cx, qreal cy, qreal startAngle, qreal spanAngle ) noexcept + : QskGradient( Conic, cx, cy, startAngle, spanAngle ) +{ +} + +inline QskConicGradient::QskConicGradient( const QPointF& center, + qreal startAngle, const QColor& color1, const QColor& color2 ) + : QskConicGradient( center.x(), center.y(), startAngle, color1, color2 ) +{ +} + +inline QskConicGradient::QskConicGradient( const QPointF& center, + qreal startAngle, const QVector< QskGradientStop >& stops ) + : QskConicGradient( center.x(), center.y(), startAngle, stops ) +{ +} + +inline QskConicGradient::QskConicGradient( const QPointF& center, + qreal startAngle, QGradient::Preset preset ) + : QskConicGradient( center.x(), center.y(), startAngle, preset ) +{ +} + +inline QPointF QskConicGradient::center() const noexcept +{ + return QPointF( m_values[0], m_values[1] ); +} + +inline qreal QskConicGradient::startAngle() const noexcept +{ + return m_values[2]; +} + +inline qreal QskConicGradient::spanAngle() const noexcept +{ + return m_values[3]; +} + +#endif diff --git a/src/common/QskLinearGradient.cpp b/src/common/QskLinearGradient.cpp new file mode 100644 index 00000000..27768a2d --- /dev/null +++ b/src/common/QskLinearGradient.cpp @@ -0,0 +1,135 @@ +/****************************************************************************** + * QSkinny - Copyright (C) 2016 Uwe Rathmann + * This file may be used under the terms of the QSkinny License, Version 1.0 + *****************************************************************************/ + +#include "QskLinearGradient.h" + +QskLinearGradient::QskLinearGradient( Qt::Orientation orientation ) noexcept + : QskGradient( QskGradient::Linear ) +{ + setOrientation( orientation ); +} + +QskLinearGradient::QskLinearGradient( const QColor& color ) + : QskLinearGradient( Qt::Vertical ) +{ + setStops( color ); +} + +QskLinearGradient::QskLinearGradient( + const QColor& startColor, const QColor& stopColor ) + : QskLinearGradient( Qt::Vertical ) +{ + setStops( startColor, stopColor ); +} + +QskLinearGradient::QskLinearGradient( QGradient::Preset preset ) + : QskLinearGradient( Qt::Vertical ) +{ + setStops( preset ); +} + +QskLinearGradient::QskLinearGradient( const QVector< QskGradientStop >& stops ) + : QskLinearGradient( Qt::Vertical ) +{ + setStops( stops ); +} + +QskLinearGradient::QskLinearGradient( Qt::Orientation orientation, const QColor& color ) + : QskLinearGradient( orientation ) +{ + setStops( color ); +} + +QskLinearGradient::QskLinearGradient( Qt::Orientation orientation, + const QColor& startColor, const QColor& stopColor ) + : QskLinearGradient( orientation ) +{ + setStops( startColor, stopColor ); +} + +QskLinearGradient::QskLinearGradient( + Qt::Orientation orientation, QGradient::Preset preset ) + : QskLinearGradient( orientation ) +{ + setStops( preset ); +} + +QskLinearGradient::QskLinearGradient( + Qt::Orientation orientation, const QVector< QskGradientStop >& stops ) + : QskLinearGradient( orientation ) +{ + setStops( stops ); +} + +void QskLinearGradient::setOrientation( Qt::Orientation orientation ) noexcept +{ + setStart( 0.0, 0.0 ); + + if ( orientation == Qt::Vertical ) + setStop( 0.0, 1.0 ); + else + setStop( 1.0, 0.0 ); +} + +QskLinearGradient::QskLinearGradient( qreal x1, qreal y1, + qreal x2, qreal y2, const QColor& color1, const QColor& color2 ) + : QskLinearGradient( x1, y1, x2, y2 ) +{ + setStops( color1, color2 ); +} + +QskLinearGradient::QskLinearGradient( qreal x1, qreal y1, + qreal x2, qreal y2, QGradient::Preset preset ) + : QskLinearGradient( x1, y1, x2, y2 ) +{ + setStops( preset ); +} + +QskLinearGradient::QskLinearGradient( qreal x1, qreal y1, + qreal x2, qreal y2, const QVector< QskGradientStop >& stops ) + : QskLinearGradient( x1, y1, x2, y2 ) +{ + setStops( stops ); +} + +void QskLinearGradient::setStart( const QPointF& pos ) noexcept +{ + m_values[0] = pos.x(); + m_values[1] = pos.y(); +} + +void QskLinearGradient::setStart( qreal x, qreal y ) noexcept +{ + m_values[0] = x; + m_values[1] = y; +} + +void QskLinearGradient::setStop( const QPointF& pos ) noexcept +{ + m_values[2] = pos.x(); + m_values[3] = pos.y(); +} + +void QskLinearGradient::setStop( qreal x, qreal y ) noexcept +{ + m_values[2] = x; + m_values[3] = y; +} + +void QskLinearGradient::setInterval( Qt::Orientation orientation, qreal from, qreal to ) +{ + if ( orientation == Qt::Vertical ) + { + m_values[1] = from; + m_values[3] = to; + } + else + { + m_values[0] = from; + m_values[2] = to; + } +} + +#include "moc_QskLinearGradient.cpp" diff --git a/src/common/QskLinearGradient.h b/src/common/QskLinearGradient.h new file mode 100644 index 00000000..7d0b79bd --- /dev/null +++ b/src/common/QskLinearGradient.h @@ -0,0 +1,192 @@ +/****************************************************************************** + * QSkinny - Copyright (C) 2016 Uwe Rathmann + * This file may be used under the terms of the QSkinny License, Version 1.0 + *****************************************************************************/ + +#ifndef QSK_LINEAR_GRADIENT_H +#define QSK_LINEAR_GRADIENT_H + +#include "QskGradient.h" + +class QSK_EXPORT QskLinearGradient : public QskGradient +{ + Q_GADGET + + Q_PROPERTY( QPointF start READ start WRITE setStart ) + Q_PROPERTY( QPointF stop READ stop WRITE setStop ) + + public: + QskLinearGradient() noexcept; + + QskLinearGradient( Qt::GlobalColor ); + QskLinearGradient( QRgb ); + QskLinearGradient( const QColor& ); + QskLinearGradient( const QColor&, const QColor& ); + QskLinearGradient( QGradient::Preset ); + QskLinearGradient( const QVector< QskGradientStop >& ); + + QskLinearGradient( Qt::Orientation ) noexcept; + QskLinearGradient( Qt::Orientation, Qt::GlobalColor ); + QskLinearGradient( Qt::Orientation, QRgb ); + QskLinearGradient( Qt::Orientation, const QColor& ); + QskLinearGradient( Qt::Orientation, const QColor&, const QColor& ); + QskLinearGradient( Qt::Orientation, QGradient::Preset ); + QskLinearGradient( Qt::Orientation, const QVector< QskGradientStop >& ); + + QskLinearGradient( const QPointF&, const QPointF& ) noexcept; + QskLinearGradient( qreal x1, qreal y1, qreal x2, qreal y2 ) noexcept; + + QskLinearGradient( const QPointF&, const QPointF&, + const QColor&, const QColor& ); + + QskLinearGradient( qreal x1, qreal y1, + qreal x2, qreal y2, const QColor&, const QColor& ); + + QskLinearGradient( const QPointF&, const QPointF&, QGradient::Preset ); + + QskLinearGradient( qreal x1, qreal y1, + qreal x2, qreal y2, QGradient::Preset ); + + QskLinearGradient( const QPointF&, const QPointF&, + const QVector< QskGradientStop >& ); + + QskLinearGradient( qreal x1, qreal y1, + qreal x2, qreal y2, const QVector< QskGradientStop >& ); + + void setStart(const QPointF& start) noexcept; + void setStart( qreal x, qreal y ) noexcept; + + void setStop(const QPointF& start) noexcept; + void setStop( qreal x, qreal y ) noexcept; + + void setInterval( Qt::Orientation, qreal, qreal ); + + void setOrientation( Qt::Orientation ) noexcept; + bool isOriented( Qt::Orientation ) const noexcept; + + bool isHorizontal() const noexcept; + bool isVertical() const noexcept; + bool isTilted() const noexcept; + + QPointF start() const noexcept; + QPointF stop() const noexcept; + + qreal x1() const noexcept; + qreal y1() const noexcept; + + qreal x2() const noexcept; + qreal y2() const noexcept; +}; + +inline QskLinearGradient::QskLinearGradient() noexcept + : QskGradient( QskGradient::Linear, 0.0, 0.0, 0.0, 1.0 ) +{ +} + +inline QskLinearGradient::QskLinearGradient( Qt::GlobalColor color ) + : QskLinearGradient( QColor( color ) ) +{ +} + +inline QskLinearGradient::QskLinearGradient( QRgb rgb ) + : QskLinearGradient( QColor::fromRgba( rgb ) ) +{ +} + +inline QskLinearGradient::QskLinearGradient( + Qt::Orientation orientation, Qt::GlobalColor color ) + : QskLinearGradient( orientation, QColor( color ) ) +{ +} + +inline QskLinearGradient::QskLinearGradient( + Qt::Orientation orientation, QRgb rgb ) + : QskLinearGradient( orientation, QColor::fromRgba( rgb ) ) +{ +} + +inline QskLinearGradient::QskLinearGradient( + const QPointF& start, const QPointF& stop, + const QColor& color1, const QColor& color2 ) + : QskLinearGradient( start.x(), start.y(), stop.x(), stop.y(), color1, color2 ) +{ +} + +inline QskLinearGradient::QskLinearGradient( + const QPointF& start, const QPointF& stop, QGradient::Preset preset ) + : QskLinearGradient( start.x(), start.y(), stop.x(), stop.y(), preset ) +{ +} + +inline QskLinearGradient::QskLinearGradient( + const QPointF& start, const QPointF& stop, + const QVector< QskGradientStop >& stops ) + : QskLinearGradient( start.x(), start.y(), stop.x(), stop.y(), stops ) +{ +} + +inline QskLinearGradient::QskLinearGradient( + const QPointF& start, const QPointF& stop ) noexcept + : QskLinearGradient( start.x(), start.y(), stop.x(), stop.y() ) +{ +} + +inline QskLinearGradient::QskLinearGradient( + qreal x1, qreal y1, qreal x2, qreal y2 ) noexcept + : QskGradient( QskGradient::Linear, x1, y1, x2, y2 ) +{ +} + +inline qreal QskLinearGradient::x1() const noexcept +{ + return m_values[0]; +} + +inline qreal QskLinearGradient::y1() const noexcept +{ + return m_values[1]; +} + +inline qreal QskLinearGradient::x2() const noexcept +{ + return m_values[2]; +} + +inline qreal QskLinearGradient::y2() const noexcept +{ + return m_values[3]; +} + +inline QPointF QskLinearGradient::start() const noexcept +{ + return QPointF( x1(), y1() ); +} + +inline QPointF QskLinearGradient::stop() const noexcept +{ + return QPointF( x2(), y2() ); +} + +inline bool QskLinearGradient::isOriented( + Qt::Orientation orientation ) const noexcept +{ + return ( orientation == Qt::Horizontal ) + ? isHorizontal() : isVertical(); +} + +inline bool QskLinearGradient::isHorizontal() const noexcept +{ + return !isVertical() && ( y1() == y2() ); +} + +inline bool QskLinearGradient::isVertical() const noexcept +{ + return x1() == x2(); +} + +inline bool QskLinearGradient::isTilted() const noexcept +{ + return ( x1() != x2() ) && ( y1() != y2() ); +} + +#endif diff --git a/src/common/QskRadialGradient.cpp b/src/common/QskRadialGradient.cpp new file mode 100644 index 00000000..0f4f00b1 --- /dev/null +++ b/src/common/QskRadialGradient.cpp @@ -0,0 +1,69 @@ +/****************************************************************************** + * QSkinny - Copyright (C) 2016 Uwe Rathmann + * This file may be used under the terms of the QSkinny License, Version 1.0 + *****************************************************************************/ + +#include "QskRadialGradient.h" + +QskRadialGradient::QskRadialGradient( qreal cx, qreal cy, qreal radius ) noexcept + : QskGradient( Radial, cx, cy, radius, 0.0 ) +{ +} + +QskRadialGradient::QskRadialGradient( const QColor& color1, const QColor& color2 ) + : QskRadialGradient() +{ + setStops( color1, color2 ); +} + +QskRadialGradient::QskRadialGradient( QGradient::Preset preset ) + : QskRadialGradient() +{ + setStops( preset ); +} + +QskRadialGradient::QskRadialGradient( const QVector< QskGradientStop >& stops ) + : QskRadialGradient() +{ + setStops( stops ); +} + +QskRadialGradient::QskRadialGradient( qreal cx, qreal cy, qreal radius, + const QColor& color1, const QColor& color2 ) + : QskRadialGradient( cx, cy, radius ) +{ + setStops( color1, color2 ); +} + +QskRadialGradient::QskRadialGradient( qreal cx, qreal cy, + qreal radius, QGradient::Preset preset ) + : QskRadialGradient( cx, cy, radius ) +{ + setStops( preset ); +} + +QskRadialGradient::QskRadialGradient( qreal cx, qreal cy, + qreal radius, const QVector< QskGradientStop >& stops ) + : QskRadialGradient( cx, cy, radius ) +{ + setStops( stops ); +} + +void QskRadialGradient::setCenter( const QPointF& center ) noexcept +{ + m_values[0] = center.x(); + m_values[1] = center.y(); +} + +void QskRadialGradient::setCenter( qreal x, qreal y ) noexcept +{ + m_values[0] = x; + m_values[1] = y; +} + +void QskRadialGradient::setRadius( qreal radius ) noexcept +{ + m_values[2] = radius; +} + +#include "moc_QskRadialGradient.cpp" diff --git a/src/common/QskRadialGradient.h b/src/common/QskRadialGradient.h new file mode 100644 index 00000000..5567fa00 --- /dev/null +++ b/src/common/QskRadialGradient.h @@ -0,0 +1,90 @@ +/****************************************************************************** + * QSkinny - Copyright (C) 2016 Uwe Rathmann + * This file may be used under the terms of the QSkinny License, Version 1.0 + *****************************************************************************/ + +#ifndef QSK_RADIAL_GRADIENT_H +#define QSK_RADIAL_GRADIENT_H + +#include "QskGradient.h" + +class QSK_EXPORT QskRadialGradient : public QskGradient +{ + Q_GADGET + + Q_PROPERTY( QPointF center READ center WRITE setCenter ) + Q_PROPERTY( qreal radius READ radius WRITE setRadius ) + + public: + QskRadialGradient() noexcept; + + QskRadialGradient( const QColor&, const QColor& ); + QskRadialGradient( QGradient::Preset ); + QskRadialGradient( const QVector< QskGradientStop >& ); + + QskRadialGradient( const QPointF& center, qreal radius ) noexcept; + QskRadialGradient( qreal cx, qreal cy, qreal radius ) noexcept; + + QskRadialGradient( const QPointF& center, qreal radius, + const QColor&, const QColor& ); + + QskRadialGradient( qreal cx, qreal cy, qreal radius, + const QColor&, const QColor& ); + + QskRadialGradient( const QPointF& center, qreal radius, QGradient::Preset ); + QskRadialGradient( qreal cx, qreal cy, qreal radius, QGradient::Preset ); + + QskRadialGradient( const QPointF& center, qreal radius, + const QVector< QskGradientStop >& ); + + QskRadialGradient( qreal cx, qreal cy, qreal radius, + const QVector< QskGradientStop >& ); + + QPointF center() const noexcept; + void setCenter(const QPointF& center) noexcept; + void setCenter(qreal x, qreal y) noexcept; + + qreal radius() const noexcept; + void setRadius( qreal radius ) noexcept; +}; + +inline QskRadialGradient::QskRadialGradient() noexcept + : QskGradient( Radial, 0.5, 0.5, 0.5, 0.0 ) +{ +} + +inline QskRadialGradient::QskRadialGradient( + const QPointF& center, qreal radius ) noexcept + : QskRadialGradient( center.x(), center.y(), radius ) +{ +} + +inline QskRadialGradient::QskRadialGradient( + const QPointF& center, qreal radius, const QColor& start, const QColor& stop ) + : QskRadialGradient( center.x(), center.y(), radius, start, stop ) +{ +} + +inline QskRadialGradient::QskRadialGradient( + const QPointF& center, qreal radius, QGradient::Preset preset ) + : QskRadialGradient( center.x(), center.y(), radius, preset ) +{ +} + +inline QskRadialGradient::QskRadialGradient( + const QPointF& center, qreal radius, const QVector< QskGradientStop >& stops ) + : QskRadialGradient( center.x(), center.y(), radius, stops ) +{ +} + +inline QPointF QskRadialGradient::center() const noexcept +{ + return QPointF( m_values[0], m_values[1] ); +} + +inline qreal QskRadialGradient::radius() const noexcept +{ + return m_values[2]; +} + +#endif