-
Notifications
You must be signed in to change notification settings - Fork 0
/
widget.cpp
235 lines (210 loc) · 6.72 KB
/
widget.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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
#include "widget.h"
#include "ui_widget.h"
#include"crossSection.h"
#include<QString>
#include<QMessageBox>
#include"chouxiang.h"
#include<QFile>
#include<QDebug>
shape operator+(shape shp1,shape shp2)
{
shape shp;
double s=shp1.area+shp2.area;
double cx=(shp1.xc*shp1.area+shp2.xc*shp2.area)/s;
double cy=(shp1.yc*shp1.area+shp2.yc*shp2.area)/s;
double Ixx=shp1.Ix+shp2.Ix;
double Iyy=shp1.Iy+shp2.Iy;
double Ixxy=shp1.Ixy+shp2.Ixy;
shp=shape(cx,cy,s,Ixx,Iyy,Ixxy);
return shp;
}
shape operator-(shape shp1,shape shp2)
{
shape shp;
double s=shp1.area-shp2.area;
double cx=(shp1.xc*shp1.area-shp2.xc*shp2.area)/s;
double cy=(shp1.yc*shp1.area-shp2.yc*shp2.area)/s;
double Ixx=shp1.Ix-shp2.Ix;
double Iyy=shp1.Iy-shp2.Iy;
double Ixxy=shp1.Ixy-shp2.Ixy;
shp=shape(cx,cy,s,Ixx,Iyy,Ixxy);
return shp;
}
Widget::Widget(QWidget *parent) :
QWidget(parent),
ui(new Ui::Widget)
{
ui->setupUi(this);
setGeometry(458,188,500,400);
paintArea=new MyPainterWidget(this);
QRect rec(0,0,800,800);
paintArea->setGeometry(125,0,250,400);
QString tempStr;
tempStr="重心X坐标:"+QString::number(shp1.xc);
ui->xcLabel->setText(tempStr);
tempStr="重心Y坐标:"+QString::number(shp1.yc);
ui->ycLabel->setText(tempStr);
tempStr="面积:"+QString::number(shp1.area);
ui->areaLabel->setText(tempStr);
tempStr="Ix:"+QString::number(shp1.Ix);
ui->ixLabel->setText(tempStr);
tempStr="Iy:"+QString::number(shp1.Iy);
ui->iyLabel->setText(tempStr);
tempStr="Ixy:"+QString::number(shp1.Ixy);
ui->ixyLabel->setText(tempStr);
tempStr="Ixc:"+QString::number(shp1.Ixc());
ui->ixcLabel->setText(tempStr);
tempStr="Iyc:"+QString::number(shp1.Iyc());
ui->iycLabel->setText(tempStr);
tempStr="Ixyc:"+QString::number(shp1.Ixyc());
ui->ixycLabel->setText(tempStr);
tempStr=QString((shp1.xSymmetry)?"关于X对称 ":"") + QString((shp1.ySymmetry)?"关于Y对称":"");
ui->symmLabel->setText(tempStr);
Qt::WindowFlags flags = 0;
flags |= Qt::WindowMinimizeButtonHint;
flags |= Qt::WindowCloseButtonHint;
flags |= Qt::MSWindowsFixedSizeDialogHint;
setWindowFlags (flags);
connect(ui->addButton,SIGNAL(clicked()),paintArea,SLOT(repaint()));
connect(ui->remButton,SIGNAL(clicked()),paintArea,SLOT(repaint()));
connect(ui->clButton,SIGNAL(clicked()),paintArea,SLOT(repaint()));
//connect(ui->clButton,SIGNAL(clicked()),paintArea,SLOT(clear()));
QString strPath = QCoreApplication::applicationDirPath();
qDebug()<<strPath;
QString strCssFile = strPath + "/qss/sectionCalc.qss";
QFile fCss(strCssFile);
if( !fCss.open(QFile::ReadOnly))
{
//qDebug("css File %s load false",strCssFile);
return;
}
QString strCssContent(fCss.readAll());
qApp->setStyleSheet(strCssContent);
fCss.close();
paintArea->setStyleSheet("background-color:gray");
}
Widget::~Widget()
{
delete ui;
}
void Widget::on_addButton_clicked()
{
double x,y,up,down;
QString valueStr=ui->xText->text();
x=valueStr.toDouble();
valueStr=ui->yText->text();
y=valueStr.toDouble();
valueStr=ui->upText->text();
up=valueStr.toDouble();
valueStr=ui->downText->text();
down=valueStr.toDouble();
switch (ui->comboBox->currentIndex()) {
case 0:
//shp1=addShp(shp1,rectangle(x,y,up,down));
shp1=shp1+rectangle(x,y,up,down);
paintArea->vecRec.push_back(rectangle(x,y,up,down));
break;
case 1:
//circle temp(x,y,ring);
//if(Intersect(temp,))
shp1=shp1+ring(x,y,up,0);
paintArea->vecRing.push_back(ring(x,y,up,0));
break;
case 2:
shp1=shp1+ring(x,y,up,down);
paintArea->vecRing.push_back(ring(x,y,up,down));
break;
default:
break;
}
showshp1();
}
void Widget::on_remButton_clicked()
{
double x,y,up,down;
QString valueStr=ui->xText->text();
x=valueStr.toDouble();
valueStr=ui->yText->text();
y=valueStr.toDouble();
valueStr=ui->upText->text();
up=valueStr.toDouble();
valueStr=ui->downText->text();
down=valueStr.toDouble();
int ret;
switch (ui->comboBox->currentIndex()) {
case 0:
shp1=shp1-rectangle(x,y,up,down);
paintArea->vecEraRec.push_back(rectangle(x,y,up,down));
break;
case 1:
shp1=shp1-circle(x,y,up);
paintArea->vecEraRing.push_back(circle(x,y,up));
break;
case 2:
ret=QMessageBox::information(this,"提示","不支持圆环逻辑",QMessageBox::Ok);
default:
break;
}
showshp1();
}
void Widget::on_comboBox_currentIndexChanged(int index)
{
switch (index)
{
case 0:
ui->upLabel->setText("宽度");
ui->downLabel->setVisible(true);
ui->downText->setVisible(true);
ui->downLabel->setText("高度");
break;
case 1:
ui->downLabel->setVisible(false);
ui->downText->setVisible(false);
ui->upLabel->setText("直径");
break;
case 2:
ui->upLabel->setText("外径");
ui->downLabel->setVisible(true);
ui->downText->setVisible(true);
ui->downLabel->setText("内径");
break;
}
}
void Widget::on_pushButton_clicked()
{
chouxiang *cx=new chouxiang(0);
cx->show();
}
void Widget::on_clButton_clicked()
{
paintArea->vecEraRec.clear();
paintArea->vecEraRing.clear();
paintArea->vecRec.clear();
paintArea->vecRing.clear();
shp1=shape(0,0,0,0,0,0);
paintArea->update();
showshp1();
}
void Widget::showshp1(){
QString valueStr;
valueStr="重心X坐标:"+QString::number(shp1.xc);
ui->xcLabel->setText(valueStr);
valueStr="重心Y坐标:"+QString::number(shp1.yc);
ui->ycLabel->setText(valueStr);
valueStr="面积:"+QString::number(shp1.area);
ui->areaLabel->setText(valueStr);
valueStr="Ix:"+QString::number(shp1.Ix);
ui->ixLabel->setText(valueStr);
valueStr="Iy:"+QString::number(shp1.Iy);
ui->iyLabel->setText(valueStr);
valueStr="Ixy:"+QString::number(shp1.Ixy);
ui->ixyLabel->setText(valueStr);
valueStr="Ixc:"+QString::number(shp1.Ixc());
ui->ixcLabel->setText(valueStr);
valueStr="Iyc:"+QString::number(shp1.Iyc());
ui->iycLabel->setText(valueStr);
valueStr="Ixyc:"+QString::number(shp1.Ixyc());
ui->ixycLabel->setText(valueStr);
valueStr=QString((shp1.xSymmetry)?"关于X对称 ":"") + QString((shp1.ySymmetry)?"关于Y对称":"");
ui->symmLabel->setText(valueStr);
}