diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f147edf --- /dev/null +++ b/.gitignore @@ -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* diff --git a/LightMusicPlayer/LightMusicPlayer/LightMusicPlayer.ico b/LightMusicPlayer/LightMusicPlayer/LightMusicPlayer.ico new file mode 100644 index 0000000..735b788 Binary files /dev/null and b/LightMusicPlayer/LightMusicPlayer/LightMusicPlayer.ico differ diff --git a/LightMusicPlayer/LightMusicPlayer/LightMusicPlayer.pro b/LightMusicPlayer/LightMusicPlayer/LightMusicPlayer.pro new file mode 100644 index 0000000..3d4637e --- /dev/null +++ b/LightMusicPlayer/LightMusicPlayer/LightMusicPlayer.pro @@ -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 diff --git a/LightMusicPlayer/LightMusicPlayer/LyricWidget.cpp b/LightMusicPlayer/LightMusicPlayer/LyricWidget.cpp new file mode 100644 index 0000000..a47b0fa --- /dev/null +++ b/LightMusicPlayer/LightMusicPlayer/LyricWidget.cpp @@ -0,0 +1,133 @@ +#include "LyricWidget.h" +#include "ui_LyricWidget.h" + +#include +#include + +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 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=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(""); +} diff --git a/LightMusicPlayer/LightMusicPlayer/LyricWidget.h b/LightMusicPlayer/LightMusicPlayer/LyricWidget.h new file mode 100644 index 0000000..6028ad7 --- /dev/null +++ b/LightMusicPlayer/LightMusicPlayer/LyricWidget.h @@ -0,0 +1,50 @@ +#ifndef LYRICWIDGET_H +#define LYRICWIDGET_H + +#include +#include +#include +#include +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 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 diff --git a/LightMusicPlayer/LightMusicPlayer/LyricWidget.ui b/LightMusicPlayer/LightMusicPlayer/LyricWidget.ui new file mode 100644 index 0000000..b2bb50d --- /dev/null +++ b/LightMusicPlayer/LightMusicPlayer/LyricWidget.ui @@ -0,0 +1,213 @@ + + + LyricWidget + + + + 0 + 0 + 831 + 411 + + + + Form + + + + + + + + 0 + 30 + 831 + 31 + + + + + Microsoft JhengHei UI + 10 + 75 + true + + + + color: rgba(255, 255, 255, 170); + + + I Lived (《赐予者》电影插曲|2015年苹果秋季发布会表演歌曲原曲) - OneRepublic + + + Qt::AlignCenter + + + + + + 0 + 80 + 831 + 31 + + + + + Microsoft JhengHei UI + 10 + 75 + true + + + + color: rgba(255, 255, 255, 170); + + + I Lived (《赐予者》电影插曲|2015年苹果秋季发布会表演歌曲原曲) - OneRepublic + + + Qt::AlignCenter + + + + + + 0 + 190 + 831 + 31 + + + + + Microsoft JhengHei UI + 12 + 75 + false + true + false + + + + color: rgb(255, 255, 255); + + + I Lived (《赐予者》电影插曲|2015年苹果秋季发布会表演歌曲原曲) - OneRepublic + + + Qt::AlignCenter + + + + + + 0 + 250 + 831 + 31 + + + + + Microsoft JhengHei UI + 10 + 75 + true + + + + color: rgba(255, 255, 255, 170); + + + I Lived (《赐予者》电影插曲|2015年苹果秋季发布会表演歌曲原曲) - OneRepublic + + + Qt::AlignCenter + + + + + + 0 + 300 + 831 + 31 + + + + + Microsoft JhengHei UI + 10 + 75 + true + + + + color: rgba(255, 255, 255, 170); + + + I Lived (《赐予者》电影插曲|2015年苹果秋季发布会表演歌曲原曲) - OneRepublic + + + Qt::AlignCenter + + + + + + 0 + 130 + 831 + 31 + + + + + Microsoft JhengHei UI + 10 + 75 + true + + + + color: rgba(255, 255, 255, 170); + + + I Lived (《赐予者》电影插曲|2015年苹果秋季发布会表演歌曲原曲) - OneRepublic + + + Qt::AlignCenter + + + + + + 0 + 350 + 831 + 31 + + + + + Microsoft JhengHei UI + 10 + 75 + true + + + + color: rgba(255, 255, 255, 170); + + + I Lived (《赐予者》电影插曲|2015年苹果秋季发布会表演歌曲原曲) - OneRepublic + + + Qt::AlignCenter + + + + + + diff --git a/LightMusicPlayer/LightMusicPlayer/MainWidget.cpp b/LightMusicPlayer/LightMusicPlayer/MainWidget.cpp new file mode 100644 index 0000000..aef4557 --- /dev/null +++ b/LightMusicPlayer/LightMusicPlayer/MainWidget.cpp @@ -0,0 +1,1027 @@ +#include "MainWidget.h" +#include "ui_mainWidget.h" +#include +#include "myQSS.h" +#include +#include +#include +#include "Music.h" +#include +#include +#include +#include +#include "MusicListDialog.h" + +MainWidget::MainWidget(QWidget *parent) : + QWidget(parent), + ui(new Ui::Widget) +{ + ui->setupUi(this); + + //UI初始化(.ui文件中无法完成的设置,这里补上) + init_UI(); + + //初始化生成播放器模块及相关组件 + init_play(); + + //右键菜单初始化 + init_actions(); + + //数据库初始化 + init_sqlite(); + + //歌单初始化 + init_musicList(); + + //配置初始化 + init_settings(); + + //系统托盘初始化 + init_systemTrayIcon(); +} + +MainWidget::~MainWidget() +{ + delete ui; +} +void MainWidget::paintEvent(QPaintEvent *event) +{ + //需要添加以下代码,才能正常在主窗口Widget中显示背景图片(https://blog.csdn.net/xiejie0226/article/details/81165379) + QStyleOption opt; + opt.init(this); + QPainter p(this); + style()->drawPrimitive(QStyle::PE_Widget, &opt, &p, this); + QWidget::paintEvent(event); +} + +void MainWidget::init_UI() +{ + //窗口设置圆角后,会出现留白,需要添加以下代码 + setAttribute(Qt::WA_TranslucentBackground, true); + //去除标题栏 + setWindowFlags(Qt::FramelessWindowHint); + + //UI初始化(.ui文件中无法完成的设置,这里补上) + ui->volumeSlider->hide(); + ui->playListWidget->verticalScrollBar()->setStyleSheet(ListWidgetStyle()); + ui->localMusicWidget->verticalScrollBar()->setStyleSheet(ListWidgetStyle()); + ui->favorMusicWidget->verticalScrollBar()->setStyleSheet(ListWidgetStyle()); + ui->nameListWidget->verticalScrollBar()->setStyleSheet(ListWidgetStyle()); + ui->musicListWidget->verticalScrollBar()->setStyleSheet(ListWidgetStyle()); + ui->playListWidget->setIcon(QIcon(":/image/image/image/music.png")); + ui->localMusicWidget->setIcon(QIcon(":/image/image/image/music-file.png")); + ui->favorMusicWidget->setIcon(QIcon(":/image/image/image/like.png")); + ui->musicListWidget->setIcon(QIcon(":/image/image/image/MusicListItem.png")); +} + +void MainWidget::init_play() +{ + //播放器初始化 + player= new QMediaPlayer(this); + playlist=new QMediaPlaylist; + playlist->setPlaybackMode(QMediaPlaylist::Loop); + player->setPlaylist(playlist); + //连接槽与信号 + connect(ui->positionSlider, &QAbstractSlider::valueChanged, this, &MainWidget::setPosition); + connect(player, &QMediaPlayer::positionChanged, this, &MainWidget::updatePosition); + connect(player, &QMediaPlayer::durationChanged, this, &MainWidget::updateDuration); + connect(player, &QMediaPlayer::metaDataAvailableChanged, this, &MainWidget::updateInfo); + connect(player, &QMediaPlayer::stateChanged, this, &MainWidget::updatePlayBtn); +} + +void MainWidget::init_actions() +{ + //“当前播放”列表右键菜单初始化 + ui->playListWidget->setContextMenuPolicy(Qt::CustomContextMenu); + QAction *action_playlist_delete=new QAction(QIcon(":/image/image/image/remove.png"),u8"移除"); + connect(action_playlist_delete,&QAction::triggered,this,&MainWidget::playlist_removeMusic); + QAction *action_playlist_showfile=new QAction(QIcon(":/image/image/image/music-dir.png"),u8"打开所在文件夹"); + connect(action_playlist_showfile,&QAction::triggered,ui->playListWidget,&MusicListWidget::showInExplorer); + QAction *action_playlist_detail=new QAction(QIcon(":/image/image/image/detail.png"),u8"歌曲详情"); + connect(action_playlist_detail,&QAction::triggered,ui->playListWidget,&MusicListWidget::detail); + QAction *action_play_to_favor=new QAction(QIcon(":/image/image/image/To-like.png"),u8"添加到我喜欢"); + connect(action_play_to_favor,&QAction::triggered,this,&MainWidget::play_to_favor); + menu_playlist=new QMenu(this); + menu_playlist->addAction(action_playlist_delete); + menu_playlist->addAction(action_playlist_showfile); + menu_playlist->addAction(action_playlist_detail); + menu_playlist->addAction(action_play_to_favor); + + //“本地音乐”列表右键菜单初始化 + ui->localMusicWidget->setContextMenuPolicy(Qt::CustomContextMenu); + QAction *action_locallist_delete=new QAction(QIcon(":/image/image/image/remove.png"),u8"移除"); + connect(action_locallist_delete,&QAction::triggered,ui->localMusicWidget,&MusicListWidget::removeMusic); + QAction *action_locallist_showfile=new QAction(QIcon(":/image/image/image/music-dir.png"),u8"打开所在文件夹"); + connect(action_locallist_showfile,&QAction::triggered,ui->localMusicWidget,&MusicListWidget::showInExplorer); + QAction *action_locallist_detail=new QAction(QIcon(":/image/image/image/detail.png"),u8"歌曲详情"); + connect(action_locallist_detail,&QAction::triggered,ui->localMusicWidget,&MusicListWidget::detail); + QAction *action_local_to_favor=new QAction(QIcon(":/image/image/image/To-like.png"),u8"添加到我喜欢"); + connect(action_local_to_favor,&QAction::triggered,this,&MainWidget::local_to_favor); + QAction *action_local_to_playlist=new QAction(QIcon(":/image/image/image/To-playlist.png"),u8"添加到当前播放列表"); + connect(action_local_to_playlist,&QAction::triggered,this,&MainWidget::local_to_playlist); + menu_locallist=new QMenu(this); + menu_locallist->addAction(action_locallist_delete); + menu_locallist->addAction(action_locallist_showfile); + menu_locallist->addAction(action_locallist_detail); + menu_locallist->addAction(action_local_to_favor); + menu_locallist->addAction(action_local_to_playlist); + + //“我喜欢”列表右键菜单初始化 + ui->favorMusicWidget->setContextMenuPolicy(Qt::CustomContextMenu); + QAction *action_favorlist_delete = new QAction(QIcon(":/image/image/image/remove.png"),u8"移除"); + connect(action_favorlist_delete, &QAction::triggered, ui->favorMusicWidget, &MusicListWidget::removeMusic); + QAction *action_favorlist_showfile = new QAction(QIcon(":/image/image/image/music-dir.png"),u8"打开所在文件夹"); + connect(action_favorlist_showfile, &QAction::triggered, ui->favorMusicWidget, &MusicListWidget::showInExplorer); + QAction *action_favorlist_detail = new QAction(QIcon(":/image/image/image/detail.png"),u8"歌曲详情"); + connect(action_favorlist_detail, &QAction::triggered, ui->favorMusicWidget, &MusicListWidget::detail); + QAction *action_favor_to_playlist=new QAction(QIcon(":/image/image/image/To-playlist.png"),u8"添加到当前播放列表"); + connect(action_favor_to_playlist,&QAction::triggered,this,&MainWidget::favor_to_playlist); + menu_favorlist = new QMenu(this); + menu_favorlist->addAction(action_favorlist_delete); + menu_favorlist->addAction(action_favorlist_showfile); + menu_favorlist->addAction(action_favorlist_detail); + menu_favorlist->addAction(action_favor_to_playlist); + + //“我的歌单”列表右键菜单初始化 + ui->nameListWidget->setContextMenuPolicy(Qt::CustomContextMenu); + QAction *action_namelist_delete=new QAction(QIcon(":/image/image/image/remove.png"),u8"删除"); + connect(action_namelist_delete,&QAction::triggered,this,&MainWidget::namelist_delete); + menu_namelist=new QMenu(this); + menu_namelist->addAction(action_namelist_delete); + + //歌单展示列表右键菜单初始化 + ui->musicListWidget->setContextMenuPolicy(Qt::CustomContextMenu); + QAction *action_musiclist_delete = new QAction(QIcon(":/image/image/image/remove.png"), u8"移除"); + connect(action_musiclist_delete, &QAction::triggered, this, &MainWidget::musiclist_removeMusic); + QAction *action_musiclist_showfile = new QAction(QIcon(":/image/image/image/music-dir.png"), u8"打开所在文件夹"); + connect(action_musiclist_showfile, &QAction::triggered, ui->musicListWidget, &MusicListWidget::showInExplorer); + QAction *action_musiclist_detail = new QAction(QIcon(":/image/image/image/detail.png"), u8"歌曲详情"); + connect(action_musiclist_detail, &QAction::triggered, ui->musicListWidget, &MusicListWidget::detail); + QAction *action_musiclist_to_favor = new QAction(QIcon(":/image/image/image/To-like.png"), u8"添加到我喜欢"); + connect(action_musiclist_to_favor, &QAction::triggered, this, &MainWidget::musiclist_to_favor); + QAction *action_musiclist_to_playlist = new QAction(QIcon(":/image/image/image/To-playlist.png"), u8"添加到当前播放列表"); + connect(action_musiclist_to_playlist, &QAction::triggered, this, &MainWidget::musiclist_to_playlist); + menu_musiclist = new QMenu(this); + menu_musiclist->addAction(action_musiclist_delete); + menu_musiclist->addAction(action_musiclist_showfile); + menu_musiclist->addAction(action_musiclist_detail); + menu_musiclist->addAction(action_musiclist_to_favor); + menu_musiclist->addAction(action_musiclist_to_playlist); + + //“换肤”的菜单项 + QAction *action_backgroud_to_default = new QAction(QIcon(":/image/image/image/default.png"),u8"更换到默认背景"); + connect(action_backgroud_to_default,&QAction::triggered,this,&MainWidget::background_to_default); + QAction *action_backgroud_setting=new QAction(QIcon(":/image/image/image/setting.png"),u8"自定义背景"); + connect(action_backgroud_setting,&QAction::triggered,this,&MainWidget::background_setting); + menu_changeSkin=new QMenu(this); + menu_changeSkin->addAction(action_backgroud_to_default); + menu_changeSkin->addAction(action_backgroud_setting); +} + +void MainWidget::init_sqlite() +{ + QSqlDatabase database; + if (QSqlDatabase::contains("qt_sql_default_connection")) + { + database = QSqlDatabase::database("qt_sql_default_connection"); + } + else + { + database = QSqlDatabase::addDatabase("QSQLITE"); + database.setDatabaseName("Music.db"); + database.setUserName("NJUTang"); + database.setPassword("123456"); + if (!database.open()) + { + QMessageBox::critical(this,"无法打开数据库文件:Music.db",database.lastError().databaseText()); + exit(-1); + } + } + //检查两个表是否存在,不存在则创建不存在的表 + QSqlQuery query; + query.exec(QString("select count(*) from sqlite_master where type='table' and name='%1'").arg("MusicInfo")); + if(query.next()){ + if(query.value(0).toInt()==0){ + QSqlQuery sql_query; + //QString create_sql = "create table MusicInfo (id int primary key, name varchar(30), url varchar(200), author varchar(50), title varchar(50), duration bigint, albumTitle varchar(50), audioBitRate int)"; + QString create_sql = "create table MusicInfo (name varchar(30), url varchar(200), author varchar(50), title varchar(50), duration bigint, albumTitle varchar(50), audioBitRate int)"; + sql_query.prepare(create_sql); + sql_query.exec(); + } + } + QSqlQuery query2; + query2.exec(QString("select count(*) from sqlite_master where type='table' and name='%1'").arg("MusicLists")); + if(query2.next()){ + if(query2.value(0).toInt()==0){ + QSqlQuery sql_query; + QString create_sql = "create table MusicLists (name varchar(30))"; + sql_query.prepare(create_sql); + sql_query.exec(); + } + } +} + +void MainWidget::init_musicList() +{ + //本地音乐 初始化 + ui->localMusicWidget->musicList.setName("LocalMusic"); + ui->localMusicWidget->musicList.read_fromSQL(); + ui->localMusicWidget->refresh(); + //我喜欢 初始化 + ui->favorMusicWidget->musicList.setName("FavorMusic"); + ui->favorMusicWidget->musicList.read_fromSQL(); + ui->favorMusicWidget->refresh(); + + //从数据库中恢复歌单 + QSqlQuery sql_query; + QString select_sql = "select name from MusicLists"; + sql_query.prepare(select_sql); + if(sql_query.exec()) + { + while(sql_query.next()) + { + QString musicListName=sql_query.value(0).toString(); + MusicList tempList; + tempList.setName(musicListName); + tempList.read_fromSQL(); + musiclist.push_back(tempList); + } + } + namelist_refresh(); +} + +void MainWidget::namelist_refresh() +{ + //先清空 + QSqlQuery sql_query; + QString delete_sql = "delete from MusicLists"; + sql_query.prepare(delete_sql); + sql_query.exec(); + for(size_t i=0;inameListWidget->clear(); + for(size_t i=0;isetIcon(QIcon(":/image/image/image/music_list.png")); + item->setText(musiclist[i].getName()); + ui->nameListWidget->addItem(item); + } +} + +void MainWidget::init_settings() +{ + QSettings mysettings("./LightMusicPlayer.ini",QSettings::IniFormat); + mysettings.setIniCodec("UTF8"); + QString fileName = mysettings.value("background/image-url").toString(); + QImage testImage(fileName); + if(!fileName.isEmpty()&&!testImage.isNull()) + { + setStyleSheet(QString("QWidget#Widget{" + "border-radius:10px;" + "border-image: url(%1);}").arg(fileName)); + }else{ + fileName=":/image/image/background/default.jpg"; + QSettings mysettings("./LightMusicPlayer.ini",QSettings::IniFormat); + mysettings.setIniCodec("UTF8"); + mysettings.setValue("background/image-url",fileName); + setStyleSheet(QString("QWidget#Widget{" + "border-radius:10px;" + "border-image: url(%1);}").arg(fileName)); + } +} + +void MainWidget::musicListWidget_refresh() +{ + if(musiclist_index != -1){ + ui->musicListNameLabel->setText(u8"歌单 - "+musiclist[musiclist_index].getName()); + ui->musicListWidget->setMusicList_playing(musiclist[musiclist_index]); + } +} + +void MainWidget::on_playListWidget_customContextMenuRequested(const QPoint &pos) +{ + if(ui->playListWidget->itemAt(pos)==Q_NULLPTR) + { + return; + } + menu_playlist->exec(QCursor::pos()); +} + +void MainWidget::playlist_removeMusic() +{ + int pos=ui->playListWidget->currentRow(); + int playing_pos=playlist->currentIndex(); + ui->playListWidget->removeMusic(); + if(posstate();//记录下删除前的播放状态 + qint64 position_backup=player->position(); + playing_pos=playing_pos-1; + playlist->removeMedia(pos); + //移除后恢复 + playlist->setCurrentIndex(playing_pos); + player->setPosition(position_backup); + ui->positionSlider->setValue(position_backup); + if(state==QMediaPlayer::PlayingState){ + player->play(); + }else if(state==QMediaPlayer::PlayingState){ + player->pause(); + } + }else if(posremoveMedia(pos); + playlist->setCurrentIndex(pos); + }else{ + playlist->removeMedia(pos); + } +} + +void MainWidget::play_to_favor() +{ + int pos=ui->playListWidget->currentRow(); + ui->favorMusicWidget->musicList.addMusic(ui->playListWidget->musicList.getMusic(pos)); + ui->favorMusicWidget->refresh(); +} + +void MainWidget::local_to_favor() +{ + int pos=ui->localMusicWidget->currentRow(); + ui->favorMusicWidget->musicList.addMusic(ui->localMusicWidget->musicList.getMusic(pos)); + ui->favorMusicWidget->refresh(); +} + +void MainWidget::local_to_playlist() +{ + int pos=ui->localMusicWidget->currentRow(); + Music tempMusic=ui->localMusicWidget->musicList.getMusic(pos); + ui->playListWidget->musicList.addMusic(tempMusic); + ui->playListWidget->refresh(); + //添加到播放器 + playlist->addMedia(tempMusic.getUrl()); +} + +void MainWidget::favor_to_playlist() +{ + int pos=ui->favorMusicWidget->currentRow(); + Music tempMusic=ui->favorMusicWidget->musicList.getMusic(pos); + ui->playListWidget->musicList.addMusic(tempMusic); + ui->playListWidget->refresh(); + //添加到播放器 + playlist->addMedia(tempMusic.getUrl()); +} + +void MainWidget::namelist_delete() +{ + int pos=ui->nameListWidget->currentRow(); + musiclist[pos].remove_SQL_all();//先从数据库中删除歌曲信息 + //移除歌单 + int i=0; + for(auto it=musiclist.begin();it!=musiclist.end();){ + if(i==pos){ + it= musiclist.erase(it); + break; + } + else{ + it++; + } + i++; + } + namelist_refresh(); +} + +void MainWidget::musiclist_removeMusic() +{ + int pos=ui->musicListWidget->currentRow(); + musiclist[musiclist_index].removeMusic(pos); + musicListWidget_refresh(); +} + +void MainWidget::musiclist_to_favor() +{ + int pos=ui->musicListWidget->currentRow(); + ui->favorMusicWidget->musicList.addMusic(musiclist[musiclist_index].getMusic(pos)); + ui->favorMusicWidget->refresh(); +} + +void MainWidget::musiclist_to_playlist() +{ + int pos=ui->musicListWidget->currentRow(); + Music tempMusic=ui->musicListWidget->musicList.getMusic(pos); + ui->playListWidget->musicList.addMusic(tempMusic); + ui->playListWidget->refresh(); + //添加到播放器 + playlist->addMedia(tempMusic.getUrl()); +} + +void MainWidget::background_to_default() +{ + QString fileName=":/image/image/background/default.jpg"; + QSettings mysettings("./LightMusicPlayer.ini",QSettings::IniFormat); + mysettings.setIniCodec("UTF8"); + mysettings.setValue("background/image-url",fileName); + setStyleSheet(QString("QWidget#Widget{" + "border-radius:10px;" + "border-image: url(%1);}").arg(fileName)); +} + +void MainWidget::background_setting() +{ + //从默认图片位置打开文件选择框 + QString fileName=QFileDialog::getOpenFileName(this,("选择自定义背景图片"),QStandardPaths::standardLocations(QStandardPaths::PicturesLocation).first(),u8"图片文件(*jpg *png)"); + if(!fileName.isEmpty()) + { + QImage testImage(fileName); + if(!testImage.isNull()){ + QSettings mysettings("./LightMusicPlayer.ini",QSettings::IniFormat); + mysettings.setIniCodec("UTF8"); + mysettings.setValue("background/image-url",fileName); + setStyleSheet(QString("QWidget#Widget{" + "border-radius:10px;" + "border-image: url(%1);}").arg(fileName)); + } + } +} + + + +void MainWidget::on_localMusicWidget_customContextMenuRequested(const QPoint &pos) +{ + if(ui->localMusicWidget->itemAt(pos)==Q_NULLPTR) + { + return; + } + menu_locallist->exec(QCursor::pos()); +} + +void MainWidget::on_favorMusicWidget_customContextMenuRequested(const QPoint &pos) +{ + if(ui->favorMusicWidget->itemAt(pos)==Q_NULLPTR) + { + return; + } + menu_favorlist->exec(QCursor::pos()); +} + +void MainWidget::on_nameListWidget_customContextMenuRequested(const QPoint &pos) +{ + if(ui->nameListWidget->itemAt(pos)==Q_NULLPTR) + { + return; + } + menu_namelist->exec(QCursor::pos()); +} + + +QString formatTime(qint64 timeMilliSeconds) +{ + qint64 seconds = timeMilliSeconds / 1000; + const qint64 minutes = seconds / 60; + seconds -= minutes * 60; + return QStringLiteral("%1:%2") + .arg(minutes, 2, 10, QLatin1Char('0')) + .arg(seconds, 2, 10, QLatin1Char('0')); +} + +void MainWidget::updatePosition(qint64 position) +{ + ui->positionSlider->setValue(static_cast(position)); + ui->positionLabel->setText(formatTime(position)+"/"+formatTime(player->duration())); + if(playlist->currentIndex()>=0)ui->lyricWidget->show(position); +} + +void MainWidget::updateDuration(qint64 duration) +{ + ui->positionSlider->setRange(0, static_cast(duration)); + ui->positionSlider->setEnabled(static_cast(duration) > 0); + if(!(static_cast(duration) > 0)) { + //无音乐播放时,界面元素 + ui->infoLabel->setText("KEEP CALM AND CARRY ON ..."); + mySystemTray->setToolTip(u8"LightMusicPlayer · By NJU-TJL"); + QImage image(":/image/image/image/non-music.png"); + ui->coverLabel->setPixmap(QPixmap::fromImage(image)); + ui->musicTitleLabel->setText(""); + ui->musicAlbumLabel->setText(""); + ui->musicAuthorLabel->setText(""); + ui->lyricWidget->clear(); + } + ui->positionSlider->setPageStep(static_cast(duration) / 10); +} + +void MainWidget::setPosition(int position) +{ + // avoid seeking when the slider value change is triggered from updatePosition() + if (qAbs(player->position() - position) > 99) + player->setPosition(position); +} + +void MainWidget::updateInfo() +{ + if (player->isMetaDataAvailable()) { + //返回可用MP3元数据列表(调试时可以查看) + QStringList listInfo_debug=player->availableMetaData(); + //歌曲信息 + QString info=""; + QString author = player->metaData(QStringLiteral("Author")).toStringList().join(","); + info.append(author); + QString title = player->metaData(QStringLiteral("Title")).toString(); + QString albumTitle = player->metaData(QStringLiteral("AlbumTitle")).toString(); + info.append(" - "+title); + info.append(" ["+formatTime(player->duration())+"]"); + ui->infoLabel->setText(info); + mySystemTray->setToolTip("正在播放:"+info); + //封面图片(应获取"ThumbnailImage" From: https://www.zhihu.com/question/36859497) + QImage picImage= player->metaData(QStringLiteral("ThumbnailImage")).value(); + if(picImage.isNull()) picImage=QImage(":/image/image/image/non-music.png"); + ui->coverLabel->setPixmap(QPixmap::fromImage(picImage)); + ui->coverLabel->setScaledContents(true); + //改变正在播放歌曲的图标 + for(int i=0;imediaCount();i++){ + QListWidgetItem *p=ui->playListWidget->item(i); + p->setIcon(ui->playListWidget->getIcon()); + } + int index=playlist->currentIndex(); + QListWidgetItem *p=ui->playListWidget->item(index); + p->setIcon(QIcon(":/image/image/image/music-playing.png")); + + //歌词界面显示的信息 + ui->musicTitleLabel->setText(title); + ui->musicAlbumLabel->setText(u8"专辑:"+albumTitle); + ui->musicAuthorLabel->setText(u8"歌手:"+author); + //解析歌词 + ui->lyricWidget->process(ui->playListWidget->musicList.music[index].getLyricFile()); + } +} + +void MainWidget::updatePlayBtn() +{ + if(player->state()==QMediaPlayer::PlayingState) + { + ui->btnPlay->setStyleSheet(PlayStyle()); + action_systemTray_play->setIcon(QIcon(":/image/image/image/pause2.png")); + action_systemTray_play->setText(u8"暂停"); + }else{ + ui->btnPlay->setStyleSheet(PaseStyle()); + action_systemTray_play->setIcon(QIcon(":/image/image/image/play2.png")); + action_systemTray_play->setText(u8"播放"); + } +} + +void MainWidget::systemTrayIcon_activated(QSystemTrayIcon::ActivationReason reason) +{ + switch (reason) { + case QSystemTrayIcon::DoubleClick: + //显/隐主界面 + if(isHidden()){ + show(); + }else{ + hide(); + } + break; + default: + break; + } +} + +void MainWidget::quitMusicPlayer() +{ + //退出应用 + QCoreApplication::quit(); +} + +void MainWidget::init_systemTrayIcon() +{ + mySystemTray=new QSystemTrayIcon(this); + mySystemTray->setIcon(QIcon(":/image/image/image/systemTrayIcon.png")); + mySystemTray->setToolTip(u8"LightMusicPlayer · By NJU-TJL"); + connect(mySystemTray,&QSystemTrayIcon::activated,this,&MainWidget::systemTrayIcon_activated); + //添加菜单项 + QAction *action_systemTray_pre = new QAction(QIcon(":/image/image/image/pre2.png"), u8"上一首"); + connect(action_systemTray_pre, &QAction::triggered, this, &MainWidget::on_btnPre_clicked); + action_systemTray_play = new QAction(QIcon(":/image/image/image/play2.png"), u8"播放"); + connect(action_systemTray_play, &QAction::triggered, this, &MainWidget::on_btnPlay_clicked); + QAction *action_systemTray_next = new QAction(QIcon(":/image/image/image/next2.png"), u8"下一首"); + connect(action_systemTray_next, &QAction::triggered, this, &MainWidget::on_btnNext_clicked); + action_systemTray_playmode = new QAction(QIcon(":/image/image/image/loop2.png"), u8"循环播放"); + connect(action_systemTray_playmode, &QAction::triggered, this, &MainWidget::on_btnPlayMode_clicked); + QAction *action_systemTray_quit = new QAction(QIcon(":/image/image/image/exit.png"), u8"退出应用"); + connect(action_systemTray_quit, &QAction::triggered, this, &MainWidget::quitMusicPlayer); + + QMenu *pContextMenu = new QMenu(this); + pContextMenu->addAction(action_systemTray_pre); + pContextMenu->addAction(action_systemTray_play); + pContextMenu->addAction(action_systemTray_next); + pContextMenu->addAction(action_systemTray_playmode); + pContextMenu->addAction(action_systemTray_quit); + mySystemTray->setContextMenu(pContextMenu); + mySystemTray->show(); +} + +void MainWidget::mousePressEvent(QMouseEvent *event) +{ + //实现点击界面中某点,音量条隐藏 + int x=event->pos().x(); + int y=event->pos().y(); + int x_widget=ui->volumeSlider->geometry().x(); //注:这里“wiget”的名字是要从UI文件编译后生成的ui_xxx.h文件中得知(在UI布局中看不到) + int y_widget=ui->volumeSlider->geometry().y(); + int w=ui->volumeSlider->geometry().width(); + int h=ui->volumeSlider->geometry().height(); + if(!(x>=x_widget&&x<=x_widget+w && y>=y_widget&&y<=y_widget+h)){ + ui->volumeSlider->hide(); + } + + //记录窗口移动的初始位置 + offset = event->globalPos() - pos(); + event->accept(); +} + +void MainWidget::mouseMoveEvent(QMouseEvent *event) +{ + int x=event->pos().x(); + int y=event->pos().y(); + //注:这里“layoutWidget1”的名字是要从UI文件编译后生成的ui_xxx.h文件中得知(在UI布局中看不到) + if((ytitleLabel->geometry().height())&&(xlayoutWidget1->geometry().x())){ + move(event->globalPos() - offset); + event->accept(); + setCursor(Qt::ClosedHandCursor); + } +} + +void MainWidget::mouseReleaseEvent(QMouseEvent *event) +{ + offset = QPoint(); + event->accept(); + setCursor(Qt::ArrowCursor); +} + +void MainWidget::closeEvent(QCloseEvent *event) +{ + //最小化到托盘 + if(!mySystemTray->isVisible()){ + mySystemTray->show(); + } + hide(); + event->ignore(); +} + +void MainWidget::dragEnterEvent(QDragEnterEvent *event) +{ + event->acceptProposedAction(); +} + +void MainWidget::dropEvent(QDropEvent *event) +{ + QList urls = event->mimeData()->urls(); + ui->localMusicWidget->musicList.addMusic(urls); + ui->localMusicWidget->refresh(); + ui->stackedWidget->setCurrentIndex(1);//切换到本地音乐 + +} +void MainWidget::on_btnQuit_clicked() +{ + close(); +} + +void MainWidget::on_btnPlay_clicked() +{ + if(player->state()==QMediaPlayer::PlayingState) + { + player->pause(); + + } + else if(player->state()==QMediaPlayer::PausedState){ + + player->play(); + } + else if(!playlist->isEmpty() && (player->state()==QMediaPlayer::StoppedState)) + { + playlist->setCurrentIndex(0); + player->play(); + } +} + +void MainWidget::on_btnNext_clicked() +{ + playlist->next(); +} + +void MainWidget::on_btnPre_clicked() +{ + playlist->previous(); +} + +void MainWidget::on_btnPlayMode_clicked() +{ + if(playlist->playbackMode()==QMediaPlaylist::Loop){ + ui->btnPlayMode->setStyleSheet(RandomStyle()); + ui->btnPlayMode->setToolTip(u8"随机播放"); + action_systemTray_playmode->setIcon(QIcon(":/image/image/image/random2.png")); + action_systemTray_playmode->setText(u8"随机播放"); + playlist->setPlaybackMode(QMediaPlaylist::Random); + } + else if(playlist->playbackMode()==QMediaPlaylist::Random){ + ui->btnPlayMode->setStyleSheet(LoopOneStyle()); + ui->btnPlayMode->setToolTip(u8"单曲循环"); + action_systemTray_playmode->setIcon(QIcon(":/image/image/image/loop-one2.png")); + action_systemTray_playmode->setText(u8"单曲循环"); + playlist->setPlaybackMode(QMediaPlaylist::CurrentItemInLoop); + } + else if(playlist->playbackMode()==QMediaPlaylist::CurrentItemInLoop){ + ui->btnPlayMode->setStyleSheet(LoopStyle()); + ui->btnPlayMode->setToolTip(u8"循环播放"); + action_systemTray_playmode->setIcon(QIcon(":/image/image/image/loop2.png")); + action_systemTray_playmode->setText(u8"循环播放"); + playlist->setPlaybackMode(QMediaPlaylist::Loop); + } +} + +void MainWidget::on_btnMin_clicked() +{ + showMinimized();//窗口最小化 +} + +void MainWidget::on_btnAdd_clicked() +{ + QFileDialog fileDialog(this); + fileDialog.setAcceptMode(QFileDialog::AcceptOpen); + fileDialog.setFileMode(QFileDialog::ExistingFiles); + fileDialog.setWindowTitle(tr("添加本地音乐(注:自动过滤,按下\"Ctrl+A\"全选添加即可;不支持添加文件夹)")); + QStringList list;list<<"application/octet-stream"; + fileDialog.setMimeTypeFilters(list); + fileDialog.setDirectory(QStandardPaths::standardLocations(QStandardPaths::MusicLocation).value(0, QDir::homePath())); + if (fileDialog.exec() == QDialog::Accepted){ + QList urls=fileDialog.selectedUrls(); + ui->localMusicWidget->musicList.addMusic(urls); + ui->localMusicWidget->refresh(); + ui->stackedWidget->setCurrentIndex(1);//切换到本地音乐 + } +} + + +void MainWidget::on_btnVolume_clicked() +{ + if(ui->volumeSlider->isHidden()){ + ui->volumeSlider->show(); + }else{ + ui->volumeSlider->hide(); + } +} + +void MainWidget::on_volumeSlider_valueChanged(int value) +{ + player->setVolume(value); +} + +void MainWidget::on_btnAddMusicList_clicked() +{ + bool ok; + QString text=QInputDialog::getText(this,u8"新建歌单",u8"请输入新歌单的名字:",QLineEdit::Normal,"",&ok); + if(ok && !text.isEmpty()){ + MusicList tempMusic; + tempMusic.setName(text); + musiclist.push_back(tempMusic); + namelist_refresh(); + } +} + + +void MainWidget::on_btnCurMusic_clicked() +{ + //切换到“当前播放”界面 + ui->stackedWidget->setCurrentIndex(0); +} +void MainWidget::on_btnLocalMusic_clicked() +{ + //切换到“本地音乐”界面 + ui->stackedWidget->setCurrentIndex(1); +} +void MainWidget::on_btnFavorMusic_clicked() +{ + //切换到“我喜欢”界面 + ui->stackedWidget->setCurrentIndex(2); +} + +void MainWidget::on_playListWidget_doubleClicked(const QModelIndex &index) +{ + int i=index.row(); + playlist->setCurrentIndex(i); + player->play(); +} +void MainWidget::on_localMusicWidget_doubleClicked(const QModelIndex &index) +{ + playlist->clear(); + ui->localMusicWidget->musicList.addToPlayList(playlist); + ui->playListWidget->setMusicList_playing(ui->localMusicWidget->musicList); + int i=index.row(); + playlist->setCurrentIndex(i); + player->play(); + ui->stackedWidget->setCurrentIndex(0);//跳转到当前播放列表 +} +void MainWidget::on_favorMusicWidget_doubleClicked(const QModelIndex &index) +{ + playlist->clear(); + ui->favorMusicWidget->musicList.addToPlayList(playlist); + ui->playListWidget->setMusicList_playing(ui->favorMusicWidget->musicList); + int i=index.row(); + playlist->setCurrentIndex(i); + player->play(); + ui->stackedWidget->setCurrentIndex(0);//跳转到当前播放列表 +} + +void MainWidget::on_nameListWidget_doubleClicked(const QModelIndex &index) +{ + ui->stackedWidget->setCurrentIndex(3);//跳转到歌单内容列表 + musiclist_index=index.row(); + musicListWidget_refresh(); +} + +void MainWidget::on_btnSkin_clicked() +{ + menu_changeSkin->exec(QCursor::pos()); +} + +void MainWidget::on_btnAddtoMusicList_clicked() +{ + MusicListDialog *dialog=new MusicListDialog(this); + int num=ui->localMusicWidget->count(); + bool *results=new bool[num]; + dialog->setMusicList(ui->localMusicWidget->musicList,results); + if(dialog->exec()==QDialog::Accepted){ + for(int i=0;ilocalMusicWidget->musicList.getMusic(i)); + } + } + musicListWidget_refresh(); + } + delete []results; +} + +void MainWidget::on_musicListWidget_doubleClicked(const QModelIndex &index) +{ + playlist->clear(); + musiclist[musiclist_index].addToPlayList(playlist); + ui->playListWidget->setMusicList_playing(musiclist[musiclist_index]); + int i=index.row(); + playlist->setCurrentIndex(i); + player->play(); + ui->stackedWidget->setCurrentIndex(0);//跳转到当前播放列表 +} + +void MainWidget::on_musicListWidget_customContextMenuRequested(const QPoint &pos) +{ + if(ui->musicListWidget->itemAt(pos)==Q_NULLPTR) + { + return; + } + menu_musiclist->exec(QCursor::pos()); +} + +void MainWidget::on_btnAddtoFavor_clicked() +{ + MusicListDialog *dialog=new MusicListDialog(this); + int num=ui->localMusicWidget->count(); + bool *results=new bool[num]; + dialog->setMusicList(ui->localMusicWidget->musicList,results); + if(dialog->exec()==QDialog::Accepted){ + for(int i=0;ifavorMusicWidget->musicList.addMusic(ui->localMusicWidget->musicList.getMusic(i)); + } + } + ui->favorMusicWidget->refresh(); + } + delete []results; +} + +void MainWidget::on_btnSortSinger_clicked() +{ + ui->localMusicWidget->musicList.sort_by(AUTHOR); + ui->localMusicWidget->refresh(); +} +void MainWidget::on_btnSortTitle_clicked() +{ + ui->localMusicWidget->musicList.sort_by(TITLE); + ui->localMusicWidget->refresh(); +} +void MainWidget::on_btnSortDuration_clicked() +{ + ui->localMusicWidget->musicList.sort_by(DURATION); + ui->localMusicWidget->refresh(); +} + +void MainWidget::on_btnSortSinger_2_clicked() +{ + ui->favorMusicWidget->musicList.sort_by(AUTHOR); + ui->favorMusicWidget->refresh(); +} +void MainWidget::on_btnSortTitle_2_clicked() +{ + ui->favorMusicWidget->musicList.sort_by(TITLE); + ui->favorMusicWidget->refresh(); +} +void MainWidget::on_btnSortDuration_2_clicked() +{ + ui->favorMusicWidget->musicList.sort_by(DURATION); + ui->favorMusicWidget->refresh(); +} + +void MainWidget::on_btnSortSinger_4_clicked() +{ + musiclist[musiclist_index].sort_by(AUTHOR); + musicListWidget_refresh(); +} +void MainWidget::on_btnSortTitle_4_clicked() +{ + musiclist[musiclist_index].sort_by(TITLE); + musicListWidget_refresh(); +} +void MainWidget::on_btnSortDuration_4_clicked() +{ + musiclist[musiclist_index].sort_by(DURATION); + musicListWidget_refresh(); +} + +void MainWidget::on_btnNeaten_clicked() +{ + ui->localMusicWidget->musicList.neaten(); + ui->localMusicWidget->refresh(); +} +void MainWidget::on_btnNeaten_2_clicked() +{ + ui->favorMusicWidget->musicList.neaten(); + ui->favorMusicWidget->refresh(); +} +void MainWidget::on_btnNeaten_3_clicked() +{ + musiclist[musiclist_index].neaten(); + musicListWidget_refresh(); +} + +void MainWidget::on_btnTitle_clicked() +{ + on_btnAbout_clicked(); +} + +void MainWidget::on_btnLyric_clicked() +{ + ui->stackedWidget->setCurrentIndex(4); +} + +void MainWidget::on_btnClear_clicked() +{ + QMessageBox::StandardButton btn; + btn = QMessageBox::question(this, "提示", "此操作不可逆!\n确实要清空吗?", QMessageBox::Yes|QMessageBox::No); + if (btn == QMessageBox::Yes) { + ui->playListWidget->musicList.clear(); + ui->playListWidget->refresh(); + playlist->clear(); + } +} + +void MainWidget::on_btnClear_2_clicked() +{ + QMessageBox::StandardButton btn; + btn = QMessageBox::question(this, "提示", "此操作不可逆!\n确实要清空吗?", QMessageBox::Yes|QMessageBox::No); + if (btn == QMessageBox::Yes) { + ui->localMusicWidget->musicList.clear(); + ui->localMusicWidget->refresh(); + } +} + +void MainWidget::on_btnClear_3_clicked() +{ + QMessageBox::StandardButton btn; + btn = QMessageBox::question(this, "提示", "此操作不可逆!\n确实要清空吗?", QMessageBox::Yes|QMessageBox::No); + if (btn == QMessageBox::Yes) { + ui->favorMusicWidget->musicList.clear(); + ui->favorMusicWidget->refresh(); + } +} + +void MainWidget::on_btnClear_4_clicked() +{ + QMessageBox::StandardButton btn; + btn = QMessageBox::question(this, "提示", "此操作不可逆!\n确实要清空吗?", QMessageBox::Yes|QMessageBox::No); + if (btn == QMessageBox::Yes) { + musiclist[musiclist_index].clear(); + musicListWidget_refresh(); + } +} + +void MainWidget::on_btnAbout_clicked() +{ + QMessageBox::about(this,u8"关于","LightMusicPlayer | 一款精致小巧的本地音乐播放器\n" + "作者:NJU-TJL\n\n" + "【歌词文件说明】需要与对应的歌曲MP3在同目录且同名(.lry文件)\n" + "【快捷键说明】\n" + "播放/暂停 - 空格\n" + "上一曲/下一曲 - Alt键+方向键←/→\n" + "【添加本地音乐】可直接拖拽至软件界面内或者点击本地音乐界面的添加按钮(Ctrl键+O)\n" + "【音乐文件类型】添加过程中会自动过滤得到可播放的文件类型(.mp3/.flac/.mpga文件),所以添加时无需考虑文件类型,使用\"Ctrl+A\"选择文件夹内全部文件添加即可\n" + "\n注:鼠标移动到不认识的按钮上,会有说明哦~\n"); +} diff --git a/LightMusicPlayer/LightMusicPlayer/Music.cpp b/LightMusicPlayer/LightMusicPlayer/Music.cpp new file mode 100644 index 0000000..f63864f --- /dev/null +++ b/LightMusicPlayer/LightMusicPlayer/Music.cpp @@ -0,0 +1,85 @@ +#include "Music.h" +#include +#include +#include +#include + +Music::Music(QUrl iurl) +{ + url=iurl; + refreshInfo(); +} + +extern QString formatTime(qint64 timeMilliSeconds); +void Music::refreshInfo() +{ + QMediaPlayer tempPlayer; + tempPlayer.setMedia(url); + //元数据的解析需要时间,所以这里需要循环等待(但同时需要保持Qt事件处理机制在运行) + while(!tempPlayer.isMetaDataAvailable()){ + QCoreApplication::processEvents(); + } + QStringList list=tempPlayer.availableMetaData();//调试时查看有哪些元数据可用 + if(tempPlayer.isMetaDataAvailable()){ + //歌曲信息 + author = tempPlayer.metaData(QStringLiteral("Author")).toStringList().join(","); + //author = tempPlayer.metaData(QStringLiteral("Author")).toString(); //查手册发现,这里返回的是StringList + //author=tempPlayer.metaData(QStringLiteral("ContributingArtist")).toStringList().join(","); //另一种元数据 + title = tempPlayer.metaData(QStringLiteral("Title")).toString(); + albumTitle = tempPlayer.metaData(QStringLiteral("AlbumTitle")).toString(); + audioBitRate = tempPlayer.metaData(QStringLiteral("AudioBitRate")).toInt(); + duration=tempPlayer.duration(); + } +} + +QString Music::getLyricFile() +{ + QString mp3FilePath=url.toLocalFile(); + mp3FilePath.replace(".mp3",".lrc"); + mp3FilePath.replace(".flac",".lrc"); + mp3FilePath.replace(".mpga",".lrc"); + return mp3FilePath; +} + +QString Music::getInfo() const +{ + return author+" - "+title+" ["+formatTime(duration)+"]"; +} + +void Music::detail() +{ + QString info("歌曲名:%1\n艺术家:%2\n时长:%3\n唱片集:%4\n比特率:%5\n文件路径:%6"); + info=info.arg(title,author,formatTime(duration),albumTitle,QString::number(audioBitRate)+"bps",url.toString()); + QMessageBox::about(Q_NULLPTR,"歌曲信息",info); +} + +void Music::insertSQL(const QString &name) +{ + QSqlQuery sql_query; + QString insert_sql = "insert into MusicInfo values (?, ?, ?, ?, ?, ?, ?)"; + sql_query.prepare(insert_sql); + sql_query.addBindValue(name); + sql_query.addBindValue(url.toString()); + sql_query.addBindValue(author); + sql_query.addBindValue(title); + sql_query.addBindValue(duration); + sql_query.addBindValue(albumTitle); + sql_query.addBindValue(audioBitRate); + sql_query.exec(); +} + +bool MusicCompare::operator()(const Music &A, const Music &B) +{ + switch (key) { + case TITLE: + return A.title +#include + +//歌曲类 +class Music +{ +private: + //歌曲资源地址 + QUrl url; + //歌手 + QString author; + //歌曲名 + QString title; + //时长 + qint64 duration; + //唱片集 + QString albumTitle; + //比特率 + int audioBitRate; + + //根据歌曲url获得歌曲信息 + void refreshInfo(); + + friend class MusicCompare; +public: + Music(){} + Music(QUrl iurl); + + //返回歌曲Url + QUrl getUrl() const {return url;} + //返回歌曲的信息 + QString getInfo() const; + //弹窗显示歌曲信息 + void detail(); + //存入数据库 + void insertSQL(const QString& name); + //根据文件名来获取歌词路径 + QString getLyricFile(); + + friend class MusicList; +}; + +//排序的可选属性 +enum COMPARE{DEFAULT,TITLE,AUTHOR,DURATION,EQUALITY}; + +//用于歌曲排序的函数对象 +class MusicCompare +{ + COMPARE key; +public: + MusicCompare(){key=DEFAULT;} + MusicCompare(COMPARE ikey){key=ikey;} + bool operator()(const Music& A, const Music& B); +}; + +#endif // MUSIC_H diff --git a/LightMusicPlayer/LightMusicPlayer/MusicList.cpp b/LightMusicPlayer/LightMusicPlayer/MusicList.cpp new file mode 100644 index 0000000..40b1f30 --- /dev/null +++ b/LightMusicPlayer/LightMusicPlayer/MusicList.cpp @@ -0,0 +1,181 @@ +#include "MusicList.h" +#include +#include +#include +#include +#include +#include "MusicListWidget.h" + +MusicList::MusicList(const QList &urls, QString iname) +{ + addMusic(urls); + setName(iname); +} + +void MusicList::addMusic(const QList &urls) +{ + //实测这里耗时较长,所以添加一个进度显示对话框 + QProgressDialog proDialog(u8"添加进度",u8"取消",0,urls.size()); + proDialog.setMinimumSize(350,150); + proDialog.setWindowModality(Qt::WindowModal); + proDialog.setWindowTitle("添加中...请稍后"); + proDialog.show(); + int x=0; + foreach (QUrl i, urls) { + x++; + proDialog.setValue(x); + //过滤Url的类型 + QMimeDatabase db; + QMimeType mime = db.mimeTypeForFile(i.toLocalFile()); + if(mime.name()!="audio/mpeg"&&mime.name()!="audio/flac"){ + continue; + } + //剩下的符合类型 + music.push_back(Music(i)); + if(sql_flag){ + music[music.size()-1].insertSQL(name); + } + if(proDialog.wasCanceled()) break; + } +} + +void MusicList::addMusic(const Music &iMusic) +{ + music.push_back(iMusic); + if(sql_flag){ + music[music.size()-1].insertSQL(name); + } +} + +Music MusicList::getMusic(int pos) +{ + return music[pos]; +} + +void MusicList::addToPlayList(QMediaPlaylist *playlist) +{ + for(auto i=music.begin();i!=music.end();i++){ + playlist->addMedia(i->getUrl()); + } +} + +void MusicList::addToListWidget(MusicListWidget *listWidget) +{ + foreach(const Music &i,music){ + QListWidgetItem *item = new QListWidgetItem; + item->setIcon(listWidget->getIcon()); + item->setText(i.getInfo()); + listWidget->addItem(item); + } +} + +void MusicList::removeMusic(int pos) +{ + if(sql_flag){ + remove_SQL_all(); + int i=0; + for(auto it=music.begin();it!=music.end();){ + if(i==pos){ + it= music.erase(it); + break; + } + else{ + it++; + } + i++; + + } + insert_SQL_all(); + }else{ + int i=0; + for(auto it=music.begin();it!=music.end();){ + if(i==pos){ + it= music.erase(it); + break; + } + else{ + it++; + } + i++; + + } + } + +} + +void MusicList::showInExplorer(int pos) +{ + QString str=music[pos].getUrl().toString(); + str.remove(str.split("/").last());//切割字符串获得所在的文件夹路径 + QDesktopServices::openUrl(str); +} + +void MusicList::detail(int pos) +{ + music[pos].detail(); +} + +void MusicList::remove_SQL_all() +{ + QSqlQuery sql_query; + QString delete_sql = "delete from MusicInfo where name = ?"; + sql_query.prepare(delete_sql); + sql_query.addBindValue(name); + sql_query.exec(); +} + +void MusicList::insert_SQL_all() +{ + for(auto i=music.begin();i!=music.end();i++){ + i->insertSQL(name); + } +} + +void MusicList::read_fromSQL() +{ + QSqlQuery sql_query; + QString select_sql = "select url, author, title, duration, albumTitle, audioBitRate from MusicInfo where name = ?"; + sql_query.prepare(select_sql); + sql_query.addBindValue(name); + if(sql_query.exec()) + { + while(sql_query.next()) + { + Music tempMusic; + tempMusic.url=QUrl(sql_query.value(0).toString()); + tempMusic.author=sql_query.value(1).toString(); + tempMusic.title=sql_query.value(2).toString(); + tempMusic.duration=sql_query.value(3).toLongLong(); + tempMusic.albumTitle=sql_query.value(4).toString(); + tempMusic.audioBitRate=sql_query.value(5).toInt(); + music.push_back(tempMusic); + } + } +} + +void MusicList::sort_by(COMPARE key) +{ + sort(music.begin(),music.end(),MusicCompare(key)); + if(sql_flag){ + remove_SQL_all(); + insert_SQL_all(); + } +} + +void MusicList::neaten() +{ + sort(music.begin(),music.end(),MusicCompare(DEFAULT)); + music.erase(unique(music.begin(),music.end(),MusicCompare(EQUALITY)), music.end()); + if(sql_flag){ + remove_SQL_all(); + insert_SQL_all(); + } +} + +void MusicList::clear() +{ + music.clear(); + if(sql_flag){ + remove_SQL_all(); + } +} diff --git a/LightMusicPlayer/LightMusicPlayer/MusicList.h b/LightMusicPlayer/LightMusicPlayer/MusicList.h new file mode 100644 index 0000000..69bd2e5 --- /dev/null +++ b/LightMusicPlayer/LightMusicPlayer/MusicList.h @@ -0,0 +1,61 @@ +#ifndef MUSICLIST_H +#define MUSICLIST_H +#include +using namespace std; + +#include"Music.h" +#include +#include + +class MusicListWidget; +//歌曲列表 +class MusicList +{ + //歌单名 + QString name; + //所存储的歌曲 + vector music; + + //控制是否需要与数据库交互(比如:当前播放列表的歌单删除歌曲时不需要更新数据库,只是临时的) + bool sql_flag=true; + + friend class MainWidget; +public: + MusicList(){} + MusicList(const QList& urls,QString iname=""); + //设定歌单名 + void setName(const QString& iname){name=iname;} + QString getName(){ return name; } + //设定数据库标志 + void setSQL(bool on){ sql_flag=on; } + //从url添加歌曲 + void addMusic(const QList& urls); + //添加一首歌曲 + void addMusic(const Music& iMusic); + //获取指定位置的歌曲 + Music getMusic(int pos); + //将本歌单加入播放列表 + void addToPlayList(QMediaPlaylist *playlist); + //歌单可视化 + void addToListWidget(MusicListWidget *listWidget); + //移除指定的歌曲 + void removeMusic(int pos); + //在文件夹中打开 + void showInExplorer(int pos); + //显示指定歌曲详细信息 + void detail(int pos); + //数据库中移除全部本歌单的歌曲 + void remove_SQL_all(); + //将歌单中的歌曲全部写入数据库 + void insert_SQL_all(); + //从数据中恢复本歌单 + void read_fromSQL(); + //将本列表中的歌曲排序 + void sort_by(COMPARE key); + //整理歌单:将歌单中的重复歌曲去掉并排序 + void neaten(); + //清空本歌单 + void clear(); +}; + +#endif // MUSICLIST_H diff --git a/LightMusicPlayer/LightMusicPlayer/MusicListDialog.cpp b/LightMusicPlayer/LightMusicPlayer/MusicListDialog.cpp new file mode 100644 index 0000000..08f7072 --- /dev/null +++ b/LightMusicPlayer/LightMusicPlayer/MusicListDialog.cpp @@ -0,0 +1,30 @@ +#include "MusicListDialog.h" +#include "ui_MusicListDialog.h" + +MusicListDialog::MusicListDialog(QWidget *parent) : + QDialog(parent), + ui(new Ui::MusicListDialog) +{ + ui->setupUi(this); +} + +MusicListDialog::~MusicListDialog() +{ + delete ui; +} + +void MusicListDialog::setMusicList(MusicList &ilist, bool *results) +{ + selected_flag=results; + ui->listWidget->setIcon(QIcon(":/image/image/image/dialog-music.png")); + ilist.addToListWidget(ui->listWidget); + num=ui->listWidget->count(); + +} + +void MusicListDialog::on_buttonBox_accepted() +{ + for(int i=0;ilistWidget->item(i)->isSelected(); + } +} diff --git a/LightMusicPlayer/LightMusicPlayer/MusicListDialog.h b/LightMusicPlayer/LightMusicPlayer/MusicListDialog.h new file mode 100644 index 0000000..1ad88a2 --- /dev/null +++ b/LightMusicPlayer/LightMusicPlayer/MusicListDialog.h @@ -0,0 +1,34 @@ +#ifndef MUSICLISTDIALOG_H +#define MUSICLISTDIALOG_H + +#include +#include "MusicList.h" +#include "MusicListWidget.h" + +namespace Ui { +class MusicListDialog; +} + +class MusicListDialog : public QDialog +{ + Q_OBJECT + //歌曲数量 + int num; + //存放歌曲条目是否被选择(用于返回选择结果) + bool *selected_flag; +public: + explicit MusicListDialog(QWidget *parent = nullptr); + ~MusicListDialog(); + + //设定对话框展示出的歌单以及选择结果存放的地方 + void setMusicList(MusicList& ilist, bool *results); + +private slots: + + void on_buttonBox_accepted(); + +private: + Ui::MusicListDialog *ui; +}; + +#endif // MUSICLISTDIALOG_H diff --git a/LightMusicPlayer/LightMusicPlayer/MusicListDialog.ui b/LightMusicPlayer/LightMusicPlayer/MusicListDialog.ui new file mode 100644 index 0000000..8b43dbb --- /dev/null +++ b/LightMusicPlayer/LightMusicPlayer/MusicListDialog.ui @@ -0,0 +1,152 @@ + + + MusicListDialog + + + + 0 + 0 + 801 + 491 + + + + + 0 + 0 + + + + + 801 + 491 + + + + + 801 + 491 + + + + 添加歌曲 + + + + + 430 + 440 + 341 + 32 + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + 30 + 50 + 741 + 381 + + + + + 0 + 0 + + + + + 微软雅黑 + 75 + true + + + + + + + Qt::ScrollBarAsNeeded + + + QAbstractScrollArea::AdjustIgnored + + + QAbstractItemView::MultiSelection + + + QAbstractItemView::SelectRows + + + + + + 40 + 20 + 731 + 31 + + + + + Microsoft YaHei UI + 8 + 50 + false + + + + 注:此处为多选模式,单击或者按住拖动即可选择相应歌曲 + + + + + + MusicListWidget + QListWidget +
MusicListWidget.h
+
+
+ + + + buttonBox + accepted() + MusicListDialog + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + MusicListDialog + reject() + + + 316 + 260 + + + 286 + 274 + + + + +
diff --git a/LightMusicPlayer/LightMusicPlayer/MusicListWidget.cpp b/LightMusicPlayer/LightMusicPlayer/MusicListWidget.cpp new file mode 100644 index 0000000..ebb6a53 --- /dev/null +++ b/LightMusicPlayer/LightMusicPlayer/MusicListWidget.cpp @@ -0,0 +1,52 @@ +#include "MusicListWidget.h" + +MusicListWidget::MusicListWidget(QWidget *parent) + :QListWidget (parent) +{ + +} + +void MusicListWidget::refresh() +{ + clear();//先清空 + musicList.addToListWidget(this); +} + +void MusicListWidget::setMusicList(const MusicList &music) +{ + musicList=music; + refresh(); +} + +void MusicListWidget::setMusicList_playing(const MusicList &music) +{ + musicList=music; + musicList.setSQL(false); + refresh(); +} + +void MusicListWidget::removeMusic() +{ + int pos=currentRow(); + //移除 + musicList.removeMusic(pos); + //实测这里如果直接使用removeMedia会导致当前播放的歌曲乱跳...(所以这里只能从更上层调用的地方来移除正在播放的歌曲) + //playlist->removeMedia(pos); + + //从ListWidget中移除 + QListWidgetItem *tempItem=takeItem(pos); + removeItemWidget(tempItem); + delete tempItem; +} + +void MusicListWidget::showInExplorer() +{ + int pos=currentRow(); + musicList.showInExplorer(pos); +} + +void MusicListWidget::detail() +{ + int pos=currentRow(); + musicList.detail(pos); +} diff --git a/LightMusicPlayer/LightMusicPlayer/MusicListWidget.h b/LightMusicPlayer/LightMusicPlayer/MusicListWidget.h new file mode 100644 index 0000000..a534e04 --- /dev/null +++ b/LightMusicPlayer/LightMusicPlayer/MusicListWidget.h @@ -0,0 +1,37 @@ +#ifndef MYLISTWIDGET_H +#define MYLISTWIDGET_H + +#include +#include + +class MusicListWidget:public QListWidget +{ + Q_OBJECT + //当前歌曲列表(存储的是歌曲信息) + MusicList musicList; + //当前展示列表项使用的图标 + QIcon icon=QIcon(":/image/image/image/music.png"); +public: + MusicListWidget(QWidget *parent = Q_NULLPTR); + //刷新显示(当musicList有所变化时,需要调用) + void refresh(); + //设置歌曲列表 + void setMusicList(const MusicList& music); + //设置播放列表 + void setMusicList_playing(const MusicList& music); + //移除歌曲 + void removeMusic(); + //在文件夹中打开 + void showInExplorer(); + //歌曲详情 + void detail(); + //设置/获取图标Icon + void setIcon(QIcon iicon){ icon=iicon; } + QIcon getIcon(){ return icon; } + + friend class MainWidget; +private: + +}; + +#endif // MYLISTWIDGET_H diff --git a/LightMusicPlayer/LightMusicPlayer/image/background/default.jpg b/LightMusicPlayer/LightMusicPlayer/image/background/default.jpg new file mode 100644 index 0000000..25beb76 Binary files /dev/null and b/LightMusicPlayer/LightMusicPlayer/image/background/default.jpg differ diff --git a/LightMusicPlayer/LightMusicPlayer/image/image-hover/add-hover.png b/LightMusicPlayer/LightMusicPlayer/image/image-hover/add-hover.png new file mode 100644 index 0000000..0e2fd1e Binary files /dev/null and b/LightMusicPlayer/LightMusicPlayer/image/image-hover/add-hover.png differ diff --git a/LightMusicPlayer/LightMusicPlayer/image/image-hover/loop-hover.png b/LightMusicPlayer/LightMusicPlayer/image/image-hover/loop-hover.png new file mode 100644 index 0000000..975fe09 Binary files /dev/null and b/LightMusicPlayer/LightMusicPlayer/image/image-hover/loop-hover.png differ diff --git a/LightMusicPlayer/LightMusicPlayer/image/image-hover/loop-one-hover.png b/LightMusicPlayer/LightMusicPlayer/image/image-hover/loop-one-hover.png new file mode 100644 index 0000000..427f294 Binary files /dev/null and b/LightMusicPlayer/LightMusicPlayer/image/image-hover/loop-one-hover.png differ diff --git a/LightMusicPlayer/LightMusicPlayer/image/image-hover/music-voice-hover.png b/LightMusicPlayer/LightMusicPlayer/image/image-hover/music-voice-hover.png new file mode 100644 index 0000000..9af782e Binary files /dev/null and b/LightMusicPlayer/LightMusicPlayer/image/image-hover/music-voice-hover.png differ diff --git a/LightMusicPlayer/LightMusicPlayer/image/image-hover/next-hover.png b/LightMusicPlayer/LightMusicPlayer/image/image-hover/next-hover.png new file mode 100644 index 0000000..9b1fe8e Binary files /dev/null and b/LightMusicPlayer/LightMusicPlayer/image/image-hover/next-hover.png differ diff --git a/LightMusicPlayer/LightMusicPlayer/image/image-hover/pase-hover.png b/LightMusicPlayer/LightMusicPlayer/image/image-hover/pase-hover.png new file mode 100644 index 0000000..af2c44a Binary files /dev/null and b/LightMusicPlayer/LightMusicPlayer/image/image-hover/pase-hover.png differ diff --git a/LightMusicPlayer/LightMusicPlayer/image/image-hover/play-hover.png b/LightMusicPlayer/LightMusicPlayer/image/image-hover/play-hover.png new file mode 100644 index 0000000..cb60cc8 Binary files /dev/null and b/LightMusicPlayer/LightMusicPlayer/image/image-hover/play-hover.png differ diff --git a/LightMusicPlayer/LightMusicPlayer/image/image-hover/play-random-hover.png b/LightMusicPlayer/LightMusicPlayer/image/image-hover/play-random-hover.png new file mode 100644 index 0000000..64dd3d4 Binary files /dev/null and b/LightMusicPlayer/LightMusicPlayer/image/image-hover/play-random-hover.png differ diff --git a/LightMusicPlayer/LightMusicPlayer/image/image-hover/pre-hover.png b/LightMusicPlayer/LightMusicPlayer/image/image-hover/pre-hover.png new file mode 100644 index 0000000..1054942 Binary files /dev/null and b/LightMusicPlayer/LightMusicPlayer/image/image-hover/pre-hover.png differ diff --git a/LightMusicPlayer/LightMusicPlayer/image/image/MusicListItem.png b/LightMusicPlayer/LightMusicPlayer/image/image/MusicListItem.png new file mode 100644 index 0000000..549ef03 Binary files /dev/null and b/LightMusicPlayer/LightMusicPlayer/image/image/MusicListItem.png differ diff --git a/LightMusicPlayer/LightMusicPlayer/image/image/MyPlayer.png b/LightMusicPlayer/LightMusicPlayer/image/image/MyPlayer.png new file mode 100644 index 0000000..a32a4d6 Binary files /dev/null and b/LightMusicPlayer/LightMusicPlayer/image/image/MyPlayer.png differ diff --git a/LightMusicPlayer/LightMusicPlayer/image/image/Title.png b/LightMusicPlayer/LightMusicPlayer/image/image/Title.png new file mode 100644 index 0000000..d311a6e Binary files /dev/null and b/LightMusicPlayer/LightMusicPlayer/image/image/Title.png differ diff --git a/LightMusicPlayer/LightMusicPlayer/image/image/To-like.png b/LightMusicPlayer/LightMusicPlayer/image/image/To-like.png new file mode 100644 index 0000000..3cea90a Binary files /dev/null and b/LightMusicPlayer/LightMusicPlayer/image/image/To-like.png differ diff --git a/LightMusicPlayer/LightMusicPlayer/image/image/To-playlist.png b/LightMusicPlayer/LightMusicPlayer/image/image/To-playlist.png new file mode 100644 index 0000000..30fac17 Binary files /dev/null and b/LightMusicPlayer/LightMusicPlayer/image/image/To-playlist.png differ diff --git a/LightMusicPlayer/LightMusicPlayer/image/image/about.png b/LightMusicPlayer/LightMusicPlayer/image/image/about.png new file mode 100644 index 0000000..5d92e3e Binary files /dev/null and b/LightMusicPlayer/LightMusicPlayer/image/image/about.png differ diff --git a/LightMusicPlayer/LightMusicPlayer/image/image/add.png b/LightMusicPlayer/LightMusicPlayer/image/image/add.png new file mode 100644 index 0000000..3197e36 Binary files /dev/null and b/LightMusicPlayer/LightMusicPlayer/image/image/add.png differ diff --git a/LightMusicPlayer/LightMusicPlayer/image/image/addFromLocal.png b/LightMusicPlayer/LightMusicPlayer/image/image/addFromLocal.png new file mode 100644 index 0000000..00b2e88 Binary files /dev/null and b/LightMusicPlayer/LightMusicPlayer/image/image/addFromLocal.png differ diff --git a/LightMusicPlayer/LightMusicPlayer/image/image/clear.png b/LightMusicPlayer/LightMusicPlayer/image/image/clear.png new file mode 100644 index 0000000..fd5031d Binary files /dev/null and b/LightMusicPlayer/LightMusicPlayer/image/image/clear.png differ diff --git a/LightMusicPlayer/LightMusicPlayer/image/image/current-music.png b/LightMusicPlayer/LightMusicPlayer/image/image/current-music.png new file mode 100644 index 0000000..532d7e7 Binary files /dev/null and b/LightMusicPlayer/LightMusicPlayer/image/image/current-music.png differ diff --git a/LightMusicPlayer/LightMusicPlayer/image/image/default.png b/LightMusicPlayer/LightMusicPlayer/image/image/default.png new file mode 100644 index 0000000..39fcd47 Binary files /dev/null and b/LightMusicPlayer/LightMusicPlayer/image/image/default.png differ diff --git a/LightMusicPlayer/LightMusicPlayer/image/image/detail.png b/LightMusicPlayer/LightMusicPlayer/image/image/detail.png new file mode 100644 index 0000000..47457bc Binary files /dev/null and b/LightMusicPlayer/LightMusicPlayer/image/image/detail.png differ diff --git a/LightMusicPlayer/LightMusicPlayer/image/image/dialog-music.png b/LightMusicPlayer/LightMusicPlayer/image/image/dialog-music.png new file mode 100644 index 0000000..fc23ba8 Binary files /dev/null and b/LightMusicPlayer/LightMusicPlayer/image/image/dialog-music.png differ diff --git a/LightMusicPlayer/LightMusicPlayer/image/image/duration.png b/LightMusicPlayer/LightMusicPlayer/image/image/duration.png new file mode 100644 index 0000000..0edbd8f Binary files /dev/null and b/LightMusicPlayer/LightMusicPlayer/image/image/duration.png differ diff --git a/LightMusicPlayer/LightMusicPlayer/image/image/exit.png b/LightMusicPlayer/LightMusicPlayer/image/image/exit.png new file mode 100644 index 0000000..1ed7339 Binary files /dev/null and b/LightMusicPlayer/LightMusicPlayer/image/image/exit.png differ diff --git a/LightMusicPlayer/LightMusicPlayer/image/image/favo-music.png b/LightMusicPlayer/LightMusicPlayer/image/image/favo-music.png new file mode 100644 index 0000000..a5986fd Binary files /dev/null and b/LightMusicPlayer/LightMusicPlayer/image/image/favo-music.png differ diff --git a/LightMusicPlayer/LightMusicPlayer/image/image/like.png b/LightMusicPlayer/LightMusicPlayer/image/image/like.png new file mode 100644 index 0000000..94f8e5b Binary files /dev/null and b/LightMusicPlayer/LightMusicPlayer/image/image/like.png differ diff --git a/LightMusicPlayer/LightMusicPlayer/image/image/local-music.png b/LightMusicPlayer/LightMusicPlayer/image/image/local-music.png new file mode 100644 index 0000000..9a1ea9d Binary files /dev/null and b/LightMusicPlayer/LightMusicPlayer/image/image/local-music.png differ diff --git a/LightMusicPlayer/LightMusicPlayer/image/image/loop-one.png b/LightMusicPlayer/LightMusicPlayer/image/image/loop-one.png new file mode 100644 index 0000000..4d101aa Binary files /dev/null and b/LightMusicPlayer/LightMusicPlayer/image/image/loop-one.png differ diff --git a/LightMusicPlayer/LightMusicPlayer/image/image/loop-one2.png b/LightMusicPlayer/LightMusicPlayer/image/image/loop-one2.png new file mode 100644 index 0000000..9f82cf2 Binary files /dev/null and b/LightMusicPlayer/LightMusicPlayer/image/image/loop-one2.png differ diff --git a/LightMusicPlayer/LightMusicPlayer/image/image/loop.png b/LightMusicPlayer/LightMusicPlayer/image/image/loop.png new file mode 100644 index 0000000..0466e0e Binary files /dev/null and b/LightMusicPlayer/LightMusicPlayer/image/image/loop.png differ diff --git a/LightMusicPlayer/LightMusicPlayer/image/image/loop2.png b/LightMusicPlayer/LightMusicPlayer/image/image/loop2.png new file mode 100644 index 0000000..f723ab7 Binary files /dev/null and b/LightMusicPlayer/LightMusicPlayer/image/image/loop2.png differ diff --git a/LightMusicPlayer/LightMusicPlayer/image/image/lyric.png b/LightMusicPlayer/LightMusicPlayer/image/image/lyric.png new file mode 100644 index 0000000..8f77a62 Binary files /dev/null and b/LightMusicPlayer/LightMusicPlayer/image/image/lyric.png differ diff --git a/LightMusicPlayer/LightMusicPlayer/image/image/min.png b/LightMusicPlayer/LightMusicPlayer/image/image/min.png new file mode 100644 index 0000000..30580bc Binary files /dev/null and b/LightMusicPlayer/LightMusicPlayer/image/image/min.png differ diff --git a/LightMusicPlayer/LightMusicPlayer/image/image/music-dir.png b/LightMusicPlayer/LightMusicPlayer/image/image/music-dir.png new file mode 100644 index 0000000..990050b Binary files /dev/null and b/LightMusicPlayer/LightMusicPlayer/image/image/music-dir.png differ diff --git a/LightMusicPlayer/LightMusicPlayer/image/image/music-file.png b/LightMusicPlayer/LightMusicPlayer/image/image/music-file.png new file mode 100644 index 0000000..2689276 Binary files /dev/null and b/LightMusicPlayer/LightMusicPlayer/image/image/music-file.png differ diff --git a/LightMusicPlayer/LightMusicPlayer/image/image/music-playing.png b/LightMusicPlayer/LightMusicPlayer/image/image/music-playing.png new file mode 100644 index 0000000..422c958 Binary files /dev/null and b/LightMusicPlayer/LightMusicPlayer/image/image/music-playing.png differ diff --git a/LightMusicPlayer/LightMusicPlayer/image/image/music-voice.png b/LightMusicPlayer/LightMusicPlayer/image/image/music-voice.png new file mode 100644 index 0000000..09f3c4f Binary files /dev/null and b/LightMusicPlayer/LightMusicPlayer/image/image/music-voice.png differ diff --git a/LightMusicPlayer/LightMusicPlayer/image/image/music.png b/LightMusicPlayer/LightMusicPlayer/image/image/music.png new file mode 100644 index 0000000..74d52b6 Binary files /dev/null and b/LightMusicPlayer/LightMusicPlayer/image/image/music.png differ diff --git a/LightMusicPlayer/LightMusicPlayer/image/image/music_list.png b/LightMusicPlayer/LightMusicPlayer/image/image/music_list.png new file mode 100644 index 0000000..cbbf1d7 Binary files /dev/null and b/LightMusicPlayer/LightMusicPlayer/image/image/music_list.png differ diff --git a/LightMusicPlayer/LightMusicPlayer/image/image/myMusicList.png b/LightMusicPlayer/LightMusicPlayer/image/image/myMusicList.png new file mode 100644 index 0000000..3dbfe8a Binary files /dev/null and b/LightMusicPlayer/LightMusicPlayer/image/image/myMusicList.png differ diff --git a/LightMusicPlayer/LightMusicPlayer/image/image/next.png b/LightMusicPlayer/LightMusicPlayer/image/image/next.png new file mode 100644 index 0000000..7c6820f Binary files /dev/null and b/LightMusicPlayer/LightMusicPlayer/image/image/next.png differ diff --git a/LightMusicPlayer/LightMusicPlayer/image/image/next2.png b/LightMusicPlayer/LightMusicPlayer/image/image/next2.png new file mode 100644 index 0000000..e59d686 Binary files /dev/null and b/LightMusicPlayer/LightMusicPlayer/image/image/next2.png differ diff --git a/LightMusicPlayer/LightMusicPlayer/image/image/non-music.png b/LightMusicPlayer/LightMusicPlayer/image/image/non-music.png new file mode 100644 index 0000000..82cf9cf Binary files /dev/null and b/LightMusicPlayer/LightMusicPlayer/image/image/non-music.png differ diff --git a/LightMusicPlayer/LightMusicPlayer/image/image/pase.png b/LightMusicPlayer/LightMusicPlayer/image/image/pase.png new file mode 100644 index 0000000..e270087 Binary files /dev/null and b/LightMusicPlayer/LightMusicPlayer/image/image/pase.png differ diff --git a/LightMusicPlayer/LightMusicPlayer/image/image/pause2.png b/LightMusicPlayer/LightMusicPlayer/image/image/pause2.png new file mode 100644 index 0000000..a67da3f Binary files /dev/null and b/LightMusicPlayer/LightMusicPlayer/image/image/pause2.png differ diff --git a/LightMusicPlayer/LightMusicPlayer/image/image/play-random.png b/LightMusicPlayer/LightMusicPlayer/image/image/play-random.png new file mode 100644 index 0000000..8d5c871 Binary files /dev/null and b/LightMusicPlayer/LightMusicPlayer/image/image/play-random.png differ diff --git a/LightMusicPlayer/LightMusicPlayer/image/image/play.png b/LightMusicPlayer/LightMusicPlayer/image/image/play.png new file mode 100644 index 0000000..1c4f7d3 Binary files /dev/null and b/LightMusicPlayer/LightMusicPlayer/image/image/play.png differ diff --git a/LightMusicPlayer/LightMusicPlayer/image/image/play2.png b/LightMusicPlayer/LightMusicPlayer/image/image/play2.png new file mode 100644 index 0000000..e4d8da6 Binary files /dev/null and b/LightMusicPlayer/LightMusicPlayer/image/image/play2.png differ diff --git a/LightMusicPlayer/LightMusicPlayer/image/image/pre.png b/LightMusicPlayer/LightMusicPlayer/image/image/pre.png new file mode 100644 index 0000000..d524e39 Binary files /dev/null and b/LightMusicPlayer/LightMusicPlayer/image/image/pre.png differ diff --git a/LightMusicPlayer/LightMusicPlayer/image/image/pre2.png b/LightMusicPlayer/LightMusicPlayer/image/image/pre2.png new file mode 100644 index 0000000..ccfb288 Binary files /dev/null and b/LightMusicPlayer/LightMusicPlayer/image/image/pre2.png differ diff --git a/LightMusicPlayer/LightMusicPlayer/image/image/quit.png b/LightMusicPlayer/LightMusicPlayer/image/image/quit.png new file mode 100644 index 0000000..b6ff351 Binary files /dev/null and b/LightMusicPlayer/LightMusicPlayer/image/image/quit.png differ diff --git a/LightMusicPlayer/LightMusicPlayer/image/image/random2.png b/LightMusicPlayer/LightMusicPlayer/image/image/random2.png new file mode 100644 index 0000000..7b79fc6 Binary files /dev/null and b/LightMusicPlayer/LightMusicPlayer/image/image/random2.png differ diff --git a/LightMusicPlayer/LightMusicPlayer/image/image/remove.png b/LightMusicPlayer/LightMusicPlayer/image/image/remove.png new file mode 100644 index 0000000..2bcb4c7 Binary files /dev/null and b/LightMusicPlayer/LightMusicPlayer/image/image/remove.png differ diff --git a/LightMusicPlayer/LightMusicPlayer/image/image/remove_dup.png b/LightMusicPlayer/LightMusicPlayer/image/image/remove_dup.png new file mode 100644 index 0000000..21d4ae2 Binary files /dev/null and b/LightMusicPlayer/LightMusicPlayer/image/image/remove_dup.png differ diff --git a/LightMusicPlayer/LightMusicPlayer/image/image/setting.png b/LightMusicPlayer/LightMusicPlayer/image/image/setting.png new file mode 100644 index 0000000..f8206c5 Binary files /dev/null and b/LightMusicPlayer/LightMusicPlayer/image/image/setting.png differ diff --git a/LightMusicPlayer/LightMusicPlayer/image/image/singer.png b/LightMusicPlayer/LightMusicPlayer/image/image/singer.png new file mode 100644 index 0000000..901c26d Binary files /dev/null and b/LightMusicPlayer/LightMusicPlayer/image/image/singer.png differ diff --git a/LightMusicPlayer/LightMusicPlayer/image/image/skin.png b/LightMusicPlayer/LightMusicPlayer/image/image/skin.png new file mode 100644 index 0000000..f6cbd4f Binary files /dev/null and b/LightMusicPlayer/LightMusicPlayer/image/image/skin.png differ diff --git a/LightMusicPlayer/LightMusicPlayer/image/image/sliderHandle.png b/LightMusicPlayer/LightMusicPlayer/image/image/sliderHandle.png new file mode 100644 index 0000000..b040bc7 Binary files /dev/null and b/LightMusicPlayer/LightMusicPlayer/image/image/sliderHandle.png differ diff --git a/LightMusicPlayer/LightMusicPlayer/image/image/sort-alpha-asc_ea48_ether.png b/LightMusicPlayer/LightMusicPlayer/image/image/sort-alpha-asc_ea48_ether.png new file mode 100644 index 0000000..a554da2 Binary files /dev/null and b/LightMusicPlayer/LightMusicPlayer/image/image/sort-alpha-asc_ea48_ether.png differ diff --git a/LightMusicPlayer/LightMusicPlayer/image/image/systemTrayIcon.png b/LightMusicPlayer/LightMusicPlayer/image/image/systemTrayIcon.png new file mode 100644 index 0000000..b3f0ceb Binary files /dev/null and b/LightMusicPlayer/LightMusicPlayer/image/image/systemTrayIcon.png differ diff --git a/LightMusicPlayer/LightMusicPlayer/image/image/volumeHandle.png b/LightMusicPlayer/LightMusicPlayer/image/image/volumeHandle.png new file mode 100644 index 0000000..9fdaebe Binary files /dev/null and b/LightMusicPlayer/LightMusicPlayer/image/image/volumeHandle.png differ diff --git a/LightMusicPlayer/LightMusicPlayer/imagefile.qrc b/LightMusicPlayer/LightMusicPlayer/imagefile.qrc new file mode 100644 index 0000000..24070ea --- /dev/null +++ b/LightMusicPlayer/LightMusicPlayer/imagefile.qrc @@ -0,0 +1,66 @@ + + + image/background/default.jpg + image/image/quit.png + image/image-hover/pase-hover.png + image/image-hover/play-hover.png + image/image/pase.png + image/image/play.png + image/image/next.png + image/image/pre.png + image/image-hover/next-hover.png + image/image-hover/pre-hover.png + image/image/sliderHandle.png + image/image/loop.png + image/image/loop-one.png + image/image/play-random.png + image/image-hover/loop-hover.png + image/image-hover/loop-one-hover.png + image/image-hover/play-random-hover.png + image/image/min.png + image/image/add.png + image/image-hover/add-hover.png + image/image/volumeHandle.png + image/image-hover/music-voice-hover.png + image/image/local-music.png + image/image/favo-music.png + image/image/current-music.png + image/image/music-file.png + image/image/music-playing.png + image/image/detail.png + image/image/music-dir.png + image/image/remove.png + image/image/To-playlist.png + image/image/music.png + image/image/music-voice.png + image/image/like.png + image/image/To-like.png + image/image/music_list.png + image/image/myMusicList.png + image/image/default.png + image/image/setting.png + image/image/skin.png + image/image/dialog-music.png + image/image/MusicListItem.png + image/image/next2.png + image/image/pause2.png + image/image/play2.png + image/image/pre2.png + image/image/exit.png + image/image/loop2.png + image/image/loop-one2.png + image/image/random2.png + image/image/systemTrayIcon.png + image/image/singer.png + image/image/duration.png + image/image/sort-alpha-asc_ea48_ether.png + image/image/addFromLocal.png + image/image/non-music.png + image/image/Title.png + image/image/lyric.png + image/image/clear.png + image/image/remove_dup.png + image/image/about.png + image/image/MyPlayer.png + + diff --git a/LightMusicPlayer/LightMusicPlayer/main.cpp b/LightMusicPlayer/LightMusicPlayer/main.cpp new file mode 100644 index 0000000..3f213b7 --- /dev/null +++ b/LightMusicPlayer/LightMusicPlayer/main.cpp @@ -0,0 +1,11 @@ +#include "MainWidget.h" +#include + +int main(int argc, char *argv[]) +{ + QApplication a(argc, argv); + MainWidget w; + w.show(); + + return a.exec(); +} diff --git a/LightMusicPlayer/LightMusicPlayer/mainWidget.h b/LightMusicPlayer/LightMusicPlayer/mainWidget.h new file mode 100644 index 0000000..9865f66 --- /dev/null +++ b/LightMusicPlayer/LightMusicPlayer/mainWidget.h @@ -0,0 +1,165 @@ +#ifndef MAINWIDGET_H +#define MAINWIDGET_H + +#include +#include +#include +#include +#include +#include "MusicList.h" +#include "LyricWidget.h" +#include + + +namespace Ui { +class Widget; +} + +class MainWidget : public QWidget +{ + Q_OBJECT + +public: + explicit MainWidget(QWidget *parent = nullptr); + ~MainWidget() override; + +private: + Ui::Widget *ui; + void paintEvent(QPaintEvent *event) override; + + //UI组件额外的一些处理 + void init_UI(); + + //当前播放器 + QMediaPlayer *player; + //当前播放列表 + QMediaPlaylist *playlist; + //初始化一些成员变量以及connect连接 + void init_play(); + //更新播放信息相关(进度、信息等) + void updatePosition(qint64 position); + void updateDuration(qint64 duration); + void setPosition(int position); + void updateInfo(); + void updatePlayBtn(); + + //系统托盘 + QSystemTrayIcon *mySystemTray; + QAction *action_systemTray_play; + QAction *action_systemTray_playmode; + //响应系统托盘的动作(双击等) + void systemTrayIcon_activated(QSystemTrayIcon::ActivationReason reason); + //退出应用 + void quitMusicPlayer(); + //系统托盘初始化 + void init_systemTrayIcon(); + + //数据库初始化 + void init_sqlite(); + //配置初始化(配置文件读取) + void init_settings(); + //“本地音乐”、“我喜欢”等歌单的初始化 + void init_musicList(); + + //歌单 + vector musiclist; + //用于标识现在展示的是哪个歌单 + int musiclist_index=-1; + //更新展示歌单名字的listwidget + void namelist_refresh(); + //用于更新展示歌单内容的listwidget + void musicListWidget_refresh(); + + /*右键菜单*/ + //菜单项的初始化 + void init_actions(); + //“当前播放”列表的右键菜单 + QMenu *menu_playlist; + //“本地音乐”列表的右键菜单 + QMenu *menu_locallist; + //“我喜欢”列表的右键菜单 + QMenu *menu_favorlist; + //“歌单名列表”的右键菜单 + QMenu *menu_namelist; + //“歌单展示列表”的右键菜单 + QMenu *menu_musiclist; + //更换皮肤的菜单 + QMenu *menu_changeSkin; + +protected: + //窗口拖动时记录的起始点 + QPoint offset; + /*重写Widget的一些方法*/ + //实现窗口可拖动 + void mousePressEvent(QMouseEvent *event) override; + void mouseMoveEvent(QMouseEvent *event) override; + void mouseReleaseEvent(QMouseEvent *event) override; + //关闭时不退出,而是到系统托盘 + void closeEvent(QCloseEvent *event) override; + //拖拽文件进入 + void dragEnterEvent(QDragEnterEvent* event) override; + void dropEvent(QDropEvent* event) override; + +private slots: + /*部分右键菜单项对应的操作(即对应QAction连接的槽函数)*/ + void playlist_removeMusic();//当前播放列表-右键菜单 移除歌曲 + void play_to_favor();//从当前播放添加到我喜欢 + void local_to_favor();//从本地音乐添加到我喜欢 + void local_to_playlist();//从本地音乐添加到当前播放列表 + void favor_to_playlist();//从我喜欢添加到当前播放列表 + void namelist_delete();//移除歌单 + void musiclist_removeMusic();//从歌单展示列表移除歌曲 + void musiclist_to_favor();//从当前歌单添加到我喜欢 + void musiclist_to_playlist();//从当前歌单添加到正在播放 + void background_to_default();//换到默认背景 + void background_setting();//自定义背景 + + /*一些点击事件的响应(使用.ui中的部件“转到槽”自动生成)*/ + void on_btnCurMusic_clicked(); + void on_btnLocalMusic_clicked(); + void on_btnFavorMusic_clicked(); + void on_btnQuit_clicked(); + void on_btnMin_clicked(); + void on_btnPlay_clicked(); + void on_btnNext_clicked(); + void on_btnPre_clicked(); + void on_btnPlayMode_clicked(); + void on_btnAdd_clicked(); + void on_btnVolume_clicked(); + void on_volumeSlider_valueChanged(int value); + void on_btnAddMusicList_clicked(); + void on_playListWidget_doubleClicked(const QModelIndex &index); + void on_localMusicWidget_doubleClicked(const QModelIndex &index); + void on_favorMusicWidget_doubleClicked(const QModelIndex &index); + void on_playListWidget_customContextMenuRequested(const QPoint &pos); + void on_localMusicWidget_customContextMenuRequested(const QPoint &pos); + void on_favorMusicWidget_customContextMenuRequested(const QPoint &pos); + void on_nameListWidget_customContextMenuRequested(const QPoint &pos); + void on_nameListWidget_doubleClicked(const QModelIndex &index); + void on_btnSkin_clicked(); + void on_btnAddtoMusicList_clicked(); + void on_musicListWidget_doubleClicked(const QModelIndex &index); + void on_musicListWidget_customContextMenuRequested(const QPoint &pos); + void on_btnAddtoFavor_clicked(); + void on_btnNeaten_clicked();//整理歌单按钮 + void on_btnNeaten_2_clicked(); + void on_btnNeaten_3_clicked(); + void on_btnTitle_clicked(); + void on_btnLyric_clicked(); + void on_btnClear_clicked();//清空 + void on_btnClear_2_clicked(); + void on_btnClear_3_clicked(); + void on_btnClear_4_clicked(); + void on_btnAbout_clicked(); + void on_btnSortSinger_clicked();//歌单排序 + void on_btnSortTitle_clicked(); + void on_btnSortDuration_clicked(); + void on_btnSortSinger_2_clicked(); + void on_btnSortTitle_2_clicked(); + void on_btnSortDuration_2_clicked(); + void on_btnSortSinger_4_clicked(); + void on_btnSortTitle_4_clicked(); + void on_btnSortDuration_4_clicked(); +}; + +#endif // MAINWIDGET_H diff --git a/LightMusicPlayer/LightMusicPlayer/mainWidget.ui b/LightMusicPlayer/LightMusicPlayer/mainWidget.ui new file mode 100644 index 0000000..3f8693a --- /dev/null +++ b/LightMusicPlayer/LightMusicPlayer/mainWidget.ui @@ -0,0 +1,2390 @@ + + + Widget + + + + 0 + 0 + 1200 + 800 + + + + + 1200 + 800 + + + + + 1200 + 800 + + + + true + + + Widget + + + + + + QWidget#Widget{ +border-radius:10px; +border-image: url(:/image/image/background/default.jpg); +} + + + + + + 466 + 710 + 311 + 61 + + + + + 0 + + + + + + 0 + 35 + + + + PointingHandCursor + + + 上一首 + + + QPushButton +{ +background-image: url(:/image/image/image/pre.png); +background-repeat:no-repeat; +background-position:center center; +border:none; +} +QPushButton:hover{ +background-image: url(:/image/image/image-hover/pre-hover.png); +background-repeat:no-repeat; +background-position:center center; +} +QPushButton:pressed{ +background-image: url(:/image/image/image/pre.png); +background-repeat:no-repeat; +background-position:center center; +} + + + + + + + Alt+Left + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + 0 + 35 + + + + PointingHandCursor + + + 播放/暂停 + + + QPushButton +{ +background-image: url(:/image/image/image/pase.png); +background-repeat:no-repeat; +background-position:center center; +border:none; +} + +QPushButton:hover{ +background-image: url(:/image/image/image-hover/pase-hover.png); +background-repeat:no-repeat; +background-position:center center; +} + +QPushButton:pressed{ +background-image: url(:/image/image/image/pase.png); +background-repeat:no-repeat; +background-position:center center; +} + + + + + + + Space + + + false + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + 0 + 35 + + + + PointingHandCursor + + + 下一首 + + + QPushButton +{ +background-image: url(:/image/image/image/next.png); +background-repeat:no-repeat; +background-position:center center; +border:none; +} +QPushButton:hover{ +background-image: url(:/image/image/image-hover/next-hover.png); +background-repeat:no-repeat; +background-position:center center; +} +QPushButton:pressed{ +background-image: url(:/image/image/image/next.png); +background-repeat:no-repeat; +background-position:center center; +} + + + + + + + Alt+Right + + + + + + + + false + + + + 470 + 670 + 521 + 21 + + + + + 13 + + + + PointingHandCursor + + + QSlider::add-page:Horizontal +{ +background-color: rgba(255, 255, 255,150); +height:4px; +} +QSlider::sub-page:Horizontal +{ +background-color: rgb(255, 255, 255); +height:4px; +} +QSlider::groove:Horizontal +{ +background:transparent; +height:4px; +} +QSlider::handle:Horizontal +{ +height:16px; +width:16px; +border-image:url(:/image/image/image/sliderHandle.png); +margin: -6 0px; +} + + + + + 10 + + + Qt::Horizontal + + + QSlider::NoTicks + + + + + false + + + + 990 + 670 + 141 + 21 + + + + + Calibri + 11 + 75 + false + true + + + + color:rgb(255, 255, 255); + + + 00:00/00:00 + + + Qt::AlignCenter + + + + + + 850 + 720 + 35 + 41 + + + + + 35 + 35 + + + + PointingHandCursor + + + 循环播放 + + + QPushButton +{ +background-image: url(:/image/image/image/loop.png); +background-repeat:no-repeat; +background-position:center center; +border:none; +} + +QPushButton:hover{ +background-image: url(:/image/image/image-hover/loop-hover.png); +background-repeat:no-repeat; +background-position:center center; +} + +QPushButton:pressed{ +background-image: url(:/image/image/image/loop.png); +background-repeat:no-repeat; +background-position:center center; +} + + + + + + + false + + + + + + 1100 + 0 + 91 + 51 + + + + + 0 + + + + + + 35 + 35 + + + + 最小化 + + + QPushButton +{ +border-radius:0px; +background-image: url(:/image/image/image/min.png); +background-color: rgba(255, 255, 255,0); +background-repeat:no-repeat; +border:none; +background-position:center center; +} +QPushButton:hover{ + background-color: rgb(255, 255, 255,100); +} +QPushButton:pressed{ +background-color: rgba(95, 95, 95,100); +border-color:rgba(255,255,255,30); +border-style:inset; +color:rgba(0,0,0,100); +} + + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + false + + + + 16777215 + 20 + + + + color: rgb(248, 246, 231); + + + QFrame::Plain + + + 2 + + + Qt::Vertical + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + 35 + 35 + + + + 关闭 + + + QPushButton +{ +border-radius:0px; +background-image: url(:/image/image/image/quit.png); +background-repeat:no-repeat; +border:none; +background-position:center center; + +} +QPushButton:hover{ + +background-color: rgba(230,0,0,0.5); +} +QPushButton:pressed{ +background-color: rgba(95, 95, 95,100); +border-color:rgba(255,255,255,30); +border-style:inset; +color:rgba(0,0,0,100); + +} + + + + + + + + + + + + true + + + + 476 + 640 + 631 + 21 + + + + + Microsoft YaHei UI + 75 + true + + + + color:rgb(255, 255, 255); + + + KEEP CALM AND CARRY ON ... + + + + + + 280 + 620 + 161 + 161 + + + + + + + :/image/image/image/non-music.png + + + true + + + + + + 1140 + 540 + 35 + 170 + + + + + 35 + 170 + + + + QSlider + { + background-color: rgba(255,255,255,0.2); + min-width:5px; + max-width:5px; + border:15px solid rgba(255,255,255,0.2); + } + QSlider::add-page:vertical + { + + background-color: rgb(250, 250, 0); + width:4px; + } + QSlider::sub-page:vertical + { + background-color: rgba(255,255,255,0.5); + width:4px; + } + QSlider::groove:vertical + { + background:transparent; + width:6px; + } + QSlider::handle:vertical + { + height: 13px; + width:13px; + + margin: -0 -4px; + border-image: url(:/image/image/image/volumeHandle.png); + } + + + 100 + + + 100 + + + Qt::Vertical + + + + + + 1140 + 720 + 36 + 35 + + + + + 35 + 35 + + + + PointingHandCursor + + + 音量控制 + + + QPushButton +{ +background-image: url(:/image/image/image/music-voice.png); +background-repeat:no-repeat; +background-position:center center; +border:none; +} + +QPushButton:hover{ +background-image: url(:/image/image/image-hover/music-voice-hover.png); +background-repeat:no-repeat; +background-position:center center; +} + +QPushButton:pressed{ +background-image: url(:/image/image/image/music-voice.png); +background-repeat:no-repeat; +background-position:center center; +} + + + + + + + + + + 70 + 160 + 131 + 41 + + + + + Microsoft YaHei UI + 10 + 75 + true + + + + PointingHandCursor + + + QPushButton +{ +color:rgb(255, 255, 255); +border-radius:0px; +background-color: rgba(255, 255, 255,0); +background-repeat:no-repeat; +border:none; +background-position:center center; +} +QPushButton:hover{ + background-color: rgb(255, 255, 255,100); +} +QPushButton:pressed{ +background-color: rgba(95, 95, 95,100); +border-color:rgba(255,255,255,30); +border-style:inset; +color:rgb(255, 255, 255); +} + + + + 本地音乐 + + + + :/image/image/image/local-music.png:/image/image/image/local-music.png + + + + 30 + 30 + + + + true + + + + + + 280 + 70 + 831 + 531 + + + + 4 + + + + + + 0 + 40 + 831 + 491 + + + + + 75 + true + + + + color: rgb(255, 255, 255); +background-color: rgba(255, 255, 255, 50); + + + + Qt::ScrollBarAlwaysOff + + + QAbstractScrollArea::AdjustToContentsOnFirstShow + + + QAbstractItemView::SingleSelection + + + false + + + false + + + false + + + false + + + + + true + + + + 0 + 0 + 111 + 41 + + + + + Microsoft YaHei UI + 9 + 75 + false + true + + + + color:rgb(255, 255, 255); + + + + 当前播放 + + + Qt::AlignCenter + + + + + + 100 + 0 + 41 + 41 + + + + + Microsoft YaHei UI + 10 + 75 + true + + + + PointingHandCursor + + + 清空当前列表 + + + + + + + + + + :/image/image/image/clear.png:/image/image/image/clear.png + + + + 30 + 30 + + + + true + + + + + + + + 0 + 40 + 831 + 491 + + + + + 75 + true + + + + color: rgb(255, 255, 255); +background-color: rgba(255, 255, 255, 50); + + + + Qt::ScrollBarAlwaysOff + + + QAbstractScrollArea::AdjustToContentsOnFirstShow + + + QAbstractItemView::SingleSelection + + + false + + + false + + + false + + + false + + + + + true + + + + 0 + 0 + 111 + 41 + + + + + Microsoft YaHei UI + 9 + 75 + false + true + + + + color:rgb(255, 255, 255); + + + + 本地音乐 + + + Qt::AlignCenter + + + + + + 670 + 0 + 155 + 43 + + + + + + + + Microsoft YaHei UI + 10 + 75 + true + + + + PointingHandCursor + + + 按歌手名排序 + + + + + + + + + + :/image/image/image/singer.png:/image/image/image/singer.png + + + + 30 + 30 + + + + true + + + + + + + + Microsoft YaHei UI + 10 + 75 + true + + + + PointingHandCursor + + + 按歌曲名排序 + + + + + + + + + + :/image/image/image/sort-alpha-asc_ea48_ether.png:/image/image/image/sort-alpha-asc_ea48_ether.png + + + + 30 + 30 + + + + true + + + + + + + + Microsoft YaHei UI + 10 + 75 + true + + + + PointingHandCursor + + + 按时长排序 + + + + + + + + + + :/image/image/image/duration.png:/image/image/image/duration.png + + + + 30 + 30 + + + + true + + + + + + + + + 590 + 0 + 41 + 41 + + + + + Microsoft YaHei UI + 10 + 75 + true + + + + PointingHandCursor + + + 整理歌曲(排序且去除重复) + + + + + + + + + + :/image/image/image/remove_dup.png:/image/image/image/remove_dup.png + + + + 30 + 30 + + + + true + + + + + + 100 + 0 + 41 + 41 + + + + + Microsoft YaHei UI + 10 + 75 + true + + + + PointingHandCursor + + + 清空当前列表 + + + + + + + + + + :/image/image/image/clear.png:/image/image/image/clear.png + + + + 30 + 30 + + + + true + + + + + + + true + + + + 30 + 0 + 71 + 41 + + + + + Microsoft YaHei UI + 9 + 75 + false + true + + + + color:rgb(255, 255, 255); + + + + 我喜欢 + + + Qt::AlignCenter + + + + + + 0 + 40 + 831 + 491 + + + + + 75 + true + + + + color: rgb(255, 255, 255); +background-color: rgba(255, 255, 255, 50); + + + + Qt::ScrollBarAlwaysOff + + + QAbstractScrollArea::AdjustToContentsOnFirstShow + + + QAbstractItemView::SingleSelection + + + false + + + false + + + false + + + false + + + + + + 0 + 0 + 35 + 41 + + + + + 35 + 35 + + + + PointingHandCursor + + + 添加音乐 + + + QPushButton +{ +background-image: url(:/image/image/image/add.png); +background-repeat:no-repeat; +background-position:center center; +border:none; +} + +QPushButton:hover{ +background-image: url(:/image/image/image-hover/add-hover.png); +background-repeat:no-repeat; +background-position:center center; +} + +QPushButton:pressed{ +background-image: url(:/image/image/image/add.png); +background-repeat:no-repeat; +background-position:center center; +} + + + + + + + + + + 670 + 0 + 155 + 43 + + + + + + + + Microsoft YaHei UI + 10 + 75 + true + + + + PointingHandCursor + + + 按歌手名排序 + + + + + + + + + + :/image/image/image/singer.png:/image/image/image/singer.png + + + + 30 + 30 + + + + true + + + + + + + + Microsoft YaHei UI + 10 + 75 + true + + + + PointingHandCursor + + + 按歌曲名排序 + + + + + + + + + + :/image/image/image/sort-alpha-asc_ea48_ether.png:/image/image/image/sort-alpha-asc_ea48_ether.png + + + + 30 + 30 + + + + true + + + + + + + + Microsoft YaHei UI + 10 + 75 + true + + + + PointingHandCursor + + + 按时长排序 + + + + + + + + + + :/image/image/image/duration.png:/image/image/image/duration.png + + + + 30 + 30 + + + + true + + + + + + + + + 590 + 0 + 41 + 41 + + + + + Microsoft YaHei UI + 10 + 75 + true + + + + PointingHandCursor + + + 整理歌曲(排序且去除重复) + + + + + + + + + + :/image/image/image/remove_dup.png:/image/image/image/remove_dup.png + + + + 30 + 30 + + + + true + + + + + + 100 + 0 + 41 + 41 + + + + + Microsoft YaHei UI + 10 + 75 + true + + + + PointingHandCursor + + + 清空当前列表 + + + + + + + + + + :/image/image/image/clear.png:/image/image/image/clear.png + + + + 30 + 30 + + + + true + + + + + + + + 0 + 40 + 831 + 491 + + + + + 75 + true + + + + color: rgb(255, 255, 255); +background-color: rgba(255, 255, 255, 50); + + + + Qt::ScrollBarAlwaysOff + + + QAbstractScrollArea::AdjustToContentsOnFirstShow + + + QAbstractItemView::SingleSelection + + + false + + + false + + + false + + + false + + + + + true + + + + 90 + 0 + 731 + 41 + + + + + Microsoft YaHei UI + 9 + 75 + false + true + + + + color:rgb(255, 255, 255); + + + + 歌单 + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter + + + + + + 0 + 0 + 35 + 41 + + + + + 35 + 35 + + + + PointingHandCursor + + + 添加音乐 + + + QPushButton +{ +background-image: url(:/image/image/image/add.png); +background-repeat:no-repeat; +background-position:center center; +border:none; +} + +QPushButton:hover{ +background-image: url(:/image/image/image-hover/add-hover.png); +background-repeat:no-repeat; +background-position:center center; +} + +QPushButton:pressed{ +background-image: url(:/image/image/image/add.png); +background-repeat:no-repeat; +background-position:center center; +} + + + + + + + + + + 670 + 0 + 155 + 43 + + + + + + + + Microsoft YaHei UI + 10 + 75 + true + + + + PointingHandCursor + + + 按歌手名排序 + + + + + + + + + + :/image/image/image/singer.png:/image/image/image/singer.png + + + + 30 + 30 + + + + true + + + + + + + + Microsoft YaHei UI + 10 + 75 + true + + + + PointingHandCursor + + + 按歌曲名排序 + + + + + + + + + + :/image/image/image/sort-alpha-asc_ea48_ether.png:/image/image/image/sort-alpha-asc_ea48_ether.png + + + + 30 + 30 + + + + true + + + + + + + + Microsoft YaHei UI + 10 + 75 + true + + + + PointingHandCursor + + + 按时长排序 + + + + + + + + + + :/image/image/image/duration.png:/image/image/image/duration.png + + + + 30 + 30 + + + + true + + + + + + + + + 590 + 0 + 41 + 41 + + + + + Microsoft YaHei UI + 10 + 75 + true + + + + PointingHandCursor + + + 整理歌曲(排序且去除重复) + + + + + + + + + + :/image/image/image/remove_dup.png:/image/image/image/remove_dup.png + + + + 30 + 30 + + + + true + + + + + + 40 + 0 + 31 + 41 + + + + + Microsoft YaHei UI + 10 + 75 + true + + + + PointingHandCursor + + + 清空当前列表 + + + + + + + + + + :/image/image/image/clear.png:/image/image/image/clear.png + + + + 30 + 30 + + + + true + + + + + + + + 0 + 120 + 831 + 411 + + + + + + true + + + + 0 + 0 + 831 + 41 + + + + + Microsoft YaHei UI + 14 + 75 + false + true + + + + color:rgb(255, 255, 255); + + + + + + + Qt::AlignCenter + + + + + true + + + + 0 + 80 + 831 + 21 + + + + + Microsoft YaHei UI + 9 + 75 + false + true + + + + color:rgb(255, 255, 255); + + + + + + + Qt::AlignCenter + + + + + true + + + + 0 + 50 + 831 + 21 + + + + + Microsoft YaHei UI + 9 + 75 + false + true + + + + color:rgb(255, 255, 255); + + + + + + + Qt::AlignCenter + + + + + + + + 70 + 220 + 131 + 41 + + + + + Microsoft YaHei UI + 10 + 75 + true + + + + PointingHandCursor + + + QPushButton +{ +color:rgb(255, 255, 255); +border-radius:0px; +background-color: rgba(255, 255, 255,0); +background-repeat:no-repeat; +border:none; +background-position:center center; +} +QPushButton:hover{ + background-color: rgb(255, 255, 255,100); +} +QPushButton:pressed{ +background-color: rgba(95, 95, 95,100); +border-color:rgba(255,255,255,30); +border-style:inset; +color:rgb(255, 255, 255); +} + + + + 我喜欢 + + + + :/image/image/image/favo-music.png:/image/image/image/favo-music.png + + + + 30 + 30 + + + + true + + + + + + 70 + 100 + 131 + 41 + + + + + Microsoft YaHei UI + 10 + 75 + true + + + + PointingHandCursor + + + QPushButton +{ +color:rgb(255, 255, 255); +border-radius:0px; +background-color: rgba(255, 255, 255,0); +background-repeat:no-repeat; +border:none; +background-position:center center; +} +QPushButton:hover{ + background-color: rgb(255, 255, 255,100); +} +QPushButton:pressed{ +background-color: rgba(95, 95, 95,100); +border-color:rgba(255,255,255,30); +border-style:inset; +color:rgb(255, 255, 255); +} + + + + 当前播放 + + + + :/image/image/image/current-music.png:/image/image/image/current-music.png + + + + 30 + 30 + + + + true + + + + + + 20 + 350 + 241 + 431 + + + + + 75 + true + + + + color: rgb(255, 255, 255); +background-color: rgba(255, 255, 255, 50); + + + + Qt::ScrollBarAlwaysOff + + + + + true + + + + 80 + 310 + 111 + 35 + + + + + Microsoft YaHei UI + 10 + 75 + false + true + + + + color:rgb(255, 255, 255); + + + + 我的歌单 + + + Qt::AlignCenter + + + + + + 180 + 310 + 35 + 35 + + + + + 35 + 35 + + + + PointingHandCursor + + + 添加音乐 + + + QPushButton +{ +background-image: url(:/image/image/image/add.png); +background-repeat:no-repeat; +background-position:center center; +border:none; +} + +QPushButton:hover{ +background-image: url(:/image/image/image-hover/add-hover.png); +background-repeat:no-repeat; +background-position:center center; +} + +QPushButton:pressed{ +background-image: url(:/image/image/image/add.png); +background-repeat:no-repeat; +background-position:center center; +} + + + + + + + + + + 60 + 310 + 31 + 31 + + + + + + + :/image/image/image/myMusicList.png + + + true + + + + + + 1030 + 10 + 35 + 35 + + + + + 35 + 35 + + + + PointingHandCursor + + + 更换背景 + + + + + + + + + + :/image/image/image/skin.png:/image/image/image/skin.png + + + + 30 + 30 + + + + true + + + + + + 10 + 0 + 338 + 53 + + + + + + + + Microsoft YaHei UI + 10 + 75 + true + + + + PointingHandCursor + + + 关于 + + + + + + + + + + :/image/image/image/Title.png:/image/image/image/Title.png + + + + 40 + 40 + + + + true + + + + + + + true + + + + Microsoft YaHei UI + 9 + 75 + false + true + + + + color:rgb(255, 255, 255); + + + + LightMusicPlayer | By NJU-TJL + + + Qt::AlignCenter + + + + + + + + + 950 + 720 + 35 + 41 + + + + + 35 + 35 + + + + PointingHandCursor + + + 进入歌词界面 + + + + + + + + + + :/image/image/image/lyric.png:/image/image/image/lyric.png + + + + 30 + 30 + + + + true + + + + + + 980 + 10 + 35 + 35 + + + + + 35 + 35 + + + + PointingHandCursor + + + 关于 + + + + + + + + + + :/image/image/image/about.png:/image/image/image/about.png + + + + 30 + 30 + + + + true + + + + + + 1050 + 720 + 41 + 41 + + + + + Microsoft YaHei UI + 10 + 75 + true + + + + PointingHandCursor + + + 添加本地音乐 + + + + + + + + + + :/image/image/image/addFromLocal.png:/image/image/image/addFromLocal.png + + + + 30 + 30 + + + + Ctrl+O + + + true + + + + + + + MusicListWidget + QListWidget +
MusicListWidget.h
+
+ + LyricWidget + QWidget +
LyricWidget.h
+ 1 +
+
+ + + + +
diff --git a/LightMusicPlayer/LightMusicPlayer/myqss.h b/LightMusicPlayer/LightMusicPlayer/myqss.h new file mode 100644 index 0000000..fd39b2b --- /dev/null +++ b/LightMusicPlayer/LightMusicPlayer/myqss.h @@ -0,0 +1,206 @@ +#ifndef MYQSS_H +#define MYQSS_H +#include + +/*此文件统一存放一些QSS样式代码*/ + +//播放按钮样式 +inline QString PlayStyle() +{ + return "QPushButton" + " {" + "background-image:url(:/image/image/image/play.png);" + " background-repeat:no-repeat;" + " background-position:center center;" + " border:none;" + +" }" + + "QPushButton:hover{" + " background-repeat:no-repeat;" + " background-position:center center;" + "background-image:url(:/image/image/image-hover/play-hover.png);" + + " }" + " QPushButton:pressed{" + "background-repeat:no-repeat;" + " background-position:center center;" + " background-image:url(:/image/image/image/play.png);" + + "}"; +} +//暂停按钮样式 +inline QString PaseStyle() +{ + return "QPushButton" + " {" + "background-image:url(:/image/image/image/pase.png);" + " background-repeat:no-repeat;" + " background-position:center center;" + " border:none;" + +" }" + + "QPushButton:hover{" + " background-repeat:no-repeat;" + " background-position:center center;" + "background-image:url(:/image/image/image-hover/pase-hover.png);" + + " }" + " QPushButton:pressed{" + "background-repeat:no-repeat;" + " background-position:center center;" + " background-image:url(:/image/image/image/pase.png);" + + "}"; +} +inline QString RandomStyle() +{ + + return "QPushButton" + " {" + "background-image:url(:/image/image/image/play-random.png);" + " background-repeat:no-repeat;" + " background-position:center center;" + " border:none;" + +" }" + + "QPushButton:hover{" + " background-repeat:no-repeat;" + " background-position:center center;" + "background-image:url(:/image/image/image-hover/play-random-hover.png);" + + " }" + " QPushButton:pressed{" + "background-repeat:no-repeat;" + " background-position:center center;" + " background-image:url(:/image/image/image/play-random.png);" + + "}"; + +} +inline QString LoopStyle() +{ + + + return "QPushButton" + " {" + "background-image:url(:/image/image/image/loop.png);" + " background-repeat:no-repeat;" + " background-position:center center;" + " border:none;" + +" }" + + "QPushButton:hover{" + " background-repeat:no-repeat;" + " background-position:center center;" + "background-image:url(:/image/image/image-hover/loop-hover.png);" + + " }" + " QPushButton:pressed{" + "background-repeat:no-repeat;" + " background-position:center center;" + " background-image:url(:/image/image/image/loop.png);" + + "}"; + +} +inline QString LoopOneStyle() +{ + + + return "QPushButton" + " {" + "background-image:url(:/image/image/image/loop-one.png);" + " background-repeat:no-repeat;" + " background-position:center center;" + " border:none;" + +" }" + + "QPushButton:hover{" + " background-repeat:no-repeat;" + " background-position:center center;" + "background-image:url(:/image/image/image-hover/loop-one-hover.png);" + + " }" + " QPushButton:pressed{" + "background-repeat:no-repeat;" + " background-position:center center;" + " background-image:url(:/image/image/image/loop-one.png);" + + "}"; + +} + +inline QString ListWidgetStyle(){ + return "QScrollBar:vertical" + "{" + "width:8px;" + "background-color:transparent;" + "margin:0px,0px,0px,0px;" + " padding-top:12px; /*上预留位置*/" + " padding-bottom:12px; /*下预留位置*/" + "}" + + + " QScrollBar::handle:vertical" + " {" + "width:8px;" + " background-color:rgba(255,255,255,0.2);" + " border-radius:4px;" + " min-height:20px;" + " }" + + + " QScrollBar::handle:vertical:hover" + " {" + " width:9px;" + " background-color:rgba(255,255,255,0.5);" + " border-radius:4px;" + " min-height:20;" + " }" + + " QScrollBar::add-line:vertical" + " {" + " height:12px;" + " width:10px;" + " border-image:url(:/selectfile/scroll/3.png);" + " subcontrol-position:bottom;" + " }" + + " QScrollBar::sub-line:vertical" + " {" + " height:12px;" + "width:10px;" + " border-image:url(:/selectfile/scroll/1.png);" + "subcontrol-position:top;" + " }" + " QScrollBar::add-line:vertical:hover" + " {" + " height:12px;" + "width:10px;" + " border-image:url(:/selectfile/scroll/4.png);" + "subcontrol-position:bottom;" + " }" + + + " QScrollBar::sub-line:vertical:hover" + " {" + " height:12px;" + " width:10px;" + " border-image:url(:/selectfile/scroll/2.png);" + " subcontrol-position:top;" + " }" + + " QScrollBar::add-page:vertical,QScrollBar::sub-page:vertical" + " {" + " background-color:transparent;" + " border-radius:4px;" + "}"; + +} + +#endif // MYQSS_H