-
Notifications
You must be signed in to change notification settings - Fork 0
/
shape.h
91 lines (85 loc) · 2.59 KB
/
shape.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#ifndef SHAPE_H
#define SHAPE_H
#include <QVector>
#include <QPoint>
#include <QColor>
class MainWindow;
class Shape{
protected:
int id;
QColor color;
QVector<QPoint> points;
bool dotted;//draw in dotted line
bool rotatable;//ellipse is not rotatable
bool clipable;
public:
Shape();
virtual void translateShape(int dx,int dy);
virtual void rotateShape(QPoint¢er,int r);//in angle
virtual void rotateShapeArc(QPoint¢er,double r);//in arc
virtual void scale(QPoint¢er,double s);//不同图像的scale不一样
virtual bool clip(QPoint&rect1,QPoint&rect2,int algorithm);
friend class MainWindow;
void setDotted();
void setUndotted();
bool getDotted();
void setColor(QColor color);
QColor getColor();
virtual ~Shape(){}
};
class Line :public Shape{
private:
QPoint startPoint;
QPoint endPoint;
int algorithm;
public:
Line(int id=0);
Line(QPoint startPoint,QPoint endPoint,int type,int id,QColor colr);
void translateShape(int dx,int dy);//也许可以增加simpleTranslate,用originPoint辅助
void scale(QPoint¢er,double s);//start and end piont scale and then redraw
void rotateShapeArc(QPoint¢er,double r);
void rotateShape(QPoint¢er,int r);
bool clip(QPoint&rect1,QPoint&rect2,int algorithm);
virtual ~Line(){}
};
class Polygon :public Shape{
private:
QVector<QPoint>lineStartEndPair;
int algorithm;
public:
Polygon(int id=0);
Polygon(QVector<QPoint>& points,int type,int id,QColor colr);
void translateShape(int dx,int dy);
void scale(QPoint¢er,double s);//scale each line and redraw
void rotateShapeArc(QPoint¢er,double r);
void rotateShape(QPoint¢er,int r);
virtual ~Polygon(){}
};
class Ellipse :public Shape{
private:
QPoint center;
int rx;
int ry;
public:
Ellipse(int id=0);
Ellipse(QPoint center,int rx,int ry,int id,QColor colr);
void translateShape(int dx,int dy);
void scale(QPoint¢er,double s);//scale center and rx,ry,redraw
virtual ~Ellipse(){}
};
//曲线支持平移、缩放、旋转
class Curve :public Shape{
private:
const int DEFUALT_BSPLINE_K = 4;//默认三次B样条
QVector<QPoint> ctlPoints;//控制点
int algorithm;//曲线算法
public:
Curve(int id = 0);
Curve(QVector<QPoint>& points,int type,int id,QColor color);
void translateShape(int dx,int dy);
void scale(QPoint¢er,double s);//scale center and rx,ry,redraw
void rotateShapeArc(QPoint¢er,double r);
void rotateShape(QPoint¢er,int r);
virtual ~Curve(){}
};
#endif // SHAPE_H