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#ifndef QTGRADIENTSTOPSMODEL_H
5#define QTGRADIENTSTOPSMODEL_H
6
7#include <QtCore/QObject>
8#include <QtCore/QMap>
9
10QT_BEGIN_NAMESPACE
11
12class QColor;
13
14class QtGradientStopsModel;
15
16class QtGradientStop
17{
18public:
19 qreal position() const;
20 QColor color() const;
21 QtGradientStopsModel *gradientModel() const;
22
23private:
24 void setColor(const QColor &color);
25 void setPosition(qreal position);
26 friend class QtGradientStopsModel;
27 QtGradientStop(QtGradientStopsModel *model = 0);
28 ~QtGradientStop();
29 QScopedPointer<class QtGradientStopPrivate> d_ptr;
30};
31
32class QtGradientStopsModel : public QObject
33{
34 Q_OBJECT
35public:
36 using PositionStopMap = QMap<qreal, QtGradientStop *>;
37
38 QtGradientStopsModel(QObject *parent = 0);
39 ~QtGradientStopsModel();
40
41 PositionStopMap stops() const;
42 QtGradientStop *at(qreal pos) const;
43 QColor color(qreal pos) const; // calculated between points
44 QList<QtGradientStop *> selectedStops() const;
45 QtGradientStop *currentStop() const;
46 bool isSelected(QtGradientStop *stop) const;
47 QtGradientStop *firstSelected() const;
48 QtGradientStop *lastSelected() const;
49 QtGradientStopsModel *clone() const;
50
51 QtGradientStop *addStop(qreal pos, const QColor &color);
52 void removeStop(QtGradientStop *stop);
53 void moveStop(QtGradientStop *stop, qreal newPos);
54 void swapStops(QtGradientStop *stop1, QtGradientStop *stop2);
55 void changeStop(QtGradientStop *stop, const QColor &newColor);
56 void selectStop(QtGradientStop *stop, bool select);
57 void setCurrentStop(QtGradientStop *stop);
58
59 void moveStops(double newPosition); // moves current stop to newPos and all selected stops are moved accordingly
60 void clear();
61 void clearSelection();
62 void flipAll();
63 void selectAll();
64 void deleteStops();
65
66signals:
67 void stopAdded(QtGradientStop *stop);
68 void stopRemoved(QtGradientStop *stop);
69 void stopMoved(QtGradientStop *stop, qreal newPos);
70 void stopsSwapped(QtGradientStop *stop1, QtGradientStop *stop2);
71 void stopChanged(QtGradientStop *stop, const QColor &newColor);
72 void stopSelected(QtGradientStop *stop, bool selected);
73 void currentStopChanged(QtGradientStop *stop);
74
75private:
76 QScopedPointer<class QtGradientStopsModelPrivate> d_ptr;
77 Q_DECLARE_PRIVATE(QtGradientStopsModel)
78 Q_DISABLE_COPY_MOVE(QtGradientStopsModel)
79};
80
81QT_END_NAMESPACE
82
83#endif
84

source code of qttools/src/shared/qtgradienteditor/qtgradientstopsmodel.h