-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
环境:Qt5 (Qt Creator 4.8.2 + Qt 5.9.8 MinGW 32bit)
- Loading branch information
Tang
committed
Dec 23, 2019
0 parents
commit 0f0c493
Showing
83 changed files
with
5,063 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
# C++ objects and libs | ||
*.slo | ||
*.lo | ||
*.o | ||
*.a | ||
*.la | ||
*.lai | ||
*.so | ||
*.so.* | ||
*.dll | ||
*.dylib | ||
|
||
# Qt-es | ||
object_script.*.Release | ||
object_script.*.Debug | ||
*_plugin_import.cpp | ||
/.qmake.cache | ||
/.qmake.stash | ||
*.pro.user | ||
*.pro.user.* | ||
*.qbs.user | ||
*.qbs.user.* | ||
*.moc | ||
moc_*.cpp | ||
moc_*.h | ||
qrc_*.cpp | ||
ui_*.h | ||
*.qmlc | ||
*.jsc | ||
Makefile* | ||
*build-* | ||
*.qm | ||
*.prl | ||
|
||
# Qt unit tests | ||
target_wrapper.* | ||
|
||
# QtCreator | ||
*.autosave | ||
|
||
# QtCreator Qml | ||
*.qmlproject.user | ||
*.qmlproject.user.* | ||
|
||
# QtCreator CMake | ||
CMakeLists.txt.user* | ||
|
||
# QtCreator 4.8< compilation database | ||
compile_commands.json | ||
|
||
# QtCreator local machine specific files for imported projects | ||
*creator.user* |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
#------------------------------------------------- | ||
# | ||
# Project created by QtCreator 2019-12-11T10:44:34 | ||
# | ||
#------------------------------------------------- | ||
|
||
QT += core gui sql | ||
QT += multimedia | ||
|
||
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets | ||
|
||
TARGET = LightMusicPlayer | ||
TEMPLATE = app | ||
|
||
# The following define makes your compiler emit warnings if you use | ||
# any feature of Qt which has been marked as deprecated (the exact warnings | ||
# depend on your compiler). Please consult the documentation of the | ||
# deprecated API in order to know how to port your code away from it. | ||
DEFINES += QT_DEPRECATED_WARNINGS | ||
|
||
# You can also make your code fail to compile if you use deprecated APIs. | ||
# In order to do so, uncomment the following line. | ||
# You can also select to disable deprecated APIs only up to a certain version of Qt. | ||
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 | ||
|
||
CONFIG += c++11 | ||
|
||
SOURCES += \ | ||
main.cpp \ | ||
Music.cpp \ | ||
MainWidget.cpp \ | ||
MusicListWidget.cpp \ | ||
MusicList.cpp \ | ||
MusicListDialog.cpp \ | ||
LyricWidget.cpp | ||
|
||
HEADERS += \ | ||
Music.h \ | ||
myQSS.h \ | ||
MainWidget.h \ | ||
MusicListWidget.h \ | ||
MusicList.h \ | ||
MusicListDialog.h \ | ||
LyricWidget.h | ||
|
||
FORMS += \ | ||
MusicListDialog.ui \ | ||
mainWidget.ui \ | ||
LyricWidget.ui | ||
|
||
# Default rules for deployment. | ||
qnx: target.path = /tmp/$${TARGET}/bin | ||
else: unix:!android: target.path = /opt/$${TARGET}/bin | ||
!isEmpty(target.path): INSTALLS += target | ||
|
||
RESOURCES += \ | ||
imagefile.qrc | ||
|
||
|
||
RC_ICONS = LightMusicPlayer.ico |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
#include "LyricWidget.h" | ||
#include "ui_LyricWidget.h" | ||
|
||
#include <algorithm> | ||
#include <QTextCodec> | ||
|
||
LyricWidget::LyricWidget(QWidget *parent) : | ||
QWidget(parent), | ||
ui(new Ui::LyricWidget) | ||
{ | ||
ui->setupUi(this); | ||
clear();//清空用于排版时的测试内容(.ui文件中) | ||
} | ||
|
||
LyricWidget::~LyricWidget() | ||
{ | ||
delete ui; | ||
} | ||
|
||
|
||
//重载比较(歌词按时间排序) | ||
bool operator <(const LyricLine& A, const LyricLine& B){ | ||
return A.time<B.time; | ||
} | ||
|
||
bool LyricWidget::process(QString filePath) | ||
{ | ||
QFile lyricFile(filePath); | ||
lyricFile.open(QFile::ReadOnly); | ||
QString content(QString::fromLocal8Bit(lyricFile.readAll())); | ||
lyricFile.close(); | ||
|
||
//先清空歌词 | ||
lines.clear(); | ||
|
||
const QRegExp rx("\\[(\\d+):(\\d+(\\.\\d+)?)\\]"); //用来查找时间标签的正则表达式 | ||
|
||
// 步骤1 | ||
int pos = rx.indexIn(content); | ||
if (pos == -1) { | ||
return false; | ||
} | ||
else { | ||
int lastPos; | ||
QList<int> timeLabels; | ||
do { | ||
// 步骤2 | ||
timeLabels << (rx.cap(1).toInt() * 60 + rx.cap(2).toDouble()) * 1000; | ||
lastPos = pos + rx.matchedLength(); | ||
pos = rx.indexIn(content, lastPos); | ||
if (pos == -1) { | ||
QString text = content.mid(lastPos).trimmed(); | ||
foreach (const int& time, timeLabels) | ||
lines.push_back(LyricLine(time, text)); | ||
break; | ||
} | ||
// 步骤3 | ||
QString text = content.mid(lastPos, pos - lastPos); | ||
if (!text.isEmpty()) { | ||
foreach (const int& time, timeLabels) | ||
lines.push_back(LyricLine(time, text.trimmed())); | ||
timeLabels.clear(); | ||
} | ||
} | ||
while (true); | ||
// 步骤4 | ||
stable_sort(lines.begin(), lines.end()); | ||
} | ||
if (lines.size()) { | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
int LyricWidget::getIndex(qint64 position) | ||
{ | ||
if(!lines.size()){ | ||
return -1; | ||
}else{ | ||
if(lines[0].time>=position){ | ||
return 0; | ||
} | ||
} | ||
int i=1; | ||
for(i=1;i<lines.size();i++){ | ||
if(lines[i-1].time<position && lines[i].time>=position){ | ||
return i-1; | ||
} | ||
} | ||
return lines.size()-1; | ||
} | ||
|
||
void LyricWidget::show(qint64 position) | ||
{ | ||
int index=getIndex(position); | ||
if(index==-1){ | ||
ui->label_3i->setText(""); | ||
ui->label_2i->setText(""); | ||
ui->label_1i->setText(""); | ||
ui->label_i->setText(u8"当前歌曲无歌词"); | ||
ui->label_i1->setText(""); | ||
ui->label_i2->setText(""); | ||
ui->label_i3->setText(""); | ||
}else{ | ||
ui->label_3i->setText(getLyricText(index-3)); | ||
ui->label_2i->setText(getLyricText(index-2)); | ||
ui->label_1i->setText(getLyricText(index-1)); | ||
ui->label_i->setText(getLyricText(index)); | ||
ui->label_i1->setText(getLyricText(index+1)); | ||
ui->label_i2->setText(getLyricText(index+2)); | ||
ui->label_i3->setText(getLyricText(index+3)); | ||
} | ||
} | ||
|
||
QString LyricWidget::getLyricText(int index) | ||
{ | ||
if(index<0 || index>=lines.size()){ | ||
return ""; | ||
}else{ | ||
return lines[index].text; | ||
} | ||
} | ||
|
||
void LyricWidget::clear() | ||
{ | ||
ui->label_3i->setText(""); | ||
ui->label_2i->setText(""); | ||
ui->label_1i->setText(""); | ||
ui->label_i->setText(""); | ||
ui->label_i1->setText(""); | ||
ui->label_i2->setText(""); | ||
ui->label_i3->setText(""); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
#ifndef LYRICWIDGET_H | ||
#define LYRICWIDGET_H | ||
|
||
#include<QWidget> | ||
#include<QLabel> | ||
#include<QFile> | ||
#include<vector> | ||
using namespace std; | ||
|
||
//表示一行歌词(一个时间点+对应的歌词文本) | ||
class LyricLine | ||
{ | ||
public: | ||
qint64 time; | ||
QString text; | ||
LyricLine(qint64 time, QString text):time(time), text(text){} | ||
}; | ||
|
||
bool operator <(const LyricLine& A, const LyricLine& B); | ||
|
||
namespace Ui { | ||
class LyricWidget; | ||
} | ||
|
||
class LyricWidget : public QWidget | ||
{ | ||
Q_OBJECT | ||
|
||
//储存所有歌词 | ||
vector<LyricLine> lines; | ||
public: | ||
explicit LyricWidget(QWidget *parent = nullptr); | ||
~LyricWidget(); | ||
|
||
//将歌词文件的内容处理为歌词结构的QList | ||
bool process(QString filePath); | ||
//根据时间找到对应位置的歌词 | ||
int getIndex(qint64 position); | ||
//显示当前播放进度的歌词 | ||
void show(qint64 position); | ||
//根据下标获得歌词内容 | ||
QString getLyricText(int index); | ||
//清空歌词Label | ||
void clear(); | ||
|
||
private: | ||
Ui::LyricWidget *ui; | ||
}; | ||
|
||
#endif // LYRICWIDGET_H |
Oops, something went wrong.