⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 krdetailedview.cpp

📁 LINUX 下, 以 QT/KDE 写的档案管理员
💻 CPP
📖 第 1 页 / 共 4 页
字号:
/***************************************************************************                  krdetailedview.cpp                 -------------------copyright            : (C) 2000-2002 by Shie Erlich & Rafi Yanaie-mail               : krusader@users.sourceforge.netweb site             : http://krusader.sourceforge.net---------------------------------------------------------------------------Description***************************************************************************Adb   dD d8888b. db    db .d8888.  .d8b.  d8888b. d88888b d8888b.88 ,8P' 88  `8D 88    88 88'  YP d8' `8b 88  `8D 88'     88  `8D88,8P   88oobY' 88    88 `8bo.   88ooo88 88   88 88ooooo 88oobY'88`8b   88`8b   88    88   `Y8b. 88~~~88 88   88 88~~~~~ 88`8b88 `88. 88 `88. 88b  d88 db   8D 88   88 88  .8D 88.     88 `88.YP   YD 88   YD ~Y8888P' `8888Y' YP   YP Y8888D' Y88888P 88   YD                                         S o u r c e    F i l e****************************************************************************                                                                         **   This program is free software; you can redistribute it and/or modify  **   it under the terms of the GNU General Public License as published by  **   the Free Software Foundation; either version 2 of the License, or     **   (at your option) any later version.                                   **                                                                         ****************************************************************************/#include "krdetailedview.h"#include "krdetailedviewitem.h"#include "krcolorcache.h"#include "krselectionmode.h"#include "../krusader.h"#include "../kicons.h"#include "../defaults.h"#include "../krusaderview.h"#include "../krslots.h"#include "../VFS/krpermhandler.h"#include "../VFS/krarchandler.h"#include "../GUI/kcmdline.h"#include "../Dialogs/krspecialwidgets.h"#include "../panelmanager.h"#include <qlayout.h>#include <qdir.h>#include <qwhatsthis.h>#include <qheader.h>#include <qstyle.h>#include <kprogress.h>#include <kstatusbar.h>#include <kinputdialog.h>#include <kmessagebox.h>#include <klocale.h>#include <kpopupmenu.h>#include <qdict.h>////////////////////////////////////////////////////////////////////////////  The following is KrDetailedView's settings in KConfig:// Group name: KrDetailedView//// Ext Column#define _ExtColumn          true // Mime Column#define _MimeColumn         false // Size Column#define _SizeColumn         true // DateTime Column#define _DateTimeColumn     true // Perm Column#define _PermColumn         false // KrPerm Column#define _KrPermColumn       true // Owner Column#define _OwnerColumn        false // Group Column#define _GroupColumn        false // Do Quicksearch#define _DoQuicksearch      true //////////////////////////////////////////////////////////////////////////#define CANCEL_TWO_CLICK_RENAME {singleClicked = false;renameTimer.stop();}#define COLUMN(X)	static_cast<KrDetailedViewProperties*>(_properties)->column[ KrDetailedViewProperties::X ]#define PROPS	static_cast<KrDetailedViewProperties*>(_properties)	#define VF	getVfile()#define COLUMN_POPUP_IDS    91QString KrDetailedView::ColumnName[ KrDetailedViewProperties::MAX_COLUMNS ];KrDetailedView::KrDetailedView( QWidget *parent, bool &left, KConfig *cfg, const char *name ) :      KListView( parent, name ), KrView( cfg ), _currDragItem( 0L ), currentlyRenamedItem( 0 ),      pressedItem( 0 ) {	setWidget( this );	_nameInKConfig=QString( "KrDetailedView" ) + QString( ( left ? "Left" : "Right" ) ) ;	krConfig->setGroup("Private");	if (krConfig->readBoolEntry("Enable Input Method", true))		setInputMethodEnabled(true);}void KrDetailedView::setup() {	lastSwushPosition = 0;   if ( ColumnName[ 0 ].isEmpty() ) {      ColumnName[ 0 ] = i18n( "Name" );      ColumnName[ 1 ] = i18n( "Ext" );      ColumnName[ 2 ] = i18n( "Type" );      ColumnName[ 3 ] = i18n( "Size" );      ColumnName[ 4 ] = i18n( "Modified" );      ColumnName[ 5 ] = i18n( "Perms" );      ColumnName[ 6 ] = i18n( "rwx" );      ColumnName[ 7 ] = i18n( "Owner" );      ColumnName[ 8 ] = i18n( "Group" );   }   /////////////////////////////// listview ////////////////////////////////////   { // use the {} so that KConfigGroupSaver will work correctly!      KConfigGroupSaver grpSvr( _config, "Look&Feel" );      setFont( _config->readFontEntry( "Filelist Font", _FilelistFont ) );      // decide on single click/double click selection      if ( _config->readBoolEntry( "Single Click Selects", _SingleClickSelects ) &&           KGlobalSettings::singleClick() ) {         connect( this, SIGNAL( executed( QListViewItem* ) ), this, SLOT( slotExecuted( QListViewItem* ) ) );      } else {         connect( this, SIGNAL( clicked( QListViewItem* ) ), this, SLOT( slotClicked( QListViewItem* ) ) );         connect( this, SIGNAL( doubleClicked( QListViewItem* ) ), this, SLOT( slotDoubleClicked( QListViewItem* ) ) );      }      // a change in the selection needs to update totals      connect( this, SIGNAL( onItem( QListViewItem* ) ), this, SLOT( slotItemDescription( QListViewItem* ) ) );      connect( this, SIGNAL( contextMenuRequested( QListViewItem*, const QPoint&, int ) ),               this, SLOT( handleContextMenu( QListViewItem*, const QPoint&, int ) ) );		connect( this, SIGNAL( rightButtonPressed(QListViewItem*, const QPoint&, int)),			this, SLOT(slotRightButtonPressed(QListViewItem*, const QPoint&, int)));      connect( this, SIGNAL( currentChanged( QListViewItem* ) ), this, SLOT( setNameToMakeCurrent( QListViewItem* ) ) );      connect( this, SIGNAL( currentChanged( QListViewItem* ) ), this, SLOT( transformCurrentChanged( QListViewItem* ) ) );      connect( this, SIGNAL( mouseButtonClicked ( int, QListViewItem *, const QPoint &, int ) ),               this, SLOT( slotMouseClicked ( int, QListViewItem *, const QPoint &, int ) ) );      connect( &KrColorCache::getColorCache(), SIGNAL( colorsRefreshed() ), this, SLOT( refreshColors() ) );		connect( header(), SIGNAL(clicked(int)), this, SLOT(sortOrderChanged(int )));   }   // add whatever columns are needed to the listview   krConfig->setGroup( nameInKConfig() );   	newColumn( KrDetailedViewProperties::Name );  // we always have a name   setColumnWidthMode( COLUMN(Name), QListView::Manual );   if ( _config->readBoolEntry( "Ext Column", _ExtColumn ) ) {      newColumn( KrDetailedViewProperties::Extention );      setColumnWidthMode( COLUMN(Extention), QListView::Manual );      setColumnWidth( COLUMN(Extention), QFontMetrics( font() ).width( "tar.bz2" ) );   }   if ( _config->readBoolEntry( "Mime Column", _MimeColumn ) ) {      newColumn( KrDetailedViewProperties::Mime );      setColumnWidthMode( COLUMN(Mime), QListView::Manual );      setColumnWidth( COLUMN(Mime), QFontMetrics( font() ).width( 'X' ) * 6 );   }   if ( _config->readBoolEntry( "Size Column", _SizeColumn ) ) {      newColumn( KrDetailedViewProperties::Size );      setColumnWidthMode( COLUMN(Size), QListView::Manual );      setColumnWidth( COLUMN(Size), QFontMetrics( font() ).width( "9" ) * 10 );      setColumnAlignment( COLUMN(Size), Qt::AlignRight ); // right-align numbers   }   if ( _config->readBoolEntry( "DateTime Column", _DateTimeColumn ) ) {      newColumn( KrDetailedViewProperties::DateTime );      setColumnWidthMode( COLUMN(DateTime), QListView::Manual );      //setColumnWidth( column( DateTime ), QFontMetrics( font() ).width( "99/99/99  99:99" ) );      setColumnWidth( COLUMN(DateTime), QFontMetrics( font() ).width( KGlobal::locale() ->formatDateTime(                         QDateTime ( QDate( 2099, 12, 29 ), QTime( 23, 59 ) ) ) ) + 3 );   }   if ( _config->readBoolEntry( "Perm Column", _PermColumn ) ) {      newColumn( KrDetailedViewProperties::Permissions );      setColumnWidthMode( COLUMN(Permissions), QListView::Manual );      setColumnWidth( COLUMN(Permissions), QFontMetrics( font() ).width( "drwxrwxrwx" ) );   }   if ( _config->readBoolEntry( "KrPerm Column", _KrPermColumn ) ) {      newColumn( KrDetailedViewProperties::KrPermissions );      setColumnWidthMode( COLUMN(KrPermissions), QListView::Manual );      setColumnWidth( COLUMN(KrPermissions), QFontMetrics( font() ).width( "RWX" ) );   }   if ( _config->readBoolEntry( "Owner Column", _OwnerColumn ) ) {      newColumn( KrDetailedViewProperties::Owner );      setColumnWidthMode( COLUMN(Owner), QListView::Manual );      setColumnWidth( COLUMN(Owner), QFontMetrics( font() ).width( 'X' ) * 6 );   }   if ( _config->readBoolEntry( "Group Column", _GroupColumn ) ) {      newColumn( KrDetailedViewProperties::Group );      setColumnWidthMode( COLUMN(Group), QListView::Manual );      setColumnWidth( COLUMN(Group), QFontMetrics( font() ).width( 'X' ) * 6 );   }      // determine basic settings for the listview   setAcceptDrops( true );   setDragEnabled( true );   setTooltipColumn( COLUMN(Name) );   setDropVisualizer(false);   setDropHighlighter(true);   setSelectionModeExt( KListView::FileManager );   setAllColumnsShowFocus( true );   setShowSortIndicator( true );   header() ->setStretchEnabled( true, COLUMN(Name) );   //---- don't enable these lines, as it causes an ugly bug with inplace renaming   //-->  setItemsRenameable( true );   //-->  setRenameable( column( Name ), true );   //-------------------------------------------------------------------------------   header()->installEventFilter( this );   renameLineEdit()->installEventFilter( this );      // allow in-place renaming   connect( renameLineEdit(), SIGNAL( done( QListViewItem *, int ) ),            this, SLOT( inplaceRenameFinished( QListViewItem*, int ) ) );   connect( &renameTimer, SIGNAL( timeout() ), this, SLOT( renameCurrentItem() ) );   connect( &contextMenuTimer, SIGNAL (timeout()), this, SLOT (showContextMenu()));	connect( header(), SIGNAL(clicked(int)), this, SLOT(slotSortOrderChanged(int )));   setFocusPolicy( StrongFocus );   restoreSettings();   refreshColors();   CANCEL_TWO_CLICK_RENAME;}KrDetailedView::~KrDetailedView() {	delete _properties; _properties = 0;	delete _operator; _operator = 0;}void KrDetailedView::newColumn( KrDetailedViewProperties::ColumnType type ) {	// get the next available column	int max = KrDetailedViewProperties::Unused;	for (int i=0; i<KrDetailedViewProperties::MAX_COLUMNS; ++i) {		if (PROPS->column[i]>=max)			max = PROPS->column[i]+1;	}	if ( max >= KrDetailedViewProperties::MAX_COLUMNS )      perror( "KrDetailedView::newColumn() - too many columns" );		PROPS->column[type] = max;	addColumn( ColumnName[type], -1 );}/** * returns the number of column which holds values of type 'type'. * if such values are not presented in the view, -1 is returned. */int KrDetailedView::column( KrDetailedViewProperties::ColumnType type ) {	return PROPS->column[type];}// if vfile passes the filter, create an item, otherwise, drop itKrViewItem *KrDetailedView::preAddItem( vfile *vf ) {   QString size = KRpermHandler::parseSize( vf->vfile_getSize() );   QString name = vf->vfile_getName();   bool isDir = vf->vfile_isDir();   if ( !isDir || ( isDir && ( _properties->filter & KrViewProperties::ApplyToDirs ) ) ) {      switch ( _properties->filter ) {            case KrViewProperties::All :               break;            case KrViewProperties::Custom :            if ( !_properties->filterMask.match( vf ) ) return 0;            break;            case KrViewProperties::Dirs:            if ( !vf->vfile_isDir() ) return 0;            break;            case KrViewProperties::Files:            if ( vf->vfile_isDir() ) return 0;            break;            case KrViewProperties::ApplyToDirs :            break; // no-op, stop compiler complaints      }   }   // passed the filter ...	return new KrDetailedViewItem( this, lastItem(), vf );}bool KrDetailedView::preDelItem(KrViewItem *item) {   /* KDE HACK START - the renaming item is not disappeared after delete */   /* solution: we send an ESC key event to terminate the rename */   if( item ) {      QListViewItem * viewItem = dynamic_cast<QListViewItem*>( item );      if( viewItem == currentlyRenamedItem ) {         currentlyRenamedItem = 0;         QKeyEvent escEvent( QEvent::KeyPress, Key_Escape, 27, 0 );         QApplication::sendEvent( renameLineEdit(), &escEvent );      }   }   /* KDE HACK END */   return true;}void KrDetailedView::addItems( vfs *v, bool addUpDir ) {   QListViewItem * item = firstChild();   QListViewItem *currentItem = item;   QString size, name;   // add the up-dir arrow if needed   if ( addUpDir ) {      new KrDetailedViewItem( this, ( QListViewItem* ) 0L, ( vfile* ) 0L );   }   // text for updating the status bar   QString statusText = QString("%1/  ").arg( v->vfs_getOrigin().fileName() ) + i18n("Directory");   int cnt = 0;   int cl = columnSorted();   bool as = ascendingSort();   setSorting( -1 ); // disable sorting   for ( vfile * vf = v->vfs_getFirstFile(); vf != 0 ; vf = v->vfs_getNextFile() ) {      size = KRpermHandler::parseSize( vf->vfile_getSize() );      name = vf->vfile_getName();      bool isDir = vf->vfile_isDir();      if ( !isDir || ( isDir && ( _properties->filter & KrViewProperties::ApplyToDirs ) ) ) {         switch ( _properties->filter ) {               case KrViewProperties::All :               break;               case KrViewProperties::Custom :               if ( !_properties->filterMask.match( vf ) )                  continue;               break;               case KrViewProperties::Dirs:               if ( !vf->vfile_isDir() )                  continue;               break;               case KrViewProperties::Files:               if ( vf->vfile_isDir() )                  continue;               break;               case KrViewProperties::ApplyToDirs :               break; // no-op, stop compiler complaints         }      }      KrDetailedViewItem *dvitem = new KrDetailedViewItem( this, item, vf );      _dict.insert( vf->vfile_getName(), dvitem );      if ( isDir )         ++_numDirs;      else         _countSize += dvitem->VF->vfile_getSize();      ++_count;      // if the item should be current - make it so      if ( dvitem->name() == nameToMakeCurrent() )      {         currentItem = static_cast<QListViewItem*>(dvitem);         statusText = dvitem->description();      }      cnt++;   }   // re-enable sorting   setSorting( cl, as );   sort();   if ( !currentItem )      currentItem = firstChild();   KListView::setCurrentItem( currentItem );   ensureItemVisible( currentItem );   op()->emitItemDescription( statusText );}QString KrDetailedView::getCurrentItem() const {   QListViewItem * it = currentItem();   if ( !it )      return QString::null;   else      return dynamic_cast<KrViewItem*>( it ) ->name();}void KrDetailedView::setCurrentItem( const QString& name ) {   KrDetailedViewItem * it = dynamic_cast<KrDetailedViewItem*>(_dict[ name ]);   if ( it )      KListView::setCurrentItem( it );}void KrDetailedView::clear() {   /* KDE HACK START - the renaming item is not disappeared after clear */   /* solution: we send an ESC key event to terminate the rename */   if( currentlyRenamedItem ) {      currentlyRenamedItem = 0;      QKeyEvent escEvent( QEvent::KeyPress, Key_Escape, 27, 0 );      QApplication::sendEvent( renameLineEdit(), &escEvent );   }   /* KDE HACK END */   op()->emitSelectionChanged(); /* to avoid rename crash at refresh */   KListView::clear();   KrView::clear();}void KrDetailedView::setSortMode( KrViewProperties::SortSpec mode ) {   KrView::setSortMode(mode); // the KrViewItems will check it by themselves   bool ascending = !( mode & KrViewProperties::Descending );

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -