-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathC2DDrawWindow.cpp
87 lines (73 loc) · 2.16 KB
/
C2DDrawWindow.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
#include"C2DDrawWindow.h"
#include"C2DDrawWidget.h"
#include<QHBoxLayout>
#include<qaction.h>
#include<qtoolbar.h>
#include<qstatusbar.h>
#include<qcolordialog.h>
C2DDrawWindow::C2DDrawWindow()
{
this->setWindowTitle("2DDrawWindow");//标题
QIcon icon1("color.jpg");//创建图标
QIcon icon2("delete.jpg");
QIcon icon3("CurveLine.jpg");
QIcon icon4("Lines.jpg");
QIcon icon5("Ellipse.jpg");
C2DDrawWidget* mywidget = new C2DDrawWidget;//实例化
QToolBar* m_tool_bar = new QToolBar();//创建工具栏
addToolBar(Qt::TopToolBarArea, m_tool_bar);
QAction* toolbar1 = new QAction(icon1, tr("colorChange"), this);//添加按钮
QAction* toolbar2 = new QAction(icon2, tr("delete"), this);
QAction* toolbar3 = new QAction(icon3, tr("curveLine"), this);
QAction* toolbar4 = new QAction(icon4, tr("Lines"), this);
QAction* toolbar5 = new QAction(icon5, tr("Ellipse"), this);
m_tool_bar->addAction(toolbar1);
m_tool_bar->addAction(toolbar2);
m_tool_bar->addAction(toolbar3);
m_tool_bar->addAction(toolbar4);
m_tool_bar->addAction(toolbar5);
connect(toolbar1, SIGNAL(triggered()), mywidget, SLOT(slotChangePntColor()));//连接按钮功能
connect(toolbar2, SIGNAL(triggered()), mywidget, SLOT(slotClearPoint()));
connect(toolbar3, SIGNAL(triggered()), mywidget, SLOT(slotDrawCurve()));
connect(toolbar4, SIGNAL(triggered()), mywidget, SLOT(slotDrawLine()));
connect(toolbar5, SIGNAL(triggered()), mywidget, SLOT(slotDrawEllipse()));
this->setCentralWidget(mywidget);
}
void C2DDrawWidget::slotChangePntColor()
{
QColor t_color = QColorDialog::getColor(Qt::white, this);
if (t_color.isValid())
{
PntColor = t_color;
update();
}
else return;
}
void C2DDrawWidget::slotDrawCurve()
{
CurveFlag = !CurveFlag;
update();
}
void C2DDrawWidget::slotClearPoint()
{
LineT.setLine(-100, -100, -100, -100);
EllipseT.setRect(-100, -100, 0, 0);
ellipse.clear();
curves.clear();
lines.clear();
points.clear();
update();
}
void C2DDrawWidget::slotDrawLine()
{
LineFlag = !LineFlag;
update();
}
void C2DDrawWidget::slotDrawEllipse()
{
EllipseFlag = !EllipseFlag;
update();
}
C2DDrawWindow::~C2DDrawWindow()
{
}