Skip to content

Commit fcd131c

Browse files
authored
Merge pull request #85 from JunWang666/ui_splashscreen
[优化] 启动界面:重构 nativeSplash 类,新增渐变动画与进度条,调整布局与样式提升视觉体验
2 parents 7bdf30c + bb9cfa4 commit fcd131c

4 files changed

Lines changed: 132 additions & 89 deletions

File tree

main.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ int main(int argc, char *argv[]) {
3838

3939
qInstallMessageHandler(service::customMessageHandler); //拦截部分错误,真的修不好了喵眼不见心不烦
4040

41-
//view::SplashScreen::SplashScreen splash;
42-
//splash.show();
41+
view::SplashScreen::nativeSplash splash;
42+
splash.show();
4343

4444

4545
service::logger::instance().setLogFile(
@@ -64,10 +64,11 @@ int main(int argc, char *argv[]) {
6464

6565
view::login::loginPage b;
6666
b.show();
67-
//splash.close();
6867

6968
setup_tasks();
7069
service::taskManager::getTimer().startAll();
7170

71+
splash.closeSplash();
72+
7273
return QApplication::exec();
7374
}

view/SplashScreen/nativesplash.cpp

Lines changed: 45 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,52 @@
55
// You may need to build the project (run Qt uic code generator) to get "ui_nativeSplash.h" resolved
66

77
#include "nativesplash.h"
8+
#include <QGraphicsOpacityEffect>
9+
#include <QPropertyAnimation>
10+
811
#include "ui_nativeSplash.h"
912

1013
namespace view::SplashScreen {
11-
nativeSplash::nativeSplash(QWidget *parent) :
12-
QWidget(parent), ui(new Ui::nativeSplash) {
13-
ui->setupUi(this);
14-
service::style::setMica(this);
15-
}
16-
17-
nativeSplash::~nativeSplash() {
18-
delete ui;
19-
}
14+
nativeSplash::nativeSplash(QWidget *parent) : QWidget(parent), ui(new Ui::nativeSplash) {
15+
ui->setupUi(this);
16+
service::style::setMica(this);
17+
setWindowFlags(Qt::FramelessWindowHint | Qt::Tool | Qt::WindowStaysOnTopHint);
18+
19+
QGraphicsOpacityEffect *effect = new QGraphicsOpacityEffect(this);
20+
this->setGraphicsEffect(effect);
21+
22+
QPropertyAnimation *anim = new QPropertyAnimation(effect, "opacity");
23+
anim->setDuration(800);
24+
anim->setStartValue(0);
25+
anim->setEndValue(1);
26+
anim->setEasingCurve(QEasingCurve::OutQuad);
27+
anim->start(QPropertyAnimation::DeleteWhenStopped);
28+
29+
ui->progressBar->setMaximum(0);
30+
ui->progressBar->setMinimum(0);
31+
32+
play_animation();
33+
}
34+
35+
nativeSplash::~nativeSplash() {
36+
delete ui;
37+
}
38+
39+
void nativeSplash::closeSplash() {
40+
QGraphicsOpacityEffect *effect = new QGraphicsOpacityEffect(this);
41+
this->setGraphicsEffect(effect);
42+
43+
44+
QPropertyAnimation *anim = new QPropertyAnimation(effect, "opacity");
45+
anim->setDuration(400);
46+
anim->setStartValue(1);
47+
anim->setEndValue(0);
48+
anim->setEasingCurve(QEasingCurve::InQuad);
49+
anim->start(QPropertyAnimation::DeleteWhenStopped);
50+
connect(anim, &QPropertyAnimation::finished, this, &nativeSplash::close);
51+
}
52+
53+
void nativeSplash::play_animation() {
54+
55+
}
2056
} // view::SplashScreen

view/SplashScreen/nativesplash.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,11 @@ Q_OBJECT
1818
public:
1919
explicit nativeSplash(QWidget *parent = nullptr);
2020
~nativeSplash() override;
21+
void closeSplash();
2122

2223
private:
2324
Ui::nativeSplash *ui;
25+
void play_animation();
2426
};
2527
} // view::SplashScreen
2628

view/SplashScreen/nativesplash.ui

Lines changed: 81 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -6,92 +6,96 @@
66
<rect>
77
<x>0</x>
88
<y>0</y>
9-
<width>662</width>
10-
<height>449</height>
9+
<width>611</width>
10+
<height>419</height>
1111
</rect>
1212
</property>
1313
<property name="windowTitle">
1414
<string>nativeSplash</string>
1515
</property>
16-
<layout class="QVBoxLayout" name="verticalLayout">
17-
<item>
18-
<widget class="QFrame" name="frame">
19-
<property name="minimumSize">
20-
<size>
21-
<width>600</width>
22-
<height>400</height>
23-
</size>
24-
</property>
25-
<property name="maximumSize">
26-
<size>
27-
<width>600</width>
28-
<height>400</height>
29-
</size>
30-
</property>
31-
<property name="styleSheet">
32-
<string notr="true">QFrame {
33-
background-color: transparent;
34-
border: none;
35-
}
36-
</string>
37-
</property>
38-
<property name="frameShape">
39-
<enum>QFrame::Shape::StyledPanel</enum>
40-
</property>
41-
<property name="frameShadow">
42-
<enum>QFrame::Shadow::Raised</enum>
43-
</property>
44-
<widget class="QLabel" name="label">
45-
<property name="geometry">
46-
<rect>
47-
<x>10</x>
48-
<y>-50</y>
49-
<width>221</width>
50-
<height>221</height>
51-
</rect>
52-
</property>
53-
<property name="sizePolicy">
54-
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
55-
<horstretch>1</horstretch>
56-
<verstretch>1</verstretch>
57-
</sizepolicy>
58-
</property>
59-
<property name="text">
60-
<string/>
61-
</property>
62-
<property name="pixmap">
63-
<pixmap resource="../../assets/Logo/LogoResource.qrc">:/Logo1.png</pixmap>
64-
</property>
65-
<property name="scaledContents">
66-
<bool>true</bool>
67-
</property>
68-
</widget>
69-
<widget class="QLabel" name="label_2">
70-
<property name="geometry">
71-
<rect>
72-
<x>230</x>
73-
<y>0</y>
74-
<width>501</width>
75-
<height>401</height>
76-
</rect>
77-
</property>
78-
<property name="styleSheet">
79-
<string notr="true">QLabel {
16+
<property name="styleSheet">
17+
<string notr="true"/>
18+
</property>
19+
<widget class="QLabel" name="label">
20+
<property name="geometry">
21+
<rect>
22+
<x>0</x>
23+
<y>-60</y>
24+
<width>221</width>
25+
<height>221</height>
26+
</rect>
27+
</property>
28+
<property name="sizePolicy">
29+
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
30+
<horstretch>1</horstretch>
31+
<verstretch>1</verstretch>
32+
</sizepolicy>
33+
</property>
34+
<property name="text">
35+
<string/>
36+
</property>
37+
<property name="pixmap">
38+
<pixmap resource="../../assets/Logo/LogoResource.qrc">:/Logo1.png</pixmap>
39+
</property>
40+
<property name="scaledContents">
41+
<bool>true</bool>
42+
</property>
43+
</widget>
44+
<widget class="QLabel" name="label_2">
45+
<property name="geometry">
46+
<rect>
47+
<x>200</x>
48+
<y>0</y>
49+
<width>551</width>
50+
<height>431</height>
51+
</rect>
52+
</property>
53+
<property name="styleSheet">
54+
<string notr="true">QLabel {
8055
border-radius: 20px;
8156
background-clip: content-box;
8257
}
8358
</string>
84-
</property>
85-
<property name="text">
86-
<string/>
87-
</property>
88-
<property name="pixmap">
89-
<pixmap resource="../../assets/LandScapes/LandScape.qrc">:/landscape/BB1msMpB.jpg</pixmap>
90-
</property>
91-
</widget>
92-
</widget>
93-
</item>
94-
</layout>
59+
</property>
60+
<property name="text">
61+
<string/>
62+
</property>
63+
<property name="pixmap">
64+
<pixmap resource="../../assets/LandScapes/LandScape.qrc">:/landscape/BB1msMpB.jpg</pixmap>
65+
</property>
66+
</widget>
67+
<widget class="QProgressBar" name="progressBar">
68+
<property name="geometry">
69+
<rect>
70+
<x>10</x>
71+
<y>370</y>
72+
<width>171</width>
73+
<height>41</height>
74+
</rect>
75+
</property>
76+
<property name="styleSheet">
77+
<string notr="true"/>
78+
</property>
79+
<property name="value">
80+
<number>24</number>
81+
</property>
82+
<property name="textVisible">
83+
<bool>false</bool>
84+
</property>
85+
</widget>
86+
<widget class="QLabel" name="label_3">
87+
<property name="geometry">
88+
<rect>
89+
<x>10</x>
90+
<y>360</y>
91+
<width>151</width>
92+
<height>21</height>
93+
</rect>
94+
</property>
95+
<property name="text">
96+
<string>Loading resources...</string>
97+
</property>
98+
</widget>
9599
</widget>
96100
<resources>
97101
<include location="../../assets/Logo/LogoResource.qrc"/>

0 commit comments

Comments
 (0)