📄 qmplaylistbrowseritem.cpp
字号:
/* qmplaylistbrowseritem.cpp * * $Id: qmplaylistbrowseritem.cpp,v 1.16.2.2 2002/10/11 06:39:03 kyllingstad Exp $ * * Apollo sound player: http://www.apolloplayer.org * Copyright(C) 2000-2002 Apollo Team. See CREDITS file. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * The GNU General Public License is also available online at: * * http://www.gnu.org/copyleft/gpl.html */#include "qmplaylistbrowseritem.h"#include "qmconfig.h"#include "qmpixmapsupplier.h"#include <qtextstream.h>/* Disables false warning in Visual Studio about dynamic_cast */#ifdef _WS_WIN_#pragma warning(disable: 4541)#endif/** * @file qmplaylistbrowseritem.cpp * @brief A playlist, can contain other playlists *//*! \class QmPlayListBrowserItem qmplaylistbrowseritem.h \brief Represents a playlist item in the playlist tree (browser). Do not confuse this class with QmPlayListItem. Instances of QmPlayListItem are in the playlist itself, that is, folders and songs, which are traversed and played. Items of QmPlayListBrowserItem represents entire either playlists or folders in the playlist tree. The difference between a folder and a playlist are: <ul> <li>A playlist cannot contain other folders (folder here not being a directory in the filesystem but a playlist container in the playlist tree).</li> <li>A folder does not have a filename.</li> </ul> \todo We may want unify these two concepts somehow?*//*! Creates a root item to be placed in the playlist browser (selector) \a parent. The \a name is the visible text of the item. The \a filename is the filename of the playlist. However, if \a is_folder is true, \a filename will be not be used, although it can still be retrieved through QmBrowserItem::fileName(). The \a is_folder argument specifies whether the item is to be a playlist or a folder of playlists/folders.*/QmPlayListBrowserItem::QmPlayListBrowserItem( QListView *parent, QListViewItem *after, const QString &name, const QString &playlist, bool isFolder) : QmBrowserItem(parent, after, name, playlist), m_IsFolder(isFolder){ init();}/*! \overload */QmPlayListBrowserItem::QmPlayListBrowserItem( QmPlayListBrowserItem *parent, QListViewItem *after, const QString &name, const QString &playlist, bool is_folder) : QmBrowserItem(parent, after, name, playlist), m_IsFolder(is_folder){ init();}voidQmPlayListBrowserItem::init(){ QmPixmapSupplier *sup = QmPixmapSupplier::instance(); if ( m_IsFolder ) setPixmap( 0, sup->pixmap( "icons-folder" ) ); else setPixmap( 0, sup->pixmap( "icons-playlist" ) );}/*!*/QmPlayListBrowserItem::~QmPlayListBrowserItem(){}/*! \return True if this item is a folder, false otherwise.*/boolQmPlayListBrowserItem::isFolder() const{ return m_IsFolder;}/*! Saves the item to \a out. Unlike QmBrowserItem::save(QTextStream&), this saves \e all items, regardless of depth.*/voidQmPlayListBrowserItem::save( QTextStream &out) const{ QListViewItemIterator it(listView()); save(out, it); // Debug: Dump to stdout.// QTextStream q_cout( stdout, IO_WriteOnly );// save(q_cout, it);}/*! Recursive helper function for save(QTextStream &). \a out is the same as in the other save function. */voidQmPlayListBrowserItem::save( QTextStream &out, QListViewItemIterator &it) const{ QmBrowserItem *item; QmPlayListBrowserItem *pitem; QString tag; while(it.current() != 0) { item = dynamic_cast<QmBrowserItem*>(it.current()); CHECK_PTR(item); pitem = dynamic_cast<QmPlayListBrowserItem*>(item); CHECK_PTR(pitem); QString s1(QmConfig::indent(item->depth() + 1)); QString s2(QmConfig::indent(item->depth() + 2)); if( pitem->isFolder() ) tag = "dir"; else tag = "playlist"; out << s1 << "<" << tag << ">\n" << s2 << "<name>" << "<![CDATA[" << item->text(0) << "]]>" << "</name>\n"; if( ! pitem->isFolder() ) out << s2 << "<path>" << "<![CDATA[" << pitem->fileName() << "]]>" << "</path>\n"; out << s2 << "<open>" << item->isOpen() << "</open>\n"; ++it; if(it.current() == 0) { out << s1 << "</" << tag << ">\n"; break; } else { if(it.current()->depth() == item->depth()) out << s1 << "</" << tag << ">\n"; else if(it.current()->depth() > item->depth()) { save(out, it); out << s1 << "</" << tag << ">\n"; } else { out << s1 << "</" << tag << ">\n"; return; } } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -