1// Copyright (C) 2021 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
3
4#ifndef TRIMPATH_P_H
5#define TRIMPATH_P_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists purely as an
12// implementation detail. This header file may change from version to
13// version without notice, or even be removed.
14//
15// We mean it.
16//
17
18#include <QMetaType>
19#include <QPainterPath>
20#include <private/qglobal_p.h>
21
22QT_BEGIN_NAMESPACE
23
24class TrimPath {
25public:
26 TrimPath() = default;
27 TrimPath(const QPainterPath &path)
28 : mPath(path) {}
29 TrimPath(const TrimPath &other)
30 : mPath(other.mPath), mLens(other.mLens) {}
31 ~TrimPath() {}
32
33 void setPath(const QPainterPath &path) {
34 mPath = path;
35 mLens.clear();
36 }
37
38 QPainterPath path() const {
39 return mPath;
40 }
41
42 QPainterPath trimmed(qreal f1, qreal f2, qreal offset = 0.0) const;
43
44private:
45 bool lensIsDirty() const {
46 return mLens.size() != mPath.elementCount();
47 }
48 void updateLens() const;
49 int elementAtLength(qreal len) const;
50 QPointF endPointOfElement(int elemIdx) const;
51 void appendTrimmedElement(QPainterPath *to, int elemIdx, bool trimStart, qreal startLen, bool trimEnd, qreal endLen) const;
52 void appendStartOfElement(QPainterPath *to, int elemIdx, qreal len) const {
53 appendTrimmedElement(to, elemIdx, trimStart: false, startLen: 0.0, trimEnd: true, endLen: len);
54 }
55 void appendEndOfElement(QPainterPath *to, int elemIdx, qreal len) const {
56 appendTrimmedElement(to, elemIdx, trimStart: true, startLen: len, trimEnd: false, endLen: 1.0);
57 }
58
59 void appendElementRange(QPainterPath *to, int first, int last) const;
60
61 QPainterPath mPath;
62 mutable QList<qreal> mLens;
63};
64
65QT_END_NAMESPACE
66
67Q_DECLARE_METATYPE(TrimPath)
68
69#endif // TRIMPATH_P_H
70

source code of qtlottie/src/bodymovin/trimpath_p.h