-
Notifications
You must be signed in to change notification settings - Fork 0
/
QCADView.cpp
142 lines (117 loc) · 2.45 KB
/
QCADView.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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#include "QCADView.h"
#include "ENTITY.H"
#include "MCommand.H"
#include "mainwindow.h"
#include "MCreateLine.h"
#include "MSelectCmd.h"
#include <QPainter>
#include <QStatusBar>
QCADView::QCADView()
{
m_pCmd = NULL;
m_lineColor = QColor(0, 0, 0);
m_penStyle = Qt::SolidLine;
m_penWidth = 1;
m_brushColor = QColor(255, 255, 255);
}
QCADView::~QCADView()
{
//清楚实体链表!!!
//清楚命令,可能重复
delete m_pCmd;
}
void QCADView::paintEvent(QPaintEvent* event)
{
QPainter dc(this);
//绘制画布
//坐标系统
dc.setPen(QPen(Qt::black, 1));
dc.drawLine(0, 0, 1000, 0);
dc.drawLine(0, 0, 0, 1000);
//绘制全部实体
foreach (MEntity* pEnt, m_EntityList)
{
//如果实体在选择集中,则显示状态
if( !m_SelectEntityList.contains(pEnt) )
{
dc.setPen(pEnt->GetPen());
dc.setBrush(pEnt->GetBrush());
}
else {
QPen pen(Qt::DashLine);
pen.setColor(Qt::green);
pen.setWidth(1);
QBrush brush(Qt::white);
dc.setPen(pen);
dc.setBrush(brush);
}
pEnt->Draw(&dc);
}
}
void QCADView::mousePressEvent(QMouseEvent* mouseEvent)
{
if (mouseEvent->button() == Qt::LeftButton && m_pCmd)
{
m_pCmd->OnLButtonDown(mouseEvent);
}
if (mouseEvent->button() == Qt::RightButton && m_pCmd)
{
m_pCmd->OnRButtonDown(mouseEvent);
}
}
void QCADView::mouseMoveEvent(QMouseEvent* mouseEvent)
{
if (m_pCmd)
{
m_pCmd->OnMouseMove(mouseEvent);
return;
}
//显示屏幕坐标和世界坐标
MainWindow* pMain = g_pMainWnd;
QPointF scnPos = mouseEvent->pos();
QString sScreenPosX = QString::number(scnPos.x(), 'f', 2);
QString sScreenPosY = QString::number(scnPos.y(), 'f', 2);
QString sScnPos = QStringLiteral("当前坐标:");
sScnPos += sScreenPosX;
sScnPos += ", ";
sScnPos += sScreenPosY;
if (m_pCmd == NULL)
pMain->statusBar()->showMessage(sScnPos);
}
void QCADView::mouseReleaseEvent(QMouseEvent* mouseEvent)
{
}
void QCADView::mouseDoubleClickEvent(QMouseEvent* mouseEvent)
{
if (mouseEvent->button() != Qt::LeftButton)
{
return;
}
if (m_pCmd)
{
m_pCmd->OnLButtonDblClk(mouseEvent);
}
}
void QCADView::addEntity(MEntity* pEnt)
{
m_EntityList.push_back(pEnt);
}
void QCADView::drawLine()
{
//QPainter pDC(this);
if (m_pCmd && m_pCmd->GetType() == ctCreateLine)
return;
delete m_pCmd;
m_pCmd = new MCreateLine(this);
}
void QCADView::selectEntity()
{
if (m_pCmd && m_pCmd->GetType() == ctSelect)
return;
delete m_pCmd;
m_pCmd = new MSelectCmd(this);
}
void QCADView::AddSelection(MEntity* pEnt)
{
m_SelectEntityList.push_back(pEnt);
}