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

📄 resource.cpp

📁 Linux下的基于X11的图形开发环境。
💻 CPP
📖 第 1 页 / 共 5 页
字号:
/************************************************************************ Copyright (C) 2000-2002 Trolltech AS.  All rights reserved.**** This file is part of Qt Designer.**** 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 <qmenudata.h>#include "resource.h"#include "defs.h"#include "metadatabase.h"#include "formwindow.h"#include "mainwindow.h"#include "qdom.h"#include <widgetdatabase.h>#include "widgetfactory.h"#include "layout.h"#include <domtool.h>#include "command.h"#ifndef QT_NO_SQL#include "database.h"#endif#include "actiondnd.h"#include "project.h"#include "pixmapcollection.h"#include "formfile.h"#include <qfeatures.h>#include <qfile.h>#include <qtextstream.h>#include <qobject.h>#include <qwidget.h>#include <qobjectlist.h>#include <qmetaobject.h>#include <qworkspace.h>#include <qtabwidget.h>#include <qapplication.h>#include <qbuffer.h>#include <qlayout.h>#include <qtooltip.h>#include <qwhatsthis.h>#include <qtabwidget.h>#include <qlistbox.h>#include <qcombobox.h>#include <qwidgetstack.h>#include <qtabbar.h>#include <qheader.h>#include <qlistview.h>#include <qiconview.h>#include <qlabel.h>#include <qwizard.h>#include <qtextcodec.h>#include <qdatetime.h>#ifndef QT_NO_TABLE#include <qtable.h>#endifstatic QString makeIndent( int indent ){    QString s;    s.fill( ' ', indent * 4 );    return s;}static QString entitize( const QString &s, bool attribute = FALSE ){    QString s2 = s;    s2 = s2.replace( "&", "&amp;" );    s2 = s2.replace( ">", "&gt;" );    s2 = s2.replace( "<", "&lt;" );    if ( attribute ) {	s2 = s2.replace( "\"", "&quot;" );	s2 = s2.replace( "'", "&apos;" );    }    return s2;}static QString mkBool( bool b ){    return b? "true" : "false";}/*!  \class Resource resource.h  \brief Class for saving/loading, etc. forms  This class is used for saving and loading forms, code generation,  transferring data of widgets over the clipboard, etc..*/Resource::Resource(){    mainwindow = 0;    formwindow = 0;    toplevel = 0;    copying = FALSE;    pasting = FALSE;    hadGeometry = FALSE;    langIface = 0;    hasFunctions = FALSE;}Resource::Resource( MainWindow* mw )    : mainwindow( mw ){    formwindow = 0;    toplevel = 0;    copying = FALSE;    pasting = FALSE;    hadGeometry = FALSE;    langIface = 0;    hasFunctions = FALSE;}Resource::~Resource(){    if ( langIface )	langIface->release();}void Resource::setWidget( FormWindow *w ){    formwindow = w;    toplevel = w;}QWidget *Resource::widget() const{    return toplevel;}bool Resource::load( FormFile *ff, Project *defProject ){    if ( !ff || ff->absFileName().isEmpty() )	return FALSE;    currFileName = ff->absFileName();    mainContainerSet = FALSE;    QFile f( ff->absFileName() );    f.open( IO_ReadOnly );    bool b = load( ff, &f, defProject );    f.close();    return b;}#undef signals#undef slotsbool Resource::load( FormFile *ff, QIODevice* dev, Project *defProject ){    QDomDocument doc;    QString errMsg;    int errLine;    if ( !doc.setContent( dev, &errMsg, &errLine ) ) {	qDebug( QString("Parse error: ") + errMsg + QString(" in line %d"), errLine );	return FALSE;    }    DomTool::fixDocument( doc );    QWidget *p = mainwindow ? mainwindow->qWorkspace() : 0;    toplevel = formwindow = new FormWindow( ff, p, 0 );    if ( defProject )	formwindow->setProject( defProject );    else if ( MainWindow::self )	formwindow->setProject( MainWindow::self->currProject() );    if ( mainwindow )	formwindow->setMainWindow( mainwindow );    MetaDataBase::addEntry( formwindow );    if ( !langIface ) {	QString lang = "Qt Script";	if ( mainwindow )	    lang = mainwindow->currProject()->language();	langIface = MetaDataBase::languageInterface( lang );	if ( langIface )	    langIface->addRef();    }    QDomElement e = doc.firstChild().toElement().firstChild().toElement();    QDomElement forwards = e;    while ( forwards.tagName() != "forwards" && !forwards.isNull() )	forwards = forwards.nextSibling().toElement();    QDomElement includes = e;    while ( includes.tagName() != "includes" && !includes.isNull() )	includes = includes.nextSibling().toElement();    QDomElement variables = e;    while ( variables.tagName() != "variables" && !variables.isNull() )	variables = variables.nextSibling().toElement();    QDomElement signals = e;    while ( signals.tagName() != "signals" && !signals.isNull() )	signals = signals.nextSibling().toElement();    QDomElement slots = e;    while ( slots.tagName() != "slots" && !slots.isNull() )	slots = slots.nextSibling().toElement();    QDomElement functions = e;    while ( functions.tagName() != "functions" && !functions.isNull() )	functions = functions.nextSibling().toElement();    QDomElement connections = e;    while ( connections.tagName() != "connections" && !connections.isNull() )	connections = connections.nextSibling().toElement();    QDomElement imageCollection = e;    images.clear();    while ( imageCollection.tagName() != "images" && !imageCollection.isNull() )	imageCollection = imageCollection.nextSibling().toElement();    QDomElement customWidgets = e;    while ( customWidgets.tagName() != "customwidgets" && !customWidgets.isNull() )	customWidgets = customWidgets.nextSibling().toElement();    QDomElement tabOrder = e;    while ( tabOrder.tagName() != "tabstops" && !tabOrder.isNull() )	tabOrder = tabOrder.nextSibling().toElement();    QDomElement actions = e;    while ( actions.tagName() != "actions" && !actions.isNull() )	actions = actions.nextSibling().toElement();    QDomElement toolbars = e;    while ( toolbars.tagName() != "toolbars" && !toolbars.isNull() )	toolbars = toolbars.nextSibling().toElement();    QDomElement menubar = e;    while ( menubar.tagName() != "menubar" && !menubar.isNull() )	menubar = menubar.nextSibling().toElement();    QDomElement widget;    while ( !e.isNull() ) {	if ( e.tagName() == "widget" ) {	    widgets.clear();	    widget = e;	} else if ( e.tagName() == "include" ) { // compatibility with 2.x	    MetaDataBase::Include inc;	    inc.location = "global";	    if ( e.attribute( "location" ) == "local" )		inc.location = "local";	    inc.implDecl = "in declaration";	    if ( e.attribute( "impldecl" ) == "in implementation" )		inc.implDecl = "in implementation";	    inc.header = e.firstChild().toText().data();	    if ( inc.header.right( 5 ) != ".ui.h" ) {		metaIncludes.append( inc );	    } else {		if ( formwindow->formFile() )		    formwindow->formFile()->setCodeFileState( FormFile::Ok );	    }	} else if ( e.tagName() == "comment" ) {	    metaInfo.comment = e.firstChild().toText().data();	} else if ( e.tagName() == "forward" ) { // compatibility with old betas	    metaForwards << e.firstChild().toText().data();	} else if ( e.tagName() == "variable" ) { // compatibility with old betas	    MetaDataBase::Variable v;	    v.varName = e.firstChild().toText().data();	    v.varAccess = "protected";	    metaVariables << v;	} else if ( e.tagName() == "author" ) {	    metaInfo.author = e.firstChild().toText().data();	} else if ( e.tagName() == "class" ) {	    metaInfo.className = e.firstChild().toText().data();	} else if ( e.tagName() == "pixmapfunction" ) {	    if ( formwindow ) {		formwindow->setSavePixmapInline( FALSE );		formwindow->setSavePixmapInProject( FALSE );		formwindow->setPixmapLoaderFunction( e.firstChild().toText().data() );	    }	} else if ( e.tagName() == "pixmapinproject" ) {	    if ( formwindow ) {		formwindow->setSavePixmapInline( FALSE );		formwindow->setSavePixmapInProject( TRUE );	    }	} else if ( e.tagName() == "exportmacro" ) {	    exportMacro = e.firstChild().toText().data();	} else if ( e.tagName() == "layoutdefaults" ) {	    formwindow->setLayoutDefaultSpacing( e.attribute( "spacing", QString::number( formwindow->layoutDefaultSpacing() ) ).toInt() );	    formwindow->setLayoutDefaultMargin( e.attribute( "margin", QString::number( formwindow->layoutDefaultMargin() ) ).toInt() );	} else if ( e.tagName() == "layoutfunctions" ) {	    formwindow->setSpacingFunction( e.attribute( "spacing" ) );	    formwindow->setMarginFunction( e.attribute( "margin" ) );	    if ( !formwindow->marginFunction().isEmpty() || !formwindow->spacingFunction().isEmpty() )		formwindow->hasLayoutFunctions( TRUE );	}	e = e.nextSibling().toElement();    }    if ( !imageCollection.isNull() )	loadImageCollection( imageCollection );    if ( !customWidgets.isNull() )	loadCustomWidgets( customWidgets, this );#if defined (QT_NON_COMMERCIAL)    bool previewMode = MainWindow::self ? MainWindow::self->isPreviewing() : FALSE;    QWidget *w = (QWidget*)createObject( widget, !previewMode ? (QWidget*)formwindow : MainWindow::self );    if ( !w )	return FALSE;    if ( previewMode )	w->reparent( MainWindow::self, Qt::WType_TopLevel,  w->pos(), TRUE );#else    if ( !createObject( widget, formwindow) )	return FALSE;#endif    if ( !forwards.isNull() ) {	for ( QDomElement n = forwards.firstChild().toElement(); !n.isNull(); n = n.nextSibling().toElement() )	    if ( n.tagName() == "forward" )		metaForwards << n.firstChild().toText().data();    }    if ( !includes.isNull() ) {	for ( QDomElement n = includes.firstChild().toElement(); !n.isNull(); n = n.nextSibling().toElement() )	    if ( n.tagName() == "include" ) {		if ( n.tagName() == "include" ) {		    MetaDataBase::Include inc;		    inc.location = "global";		    if ( n.attribute( "location" ) == "local" )			inc.location = "local";		    inc.implDecl = "in declaration";		    if ( n.attribute( "impldecl" ) == "in implementation" )			inc.implDecl = "in implementation";		    inc.header = n.firstChild().toText().data();		    if ( inc.header.right( 5 ) != ".ui.h" ) {			metaIncludes.append( inc );		    } else {			if ( formwindow->formFile() )			    formwindow->formFile()->setCodeFileState( FormFile::Ok );		    }		}	    }    }    if ( !variables.isNull() ) {	for ( QDomElement n = variables.firstChild().toElement(); !n.isNull();	      n = n.nextSibling().toElement() ) {	    if ( n.tagName() == "variable" ) {		MetaDataBase::Variable v;		v.varName = n.firstChild().toText().data();		v.varAccess = n.attribute( "access", "protected" );		if ( v.varAccess.isEmpty() )		    v.varAccess = "protected";		metaVariables << v;	    }	}    }    if ( !signals.isNull() ) {	for ( QDomElement n = signals.firstChild().toElement(); !n.isNull(); n = n.nextSibling().toElement() )	    if ( n.tagName() == "signal" )		metaSignals << n.firstChild().toText().data();    }    if ( !slots.isNull() ) {	for ( QDomElement n = slots.firstChild().toElement(); !n.isNull(); n = n.nextSibling().toElement() )	    if ( n.tagName() == "slot" ) {		MetaDataBase::Function function;		function.specifier = n.attribute( "specifier", "virtual" );		if ( function.specifier.isEmpty() )		    function.specifier = "virtual";

⌨️ 快捷键说明

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