1 | // Copyright (C) 2016 The Qt Company Ltd. |
2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
3 | |
4 | // |
5 | // W A R N I N G |
6 | // ------------- |
7 | // |
8 | // This file is not part of the Qt API. It exists for the convenience |
9 | // of Qt Designer. This header file may change from version to version |
10 | // without notice, or even be removed. |
11 | // |
12 | // We mean it. |
13 | // |
14 | |
15 | #ifndef QTGRADIENTSTOPSMODEL_H |
16 | #define QTGRADIENTSTOPSMODEL_H |
17 | |
18 | #include <QtCore/QObject> |
19 | #include <QtCore/QMap> |
20 | |
21 | QT_BEGIN_NAMESPACE |
22 | |
23 | class QColor; |
24 | |
25 | class QtGradientStopsModel; |
26 | |
27 | class QtGradientStop |
28 | { |
29 | public: |
30 | qreal position() const; |
31 | QColor color() const; |
32 | QtGradientStopsModel *gradientModel() const; |
33 | |
34 | private: |
35 | void setColor(QColor color); |
36 | void setPosition(qreal position); |
37 | friend class QtGradientStopsModel; |
38 | QtGradientStop(QtGradientStopsModel *model = 0); |
39 | ~QtGradientStop(); |
40 | QScopedPointer<class QtGradientStopPrivate> d_ptr; |
41 | }; |
42 | |
43 | class QtGradientStopsModel : public QObject |
44 | { |
45 | Q_OBJECT |
46 | public: |
47 | using PositionStopMap = QMap<qreal, QtGradientStop *>; |
48 | |
49 | QtGradientStopsModel(QObject *parent = 0); |
50 | ~QtGradientStopsModel(); |
51 | |
52 | PositionStopMap stops() const; |
53 | QtGradientStop *at(qreal pos) const; |
54 | QColor color(qreal pos) const; // calculated between points |
55 | QList<QtGradientStop *> selectedStops() const; |
56 | QtGradientStop *currentStop() const; |
57 | bool isSelected(QtGradientStop *stop) const; |
58 | QtGradientStop *firstSelected() const; |
59 | QtGradientStop *lastSelected() const; |
60 | QtGradientStopsModel *clone() const; |
61 | |
62 | QtGradientStop *addStop(qreal pos, QColor color); |
63 | void removeStop(QtGradientStop *stop); |
64 | void moveStop(QtGradientStop *stop, qreal newPos); |
65 | void swapStops(QtGradientStop *stop1, QtGradientStop *stop2); |
66 | void changeStop(QtGradientStop *stop, QColor newColor); |
67 | void selectStop(QtGradientStop *stop, bool select); |
68 | void setCurrentStop(QtGradientStop *stop); |
69 | |
70 | void moveStops(double newPosition); // moves current stop to newPos and all selected stops are moved accordingly |
71 | void clear(); |
72 | void clearSelection(); |
73 | void flipAll(); |
74 | void selectAll(); |
75 | void deleteStops(); |
76 | |
77 | signals: |
78 | void stopAdded(QtGradientStop *stop); |
79 | void stopRemoved(QtGradientStop *stop); |
80 | void stopMoved(QtGradientStop *stop, qreal newPos); |
81 | void stopsSwapped(QtGradientStop *stop1, QtGradientStop *stop2); |
82 | void stopChanged(QtGradientStop *stop, const QColor &newColor); |
83 | void stopSelected(QtGradientStop *stop, bool selected); |
84 | void currentStopChanged(QtGradientStop *stop); |
85 | |
86 | private: |
87 | QScopedPointer<class QtGradientStopsModelPrivate> d_ptr; |
88 | Q_DECLARE_PRIVATE(QtGradientStopsModel) |
89 | Q_DISABLE_COPY_MOVE(QtGradientStopsModel) |
90 | }; |
91 | |
92 | QT_END_NAMESPACE |
93 | |
94 | #endif |
95 | |