📄 mainwindow.cpp
字号:
#ifdef QT_CONTAINER_CUSTOM_WIDGETSstatic QWidgetContainerInterfacePrivate *containerWidgetInterface( QWidget *w ){ WidgetInterface *iface = 0; widgetManager()->queryInterface( WidgetFactory::classNameOf( w ), &iface ); if ( !iface ) return 0; QWidgetContainerInterfacePrivate *iface2 = 0; iface->queryInterface( IID_QWidgetContainer, (QUnknownInterface**)&iface2 ); if ( !iface2 ) return 0; iface->release(); return iface2;}#endifvoid MainWindow::setupRMBSpecialCommands( QValueList<uint> &ids, QMap<QString, int> &commands, QWidget *w ){ int id; if ( w->inherits( "QTabWidget" ) ) { if ( ids.isEmpty() ) ids << rmbWidgets->insertSeparator( 0 ); if ( ( (QDesignerTabWidget*)w )->count() > 1) { ids << ( id = rmbWidgets->insertItem( tr("Delete Page"), -1, 0 ) ); commands.insert( "remove", id ); } ids << ( id = rmbWidgets->insertItem( tr("Add Page"), -1, 0 ) ); commands.insert( "add", id ); } else if ( w->inherits( "QWidgetStack" ) ) { if ( ids.isEmpty() ) ids << rmbWidgets->insertSeparator( 0 ); if ( ( (QDesignerWidgetStack*)w )->count() > 1) { ids << ( id = rmbWidgets->insertItem( tr("Previous Page"), -1, 0 ) ); commands.insert( "prevpage", id ); ids << ( id = rmbWidgets->insertItem( tr("Next Page"), -1, 0 ) ); ids << rmbWidgets->insertSeparator( 0 ); commands.insert( "nextpage", id ); ids << ( id = rmbWidgets->insertItem( tr("Delete Page"), -1, 0 ) ); commands.insert( "remove", id ); } ids << ( id = rmbWidgets->insertItem( tr("Add Page"), -1, 0 ) ); commands.insert( "add", id );#ifdef QT_CONTAINER_CUSTOM_WIDGETS } else if ( WidgetDatabase:: isCustomPluginWidget( WidgetDatabase:: idFromClassName( WidgetFactory::classNameOf( w ) ) ) ) { QWidgetContainerInterfacePrivate *iface = containerWidgetInterface( w ); if ( iface && iface->supportsPages( WidgetFactory::classNameOf( w ) ) ) { if ( ids.isEmpty() ) ids << rmbWidgets->insertSeparator( 0 ); if ( iface->count( WidgetFactory::classNameOf( w ), w ) > 1 ) { ids << ( id = rmbWidgets->insertItem( tr( "Delete Page" ), -1, 0 ) ); commands.insert( "remove", id ); } ids << ( id = rmbWidgets->insertItem( tr("Add Page"), -1, 0 ) ); commands.insert( "add", id ); if ( iface->currentIndex( WidgetFactory::classNameOf( w ), w ) != -1 ) { ids << ( id = rmbWidgets->insertItem( tr("Rename Current Page..."), -1, 0 ) ); commands.insert( "rename", id ); } } if ( iface ) iface->release();#endif } if ( WidgetFactory::hasSpecialEditor( WidgetDatabase:: idFromClassName( WidgetFactory::classNameOf( w ) ) ) ) { if ( ids.isEmpty() ) ids << rmbWidgets->insertSeparator( 0 ); ids << ( id = rmbWidgets->insertItem( tr("Edit..."), -1, 0 ) ); commands.insert( "edit", id ); }}void MainWindow::setupRMBSpecialCommands( QValueList<uint> &ids, QMap<QString, int> &commands, FormWindow *fw ){ int id; if ( fw->mainContainer()->inherits( "QWizard" ) ) { if ( ids.isEmpty() ) ids << rmbFormWindow->insertSeparator( 0 ); if ( ( (QWizard*)fw->mainContainer() )->pageCount() > 1) { ids << ( id = rmbFormWindow->insertItem( tr("Delete Page"), -1, 0 ) ); commands.insert( "remove", id ); } ids << ( id = rmbFormWindow->insertItem( tr("Add Page"), -1, 0 ) ); commands.insert( "add", id ); ids << ( id = rmbFormWindow->insertItem( tr("Edit Page Title..."), -1, 0 ) ); commands.insert( "rename", id ); ids << ( id = rmbFormWindow->insertItem( tr("Edit Pages..."), -1, 0 ) ); commands.insert( "edit", id ); } else if ( fw->mainContainer()->inherits( "QMainWindow" ) ) { if ( ids.isEmpty() ) ids << rmbFormWindow->insertSeparator( 0 ); ids << ( id = rmbFormWindow->insertItem( tr( "Add Menu Item" ), -1, 0 ) ); commands.insert( "add_menu_item", id ); ids << ( id = rmbFormWindow->insertItem( tr( "Add Toolbar" ), -1, 0 ) ); commands.insert( "add_toolbar", id ); }}void MainWindow::handleRMBProperties( int id, QMap<QString, int> &props, QWidget *w ){ if ( id == props[ "text" ] ) { bool ok = FALSE; QString text; if ( w->inherits( "QTextView" ) || w->inherits( "QLabel" ) || w->inherits( "QButton" ) ) { text = MultiLineEditor::getText( this, w->property("text").toString(), !w->inherits( "QButton" ) ); ok = !text.isNull(); } else { text = QInputDialog::getText( tr("Text"), tr( "New text" ), QLineEdit::Normal, w->property("text").toString(), &ok, this ); } if ( ok ) { QString pn( tr( "Set the 'text' of '%2'" ).arg( w->name() ) ); SetPropertyCommand *cmd = new SetPropertyCommand( pn, formWindow(), w, propertyEditor, "text", w->property( "text" ), text, QString::null, QString::null ); cmd->execute(); formWindow()->commandHistory()->addCommand( cmd ); MetaDataBase::setPropertyChanged( w, "text", TRUE ); } } else if ( id == props[ "title" ] ) { bool ok = FALSE; QString title = QInputDialog::getText( tr("Title"), tr( "New title" ), QLineEdit::Normal, w->property("title").toString(), &ok, this ); if ( ok ) { QString pn( tr( "Set the 'title' of '%2'" ).arg( w->name() ) ); SetPropertyCommand *cmd = new SetPropertyCommand( pn, formWindow(), w, propertyEditor, "title", w->property( "title" ), title, QString::null, QString::null ); cmd->execute(); formWindow()->commandHistory()->addCommand( cmd ); MetaDataBase::setPropertyChanged( w, "title", TRUE ); } } else if ( id == props[ "pagetitle" ] ) { bool ok = FALSE; QString text = QInputDialog::getText( tr("Page Title"), tr( "New page title" ), QLineEdit::Normal, w->property("pageTitle").toString(), &ok, this ); if ( ok ) { QString pn( tr( "Set the 'pageTitle' of '%2'" ).arg( w->name() ) ); SetPropertyCommand *cmd = new SetPropertyCommand( pn, formWindow(), w, propertyEditor, "pageTitle", w->property( "pageTitle" ), text, QString::null, QString::null ); cmd->execute(); formWindow()->commandHistory()->addCommand( cmd ); MetaDataBase::setPropertyChanged( w, "pageTitle", TRUE ); } } else if ( id == props[ "pixmap" ] ) { QPixmap oldPix = w->property( "pixmap" ).toPixmap(); QPixmap pix = qChoosePixmap( this, formWindow(), oldPix ); if ( !pix.isNull() ) { QString pn( tr( "Set the 'pixmap' of '%2'" ).arg( w->name() ) ); SetPropertyCommand *cmd = new SetPropertyCommand( pn, formWindow(), w, propertyEditor, "pixmap", w->property( "pixmap" ), pix, QString::null, QString::null ); cmd->execute(); formWindow()->commandHistory()->addCommand( cmd ); MetaDataBase::setPropertyChanged( w, "pixmap", TRUE ); } }}void MainWindow::handleRMBSpecialCommands( int id, QMap<QString, int> &commands, QWidget *w ){ if ( w->inherits( "QTabWidget" ) ) { QTabWidget *tw = (QTabWidget*)w; if ( id == commands[ "add" ] ) { AddTabPageCommand *cmd = new AddTabPageCommand( tr( "Add Page to %1" ).arg( tw->name() ), formWindow(), tw, "Tab" ); formWindow()->commandHistory()->addCommand( cmd ); cmd->execute(); } else if ( id == commands[ "remove" ] ) { if ( tw->currentPage() ) { QDesignerTabWidget *dtw = (QDesignerTabWidget*)tw; DeleteTabPageCommand *cmd = new DeleteTabPageCommand( tr( "Delete Page %1 of %2" ). arg( dtw->pageTitle() ).arg( tw->name() ), formWindow(), tw, tw->currentPage() ); formWindow()->commandHistory()->addCommand( cmd ); cmd->execute(); } } } else if ( w->inherits( "QWidgetStack" ) ) { QDesignerWidgetStack *ws = (QDesignerWidgetStack*)w; if ( id == commands[ "add" ] ) { AddWidgetStackPageCommand *cmd = new AddWidgetStackPageCommand( tr( "Add Page to %1" ).arg( ws->name() ), formWindow(), ws ); formWindow()->commandHistory()->addCommand( cmd ); cmd->execute(); } else if ( id == commands[ "remove" ] ) { if ( ws->visibleWidget() ) { DeleteWidgetStackPageCommand *cmd = new DeleteWidgetStackPageCommand( tr( "Delete Page %1 of %2" ). arg( ws->currentPage() ).arg( ws->name() ), formWindow(), ws, ws->visibleWidget() ); formWindow()->commandHistory()->addCommand( cmd ); cmd->execute(); } } else if ( id == commands[ "nextpage" ] ) { int currentPage = w->property( "currentPage" ).toInt(); QString pn( tr( "Raise next page of '%2'" ).arg( w->name() ) ); SetPropertyCommand *cmd = new SetPropertyCommand( pn, formWindow(), w, propertyEditor, "currentPage", currentPage, currentPage + 1, QString::null, QString::null ); cmd->execute(); formWindow()->commandHistory()->addCommand( cmd ); MetaDataBase::setPropertyChanged( w, "currentPage", TRUE ); } else if ( id == commands[ "prevpage" ] ) { int currentPage = w->property( "currentPage" ).toInt(); QString pn( tr( "Raise previous page of '%2'" ).arg( w->name() ) ); SetPropertyCommand *cmd = new SetPropertyCommand( pn, formWindow(), w, propertyEditor, "currentPage", currentPage, currentPage -1, QString::null, QString::null ); cmd->execute(); formWindow()->commandHistory()->addCommand( cmd ); MetaDataBase::setPropertyChanged( w, "currentPage", TRUE ); }#ifdef QT_CONTAINER_CUSTOM_WIDGETS } else if ( WidgetDatabase:: isCustomPluginWidget( WidgetDatabase:: idFromClassName( WidgetFactory::classNameOf( w ) ) ) ) { if ( id == commands[ "add" ] ) { AddContainerPageCommand *cmd = new AddContainerPageCommand( tr( "Add Page to %1" ).arg( w->name() ), formWindow(), w, "Page" ); formWindow()->commandHistory()->addCommand( cmd ); cmd->execute(); } else if ( id == commands[ "remove" ] ) { QWidgetContainerInterfacePrivate *iface = containerWidgetInterface( w ); if ( iface ) { QString wClassName = WidgetFactory::classNameOf( w ); int index = iface->currentIndex( wClassName, w ); DeleteContainerPageCommand *cmd = new DeleteContainerPageCommand( tr( "Delete Page %1 of %2" ). arg( iface->pageLabel( wClassName, w, index ) ). arg( w->name() ), formWindow(), w, index ); formWindow()->commandHistory()->addCommand( cmd ); cmd->execute(); iface->release(); } } else if ( id == commands[ "rename" ] ) { QWidgetContainerInterfacePrivate *iface = containerWidgetInterface( w ); if ( iface ) { bool ok = FALSE; QString wClassName = WidgetFactory::classNameOf( w ); int index = iface->currentIndex( wClassName, w ); QString text = QInputDialog::getText( tr("Page Title"), tr( "New page title" ), QLineEdit::Normal, iface->pageLabel( wClassName, w, index ), &ok, this ); if ( ok ) { RenameContainerPageCommand *cmd = new RenameContainerPageCommand( tr( "Rename Page %1 to %2" ). arg( iface-> pageLabel( wClassName, w, index ) ). arg( text ), formWindow(), w, index, text ); formWindow()->commandHistory()->addCommand( cmd ); cmd->execute(); } iface->release(); } }#endif } if ( WidgetFactory::hasSpecialEditor( WidgetDatabase:: idFromClassName( WidgetFactory::classNameOf( w ) ) ) ) { if ( id == commands[ "edit" ] ) WidgetFactory::editWidget( WidgetDatabase:: idFromClassName( WidgetFactory::classNameOf( w ) ), this, w, formWindow() ); }}void MainWindow::handleRMBSpecialCommands( int id, QMap<QString, int> &commands, FormWindow *fw ){ if ( fw->mainContainer()->inherits( "QWizard" ) ) { QWizard *wiz = (QWizard*)fw->mainContainer(); if ( id == commands[ "add" ] ) { AddWizardPageCommand *cmd = new AddWizardPageCommand( tr( "Add Page to %1" ).arg( wiz->name() ), formWindow(), wiz, "Page" ); formWindow()->commandHistory()->addCommand( cmd ); cmd->execute(); } else if ( id == commands[ "remove" ] ) { if ( wiz->currentPage() ) { QDesignerWizard *dw = (QDesignerWizard*)wiz; DeleteWizardPageCommand *cmd = new DeleteWizardPageCommand( tr( "Delete Page %1 of %2" ). arg( dw->pageTitle() ).arg( wiz->name() ), formWindow(), wiz, wiz->indexOf( wiz->currentPage() ) ); formWindow()->commandHistory()->addCommand( cmd ); cmd->execute(); } } else if ( id == commands[ "edit" ] ) { WizardEditor *e = new WizardEditor( this, wiz, fw ); e->exec(); delete e; } else if ( id == commands[ "rename" ] ) { bool ok = FALSE; QDesignerWizard *dw = (QDesignerWizard*)wiz; QString text = QInputDialog::getText( tr("Page Title"), tr( "New page title" ), QLineEdit::Normal, dw->pageTitle(), &ok, this ); if ( ok ) { QString pn( tr( "Rename page %1 of %2" ).arg( dw->pageTitle() ).arg( wiz->name() ) ); RenameWizardPageCommand *cmd = new RenameWizardPageCommand( pn, formWindow() , wiz, wiz->indexOf( wiz->currentPage() ), text ); formWindow()->commandHistory()->addCommand( cmd ); cmd->execute(); } } } else if ( fw->mainContainer()->inherits( "QMainWindow" ) ) { QMainWindow *mw = (QMainWindow*)fw->mainContainer(); if ( id == commands[ "add_toolbar" ] ) { AddToolBarCommand *cmd = new AddToolBarCommand( tr( "Add Toolbar to '%1'" ).arg( formWindow()->name() ), formWindow(), mw ); formWindow()->commandHistory()->addCommand( cmd ); cmd->execute(); } else if ( id == commands[ "add_menu_item" ] ) { AddMenuCommand *cmd = new AddMenuCommand( tr( "Add Menu to '%1'" ).arg( formWindow()->name() ), formWindow(), mw ); formWindow()->commandHistory()->addCommand( cmd ); cmd->execute(); } }}void MainWindow::clipboardChanged(){ QString text( qApp->clipboard()->text() ); QString start( "<!DOCTYPE UI-SELECTION>" ); actionEditPaste->setEnabled( text.left( start.length() ) == start );}void MainWindow::selectionChanged(){ layoutChilds = FALSE; layoutSelected = FALSE; breakLayout = FALSE; if ( !formWindow() ) { actionEditCut->setEnabled( FALSE ); actionEditCopy->setEnabled( FALSE ); actionEditDelete->setEnabled( FALSE ); actionEditAdjustSize->setEnabled( FALSE ); actionEditHLayout->setEnabled( FALSE ); actionEditVLayout->setEnabled( FALSE ); actionEditSplitHorizontal->setEnabled( FALSE ); actionEditSplitVertical->setEnabled( FALSE ); actionEditGr
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -