[190] | 1 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
|
---|
| 2 | <!-- /home/espenr/tmp/qt-3.3.8-espenr-2499/qt-x11-free-3.3.8/examples/fileiconview/fileiconview.doc:4 -->
|
---|
| 3 | <html>
|
---|
| 4 | <head>
|
---|
| 5 | <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
|
---|
| 6 | <title>Simple Filemanager</title>
|
---|
| 7 | <style type="text/css"><!--
|
---|
| 8 | fn { margin-left: 1cm; text-indent: -1cm; }
|
---|
| 9 | a:link { color: #004faf; text-decoration: none }
|
---|
| 10 | a:visited { color: #672967; text-decoration: none }
|
---|
| 11 | body { background: #ffffff; color: black; }
|
---|
| 12 | --></style>
|
---|
| 13 | </head>
|
---|
| 14 | <body>
|
---|
| 15 |
|
---|
| 16 | <table border="0" cellpadding="0" cellspacing="0" width="100%">
|
---|
| 17 | <tr bgcolor="#E5E5E5">
|
---|
| 18 | <td valign=center>
|
---|
| 19 | <a href="index.html">
|
---|
| 20 | <font color="#004faf">Home</font></a>
|
---|
| 21 | | <a href="classes.html">
|
---|
| 22 | <font color="#004faf">All Classes</font></a>
|
---|
| 23 | | <a href="mainclasses.html">
|
---|
| 24 | <font color="#004faf">Main Classes</font></a>
|
---|
| 25 | | <a href="annotated.html">
|
---|
| 26 | <font color="#004faf">Annotated</font></a>
|
---|
| 27 | | <a href="groups.html">
|
---|
| 28 | <font color="#004faf">Grouped Classes</font></a>
|
---|
| 29 | | <a href="functions.html">
|
---|
| 30 | <font color="#004faf">Functions</font></a>
|
---|
| 31 | </td>
|
---|
| 32 | <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>
|
---|
| 33 |
|
---|
| 34 |
|
---|
| 35 | <p>
|
---|
| 36 | This example implements a simple and not fully functional file manager using
|
---|
| 37 | a widget derived from <a href="qiconview.html">QIconView</a> to display the current directory.
|
---|
| 38 | To display the directory tree the
|
---|
| 39 | widget written in the <a href="dirview-example.html">dirview</a> example is
|
---|
| 40 | used.
|
---|
| 41 | <p> <hr>
|
---|
| 42 | <p> Header file of the file icon view:
|
---|
| 43 | <p> <pre>/****************************************************************************
|
---|
| 44 | ** $Id: fileiconview-example.html 2051 2007-02-21 10:04:20Z chehrlic $
|
---|
| 45 | **
|
---|
| 46 | ** Copyright (C) 1992-2007 Trolltech ASA. All rights reserved.
|
---|
| 47 | **
|
---|
| 48 | ** This file is part of an example program for Qt. This example
|
---|
| 49 | ** program may be used, distributed and modified without limitation.
|
---|
| 50 | **
|
---|
| 51 | *****************************************************************************/
|
---|
| 52 |
|
---|
| 53 | #ifndef QTFILEICONVIEW_H
|
---|
| 54 | #define QTFILEICONVIEW_H
|
---|
| 55 |
|
---|
| 56 |
|
---|
| 57 | #include <<a href="qiconset-h.html">qiconset.h</a>>
|
---|
| 58 | #include <<a href="qstring-h.html">qstring.h</a>>
|
---|
| 59 | #include <<a href="qfileinfo-h.html">qfileinfo.h</a>>
|
---|
| 60 | #include <<a href="qdir-h.html">qdir.h</a>>
|
---|
| 61 | #include <<a href="qtimer-h.html">qtimer.h</a>>
|
---|
| 62 | #include <<a href="qiconview-h.html">qiconview.h</a>>
|
---|
| 63 |
|
---|
| 64 | class QtFileIconView;
|
---|
| 65 | class QDragObject;
|
---|
| 66 | class QResizeEvent;
|
---|
| 67 |
|
---|
| 68 | /*****************************************************************************
|
---|
| 69 | *
|
---|
| 70 | * Class QtFileIconDrag
|
---|
| 71 | *
|
---|
| 72 | *****************************************************************************/
|
---|
| 73 |
|
---|
| 74 | class QtFileIconDrag : public <a href="qicondrag.html">QIconDrag</a>
|
---|
| 75 | {
|
---|
| 76 | <a href="metaobjects.html#Q_OBJECT">Q_OBJECT</a>
|
---|
| 77 |
|
---|
| 78 | public:
|
---|
| 79 | QtFileIconDrag( <a href="qwidget.html">QWidget</a> * dragSource, const char* name = 0 );
|
---|
| 80 |
|
---|
| 81 | const char* format( int i ) const;
|
---|
| 82 | <a href="qbytearray.html">QByteArray</a> encodedData( const char* mime ) const;
|
---|
| 83 | static bool canDecode( <a href="qmimesource.html">QMimeSource</a>* e );
|
---|
| 84 | void append( const <a href="qicondragitem.html">QIconDragItem</a> &item, const <a href="qrect.html">QRect</a> &pr, const <a href="qrect.html">QRect</a> &tr, const <a href="qstring.html">QString</a> &url );
|
---|
| 85 |
|
---|
| 86 | private:
|
---|
| 87 | <a href="qstringlist.html">QStringList</a> urls;
|
---|
| 88 |
|
---|
| 89 | };
|
---|
| 90 |
|
---|
| 91 | /*****************************************************************************
|
---|
| 92 | *
|
---|
| 93 | * Class QtFileIconView
|
---|
| 94 | *
|
---|
| 95 | *****************************************************************************/
|
---|
| 96 | class QtFileIconViewItem;
|
---|
| 97 | class QtFileIconView : public <a href="qiconview.html">QIconView</a>
|
---|
| 98 | {
|
---|
| 99 | Q_OBJECT
|
---|
| 100 |
|
---|
| 101 | public:
|
---|
| 102 | QtFileIconView( const <a href="qstring.html">QString</a> &dir, QWidget *parent = 0, const char *name = 0 );
|
---|
| 103 |
|
---|
| 104 | enum ViewMode { Large, Small };
|
---|
| 105 |
|
---|
| 106 | void setViewMode( ViewMode m );
|
---|
| 107 | ViewMode viewMode() const { return vm; }
|
---|
| 108 | void setOpenItem( QtFileIconViewItem *i ) {
|
---|
| 109 | openItem = i;
|
---|
| 110 | }
|
---|
| 111 |
|
---|
| 112 | public slots:
|
---|
| 113 | void setDirectory( const <a href="qstring.html">QString</a> &dir );
|
---|
| 114 | void setDirectory( const <a href="qdir.html">QDir</a> &dir );
|
---|
| 115 | void newDirectory();
|
---|
| 116 | <a href="qdir.html">QDir</a> currentDir();
|
---|
| 117 |
|
---|
| 118 | signals:
|
---|
| 119 | void directoryChanged( const <a href="qstring.html">QString</a> & );
|
---|
| 120 | void startReadDir( int dirs );
|
---|
| 121 | void readNextDir();
|
---|
| 122 | void readDirDone();
|
---|
| 123 | void enableUp();
|
---|
| 124 | void disableUp();
|
---|
| 125 | void enableMkdir();
|
---|
| 126 | void disableMkdir();
|
---|
| 127 |
|
---|
| 128 | protected slots:
|
---|
| 129 | void itemDoubleClicked( <a href="qiconviewitem.html">QIconViewItem</a> *i );
|
---|
| 130 | void slotDropped( <a href="qdropevent.html">QDropEvent</a> *e, const <a href="qvaluelist.html">QValueList</a><QIconDragItem> & );
|
---|
| 131 |
|
---|
| 132 | void viewLarge();
|
---|
| 133 | void viewSmall();
|
---|
| 134 | void viewBottom();
|
---|
| 135 | void viewRight();
|
---|
| 136 | void flowEast();
|
---|
| 137 | void flowSouth();
|
---|
| 138 | void itemTextTruncate();
|
---|
| 139 | void itemTextWordWrap();
|
---|
| 140 | void sortAscending();
|
---|
| 141 | void sortDescending();
|
---|
| 142 | void arrangeItemsInGrid() {
|
---|
| 143 | <a name="x807"></a> QIconView::<a href="qiconview.html#arrangeItemsInGrid">arrangeItemsInGrid</a>( TRUE );
|
---|
| 144 | }
|
---|
| 145 |
|
---|
| 146 | void slotRightPressed( <a href="qiconviewitem.html">QIconViewItem</a> *item );
|
---|
| 147 | void openFolder();
|
---|
| 148 |
|
---|
| 149 | protected:
|
---|
| 150 | void readDir( const <a href="qdir.html">QDir</a> &dir );
|
---|
| 151 | virtual QDragObject *dragObject();
|
---|
| 152 |
|
---|
| 153 | virtual void keyPressEvent( <a href="qkeyevent.html">QKeyEvent</a> *e );
|
---|
| 154 |
|
---|
| 155 | <a href="qdir.html">QDir</a> viewDir;
|
---|
| 156 | int newFolderNum;
|
---|
| 157 | <a href="qsize.html">QSize</a> sz;
|
---|
| 158 | <a href="qpixmap.html">QPixmap</a> pix;
|
---|
| 159 | ViewMode vm;
|
---|
| 160 | QtFileIconViewItem *openItem;
|
---|
| 161 |
|
---|
| 162 | };
|
---|
| 163 |
|
---|
| 164 | /*****************************************************************************
|
---|
| 165 | *
|
---|
| 166 | * Class QtFileIconViewItem
|
---|
| 167 | *
|
---|
| 168 | *****************************************************************************/
|
---|
| 169 |
|
---|
| 170 | class QtFileIconViewItem : public <a href="qiconviewitem.html">QIconViewItem</a>
|
---|
| 171 | {
|
---|
| 172 | friend class QtFileIconView;
|
---|
| 173 |
|
---|
| 174 | public:
|
---|
| 175 | enum ItemType {
|
---|
| 176 | File = 0,
|
---|
| 177 | Dir,
|
---|
| 178 | Link
|
---|
| 179 | };
|
---|
| 180 |
|
---|
| 181 | QtFileIconViewItem( QtFileIconView *parent, QFileInfo *fi );
|
---|
| 182 |
|
---|
| 183 | virtual ~QtFileIconViewItem();
|
---|
| 184 |
|
---|
| 185 | ItemType type() const
|
---|
| 186 | { return itemType; }
|
---|
| 187 | <a href="qstring.html">QString</a> filename() const { return itemFileName; }
|
---|
| 188 |
|
---|
| 189 | virtual bool acceptDrop( const <a href="qmimesource.html">QMimeSource</a> *e ) const;
|
---|
| 190 |
|
---|
| 191 | virtual void setText( const <a href="qstring.html">QString</a> &text );
|
---|
| 192 | virtual QPixmap *pixmap() const;
|
---|
| 193 |
|
---|
| 194 | virtual void dragEntered();
|
---|
| 195 | virtual void dragLeft();
|
---|
| 196 |
|
---|
| 197 | void viewModeChanged( QtFileIconView::ViewMode m );
|
---|
| 198 | void paintItem( <a href="qpainter.html">QPainter</a> *p, const <a href="qcolorgroup.html">QColorGroup</a> &cg );
|
---|
| 199 |
|
---|
| 200 | protected:
|
---|
| 201 | virtual void dropped( <a href="qdropevent.html">QDropEvent</a> *e, const <a href="qvaluelist.html">QValueList</a><QIconDragItem> & );
|
---|
| 202 |
|
---|
| 203 | <a href="qstring.html">QString</a> itemFileName;
|
---|
| 204 | <a href="qfileinfo.html">QFileInfo</a> *itemFileInfo;
|
---|
| 205 | ItemType itemType;
|
---|
| 206 | bool checkSetText;
|
---|
| 207 | <a href="qtimer.html">QTimer</a> timer;
|
---|
| 208 | QtFileIconView::ViewMode vm;
|
---|
| 209 |
|
---|
| 210 | };
|
---|
| 211 |
|
---|
| 212 |
|
---|
| 213 | #endif
|
---|
| 214 | </pre>
|
---|
| 215 |
|
---|
| 216 | <p> <hr>
|
---|
| 217 | <p> Implementation of the file icon view:
|
---|
| 218 | <p> <pre>/****************************************************************************
|
---|
| 219 | ** $Id: fileiconview-example.html 2051 2007-02-21 10:04:20Z chehrlic $
|
---|
| 220 | **
|
---|
| 221 | ** Copyright (C) 1992-2007 Trolltech ASA. All rights reserved.
|
---|
| 222 | **
|
---|
| 223 | ** This file is part of an example program for Qt. This example
|
---|
| 224 | ** program may be used, distributed and modified without limitation.
|
---|
| 225 | **
|
---|
| 226 | *****************************************************************************/
|
---|
| 227 |
|
---|
| 228 | #include "qfileiconview.h"
|
---|
| 229 | #include <<a href="qpainter-h.html">qpainter.h</a>>
|
---|
| 230 | #include <<a href="qstringlist-h.html">qstringlist.h</a>>
|
---|
| 231 | #include <<a href="qpixmap-h.html">qpixmap.h</a>>
|
---|
| 232 | #include <<a href="qmime-h.html">qmime.h</a>>
|
---|
| 233 | #include <<a href="qstrlist-h.html">qstrlist.h</a>>
|
---|
| 234 | #include <<a href="qdragobject-h.html">qdragobject.h</a>>
|
---|
| 235 | #include <<a href="qmessagebox-h.html">qmessagebox.h</a>>
|
---|
| 236 | #include <<a href="qevent-h.html">qevent.h</a>>
|
---|
| 237 | #include <<a href="qpopupmenu-h.html">qpopupmenu.h</a>>
|
---|
| 238 | #include <<a href="qcursor-h.html">qcursor.h</a>>
|
---|
| 239 | #include <<a href="qapplication-h.html">qapplication.h</a>>
|
---|
| 240 | #include <<a href="qwmatrix-h.html">qwmatrix.h</a>>
|
---|
| 241 |
|
---|
| 242 | #include <stdlib.h>
|
---|
| 243 |
|
---|
| 244 | static const char * file_icon[]={
|
---|
| 245 | "32 32 17 1",
|
---|
| 246 | "# c #000000",
|
---|
| 247 | "a c #ffffff",
|
---|
| 248 | "j c #808080",
|
---|
| 249 | "n c #a0a0a4",
|
---|
| 250 | "g c #c0c0c0",
|
---|
| 251 | "m c #004000",
|
---|
| 252 | "o c #000000",
|
---|
| 253 | "l c #004040",
|
---|
| 254 | "k c #404000",
|
---|
| 255 | "i c #c0c000",
|
---|
| 256 | "h c #ffff00",
|
---|
| 257 | "b c #ffffc0",
|
---|
| 258 | "e c #ff8000",
|
---|
| 259 | "f c #c05800",
|
---|
| 260 | "c c #ffa858",
|
---|
| 261 | "d c #ffdca8",
|
---|
| 262 | ". c None",
|
---|
| 263 | "................................",
|
---|
| 264 | "................................",
|
---|
| 265 | "................................",
|
---|
| 266 | "................................",
|
---|
| 267 | ".............#....###...........",
|
---|
| 268 | "...###......#a##.#aba##.........",
|
---|
| 269 | "..#cdb#....#aaaa#aaaaaa##.......",
|
---|
| 270 | "..#ecdb#..#aaaa#aaaaaaaba##.....",
|
---|
| 271 | "..#fecdb##aaaa#aaaaaaaaaaab##...",
|
---|
| 272 | "...#fecdb#aaa#aaaaaaabaabaaaa##.",
|
---|
| 273 | "....#fecdb#a#baaaaa#baaaaaabaaa#",
|
---|
| 274 | ".....#fecdb#aaaaab#a##baaaaaaa#.",
|
---|
| 275 | ".....##fecdb#bbba#aaaa##baaab#..",
|
---|
| 276 | "....#bb#fecdb#ba#aaaaaaa##aa#...",
|
---|
| 277 | "...#bbbb#fecdb##aaabaaaaaa##....",
|
---|
| 278 | "..#bbbb#b#fecdb#aaaaaaabaaaa##..",
|
---|
| 279 | ".#bbbb#bbb#fecdg#aaaaaaaaaaaba#.",
|
---|
| 280 | "#hhbb#bbbbb#fegg#iiaaaaaaaaaaaa#",
|
---|
| 281 | "#jhhhklibbbk#ggj#aaiiaaaaaaaaa#j",
|
---|
| 282 | ".#mjhhhkmikab####aaabiiaaaaaa#j.",
|
---|
| 283 | "...##jhhhmaaibbaaiibaaaiiaab#n..",
|
---|
| 284 | ".....##j#baaaiiabaaiibaabaa#n...",
|
---|
| 285 | "......##baibaabiibaaaiiabb#j....",
|
---|
| 286 | "......#bbbbiiaabbiiaaaaabon.....",
|
---|
| 287 | ".....#bbbbbbbiiabbaiiaab#n......",
|
---|
| 288 | ".....#jbbbbbbbbiibaabba#n.......",
|
---|
| 289 | "......##jbbbbbbbbiiaabmj........",
|
---|
| 290 | "........##jbbbbbbbbbb#j.........",
|
---|
| 291 | "..........##nbbbbbbbmj..........",
|
---|
| 292 | "............##jbbbb#j...........",
|
---|
| 293 | "..............#mjj#n............",
|
---|
| 294 | "................##n............."};
|
---|
| 295 |
|
---|
| 296 | static const char * folder_icon[]={
|
---|
| 297 | "32 32 11 1",
|
---|
| 298 | "# c #000000",
|
---|
| 299 | "b c #c0c000",
|
---|
| 300 | "d c #585858",
|
---|
| 301 | "a c #ffff00",
|
---|
| 302 | "i c #400000",
|
---|
| 303 | "h c #a0a0a4",
|
---|
| 304 | "e c #000000",
|
---|
| 305 | "c c #ffffff",
|
---|
| 306 | "f c #303030",
|
---|
| 307 | "g c #c0c0c0",
|
---|
| 308 | ". c None",
|
---|
| 309 | "...###..........................",
|
---|
| 310 | "...#aa##........................",
|
---|
| 311 | ".###baaa##......................",
|
---|
| 312 | ".#cde#baaa##....................",
|
---|
| 313 | ".#cccdeebaaa##..##f.............",
|
---|
| 314 | ".#cccccdeebaaa##aaa##...........",
|
---|
| 315 | ".#cccccccdeebaaaaaaaa##.........",
|
---|
| 316 | ".#cccccccccdeebababaaa#.........",
|
---|
| 317 | ".#cccccgcgghhebbbbbbbaa#........",
|
---|
| 318 | ".#ccccccgcgggdebbbbbbba#........",
|
---|
| 319 | ".#cccgcgcgcgghdeebiebbba#.......",
|
---|
| 320 | ".#ccccgcggggggghdeddeeba#.......",
|
---|
| 321 | ".#cgcgcgcggggggggghghdebb#......",
|
---|
| 322 | ".#ccgcggggggggghghghghd#b#......",
|
---|
| 323 | ".#cgcgcggggggggghghghhd#b#......",
|
---|
| 324 | ".#gcggggggggghghghhhhhd#b#......",
|
---|
| 325 | ".#cgcggggggggghghghhhhd#b#......",
|
---|
| 326 | ".#ggggggggghghghhhhhhhdib#......",
|
---|
| 327 | ".#gggggggggghghghhhhhhd#b#......",
|
---|
| 328 | ".#hhggggghghghhhhhhhhhd#b#......",
|
---|
| 329 | ".#ddhhgggghghghhhhhhhhd#b#......",
|
---|
| 330 | "..##ddhhghghhhhhhhhhhhdeb#......",
|
---|
| 331 | "....##ddhhhghhhhhhhhhhd#b#......",
|
---|
| 332 | "......##ddhhhhhhhhhhhhd#b#......",
|
---|
| 333 | "........##ddhhhhhhhhhhd#b#......",
|
---|
| 334 | "..........##ddhhhhhhhhd#b#......",
|
---|
| 335 | "............##ddhhhhhhd#b###....",
|
---|
| 336 | "..............##ddhhhhd#b#####..",
|
---|
| 337 | "................##ddhhd#b######.",
|
---|
| 338 | "..................##dddeb#####..",
|
---|
| 339 | "....................##d#b###....",
|
---|
| 340 | "......................####......"};
|
---|
| 341 |
|
---|
| 342 |
|
---|
| 343 | static const char * link_icon[]={
|
---|
| 344 | "32 32 12 1",
|
---|
| 345 | "# c #000000",
|
---|
| 346 | "h c #a0a0a4",
|
---|
| 347 | "b c #c00000",
|
---|
| 348 | "d c #585858",
|
---|
| 349 | "i c #400000",
|
---|
| 350 | "c c #ffffff",
|
---|
| 351 | "e c #000000",
|
---|
| 352 | "g c #c0c0c0",
|
---|
| 353 | "a c #ff0000",
|
---|
| 354 | "f c #303030",
|
---|
| 355 | "n c white",
|
---|
| 356 | ". c None",
|
---|
| 357 | "...###..........................",
|
---|
| 358 | "...#aa##........................",
|
---|
| 359 | ".###baaa##......................",
|
---|
| 360 | ".#cde#baaa##....................",
|
---|
| 361 | ".#cccdeebaaa##..##f.............",
|
---|
| 362 | ".#cccccdeebaaa##aaa##...........",
|
---|
| 363 | ".#cccccccdeebaaaaaaaa##.........",
|
---|
| 364 | ".#cccccccccdeebababaaa#.........",
|
---|
| 365 | ".#cccccgcgghhebbbbbbbaa#........",
|
---|
| 366 | ".#ccccccgcgggdebbbbbbba#........",
|
---|
| 367 | ".#cccgcgcgcgghdeebiebbba#.......",
|
---|
| 368 | ".#ccccgcggggggghdeddeeba#.......",
|
---|
| 369 | ".#cgcgcgcggggggggghghdebb#......",
|
---|
| 370 | ".#ccgcggggggggghghghghd#b#......",
|
---|
| 371 | ".#cgcgcggggggggghghghhd#b#......",
|
---|
| 372 | ".#gcggggggggghghghhhhhd#b#......",
|
---|
| 373 | ".#cgcggggggggghghghhhhd#b#......",
|
---|
| 374 | ".#ggggggggghghghhhhhhhdib#......",
|
---|
| 375 | ".#gggggggggghghghhhhhhd#b#......",
|
---|
| 376 | ".#hhggggghghghhhhhhhhhd#b#......",
|
---|
| 377 | ".#ddhhgggghghghhhhhhhhd#b#......",
|
---|
| 378 | "..##ddhhghghhhhhhhhhhhdeb#......",
|
---|
| 379 | "############hhhhhhhhhhd#b#......",
|
---|
| 380 | "#nnnnnnnnnn#hhhhhhhhhhd#b#......",
|
---|
| 381 | "#nnnnnnnnnn#hhhhhhhhhhd#b#......",
|
---|
| 382 | "#nn#nn#nnnn#ddhhhhhhhhd#b#......",
|
---|
| 383 | "#nn##n##nnn###ddhhhhhhd#b###....",
|
---|
| 384 | "#nnn#####nn#..##ddhhhhd#b#####..",
|
---|
| 385 | "#nnnnn##nnn#....##ddhhd#b######.",
|
---|
| 386 | "#nnnnn#nnnn#......##dddeb#####..",
|
---|
| 387 | "#nnnnnnnnnn#........##d#b###....",
|
---|
| 388 | "############..........####......"};
|
---|
| 389 |
|
---|
| 390 | static const char * folder_locked_icon[]={
|
---|
| 391 | "32 32 12 1",
|
---|
| 392 | "# c #000000",
|
---|
| 393 | "g c #808080",
|
---|
| 394 | "h c #c0c0c0",
|
---|
| 395 | "f c #c05800",
|
---|
| 396 | "c c #ffffff",
|
---|
| 397 | "d c #585858",
|
---|
| 398 | "b c #ffa858",
|
---|
| 399 | "a c #ffdca8",
|
---|
| 400 | "e c #000000",
|
---|
| 401 | "i c #a0a0a4",
|
---|
| 402 | "j c #c0c0c0",
|
---|
| 403 | ". c None",
|
---|
| 404 | "...###..........................",
|
---|
| 405 | "...#aa##........................",
|
---|
| 406 | ".###baaa##......................",
|
---|
| 407 | ".#cde#baaa##....................",
|
---|
| 408 | ".#cccdeeba#######...............",
|
---|
| 409 | ".#cccccde##fffff##..............",
|
---|
| 410 | ".#cccccc##fffgggg#..............",
|
---|
| 411 | ".#ccccccc#ffg####a##............",
|
---|
| 412 | ".#ccccchc#ffg#eebbaa##..........",
|
---|
| 413 | ".#ccccccc#ffg#ddeebbba##........",
|
---|
| 414 | ".#ccchccc#ffg#ihddeebbba##......",
|
---|
| 415 | ".#cccccaa#ffg#ihhhddeeba##......",
|
---|
| 416 | ".#chchhbbaafg#ihhhihidebb#......",
|
---|
| 417 | ".#cchccbbbbaa#ihhihihid#b#......",
|
---|
| 418 | ".#chchhbb#bbbaaiihihiid#b#......",
|
---|
| 419 | ".#hchhcbb#fbbbafhiiiiid#b#......",
|
---|
| 420 | ".#chchhbb#ffgbbfihiiiid#b#......",
|
---|
| 421 | ".#hhhhhbb#ffg#bfiiiiiid#b#......",
|
---|
| 422 | ".#hhhhhbbaffg#bfiiiiiid#b#......",
|
---|
| 423 | ".#iihhhjbbaab#bfiiiiiid#b#......",
|
---|
| 424 | ".#ddiihhh#bbbabfiiiiiid#b#......",
|
---|
| 425 | "..##ddiih#ffbbbfiiiiiid#b#......",
|
---|
| 426 | "....##ddi#ffg#biiiiiiid#b#......",
|
---|
| 427 | "......##d#ffg#iiiiiiiid#b#......",
|
---|
| 428 | "........##ffg#iiiiiiiid#b#......",
|
---|
| 429 | ".........#ffg#iiiiiiiid#b#......",
|
---|
| 430 | ".........#ffg#ddiiiiiid#b###....",
|
---|
| 431 | ".........##fg###ddiiiid#b#####..",
|
---|
| 432 | "...........####.##ddiid#b######.",
|
---|
| 433 | "..................##dddeb#####..",
|
---|
| 434 | "....................##d#b###....",
|
---|
| 435 | "......................####......"};
|
---|
| 436 |
|
---|
| 437 | static QPixmap *iconFolderLockedLarge = 0;
|
---|
| 438 | static QPixmap *iconFolderLarge = 0;
|
---|
| 439 | static QPixmap *iconFileLarge = 0;
|
---|
| 440 | static QPixmap *iconLinkLarge = 0;
|
---|
| 441 | static QPixmap *iconFolderLockedSmall = 0;
|
---|
| 442 | static QPixmap *iconFolderSmall = 0;
|
---|
| 443 | static QPixmap *iconFileSmall = 0;
|
---|
| 444 | static QPixmap *iconLinkSmall = 0;
|
---|
| 445 |
|
---|
| 446 | static void cleanup()
|
---|
| 447 | {
|
---|
| 448 | delete iconFolderLockedLarge;
|
---|
| 449 | iconFolderLockedLarge = 0;
|
---|
| 450 | delete iconFolderLarge;
|
---|
| 451 | iconFolderLarge = 0;
|
---|
| 452 | delete iconFileLarge;
|
---|
| 453 | iconFileLarge = 0;
|
---|
| 454 | delete iconLinkLarge;
|
---|
| 455 | iconLinkLarge = 0;
|
---|
| 456 | delete iconFolderLockedSmall;
|
---|
| 457 | iconFolderLockedSmall = 0;
|
---|
| 458 | delete iconFolderSmall;
|
---|
| 459 | iconFolderSmall = 0;
|
---|
| 460 | delete iconFileSmall;
|
---|
| 461 | iconFileSmall = 0;
|
---|
| 462 | delete iconLinkSmall;
|
---|
| 463 | iconLinkSmall = 0;
|
---|
| 464 | }
|
---|
| 465 |
|
---|
| 466 | /*****************************************************************************
|
---|
| 467 | *
|
---|
| 468 | * Class QtFileIconDrag
|
---|
| 469 | *
|
---|
| 470 | *****************************************************************************/
|
---|
| 471 |
|
---|
| 472 | <a name="f301"></a>QtFileIconDrag::QtFileIconDrag( <a href="qwidget.html">QWidget</a> * dragSource, const char* name )
|
---|
| 473 | : <a href="qicondrag.html">QIconDrag</a>( dragSource, name )
|
---|
| 474 | {
|
---|
| 475 | }
|
---|
| 476 |
|
---|
| 477 | <a name="x832"></a>const char* QtFileIconDrag::<a href="qmimesource.html#format">format</a>( int i ) const
|
---|
| 478 | {
|
---|
| 479 | if ( i == 0 )
|
---|
| 480 | return "application/x-qiconlist";
|
---|
| 481 | else if ( i == 1 )
|
---|
| 482 | return "text/uri-list";
|
---|
| 483 | else
|
---|
| 484 | return 0;
|
---|
| 485 | }
|
---|
| 486 |
|
---|
| 487 | <a name="x831"></a>QByteArray QtFileIconDrag::<a href="qicondrag.html#encodedData">encodedData</a>( const char* mime ) const
|
---|
| 488 | {
|
---|
| 489 | <a href="qbytearray.html">QByteArray</a> a;
|
---|
| 490 | if ( QString( mime ) == "application/x-qiconlist" ) {
|
---|
| 491 | a = QIconDrag::<a href="qicondrag.html#encodedData">encodedData</a>( mime );
|
---|
| 492 | } else if ( QString( mime ) == "text/uri-list" ) {
|
---|
| 493 | <a href="qstring.html">QString</a> s = urls.join( "\r\n" );
|
---|
| 494 | <a name="x870"></a><a name="x856"></a> a.<a href="qmemarray.html#resize">resize</a>( s.<a href="qstring.html#length">length</a>() );
|
---|
| 495 | <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>() );
|
---|
| 496 | }
|
---|
| 497 | return a;
|
---|
| 498 | }
|
---|
| 499 |
|
---|
| 500 | <a name="x830"></a>bool QtFileIconDrag::<a href="qicondrag.html#canDecode">canDecode</a>( <a href="qmimesource.html">QMimeSource</a>* e )
|
---|
| 501 | {
|
---|
| 502 | <a name="x819"></a> return e-><a href="qdropevent.html#provides">provides</a>( "application/x-qiconlist" ) ||
|
---|
| 503 | e-><a href="qdropevent.html#provides">provides</a>( "text/uri-list" );
|
---|
| 504 | }
|
---|
| 505 |
|
---|
| 506 | <a name="x829"></a>void QtFileIconDrag::<a href="qicondrag.html#append">append</a>( const <a href="qicondragitem.html">QIconDragItem</a> &item, const <a href="qrect.html">QRect</a> &pr,
|
---|
| 507 | const <a href="qrect.html">QRect</a> &tr, const <a href="qstring.html">QString</a> &url )
|
---|
| 508 | {
|
---|
| 509 | QIconDrag::<a href="qicondrag.html#append">append</a>( item, pr, tr );
|
---|
| 510 | <a href="qstring.html">QString</a> ourUrl = url;
|
---|
| 511 | #ifdef Q_WS_WIN
|
---|
| 512 | if (ourUrl.<a href="qstring.html#length">length</a>() > 2 && ourUrl[1] != ':') {
|
---|
| 513 | <a href="qdir.html">QDir</a> dir(ourUrl);
|
---|
| 514 | <a name="x810"></a> ourUrl = dir.<a href="qdir.html#absPath">absPath</a>();
|
---|
| 515 | }
|
---|
| 516 | #endif
|
---|
| 517 | urls << QUriDrag::<a href="quridrag.html#localFileToUri">localFileToUri</a>(ourUrl);
|
---|
| 518 | }
|
---|
| 519 |
|
---|
| 520 | /*****************************************************************************
|
---|
| 521 | *
|
---|
| 522 | * Class QtFileIconViewItem
|
---|
| 523 | *
|
---|
| 524 | *****************************************************************************/
|
---|
| 525 |
|
---|
| 526 | <a name="f322"></a>QtFileIconViewItem::QtFileIconViewItem( QtFileIconView *parent, QFileInfo *fi )
|
---|
| 527 | <a name="x824"></a><a name="x823"></a> : <a href="qiconviewitem.html">QIconViewItem</a>( parent, fi-><a href="qfileinfo.html#fileName">fileName</a>() ), itemFileName( fi-><a href="qfileinfo.html#filePath">filePath</a>() ),
|
---|
| 528 | itemFileInfo( fi ), checkSetText( FALSE )
|
---|
| 529 | {
|
---|
| 530 | vm = QtFileIconView::Large;
|
---|
| 531 |
|
---|
| 532 | <a name="x825"></a> if ( itemFileInfo-><a href="qfileinfo.html#isDir">isDir</a>() )
|
---|
| 533 | itemType = Dir;
|
---|
| 534 | <a name="x826"></a> else if ( itemFileInfo-><a href="qfileinfo.html#isFile">isFile</a>() )
|
---|
| 535 | itemType = File;
|
---|
| 536 | <a name="x827"></a> if ( itemFileInfo-><a href="qfileinfo.html#isSymLink">isSymLink</a>() )
|
---|
| 537 | itemType = Link;
|
---|
| 538 |
|
---|
| 539 | viewModeChanged( ( (QtFileIconView*)<a href="qiconviewitem.html#iconView">iconView</a>() )->viewMode() );
|
---|
| 540 |
|
---|
| 541 | if ( itemFileInfo-><a href="qfileinfo.html#fileName">fileName</a>() == "." ||
|
---|
| 542 | itemFileInfo-><a href="qfileinfo.html#fileName">fileName</a>() == ".." )
|
---|
| 543 | <a href="qiconviewitem.html#setRenameEnabled">setRenameEnabled</a>( FALSE );
|
---|
| 544 |
|
---|
| 545 | checkSetText = TRUE;
|
---|
| 546 |
|
---|
| 547 | QObject::<a href="qobject.html#connect">connect</a>( &timer, SIGNAL( timeout() ),
|
---|
| 548 | <a href="qiconviewitem.html#iconView">iconView</a>(), SLOT( openFolder() ) );
|
---|
| 549 | }
|
---|
| 550 |
|
---|
| 551 | <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> &cg )
|
---|
| 552 | {
|
---|
| 553 | if ( itemFileInfo-><a href="qfileinfo.html#isSymLink">isSymLink</a>() ) {
|
---|
| 554 | <a name="x861"></a> <a href="qfont.html">QFont</a> f( p-><a href="qpainter.html#font">font</a>() );
|
---|
| 555 | <a name="x828"></a> f.<a href="qfont.html#setItalic">setItalic</a>( TRUE );
|
---|
| 556 | p-><a href="qpainter.html#setFont">setFont</a>( f );
|
---|
| 557 | }
|
---|
| 558 |
|
---|
| 559 | QIconViewItem::<a href="qiconviewitem.html#paintItem">paintItem</a>( p, cg );
|
---|
| 560 | }
|
---|
| 561 |
|
---|
| 562 | void <a name="f323"></a>QtFileIconViewItem::viewModeChanged( QtFileIconView::ViewMode m )
|
---|
| 563 | {
|
---|
| 564 | vm = m;
|
---|
| 565 | <a href="qiconviewitem.html#setDropEnabled">setDropEnabled</a>( itemType == Dir && QDir( itemFileName ).isReadable() );
|
---|
| 566 | <a href="qiconviewitem.html#calcRect">calcRect</a>();
|
---|
| 567 | }
|
---|
| 568 |
|
---|
| 569 | <a name="x843"></a>QPixmap *QtFileIconViewItem::<a href="qiconviewitem.html#pixmap">pixmap</a>() const
|
---|
| 570 | {
|
---|
| 571 | switch ( itemType ) {
|
---|
| 572 | case Dir:
|
---|
| 573 | {
|
---|
| 574 | if ( !QDir( itemFileName ).isReadable() ) {
|
---|
| 575 | if ( vm == QtFileIconView::Small )
|
---|
| 576 | return iconFolderLockedSmall;
|
---|
| 577 | else
|
---|
| 578 | return iconFolderLockedLarge;
|
---|
| 579 | } else {
|
---|
| 580 | if ( vm == QtFileIconView::Small )
|
---|
| 581 | return iconFolderSmall;
|
---|
| 582 | else
|
---|
| 583 | return iconFolderLarge;
|
---|
| 584 | }
|
---|
| 585 | }
|
---|
| 586 | case Link:
|
---|
| 587 | {
|
---|
| 588 | if ( vm == QtFileIconView::Small )
|
---|
| 589 | return iconLinkSmall;
|
---|
| 590 | else
|
---|
| 591 | return iconLinkLarge;
|
---|
| 592 | }
|
---|
| 593 | default:
|
---|
| 594 | {
|
---|
| 595 | if ( vm == QtFileIconView::Small )
|
---|
| 596 | return iconFileSmall;
|
---|
| 597 | else
|
---|
| 598 | return iconFileLarge;
|
---|
| 599 | }
|
---|
| 600 | }
|
---|
| 601 | }
|
---|
| 602 |
|
---|
| 603 | QtFileIconViewItem::~QtFileIconViewItem()
|
---|
| 604 | {
|
---|
| 605 | delete itemFileInfo;
|
---|
| 606 | }
|
---|
| 607 |
|
---|
| 608 | <a name="x850"></a>void QtFileIconViewItem::<a href="qiconviewitem.html#setText">setText</a>( const <a href="qstring.html">QString</a> &text )
|
---|
| 609 | {
|
---|
| 610 | if ( checkSetText ) {
|
---|
| 611 | if ( text == "." || text == "." || text.<a href="qstring.html#isEmpty">isEmpty</a>() )
|
---|
| 612 | return;
|
---|
| 613 | <a name="x821"></a> <a href="qdir.html">QDir</a> dir( itemFileInfo-><a href="qfileinfo.html#dir">dir</a>() );
|
---|
| 614 | <a name="x814"></a> if ( dir.<a href="qdir.html#rename">rename</a>( itemFileInfo-><a href="qfileinfo.html#fileName">fileName</a>(), text ) ) {
|
---|
| 615 | <a name="x822"></a> itemFileName = itemFileInfo-><a href="qfileinfo.html#dirPath">dirPath</a>( TRUE ) + "/" + text;
|
---|
| 616 | delete itemFileInfo;
|
---|
| 617 | itemFileInfo = new <a href="qfileinfo.html">QFileInfo</a>( itemFileName );
|
---|
| 618 | QIconViewItem::<a href="qiconviewitem.html#setText">setText</a>( text );
|
---|
| 619 | }
|
---|
| 620 | } else {
|
---|
| 621 | QIconViewItem::<a href="qiconviewitem.html#setText">setText</a>( text );
|
---|
| 622 | }
|
---|
| 623 | }
|
---|
| 624 |
|
---|
| 625 | <a name="x836"></a>bool QtFileIconViewItem::<a href="qiconviewitem.html#acceptDrop">acceptDrop</a>( const <a href="qmimesource.html">QMimeSource</a> *e ) const
|
---|
| 626 | {
|
---|
| 627 | if ( type() == Dir && e-><a href="qdropevent.html#provides">provides</a>( "text/uri-list" ) &&
|
---|
| 628 | dropEnabled() )
|
---|
| 629 | return TRUE;
|
---|
| 630 |
|
---|
| 631 | return FALSE;
|
---|
| 632 | }
|
---|
| 633 |
|
---|
| 634 | <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><QIconDragItem> & )
|
---|
| 635 | {
|
---|
| 636 | timer.stop();
|
---|
| 637 |
|
---|
| 638 | if ( !QUriDrag::canDecode( e ) ) {
|
---|
| 639 | <a name="x818"></a> e-><a href="qdropevent.html#ignore">ignore</a>();
|
---|
| 640 | return;
|
---|
| 641 | }
|
---|
| 642 |
|
---|
| 643 | <a href="qstringlist.html">QStringList</a> lst;
|
---|
| 644 | <a name="x873"></a> QUriDrag::<a href="quridrag.html#decodeLocalFiles">decodeLocalFiles</a>( e, lst );
|
---|
| 645 |
|
---|
| 646 | <a href="qstring.html">QString</a> str;
|
---|
| 647 | <a name="x817"></a> if ( e-><a href="qdropevent.html#action">action</a>() == QDropEvent::Copy )
|
---|
| 648 | str = "Copy\n\n";
|
---|
| 649 | else
|
---|
| 650 | str = "Move\n\n";
|
---|
| 651 | <a name="x874"></a> for ( uint i = 0; i < lst.<a href="qvaluelist.html#count">count</a>(); ++i )
|
---|
| 652 | str += QString( " %1\n" ).arg( lst[i] );
|
---|
| 653 | str += QString( "\n"
|
---|
| 654 | "To\n\n"
|
---|
| 655 | " %1" ).arg( filename() );
|
---|
| 656 |
|
---|
| 657 | <a name="x859"></a> QMessageBox::<a href="qmessagebox.html#information">information</a>( iconView(), e-><a href="qdropevent.html#action">action</a>() == QDropEvent::Copy ? "Copy" : "Move" , str, "Not Implemented" );
|
---|
| 658 | if ( e-><a href="qdropevent.html#action">action</a>() == QDropEvent::Move )
|
---|
| 659 | QMessageBox::<a href="qmessagebox.html#information">information</a>( iconView(), "Remove" , str, "Not Implemented" );
|
---|
| 660 | <a name="x816"></a> e-><a href="qdropevent.html#acceptAction">acceptAction</a>();
|
---|
| 661 | }
|
---|
| 662 |
|
---|
| 663 | <a name="x837"></a>void QtFileIconViewItem::<a href="qiconviewitem.html#dragEntered">dragEntered</a>()
|
---|
| 664 | {
|
---|
| 665 | if ( type() != Dir ||
|
---|
| 666 | type() == Dir && !QDir( itemFileName ).isReadable() )
|
---|
| 667 | return;
|
---|
| 668 |
|
---|
| 669 | ( (QtFileIconView*)iconView() )->setOpenItem( this );
|
---|
| 670 | timer.start( 1500 );
|
---|
| 671 | }
|
---|
| 672 |
|
---|
| 673 | <a name="x838"></a>void QtFileIconViewItem::<a href="qiconviewitem.html#dragLeft">dragLeft</a>()
|
---|
| 674 | {
|
---|
| 675 | if ( type() != Dir ||
|
---|
| 676 | type() == Dir && !QDir( itemFileName ).isReadable() )
|
---|
| 677 | return;
|
---|
| 678 |
|
---|
| 679 | timer.stop();
|
---|
| 680 | }
|
---|
| 681 |
|
---|
| 682 | /*****************************************************************************
|
---|
| 683 | *
|
---|
| 684 | * Class QtFileIconView
|
---|
| 685 | *
|
---|
| 686 | *****************************************************************************/
|
---|
| 687 |
|
---|
| 688 | <a name="f302"></a>QtFileIconView::QtFileIconView( const <a href="qstring.html">QString</a> &dir, QWidget *parent, const char *name )
|
---|
| 689 | : <a href="qiconview.html">QIconView</a>( parent, name ), viewDir( dir ), newFolderNum( 0 )
|
---|
| 690 | {
|
---|
| 691 | if ( !iconFolderLockedLarge ) {
|
---|
| 692 | <a href="qapplication.html#qAddPostRoutine">qAddPostRoutine</a>( cleanup );
|
---|
| 693 | <a href="qwmatrix.html">QWMatrix</a> m;
|
---|
| 694 | <a name="x876"></a> m.<a href="qwmatrix.html#scale">scale</a>( 0.6, 0.6 );
|
---|
| 695 | <a href="qpixmap.html">QPixmap</a> iconpix( folder_locked_icon );
|
---|
| 696 | iconFolderLockedLarge = new <a href="qpixmap.html">QPixmap</a>( folder_locked_icon );
|
---|
| 697 | <a name="x863"></a> iconpix = iconpix.<a href="qpixmap.html#xForm">xForm</a>( m );
|
---|
| 698 | iconFolderLockedSmall = new <a href="qpixmap.html">QPixmap</a>( iconpix );
|
---|
| 699 | iconpix = QPixmap( folder_icon );
|
---|
| 700 | iconFolderLarge = new <a href="qpixmap.html">QPixmap</a>( folder_icon );
|
---|
| 701 | iconpix = iconpix.<a href="qpixmap.html#xForm">xForm</a>( m );
|
---|
| 702 | iconFolderSmall = new <a href="qpixmap.html">QPixmap</a>( iconpix );
|
---|
| 703 | iconpix = QPixmap( file_icon );
|
---|
| 704 | iconFileLarge = new <a href="qpixmap.html">QPixmap</a>( file_icon );
|
---|
| 705 | iconpix = iconpix.<a href="qpixmap.html#xForm">xForm</a>( m );
|
---|
| 706 | iconFileSmall = new <a href="qpixmap.html">QPixmap</a>( iconpix );
|
---|
| 707 | iconpix = QPixmap( link_icon );
|
---|
| 708 | iconLinkLarge = new <a href="qpixmap.html">QPixmap</a>( link_icon );
|
---|
| 709 | iconpix = iconpix.<a href="qpixmap.html#xForm">xForm</a>( m );
|
---|
| 710 | iconLinkSmall = new <a href="qpixmap.html">QPixmap</a>( iconpix );
|
---|
| 711 | }
|
---|
| 712 |
|
---|
| 713 | vm = Large;
|
---|
| 714 |
|
---|
| 715 | <a href="qiconview.html#setGridX">setGridX</a>( 75 );
|
---|
| 716 | <a href="qiconview.html#setResizeMode">setResizeMode</a>( Adjust );
|
---|
| 717 | <a href="qiconview.html#setWordWrapIconText">setWordWrapIconText</a>( FALSE );
|
---|
| 718 |
|
---|
| 719 | <a href="qobject.html#connect">connect</a>( this, SIGNAL( <a href="qiconview.html#doubleClicked">doubleClicked</a>( <a href="qiconviewitem.html">QIconViewItem</a> * ) ),
|
---|
| 720 | this, SLOT( itemDoubleClicked( <a href="qiconviewitem.html">QIconViewItem</a> * ) ) );
|
---|
| 721 | <a href="qobject.html#connect">connect</a>( this, SIGNAL( <a href="qiconview.html#returnPressed">returnPressed</a>( <a href="qiconviewitem.html">QIconViewItem</a> * ) ),
|
---|
| 722 | this, SLOT( itemDoubleClicked( <a href="qiconviewitem.html">QIconViewItem</a> * ) ) );
|
---|
| 723 | <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><QIconDragItem> & ) ),
|
---|
| 724 | this, SLOT( slotDropped( <a href="qdropevent.html">QDropEvent</a> *, const <a href="qvaluelist.html">QValueList</a><QIconDragItem> & ) ) );
|
---|
| 725 | <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> & ) ),
|
---|
| 726 | this, SLOT( slotRightPressed( <a href="qiconviewitem.html">QIconViewItem</a> * ) ) );
|
---|
| 727 |
|
---|
| 728 | <a href="qscrollview.html#setHScrollBarMode">setHScrollBarMode</a>( AlwaysOff );
|
---|
| 729 | <a href="qscrollview.html#setVScrollBarMode">setVScrollBarMode</a>( Auto );
|
---|
| 730 |
|
---|
| 731 | <a href="qiconview.html#setAutoArrange">setAutoArrange</a>( TRUE );
|
---|
| 732 | <a href="qiconview.html#setSorting">setSorting</a>( TRUE );
|
---|
| 733 | openItem = 0;
|
---|
| 734 | }
|
---|
| 735 |
|
---|
| 736 | void <a name="f303"></a>QtFileIconView::openFolder()
|
---|
| 737 | {
|
---|
| 738 | if ( !openItem )
|
---|
| 739 | return;
|
---|
| 740 | if ( openItem->type() != QtFileIconViewItem::Dir ||
|
---|
| 741 | openItem->type() == QtFileIconViewItem::Dir &&
|
---|
| 742 | !QDir( openItem->itemFileName ).isReadable() )
|
---|
| 743 | return;
|
---|
| 744 |
|
---|
| 745 | openItem->timer.stop();
|
---|
| 746 | setDirectory( openItem->itemFileName );
|
---|
| 747 | }
|
---|
| 748 |
|
---|
| 749 | void <a name="f304"></a>QtFileIconView::setDirectory( const <a href="qstring.html">QString</a> &dir )
|
---|
| 750 | {
|
---|
| 751 | viewDir = QDir( dir );
|
---|
| 752 | readDir( viewDir );
|
---|
| 753 | }
|
---|
| 754 |
|
---|
| 755 | void QtFileIconView::setDirectory( const <a href="qdir.html">QDir</a> &dir )
|
---|
| 756 | {
|
---|
| 757 | viewDir = dir;
|
---|
| 758 | readDir( viewDir );
|
---|
| 759 | }
|
---|
| 760 |
|
---|
| 761 | void <a name="f305"></a>QtFileIconView::newDirectory()
|
---|
| 762 | {
|
---|
| 763 | <a href="qiconview.html#setAutoArrange">setAutoArrange</a>( FALSE );
|
---|
| 764 | <a href="qiconview.html#selectAll">selectAll</a>( FALSE );
|
---|
| 765 | if ( viewDir.mkdir( QString( "New Folder %1" ).arg( ++newFolderNum ) ) ) {
|
---|
| 766 | <a href="qfileinfo.html">QFileInfo</a> *fi = new <a href="qfileinfo.html">QFileInfo</a>( viewDir, QString( "New Folder %1" ).arg( newFolderNum ) );
|
---|
| 767 | QtFileIconViewItem *item = new QtFileIconViewItem( this, new <a href="qfileinfo.html">QFileInfo</a>( *fi ) );
|
---|
| 768 | <a name="x847"></a> item-><a href="qiconviewitem.html#setKey">setKey</a>( QString( "000000%1" ).arg( fi-><a href="qfileinfo.html#fileName">fileName</a>() ) );
|
---|
| 769 | delete fi;
|
---|
| 770 | <a href="qscrollview.html#repaintContents">repaintContents</a>( <a href="qscrollview.html#contentsX">contentsX</a>(), contentsY(), contentsWidth(), contentsHeight(), FALSE );
|
---|
| 771 | <a href="qiconview.html#ensureItemVisible">ensureItemVisible</a>( item );
|
---|
| 772 | <a name="x849"></a> item-><a href="qiconviewitem.html#setSelected">setSelected</a>( TRUE, TRUE );
|
---|
| 773 | <a href="qiconview.html#setCurrentItem">setCurrentItem</a>( item );
|
---|
| 774 | <a href="qiconview.html#repaintItem">repaintItem</a>( item );
|
---|
| 775 | <a name="x808"></a> qApp-><a href="qapplication.html#processEvents">processEvents</a>();
|
---|
| 776 | <a name="x845"></a> item-><a href="qiconviewitem.html#rename">rename</a>();
|
---|
| 777 | }
|
---|
| 778 | <a href="qiconview.html#setAutoArrange">setAutoArrange</a>( TRUE );
|
---|
| 779 | }
|
---|
| 780 |
|
---|
| 781 | QDir <a name="f306"></a>QtFileIconView::currentDir()
|
---|
| 782 | {
|
---|
| 783 | return viewDir;
|
---|
| 784 | }
|
---|
| 785 |
|
---|
| 786 | static bool isRoot( const <a href="qstring.html">QString</a> &s )
|
---|
| 787 | {
|
---|
| 788 | #if defined(Q_OS_UNIX)
|
---|
| 789 | if ( s == "/" )
|
---|
| 790 | return TRUE;
|
---|
| 791 | #elif defined(Q_OS_WIN32)
|
---|
| 792 | <a href="qstring.html">QString</a> p = s;
|
---|
| 793 | if ( p.<a href="qstring.html#length">length</a>() == 3 &&
|
---|
| 794 | <a name="x871"></a> p.<a href="qstring.html#right">right</a>( 2 ) == ":/" )
|
---|
| 795 | return TRUE;
|
---|
| 796 | if ( p[ 0 ] == '/' && p[ 1 ] == '/' ) {
|
---|
| 797 | <a name="x867"></a> int slashes = p.<a href="qstring.html#contains">contains</a>( '/' );
|
---|
| 798 | if ( slashes <= 3 )
|
---|
| 799 | return TRUE;
|
---|
| 800 | if ( slashes == 4 && p[ (int)p.<a href="qstring.html#length">length</a>() - 1 ] == '/' )
|
---|
| 801 | return TRUE;
|
---|
| 802 | }
|
---|
| 803 | #endif
|
---|
| 804 |
|
---|
| 805 | return FALSE;
|
---|
| 806 | }
|
---|
| 807 |
|
---|
| 808 | void <a name="f307"></a>QtFileIconView::readDir( const <a href="qdir.html">QDir</a> &dir )
|
---|
| 809 | {
|
---|
| 810 | <a name="x813"></a> if ( !dir.<a href="qdir.html#isReadable">isReadable</a>() )
|
---|
| 811 | return;
|
---|
| 812 |
|
---|
| 813 | if ( isRoot( dir.<a href="qdir.html#absPath">absPath</a>() ) )
|
---|
| 814 | emit disableUp();
|
---|
| 815 | else
|
---|
| 816 | emit enableUp();
|
---|
| 817 |
|
---|
| 818 | <a href="qiconview.html#clear">clear</a>();
|
---|
| 819 |
|
---|
| 820 | emit directoryChanged( dir.<a href="qdir.html#absPath">absPath</a>() );
|
---|
| 821 |
|
---|
| 822 | <a name="x812"></a> const QFileInfoList *filist = dir.<a href="qdir.html#entryInfoList">entryInfoList</a>( QDir::DefaultFilter, QDir::DirsFirst | QDir::Name );
|
---|
| 823 |
|
---|
| 824 | emit startReadDir( filist->count() );
|
---|
| 825 |
|
---|
| 826 | QFileInfoListIterator it( *filist );
|
---|
| 827 | <a href="qfileinfo.html">QFileInfo</a> *fi;
|
---|
| 828 | bool allowRename = FALSE, allowRenameSet = FALSE;
|
---|
| 829 | while ( ( fi = it.current() ) != 0 ) {
|
---|
| 830 | ++it;
|
---|
| 831 | if ( fi && fi-><a href="qfileinfo.html#fileName">fileName</a>() == ".." && ( fi-><a href="qfileinfo.html#dirPath">dirPath</a>() == "/" || fi-><a href="qfileinfo.html#dirPath">dirPath</a>().isEmpty() ) )
|
---|
| 832 | continue;
|
---|
| 833 | emit readNextDir();
|
---|
| 834 | QtFileIconViewItem *item = new QtFileIconViewItem( this, new <a href="qfileinfo.html">QFileInfo</a>( *fi ) );
|
---|
| 835 | if ( fi-><a href="qfileinfo.html#isDir">isDir</a>() )
|
---|
| 836 | item-><a href="qiconviewitem.html#setKey">setKey</a>( QString( "000000%1" ).arg( fi-><a href="qfileinfo.html#fileName">fileName</a>() ) );
|
---|
| 837 | else
|
---|
| 838 | item-><a href="qiconviewitem.html#setKey">setKey</a>( fi-><a href="qfileinfo.html#fileName">fileName</a>() );
|
---|
| 839 | if ( !allowRenameSet ) {
|
---|
| 840 | <a name="x820"></a> if ( !QFileInfo( fi-><a href="qfileinfo.html#absFilePath">absFilePath</a>() ).isWritable() ||
|
---|
| 841 | <a name="x851"></a> item-><a href="qiconviewitem.html#text">text</a>() == "." || item-><a href="qiconviewitem.html#text">text</a>() == ".." )
|
---|
| 842 | allowRename = FALSE;
|
---|
| 843 | else
|
---|
| 844 | allowRename = TRUE;
|
---|
| 845 | if ( item-><a href="qiconviewitem.html#text">text</a>() == "." || item-><a href="qiconviewitem.html#text">text</a>() == ".." )
|
---|
| 846 | allowRenameSet = FALSE;
|
---|
| 847 | else
|
---|
| 848 | allowRenameSet = TRUE;
|
---|
| 849 | }
|
---|
| 850 | <a name="x848"></a> item-><a href="qiconviewitem.html#setRenameEnabled">setRenameEnabled</a>( allowRename );
|
---|
| 851 | }
|
---|
| 852 |
|
---|
| 853 | if ( !QFileInfo( dir.<a href="qdir.html#absPath">absPath</a>() ).isWritable() )
|
---|
| 854 | emit disableMkdir();
|
---|
| 855 | else
|
---|
| 856 | emit enableMkdir();
|
---|
| 857 |
|
---|
| 858 | emit readDirDone();
|
---|
| 859 | }
|
---|
| 860 |
|
---|
| 861 | void <a name="f308"></a>QtFileIconView::itemDoubleClicked( <a href="qiconviewitem.html">QIconViewItem</a> *i )
|
---|
| 862 | {
|
---|
| 863 | QtFileIconViewItem *item = ( QtFileIconViewItem* )i;
|
---|
| 864 |
|
---|
| 865 | if ( item->type() == QtFileIconViewItem::Dir ) {
|
---|
| 866 | viewDir = QDir( item->filename() );
|
---|
| 867 | readDir( viewDir );
|
---|
| 868 | } else if ( item->type() == QtFileIconViewItem::Link &&
|
---|
| 869 | QFileInfo( QFileInfo( item->filename() ).readLink() ).isDir() ) {
|
---|
| 870 | viewDir = QDir( QFileInfo( item->filename() ).readLink() );
|
---|
| 871 | readDir( viewDir );
|
---|
| 872 | }
|
---|
| 873 | }
|
---|
| 874 |
|
---|
| 875 | <a name="x834"></a>QDragObject *QtFileIconView::<a href="qiconview.html#dragObject">dragObject</a>()
|
---|
| 876 | {
|
---|
| 877 | if ( !currentItem() )
|
---|
| 878 | return 0;
|
---|
| 879 |
|
---|
| 880 | <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>()->mapFromGlobal( QCursor::<a href="qcursor.html#pos">pos</a>() ) );
|
---|
| 881 | QtFileIconDrag *drag = new QtFileIconDrag( <a href="qscrollview.html#viewport">viewport</a>() );
|
---|
| 882 | <a name="x815"></a> drag-><a href="qdragobject.html#setPixmap">setPixmap</a>( *currentItem()->pixmap(),
|
---|
| 883 | QPoint( <a href="qiconview.html#currentItem">currentItem</a>()->pixmapRect().width() / 2, currentItem()->pixmapRect().height() / 2 ) );
|
---|
| 884 | for ( QtFileIconViewItem *item = (QtFileIconViewItem*)<a href="qiconview.html#firstItem">firstItem</a>(); item;
|
---|
| 885 | <a name="x841"></a> item = (QtFileIconViewItem*)item-><a href="qiconviewitem.html#nextItem">nextItem</a>() ) {
|
---|
| 886 | <a name="x840"></a> if ( item-><a href="qiconviewitem.html#isSelected">isSelected</a>() ) {
|
---|
| 887 | <a href="qicondragitem.html">QIconDragItem</a> id;
|
---|
| 888 | <a name="x833"></a> id.<a href="qicondragitem.html#setData">setData</a>( QCString( item->filename() ) );
|
---|
| 889 | drag-><a href="qicondrag.html#append">append</a>( id,
|
---|
| 890 | <a name="x864"></a><a name="x844"></a> QRect( item-><a href="qiconviewitem.html#pixmapRect">pixmapRect</a>( FALSE ).x() - orig.<a href="qpoint.html#x">x</a>(),
|
---|
| 891 | <a name="x865"></a> item-><a href="qiconviewitem.html#pixmapRect">pixmapRect</a>( FALSE ).y() - orig.<a href="qpoint.html#y">y</a>(),
|
---|
| 892 | item-><a href="qiconviewitem.html#pixmapRect">pixmapRect</a>().width(), item-><a href="qiconviewitem.html#pixmapRect">pixmapRect</a>().height() ),
|
---|
| 893 | <a name="x852"></a> QRect( item-><a href="qiconviewitem.html#textRect">textRect</a>( FALSE ).x() - orig.<a href="qpoint.html#x">x</a>(),
|
---|
| 894 | item-><a href="qiconviewitem.html#textRect">textRect</a>( FALSE ).y() - orig.<a href="qpoint.html#y">y</a>(),
|
---|
| 895 | item-><a href="qiconviewitem.html#textRect">textRect</a>().width(), item-><a href="qiconviewitem.html#textRect">textRect</a>().height() ),
|
---|
| 896 | QString( item->filename() ) );
|
---|
| 897 | }
|
---|
| 898 | }
|
---|
| 899 |
|
---|
| 900 | return drag;
|
---|
| 901 | }
|
---|
| 902 |
|
---|
| 903 | <a name="x835"></a>void QtFileIconView::<a href="qwidget.html#keyPressEvent">keyPressEvent</a>( <a href="qkeyevent.html">QKeyEvent</a> *e )
|
---|
| 904 | {
|
---|
| 905 | <a name="x853"></a> if ( e-><a href="qkeyevent.html#key">key</a>() == Key_N &&
|
---|
| 906 | <a name="x854"></a> ( e-><a href="qkeyevent.html#state">state</a>() & ControlButton ) )
|
---|
| 907 | newDirectory();
|
---|
| 908 | else
|
---|
| 909 | QIconView::<a href="qwidget.html#keyPressEvent">keyPressEvent</a>( e );
|
---|
| 910 | }
|
---|
| 911 |
|
---|
| 912 | void <a name="f309"></a>QtFileIconView::slotDropped( <a href="qdropevent.html">QDropEvent</a> *e, const <a href="qvaluelist.html">QValueList</a><QIconDragItem> & )
|
---|
| 913 | {
|
---|
| 914 | if ( openItem )
|
---|
| 915 | openItem->timer.stop();
|
---|
| 916 | if ( !QUriDrag::canDecode( e ) ) {
|
---|
| 917 | e-><a href="qdropevent.html#ignore">ignore</a>();
|
---|
| 918 | return;
|
---|
| 919 | }
|
---|
| 920 |
|
---|
| 921 | <a href="qstringlist.html">QStringList</a> lst;
|
---|
| 922 | QUriDrag::<a href="quridrag.html#decodeLocalFiles">decodeLocalFiles</a>( e, lst );
|
---|
| 923 |
|
---|
| 924 | <a href="qstring.html">QString</a> str;
|
---|
| 925 | if ( e-><a href="qdropevent.html#action">action</a>() == QDropEvent::Copy )
|
---|
| 926 | str = "Copy\n\n";
|
---|
| 927 | else
|
---|
| 928 | str = "Move\n\n";
|
---|
| 929 | for ( uint i = 0; i < lst.<a href="qvaluelist.html#count">count</a>(); ++i )
|
---|
| 930 | <a name="x811"></a> str += QString( " %1\n" ).arg( QDir::<a href="qdir.html#convertSeparators">convertSeparators</a>(lst[i]) );
|
---|
| 931 | str += QString( "\n"
|
---|
| 932 | "To\n\n"
|
---|
| 933 | " %1" ).arg( viewDir.absPath() );
|
---|
| 934 |
|
---|
| 935 | QMessageBox::<a href="qmessagebox.html#information">information</a>( this, e-><a href="qdropevent.html#action">action</a>() == QDropEvent::Copy ? "Copy" : "Move" , str, "Not Implemented" );
|
---|
| 936 | if ( e-><a href="qdropevent.html#action">action</a>() == QDropEvent::Move )
|
---|
| 937 | <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" );
|
---|
| 938 | e-><a href="qdropevent.html#acceptAction">acceptAction</a>();
|
---|
| 939 | openItem = 0;
|
---|
| 940 | }
|
---|
| 941 |
|
---|
| 942 | void <a name="f310"></a>QtFileIconView::viewLarge()
|
---|
| 943 | {
|
---|
| 944 | setViewMode( Large );
|
---|
| 945 | }
|
---|
| 946 |
|
---|
| 947 | void <a name="f311"></a>QtFileIconView::viewSmall()
|
---|
| 948 | {
|
---|
| 949 | setViewMode( Small );
|
---|
| 950 | }
|
---|
| 951 |
|
---|
| 952 | void <a name="f312"></a>QtFileIconView::viewBottom()
|
---|
| 953 | {
|
---|
| 954 | <a href="qiconview.html#setItemTextPos">setItemTextPos</a>( Bottom );
|
---|
| 955 | }
|
---|
| 956 |
|
---|
| 957 | void <a name="f313"></a>QtFileIconView::viewRight()
|
---|
| 958 | {
|
---|
| 959 | <a href="qiconview.html#setItemTextPos">setItemTextPos</a>( Right );
|
---|
| 960 | }
|
---|
| 961 |
|
---|
| 962 | void <a name="f314"></a>QtFileIconView::flowEast()
|
---|
| 963 | {
|
---|
| 964 | <a href="qscrollview.html#setHScrollBarMode">setHScrollBarMode</a>( AlwaysOff );
|
---|
| 965 | <a href="qscrollview.html#setVScrollBarMode">setVScrollBarMode</a>( Auto );
|
---|
| 966 | <a href="qiconview.html#setArrangement">setArrangement</a>( LeftToRight );
|
---|
| 967 | }
|
---|
| 968 |
|
---|
| 969 | void <a name="f315"></a>QtFileIconView::flowSouth()
|
---|
| 970 | {
|
---|
| 971 | <a href="qscrollview.html#setVScrollBarMode">setVScrollBarMode</a>( AlwaysOff );
|
---|
| 972 | <a href="qscrollview.html#setHScrollBarMode">setHScrollBarMode</a>( Auto );
|
---|
| 973 | <a href="qiconview.html#setArrangement">setArrangement</a>( TopToBottom );
|
---|
| 974 | }
|
---|
| 975 |
|
---|
| 976 | void <a name="f316"></a>QtFileIconView::sortAscending()
|
---|
| 977 | {
|
---|
| 978 | <a href="qiconview.html#sort">sort</a>( TRUE );
|
---|
| 979 | }
|
---|
| 980 |
|
---|
| 981 | void <a name="f317"></a>QtFileIconView::sortDescending()
|
---|
| 982 | {
|
---|
| 983 | <a href="qiconview.html#sort">sort</a>( FALSE );
|
---|
| 984 | }
|
---|
| 985 |
|
---|
| 986 | void <a name="f318"></a>QtFileIconView::itemTextTruncate()
|
---|
| 987 | {
|
---|
| 988 | <a href="qiconview.html#setWordWrapIconText">setWordWrapIconText</a>( FALSE );
|
---|
| 989 | }
|
---|
| 990 |
|
---|
| 991 | void <a name="f319"></a>QtFileIconView::itemTextWordWrap()
|
---|
| 992 | {
|
---|
| 993 | <a href="qiconview.html#setWordWrapIconText">setWordWrapIconText</a>( TRUE );
|
---|
| 994 | }
|
---|
| 995 |
|
---|
| 996 | void <a name="f320"></a>QtFileIconView::slotRightPressed( <a href="qiconviewitem.html">QIconViewItem</a> *item )
|
---|
| 997 | {
|
---|
| 998 | if ( !item ) { // right pressed on viewport
|
---|
| 999 | <a href="qpopupmenu.html">QPopupMenu</a> menu( this );
|
---|
| 1000 |
|
---|
| 1001 | menu.<a href="qmenudata.html#insertItem">insertItem</a>( "&Large view", this, SLOT( viewLarge() ) );
|
---|
| 1002 | menu.<a href="qmenudata.html#insertItem">insertItem</a>( "&Small view", this, SLOT( viewSmall() ) );
|
---|
| 1003 | menu.<a href="qmenudata.html#insertSeparator">insertSeparator</a>();
|
---|
| 1004 | menu.<a href="qmenudata.html#insertItem">insertItem</a>( "Text at the &bottom", this, SLOT( viewBottom() ) );
|
---|
| 1005 | menu.<a href="qmenudata.html#insertItem">insertItem</a>( "Text at the &right", this, SLOT( viewRight() ) );
|
---|
| 1006 | menu.<a href="qmenudata.html#insertSeparator">insertSeparator</a>();
|
---|
| 1007 | menu.<a href="qmenudata.html#insertItem">insertItem</a>( "Arrange l&eft to right", this, SLOT( flowEast() ) );
|
---|
| 1008 | menu.<a href="qmenudata.html#insertItem">insertItem</a>( "Arrange t&op to bottom", this, SLOT( flowSouth() ) );
|
---|
| 1009 | menu.<a href="qmenudata.html#insertSeparator">insertSeparator</a>();
|
---|
| 1010 | menu.<a href="qmenudata.html#insertItem">insertItem</a>( "&Truncate item text", this, SLOT( itemTextTruncate() ) );
|
---|
| 1011 | menu.<a href="qmenudata.html#insertItem">insertItem</a>( "&Wordwrap item text", this, SLOT( itemTextWordWrap() ) );
|
---|
| 1012 | menu.<a href="qmenudata.html#insertSeparator">insertSeparator</a>();
|
---|
| 1013 | menu.<a href="qmenudata.html#insertItem">insertItem</a>( "Arrange items in &grid", this, SLOT( <a href="qiconview.html#arrangeItemsInGrid">arrangeItemsInGrid</a>() ) );
|
---|
| 1014 | menu.<a href="qmenudata.html#insertSeparator">insertSeparator</a>();
|
---|
| 1015 | menu.<a href="qmenudata.html#insertItem">insertItem</a>( "Sort &ascending", this, SLOT( sortAscending() ) );
|
---|
| 1016 | menu.<a href="qmenudata.html#insertItem">insertItem</a>( "Sort &descending", this, SLOT( sortDescending() ) );
|
---|
| 1017 |
|
---|
| 1018 | <a name="x875"></a> menu.<a href="qwidget.html#setMouseTracking">setMouseTracking</a>( TRUE );
|
---|
| 1019 | <a name="x866"></a> menu.<a href="qpopupmenu.html#exec">exec</a>( QCursor::<a href="qcursor.html#pos">pos</a>() );
|
---|
| 1020 | } else { // on item
|
---|
| 1021 | <a href="qpopupmenu.html">QPopupMenu</a> menu( this );
|
---|
| 1022 |
|
---|
| 1023 | int RENAME_ITEM = menu.<a href="qmenudata.html#insertItem">insertItem</a>( "Rename Item" );
|
---|
| 1024 | int REMOVE_ITEM = menu.<a href="qmenudata.html#insertItem">insertItem</a>( "Remove Item" );
|
---|
| 1025 |
|
---|
| 1026 | menu.<a href="qwidget.html#setMouseTracking">setMouseTracking</a>( TRUE );
|
---|
| 1027 | int id = menu.<a href="qpopupmenu.html#exec">exec</a>( QCursor::<a href="qcursor.html#pos">pos</a>() );
|
---|
| 1028 |
|
---|
| 1029 | if ( id == -1 )
|
---|
| 1030 | return;
|
---|
| 1031 |
|
---|
| 1032 | <a name="x846"></a> if ( id == RENAME_ITEM && item-><a href="qiconviewitem.html#renameEnabled">renameEnabled</a>() ) {
|
---|
| 1033 | item-><a href="qiconviewitem.html#rename">rename</a>();
|
---|
| 1034 | } else if ( id == REMOVE_ITEM ) {
|
---|
| 1035 | delete item;
|
---|
| 1036 | QMessageBox::<a href="qmessagebox.html#information">information</a>( this, "Not implemented!", "Deleting files not implemented yet,\n"
|
---|
| 1037 | "The item has only been removed from the view! " );
|
---|
| 1038 | }
|
---|
| 1039 | }
|
---|
| 1040 | }
|
---|
| 1041 |
|
---|
| 1042 | void <a name="f321"></a>QtFileIconView::setViewMode( ViewMode m )
|
---|
| 1043 | {
|
---|
| 1044 | if ( m == vm )
|
---|
| 1045 | return;
|
---|
| 1046 |
|
---|
| 1047 | vm = m;
|
---|
| 1048 | QtFileIconViewItem *item = (QtFileIconViewItem*)<a href="qiconview.html#firstItem">firstItem</a>();
|
---|
| 1049 | for ( ; item; item = (QtFileIconViewItem*)item-><a href="qiconviewitem.html#nextItem">nextItem</a>() )
|
---|
| 1050 | item->viewModeChanged( vm );
|
---|
| 1051 |
|
---|
| 1052 | <a href="qiconview.html#arrangeItemsInGrid">arrangeItemsInGrid</a>();
|
---|
| 1053 | }
|
---|
| 1054 | </pre>
|
---|
| 1055 |
|
---|
| 1056 | <p> <hr>
|
---|
| 1057 | <p> Header file of the main window:
|
---|
| 1058 | <p> <pre>/****************************************************************************
|
---|
| 1059 | ** $Id: fileiconview-example.html 2051 2007-02-21 10:04:20Z chehrlic $
|
---|
| 1060 | **
|
---|
| 1061 | ** Copyright (C) 1992-2007 Trolltech ASA. All rights reserved.
|
---|
| 1062 | **
|
---|
| 1063 | ** This file is part of an example program for Qt. This example
|
---|
| 1064 | ** program may be used, distributed and modified without limitation.
|
---|
| 1065 | **
|
---|
| 1066 | *****************************************************************************/
|
---|
| 1067 |
|
---|
| 1068 | #ifndef MAINWIN_H
|
---|
| 1069 | #define MAINWIN_H
|
---|
| 1070 |
|
---|
| 1071 | #include <<a href="qmainwindow-h.html">qmainwindow.h</a>>
|
---|
| 1072 |
|
---|
| 1073 | class QtFileIconView;
|
---|
| 1074 | class DirectoryView;
|
---|
| 1075 | class QProgressBar;
|
---|
| 1076 | class QLabel;
|
---|
| 1077 | class QComboBox;
|
---|
| 1078 | class QToolButton;
|
---|
| 1079 |
|
---|
| 1080 | class FileMainWindow : public <a href="qmainwindow.html">QMainWindow</a>
|
---|
| 1081 | {
|
---|
| 1082 | Q_OBJECT
|
---|
| 1083 |
|
---|
| 1084 | public:
|
---|
| 1085 | FileMainWindow();
|
---|
| 1086 |
|
---|
| 1087 | QtFileIconView *fileView() { return fileview; }
|
---|
| 1088 | DirectoryView *dirList() { return dirlist; }
|
---|
| 1089 |
|
---|
| 1090 | void show();
|
---|
| 1091 |
|
---|
| 1092 | protected:
|
---|
| 1093 | void setup();
|
---|
| 1094 | void setPathCombo();
|
---|
| 1095 |
|
---|
| 1096 | QtFileIconView *fileview;
|
---|
| 1097 | DirectoryView *dirlist;
|
---|
| 1098 | <a href="qprogressbar.html">QProgressBar</a> *progress;
|
---|
| 1099 | <a href="qlabel.html">QLabel</a> *label;
|
---|
| 1100 | <a href="qcombobox.html">QComboBox</a> *pathCombo;
|
---|
| 1101 | <a href="qtoolbutton.html">QToolButton</a> *upButton, *mkdirButton;
|
---|
| 1102 |
|
---|
| 1103 | protected slots:
|
---|
| 1104 | void directoryChanged( const <a href="qstring.html">QString</a> & );
|
---|
| 1105 | void slotStartReadDir( int dirs );
|
---|
| 1106 | void slotReadNextDir();
|
---|
| 1107 | void slotReadDirDone();
|
---|
| 1108 | void cdUp();
|
---|
| 1109 | void newFolder();
|
---|
| 1110 | void changePath( const <a href="qstring.html">QString</a> &path );
|
---|
| 1111 | void enableUp();
|
---|
| 1112 | void disableUp();
|
---|
| 1113 | void enableMkdir();
|
---|
| 1114 | void disableMkdir();
|
---|
| 1115 |
|
---|
| 1116 | };
|
---|
| 1117 |
|
---|
| 1118 | #endif
|
---|
| 1119 | </pre>
|
---|
| 1120 |
|
---|
| 1121 | <p> <hr>
|
---|
| 1122 | <p> Implementation of the main window:
|
---|
| 1123 | <p> <pre>/****************************************************************************
|
---|
| 1124 | ** $Id: fileiconview-example.html 2051 2007-02-21 10:04:20Z chehrlic $
|
---|
| 1125 | **
|
---|
| 1126 | ** Copyright (C) 1992-2007 Trolltech ASA. All rights reserved.
|
---|
| 1127 | **
|
---|
| 1128 | ** This file is part of an example program for Qt. This example
|
---|
| 1129 | ** program may be used, distributed and modified without limitation.
|
---|
| 1130 | **
|
---|
| 1131 | *****************************************************************************/
|
---|
| 1132 |
|
---|
| 1133 | #include "mainwindow.h"
|
---|
| 1134 | #include "qfileiconview.h"
|
---|
| 1135 | #include "../dirview/dirview.h"
|
---|
| 1136 |
|
---|
| 1137 | #include <<a href="qsplitter-h.html">qsplitter.h</a>>
|
---|
| 1138 | #include <<a href="qprogressbar-h.html">qprogressbar.h</a>>
|
---|
| 1139 | #include <<a href="qlabel-h.html">qlabel.h</a>>
|
---|
| 1140 | #include <<a href="qstatusbar-h.html">qstatusbar.h</a>>
|
---|
| 1141 | #include <<a href="qtoolbar-h.html">qtoolbar.h</a>>
|
---|
| 1142 | #include <<a href="qcombobox-h.html">qcombobox.h</a>>
|
---|
| 1143 | #include <<a href="qpixmap-h.html">qpixmap.h</a>>
|
---|
| 1144 | #include <<a href="qtoolbutton-h.html">qtoolbutton.h</a>>
|
---|
| 1145 | #include <<a href="qdir-h.html">qdir.h</a>>
|
---|
| 1146 | #include <<a href="qfileinfo-h.html">qfileinfo.h</a>>
|
---|
| 1147 |
|
---|
| 1148 | static const char* cdtoparent_xpm[]={
|
---|
| 1149 | "15 13 3 1",
|
---|
| 1150 | ". c None",
|
---|
| 1151 | "* c #000000",
|
---|
| 1152 | "a c #ffff99",
|
---|
| 1153 | "..*****........",
|
---|
| 1154 | ".*aaaaa*.......",
|
---|
| 1155 | "***************",
|
---|
| 1156 | "*aaaaaaaaaaaaa*",
|
---|
| 1157 | "*aaaa*aaaaaaaa*",
|
---|
| 1158 | "*aaa***aaaaaaa*",
|
---|
| 1159 | "*aa*****aaaaaa*",
|
---|
| 1160 | "*aaaa*aaaaaaaa*",
|
---|
| 1161 | "*aaaa*aaaaaaaa*",
|
---|
| 1162 | "*aaaa******aaa*",
|
---|
| 1163 | "*aaaaaaaaaaaaa*",
|
---|
| 1164 | "*aaaaaaaaaaaaa*",
|
---|
| 1165 | "***************"};
|
---|
| 1166 |
|
---|
| 1167 | static const char* newfolder_xpm[] = {
|
---|
| 1168 | "15 14 4 1",
|
---|
| 1169 | " c None",
|
---|
| 1170 | ". c #000000",
|
---|
| 1171 | "+ c #FFFF00",
|
---|
| 1172 | "@ c #FFFFFF",
|
---|
| 1173 | " . ",
|
---|
| 1174 | " ",
|
---|
| 1175 | " . ",
|
---|
| 1176 | " . . ",
|
---|
| 1177 | " .... . . . ",
|
---|
| 1178 | " .+@+@. . . ",
|
---|
| 1179 | ".......... . .",
|
---|
| 1180 | ".@+@+@+@+@.. ",
|
---|
| 1181 | ".+@+@+@+@+. . ",
|
---|
| 1182 | ".@+@+@+@+@. . ",
|
---|
| 1183 | ".+@+@+@+@+. ",
|
---|
| 1184 | ".@+@+@+@+@. ",
|
---|
| 1185 | ".+@+@+@+@+. ",
|
---|
| 1186 | "........... "};
|
---|
| 1187 |
|
---|
| 1188 | <a name="f324"></a>FileMainWindow::FileMainWindow()
|
---|
| 1189 | : <a href="qmainwindow.html">QMainWindow</a>()
|
---|
| 1190 | {
|
---|
| 1191 | setup();
|
---|
| 1192 | }
|
---|
| 1193 |
|
---|
| 1194 | void FileMainWindow::<a href="qwidget.html#show">show</a>()
|
---|
| 1195 | {
|
---|
| 1196 | QMainWindow::<a href="qwidget.html#show">show</a>();
|
---|
| 1197 | }
|
---|
| 1198 |
|
---|
| 1199 | void <a name="f325"></a>FileMainWindow::setup()
|
---|
| 1200 | {
|
---|
| 1201 | <a href="qsplitter.html">QSplitter</a> *splitter = new <a href="qsplitter.html">QSplitter</a>( this );
|
---|
| 1202 |
|
---|
| 1203 | dirlist = new DirectoryView( splitter, "dirlist", TRUE );
|
---|
| 1204 | <a name="x886"></a> dirlist-><a href="qlistview.html#addColumn">addColumn</a>( "Name" );
|
---|
| 1205 | dirlist-><a href="qlistview.html#addColumn">addColumn</a>( "Type" );
|
---|
| 1206 | Directory *root = new Directory( dirlist, "/" );
|
---|
| 1207 | <a name="x887"></a> root-><a href="qlistviewitem.html#setOpen">setOpen</a>( TRUE );
|
---|
| 1208 | <a name="x894"></a> splitter-><a href="qsplitter.html#setResizeMode">setResizeMode</a>( dirlist, QSplitter::KeepSize );
|
---|
| 1209 |
|
---|
| 1210 | fileview = new QtFileIconView( "/", splitter );
|
---|
| 1211 | <a name="x884"></a> fileview-><a href="qiconview.html#setSelectionMode">setSelectionMode</a>( QIconView::Extended );
|
---|
| 1212 |
|
---|
| 1213 | <a href="qmainwindow.html#setCentralWidget">setCentralWidget</a>( splitter );
|
---|
| 1214 |
|
---|
| 1215 | <a href="qtoolbar.html">QToolBar</a> *toolbar = new <a href="qtoolbar.html">QToolBar</a>( this, "toolbar" );
|
---|
| 1216 | <a href="qmainwindow.html#setRightJustification">setRightJustification</a>( TRUE );
|
---|
| 1217 |
|
---|
| 1218 | (void)new <a href="qlabel.html">QLabel</a>( <a href="qobject.html#tr">tr</a>( " Path: " ), toolbar );
|
---|
| 1219 |
|
---|
| 1220 | pathCombo = new <a href="qcombobox.html">QComboBox</a>( TRUE, toolbar );
|
---|
| 1221 | <a name="x880"></a> pathCombo-><a href="qcombobox.html#setAutoCompletion">setAutoCompletion</a>( TRUE );
|
---|
| 1222 | <a name="x896"></a> toolbar-><a href="qtoolbar.html#setStretchableWidget">setStretchableWidget</a>( pathCombo );
|
---|
| 1223 | <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> & ) ),
|
---|
| 1224 | this, SLOT ( changePath( const <a href="qstring.html">QString</a> & ) ) );
|
---|
| 1225 |
|
---|
| 1226 | <a name="x895"></a> toolbar-><a href="qtoolbar.html#addSeparator">addSeparator</a>();
|
---|
| 1227 |
|
---|
| 1228 | <a href="qpixmap.html">QPixmap</a> pix;
|
---|
| 1229 |
|
---|
| 1230 | pix = QPixmap( cdtoparent_xpm );
|
---|
| 1231 | upButton = new <a href="qtoolbutton.html">QToolButton</a>( pix, "One directory up", <a href="qstring.html#QString-null">QString::null</a>,
|
---|
| 1232 | this, SLOT( cdUp() ), toolbar, "cd up" );
|
---|
| 1233 |
|
---|
| 1234 | pix = QPixmap( newfolder_xpm );
|
---|
| 1235 | mkdirButton = new <a href="qtoolbutton.html">QToolButton</a>( pix, "New Folder", QString::null,
|
---|
| 1236 | this, SLOT( newFolder() ), toolbar, "new folder" );
|
---|
| 1237 |
|
---|
| 1238 | <a href="qobject.html#connect">connect</a>( dirlist, SIGNAL( folderSelected( const <a href="qstring.html">QString</a> & ) ),
|
---|
| 1239 | fileview, SLOT ( setDirectory( const <a href="qstring.html">QString</a> & ) ) );
|
---|
| 1240 | <a href="qobject.html#connect">connect</a>( fileview, SIGNAL( directoryChanged( const <a href="qstring.html">QString</a> & ) ),
|
---|
| 1241 | this, SLOT( directoryChanged( const <a href="qstring.html">QString</a> & ) ) );
|
---|
| 1242 | <a href="qobject.html#connect">connect</a>( fileview, SIGNAL( startReadDir( int ) ),
|
---|
| 1243 | this, SLOT( slotStartReadDir( int ) ) );
|
---|
| 1244 | <a href="qobject.html#connect">connect</a>( fileview, SIGNAL( readNextDir() ),
|
---|
| 1245 | this, SLOT( slotReadNextDir() ) );
|
---|
| 1246 | <a href="qobject.html#connect">connect</a>( fileview, SIGNAL( readDirDone() ),
|
---|
| 1247 | this, SLOT( slotReadDirDone() ) );
|
---|
| 1248 |
|
---|
| 1249 | <a href="qmainwindow.html#setDockEnabled">setDockEnabled</a>( DockLeft, FALSE );
|
---|
| 1250 | <a href="qmainwindow.html#setDockEnabled">setDockEnabled</a>( DockRight, FALSE );
|
---|
| 1251 |
|
---|
| 1252 | label = new <a href="qlabel.html">QLabel</a>( <a href="qmainwindow.html#statusBar">statusBar</a>() );
|
---|
| 1253 | <a href="qmainwindow.html#statusBar">statusBar</a>()->addWidget( label, 2, TRUE );
|
---|
| 1254 | progress = new <a href="qprogressbar.html">QProgressBar</a>( <a href="qmainwindow.html#statusBar">statusBar</a>() );
|
---|
| 1255 | <a href="qmainwindow.html#statusBar">statusBar</a>()->addWidget( progress, 1, TRUE );
|
---|
| 1256 |
|
---|
| 1257 | <a href="qobject.html#connect">connect</a>( fileview, SIGNAL( enableUp() ),
|
---|
| 1258 | this, SLOT( enableUp() ) );
|
---|
| 1259 | <a href="qobject.html#connect">connect</a>( fileview, SIGNAL( disableUp() ),
|
---|
| 1260 | this, SLOT( disableUp() ) );
|
---|
| 1261 | <a href="qobject.html#connect">connect</a>( fileview, SIGNAL( enableMkdir() ),
|
---|
| 1262 | this, SLOT( enableMkdir() ) );
|
---|
| 1263 | <a href="qobject.html#connect">connect</a>( fileview, SIGNAL( disableMkdir() ),
|
---|
| 1264 | this, SLOT( disableMkdir() ) );
|
---|
| 1265 | }
|
---|
| 1266 |
|
---|
| 1267 | void <a name="f326"></a>FileMainWindow::setPathCombo()
|
---|
| 1268 | {
|
---|
| 1269 | <a href="qstring.html">QString</a> dir = <a href="qwidget.html#caption">caption</a>();
|
---|
| 1270 | int i = 0;
|
---|
| 1271 | bool found = FALSE;
|
---|
| 1272 | <a name="x878"></a> for ( i = 0; i < pathCombo-><a href="qcombobox.html#count">count</a>(); ++i ) {
|
---|
| 1273 | <a name="x882"></a> if ( pathCombo-><a href="qcombobox.html#text">text</a>( i ) == dir) {
|
---|
| 1274 | found = TRUE;
|
---|
| 1275 | break;
|
---|
| 1276 | }
|
---|
| 1277 | }
|
---|
| 1278 |
|
---|
| 1279 | if ( found )
|
---|
| 1280 | <a name="x881"></a> pathCombo-><a href="qcombobox.html#setCurrentItem">setCurrentItem</a>( i );
|
---|
| 1281 | else {
|
---|
| 1282 | <a name="x879"></a> pathCombo-><a href="qcombobox.html#insertItem">insertItem</a>( dir );
|
---|
| 1283 | pathCombo-><a href="qcombobox.html#setCurrentItem">setCurrentItem</a>( pathCombo-><a href="qcombobox.html#count">count</a>() - 1 );
|
---|
| 1284 | }
|
---|
| 1285 |
|
---|
| 1286 | }
|
---|
| 1287 |
|
---|
| 1288 | void <a name="f327"></a>FileMainWindow::directoryChanged( const <a href="qstring.html">QString</a> &dir )
|
---|
| 1289 | {
|
---|
| 1290 | <a href="qwidget.html#setCaption">setCaption</a>( dir );
|
---|
| 1291 | setPathCombo();
|
---|
| 1292 | }
|
---|
| 1293 |
|
---|
| 1294 | void <a name="f328"></a>FileMainWindow::slotStartReadDir( int dirs )
|
---|
| 1295 | {
|
---|
| 1296 | label-><a href="qlabel.html#setText">setText</a>( <a href="qobject.html#tr">tr</a>( " Reading Directory..." ) );
|
---|
| 1297 | <a name="x890"></a> progress-><a href="qprogressbar.html#reset">reset</a>();
|
---|
| 1298 | <a name="x892"></a> progress-><a href="qprogressbar.html#setTotalSteps">setTotalSteps</a>( dirs );
|
---|
| 1299 | }
|
---|
| 1300 |
|
---|
| 1301 | void <a name="f329"></a>FileMainWindow::slotReadNextDir()
|
---|
| 1302 | {
|
---|
| 1303 | <a name="x889"></a> int p = progress-><a href="qprogressbar.html#progress">progress</a>();
|
---|
| 1304 | <a name="x891"></a> progress-><a href="qprogressbar.html#setProgress">setProgress</a>( ++p );
|
---|
| 1305 | }
|
---|
| 1306 |
|
---|
| 1307 | void <a name="f330"></a>FileMainWindow::slotReadDirDone()
|
---|
| 1308 | {
|
---|
| 1309 | label-><a href="qlabel.html#setText">setText</a>( <a href="qobject.html#tr">tr</a>( " Reading Directory Done." ) );
|
---|
| 1310 | <a name="x893"></a> progress-><a href="qprogressbar.html#setProgress">setProgress</a>( progress-><a href="qprogressbar.html#totalSteps">totalSteps</a>() );
|
---|
| 1311 | }
|
---|
| 1312 |
|
---|
| 1313 | void <a name="f331"></a>FileMainWindow::cdUp()
|
---|
| 1314 | {
|
---|
| 1315 | <a href="qdir.html">QDir</a> dir = fileview->currentDir();
|
---|
| 1316 | <a name="x883"></a> dir.<a href="qdir.html#cd">cd</a>( ".." );
|
---|
| 1317 | fileview->setDirectory( dir );
|
---|
| 1318 | }
|
---|
| 1319 |
|
---|
| 1320 | void <a name="f332"></a>FileMainWindow::newFolder()
|
---|
| 1321 | {
|
---|
| 1322 | fileview->newDirectory();
|
---|
| 1323 | }
|
---|
| 1324 |
|
---|
| 1325 | void <a name="f333"></a>FileMainWindow::changePath( const <a href="qstring.html">QString</a> &path )
|
---|
| 1326 | {
|
---|
| 1327 | if ( QFileInfo( path ).exists() )
|
---|
| 1328 | fileview->setDirectory( path );
|
---|
| 1329 | else
|
---|
| 1330 | setPathCombo();
|
---|
| 1331 | }
|
---|
| 1332 |
|
---|
| 1333 | void <a name="f334"></a>FileMainWindow::enableUp()
|
---|
| 1334 | {
|
---|
| 1335 | <a name="x897"></a> upButton-><a href="qwidget.html#setEnabled">setEnabled</a>( TRUE );
|
---|
| 1336 | }
|
---|
| 1337 |
|
---|
| 1338 | void <a name="f335"></a>FileMainWindow::disableUp()
|
---|
| 1339 | {
|
---|
| 1340 | upButton-><a href="qwidget.html#setEnabled">setEnabled</a>( FALSE );
|
---|
| 1341 | }
|
---|
| 1342 |
|
---|
| 1343 | void <a name="f336"></a>FileMainWindow::enableMkdir()
|
---|
| 1344 | {
|
---|
| 1345 | mkdirButton-><a href="qwidget.html#setEnabled">setEnabled</a>( TRUE );
|
---|
| 1346 | }
|
---|
| 1347 |
|
---|
| 1348 | void <a name="f337"></a>FileMainWindow::disableMkdir()
|
---|
| 1349 | {
|
---|
| 1350 | mkdirButton-><a href="qwidget.html#setEnabled">setEnabled</a>( FALSE );
|
---|
| 1351 | }
|
---|
| 1352 | </pre>
|
---|
| 1353 |
|
---|
| 1354 | <p> <hr>
|
---|
| 1355 | <p> Main:
|
---|
| 1356 | <p> <pre>/****************************************************************************
|
---|
| 1357 | ** $Id: fileiconview-example.html 2051 2007-02-21 10:04:20Z chehrlic $
|
---|
| 1358 | **
|
---|
| 1359 | ** Copyright (C) 1992-2007 Trolltech ASA. All rights reserved.
|
---|
| 1360 | **
|
---|
| 1361 | ** This file is part of an example program for Qt. This example
|
---|
| 1362 | ** program may be used, distributed and modified without limitation.
|
---|
| 1363 | **
|
---|
| 1364 | *****************************************************************************/
|
---|
| 1365 |
|
---|
| 1366 | #include "mainwindow.h"
|
---|
| 1367 | #include "qfileiconview.h"
|
---|
| 1368 |
|
---|
| 1369 | #include <<a href="qapplication-h.html">qapplication.h</a>>
|
---|
| 1370 |
|
---|
| 1371 |
|
---|
| 1372 | int main( int argc, char **argv )
|
---|
| 1373 | {
|
---|
| 1374 | <a href="qapplication.html">QApplication</a> a( argc, argv );
|
---|
| 1375 |
|
---|
| 1376 | FileMainWindow mw;
|
---|
| 1377 | mw.<a href="qwidget.html#resize">resize</a>( 680, 480 );
|
---|
| 1378 | a.<a href="qapplication.html#setMainWidget">setMainWidget</a>( &mw );
|
---|
| 1379 | mw.fileView()->setDirectory( "/" );
|
---|
| 1380 | <a name="x900"></a> mw.<a href="qwidget.html#show">show</a>();
|
---|
| 1381 | return a.<a href="qapplication.html#exec">exec</a>();
|
---|
| 1382 | }
|
---|
| 1383 | </pre>
|
---|
| 1384 |
|
---|
| 1385 | <p>See also <a href="examples.html">Examples</a>.
|
---|
| 1386 |
|
---|
| 1387 | <!-- eof -->
|
---|
| 1388 | <p><address><hr><div align=center>
|
---|
| 1389 | <table width=100% cellspacing=0 border=0><tr>
|
---|
| 1390 | <td>Copyright © 2007
|
---|
| 1391 | <a href="troll.html">Trolltech</a><td align=center><a href="trademarks.html">Trademarks</a>
|
---|
| 1392 | <td align=right><div align=right>Qt 3.3.8</div>
|
---|
| 1393 | </table></div></address></body>
|
---|
| 1394 | </html>
|
---|