resource.cpp

来自「qt-x11-free-3.0.3.tar.gz minigui图形界面工具」· C++ 代码 · 共 1,943 行 · 第 1/5 页

CPP
1,943
字号
/************************************************************************ Copyright (C) 2000 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"#include "pixmapchooser.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 <qregexp.h>#include <zlib.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( QRegExp( "&" ), "&amp;" );    s2 = s2.replace( QRegExp( ">" ), "&gt;" );    s2 = s2.replace( QRegExp( "<" ), "&lt;" );    if ( attribute ) {	s2 = s2.replace( QRegExp( "\"" ), "&quot;" );	s2 = s2.replace( QRegExp( "'" ), "&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 ){    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 );    f.close();    return b;}#undef signals#undef slotsbool Resource::load( FormFile *ff, QIODevice* dev ){    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 );    toplevel = formwindow = new FormWindow( ff, mainwindow->qWorkspace(), 0 );    formwindow->setProject( MainWindow::self->currProject() );    formwindow->setMainWindow( mainwindow );    MetaDataBase::addEntry( formwindow );    if (!langIface) {	langIface = MetaDataBase::languageInterface( mainwindow->currProject()->language() );	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 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 functions = e;    while ( functions.tagName() != "functions" && !functions.isNull() )	functions = functions.nextSibling().toElement();    QDomElement widget;    while ( !e.isNull() ) {	if ( e.tagName() == "widget" ) {	    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 ( 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	    metaVariables << e.firstChild().toText().data();	} 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() );	}	e = e.nextSibling().toElement();    }    if ( !imageCollection.isNull() )	loadImageCollection( imageCollection );    if ( !customWidgets.isNull() )	loadCustomWidgets( customWidgets, this );#if defined (QT_NON_COMMERCIAL)    bool previewMode = MainWindow::self->isPreviewing();    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 );		}	    }    }    if ( !variables.isNull() ) {	for ( QDomElement n = variables.firstChild().toElement(); !n.isNull(); n = n.nextSibling().toElement() )	    if ( n.tagName() == "variable" )		metaVariables << n.firstChild().toText().data();    }    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::Slot slot;		slot.specifier = n.attribute( "specifier", "virtual" );		if ( slot.specifier.isEmpty() )		    slot.specifier = "virtual";		slot.access = n.attribute( "access", "public" );		if ( slot.access.isEmpty() )		    slot.access = "public";		slot.language = n.attribute( "language", "C++" );		slot.returnType = n.attribute( "returnType", "void" );		if ( slot.returnType.isEmpty() )		    slot.returnType = "void";		slot.slot = n.firstChild().toText().data();		if ( !MetaDataBase::hasSlot( formwindow, slot.slot, TRUE ) )		    MetaDataBase::addSlot( formwindow, slot.slot, slot.specifier,					   slot.access, slot.language, slot.returnType );		else		    MetaDataBase::changeSlotAttributes( formwindow, slot.slot,							slot.specifier, slot.access,							slot.language, slot.returnType );	    }    }    if ( !actions.isNull() )	loadActions( actions );    if ( !toolbars.isNull() )	loadToolBars( toolbars );    if ( !menubar.isNull() )	loadMenuBar( menubar );    if ( !connections.isNull() )	loadConnections( connections );    if ( !functions.isNull() )	loadFunctions( functions );    if ( !tabOrder.isNull() )	loadTabOrder( tabOrder );    if ( formwindow ) {	MetaDataBase::setIncludes( formwindow, metaIncludes );	MetaDataBase::setForwards( formwindow, metaForwards );	MetaDataBase::setVariables( formwindow, metaVariables );	MetaDataBase::setSignalList( formwindow, metaSignals );	metaInfo.classNameChanged = metaInfo.className != QString( formwindow->name() );	MetaDataBase::setMetaInfo( formwindow, metaInfo );

⌨️ 快捷键说明

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