📄 qfileiconview.cpp.bak
字号:
void QtFileIconView::slotPaste( const QString &dir ){ if ( !cpyCutList.count() ) return; int i, err; QString commd, dest, basename, cd = dir; if(cd == "/") cd = ""; for ( QStringList::Iterator it = cpyCutList.begin(); it != cpyCutList.end(); ++it ) { basename = (*it).mid((*it).findRev("/") + 1, (*it).length()); dest = cd + "/" + basename; if( QFile( dest ).exists() ){ i = 1; dest = cd + "/Copy of " + basename; while( QFile( dest ).exists() ){ dest.sprintf( "%s/Copy (%d) of %s", (const char *) cd, i++, (const char *) basename ); } }// if( QFileInfo( (*it) ).isDir() ){ if ( cpyCutFlag ) commd = "/bin/mv \"" + (*it) +"\" " + "\"" + dest + "\"" + "&"; else commd = "/bin/cp -fpR \"" + (*it) +"\" " + "\"" + dest + "\"" + "&"; err = system( (const char *) commd );// QMessageBox::information( this, "Paste Emu", commd, "ok" );/* } else if( !copyFile( dest, (*it) ) ){ err = -1; } else { err = 0; }*/ if ( err != 0 ) { QMessageBox::warning( this, tr("Paste file"), tr("Paste failed!"), tr("OK") ); break; } } readDir( currentDir().absPath() ); emit resetListDir( currentDir().absPath() ); // QIconViewItem *i2 = firstItem(); basename = dest.mid( dest.findRev("/") + 1, dest.length() );/* while( i2 ){ if( i2->text() == basename ){ i2->setSelected( TRUE, TRUE ); ensureItemVisible( i2 ); break; } i2 = i2->nextItem(); }*/ if ( cpyCutFlag ) { cpyCutList.clear(); emit disablePaste(); } cpyCutFlag = 0;}void QtFileIconView::slotCut(){ cpyCutFlag = 1; slotPreCpyCut();}void QtFileIconView::slotDel(){ QString commd; int er; QDir d = currentDir(); QStringList fl; QIconViewItem *item = firstItem(); while ( item != 0 ) { if( item->isSelected() && item->text() != ".." && item->text() != "." ) fl += d.absPath() + "/" + item->text(); item = item->nextItem(); } if( fl.count() < 1 ) { return; } if( QMessageBox::warning( this, tr("Delete"), tr("Are you sure?"), tr("Yes"), tr("No") ) == 0) { for ( QStringList::Iterator it = fl.begin(); it != fl.end(); ++it ) { commd = "/bin/rm -rf \"" + (*it) + "\""; er = system( (const char *) commd ); if ( er != 0 ) { QMessageBox::warning( this, tr("Delete"), tr("Delete failed!"), tr("OK") ); break; }// QMessageBox::information( this, "Del Emu" , ( *it ), "ok" ); } readDir( d ); emit resetListDir( d.absPath() ); }}/***************************************************************************** * * Class QtFileIconView * *****************************************************************************/QtFileIconView::QtFileIconView( const QString &dir, QWidget *parent, const char *name ) : QIconView( parent, name ), viewDir( dir ), newFolderNum( 0 ){ if ( !iconFolderLockedLarge ) { qAddPostRoutine( cleanup ); QWMatrix m; m.scale( 0.65, 0.65 ); QPixmap iconpix( folder_locked_icon ); iconFolderLockedLarge = new QPixmap( folder_locked_icon ); iconpix = iconpix.xForm( m ); iconFolderLockedSmall = new QPixmap( iconpix ); iconpix = QPixmap( folder_icon ); iconFolderLarge = new QPixmap( folder_icon ); iconpix = iconpix.xForm( m ); iconFolderSmall = new QPixmap( iconpix ); iconpix = QPixmap( file_icon ); iconFileLarge = new QPixmap( file_icon ); iconpix = iconpix.xForm( m ); iconFileSmall = new QPixmap( iconpix ); iconpix = QPixmap( link_icon ); iconLinkLarge = new QPixmap( link_icon ); iconpix = iconpix.xForm( m ); iconLinkSmall = new QPixmap( iconpix ); } vm = Small; setGridX( 65 );// setResizeMode( Adjust ); setWordWrapIconText( FALSE ); setSelectionMode( Multi ); connect( this, SIGNAL( doubleClicked( QIconViewItem * ) ), this, SLOT( itemDoubleClicked( QIconViewItem * ) ) ); connect( this, SIGNAL( returnPressed( QIconViewItem * ) ), this, SLOT( itemDoubleClicked( QIconViewItem * ) ) ); connect( this, SIGNAL( dropped( QDropEvent *, const QValueList<QIconDragItem> & ) ), this, SLOT( slotDropped( QDropEvent *, const QValueList<QIconDragItem> & ) ) ); connect( this, SIGNAL( rightButtonClicked( QIconViewItem *, const QPoint & ) ), this, SLOT( slotRightPressed( QIconViewItem * ) ) ); setHScrollBarMode( AlwaysOff ); setVScrollBarMode( Auto ); setAutoArrange( TRUE ); setSorting( true, true ); openItem = 0;}void QtFileIconView::openFolder(){ if ( !openItem ) return; if ( openItem->type() != QtFileIconViewItem::Dir || openItem->type() == QtFileIconViewItem::Dir && !QDir( openItem->itemFileName ).isReadable() ) return; openItem->timer.stop(); setDirectory( openItem->itemFileName );}void QtFileIconView::setDirectory( const QString &dir ){ viewDir = QDir( dir ); readDir( viewDir );}void QtFileIconView::setDirectory( const QDir &dir ){ viewDir = dir; readDir( viewDir );}void QtFileIconView::newDirectory(){ setAutoArrange( FALSE ); selectAll( FALSE ); if ( viewDir.mkdir( QString( "New Folder %1" ).arg( ++newFolderNum ) ) ) { QFileInfo *fi = new QFileInfo( viewDir, QString( "New Folder %1" ).arg( newFolderNum ) ); QtFileIconViewItem *item = new QtFileIconViewItem( this, new QFileInfo( *fi ) ); item->setKey( QString( "000000%1" ).arg( fi->fileName() ) ); sort(); emit resetListDir( fi->dirPath( 1 ) ); delete fi; repaintContents( contentsX(), contentsY(), contentsWidth(), contentsHeight(), FALSE ); ensureItemVisible( item ); item->setSelected( TRUE, TRUE ); setCurrentItem( item ); repaintItem( item ); qApp->processEvents(); item->rename(); } setAutoArrange( TRUE );}QDir QtFileIconView::currentDir(){ return viewDir;}static bool isRoot( const QString &s ){#if defined(Q_OS_UNIX) if ( s == "/" ) return TRUE;#elif defined(Q_OS_WIN32) QString p = s; if ( p.length() == 3 && p.right( 2 ) == ":/" ) return TRUE; if ( p[ 0 ] == '/' && p[ 1 ] == '/' ) { int slashes = p.contains( '/' ); if ( slashes <= 3 ) return TRUE; if ( slashes == 4 && p[ (int)p.length() - 1 ] == '/' ) return TRUE; }#endif return FALSE;}void QtFileIconView::readDir( const QDir &dir ){ if ( !dir.isReadable() ) return; if ( isRoot( dir.absPath() ) ) emit disableUp(); else emit enableUp(); if( !cpyCutList.count() ) emit disablePaste(); else emit enablePaste(); clear(); emit directoryChanged( dir.absPath() ); const QFileInfoList *filist = dir.entryInfoList( QDir::DefaultFilter, QDir::DirsFirst | QDir::Name ); emit startReadDir( filist->count() ); QFileInfoListIterator it( *filist ); QFileInfo *fi; bool allowRename = FALSE, allowRenameSet = FALSE; while ( ( fi = it.current() ) != 0 ) { ++it; if ( fi && fi->fileName() == ".." && ( fi->dirPath() == "/" || fi->dirPath().isEmpty() ) ) continue; emit readNextDir(); QtFileIconViewItem *item = new QtFileIconViewItem( this, new QFileInfo( *fi ) ); if ( fi->isDir() ) item->setKey( QString( "000000%1" ).arg( fi->fileName() ) ); else item->setKey( fi->fileName() ); if ( !allowRenameSet ) { if ( !QFileInfo( fi->absFilePath() ).isWritable() || item->text() == "." || item->text() == ".." ) allowRename = FALSE; else allowRename = TRUE; if ( item->text() == "." || item->text() == ".." ) allowRenameSet = FALSE; else allowRenameSet = TRUE; } item->setRenameEnabled( allowRename ); } if ( !QFileInfo( dir.absPath() ).isWritable() ) emit disableMkdir(); else emit enableMkdir(); emit readDirDone();}void QtFileIconView::itemDoubleClicked( QIconViewItem *i ){ QtFileIconViewItem *item = ( QtFileIconViewItem* )i; if ( item->type() == QtFileIconViewItem::Dir ) { viewDir = QDir( item->filename() ); readDir( viewDir ); } else if ( item->type() == QtFileIconViewItem::Link && QFileInfo( QFileInfo( item->filename() ).readLink() ).isDir() ) { viewDir = QDir( QFileInfo( item->filename() ).readLink() ); readDir( viewDir ); }}QDragObject *QtFileIconView::dragObject(){ if ( !currentItem() ) return 0; QPoint orig = viewportToContents( viewport()->mapFromGlobal( QCursor::pos() ) ); QtFileIconDrag *drag = new QtFileIconDrag( viewport() ); drag->setPixmap( *currentItem()->pixmap(), QPoint( currentItem()->pixmapRect().width() / 2, currentItem()->pixmapRect().height() / 2 ) ); for ( QtFileIconViewItem *item = (QtFileIconViewItem*)firstItem(); item; item = (QtFileIconViewItem*)item->nextItem() ) { if ( item->isSelected() ) { QIconDragItem id; id.setData( QCString( item->filename() ) ); drag->append( id, QRect( item->pixmapRect( FALSE ).x() - orig.x(), item->pixmapRect( FALSE ).y() - orig.y(), item->pixmapRect().width(), item->pixmapRect().height() ), QRect( item->textRect( FALSE ).x() - orig.x(), item->textRect( FALSE ).y() - orig.y(), item->textRect().width(), item->textRect().height() ), QString( item->filename() ) ); } } return drag;}void QtFileIconView::keyPressEvent( QKeyEvent *e ){ switch ( e->key() ) { case Key_Escape: clearSelection(); break; case Key_5: slotRightPressed( currentItem() ); default: QIconView::keyPressEvent( e ); break; }}void QtFileIconView::slotDropped( QDropEvent *e, const QValueList<QIconDragItem> & ){ if ( openItem ) openItem->timer.stop(); if ( !QUriDrag::canDecode( e ) ) { e->ignore(); return; }// QStringList lst; QUriDrag::decodeLocalFiles( e, cpyCutList ); QString str; if ( e->action() == QDropEvent::Copy ) slotCopy(); else slotCut(); slotPaste( viewDir.absPath() );/* QMessageBox::information( this, e->action() == QDropEvent::Copy ? "Copy" : "Move" , str, "Not Implemented" ); if ( e->action() == QDropEvent::Move ) QMessageBox::information( this, "Remove" , QDir::convertSeparators(lst.join("\n")), "Not Implemented" );*/ e->acceptAction(); openItem = 0;}void QtFileIconView::viewLarge(){ setViewMode( Large );}void QtFileIconView::viewSmall(){ setViewMode( Small );}void QtFileIconView::viewBottom(){ setItemTextPos( Bottom );}void QtFileIconView::viewRight(){ setItemTextPos( Right );}void QtFileIconView::flowEast(){ setHScrollBarMode( AlwaysOff ); setVScrollBarMode( Auto ); setArrangement( LeftToRight );}void QtFileIconView::flowSouth(){ setVScrollBarMode( AlwaysOff ); setHScrollBarMode( Auto ); setArrangement( TopToBottom );}void QtFileIconView::sortAscending(){ sort( TRUE );}void QtFileIconView::sortDescending(){ sort( FALSE );}void QtFileIconView::itemTextTruncate(){ setWordWrapIconText( FALSE );}void QtFileIconView::itemTextWordWrap(){ setWordWrapIconText( TRUE );}void QtFileIconView::slotRightPressed( QIconViewItem *item ){ if ( !item || !item->isSelected () ) { // right pressed on viewport QPopupMenu menu( this ); menu.insertItem( "&Large view", this, SLOT( viewLarge() ) ); menu.insertItem( "&Small view", this, SLOT( viewSmall() ) ); menu.insertSeparator(); menu.insertItem( "Text at the &bottom", this, SLOT( viewBottom() ) ); menu.insertItem( "Text at the &right", this, SLOT( viewRight() ) ); menu.insertSeparator(); menu.insertItem( "Arrange l&eft to right", this, SLOT( flowEast() ) ); menu.insertItem( "Arrange t&op to bottom", this, SLOT( flowSouth() ) ); menu.insertSeparator(); menu.insertItem( "&Truncate item text", this, SLOT( itemTextTruncate() ) ); menu.insertItem( "&Wordwrap item text", this, SLOT( itemTextWordWrap() ) ); menu.insertSeparator(); menu.insertItem( "Arrange items in &grid", this, SLOT( arrangeItemsInGrid() ) ); menu.insertSeparator(); menu.insertItem( "Sort &ascending", this, SLOT( sortAscending() ) ); menu.insertItem( "Sort &descending", this, SLOT( sortDescending() ) ); menu.setMouseTracking( TRUE ); menu.exec( QCursor::pos() ); } else if ( item->text() != "." && item->text() != ".." ) { // on valid item QPopupMenu menu( this ); int RENAME_ITEM = menu.insertItem( "Rename Item" ); int PASTE_ITEM = 0; menu.insertItem( "Remove Item(s)", this, SLOT( slotDel() ) ); menu.insertItem( "Copy Item(s)", this, SLOT( slotCopy() ) ); menu.insertItem( "Cut Item(s)", this, SLOT( slotCut() ) ); if( cpyCutList.count() ) PASTE_ITEM = menu.insertItem( "Paste in here" ); menu.setMouseTracking( TRUE ); int id = menu.exec( QCursor::pos() ); if ( id == -1 ) return; if ( id == RENAME_ITEM && item->renameEnabled() ) { item->rename(); } else if ( id == PASTE_ITEM ) { QString str = currentDir().absPath() + "/" + item->text(); slotPaste( str ); } }}void QtFileIconView::setViewMode( ViewMode m ){ if ( m == vm ) return; vm = m; QtFileIconViewItem *item = (QtFileIconViewItem*)firstItem(); for ( ; item; item = (QtFileIconViewItem*)item->nextItem() ) item->viewModeChanged( vm ); arrangeItemsInGrid();}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -