📄 customwidgeteditorimpl.cpp
字号:
editSignal->blockSignals( TRUE ); editSignal->setEnabled( TRUE ); buttonRemoveSignal->setEnabled( TRUE ); editSignal->setText( i->text() ); editSignal->blockSignals( FALSE );}void CustomWidgetEditor::addSignal(){ QListBoxItem *i = new QListBoxText( listSignals, "signal()" ); listSignals->setCurrentItem( i ); listSignals->setSelected( i, TRUE ); MetaDataBase::CustomWidget *w = findWidget( boxWidgets->item( boxWidgets->currentItem() ) ); if ( w ) w->lstSignals.append( i->text().latin1() );}void CustomWidgetEditor::removeSignal(){ QString s = listSignals->currentText(); delete listSignals->item( listSignals->currentItem() ); if ( listSignals->currentItem() != -1 ) listSignals->setSelected( listSignals->currentItem(), TRUE ); MetaDataBase::CustomWidget *w = findWidget( boxWidgets->item( boxWidgets->currentItem() ) ); if ( w ) w->lstSignals.remove( s.latin1() );}void CustomWidgetEditor::signalNameChanged( const QString &s ){ MetaDataBase::CustomWidget *w = findWidget( boxWidgets->item( boxWidgets->currentItem() ) ); if ( !w || listSignals->currentItem() == -1 ) return; QValueList<QCString>::Iterator it = w->lstSignals.find( listSignals->currentText().latin1() ); if ( it != w->lstSignals.end() ) w->lstSignals.remove( it ); listSignals->blockSignals( TRUE ); listSignals->changeItem( s, listSignals->currentItem() ); listSignals->blockSignals( FALSE ); w->lstSignals.append( s.latin1() );}void CustomWidgetEditor::slotAccessChanged( const QString &s ){ MetaDataBase::CustomWidget *w = findWidget( boxWidgets->item( boxWidgets->currentItem() ) ); if ( !w || !listSlots->currentItem() ) return; MetaDataBase::Function slot; slot.function = listSlots->currentItem()->text( 0 ); slot.access = listSlots->currentItem()->text( 1 ); QValueList<MetaDataBase::Function>::Iterator it = w->lstSlots.find( slot ); if ( it != w->lstSlots.end() ) w->lstSlots.remove( it ); listSlots->currentItem()->setText( 1, s ); slot.function = listSlots->currentItem()->text( 0 ); slot.access = listSlots->currentItem()->text( 1 ); w->lstSlots.append( slot );}void CustomWidgetEditor::slotNameChanged( const QString &s ){ MetaDataBase::CustomWidget *w = findWidget( boxWidgets->item( boxWidgets->currentItem() ) ); if ( !w || !listSlots->currentItem() ) return; MetaDataBase::Function slot; slot.function = listSlots->currentItem()->text( 0 ); slot.access = listSlots->currentItem()->text( 1 ); QValueList<MetaDataBase::Function>::Iterator it = w->lstSlots.find( slot ); if ( it != w->lstSlots.end() ) w->lstSlots.remove( it ); listSlots->currentItem()->setText( 0, s ); slot.function = listSlots->currentItem()->text( 0 ); slot.access = listSlots->currentItem()->text( 1 ); w->lstSlots.append( slot );}void CustomWidgetEditor::addSlot(){ QListViewItem *i = new QListViewItem( listSlots, "slot()", "public" ); listSlots->setCurrentItem( i ); listSlots->setSelected( i, TRUE ); MetaDataBase::CustomWidget *w = findWidget( boxWidgets->item( boxWidgets->currentItem() ) ); if ( w ) { MetaDataBase::Function slot; slot.function = "slot()"; slot.access = "public"; slot.type = "slot"; w->lstSlots.append( slot ); }}void CustomWidgetEditor::removeSlot(){ MetaDataBase::Function slot; slot.function = "1 2 3"; if ( listSlots->currentItem() ) { slot.function = listSlots->currentItem()->text( 0 ); slot.access = listSlots->currentItem()->text( 1 ); } delete listSlots->currentItem(); if ( listSlots->currentItem() ) listSlots->setSelected( listSlots->currentItem(), TRUE ); MetaDataBase::CustomWidget *w = findWidget( boxWidgets->item( boxWidgets->currentItem() ) ); if ( w && slot.function != "1 2 3" ) w->lstSlots.remove( slot );}void CustomWidgetEditor::currentSlotChanged( QListViewItem *i ){ editSlot->blockSignals( TRUE ); editSlot->setText( "" ); editSignal->blockSignals( FALSE ); if ( !i ) { editSlot->setEnabled( FALSE ); comboAccess->setEnabled( FALSE ); buttonRemoveSlot->setEnabled( FALSE ); return; } editSlot->setEnabled( TRUE ); comboAccess->setEnabled( TRUE ); buttonRemoveSlot->setEnabled( TRUE ); editSlot->blockSignals( TRUE ); comboAccess->blockSignals( TRUE ); editSlot->setText( i->text( 0 ) ); if ( i->text( 1 ) == tr( "protected" ) ) comboAccess->setCurrentItem( 1 ); else comboAccess->setCurrentItem( 0 ); editSlot->blockSignals( FALSE ); comboAccess->blockSignals( FALSE );}void CustomWidgetEditor::propertyTypeChanged( const QString &s ){ MetaDataBase::CustomWidget *w = findWidget( boxWidgets->item( boxWidgets->currentItem() ) ); if ( !w || !listProperties->currentItem() ) return; MetaDataBase::Property property; property.property = listProperties->currentItem()->text( 0 ); property.type = listProperties->currentItem()->text( 1 ); QValueList<MetaDataBase::Property>::Iterator it = w->lstProperties.find( property ); if ( it != w->lstProperties.end() ) w->lstProperties.remove( it ); listProperties->currentItem()->setText( 1, s ); property.property = listProperties->currentItem()->text( 0 ); property.type = listProperties->currentItem()->text( 1 ); w->lstProperties.append( property );}void CustomWidgetEditor::propertyNameChanged( const QString &s ){ MetaDataBase::CustomWidget *w = findWidget( boxWidgets->item( boxWidgets->currentItem() ) ); if ( !w || !listProperties->currentItem() ) return; MetaDataBase::Property property; property.property = listProperties->currentItem()->text( 0 ); property.type = listProperties->currentItem()->text( 1 ); QValueList<MetaDataBase::Property>::Iterator it = w->lstProperties.find( property ); if ( it != w->lstProperties.end() ) w->lstProperties.remove( it ); listProperties->currentItem()->setText( 0, s ); property.property = listProperties->currentItem()->text( 0 ); property.type = listProperties->currentItem()->text( 1 ); w->lstProperties.append( property );}void CustomWidgetEditor::addProperty(){ QListViewItem *i = new QListViewItem( listProperties, "property", "String" ); listProperties->setCurrentItem( i ); listProperties->setSelected( i, TRUE ); MetaDataBase::CustomWidget *w = findWidget( boxWidgets->item( boxWidgets->currentItem() ) ); if ( w ) { MetaDataBase::Property prop; prop.property = "property"; prop.type = "String"; w->lstProperties.append( prop ); }}void CustomWidgetEditor::removeProperty(){ MetaDataBase::Property property; property.property = "1 2 3"; if ( listProperties->currentItem() ) { property.property = listProperties->currentItem()->text( 0 ); property.type = listProperties->currentItem()->text( 1 ); } delete listProperties->currentItem(); if ( listProperties->currentItem() ) listProperties->setSelected( listProperties->currentItem(), TRUE ); MetaDataBase::CustomWidget *w = findWidget( boxWidgets->item( boxWidgets->currentItem() ) ); if ( w && property.property != "1 2 3" ) w->lstProperties.remove( property );}void CustomWidgetEditor::currentPropertyChanged( QListViewItem *i ){ editProperty->blockSignals( TRUE ); editProperty->setText( "" ); editSignal->blockSignals( FALSE ); if ( !i ) { editProperty->setEnabled( FALSE ); comboType->setEnabled( FALSE ); buttonRemoveProperty->setEnabled( FALSE ); return; } editProperty->setEnabled( TRUE ); comboType->setEnabled( TRUE ); buttonRemoveProperty->setEnabled( TRUE ); editProperty->blockSignals( TRUE ); comboType->blockSignals( TRUE ); editProperty->setText( i->text( 0 ) ); for ( int j = 0; j < comboType->count(); ++j ) { if ( i->text( 1 ) == comboType->text( j ) ) { comboType->setCurrentItem( j ); break; } } editProperty->blockSignals( FALSE ); comboType->blockSignals( FALSE );}static QString makeIndent2( int indent ){ QString s; s.fill( ' ', indent * 4 ); return s;}static QString entitize2( const QString &s ){ QString s2 = s; s2 = s2.replace( "\"", """ ); s2 = s2.replace( "&", "&" ); s2 = s2.replace( ">", ">" ); s2 = s2.replace( "<", "<" ); s2 = s2.replace( "'", "'" ); return s2;}void CustomWidgetEditor::saveDescription(){ QString fn = QFileDialog::getSaveFileName( QString::null, tr( "Custom-Widget Description (*.cw);;All Files (*)" ), this ); if ( fn.isEmpty() ) return; if ( QFileInfo( fn ).extension() != "cw" ) fn += ".cw"; QFile f( fn ); if ( !f.open( IO_WriteOnly ) ) return; QTextStream ts( &f ); ts.setCodec( QTextCodec::codecForName( "UTF-8" ) ); int indent = 0; ts << "<!DOCTYPE CW><CW>" << endl; ts << makeIndent2( indent ) << "<customwidgets>" << endl; indent++; QPtrList<MetaDataBase::CustomWidget> *lst = MetaDataBase::customWidgets(); for ( MetaDataBase::CustomWidget *w = lst->first(); w; w = lst->next() ) { ts << makeIndent2( indent ) << "<customwidget>" << endl; indent++; ts << makeIndent2( indent ) << "<class>" << w->className << "</class>" << endl; ts << makeIndent2( indent ) << "<header location=\"" << ( w->includePolicy == MetaDataBase::CustomWidget::Local ? "local" : "global" ) << "\">" << w->includeFile << "</header>" << endl; ts << makeIndent2( indent ) << "<sizehint>" << endl; indent++; ts << makeIndent2( indent ) << "<width>" << w->sizeHint.width() << "</width>" << endl; ts << makeIndent2( indent ) << "<height>" << w->sizeHint.height() << "</height>" << endl; indent--; ts << makeIndent2( indent ) << "</sizehint>" << endl; ts << makeIndent2( indent ) << "<container>" << (int)w->isContainer << "</container>" << endl; ts << makeIndent2( indent ) << "<sizepolicy>" << endl; indent++; ts << makeIndent2( indent ) << "<hordata>" << (int)w->sizePolicy.horData() << "</hordata>" << endl; ts << makeIndent2( indent ) << "<verdata>" << (int)w->sizePolicy.verData() << "</verdata>" << endl; indent--; ts << makeIndent2( indent ) << "</sizepolicy>" << endl; ts << makeIndent2( indent ) << "<pixmap>" << endl; indent++; Resource::saveImageData( w->pixmap->convertToImage(), ts, indent ); indent--; ts << makeIndent2( indent ) << "</pixmap>" << endl; if ( !w->lstSignals.isEmpty() ) { for ( QValueList<QCString>::Iterator it = w->lstSignals.begin(); it != w->lstSignals.end(); ++it ) ts << makeIndent2( indent ) << "<signal>" << entitize2( *it ) << "</signal>" << endl; } if ( !w->lstSlots.isEmpty() ) { for ( QValueList<MetaDataBase::Function>::Iterator it = w->lstSlots.begin(); it != w->lstSlots.end(); ++it ) ts << makeIndent2( indent ) << "<slot access=\"" << (*it).access << "\">" << entitize2( (*it).function ) << "</slot>" << endl; } if ( !w->lstProperties.isEmpty() ) { for ( QValueList<MetaDataBase::Property>::Iterator it = w->lstProperties.begin(); it != w->lstProperties.end(); ++it ) ts << makeIndent2( indent ) << "<property type=\"" << (*it).type << "\">" << entitize2( (*it).property ) << "</property>" << endl; } indent--; ts << makeIndent2( indent ) << "</customwidget>" << endl; } indent--; ts << makeIndent2( indent ) << "</customwidgets>" << endl; ts << "</CW>" << endl;}void CustomWidgetEditor::loadDescription(){ QString fn = QFileDialog::getOpenFileName( QString::null, tr( "Custom-Widget Description (*.cw);;All Files (*)" ), this ); if ( fn.isEmpty() ) return; QFile f( fn ); if ( !f.open( IO_ReadOnly ) ) return; QDomDocument doc; QString errMsg; int errLine; if ( !doc.setContent( &f, &errMsg, &errLine ) ) { qDebug( QString("Parse error: ") + errMsg + QString(" in line %d"), errLine ); return; } QDomElement firstWidget = doc.firstChild().toElement().firstChild().toElement(); while ( firstWidget.tagName() != "customwidgets" ) firstWidget = firstWidget.nextSibling().toElement(); Resource::loadCustomWidgets( firstWidget, 0 ); boxWidgets->clear(); setupDefinition(); setupSignals(); setupSlots(); setupProperties();}void CustomWidgetEditor::updateCustomWidgetSizes(){ if ( cwLst.isEmpty() ) cwLst = *mainWindow->queryList( "CustomWidget" ); for ( QObject *o = cwLst.first(); o; o = cwLst.next() ) ( (QWidget*)o )->updateGeometry();}void CustomWidgetEditor::horDataChanged( int a ){ QSizePolicy::SizeType st = int_to_size_type( a ); QListBoxItem *i = boxWidgets->item( boxWidgets->currentItem() ); MetaDataBase::CustomWidget *w = findWidget( i ); if ( !i || !w ) return; QSizePolicy osp = w->sizePolicy; w->sizePolicy.setHorData( st ); if ( cwLst.isEmpty() ) cwLst = *mainWindow->queryList( "CustomWidget" ); for ( QObject *o = cwLst.first(); o; o = cwLst.next() ) { CustomWidget *cw = (CustomWidget*)o; if ( cw->realClassName() == boxWidgets->currentText() ) { if ( cw->sizePolicy() == osp ) cw->setSizePolicy( w->sizePolicy ); } }}void CustomWidgetEditor::verDataChanged( int a ){ QSizePolicy::SizeType st = int_to_size_type( a ); QListBoxItem *i = boxWidgets->item( boxWidgets->currentItem() ); MetaDataBase::CustomWidget *w = findWidget( i ); if ( !i || !w ) return; QSizePolicy osp = w->sizePolicy; w->sizePolicy.setVerData( st ); if ( cwLst.isEmpty() ) cwLst = *mainWindow->queryList( "CustomWidget" ); for ( QObject *o = cwLst.first(); o; o = cwLst.next() ) { CustomWidget *cw = (CustomWidget*)o; if ( cw->realClassName() == boxWidgets->currentText() ) { if ( cw->sizePolicy() == osp ) cw->setSizePolicy( w->sizePolicy ); } }}void CustomWidgetEditor::widgetIsContainer( bool b ){ QListBoxItem *i = boxWidgets->item( boxWidgets->currentItem() ); MetaDataBase::CustomWidget *w = findWidget( i ); if ( !i || !w ) return; w->isContainer = b; WidgetDatabaseRecord *r = WidgetDatabase::at( w->id ); if ( r ) r->isContainer = b;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -