Skip to content

Commit caaddc3

Browse files
author
hudejie
committed
增加音乐目录设置
1 parent b8ae819 commit caaddc3

19 files changed

+542
-89
lines changed

MusicPlayer.pro

+6-3
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ HEADERS += include/musicplayer.h \
2525
include/iconhelper.h \
2626
include/slider.h \
2727
include/libzplay.h \
28-
include/musicmgr.h
28+
include/musicmgr.h \
29+
cfgdlg.h
2930

3031
SOURCES += source/main.cpp\
3132
source/musicplayer.cpp \
@@ -34,9 +35,11 @@ SOURCES += source/main.cpp\
3435
source/boderpane.cpp \
3536
source/iconhelper.cpp \
3637
source/slider.cpp \
37-
source/musicmgr.cpp
38+
source/musicmgr.cpp \
39+
cfgdlg.cpp
3840

39-
FORMS += ui/musicplayer.ui
41+
FORMS += ui/musicplayer.ui \
42+
cfgdlg.ui
4043

4144
RESOURCES += \
4245
res/res.qrc

README.md

+29-26
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,43 @@
11
# MusicPlayer
22

3-
#### 介绍
4-
{**以下是 Gitee 平台说明,您可以替换此简介**
5-
Gitee 是 OSCHINA 推出的基于 Git 的代码托管平台(同时支持 SVN)。专为开发者提供稳定、高效、安全的云端软件开发协作平台
6-
无论是个人、团队、或是企业,都能够用 Gitee 实现代码托管、项目管理、协作开发。企业项目请看 [https://gitee.com/enterprises](https://gitee.com/enterprises)}
3+
# 📚简介
4+
本项目为Qt实现一款小而美的音乐播放器。
75

6+
# 💾体验程序
7+
- [安装包地址](https://gitee.com/hudejie/MusicPlayer/raw/master/setup/Setup.exe)
88

9-
#### 软件架构
10-
软件架构说明
9+
# 📦软件架构
10+
- Qt 5.9 + msvc 2015
11+
- Windows(x32, x64)/Linux(x32, x64)
12+
- 理论上Qt 5.6以上msvc编译器都支持
1113

14+
# 🛠️主要技术
1215

13-
#### 安装教程
1416

15-
1. xxxx
16-
2. xxxx
17-
3. xxxx
17+
| 模块 | 介绍 |
18+
| -------------------|---------------------------------------------------------------------------------- |
19+
| qss | 样式表,本程序所有窗体、控件的样式都由qss设计 |
20+
| signal\slot | 控件、窗体间通信,事件处理 |
21+
| QThread | 异步处理 | |
22+
| QPainter | 部分窗口的绘制,例如实时天气界面 |
23+
| iconfont | 阿里巴巴矢量图标库,主要用于按钮及标签上图标等显示 |
1824

19-
#### 使用说明
2025

21-
1. xxxx
22-
2. xxxx
23-
3. xxxx
26+
# 🗺️软件截图
2427

25-
#### 参与贡献
28+
### 主界面
29+
![导航](https://gitee.com/hudejie/MusicPlayer/raw/master/screenshot/main.gif)
2630

27-
1. Fork 本仓库
28-
2. 新建 Feat_xxx 分支
29-
3. 提交代码
30-
4. 新建 Pull Request
3131

32+
# 📝参考网址
3233

33-
#### 特技
34+
#### [📗qt官网](https://doc.qt.io/)
3435

35-
1. 使用 Readme\_XXX.md 来支持不同的语言,例如 Readme\_en.md, Readme\_zh.md
36-
2. Gitee 官方博客 [blog.gitee.com](https://blog.gitee.com)
37-
3. 你可以 [https://gitee.com/explore](https://gitee.com/explore) 这个地址来了解 Gitee 上的优秀开源项目
38-
4. [GVP](https://gitee.com/gvp) 全称是 Gitee 最有价值开源项目,是综合评定出的优秀开源项目
39-
5. Gitee 官方提供的使用手册 [https://gitee.com/help](https://gitee.com/help)
40-
6. Gitee 封面人物是一档用来展示 Gitee 会员风采的栏目 [https://gitee.com/gitee-stars/](https://gitee.com/gitee-stars/)
36+
37+
# 📌CSDN
38+
39+
#### [🎉欢迎关注CSDN](https://blog.csdn.net/qq_25549309)
40+
41+
# 🧡Star
42+
43+
#### 如果你觉得项目用来学习不错,可以给项目点点star,谢谢。

cfgdlg.cpp

+99
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
#include "cfgdlg.h"
2+
#include "ui_cfgdlg.h"
3+
#include <QVBoxLayout>
4+
#include <QFileDialog>
5+
#include <QDir>
6+
#include <QDebug>
7+
#include "musicmgr.h"
8+
9+
10+
#ifdef WIN32
11+
#include "Windows.h"
12+
#pragma comment(lib, "User32.lib")
13+
#endif
14+
15+
#if _MSC_VER >= 1600
16+
#pragma execution_character_set("utf-8")
17+
#endif
18+
19+
20+
CfgDlg::CfgDlg(QWidget *parent) :
21+
BoderPane(parent),
22+
ui(new Ui::CfgDlg)
23+
{
24+
ui->setupUi(this);
25+
26+
setWindowFlags(Qt::FramelessWindowHint | Qt::Popup);
27+
setProperty("form", "cfgdlg");
28+
setAttribute(Qt::WA_StyledBackground); // 禁止父窗口样式影响子控件样式
29+
30+
CreateAllChildWnd();
31+
InitCtrl();
32+
InitSolts();
33+
Relayout();
34+
}
35+
36+
CfgDlg::~CfgDlg()
37+
{
38+
delete ui;
39+
}
40+
41+
void CfgDlg::CreateAllChildWnd()
42+
{
43+
44+
}
45+
46+
void CfgDlg::InitCtrl()
47+
{
48+
49+
}
50+
51+
void CfgDlg::InitSolts()
52+
{
53+
54+
}
55+
56+
void CfgDlg::Relayout()
57+
{
58+
QVBoxLayout *layoutMain = new QVBoxLayout();
59+
layoutMain->addWidget(ui->m_widgetCenter);
60+
layoutMain->setMargin(8);
61+
62+
centralWidget()->setLayout(layoutMain);
63+
}
64+
65+
bool CfgDlg::event(QEvent *event)
66+
{
67+
static bool class_amended = false;
68+
if (event->type() == QEvent::WinIdChange)
69+
{
70+
HWND hwnd = reinterpret_cast<HWND>(winId());
71+
if (class_amended == false)
72+
{
73+
class_amended = true;
74+
DWORD class_style = ::GetClassLong(hwnd, GCL_STYLE);
75+
class_style &= ~CS_DROPSHADOW;
76+
::SetClassLong(hwnd, GCL_STYLE, class_style); // windows系统函数
77+
}
78+
}
79+
else if (event->type() == QEvent::Show)
80+
{
81+
ui->m_editDir->setText(DATAMGR->GetRootDir());
82+
}
83+
84+
return BoderPane::event(event);
85+
}
86+
87+
void CfgDlg::on_m_btnModify_clicked()
88+
{
89+
QString strCurDir = ui->m_editDir->text();
90+
if (strCurDir.isEmpty())
91+
strCurDir = QDir::currentPath(); // 获取系统当前目录
92+
93+
QString strDir = QFileDialog::getExistingDirectory(this, tr("选择目录"), strCurDir);
94+
if (strDir.isEmpty())
95+
return;
96+
97+
ui->m_editDir->setText(strDir);
98+
DATAMGR->SetRootDir(strDir);
99+
}

cfgdlg.h

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#ifndef CFGDLG_H
2+
#define CFGDLG_H
3+
4+
#include <QWidget>
5+
#include "boderpane.h"
6+
7+
namespace Ui {
8+
class CfgDlg;
9+
}
10+
11+
class CfgDlg : public BoderPane
12+
{
13+
Q_OBJECT
14+
15+
public:
16+
explicit CfgDlg(QWidget *parent = 0);
17+
~CfgDlg();
18+
19+
private slots:
20+
void on_m_btnModify_clicked();
21+
22+
private:
23+
void CreateAllChildWnd();
24+
void InitCtrl();
25+
void InitSolts();
26+
void Relayout();
27+
28+
bool event(QEvent *event);
29+
30+
private:
31+
Ui::CfgDlg *ui;
32+
};
33+
34+
#endif // CFGDLG_H

cfgdlg.ui

+124
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<ui version="4.0">
3+
<class>CfgDlg</class>
4+
<widget class="QWidget" name="CfgDlg">
5+
<property name="geometry">
6+
<rect>
7+
<x>0</x>
8+
<y>0</y>
9+
<width>330</width>
10+
<height>121</height>
11+
</rect>
12+
</property>
13+
<property name="sizePolicy">
14+
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
15+
<horstretch>31</horstretch>
16+
<verstretch>0</verstretch>
17+
</sizepolicy>
18+
</property>
19+
<property name="minimumSize">
20+
<size>
21+
<width>330</width>
22+
<height>0</height>
23+
</size>
24+
</property>
25+
<property name="maximumSize">
26+
<size>
27+
<width>330</width>
28+
<height>16777215</height>
29+
</size>
30+
</property>
31+
<property name="windowTitle">
32+
<string>Form</string>
33+
</property>
34+
<widget class="QWidget" name="m_widgetCenter" native="true">
35+
<property name="geometry">
36+
<rect>
37+
<x>20</x>
38+
<y>20</y>
39+
<width>300</width>
40+
<height>91</height>
41+
</rect>
42+
</property>
43+
<property name="minimumSize">
44+
<size>
45+
<width>300</width>
46+
<height>0</height>
47+
</size>
48+
</property>
49+
<property name="maximumSize">
50+
<size>
51+
<width>300</width>
52+
<height>16777215</height>
53+
</size>
54+
</property>
55+
<layout class="QVBoxLayout" name="verticalLayout">
56+
<property name="spacing">
57+
<number>10</number>
58+
</property>
59+
<item>
60+
<widget class="QLabel" name="label">
61+
<property name="font">
62+
<font>
63+
<family>微软雅黑</family>
64+
<pointsize>14</pointsize>
65+
</font>
66+
</property>
67+
<property name="styleSheet">
68+
<string notr="true"/>
69+
</property>
70+
<property name="text">
71+
<string>设置</string>
72+
</property>
73+
<property name="alignment">
74+
<set>Qt::AlignCenter</set>
75+
</property>
76+
</widget>
77+
</item>
78+
<item>
79+
<layout class="QHBoxLayout" name="horizontalLayout">
80+
<item>
81+
<widget class="QLabel" name="m_labelDir">
82+
<property name="styleSheet">
83+
<string notr="true">color: #909090;</string>
84+
</property>
85+
<property name="text">
86+
<string>音乐目录</string>
87+
</property>
88+
</widget>
89+
</item>
90+
<item>
91+
<widget class="QLineEdit" name="m_editDir">
92+
<property name="readOnly">
93+
<bool>true</bool>
94+
</property>
95+
</widget>
96+
</item>
97+
<item>
98+
<widget class="QPushButton" name="m_btnModify">
99+
<property name="text">
100+
<string>更改</string>
101+
</property>
102+
</widget>
103+
</item>
104+
</layout>
105+
</item>
106+
<item>
107+
<spacer name="verticalSpacer">
108+
<property name="orientation">
109+
<enum>Qt::Vertical</enum>
110+
</property>
111+
<property name="sizeHint" stdset="0">
112+
<size>
113+
<width>20</width>
114+
<height>171</height>
115+
</size>
116+
</property>
117+
</spacer>
118+
</item>
119+
</layout>
120+
</widget>
121+
</widget>
122+
<resources/>
123+
<connections/>
124+
</ui>

include/musicmgr.h

+11
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ class MusicMgr : public QObject
2626

2727
public:
2828
void Init();
29+
void SetRootDir(QString strRootDir);
30+
QString GetRootDir() { return m_strRootDir; }
2931
void GetMusicList(QList<MusicInfos> &listMusic) { listMusic = m_listMusics; }
3032
void GetMusicInfo(int nIndex, MusicInfos& item);
3133

@@ -34,11 +36,20 @@ class MusicMgr : public QObject
3436

3537
void ScanMusicFiles();
3638
void GetMusicInfo(QString strPath, MusicInfos &tMusicInfo);
39+
void ReadCfg(QString &strCfg);
40+
void WriteCfg(QString strCfg);
41+
QString GetIniFilePath();
42+
43+
signals:
44+
void SignalMusicListChange();
3745

3846
private:
3947
static MusicMgr *m_pMusicMgr;
4048
QList<MusicInfos> m_listMusics;
4149
libZPlay::ZPlay *m_pZPlayer;
50+
51+
QString m_strRootDir;
52+
4253
};
4354

4455
#define DATAMGR MusicMgr::GetInstance()

0 commit comments

Comments
 (0)