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

📄 krbriefview.cpp

📁 LINUX 下, 以 QT/KDE 写的档案管理员
💻 CPP
📖 第 1 页 / 共 4 页
字号:
/***************************************************************************                   krbriefview.cpp                 -------------------copyright            : (C) 2000-2007 by Shie Erlich & Rafi Yanai & Csaba Karaie-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 "krbriefview.h"#include "krbriefviewitem.h"#include "krcolorcache.h"#include "krselectionmode.h"#include "../krusader.h"#include "../kicons.h"#include "../defaults.h"#include "../krslots.h"#include "../VFS/krarchandler.h"#include "../VFS/krquery.h"#include "../Dialogs/krspecialwidgets.h"#include <qheader.h>#include <qtooltip.h>#define CANCEL_TWO_CLICK_RENAME {singleClicked = false;renameTimer.stop();}#define PROPS	 static_cast<KrBriefViewProperties*>(_properties)	#define MAX_COLS 5#define VF	 getVfile()class KrBriefViewToolTip : public QToolTip{public:    KrBriefViewToolTip( KrBriefView *view, QWidget *parent );    void maybeTip( const QPoint &pos );    virtual ~KrBriefViewToolTip() {}private:    KrBriefView *view;};KrBriefViewToolTip::KrBriefViewToolTip( KrBriefView *lv, QWidget *parent )  : QToolTip( parent ), view( lv ){}void KrBriefViewToolTip::maybeTip( const QPoint &pos ){  QIconViewItem *item = view->findItem( view->viewportToContents( pos ) );  if ( !item )    return;      int width = QFontMetrics( view->font() ).width( item->text() ) + 4;      QRect r = item->rect();  r.setTopLeft( view->contentsToViewport( r.topLeft() ) );  if( width > item->textRect().width() )    tip( r, item->text() );}KrBriefView::KrBriefView( QHeader * headerIn, QWidget *parent, bool &left, KConfig *cfg, const char *name ):	KIconView(parent, name), KrView( cfg ), header( headerIn ), _currDragItem( 0 ),            currentlyRenamedItem( 0 ), pressedItem( 0 ), mouseEvent( 0 ) {	setWidget( this );	_nameInKConfig = QString( "KrBriefView" ) + QString( ( left ? "Left" : "Right" ) );	krConfig->setGroup("Private");	if (krConfig->readBoolEntry("Enable Input Method", true))		setInputMethodEnabled(true);	toolTip = new KrBriefViewToolTip( this, viewport() );}void KrBriefView::setup() {   lastSwushPosition = 0;         // 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( QIconViewItem* ) ), this, SLOT( slotExecuted( QIconViewItem* ) ) );   } else {      connect( this, SIGNAL( clicked( QIconViewItem* ) ), this, SLOT( slotClicked( QIconViewItem* ) ) );      connect( this, SIGNAL( doubleClicked( QIconViewItem* ) ), this, SLOT( slotDoubleClicked( QIconViewItem* ) ) );   }   // a change in the selection needs to update totals   connect( this, SIGNAL( onItem( QIconViewItem* ) ), this, SLOT( slotItemDescription( QIconViewItem* ) ) );   connect( this, SIGNAL( contextMenuRequested( QIconViewItem*, const QPoint& ) ),            this, SLOT( handleContextMenu( QIconViewItem*, const QPoint& ) ) );	connect( this, SIGNAL( rightButtonPressed(QIconViewItem*, const QPoint&)),		this, SLOT(slotRightButtonPressed(QIconViewItem*, const QPoint&)));   connect( this, SIGNAL( currentChanged( QIconViewItem* ) ), this, SLOT( setNameToMakeCurrent( QIconViewItem* ) ) );   connect( this, SIGNAL( currentChanged( QIconViewItem* ) ), this, SLOT( transformCurrentChanged( QIconViewItem* ) ) );   connect( this, SIGNAL( mouseButtonClicked ( int, QIconViewItem *, const QPoint & ) ),            this, SLOT( slotMouseClicked ( int, QIconViewItem *, const QPoint & ) ) );   connect( &KrColorCache::getColorCache(), SIGNAL( colorsRefreshed() ), this, SLOT( refreshColors() ) );   // add whatever columns are needed to the listview   krConfig->setGroup( nameInKConfig() );      // determine basic settings for the view   setAcceptDrops( true );   setItemsMovable( false );   setItemTextPos( QIconView::Right );   setArrangement( QIconView::TopToBottom );   setWordWrapIconText( false );   setSpacing( 0 );   horizontalScrollBar()->installEventFilter( this );   // allow in-place renaming   connect( this, SIGNAL( itemRenamed ( QIconViewItem * ) ),             this, SLOT( inplaceRenameFinished( QIconViewItem * ) ) );   connect( &renameTimer, SIGNAL( timeout() ), this, SLOT( renameCurrentItem() ) );   connect( &contextMenuTimer, SIGNAL (timeout()), this, SLOT (showContextMenu()));   setSelectionMode( QIconView::Extended );   setFocusPolicy( StrongFocus );   restoreSettings();   refreshColors();   CANCEL_TWO_CLICK_RENAME;   // setting the header    while( header->count() )      header->removeLabel( 0 );   header->addLabel( i18n( "Name" ) );   header->setStretchEnabled( true );   header->setSortIndicator( 0, sortDirection() ? Qt::Ascending : Qt::Descending );   connect( header, SIGNAL(clicked( int )), this, SLOT( changeSortOrder()));   header->installEventFilter( this );   header->show();}KrBriefView::~KrBriefView() {	delete _properties; _properties = 0;	delete _operator; _operator = 0;	if( mouseEvent )		delete mouseEvent;	mouseEvent = 0;	delete toolTip;}void KrBriefView::resizeEvent ( QResizeEvent * resEvent ){   QPoint pnt( contentsX(), contentsY() );   QRect viewportRect( pnt, resEvent->oldSize() );   bool visible = false;   if( currentItem() )     visible = viewportRect.contains( currentItem()->rect() );   KIconView::resizeEvent( resEvent );   redrawColumns();   if( visible && currentItem() )      ensureItemVisible( currentItem() );}void KrBriefView::redrawColumns(){   bool ascending = sortDirection();   setSorting( false, ascending );   setGridX( width() / PROPS->numberOfColumns );   // QT bug, it's important for recalculating the bounding rectangle   for( QIconViewItem * item = firstItem(); item; item = item->nextItem() )   {      QString txt = item->text();      item->setText( "" );      item->setText( txt );   }   setSorting( true, ascending );   arrangeItemsInGrid();}// if vfile passes the filter, create an item, otherwise, drop itKrViewItem *KrBriefView::preAddItem( vfile *vf ) {   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 KrBriefViewItem( this, lastItem(), vf );}bool KrBriefView::preDelItem(KrViewItem *item) {   if( item ) {      KrBriefViewItem * viewItem = dynamic_cast<KrBriefViewItem*>( item );      if( viewItem == currentlyRenamedItem ) {         currentlyRenamedItem->cancelRename();         currentlyRenamedItem = 0;      }   }   return true;}void KrBriefView::addItems( vfs *v, bool addUpDir ) {   QIconViewItem * item = firstItem();   QIconViewItem * currentItem = item;   // add the up-dir arrow if needed   if ( addUpDir ) {      new KrBriefViewItem( this, ( QIconViewItem* ) 0L, ( vfile* ) 0L );   }   // text for updating the status bar   QString statusText = QString("%1/  ").arg( v->vfs_getOrigin().fileName() ) + i18n("Directory");   bool as = sortDirection();   setSorting( false, as ); // disable sorting   for ( vfile * vf = v->vfs_getFirstFile(); vf != 0 ; vf = v->vfs_getNextFile() ) {      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         }      }      KrBriefViewItem *bvitem = new KrBriefViewItem( this, item, vf );      _dict.insert( vf->vfile_getName(), bvitem );      if ( isDir )         ++_numDirs;      else         _countSize += bvitem->VF->vfile_getSize();      ++_count;      // if the item should be current - make it so      if ( bvitem->name() == nameToMakeCurrent() )      {         currentItem = static_cast<QIconViewItem*>(bvitem);         statusText = bvitem->description();      }   }   // re-enable sorting   setSorting( true, as );   sort( as );   if ( !currentItem )      currentItem = firstItem();   KIconView::setCurrentItem( currentItem );   ensureItemVisible( currentItem );   op()->emitItemDescription( statusText );}void KrBriefView::delItem( const QString &name ) {   KrView::delItem( name );   arrangeItemsInGrid();}QString KrBriefView::getCurrentItem() const {   QIconViewItem * it = currentItem();   if ( !it )      return QString::null;   else      return dynamic_cast<KrViewItem*>( it ) ->name();}void KrBriefView::setCurrentItem( const QString& name ) {   KrBriefViewItem * it = dynamic_cast<KrBriefViewItem*>(_dict[ name ]);   if ( it )      KIconView::setCurrentItem( it );}void KrBriefView::clear() {   if( currentlyRenamedItem ) {      currentlyRenamedItem->cancelRename();      currentlyRenamedItem = 0;   }   op()->emitSelectionChanged(); /* to avoid rename crash at refresh */   KIconView::clear();   KrView::clear();}void KrBriefView::slotClicked( QIconViewItem *item ) {   if ( !item ) return ;   if ( !modifierPressed ) {      if ( singleClicked && !renameTimer.isActive() ) {         KConfig * config = KGlobal::config();         config->setGroup( "KDE" );         int doubleClickInterval = config->readNumEntry( "DoubleClickInterval", 400 );         int msecsFromLastClick = clickTime.msecsTo( QTime::currentTime() );         if ( msecsFromLastClick > doubleClickInterval && msecsFromLastClick < 5 * doubleClickInterval ) {            singleClicked = false;            renameTimer.start( doubleClickInterval, true );            return ;         }      }      CANCEL_TWO_CLICK_RENAME;      singleClicked = true;      clickTime = QTime::currentTime();      clickedItem = item;   }}void KrBriefView::slotDoubleClicked( QIconViewItem *item ) {   CANCEL_TWO_CLICK_RENAME;   if ( !item )

⌨️ 快捷键说明

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