📄 mainwindow.cpp
字号:
} else if ( o->inherits( "FormWindow" ) ) { FormWindow *fw = (FormWindow*)o; if ( fw->formFile() && fw->formFile()->editor() ) fw->formFile()->editor()->checkTimeStamp(); } break; case QEvent::FocusOut: if ( !o->inherits( "FormWindow" ) && isAFormWindowChild( o ) ) return TRUE; break; default: return QMainWindow::eventFilter( o, e ); } return QMainWindow::eventFilter( o, e );}QWidget *MainWindow::isAFormWindowChild( QObject *o ) const{ if ( o->parent() && o->parent()->inherits( "QWizard" ) && !o->inherits( "QPushButton" ) ) return 0; while ( o ) { if ( o->inherits( "FormWindow" ) ) return (QWidget*)o; o = o->parent(); } return 0;}QWidget *MainWindow::isAToolBarChild( QObject *o ) const{ while ( o ) { if ( o->inherits( "QDesignerToolBar" ) ) return (QWidget*)o; if ( o->inherits( "FormWindow" ) ) return 0; o = o->parent(); } return 0;}FormWindow *MainWindow::formWindow(){ if ( qworkspace->activeWindow() ) { FormWindow *fw = 0; if ( qworkspace->activeWindow()->inherits( "FormWindow" ) ) fw = (FormWindow*)qworkspace->activeWindow(); else if ( lastActiveFormWindow && qworkspace->windowList().find( lastActiveFormWindow ) != -1) fw = lastActiveFormWindow; return fw; } return 0;}void MainWindow::emitProjectSignals(){ emit hasNonDummyProject( !currentProject->isDummy() ); emit hasActiveWindowOrProject( !!qworkspace->activeWindow() || !currentProject->isDummy() );}void MainWindow::insertFormWindow( FormWindow *fw ){ if ( fw ) QWhatsThis::add( fw, tr( "<b>The Form Window</b>" "<p>Use the various tools to add widgets or to change the layout " "and behavior of the components in the form. Select one or multiple " "widgets to move them or lay them out. If a single widget is chosen it can " "be resized using the resize handles.</p>" "<p>Changes in the <b>Property Editor</b> are visible at design time, " "and you can preview the form in different styles.</p>" "<p>You can change the grid resolution, or turn the grid off in the " "<b>Preferences</b> dialog in the <b>Edit</b> menu." "<p>You can have several forms open, and all open forms are listed " "in the <b>Form List</b>.") ); connect( fw, SIGNAL( showProperties( QObject * ) ), this, SLOT( showProperties( QObject * ) ) ); connect( fw, SIGNAL( updateProperties( QObject * ) ), this, SLOT( updateProperties( QObject * ) ) ); connect( this, SIGNAL( currentToolChanged() ), fw, SLOT( currentToolChanged() ) ); connect( fw, SIGNAL( selectionChanged() ), this, SLOT( selectionChanged() ) ); connect( fw, SIGNAL( undoRedoChanged( bool, bool, const QString &, const QString & ) ), this, SLOT( updateUndoRedo( bool, bool, const QString &, const QString & ) ) ); if ( !mblockNewForms ) { } else { fw->setProject( currentProject ); } fw->show(); fw->currentToolChanged(); if ( fw->caption().isEmpty() && qstrlen( fw->name() ) ) fw->setCaption( fw->name() ); fw->mainContainer()->setCaption( fw->caption() ); WidgetFactory::saveDefaultProperties( fw->mainContainer(), WidgetDatabase:: idFromClassName( WidgetFactory::classNameOf( fw->mainContainer() ) ) ); activeWindowChanged( fw ); emit formWindowsChanged(); for ( SourceEditor *e = sourceEditors.first(); e; e = sourceEditors.next() ) { if ( e->project() == fw->project() ) e->resetContext(); }}void MainWindow::createNewProject( const QString &lang ){ Project *pro = new Project( "", "", projectSettingsPluginManager ); pro->setLanguage( lang ); if ( !openProjectSettings( pro ) ) { delete pro; return; } if ( !pro->isValid() ) { QMessageBox::information( this, tr("New Project"), tr( "Cannot create an invalid project." ) ); delete pro; return; } QAction *a = new QAction( pro->makeRelative( pro->fileName() ), pro->makeRelative( pro->fileName() ), 0, actionGroupProjects, 0, TRUE ); projects.insert( a, pro ); addRecentlyOpened( pro->makeAbsolute( pro->fileName() ), recentlyProjects ); projectSelected( a );}bool MainWindow::unregisterClient( FormWindow *w ){ propertyEditor->closed( w ); objectHierarchy()->closed( w ); if ( w == lastActiveFormWindow ) lastActiveFormWindow = 0; QPtrList<SourceEditor> waitingForDelete; waitingForDelete.setAutoDelete( TRUE ); for ( SourceEditor *e = sourceEditors.first(); e; e = sourceEditors.next() ) { if ( e->object() == w ) waitingForDelete.append( e ); } if ( actionEditor->form() == w ) { actionEditor->setFormWindow( 0 ); actionEditor->parentWidget()->hide(); } return TRUE;}void MainWindow::activeWindowChanged( QWidget *w ){ QWidget *old = formWindow(); if ( w && w->inherits( "FormWindow" ) ) { FormWindow *fw = (FormWindow*)w; FormWindow *ofw = lastActiveFormWindow; lastActiveFormWindow = fw; lastActiveFormWindow->updateUndoInfo(); emit hasActiveForm( TRUE ); if ( formWindow() ) { formWindow()->emitShowProperties(); emit formModified( formWindow()->commandHistory()->isModified() ); if ( currentTool() != POINTER_TOOL ) formWindow()->clearSelection(); } workspace()->activeFormChanged( fw ); setAppropriate( (QDockWindow*)actionEditor->parentWidget(), lastActiveFormWindow->mainContainer()->inherits( "QMainWindow" ) ); if ( appropriate( (QDockWindow*)actionEditor->parentWidget() ) ) { if ( actionEditor->wantToBeShown() ) actionEditor->parentWidget()->show(); } else { QWidget *mc = 0; if ( ofw && (mc = ofw->mainContainer()) && mc->inherits( "QMainWindow" ) ) actionEditor->setWantToBeShown( !actionEditor->parentWidget()->isHidden() ); actionEditor->parentWidget()->hide(); } actionEditor->setFormWindow( lastActiveFormWindow ); if ( wspace && fw->project() && fw->project() != currentProject ) { for ( QMap<QAction*, Project *>::ConstIterator it = projects.begin(); it != projects.end(); ++it ) { if ( *it == fw->project() ) { projectSelected( it.key() ); break; } } } emit formWindowChanged(); } else if ( w == propertyEditor ) { propertyEditor->resetFocus(); } else if ( !lastActiveFormWindow ) { emit formWindowChanged(); emit hasActiveForm( FALSE ); actionEditUndo->setEnabled( FALSE ); actionEditRedo->setEnabled( FALSE ); } if ( !w ) { emit formWindowChanged(); emit hasActiveForm( FALSE ); propertyEditor->clear(); hierarchyView->clear(); updateUndoRedo( FALSE, FALSE, QString::null, QString::null ); } selectionChanged(); if ( w && w->inherits( "SourceEditor" ) ) { SourceEditor *se = (SourceEditor*)w; QGuardedPtr<FormWindow> fw = se->formWindow(); if ( se->formWindow() && lastActiveFormWindow != fw ) { activeWindowChanged( se->formWindow() ); } actionSearchFind->setEnabled( TRUE ); actionSearchIncremetal->setEnabled( TRUE ); actionSearchReplace->setEnabled( TRUE ); actionSearchGotoLine->setEnabled( TRUE ); incrementalSearch->setEnabled( TRUE ); actionEditUndo->setEnabled( FALSE ); actionEditRedo->setEnabled( FALSE ); actionEditCut->setEnabled( TRUE ); actionEditCopy->setEnabled( TRUE ); actionEditPaste->setEnabled( TRUE ); actionEditSelectAll->setEnabled( TRUE ); actionEditUndo->setMenuText( tr( "&Undo" ) ); actionEditUndo->setToolTip( textNoAccel( actionEditUndo->menuText()) ); actionEditRedo->setMenuText( tr( "&Redo" ) ); actionEditRedo->setToolTip( textNoAccel( actionEditRedo->menuText()) ); if ( hierarchyView->sourceEditor() != w ) hierarchyView->showClasses( se ); actionEditor->setFormWindow( 0 ); if ( wspace && se->project() && se->project() != currentProject ) { for ( QMap<QAction*, Project *>::ConstIterator it = projects.begin(); it != projects.end(); ++it ) { if ( *it == se->project() ) { projectSelected( it.key() ); break; } } } workspace()->activeEditorChanged( se ); } else { actionSearchFind->setEnabled( FALSE ); actionSearchIncremetal->setEnabled( FALSE ); actionSearchReplace->setEnabled( FALSE ); actionSearchGotoLine->setEnabled( FALSE ); incrementalSearch->setEnabled( FALSE ); } if ( currentTool() == ORDER_TOOL && w != old ) emit currentToolChanged(); emit hasActiveWindow( !!qworkspace->activeWindow() );}void MainWindow::updateUndoRedo( bool undoAvailable, bool redoAvailable, const QString &undoCmd, const QString &redoCmd ){ if ( qWorkspace()->activeWindow() && qWorkspace()->activeWindow()->inherits( "SourceEditor" ) ) return; // do not set a formWindow related command actionEditUndo->setEnabled( undoAvailable ); actionEditRedo->setEnabled( redoAvailable ); if ( !undoCmd.isEmpty() ) actionEditUndo->setMenuText( tr( "&Undo: %1" ).arg( undoCmd ) ); else actionEditUndo->setMenuText( tr( "&Undo: Not Available" ) ); if ( !redoCmd.isEmpty() ) actionEditRedo->setMenuText( tr( "&Redo: %1" ).arg( redoCmd ) ); else actionEditRedo->setMenuText( tr( "&Redo: Not Available" ) ); actionEditUndo->setToolTip( textNoAccel( actionEditUndo->menuText()) ); actionEditRedo->setToolTip( textNoAccel( actionEditRedo->menuText()) ); if ( currentTool() == ORDER_TOOL ) { actionEditUndo->setEnabled( FALSE ); actionEditRedo->setEnabled( FALSE ); }}void MainWindow::updateEditorUndoRedo(){ if ( !qWorkspace()->activeWindow() || !qWorkspace()->activeWindow()->inherits( "SourceEditor" ) ) return; SourceEditor *editor = (SourceEditor*)qWorkspace()->activeWindow(); actionEditUndo->setEnabled( editor->editIsUndoAvailable() ); actionEditRedo->setEnabled( editor->editIsRedoAvailable() );}QWorkspace *MainWindow::qWorkspace() const{ return qworkspace;}void MainWindow::popupFormWindowMenu( const QPoint & gp, FormWindow *fw ){ QValueList<uint> ids; QMap<QString, int> commands; setupRMBSpecialCommands( ids, commands, fw ); setupRMBProperties( ids, commands, fw ); qApp->processEvents(); int r = rmbFormWindow->exec( gp ); handleRMBProperties( r, commands, fw ); handleRMBSpecialCommands( r, commands, fw ); for ( QValueList<uint>::ConstIterator i = ids.begin(); i != ids.end(); ++i ) rmbFormWindow->removeItem( *i );}void MainWindow::popupWidgetMenu( const QPoint &gp, FormWindow * /*fw*/, QWidget * w){ QValueList<uint> ids; QMap<QString, int> commands; setupRMBSpecialCommands( ids, commands, w ); setupRMBProperties( ids, commands, w ); qApp->processEvents(); int r = rmbWidgets->exec( gp ); handleRMBProperties( r, commands, w ); handleRMBSpecialCommands( r, commands, w ); for ( QValueList<uint>::ConstIterator i = ids.begin(); i != ids.end(); ++i ) rmbWidgets->removeItem( *i );}void MainWindow::setupRMBProperties( QValueList<uint> &ids, QMap<QString, int> &props, QWidget *w ){ const QMetaProperty* text = w->metaObject()->property( w->metaObject()->findProperty( "text", TRUE ), TRUE ); if ( text && qstrcmp( text->type(), "QString") != 0 ) text = 0; const QMetaProperty* title = w->metaObject()->property( w->metaObject()->findProperty( "title", TRUE ), TRUE ); if ( title && qstrcmp( title->type(), "QString") != 0 ) title = 0; const QMetaProperty* pagetitle = w->metaObject()->property( w->metaObject()->findProperty( "pageTitle", TRUE ), TRUE ); if ( pagetitle && qstrcmp( pagetitle->type(), "QString") != 0 ) pagetitle = 0; const QMetaProperty* pixmap = w->metaObject()->property( w->metaObject()->findProperty( "pixmap", TRUE ), TRUE ); 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 ); } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -