This file is indexed.

/usr/share/qt3/doc/html/dirview-example.html is in qt3-doc 3:3.3.8-b-8ubuntu3.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
<!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 Qt.  This example
** program may be used, distributed and modified without limitation.
**
*****************************************************************************/

#ifndef DIRVIEW_H
#define DIRVIEW_H

#include &lt;<a href="qlistview-h.html">qlistview.h</a>&gt;
#include &lt;<a href="qstring-h.html">qstring.h</a>&gt;
#include &lt;<a href="qfile-h.html">qfile.h</a>&gt;
#include &lt;<a href="qfileinfo-h.html">qfileinfo.h</a>&gt;
#include &lt;<a href="qtimer-h.html">qtimer.h</a>&gt;

class QWidget;
class QDragEnterEvent;
class QDragMoveEvent;
class QDragLeaveEvent;
class QDropEvent;

class FileItem : public <a href="qlistviewitem.html">QListViewItem</a>
{
public:
    FileItem( <a href="qlistviewitem.html">QListViewItem</a> *parent, const <a href="qstring.html">QString</a> &amp;s1, const <a href="qstring.html">QString</a> &amp;s2 )
        : <a href="qlistviewitem.html">QListViewItem</a>( parent, s1, s2 ), pix( 0 ) {}

    const <a href="qpixmap.html">QPixmap</a> *pixmap( int i ) const;
#if !defined(Q_NO_USING_KEYWORD)
    using QListViewItem::setPixmap;
#endif
    void setPixmap( <a href="qpixmap.html">QPixmap</a> *p );

private:
    <a href="qpixmap.html">QPixmap</a> *pix;

};

class Directory : public <a href="qlistviewitem.html">QListViewItem</a>
{
public:
    Directory( <a href="qlistview.html">QListView</a> * parent, const <a href="qstring.html">QString</a>&amp; filename );
    Directory( Directory * parent, const <a href="qstring.html">QString</a>&amp; filename, const <a href="qstring.html">QString</a> &amp;col2 )
        : <a href="qlistviewitem.html">QListViewItem</a>( parent, filename, col2 ), pix( 0 ) {}
    Directory( Directory * parent, const <a href="qstring.html">QString</a>&amp; filename );

    <a href="qstring.html">QString</a> text( int column ) const;

    <a href="qstring.html">QString</a> fullName();

    void setOpen( bool );
    void setup();

    const <a href="qpixmap.html">QPixmap</a> *pixmap( int i ) const;
#if !defined(Q_NO_USING_KEYWORD)
    using QListViewItem::setPixmap;
#endif
    void setPixmap( <a href="qpixmap.html">QPixmap</a> *p );

private:
    <a href="qfile.html">QFile</a> f;
    Directory * p;
    bool readable;
    bool showDirsOnly;
    <a href="qpixmap.html">QPixmap</a> *pix;

};

class DirectoryView : public <a href="qlistview.html">QListView</a>
{
    <a href="metaobjects.html#Q_OBJECT">Q_OBJECT</a>

public:
    DirectoryView( <a href="qwidget.html">QWidget</a> *parent = 0, const char *name = 0, bool sdo = FALSE );
    bool showDirsOnly() { return dirsOnly; }

public slots:
    void setDir( const <a href="qstring.html">QString</a> &amp; );

signals:
    void folderSelected( const <a href="qstring.html">QString</a> &amp; );

protected slots:
    void slotFolderSelected( <a href="qlistviewitem.html">QListViewItem</a> * );
    void openFolder();

protected:
    void contentsDragEnterEvent( <a href="qdragenterevent.html">QDragEnterEvent</a> *e );
    void contentsDragMoveEvent( <a href="qdragmoveevent.html">QDragMoveEvent</a> *e );
    void contentsDragLeaveEvent( <a href="qdragleaveevent.html">QDragLeaveEvent</a> *e );
    void contentsDropEvent( <a href="qdropevent.html">QDropEvent</a> *e );
    void contentsMouseMoveEvent( <a href="qmouseevent.html">QMouseEvent</a> *e );
    void contentsMousePressEvent( <a href="qmouseevent.html">QMouseEvent</a> *e );
    void contentsMouseReleaseEvent( <a href="qmouseevent.html">QMouseEvent</a> *e );

private:
    <a href="qstring.html">QString</a> fullPath(QListViewItem* item);
    bool dirsOnly;
    <a href="qlistviewitem.html">QListViewItem</a> *oldCurrent;
    <a href="qlistviewitem.html">QListViewItem</a> *dropItem;
    <a href="qtimer.html">QTimer</a>* autoopen_timer;
    <a href="qpoint.html">QPoint</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 Qt.  This example
** program may be used, distributed and modified without limitation.
**
*****************************************************************************/

#include "dirview.h"

#include &lt;<a href="qdir-h.html">qdir.h</a>&gt;
#include &lt;<a href="qfile-h.html">qfile.h</a>&gt;
#include &lt;<a href="qfileinfo-h.html">qfileinfo.h</a>&gt;
#include &lt;<a href="qpixmap-h.html">qpixmap.h</a>&gt;
#include &lt;<a href="qevent-h.html">qevent.h</a>&gt;
#include &lt;<a href="qpoint-h.html">qpoint.h</a>&gt;
#include &lt;<a href="qmessagebox-h.html">qmessagebox.h</a>&gt;
#include &lt;<a href="qdragobject-h.html">qdragobject.h</a>&gt;
#include &lt;<a href="qmime-h.html">qmime.h</a>&gt;
#include &lt;<a href="qstrlist-h.html">qstrlist.h</a>&gt;
#include &lt;<a href="qstringlist-h.html">qstringlist.h</a>&gt;
#include &lt;<a href="qapplication-h.html">qapplication.h</a>&gt;
#include &lt;<a href="qheader-h.html">qheader.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#......",
    ".......##......."};

QPixmap *folderLocked = 0;
QPixmap *folderClosed = 0;
QPixmap *folderOpen = 0;
QPixmap *fileNormal = 0;

/*****************************************************************************
 *
 * Class Directory
 *
 *****************************************************************************/

<a name="f476"></a>Directory::Directory( Directory * parent, const <a href="qstring.html">QString</a>&amp; filename )
    : <a href="qlistviewitem.html">QListViewItem</a>( parent ), f(filename),
      showDirsOnly( parent-&gt;showDirsOnly ),
      pix( 0 )
{
    p = parent;
    readable = QDir( 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="qlistview.html">QListView</a> * parent, const <a href="qstring.html">QString</a>&amp; filename )
    : <a href="qlistviewitem.html">QListViewItem</a>( parent ), f(filename),
      showDirsOnly( ( (DirectoryView*)parent )-&gt;showDirsOnly() ),
      pix( 0 )
{
    p = 0;
    readable = QDir( fullName() ).isReadable();
}


<a name="x1691"></a>void Directory::<a href="qlistviewitem.html#setPixmap">setPixmap</a>( <a href="qpixmap.html">QPixmap</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 QPixmap *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="qstring.html">QString</a> s( fullName() );
        <a href="qdir.html">QDir</a> thisDir( s );
<a name="x1667"></a>        if ( !thisDir.<a href="qdir.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 QFileInfoList * files = thisDir.<a href="qdir.html#entryInfoList">entryInfoList</a>();
        if ( files ) {
            QFileInfoListIterator it( *files );
            <a href="qfileinfo.html">QFileInfo</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="qfileinfo.html#fileName">fileName</a>() == "." || fi-&gt;<a href="qfileinfo.html#fileName">fileName</a>() == ".." )
                    ; // nothing
<a name="x1678"></a>                else if ( fi-&gt;<a href="qfileinfo.html#isSymLink">isSymLink</a>() &amp;&amp; !showDirsOnly ) {
                    FileItem *item = new FileItem( this, fi-&gt;<a href="qfileinfo.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="qfileinfo.html#isDir">isDir</a>() )
                    (void)new Directory( this, fi-&gt;<a href="qfileinfo.html#fileName">fileName</a>() );
                else if ( !showDirsOnly ) {
                    FileItem *item
                        = new FileItem( this, fi-&gt;<a href="qfileinfo.html#fileName">fileName</a>(),
<a name="x1677"></a>                                             fi-&gt;<a href="qfileinfo.html#isFile">isFile</a>()?"File":"Special" );
                    item-&gt;<a href="qlistviewitem.html#setPixmap">setPixmap</a>( fileNormal );
                }
            }
        }
        listView()-&gt;setUpdatesEnabled( TRUE );
    }
    QListViewItem::<a href="qlistviewitem.html#setOpen">setOpen</a>( o );
}


<a name="x1692"></a>void Directory::<a href="qlistviewitem.html#setup">setup</a>()
{
    setExpandable( TRUE );
    QListViewItem::<a href="qlistviewitem.html#setup">setup</a>();
}


QString <a name="f477"></a>Directory::fullName()
{
    <a href="qstring.html">QString</a> s;
    if ( p ) {
        s = p-&gt;fullName();
<a name="x1701"></a>        s.<a href="qstring.html#append">append</a>( f.name() );
        s.<a href="qstring.html#append">append</a>( "/" );
    } else {
        s = f.name();
    }
    return s;
}


<a name="x1693"></a>QString 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="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#connect">connect</a>( this, SIGNAL( <a href="qlistview.html#doubleClicked">doubleClicked</a>( <a href="qlistviewitem.html">QListViewItem</a> * ) ),
             this, SLOT( slotFolderSelected( <a href="qlistviewitem.html">QListViewItem</a> * ) ) );
    <a href="qobject.html#connect">connect</a>( this, SIGNAL( <a href="qlistview.html#returnPressed">returnPressed</a>( <a href="qlistviewitem.html">QListViewItem</a> * ) ),
             this, SLOT( slotFolderSelected( <a href="qlistviewitem.html">QListViewItem</a> * ) ) );

    <a href="qwidget.html#setAcceptDrops">setAcceptDrops</a>( TRUE );
    <a href="qscrollview.html#viewport">viewport</a>()-&gt;setAcceptDrops( TRUE );

<a name="x1706"></a>    <a href="qobject.html#connect">connect</a>( autoopen_timer, SIGNAL( <a href="qtimer.html#timeout">timeout</a>() ),
             this, SLOT( openFolder() ) );
}

void <a name="f479"></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="f480"></a>DirectoryView::openFolder()
{
<a name="x1705"></a>    autoopen_timer-&gt;<a href="qtimer.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="qscrollview.html#contentsDragEnterEvent">contentsDragEnterEvent</a>( <a href="qdragenterevent.html">QDragEnterEvent</a> *e )
{
    if ( !QUriDrag::canDecode(e) ) {
<a name="x1669"></a>        e-&gt;<a href="qdragmoveevent.html#ignore">ignore</a>();
        return;
    }

    oldCurrent = <a href="qlistview.html#currentItem">currentItem</a>();

<a name="x1673"></a>    <a href="qlistviewitem.html">QListViewItem</a> *i = <a href="qlistview.html#itemAt">itemAt</a>( <a href="qscrollview.html#contentsToViewport">contentsToViewport</a>(e-&gt;<a href="qdropevent.html#pos">pos</a>()) );
    if ( i ) {
        dropItem = i;
<a name="x1704"></a>        autoopen_timer-&gt;<a href="qtimer.html#start">start</a>( autoopenTime );
    }
}


<a name="x1681"></a>void DirectoryView::<a href="qscrollview.html#contentsDragMoveEvent">contentsDragMoveEvent</a>( <a href="qdragmoveevent.html">QDragMoveEvent</a> *e )
{
    if ( !QUriDrag::canDecode(e) ) {
        e-&gt;<a href="qdragmoveevent.html#ignore">ignore</a>();
        return;
    }

    <a href="qpoint.html">QPoint</a> vp = <a href="qscrollview.html#contentsToViewport">contentsToViewport</a>( ( (QDragMoveEvent*)e )-&gt;pos() );
    <a href="qlistviewitem.html">QListViewItem</a> *i = <a href="qlistview.html#itemAt">itemAt</a>( vp );
    if ( i ) {
        <a href="qlistview.html#setSelected">setSelected</a>( i, TRUE );
<a name="x1668"></a>        e-&gt;<a href="qdragmoveevent.html#accept">accept</a>();
        if ( i != dropItem ) {
            autoopen_timer-&gt;<a href="qtimer.html#stop">stop</a>();
            dropItem = i;
            autoopen_timer-&gt;<a href="qtimer.html#start">start</a>( autoopenTime );
        }
<a name="x1672"></a>        switch ( e-&gt;<a href="qdropevent.html#action">action</a>() ) {
        case QDropEvent::Copy:
            break;
        case QDropEvent::Move:
<a name="x1671"></a>            e-&gt;<a href="qdropevent.html#acceptAction">acceptAction</a>();
            break;
        case QDropEvent::Link:
            e-&gt;<a href="qdropevent.html#acceptAction">acceptAction</a>();
            break;
        default:
            ;
        }
    } else {
        e-&gt;<a href="qdragmoveevent.html#ignore">ignore</a>();
        autoopen_timer-&gt;<a href="qtimer.html#stop">stop</a>();
        dropItem = 0;
    }
}

<a name="x1680"></a>void DirectoryView::<a href="qscrollview.html#contentsDragLeaveEvent">contentsDragLeaveEvent</a>( <a href="qdragleaveevent.html">QDragLeaveEvent</a> * )
{
    autoopen_timer-&gt;<a href="qtimer.html#stop">stop</a>();
    dropItem = 0;

    <a href="qlistview.html#setCurrentItem">setCurrentItem</a>( oldCurrent );
    <a href="qlistview.html#setSelected">setSelected</a>( oldCurrent, TRUE );
}

<a name="x1682"></a>void DirectoryView::<a href="qscrollview.html#contentsDropEvent">contentsDropEvent</a>( <a href="qdropevent.html">QDropEvent</a> *e )
{
    autoopen_timer-&gt;<a href="qtimer.html#stop">stop</a>();

    if ( !QUriDrag::canDecode(e) ) {
        e-&gt;<a href="qdragmoveevent.html#ignore">ignore</a>();
        return;
    }

    <a href="qlistviewitem.html">QListViewItem</a> *item = <a href="qlistview.html#itemAt">itemAt</a>( <a href="qscrollview.html#contentsToViewport">contentsToViewport</a>(e-&gt;<a href="qdropevent.html#pos">pos</a>()) );
    if ( item ) {

        <a href="qstrlist.html">QStrList</a> lst;

<a name="x1707"></a>        QUriDrag::<a href="quridrag.html#decode">decode</a>( e, lst );

        <a href="qstring.html">QString</a> str;

        switch ( e-&gt;<a href="qdropevent.html#action">action</a>() ) {
            case QDropEvent::Copy:
            str = "Copy";
            break;
            case QDropEvent::Move:
            str = "Move";
            e-&gt;<a href="qdropevent.html#acceptAction">acceptAction</a>();
            break;
            case QDropEvent::Link:
            str = "Link";
            e-&gt;<a href="qdropevent.html#acceptAction">acceptAction</a>();
            break;
            default:
            str = "Unknown";
        }

        str += "\n\n";

        e-&gt;<a href="qdragmoveevent.html#accept">accept</a>();

<a name="x1699"></a>        for ( uint i = 0; i &lt; lst.<a href="qptrlist.html#count">count</a>(); ++i ) {
<a name="x1709"></a><a name="x1697"></a><a name="x1664"></a>            <a href="qstring.html">QString</a> filename = QDir::<a href="qdir.html#convertSeparators">convertSeparators</a>(QUriDrag::<a href="quridrag.html#uriToLocalFile">uriToLocalFile</a>(lst.<a href="qptrlist.html#at">at</a>(i)));
            str += filename + "\n";
        }
        str += QString( "\nTo\n\n   %1" )
            .arg( QDir::<a href="qdir.html#convertSeparators">convertSeparators</a>(fullPath(item)) );

<a name="x1695"></a>        QMessageBox::<a href="qmessagebox.html#information">information</a>( this, "Drop target", str, "Not implemented" );
    } else
        e-&gt;<a href="qdragmoveevent.html#ignore">ignore</a>();

}


QString <a name="f481"></a>DirectoryView::fullPath(QListViewItem* item)
{
    <a href="qstring.html">QString</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 Q_WS_WIN
<a name="x1702"></a>        if (fullpath.<a href="qstring.html#length">length</a>() &gt; 2 &amp;&amp; fullpath[1] != ':') {
                <a href="qdir.html">QDir</a> dir(fullpath);
<a name="x1665"></a>                fullpath = dir.<a href="qdir.html#currentDirPath">currentDirPath</a>().left(2) + fullpath;
        }
#endif

    return fullpath;
}

<a name="x1684"></a>void DirectoryView::<a href="qlistview.html#contentsMousePressEvent">contentsMousePressEvent</a>( <a href="qmouseevent.html">QMouseEvent</a>* e )
{
    QListView::<a href="qlistview.html#contentsMousePressEvent">contentsMousePressEvent</a>(e);
    <a href="qpoint.html">QPoint</a> p( contentsToViewport( e-&gt;<a href="qdropevent.html#pos">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!
<a name="x1696"></a>        if ( p.<a href="qpoint.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="qpoint.html#x">x</a>() &lt; header()-&gt;cellPos( header()-&gt;mapToActual( 0 ) ) ) {
            presspos = e-&gt;<a href="qdropevent.html#pos">pos</a>();
            mousePressed = TRUE;
        }
    }
}

<a name="x1683"></a>void DirectoryView::<a href="qlistview.html#contentsMouseMoveEvent">contentsMouseMoveEvent</a>( <a href="qmouseevent.html">QMouseEvent</a>* e )
{
    if ( mousePressed &amp;&amp; ( presspos - e-&gt;<a href="qdropevent.html#pos">pos</a>() ).manhattanLength() &gt; QApplication::<a href="qapplication.html#startDragDistance">startDragDistance</a>() ) {
        mousePressed = FALSE;
        <a href="qlistviewitem.html">QListViewItem</a> *item = itemAt( contentsToViewport(presspos) );
        if ( item ) {
            <a href="qstring.html">QString</a> source = fullPath(item);
<a name="x1674"></a>            if ( QFile::<a href="qfile.html#exists">exists</a>(source) ) {
                <a href="quridrag.html">QUriDrag</a>* ud = new <a href="quridrag.html">QUriDrag</a>(viewport());
<a name="x1708"></a>                ud-&gt;<a href="quridrag.html#setFileNames">setFileNames</a>( source );
<a name="x1670"></a>                if ( ud-&gt;<a href="qdragobject.html#drag">drag</a>() )
                    QMessageBox::<a href="qmessagebox.html#information">information</a>( this, "Drag source",
                    QString("Delete ") + QDir::convertSeparators(source), "Not implemented" );
            }
        }
    }
}

<a name="x1685"></a>void DirectoryView::<a href="qlistview.html#contentsMouseReleaseEvent">contentsMouseReleaseEvent</a>( <a href="qmouseevent.html">QMouseEvent</a> * )
{
    mousePressed = FALSE;
}

void <a name="f482"></a>DirectoryView::setDir( const <a href="qstring.html">QString</a> &amp;s )
{
    <a href="qlistviewitemiterator.html">QListViewItemIterator</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="qstringlist.html">QStringList</a> lst( QStringList::<a href="qstringlist.html#split">split</a>( "/", s ) );
    <a href="qlistviewitem.html">QListViewItem</a> *item = <a href="qlistviewitem.html#firstChild">firstChild</a>();
<a name="x1698"></a>    QStringList::Iterator it2 = lst.<a href="qvaluelist.html#begin">begin</a>();
<a name="x1700"></a>    for ( ; it2 != lst.<a href="qvaluelist.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="qpixmap.html">QPixmap</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 QPixmap *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 Qt.  This example
** program may be used, distributed and modified without limitation.
**
*****************************************************************************/

#include &lt;<a href="qapplication-h.html">qapplication.h</a>&gt;
#include &lt;<a href="qfileinfo-h.html">qfileinfo.h</a>&gt;
#include &lt;<a href="qdir-h.html">qdir.h</a>&gt;
#include "dirview.h"

int main( int argc, char ** argv )
{
    <a href="qapplication.html">QApplication</a> a( argc, argv );

    DirectoryView mw;

<a name="x1714"></a>    mw.<a href="qlistview.html#addColumn">addColumn</a>( "Name" );
    mw.<a href="qlistview.html#addColumn">addColumn</a>( "Type" );
<a name="x1716"></a>    mw.<a href="qlistview.html#setTreeStepSize">setTreeStepSize</a>( 20 );

<a name="x1712"></a>    const QFileInfoList* roots = QDir::<a href="qdir.html#drives">drives</a>();
    <a href="qptrlistiterator.html">QPtrListIterator</a>&lt;QFileInfo&gt; i(*roots);
    <a href="qfileinfo.html">QFileInfo</a>* fi;
    while ( (fi = *i) ) {
        ++i;
<a name="x1713"></a>        Directory * root = new Directory( &amp;mw, fi-&gt;<a href="qfileinfo.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="qwidget.html#resize">resize</a>( 400, 400 );
    mw.<a href="qwidget.html#setCaption">setCaption</a>( "Qt Example - Directory Browser" );
<a name="x1715"></a>    mw.<a href="qlistview.html#setAllColumnsShowFocus">setAllColumnsShowFocus</a>( TRUE );
    a.<a href="qapplication.html#setMainWidget">setMainWidget</a>( &amp;mw );
<a name="x1717"></a>    mw.<a href="qwidget.html#show">show</a>();

    return a.<a href="qapplication.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>Qt 3.3.8</div>
</table></div></address></body>
</html>