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

📄 dirview-main-cpp.html

📁 qtopiaphone英文帮助,用于初学者和开发人员,初学者可以用来学习,开发人员可以用来资料查询.
💻 HTML
📖 第 1 页 / 共 2 页
字号:
            while( (fi=it.<a href="qlistviewitemiterator.html#b134cd">current</a>()) != 0 ) {                ++it;                if ( fi-&gt;<a href="qfileinfo.html#a9e3d2">fileName</a>() == "." || fi-&gt;<a href="qfileinfo.html#a9e3d2">fileName</a>() == ".." )                    ; // nothing                else if ( fi-&gt;<a href="qfileinfo.html#147c8d">isSymLink</a>() &amp;&amp; !showDirsOnly ) {                    FileItem *item = new FileItem( this, fi-&gt;<a href="qfileinfo.html#a9e3d2">fileName</a>(),                                                     "Symbolic Link" );                    item-&gt;<a href="qlistviewitem.html#3b5494">setPixmap</a>( fileNormal );                }                else if ( fi-&gt;<a href="qfileinfo.html#70e102">isDir</a>() )                    (void)new Directory( this, fi-&gt;<a href="qfileinfo.html#a9e3d2">fileName</a>() );                else if ( !showDirsOnly ) {                    FileItem *item                        = new FileItem( this, fi-&gt;<a href="qfileinfo.html#a9e3d2">fileName</a>(),                                             fi-&gt;<a href="qfileinfo.html#177d67">isFile</a>()?"File":"Special" );                    item-&gt;<a href="qlistviewitem.html#3b5494">setPixmap</a>( fileNormal );                }            }        }        <a href="qlistviewitem.html#5a9872">listView</a>()-&gt;setUpdatesEnabled( TRUE );    }    <a href="qlistviewitem.html#1c5a28">QListViewItem::setOpen</a>( o );}void <a name="465"></a>Directory::setup(){    <a href="qlistviewitem.html#725aac">setExpandable</a>( TRUE );    <a href="qlistviewitem.html#c97f42">QListViewItem::setup</a>();}<a href="qstring.html">QString</a> <a name="466"></a>Directory::fullName(){    <a href="qstring.html">QString</a> s;    if ( p ) {        s = p-&gt;fullName();        s.<a href="qstring.html#7478cb">append</a>( f.name() );        s.<a href="qstring.html#7478cb">append</a>( "/" );    } else {        s = f.name();    }    return s;}<a href="qstring.html">QString</a> <a name="467"></a>Directory::text( int column ) const{    if ( column == 0 )        return f.name();    else if ( readable )        return "Directory";    else        return "Unreadable Directory";}/***************************************************************************** * * Class DirectoryView * *****************************************************************************/DirectoryView::DirectoryView( <a href="qwidget.html">QWidget</a> *parent, const char *name, bool sdo )    : <a href="qlistview.html">QListView</a>( parent, name ), dirsOnly( sdo ), oldCurrent( 0 ),      dropItem( 0 ), mousePressed( FALSE ){    autoopen_timer = new <a href="qtimer.html">QTimer</a>( this );    if ( !folderLocked ) {        folderLocked = new <a href="qpixmap.html">QPixmap</a>( folder_locked );        folderClosed = new <a href="qpixmap.html">QPixmap</a>( folder_closed_xpm );        folderOpen = new <a href="qpixmap.html">QPixmap</a>( folder_open_xpm );        fileNormal = new <a href="qpixmap.html">QPixmap</a>( pix_file );    }    <a href="qobject.html#fbde73">connect</a>( this, SIGNAL( <a href="qlistview.html#653d82">doubleClicked</a>( <a href="qlistviewitem.html">QListViewItem</a> * ) ),             this, SLOT( <a href=#451>slotFolderSelected</a>( <a href="qlistviewitem.html">QListViewItem</a> * ) ) );    <a href="qobject.html#fbde73">connect</a>( this, SIGNAL( <a href="qlistview.html#25ca1d">returnPressed</a>( <a href="qlistviewitem.html">QListViewItem</a> * ) ),             this, SLOT( <a href=#451>slotFolderSelected</a>( <a href="qlistviewitem.html">QListViewItem</a> * ) ) );    <a href="qwidget.html#8169cb">setAcceptDrops</a>( TRUE );    <a href="qscrollview.html#26f2bf">viewport</a>()-&gt;setAcceptDrops( TRUE );    <a href="qobject.html#fbde73">connect</a>( autoopen_timer, SIGNAL( timeout() ),             this, SLOT( <a href=#452>openFolder</a>() ) );}void <a name="451"></a>DirectoryView::slotFolderSelected( <a href="qlistviewitem.html">QListViewItem</a> *i ){    if ( !i || !showDirsOnly() )        return;    Directory *dir = (Directory*)i;    emit folderSelected( dir-&gt;fullName() );}void <a name="452"></a>DirectoryView::openFolder(){    autoopen_timer-&gt;stop();    if ( dropItem &amp;&amp; !dropItem-&gt;isOpen() ) {        dropItem-&gt;setOpen( TRUE );        dropItem-&gt;repaint();    }}static const int autoopenTime = 750;void <a name="453"></a>DirectoryView::contentsDragEnterEvent( <a href="qdragenterevent.html">QDragEnterEvent</a> *e ){    if ( !QUriDrag::canDecode(e) ) {        e-&gt;ignore();        return;    }    oldCurrent = currentItem();    <a href="qlistviewitem.html">QListViewItem</a> *i = itemAt( <a href="qscrollview.html#daa8c7">contentsToViewport</a>(e-&gt;<a href="qmouseevent.html#ac6f25">pos</a>()) );    if ( i ) {        dropItem = i;        autoopen_timer-&gt;start( autoopenTime );    }}void <a name="454"></a>DirectoryView::contentsDragMoveEvent( <a href="qdragmoveevent.html">QDragMoveEvent</a> *e ){    if ( !QUriDrag::canDecode(e) ) {        e-&gt;ignore();        return;    }    <a href="qpoint.html">QPoint</a> vp = contentsToViewport( ( (<a href="qdragmoveevent.html">QDragMoveEvent</a>*)e )-&gt;pos() );    <a href="qlistviewitem.html">QListViewItem</a> *i = itemAt( vp );    if ( i ) {        <a href="qlistview.html#8e2ad6">setSelected</a>( i, TRUE );        e-&gt;accept();        if ( i != dropItem ) {            autoopen_timer-&gt;stop();            dropItem = i;            autoopen_timer-&gt;start( autoopenTime );        }        switch ( e-&gt;action() ) {        case QDropEvent::Copy:            break;        case QDropEvent::Move:            e-&gt;acceptAction();            break;        case QDropEvent::Link:            e-&gt;acceptAction();            break;        default:            ;        }    } else {        e-&gt;ignore();        autoopen_timer-&gt;stop();        dropItem = 0;    }}void <a name="455"></a>DirectoryView::contentsDragLeaveEvent( <a href="qdragleaveevent.html">QDragLeaveEvent</a> * ){    autoopen_timer-&gt;stop();    dropItem = 0;    <a href="qlistview.html#b22cc2">setCurrentItem</a>( oldCurrent );    <a href="qlistview.html#8e2ad6">setSelected</a>( oldCurrent, TRUE );}void <a name="456"></a>DirectoryView::contentsDropEvent( <a href="qdropevent.html">QDropEvent</a> *e ){    autoopen_timer-&gt;stop();    if ( !QUriDrag::canDecode(e) ) {        e-&gt;ignore();        return;    }    <a href="qlistviewitem.html">QListViewItem</a> *item = itemAt( <a href="qscrollview.html#daa8c7">contentsToViewport</a>(e-&gt;<a href="qmouseevent.html#ac6f25">pos</a>()) );    if ( item ) {        <a href="qstrlist.html">QStrList</a> lst;        <a href="quridrag.html#e14cb1">QUriDrag::decode</a>( e, lst );        <a href="qstring.html">QString</a> str;        switch ( e-&gt;action() ) {            case QDropEvent::Copy:            str = "Copy";            break;            case QDropEvent::Move:            str = "Move";            e-&gt;acceptAction();            break;            case QDropEvent::Link:            str = "Link";            e-&gt;acceptAction();            break;            default:            str = "Unknown";        }        str += "\n\n";        e-&gt;accept();        for ( uint i = 0; i &lt; lst.count(); ++i ) {            <a href="qstring.html">QString</a> filename = lst.at( i );            str += filename + "\n";        }        str += QString( "\nTo\n\n   %1" )               .arg( <a href=#457>fullPath</a>(item) );        <a href="qmessagebox.html#66b7c8">QMessageBox::information</a>( this, "Drop target", str, "Not implemented" );    } else        e-&gt;ignore();}<a href="qstring.html">QString</a> <a name="457"></a>DirectoryView::fullPath(<a href="qlistviewitem.html">QListViewItem</a>* item){    <a href="qstring.html">QString</a> fullpath = item-&gt;<a href="qlistviewitem.html#ca0608">text</a>(0);    while ( (item=item-&gt;<a href="qlistviewitem.html#201d81">parent</a>()) ) {        if ( item-&gt;<a href="qlistviewitem.html#201d81">parent</a>() )            fullpath = item-&gt;<a href="qlistviewitem.html#ca0608">text</a>(0) + "/" + fullpath;        else            fullpath = item-&gt;<a href="qlistviewitem.html#ca0608">text</a>(0) + fullpath;    }    return fullpath;}void <a name="458"></a>DirectoryView::contentsMousePressEvent( <a href="qmouseevent.html">QMouseEvent</a>* e ){    <a href="qlistview.html#bcd36c">QListView::contentsMousePressEvent</a>(e);    <a href="qpoint.html">QPoint</a> p( <a href="qscrollview.html#daa8c7">contentsToViewport</a>( e-&gt;<a href="qmouseevent.html#ac6f25">pos</a>() ) );    <a href="qlistviewitem.html">QListViewItem</a> *i = itemAt( p );    if ( i ) {        // if the user clicked into the root decoration of the item, don't try to start a drag!        if ( p.x() &gt; header()-&gt;cellPos( <a href="qlistview.html#db5808">header</a>()-&gt;mapToActual( 0 ) ) +             <a href="qlistview.html#0fdfbe">treeStepSize</a>() * ( i-&gt;<a href="qlistviewitem.html#1e0f46">depth</a>() + ( <a href="qlistview.html#dbdbf3">rootIsDecorated</a>() ? 1 : 0) ) + itemMargin() ||             p.x() &lt; header()-&gt;cellPos( <a href="qlistview.html#db5808">header</a>()-&gt;mapToActual( 0 ) ) ) {            presspos = e-&gt;<a href="qmouseevent.html#ac6f25">pos</a>();            mousePressed = TRUE;        }    }}void <a name="459"></a>DirectoryView::contentsMouseMoveEvent( <a href="qmouseevent.html">QMouseEvent</a>* e ){    if ( mousePressed &amp;&amp; ( presspos - e-&gt;<a href="qmouseevent.html#ac6f25">pos</a>() ).manhattanLength() &gt; <a href="qapplication.html#5a44a9">QApplication::startDragDistance</a>() ) {        mousePressed = FALSE;        <a href="qlistviewitem.html">QListViewItem</a> *item = itemAt( <a href="qscrollview.html#daa8c7">contentsToViewport</a>(presspos) );        if ( item ) {            <a href="qstring.html">QString</a> source = fullPath(item);            if ( <a href="qfile.html#900285">QFile::exists</a>(source) ) {                <a href="quridrag.html">QUriDrag</a>* ud = new <a href="quridrag.html">QUriDrag</a>(<a href="qscrollview.html#26f2bf">viewport</a>());                ud-&gt;<a href="quridrag.html#4cdc54">setUnicodeUris</a>( source );                if ( ud-&gt;<a href="qdragobject.html#bfe10b">drag</a>() )                    <a href="qmessagebox.html#66b7c8">QMessageBox::information</a>( this, "Drag source",                                              <a href="qstring.html">QString</a>("Delete ")+source, "Not implemented" );            }        }    }}void <a name="460"></a>DirectoryView::contentsMouseReleaseEvent( <a href="qmouseevent.html">QMouseEvent</a> * ){    mousePressed = FALSE;}void <a name="461"></a>DirectoryView::setDir( const QString &amp;s ){    <a href="qlistviewitemiterator.html">QListViewItemIterator</a> it( this );    ++it;    for ( ; it.<a href="qlistviewitemiterator.html#b134cd">current</a>(); ++it ) {        it.<a href="qlistviewitemiterator.html#b134cd">current</a>()-&gt;setOpen( FALSE );    }    <a href="qstringlist.html">QStringList</a> lst( <a href="qstringlist.html#6f861a">QStringList::split</a>( "/", s ) );    <a href="qlistviewitem.html">QListViewItem</a> *item = firstChild();    QStringList::Iterator it2 = lst.begin();    for ( ; it2 != lst.end(); ++it2 ) {        while ( item ) {            if ( item-&gt;<a href="qlistviewitem.html#ca0608">text</a>( 0 ) == *it2 ) {                item-&gt;<a href="qlistviewitem.html#1c5a28">setOpen</a>( TRUE );                break;            }            item = item-&gt;<a href="qlistviewitem.html#376b5c">itemBelow</a>();        }    }    if ( item )        <a href="qlistview.html#b22cc2">setCurrentItem</a>( item );}void FileItem::setPixmap( <a href="qpixmap.html">QPixmap</a> *p ){    pix = p;    setup();    widthChanged( 0 );    invalidateHeight();    repaint();}const QPixmap *FileItem::pixmap( int i ) const{    if ( i )        return 0;    return pix;}</pre>  <hr>  Main:<pre>/****************************************************************************** &#36;Id&#58; qt/examples/dirview/main.cpp   2.3.8   edited 2004-05-12 $**** Copyright (C) 1992-2000 Trolltech AS.  All rights reserved.**** This file is part of an example program for Qt.  This example** program may be used, distributed and modified without limitation.*******************************************************************************/#include &lt;<a name="qapplication.h"></a><a href="qapplication-h.html">qapplication.h</a>&gt;#include &lt;<a name="qfileinfo.h"></a><a href="qfileinfo-h.html">qfileinfo.h</a>&gt;#include &lt;<a name="qdir.h"></a><a href="qdir-h.html">qdir.h</a>&gt;#include "dirview.h"int main( int argc, char ** argv ){    <a name="QApplication"></a><a href="qapplication.html">QApplication</a> a( argc, argv );    DirectoryView mw;    mw.<a name="addColumn"></a><a href="qlistview.html#2323b8">addColumn</a>( "Name" );    mw.<a href="qlistview.html#2323b8">addColumn</a>( "Type" );    mw.<a name="setTreeStepSize"></a><a href="qlistview.html#101838">setTreeStepSize</a>( 20 );    const QFileInfoList* roots = QDir::drives();    <a name="QListIterator"></a><a href="qlistiterator.html">QListIterator</a>&lt;<a name="QFileInfo"></a><a href="qfileinfo.html">QFileInfo</a>&gt; i(*roots);    <a href="qfileinfo.html">QFileInfo</a>* fi;    while ( (fi = *i) ) {        ++i;        Directory * root = new Directory( &amp;mw, fi-&gt;<a name="filePath"></a><a href="qfileinfo.html#ebb5a0">filePath</a>() );        if ( roots-&gt;count() &lt;= 1 )            root-&gt;<a name="setOpen"></a><a href="qlistviewitem.html#1c5a28">setOpen</a>( TRUE ); // be interesting    }    mw.<a name="resize"></a><a href="qscrollview.html#3480d1">resize</a>( 400, 400 );    mw.<a name="setCaption"></a><a href="qwidget.html#d6a291">setCaption</a>( "Qt Example - Directory Browser" );    mw.<a name="setAllColumnsShowFocus"></a><a href="qlistview.html#93889b">setAllColumnsShowFocus</a>( TRUE );    a.<a name="setMainWidget"></a><a href="qapplication.html#7ad759">setMainWidget</a>( &amp;mw );    mw.<a name="show"></a><a href="qlistview.html#a21cde">show</a>();    return a.<a name="exec"></a><a href="qapplication.html#84c7bf">exec</a>();}</pre><p><address><hr><div align="center"><table width="100%" cellspacing="0" border="0"><tr><td>Copyright 

⌨️ 快捷键说明

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