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

📄 resource.cpp

📁 Qt/Embedded是一个多平台的C++图形用户界面应用程序框架
💻 CPP
📖 第 1 页 / 共 5 页
字号:
/************************************************************************ 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 "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"#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 <zlib.h>static QString makeIndent( int indent ){    QString s;    s.fill( ' ', indent * 4 );    return s;}static QString entitize( const QString &s ){    QString s2 = s;#if 0 // don't need that (RS)    s2 = s2.replace( QRegExp( "\"" ), "&quot;" );    s2 = s2.replace( QRegExp( "'" ), "&apos;" );#endif    s2 = s2.replace( QRegExp( "&" ), "&amp;" );    s2 = s2.replace( QRegExp( ">" ), "&gt;" );    s2 = s2.replace( QRegExp( "<" ), "&lt;" );    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( QStyle* s, QPalette* p )    : style( s ), pal( p ){    mainwindow = 0;    previewMode = TRUE;    formwindow = 0;    toplevel = 0;    copying = FALSE;    pasting = FALSE;}Resource::Resource( MainWindow* mw, QStyle* s, QPalette* p )    : mainwindow( mw ), style( s ), pal( p ){    formwindow = 0;    toplevel = 0;    previewMode = FALSE;    copying = FALSE;    pasting = FALSE;}void Resource::setWidget( FormWindow *w ){    formwindow = w;    toplevel = w;}QWidget *Resource::widget() const{    return toplevel;}bool Resource::load( const QString& filename ){    if ( filename.isEmpty() )	return FALSE;    mainContainerSet = FALSE;    QFile f( filename );    f.open( IO_ReadOnly );    bool b = load( &f );    f.close();    if ( formwindow )	formwindow->setFileName( filename );    return b;}bool Resource::load( QIODevice* dev, QValueList<Image> *imgs ){    QDomDocument doc;    if ( !doc.setContent( dev ) ) {	return FALSE;    }    if ( !previewMode ) {	toplevel = formwindow = new FormWindow( mainwindow->workSpace(), 0 );	formwindow->setMainWindow( mainwindow );	MetaDataBase::addEntry( formwindow );    }    QDomElement firstWidget = doc.firstChild().toElement().firstChild().toElement();    while ( firstWidget.tagName() != "widget" ) {	if ( firstWidget.tagName() == "include" ) {	    MetaDataBase::Include inc;	    inc.location = "global";	    if ( firstWidget.attribute( "location" ) == "local" )		inc.location = "local";	    inc.header = firstWidget.firstChild().toText().data();	    metaIncludes.append( inc );	} else if ( firstWidget.tagName() == "comment" ) {	    metaInfo.comment = firstWidget.firstChild().toText().data();	} else if ( firstWidget.tagName() == "forward" ) {	    metaForwards << firstWidget.firstChild().toText().data();	} else if ( firstWidget.tagName() == "author" ) {	    metaInfo.author = firstWidget.firstChild().toText().data();	} else if ( firstWidget.tagName() == "class" ) {	    metaInfo.className = firstWidget.firstChild().toText().data();	} else if ( firstWidget.tagName() == "pixmapfunction" ) {	    if ( formwindow ) {		formwindow->setSavePixmapInline( FALSE );		formwindow->setPixmapLoaderFunction( firstWidget.firstChild().toText().data() );	    }	}		firstWidget = firstWidget.nextSibling().toElement();    }    QDomElement connections = firstWidget;    while ( connections.tagName() != "connections" && !connections.isNull() )	connections = connections.nextSibling().toElement();    QDomElement imageCollection = firstWidget;    images.clear();    while ( imageCollection.tagName() != "images" && !imageCollection.isNull() )	imageCollection = imageCollection.nextSibling().toElement();    QDomElement customWidgets = firstWidget;    while ( customWidgets.tagName() != "customwidgets" && !customWidgets.isNull() )	customWidgets = customWidgets.nextSibling().toElement();    QDomElement tabOrder = firstWidget;    while ( tabOrder.tagName() != "tabstops" && !tabOrder.isNull() )	tabOrder = tabOrder.nextSibling().toElement();    if ( !imageCollection.isNull() )	loadImageCollection( imageCollection );    if ( images.isEmpty() && imgs )	images = *imgs;    if ( !customWidgets.isNull() )	loadCustomWidgets( customWidgets, this );    if ( !createObject( firstWidget, !previewMode ? formwindow : 0, 0) )	return FALSE;    if ( !connections.isNull() )	loadConnections( connections );    if ( !tabOrder.isNull() )	loadTabOrder( tabOrder );    if ( formwindow ) {	MetaDataBase::setIncludes( formwindow, metaIncludes );	MetaDataBase::setForwards( formwindow, metaForwards );	metaInfo.classNameChanged = metaInfo.className != QString( formwindow->name() );	MetaDataBase::setMetaInfo( formwindow, metaInfo );    }    if ( previewMode )	MetaDataBase::doConnections( toplevel );    if ( mainwindow && formwindow )	mainwindow->insertFormWindow( formwindow );    return TRUE;}bool Resource::save( const QString& filename ){    if ( !formwindow || filename.isEmpty() )	return FALSE;    QFile f( filename );    if ( !f.open( IO_WriteOnly ) )	return FALSE;    bool b = save( &f );    f.close();    return b;}bool Resource::save( QIODevice* dev, bool saveImages, QValueList<Image> *imgs ){    if ( !formwindow )	return FALSE;    QTextStream ts( dev );    ts.setCodec( QTextCodec::codecForName( "UTF-8" ) );    ts << "<!DOCTYPE UI><UI>" << endl;    saveMetaInfo( ts, 0 );    saveObject( formwindow->mainContainer(), 0, ts, 0 );    if ( !MetaDataBase::customWidgets()->isEmpty() && !usedCustomWidgets.isEmpty() )	saveCustomWidgets( ts, 0 );    if ( !images.isEmpty() && saveImages )	saveImageCollection( ts, 0 );    if ( !MetaDataBase::connections( formwindow ).isEmpty() || !MetaDataBase::slotList( formwindow ).isEmpty() )	saveConnections( ts, 0 );    saveTabOrder( ts, 0 );    ts << "</UI>" << endl;    if ( imgs )	*imgs = images;    images.clear();    return TRUE;}QString Resource::copy(){    if ( !formwindow )	return QString::null;    copying = TRUE;    QString s;    QTextOStream ts( &s );    ts << "<!DOCTYPE UI-SELECTION><UI-SELECTION>" << endl;    QWidgetList widgets = formwindow->selectedWidgets();    QWidgetList tmp( widgets );    for ( QWidget *w = widgets.first(); w; w = widgets.next() ) {	QWidget *p = w->parentWidget();	bool save = TRUE;	while ( p ) {	    if ( tmp.findRef( p ) != -1 ) {		save = FALSE;		break;	    }	    p = p->parentWidget();	}	if ( save )	    saveObject( w, 0, ts, 0 );    }    if ( !MetaDataBase::customWidgets()->isEmpty() && !usedCustomWidgets.isEmpty() )	saveCustomWidgets( ts, 0 );    if ( !images.isEmpty() )	saveImageCollection( ts, 0 );    ts << "</UI-SELECTION>" << endl;    return s;}void Resource::paste( const QString &cb, QWidget *parent ){    if ( !formwindow )	return;    mainContainerSet = TRUE;    pasting = TRUE;    QBuffer buf( QCString( cb.utf8() ) );    buf.open( IO_ReadOnly );    QDomDocument doc;    doc.setContent( &buf );    QDomElement firstWidget = doc.firstChild().toElement().firstChild().toElement();    QDomElement imageCollection = firstWidget;    images.clear();    while ( imageCollection.tagName() != "images" && !imageCollection.isNull() )	imageCollection = imageCollection.nextSibling().toElement();    QDomElement customWidgets = firstWidget;    while ( customWidgets.tagName() != "customwidgets" && !customWidgets.isNull() )	customWidgets = customWidgets.nextSibling().toElement();    if ( !imageCollection.isNull() )	loadImageCollection( imageCollection );    if ( !customWidgets.isNull() )	loadCustomWidgets( customWidgets, this );    QWidgetList widgets;    formwindow->clearSelection( FALSE );    formwindow->setPropertyShowingBlocked( TRUE );    formwindow->clearSelection( FALSE );    while ( !firstWidget.isNull() ) {	if ( firstWidget.tagName() == "widget" ) {	    QWidget *w = (QWidget*)createObject( firstWidget, parent, 0 );	    if ( !w )		continue;	    widgets.append( w );	    int x = w->x() + formwindow->grid().x();	    int y = w->y() + formwindow->grid().y();	    if ( w->x() + w->width() > parent->width() )		x = QMAX( 0, parent->width() - w->width() );	    if ( w->y() + w->height() > parent->height() )		y = QMAX( 0, parent->height() - w->height() );	    if ( x != w->x() || y != w->y() )		w->move( x, y );	    formwindow->selectWidget( w );	} else if ( firstWidget.tagName() == "spacer" ) {	    QWidget *w = createSpacer( firstWidget, parent, 0, firstWidget.tagName() == "vspacer" ? Qt::Vertical : Qt::Horizontal );	    if ( !w )		continue;	    widgets.append( w );	    int x = w->x() + formwindow->grid().x();	    int y = w->y() + formwindow->grid().y();	    if ( w->x() + w->width() > parent->width() )		x = QMAX( 0, parent->width() - w->width() );	    if ( w->y() + w->height() > parent->height() )		y = QMAX( 0, parent->height() - w->height() );	    if ( x != w->x() || y != w->y() )		w->move( x, y );	    formwindow->selectWidget( w );	}	firstWidget = firstWidget.nextSibling().toElement();    }    formwindow->setPropertyShowingBlocked( FALSE );    formwindow->emitShowProperties();    buf.close();    PasteCommand *cmd = new PasteCommand( FormWindow::tr( "Paste" ), formwindow, widgets );    formwindow->commandHistory()->addCommand( cmd );

⌨️ 快捷键说明

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