resource.cpp
来自「qt-x11-free-3.0.3.tar.gz minigui图形界面工具」· C++ 代码 · 共 1,943 行 · 第 1/5 页
CPP
1,943 行
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" ); 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( "QWizard" ) ) ) formwindow->insertWidget( w, pasting ); else if ( parent && ( parent->inherits( "QTabWidget" ) || parent->inherits( "QWizard" ) ) ) MetaDataBase::addEntry( w ); } } while ( !n.isNull() ) { if ( n.tagName() == "spacer" ) { createSpacer( n, w, layout, Qt::Horizontal ); } else if ( n.tagName() == "widget" ) { createObject( n, w, layout ); } else if ( n.tagName() == "hbox" ) { layout = WidgetFactory::createLayout( w, layout, WidgetFactory::HBox ); obj = layout; n = n.firstChild().toElement(); continue; } else if ( n.tagName() == "grid" ) { layout = WidgetFactory::createLayout( w, layout, WidgetFactory::Grid ); obj = layout; n = n.firstChild().toElement(); continue; } else if ( n.tagName() == "vbox" ) { layout = WidgetFactory::createLayout( w, layout, WidgetFactory::VBox ); obj = layout; n = n.firstChild().toElement(); continue; } else if ( n.tagName() == "property" && obj ) { setObjectProperty( obj, n.attribute( "name" ), n.firstChild().toElement() ); } else if ( n.tagName() == "attribute" && w ) { QString attrib = n.attribute( "name" ); QVariant v = DomTool::elementToVariant( n.firstChild().toElement(), QVariant() ); if ( parent->inherits( "QTabWidget" ) ) { if ( attrib == "title" ) ( (QTabWidget*)parent )->insertTab( w, v.toString() ); } else if ( parent->inherits( "QWizard" ) ) { if ( attrib == "title" ) ( (QWizard*)parent )->addPage( w, v.toString() ); } } else if ( n.tagName() == "item" ) { createItem( n, w ); } else if ( n.tagName() == "column" || n.tagName() =="row" ) { createColumn( n, w ); } else if ( n.tagName() == "event" ) { MetaDataBase::setEventFunctions( obj, formwindow, MainWindow::self->currProject()->language(), n.attribute( "name" ), QStringList::split( ',', n.attribute( "functions" ) ), FALSE ); } n = n.nextSibling().toElement(); } return w;}void Resource::createColumn( const QDomElement &e, QWidget *widget ){ if ( !widget ) return; if ( widget->inherits( "QListView" ) && e.tagName() == "column" ) { QListView *lv = (QListView*)widget; QDomElement n = e.firstChild().toElement(); QPixmap pix; bool hasPixmap = FALSE; QString txt; bool clickable = TRUE, resizeable = TRUE; while ( !n.isNull() ) { if ( n.tagName() == "property" ) { QString attrib = n.attribute( "name" ); QVariant v = DomTool::elementToVariant( n.firstChild().toElement(), QVariant() ); if ( attrib == "text" ) txt = v.toString(); else if ( attrib == "pixmap" ) { pix = loadPixmap( n.firstChild().toElement().toElement() ); hasPixmap = !pix.isNull(); } else if ( attrib == "clickable" ) clickable = v.toBool(); else if ( attrib == "resizeable" ) resizeable = v.toBool(); } n = n.nextSibling().toElement(); } lv->addColumn( txt ); int i = lv->header()->count() - 1; if ( hasPixmap ) { lv->header()->setLabel( i, pix, txt ); } if ( !clickable ) lv->header()->setClickEnabled( clickable, i ); if ( !resizeable ) lv->header()->setResizeEnabled( resizeable, i ); }#ifndef QT_NO_TABLE else if ( widget->inherits( "QTable" ) ) { QTable *table = (QTable*)widget; bool isRow; if ( ( isRow = e.tagName() == "row" ) ) table->setNumRows( table->numRows() + 1 ); else table->setNumCols( table->numCols() + 1 ); QDomElement n = e.firstChild().toElement(); QPixmap pix; bool hasPixmap = FALSE; QString txt; QString field; QMap<QString, QString> fieldMap = MetaDataBase::columnFields( table ); while ( !n.isNull() ) { if ( n.tagName() == "property" ) { QString attrib = n.attribute( "name" ); QVariant v = DomTool::elementToVariant( n.firstChild().toElement(), QVariant() ); if ( attrib == "text" ) txt = v.toString(); else if ( attrib == "pixmap" ) { hasPixmap = !n.firstChild().firstChild().toText().data().isEmpty(); if ( hasPixmap ) pix = loadPixmap( n.firstChild().toElement() ); } else if ( attrib == "field" ) field = v.toString(); } n = n.nextSibling().toElement(); } int i = isRow ? table->numRows() - 1 : table->numCols() - 1; QHeader *h = !isRow ? table->horizontalHeader() : table->verticalHeader(); if ( hasPixmap ) h->setLabel( i, pix, txt ); else h->setLabel( i, txt ); if ( !isRow && !field.isEmpty() ) fieldMap.insert( txt, field ); MetaDataBase::setColumnFields( table, fieldMap ); }#endif}void Resource::loadItem( const QDomElement &e, QPixmap &pix, QString &txt, bool &hasPixmap ){ QDomElement n = e; hasPixmap = FALSE; while ( !n.isNull() ) { if ( n.tagName() == "property" ) { QString attrib = n.attribute( "name" ); QVariant v = DomTool::elementToVariant( n.firstChild().toElement(), QVariant() ); if ( attrib == "text" ) txt = v.toString(); else if ( attrib == "pixmap" ) { pix = loadPixmap( n.firstChild().toElement() ); hasPixmap = !pix.isNull(); } } n = n.nextSibling().toElement(); }}void Resource::createItem( const QDomElement &e, QWidget *widget, QListViewItem *i ){ if ( !widget || !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" ) { QString attrib = n.attribute( "name" ); QVariant v = DomTool::elementToVariant( n.firstChild().toElement(), QVariant() ); if ( attrib == "text" ) textes << v.toString(); else if ( attrib == "pixmap" ) { QString s = v.toString(); if ( s.isEmpty() ) { pixmaps << QPixmap(); } else { pix = loadPixmap( n.firstChild().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 ] );
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?