QSkinny 0.8.0
C++/Qt UI toolkit
Loading...
Searching...
No Matches
QskGradientStop.h
1/******************************************************************************
2 * QSkinny - Copyright (C) The authors
3 * SPDX-License-Identifier: BSD-3-Clause
4 *****************************************************************************/
5
6#ifndef QSK_GRADIENT_STOP_H
7#define QSK_GRADIENT_STOP_H
8
9#include "QskGlobal.h"
10
11#include <qcolor.h>
12#include <qmetatype.h>
13#include <qvector.h>
14
15typedef QPair< qreal, QColor > QGradientStop;
16
17class QSK_EXPORT QskGradientStop
18{
19 Q_GADGET
20
21 Q_PROPERTY( qreal position READ position WRITE setPosition )
22 Q_PROPERTY( QColor color READ color WRITE setColor )
23
24 public:
25 constexpr QskGradientStop() noexcept = default;
26 constexpr QskGradientStop( qreal position, const QColor& ) noexcept;
27 constexpr QskGradientStop( const QGradientStop& ) noexcept;
28
29 QskGradientStop( qreal position, Qt::GlobalColor ) noexcept;
30 QskGradientStop( qreal position, QRgb ) noexcept;
31
32 constexpr bool operator==( const QskGradientStop& ) const noexcept;
33 constexpr bool operator!=( const QskGradientStop& ) const noexcept;
34
35 void setStop( qreal position, const QColor& ) noexcept;
36 void setStop( qreal position, Qt::GlobalColor ) noexcept;
37 void setStop( qreal position, QRgb ) noexcept;
38
39 constexpr qreal position() const noexcept;
40 void setPosition( qreal position ) noexcept;
41
42 constexpr const QColor& color() const noexcept;
43 void setColor( const QColor& ) noexcept;
44
45 void setRgb( QRgb ) noexcept;
46 QRgb rgb() const noexcept;
47
48 static QColor interpolated(
49 const QskGradientStop&, const QskGradientStop&, qreal position ) noexcept;
50
51 QskHashValue hash( QskHashValue seed ) const noexcept;
52
53 private:
54 qreal m_position = -1.0;
55 QColor m_color; // using QRgb instead ?
56};
57
58#if QT_VERSION >= QT_VERSION_CHECK( 6, 0, 0 )
59 Q_DECLARE_TYPEINFO( QskGradientStop, Q_RELOCATABLE_TYPE );
60#endif
61
62Q_DECLARE_METATYPE( QskGradientStop )
63
64inline constexpr QskGradientStop::QskGradientStop(
65 qreal position, const QColor& color ) noexcept
66 : m_position( position )
67 , m_color( color )
68{
69}
70
71inline QskGradientStop::QskGradientStop(
72 qreal position, const Qt::GlobalColor color ) noexcept
73 : QskGradientStop( position, QColor( color ) )
74{
75}
76
77inline QskGradientStop::QskGradientStop(
78 qreal position, QRgb rgb ) noexcept
79 : QskGradientStop( position, QColor::fromRgba( rgb ) )
80{
81}
82
83inline constexpr QskGradientStop::QskGradientStop( const QGradientStop& qtStop ) noexcept
84 : QskGradientStop( qtStop.first, qtStop.second )
85{
86}
87
88inline constexpr qreal QskGradientStop::position() const noexcept
89{
90 return m_position;
91}
92
93inline constexpr const QColor& QskGradientStop::color() const noexcept
94{
95 return m_color;
96}
97
98inline QRgb QskGradientStop::rgb() const noexcept
99{
100 return m_color.rgba();
101}
102
103inline constexpr bool QskGradientStop::operator==( const QskGradientStop& other ) const noexcept
104{
105 return ( m_position == other.m_position ) && ( m_color == other.m_color );
106}
107
108inline constexpr bool QskGradientStop::operator!=( const QskGradientStop& other ) const noexcept
109{
110 return ( !( *this == other ) );
111}
112
113#ifndef QT_NO_DEBUG_STREAM
114
115class QDebug;
116
117QSK_EXPORT QDebug operator<<( QDebug, const QskGradientStop& );
118
119#endif
120
121typedef QVector< QskGradientStop > QskGradientStops;
122
123QSK_EXPORT QColor qskInterpolatedColorAt( const QskGradientStops&, qreal pos ) noexcept;
124
125QSK_EXPORT bool qskIsMonochrome( const QskGradientStops& ) noexcept;
126QSK_EXPORT bool qskIsVisible( const QskGradientStops& ) noexcept;
127
128QSK_EXPORT QskGradientStops qskInterpolatedGradientStops(
129 const QskGradientStops&, bool, const QskGradientStops&, bool,
130 qreal ratio );
131
132QSK_EXPORT QskGradientStops qskInterpolatedGradientStops(
133 const QskGradientStops&, const QColor&, qreal ratio );
134
135QSK_EXPORT QskGradientStops qskInterpolatedGradientStops(
136 const QColor&, const QskGradientStops&, qreal ratio );
137
138QSK_EXPORT QskGradientStops qskTransparentGradientStops(
139 const QskGradientStops&, qreal ratio );
140
141QSK_EXPORT QskGradientStops qskExtractedGradientStops(
142 const QskGradientStops&, qreal from, qreal to );
143
144QSK_EXPORT QskGradientStops qskBuildGradientStops(
145 const QVector< QRgb >&, bool discrete = false );
146
147QSK_EXPORT QskGradientStops qskBuildGradientStops(
148 const QVector< QColor >&, bool discrete = false );
149
150QSK_EXPORT QskGradientStops qskRevertedGradientStops( const QskGradientStops& );
151
152QSK_EXPORT QskGradientStops qskBuildGradientStops( const QVector< QGradientStop >& );
153QSK_EXPORT QVector< QGradientStop > qskToQGradientStops( const QVector< QskGradientStop >& );
154
155#endif