📄 command.cpp
字号:
{ if ( !wasChanged ) MetaDataBase::setPropertyChanged( widget, propName, TRUE ); if ( isResetCommand ) { MetaDataBase::setPropertyChanged( widget, propName, FALSE ); if ( WidgetFactory::resetProperty( widget, propName ) ) { if ( !formWindow()->isWidgetSelected( widget ) && widget != formWindow() ) formWindow()->selectWidget( widget ); if ( editor->widget() != widget ) editor->setWidget( widget, formWindow() ); editor->propertyList()->setCurrentProperty( propName ); PropertyItem *i = (PropertyItem*)editor->propertyList()->currentItem(); if ( !i ) return; i->setValue( widget->property( propName ) ); i->setChanged( FALSE ); editor->refetchData(); editor->emitWidgetChanged(); return; } } setProperty( newValue, newCurrentItemText );}void SetPropertyCommand::unexecute(){ if ( !wasChanged ) MetaDataBase::setPropertyChanged( widget, propName, FALSE ); if ( isResetCommand ) MetaDataBase::setPropertyChanged( widget, propName, TRUE ); setProperty( oldValue, oldCurrentItemText );}bool SetPropertyCommand::canMerge( Command *c ){ SetPropertyCommand *cmd = (SetPropertyCommand*)c; const QMetaProperty *p = widget->metaObject()->property( propName, TRUE ); if ( !p ) { if ( propName == "toolTip" || propName == "whatsThis" ) return TRUE; if ( widget->inherits( "CustomWidget" ) ) { MetaDataBase::CustomWidget *cw = ( (CustomWidget*)widget )->customWidget(); if ( !cw ) return FALSE; for ( QValueList<MetaDataBase::Property>::Iterator it = cw->lstProperties.begin(); it != cw->lstProperties.end(); ++it ) { if ( QString( (*it ).property ) == propName ) { if ( (*it).type == "String" || (*it).type == "CString" || (*it).type == "Int" || (*it).type == "UInt" ) return TRUE; } } } return FALSE; } QVariant::Type t = QVariant::nameToType( p->type() ); return ( cmd->propName == propName && t == QVariant::String || t == QVariant::CString || t == QVariant::Int || t == QVariant::UInt );}void SetPropertyCommand::merge( Command *c ){ SetPropertyCommand *cmd = (SetPropertyCommand*)c; newValue = cmd->newValue; newCurrentItemText = cmd->newCurrentItemText;}bool SetPropertyCommand::checkProperty(){ if ( propName == "name" ) { QString s = newValue.toString(); if ( !formWindow()->unify( widget, s, FALSE ) ) { QMessageBox::information( formWindow()->mainWindow(), FormWindow::tr( "Set 'name' property" ), FormWindow::tr( "The name of a widget has to be unique!\n" "'%1' is already used in the form '%2',\n" "so the name has been changed back to '%3'." ). arg( newValue.toString() ). arg( formWindow()->name() ). arg( oldValue.toString() )); setProperty( oldValue, oldCurrentItemText, FALSE ); return FALSE; } } return TRUE;}void SetPropertyCommand::setProperty( const QVariant &v, const QString ¤tItemText, bool select ){ if ( !formWindow()->isWidgetSelected( widget ) && !formWindow()->isMainContainer( widget ) && select ) formWindow()->selectWidget( widget ); if ( editor->widget() != widget && select ) editor->setWidget( widget, formWindow() ); if ( select ) editor->propertyList()->setCurrentProperty( propName ); const QMetaProperty *p = widget->metaObject()->property( propName, TRUE ); if ( !p ) { if ( propName == "hAlign" ) { p = widget->metaObject()->property( "alignment", TRUE ); int align = widget->property( "alignment" ).toInt(); align &= ~( AlignLeft | AlignHCenter | AlignRight ); align |= p->keyToValue( currentItemText ); widget->setProperty( "alignment", QVariant( align ) ); } else if ( propName == "vAlign" ) { p = widget->metaObject()->property( "alignment", TRUE ); int align = widget->property( "alignment" ).toInt(); align &= ~( AlignTop | AlignVCenter | AlignBottom ); align |= p->keyToValue( currentItemText ); widget->setProperty( "alignment", QVariant( align ) ); } else if ( propName == "wordwrap" ) { int align = widget->property( "alignment" ).toInt(); align &= ~WordBreak; if ( v.toBool() ) align |= WordBreak; widget->setProperty( "alignment", QVariant( align ) ); } else if ( propName == "layoutSpacing" ) { MetaDataBase::setSpacing( WidgetFactory::containerOfWidget( editor->widget() ), v.toInt() ); } else if ( propName == "layoutMargin" ) { MetaDataBase::setMargin( WidgetFactory::containerOfWidget( editor->widget() ), v.toInt() ); } else if ( propName == "toolTip" || propName == "whatsThis" ) { MetaDataBase::setFakeProperty( editor->widget(), propName, v ); } else if ( editor->widget()->inherits( "CustomWidget" ) ) { MetaDataBase::CustomWidget *cw = ( (CustomWidget*)widget )->customWidget(); if ( cw ) { MetaDataBase::setFakeProperty( editor->widget(), propName, v ); } } editor->refetchData(); editor->emitWidgetChanged(); ( ( PropertyItem* )editor->propertyList()->currentItem() )->setChanged( MetaDataBase::isPropertyChanged( widget, propName ) ); return; } if ( p->isSetType() ) { ; } else if ( p->isEnumType() ) { widget->setProperty( propName, p->keyToValue( currentItemText ) ); } else { QVariant ov; if ( propName == "name" ) ov = widget->property( propName ); widget->setProperty( propName, v ); if ( propName == "cursor" ) MetaDataBase::setCursor( widget, v.toCursor() ); if ( propName == "name" ) { formWindow()->mainWindow()->objectHierarchy()->namePropertyChanged( widget, ov ); if ( formWindow()->isMainContainer( widget ) ) { formWindow()->mainWindow()->formlist()->nameChanged( (FormWindow*)widget ); formWindow()->setName( v.toCString() ); } } if ( propName == "caption" ) { if ( formWindow()->isMainContainer( widget ) ) formWindow()->setCaption( v.toString() ); } if ( propName == "icon" ) { if ( formWindow()->isMainContainer( widget ) ) formWindow()->setIcon( v.toPixmap() ); } } editor->refetchData(); if ( editor->propertyList()->currentItem() && select ) { ( ( PropertyItem* )editor->propertyList()->currentItem() )->showEditor(); ( ( PropertyItem* )editor->propertyList()->currentItem() )->setChanged( MetaDataBase::isPropertyChanged( widget, propName ) ); } editor->emitWidgetChanged();}// ------------------------------------------------------------LayoutHorizontalCommand::LayoutHorizontalCommand( const QString &n, FormWindow *fw, QWidget *parent, QWidget *layoutBase, const QWidgetList &wl ) : Command( n, fw ), layout( wl, parent, fw, layoutBase ){}void LayoutHorizontalCommand::execute(){ formWindow()->clearSelection( FALSE ); layout.doLayout(); formWindow()->mainWindow()->objectHierarchy()->rebuild();}void LayoutHorizontalCommand::unexecute(){ formWindow()->clearSelection( FALSE ); layout.undoLayout(); formWindow()->mainWindow()->objectHierarchy()->rebuild();}// ------------------------------------------------------------LayoutVerticalCommand::LayoutVerticalCommand( const QString &n, FormWindow *fw, QWidget *parent, QWidget *layoutBase, const QWidgetList &wl ) : Command( n, fw ), layout( wl, parent, fw, layoutBase ){}void LayoutVerticalCommand::execute(){ formWindow()->clearSelection( FALSE ); layout.doLayout(); formWindow()->mainWindow()->objectHierarchy()->rebuild();}void LayoutVerticalCommand::unexecute(){ formWindow()->clearSelection( FALSE ); layout.undoLayout(); formWindow()->mainWindow()->objectHierarchy()->rebuild();}// ------------------------------------------------------------LayoutGridCommand::LayoutGridCommand( const QString &n, FormWindow *fw, QWidget *parent, QWidget *layoutBase, const QWidgetList &wl, int xres, int yres ) : Command( n, fw ), layout( wl, parent, fw, layoutBase, QSize( xres, yres ) ){}void LayoutGridCommand::execute(){ formWindow()->clearSelection( FALSE ); layout.doLayout(); formWindow()->mainWindow()->objectHierarchy()->rebuild();}void LayoutGridCommand::unexecute(){ formWindow()->clearSelection( FALSE ); layout.undoLayout(); formWindow()->mainWindow()->objectHierarchy()->rebuild();}// ------------------------------------------------------------BreakLayoutCommand::BreakLayoutCommand( const QString &n, FormWindow *fw, QWidget *layoutBase, const QWidgetList &wl ) : Command( n, fw ), lb( layoutBase ), widgets( wl ){ WidgetFactory::LayoutType lay = WidgetFactory::layoutType( layoutBase ); spacing = MetaDataBase::spacing( layoutBase ); margin = MetaDataBase::margin( layoutBase ); layout = 0; if ( lay == WidgetFactory::HBox ) layout = new HorizontalLayout( wl, layoutBase, fw, layoutBase, FALSE ); else if ( lay == WidgetFactory::VBox ) layout = new VerticalLayout( wl, layoutBase, fw, layoutBase, FALSE ); else if ( lay == WidgetFactory::Grid ) layout = new GridLayout( wl, layoutBase, fw, layoutBase, QSize( fw->grid().x(), fw->grid().y()), FALSE );}void BreakLayoutCommand::execute(){ if ( !layout ) return; formWindow()->clearSelection( FALSE ); layout->breakLayout(); formWindow()->mainWindow()->objectHierarchy()->rebuild(); for ( QWidget *w = widgets.first(); w; w = widgets.next() ) w->resize( QMAX( 16, w->width() ), QMAX( 16, w->height() ) );}void BreakLayoutCommand::unexecute(){ if ( !layout ) return; formWindow()->clearSelection( FALSE ); layout->doLayout(); formWindow()->mainWindow()->objectHierarchy()->rebuild(); MetaDataBase::setSpacing( WidgetFactory::containerOfWidget( lb ), spacing ); MetaDataBase::setMargin( WidgetFactory::containerOfWidget( lb ), margin );}// ------------------------------------------------------------MacroCommand::MacroCommand( const QString &n, FormWindow *fw, const QList<Command> &cmds ) : Command( n, fw ), commands( cmds ){}void MacroCommand::execute(){ for ( Command *c = commands.first(); c; c = commands.next() ) c->execute();}void MacroCommand::unexecute(){ for ( Command *c = commands.last(); c; c = commands.prev() ) c->unexecute();}// ------------------------------------------------------------AddTabPageCommand::AddTabPageCommand( const QString &n, FormWindow *fw, QTabWidget *tw, const QString &label ) : Command( n, fw ), tabWidget( tw ), tabLabel( label ){ tabPage = new QDesignerWidget( formWindow(), tabWidget, "tab" ); tabPage->hide(); index = -1; MetaDataBase::addEntry( tabPage );}void AddTabPageCommand::execute(){ if ( index == -1 ) index = ( (QDesignerTabWidget*)tabWidget )->count(); tabWidget->insertTab( tabPage, tabLabel, index ); tabWidget->showPage( tabPage ); formWindow()->emitUpdateProperties( formWindow()->currentWidget() ); formWindow()->mainWindow()->objectHierarchy()->tabsChanged( tabWidget );}void AddTabPageCommand::unexecute(){ tabWidget->removePage( tabPage ); tabPage->hide(); formWindow()->emitUpdateProperties( formWindow()->currentWidget() ); formWindow()->mainWindow()->objectHierarchy()->tabsChanged( tabWidget );}// ------------------------------------------------------------DeleteTabPageCommand::DeleteTabPageCommand( const QString &n, FormWindow *fw, QTabWidget *tw, QWidget *page ) : Command( n, fw ), tabWidget( tw ), tabPage( page ){ tabLabel = ( (QDesignerTabWidget*)tabWidget )->pageTitle(); index = ( (QDesignerTabWidget*)tabWidget )->currentPage();}void DeleteTabPageCommand::execute(){ tabWidget->removePage( tabPage ); tabPage->hide(); formWindow()->emitUpdateProperties( formWindow()->currentWidget() ); formWindow()->mainWindow()->objectHierarchy()->tabsChanged( tabWidget );}void DeleteTabPageCommand::unexecute(){ tabWidget->insertTab( tabPage, tabLabel, index ); tabWidget->showPage( tabPage ); formWindow()->emitUpdateProperties( formWindow()->currentWidget() ); formWindow()->mainWindow()->objectHierarchy()->tabsChanged( tabWidget );}// ------------------------------------------------------------AddWizardPageCommand::AddWizardPageCommand( const QString &n, FormWindow *fw, QWizard *w, const QString &label ) : Command( n, fw ), wizard( w ), pageLabel( label ){ page = new QDesignerWidget( formWindow(), wizard, "page" ); page->hide(); index = -1; MetaDataBase::addEntry( page );}void AddWizardPageCommand::execute(){ if ( index == -1 ) index = wizard->pageCount(); ( (QDesignerWizard*)wizard )->insertPage( page, pageLabel, index ); ( (QDesignerWizard*)wizard )->setCurrentPage( ( (QDesignerWizard*)wizard )->pageNum( page ) ); formWindow()->emitUpdateProperties( formWindow()->currentWidget() ); formWindow()->mainWindow()->objectHierarchy()->pagesChanged( wizard );}void AddWizardPageCommand::unexecute(){ wizard->removePage( page ); page->hide(); formWindow()->emitUpdateProperties( formWindow()->currentWidget() ); formWindow()->mainWindow()->objectHierarchy()->pagesChanged( wizard );}// ------------------------------------------------------------DeleteWizardPageCommand::DeleteWizardPageCommand( const QString &n, FormWindow *fw, QWizard *w, QWidget *p ) : Command( n, fw ), wizard( w ), page( p ){ pageLabel = ( (QDesignerWizard*)wizard )->pageTitle(); index = ( (QDesignerWizard*)wizard )->currentPageNum();}void DeleteWizardPageCommand::execute(){ wizard->removePage( page ); page->hide(); formWindow()->emitUpdateProperties( formWindow()->currentWidget() ); formWindow()->mainWindow()->objectHierarchy()->pagesChanged( wizard );}void DeleteWizardPageCommand::unexecute(){ ( (QDesignerWizard*)wizard )->insertPage( page, pageLabel, index ); ( (QDesignerWizard*)wizard )->setCurrentPage( ( (QDesignerWizard*)wizard )->pageNum( page ) ); formWindow()->emitUpdateProperties( formWindow()->currentWidget() ); formWindow()->mainWindow()->objectHierarchy()->pagesChanged( wizard );}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -