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.
qt3/doc/html/fileiconview-example.html

1395 lines
56 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/fileiconview/fileiconview.doc:4 -->
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Simple Filemanager</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>Simple Filemanager</h1>
<p>
This example implements a simple and not fully functional file manager using
a widget derived from <a href="qiconview.html">QIconView</a> to display the current directory.
To display the directory tree the
widget written in the <a href="dirview-example.html">dirview</a> example is
used.
<p> <hr>
<p> Header file of the file icon view:
<p> <pre>/****************************************************************************
** $Id: qt/qfileiconview.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 QTFILEICONVIEW_H
#define QTFILEICONVIEW_H
#include &lt;<a href="qiconset-h.html">qiconset.h</a>&gt;
#include &lt;<a href="qstring-h.html">qstring.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 &lt;<a href="qtimer-h.html">qtimer.h</a>&gt;
#include &lt;<a href="qiconview-h.html">qiconview.h</a>&gt;
class QtFileIconView;
class QDragObject;
class QResizeEvent;
/*****************************************************************************
*
* Class QtFileIconDrag
*
*****************************************************************************/
class QtFileIconDrag : public <a href="qicondrag.html">QIconDrag</a>
{
<a href="metaobjects.html#Q_OBJECT">Q_OBJECT</a>
public:
QtFileIconDrag( <a href="qwidget.html">QWidget</a> * dragSource, const char* name = 0 );
const char* format( int i ) const;
<a href="qbytearray.html">QByteArray</a> encodedData( const char* mime ) const;
static bool canDecode( <a href="qmimesource.html">QMimeSource</a>* e );
void append( const <a href="qicondragitem.html">QIconDragItem</a> &amp;item, const <a href="qrect.html">QRect</a> &amp;pr, const <a href="qrect.html">QRect</a> &amp;tr, const <a href="qstring.html">QString</a> &amp;url );
private:
<a href="qstringlist.html">QStringList</a> urls;
};
/*****************************************************************************
*
* Class QtFileIconView
*
*****************************************************************************/
class QtFileIconViewItem;
class QtFileIconView : public <a href="qiconview.html">QIconView</a>
{
Q_OBJECT
public:
QtFileIconView( const <a href="qstring.html">QString</a> &amp;dir, QWidget *parent = 0, const char *name = 0 );
enum ViewMode { Large, Small };
void setViewMode( ViewMode m );
ViewMode viewMode() const { return vm; }
void setOpenItem( QtFileIconViewItem *i ) {
openItem = i;
}
public slots:
void setDirectory( const <a href="qstring.html">QString</a> &amp;dir );
void setDirectory( const <a href="qdir.html">QDir</a> &amp;dir );
void newDirectory();
<a href="qdir.html">QDir</a> currentDir();
signals:
void directoryChanged( const <a href="qstring.html">QString</a> &amp; );
void startReadDir( int dirs );
void readNextDir();
void readDirDone();
void enableUp();
void disableUp();
void enableMkdir();
void disableMkdir();
protected slots:
void itemDoubleClicked( <a href="qiconviewitem.html">QIconViewItem</a> *i );
void slotDropped( <a href="qdropevent.html">QDropEvent</a> *e, const <a href="qvaluelist.html">QValueList</a>&lt;QIconDragItem&gt; &amp; );
void viewLarge();
void viewSmall();
void viewBottom();
void viewRight();
void flowEast();
void flowSouth();
void itemTextTruncate();
void itemTextWordWrap();
void sortAscending();
void sortDescending();
void arrangeItemsInGrid() {
<a name="x807"></a> QIconView::<a href="qiconview.html#arrangeItemsInGrid">arrangeItemsInGrid</a>( TRUE );
}
void slotRightPressed( <a href="qiconviewitem.html">QIconViewItem</a> *item );
void openFolder();
protected:
void readDir( const <a href="qdir.html">QDir</a> &amp;dir );
virtual QDragObject *dragObject();
virtual void keyPressEvent( <a href="qkeyevent.html">QKeyEvent</a> *e );
<a href="qdir.html">QDir</a> viewDir;
int newFolderNum;
<a href="qsize.html">QSize</a> sz;
<a href="qpixmap.html">QPixmap</a> pix;
ViewMode vm;
QtFileIconViewItem *openItem;
};
/*****************************************************************************
*
* Class QtFileIconViewItem
*
*****************************************************************************/
class QtFileIconViewItem : public <a href="qiconviewitem.html">QIconViewItem</a>
{
friend class QtFileIconView;
public:
enum ItemType {
File = 0,
Dir,
Link
};
QtFileIconViewItem( QtFileIconView *parent, QFileInfo *fi );
virtual ~QtFileIconViewItem();
ItemType type() const
{ return itemType; }
<a href="qstring.html">QString</a> filename() const { return itemFileName; }
virtual bool acceptDrop( const <a href="qmimesource.html">QMimeSource</a> *e ) const;
virtual void setText( const <a href="qstring.html">QString</a> &amp;text );
virtual QPixmap *pixmap() const;
virtual void dragEntered();
virtual void dragLeft();
void viewModeChanged( QtFileIconView::ViewMode m );
void paintItem( <a href="qpainter.html">QPainter</a> *p, const <a href="qcolorgroup.html">QColorGroup</a> &amp;cg );
protected:
virtual void dropped( <a href="qdropevent.html">QDropEvent</a> *e, const <a href="qvaluelist.html">QValueList</a>&lt;QIconDragItem&gt; &amp; );
<a href="qstring.html">QString</a> itemFileName;
<a href="qfileinfo.html">QFileInfo</a> *itemFileInfo;
ItemType itemType;
bool checkSetText;
<a href="qtimer.html">QTimer</a> timer;
QtFileIconView::ViewMode vm;
};
#endif
</pre>
<p> <hr>
<p> Implementation of the file icon view:
<p> <pre>/****************************************************************************
** $Id: qt/qfileiconview.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 "qfileiconview.h"
#include &lt;<a href="qpainter-h.html">qpainter.h</a>&gt;
#include &lt;<a href="qstringlist-h.html">qstringlist.h</a>&gt;
#include &lt;<a href="qpixmap-h.html">qpixmap.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="qdragobject-h.html">qdragobject.h</a>&gt;
#include &lt;<a href="qmessagebox-h.html">qmessagebox.h</a>&gt;
#include &lt;<a href="qevent-h.html">qevent.h</a>&gt;
#include &lt;<a href="qpopupmenu-h.html">qpopupmenu.h</a>&gt;
#include &lt;<a href="qcursor-h.html">qcursor.h</a>&gt;
#include &lt;<a href="qapplication-h.html">qapplication.h</a>&gt;
#include &lt;<a href="qwmatrix-h.html">qwmatrix.h</a>&gt;
#include &lt;stdlib.h&gt;
static const char * file_icon[]={
"32 32 17 1",
"# c #000000",
"a c #ffffff",
"j c #808080",
"n c #a0a0a4",
"g c #c0c0c0",
"m c #004000",
"o c #000000",
"l c #004040",
"k c #404000",
"i c #c0c000",
"h c #ffff00",
"b c #ffffc0",
"e c #ff8000",
"f c #c05800",
"c c #ffa858",
"d c #ffdca8",
". c None",
"................................",
"................................",
"................................",
"................................",
".............#....###...........",
"...###......#a##.#aba##.........",
"..#cdb#....#aaaa#aaaaaa##.......",
"..#ecdb#..#aaaa#aaaaaaaba##.....",
"..#fecdb##aaaa#aaaaaaaaaaab##...",
"...#fecdb#aaa#aaaaaaabaabaaaa##.",
"....#fecdb#a#baaaaa#baaaaaabaaa#",
".....#fecdb#aaaaab#a##baaaaaaa#.",
".....##fecdb#bbba#aaaa##baaab#..",
"....#bb#fecdb#ba#aaaaaaa##aa#...",
"...#bbbb#fecdb##aaabaaaaaa##....",
"..#bbbb#b#fecdb#aaaaaaabaaaa##..",
".#bbbb#bbb#fecdg#aaaaaaaaaaaba#.",
"#hhbb#bbbbb#fegg#iiaaaaaaaaaaaa#",
"#jhhhklibbbk#ggj#aaiiaaaaaaaaa#j",
".#mjhhhkmikab####aaabiiaaaaaa#j.",
"...##jhhhmaaibbaaiibaaaiiaab#n..",
".....##j#baaaiiabaaiibaabaa#n...",
"......##baibaabiibaaaiiabb#j....",
"......#bbbbiiaabbiiaaaaabon.....",
".....#bbbbbbbiiabbaiiaab#n......",
".....#jbbbbbbbbiibaabba#n.......",
"......##jbbbbbbbbiiaabmj........",
"........##jbbbbbbbbbb#j.........",
"..........##nbbbbbbbmj..........",
"............##jbbbb#j...........",
"..............#mjj#n............",
"................##n............."};
static const char * folder_icon[]={
"32 32 11 1",
"# c #000000",
"b c #c0c000",
"d c #585858",
"a c #ffff00",
"i c #400000",
"h c #a0a0a4",
"e c #000000",
"c c #ffffff",
"f c #303030",
"g c #c0c0c0",
". c None",
"...###..........................",
"...#aa##........................",
".###baaa##......................",
".#cde#baaa##....................",
".#cccdeebaaa##..##f.............",
".#cccccdeebaaa##aaa##...........",
".#cccccccdeebaaaaaaaa##.........",
".#cccccccccdeebababaaa#.........",
".#cccccgcgghhebbbbbbbaa#........",
".#ccccccgcgggdebbbbbbba#........",
".#cccgcgcgcgghdeebiebbba#.......",
".#ccccgcggggggghdeddeeba#.......",
".#cgcgcgcggggggggghghdebb#......",
".#ccgcggggggggghghghghd#b#......",
".#cgcgcggggggggghghghhd#b#......",
".#gcggggggggghghghhhhhd#b#......",
".#cgcggggggggghghghhhhd#b#......",
".#ggggggggghghghhhhhhhdib#......",
".#gggggggggghghghhhhhhd#b#......",
".#hhggggghghghhhhhhhhhd#b#......",
".#ddhhgggghghghhhhhhhhd#b#......",
"..##ddhhghghhhhhhhhhhhdeb#......",
"....##ddhhhghhhhhhhhhhd#b#......",
"......##ddhhhhhhhhhhhhd#b#......",
"........##ddhhhhhhhhhhd#b#......",
"..........##ddhhhhhhhhd#b#......",
"............##ddhhhhhhd#b###....",
"..............##ddhhhhd#b#####..",
"................##ddhhd#b######.",
"..................##dddeb#####..",
"....................##d#b###....",
"......................####......"};
static const char * link_icon[]={
"32 32 12 1",
"# c #000000",
"h c #a0a0a4",
"b c #c00000",
"d c #585858",
"i c #400000",
"c c #ffffff",
"e c #000000",
"g c #c0c0c0",
"a c #ff0000",
"f c #303030",
"n c white",
". c None",
"...###..........................",
"...#aa##........................",
".###baaa##......................",
".#cde#baaa##....................",
".#cccdeebaaa##..##f.............",
".#cccccdeebaaa##aaa##...........",
".#cccccccdeebaaaaaaaa##.........",
".#cccccccccdeebababaaa#.........",
".#cccccgcgghhebbbbbbbaa#........",
".#ccccccgcgggdebbbbbbba#........",
".#cccgcgcgcgghdeebiebbba#.......",
".#ccccgcggggggghdeddeeba#.......",
".#cgcgcgcggggggggghghdebb#......",
".#ccgcggggggggghghghghd#b#......",
".#cgcgcggggggggghghghhd#b#......",
".#gcggggggggghghghhhhhd#b#......",
".#cgcggggggggghghghhhhd#b#......",
".#ggggggggghghghhhhhhhdib#......",
".#gggggggggghghghhhhhhd#b#......",
".#hhggggghghghhhhhhhhhd#b#......",
".#ddhhgggghghghhhhhhhhd#b#......",
"..##ddhhghghhhhhhhhhhhdeb#......",
"############hhhhhhhhhhd#b#......",
"#nnnnnnnnnn#hhhhhhhhhhd#b#......",
"#nnnnnnnnnn#hhhhhhhhhhd#b#......",
"#nn#nn#nnnn#ddhhhhhhhhd#b#......",
"#nn##n##nnn###ddhhhhhhd#b###....",
"#nnn#####nn#..##ddhhhhd#b#####..",
"#nnnnn##nnn#....##ddhhd#b######.",
"#nnnnn#nnnn#......##dddeb#####..",
"#nnnnnnnnnn#........##d#b###....",
"############..........####......"};
static const char * folder_locked_icon[]={
"32 32 12 1",
"# c #000000",
"g c #808080",
"h c #c0c0c0",
"f c #c05800",
"c c #ffffff",
"d c #585858",
"b c #ffa858",
"a c #ffdca8",
"e c #000000",
"i c #a0a0a4",
"j c #c0c0c0",
". c None",
"...###..........................",
"...#aa##........................",
".###baaa##......................",
".#cde#baaa##....................",
".#cccdeeba#######...............",
".#cccccde##fffff##..............",
".#cccccc##fffgggg#..............",
".#ccccccc#ffg####a##............",
".#ccccchc#ffg#eebbaa##..........",
".#ccccccc#ffg#ddeebbba##........",
".#ccchccc#ffg#ihddeebbba##......",
".#cccccaa#ffg#ihhhddeeba##......",
".#chchhbbaafg#ihhhihidebb#......",
".#cchccbbbbaa#ihhihihid#b#......",
".#chchhbb#bbbaaiihihiid#b#......",
".#hchhcbb#fbbbafhiiiiid#b#......",
".#chchhbb#ffgbbfihiiiid#b#......",
".#hhhhhbb#ffg#bfiiiiiid#b#......",
".#hhhhhbbaffg#bfiiiiiid#b#......",
".#iihhhjbbaab#bfiiiiiid#b#......",
".#ddiihhh#bbbabfiiiiiid#b#......",
"..##ddiih#ffbbbfiiiiiid#b#......",
"....##ddi#ffg#biiiiiiid#b#......",
"......##d#ffg#iiiiiiiid#b#......",
"........##ffg#iiiiiiiid#b#......",
".........#ffg#iiiiiiiid#b#......",
".........#ffg#ddiiiiiid#b###....",
".........##fg###ddiiiid#b#####..",
"...........####.##ddiid#b######.",
"..................##dddeb#####..",
"....................##d#b###....",
"......................####......"};
static QPixmap *iconFolderLockedLarge = 0;
static QPixmap *iconFolderLarge = 0;
static QPixmap *iconFileLarge = 0;
static QPixmap *iconLinkLarge = 0;
static QPixmap *iconFolderLockedSmall = 0;
static QPixmap *iconFolderSmall = 0;
static QPixmap *iconFileSmall = 0;
static QPixmap *iconLinkSmall = 0;
static void cleanup()
{
delete iconFolderLockedLarge;
iconFolderLockedLarge = 0;
delete iconFolderLarge;
iconFolderLarge = 0;
delete iconFileLarge;
iconFileLarge = 0;
delete iconLinkLarge;
iconLinkLarge = 0;
delete iconFolderLockedSmall;
iconFolderLockedSmall = 0;
delete iconFolderSmall;
iconFolderSmall = 0;
delete iconFileSmall;
iconFileSmall = 0;
delete iconLinkSmall;
iconLinkSmall = 0;
}
/*****************************************************************************
*
* Class QtFileIconDrag
*
*****************************************************************************/
<a name="f301"></a>QtFileIconDrag::QtFileIconDrag( <a href="qwidget.html">QWidget</a> * dragSource, const char* name )
: <a href="qicondrag.html">QIconDrag</a>( dragSource, name )
{
}
<a name="x832"></a>const char* QtFileIconDrag::<a href="qmimesource.html#format">format</a>( int i ) const
{
if ( i == 0 )
return "application/x-qiconlist";
else if ( i == 1 )
return "text/uri-list";
else
return 0;
}
<a name="x831"></a>QByteArray QtFileIconDrag::<a href="qicondrag.html#encodedData">encodedData</a>( const char* mime ) const
{
<a href="qbytearray.html">QByteArray</a> a;
if ( QString( mime ) == "application/x-qiconlist" ) {
a = QIconDrag::<a href="qicondrag.html#encodedData">encodedData</a>( mime );
} else if ( QString( mime ) == "text/uri-list" ) {
<a href="qstring.html">QString</a> s = urls.join( "\r\n" );
<a name="x870"></a><a name="x856"></a> a.<a href="qmemarray.html#resize">resize</a>( s.<a href="qstring.html#length">length</a>() );
<a name="x869"></a><a name="x855"></a> memcpy( a.<a href="qmemarray.html#data">data</a>(), s.<a href="qstring.html#latin1">latin1</a>(), s.<a href="qstring.html#length">length</a>() );
}
return a;
}
<a name="x830"></a>bool QtFileIconDrag::<a href="qicondrag.html#canDecode">canDecode</a>( <a href="qmimesource.html">QMimeSource</a>* e )
{
<a name="x819"></a> return e-&gt;<a href="qdropevent.html#provides">provides</a>( "application/x-qiconlist" ) ||
e-&gt;<a href="qdropevent.html#provides">provides</a>( "text/uri-list" );
}
<a name="x829"></a>void QtFileIconDrag::<a href="qicondrag.html#append">append</a>( const <a href="qicondragitem.html">QIconDragItem</a> &amp;item, const <a href="qrect.html">QRect</a> &amp;pr,
const <a href="qrect.html">QRect</a> &amp;tr, const <a href="qstring.html">QString</a> &amp;url )
{
QIconDrag::<a href="qicondrag.html#append">append</a>( item, pr, tr );
<a href="qstring.html">QString</a> ourUrl = url;
#ifdef Q_WS_WIN
if (ourUrl.<a href="qstring.html#length">length</a>() &gt; 2 &amp;&amp; ourUrl[1] != ':') {
<a href="qdir.html">QDir</a> dir(ourUrl);
<a name="x810"></a> ourUrl = dir.<a href="qdir.html#absPath">absPath</a>();
}
#endif
urls &lt;&lt; QUriDrag::<a href="quridrag.html#localFileToUri">localFileToUri</a>(ourUrl);
}
/*****************************************************************************
*
* Class QtFileIconViewItem
*
*****************************************************************************/
<a name="f322"></a>QtFileIconViewItem::QtFileIconViewItem( QtFileIconView *parent, QFileInfo *fi )
<a name="x824"></a><a name="x823"></a> : <a href="qiconviewitem.html">QIconViewItem</a>( parent, fi-&gt;<a href="qfileinfo.html#fileName">fileName</a>() ), itemFileName( fi-&gt;<a href="qfileinfo.html#filePath">filePath</a>() ),
itemFileInfo( fi ), checkSetText( FALSE )
{
vm = QtFileIconView::Large;
<a name="x825"></a> if ( itemFileInfo-&gt;<a href="qfileinfo.html#isDir">isDir</a>() )
itemType = Dir;
<a name="x826"></a> else if ( itemFileInfo-&gt;<a href="qfileinfo.html#isFile">isFile</a>() )
itemType = File;
<a name="x827"></a> if ( itemFileInfo-&gt;<a href="qfileinfo.html#isSymLink">isSymLink</a>() )
itemType = Link;
viewModeChanged( ( (QtFileIconView*)<a href="qiconviewitem.html#iconView">iconView</a>() )-&gt;viewMode() );
if ( itemFileInfo-&gt;<a href="qfileinfo.html#fileName">fileName</a>() == "." ||
itemFileInfo-&gt;<a href="qfileinfo.html#fileName">fileName</a>() == ".." )
<a href="qiconviewitem.html#setRenameEnabled">setRenameEnabled</a>( FALSE );
checkSetText = TRUE;
QObject::<a href="qobject.html#connect">connect</a>( &amp;timer, SIGNAL( timeout() ),
<a href="qiconviewitem.html#iconView">iconView</a>(), SLOT( openFolder() ) );
}
<a name="x842"></a>void QtFileIconViewItem::<a href="qiconviewitem.html#paintItem">paintItem</a>( <a href="qpainter.html">QPainter</a> *p, const <a href="qcolorgroup.html">QColorGroup</a> &amp;cg )
{
if ( itemFileInfo-&gt;<a href="qfileinfo.html#isSymLink">isSymLink</a>() ) {
<a name="x861"></a> <a href="qfont.html">QFont</a> f( p-&gt;<a href="qpainter.html#font">font</a>() );
<a name="x828"></a> f.<a href="qfont.html#setItalic">setItalic</a>( TRUE );
p-&gt;<a href="qpainter.html#setFont">setFont</a>( f );
}
QIconViewItem::<a href="qiconviewitem.html#paintItem">paintItem</a>( p, cg );
}
void <a name="f323"></a>QtFileIconViewItem::viewModeChanged( QtFileIconView::ViewMode m )
{
vm = m;
<a href="qiconviewitem.html#setDropEnabled">setDropEnabled</a>( itemType == Dir &amp;&amp; QDir( itemFileName ).isReadable() );
<a href="qiconviewitem.html#calcRect">calcRect</a>();
}
<a name="x843"></a>QPixmap *QtFileIconViewItem::<a href="qiconviewitem.html#pixmap">pixmap</a>() const
{
switch ( itemType ) {
case Dir:
{
if ( !QDir( itemFileName ).isReadable() ) {
if ( vm == QtFileIconView::Small )
return iconFolderLockedSmall;
else
return iconFolderLockedLarge;
} else {
if ( vm == QtFileIconView::Small )
return iconFolderSmall;
else
return iconFolderLarge;
}
}
case Link:
{
if ( vm == QtFileIconView::Small )
return iconLinkSmall;
else
return iconLinkLarge;
}
default:
{
if ( vm == QtFileIconView::Small )
return iconFileSmall;
else
return iconFileLarge;
}
}
}
QtFileIconViewItem::~QtFileIconViewItem()
{
delete itemFileInfo;
}
<a name="x850"></a>void QtFileIconViewItem::<a href="qiconviewitem.html#setText">setText</a>( const <a href="qstring.html">QString</a> &amp;text )
{
if ( checkSetText ) {
if ( text == "." || text == "." || text.<a href="qstring.html#isEmpty">isEmpty</a>() )
return;
<a name="x821"></a> <a href="qdir.html">QDir</a> dir( itemFileInfo-&gt;<a href="qfileinfo.html#dir">dir</a>() );
<a name="x814"></a> if ( dir.<a href="qdir.html#rename">rename</a>( itemFileInfo-&gt;<a href="qfileinfo.html#fileName">fileName</a>(), text ) ) {
<a name="x822"></a> itemFileName = itemFileInfo-&gt;<a href="qfileinfo.html#dirPath">dirPath</a>( TRUE ) + "/" + text;
delete itemFileInfo;
itemFileInfo = new <a href="qfileinfo.html">QFileInfo</a>( itemFileName );
QIconViewItem::<a href="qiconviewitem.html#setText">setText</a>( text );
}
} else {
QIconViewItem::<a href="qiconviewitem.html#setText">setText</a>( text );
}
}
<a name="x836"></a>bool QtFileIconViewItem::<a href="qiconviewitem.html#acceptDrop">acceptDrop</a>( const <a href="qmimesource.html">QMimeSource</a> *e ) const
{
if ( type() == Dir &amp;&amp; e-&gt;<a href="qdropevent.html#provides">provides</a>( "text/uri-list" ) &amp;&amp;
dropEnabled() )
return TRUE;
return FALSE;
}
<a name="x839"></a>void QtFileIconViewItem::<a href="qiconviewitem.html#dropped">dropped</a>( <a href="qdropevent.html">QDropEvent</a> *e, const <a href="qvaluelist.html">QValueList</a>&lt;QIconDragItem&gt; &amp; )
{
timer.stop();
if ( !QUriDrag::canDecode( e ) ) {
<a name="x818"></a> e-&gt;<a href="qdropevent.html#ignore">ignore</a>();
return;
}
<a href="qstringlist.html">QStringList</a> lst;
<a name="x873"></a> QUriDrag::<a href="quridrag.html#decodeLocalFiles">decodeLocalFiles</a>( e, lst );
<a href="qstring.html">QString</a> str;
<a name="x817"></a> if ( e-&gt;<a href="qdropevent.html#action">action</a>() == QDropEvent::Copy )
str = "Copy\n\n";
else
str = "Move\n\n";
<a name="x874"></a> for ( uint i = 0; i &lt; lst.<a href="qvaluelist.html#count">count</a>(); ++i )
str += QString( " %1\n" ).arg( lst[i] );
str += QString( "\n"
"To\n\n"
" %1" ).arg( filename() );
<a name="x859"></a> QMessageBox::<a href="qmessagebox.html#information">information</a>( iconView(), e-&gt;<a href="qdropevent.html#action">action</a>() == QDropEvent::Copy ? "Copy" : "Move" , str, "Not Implemented" );
if ( e-&gt;<a href="qdropevent.html#action">action</a>() == QDropEvent::Move )
QMessageBox::<a href="qmessagebox.html#information">information</a>( iconView(), "Remove" , str, "Not Implemented" );
<a name="x816"></a> e-&gt;<a href="qdropevent.html#acceptAction">acceptAction</a>();
}
<a name="x837"></a>void QtFileIconViewItem::<a href="qiconviewitem.html#dragEntered">dragEntered</a>()
{
if ( type() != Dir ||
type() == Dir &amp;&amp; !QDir( itemFileName ).isReadable() )
return;
( (QtFileIconView*)iconView() )-&gt;setOpenItem( this );
timer.start( 1500 );
}
<a name="x838"></a>void QtFileIconViewItem::<a href="qiconviewitem.html#dragLeft">dragLeft</a>()
{
if ( type() != Dir ||
type() == Dir &amp;&amp; !QDir( itemFileName ).isReadable() )
return;
timer.stop();
}
/*****************************************************************************
*
* Class QtFileIconView
*
*****************************************************************************/
<a name="f302"></a>QtFileIconView::QtFileIconView( const <a href="qstring.html">QString</a> &amp;dir, QWidget *parent, const char *name )
: <a href="qiconview.html">QIconView</a>( parent, name ), viewDir( dir ), newFolderNum( 0 )
{
if ( !iconFolderLockedLarge ) {
<a href="qapplication.html#qAddPostRoutine">qAddPostRoutine</a>( cleanup );
<a href="qwmatrix.html">QWMatrix</a> m;
<a name="x876"></a> m.<a href="qwmatrix.html#scale">scale</a>( 0.6, 0.6 );
<a href="qpixmap.html">QPixmap</a> iconpix( folder_locked_icon );
iconFolderLockedLarge = new <a href="qpixmap.html">QPixmap</a>( folder_locked_icon );
<a name="x863"></a> iconpix = iconpix.<a href="qpixmap.html#xForm">xForm</a>( m );
iconFolderLockedSmall = new <a href="qpixmap.html">QPixmap</a>( iconpix );
iconpix = QPixmap( folder_icon );
iconFolderLarge = new <a href="qpixmap.html">QPixmap</a>( folder_icon );
iconpix = iconpix.<a href="qpixmap.html#xForm">xForm</a>( m );
iconFolderSmall = new <a href="qpixmap.html">QPixmap</a>( iconpix );
iconpix = QPixmap( file_icon );
iconFileLarge = new <a href="qpixmap.html">QPixmap</a>( file_icon );
iconpix = iconpix.<a href="qpixmap.html#xForm">xForm</a>( m );
iconFileSmall = new <a href="qpixmap.html">QPixmap</a>( iconpix );
iconpix = QPixmap( link_icon );
iconLinkLarge = new <a href="qpixmap.html">QPixmap</a>( link_icon );
iconpix = iconpix.<a href="qpixmap.html#xForm">xForm</a>( m );
iconLinkSmall = new <a href="qpixmap.html">QPixmap</a>( iconpix );
}
vm = Large;
<a href="qiconview.html#setGridX">setGridX</a>( 75 );
<a href="qiconview.html#setResizeMode">setResizeMode</a>( Adjust );
<a href="qiconview.html#setWordWrapIconText">setWordWrapIconText</a>( FALSE );
<a href="qobject.html#connect">connect</a>( this, SIGNAL( <a href="qiconview.html#doubleClicked">doubleClicked</a>( <a href="qiconviewitem.html">QIconViewItem</a> * ) ),
this, SLOT( itemDoubleClicked( <a href="qiconviewitem.html">QIconViewItem</a> * ) ) );
<a href="qobject.html#connect">connect</a>( this, SIGNAL( <a href="qiconview.html#returnPressed">returnPressed</a>( <a href="qiconviewitem.html">QIconViewItem</a> * ) ),
this, SLOT( itemDoubleClicked( <a href="qiconviewitem.html">QIconViewItem</a> * ) ) );
<a href="qobject.html#connect">connect</a>( this, SIGNAL( <a href="qiconview.html#dropped">dropped</a>( <a href="qdropevent.html">QDropEvent</a> *, const <a href="qvaluelist.html">QValueList</a>&lt;QIconDragItem&gt; &amp; ) ),
this, SLOT( slotDropped( <a href="qdropevent.html">QDropEvent</a> *, const <a href="qvaluelist.html">QValueList</a>&lt;QIconDragItem&gt; &amp; ) ) );
<a href="qobject.html#connect">connect</a>( this, SIGNAL( <a href="qiconview.html#contextMenuRequested">contextMenuRequested</a>( <a href="qiconviewitem.html">QIconViewItem</a> *, const <a href="qpoint.html">QPoint</a> &amp; ) ),
this, SLOT( slotRightPressed( <a href="qiconviewitem.html">QIconViewItem</a> * ) ) );
<a href="qscrollview.html#setHScrollBarMode">setHScrollBarMode</a>( AlwaysOff );
<a href="qscrollview.html#setVScrollBarMode">setVScrollBarMode</a>( Auto );
<a href="qiconview.html#setAutoArrange">setAutoArrange</a>( TRUE );
<a href="qiconview.html#setSorting">setSorting</a>( TRUE );
openItem = 0;
}
void <a name="f303"></a>QtFileIconView::openFolder()
{
if ( !openItem )
return;
if ( openItem-&gt;type() != QtFileIconViewItem::Dir ||
openItem-&gt;type() == QtFileIconViewItem::Dir &amp;&amp;
!QDir( openItem-&gt;itemFileName ).isReadable() )
return;
openItem-&gt;timer.stop();
setDirectory( openItem-&gt;itemFileName );
}
void <a name="f304"></a>QtFileIconView::setDirectory( const <a href="qstring.html">QString</a> &amp;dir )
{
viewDir = QDir( dir );
readDir( viewDir );
}
void QtFileIconView::setDirectory( const <a href="qdir.html">QDir</a> &amp;dir )
{
viewDir = dir;
readDir( viewDir );
}
void <a name="f305"></a>QtFileIconView::newDirectory()
{
<a href="qiconview.html#setAutoArrange">setAutoArrange</a>( FALSE );
<a href="qiconview.html#selectAll">selectAll</a>( FALSE );
if ( viewDir.mkdir( QString( "New Folder %1" ).arg( ++newFolderNum ) ) ) {
<a href="qfileinfo.html">QFileInfo</a> *fi = new <a href="qfileinfo.html">QFileInfo</a>( viewDir, QString( "New Folder %1" ).arg( newFolderNum ) );
QtFileIconViewItem *item = new QtFileIconViewItem( this, new <a href="qfileinfo.html">QFileInfo</a>( *fi ) );
<a name="x847"></a> item-&gt;<a href="qiconviewitem.html#setKey">setKey</a>( QString( "000000%1" ).arg( fi-&gt;<a href="qfileinfo.html#fileName">fileName</a>() ) );
delete fi;
<a href="qscrollview.html#repaintContents">repaintContents</a>( <a href="qscrollview.html#contentsX">contentsX</a>(), contentsY(), contentsWidth(), contentsHeight(), FALSE );
<a href="qiconview.html#ensureItemVisible">ensureItemVisible</a>( item );
<a name="x849"></a> item-&gt;<a href="qiconviewitem.html#setSelected">setSelected</a>( TRUE, TRUE );
<a href="qiconview.html#setCurrentItem">setCurrentItem</a>( item );
<a href="qiconview.html#repaintItem">repaintItem</a>( item );
<a name="x808"></a> qApp-&gt;<a href="qapplication.html#processEvents">processEvents</a>();
<a name="x845"></a> item-&gt;<a href="qiconviewitem.html#rename">rename</a>();
}
<a href="qiconview.html#setAutoArrange">setAutoArrange</a>( TRUE );
}
QDir <a name="f306"></a>QtFileIconView::currentDir()
{
return viewDir;
}
static bool isRoot( const <a href="qstring.html">QString</a> &amp;s )
{
#if defined(Q_OS_UNIX)
if ( s == "/" )
return TRUE;
#elif defined(Q_OS_WIN32)
<a href="qstring.html">QString</a> p = s;
if ( p.<a href="qstring.html#length">length</a>() == 3 &amp;&amp;
<a name="x871"></a> p.<a href="qstring.html#right">right</a>( 2 ) == ":/" )
return TRUE;
if ( p[ 0 ] == '/' &amp;&amp; p[ 1 ] == '/' ) {
<a name="x867"></a> int slashes = p.<a href="qstring.html#contains">contains</a>( '/' );
if ( slashes &lt;= 3 )
return TRUE;
if ( slashes == 4 &amp;&amp; p[ (int)p.<a href="qstring.html#length">length</a>() - 1 ] == '/' )
return TRUE;
}
#endif
return FALSE;
}
void <a name="f307"></a>QtFileIconView::readDir( const <a href="qdir.html">QDir</a> &amp;dir )
{
<a name="x813"></a> if ( !dir.<a href="qdir.html#isReadable">isReadable</a>() )
return;
if ( isRoot( dir.<a href="qdir.html#absPath">absPath</a>() ) )
emit disableUp();
else
emit enableUp();
<a href="qiconview.html#clear">clear</a>();
emit directoryChanged( dir.<a href="qdir.html#absPath">absPath</a>() );
<a name="x812"></a> const QFileInfoList *filist = dir.<a href="qdir.html#entryInfoList">entryInfoList</a>( QDir::DefaultFilter, QDir::DirsFirst | QDir::Name );
emit startReadDir( filist-&gt;count() );
QFileInfoListIterator it( *filist );
<a href="qfileinfo.html">QFileInfo</a> *fi;
bool allowRename = FALSE, allowRenameSet = FALSE;
while ( ( fi = it.current() ) != 0 ) {
++it;
if ( fi &amp;&amp; fi-&gt;<a href="qfileinfo.html#fileName">fileName</a>() == ".." &amp;&amp; ( fi-&gt;<a href="qfileinfo.html#dirPath">dirPath</a>() == "/" || fi-&gt;<a href="qfileinfo.html#dirPath">dirPath</a>().isEmpty() ) )
continue;
emit readNextDir();
QtFileIconViewItem *item = new QtFileIconViewItem( this, new <a href="qfileinfo.html">QFileInfo</a>( *fi ) );
if ( fi-&gt;<a href="qfileinfo.html#isDir">isDir</a>() )
item-&gt;<a href="qiconviewitem.html#setKey">setKey</a>( QString( "000000%1" ).arg( fi-&gt;<a href="qfileinfo.html#fileName">fileName</a>() ) );
else
item-&gt;<a href="qiconviewitem.html#setKey">setKey</a>( fi-&gt;<a href="qfileinfo.html#fileName">fileName</a>() );
if ( !allowRenameSet ) {
<a name="x820"></a> if ( !QFileInfo( fi-&gt;<a href="qfileinfo.html#absFilePath">absFilePath</a>() ).isWritable() ||
<a name="x851"></a> item-&gt;<a href="qiconviewitem.html#text">text</a>() == "." || item-&gt;<a href="qiconviewitem.html#text">text</a>() == ".." )
allowRename = FALSE;
else
allowRename = TRUE;
if ( item-&gt;<a href="qiconviewitem.html#text">text</a>() == "." || item-&gt;<a href="qiconviewitem.html#text">text</a>() == ".." )
allowRenameSet = FALSE;
else
allowRenameSet = TRUE;
}
<a name="x848"></a> item-&gt;<a href="qiconviewitem.html#setRenameEnabled">setRenameEnabled</a>( allowRename );
}
if ( !QFileInfo( dir.<a href="qdir.html#absPath">absPath</a>() ).isWritable() )
emit disableMkdir();
else
emit enableMkdir();
emit readDirDone();
}
void <a name="f308"></a>QtFileIconView::itemDoubleClicked( <a href="qiconviewitem.html">QIconViewItem</a> *i )
{
QtFileIconViewItem *item = ( QtFileIconViewItem* )i;
if ( item-&gt;type() == QtFileIconViewItem::Dir ) {
viewDir = QDir( item-&gt;filename() );
readDir( viewDir );
} else if ( item-&gt;type() == QtFileIconViewItem::Link &amp;&amp;
QFileInfo( QFileInfo( item-&gt;filename() ).readLink() ).isDir() ) {
viewDir = QDir( QFileInfo( item-&gt;filename() ).readLink() );
readDir( viewDir );
}
}
<a name="x834"></a>QDragObject *QtFileIconView::<a href="qiconview.html#dragObject">dragObject</a>()
{
if ( !currentItem() )
return 0;
<a name="x809"></a> <a href="qpoint.html">QPoint</a> orig = <a href="qscrollview.html#viewportToContents">viewportToContents</a>( <a href="qscrollview.html#viewport">viewport</a>()-&gt;mapFromGlobal( QCursor::<a href="qcursor.html#pos">pos</a>() ) );
QtFileIconDrag *drag = new QtFileIconDrag( <a href="qscrollview.html#viewport">viewport</a>() );
<a name="x815"></a> drag-&gt;<a href="qdragobject.html#setPixmap">setPixmap</a>( *currentItem()-&gt;pixmap(),
QPoint( <a href="qiconview.html#currentItem">currentItem</a>()-&gt;pixmapRect().width() / 2, currentItem()-&gt;pixmapRect().height() / 2 ) );
for ( QtFileIconViewItem *item = (QtFileIconViewItem*)<a href="qiconview.html#firstItem">firstItem</a>(); item;
<a name="x841"></a> item = (QtFileIconViewItem*)item-&gt;<a href="qiconviewitem.html#nextItem">nextItem</a>() ) {
<a name="x840"></a> if ( item-&gt;<a href="qiconviewitem.html#isSelected">isSelected</a>() ) {
<a href="qicondragitem.html">QIconDragItem</a> id;
<a name="x833"></a> id.<a href="qicondragitem.html#setData">setData</a>( QCString( item-&gt;filename() ) );
drag-&gt;<a href="qicondrag.html#append">append</a>( id,
<a name="x864"></a><a name="x844"></a> QRect( item-&gt;<a href="qiconviewitem.html#pixmapRect">pixmapRect</a>( FALSE ).x() - orig.<a href="qpoint.html#x">x</a>(),
<a name="x865"></a> item-&gt;<a href="qiconviewitem.html#pixmapRect">pixmapRect</a>( FALSE ).y() - orig.<a href="qpoint.html#y">y</a>(),
item-&gt;<a href="qiconviewitem.html#pixmapRect">pixmapRect</a>().width(), item-&gt;<a href="qiconviewitem.html#pixmapRect">pixmapRect</a>().height() ),
<a name="x852"></a> QRect( item-&gt;<a href="qiconviewitem.html#textRect">textRect</a>( FALSE ).x() - orig.<a href="qpoint.html#x">x</a>(),
item-&gt;<a href="qiconviewitem.html#textRect">textRect</a>( FALSE ).y() - orig.<a href="qpoint.html#y">y</a>(),
item-&gt;<a href="qiconviewitem.html#textRect">textRect</a>().width(), item-&gt;<a href="qiconviewitem.html#textRect">textRect</a>().height() ),
QString( item-&gt;filename() ) );
}
}
return drag;
}
<a name="x835"></a>void QtFileIconView::<a href="qwidget.html#keyPressEvent">keyPressEvent</a>( <a href="qkeyevent.html">QKeyEvent</a> *e )
{
<a name="x853"></a> if ( e-&gt;<a href="qkeyevent.html#key">key</a>() == Key_N &amp;&amp;
<a name="x854"></a> ( e-&gt;<a href="qkeyevent.html#state">state</a>() &amp; ControlButton ) )
newDirectory();
else
QIconView::<a href="qwidget.html#keyPressEvent">keyPressEvent</a>( e );
}
void <a name="f309"></a>QtFileIconView::slotDropped( <a href="qdropevent.html">QDropEvent</a> *e, const <a href="qvaluelist.html">QValueList</a>&lt;QIconDragItem&gt; &amp; )
{
if ( openItem )
openItem-&gt;timer.stop();
if ( !QUriDrag::canDecode( e ) ) {
e-&gt;<a href="qdropevent.html#ignore">ignore</a>();
return;
}
<a href="qstringlist.html">QStringList</a> lst;
QUriDrag::<a href="quridrag.html#decodeLocalFiles">decodeLocalFiles</a>( e, lst );
<a href="qstring.html">QString</a> str;
if ( e-&gt;<a href="qdropevent.html#action">action</a>() == QDropEvent::Copy )
str = "Copy\n\n";
else
str = "Move\n\n";
for ( uint i = 0; i &lt; lst.<a href="qvaluelist.html#count">count</a>(); ++i )
<a name="x811"></a> str += QString( " %1\n" ).arg( QDir::<a href="qdir.html#convertSeparators">convertSeparators</a>(lst[i]) );
str += QString( "\n"
"To\n\n"
" %1" ).arg( viewDir.absPath() );
QMessageBox::<a href="qmessagebox.html#information">information</a>( this, e-&gt;<a href="qdropevent.html#action">action</a>() == QDropEvent::Copy ? "Copy" : "Move" , str, "Not Implemented" );
if ( e-&gt;<a href="qdropevent.html#action">action</a>() == QDropEvent::Move )
<a name="x872"></a> QMessageBox::<a href="qmessagebox.html#information">information</a>( this, "Remove" , QDir::convertSeparators(lst.<a href="qstringlist.html#join">join</a>("\n")), "Not Implemented" );
e-&gt;<a href="qdropevent.html#acceptAction">acceptAction</a>();
openItem = 0;
}
void <a name="f310"></a>QtFileIconView::viewLarge()
{
setViewMode( Large );
}
void <a name="f311"></a>QtFileIconView::viewSmall()
{
setViewMode( Small );
}
void <a name="f312"></a>QtFileIconView::viewBottom()
{
<a href="qiconview.html#setItemTextPos">setItemTextPos</a>( Bottom );
}
void <a name="f313"></a>QtFileIconView::viewRight()
{
<a href="qiconview.html#setItemTextPos">setItemTextPos</a>( Right );
}
void <a name="f314"></a>QtFileIconView::flowEast()
{
<a href="qscrollview.html#setHScrollBarMode">setHScrollBarMode</a>( AlwaysOff );
<a href="qscrollview.html#setVScrollBarMode">setVScrollBarMode</a>( Auto );
<a href="qiconview.html#setArrangement">setArrangement</a>( LeftToRight );
}
void <a name="f315"></a>QtFileIconView::flowSouth()
{
<a href="qscrollview.html#setVScrollBarMode">setVScrollBarMode</a>( AlwaysOff );
<a href="qscrollview.html#setHScrollBarMode">setHScrollBarMode</a>( Auto );
<a href="qiconview.html#setArrangement">setArrangement</a>( TopToBottom );
}
void <a name="f316"></a>QtFileIconView::sortAscending()
{
<a href="qiconview.html#sort">sort</a>( TRUE );
}
void <a name="f317"></a>QtFileIconView::sortDescending()
{
<a href="qiconview.html#sort">sort</a>( FALSE );
}
void <a name="f318"></a>QtFileIconView::itemTextTruncate()
{
<a href="qiconview.html#setWordWrapIconText">setWordWrapIconText</a>( FALSE );
}
void <a name="f319"></a>QtFileIconView::itemTextWordWrap()
{
<a href="qiconview.html#setWordWrapIconText">setWordWrapIconText</a>( TRUE );
}
void <a name="f320"></a>QtFileIconView::slotRightPressed( <a href="qiconviewitem.html">QIconViewItem</a> *item )
{
if ( !item ) { // right pressed on viewport
<a href="qpopupmenu.html">QPopupMenu</a> menu( this );
menu.<a href="qmenudata.html#insertItem">insertItem</a>( "&amp;Large view", this, SLOT( viewLarge() ) );
menu.<a href="qmenudata.html#insertItem">insertItem</a>( "&amp;Small view", this, SLOT( viewSmall() ) );
menu.<a href="qmenudata.html#insertSeparator">insertSeparator</a>();
menu.<a href="qmenudata.html#insertItem">insertItem</a>( "Text at the &amp;bottom", this, SLOT( viewBottom() ) );
menu.<a href="qmenudata.html#insertItem">insertItem</a>( "Text at the &amp;right", this, SLOT( viewRight() ) );
menu.<a href="qmenudata.html#insertSeparator">insertSeparator</a>();
menu.<a href="qmenudata.html#insertItem">insertItem</a>( "Arrange l&amp;eft to right", this, SLOT( flowEast() ) );
menu.<a href="qmenudata.html#insertItem">insertItem</a>( "Arrange t&amp;op to bottom", this, SLOT( flowSouth() ) );
menu.<a href="qmenudata.html#insertSeparator">insertSeparator</a>();
menu.<a href="qmenudata.html#insertItem">insertItem</a>( "&amp;Truncate item text", this, SLOT( itemTextTruncate() ) );
menu.<a href="qmenudata.html#insertItem">insertItem</a>( "&amp;Wordwrap item text", this, SLOT( itemTextWordWrap() ) );
menu.<a href="qmenudata.html#insertSeparator">insertSeparator</a>();
menu.<a href="qmenudata.html#insertItem">insertItem</a>( "Arrange items in &amp;grid", this, SLOT( <a href="qiconview.html#arrangeItemsInGrid">arrangeItemsInGrid</a>() ) );
menu.<a href="qmenudata.html#insertSeparator">insertSeparator</a>();
menu.<a href="qmenudata.html#insertItem">insertItem</a>( "Sort &amp;ascending", this, SLOT( sortAscending() ) );
menu.<a href="qmenudata.html#insertItem">insertItem</a>( "Sort &amp;descending", this, SLOT( sortDescending() ) );
<a name="x875"></a> menu.<a href="qwidget.html#setMouseTracking">setMouseTracking</a>( TRUE );
<a name="x866"></a> menu.<a href="qpopupmenu.html#exec">exec</a>( QCursor::<a href="qcursor.html#pos">pos</a>() );
} else { // on item
<a href="qpopupmenu.html">QPopupMenu</a> menu( this );
int RENAME_ITEM = menu.<a href="qmenudata.html#insertItem">insertItem</a>( "Rename Item" );
int REMOVE_ITEM = menu.<a href="qmenudata.html#insertItem">insertItem</a>( "Remove Item" );
menu.<a href="qwidget.html#setMouseTracking">setMouseTracking</a>( TRUE );
int id = menu.<a href="qpopupmenu.html#exec">exec</a>( QCursor::<a href="qcursor.html#pos">pos</a>() );
if ( id == -1 )
return;
<a name="x846"></a> if ( id == RENAME_ITEM &amp;&amp; item-&gt;<a href="qiconviewitem.html#renameEnabled">renameEnabled</a>() ) {
item-&gt;<a href="qiconviewitem.html#rename">rename</a>();
} else if ( id == REMOVE_ITEM ) {
delete item;
QMessageBox::<a href="qmessagebox.html#information">information</a>( this, "Not implemented!", "Deleting files not implemented yet,\n"
"The item has only been removed from the view! " );
}
}
}
void <a name="f321"></a>QtFileIconView::setViewMode( ViewMode m )
{
if ( m == vm )
return;
vm = m;
QtFileIconViewItem *item = (QtFileIconViewItem*)<a href="qiconview.html#firstItem">firstItem</a>();
for ( ; item; item = (QtFileIconViewItem*)item-&gt;<a href="qiconviewitem.html#nextItem">nextItem</a>() )
item-&gt;viewModeChanged( vm );
<a href="qiconview.html#arrangeItemsInGrid">arrangeItemsInGrid</a>();
}
</pre>
<p> <hr>
<p> Header file of the main window:
<p> <pre>/****************************************************************************
** $Id: qt/mainwindow.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 MAINWIN_H
#define MAINWIN_H
#include &lt;<a href="qmainwindow-h.html">qmainwindow.h</a>&gt;
class QtFileIconView;
class DirectoryView;
class QProgressBar;
class QLabel;
class QComboBox;
class QToolButton;
class FileMainWindow : public <a href="qmainwindow.html">QMainWindow</a>
{
Q_OBJECT
public:
FileMainWindow();
QtFileIconView *fileView() { return fileview; }
DirectoryView *dirList() { return dirlist; }
void show();
protected:
void setup();
void setPathCombo();
QtFileIconView *fileview;
DirectoryView *dirlist;
<a href="qprogressbar.html">QProgressBar</a> *progress;
<a href="qlabel.html">QLabel</a> *label;
<a href="qcombobox.html">QComboBox</a> *pathCombo;
<a href="qtoolbutton.html">QToolButton</a> *upButton, *mkdirButton;
protected slots:
void directoryChanged( const <a href="qstring.html">QString</a> &amp; );
void slotStartReadDir( int dirs );
void slotReadNextDir();
void slotReadDirDone();
void cdUp();
void newFolder();
void changePath( const <a href="qstring.html">QString</a> &amp;path );
void enableUp();
void disableUp();
void enableMkdir();
void disableMkdir();
};
#endif
</pre>
<p> <hr>
<p> Implementation of the main window:
<p> <pre>/****************************************************************************
** $Id: qt/mainwindow.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 "mainwindow.h"
#include "qfileiconview.h"
#include "../dirview/dirview.h"
#include &lt;<a href="qsplitter-h.html">qsplitter.h</a>&gt;
#include &lt;<a href="qprogressbar-h.html">qprogressbar.h</a>&gt;
#include &lt;<a href="qlabel-h.html">qlabel.h</a>&gt;
#include &lt;<a href="qstatusbar-h.html">qstatusbar.h</a>&gt;
#include &lt;<a href="qtoolbar-h.html">qtoolbar.h</a>&gt;
#include &lt;<a href="qcombobox-h.html">qcombobox.h</a>&gt;
#include &lt;<a href="qpixmap-h.html">qpixmap.h</a>&gt;
#include &lt;<a href="qtoolbutton-h.html">qtoolbutton.h</a>&gt;
#include &lt;<a href="qdir-h.html">qdir.h</a>&gt;
#include &lt;<a href="qfileinfo-h.html">qfileinfo.h</a>&gt;
static const char* cdtoparent_xpm[]={
"15 13 3 1",
". c None",
"* c #000000",
"a c #ffff99",
"..*****........",
".*aaaaa*.......",
"***************",
"*aaaaaaaaaaaaa*",
"*aaaa*aaaaaaaa*",
"*aaa***aaaaaaa*",
"*aa*****aaaaaa*",
"*aaaa*aaaaaaaa*",
"*aaaa*aaaaaaaa*",
"*aaaa******aaa*",
"*aaaaaaaaaaaaa*",
"*aaaaaaaaaaaaa*",
"***************"};
static const char* newfolder_xpm[] = {
"15 14 4 1",
" c None",
". c #000000",
"+ c #FFFF00",
"@ c #FFFFFF",
" . ",
" ",
" . ",
" . . ",
" .... . . . ",
" .+@+@. . . ",
".......... . .",
".@+@+@+@+@.. ",
".+@+@+@+@+. . ",
".@+@+@+@+@. . ",
".+@+@+@+@+. ",
".@+@+@+@+@. ",
".+@+@+@+@+. ",
"........... "};
<a name="f324"></a>FileMainWindow::FileMainWindow()
: <a href="qmainwindow.html">QMainWindow</a>()
{
setup();
}
void FileMainWindow::<a href="qwidget.html#show">show</a>()
{
QMainWindow::<a href="qwidget.html#show">show</a>();
}
void <a name="f325"></a>FileMainWindow::setup()
{
<a href="qsplitter.html">QSplitter</a> *splitter = new <a href="qsplitter.html">QSplitter</a>( this );
dirlist = new DirectoryView( splitter, "dirlist", TRUE );
<a name="x886"></a> dirlist-&gt;<a href="qlistview.html#addColumn">addColumn</a>( "Name" );
dirlist-&gt;<a href="qlistview.html#addColumn">addColumn</a>( "Type" );
Directory *root = new Directory( dirlist, "/" );
<a name="x887"></a> root-&gt;<a href="qlistviewitem.html#setOpen">setOpen</a>( TRUE );
<a name="x894"></a> splitter-&gt;<a href="qsplitter.html#setResizeMode">setResizeMode</a>( dirlist, QSplitter::KeepSize );
fileview = new QtFileIconView( "/", splitter );
<a name="x884"></a> fileview-&gt;<a href="qiconview.html#setSelectionMode">setSelectionMode</a>( QIconView::Extended );
<a href="qmainwindow.html#setCentralWidget">setCentralWidget</a>( splitter );
<a href="qtoolbar.html">QToolBar</a> *toolbar = new <a href="qtoolbar.html">QToolBar</a>( this, "toolbar" );
<a href="qmainwindow.html#setRightJustification">setRightJustification</a>( TRUE );
(void)new <a href="qlabel.html">QLabel</a>( <a href="qobject.html#tr">tr</a>( " Path: " ), toolbar );
pathCombo = new <a href="qcombobox.html">QComboBox</a>( TRUE, toolbar );
<a name="x880"></a> pathCombo-&gt;<a href="qcombobox.html#setAutoCompletion">setAutoCompletion</a>( TRUE );
<a name="x896"></a> toolbar-&gt;<a href="qtoolbar.html#setStretchableWidget">setStretchableWidget</a>( pathCombo );
<a name="x877"></a> <a href="qobject.html#connect">connect</a>( pathCombo, SIGNAL( <a href="qcombobox.html#activated">activated</a>( const <a href="qstring.html">QString</a> &amp; ) ),
this, SLOT ( changePath( const <a href="qstring.html">QString</a> &amp; ) ) );
<a name="x895"></a> toolbar-&gt;<a href="qtoolbar.html#addSeparator">addSeparator</a>();
<a href="qpixmap.html">QPixmap</a> pix;
pix = QPixmap( cdtoparent_xpm );
upButton = new <a href="qtoolbutton.html">QToolButton</a>( pix, "One directory up", <a href="qstring.html#QString-null">QString::null</a>,
this, SLOT( cdUp() ), toolbar, "cd up" );
pix = QPixmap( newfolder_xpm );
mkdirButton = new <a href="qtoolbutton.html">QToolButton</a>( pix, "New Folder", QString::null,
this, SLOT( newFolder() ), toolbar, "new folder" );
<a href="qobject.html#connect">connect</a>( dirlist, SIGNAL( folderSelected( const <a href="qstring.html">QString</a> &amp; ) ),
fileview, SLOT ( setDirectory( const <a href="qstring.html">QString</a> &amp; ) ) );
<a href="qobject.html#connect">connect</a>( fileview, SIGNAL( directoryChanged( const <a href="qstring.html">QString</a> &amp; ) ),
this, SLOT( directoryChanged( const <a href="qstring.html">QString</a> &amp; ) ) );
<a href="qobject.html#connect">connect</a>( fileview, SIGNAL( startReadDir( int ) ),
this, SLOT( slotStartReadDir( int ) ) );
<a href="qobject.html#connect">connect</a>( fileview, SIGNAL( readNextDir() ),
this, SLOT( slotReadNextDir() ) );
<a href="qobject.html#connect">connect</a>( fileview, SIGNAL( readDirDone() ),
this, SLOT( slotReadDirDone() ) );
<a href="qmainwindow.html#setDockEnabled">setDockEnabled</a>( DockLeft, FALSE );
<a href="qmainwindow.html#setDockEnabled">setDockEnabled</a>( DockRight, FALSE );
label = new <a href="qlabel.html">QLabel</a>( <a href="qmainwindow.html#statusBar">statusBar</a>() );
<a href="qmainwindow.html#statusBar">statusBar</a>()-&gt;addWidget( label, 2, TRUE );
progress = new <a href="qprogressbar.html">QProgressBar</a>( <a href="qmainwindow.html#statusBar">statusBar</a>() );
<a href="qmainwindow.html#statusBar">statusBar</a>()-&gt;addWidget( progress, 1, TRUE );
<a href="qobject.html#connect">connect</a>( fileview, SIGNAL( enableUp() ),
this, SLOT( enableUp() ) );
<a href="qobject.html#connect">connect</a>( fileview, SIGNAL( disableUp() ),
this, SLOT( disableUp() ) );
<a href="qobject.html#connect">connect</a>( fileview, SIGNAL( enableMkdir() ),
this, SLOT( enableMkdir() ) );
<a href="qobject.html#connect">connect</a>( fileview, SIGNAL( disableMkdir() ),
this, SLOT( disableMkdir() ) );
}
void <a name="f326"></a>FileMainWindow::setPathCombo()
{
<a href="qstring.html">QString</a> dir = <a href="qwidget.html#caption">caption</a>();
int i = 0;
bool found = FALSE;
<a name="x878"></a> for ( i = 0; i &lt; pathCombo-&gt;<a href="qcombobox.html#count">count</a>(); ++i ) {
<a name="x882"></a> if ( pathCombo-&gt;<a href="qcombobox.html#text">text</a>( i ) == dir) {
found = TRUE;
break;
}
}
if ( found )
<a name="x881"></a> pathCombo-&gt;<a href="qcombobox.html#setCurrentItem">setCurrentItem</a>( i );
else {
<a name="x879"></a> pathCombo-&gt;<a href="qcombobox.html#insertItem">insertItem</a>( dir );
pathCombo-&gt;<a href="qcombobox.html#setCurrentItem">setCurrentItem</a>( pathCombo-&gt;<a href="qcombobox.html#count">count</a>() - 1 );
}
}
void <a name="f327"></a>FileMainWindow::directoryChanged( const <a href="qstring.html">QString</a> &amp;dir )
{
<a href="qwidget.html#setCaption">setCaption</a>( dir );
setPathCombo();
}
void <a name="f328"></a>FileMainWindow::slotStartReadDir( int dirs )
{
label-&gt;<a href="qlabel.html#setText">setText</a>( <a href="qobject.html#tr">tr</a>( " Reading Directory..." ) );
<a name="x890"></a> progress-&gt;<a href="qprogressbar.html#reset">reset</a>();
<a name="x892"></a> progress-&gt;<a href="qprogressbar.html#setTotalSteps">setTotalSteps</a>( dirs );
}
void <a name="f329"></a>FileMainWindow::slotReadNextDir()
{
<a name="x889"></a> int p = progress-&gt;<a href="qprogressbar.html#progress">progress</a>();
<a name="x891"></a> progress-&gt;<a href="qprogressbar.html#setProgress">setProgress</a>( ++p );
}
void <a name="f330"></a>FileMainWindow::slotReadDirDone()
{
label-&gt;<a href="qlabel.html#setText">setText</a>( <a href="qobject.html#tr">tr</a>( " Reading Directory Done." ) );
<a name="x893"></a> progress-&gt;<a href="qprogressbar.html#setProgress">setProgress</a>( progress-&gt;<a href="qprogressbar.html#totalSteps">totalSteps</a>() );
}
void <a name="f331"></a>FileMainWindow::cdUp()
{
<a href="qdir.html">QDir</a> dir = fileview-&gt;currentDir();
<a name="x883"></a> dir.<a href="qdir.html#cd">cd</a>( ".." );
fileview-&gt;setDirectory( dir );
}
void <a name="f332"></a>FileMainWindow::newFolder()
{
fileview-&gt;newDirectory();
}
void <a name="f333"></a>FileMainWindow::changePath( const <a href="qstring.html">QString</a> &amp;path )
{
if ( QFileInfo( path ).exists() )
fileview-&gt;setDirectory( path );
else
setPathCombo();
}
void <a name="f334"></a>FileMainWindow::enableUp()
{
<a name="x897"></a> upButton-&gt;<a href="qwidget.html#setEnabled">setEnabled</a>( TRUE );
}
void <a name="f335"></a>FileMainWindow::disableUp()
{
upButton-&gt;<a href="qwidget.html#setEnabled">setEnabled</a>( FALSE );
}
void <a name="f336"></a>FileMainWindow::enableMkdir()
{
mkdirButton-&gt;<a href="qwidget.html#setEnabled">setEnabled</a>( TRUE );
}
void <a name="f337"></a>FileMainWindow::disableMkdir()
{
mkdirButton-&gt;<a href="qwidget.html#setEnabled">setEnabled</a>( FALSE );
}
</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 "mainwindow.h"
#include "qfileiconview.h"
#include &lt;<a href="qapplication-h.html">qapplication.h</a>&gt;
int main( int argc, char **argv )
{
<a href="qapplication.html">QApplication</a> a( argc, argv );
FileMainWindow mw;
mw.<a href="qwidget.html#resize">resize</a>( 680, 480 );
a.<a href="qapplication.html#setMainWidget">setMainWidget</a>( &amp;mw );
mw.fileView()-&gt;setDirectory( "/" );
<a name="x900"></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>