Skip to content
This repository was archived by the owner on Jul 19, 2025. It is now read-only.

Commit 53986b1

Browse files
committed
chore(code): unify style
1 parent 43e1610 commit 53986b1

5 files changed

Lines changed: 177 additions & 76 deletions

File tree

48.1 KB
Binary file not shown.

mainwindow.cpp

Lines changed: 79 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -102,86 +102,24 @@ void MainWindow::setupConnections() noexcept {
102102

103103
connect(ui->music_list, &QTableView::clicked, this, &MainWindow::onPlaylistClicked);
104104

105-
connect(ui->play_mode, &QPushButton::clicked, this, [this](){
106-
switch(playlistModel.playMode) {
107-
case PlaylistModel::Ordered:
108-
playlistModel.playMode = PlaylistModel::Looped;
109-
ui->play_mode->setIcon(QIcon(":/assets/material-symbols--repeat-one-rounded.png"));
110-
ui->play_mode->setToolTip("单曲循环");
111-
break;
112-
case PlaylistModel::Looped: {
113-
playlistModel.playMode = PlaylistModel::Shuffled;
114-
ui->play_mode->setIcon(QIcon(":/assets/material-symbols--shuffle-rounded.png"));
115-
ui->play_mode->setToolTip("随机播放");
116-
playlistModel.shuffle();
117-
shuffleIndex = 0;
118-
break;
119-
}
120-
case PlaylistModel::Shuffled:
121-
playlistModel.playMode = PlaylistModel::Ordered;
122-
ui->play_mode->setIcon(QIcon(":/assets/material-symbols--playlist-play-rounded.png"));
123-
ui->play_mode->setToolTip("列表顺序播放");
124-
break;
125-
}
126-
});
105+
connect(ui->play_mode, &QPushButton::clicked, this, &MainWindow::playModeClicked);
127106

128-
connect(&player, &QMediaPlayer::durationChanged, this, [this](qint64 d){
129-
ui->music_progress->setRange(0, int(d));
130-
updateDurationDisplay();
131-
});
132-
133-
connect(&player, &QMediaPlayer::positionChanged, this, [this](qint64 p){
134-
ui->music_progress->setValue(int(p));
135-
ui->current_duration->setText(formatTime(p));
136-
});
137-
138-
connect(&player, &QMediaPlayer::mediaStatusChanged, this, [this](QMediaPlayer::MediaStatus status){
139-
if (status == QMediaPlayer::EndOfMedia) nextTrack();
140-
});
141-
142-
connect(&player, &QMediaPlayer::playbackStateChanged, this, [this](QMediaPlayer::PlaybackState state){
143-
updatePlaybackButtons();
144-
});
107+
connect(&player, &QMediaPlayer::durationChanged, this, &MainWindow::playerDurationChanged);
108+
connect(&player, &QMediaPlayer::positionChanged, this, &MainWindow::playerPositionChanged);
109+
connect(&player, &QMediaPlayer::mediaStatusChanged, this, &MainWindow::playerMediaStatusChanged);
110+
connect(&player, &QMediaPlayer::playbackStateChanged, this, &MainWindow::updatePlaybackButtons);
145111

146112
connect(ui->music_progress, &QSlider::sliderMoved, &player, &QMediaPlayer::setPosition);
113+
connect(ui->music_progress, &QSlider::sliderPressed, this, &MainWindow::musicProgressPressed);
114+
connect(ui->music_progress, &QSlider::sliderReleased, this, &MainWindow::musicProgressReleased);
115+
connect(ui->music_progress, &QSlider::valueChanged, this, &MainWindow::musicProgressValueChanged);
147116

148-
connect(ui->music_progress, &QSlider::sliderPressed, this, [this](){
149-
disconnect(&player, &QMediaPlayer::positionChanged, this, nullptr);
150-
});
151-
152-
connect(ui->music_progress, &QSlider::sliderReleased, this, [this](){
153-
player.setPosition(ui->music_progress->value());
154-
connect(&player, &QMediaPlayer::positionChanged, this, [this](qint64 p){
155-
ui->music_progress->setValue(int(p));
156-
ui->current_duration->setText(formatTime(p));
157-
});
158-
});
159-
connect(ui->music_progress, &QSlider::valueChanged, this, [this](int value){
160-
ui->current_duration->setText(formatTime(value));
161-
});
162-
163-
connect(ui->volume, &QSlider::valueChanged, this, [this](int v){
164-
if(v > 0 && muted) {
165-
muted = false;
166-
ui->mute->setIcon(QIcon(":/assets/material-symbols--volume-up-rounded.png"));
167-
ui->mute->setToolTip("静音");
168-
}
169-
else if(v == 0 && !muted) {
170-
muted = true;
171-
ui->mute->setIcon(QIcon(":/assets/material-symbols--volume-off-rounded.png"));
172-
ui->mute->setToolTip("取消静音");
173-
}
174-
audio.setVolume(v / 100.0f);
175-
});
117+
connect(ui->volume, &QSlider::valueChanged, this, &MainWindow::volumeChanged);
176118

177119
connect(ui->mute, &QPushButton::clicked, this, &MainWindow::toggleMuted);
178120

179-
connect(&playlistModel, &QAbstractItemModel::rowsInserted, this, [this](){
180-
updatePlaybackButtons();
181-
});
182-
connect(&playlistModel, &QAbstractItemModel::rowsRemoved, this, [this](){
183-
updatePlaybackButtons();
184-
});
121+
connect(&playlistModel, &QAbstractItemModel::rowsInserted, this, &MainWindow::updatePlaybackButtons);
122+
connect(&playlistModel, &QAbstractItemModel::rowsRemoved, this, &MainWindow::updatePlaybackButtons);
185123
}
186124

187125
void MainWindow::openFile() noexcept {
@@ -377,9 +315,7 @@ QString MainWindow::formatTime(qint64 milliseconds) const noexcept {
377315
}
378316

379317
void MainWindow::showAbout() noexcept{
380-
QMessageBox::about(this, "Whatever 播放器",
381-
"<div style='text-align: center'><h1>做点啥呢?Whatever.</h1><h2>2025 编程实训项目</h2><h2>组员:林峻茗、张峻鸣、易治行</h2></div><div><a href='https://github.com/25programmingpractice/whatever'>https://github.com/25programmingpractice/whatever</a></div>"
382-
);
318+
QMessageBox::about(this, "Whatever 播放器", "<div style='text-align: center'><h1>做点啥呢?Whatever.</h1><h2>2025 编程实训项目</h2><h2>组员:林峻茗、张峻鸣、易治行</h2></div><div><a href='https://github.com/25programmingpractice/whatever'>https://github.com/25programmingpractice/whatever</a></div>");
383319
}
384320

385321
void MainWindow::updatePlaybackButtons() noexcept {
@@ -475,6 +411,73 @@ void MainWindow::dropEvent(QDropEvent* ev) noexcept {
475411
ev->acceptProposedAction();
476412
}
477413

414+
void MainWindow::playModeClicked() noexcept {
415+
switch(playlistModel.playMode) {
416+
case PlaylistModel::Ordered:
417+
playlistModel.playMode = PlaylistModel::Looped;
418+
ui->play_mode->setIcon(QIcon(":/assets/material-symbols--repeat-one-rounded.png"));
419+
ui->play_mode->setToolTip("单曲循环");
420+
break;
421+
case PlaylistModel::Looped: {
422+
playlistModel.playMode = PlaylistModel::Shuffled;
423+
ui->play_mode->setIcon(QIcon(":/assets/material-symbols--shuffle-rounded.png"));
424+
ui->play_mode->setToolTip("随机播放");
425+
playlistModel.shuffle();
426+
shuffleIndex = 0;
427+
break;
428+
}
429+
case PlaylistModel::Shuffled:
430+
playlistModel.playMode = PlaylistModel::Ordered;
431+
ui->play_mode->setIcon(QIcon(":/assets/material-symbols--playlist-play-rounded.png"));
432+
ui->play_mode->setToolTip("列表顺序播放");
433+
break;
434+
}
435+
}
436+
437+
void MainWindow::playerDurationChanged(qint64 d) noexcept {
438+
ui->music_progress->setRange(0, int(d));
439+
updateDurationDisplay();
440+
}
441+
442+
void MainWindow::playerPositionChanged(qint64 p) noexcept {
443+
ui->music_progress->setValue(int(p));
444+
ui->current_duration->setText(formatTime(p));
445+
}
446+
447+
void MainWindow::playerMediaStatusChanged(QMediaPlayer::MediaStatus status) noexcept {
448+
if (status == QMediaPlayer::EndOfMedia) nextTrack();
449+
}
450+
451+
void MainWindow::musicProgressPressed() noexcept {
452+
disconnect(&player, &QMediaPlayer::positionChanged, this, nullptr);
453+
}
454+
455+
void MainWindow::musicProgressReleased() noexcept {
456+
player.setPosition(ui->music_progress->value());
457+
connect(&player, &QMediaPlayer::positionChanged, this, [this](qint64 p){
458+
ui->music_progress->setValue(int(p));
459+
ui->current_duration->setText(formatTime(p));
460+
});
461+
}
462+
463+
void MainWindow::musicProgressValueChanged(int value) noexcept {
464+
ui->current_duration->setText(formatTime(value));
465+
}
466+
467+
void MainWindow::volumeChanged(int v) noexcept {
468+
if(v > 0 && muted) {
469+
muted = false;
470+
ui->mute->setIcon(QIcon(":/assets/material-symbols--volume-up-rounded.png"));
471+
ui->mute->setToolTip("静音");
472+
}
473+
else if(v == 0 && !muted) {
474+
muted = true;
475+
ui->mute->setIcon(QIcon(":/assets/material-symbols--volume-off-rounded.png"));
476+
ui->mute->setToolTip("取消静音");
477+
}
478+
audio.setVolume(v / 100.0f);
479+
}
480+
478481
MainWindow::~MainWindow() {
479482
delete ui;
480483
}

mainwindow.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,14 @@ private slots:
4848
QString formatTime(qint64 milliseconds) const noexcept;
4949
void setupTray() noexcept;
5050
void dropEvent(QDropEvent* ev) noexcept;
51+
void playModeClicked() noexcept;
52+
void playerDurationChanged(qint64 d) noexcept;
53+
void playerPositionChanged(qint64 p) noexcept;
54+
void playerMediaStatusChanged(QMediaPlayer::MediaStatus status) noexcept;
55+
void musicProgressPressed() noexcept;
56+
void musicProgressReleased() noexcept;
57+
void musicProgressValueChanged(int value) noexcept;
58+
void volumeChanged(int v) noexcept;
5159

5260
Ui::MainWindow* ui;
5361
QAudioOutput audio;

pack_windows.bat

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
makensis windows.nsi
2+
pause

windows.nsi

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
Unicode true
2+
!include "MUI2.nsh"
3+
4+
SetCompressor /SOLID lzma
5+
RequestExecutionLevel admin
6+
7+
!define VERSION "1.0.0"
8+
9+
!define MUI_ICON "assets\material-symbols-music-cast-rounded.ico"
10+
!define MUI_UNICON "assets\material-symbols-music-cast-rounded.ico"
11+
12+
!define MUI_HEADERIMAGE
13+
!define MUI_HEADERIMAGE_BITMAP "assets\material-symbols-music-cast-rounded.bmp"
14+
!define MUI_HEADERIMAGE_BITMAP_STRETCH "AspectFitHeight"
15+
!define MUI_WELCOMEFINISHPAGE_BITMAP "assets\material-symbols-music-cast-rounded.bmp"
16+
!define MUI_WELCOMEFINISHPAGE_BITMAP_STRETCH "NoStretchNoCropNoAlign"
17+
!define MUI_UNWELCOMEFINISHPAGE_BITMAP "assets\material-symbols-music-cast-rounded.bmp"
18+
!define MUI_UNWELCOMEFINISHPAGE_BITMAP_STRETCH "NoStretchNoCropNoAlign"
19+
20+
!define MUI_ABORTWARNING
21+
!define MUI_FINISHPAGE_NOAUTOCLOSE
22+
23+
!define MUI_LICENSEPAGE_CHECKBOX
24+
!define MUI_LICENSEPAGE_CHECKBOX_TEXT "我已阅读并同意许可条款"
25+
!define MUI_LICENSEPAGE_BUTTON "下一步(N) >"
26+
27+
!insertmacro MUI_PAGE_WELCOME
28+
!insertmacro MUI_PAGE_LICENSE "LICENSE"
29+
!insertmacro MUI_PAGE_DIRECTORY
30+
!insertmacro MUI_PAGE_INSTFILES
31+
!define MUI_FINISHPAGE_RUN $INSTDIR\whatever.exe
32+
!define MUI_FINISHPAGE_RUN_TEXT "运行 Whatever 播放器"
33+
!define MUI_FINISHPAGE_RUN_NOTCHECKED
34+
!define MUI_FINISHPAGE_SHOWREADME ""
35+
!define MUI_FINISHPAGE_SHOWREADME_NOTCHECKED
36+
!define MUI_FINISHPAGE_SHOWREADME_TEXT "创建桌面快捷方式"
37+
!define MUI_FINISHPAGE_SHOWREADME_FUNCTION desktopshortcut
38+
!define MUI_FINISHPAGE_LINK "访问 Whatever GitHub 仓库"
39+
!define MUI_FINISHPAGE_LINK_LOCATION https://github.com/25programmingpractice/whatever
40+
!define MUI_FINISHPAGE_LINK_COLOR 1879e7
41+
!insertmacro MUI_PAGE_FINISH
42+
!insertmacro MUI_UNPAGE_CONFIRM
43+
!insertmacro MUI_UNPAGE_INSTFILES
44+
!insertmacro MUI_UNPAGE_FINISH
45+
!insertmacro MUI_LANGUAGE "SimpChinese"
46+
47+
Function desktopshortcut
48+
CreateShortcut "$DESKTOP\Whatever.lnk" "$INSTDIR\whatever.exe"
49+
FunctionEnd
50+
51+
OutFile "Whatever_setup_win64.exe"
52+
InstallDir "$APPDATA\Whatever"
53+
Name "Whatever 播放器"
54+
Caption "Whatever 安装程序"
55+
BrandingText "Whatever (c) 2025 Lin Junming, Zhang Junming, Yi Zhihang"
56+
57+
VIAddVersionKey /LANG=${LANG_SimpChinese} "ProductName" "Whatever"
58+
VIAddVersionKey /LANG=${LANG_SimpChinese} "CompanyName" "Lin Junming, Zhang Junming, Yi Zhihang"
59+
VIAddVersionKey /LANG=${LANG_SimpChinese} "LegalCopyright" "(c) 2025 Lin Junming, Zhang Junming, Yi Zhihang"
60+
VIAddVersionKey /LANG=${LANG_SimpChinese} "FileDescription" "Whatever 安装程序"
61+
VIAddVersionKey /LANG=${LANG_SimpChinese} "FileVersion" "${VERSION}.0"
62+
VIAddVersionKey /LANG=${LANG_SimpChinese} "ProductVersion" "${VERSION}.0"
63+
VIProductVersion "${VERSION}.0"
64+
65+
Section "MainSection" SEC01
66+
SetOutPath "$INSTDIR"
67+
File /r ".\build\build\*.*"
68+
69+
CreateShortcut "$SMPROGRAMS\Whatever.lnk" "$INSTDIR\Whatever.exe"
70+
71+
WriteUninstaller "$INSTDIR\uninstall.exe"
72+
73+
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Whatever" "DisplayName" "Whatever"
74+
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Whatever" "DisplayVersion" "${VERSION}"
75+
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Whatever" "Publisher" "Lin Junming, Zhang Junming, Yi Zhihang"
76+
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Whatever" "InstallLocation" "$INSTDIR"
77+
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Whatever" "UninstallString" '"$INSTDIR\uninstall.exe"'
78+
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Whatever" "DisplayIcon" "$INSTDIR\Whatever.exe"
79+
WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Whatever" "NoRepair" 1
80+
WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Whatever" "NoModify" 1
81+
SectionEnd
82+
83+
Section "Uninstall"
84+
RMDir /r "$INSTDIR"
85+
Delete "$DESKTOP\Whatever.lnk"
86+
Delete "$SMPROGRAMS\Whatever.lnk"
87+
DeleteRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Whatever"
88+
SectionEnd

0 commit comments

Comments
 (0)