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

📄 launcherview.cpp

📁 Trolltech公司发布的图形界面操作系统。可在qt-embedded-2.3.10平台上编译为嵌入式图形界面操作系统。
💻 CPP
📖 第 1 页 / 共 2 页
字号:
	r.append(it.currentKey());	++it;    }    r.sort();    return r;}LauncherItem* LauncherIconView::addItem(AppLnk* app, bool resort){    addCatsAndMimes(app);    LauncherItem *r=0;    if ( (tf.isEmpty() || tf.match(app->type()) >= 0)	 && (cf == -2 || app->categories().contains(cf)	     || cf == -1 && app->categories().count() == 0 ) )	r = new LauncherItem( this, app, bigIcns );    else	hidden.append(app);    if ( resort )	sort();    return r;}void LauncherIconView::updateCategoriesAndMimeTypes(){    mimes.clear();    LauncherItem* item = (LauncherItem*)firstItem();    while (item) {	addCatsAndMimes(item->appLnk());	item = (LauncherItem*)item->nextItem();    }    QListIterator<AppLnk> it(hidden);    AppLnk* l;    while ((l=it.current())) {	addCatsAndMimes(l);	++it;    }}void LauncherIconView::hideOrShowItems(bool resort){    viewport()->setUpdatesEnabled( FALSE );    hidden.setAutoDelete(FALSE);    QList<AppLnk> links=hidden;    hidden.clear();    hidden.setAutoDelete(TRUE);    LauncherItem* item = (LauncherItem*)firstItem();    LauncherItem* cur = (LauncherItem*)currentItem();    AppLnk *cura = cur ? cur->appLnk() : 0;    while (item) {	links.append(item->takeAppLnk());	item = (LauncherItem*)item->nextItem();    }    clear();    cur = 0;    QListIterator<AppLnk> it(links);    AppLnk* l;    while ((l=it.current())) {	LauncherItem *i = addItem(l,FALSE);	if ( l == cura )	    cur = i;	++it;    }    if ( resort && !autoArrange() )	sort();    setCurrentItem(cur);    viewport()->setUpdatesEnabled( TRUE );}bool LauncherIconView::removeLink(const QString& linkfile){    LauncherItem* item = (LauncherItem*)firstItem();    AppLnk* l;    bool did = FALSE;    DocLnk dl(linkfile);    while (item) {	l = item->appLnk();	LauncherItem *nextItem = (LauncherItem *)item->nextItem();	if (  l->linkFileKnown() && l->linkFile() == linkfile		|| l->fileKnown() && (		    l->file() == linkfile		    || dl.isValid() && dl.file() == l->file() ) ) {	    delete item;	    did = TRUE;	}	item = nextItem;    }    QListIterator<AppLnk> it(hidden);    while ((l=it.current())) {	++it;	if ( l->linkFileKnown() && l->linkFile() == linkfile		|| l->file() == linkfile		|| dl.isValid() && dl.file() == l->file() ) {	    hidden.removeRef(l);	   did = TRUE;	}    }    return did;}//===========================================================================LauncherView::LauncherView( QWidget* parent, const char* name, WFlags fl )    : QVBox( parent, name, fl ){    catmb = 0;    icons = new LauncherIconView( this );    setFocusProxy(icons);    QPEApplication::setStylusOperation( icons->viewport(), QPEApplication::RightOnHold );    icons->setItemsMovable( FALSE );    icons->setAutoArrange( TRUE );    icons->setSorting( TRUE );    icons->setFrameStyle( QFrame::NoFrame );    icons->setMargin( 0 );    icons->setSelectionMode( QIconView::NoSelection );    icons->setBackgroundMode( PaletteBase );    icons->setResizeMode( QIconView::Fixed );    vmode = (ViewMode)-1;    setViewMode( Icon );    connect( icons, SIGNAL(mouseButtonClicked(int,QIconViewItem*,const QPoint&)),		   SLOT(itemClicked(int,QIconViewItem*)) );    connect( icons, SIGNAL(selectionChanged()),		   SLOT(selectionChanged()) );    connect( icons, SIGNAL(returnPressed(QIconViewItem*)),		   SLOT(returnPressed(QIconViewItem*)) );    connect( icons, SIGNAL(mouseButtonPressed(int,QIconViewItem*,const QPoint&)),		   SLOT(itemPressed(int,QIconViewItem*)) );    tools = 0;    setBackgroundType( Ruled, QString::null );}LauncherView::~LauncherView(){    if ( bgCache && bgCache->contains( bgName ) )	(*bgCache)[bgName]->ref--;}void LauncherView::hideIcons(){    icons->hide();}void LauncherView::setToolsEnabled(bool y){    if ( !y != !tools ) {	if ( y ) {	    tools = new QHBox(this);	    // Type filter	    typemb = new QComboBox(tools);	    QSizePolicy p = typemb->sizePolicy();	    p.setHorData(QSizePolicy::Expanding);	    typemb->setSizePolicy(p);	    // Category filter	    updateTools();	    tools->show();	    // Always show vscrollbar	    icons->setVScrollBarMode( QScrollView::AlwaysOn );	} else {	    delete tools;	    tools = 0;	}    }}//needed for lupdatestatic const char* translatedMimeTypes[] = {    QT_TRANSLATE_NOOP("MimeType", "Image"),    QT_TRANSLATE_NOOP("MimeType", "Audio"),    QT_TRANSLATE_NOOP("MimeType", "Text"),    QT_TRANSLATE_NOOP("MimeType", "Video"),};void LauncherView::updateTools(){    disconnect( typemb, SIGNAL(activated(int)),	        this, SLOT(showType(int)) );    if ( catmb ) disconnect( catmb, SIGNAL(signalSelected(int)),	        this, SLOT(showCategory(int)) );    // ### I want to remove this    icons->updateCategoriesAndMimeTypes();    QString prev;    // Type filter    QStringList types;    typelist = icons->mimeTypes();    for (QStringList::ConstIterator 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 = Qtopia::dehyphenate(app->name());	    else		t = t.mid(12);	} else {	    t[0] = t[0].upper();            t = qApp->translate("MimeType", t.latin1());	}	types += t;    }    types << tr("All types");    prev = typemb->currentText();    typemb->clear();    typemb->insertStringList(types);    for (int i=0; i<typemb->count(); i++) {	if ( typemb->text(i) == prev ) {	    typemb->setCurrentItem(i);	    break;	}    }    if ( prev.isNull() )	typemb->setCurrentItem(typemb->count()-1);    int pcat = catmb ? catmb->currentCategory() : -2;    if ( !catmb )	catmb = new CategorySelect(tools);    Categories cats( 0 );    cats.load( categoryFileName() );    QArray<int> vl( 0 );    catmb->setCategories( vl, "Document View", // No tr	tr("Document View") );    catmb->setRemoveCategoryEdit( TRUE );    catmb->setAllCategories( TRUE );    catmb->setCurrentCategory(pcat);    // if type has changed we need to redisplay    if ( typemb->currentText() != prev )	showType( typemb->currentItem() );    connect(typemb, SIGNAL(activated(int)), this, SLOT(showType(int)));    connect(catmb, SIGNAL(signalSelected(int)), this, SLOT(showCategory(int)));}void LauncherView::sortBy(int s){    icons->setSortMethod((LauncherIconView::SortMethod)s);}void LauncherView::showType(int t){    if ( t >= (int)typelist.count() ) {	icons->setTypeFilter("",TRUE);    } else {	QString ty = typelist[t];	if ( !ty.contains('/') )	    ty += "/*";	icons->setTypeFilter(ty,TRUE);    }}void LauncherView::showType(const QString & t){    if (t.isEmpty()) {	icons->setTypeFilter("",TRUE);    } else {	QString ty(t);	if ( !ty.contains('/') )	    ty += "/*";	icons->setTypeFilter(ty,TRUE);    }}void LauncherView::showCategory( int c ){    icons->setCategoryFilter( c, TRUE );}void LauncherView::setViewMode( ViewMode m ){    if ( vmode != m ) {	bool bigIcons = m == Icon;	icons->viewport()->setUpdatesEnabled( FALSE );	icons->setBigIcons( bigIcons );	switch ( m ) {	    case List:		icons->setItemTextPos( QIconView::Right );		break;	    case Icon:		icons->setItemTextPos( QIconView::Bottom );		break;	}	icons->hideOrShowItems( FALSE );	icons->viewport()->setUpdatesEnabled( TRUE );	vmode = m;    }}//// User images may require scaling.//QImage LauncherView::loadBackgroundImage(QString &bgName){    QImageIO imgio;    QSize   ds = qApp->desktop()->size();   // should be launcher, not desktop    bool    further_scaling = TRUE;    imgio.setFileName( bgName );    imgio.setParameters("GetHeaderInformation");    if (imgio.read() == FALSE) {	return imgio.image();    }    if (imgio.image().width() < ds.width() &&	    imgio.image().height() < ds.height()) {	further_scaling = FALSE;    }    if (!imgio.image().bits()) {	//	// Scale and load.  Note we don't scale up.	//	QString param( "Scale( %1, %2, ScaleMin )" ); // No tr	imgio.setParameters(further_scaling ?	    param.arg(ds.width()).arg(ds.height()).latin1() :	    "");	imgio.read();    } else {	if (further_scaling) {	    int	t1 = imgio.image().width() * ds.height();	    int t2 = imgio.image().height() * ds.width();	    int dsth = ds.height();	    int dstw = ds.width();	    if (t1 > t2) {		dsth = t2 / imgio.image().width();	    } else {		dstw = t1 / imgio.image().height();	    }	    //	    // Loader didn't scale for us.  Do it manually.	    //	    return imgio.image().smoothScale(dstw, dsth);	}    }    return imgio.image();}void LauncherView::setBackgroundType( BackgroundType t, const QString &val ){    bgType = t;    bgValue = val;    if (icons->hasStaticBackground())	return;    if ( !bgCache ) {	bgCache = new QMap<QString,BgPixmap*>;	qAddPostRoutine( cleanup_cache );    }    if ( bgCache->contains( bgName ) )	(*bgCache)[bgName]->ref--;    bgName = "";    QPixmap bg;    switch ( t ) {	case Ruled: {	    bgName = QString("Ruled_%1").arg(colorGroup().background().name()); // No tr	    if ( bgCache->contains( bgName ) ) {		(*bgCache)[bgName]->ref++;		bg = (*bgCache)[bgName]->pm;	    } else {		bg.resize( width(), 9 );		QPainter painter( &bg );		for ( int i = 0; i < 3; i++ ) {		    painter.setPen( white );		    painter.drawLine( 0, i*3, width()-1, i*3 );		    painter.drawLine( 0, i*3+1, width()-1, i*3+1 );		    painter.setPen( colorGroup().background().light(105) );		    painter.drawLine( 0, i*3+2, width()-1, i*3+2 );		}		painter.end();		bgCache->insert( bgName, new BgPixmap(bg) );	    }	    break;	}	case Image:	    if (!val.isEmpty()) {		bgName = val;		if ( bgCache->contains( bgName ) ) {		    (*bgCache)[bgName]->ref++;		    bg = (*bgCache)[bgName]->pm;		} else {		    QString imgFile = bgName;		    bool tile = FALSE;		    if ( imgFile[0]!='/' || !QFile::exists(imgFile) ) {			imgFile = Resource::findPixmap( "wallpaper/" + imgFile );			tile = TRUE;		    }		    QImage img = loadBackgroundImage(imgFile);		    if ( img.depth() == 1 )			img = img.convertDepth(8);		    img.setAlphaBuffer(FALSE);		    bg.convertFromImage(img);		    bgCache->insert( bgName, new BgPixmap(bg) );		}	    }	    break;	case SolidColor:	default:	    break;    }    const QObjectList *list = queryList( "QWidget", 0, FALSE );    QObject *obj;    for ( QObjectListIt it( *list ); (obj=it.current()); ++it ) {	if ( obj->isWidgetType() ) {	    QWidget *w = (QWidget*)obj;	    w->setBackgroundPixmap( bg );	    if ( bgName.isEmpty() ) {		// Solid Color		if ( val.isEmpty() ) 		    w->setBackgroundColor( colorGroup().base() );		else 		    w->setBackgroundColor( val );	    } else {		// Ruled or Image pixmap		w->setBackgroundOrigin( ParentOrigin );	    }	}    }    delete list;    icons->viewport()->update();    QTimer::singleShot( 1000, this, SLOT(flushBgCache()) );}void LauncherView::setStaticBackground(const QPixmap &pm){    if (pm.isNull()) {	if (icons->hasStaticBackground()) {	    icons->setStaticBackground(FALSE);	    setBackgroundType(bgType, bgValue);	}    } else {	icons->setStaticBackground(TRUE);	icons->setBackgroundPixmap(pm);	icons->viewport()->setBackgroundMode(NoBackground);	icons->viewport()->update();    }}void LauncherView::setTextColor( const QColor &tc ){    textCol = tc;    QColorGroup cg = icons->colorGroup();    cg.setColor( QColorGroup::Text, tc );    icons->setPalette( QPalette(cg,cg,cg) );    icons->viewport()->update();}void LauncherView::setViewFont( const QFont &f ){    icons->setFont( f );    icons->hideOrShowItems( FALSE );}void LauncherView::clearViewFont(){    icons->unsetFont();    icons->hideOrShowItems( FALSE );}void LauncherView::resizeEvent(QResizeEvent *e){    QVBox::resizeEvent( e );    if ( e->size().width() != e->oldSize().width() )	sort();}void LauncherView::selectionChanged(){    QIconViewItem* item = icons->currentItem();    if ( item && item->isSelected() ) {	AppLnk *appLnk = ((LauncherItem *)item)->appLnk();	if ( icons->inKeyEvent() ) // not for mouse press	    emit clicked( appLnk );	item->setSelected(FALSE);    }}void LauncherView::returnPressed( QIconViewItem *item ){    if ( item ) {	AppLnk *appLnk = ((LauncherItem *)item)->appLnk();	emit clicked( appLnk );    }}void LauncherView::itemClicked( int btn, QIconViewItem *item ){    if ( item ) {	AppLnk *appLnk = ((LauncherItem *)item)->appLnk();	if ( btn == LeftButton ) {	    QTOPIA_PROFILE("icon clicked");	    // Make sure it's the item we execute that gets highlighted	    icons->setCurrentItem( item );	    emit clicked( appLnk );	}	item->setSelected(FALSE);    }}void LauncherView::itemPressed( int btn, QIconViewItem *item ){    if ( item ) {	AppLnk *appLnk = ((LauncherItem *)item)->appLnk();	item->setSelected(FALSE);	if ( btn == RightButton )	    emit rightPressed( appLnk );	else if ( btn == ShiftButton )	    emit rightPressed( appLnk );    }}void LauncherView::removeAllItems(){    icons->clear();}bool LauncherView::removeLink(const QString& linkfile){    return icons->removeLink(linkfile);}void LauncherView::setSortEnabled( bool v ){    icons->setSorting( v );    if ( v )	sort();}void LauncherView::setUpdatesEnabled( bool u ){    icons->setUpdatesEnabled( u );}void LauncherView::sort(){    icons->sort();#ifdef QTOPIA_PHONE    if ( !icons->currentItem() )	icons->setCurrentItem(icons->firstItem());#endif}void LauncherView::addItem(AppLnk* app, bool resort){    icons->addItem(app,resort);}void LauncherView::paletteChange( const QPalette &p ){    icons->unsetPalette();    QVBox::paletteChange( p );    if ( bgType == Ruled )	setBackgroundType( Ruled, QString::null );    QColorGroup cg = colorGroup();    cg.setColor( QColorGroup::Text, textCol );    icons->setPalette( QPalette(cg,cg,cg) );}void LauncherView::fontChange(const QFont&){    icons->hideOrShowItems( FALSE );}void LauncherView::relayout(void){    icons->hideOrShowItems(FALSE);}void LauncherView::flushBgCache(){    if ( !bgCache )	return;    // remove unreferenced backgrounds.    QMap<QString,BgPixmap*>::Iterator it = bgCache->begin();    while ( it != bgCache->end() ) {	QMap<QString,BgPixmap*>::Iterator curr = it;	++it;	if ( (*curr)->ref == 0 ) {	    delete (*curr);	    bgCache->remove( curr );	}    }}void LauncherView::resetSelection(){    if (icons->firstItem()) {	icons->setCurrentItem(icons->firstItem());	icons->setContentsPos(0,0);    }}QStringList LauncherView::mimeTypes() const{    return icons->mimeTypes();}const AppLnk *LauncherView::currentItem() const{    QIconViewItem* item = icons->currentItem();    if (item)	return ((LauncherItem *)item)->appLnk();    return 0;}uint LauncherView::count() const{    return icons->count();}#include "launcherview.moc"

⌨️ 快捷键说明

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