📄 resource.cpp
字号:
for ( QPtrListIterator<char> it( lst ); it.current(); ++it ) { if ( changed.find( QString::fromLatin1( it.current() ) ) == changed.end() ) continue; if ( saved.find( QString::fromLatin1( it.current() ) ) != saved.end() ) continue; saved << QString::fromLatin1( it.current() ); const QMetaProperty* p = w->metaObject()-> property( w->metaObject()->findProperty( it.current(), TRUE ), TRUE ); if ( !p || !p->stored( w ) || ( inLayout && qstrcmp( p->name(), "geometry" ) == 0 ) ) continue; if ( w->inherits( "QLabel" ) && qstrcmp( p->name(), "pixmap" ) == 0 && ( !( (QLabel*)w )->pixmap() || ( (QLabel*)w )->pixmap()->isNull() ) ) continue; if ( w->inherits( "QDesignerMenuBar" ) && ( qstrcmp( p->name(), "itemName" ) == 0 || qstrcmp( p->name(), "itemNumber" ) == 0 || qstrcmp( p->name(), "itemText" ) == 0 ) ) continue; if ( qstrcmp( p->name(), "name" ) == 0 ) knownNames << w->property( "name" ).toString(); ts << makeIndent( indent ) << "<property"; ts << " name=\"" << it.current() << "\""; if ( !p->stdSet() ) ts << " stdset=\"0\""; ts << ">" << endl; indent++; if ( p->isSetType() ) { saveSetProperty( w, it.current(), QVariant::nameToType( p->type() ), ts, indent ); } else if ( p->isEnumType() ) { saveEnumProperty( w, it.current(), QVariant::nameToType( p->type() ), ts, indent ); } else { saveProperty( w, it.current(), w->property( p->name() ), QVariant::nameToType( p->type() ), ts, indent ); } indent--; ts << makeIndent( indent ) << "</property>" << endl; } if ( w->isWidgetType() && MetaDataBase::fakeProperties( w ) ) { QMap<QString, QVariant>* fakeProperties = MetaDataBase::fakeProperties( w ); for ( QMap<QString, QVariant>::Iterator fake = fakeProperties->begin(); fake != fakeProperties->end(); ++fake ) { if ( MetaDataBase::isPropertyChanged( w, fake.key() ) ) { if ( w->inherits( "CustomWidget" ) ) { MetaDataBase::CustomWidget *cw = ( (CustomWidget*)w )->customWidget(); if ( cw && !cw->hasProperty( fake.key().latin1() ) && fake.key() != "toolTip" && fake.key() != "whatsThis" ) continue; } ts << makeIndent( indent ) << "<property name=\"" << fake.key() << "\" stdset=\"0\">" << endl; indent++; saveProperty( w, fake.key(), *fake, (*fake).type(), ts, indent ); indent--; ts << makeIndent( indent ) << "</property>" << endl; } } }}void Resource::saveSetProperty( QObject *w, const QString &name, QVariant::Type, QTextStream &ts, int indent ){ const QMetaProperty *p = w->metaObject()->property( w->metaObject()->findProperty( name, TRUE ), TRUE ); QStrList l( p->valueToKeys( w->property( name ).toInt() ) ); QString v; for ( uint i = 0; i < l.count(); ++i ) { v += l.at( i ); if ( i < l.count() - 1 ) v += "|"; } ts << makeIndent( indent ) << "<set>" << v << "</set>" << endl;}void Resource::saveEnumProperty( QObject *w, const QString &name, QVariant::Type, QTextStream &ts, int indent ){ const QMetaProperty *p = w->metaObject()->property( w->metaObject()->findProperty( name, TRUE ), TRUE ); ts << makeIndent( indent ) << "<enum>" << p->valueToKey( w->property( name ).toInt() ) << "</enum>" << endl;}void Resource::saveProperty( QObject *w, const QString &name, const QVariant &value, QVariant::Type t, QTextStream &ts, int indent ){ if ( name == "hAlign" || name =="vAlign" || name == "wordwrap" || name == "layoutMargin" || name =="layoutSpacing" ) return; int num; uint unum; double dob; QString comment; if ( w && formwindow->widgets()->find( (QWidget*)w ) || formwindow->actionList().find( (QAction*)w ) ) comment = MetaDataBase::propertyComment( w, name ); switch ( t ) { case QVariant::String: ts << makeIndent( indent ) << "<string>" << entitize( value.toString() ) << "</string>" << endl; if ( !comment.isEmpty() ) ts << makeIndent( indent ) << "<comment>" << entitize( comment ) << "</comment>" << endl; break; case QVariant::CString: ts << makeIndent( indent ) << "<cstring>" << entitize( value.toCString() ).latin1() << "</cstring>" << endl; break; case QVariant::Bool: ts << makeIndent( indent ) << "<bool>" << mkBool( value.toBool() ) << "</bool>" << endl; break; case QVariant::Int: if ( w && w->inherits( "QLayout" ) ) { num = -1; if ( name == "spacing" ) num = MetaDataBase::spacing( WidgetFactory::containerOfWidget( WidgetFactory::layoutParent( (QLayout*)w ) ) ); else if ( name == "margin" ) num = MetaDataBase::margin( WidgetFactory::containerOfWidget( WidgetFactory::layoutParent( (QLayout*)w ) ) ); if ( num != -1 ) ts << makeIndent( indent ) << "<number>" << QString::number( num ) << "</number>" << endl; } else { num = value.toInt(); ts << makeIndent( indent ) << "<number>" << QString::number( num ) << "</number>" << endl; } break; case QVariant::Double: dob = value.toDouble(); ts << makeIndent( indent ) << "<number>" << QString::number( dob ) << "</number>" << endl; break; case QVariant::KeySequence: ts << makeIndent( indent ) << "<string>" << entitize( value.toString() ) << "</string>" << endl; break; case QVariant::UInt: unum = value.toUInt(); ts << makeIndent( indent ) << "<number>" << QString::number( unum ) << "</number>" << endl; break; case QVariant::Rect: { QVariant v( value ); ts << makeIndent( indent ) << "<rect>" << endl; indent++; ts << makeIndent( indent ) << "<x>" << QString::number( v.toRect().x() ) << "</x>" << endl; ts << makeIndent( indent ) << "<y>" << QString::number( v.toRect().y() ) << "</y>" << endl; ts << makeIndent( indent ) << "<width>" << QString::number( v.toRect().width() ) << "</width>" << endl; ts << makeIndent( indent ) << "<height>" << QString::number( v.toRect().height() ) << "</height>" << endl; indent--; ts << makeIndent( indent ) << "</rect>" << endl; } break; case QVariant::Point: { QVariant v( value ); ts << makeIndent( indent ) << "<point>" << endl; indent++; ts << makeIndent( indent ) << "<x>" << QString::number( v.toPoint().x() ) << "</x>" << endl; ts << makeIndent( indent ) << "<y>" << QString::number( v.toPoint().y() ) << "</y>" << endl; indent--; ts << makeIndent( indent ) << "</point>" << endl; } break; case QVariant::Size: { QVariant v( value ); ts << makeIndent( indent ) << "<size>" << endl; indent++; ts << makeIndent( indent ) << "<width>" << QString::number( v.toSize().width() ) << "</width>" << endl; ts << makeIndent( indent ) << "<height>" << QString::number( v.toSize().height() ) << "</height>" << endl; indent--; ts << makeIndent( indent ) << "</size>" << endl; } break; case QVariant::Color: { QVariant v( value ); ts << makeIndent( indent ) << "<color>" << endl; indent++; saveColor( ts, indent, v.toColor() ); indent--; ts << makeIndent( indent ) << "</color>" << endl; } break; case QVariant::Font: { QVariant v( value ); ts << makeIndent( indent ) << "<font>" << endl; QFont f( qApp->font() ); if ( w && w->isWidgetType() && ((QWidget*)w)->parentWidget() ) f = ((QWidget*)w)->parentWidget()->font(); QFont f2( v.toFont() ); indent++; if ( f.family() != f2.family() ) ts << makeIndent( indent ) << "<family>" << f2.family() << "</family>" << endl; if ( f.pointSize() != f2.pointSize() ) ts << makeIndent( indent ) << "<pointsize>" << QString::number( f2.pointSize() ) << "</pointsize>" << endl; if ( f.bold() != f2.bold() ) ts << makeIndent( indent ) << "<bold>" << QString::number( (int)f2.bold() ) << "</bold>" << endl; if ( f.italic() != f2.italic() ) ts << makeIndent( indent ) << "<italic>" << QString::number( (int)f2.italic() ) << "</italic>" << endl; if ( f.underline() != f2.underline() ) ts << makeIndent( indent ) << "<underline>" << QString::number( (int)f2.underline() ) << "</underline>" << endl; if ( f.strikeOut() != f2.strikeOut() ) ts << makeIndent( indent ) << "<strikeout>" << QString::number( (int)f2.strikeOut() ) << "</strikeout>" << endl; indent--; ts << makeIndent( indent ) << "</font>" << endl; } break; case QVariant::SizePolicy: { QSizePolicy sp( value.toSizePolicy() ); ts << makeIndent( indent ) << "<sizepolicy>" << endl; indent++; ts << makeIndent( indent ) << "<hsizetype>" << (int)sp.horData() << "</hsizetype>" << endl; ts << makeIndent( indent ) << "<vsizetype>" << (int)sp.verData() << "</vsizetype>" << endl; ts << makeIndent( indent ) << "<horstretch>" << (int)sp.horStretch() << "</horstretch>" << endl; ts << makeIndent( indent ) << "<verstretch>" << (int)sp.verStretch() << "</verstretch>" << endl; indent--; ts << makeIndent( indent ) << "</sizepolicy>" << endl; break; } case QVariant::Pixmap: savePixmap( value.toPixmap(), ts, indent ); break; case QVariant::IconSet: savePixmap( value.toIconSet().pixmap(), ts, indent, "iconset" ); break; case QVariant::Image: ts << makeIndent( indent ) << "<image>" << saveInCollection( value.toImage() ) << "</image>" << endl; break; case QVariant::Palette: { QPalette p( value.toPalette() ); ts << makeIndent( indent ) << "<palette>" << endl; indent++; ts << makeIndent( indent ) << "<active>" << endl; indent++; saveColorGroup( ts, indent, p.active() ); indent--; ts << makeIndent( indent ) << "</active>" << endl; ts << makeIndent( indent ) << "<disabled>" << endl; indent++; saveColorGroup( ts, indent, p.disabled() ); indent--; ts << makeIndent( indent ) << "</disabled>" << endl; ts << makeIndent( indent ) << "<inactive>" << endl; indent++; saveColorGroup( ts, indent, p.inactive() ); indent--; ts << makeIndent( indent ) << "</inactive>" << endl; indent--; ts << makeIndent( indent ) << "</palette>" << endl; } break; case QVariant::Cursor: ts << makeIndent( indent ) << "<cursor>" << value.toCursor().shape() << "</cursor>" << endl; break; case QVariant::StringList: { QStringList lst = value.toStringList(); uint i = 0; ts << makeIndent( indent ) << "<stringlist>" << endl; indent++; if ( !lst.isEmpty() ) { for ( i = 0; i < lst.count(); ++i ) ts << makeIndent( indent ) << "<string>" << entitize( lst[ i ] ) << "</string>" << endl; } indent--; ts << makeIndent( indent ) << "</stringlist>" << endl; } break; case QVariant::Date: { QDate d = value.toDate(); ts << makeIndent( indent ) << "<date>" << endl; indent++; ts << makeIndent( indent ) << "<year>" << d.year() << "</year>" << endl; ts << makeIndent( indent ) << "<month>" << d.month() << "</month>" << endl; ts << makeIndent( indent ) << "<day>" << d.day() << "</day>" << endl; indent--; ts << makeIndent( indent ) << "</date>" << endl; break; } case QVariant::Time: { QTime t = value.toTime(); ts << makeIndent( indent ) << "<time>" << endl; indent++; ts << makeIndent( indent ) << "<hour>" << t.hour() << "</hour>" << endl; ts << makeIndent( indent ) << "<minute>" << t.minute() << "</minute>" << endl; ts << makeIndent( indent ) << "<second>" << t.second() << "</second>" << endl; indent--; ts << makeIndent( indent ) << "</time>" << endl; break; } case QVariant::DateTime: { QDateTime dt = value.toDateTime(); ts << makeIndent( indent ) << "<datetime>" << endl; indent++; ts << makeIndent( indent ) << "<year>" << dt.date().year() << "</year>" << endl; ts << makeIndent( indent ) << "<month>" << dt.date().month() << "</month>" << endl; ts << makeIndent( indent ) << "<day>" << dt.date().day() << "</day>" << endl; ts << makeIndent( indent ) << "<hour>" << dt.time().hour() << "</hour>" << endl; ts << makeIndent( indent ) << "<minute>" << dt.time().minute() << "</minute>" << endl; ts << makeIndent( indent ) << "<second>" << dt.time().second() << "</second>" << endl; indent--; ts << makeIndent( indent ) << "</datetime>" << endl; break; } default: qWarning( "saving the property %s of type %d not supported yet", name.latin1(), (int)t ); }}void Resource::saveColorGroup( QTextStream &ts, int indent, const QColorGroup &cg ){ for( int r = 0 ; r < QColorGroup::NColorRoles ; r++ ) { ts << makeIndent( indent ) << "<color>" << endl; indent++; saveColor( ts, indent, cg.color( (QColorGroup::ColorRole)r ) ); indent--; ts << makeIndent( indent ) << "</color>" << endl; QPixmap* pm = cg.brush( (QColorGroup::ColorRole)r ).pixmap(); if ( pm && !pm->isNull() ) savePixmap( *pm, ts, indent ); }}void Resource::saveColor( QTextStream &ts, int indent, const QColor &c ){ ts << makeIndent( indent ) << "<red>" << QString::number( c.red() ) << "</red>" << endl; ts << makeIndent( indent ) << "<green>" << QString::number( c.green() ) << "</green>" << endl; ts << makeIndent( indent ) << "<blue>" << QString::number( c.blue() ) << "</blue>" << endl;}QObject *Resource::createObject( const QDomElement &e, QWidget *parent, QLayout* layout ){ lastItem = 0; QDomElement n = e.firstChild().toElement(); QWidget *w = 0; // the widget that got created QObject *obj = 0; // gets the properties int row = e.attribute( "row" ).toInt(); int col = e.attribute( "column" ).toInt(); int rowspan = e.attribute( "rowspan" ).toInt(); int colspan = e.attribute( "colspan" ).toInt(); if ( rowspan < 1 ) rowspan = 1; if ( colspan < 1 ) colspan = 1; QString className = e.attribute( "class", "QWidget" );#ifdef QT_CONTAINER_CUSTOM_WIDGETS QString parentClassName = WidgetFactory::classNameOf( parent ); bool isPlugin = WidgetDatabase::isCustomPluginWidget( WidgetDatabase::idFromClassName( parentClassName ) ); if ( isPlugin ) qWarning( "####### loading custom container widgets without page support not implemented!" ); // ### TODO loading for custom container widgets without pages#endif if ( !className.isNull() ) { obj = WidgetFactory::create( WidgetDatabase::idFromClassName( className ), parent, 0, FALSE ); if ( !obj ) return 0; if ( !mainContainerSet ) { if ( formwindow ) formwindow->setMainContainer( (QWidget*)obj ); mainContainerSet = TRUE; } w = (QWidget*)obj; if ( w->inherits( "QMainWindow" ) ) w = ( (QMainWindow*)w )->centralWidget(); if ( layout ) { switch ( WidgetFactory::layoutType( layout ) ) { case WidgetFactory::HBox: ( (QHBoxLayout*)layout )->addWidget( w ); break; case WidgetFactory::VBox: ( (QVBoxLayout*)layout )->addWidget( w ); break; case WidgetFactory::Grid: ( (QDesignerGridLayout*)layout )->addMultiCellWidget( w, row, row + rowspan - 1, col, col + colspan - 1 ); break; default: break; } } if ( !toplevel ) toplevel = w; layout = 0; if ( w && formwindow ) { if ( !parent || ( !parent->inherits( "QTabWidget" ) && !parent->inherits("QWidgetStack") && !parent->inherits( "QWizard" )#ifdef QT_CONTAINER_CUSTOM_WIDGETS && !isPlugin#endif ) ) formwindow->insertWidget( w, pasting ); else if ( parent && ( parent->inherits( "QTabWidget" ) || parent->inherits("QWidgetStack") || parent->inherits( "QWizard" )#ifdef QT_CONTAINER_CUSTOM_WIDGETS
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -