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

📄 qmsongitem.cpp

📁 可以播放MP3,wma等文件格式的播放器
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/* qmsongitem.cpp * * $Id: qmsongitem.cpp,v 1.51.2.1 2002/10/10 21:40:52 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 "qmsongitem.h"#include <qbrush.h>#include <qdir.h>#include <qfileinfo.h>#include <qpainter.h>#include <qpixmap.h>#include <qstringlist.h>#include <qtextstream.h>#include "qmconfig.h"#include "qmmarkmanager.h"#include "qmpixmapsupplier.h"#include "qmsonginfo.h"/** * @file qmsongitem.cpp * @brief A song.  Widget. *//*!  \class QmSongItem qmsongitem.h  \brief Represents a song in the play list.  This class maintains a so-called bad list.  The bad list is a list  of files which will be skipped during play list playing.  This is  useful if some files are played incorrectly by the underlaying player,  even though the files may be fine.*//*!  Constructs a new song item in the list view \a parent,  the song being pointed to in \a filename.*/QmSongItem::QmSongItem(    QListView* parent,    QListViewItem* after,    QString filename,    long lengthSeconds,    int bitrate,    bool vbr,    QString title,    QString artist,    QString album,    QString cdPosition,	bool multiArtist,	int year,	QString comment,	QString displayString)    : QmPlayListItem(parent, after),	  m_File(filename),      m_Title(title),      m_Artist(artist),      m_Album(album),      m_CdPosition(cdPosition),	  m_Comment(comment),	  m_DisplayString(displayString),	  m_Year(year),	        m_Bitrate(bitrate),	  m_Rating(),	  m_Played(),      m_VariableBitrate(vbr),	  m_Playing(false),	  m_IsBad(false),	  m_MultiArtistAlbum(multiArtist){    init(lengthSeconds);} /*!  Destroys the song item.*/QmSongItem::~QmSongItem(){}/*!  Constructs a new song item as a child of the folder \a parent,  placed below \a after, the song being pointed to in \a filename.*/QmSongItem::QmSongItem(    QmPlayListItem* parent,    QListViewItem* after,    QString filename,    long lengthSeconds,    int bitrate,    bool vbr,    QString title,    QString artist,    QString album,    QString cdPosition,	bool multiArtist,	int year,	QString comment,	QString displayString)    : QmPlayListItem(parent, after),	  m_File(filename),      m_Title(title),      m_Artist(artist),      m_Album(album),      m_CdPosition(cdPosition),	  m_Comment(comment),	  m_DisplayString(displayString),	  m_Year(year),	        m_Bitrate(bitrate),	  m_Rating(),	  m_Played(),      m_VariableBitrate(vbr),	  m_Playing(false),	  m_IsBad(false),	  m_MultiArtistAlbum(multiArtist){    init(lengthSeconds);}/*!  Initializes the song item with a pixmap and sets some variables.*/voidQmSongItem::init(long lengthSeconds){    m_Playing = false;    setLengthSeconds(lengthSeconds);    m_LengthSeconds = lengthSeconds;	}/*!  Sets up pixmaps, if necessary. */voidQmSongItem::setup(){    QListViewItem::setup();    bool packed;    QmConfig::instance()->get( "stuff", "packed", packed);    if (packed)        setHeight(listView()->fontMetrics().height());    else	{        QmPixmapSupplier *sup = QmPixmapSupplier::instance();        setPixmap( 0, sup->pixmap( "icons-songitem" ) );    }}/*!  Reads song information from the file and fills out \a format with  the values retrieved from the song, if any.*/voidQmSongItem::readInfo(	const char *format,	const char *multiFormat){	QmSongInfo *si = QmSongInfo::create(m_File.filePath());    CHECK_PTR(si);    bool changed = false;	setField(m_Album, si->get(QmSongInfo::Album), changed);	setField(m_Title, si->get(QmSongInfo::Title), changed);	setField(m_Artist, si->get(QmSongInfo::Artist), changed);	setField(m_CdPosition, si->get(QmSongInfo::Track), changed);	if (si->get(QmSongInfo::MultiArtist).isEmpty() == m_MultiArtistAlbum)	{		m_MultiArtistAlbum = !m_MultiArtistAlbum;		changed = true;	}	QString len = si->get(QmSongInfo::Length);    	if( ! len.isEmpty())	{		changed = true;		setLengthSeconds(len.toLong());	}    if (changed)        setDisplayFormat(format, multiFormat);	delete si;}/*!  If \a value is non-empty and not the same as \a field, \a field will  be updated and \a change set to true. Otherwise, this function does  nothing. */voidQmSongItem::setField(	QString &field,	const QString &value,	bool &change){    if(value.isEmpty())        return;//    cout << field << " " << value << std::endl;        if (field != value)	{        field = value;        change = true;    }}/*!  Sets the item as being played and repaints the item.*/voidQmSongItem::setPlaying(    bool p){    m_Playing = p;	repaint();}/*!  Overridden to return the correct text for the various columns.  Column 0 returns either the filename or the song title if it has been set.  Column 1 returns the song length or an empty string.  All other columns return "-"*/QStringQmSongItem::text(    int column) const{    switch(column)    {        case 0:            return m_DisplayString.isEmpty() ?  m_File.fileName() : m_DisplayString;            break;        case 1:            return m_Length;            break;        default:            return "-";            break;    }}/*!  \return The file path of the song item, ie. the filename including the path.*/QStringQmSongItem::filePath() const{    return m_File.filePath();}/*!  Custom paint routine.*/voidQmSongItem::paintCell(    QPainter *p,    const QColorGroup &cg,    int column,    int width,    int alignment){//	QmPlayListItem::paintCell(p, cg, column, width, alignment);	if(isSelected())	{		p->setPen(cg.highlightedText());        if(this == matchItem())            p->fillRect(0, 0, width, height(), QBrush(red));		else if(isBad())			p->fillRect(0, 0, width, height(), cg.mid());		else if(m_Playing)			p->fillRect(0, 0, width, height(), QBrush(blue));		else			p->fillRect(0, 0, width, height(), cg.highlight());	}	else	{        if(this == matchItem())            p->setPen(red);		else if(isBad())			p->setPen(cg.mid());		else if(m_Playing)			p->setPen(blue);		else			p->setPen(cg.text());		p->fillRect(0, 0, width, height(), cg.base());	}	if(column == 0)	{        bool packed;        QmConfig::instance()->get( "stuff", "packed", packed);		        if(packed)		{            p->drawText(listView()->itemMargin() + listView()->itemMargin(),                                height() / 2 - p->fontMetrics().height() / 2,                        width + 1,                        height(),                        alignment,                        text(column));        }        else		{                p->drawPixmap(listView()->itemMargin(), listView()->itemMargin(),                          *pixmap(0));	            p->drawText(listView()->itemMargin() + pixmap(0)->width() + listView()->itemMargin(),                        height() / 2 - p->fontMetrics().height() / 2,                        width + 1,                        height(),                        alignment,                        text(column));        }	}	else	{		p->drawText(listView()->itemMargin(),					height() / 2 - p->fontMetrics().height() / 2,					width - 2*listView()->itemMargin(),					height(),					alignment,					text(column));	}}/*!  Paints the focus for the item.*/voidQmSongItem::paintFocus(    QPainter *p,    const QColorGroup &cg,    const QRect &r){	p->setPen(cg.highlight());	QRect rect(r.x() + 1, r.y() + 1, r.width() - 2, r.height() - 2);	p->drawWinFocusRect(rect);}/*!  Creates a "save string" which be saved to disk, and loaded at a later time  to create an identical instance of this class.    \return The save string of the item. */QStringQmSongItem::save(	const QString &rel_path) const{    QDir dir = m_File.dir();    QDir rel_dir( rel_path );    QString name = m_File.fileName();    bool done = false;    QString full_dir_name, dir_name;	    while ( !done )    {        if ( rel_dir == dir )            done = true;        else        {            dir_name = dir.dirName();            if ( dir.isRoot() )            {                full_dir_name = QString( "/" ) + full_dir_name;                done = true;            }            else            {                if ( !dir.cdUp() )                    done = true;                else                    full_dir_name = dir_name + "/" + full_dir_name;            }        }    }	    if ( full_dir_name.isEmpty() )        return name;    else        return full_dir_name + name;}/*!  This function is used to determine whether an item is a song or a folder.  \return True for items of this class.*/boolQmSongItem::isSong() const{	return true;}/*!  Sets the bad mark if \a mark is true, clears it if false.*/voidQmSongItem::setMark(	bool mark ){	if(mark)

⌨️ 快捷键说明

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