-
Notifications
You must be signed in to change notification settings - Fork 1
/
MapForm.cpp
166 lines (143 loc) · 4.31 KB
/
MapForm.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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
#include "MapForm.h"
#include "ui_MapForm.h"
MapForm::MapForm(QWidget *parent) :
QWidget(parent),
ui(new Ui::MapForm)
{
ui->setupUi(this);
setStyleSheet("QWidget{border: 1px solid #34373E;}");
m_pMap = new GraphicMap(this);
m_pMap->drag(QPoint(0,0));
}
MapForm::~MapForm()
{
delete ui;
if(m_pMap)
{
delete m_pMap;
m_pMap = nullptr;
}
}
void MapForm::paintEvent(QPaintEvent *event)
{
Q_UNUSED(event)
QPainter painter(this);
QStyleOption opt;
opt.initFrom(this);
style()->drawPrimitive(QStyle::PE_Widget, &opt, &painter, this);
m_pMap->drawMap(painter);
}
void MapForm::onCursorChange()
{
this->setCursor(Qt::ArrowCursor);
}
void MapForm::wheelEvent(QWheelEvent *event)
{
// 鼠标中轮“缩放”操作
if (m_pMap)
{
m_pMap->wheel(event->delta()>=0 ? false : true);
this->setCursor(Qt::CrossCursor);
QTimer::singleShot(500, this, SLOT(onCursorChange()));
event->accept();
this->update();
}
}
void MapForm::mousePressEvent(QMouseEvent *event)
{
// 鼠标左键按下“选择”操作
if(event->button() == Qt::LeftButton)
{
if (m_pMap)
{
m_pMap->select(BUTTONCTRL_LDOWN, event->pos());
}
event->accept();
this->update();
}
// Alt+鼠标右键弹出更新地图菜单
else if(event->button() == Qt::RightButton && event->modifiers()==Qt::AltModifier)
{
QMenu *pMenu = new QMenu(this);
pMenu->setStyleSheet("QMenu {background-color: #323334; border:none; font-size:12pt; font-family:Microsoft YaHei; color:#D0D0D0}\
QMenu::item {background-color: transparent; padding:8px 32px; margin:0px 0px;}\
QMenu::item:selected {background-color:#1E1F1F; color:#FFFFFF}\
QMenu::item:!selected {background-color:#323334; color:#D0D0D0}");
QAction *pActionUpdateMap = new QAction(QString::fromLocal8Bit("更新地图"), this);
pActionUpdateMap->setData(1);
pMenu->addAction(pActionUpdateMap);
connect(pActionUpdateMap, SIGNAL(triggered()), this, SLOT(onUpdateMapMenuEvent()));
QPoint pos = cursor().pos();
pos.setX(pos.x() + 5);
pMenu->exec(pos);
delete pActionUpdateMap;
delete pMenu;
}
}
void MapForm::mouseReleaseEvent(QMouseEvent *event)
{
// 鼠标左键抬起“提交”操作
if(event->button() == Qt::LeftButton)
{
if (m_pMap)
{
m_pMap->confirm(BUTTONCTRL_LUP, event->pos());
QCursor cursor = m_pMap->drag(event->pos()); // 完成拖拽需再调用一次
this->setCursor(cursor);
}
event->accept();
this->update();
}
}
void MapForm::mouseMoveEvent(QMouseEvent *event)
{
// 鼠标左键按下且移动为“拖拽”操作
if(event->buttons() & Qt::LeftButton)
{
if (m_pMap)
{
QCursor cursor = m_pMap->drag(event->pos());
this->setCursor(cursor);
}
event->accept();
this->update();
}
}
void MapForm::onUpdateMapMenuEvent()
{
MsgBoxEx *msgBox = new MsgBoxEx();
connect(msgBox, SIGNAL(btnOkClicked()), this, SLOT(onBtnOkClicked()));
connect(msgBox, SIGNAL(btnCancelClicked()), this, SLOT(onBtnCancelClicked()));
msgBox->setMsgBoxMode(QString::fromLocal8Bit("与地图相关数据将会被新地图数据覆盖,\n此操作不可逆,确定更新吗?"), "", MsgBoxBtnType::MsgBoxBtnType_OkCancle);
delete msgBox;
}
void MapForm::onBtnOkClicked()
{
QFile file("./res/set/map.map");
if (!file.exists())
{
MsgBoxEx *msgBox = new MsgBoxEx();
msgBox->setMsgBoxMode(QString::fromLocal8Bit("未找到 ./res/set/map.map 地图文件,请检查此文件是否在!"));
delete msgBox;
return;
}
if(m_pMap->updateMapRelateTable("./res/set/map.map") == true)
{
m_pMap->loadMapElement();
}
}
void MapForm::onBtnCancelClicked(){}
void MapForm::onShowAgv(quint32 unNo, QString strType, quint32 unCurMark, bool bRun, bool bUnVol, bool bObs, bool bError)
{
if(m_pMap)
{
m_pMap->showAgv(unNo, strType, unCurMark, bRun, bUnVol, bObs, bError);
}
}
void MapForm::onHideAgv(quint32 unNo)
{
if(m_pMap)
{
m_pMap->hideAgv(unNo);
}
}