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

📄 fileselector.cpp

📁 Trolltech公司发布的图形界面操作系统。可在qt-embedded-2.3.7平台上编译为嵌入式图形界面操作系统。
💻 CPP
📖 第 1 页 / 共 2 页
字号:
    QPEApplication::setStylusOperation( view->viewport(), QPEApplication::RightOnHold );    connect( view, SIGNAL( mouseButtonClicked( int, QListViewItem *, const QPoint &, int ) ),	     this, SLOT( fileClicked( int, QListViewItem *, const QPoint &, int ) ) );    connect( view, SIGNAL( mouseButtonPressed( int, QListViewItem *, const QPoint &, int ) ),	     this, SLOT( filePressed( int, QListViewItem *, const QPoint &, int ) ) );    connect( view, SIGNAL( returnPressed( QListViewItem * ) ),	     this, SLOT( fileClicked( QListViewItem * ) ) );    setFocusProxy( view );    QHBox *hb = new QHBox( this );    d->typeCombo = new TypeCombo( hb );    connect( d->typeCombo, SIGNAL(selected(const QString&)),	    this, SLOT(typeSelected(const QString&)) );    QWhatsThis::add( d->typeCombo, tr("Show documents of this type") );    Categories c;    c.load(categoryFileName());    QArray<int> vl( 0 );    d->catSelect = new CategorySelect( hb );    d->catSelect->setRemoveCategoryEdit( TRUE );    d->catSelect->setCategories( vl, "Document View", // No tr	tr("Document View") );    d->catSelect->setAllCategories( TRUE );    connect( d->catSelect, SIGNAL(signalSelected(int)), this, SLOT(catSelected(int)) );    QWhatsThis::add( d->catSelect, tr("Show documents in this category") );    setCloseVisible( closeVisible );    d->storage = new StorageInfo( this );    connect( d->storage, SIGNAL( disksChanged() ), SLOT( cardChanged() ) );    connect( qApp, SIGNAL(linkChanged(const QString&)), this, SLOT(linkChanged(const QString&)) );    updateWhatsThis();}/*!  Destroys the widget.*/FileSelector::~FileSelector(){    delete d;}/*!  Returns the number of files in the view. If this is zero, an editor  application might bypass the selector and immediately start with  a "new" document.*/int FileSelector::fileCount(){    if ( !d->files )	reread();    return d->files->children().count();}/*!  Calling this function is the programmatic equivalent of the user  pressing the "new" button.  \sa newSelected(), closeMe()*/void FileSelector::createNew(){    DocLnk f;    emit newSelected( f );    emit closeMe();}void FileSelector::fileClicked( int button, QListViewItem *i, const QPoint &, int ){    if ( !i )	return;    if ( button == Qt::LeftButton ) {	fileClicked( i );    }}void FileSelector::filePressed( int button, QListViewItem *i, const QPoint &, int ){    if ( !i || i == d->newDocItem )	return;    if ( button == Qt::RightButton ) {	DocLnk l = ((FileSelectorItem *)i)->file();	QPopupMenu pop( this );	pop.insertItem( tr("Delete"), 1 );	if ( pop.exec(QCursor::pos()) == 1 && 	     QPEMessageBox::confirmDelete( this, tr("Delete"), l.name() ) ) {	    l.removeFiles();	    // We get a linkChanged so rereading happens again	}    }}void FileSelector::fileClicked( QListViewItem *i ){    if ( !i )	return;    if ( i == d->newDocItem ) {	createNew();    } else {	emit fileSelected( ( (FileSelectorItem*)i )->file() );	emit closeMe();    }}void FileSelector::typeSelected( const QString &type ){    d->mimeFilters.clear();    QStringList subFilter = QStringList::split(";", type);    for( QStringList::Iterator it = subFilter.begin(); it != subFilter.end(); ++it )	d->mimeFilters.append( QRegExp(*it, FALSE, TRUE) );    updateView();    emit typeChanged();}void FileSelector::catSelected( int c ){    d->catId = c;    updateView();    emit categoryChanged();}void FileSelector::cardChanged(){    if ( isVisible() ) 	d->initReread( view, 200 );    else	d->needReread = TRUE;}void FileSelector::linkChanged( const QString & ){    if ( isVisible() ) 	d->initReread( view, 200 );    else	d->needReread = TRUE;}const DocLnk *FileSelector::selected(){    FileSelectorItem *item = (FileSelectorItem *)view->selectedItem();    if ( item && item != d->newDocItem ) {	qWarning( "Using the FileSelector::selected() function is deprecated.\nPlease remember to delete the returned object." );	return new DocLnk( item->file() );    }    return NULL;}/*!  \fn void FileSelector::fileSelected( const DocLnk &f )  This signal is emitted when the user selects a document.  \a f is the document.*//*!  \fn void FileSelector::newSelected( const DocLnk &f )  This signal is emitted when the user selects a "new" document.  \a f is a DocLnk for the document. You will need to set the type  of the document after copying it.*//*!  \fn void FileSelector::closeMe()  This signal is emitted when the user no longer needs to view the widget.*//*!  If \a b is TRUE a "new document" entry is visible; if \a b is FALSE  this entry is not visible and the user is unable to create new  documents from the dialog.*/void FileSelector::setNewVisible( bool b ){    if ( d->showNew != b ) {	d->showNew = b;	updateView();	updateWhatsThis();    }}/*!  If \a b is TRUE a "close" or "no document" button is visible; if \a  b is FALSE this button is not visible and the user is unable to  leave the dialog without creating or selecting a document.  This function is deprecated.*/void FileSelector::setCloseVisible( bool b ){    if (  b )	d->toolbar->show();    else	d->toolbar->hide();}/*!  Rereads the list of documents.*/void FileSelector::reread(){#ifdef Q_WS_QWS    delete d->files;    d->files = new DocLnkSet;    Global::findDocuments(d->files, filter);    d->typeCombo->reread( *d->files, filter );#endif    d->needReread = FALSE;    updateView();}void FileSelector::slotReread(){    reread();}void FileSelector::showEvent( QShowEvent *e ){    if ( d->needReread )	d->initReread( view, 0 );    QVBox::showEvent( e );}class AppLnkPriv : public AppLnk {public:    inline bool linkFileKnown() const    {	return !mLinkFile.isNull();    }};static inline bool linkFileKnown(const AppLnk* l){    return ((const AppLnkPriv*)l)->linkFileKnown();}static int compareDocLnk(const void* va, const void* vb){    const DocLnk* docB = *(const DocLnk**)va;    const DocLnk* docA = *(const DocLnk**)vb;    const QChar *a = docA->name().unicode();    const QChar *b = docB->name().unicode();    int alen = docA->name().length();    int blen = docB->name().length();    int l = alen < blen ? alen : blen;    while ( l-- && a->lower() == b->lower() )	a++,b++;    if ( l!=-1 ) {	QChar al = a->lower();	QChar bl = b->lower();	return al.unicode() - bl.unicode();    } else {	if ( alen == blen ) {	    QFileInfo fa(linkFileKnown(docA) ? docA->linkFile() : docA->file());	    QFileInfo fb(linkFileKnown(docB) ? docB->linkFile() : docB->file());	    return fa.lastModified().secsTo(fb.lastModified());	} else {	    return alen - blen; 	}    }}void FileSelector::updateView(){    FileSelectorItem *item = (FileSelectorItem *)view->selectedItem();    if ( item == d->newDocItem )	item = 0;    QString oldFile;    if ( item )	oldFile = item->file().file();    view->clear();    int ndocs = d->files->children().count();    QListIterator<DocLnk> dit( d->files->children() );    DocLnk* *doc = new DocLnk*[ndocs];    int i=0;    for ( ; dit.current(); ++dit ) {	doc[i++] = dit.current();    }    qsort(doc,ndocs,sizeof(doc[0]),compareDocLnk);    for ( i=0; i<ndocs; ++i ) {	bool mimeMatch = FALSE;	if ( d->mimeFilters.count() ) {	    QValueList<QRegExp>::Iterator it;	    for ( it = d->mimeFilters.begin(); it != d->mimeFilters.end(); ++it ) {		if ( (*it).match(doc[i]->type()) >= 0 ) {		    mimeMatch = TRUE;		    break;		}	    }	} else {	    mimeMatch = TRUE;	}	if ( mimeMatch &&		(d->catId == -2 || doc[i]->categories().contains(d->catId) ||		 (d->catId == -1 && doc[i]->categories().isEmpty())) ) {	    item = new FileSelectorItem( view, *doc[i] );	    if ( oldFile && item->fl.file() == oldFile )		view->setCurrentItem( item );	}    }    delete [] doc;    if ( d->showNew )	d->newDocItem = new NewDocItem( view, DocLnk() );    else 	d->newDocItem = 0;    if ( !view->selectedItem() || view->childCount() == 1 ) {	view->setCurrentItem( view->firstChild() );	view->setSelected( view->firstChild(), TRUE );    }}void FileSelector::updateWhatsThis(){    QWhatsThis::remove( this );    QString text = tr("Click to select a document from the list");    if ( d->showNew )	text += tr(", or select <b>New Document</b> to create a new document.");    text += tr("<br><br>Click and hold for document properties.");    QWhatsThis::add( this, text );}/*!    \fn const DocLnk *FileSelector::selected()    Returns a copy of the selected \link doclnk.html DocLnk\endlink which    must be deleted by the caller.    This function is deprecated. It will be removed in Qtopia 2.    Please switch to using \link selectedDocument() \endlink instead.*//*!    \fn DocLnk FileSelector::selectedDocument() const    Returns the selected \link doclnk.html DocLnk\endlink.*//*!    \fn QValueList<DocLnk> FileSelector::fileList() const    Returns the entire list of documents.*/#include "fileselector.moc"

⌨️ 快捷键说明

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