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

📄 krdetailedview.cpp

📁 LINUX 下, 以 QT/KDE 写的档案管理员
💻 CPP
📖 第 1 页 / 共 4 页
字号:
   QString newName, fileName;	// handle inplace renaming, if possible	   KrDetailedViewItem *it = static_cast<KrDetailedViewItem*>(getCurrentKrViewItem());   if ( it )      fileName = it->name();   else      return ; // quit if no current item available   // don't allow anyone to rename ..   if ( fileName == ".." )      return ;   // determine which column is inplace renameable   for ( c = 0; c < columns(); c++ )      if ( isRenameable( c ) )         break; // one MUST be renamable   if ( !isRenameable( c ) )      c = -1; // failsafe   if ( c >= 0 ) {      rename( static_cast<QListViewItem*>( it ), c );      // if applicable, select only the name without extension      KConfigGroupSaver svr(krConfig,"Look&Feel");      if (!krConfig->readBoolEntry("Rename Selects Extension", true)) {	if (it->hasExtension() && !it->VF->vfile_isDir() ) 		renameLineEdit()->setSelection(0, it->name().findRev(it->extension())-1);      }      // signal will be emited when renaming is done, and finalization      // will occur in inplaceRenameFinished()   } else {   	// do this in case inplace renaming is disabled   	// this actually does the good old dialog box rename   	KrView::renameCurrentItem();   }}void KrDetailedView::inplaceRenameFinished( QListViewItem * it, int ) {   if( currentlyRenamedItem == 0 )      return;   if ( !it ) { // major failure - call developers      krOut << "Major failure at inplaceRenameFinished(): item is null" << endl;      return;   }      if( COLUMN( Extention ) != -1 && !currentlyRenamedItem )     return; /* does the event filter restored the original state? */      // check if the item was indeed renamed   bool restoreView = false;   if ( it->text( COLUMN( Name ) ) != static_cast<KrDetailedViewItem*>( it ) ->name() ) { // was renamed      op()->emitRenameItem( static_cast<KrDetailedViewItem*>( it ) ->name(), it->text( COLUMN( Name ) ) );   } else restoreView = true;   // restore the view always! if the file was indeed renamed, we'll get a signal from the vfs about   // it, and update the view when needed#if 0   if ( COLUMN( Extention ) != -1 && restoreView ) { // nothing happened, restore the view (if needed)#endif            QString ext, name = static_cast<KrDetailedViewItem*>( it ) ->name();      if ( !static_cast<KrDetailedViewItem*>( it ) ->VF->vfile_isDir() && COLUMN( Extention ) != -1 ) {		ext = static_cast<KrDetailedViewItem*>( it ) ->extension();		name = static_cast<KrDetailedViewItem*>( it ) ->name( false );      }      it->setText( COLUMN( Name ), name );      it->setText( COLUMN( Extention ), ext );      repaintItem( it );#if 0   }#endif   setFocus();      currentlyRenamedItem = 0;}// TODO: move the whole quicksearch mess out of here and into krviewvoid KrDetailedView::quickSearch( const QString & str, int direction ) {   KrViewItem * item = getCurrentKrViewItem();   if (!item)      return;   KConfigGroupSaver grpSvr( _config, "Look&Feel" );   bool caseSensitive = _config->readBoolEntry( "Case Sensitive Quicksearch", _CaseSensitiveQuicksearch );   if ( !direction ) {      if ( caseSensitive ? item->name().startsWith( str ) : item->name().lower().startsWith( str.lower() ) )         return ;      direction = 1;   }   KrViewItem * startItem = item;   while ( true ) {      item = ( direction > 0 ) ? getNext( item ) : getPrev( item );      if ( !item )         item = ( direction > 0 ) ? getFirst() : getLast();      if ( item == startItem )         return ;      if ( caseSensitive ? item->name().startsWith( str ) : item->name().lower().startsWith( str.lower() ) ) {			setCurrentItem( item->name() );			makeItemVisible( item );         return ;      }   }}void KrDetailedView::stopQuickSearch( QKeyEvent * e ) {   if( ACTIVE_PANEL && ACTIVE_PANEL->quickSearch ) {     ACTIVE_PANEL->quickSearch->hide();     ACTIVE_PANEL->quickSearch->clear();     krDirUp->setEnabled( true );     if ( e )        keyPressEvent( e );   }}// internal: converts signal from qlistview to krviewvoid KrDetailedView::setNameToMakeCurrent( QListViewItem * it ) {	if (!it) return;   KrView::setNameToMakeCurrent( static_cast<KrDetailedViewItem*>( it ) ->name() );}void KrDetailedView::slotMouseClicked( int button, QListViewItem * item, const QPoint&, int ) {   pressedItem = 0; // if the signals are emitted, don't emit twice at contentsMouseReleaseEvent   if ( button == Qt::MidButton )      emit middleButtonClicked( dynamic_cast<KrViewItem *>( item ) );}void KrDetailedView::refreshColors() {   krConfig->setGroup("Colors");   bool kdeDefault = krConfig->readBoolEntry("KDE Default");    bool alternateBackgroundEnabled = krConfig->readBoolEntry("Enable Alternate Background");    if ( !kdeDefault ) {      // KDE default is not choosen: set the background color (as this paints the empty areas) and the alternate color      bool isActive = hasFocus();      if ( MAIN_VIEW && ACTIVE_PANEL && ACTIVE_PANEL->view )         isActive = ( static_cast<KrView *>( this ) == ACTIVE_PANEL->view );      QColorGroup cg;      KrColorCache::getColorCache().getColors(cg, KrColorItemType(KrColorItemType::File, false, isActive, false, false));      setPaletteBackgroundColor( cg.background() );      KrColorCache::getColorCache().getColors(cg, KrColorItemType(KrColorItemType::File, true, isActive, false, false));      setAlternateBackground( cg.background() );   } else {      // KDE default is choosen: set back the background color      setPaletteBackgroundColor( KGlobalSettings::baseColor() );      // Set the alternate color to its default or to an invalid color, to turn alternate the background off.      setAlternateBackground( alternateBackgroundEnabled ? KGlobalSettings::alternateBackgroundColor() : QColor() );   }}bool KrDetailedView::event( QEvent *e ) {   modifierPressed = false;   switch ( e->type() ) {         case QEvent::Timer:         case QEvent::MouseMove:         case QEvent::MouseButtonPress:         case QEvent::MouseButtonRelease:         break;         default:         CANCEL_TWO_CLICK_RENAME;   }   return KListView::event( e );}bool KrDetailedView::eventFilter( QObject * watched, QEvent * e ){  if( watched == renameLineEdit() )  {    if( currentlyRenamedItem && e->type() == QEvent::Hide )    {      /* checking if the currentlyRenamedItem pointer is valid (vfs_refresh can delete this item) */      for( QListViewItem *it = firstChild(); it; it = it->nextSibling() )        if( it == currentlyRenamedItem )        {          if ( it->text( COLUMN( Name ) ) == dynamic_cast<KrDetailedViewItem*>( it ) ->name()  && COLUMN( Extention ) != -1 )             inplaceRenameFinished( it, COLUMN( Name ) );          break;        }    }    return FALSE;  }  else if( watched == header() )  {    if( e->type() == QEvent::MouseButtonPress && ((QMouseEvent *)e )->button() == Qt::RightButton )    {      selectColumns();      return TRUE;    }    return FALSE;  }  return KListView::eventFilter( watched, e );}void KrDetailedView::makeItemVisible( const KrViewItem *item ) {//	qApp->processEvents();  // Please don't remove the comment. Causes crash if it is inserted!	ensureItemVisible( static_cast<const KrDetailedViewItem*>( item ) ); }void KrDetailedView::initOperator() {	_operator = new KrViewOperator(this, this);	// klistview emits selection changed, so chain them to operator	connect(this, SIGNAL(selectionChanged()), _operator, SIGNAL(selectionChanged()));}void KrDetailedView::initProperties() {	_properties = new KrDetailedViewProperties;	KConfigGroupSaver grpSvr( _config, "Look&Feel" );		for (int i=0; i<KrDetailedViewProperties::MAX_COLUMNS;++i)		PROPS->column[i]=-1;		PROPS->displayIcons = _config->readBoolEntry( "With Icons", _WithIcons );	bool dirsByNameAlways = _config->readBoolEntry("Always sort dirs by name", false);	PROPS->sortMode = static_cast<KrViewProperties::SortSpec>( KrViewProperties::Name |			KrViewProperties::Descending | KrViewProperties::DirsFirst | 			(dirsByNameAlways ? KrViewProperties::AlwaysSortDirsByName : 0) );	PROPS->numericPermissions = _config->readBoolEntry("Numeric permissions", _NumericPermissions);	if ( !_config->readBoolEntry( "Case Sensative Sort", _CaseSensativeSort ) )      	PROPS->sortMode = static_cast<KrViewProperties::SortSpec>( _properties->sortMode |				 KrViewProperties::IgnoreCase );	PROPS->humanReadableSize = krConfig->readBoolEntry("Human Readable Size", _HumanReadableSize);	PROPS->localeAwareCompareIsCaseSensitive = QString( "a" ).localeAwareCompare( "B" ) > 0; // see KDE bug #40131	QStringList defaultAtomicExtensions;	defaultAtomicExtensions += ".tar.gz";	defaultAtomicExtensions += ".tar.bz2";	defaultAtomicExtensions += ".moc.cpp";	QStringList atomicExtensions = krConfig->readListEntry("Atomic Extensions", defaultAtomicExtensions);	for (QStringList::iterator i = atomicExtensions.begin(); i != atomicExtensions.end(); )	{		QString & ext = *i;		ext = ext.stripWhiteSpace();		if (!ext.length())		{			i = atomicExtensions.remove(i);			continue;		}		if (!ext.startsWith("."))			ext.insert(0, '.');		++i;	}	PROPS->atomicExtensions = atomicExtensions;}void KrDetailedView::selectColumns(){  KPopupMenu popup( this );  popup.insertTitle( i18n("Columns"));    bool refresh = false;    bool hasExtention = COLUMN( Extention ) != -1;  bool hasMime      = COLUMN( Mime ) != -1;  bool hasSize      = COLUMN( Size ) != -1;  bool hasDate      = COLUMN( DateTime ) != -1;  bool hasPerms     = COLUMN( Permissions ) != -1;  bool hasKrPerms   = COLUMN( KrPermissions ) != -1;  bool hasOwner     = COLUMN( Owner ) != -1;  bool hasGroup     = COLUMN( Group ) != -1;    popup.insertItem( i18n( "Ext" ), COLUMN_POPUP_IDS + KrDetailedViewProperties::Extention );  popup.setItemChecked( COLUMN_POPUP_IDS + KrDetailedViewProperties::Extention, hasExtention );  popup.insertItem( i18n( "Type" ), COLUMN_POPUP_IDS + KrDetailedViewProperties::Mime );  popup.setItemChecked( COLUMN_POPUP_IDS + KrDetailedViewProperties::Mime, hasMime );  popup.insertItem( i18n( "Size" ), COLUMN_POPUP_IDS + KrDetailedViewProperties::Size );  popup.setItemChecked( COLUMN_POPUP_IDS + KrDetailedViewProperties::Size, hasSize );  popup.insertItem( i18n( "Modified" ), COLUMN_POPUP_IDS + KrDetailedViewProperties::DateTime );  popup.setItemChecked( COLUMN_POPUP_IDS + KrDetailedViewProperties::DateTime, hasDate );  popup.insertItem( i18n( "Perms" ), COLUMN_POPUP_IDS + KrDetailedViewProperties::Permissions );  popup.setItemChecked( COLUMN_POPUP_IDS + KrDetailedViewProperties::Permissions, hasPerms );  popup.insertItem( i18n( "rwx" ), COLUMN_POPUP_IDS + KrDetailedViewProperties::KrPermissions );  popup.setItemChecked( COLUMN_POPUP_IDS + KrDetailedViewProperties::KrPermissions, hasKrPerms );        popup.insertItem( i18n( "Owner" ), COLUMN_POPUP_IDS + KrDetailedViewProperties::Owner );  popup.setItemChecked( COLUMN_POPUP_IDS + KrDetailedViewProperties::Owner, hasOwner );        popup.insertItem( i18n( "Group" ), COLUMN_POPUP_IDS + KrDetailedViewProperties::Group );  popup.setItemChecked( COLUMN_POPUP_IDS + KrDetailedViewProperties::Group, hasGroup );            int result=popup.exec(QCursor::pos());  krConfig->setGroup( nameInKConfig() );    switch( result - COLUMN_POPUP_IDS )  {  case KrDetailedViewProperties::Extention:    krConfig->writeEntry( "Ext Column", !hasExtention );    refresh = true;    break;  case KrDetailedViewProperties::Mime:    krConfig->writeEntry( "Mime Column", !hasMime );    refresh = true;    break;  case KrDetailedViewProperties::Size:    krConfig->writeEntry( "Size Column", !hasSize );    refresh = true;    break;  case KrDetailedViewProperties::DateTime:    krConfig->writeEntry( "DateTime Column", !hasDate );    refresh = true;    break;  case KrDetailedViewProperties::Permissions:    krConfig->writeEntry( "Perm Column", !hasPerms );    refresh = true;    break;  case KrDetailedViewProperties::KrPermissions:    krConfig->writeEntry( "KrPerm Column", !hasKrPerms );    refresh = true;    break;  case KrDetailedViewProperties::Owner:    krConfig->writeEntry( "Owner Column", !hasOwner );    refresh = true;    break;  case KrDetailedViewProperties::Group:    krConfig->writeEntry( "Group Column", !hasGroup );    refresh = true;    break;  }    if( refresh )  {	 PanelManager *p = ACTIVE_PANEL->view == this ? ACTIVE_MNG : OTHER_MNG;    QTimer::singleShot( 0, p, SLOT( slotRecreatePanels() ) );  }}void KrDetailedView::sortOrderChanged(int) {	ensureItemVisible(currentItem());}void KrDetailedView::updateView() {	triggerUpdate(); 	op()->emitSelectionChanged();}void KrDetailedView::updateItem(KrViewItem* item) {	dynamic_cast<KrDetailedViewItem*>(item)->repaintItem();}void KrDetailedView::slotRightButtonPressed(QListViewItem*, const QPoint& point, int) {	op()->emitEmptyContextMenu(point);}// hack: this needs to be done in a more cross-view wayvoid KrDetailedView::slotSortOrderChanged(int col) {	// map the column to a sort specification	KrViewProperties::SortSpec sp = KrViewProperties::Name;	int i;	for (i = 0; i < KrDetailedViewProperties::MAX_COLUMNS; ++i) {		if (PROPS->column[i] == col) break;	}	switch (i) {		case KrDetailedViewProperties::Name:			sp = KrViewProperties::Name; break;		case KrDetailedViewProperties::Extention:			sp = KrViewProperties::Ext; break;		case KrDetailedViewProperties::Mime:			sp = KrViewProperties::Type; break;		case KrDetailedViewProperties::Size:			sp = KrViewProperties::Size; break;		case KrDetailedViewProperties::DateTime:			sp = KrViewProperties::Modified; break;		case KrDetailedViewProperties::Permissions:			sp = KrViewProperties::Permissions; break;		case KrDetailedViewProperties::KrPermissions:			sp = KrViewProperties::KrPermissions; break;		case KrDetailedViewProperties::Owner:			sp = KrViewProperties::Owner; break;		case KrDetailedViewProperties::Group:			sp = KrViewProperties::Group; break;		default: qFatal("slotSortOrderChanged: unknown column");	}	if (sortMode() & KrViewProperties::DirsFirst) 		sp = static_cast<KrViewProperties::SortSpec>(sp | KrViewProperties::DirsFirst);	if (sortMode() & KrViewProperties::IgnoreCase)		sp = static_cast<KrViewProperties::SortSpec>(sp | KrViewProperties::IgnoreCase);	if (sortMode() & KrViewProperties::Descending)		sp = static_cast<KrViewProperties::SortSpec>(sp | KrViewProperties::Descending);	if (sortMode() & KrViewProperties::AlwaysSortDirsByName)		sp = static_cast<KrViewProperties::SortSpec>(sp | KrViewProperties::AlwaysSortDirsByName);	// fix the ascending/decending stuff	if (sortMode() == sp) {		if (sp & KrViewProperties::Descending) 			sp = static_cast<KrViewProperties::SortSpec>(sp &~ KrViewProperties::Descending);		else sp = static_cast<KrViewProperties::SortSpec>(sp | KrViewProperties::Descending);	}	PROPS->sortMode = sp;		if( !_focused )		op()->emitNeedFocus();}#include "krdetailedview.moc"

⌨️ 快捷键说明

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