📄 fileiconview-main-cpp.html
字号:
for ( ; item; item = (QtFileIconViewItem*)item-><a href="qiconviewitem.html#005b99">nextItem</a>() ) item->viewModeChanged( vm ); <a href="qiconview.html#9fb7be">arrangeItemsInGrid</a>();}</pre> <hr> Header file of the mainwindow: <pre>/****************************************************************************** $Id: qt/examples/fileiconview/mainwindow.h 2.3.8 edited 2004-05-12 $**** Copyright (C) 1992-2000 Trolltech AS. All rights reserved.**** This file is part of an example program for Qt. This example** program may be used, distributed and modified without limitation.*******************************************************************************/#ifndef MAINWIN_H#define MAINWIN_H#include <<a href="qmainwindow-h.html">qmainwindow.h</a>>class QtFileIconView;class DirectoryView;class QProgressBar;class QLabel;class QComboBox;class QToolButton;class FileMainWindow : public QMainWindow{ Q_OBJECTpublic: 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 QString & ); void slotStartReadDir( int dirs ); void slotReadNextDir(); void slotReadDirDone(); void cdUp(); void newFolder(); void changePath( const QString &path ); void enableUp(); void disableUp(); void enableMkdir(); void disableMkdir();};#endif</pre> <hr> Implementation of the mainwindow: <pre>/****************************************************************************** $Id: qt/examples/fileiconview/mainwindow.cpp 2.3.8 edited 2004-05-12 $**** Copyright (C) 1992-2000 Trolltech AS. All rights reserved.**** This file is part of an example program for Qt. This example** program may be used, distributed and modified without limitation.*******************************************************************************/#include "mainwindow.h"#include "qfileiconview.h"#include "../dirview/dirview.h"#include <<a href="qsplitter-h.html">qsplitter.h</a>>#include <<a href="qprogressbar-h.html">qprogressbar.h</a>>#include <<a href="qlabel-h.html">qlabel.h</a>>#include <<a href="qstatusbar-h.html">qstatusbar.h</a>>#include <<a href="qtoolbar-h.html">qtoolbar.h</a>>#include <<a href="qcombobox-h.html">qcombobox.h</a>>#include <<a href="qpixmap-h.html">qpixmap.h</a>>#include <<a href="qtoolbutton-h.html">qtoolbutton.h</a>>#include <<a href="qdir-h.html">qdir.h</a>>#include <<a href="qfileinfo-h.html">qfileinfo.h</a>>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", " . ", " ", " . ", " . . ", " .... . . . ", " .+@+@. . . ", ".......... . .", ".@+@+@+@+@.. ", ".+@+@+@+@+. . ", ".@+@+@+@+@. . ", ".+@+@+@+@+. ", ".@+@+@+@+@. ", ".+@+@+@+@+. ", "........... "};FileMainWindow::FileMainWindow() : <a href="qmainwindow.html">QMainWindow</a>(){ <a href=#207>setup</a>();}void <a name="206"></a>FileMainWindow::show(){ <a href="qmainwindow.html#eb53e3">QMainWindow::show</a>();}void <a name="207"></a>FileMainWindow::setup(){ <a href="qsplitter.html">QSplitter</a> *splitter = new <a href="qsplitter.html">QSplitter</a>( this ); dirlist = new DirectoryView( splitter, "dirlist", TRUE ); dirlist->addColumn( "Name" ); dirlist->addColumn( "Type" ); Directory *root = new Directory( dirlist, "/" ); root-><a href="qlistviewitem.html#1c5a28">setOpen</a>( TRUE ); splitter-><a href="qsplitter.html#33bf83">setResizeMode</a>( dirlist, QSplitter::KeepSize ); fileview = new QtFileIconView( "/", splitter ); fileview->setSelectionMode( QIconView::Extended ); <a href="qmainwindow.html#fce9ba">setCentralWidget</a>( splitter ); <a href="qtoolbar.html">QToolBar</a> *toolbar = new <a href="qtoolbar.html">QToolBar</a>( this, "toolbar" ); <a href="qmainwindow.html#edcb2d">setRightJustification</a>( TRUE ); (void)new <a href="qlabel.html">QLabel</a>( <a href="qobject.html#2418a9">tr</a>( " Path: " ), toolbar ); pathCombo = new <a href="qcombobox.html">QComboBox</a>( TRUE, toolbar ); pathCombo->setAutoCompletion( TRUE ); toolbar-><a href="qtoolbar.html#7b948e">setStretchableWidget</a>( pathCombo ); <a href="qobject.html#fbde73">connect</a>( pathCombo, SIGNAL( activated( const QString & ) ), this, SLOT ( <a href=#215>changePath</a>( const QString & ) ) ); toolbar-><a href="qtoolbar.html#af219d">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", QString::null, this, SLOT( <a href=#213>cdUp</a>() ), toolbar, "cd up" ); pix = QPixmap( newfolder_xpm ); mkdirButton = new <a href="qtoolbutton.html">QToolButton</a>( pix, "New Folder", QString::null, this, SLOT( <a href=#214>newFolder</a>() ), toolbar, "new folder" ); <a href="qobject.html#fbde73">connect</a>( dirlist, SIGNAL( folderSelected( const QString & ) ), fileview, SLOT ( setDirectory( const QString & ) ) ); <a href="qobject.html#fbde73">connect</a>( fileview, SIGNAL( <a href=#209>directoryChanged</a>( const QString & ) ), this, SLOT( <a href=#209>directoryChanged</a>( const QString & ) ) ); <a href="qobject.html#fbde73">connect</a>( fileview, SIGNAL( startReadDir( int ) ), this, SLOT( <a href=#210>slotStartReadDir</a>( int ) ) ); <a href="qobject.html#fbde73">connect</a>( fileview, SIGNAL( readNextDir() ), this, SLOT( <a href=#211>slotReadNextDir</a>() ) ); <a href="qobject.html#fbde73">connect</a>( fileview, SIGNAL( readDirDone() ), this, SLOT( <a href=#212>slotReadDirDone</a>() ) ); <a href="qmainwindow.html#712cb8">setDockEnabled</a>( Left, FALSE ); <a href="qmainwindow.html#712cb8">setDockEnabled</a>( Right, FALSE ); label = new <a href="qlabel.html">QLabel</a>( <a href="qmainwindow.html#530937">statusBar</a>() ); <a href="qmainwindow.html#530937">statusBar</a>()->addWidget( label, 2, TRUE ); progress = new <a href="qprogressbar.html">QProgressBar</a>( <a href="qmainwindow.html#530937">statusBar</a>() ); <a href="qmainwindow.html#530937">statusBar</a>()->addWidget( progress, 1, TRUE ); <a href="qobject.html#fbde73">connect</a>( fileview, SIGNAL( <a href=#216>enableUp</a>() ), this, SLOT( <a href=#216>enableUp</a>() ) ); <a href="qobject.html#fbde73">connect</a>( fileview, SIGNAL( <a href=#217>disableUp</a>() ), this, SLOT( <a href=#217>disableUp</a>() ) ); <a href="qobject.html#fbde73">connect</a>( fileview, SIGNAL( <a href=#218>enableMkdir</a>() ), this, SLOT( <a href=#218>enableMkdir</a>() ) ); <a href="qobject.html#fbde73">connect</a>( fileview, SIGNAL( <a href=#219>disableMkdir</a>() ), this, SLOT( <a href=#219>disableMkdir</a>() ) );}void <a name="208"></a>FileMainWindow::setPathCombo(){ <a href="qstring.html">QString</a> dir = caption(); int i = 0; bool found = FALSE; for ( i = 0; i < pathCombo->count(); ++i ) { if ( pathCombo->text( i ) == dir) { found = TRUE; break; } } if ( found ) pathCombo->setCurrentItem( i ); else { pathCombo->insertItem( dir ); pathCombo->setCurrentItem( pathCombo->count() - 1 ); }}void <a name="209"></a>FileMainWindow::directoryChanged( const QString &dir ){ <a href="qwidget.html#d6a291">setCaption</a>( dir ); <a href=#208>setPathCombo</a>();}void <a name="210"></a>FileMainWindow::slotStartReadDir( int dirs ){ label->setText( <a href="qobject.html#2418a9">tr</a>( " Reading Directory..." ) ); progress->reset(); progress->setTotalSteps( dirs );}void <a name="211"></a>FileMainWindow::slotReadNextDir(){ int p = progress->progress(); progress->setProgress( ++p );}void <a name="212"></a>FileMainWindow::slotReadDirDone(){ label->setText( <a href="qobject.html#2418a9">tr</a>( " Reading Directory Done." ) ); progress->setProgress( progress->totalSteps() );}void <a name="213"></a>FileMainWindow::cdUp(){ <a href="qdir.html">QDir</a> dir = fileview->currentDir(); dir.<a href="qdir.html#f0fc10">cd</a>( ".." ); fileview->setDirectory( dir );}void <a name="214"></a>FileMainWindow::newFolder(){ fileview->newDirectory();}void <a name="215"></a>FileMainWindow::changePath( const QString &path ){ if ( <a href="qfileinfo.html">QFileInfo</a>( path ).exists() ) fileview->setDirectory( path ); else <a href=#208>setPathCombo</a>();}void <a name="216"></a>FileMainWindow::enableUp(){ upButton->setEnabled( TRUE );}void <a name="217"></a>FileMainWindow::disableUp(){ upButton->setEnabled( FALSE );}void <a name="218"></a>FileMainWindow::enableMkdir(){ mkdirButton->setEnabled( TRUE );}void <a name="219"></a>FileMainWindow::disableMkdir(){ mkdirButton->setEnabled( FALSE );}</pre> <hr> Main:<pre>/****************************************************************************** $Id: qt/examples/fileiconview/main.cpp 2.3.8 edited 2004-05-12 $**** Copyright (C) 1992-2000 Trolltech AS. All rights reserved.**** This file is part of an example program for Qt. This example** program may be used, distributed and modified without limitation.*******************************************************************************/#include "mainwindow.h"#include "qfileiconview.h"#include <<a name="qapplication.h"></a><a href="qapplication-h.html">qapplication.h</a>>int main( int argc, char **argv ){ <a name="QApplication"></a><a href="qapplication.html">QApplication</a> a( argc, argv ); FileMainWindow mw; mw.<a name="resize"></a><a href="qwidget.html#ff9d07">resize</a>( 680, 480 ); a.<a name="setMainWidget"></a><a href="qapplication.html#7ad759">setMainWidget</a>( &mw ); mw.fileView()->setDirectory( "/" ); mw.<a name="show"></a><a href="qmainwindow.html#eb53e3">show</a>(); return a.<a name="exec"></a><a href="qapplication.html#84c7bf">exec</a>();}</pre><p><address><hr><div align="center"><table width="100%" cellspacing="0" border="0"><tr><td>Copyright
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -