1 | // Copyright (C) 2023 The Qt Company Ltd. |
---|---|
2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only |
3 | |
4 | #include "colorgradient_p.h" |
5 | |
6 | QT_BEGIN_NAMESPACE |
7 | |
8 | ColorGradientStop::ColorGradientStop(QObject *parent) |
9 | : QObject(parent) |
10 | { |
11 | } |
12 | |
13 | qreal ColorGradientStop::position() const |
14 | { |
15 | return m_position; |
16 | } |
17 | |
18 | void ColorGradientStop::setPosition(qreal position) |
19 | { |
20 | m_position = position; |
21 | updateGradient(); |
22 | emit positionChanged(position); |
23 | } |
24 | |
25 | QColor ColorGradientStop::color() const |
26 | { |
27 | return m_color; |
28 | } |
29 | |
30 | void ColorGradientStop::setColor(const QColor &color) |
31 | { |
32 | m_color = color; |
33 | updateGradient(); |
34 | emit colorChanged(color); |
35 | } |
36 | |
37 | void ColorGradientStop::updateGradient() |
38 | { |
39 | if (ColorGradient *grad = qobject_cast<ColorGradient*>(object: parent())) |
40 | grad->doUpdate(); |
41 | } |
42 | |
43 | ColorGradient::ColorGradient(QObject *parent) |
44 | : QObject(parent) |
45 | { |
46 | } |
47 | |
48 | ColorGradient::~ColorGradient() |
49 | { |
50 | } |
51 | |
52 | QQmlListProperty<ColorGradientStop> ColorGradient::stops() |
53 | { |
54 | return QQmlListProperty<ColorGradientStop>(this, &m_stops); |
55 | } |
56 | |
57 | void ColorGradient::doUpdate() |
58 | { |
59 | emit updated(); |
60 | } |
61 | |
62 | QT_END_NAMESPACE |
63 |