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

📄 krsearchdialog.cpp

📁 LINUX 下, 以 QT/KDE 写的档案管理员
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/***************************************************************************                                 krsearchdialog.cpp                             -------------------    copyright            : (C) 2001 by Shie Erlich & Rafi Yanai    email                : krusader@users.sourceforge.net    web site		 : http://krusader.sourceforge.net ---------------------------------------------------------------------------  Description ***************************************************************************  A     db   dD d8888b. db    db .d8888.  .d8b.  d8888b. d88888b d8888b.     88 ,8P' 88  `8D 88    88 88'  YP d8' `8b 88  `8D 88'     88  `8D     88,8P   88oobY' 88    88 `8bo.   88ooo88 88   88 88ooooo 88oobY'     88`8b   88`8b   88    88   `Y8b. 88~~~88 88   88 88~~~~~ 88`8b     88 `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 "../krusader.h"#include "../defaults.h"#include "../panelmanager.h"#include "../VFS/vfs.h"#include "../krusaderview.h"#include "../Panel/listpanel.h"#include "../Panel/panelfunc.h"#include "../Dialogs/krdialogs.h"#include "../VFS/virt_vfs.h"#include "../KViewer/krviewer.h"#include "krsearchmod.h"#include "krsearchdialog.h"#include <kinputdialog.h>#include <qregexp.h>#include <qfontmetrics.h>#include <kmessagebox.h>#include <kpopupmenu.h>#include <qcursor.h>#include <qclipboard.h>#include <qheader.h>#include <kurldrag.h>#include <../kicons.h>class SearchListView : public QListView{public:  SearchListView( QWidget * parent, const char * name ) : QListView( parent, name )  {  }  void startDrag()   {    KURL::List urls;    QListViewItem * item = firstChild();    while( item )    {      if( item->isSelected() )      {         QString name = item->text(1);         name += (name.endsWith( "/" ) ? item->text(0) : "/" + item->text(0) );         urls.push_back( vfs::fromPathOrURL( name ) );      }      item = item->nextSibling();    }    if( urls.count() == 0 )      return;    KURLDrag *d = new KURLDrag(urls, this);    d->setPixmap( FL_LOADICON( "file" ), QPoint( -7, 0 ) );    d->dragCopy();  }};KrSearchDialog *KrSearchDialog::SearchDialog = 0;QString KrSearchDialog::lastSearchText = "*";int KrSearchDialog::lastSearchType = 0;bool KrSearchDialog::lastSearchForCase = false;bool KrSearchDialog::lastRemoteContentSearch = false;bool KrSearchDialog::lastContainsWholeWord = false;bool KrSearchDialog::lastContainsWithCase = true;bool KrSearchDialog::lastSearchInSubDirs = true;bool KrSearchDialog::lastSearchInArchives = false;bool KrSearchDialog::lastFollowSymLinks = false;// class starts here /////////////////////////////////////////KrSearchDialog::KrSearchDialog( QString profile, QWidget* parent,  const char* name, bool modal, WFlags fl )                : QDialog( parent, name, modal, fl ), query(0), searcher(0){  setCaption( i18n( "Krusader::Search" ) );  QGridLayout* searchBaseLayout = new QGridLayout( this );  searchBaseLayout->setSpacing( 6 );  searchBaseLayout->setMargin( 11 );  // creating the dialog buttons ( Search, Stop, Close )  QHBoxLayout* buttonsLayout = new QHBoxLayout();  buttonsLayout->setSpacing( 6 );  buttonsLayout->setMargin( 0 );  profileManager = new ProfileManager( "SearcherProfile", this, "profileManager" );  buttonsLayout->addWidget( profileManager );  QSpacerItem* spacer = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );  buttonsLayout->addItem( spacer );  mainFeedToListBoxBtn = new QPushButton( this, "mainFeedToListBoxBtn" );  mainFeedToListBoxBtn->setText( i18n( "Feed to listbox" ) );  mainFeedToListBoxBtn->setEnabled(false);  buttonsLayout->addWidget( mainFeedToListBoxBtn );  mainSearchBtn = new QPushButton( this, "mainSearchBtn" );  mainSearchBtn->setText( i18n( "Search" ) );  mainSearchBtn->setDefault(true);  buttonsLayout->addWidget( mainSearchBtn );  mainStopBtn = new QPushButton( this, "mainStopBtn" );  mainStopBtn->setEnabled( false );  mainStopBtn->setText( i18n( "Stop" ) );  buttonsLayout->addWidget( mainStopBtn );  mainCloseBtn = new QPushButton( this, "mainCloseBtn" );  mainCloseBtn->setText( i18n( "Close" ) );  buttonsLayout->addWidget( mainCloseBtn );  searchBaseLayout->addLayout( buttonsLayout, 1, 0 );  // creating the searcher tabs  searcherTabs = new QTabWidget( this, "searcherTabs" );  filterTabs = FilterTabs::addTo( searcherTabs, FilterTabs::Default | FilterTabs::HasRemoteContentSearch );  generalFilter = (GeneralFilter *)filterTabs->get( "GeneralFilter" );  resultTab = new QWidget( searcherTabs, "resultTab" );  resultLayout = new QGridLayout( resultTab );  resultLayout->setSpacing( 6 );  resultLayout->setMargin( 11 );  // creating the result tab  QHBoxLayout* resultLabelLayout = new QHBoxLayout();  resultLabelLayout->setSpacing( 6 );  resultLabelLayout->setMargin( 0 );  foundLabel = new QLabel( resultTab, "foundLabel" );  foundLabel->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)1, (QSizePolicy::SizeType)1, foundLabel->sizePolicy().hasHeightForWidth() ) );  foundLabel->setFrameShape( QLabel::StyledPanel );  foundLabel->setFrameShadow( QLabel::Sunken );  foundLabel->setText( i18n( "Found 0 matches." ) );  resultLabelLayout->addWidget( foundLabel );  searchingLabel = new KSqueezedTextLabel( resultTab, "searchingLabel" );  searchingLabel->setFrameShape( QLabel::StyledPanel );  searchingLabel->setFrameShadow( QLabel::Sunken );  searchingLabel->setText( "" );  resultLabelLayout->addWidget( searchingLabel );  resultLayout->addLayout( resultLabelLayout, 2, 0 );  // creating the result list view  resultsList = new SearchListView( resultTab, "resultsList" );  resultsList->addColumn( i18n( "Name" ) );  resultsList->addColumn( i18n( "Location" ) );  resultsList->addColumn( i18n( "Size" ) );  resultsList->addColumn( i18n( "Date" ) );  resultsList->addColumn( i18n( "Permissions" ) );  resultsList->setSorting(1); // sort by location  resultsList->setSelectionMode( QListView::Extended );  // fix the results list  // => make the results font smaller  QFont resultsFont(  resultsList->font() );  resultsFont.setPointSize(resultsFont.pointSize()-1);  resultsList->setFont(resultsFont);  resultsList->setAllColumnsShowFocus(true);  for (int i=0; i<5; ++i) // don't let it resize automatically    resultsList->setColumnWidthMode(i, QListView::Manual);  int i=QFontMetrics(resultsList->font()).width("W");  int j=QFontMetrics(resultsList->font()).width("0");  j=(i>j ? i : j);  resultsList->setColumnWidth(0, krConfig->readNumEntry("Name Width", j*14) );  resultsList->setColumnWidth(1, krConfig->readNumEntry("Path Width", j*25) );  resultsList->setColumnWidth(2, krConfig->readNumEntry("Size Width", j*6) );  resultsList->setColumnWidth(3, krConfig->readNumEntry("Date Width", j*7) );  resultsList->setColumnWidth(4, krConfig->readNumEntry("Perm Width", j*7) );  resultsList->setColumnAlignment( 2, AlignRight );  resultsList->header()->setStretchEnabled( true, 1 );  resultLayout->addWidget( resultsList, 0, 0 );  QHBoxLayout* foundTextLayout = new QHBoxLayout();  foundTextLayout->setSpacing( 6 );  foundTextLayout->setMargin( 0 );    QLabel *l1 = new QLabel(resultTab);  l1->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)1, (QSizePolicy::SizeType)1, l1->sizePolicy().hasHeightForWidth() ) );  l1->setFrameShape( QLabel::StyledPanel );  l1->setFrameShadow( QLabel::Sunken );  l1->setText(i18n("Text found:"));  foundTextLayout->addWidget( l1 );  foundTextLabel = new KrSqueezedTextLabel(resultTab);  foundTextLabel->setFrameShape( QLabel::StyledPanel );  foundTextLabel->setFrameShadow( QLabel::Sunken );  foundTextLabel->setText("");  foundTextLayout->addWidget( foundTextLabel );  resultLayout->addLayout(foundTextLayout, 1, 0);    searcherTabs->insertTab( resultTab, i18n( "&Results" ) );  searchBaseLayout->addWidget( searcherTabs, 0, 0 );  // signals and slots connections  connect( mainSearchBtn, SIGNAL( clicked() ), this, SLOT( startSearch() ) );  connect( mainStopBtn, SIGNAL( clicked() ), this, SLOT( stopSearch() ) );  connect( resultsList, SIGNAL( returnPressed(QListViewItem*) ), this,  	SLOT( resultDoubleClicked(QListViewItem*) ) );  connect( resultsList, SIGNAL( doubleClicked(QListViewItem*) ), this,  	SLOT( resultDoubleClicked(QListViewItem*) ) );  connect( resultsList, SIGNAL( currentChanged(QListViewItem*) ), this,  		SLOT( resultClicked(QListViewItem*) ) );  connect( resultsList, SIGNAL( clicked(QListViewItem*) ), this,  		SLOT( resultClicked(QListViewItem*) ) );  connect( resultsList, SIGNAL( rightButtonClicked(QListViewItem*,const QPoint&,int) ), this, SLOT( rightClickMenu(QListViewItem*, const QPoint&, int) ) );  connect( mainCloseBtn, SIGNAL( clicked() ), this, SLOT( closeDialog() ) );  connect( mainFeedToListBoxBtn, SIGNAL( clicked() ), this, SLOT( feedToListBox() ) );  connect( profileManager, SIGNAL( loadFromProfile( QString ) ), filterTabs, SLOT( loadFromProfile( QString ) ) );  connect( profileManager, SIGNAL( saveToProfile( QString ) ), filterTabs, SLOT( saveToProfile( QString ) ) );  // tab order  setTabOrder( mainSearchBtn, mainCloseBtn );  setTabOrder( mainCloseBtn, mainStopBtn );  setTabOrder( mainStopBtn, searcherTabs );  setTabOrder( searcherTabs, resultsList );  krConfig->setGroup( "Search" );  int sx = krConfig->readNumEntry( "Window Width",  -1 );  int sy = krConfig->readNumEntry( "Window Height",  -1 );  if( sx != -1 && sy != -1 )    resize( sx, sy );  if( krConfig->readBoolEntry( "Window Maximized",  false ) )      showMaximized();  else      show();  generalFilter->searchFor->setFocus();  isSearching = closed = false;  // finaly, load a profile of apply defaults:  if ( profile.isEmpty() ) {    // load the last used values    generalFilter->searchFor->setEditText( lastSearchText );    generalFilter->searchFor->lineEdit()->selectAll();    generalFilter->ofType->setCurrentItem( lastSearchType );    generalFilter->searchForCase->setChecked( lastSearchForCase );    generalFilter->remoteContentSearch->setChecked( lastRemoteContentSearch );    generalFilter->containsWholeWord->setChecked( lastContainsWholeWord );    generalFilter->containsTextCase->setChecked( lastContainsWithCase );    generalFilter->searchInDirs->setChecked( lastSearchInSubDirs );    generalFilter->searchInArchives->setChecked( lastSearchInArchives );    generalFilter->followLinks->setChecked( lastFollowSymLinks );    // the path in the active panel should be the default search location    generalFilter->searchIn->lineEdit()->setText( ACTIVE_PANEL->virtualPath().prettyURL() );  }  else    profileManager->loadProfile( profile ); // important: call this _after_ you've connected profileManager ot the loadFromProfile!!}void KrSearchDialog::closeDialog( bool isAccept ){  // stop the search if it's on-going  if (searcher!=0) {    delete searcher;    searcher = 0;  }  // saving the searcher state  krConfig->setGroup( "Search" );  krConfig->writeEntry("Window Width", sizeX );  krConfig->writeEntry("Window Height", sizeY );  krConfig->writeEntry("Window Maximized", isMaximized() );  krConfig->writeEntry("Name Width",  resultsList->columnWidth( 0 ) );

⌨️ 快捷键说明

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