-
Notifications
You must be signed in to change notification settings - Fork 0
/
mainwindow.cpp
251 lines (208 loc) · 7.69 KB
/
mainwindow.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
250
251
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QDebug>
#include "utils.h"
#include "my_style.h"
#include <iostream>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
this->setWindowTitle("UsefulToolbox");
timer = new QTimer(this);
timer->start(1000);
connect(timer, &QTimer::timeout, this, &MainWindow::showDateTime);
ui->stackedWidget->setCurrentWidget(ui->pageHome);
ui->pbHome->hide();
Log4Qt::PropertyConfigurator::configure("log.conf");
mylog1 = Log4Qt::Logger::logger("Mylog1");
mylog1->info("Welcome to UsefulToolbox!");
// mylog1->warn("log warn");
// mylog1->error("log error");
// mylog1->fatal("log fatal");
QPixmap image(":/icon-tool.png");
ui->lbImg->setPixmap(image);
ui->lbImg->setAlignment(Qt::AlignCenter);
ui->lbImg->setScaledContents(true);
ui->lbImg->setVisible(false);
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::on_pbDevice_clicked()
{
qDebug() << "pbDevice";
mylog1->info("pbDevice");
ui->stackedWidget->setCurrentWidget(ui->pageDevice);
ui->pbHome->show();
ui->tbOS->setText(getSysInfo());
}
void MainWindow::on_pbClock_clicked()
{
qDebug() << "pbClock";
ui->stackedWidget->setCurrentWidget(ui->pageClock);
ui->pbHome->show();
connect(timer, &QTimer::timeout, this, &MainWindow::showClock);
}
void MainWindow::on_pbMap_clicked()
{
qDebug() << "pbMap";
ui->stackedWidget->setCurrentWidget(ui->pageMap);
ui->pbHome->show();
QQuickWidget* mapQml = ui->quickWidget;
mapQml->rootContext()->setContextProperty("$color", "white");
QUrl source("qrc:/mapApp.qml");
mapQml->setSource(source);
QUrl source2("qrc:/helloApp.qml");
mapQml->setSource(source2);
mapQml->setResizeMode(QQuickWidget::SizeRootObjectToView);
// mapQml->resize(400, 600);
// QQuickItem* qmlItem = ui->quickWidget->rootObject();
// connect(qmlItem, SIGNAL(qmlClick()), this, SLOT(onQmlClick()));
// connect(this, SIGNAL(cppClick()), qmlItem, SLOT(onCppClick()));
}
void MainWindow::on_pbWeather_clicked()
{
qDebug() << "pbWeather";
ui->stackedWidget->setCurrentWidget(ui->pageWeather);
ui->pbHome->show();
ui->leWeatherCity->setPlaceholderText("输入城市名");
connect(ui->pbWeatherCity, &QPushButton::clicked, this, &MainWindow::showWeather);
ui->leLongitude->setPlaceholderText("输入经度");
connect(ui->pbUtm, &QPushButton::clicked, this, &MainWindow::showUtm);
}
void MainWindow::on_pbBmi_clicked()
{
qDebug() << "pbBmi";
ui->stackedWidget->setCurrentWidget(ui->pageBmi);
ui->pbHome->show();
ui->leHeight->setPlaceholderText("输入身高(cm)");
ui->leWeight->setPlaceholderText("输入体重(kg)");
connect(ui->pbBmiCal, &QPushButton::clicked, this, &MainWindow::showBmi);
QString tableHtml =
"<h3>身体质量指数参考表</h3>"
"<div style='text-align:center;'>"
"<table border='1' cellpadding='5'>"
"<tr><th>BMI 范围</th><th>体重描述</th></tr>"
"<tr><td>< 18.5</td><td>过轻</td></tr>"
"<tr><td>18.5 - 23.9</td><td>正常</td></tr>"
"<tr><td>24.0 - 27.9</td><td>偏胖</td></tr>"
"<tr><td>>= 28.0</td><td>肥胖</td></tr>"
"</table>";
ui->lbBmiRef->setText(tableHtml);
}
void MainWindow::on_pbCount_clicked()
{
qDebug() << "pbCount";
ui->stackedWidget->setCurrentWidget(ui->pageCount);
ui->pbHome->show();
connect(timer, &QTimer::timeout, this, &MainWindow::showCountDown);
}
void MainWindow::on_pbTimestamp_clicked()
{
qDebug() << "pbTimestamp";
ui->stackedWidget->setCurrentWidget(ui->pageTimestamp);
ui->pbHome->show();
ui->leTimestamp->setPlaceholderText("输入时间戳");
connect(timer, &QTimer::timeout, this, &MainWindow::showTimestamp);
connect(ui->pbTimeConvert, &QPushButton::clicked, this, &MainWindow::showConvertTimestamp);
}
void MainWindow::on_pbUuid_clicked()
{
qDebug() << "pbUuid";
ui->stackedWidget->setCurrentWidget(ui->pageUuid);
ui->pbHome->show();
ui->leUuidCount->setPlaceholderText("输入UUID数量");
connect(ui->pbUuidGen, &QPushButton::clicked, this, &MainWindow::showUuid);
}
void MainWindow::on_pbHome_clicked()
{
qDebug() << "pbHome";
ui->stackedWidget->setCurrentWidget(ui->pageHome);
ui->pbHome->hide();
}
void MainWindow::on_pbShare_clicked()
{
qDebug() << "pbShare";
QMessageBox msgBox;
msgBox.setWindowTitle("About me");
msgBox.setText("DevFrank实用工具箱PC端,复刻同名wx小程序\n\n"
"GitHub: https://github.com/frankwang98\n"
"CSDN: https://devfrank.blog.csdn.net/\n"
"Wx小程序: DevFrank实用工具箱");
msgBox.setIcon(QMessageBox::Information);
msgBox.exec();
}
/***************************************************************************/
void MainWindow::showDateTime()
{
QDateTime currentDateTime = QDateTime::currentDateTime();
QString dateTimeString = currentDateTime.toString("yyyy-MM-dd hh:mm:ss");
ui->lbClock->setText(dateTimeString);
}
void MainWindow::showClock()
{
QDateTime currentDateTime = QDateTime::currentDateTime();
QString dateTimeString2 = currentDateTime.toString("hh:mm:ss");
ui->lbClockInfo->setAlignment(Qt::AlignCenter);
ui->lbClockInfo->setText(dateTimeString2);
ui->lbClockInfo->setStyleSheet(clockStyle);
}
void MainWindow::showWeather()
{
QByteArray fileData = getJsonData("cityIds.json");
// qDebug() << "test: " << getAreaIdByCityName("xx", fileData);
ui->lbWeatherCity->setAlignment(Qt::AlignCenter);
ui->lbWeatherCity->setText(QString::number(getAreaIdByCityName(ui->leWeatherCity->text(), fileData)));
}
void MainWindow::showUtm()
{
double longitude = ui->leLongitude->text().toDouble();
ui->lbUtm->setText(QString::number(longitudeToZone(longitude)));
}
void MainWindow::showBmi()
{
double height = ui->leHeight->text().toDouble();
double weight = ui->leWeight->text().toDouble();
QString bmi = getBmiInfo(height, weight);
ui->lbBmiResult->setText(bmi);
}
void MainWindow::showCountDown()
{
QDateTime currentDateTime = QDateTime::currentDateTime();
// 设置New Year
QDateTime newYearDateTime(QDate(2025, 1, 1), QTime(0, 0, 0));
qint64 secondsLeft = currentDateTime.secsTo(newYearDateTime);
int daysLeft = secondsLeft / 86400;
int hoursLeft = (secondsLeft % 86400) / 3600;
int minutesLeft = (secondsLeft % 3600) / 60;
int secondsLeftFinal = secondsLeft % 60;
QString countdownText = QString("距离新年还有 %1天 \n %2小时 %3分钟 %4秒 \n 享受当下的时光!")
.arg(daysLeft)
.arg(hoursLeft, 2, 10, QChar('0'))
.arg(minutesLeft, 2, 10, QChar('0'))
.arg(secondsLeftFinal, 2, 10, QChar('0'));
ui->lbCountDown->setAlignment(Qt::AlignCenter);
ui->lbCountDown->setText(countdownText);
ui->lbCountDown->setStyleSheet(countStyle);
}
void MainWindow::showTimestamp()
{
QDateTime currentDateTime = QDateTime::currentDateTime();
QString timestampString = currentDateTime.toString("yyyy-MM-dd hh:mm:ss");
ui->lbTimestamp1->setText(timestampString);
qint64 timestamp = currentDateTime.toSecsSinceEpoch();
ui->lbTimestamp2->setText(QString::number(timestamp));
ui->lbTimestamp3->setText(currentDateTime.toUTC().toString());
}
void MainWindow::showConvertTimestamp()
{
qint64 timestamp = ui->leTimestamp->text().toLongLong();
ui->lbConvertResult->setText(convertTimestamp(timestamp));
}
void MainWindow::showUuid()
{
ui->tbUuid->setText(getUuidInfo(ui->leUuidCount->text().toInt()));
}