代码拉取完成,页面将自动刷新
#include <QDebug>
#include <QDir>
#include "playlist.h"
#include "ui_playlist.h"
#include "globalhelper.h"
Playlist::Playlist(QWidget* parent) :
QWidget(parent),
ui(new Ui::Playlist)
{
ui->setupUi(this);
}
Playlist::~Playlist()
{
QStringList strListPlayList;
for (int i = 0; i < ui->List->count(); i++)
{
strListPlayList.append(ui->List->item(i)->toolTip());
}
GlobalHelper::SavePlaylist(strListPlayList);
delete ui;
}
bool Playlist::Init()
{
if (ui->List->Init() == false)
{
return false;
}
if (InitUi() == false)
{
return false;
}
if (ConnectSignalSlots() == false)
{
return false;
}
setAcceptDrops(true);
return true;
}
bool Playlist::InitUi()
{
setStyleSheet(GlobalHelper::GetQssStr("://res/qss/playlist.css"));
//ui->List->hide();
//this->setFixedWidth(ui->HideOrShowBtn->width());
//GlobalHelper::SetIcon(ui->HideOrShowBtn, 12, QChar(0xf104));
ui->List->clear();
QStringList strListPlaylist;
GlobalHelper::GetPlaylist(strListPlaylist);
for (QString strVideoFile : strListPlaylist)
{
QFileInfo fileInfo(strVideoFile);
if (fileInfo.exists())
{
QListWidgetItem* pItem = new QListWidgetItem(ui->List);
pItem->setData(Qt::UserRole, QVariant(fileInfo.filePath())); // 用户数据
pItem->setText(QString("%1").arg(fileInfo.fileName())); // 显示文本
pItem->setToolTip(fileInfo.filePath());
ui->List->addItem(pItem);
}
}
if (strListPlaylist.length() > 0)
{
ui->List->setCurrentRow(0);
}
//ui->List->addItems(strListPlaylist);
return true;
}
bool Playlist::ConnectSignalSlots()
{
QList<bool> listRet;
bool bRet;
bRet = connect(ui->List, &MediaList::SigAddFile, this, &Playlist::OnAddFile);
listRet.append(bRet);
for (bool bReturn : listRet)
{
if (bReturn == false)
{
return false;
}
}
return true;
}
void Playlist::on_List_itemDoubleClicked(QListWidgetItem* item)
{
emit SigPlay(item->data(Qt::UserRole).toString());
m_nCurrentPlayListIndex = ui->List->row(item);
ui->List->setCurrentRow(m_nCurrentPlayListIndex);
}
bool Playlist::GetPlaylistStatus()
{
if (this->isHidden())
{
return false;
}
return true;
}
int Playlist::GetCurrentIndex()
{
return 0;
}
void Playlist::OnAddFile(QString strFileName)
{
bool bSupportMovie = strFileName.endsWith(".mkv", Qt::CaseInsensitive) ||
strFileName.endsWith(".rmvb", Qt::CaseInsensitive) ||
strFileName.endsWith(".mp4", Qt::CaseInsensitive) ||
strFileName.endsWith(".avi", Qt::CaseInsensitive) ||
strFileName.endsWith(".flv", Qt::CaseInsensitive) ||
strFileName.endsWith(".wmv", Qt::CaseInsensitive) ||
strFileName.endsWith(".3gp", Qt::CaseInsensitive) ||
strFileName.endsWith(".mov", Qt::CaseInsensitive);
if (!bSupportMovie)
{
return;
}
QFileInfo fileInfo(strFileName);
QList<QListWidgetItem*> listItem = ui->List->findItems(fileInfo.fileName(), Qt::MatchExactly);
QListWidgetItem* pItem = nullptr;
if (listItem.isEmpty())
{
pItem = new QListWidgetItem(ui->List);
pItem->setData(Qt::UserRole, QVariant(fileInfo.filePath())); // 用户数据
pItem->setText(fileInfo.fileName()); // 显示文本
pItem->setToolTip(fileInfo.filePath());
ui->List->addItem(pItem);
}
else
{
pItem = listItem.at(0);
}
}
void Playlist::OnAddFileAndPlay(QString strFileName)
{
bool bSupportMovie = strFileName.endsWith(".mkv", Qt::CaseInsensitive) ||
strFileName.endsWith(".rmvb", Qt::CaseInsensitive) ||
strFileName.endsWith(".mp4", Qt::CaseInsensitive) ||
strFileName.endsWith(".avi", Qt::CaseInsensitive) ||
strFileName.endsWith(".flv", Qt::CaseInsensitive) ||
strFileName.endsWith(".wmv", Qt::CaseInsensitive) ||
strFileName.endsWith(".3gp", Qt::CaseInsensitive);
if (!bSupportMovie)
{
return;
}
QFileInfo fileInfo(strFileName);
QList<QListWidgetItem*> listItem = ui->List->findItems(fileInfo.fileName(), Qt::MatchExactly);
QListWidgetItem* pItem = nullptr;
if (listItem.isEmpty())
{
pItem = new QListWidgetItem(ui->List);
pItem->setData(Qt::UserRole, QVariant(fileInfo.filePath())); // 用户数据
pItem->setText(fileInfo.fileName()); // 显示文本
pItem->setToolTip(fileInfo.filePath());
ui->List->addItem(pItem);
}
else
{
pItem = listItem.at(0);
}
on_List_itemDoubleClicked(pItem);
}
void Playlist::OnBackwardPlay()
{
if (m_nCurrentPlayListIndex == 0)
{
m_nCurrentPlayListIndex = ui->List->count() - 1;
on_List_itemDoubleClicked(ui->List->item(m_nCurrentPlayListIndex));
ui->List->setCurrentRow(m_nCurrentPlayListIndex);
}
else
{
m_nCurrentPlayListIndex--;
on_List_itemDoubleClicked(ui->List->item(m_nCurrentPlayListIndex));
ui->List->setCurrentRow(m_nCurrentPlayListIndex);
}
}
void Playlist::OnForwardPlay()
{
if (m_nCurrentPlayListIndex == ui->List->count() - 1)
{
m_nCurrentPlayListIndex = 0;
on_List_itemDoubleClicked(ui->List->item(m_nCurrentPlayListIndex));
ui->List->setCurrentRow(m_nCurrentPlayListIndex);
}
else
{
m_nCurrentPlayListIndex++;
on_List_itemDoubleClicked(ui->List->item(m_nCurrentPlayListIndex));
ui->List->setCurrentRow(m_nCurrentPlayListIndex);
}
}
void Playlist::dropEvent(QDropEvent* event)
{
QList<QUrl> urls = event->mimeData()->urls();
if (urls.isEmpty())
{
return;
}
for (QUrl url : urls)
{
QString strFileName = url.toLocalFile();
OnAddFile(strFileName);
}
}
void Playlist::dragEnterEvent(QDragEnterEvent* event)
{
event->acceptProposedAction();
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。