You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
tqt3/doc/html/dirview-example.html

752 lines
29 KiB

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!-- /home/espenr/tmp/qt-3.3.8-espenr-2499/qt-x11-free-3.3.8/examples/dirview/dirview.doc:5 -->
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>A Directory Browser</title>
<style type="text/css"><!--
fn { margin-left: 1cm; text-indent: -1cm; }
a:link { color: #004faf; text-decoration: none }
a:visited { color: #672967; text-decoration: none }
body { background: #ffffff; color: black; }
--></style>
</head>
<body>
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr bgcolor="#E5E5E5">
<td valign=center>
<a href="index.html">
<font color="#004faf">Home</font></a>
| <a href="classes.html">
<font color="#004faf">All&nbsp;Classes</font></a>
| <a href="mainclasses.html">
<font color="#004faf">Main&nbsp;Classes</font></a>
| <a href="annotated.html">
<font color="#004faf">Annotated</font></a>
| <a href="groups.html">
<font color="#004faf">Grouped&nbsp;Classes</font></a>
| <a href="functions.html">
<font color="#004faf">Functions</font></a>
</td>
<td align="right" valign="center"><img src="logo32.png" align="right" width="64" height="32" border="0"></td></tr></table><h1 align=center>A Directory Browser</h1>
<p>
This example program demonstrates how to use a listview and
listview items to build a multi-column hierarchical, memory- and
CPU-efficient directory browser. It also demonstrates how to use
Drag&Drop in a listview.
<p> <hr>
<p> Header file:
<p> <pre>/****************************************************************************
** $Id: qt/dirview.h 3.3.8 edited Jan 11 14:37 $
**
** Copyright (C) 1992-2007 Trolltech ASA. All rights reserved.
**
** This file is part of an example program for TQt. This example
** program may be used, distributed and modified without limitation.
**
*****************************************************************************/
#ifndef DIRVIEW_H
#define DIRVIEW_H
#include &lt;<a href="qlistview-h.html">ntqlistview.h</a>&gt;
#include &lt;<a href="tqstring-h.html">tqstring.h</a>&gt;
#include &lt;<a href="tqfile-h.html">tqfile.h</a>&gt;
#include &lt;<a href="tqfileinfo-h.html">tqfileinfo.h</a>&gt;
#include &lt;<a href="tqtimer-h.html">tqtimer.h</a>&gt;
class TQWidget;
class TQDragEnterEvent;
class TQDragMoveEvent;
class TQDragLeaveEvent;
class TQDropEvent;
class FileItem : public <a href="qlistviewitem.html">TQListViewItem</a>
{
public:
FileItem( <a href="qlistviewitem.html">TQListViewItem</a> *parent, const <a href="tqstring.html">TQString</a> &amp;s1, const <a href="tqstring.html">TQString</a> &amp;s2 )
: <a href="qlistviewitem.html">TQListViewItem</a>( parent, s1, s2 ), pix( 0 ) {}
const <a href="tqpixmap.html">TQPixmap</a> *pixmap( int i ) const;
#if !defined(Q_NO_USING_KEYWORD)
using TQListViewItem::setPixmap;
#endif
void setPixmap( <a href="tqpixmap.html">TQPixmap</a> *p );
private:
<a href="tqpixmap.html">TQPixmap</a> *pix;
};
class Directory : public <a href="qlistviewitem.html">TQListViewItem</a>
{
public:
Directory( <a href="ntqlistview.html">TQListView</a> * parent, const <a href="tqstring.html">TQString</a>&amp; filename );
Directory( Directory * parent, const <a href="tqstring.html">TQString</a>&amp; filename, const <a href="tqstring.html">TQString</a> &amp;col2 )
: <a href="qlistviewitem.html">TQListViewItem</a>( parent, filename, col2 ), pix( 0 ) {}
Directory( Directory * parent, const <a href="tqstring.html">TQString</a>&amp; filename );
<a href="tqstring.html">TQString</a> text( int column ) const;
<a href="tqstring.html">TQString</a> fullName();
void setOpen( bool );
void setup();
const <a href="tqpixmap.html">TQPixmap</a> *pixmap( int i ) const;
#if !defined(Q_NO_USING_KEYWORD)
using TQListViewItem::setPixmap;
#endif
void setPixmap( <a href="tqpixmap.html">TQPixmap</a> *p );
private:
<a href="tqfile.html">TQFile</a> f;
Directory * p;
bool readable;
bool showDirsOnly;
<a href="tqpixmap.html">TQPixmap</a> *pix;
};
class DirectoryView : public <a href="ntqlistview.html">TQListView</a>
{
<a href="metaobjects.html#TQ_OBJECT">TQ_OBJECT</a>
public:
DirectoryView( <a href="tqwidget.html">TQWidget</a> *parent = 0, const char *name = 0, bool sdo = FALSE );
bool showDirsOnly() { return dirsOnly; }
public slots:
void setDir( const <a href="tqstring.html">TQString</a> &amp; );
signals:
void folderSelected( const <a href="tqstring.html">TQString</a> &amp; );
protected slots:
void slotFolderSelected( <a href="qlistviewitem.html">TQListViewItem</a> * );
void openFolder();
protected:
void contentsDragEnterEvent( <a href="tqdragenterevent.html">TQDragEnterEvent</a> *e );
void contentsDragMoveEvent( <a href="tqdragmoveevent.html">TQDragMoveEvent</a> *e );
void contentsDragLeaveEvent( <a href="tqdragleaveevent.html">TQDragLeaveEvent</a> *e );
void contentsDropEvent( <a href="tqdropevent.html">TQDropEvent</a> *e );
void contentsMouseMoveEvent( <a href="qmouseevent.html">TQMouseEvent</a> *e );
void contentsMousePressEvent( <a href="qmouseevent.html">TQMouseEvent</a> *e );
void contentsMouseReleaseEvent( <a href="qmouseevent.html">TQMouseEvent</a> *e );
private:
<a href="tqstring.html">TQString</a> fullPath(TQListViewItem* item);
bool dirsOnly;
<a href="qlistviewitem.html">TQListViewItem</a> *oldCurrent;
<a href="qlistviewitem.html">TQListViewItem</a> *dropItem;
<a href="tqtimer.html">TQTimer</a>* autoopen_timer;
<a href="tqpoint.html">TQPoint</a> presspos;
bool mousePressed;
};
#endif
</pre>
<p> <hr>
<p> And here is the main implementation file. Note the way the program
scans subdirectories only when it has to. This allows the program
to handle very large file systems efficiently. The same technique
can be used in any other trees.
<p> <pre>/****************************************************************************
** $Id: qt/dirview.cpp 3.3.8 edited Jan 11 14:37 $
**
** Copyright (C) 1992-2007 Trolltech ASA. All rights reserved.
**
** This file is part of an example program for TQt. This example
** program may be used, distributed and modified without limitation.
**
*****************************************************************************/
#include "dirview.h"
#include &lt;<a href="tqdir-h.html">tqdir.h</a>&gt;
#include &lt;<a href="tqfile-h.html">tqfile.h</a>&gt;
#include &lt;<a href="tqfileinfo-h.html">tqfileinfo.h</a>&gt;
#include &lt;<a href="tqpixmap-h.html">tqpixmap.h</a>&gt;
#include &lt;<a href="tqevent-h.html">tqevent.h</a>&gt;
#include &lt;<a href="tqpoint-h.html">tqpoint.h</a>&gt;
#include &lt;<a href="qmessagebox-h.html">ntqmessagebox.h</a>&gt;
#include &lt;<a href="tqdragobject-h.html">tqdragobject.h</a>&gt;
#include &lt;<a href="tqmime-h.html">tqmime.h</a>&gt;
#include &lt;<a href="tqstrlist-h.html">tqstrlist.h</a>&gt;
#include &lt;<a href="tqstringlist-h.html">tqstringlist.h</a>&gt;
#include &lt;<a href="qapplication-h.html">ntqapplication.h</a>&gt;
#include &lt;<a href="qheader-h.html">ntqheader.h</a>&gt;
static const char* folder_closed_xpm[]={
"16 16 9 1",
"g c #808080",
"b c #c0c000",
"e c #c0c0c0",
"# c #000000",
"c c #ffff00",
". c None",
"a c #585858",
"f c #a0a0a4",
"d c #ffffff",
"..###...........",
".#abc##.........",
".#daabc#####....",
".#ddeaabbccc#...",
".#dedeeabbbba...",
".#edeeeeaaaab#..",
".#deeeeeeefe#ba.",
".#eeeeeeefef#ba.",
".#eeeeeefeff#ba.",
".#eeeeefefff#ba.",
".##geefeffff#ba.",
"...##gefffff#ba.",
".....##fffff#ba.",
".......##fff#b##",
".........##f#b##",
"...........####."};
static const char* folder_open_xpm[]={
"16 16 11 1",
"# c #000000",
"g c #c0c0c0",
"e c #303030",
"a c #ffa858",
"b c #808080",
"d c #a0a0a4",
"f c #585858",
"c c #ffdca8",
"h c #dcdcdc",
"i c #ffffff",
". c None",
"....###.........",
"....#ab##.......",
"....#acab####...",
"###.#acccccca#..",
"#ddefaaaccccca#.",
"#bdddbaaaacccab#",
".eddddbbaaaacab#",
".#bddggdbbaaaab#",
"..edgdggggbbaab#",
"..#bgggghghdaab#",
"...ebhggghicfab#",
"....#edhhiiidab#",
"......#egiiicfb#",
"........#egiibb#",
"..........#egib#",
"............#ee#"};
static const char * folder_locked[]={
"16 16 10 1",
"h c #808080",
"b c #ffa858",
"f c #c0c0c0",
"e c #c05800",
"# c #000000",
"c c #ffdca8",
". c None",
"a c #585858",
"g c #a0a0a4",
"d c #ffffff",
"..#a#...........",
".#abc####.......",
".#daa#eee#......",
".#ddf#e##b#.....",
".#dfd#e#bcb##...",
".#fdccc#daaab#..",
".#dfbbbccgfg#ba.",
".#ffb#ebbfgg#ba.",
".#ffbbe#bggg#ba.",
".#fffbbebggg#ba.",
".##hf#ebbggg#ba.",
"...###e#gggg#ba.",
".....#e#gggg#ba.",
"......###ggg#b##",
".........##g#b##",
"...........####."};
static const char * pix_file []={
"16 16 7 1",
"# c #000000",
"b c #ffffff",
"e c #000000",
"d c #404000",
"c c #c0c000",
"a c #ffffc0",
". c None",
"................",
".........#......",
"......#.#a##....",
".....#b#bbba##..",
"....#b#bbbabbb#.",
"...#b#bba##bb#..",
"..#b#abb#bb##...",
".#a#aab#bbbab##.",
"#a#aaa#bcbbbbbb#",
"#ccdc#bcbbcbbb#.",
".##c#bcbbcabb#..",
"...#acbacbbbe...",
"..#aaaacaba#....",
"...##aaaaa#.....",
".....##aa#......",
".......##......."};
TQPixmap *folderLocked = 0;
TQPixmap *folderClosed = 0;
TQPixmap *folderOpen = 0;
TQPixmap *fileNormal = 0;
/*****************************************************************************
*
* Class Directory
*
*****************************************************************************/
<a name="f476"></a>Directory::Directory( Directory * parent, const <a href="tqstring.html">TQString</a>&amp; filename )
: <a href="qlistviewitem.html">TQListViewItem</a>( parent ), f(filename),
showDirsOnly( parent-&gt;showDirsOnly ),
pix( 0 )
{
p = parent;
readable = TQDir( fullName() ).isReadable();
if ( !readable )
<a href="qlistviewitem.html#setPixmap">setPixmap</a>( folderLocked );
else
<a href="qlistviewitem.html#setPixmap">setPixmap</a>( folderClosed );
}
Directory::Directory( <a href="ntqlistview.html">TQListView</a> * parent, const <a href="tqstring.html">TQString</a>&amp; filename )
: <a href="qlistviewitem.html">TQListViewItem</a>( parent ), f(filename),
showDirsOnly( ( (DirectoryView*)parent )-&gt;showDirsOnly() ),
pix( 0 )
{
p = 0;
readable = TQDir( fullName() ).isReadable();
}
<a name="x1691"></a>void Directory::<a href="qlistviewitem.html#setPixmap">setPixmap</a>( <a href="tqpixmap.html">TQPixmap</a> *px )
{
pix = px;
<a href="qlistviewitem.html#setup">setup</a>();
<a href="qlistviewitem.html#widthChanged">widthChanged</a>( 0 );
<a href="qlistviewitem.html#invalidateHeight">invalidateHeight</a>();
<a href="qlistviewitem.html#repaint">repaint</a>();
}
<a name="x1689"></a>const TQPixmap *Directory::<a href="qlistviewitem.html#pixmap">pixmap</a>( int i ) const
{
if ( i )
return 0;
return pix;
}
<a name="x1690"></a>void Directory::<a href="qlistviewitem.html#setOpen">setOpen</a>( bool o )
{
if ( o )
<a href="qlistviewitem.html#setPixmap">setPixmap</a>( folderOpen );
else
<a href="qlistviewitem.html#setPixmap">setPixmap</a>( folderClosed );
if ( o &amp;&amp; !childCount() ) {
<a href="tqstring.html">TQString</a> s( fullName() );
<a href="tqdir.html">TQDir</a> thisDir( s );
<a name="x1667"></a> if ( !thisDir.<a href="tqdir.html#isReadable">isReadable</a>() ) {
readable = FALSE;
<a href="qlistviewitem.html#setExpandable">setExpandable</a>( FALSE );
return;
}
<a href="qlistviewitem.html#listView">listView</a>()-&gt;setUpdatesEnabled( FALSE );
<a name="x1666"></a> const TQFileInfoList * files = thisDir.<a href="tqdir.html#entryInfoList">entryInfoList</a>();
if ( files ) {
TQFileInfoListIterator it( *files );
<a href="tqfileinfo.html">TQFileInfo</a> * fi;
<a name="x1694"></a> while( (fi=it.<a href="qlistviewitemiterator.html#current">current</a>()) != 0 ) {
++it;
<a name="x1675"></a> if ( fi-&gt;<a href="tqfileinfo.html#fileName">fileName</a>() == "." || fi-&gt;<a href="tqfileinfo.html#fileName">fileName</a>() == ".." )
; // nothing
<a name="x1678"></a> else if ( fi-&gt;<a href="tqfileinfo.html#isSymLink">isSymLink</a>() &amp;&amp; !showDirsOnly ) {
FileItem *item = new FileItem( this, fi-&gt;<a href="tqfileinfo.html#fileName">fileName</a>(),
"Symbolic Link" );
item-&gt;<a href="qlistviewitem.html#setPixmap">setPixmap</a>( fileNormal );
}
<a name="x1676"></a> else if ( fi-&gt;<a href="tqfileinfo.html#isDir">isDir</a>() )
(void)new Directory( this, fi-&gt;<a href="tqfileinfo.html#fileName">fileName</a>() );
else if ( !showDirsOnly ) {
FileItem *item
= new FileItem( this, fi-&gt;<a href="tqfileinfo.html#fileName">fileName</a>(),
<a name="x1677"></a> fi-&gt;<a href="tqfileinfo.html#isFile">isFile</a>()?"File":"Special" );
item-&gt;<a href="qlistviewitem.html#setPixmap">setPixmap</a>( fileNormal );
}
}
}
listView()-&gt;setUpdatesEnabled( TRUE );
}
TQListViewItem::<a href="qlistviewitem.html#setOpen">setOpen</a>( o );
}
<a name="x1692"></a>void Directory::<a href="qlistviewitem.html#setup">setup</a>()
{
setExpandable( TRUE );
TQListViewItem::<a href="qlistviewitem.html#setup">setup</a>();
}
TQString <a name="f477"></a>Directory::fullName()
{
<a href="tqstring.html">TQString</a> s;
if ( p ) {
s = p-&gt;fullName();
<a name="x1701"></a> s.<a href="tqstring.html#append">append</a>( f.name() );
s.<a href="tqstring.html#append">append</a>( "/" );
} else {
s = f.name();
}
return s;
}
<a name="x1693"></a>TQString Directory::<a href="qlistviewitem.html#text">text</a>( int column ) const
{
if ( column == 0 )
return f.name();
else if ( readable )
return "Directory";
else
return "Unreadable Directory";
}
/*****************************************************************************
*
* Class DirectoryView
*
*****************************************************************************/
<a name="f478"></a>DirectoryView::DirectoryView( <a href="tqwidget.html">TQWidget</a> *parent, const char *name, bool sdo )
: <a href="ntqlistview.html">TQListView</a>( parent, name ), dirsOnly( sdo ), oldCurrent( 0 ),
dropItem( 0 ), mousePressed( FALSE )
{
autoopen_timer = new <a href="tqtimer.html">TQTimer</a>( this );
if ( !folderLocked ) {
folderLocked = new <a href="tqpixmap.html">TQPixmap</a>( folder_locked );
folderClosed = new <a href="tqpixmap.html">TQPixmap</a>( folder_closed_xpm );
folderOpen = new <a href="tqpixmap.html">TQPixmap</a>( folder_open_xpm );
fileNormal = new <a href="tqpixmap.html">TQPixmap</a>( pix_file );
}
<a href="tqobject.html#connect">connect</a>( this, TQ_SIGNAL( <a href="ntqlistview.html#doubleClicked">doubleClicked</a>( <a href="qlistviewitem.html">TQListViewItem</a> * ) ),
this, TQ_SLOT( slotFolderSelected( <a href="qlistviewitem.html">TQListViewItem</a> * ) ) );
<a href="tqobject.html#connect">connect</a>( this, TQ_SIGNAL( <a href="ntqlistview.html#returnPressed">returnPressed</a>( <a href="qlistviewitem.html">TQListViewItem</a> * ) ),
this, TQ_SLOT( slotFolderSelected( <a href="qlistviewitem.html">TQListViewItem</a> * ) ) );
<a href="tqwidget.html#setAcceptDrops">setAcceptDrops</a>( TRUE );
<a href="tqscrollview.html#viewport">viewport</a>()-&gt;setAcceptDrops( TRUE );
<a name="x1706"></a> <a href="tqobject.html#connect">connect</a>( autoopen_timer, TQ_SIGNAL( <a href="tqtimer.html#timeout">timeout</a>() ),
this, TQ_SLOT( openFolder() ) );
}
void <a name="f479"></a>DirectoryView::slotFolderSelected( <a href="qlistviewitem.html">TQListViewItem</a> *i )
{
if ( !i || !showDirsOnly() )
return;
Directory *dir = (Directory*)i;
emit folderSelected( dir-&gt;fullName() );
}
void <a name="f480"></a>DirectoryView::openFolder()
{
<a name="x1705"></a> autoopen_timer-&gt;<a href="tqtimer.html#stop">stop</a>();
if ( dropItem &amp;&amp; !dropItem-&gt;isOpen() ) {
dropItem-&gt;setOpen( TRUE );
dropItem-&gt;repaint();
}
}
static const int autoopenTime = 750;
<a name="x1679"></a>void DirectoryView::<a href="tqscrollview.html#contentsDragEnterEvent">contentsDragEnterEvent</a>( <a href="tqdragenterevent.html">TQDragEnterEvent</a> *e )
{
if ( !TQUriDrag::canDecode(e) ) {
<a name="x1669"></a> e-&gt;<a href="tqdragmoveevent.html#ignore">ignore</a>();
return;
}
oldCurrent = <a href="ntqlistview.html#currentItem">currentItem</a>();
<a name="x1673"></a> <a href="qlistviewitem.html">TQListViewItem</a> *i = <a href="ntqlistview.html#itemAt">itemAt</a>( <a href="tqscrollview.html#contentsToViewport">contentsToViewport</a>(e-&gt;<a href="tqdropevent.html#pos">pos</a>()) );
if ( i ) {
dropItem = i;
<a name="x1704"></a> autoopen_timer-&gt;<a href="tqtimer.html#start">start</a>( autoopenTime );
}
}
<a name="x1681"></a>void DirectoryView::<a href="tqscrollview.html#contentsDragMoveEvent">contentsDragMoveEvent</a>( <a href="tqdragmoveevent.html">TQDragMoveEvent</a> *e )
{
if ( !TQUriDrag::canDecode(e) ) {
e-&gt;<a href="tqdragmoveevent.html#ignore">ignore</a>();
return;
}
<a href="tqpoint.html">TQPoint</a> vp = <a href="tqscrollview.html#contentsToViewport">contentsToViewport</a>( ( (TQDragMoveEvent*)e )-&gt;pos() );
<a href="qlistviewitem.html">TQListViewItem</a> *i = <a href="ntqlistview.html#itemAt">itemAt</a>( vp );
if ( i ) {
<a href="ntqlistview.html#setSelected">setSelected</a>( i, TRUE );
<a name="x1668"></a> e-&gt;<a href="tqdragmoveevent.html#accept">accept</a>();
if ( i != dropItem ) {
autoopen_timer-&gt;<a href="tqtimer.html#stop">stop</a>();
dropItem = i;
autoopen_timer-&gt;<a href="tqtimer.html#start">start</a>( autoopenTime );
}
<a name="x1672"></a> switch ( e-&gt;<a href="tqdropevent.html#action">action</a>() ) {
case TQDropEvent::Copy:
break;
case TQDropEvent::Move:
<a name="x1671"></a> e-&gt;<a href="tqdropevent.html#acceptAction">acceptAction</a>();
break;
case TQDropEvent::Link:
e-&gt;<a href="tqdropevent.html#acceptAction">acceptAction</a>();
break;
default:
;
}
} else {
e-&gt;<a href="tqdragmoveevent.html#ignore">ignore</a>();
autoopen_timer-&gt;<a href="tqtimer.html#stop">stop</a>();
dropItem = 0;
}
}
<a name="x1680"></a>void DirectoryView::<a href="tqscrollview.html#contentsDragLeaveEvent">contentsDragLeaveEvent</a>( <a href="tqdragleaveevent.html">TQDragLeaveEvent</a> * )
{
autoopen_timer-&gt;<a href="tqtimer.html#stop">stop</a>();
dropItem = 0;
<a href="ntqlistview.html#setCurrentItem">setCurrentItem</a>( oldCurrent );
<a href="ntqlistview.html#setSelected">setSelected</a>( oldCurrent, TRUE );
}
<a name="x1682"></a>void DirectoryView::<a href="tqscrollview.html#contentsDropEvent">contentsDropEvent</a>( <a href="tqdropevent.html">TQDropEvent</a> *e )
{
autoopen_timer-&gt;<a href="tqtimer.html#stop">stop</a>();
if ( !TQUriDrag::canDecode(e) ) {
e-&gt;<a href="tqdragmoveevent.html#ignore">ignore</a>();
return;
}
<a href="qlistviewitem.html">TQListViewItem</a> *item = <a href="ntqlistview.html#itemAt">itemAt</a>( <a href="tqscrollview.html#contentsToViewport">contentsToViewport</a>(e-&gt;<a href="tqdropevent.html#pos">pos</a>()) );
if ( item ) {
<a href="tqstrlist.html">TQStrList</a> lst;
<a name="x1707"></a> TQUriDrag::<a href="tquridrag.html#decode">decode</a>( e, lst );
<a href="tqstring.html">TQString</a> str;
switch ( e-&gt;<a href="tqdropevent.html#action">action</a>() ) {
case TQDropEvent::Copy:
str = "Copy";
break;
case TQDropEvent::Move:
str = "Move";
e-&gt;<a href="tqdropevent.html#acceptAction">acceptAction</a>();
break;
case TQDropEvent::Link:
str = "Link";
e-&gt;<a href="tqdropevent.html#acceptAction">acceptAction</a>();
break;
default:
str = "Unknown";
}
str += "\n\n";
e-&gt;<a href="tqdragmoveevent.html#accept">accept</a>();
<a name="x1699"></a> for ( uint i = 0; i &lt; lst.<a href="tqptrlist.html#count">count</a>(); ++i ) {
<a name="x1709"></a><a name="x1697"></a><a name="x1664"></a> <a href="tqstring.html">TQString</a> filename = TQDir::<a href="tqdir.html#convertSeparators">convertSeparators</a>(TQUriDrag::<a href="tquridrag.html#uriToLocalFile">uriToLocalFile</a>(lst.<a href="tqptrlist.html#at">at</a>(i)));
str += filename + "\n";
}
str += TQString( "\nTo\n\n %1" )
.arg( TQDir::<a href="tqdir.html#convertSeparators">convertSeparators</a>(fullPath(item)) );
<a name="x1695"></a> TQMessageBox::<a href="ntqmessagebox.html#information">information</a>( this, "Drop target", str, "Not implemented" );
} else
e-&gt;<a href="tqdragmoveevent.html#ignore">ignore</a>();
}
TQString <a name="f481"></a>DirectoryView::fullPath(TQListViewItem* item)
{
<a href="tqstring.html">TQString</a> fullpath = item-&gt;<a href="qlistviewitem.html#text">text</a>(0);
<a name="x1688"></a> while ( (item=item-&gt;<a href="qlistviewitem.html#parent">parent</a>()) ) {
if ( item-&gt;<a href="qlistviewitem.html#parent">parent</a>() )
fullpath = item-&gt;<a href="qlistviewitem.html#text">text</a>(0) + "/" + fullpath;
else
fullpath = item-&gt;<a href="qlistviewitem.html#text">text</a>(0) + fullpath;
}
#ifdef TQ_WS_WIN
<a name="x1702"></a> if (fullpath.<a href="tqstring.html#length">length</a>() &gt; 2 &amp;&amp; fullpath[1] != ':') {
<a href="tqdir.html">TQDir</a> dir(fullpath);
<a name="x1665"></a> fullpath = dir.<a href="tqdir.html#currentDirPath">currentDirPath</a>().left(2) + fullpath;
}
#endif
return fullpath;
}
<a name="x1684"></a>void DirectoryView::<a href="ntqlistview.html#contentsMousePressEvent">contentsMousePressEvent</a>( <a href="qmouseevent.html">TQMouseEvent</a>* e )
{
TQListView::<a href="ntqlistview.html#contentsMousePressEvent">contentsMousePressEvent</a>(e);
<a href="tqpoint.html">TQPoint</a> p( contentsToViewport( e-&gt;<a href="tqdropevent.html#pos">pos</a>() ) );
<a href="qlistviewitem.html">TQListViewItem</a> *i = itemAt( p );
if ( i ) {
// if the user clicked into the root decoration of the item, don't try to start a drag!
<a name="x1696"></a> if ( p.<a href="tqpoint.html#x">x</a>() &gt; header()-&gt;cellPos( header()-&gt;mapToActual( 0 ) ) +
<a name="x1686"></a> treeStepSize() * ( i-&gt;<a href="qlistviewitem.html#depth">depth</a>() + ( rootIsDecorated() ? 1 : 0) ) + itemMargin() ||
p.<a href="tqpoint.html#x">x</a>() &lt; header()-&gt;cellPos( header()-&gt;mapToActual( 0 ) ) ) {
presspos = e-&gt;<a href="tqdropevent.html#pos">pos</a>();
mousePressed = TRUE;
}
}
}
<a name="x1683"></a>void DirectoryView::<a href="ntqlistview.html#contentsMouseMoveEvent">contentsMouseMoveEvent</a>( <a href="qmouseevent.html">TQMouseEvent</a>* e )
{
if ( mousePressed &amp;&amp; ( presspos - e-&gt;<a href="tqdropevent.html#pos">pos</a>() ).manhattanLength() &gt; TQApplication::<a href="ntqapplication.html#startDragDistance">startDragDistance</a>() ) {
mousePressed = FALSE;
<a href="qlistviewitem.html">TQListViewItem</a> *item = itemAt( contentsToViewport(presspos) );
if ( item ) {
<a href="tqstring.html">TQString</a> source = fullPath(item);
<a name="x1674"></a> if ( TQFile::<a href="tqfile.html#exists">exists</a>(source) ) {
<a href="tquridrag.html">TQUriDrag</a>* ud = new <a href="tquridrag.html">TQUriDrag</a>(viewport());
<a name="x1708"></a> ud-&gt;<a href="tquridrag.html#setFileNames">setFileNames</a>( source );
<a name="x1670"></a> if ( ud-&gt;<a href="tqdragobject.html#drag">drag</a>() )
TQMessageBox::<a href="ntqmessagebox.html#information">information</a>( this, "Drag source",
TQString("Delete ") + TQDir::convertSeparators(source), "Not implemented" );
}
}
}
}
<a name="x1685"></a>void DirectoryView::<a href="ntqlistview.html#contentsMouseReleaseEvent">contentsMouseReleaseEvent</a>( <a href="qmouseevent.html">TQMouseEvent</a> * )
{
mousePressed = FALSE;
}
void <a name="f482"></a>DirectoryView::setDir( const <a href="tqstring.html">TQString</a> &amp;s )
{
<a href="qlistviewitemiterator.html">TQListViewItemIterator</a> it( this );
++it;
for ( ; it.<a href="qlistviewitemiterator.html#current">current</a>(); ++it ) {
it.<a href="qlistviewitemiterator.html#current">current</a>()-&gt;setOpen( FALSE );
}
<a name="x1703"></a> <a href="tqstringlist.html">TQStringList</a> lst( TQStringList::<a href="tqstringlist.html#split">split</a>( "/", s ) );
<a href="qlistviewitem.html">TQListViewItem</a> *item = <a href="qlistviewitem.html#firstChild">firstChild</a>();
<a name="x1698"></a> TQStringList::Iterator it2 = lst.<a href="tqvaluelist.html#begin">begin</a>();
<a name="x1700"></a> for ( ; it2 != lst.<a href="tqvaluelist.html#end">end</a>(); ++it2 ) {
while ( item ) {
if ( item-&gt;<a href="qlistviewitem.html#text">text</a>( 0 ) == *it2 ) {
item-&gt;<a href="qlistviewitem.html#setOpen">setOpen</a>( TRUE );
break;
}
<a name="x1687"></a> item = item-&gt;<a href="qlistviewitem.html#itemBelow">itemBelow</a>();
}
}
if ( item )
setCurrentItem( item );
}
void FileItem::<a href="qlistviewitem.html#setPixmap">setPixmap</a>( <a href="tqpixmap.html">TQPixmap</a> *p )
{
pix = p;
<a href="qlistviewitem.html#setup">setup</a>();
<a href="qlistviewitem.html#widthChanged">widthChanged</a>( 0 );
<a href="qlistviewitem.html#invalidateHeight">invalidateHeight</a>();
<a href="qlistviewitem.html#repaint">repaint</a>();
}
const TQPixmap *FileItem::<a href="qlistviewitem.html#pixmap">pixmap</a>( int i ) const
{
if ( i )
return 0;
return pix;
}
</pre>
<p> <hr>
<p> Main:
<p> <pre>/****************************************************************************
** $Id: qt/main.cpp 3.3.8 edited Jan 11 14:37 $
**
** Copyright (C) 1992-2007 Trolltech ASA. All rights reserved.
**
** This file is part of an example program for TQt. This example
** program may be used, distributed and modified without limitation.
**
*****************************************************************************/
#include &lt;<a href="qapplication-h.html">ntqapplication.h</a>&gt;
#include &lt;<a href="tqfileinfo-h.html">tqfileinfo.h</a>&gt;
#include &lt;<a href="tqdir-h.html">tqdir.h</a>&gt;
#include "dirview.h"
int main( int argc, char ** argv )
{
<a href="ntqapplication.html">TQApplication</a> a( argc, argv );
DirectoryView mw;
<a name="x1714"></a> mw.<a href="ntqlistview.html#addColumn">addColumn</a>( "Name" );
mw.<a href="ntqlistview.html#addColumn">addColumn</a>( "Type" );
<a name="x1716"></a> mw.<a href="ntqlistview.html#setTreeStepSize">setTreeStepSize</a>( 20 );
<a name="x1712"></a> const TQFileInfoList* roots = TQDir::<a href="tqdir.html#drives">drives</a>();
<a href="tqptrlistiterator.html">TQPtrListIterator</a>&lt;TQFileInfo&gt; i(*roots);
<a href="tqfileinfo.html">TQFileInfo</a>* fi;
while ( (fi = *i) ) {
++i;
<a name="x1713"></a> Directory * root = new Directory( &amp;mw, fi-&gt;<a href="tqfileinfo.html#filePath">filePath</a>() );
if ( roots-&gt;count() &lt;= 1 )
<a name="x1718"></a> root-&gt;<a href="qlistviewitem.html#setOpen">setOpen</a>( TRUE ); // be interesting
}
<a name="x1719"></a> mw.<a href="tqwidget.html#resize">resize</a>( 400, 400 );
mw.<a href="tqwidget.html#setCaption">setCaption</a>( "TQt Example - Directory Browser" );
<a name="x1715"></a> mw.<a href="ntqlistview.html#setAllColumnsShowFocus">setAllColumnsShowFocus</a>( TRUE );
a.<a href="ntqapplication.html#setMainWidget">setMainWidget</a>( &amp;mw );
<a name="x1717"></a> mw.<a href="tqwidget.html#show">show</a>();
return a.<a href="ntqapplication.html#exec">exec</a>();
}
</pre>
<p>See also <a href="examples.html">Examples</a>.
<!-- eof -->
<p><address><hr><div align=center>
<table width=100% cellspacing=0 border=0><tr>
<td>Copyright &copy; 2007
<a href="troll.html">Trolltech</a><td align=center><a href="trademarks.html">Trademarks</a>
<td align=right><div align=right>TQt 3.3.8</div>
</table></div></address></body>
</html>