📄 mainwindow.cpp
字号:
if ( pixmap && qstrcmp( pixmap->type(), "QPixmap") != 0 ) pixmap = 0; if ( text && text->designable(w) || title && title->designable(w) || pagetitle && pagetitle->designable(w) || pixmap && pixmap->designable(w) ) { int id = 0; if ( ids.isEmpty() ) ids << rmbWidgets->insertSeparator(0); if ( pixmap && pixmap->designable(w) ) { ids << ( id = rmbWidgets->insertItem( tr("Choose Pixmap..."), -1, 0) ); props.insert( "pixmap", id ); } if ( text && text->designable(w) && !w->inherits( "QTextEdit" ) ) { ids << ( id = rmbWidgets->insertItem( tr("Edit Text..."), -1, 0) ); props.insert( "text", id ); } if ( title && title->designable(w) ) { ids << ( id = rmbWidgets->insertItem( tr("Edit Title..."), -1, 0) ); props.insert( "title", id ); } if ( pagetitle && pagetitle->designable(w) ) { ids << ( id = rmbWidgets->insertItem( tr("Edit Page Title..."), -1, 0) ); props.insert( "pagetitle", id ); } }}#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 ); } else if ( w->inherits( "QToolBox" ) ) { if ( ids.isEmpty() ) ids << rmbWidgets->insertSeparator( 0 ); if ( ( (QToolBox*)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 );#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; bool oldDoWrap = FALSE; if ( w->inherits( "QLabel" ) ) { int align = w->property( "alignment" ).toInt(); if ( align & WordBreak ) oldDoWrap = TRUE; } bool doWrap = oldDoWrap; QString text; if ( w->inherits( "QTextView" ) || w->inherits( "QLabel" ) || w->inherits( "QButton" ) ) { text = MultiLineEditor::getText( this, w->property( "text" ).toString(), !w->inherits( "QButton" ), &doWrap ); ok = !text.isNull(); } else { text = QInputDialog::getText( tr("Text"), tr( "New text" ), QLineEdit::Normal, w->property("text").toString(), &ok, this ); } if ( ok ) { if ( oldDoWrap != doWrap ) { QString pn( tr( "Set 'wordwrap' of '%1'" ).arg( w->name() ) ); SetPropertyCommand *cmd = new SetPropertyCommand( pn, formWindow(), w, propertyEditor, "wordwrap", QVariant( oldDoWrap, 0 ), QVariant( doWrap, 0 ), QString::null, QString::null ); cmd->execute(); formWindow()->commandHistory()->addCommand( cmd ); MetaDataBase::setPropertyChanged( w, "wordwrap", TRUE ); } QString pn( tr( "Set the 'text' of '%1'" ).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( "QToolBox" ) ) { QToolBox *tb = (QToolBox*)w; if ( id == commands[ "add" ] ) { AddToolBoxPageCommand *cmd = new AddToolBoxPageCommand( tr( "Add Page to %1" ).arg( tb->name() ), formWindow(), tb, "Page" ); formWindow()->commandHistory()->addCommand( cmd ); cmd->execute(); } else if ( id == commands[ "remove" ] ) { if ( tb->currentItem() ) { DeleteToolBoxPageCommand *cmd = new DeleteToolBoxPageCommand( tr( "Delete Page %1 of %2" ). arg( tb->itemLabel( tb->currentIndex() ) ). arg( tb->name() ), formWindow(), tb, tb->currentItem() ); 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, "WizardPage" ); formWindow()->commandHisto
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -