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

📄 qmlistview.cpp

📁 可以播放MP3,wma等文件格式的播放器
💻 CPP
📖 第 1 页 / 共 2 页
字号:
QmListView::insertBelow(	QListViewItem *insertitem,	QListViewItem *itemabove){	CHECK_PTR(insertitem);		// First, insert the item so that it has the same parent (if any)...	if(itemabove == 0)    {		insertItem(0, insertitem, 0);    }	else	{        if(m_InsertPos == Child)        {            insertItem(itemabove, insertitem, 0);        }        else        {            insertItem(itemabove->parent(), insertitem, itemabove);        }	}}/*!  Helper function for inserting items.  Inserts \a item so that the item \a parent is it's parent  and makes sure it's placed after the item \c after.  If parent is 0 it is placed at toplevel.  If after is 0 it is placed at the top of the current level.*/voidQmListView::insertItem( QListViewItem *parent,                        QListViewItem *item,                        QListViewItem *after ){    if ( parent )    {        if ( !after )            parent->insertItem( item );        else        {            parent->insertItem( item );            item->moveItem( after );        }    }    else    {        if ( !after )            QListView::insertItem( item );        else        {            QListView::insertItem( item );            item->moveItem( after );        }    }}/*!  \return True if \a parent is the parent of \a item at \e any level,  that is, \a parent does not have to be the immediate parent of \a item  for this function to return true.  If \a parent and \a item is not  connected at all, false is returned.  \a parent can be null, in which this  function will always return false, but not \a item can never be null.*/boolQmListView::isParent(	QListViewItem *parent,	QListViewItem *item) const{	CHECK_PTR(item);	if(parent == 0)		return false;		QListViewItem *temp = item->parent();	while(temp)	{		if(temp == parent)			return true;		temp = temp->parent();	}	return false;}/*!  \return The save filename. */const QString &QmListView::fileName() const{	return m_FileName;}/*!  This function checks whether the dragged items can be dropped below  \a itemabove, that is, whether the dragged items can have the parent  of \a itemabove as a parent.  Usually that would be legal, but it is not if \a itemabove is a child  of any of the items being dragged.  For example, if you have a list  like this:  <ul>  <li>Folder</li>  <ul>  <li>Item 1</li>  <li>Item 2</li>  <li>Item 3</li>  </ul>  </ul>  If you drag 'Folder', it cannot be placed somewhere in between Item 1,  2, or 3.  This function will use selectedItems() to get the list of items being  dragged.  A drop is also considered "illegal" if the item above itself is  selected.  This is because the item above will be used to place the  dropped items, and if the item above is removed, there drop position  is undefined.  \return True if the selected items can be inserted below \a itemabove,  false otherwise.  If \a itemabove is null, true will be returned. */boolQmListView::isDroppable(	QListViewItem *itemabove){	if( ! m_Reorganizable)		return false;		// If there's no item above, the dragged item(s) is/are to inserted at	// the top of the list, that is, they are droppable, so return true.		if(itemabove == 0)		return true;		QList<QListViewItem> *selected = selectedItems();	QListIterator<QListViewItem> it(*selected);	bool rc = true;		for(it.toFirst(); it.current(); ++it)	{		if(itemabove == it.current())		{			rc = false;			break;		}		else if(isParent(it.current(), itemabove))		{			rc = false;			break;		}	}	delete selected;	return rc;}/*!  This function will build a list of selected items.  The term  'selected' here has a different meaning than is normal:  The returned list will contain the minimum set of items.  For  example, if a folder and children of it are selected, only the folder  item will be in the list.  When a folder is selected, all it's  children are implicitly considered to be selected, although this is  not shown visibly to the user.  A different case would be to have children of a folder selected, but  not the folder itself.  In this case, all the children will be added  to the list.  By defining selected as this, it's is possible to e.g. safely delete  all items in the list and therefore also from the listview.  If  children of a parent had been included, these children would  automatically be deleted if the parent was deleted, and therefore  raise a segmentation fault.  \return A list of the selected items.  An  empty list will be returned if no items are selected, but not null.  \warning The caller is responsible for deleting the returned list!*/QList<QListViewItem>*QmListView::selectedItems(){	QList<QListViewItem> *selected = new QList<QListViewItem>;	for( QListViewItemIterator it(this); it.current(); ++it )	{		if( it.current()->isSelected() )		{			selected->append( it.current() );			// If the item has children, we will skip checking them			// whether they are selected or not because they are			// assumed to be selected when their parent is selected.			if( it.current()->childCount() > 0 )			{								int depth = it.current()->depth();				++it;								while(it.current() != 0)				{					if(it.current()->depth() > depth)						++it;					else					{						// We need to jump back one item so we don't skip						// one item because of the ++it in the outermost loop.												--it;						break;					}				}			}		}    }	return selected;}/*!  Removes the selected items*/voidQmListView::removeSelectedItems(){	QList<QListViewItem> *selected = selectedItems();	selected->setAutoDelete(true);	delete selected;}/*!  Calls QListView::clear()*/voidQmListView::clear(){	QListView::clear();}/*!  \return True if there are selected item(s), false otherwise.  \warning This function is rather slow.  It's a convenience function around selectedItems().  \todo Should be const, but selectedItems() is not const so.*/boolQmListView::hasSelectedItems(){	QList<QListViewItem> *selected = selectedItems();	bool rc;		if(selected->count() > 0)		rc = true;	else		rc = false;	delete selected;	return rc;}/*!  Akin to firstChild() but instead returns the last item in the listview.    \sa firstChild()*/QListViewItem*QmListView::lastChild() const{    QListViewItem *found = 0;    QListViewItem *item = firstChild();    while ( item )    {        found = item;        item = item->nextSibling();    }    return found;}/*!  Similar to lastChild(), except this one returns the absolute bottommost  item in the list while lastChild() returns the last item that is directly  a child of the list view (view may not be the bottommost as that item  can have children).  \sa lastChild()*/QListViewItem*QmListView::lastItem() const{    QListViewItem *found = 0;    QListViewItem *item = lastChild();    while ( item )    {        found = item;        item = item->itemBelow();    }    return found;	}/*!  Determines whether \a item is a folder or not.  \return True if \a item is a folder, false otherwise or if \a item is null.*/boolQmListView::isFolder(	QListViewItem *item){	if(dynamic_cast<QmDirItem*>(item) == 0)		return false;	else		return true;}/*!  Call this function with a filename, and the object will save itself to  that file.  \sa disableSelfSave()*/voidQmListView::enableSelfSave(	const QString &filename){	m_FileName = filename;}/*!  Disables self saving.  \sa enableSelfSave()*/voidQmListView::disableSelfSave(){	m_FileName = QString::null;}/*!  Self saves, if enabled.  \sa enableSelfSave(), disableSelfSave() */voidQmListView::save(){	if(m_FileName.isEmpty())		return;	    QFile save_file( m_FileName );	    if ( !save_file.open( IO_WriteOnly ) )    {        QmMainWindow::mainwin->statusUpdate(new Message(Message::Error,                                                        "Error: could not write to %s ",                                                        m_FileName.latin1()));        return;    }	    QTextStream save_stream( &save_file );    save_stream.setEncoding(QTextStream::UnicodeUTF8);    save_stream << "<?xml version='1.0'?>\n"                 << "<!DOCTYPE APOLLO-PLAYLIST>\n";	save(save_stream);}/*!  Saves the object to \a out in XML format.  \sa save() */voidQmListView::save(	QTextStream &out){	QListViewItemIterator it(this);	out << "<apollo-" << name() << ">\n";	// Save the FIRST item in the list.  This item is then responsible for saving	// the rest of the items in whatever fashion it desires.  It's necessary to let	// this be the reponsibility of the item and not the listview.  The reason is that	// in some cases, only root items, for example, needs to be saved.  Other times,	// the entire tree needs to be saved.  Doing a simple iteration from the listview's	// perspective will not be sufficient.		if(it.current() != 0)	{		QmListViewItem *item = dynamic_cast<QmListViewItem*>(it.current());			if(item == 0)			qWarning("QmListView::save() - Unable to save item not derived from QmListViewItem.");		else			item->save(out);	}	out << "</apollo-" << name() << ">\n";}/*!  Set \a r to true to enable reorganizability, e.g. drag and drop operations.  False to disable. */voidQmListView::reorganizable(	bool r){	m_Reorganizable = r;}/*!  Slot which is called by the scroll timer.  It will scroll the view upwards if the pointer is at the top margin,  or down if at the bottom margin.  It also makes sure the indicator marker is updated.  \sa moveIndicator(), atTopMargin(), atBottomMargin()*/voidQmListView::slotScrollView(){    int movement = 15;    if ( m_DragPos.y() < 0 || m_DragPos.y() > viewport()->height() )        movement *= 2;    if ( atTopMargin( m_DragPos ) )    {        scrollBy( 0, -movement );    }    else if ( atBottomMargin( m_DragPos ) )    {        scrollBy( 0, movement );    }    moveIndicator( m_PointerPos );}/*!  Returns true if the position is inside the top margin,  which is the 24 top pixels.  \sa atBottomMargin()*/boolQmListView::atTopMargin( const QPoint &pos ){    return pos.y() < 24;}/*!  Returns true if the position is inside the bottom margin,  which is the 24 bottom pixels.  \sa atTopMargin()*/boolQmListView::atBottomMargin( const QPoint &pos ){    return  pos.y() > viewport()->height() - 24;}/*!  Moves the indicator to the place specified by \a mousepos.*/voidQmListView::moveIndicator( const QPoint &mousepos ){    m_pDropIndicator->show();    QPoint pos = indicatorPos(mousepos);    int indicatorwidth = header()->sectionSize(0) - pos.x();    m_pDropIndicator->setFixedWidth(indicatorwidth);    int ypos = QMIN(pos.y(),                    contentsY() + viewport()->height() - m_pDropIndicator->height() );    moveChild(m_pDropIndicator, pos.x(), ypos );}

⌨️ 快捷键说明

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