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

📄 mainwindowactions.cpp

📁 这个是Linux的qt源代码
💻 CPP
📖 第 1 页 / 共 5 页
字号:
    actionHelpRegister->addTo( menu );#endif    menu->insertSeparator();    actionHelpWhatsThis->addTo( menu );}void MainWindow::fileNew(){    statusBar()->message( tr( "Create a new project, form or source file...") );    NewForm dlg( this, projectNames(), currentProject->projectName(), templatePath() );    dlg.exec();    statusBar()->clear();}void MainWindow::fileNewDialog(){    static int forms = 0;    QString n = "Dialog" + QString::number( ++forms );    while ( currentProject->findFormFile( n + ".ui" ) )	n = "Dialog" + QString::number( ++forms );    FormWindow *fw = 0;    FormFile *ff = new FormFile( n + ".ui", FALSE, currentProject );    fw = new FormWindow( ff, MainWindow::self, MainWindow::self->qWorkspace(), n );    ff->setModified( TRUE );    currentProject->setModified( TRUE );    workspace()->update();    fw->setProject( currentProject );    MetaDataBase::addEntry( fw );    QWidget *w = WidgetFactory::create( WidgetDatabase::idFromClassName( "QDialog" ), fw, n.latin1() );    fw->setMainContainer( w );    fw->setCaption( n );    fw->resize( 600, 480 );    insertFormWindow( fw );    fw->killAccels( fw );    fw->project()->setModified( TRUE );    fw->setFocus();    fw->setSavePixmapInProject( TRUE );    fw->setSavePixmapInline( FALSE );}void MainWindow::fileNewFile(){    QString name = QInputDialog::getText( tr( "Name of File" ), tr( "Enter the name of the new source file:" ) );    if ( name.isEmpty() )	return;    if ( name.right( 3 ) != ".qs" )	name += ".qs";    SourceFile *f = new SourceFile( name, FALSE, currentProject );    MainWindow::self->editSource( f );    f->setModified( TRUE );    currentProject->setModified( TRUE );    workspace()->update();}void MainWindow::fileQuit(){    close();    if ( !singleProjectMode() )	qApp->closeAllWindows();}void MainWindow::fileClose(){    if ( !currentProject->isDummy() ) {	fileCloseProject();    } else {	QWidget *w = qworkspace->activeWindow();	if ( w ) {	    if ( w->inherits( "FormWindow" ) )		( (FormWindow*)w )->formFile()->close();	    else if ( w->inherits( "SourceEditor" ) )		( (SourceEditor*)w )->close();	}    }}void MainWindow::fileCloseProject(){    if ( currentProject->isDummy() )	return;    Project *pro = currentProject;    QAction* a = 0;    QAction* lastValid = 0;    for ( QMap<QAction*, Project* >::Iterator it = projects.begin(); it != projects.end(); ++it ) {	if ( it.data() == pro ) {	    a = it.key();	    if ( lastValid )		break;	}	lastValid = it.key();    }    if ( a ) {	if ( pro->isModified() ) {	    switch ( QMessageBox::warning( this, tr( "Save Project Settings" ),					   tr( "Save changes to '%1'?" ).arg( pro->fileName() ),					   tr( "&Yes" ), tr( "&No" ), tr( "&Cancel" ), 0, 2 ) ) {	    case 0: // save		pro->save();		break;	    case 1: // don't save		break;	    case 2: // cancel		return;	    default:		break;	    }	}	QWidgetList windows = qWorkspace()->windowList();	qWorkspace()->blockSignals( TRUE );	QWidgetListIt wit( windows );	while ( wit.current() ) {	    QWidget *w = wit.current();	    ++wit;	    if ( w->inherits( "FormWindow" ) ) {		if ( ( (FormWindow*)w )->project() == pro ) {		    if ( ( (FormWindow*)w )->formFile()->editor() )			windows.removeRef( ( (FormWindow*)w )->formFile()->editor() );		    if ( !( (FormWindow*)w )->formFile()->close() )			return;		}	    } else if ( w->inherits( "SourceEditor" ) ) {		if ( !( (SourceEditor*)w )->close() )		    return;	    }	}	hierarchyView->clear();	windows = qWorkspace()->windowList();	qWorkspace()->blockSignals( FALSE );	actionGroupProjects->removeChild( a );	projects.remove( a );	delete a;	currentProject = 0;	if ( lastValid ) {	    projectSelected( lastValid );	    statusBar()->message( "Selected project '" + tr( currentProject->projectName() + "'") );	}	if ( !windows.isEmpty() ) {	    for ( QWidget *w = windows.first(); w; w = windows.next() ) {		if ( !w->inherits( "FormWindow" ) )		    continue;		w->setFocus();		activeWindowChanged( w );		break;	    }	} else {	    emit hasActiveWindow( FALSE );	    emit hasActiveForm( FALSE );	    updateUndoRedo( FALSE, FALSE, QString::null, QString::null );	}    }}void MainWindow::fileOpen() // as called by the menu{    fileOpen( "", "", "", FALSE );}void MainWindow::projectInsertFile(){    fileOpen( "", "" );}void MainWindow::fileOpen( const QString &filter, const QString &extension, const QString &fn, bool inProject  ){    statusBar()->message( tr( "Open a file...") );    QPluginManager<ImportFilterInterface> manager( IID_ImportFilter, QApplication::libraryPaths(), pluginDirectory() );    Project* project = inProject ? currentProject : eProject;    QStringList additionalSources;    {	QStringList filterlist;	if ( filter.isEmpty() ) {	    if ( !inProject )		filterlist << tr( "Designer Files (*.ui *.pro)" );	    filterlist << tr( "Qt User-Interface Files (*.ui)" );	    if ( !inProject )		filterlist << tr( "QMAKE Project Files (*.pro)" );	    QStringList list = manager.featureList();	    for ( QStringList::Iterator it = list.begin(); it != list.end(); ++it )		filterlist << *it;	    LanguageInterface *iface = MetaDataBase::languageInterface( project->language() );	    if ( iface ) {		filterlist +=  iface->fileFilterList();		additionalSources += iface->fileExtensionList();	    }	    filterlist << tr( "All Files (*)" );	} else {	    filterlist << filter;	}	QString filters = filterlist.join( ";;" );	QStringList filenames;	if ( fn.isEmpty() ) {	    if ( !inProject ) {		QString f = QFileDialog::getOpenFileName( QString::null, filters, this, 0,							  tr("Open" ), &lastOpenFilter );		filenames << f;	    } else {		filenames = QFileDialog::getOpenFileNames( filters, QString::null, this, 0,							   tr("Add"), &lastOpenFilter );	    }	} else {	    filenames << fn;	}	for ( QStringList::Iterator fit = filenames.begin(); fit != filenames.end(); ++fit ) {	    QString filename = *fit;	    if ( !filename.isEmpty() ) {		QFileInfo fi( filename );		if ( fi.extension( FALSE ) == "pro" && ( extension.isEmpty() || extension.find( ";pro" ) != -1 ) ) {		    addRecentlyOpened( filename, recentlyProjects );		    openProject( filename );		} else if ( fi.extension( FALSE ) == "ui" && ( extension.isEmpty() || extension.find( ";ui" ) != -1 ) ) {		    if ( !inProject )			setCurrentProject( eProject );		    openFormWindow( filename );		    addRecentlyOpened( filename, recentlyFiles );		} else if ( !extension.isEmpty() && extension.find( ";" + fi.extension( FALSE ) ) != -1 ||			    additionalSources.find( fi.extension( FALSE ) ) != additionalSources.end() ) {		    SourceFile *sf = project->findSourceFile( project->makeRelative( filename ) );		    if ( !sf )			sf = new SourceFile( project->makeRelative( filename ), FALSE, project );		    editSource( sf );		} else if ( extension.isEmpty() ) {		    QString filter;		    for ( QStringList::Iterator it2 = filterlist.begin(); it2 != filterlist.end(); ++it2 ) {			if ( (*it2).contains( "." + fi.extension( FALSE ), FALSE ) ) {			    filter = *it2;			    break;			}		    }		    ImportFilterInterface* iface = 0;		    manager.queryInterface( filter, &iface );		    if ( !iface ) {			statusBar()->message( tr( "No import filter is available to import '%1'").					      arg( filename ), 3000 );			return;		    }		    statusBar()->message( tr( "Importing '%1' using import filter ...").arg( filename ) );		    QStringList list = iface->import( filter, filename );		    iface->release();		    if ( list.isEmpty() ) {			statusBar()->message( tr( "Nothing to load in '%1'").arg( filename ), 3000 );			return;		    }		    if ( !inProject )			setCurrentProject( eProject );		    addRecentlyOpened( filename, recentlyFiles );		    for ( QStringList::Iterator it = list.begin(); it != list.end(); ++it ) {			openFormWindow( *it, FALSE );			QFile::remove( *it );		    }		    statusBar()->clear();		}	    }	}    }}FormWindow *MainWindow::openFormWindow( const QString &filename, bool validFileName, FormFile *ff ){    if ( filename.isEmpty() )	return 0;    bool makeNew = FALSE;    if ( !QFile::exists( filename ) ) {	makeNew = TRUE;    } else {	QFile f( filename );	f.open( IO_ReadOnly );	QTextStream ts( &f );	makeNew = ts.read().length() < 2;    }    if ( makeNew ) {	fileNew();	if ( formWindow() )	    formWindow()->setFileName( filename );	return formWindow();    }    statusBar()->message( tr( "Reading file '%1'...").arg( filename ) );    FormFile *ff2 = currentProject->findFormFile( currentProject->makeRelative(filename) );    if ( ff2 && ff2->formWindow() ) {	ff2->formWindow()->setFocus();	return ff2->formWindow();    }    if ( ff2 )	ff = ff2;    QApplication::setOverrideCursor( WaitCursor );    Resource resource( this );    if ( !ff )	ff = new FormFile( currentProject->makeRelative( filename ), FALSE, currentProject );    bool b = resource.load( ff ) && (FormWindow*)resource.widget();    if ( !validFileName && resource.widget() )	( (FormWindow*)resource.widget() )->setFileName( QString::null );    QApplication::restoreOverrideCursor();    if ( b ) {	rebuildCustomWidgetGUI();	statusBar()->message( tr( "Loaded file '%1'").arg( filename ), 3000 );    } else {	statusBar()->message( tr( "Failed to load file '%1'").arg( filename ), 5000 );	QMessageBox::information( this, tr("Load File"), tr("Couldn't load file '%1'").arg( filename ) );	delete ff;    }    return (FormWindow*)resource.widget();}bool MainWindow::fileSave(){    if ( !currentProject->isDummy() )	return fileSaveProject();    return fileSaveForm();}bool MainWindow::fileSaveForm(){    for ( SourceEditor *e = sourceEditors.first(); e; e = sourceEditors.next() ) {	if ( e->object() == formWindow() || e == qWorkspace()->activeWindow() ) {	    e->save();	}    }    FormWindow *fw = 0;    QWidget *w = qWorkspace()->activeWindow();    if ( w ) {

⌨️ 快捷键说明

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