⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 qmplaylist.cpp

📁 可以播放MP3,wma等文件格式的播放器
💻 CPP
📖 第 1 页 / 共 4 页
字号:
/*!  Clears the playlist.  The playing item will be cleared.  \warning This should only be called directly by QmMainWindow.*/voidQmPlayList::clear(){	m_pCurrentSong = 0;	QListView::clear();    m_Dirty = false;    m_SongIndexDirty = true;}/*!  \return True if \a item is selected directly \e or if a parent of the item  is selected.  False otherwise or if \a item is null.*/boolQmPlayList::isSelected(	QListViewItem *item) const{	if(item == 0)		return false;		if(item->isSelected())		return true;	for (QListViewItem *parent = item->parent(); parent; parent = parent->parent())		if(parent->isSelected())			return true;	return false;}/*!  Adjust name column width on viewport resize.*/voidQmPlayList::viewportResizeEvent(    QResizeEvent *e){    QmListView::viewportResizeEvent( e );    setColumnWidth(0, e->size().width() - columnWidth(1));//     QmListView::setGeometry(x,y,w,h);//     QSize s = viewportSize(w, h);// 	if(columns() == 1)// 		setColumnWidth( 0, s.width());// 	else// 	{// 		setColumnWidth( 0, s.width() - m_LengthWidth);// 		setColumnWidth( 1, m_LengthWidth );// 	}//     triggerUpdate();}/*!  Remove(s) the selected item(s), if any.  If the playing item is selected either directly or indirectly (i.e. a parent is selected), the  next song to play will be returned.  If there is no next song to play or there is no need to  play a new song, null will be returned.  If there is no next song to play AND the current item is the playing item, \a stop_playing will  be set to true.  The callee should stop playing as the playing item has been deleted, but  there was no other song to return for playing.  \a stop_playing will be false in all other  cases.  \return The new song to play if any, otherwise null.*/QmSongItem*QmPlayList::removeSelected(	bool *stop_playing){	QmSongItem *ret = 0;	m_DeletingItems = true;	*stop_playing = false;		// If the playing item is selected, either directly or indirectly, find the new	// song to play.	if(m_pCurrentSong && isSelected( m_pCurrentSong ))	{        // Search forward (down)		SongIndexIterator i;		for(i = std::find(m_SongIndex.begin(), m_SongIndex.end(), m_pCurrentSong); i != m_SongIndex.end(); ++i)        {			if ( ! isSelected(*i))				break;        }        // If we didn't find a song in the forward search, search backward (up)		if(i == m_SongIndex.end())        {			for(i = std::find(m_SongIndex.begin(), m_SongIndex.end(), m_pCurrentSong); i != m_SongIndex.begin(); --i)            {				if ( ! isSelected(*i))					break;            }        }		if (isSelected(*i))        {            m_pCurrentSong = 0;            *stop_playing = true;        }		else {			setCurrent(*i);			ret = m_pCurrentSong;		}	}	// Delete selected items.	QList<QListViewItem> *selected = selectedItems();	selected->setAutoDelete(true);	delete selected;	m_DeletingItems = false;    setDirty();	updateSongIndex(true);		return ret;}/*!  \return wheter the song playing or would be playing is the first non-bad song in the list*/boolQmPlayList::atBeginning() {	// rk: what to do with empty list? throw exception, write a bug message in the bug log?	// return true for now.	if (m_SongIndex.empty())		return true;	    if(m_pCurrentSong == 0)		setCurrent(m_SongIndex.front());		return m_pCurrentSong == m_SongIndex[0];}/*!  \return wheter the song playing or would be playing is the last non-bad song in the list*/boolQmPlayList::atEnd() {	updateSongIndex(); 	if (m_SongIndex.empty())		return true;    if(m_pCurrentSong == 0)		setCurrent(m_SongIndex.front()); 	return m_pCurrentSong == m_SongIndex.back();}/*!  \return The position of the playing or would be playing item, or -1 if empty*/intQmPlayList::position(){	updateSongIndex();	if (m_SongIndex.empty())		return -1;	if (m_pCurrentSong == 0)		setCurrent(m_SongIndex.front()); 				return std::find(m_SongIndex.begin(), m_SongIndex.end(), m_pCurrentSong) - m_SongIndex.begin();}/*!  Deletes the song at the specified position (0-based depth first).*/voidQmPlayList::deletePosition(    uint pos){	updateSongIndex();	if (m_SongIndex.empty())		return;		if (pos < 0 || m_SongIndex.size() <= pos)		return;	if (m_SongIndex[pos] == m_pCurrentSong)    {		if (m_SongIndex.size() == 1)		{			if (m_pCurrentSong)				m_pCurrentSong->setPlaying(false);			m_pCurrentSong = 0;		}		else 			setCurrent(m_SongIndex[pos+1 % m_SongIndex.size()]); 	}	delete m_SongIndex[pos];}/*!  \return True if empty, false otherwise.*/boolQmPlayList::isEmpty() const{	return firstChild() == 0;}/*!  Appends the directory (path) \a dir to the playlist.  If,  for some reason, \a dir cannot be read, this function fails  silently.  \sa prependDir(const QString&), prependList(const QString&)*/voidQmPlayList::appendDir(	const QString &dir){	if(dir.isEmpty())	{		qWarning("QmPlayList::appendDir(): Filename is empty.\n");		return;	}        int count = 0;	(void) new QmDirItem(this, lastChild(), dir, count, true);    setDirty();		triggerUpdate();    QmMainWindow::mainwin->statusUpdate(new Message(Message::Status, "Loaded %d songs", count));}/*!  Prepends the directory (path) \a dir to the playlist.  If,  for some reason, \a dir cannot be read, this function fails  silently.  \sa appendDir(const QString&), appendList(const QString&) */voidQmPlayList::prependDir(	const QString &dir){	if(dir.isEmpty())	{		qWarning("BUG: QmPlayList::prependDir(): Filename is empty.\n");		return;	}        int count = 0;	(void) new QmDirItem(this, 0, dir, count, true);    setDirty();		triggerUpdate();    QmMainWindow::mainwin->statusUpdate(new Message(Message::Status, "Loaded %d songs", count));}/*!  Appends the playlist \a filename to the playlist.  If,  for some reason, \a filename cannot be read, this function fails  silently.  \sa prependList(const QString&), prependDir(const QString&) */voidQmPlayList::appendList(	const QString &filename){	if(filename.isEmpty())	{		qWarning("BUG: QmPlayList::appendList(): Filename is empty.\n");		return;	}	bool dirty = !isEmpty();	loadPlayList(filename, dynamic_cast<QmPlayListItem*>(lastChild()));	triggerUpdate();	if (dirty)		setDirty();}/*!  Prepends the playlist \a filename to the playlist.  If,  for some reason, \a filename cannot be read, this function fails  silently.  \sa appendList(const QString&), appendDir(const QString&) */voidQmPlayList::prependList(	const QString &filename){	if(filename.isEmpty())	{		qWarning("BUG: QmPlayList::prependList(): Filename is empty.\n");		return;	}	bool dirty = !isEmpty();	loadPlayList(filename);	triggerUpdate();	if (dirty)		setDirty();}/*!  Appends the song \a filename to the playlist.  If,  for some reason, \a filename cannot be read, this function fails  silently.  \sa prependList(const QString&), prependDir(const QString&) */voidQmPlayList::appendSong(	const QString &filename){	if(filename.isEmpty())	{		qWarning("BUG: QmPlayList::appendSong(): Filename is empty.\n");		return;	}    	triggerUpdate();	(void) new QmSongItem(this, lastChild(), filename);	setDirty();	}/*!  Prepends the song \a filename to the playlist.  If,  for some reason, \a filename cannot be read, this function fails  silently.  \sa appendList(const QString&), appendDir(const QString&) */voidQmPlayList::prependSong(	const QString &filename){	if(filename.isEmpty())	{		qWarning("BUG: QmPlayList::prependSong(): Filename is empty.\n");		return;	}		triggerUpdate();	(void) new QmSongItem(this, 0, filename);	setDirty();	}/*!  Saves the playlist to \a filename.  If \a filename is QString::null, the  the default playlist (stored in the Apollo configuration directory) will be  overwritten.  This function will silently fail if the file cannot be saved. */// rk: use saveAs*(), but keep this here for now// void// QmPlayList::savePlayList(// 	const QString &filename)// {//     if(filename.isEmpty())// 		qWarning("QmPlayList::savePlayList(): Filename is empty.\n");//     else {//         QmPlayListFormat *f = QmPlayListFormat::getFormat(filename, true);//         f->save(this, filename);//         delete f;//         m_Dirty = false;//     }// }/*!  Sets the display format for each item on the playlist.*/voidQmPlayList::setDisplayFormat(const QString &format, const QString &formatMulti) {	const char* cformat = format.latin1();	const char* cformatMulti = formatMulti.latin1();    for (QListViewItemIterator it(this); it.current(); ++it)        static_cast<QmPlayListItem*>(it.current())->setDisplayFormat(cformat, cformatMulti);}/*!  Loads the playlist \a filename.  If \a filename is QString::null, the  default playlist (stored in the Apollo configuration directory) will be  loaded.  The \a above argument specifies where the new items will be placed.  If  \a above is null, the will be placed at the start of the list.  This function will silently fail if something is wrong with the playlist  file. */QmPlayListItem*QmPlayList::loadPlayList(	const QString &filename,	QmPlayListItem *above){    bool empty = isEmpty();	if(filename.isEmpty())	{		QmMainWindow::mainwin->statusUpdate(new Message(Message::Error,                                                        "Error: tried to load playlist without a filename"));		return 0;	}		QmPlayListFormat *f = QmPlayListFormat::getFormat(filename);	QmPlayListItem *ret = f->load(this, filename, above);    	if (empty)	{        m_Filename = filename;        m_Dirty = false;		m_SongIndexDirty = true;    }	else        setDirty();    	delete f;    reCalculate();	triggerUpdate();	return ret;}/*!  Marks the selected item as the next one to be played.*/voidQmPlayList::continueHere(){    QmMainWindow::mainwin->continueHere(dynamic_cast<QmPlayListItem *>(currentItem()));}/*!  \todo just as hook for later (following qmplaylistbrowser pattern)*/voidQmPlayList::showPopup(QListViewItem *current, const QPoint &pos, int){    m_pMenu->popup(pos);}/*!  Called when either of the mouse buttons are clicked.  \sa showPopup(QListViewItem*, const QPoint&, int) */voidQmPlayList::mouseClick(    int button,    QListViewItem * item,    const QPoint & pos,    int c ){    if (button & Qt::MidButton)        QmMainWindow::mainwin->addToPlayFirst();    else if (button & Qt::RightButton)        showPopup(item, pos, c);//    else if ( button & Qt::LeftButton )}/*! */voidQmPlayList::dragEnterEvent(    QDragEnterEvent *event){	event->accept(canDecode(event) || QmListView::canDecode(event));

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -