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

📄 resource.cpp

📁 这个是Linux的qt源代码
💻 CPP
📖 第 1 页 / 共 5 页
字号:
    ts << "</UI>" << endl;    bool ok = saveFormCode( formwindow->formFile(), langIface );    images.clear();    return ok;}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;    QDomDocument doc;    QString errMsg;    int errLine;    if ( !doc.setContent( cb, &errMsg, &errLine ) ) {	qDebug( QString("Parse error: ") + errMsg + QString(" in line %d"), errLine );    }    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();    PasteCommand *cmd = new PasteCommand( FormWindow::tr( "Paste" ), formwindow, widgets );    formwindow->commandHistory()->addCommand( cmd );}void Resource::saveObject( QObject *obj, QDesignerGridLayout* grid, QTextStream &ts, int indent ){    if ( obj && obj->isWidgetType() && ( (QWidget*)obj )->isHidden() )	return;    QString closeTag;    const char* className = WidgetFactory::classNameOf( obj );    int classID = WidgetDatabase::idFromClassName( className );    bool isPlugin = WidgetDatabase::isCustomPluginWidget( classID );    if ( obj->isWidgetType() ) {	if ( obj->isA("CustomWidget") || isPlugin ) {	    usedCustomWidgets << QString( className );	    includeHints << WidgetDatabase::includeFile( classID );	}	if ( obj != formwindow && !formwindow->widgets()->find( (QWidget*)obj ) )	    return; // we don't know anything about this thing	QString attributes;	if ( grid ) {	    QDesignerGridLayout::Item item = grid->items[ (QWidget*)obj ];	    attributes += QString(" row=\"") + QString::number(item.row) + "\"";	    attributes += QString(" column=\"") + QString::number(item.column) + "\"";	    if ( item.rowspan * item.colspan != 1 ) {		attributes += QString(" rowspan=\"") + QString::number(item.rowspan) + "\"";		attributes += QString(" colspan=\"") + QString::number(item.colspan) + "\"";	    }	}	if ( qstrcmp( className, "Spacer" ) == 0 ) {	    closeTag = makeIndent( indent ) + "</spacer>\n";	    ts << makeIndent( indent ) << "<spacer" << attributes << ">" << endl;	    ++indent;	} else {	    closeTag = makeIndent( indent ) + "</widget>\n";	    ts << makeIndent( indent ) << "<widget class=\"" << className << "\"" << attributes << ">" << endl;	    ++indent;	}	if ( WidgetFactory::hasItems(classID) )	    saveItems( obj, ts, indent );	saveObjectProperties( obj, ts, indent );    } else {	// test for other objects we created. Nothing so far.	return;    }    QDesignerWidgetStack* ws = 0;    if ( obj->inherits( "QTabWidget" ) ) {	QTabWidget* tw = (QTabWidget*) obj;	QObjectList* tmpl = tw->queryList( "QWidgetStack" );	QWidgetStack *ws = (QWidgetStack*)tmpl->first();	QTabBar *tb = ( (QDesignerTabWidget*)obj )->tabBar();	for ( int i = 0; i < tb->count(); ++i ) {	    QTab *t = tb->tabAt( i );	    if ( !t )		continue;	    QWidget *w = ws->widget( t->identifier() );	    if ( !w )		continue;	    if ( WidgetDatabase::idFromClassName( WidgetFactory::classNameOf(w) ) == -1 )		continue; // we don't know this widget	    ts << makeIndent( indent ) << "<widget class=\"QWidget\">" << endl;	    ++indent;	    ts << makeIndent( indent ) << "<property name=\"name\">" << endl;	    indent++;	    ts << makeIndent( indent ) << "<cstring>" << entitize( w->name() ) << "</cstring>" << endl;	    indent--;	    ts << makeIndent( indent ) << "</property>" << endl;	    ts << makeIndent( indent ) << "<attribute name=\"title\">" << endl;	    indent++;	    ts << makeIndent( indent ) << "<string>" << entitize( t->text() ) << "</string>" << endl;	    indent--;	    ts << makeIndent( indent ) << "</attribute>" << endl;	    saveChildrenOf( w, ts, indent );	    --indent;	    ts << makeIndent( indent ) << "</widget>" << endl;	}	delete tmpl;    } else if ( (ws = ::qt_cast<QDesignerWidgetStack*>(obj)) != 0 ) {	for ( int i = 0; i < ws->count(); ++i ) {	    QWidget *w = ws->page( i );	    if ( !w )		continue;	    if ( WidgetDatabase::idFromClassName(WidgetFactory::classNameOf(w)) == -1 )		continue; // we don't know this widget	    ts << makeIndent( indent ) << "<widget class=\"QWidget\">" << endl;	    ++indent;	    ts << makeIndent( indent ) << "<property name=\"name\">" << endl;	    indent++;	    ts << makeIndent( indent ) << "<cstring>" << entitize( w->name() ) << "</cstring>" << endl;	    indent--;	    ts << makeIndent( indent ) << "</property>" << endl;	    ts << makeIndent( indent ) << "<attribute name=\"id\">" << endl;	    indent++;	    ts << makeIndent( indent ) << "<number>" << QString::number(i) << "</number>" << endl;	    indent--;	    ts << makeIndent( indent ) << "</attribute>" << endl;	    saveChildrenOf( w, ts, indent );	    --indent;	    ts << makeIndent( indent ) << "</widget>" << endl;	}    } else if ( obj->inherits( "QToolBox" ) ) {	QToolBox* tb = (QToolBox*)obj;	for ( int i = 0; i < tb->count(); ++i ) {	    QWidget *w = tb->item( i );	    if ( !w )		continue;	    if ( WidgetDatabase::idFromClassName(WidgetFactory::classNameOf(w)) == -1 )		continue; // we don't know this widget	    ts << makeIndent( indent ) << "<widget class=\"QWidget\">" << endl;	    ++indent;	    ts << makeIndent( indent ) << "<property name=\"name\">" << endl;	    indent++;	    ts << makeIndent( indent ) << "<cstring>" << entitize( w->name() ) << "</cstring>" << endl;	    indent--;	    ts << makeIndent( indent ) << "</property>" << endl;	    ts << makeIndent( indent ) << "<property name=\"backgroundMode\">" << endl;	    indent++;	    saveEnumProperty( w, "backgroundMode", QVariant::Invalid, ts, indent );	    indent--;	    ts << makeIndent( indent ) << "</property>" << endl;	    ts << makeIndent( indent ) << "<attribute name=\"label\">" << endl;	    indent++;	    ts << makeIndent( indent ) << "<string>" << entitize( tb->itemLabel( tb->indexOf(w) ) ) << "</string>" << endl;	    indent--;	    ts << makeIndent( indent ) << "</attribute>" << endl;	    saveChildrenOf( w, ts, indent );	    --indent;	    ts << makeIndent( indent ) << "</widget>" << endl;	}    } else if ( obj->inherits( "QWizard" ) ) {	QWizard* wiz = (QWizard*)obj;	for ( int i = 0; i < wiz->pageCount(); ++i ) {	    QWidget *w = wiz->page( i );	    if ( !w )		continue;	    if ( WidgetDatabase::idFromClassName(WidgetFactory::classNameOf(w)) == -1 )		continue; // we don't know this widget	    ts << makeIndent( indent ) << "<widget class=\"QWidget\">" << endl;	    ++indent;	    ts << makeIndent( indent ) << "<property name=\"name\">" << endl;	    indent++;	    ts << makeIndent( indent ) << "<cstring>" << entitize( w->name() ) << "</cstring>" << endl;	    indent--;	    ts << makeIndent( indent ) << "</property>" << endl;	    ts << makeIndent( indent ) << "<attribute name=\"title\">" << endl;	    indent++;	    ts << makeIndent( indent ) << "<string>" << entitize( wiz->title( w ) ) << "</string>" << endl;	    indent--;	    ts << makeIndent( indent ) << "</attribute>" << endl;	    saveChildrenOf( w, ts, indent );	    --indent;	    ts << makeIndent( indent ) << "</widget>" << endl;	}    } else if ( obj->inherits( "QMainWindow" ) ) {	saveChildrenOf( ( (QMainWindow*)obj )->centralWidget(), ts, indent );    } else {	bool saved = FALSE;#ifdef QT_CONTAINER_CUSTOM_WIDGETS	if ( isPlugin ) {	    WidgetInterface *iface = 0;	    widgetManager()->queryInterface( className, &iface );	    if ( iface ) {		QWidgetContainerInterfacePrivate *iface2 = 0;		iface->queryInterface( IID_QWidgetContainer, (QUnknownInterface**)&iface2 );		if ( iface2 ) {		    if ( iface2->supportsPages( className ) )  {			QWidgetList containers = iface2->pages( className, (QWidget*)obj );			if ( !containers.isEmpty() ) {			    saved = TRUE;			    int i = 0;			    for ( QWidget *w = containers.first(); w; w = containers.next(), ++i ) {				if ( WidgetDatabase::				     idFromClassName( WidgetFactory::classNameOf( w ) ) == -1 )				    continue; // we don't know this widget				ts << makeIndent( indent ) << "<widget class=\""				   << WidgetFactory::classNameOf( w )				   << "\">" << endl;				++indent;				ts << makeIndent( indent ) << "<property name=\"name\">" << endl;				indent++;				ts << makeIndent( indent ) << "<cstring>" << entitize( w->name() )				   << "</cstring>" << endl;				indent--;				ts << makeIndent( indent ) << "</property>" << endl;				ts << makeIndent( indent ) << "<attribute name=\"label\">" << endl;				indent++;				ts << makeIndent( indent ) << "<cstring>"				   << entitize( iface2->pageLabel( className, (QWidget*)obj, i ) )				   << "</cstring>" << endl;				indent--;				ts << makeIndent( indent ) << "</attribute>" << endl;				saveChildrenOf( w, ts, indent );				--indent;				ts << makeIndent( indent ) << "</widget>" << endl;			    }			}		    } else {			saved = TRUE;			QWidget *w = iface2->containerOfWidget( className, (QWidget*)obj );			if ( obj != w ) {			    ts << makeIndent( indent ) << "<widget class=\""			       << WidgetFactory::classNameOf( w )			       << "\">" << endl;			    ++indent;			    ts << makeIndent( indent ) << "<property name=\"name\">" << endl;			    indent++;			    ts << makeIndent( indent ) << "<cstring>" << entitize( w->name() )			       << "</cstring>" << endl;			    indent--;			    ts << makeIndent( indent ) << "</property>" << endl;			    saveChildrenOf( w, ts, indent );			    --indent;			    ts << makeIndent( indent ) << "</widget>" << endl;			}			// Create a custom widget and then store it in the database			// so we can save the custom widgets.			MetaDataBase::CustomWidget *cw = new MetaDataBase::CustomWidget;			cw->className = className;			cw->includeFile =  WidgetDatabase::includeFile( classID );			QStrList lst = w->metaObject()->signalNames( TRUE );			for ( QPtrListIterator<char> it(lst); it.current(); ++it )			    cw->lstSignals.append(it.current());			int i;			int total = w->metaObject()->numProperties( TRUE );			for ( i = 0; i < total; i++ ) {			    const QMetaProperty *p = w->metaObject()->property( i, TRUE );			    if ( p->designable(w) ) {				MetaDataBase::Property prop;				prop.property = p->name();				QString pType = p->type();				// *sigh* designer types are not normal types				// Handle most cases, the ones it misses are				// probably too difficult to deal with anyway...				if ( pType.startsWith("Q") ) {				    pType = pType.right( pType.length() - 1 );				} else {				    pType[0] = pType[0].upper();

⌨️ 快捷键说明

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