1 /**************************************************************************** 2 ** 3 ** Copyright (C) 2016 The Qt Company Ltd. 4 ** Contact: https://www.qt.io/licensing/ 5 ** 6 ** This file is part of Qt Creator. 7 ** 8 ** Commercial License Usage 9 ** Licensees holding valid commercial Qt licenses may use this file in 10 ** accordance with the commercial license agreement provided with the 11 ** Software or, alternatively, in accordance with the terms contained in 12 ** a written agreement between you and The Qt Company. For licensing terms 13 ** and conditions see https://www.qt.io/terms-conditions. For further 14 ** information use the contact form at https://www.qt.io/contact-us. 15 ** 16 ** GNU General Public License Usage 17 ** Alternatively, this file may be used under the terms of the GNU 18 ** General Public License version 3 as published by the Free Software 19 ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT 20 ** included in the packaging of this file. Please review the following 21 ** information to ensure the GNU General Public License requirements will 22 ** be met: https://www.gnu.org/licenses/gpl-3.0.html. 23 ** 24 ****************************************************************************/ 25 26 #pragma once 27 28 #include "controlpoint.h" 29 30 #include <modelnode.h> 31 32 #include <QMap> 33 34 #include <QPointF> 35 #include <QExplicitlySharedDataPointer> 36 37 namespace QmlDesigner { 38 39 class CubicSegmentData : public QSharedData 40 { 41 public: 42 CubicSegmentData(); 43 ModelNode modelNode; 44 ControlPoint firstControllPoint; 45 ControlPoint secondControllPoint; 46 ControlPoint thirdControllPoint; 47 ControlPoint fourthControllPoint; 48 QMap<QString, QVariant> attributes; 49 double percent; 50 }; 51 52 class CubicSegment 53 { 54 friend bool operator ==(const CubicSegment& firstCubicSegment, const CubicSegment& secondCubicSegment); 55 56 public: 57 CubicSegment(); 58 59 static CubicSegment create(); 60 61 void setModelNode(const ModelNode &modelNode); 62 ModelNode modelNode() const; 63 64 void setFirstControlPoint(const ControlPoint &firstControlPoint); 65 void setFirstControlPoint(double x, double y); 66 void setFirstControlPoint(const QPointF &coordiante); 67 68 void setSecondControlPoint(const ControlPoint &secondControlPoint); 69 void setSecondControlPoint(double x, double y); 70 void setSecondControlPoint(const QPointF &coordiante); 71 72 void setThirdControlPoint(const ControlPoint &thirdControlPoint); 73 void setThirdControlPoint(double x, double y); 74 void setThirdControlPoint(const QPointF &coordiante); 75 76 void setFourthControlPoint(const ControlPoint &fourthControlPoint); 77 void setFourthControlPoint(double x, double y); 78 void setFourthControlPoint(const QPointF &coordiante); 79 80 void setAttributes(const QMap<QString, QVariant> &attributes); 81 82 void setPercent(double percent); 83 84 ControlPoint firstControlPoint() const; 85 ControlPoint secondControlPoint() const; 86 ControlPoint thirdControlPoint() const; 87 ControlPoint fourthControlPoint() const; 88 89 const QMap<QString, QVariant> attributes() const; 90 91 double percent() const; 92 93 QList<ControlPoint> controlPoints() const; 94 95 double firstControlX() const; 96 double firstControlY() const; 97 double secondControlX() const; 98 double secondControlY() const; 99 double thirdControlX() const; 100 double thirdControlY() const; 101 double fourthControlX() const; 102 double fourthControlY() const; 103 double quadraticControlX() const; 104 double quadraticControlY() const; 105 106 bool isValid() const; 107 bool canBeConvertedToLine() const; 108 bool canBeConvertedToQuad() const; 109 110 QPointF sample(double t) const; 111 double minimumDistance(const QPointF &pickPoint, double &t) const; 112 113 QPair<CubicSegment, CubicSegment> split(double t); 114 115 void makeStraightLine(); 116 117 void updateModelNode(); 118 119 private: 120 QExplicitlySharedDataPointer<CubicSegmentData> d; 121 }; 122 123 bool operator ==(const CubicSegment& firstCubicSegment, const CubicSegment& secondCubicSegment); 124 QDebug operator<<(QDebug debug, const CubicSegment &cubicSegment); 125 126 } // namespace QmlDesigner 127