📄 qmdirbrowseritem.cpp
字号:
/* qmdirbrowseritem.cpp * * $Id: qmdirbrowseritem.cpp,v 1.14.2.3 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 "qmdirbrowseritem.h"// #include "qmpixmapsupplier.h"#include "qmconfig.h"#include <iostream>#include <qdir.h>#include <qfileinfo.h>#include <qlistview.h>#include <qtextstream.h>#include <qstringlist.h>/* Disables false warning in Visual Studio about dynamic_cast */#ifdef _WS_WIN_#pragma warning(disable: 4541)#endif/** * @file qmdirbrowseritem.cpp * @brief Directory widget for the browser */struct stat QmDirBrowserItem::statBuf;/*! \class QmDirBrowserItem qmdirbrowseritem.h \brief Represents a directory in the browser. Instances of this class represents directories in the directory tree.*/QmDirBrowserItem::QmDirBrowserItem( QListView *parent, const QString &text, const QString &filename) : QmBrowserItem(parent, 0, text, filename){// This is (unsurprisingly) painfully slow:// (didn't bother trying to optimise it since the c-way is ok)// QDir tmp(filename);// tmp.setFilter(QDir::Dirs);// QStringList subdirs = tmp.entryList();// setExpandable(subdirs.count() > 2); if (stat(filename.latin1(), &statBuf) == 0) setExpandable(statBuf.st_nlink > 2);// QmPixmapSupplier *sup = QmPixmapSupplier::instance();// setPixmap( 0, sup->pixmap( "icons-folder" ) );}QmDirBrowserItem::QmDirBrowserItem( QmDirBrowserItem *parent, const QString &text, const QString &filename) : QmBrowserItem(parent, 0, text, filename){ if (stat(filename.latin1(), &statBuf) == 0) setExpandable(statBuf.st_nlink > 2);// QmPixmapSupplier *sup = QmPixmapSupplier::instance();// setPixmap( 0, sup->pixmap( "icons-folder" ) );}QmDirBrowserItem::~QmDirBrowserItem(){}/*! Reads the subfolders of the folder this item is representing if \a o is true. Based on Qt's dirview example code. */voidQmDirBrowserItem::setOpen( bool o){ if ( o && ! childCount() ) { QString s( fileName() ); QDir thisDir( s ); if ( ! thisDir.isReadable() ) { setExpandable( false ); return; } listView()->setUpdatesEnabled( false ); const QFileInfoList * files = thisDir.entryInfoList(); if ( files ) { QFileInfoListIterator it( *files ); QFileInfo * fi; while( (fi=it.current()) != 0 ) { ++it; if ( fi->fileName() == "." || fi->fileName() == ".." ) ; // nothing else if ( fi->isDir() && fi->isReadable() ) (void) new QmDirBrowserItem( this, fi->fileName(), fi->filePath() ); } } listView()->setUpdatesEnabled( true ); } QListViewItem::setOpen( o );}/*! Saves the item to \a out. Only root items are saved, i.e. items with depth 0.*/voidQmDirBrowserItem::save( QTextStream &out) const{ if(depth() > 0) return; QString s1(QmConfig::indent(1)); QString s2(QmConfig::indent(2)); const QmBrowserItem *item = this; while(item != 0) { out << s1 << "<dir>\n" << s2 << "<name>" << "<![CDATA[" << item->text(0) << "]]>" << "</name>\n" << s2 << "<path>" << "<![CDATA[" << item->fileName() << "]]>" << "</path>\n" << s2 << "<open>" << item->isOpen() << "</open>\n" << s1 << "</dir>\n"; // It's too bad we have to do a dynamic cast so often, but there's no way around it. item = dynamic_cast<const QmBrowserItem*>(item->nextSibling()); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -