-
Notifications
You must be signed in to change notification settings - Fork 0
/
CREATEELLIPSE.CPP
105 lines (92 loc) · 2.18 KB
/
CREATEELLIPSE.CPP
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
92
93
94
95
96
97
98
99
100
101
102
103
104
#include "math.h"
#include "Command.h"
#include "CreateCmd.h"
#include "diagramscene.h"
#include <QGraphicsEllipseItem>
#include <QRectF>
CCreateEllipse::CCreateEllipse(DiagramScene* pDiagramScene)
: m_LeftTop(0,0), m_RightBottum(0,0)
{
m_nStep = 0; // 初始化操作步为 0
m_pDiagramScene = pDiagramScene;
}
CCreateEllipse::~CCreateEllipse()
{
}
int CCreateEllipse::GetType()
{
return ctCreateEllipse;
}
int CCreateEllipse::OnLButtonDown(QGraphicsSceneMouseEvent* mouseEvent)
{
m_nStep ++; // 每次单击鼠标左键时操作步加 1
switch(m_nStep) // 根据操作步执行相应的操作
{
case 1:
{
m_LeftTop = m_RightBottum = mouseEvent->scenePos();
Prompt(QStringLiteral("请输入椭圆的右下点:"));
m_pEllipse = new QGraphicsEllipseItem();
QRectF rect;
rect.setBottomLeft(m_LeftTop);
rect.setTopRight(m_RightBottum);
m_pEllipse->setRect(rect);
m_pDiagramScene->addItem(m_pEllipse);
break;
}
case 2:
{
m_RightBottum = mouseEvent->scenePos();
QRectF rect;
rect.setBottomLeft(m_LeftTop);
rect.setTopRight(m_RightBottum);
m_pEllipse->setRect(rect);
m_nStep = 0; // 将操作步重置为 0
Prompt(QStringLiteral("请输入椭圆的左上点:"));
break;
}
}
return 0;
}
int CCreateEllipse::OnMouseMove(QGraphicsSceneMouseEvent* mouseEvent)
{
//::SetCursor(AfxGetApp()->LoadCursor(IDC_DRAW_ELLIPSE));
switch(m_nStep)
{
case 0:
Prompt(QStringLiteral("请输入椭圆的左上点:"));
break;
case 1:
{
m_RightBottum = mouseEvent->scenePos();
QRectF rect;
rect.setBottomLeft(m_LeftTop);
rect.setTopRight(m_RightBottum);
m_pEllipse->setRect(rect);
break;
}
}
return 0;
}
// 单击鼠标右键取消当前的操作
int CCreateEllipse::OnRButtonDown(QGraphicsSceneMouseEvent* mouseEvent)
{
// 如果当前的操作步为 1 ,那么要在结束本次操作前擦除上次鼠标移动时绘制的橡皮线
if(m_nStep == 1){
;
}
m_nStep = 0; // 将操作步重置为 0
Prompt(QStringLiteral("请输入椭圆的左上点:"));
return 0;
}
// 调用Cancel 函数取消本次操作
int CCreateEllipse::Cancel()
{
// 如果当前的操作步为 1 ,那么要在结束本次操作前擦除上次鼠标移动时绘制的橡皮线
if(m_nStep == 1){
;
}
m_nStep = 0; // 将操作步重置为 0
Prompt(QStringLiteral("就绪")); // 等待提示新类型的命令操作
return 0 ;
}