Skip to content

Commit 4795173

Browse files
committed
Add .cache/ to .gitignore and update aboutscreen.h, sysinfo.h, titlescreen.h, mainwindow.h, sysinfo.cpp, and main.cpp
1 parent 2c3f8a1 commit 4795173

10 files changed

+184
-88
lines changed

.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -73,4 +73,5 @@ CMakeLists.txt.user*
7373
*.exe
7474

7575
build/
76-
.vscode/
76+
.vscode/
77+
.cache/

aboutscreen.cpp

+22-14
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ AboutScreen::AboutScreen(QWidget *parent)
1818

1919
AboutScreen::~AboutScreen()
2020
{
21+
disconnect(ui->pushButton_1, &QPushButton::clicked, this, &AboutScreen::showMoreInfo);
22+
disconnect(ui->pushButton_2, &QPushButton::clicked, this, &AboutScreen::backToTitleScreen);
23+
disconnect(ui->pushButton_1, &QPushButton::clicked, this, &AboutScreen::playClickSound);
24+
disconnect(ui->pushButton_2, &QPushButton::clicked, this, &AboutScreen::playClickSound);
2125
delete ui;
2226
}
2327

@@ -31,6 +35,11 @@ void AboutScreen::initUI() {
3135
}
3236
this->resize(screenSize);
3337
ui->frame->resize(screenSize);
38+
ui->layoutWidget->setGeometry(screenSize.width() * 0.25, screenSize.height() * 0.2,
39+
screenSize.width() * 0.5, screenSize.height() * 0.5);
40+
ui->label->resize(screenSize.width() * 0.3, screenSize.height() * 0.1);
41+
ui->label_2->resize(screenSize.width() * 0.3, screenSize.height() * 0.3);
42+
3443
QSize btnSize(screenSize.width() / 5, screenSize.height() / 25);
3544
// 设置圆角
3645
int radius = btnSize.height() / 2;
@@ -40,20 +49,15 @@ void AboutScreen::initUI() {
4049
QString fontName = QFontDatabase::applicationFontFamilies(fontID).at(0);
4150
QFont btnFont(fontName, btnSize.height() / 3);
4251
// 设置按钮样式
43-
QString btnName = "pushButton_";
44-
for (int i = 0; i < 2; i++) {
45-
QString btn = btnName + QString::number(i + 1);
46-
QPushButton *btnPtr = this->findChild<QPushButton *>(btn);
47-
btnPtr->setFixedSize(btnSize);
48-
btnPtr->setFont(btnFont);
49-
btnPtr->setStyleSheet(btnStyle);
50-
connect(btnPtr, &QPushButton::clicked, this,
51-
[this]() { QSound::play(":/res/click.wav"); });
52-
}
53-
ui->layoutWidget->setGeometry(screenSize.width() * 0.25, screenSize.height() * 0.2,
54-
screenSize.width() * 0.5, screenSize.height() * 0.5);
55-
ui->label->resize(screenSize.width() * 0.3, screenSize.height() * 0.1);
56-
ui->label_2->resize(screenSize.width() * 0.3, screenSize.height() * 0.3);
52+
ui->pushButton_1->setFixedSize(btnSize);
53+
ui->pushButton_1->setFont(btnFont);
54+
ui->pushButton_1->setStyleSheet(btnStyle);
55+
connect(ui->pushButton_1, &QPushButton::clicked, this, &AboutScreen::playClickSound);
56+
ui->pushButton_2->setFixedSize(btnSize);
57+
ui->pushButton_2->setFont(btnFont);
58+
ui->pushButton_2->setStyleSheet(btnStyle);
59+
connect(ui->pushButton_2, &QPushButton::clicked, this, &AboutScreen::playClickSound);
60+
5761
ui->label->setFont(QFont(fontName, btnSize.height()));
5862
ui->label_2->setFont(QFont(fontName, btnSize.height() / 3));
5963
ui->label_3->setFont(QFont(fontName, btnSize.height() / 3));
@@ -77,4 +81,8 @@ void AboutScreen::showMoreInfo() {
7781
"作者b站主页</a>");
7882
ui->label_3->show();
7983
ui->pushButton_1->hide();
84+
}
85+
86+
void AboutScreen::playClickSound() {
87+
QSound::play(":/res/click.wav");
8088
}

aboutscreen.h

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ class AboutScreen : public QWidget
2121
void initUI();
2222
void backToTitleScreen();
2323
void showMoreInfo();
24+
void playClickSound();
2425
};
2526

2627
#endif // ABOUTSCREEN_H

main.cpp

+30-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,35 @@
1+
#include <QApplication>
2+
#include <QDebug>
3+
#include <QObject>
4+
#include <cstddef>
5+
16
#include "mainwindow.h"
7+
struct MemoryManager {
8+
size_t totalAllocated = 0;
9+
size_t totalFreed = 0;
10+
} memoryManager;
211

3-
#include <QApplication>
4-
int main(int argc, char *argv[])
5-
{
12+
void* operator new(size_t size) {
13+
void* p = malloc(size);
14+
memoryManager.totalAllocated += size;
15+
qDebug() << "allocated at " << p;
16+
qDebug() << "total allocated " << memoryManager.totalAllocated << " bytes. Using "
17+
<< memoryManager.totalAllocated - memoryManager.totalFreed
18+
<< " bytes";
19+
// qDebug() << "Allocated " << size << " bytes";
20+
return p;
21+
}
22+
23+
void operator delete(void* p, size_t size) noexcept {
24+
free(p);
25+
qDebug() << "Freed at " << p;
26+
memoryManager.totalFreed += size;
27+
qDebug() << "total freed " << memoryManager.totalFreed << " bytes. Using "
28+
<< memoryManager.totalAllocated - memoryManager.totalFreed
29+
<< " bytes";
30+
}
31+
32+
int main(int argc, char* argv[]) {
633
QApplication a(argc, argv);
734
MainWindow w;
835
w.show();

mainwindow.cpp

+40-30
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ MainWindow::MainWindow(QWidget *parent)
2424
ui(new Ui::MainWindow),
2525
m_timer(new QTimer(this)),
2626
m_sysinfo(new SYSinfo()),
27-
m_bootScreen(nullptr),
27+
// m_bootScreen(nullptr),
2828
m_effect(nullptr),
2929
m_animation(nullptr),
3030
m_label(nullptr),
@@ -102,49 +102,59 @@ void MainWindow::codePrintUpdate() {
102102
}
103103

104104
void MainWindow::loadBootScreen() {
105+
disconnect(this, &MainWindow::bootCompleted, this, &MainWindow::loadBootScreen);
105106
ui->textEdit->hide();
106107
// 设置启动画面
107108
m_label = new QLabel(this);
108-
m_bootScreen = new QPixmap(":/res/bootScreen.png");
109-
m_bootScreen->scaled(this->size(), Qt::KeepAspectRatio,
110-
Qt::SmoothTransformation);
111-
m_label->setPixmap(*m_bootScreen);
109+
// m_bootScreen = new QPixmap(":/res/bootScreen.png");
110+
// m_bootScreen->scaled(this->size(), Qt::KeepAspectRatio,
111+
// Qt::SmoothTransformation);
112+
// m_label->setPixmap(*m_bootScreen);
113+
QPixmap bootScreen(":/res/bootScreen.png");
114+
bootScreen = bootScreen.scaled(this->size(), Qt::KeepAspectRatio,
115+
Qt::SmoothTransformation);
116+
m_label->setPixmap(bootScreen);
112117
m_label->setScaledContents(true);
113118
m_label->resize(this->size());
114119
m_label->show();
115120

116121
// 淡入图片动画
117-
m_effect = new QGraphicsOpacityEffect(this);
118-
m_label->setGraphicsEffect(m_effect);
119-
m_animation = new QPropertyAnimation(m_effect, "opacity");
120-
m_animation->setDuration(3000);
121-
m_animation->setStartValue(0);
122-
m_animation->setEndValue(1);
123-
m_animation->start();
122+
fadeIn();
124123

125124
// 淡出图片动画
126-
QTimer::singleShot(5000, this, [this]() {
127-
connect(m_animation, &QPropertyAnimation::finished, this, [this]() {
128-
delete m_animation;
129-
delete m_effect;
130-
delete m_label;
131-
delete m_bootScreen;
132-
m_animation = nullptr;
133-
m_effect = nullptr;
134-
m_label = nullptr;
135-
m_bootScreen = nullptr;
136-
// 动画结束后加载标题界面
137-
loadTitleScreen();
138-
});
139-
m_animation->setDuration(3000);
140-
m_animation->setStartValue(1);
141-
m_animation->setEndValue(0);
142-
m_animation->start();
143-
});
125+
QTimer::singleShot(5000, this, &MainWindow::fadeOut);
144126
}
145127

146128
void MainWindow::loadTitleScreen() {
129+
disconnect(m_animation, &QPropertyAnimation::finished, this, &MainWindow::loadTitleScreen);
130+
delete m_animation;
131+
delete m_effect;
132+
delete m_label;
133+
// delete m_bootScreen;
134+
m_animation = nullptr;
135+
m_effect = nullptr;
136+
m_label = nullptr;
137+
// m_bootScreen = nullptr;
147138
m_titlescreen = new TitleScreen(this);
148139
m_titlescreen->show();
149140
this->centralWidget()->hide();
150141
}
142+
143+
void MainWindow::fadeOut() {
144+
connect(m_animation, &QPropertyAnimation::finished, this,
145+
&MainWindow::loadTitleScreen);
146+
m_animation->setDuration(3000);
147+
m_animation->setStartValue(1);
148+
m_animation->setEndValue(0);
149+
m_animation->start();
150+
}
151+
152+
void MainWindow::fadeIn() {
153+
m_effect = new QGraphicsOpacityEffect(this);
154+
m_label->setGraphicsEffect(m_effect);
155+
m_animation = new QPropertyAnimation(m_effect, "opacity");
156+
m_animation->setDuration(3000);
157+
m_animation->setStartValue(0);
158+
m_animation->setEndValue(1);
159+
m_animation->start();
160+
}

mainwindow.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class MainWindow : public QMainWindow {
2929
Ui::MainWindow* ui;
3030
QTimer* m_timer = nullptr;
3131
SYSinfo* m_sysinfo = nullptr;
32-
QPixmap* m_bootScreen = nullptr;
32+
// QPixmap* m_bootScreen = nullptr;
3333
QGraphicsOpacityEffect* m_effect = nullptr;
3434
QPropertyAnimation* m_animation = nullptr;
3535
QLabel* m_label = nullptr;
@@ -40,6 +40,8 @@ class MainWindow : public QMainWindow {
4040
void codePrintUpdate();
4141
void loadBootScreen();
4242
void loadTitleScreen();
43+
void fadeOut();
44+
void fadeIn();
4345
signals:
4446
void bootCompleted();
4547
// void animationFinished();

sysinfo.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ SYSinfo::SYSinfo() {
6262

6363
// CPU cores
6464
int nCores = 0;
65-
getCPUInfo(nCores);
65+
getCPUCore(nCores);
6666
m_data[2] += ": " + std::to_string(nCores);
6767

6868
// CPU threads
@@ -95,7 +95,7 @@ SYSinfo::SYSinfo() {
9595
" GB";
9696
}
9797

98-
void SYSinfo::getCPUInfo(int& cpu_cores) {
98+
void SYSinfo::getCPUCore(int& cpu_cores) {
9999
DWORD bufferSize = 0;
100100
GetLogicalProcessorInformation(nullptr, &bufferSize);
101101
std::vector<SYSTEM_LOGICAL_PROCESSOR_INFORMATION> buffer(bufferSize / sizeof(SYSTEM_LOGICAL_PROCESSOR_INFORMATION));

sysinfo.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ struct SYSinfo {
99
"CPU_THREADS", "MEMORY", "DISK", "// COMPLETE."};
1010

1111
SYSinfo();
12-
void getCPUInfo(int& cpu_cores);
12+
void getCPUCore(int& cpu_cores);
1313
void getCPUname(std::string& cpuName);
1414
};
1515
#endif // SYSINFO_H

0 commit comments

Comments
 (0)