📄 resource.cpp
字号:
else r += l - 'a' + 10; ba[ i ] = r; } QString format = n2.attribute( "format", "PNG" ); if ( format == "XPM.GZ" ) { ulong len = n2.attribute( "length" ).toULong(); if ( len < data.length() * 5 ) len = data.length() * 5; QByteArray baunzip( len ); ::uncompress( (uchar*) baunzip.data(), &len, (uchar*) ba, data.length()/2 ); img.loadFromData( (const uchar*)baunzip.data(), len, "XPM" ); } else { img.loadFromData( (const uchar*)ba, data.length() / 2, format ); } delete [] ba; return img;}void Resource::loadImageCollection( const QDomElement &e ){ QDomElement n = e.firstChild().toElement(); while ( !n.isNull() ) { if ( n.tagName() == "image" ) { QDomElement n2 = n.firstChild().toElement(); Image img; while ( !n2.isNull() ) { if ( n2.tagName() == "name" ) img.name = n2.firstChild().toText().data(); else if ( n2.tagName() == "data" ) img.img = loadImageData( n2 ); n2 = n2.nextSibling().toElement(); } images.append( img ); n = n.nextSibling().toElement(); } }}QImage Resource::loadFromCollection( const QString &name ){ QValueList<Image>::Iterator it = images.begin(); for ( ; it != images.end(); ++it ) { if ( ( *it ).name == name ) return ( *it ).img; } return QImage();}void Resource::saveConnections( QTextStream &ts, int indent ){ ts << makeIndent( indent ) << "<connections>" << endl; indent++; QValueList<MetaDataBase::Connection> connections = MetaDataBase::connections( formwindow ); QValueList<MetaDataBase::Connection>::Iterator it = connections.begin(); for ( ; it != connections.end(); ++it ) { MetaDataBase::Connection conn = *it; if ( ( knownNames.findIndex( QString( conn.sender->name() ) ) == -1 && qstrcmp( conn.sender->name(), "this" ) != 0 ) || ( knownNames.findIndex( QString( conn.receiver->name() ) ) == -1 && qstrcmp( conn.receiver->name(), "this" ) != 0 ) ) continue; if ( formwindow->isMainContainer( (QWidget*)(*it).receiver ) && !MetaDataBase::hasSlot( formwindow, (*it).slot ) ) continue; if ( conn.sender->inherits( "CustomWidget" ) ) { MetaDataBase::CustomWidget *cw = ( (CustomWidget*)conn.sender )->customWidget(); if ( cw && !cw->hasSignal( conn.signal ) ) continue; } if ( conn.receiver->inherits( "CustomWidget" ) ) { MetaDataBase::CustomWidget *cw = ( (CustomWidget*)conn.receiver )->customWidget(); if ( cw && !cw->hasSlot( conn.slot ) ) continue; } ts << makeIndent( indent ) << "<connection>" << endl; indent++; ts << makeIndent( indent ) << "<sender>" << entitize( conn.sender->name() ) << "</sender>" << endl; ts << makeIndent( indent ) << "<signal>" << entitize( conn.signal ) << "</signal>" << endl; ts << makeIndent( indent ) << "<receiver>" << entitize( conn.receiver->name() ) << "</receiver>" << endl; ts << makeIndent( indent ) << "<slot>" << entitize( conn.slot ) << "</slot>" << endl; indent--; ts << makeIndent( indent ) << "</connection>" << endl; } QValueList<MetaDataBase::Slot> slotList = MetaDataBase::slotList( formwindow ); if ( !slotList.isEmpty() ) { QValueList<MetaDataBase::Slot>::Iterator it = slotList.begin(); for ( ; it != slotList.end(); ++it ) { MetaDataBase::Slot slot = *it; ts << makeIndent( indent ) << "<slot access=\"" << slot.access << "\">" << entitize( slot.slot ) << "</slot>" << endl; } } indent--; ts << makeIndent( indent ) << "</connections>" << endl;}void Resource::loadConnections( const QDomElement &e ){ QDomElement n = e.firstChild().toElement(); while ( !n.isNull() ) { if ( n.tagName() == "connection" ) { QDomElement n2 = n.firstChild().toElement(); MetaDataBase::Connection conn; while ( !n2.isNull() ) { if ( n2.tagName() == "sender" ) { QString name = n2.firstChild().toText().data(); if ( name == "this" || qstrcmp( toplevel->name(), name ) == 0 ) { conn.sender = toplevel; } else { if ( name == "this" ) name = toplevel->name(); QObjectList *l = toplevel->queryList( 0, name, FALSE ); if ( l ) { if ( l->first() ) conn.sender = l->first(); delete l; } } } else if ( n2.tagName() == "signal" ) { conn.signal = n2.firstChild().toText().data(); } else if ( n2.tagName() == "receiver" ) { QString name = n2.firstChild().toText().data(); if ( name == "this" || qstrcmp( toplevel->name(), name ) == 0 ) { conn.receiver = toplevel; } else { QObjectList *l = toplevel->queryList( 0, name, FALSE ); if ( l ) { if ( l->first() ) conn.receiver = l->first(); delete l; } } } else if ( n2.tagName() == "slot" ) { conn.slot = n2.firstChild().toText().data(); } n2 = n2.nextSibling().toElement(); } if ( formwindow ) { if ( conn.sender == formwindow ) conn.sender = formwindow->mainContainer(); if ( conn.receiver == formwindow ) conn.receiver = formwindow->mainContainer(); } MetaDataBase::addConnection( formwindow ? formwindow : toplevel, conn.sender, conn.signal, conn.receiver, conn.slot ); } else if ( n.tagName() == "slot" ) { MetaDataBase::Slot slot; slot.access = n.attribute( "access", "public" ); slot.slot = n.firstChild().toText().data(); MetaDataBase::addSlot( formwindow ? formwindow : toplevel, slot.slot, slot.access ); } n = n.nextSibling().toElement(); }}void Resource::saveCustomWidgets( QTextStream &ts, int indent ){ ts << makeIndent( indent ) << "<customwidgets>" << endl; indent++; QList<MetaDataBase::CustomWidget> *lst = MetaDataBase::customWidgets(); for ( MetaDataBase::CustomWidget *w = lst->first(); w; w = lst->next() ) { if ( usedCustomWidgets.findIndex( w->className ) == -1 ) continue; ts << makeIndent( indent ) << "<customwidget>" << endl; indent++; ts << makeIndent( indent ) << "<class>" << w->className << "</class>" << endl; ts << makeIndent( indent ) << "<header location=\"" << ( w->includePolicy == MetaDataBase::CustomWidget::Local ? "local" : "global" ) << "\">" << w->includeFile << "</header>" << endl; ts << makeIndent( indent ) << "<sizehint>" << endl; indent++; ts << makeIndent( indent ) << "<width>" << w->sizeHint.width() << "</width>" << endl; ts << makeIndent( indent ) << "<height>" << w->sizeHint.height() << "</height>" << endl; indent--; ts << makeIndent( indent ) << "</sizehint>" << endl; ts << makeIndent( indent ) << "<container>" << (int)w->isContainer << "</container>" << endl; ts << makeIndent( indent ) << "<sizepolicy>" << endl; indent++; ts << makeIndent( indent ) << "<hordata>" << (int)w->sizePolicy.horData() << "</hordata>" << endl; ts << makeIndent( indent ) << "<verdata>" << (int)w->sizePolicy.verData() << "</verdata>" << endl; indent--; ts << makeIndent( indent ) << "</sizepolicy>" << endl; ts << makeIndent( indent ) << "<pixmap>" << saveInCollection( w->pixmap->convertToImage() ) << "</pixmap>" << endl; if ( !w->lstSignals.isEmpty() ) { for ( QValueList<QCString>::Iterator it = w->lstSignals.begin(); it != w->lstSignals.end(); ++it ) ts << makeIndent( indent ) << "<signal>" << entitize( *it ) << "</signal>" << endl; } if ( !w->lstSlots.isEmpty() ) { for ( QValueList<MetaDataBase::Slot>::Iterator it = w->lstSlots.begin(); it != w->lstSlots.end(); ++it ) ts << makeIndent( indent ) << "<slot access=\"" << (*it).access << "\">" << entitize( (*it).slot ) << "</slot>" << endl; } if ( !w->lstProperties.isEmpty() ) { for ( QValueList<MetaDataBase::Property>::Iterator it = w->lstProperties.begin(); it != w->lstProperties.end(); ++it ) ts << makeIndent( indent ) << "<property type=\"" << (*it).type << "\">" << entitize( (*it).property ) << "</property>" << endl; } indent--; ts << makeIndent( indent ) << "</customwidget>" << endl; } indent--; ts << makeIndent( indent ) << "</customwidgets>" << endl;}void Resource::loadCustomWidgets( const QDomElement &e, Resource *r ){ QDomElement n = e.firstChild().toElement(); while ( !n.isNull() ) { if ( n.tagName() == "customwidget" ) { QDomElement n2 = n.firstChild().toElement(); MetaDataBase::CustomWidget *w = new MetaDataBase::CustomWidget; while ( !n2.isNull() ) { if ( n2.tagName() == "class" ) { w->className = n2.firstChild().toText().data(); } else if ( n2.tagName() == "header" ) { w->includeFile = n2.firstChild().toText().data(); QString s = n2.attribute( "location" ); if ( s != "local" ) w->includePolicy = MetaDataBase::CustomWidget::Global; else w->includePolicy = MetaDataBase::CustomWidget::Local; } else if ( n2.tagName() == "sizehint" ) { QDomElement n3 = n2.firstChild().toElement(); while ( !n3.isNull() ) { if ( n3.tagName() == "width" ) w->sizeHint.setWidth( n3.firstChild().toText().data().toInt() ); else if ( n3.tagName() == "height" ) w->sizeHint.setHeight( n3.firstChild().toText().data().toInt() ); n3 = n3.nextSibling().toElement(); } } else if ( n2.tagName() == "sizepolicy" ) { QDomElement n3 = n2.firstChild().toElement(); while ( !n3.isNull() ) { if ( n3.tagName() == "hordata" ) w->sizePolicy.setHorData( (QSizePolicy::SizeType)n3.firstChild().toText().data().toInt() ); else if ( n3.tagName() == "verdata" ) w->sizePolicy.setVerData( (QSizePolicy::SizeType)n3.firstChild().toText().data().toInt() ); n3 = n3.nextSibling().toElement(); } } else if ( n2.tagName() == "pixmap" ) { QPixmap pix; if ( r ) { pix = r->loadPixmap( n2 ); } else { QDomElement n3 = n2.firstChild().toElement(); QImage img; while ( !n3.isNull() ) { if ( n3.tagName() == "data" ) { img = loadImageData( n3 ); } n3 = n3.nextSibling().toElement(); } pix.convertFromImage( img ); } w->pixmap = new QPixmap( pix ); } else if ( n2.tagName() == "signal" ) { w->lstSignals.append( n2.firstChild().toText().data().latin1() ); } else if ( n2.tagName() == "container" ) { w->isContainer = (bool)n2.firstChild().toText().data().toInt(); } else if ( n2.tagName() == "slot" ) { MetaDataBase::Slot slot; slot.slot = n2.firstChild().toText().data().latin1(); slot.access = n2.attribute( "access" ); w->lstSlots.append( slot ); } else if ( n2.tagName() == "property" ) { MetaDataBase::Property property; property.property = n2.firstChild().toText().data().latin1(); property.type = n2.attribute( "type" ); w->lstProperties.append( property ); } n2 = n2.nextSibling().toElement(); } MetaDataBase::addCustomWidget( w ); } n = n.nextSibling().toElement(); }}void Resource::saveTabOrder( QTextStream &ts, int indent ){ QWidgetList l = MetaDataBase::tabOrder( toplevel ); if ( l.isEmpty() ) return; ts << makeIndent( indent ) << "<tabstops>" << endl; indent++; for ( QWidget *w = l.first(); w; w = l.next() ) { if ( w->testWState( Qt::WState_ForceHide ) || knownNames.findIndex( w->name() ) == -1 ) continue; ts << makeIndent( indent ) << "<tabstop>" << w->name() << "</tabstop>" << endl; } indent--; ts << makeIndent( indent ) << "</tabstops>" << endl;}void Resource::loadTabOrder( const QDomElement &e ){ QWidget *last = 0; QDomElement n = e.firstChild().toElement(); QWidgetList widgets; while ( !n.isNull() ) { if ( n.tagName() == "tabstop" ) { QString name = n.firstChild().toText().data(); QObjectList *l = toplevel->queryList( 0, name, FALSE ); if ( l ) { if ( l->first() ) { QWidget *w = (QWidget*)l->first(); widgets.append( w ); if ( last ) toplevel->setTabOrder( last, w ); last = w; } delete l; } } n = n.nextSibling().toElement(); } if ( !widgets.isEmpty() ) MetaDataBase::setTabOrder( toplevel, widgets );}void Resource::saveMetaInfo( QTextStream &ts, int indent ){ MetaDataBase::MetaInfo info = MetaDataBase::metaInfo( formwindow ); QString cn; if ( info.classNameChanged && !info.className.isEmpty() ) cn = info.className; else cn = formwindow->name(); ts << makeIndent( indent ) << "<class>" << entitize( cn ) << "</class>" << endl; if ( !info.comment.isEmpty() ) ts << makeIndent( indent ) << "<comment>" << entitize( info.comment ) << "</comment>" << endl; if ( !info.author.isEmpty() ) ts << makeIndent( indent ) << "<author>" << entitize( info.author ) << "</author>" << endl; QValueList<MetaDataBase::Include> includes = MetaDataBase::includes( formwindow ); for ( QValueList<MetaDataBase::Include>::Iterator it = includes.begin(); it != includes.end(); ++it ) ts << makeIndent( indent ) << "<include location=\"" << (*it).location << "\">" << (*it).header << "</include>" << endl; QStringList forwards = MetaDataBase::forwards( formwindow ); for ( QStringList::Iterator it2 = forwards.begin(); it2 != forwards.end(); ++it2 ) ts << makeIndent( indent ) << "<forward>" << *it2 << "</forward>" << endl; if ( formwindow && !formwindow->savePixmapInline() ) ts << makeIndent( indent ) << "<pixmapfunction>" << formwindow->pixmapLoaderFunction() << "</pixmapfunction>" << endl;}QColorGroup Resource::loadColorGroup( const QDomElement &e ){ QColorGroup cg; int r = -1; QDomElement n = e.firstChild().toElement(); QColor col; while ( !n.isNull() ) { if ( n.tagName() == "color" ) { r++; cg.setColor( (QColorGroup::ColorRole)r, (col = DomTool::readColor( n ) ) ); } else if ( n.tagName() == "pixmap" ) { QImage img = loadFromCollection( n.firstChild().toText().data() ); QPixmap pix = loadPixmap( n ); cg.setBrush( (QColorGroup::ColorRole)r, QBrush( col, pix ) ); } n = n.nextSibling().toElement(); } return cg;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -