This repository has been archived by the owner on Aug 31, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwidget.cpp
250 lines (204 loc) · 6.78 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
236
237
238
239
240
241
242
243
244
245
246
247
248
249
#include "widget.h"
#include "donghao_alkane.h"
#include "ui_widget.h"
#include <QGraphicsDropShadowEffect>
#include <QMouseEvent>
#include <QSpinBox>
#include <QPainter>
#include <QImage>
#include <QDebug>
int t = 0;
int o[8][3][2][18];
double cNumber, hNumber;
Widget::Widget(QWidget *parent)
: QWidget(parent)
, ui(new Ui::Widget)
{
ui->setupUi(this);
//Remove border
this->setWindowFlags(Qt::FramelessWindowHint);
//Add Shadoweffect
QGraphicsDropShadowEffect *shadow = new QGraphicsDropShadowEffect();
shadow->setBlurRadius(10);
shadow->setColor(Qt::black);
shadow->setOffset(0);
ui->shadowWidget->setGraphicsEffect(shadow);
//Make the main windows translucent
this->setAttribute(Qt::WA_TranslucentBackground);
}
Widget::~Widget()
{
delete ui;
}
void Widget::mouseMoveEvent(QMouseEvent *event)
{
QWidget::mouseMoveEvent(event);
QPoint y = event->globalPos();//mouse position relative to the left up of the computer
QPoint x = y - this->z;
this->move(x);
}
void Widget::mousePressEvent(QMouseEvent *event)
{
QWidget::mousePressEvent(event);
QPoint y = event->globalPos();//mouse position relative to the left up of the computer
QPoint x = this->geometry().topLeft(); //The widget position relative to the left-up of the computer
this->z = y - x;
}
void Widget::mouseReleaseEvent(QMouseEvent *event)
{
QWidget::mouseReleaseEvent(event);
this->z = QPoint();
}
void Widget::on_btnClose_clicked()
{
this->close();
}
void Widget::on_btnMin_clicked()
{
this->showMinimized();
}
void Widget::on_btnMax_clicked()
{
if(this->isMaximized()) {
ui->vlMain->setMargin(9);
this->showNormal();
} else {
ui->vlMain->setMargin(0);
this->showMaximized();
}
}
void Widget::on_AlkaneBtn_clicked()
{
cNumber = ui->cNumberSpinBox->value();
hNumber = ui->hNumberSpinBox->value();
if((cNumber*2+2) == hNumber && 0<cNumber && cNumber <= 8)
{
molarMass = 12.011*cNumber + 1.008*hNumber;
ui->molarMassDoubleSpinBox->setNum(molarMass);
double cAtomPer, hAtomPer, cMassPer, hMassPer;
cAtomPer = cNumber/(cNumber+hNumber);
hAtomPer = hNumber/(cNumber+hNumber);
cMassPer = 12.011*cNumber/(12.011*cNumber+1.008*hNumber);
hMassPer = 1.008*hNumber/(12.011*cNumber+1.008*hNumber);
ui->cAtomPerDoubleSpinBox->setValue(cAtomPer);
ui->hAtomPerDoubleSpinBox->setValue(hAtomPer);
ui->cMassPerDoubleSpinBox->setValue(cMassPer);
ui->hMassPerDoubleSpinBox->setValue(hMassPer);
//DongHao
t = 0;
Wanting(cNumber,hNumber);
qDebug()<<"t: "<<t<<endl;
//MessageBox
ui->messageBox->setText("Success!");
//Pop Image
new_image = new image;
new_image->show();
}
else {
ui->messageBox->setText("Input wrong, type again");
}
}
void Widget::on_OlefinBtn_clicked()
{
cNumber = ui->cNumberSpinBox->value();
hNumber = ui->hNumberSpinBox->value();
if(cNumber*2 == hNumber && cNumber >= 2 && cNumber <= 6)
{
ui->messageBox->setText("Success!");
molarMass = 12.011*cNumber + 1.008*hNumber;
ui->molarMassDoubleSpinBox->setNum(molarMass);
double cAtomPer, hAtomPer, cMassPer, hMassPer;
cAtomPer = cNumber/(cNumber+hNumber);
hAtomPer = hNumber/(cNumber+hNumber);
cMassPer = 12.011*cNumber/(12.011*cNumber+1.008*hNumber);
hMassPer = 1.008*hNumber/(12.011*cNumber+1.008*hNumber);
ui->cAtomPerDoubleSpinBox->setValue(cAtomPer);
ui->hAtomPerDoubleSpinBox->setValue(hAtomPer);
ui->cMassPerDoubleSpinBox->setValue(cMassPer);
ui->hMassPerDoubleSpinBox->setValue(hMassPer);
//Pop Image
new_olefin_image = new Olefin_image;
new_olefin_image->show();
}
else {
ui->messageBox->setText("Input wrong, type again");
}
}
void Widget::on_CyclaneBtn_clicked()
{
cNumber = ui->cNumberSpinBox->value();
hNumber = ui->hNumberSpinBox->value();
molarMass = 12.011*cNumber + 1.008*hNumber;
ui->molarMassDoubleSpinBox->setNum(molarMass);
double cAtomPer, hAtomPer, cMassPer, hMassPer;
cAtomPer = cNumber/(cNumber+hNumber);
hAtomPer = hNumber/(cNumber+hNumber);
cMassPer = 12.011*cNumber/(12.011*cNumber+1.008*hNumber);
hMassPer = 1.008*hNumber/(12.011*cNumber+1.008*hNumber);
if(hNumber == 2*cNumber && cNumber <= 6 && cNumber >= 3)
{
ui->messageBox->setText("Success!");
ui->cAtomPerDoubleSpinBox->setValue(cAtomPer);
ui->hAtomPerDoubleSpinBox->setValue(hAtomPer);
ui->cMassPerDoubleSpinBox->setValue(cMassPer);
ui->hMassPerDoubleSpinBox->setValue(hMassPer);
new_cyclane_image = new CyclaneImage;
new_cyclane_image->show();
}
//MessageBox
else {
ui->messageBox->setText("Input wrong, type again");
}
}
void Widget::on_AreneBtn_clicked()
{
cNumber = ui->cNumberSpinBox->value();
hNumber = ui->hNumberSpinBox->value();
molarMass = 12.011*cNumber + 1.008*hNumber;
ui->molarMassDoubleSpinBox->setNum(molarMass);
double cAtomPer, hAtomPer, cMassPer, hMassPer;
cAtomPer = cNumber/(cNumber+hNumber);
hAtomPer = hNumber/(cNumber+hNumber);
cMassPer = 12.011*cNumber/(12.011*cNumber+1.008*hNumber);
hMassPer = 1.008*hNumber/(12.011*cNumber+1.008*hNumber);
ui->cAtomPerDoubleSpinBox->setValue(cAtomPer);
ui->hAtomPerDoubleSpinBox->setValue(hAtomPer);
ui->cMassPerDoubleSpinBox->setValue(cMassPer);
ui->hMassPerDoubleSpinBox->setValue(hMassPer);
if((cNumber*2 - 6) == hNumber && cNumber >= 6 && cNumber <= 9)
{
ui->messageBox->setText("Success!");
new_arene_image = new AreneImage;
new_arene_image->show();
}
//MessageBox
else {
ui->messageBox->setText("Input wrong, type again");
}
}
void Widget::on_pushButton_clicked()
{
cNumber = ui->cNumberSpinBox->value();
hNumber = ui->hNumberSpinBox->value();
molarMass = 12.011*cNumber + 1.008*hNumber;
ui->molarMassDoubleSpinBox->setNum(molarMass);
double cAtomPer, hAtomPer, cMassPer, hMassPer;
cAtomPer = cNumber/(cNumber+hNumber);
hAtomPer = hNumber/(cNumber+hNumber);
cMassPer = 12.011*cNumber/(12.011*cNumber+1.008*hNumber);
hMassPer = 1.008*hNumber/(12.011*cNumber+1.008*hNumber);
ui->cAtomPerDoubleSpinBox->setValue(cAtomPer);
ui->hAtomPerDoubleSpinBox->setValue(hAtomPer);
ui->cMassPerDoubleSpinBox->setValue(cMassPer);
ui->hMassPerDoubleSpinBox->setValue(hMassPer);
if((cNumber*2 - 2) == hNumber && cNumber >= 2 && cNumber <= 7)
{
ui->messageBox->setText("Success!");
new_alkyen_image = new alkyen;
new_alkyen_image->show();
}
//MessageBox
else {
ui->messageBox->setText("Input wrong, type again");
}
}