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

📄 fileselector.cpp

📁 Trolltech公司发布的图形界面操作系统。可在qt-embedded-2.3.7平台上编译为嵌入式图形界面操作系统。
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/************************************************************************ Copyright (C) 2000-2002 Trolltech AS.  All rights reserved.**** This file is part of the Qtopia Environment.**** This file may be distributed and/or modified under the terms of the** GNU General Public License version 2 as published by the Free Software** Foundation and appearing in the file LICENSE.GPL included in the** packaging of this file.**** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.**** See http://www.trolltech.com/gpl/ for GPL licensing information.**** Contact info@trolltech.com if any conditions of this licensing are** not clear to you.************************************************************************/#include "global.h"#include "fileselector.h"#include "fileselector_p.h"#include "resource.h"#include "config.h"#include "applnk.h"#include "storage.h"#include "qpemenubar.h"#ifdef Q_WS_QWS#include "qcopchannel_qws.h"#endif#include "applnk.h"#include "qpeapplication.h"#include "categorymenu.h"#include "categoryselect.h"#include "mimetype.h"#include "categories.h"#include "qpemessagebox.h"#include <stdlib.h>#include <qtimer.h>#include <qdir.h>#include <qwidget.h>#include <qregexp.h>#include <qpopupmenu.h>#include <qtoolbutton.h>#include <qpushbutton.h>#include <qheader.h>#include <qpainter.h>#include <qtooltip.h>#include <qwhatsthis.h>QIconSet qtopia_internal_loadIconSet( const QString &pix );class TypeCombo : public QComboBox{    Q_OBJECTpublic:    TypeCombo( QWidget *parent, const char *name=0 )	: QComboBox( parent, name )    {	setSizePolicy( QSizePolicy( QSizePolicy::Preferred, QSizePolicy::Preferred) );	connect( this, SIGNAL(activated(int)), this, SLOT(selectType(int)) );    }    void reread( DocLnkSet &files, const QString &filter );signals:    void selected( const QString & );protected slots:    void selectType( int idx ) {	emit selected( typelist[idx] );    }protected:    QStringList typelist;    QString prev;};void TypeCombo::reread( DocLnkSet &files, const QString &filter ){    typelist.clear();    QStringList filters = QStringList::split( ';', filter );    int pos = filter.find( '/' );    //### do for each filter    if ( filters.count() == 1 && pos >= 0 && filter[pos+1] != '*' ) {	typelist.append( filter );	clear();	QString minor = filter.mid( pos+1 );	minor[0] = minor[0].upper();	insertItem( tr("%1 files").arg(minor) );	setCurrentItem(0);	setEnabled( FALSE );	return;    }    QListIterator<DocLnk> dit( files.children() );    for ( ; dit.current(); ++dit ) {	if ( !typelist.contains( (*dit)->type() ) )	    typelist.append(  (*dit)->type() );    }    QStringList types;    QStringList::ConstIterator it;    for (it = typelist.begin(); it!=typelist.end(); ++it) {	QString t = *it;	if ( t.left(12) == "application/" ) {	    MimeType mt(t);	    const AppLnk* app = mt.application();	    if ( app )		t = app->name();	    else		t = t.mid(12);	} else {	    QString major, minor;	    int pos = t.find( '/' );	    if ( pos >= 0 ) {		major = t.left( pos );		minor = t.mid( pos+1 );	    }	    if ( minor.find( "x-" ) == 0 )		minor = minor.mid( 2 );	    minor[0] = minor[0].upper();	    major[0] = major[0].upper();	    if ( filters.count() > 1 )		t = tr("%1 %2", "minor mimetype / major mimetype").arg(minor).arg(major);	    else		t = minor;	}	types += tr("%1 files").arg(t);    }    for (it = filters.begin(); it!=filters.end(); ++it) {	typelist.append( *it );	int pos = (*it).find( '/' );	if ( pos >= 0 ) {	    QString maj = (*it).left( pos );	    maj[0] = maj[0].upper();	    types << tr("All %1 files").arg(maj);	}    }    if ( filters.count() > 1 ) {	typelist.append( filter );	types << tr("All files");    }    prev = currentText();    clear();    insertStringList(types);    for (int i=0; i<count(); i++) {	if ( text(i) == prev ) {	    setCurrentItem(i);	    break;	}    }    if ( prev.isNull() )	setCurrentItem(count()-1);    setEnabled( TRUE );}//===========================================================================FileSelectorItem::FileSelectorItem( QListView *parent, const DocLnk &f )    : QListViewItem( parent ), fl( f ){    setText( 0, f.name() );    setPixmap( 0, f.pixmap() );}FileSelectorItem::~FileSelectorItem(){}FileSelectorView::FileSelectorView( QWidget *parent, const char *name )    : QListView( parent, name ){    setAllColumnsShowFocus( TRUE );    addColumn( tr( "Name" ) );    header()->hide();}FileSelectorView::~FileSelectorView(){}void FileSelectorView::keyPressEvent( QKeyEvent *e ){    QString txt = e->text();    if (e->key() == Key_Space)	emit returnPressed( currentItem() );    else if ( !txt.isNull() && txt[0] > ' ' && e->key() < 0x1000 )	e->ignore();    else	QListView::keyPressEvent(e);}class NewDocItem : public FileSelectorItem{public:    NewDocItem( QListView *parent, const DocLnk &f )	: FileSelectorItem( parent, f ) {	setText( 0, FileSelector::tr("New Document") );	QImage img( Resource::loadImage( "new" ) );	QPixmap pm;	pm = img.smoothScale( AppLnk::smallIconSize(), AppLnk::smallIconSize() );	setPixmap( 0, pm );    }    QString key ( int, bool ) const {	return QString("\n");    }    void paintCell( QPainter *p, const QColorGroup &cg, int column, int width, int alignment ) {	QFont oldFont = p->font();	QFont newFont = p->font();	newFont.setWeight( QFont::Bold );	p->setFont( newFont );	FileSelectorItem::paintCell( p, cg, column, width, alignment );	p->setFont( oldFont );    }    int width( const QFontMetrics &fm, const QListView *v, int c ) const {	return FileSelectorItem::width( fm, v, c )*4/3; // allow for bold font    }};//===========================================================================class FileSelectorPrivate{public:    FileSelectorPrivate()    {	newDocItem = 0;	files = new DocLnkSet;    }    ~FileSelectorPrivate()    {	delete files;	// everything else is a subobject    }    void initReread( QListView *view, int timeout ) {	view->clear();	new QListViewItem( view, FileSelector::tr("Finding Documents...") );	rereadTimer->start( timeout, TRUE );    }    TypeCombo *typeCombo;    CategorySelect *catSelect;    QValueList<QRegExp> mimeFilters;    int catId;    bool showNew;    NewDocItem *newDocItem; // child of listview    DocLnkSet* files;    QHBox *toolbar;    StorageInfo *storage;    bool needReread;    QTimer *rereadTimer;};/*!  \class FileSelector fileselector.h  \brief The FileSelector widget allows the user to select DocLnk objects.  This class presents a file selection dialog to the user. This widget  is usually the first widget seen in a \link docwidget.html  document-oriented application\endlink. The developer will most often  create this widget in combination with a <a  href="qwidgetstack.html"> QWidgetStack</a> and the appropriate  editor and/or viewer widget for their application. This widget  should be shown first and the user can the select which document  they wish to operate on. Please refer to the implementation of  texteditor for an example of how to tie these classes together.  Use setNewVisible() depending on whether the application can be used  to create new files or not. Use setCloseVisible() depending on  whether the user may leave the dialog without creating or selecting  a document or not. The number of files in the view is available from  fileCount(). To force the view to be updated call reread().  If the user presses the 'New Document' button the newSelected()  signal is emitted. If the user selects an existing file the  fileSelected() signal is emitted. The selected file's \link  doclnk.html DocLnk\endlink is available from the selected()  function. If the file selector is no longer necessary the closeMe()  signal is emitted.  The typeChanged() and categoryChanged() signals are emitted when  either a different file type or category are selected. Note that  in Qtopia 1.5.0, there were no selectors for this, so these signals  are never emitted on that platform.  \ingroup qtopiaemb  \sa FileManager*//*! \fn void FileSelector::typeChanged(void)  This signal is emitted when a different file type is selected.*//*! \fn void FileSelector::categoryChanged(void)  This signal is emitted when a different category is selected.*//*!  Constructs a FileSelector with mime filter \a f.  The standard Qt \a parent and \a name parameters are passed to the  parent widget.  If \a newVisible is TRUE, the widget has a button to allow the user  the create "new" documents; this is useful for applications that can  create and edit documents but not suitable for applications that  only provide viewing.  \a closeVisible is deprecated  \sa DocLnkSet::DocLnkSet()*/FileSelector::FileSelector( const QString &f, QWidget *parent, const char *name, bool newVisible, bool closeVisible )    : QVBox( parent, name ), filter( f ){    setMargin( 0 );    setSpacing( 0 );    d = new FileSelectorPrivate();    d->showNew = newVisible;    d->catId = -2; // All files    d->files = 0;    d->toolbar = new QHBox( this );    d->toolbar->setBackgroundMode( PaletteButton );   // same colour as toolbars    d->toolbar->setSpacing( 0 );    d->toolbar->hide();    d->rereadTimer = new QTimer( this );    connect( d->rereadTimer, SIGNAL(timeout()), this, SLOT(slotReread()) );    d->needReread = TRUE;    QWidget *spacer = new QWidget( d->toolbar );    spacer->setBackgroundMode( PaletteButton );    QToolButton *tb = new QToolButton( d->toolbar );    tb->setIconSet( qtopia_internal_loadIconSet( "close" ) );    connect( tb, SIGNAL( clicked() ), this, SIGNAL( closeMe() ) );    buttonClose = tb;    tb->setFixedSize( 18, 20 ); // tb->sizeHint() );    tb->setAutoRaise( TRUE );    QToolTip::add( tb, tr( "Close the File Selector" ) );    QPEMenuToolFocusManager::manager()->addWidget( tb );    view = new FileSelectorView( this, "fileview" );    view->setSorting(-1);    view->setFrameStyle( QFrame::NoFrame );

⌨️ 快捷键说明

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