📄 resource.cpp
字号:
} if ( !clickable ) lv->header()->setClickEnabled( clickable, i ); if ( !resizeable ) lv->header()->setResizeEnabled( resizeable, i ); }}void Resource::loadItem( const QDomElement &e, QPixmap &pix, QString &txt, bool &hasPixmap ){ QDomElement n = e; hasPixmap = FALSE; while ( !n.isNull() ) { if ( n.tagName() == "property" ) { QDomElement n2 = n.firstChild().toElement(); if ( n2.tagName() == "name" ) { QString attrib = n2.firstChild().toText().data(); QVariant v = DomTool::elementToVariant( n2.nextSibling().toElement(), QVariant() ); if ( attrib == "text" ) txt = v.toString(); else if ( attrib == "pixmap" ) { pix = loadPixmap( n2.nextSibling().toElement() ); hasPixmap = TRUE; } } } n = n.nextSibling().toElement(); }}void Resource::createItem( const QDomElement &e, QWidget *widget, QListViewItem *i ){ if ( !WidgetFactory::hasItems( WidgetDatabase::idFromClassName( WidgetFactory::classNameOf( widget ) ) ) ) return; if ( widget->inherits( "QListBox" ) || widget->inherits( "QComboBox" ) ) { QDomElement n = e.firstChild().toElement(); QPixmap pix; bool hasPixmap = FALSE; QString txt; loadItem( n, pix, txt, hasPixmap ); QListBox *lb = 0; if ( widget->inherits( "QListBox" ) ) lb = (QListBox*)widget; else lb = ( (QComboBox*)widget)->listBox(); if ( hasPixmap ) { new QListBoxPixmap( lb, pix, txt ); } else { new QListBoxText( lb, txt ); } } else if ( widget->inherits( "QIconView" ) ) { QDomElement n = e.firstChild().toElement(); QPixmap pix; bool hasPixmap = FALSE; QString txt; loadItem( n, pix, txt, hasPixmap ); QIconView *iv = (QIconView*)widget; new QIconViewItem( iv, txt, pix ); } else if ( widget->inherits( "QListView" ) ) { QDomElement n = e.firstChild().toElement(); QPixmap pix; QValueList<QPixmap> pixmaps; QStringList textes; QListViewItem *item = 0; QListView *lv = (QListView*)widget; if ( i ) item = new QListViewItem( i, lastItem ); else item = new QListViewItem( lv, lastItem ); while ( !n.isNull() ) { if ( n.tagName() == "property" ) { QDomElement n2 = n.firstChild().toElement(); if ( n2.tagName() == "name" ) { QString attrib = n2.firstChild().toText().data(); QVariant v = DomTool::elementToVariant( n2.nextSibling().toElement(), QVariant() ); if ( attrib == "text" ) textes << v.toString(); else if ( attrib == "pixmap" ) { QString s = v.toString(); if ( s.isEmpty() ) { pixmaps << QPixmap(); } else { pix = loadPixmap( n2.nextSibling().toElement() ); pixmaps << pix; } } } } else if ( n.tagName() == "item" ) { item->setOpen( TRUE ); createItem( n, widget, item ); } n = n.nextSibling().toElement(); } for ( int i = 0; i < lv->columns(); ++i ) { item->setText( i, textes[ i ] ); item->setPixmap( i, pixmaps[ i ] ); } lastItem = item; }}QWidget *Resource::createSpacer( const QDomElement &e, QWidget *parent, QLayout *layout, Qt::Orientation o ){ Spacer *spacer = (Spacer*) WidgetFactory::create( WidgetDatabase::idFromClassName("Spacer"), parent, "spacer", FALSE); spacer->setOrientation( o ); QDomElement n = e.firstChild().toElement(); 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; spacer->setAutoResize( FALSE ); while ( !n.isNull() ) { if ( n.tagName() == "property" ) { QDomElement n2 = n.firstChild().toElement(); if ( n2.tagName() == "name" ) setObjectProperty( spacer, n2.firstChild().toText().data(), n2.nextSibling().toElement() ); } n = n.nextSibling().toElement(); } spacer->setAutoResize( TRUE ); if ( !previewMode ) { if ( formwindow ) formwindow->insertWidget( spacer, pasting ); if ( layout ) { if ( layout->inherits( "QBoxLayout" ) ) ( (QBoxLayout*)layout )->addWidget( spacer, 0, spacer->alignment() ); else ( (QDesignerGridLayout*)layout )->addMultiCellWidget( spacer, row, row + rowspan - 1, col, col + colspan - 1, spacer->alignment() ); } } else { QSpacerItem *item = new QSpacerItem( spacer->width(), spacer->height(), spacer->sizePolicy().horData(), spacer->sizePolicy().verData() ); if ( layout ) { if ( layout->inherits( "QBoxLayout" ) ) ( (QBoxLayout*)layout )->addItem( item ); else ( (QDesignerGridLayout*)layout )->addMultiCell( item, row, row + rowspan - 1, col, col + colspan - 1, spacer->alignment() ); } delete spacer; return 0; } return spacer;}/*! Attention: this function has to be in sync with Uic::setObjectProperty(). If you change one, change both.*/void Resource::setObjectProperty( QObject* obj, const QString &prop, const QDomElement &e ){ const QMetaProperty *p = obj->metaObject()->property( prop, TRUE ); if ( !obj->inherits( "QLayout" ) && !previewMode ) {// no layouts in metadatabase... (RS) if ( obj->inherits( "CustomWidget" ) ) { MetaDataBase::CustomWidget *cw = ( (CustomWidget*)obj )->customWidget(); if ( cw && !cw->hasProperty( prop.latin1() ) && !p && prop != "toolTip" && prop != "whatsThis" ) return; } MetaDataBase::setPropertyChanged( obj, prop, TRUE ); } QVariant defVarient; if ( e.tagName() == "font" ) { QFont f( qApp->font() ); if ( obj->isWidgetType() && ( (QWidget*)obj )->parentWidget() ) f = ( (QWidget*)obj )->parentWidget()->font(); defVarient = QVariant( f ); } QString comment; QVariant v( DomTool::elementToVariant( e, defVarient, comment ) ); if ( !comment.isEmpty() ) { MetaDataBase::addEntry( obj ); MetaDataBase::setPropertyComment( obj, prop, comment ); } if ( !p ) { if ( !previewMode ) MetaDataBase::setFakeProperty( obj, prop, v ); if ( obj->isWidgetType() ) { if ( prop == "toolTip" ) { if ( previewMode && !v.toString().isEmpty() ) QToolTip::add( (QWidget*)obj, v.toString() ); } else if ( prop == "whatsThis" ) { if ( previewMode && !v.toString().isEmpty() ) QWhatsThis::add( (QWidget*)obj, v.toString() ); } return; } } if ( e.tagName() == "pixmap" ) { QPixmap pix = loadPixmap( e ); v = QVariant( pix ); } else if ( e.tagName() == "iconset" ) { QPixmap pix; pix.convertFromImage( loadFromCollection( v.toString() ) ); v = QVariant( QIconSet( pix ) ); } else if ( e.tagName() == "image" ) { v = QVariant( loadFromCollection( v.toString() ) ); } else if ( e.tagName() == "palette" ) { QDomElement n = e.firstChild().toElement(); QPalette p; while ( !n.isNull() ) { QColorGroup cg; if ( n.tagName() == "active" ) { cg = loadColorGroup( n ); p.setActive( cg ); } else if ( n.tagName() == "inactive" ) { cg = loadColorGroup( n ); p.setInactive( cg ); } else if ( n.tagName() == "disabled" ) { cg = loadColorGroup( n ); p.setDisabled( cg ); } n = n.nextSibling().toElement(); } v = QPalette( p ); } else if ( e.tagName() == "enum" && p && p->isEnumType() ) { QString key( v.toString() ); v = QVariant( p->keyToValue( key ) ); } else if ( e.tagName() == "set" && p && p->isSetType() ) { QString keys( v.toString() ); QStringList lst = QStringList::split( '|', keys ); QStrList l; for ( QStringList::Iterator it = lst.begin(); it != lst.end(); ++it ) l.append( *it ); v = QVariant( p->keysToValue( l ) ); } if ( !previewMode && prop == "caption" ) { QCString s1 = v.toCString(); QString s2 = v.toString(); if ( !s1.isEmpty() ) formwindow->setCaption( s1 ); else if ( !s2.isEmpty() ) formwindow->setCaption( s2 ); } if ( !previewMode && prop == "icon" ) { formwindow->setIcon( v.toPixmap() ); } if ( prop == "geometry" ) { if ( previewMode && obj == toplevel ) { toplevel->resize( v.toRect().size() ); return; } else if ( !previewMode && obj == formwindow->mainContainer() ) { formwindow->resize( v.toRect().size() ); return; } } if ( obj->inherits( "QLayout" ) && !previewMode ) { if ( prop == "spacing" ) { MetaDataBase::setSpacing( WidgetFactory::containerOfWidget( WidgetFactory::layoutParent( (QLayout*)obj ) ), v.toInt() ); return; } if ( prop == "margin" ) { MetaDataBase::setMargin( WidgetFactory::containerOfWidget( WidgetFactory::layoutParent( (QLayout*)obj ) ), v.toInt() ); return; } } if ( prop == "name" ) { if ( pasting ) { QString s = v.toString(); formwindow->unify( (QWidget*)obj, s, TRUE ); obj->setName( s ); return; } else if ( !previewMode && formwindow && obj == formwindow->mainContainer() ) { formwindow->setName( v.toCString() ); } } if ( prop == "sizePolicy" ) { QSizePolicy sp = v.toSizePolicy(); sp.setHeightForWidth( ( (QWidget*)obj )->sizePolicy().hasHeightForWidth() ); } obj->setProperty( prop, v );}QString Resource::saveInCollection( const QImage &img ){ QString imgName = "none"; QValueList<Image>::Iterator it = images.begin(); for ( ; it != images.end(); ++it ) { if ( img == ( *it ).img ) { imgName = ( *it ).name; break; } } if ( imgName == "none" ) { Image i; imgName = "image" + QString::number( images.count() ); i.name = imgName; i.img = img; images.append( i ); } return imgName;}void Resource::saveImageData( const QImage &img, QTextStream &ts, int indent ){ QByteArray ba; QBuffer buf( ba ); buf.open( IO_WriteOnly ); QImageIO iio( &buf, "XPM" ); iio.setImage( img ); iio.write(); buf.close(); ulong len = ba.size() * 2; QByteArray bazip( len ); ::compress( (uchar*) bazip.data(), &len, (uchar*) ba.data(), ba.size() ); QString res; ts << makeIndent( indent ) << "<data format=\"XPM.GZ\" length=\"" << ba.size() << "\">"; static const char hexchars[] = "0123456789abcdef"; for ( int i = 0; i < (int)len; ++i ) { uchar s = (uchar) bazip[i]; ts << hexchars[s >> 4]; ts << hexchars[s & 0x0f]; } ts << "</data>" << endl;}void Resource::saveImageCollection( QTextStream &ts, int indent ){ ts << makeIndent( indent ) << "<images>" << endl; indent++; QValueList<Image>::Iterator it = images.begin(); for ( ; it != images.end(); ++it ) { ts << makeIndent( indent ) << "<image>" << endl; indent++; ts << makeIndent( indent ) << "<name>" << ( *it ).name << "</name>" << endl; saveImageData( (*it).img, ts, indent ); indent--; ts << makeIndent( indent ) << "</image>" << endl; } indent--; ts << makeIndent( indent ) << "</images>" << endl;}static QImage loadImageData( QDomElement &n2 ){ QImage img; QString data = n2.firstChild().toText().data(); char *ba = new char[ data.length() / 2 ]; for ( int i = 0; i < (int)data.length() / 2; ++i ) { char h = data[ 2 * i ].latin1(); char l = data[ 2 * i + 1 ].latin1(); uchar r = 0; if ( h <= '9' ) r += h - '0'; else r += h - 'a' + 10; r = r << 4; if ( l <= '9' ) r += l - '0';
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -