1/****************************************************************************
2**
3** Copyright (C) 2016 The Qt Company Ltd.
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the tools applications of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:GPL-EXCEPT$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** GNU General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU
19** General Public License version 3 as published by the Free Software
20** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
21** included in the packaging of this file. Please review the following
22** information to ensure the GNU General Public License requirements will
23** be met: https://www.gnu.org/licenses/gpl-3.0.html.
24**
25** $QT_END_LICENSE$
26**
27****************************************************************************/
28
29#ifndef SPLINEEDITOR_H
30#define SPLINEEDITOR_H
31
32#include <QWidget>
33#include <QMenu>
34#include <QAction>
35#include <QScrollArea>
36
37#include <QEasingCurve>
38#include <QHash>
39
40class SegmentProperties;
41
42class SplineEditor : public QWidget
43{
44 Q_OBJECT
45
46 Q_PROPERTY(QEasingCurve easingCurve READ easingCurve WRITE setEasingCurve NOTIFY easingCurveChanged);
47
48public:
49 explicit SplineEditor(QWidget *parent = 0);
50 QString generateCode();
51 QStringList presetNames() const;
52 QWidget *pointListWidget();
53
54 void setControlPoint(int index, const QPointF &point)
55 {
56 m_controlPoints[index] = point;
57 update();
58 }
59
60 void setSmooth(int index, bool smooth)
61 {
62 m_smoothAction->setChecked(smooth);
63 smoothPoint(index: index * 3 + 2);
64 //update();
65 }
66
67signals:
68 void easingCurveChanged();
69 void easingCurveCodeChanged(const QString &code);
70
71
72public slots:
73 void setEasingCurve(const QEasingCurve &easingCurve);
74 void setPreset(const QString &name);
75 void setEasingCurve(const QString &code);
76
77protected:
78 void paintEvent(QPaintEvent *) override;
79 void mousePressEvent(QMouseEvent *) override;
80 void mouseMoveEvent(QMouseEvent *) override;
81 void mouseReleaseEvent(QMouseEvent *) override;
82#if QT_CONFIG(contextmenu)
83 void contextMenuEvent(QContextMenuEvent *) override;
84#endif // contextmenu
85
86 void invalidate();
87 void invalidateSmoothList();
88 void invalidateSegmentProperties();
89
90 QEasingCurve easingCurve() const
91 { return m_easingCurve; }
92
93 QHash<QString, QEasingCurve> presets() const;
94
95private:
96 int findControlPoint(const QPoint &point);
97 bool isSmooth(int i) const;
98
99 void smoothPoint( int index);
100 void cornerPoint( int index);
101 void deletePoint(int index);
102 void addPoint(const QPointF point);
103
104 void initPresets();
105
106 void setupPointListWidget();
107
108 bool isControlPointSmooth(int i) const;
109
110 QEasingCurve m_easingCurve;
111 QVector<QPointF> m_controlPoints;
112 QVector<bool> m_smoothList;
113 int m_numberOfSegments;
114 int m_activeControlPoint;
115 bool m_mouseDrag;
116 QPoint m_mousePress;
117 QHash<QString, QEasingCurve> m_presets;
118
119 QMenu *m_pointContextMenu;
120 QMenu *m_curveContextMenu;
121 QAction *m_deleteAction;
122 QAction *m_smoothAction;
123 QAction *m_cornerAction;
124 QAction *m_addPoint;
125
126 QScrollArea *m_pointListWidget;
127
128 QList<SegmentProperties*> m_segmentProperties;
129 bool m_block;
130};
131
132#endif // SPLINEEDITOR_H
133

source code of qtdeclarative/tools/qmleasing/splineeditor.h