mainwindow.cpp

来自「qt-x11-free-3.0.3.tar.gz minigui图形界面工具」· C++ 代码 · 共 1,927 行 · 第 1/5 页

CPP
1,927
字号
 /************************************************************************ Copyright (C) 2000 Trolltech AS.  All rights reserved.**** This file is part of Qt Designer.**** This file may be distributed and/or modified under the terms of the** GNU General Public License version 2 as published by the Free Software** Foundation and appearing in the file LICENSE.GPL included in the** packaging of this file.**** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.**** See http://www.trolltech.com/gpl/ for GPL licensing information.**** Contact info@trolltech.com if any conditions of this licensing are** not clear to you.************************************************************************/#include "designerappiface.h"#include "designerapp.h"#include "mainwindow.h"#include "defs.h"#include "globaldefs.h"#include "formwindow.h"#include "widgetdatabase.h"#include "widgetfactory.h"#include "propertyeditor.h"#include "metadatabase.h"#include "resource.h"#include "pixmapchooser.h"#include "config.h"#include "hierarchyview.h"#include "newformimpl.h"#include "workspace.h"#include "about.h"#include "multilineeditorimpl.h"#include "wizardeditorimpl.h"#include "outputwindow.h"#include <qinputdialog.h>#if defined(HAVE_KDE)#include <ktoolbar.h>#else#include <qtoolbar.h>#endif#include <qfeatures.h>#include <qmetaobject.h>#include <qaction.h>#include <qpixmap.h>#include <qworkspace.h>#include <qfiledialog.h>#include <qclipboard.h>#include <qmessagebox.h>#include <qbuffer.h>#include <qdir.h>#include <qstyle.h>#include <qlabel.h>#include <qstatusbar.h>#include <qfile.h>#include <qcheckbox.h>#include <qwhatsthis.h>#include <qwizard.h>#include <qdir.h>#include <qtimer.h>#include <qlistbox.h>#include <stdlib.h>#include <qdockwindow.h>#include <qregexp.h>#include <qstylefactory.h>#include "actioneditorimpl.h"#include "actiondnd.h"#include "project.h"#include "projectsettingsimpl.h"#include "qwidgetfactory.h"#include <qvbox.h>#include <qprocess.h>#include <qsettings.h>#include "pixmapcollection.h"#include "sourcefile.h"#include "qcompletionedit.h"#include <qaccel.h>#include <qtooltip.h>#include <stdlib.h>static bool mblockNewForms = FALSE;extern QMap<QWidget*, QString> *qwf_functions;extern QMap<QWidget*, QString> *qwf_forms;extern QString *qwf_language;extern bool qwf_execute_code;extern bool qwf_stays_on_top;extern void set_splash_status( const QString &txt );/*### static bool tbSettingsRead = FALSE; */MainWindow *MainWindow::self = 0;QString assistantPath(){#ifdef Q_OS_MACX    return QDir::cleanDirPath(QString(getenv("QTDIR")) + QDir::separator() +			      "bin" + QDir::separator() +			      "assistant.app/Contents/MacOS/assistant");#else    return "assistant";#endif}static QString textNoAccel( const QString& text){    QString t = text;    int i;    while ( (i = t.find('&') )>= 0 ) {	t.remove(i,1);    }    return t;}MainWindow::MainWindow( bool asClient )#if defined(HAVE_KDE)    : KMainWindow( 0, "mainwindow", WType_TopLevel | WDestructiveClose | WGroupLeader ),#else    : QMainWindow( 0, "mainwindow", WType_TopLevel | WDestructiveClose | WGroupLeader ),#endif      grd( 10, 10 ), sGrid( TRUE ), snGrid( TRUE ), restoreConfig( TRUE ), splashScreen( TRUE ),      docPath( "$QTDIR/doc/html" ), fileFilter( tr( "Qt User-Interface Files (*.ui)" ) ), client( asClient ),      previewing( FALSE ), databaseAutoEdit( FALSE ){    init_colors();    desInterface = new DesignerInterfaceImpl( this );    desInterface->addRef();    inDebugMode = FALSE;    updateSlotsTimer = new QTimer( this );    connect( updateSlotsTimer, SIGNAL( timeout() ),	     this, SLOT( doSlotsChanged() ) );    set_splash_status( "Loading Plugins..." );    setupPluginManagers();    qApp->setMainWidget( this );    QWidgetFactory::addWidgetFactory( new CustomWidgetFactory );    self = this;    setIcon( PixmapChooser::loadPixmap( "logo" ) );    actionGroupTools = 0;    prefDia = 0;    windowMenu = 0;    hierarchyView = 0;    actionEditor = 0;    currentProject = 0;    wspace = 0;    oWindow = 0;    statusBar()->clear();#if defined(QT_NON_COMMERCIAL)    statusBar()->addWidget( new QLabel(tr("Ready - This is the non-commercial version of Qt - "	"For commercial evaluations, use the help menu to register with Trolltech."), statusBar()), 1 );#else    statusBar()->addWidget( new QLabel("Ready", statusBar()), 1 );#endif    set_splash_status( "Setting up GUI..." );    setupMDI();    setupMenuBar();    setupFileActions();    setupEditActions();    setupProjectActions();    setupSearchActions();#if defined(HAVE_KDE)    layoutToolBar = new KToolBar( this, "Layout" );    ( (KToolBar*)layoutToolBar )->setFullSize( FALSE );#else    layoutToolBar = new QToolBar( this, "Layout" );    layoutToolBar->setCloseMode( QDockWindow::Undocked );#endif    addToolBar( layoutToolBar, tr( "Layout" ) );    setupToolActions();    setupLayoutActions();    setupPreviewActions();    setupOutputWindow();    setupActionManager();    setupWindowActions();    setupWorkspace();    setupHierarchyView();    setupPropertyEditor();    setupActionEditor();    setupHelpActions();    setupRMBMenus();    connect( this, SIGNAL( projectChanged() ), this, SLOT( emitProjectSignals() ) );    connect( this, SIGNAL( hasActiveWindow(bool) ), this, SLOT( emitProjectSignals() ) );    emit hasActiveForm( FALSE );    emit hasActiveWindow( FALSE );    lastPressWidget = 0;    qApp->installEventFilter( this );    QSize as( qApp->desktop()->size() );    as -= QSize( 30, 30 );    resize( QSize( 1200, 1000 ).boundedTo( as ) );    connect( qApp->clipboard(), SIGNAL( dataChanged() ),	     this, SLOT( clipboardChanged() ) );    clipboardChanged();    layoutChilds = FALSE;    layoutSelected = FALSE;    breakLayout = FALSE;    backPix = TRUE;    set_splash_status( "Loading User Settings..." );    readConfig();    // hack to make WidgetFactory happy (so it knows QWidget and QDialog for resetting properties)    QWidget *w = WidgetFactory::create( WidgetDatabase::idFromClassName( "QWidget" ), this, 0, FALSE );    delete w;    w = WidgetFactory::create( WidgetDatabase::idFromClassName( "QDialog" ), this, 0, FALSE );    delete w;    w = WidgetFactory::create( WidgetDatabase::idFromClassName( "QLabel" ), this, 0, FALSE );    delete w;    w = WidgetFactory::create( WidgetDatabase::idFromClassName( "QTabWidget" ), this, 0, FALSE );    delete w;    w = WidgetFactory::create( WidgetDatabase::idFromClassName( "QFrame" ), this, 0, FALSE );    delete w;    setAppropriate( (QDockWindow*)actionEditor->parentWidget(), FALSE );    actionEditor->parentWidget()->hide();    statusBar()->setSizeGripEnabled( TRUE );    set_splash_status( "Initialization Done." );}MainWindow::~MainWindow(){    QValueList<Tab>::Iterator tit;    for ( tit = preferenceTabs.begin(); tit != preferenceTabs.end(); ++tit ) {	Tab t = *tit;	delete t.w;    }    for ( tit = projectTabs.begin(); tit != projectTabs.end(); ++tit ) {	Tab t = *tit;	delete t.w;    }    QMap< QAction*, Project* >::Iterator it = projects.begin();    while ( it != projects.end() ) {	Project *p = *it;	++it;	delete p;    }    projects.clear();    delete oWindow;    oWindow = 0;    desInterface->release();    desInterface = 0;    delete actionPluginManager;    delete preferencePluginManager;    delete projectSettingsPluginManager;    delete interpreterPluginManager;    delete programPluginManager;    delete templateWizardPluginManager;    delete editorPluginManager;    delete sourceTemplatePluginManager;    MetaDataBase::clearDataBase();}void MainWindow::setupMDI(){    QVBox *vbox = new QVBox( this );    setCentralWidget( vbox );    vbox->setFrameStyle( QFrame::StyledPanel | QFrame::Sunken );    vbox->setMargin( 1 );    vbox->setLineWidth( 1 );    qworkspace = new QWorkspace( vbox );    qworkspace->setBackgroundMode( PaletteDark );    qworkspace->setBackgroundPixmap( PixmapChooser::loadPixmap( "background.png", PixmapChooser::NoSize ) );    qworkspace->setScrollBarsEnabled( TRUE );    connect( qworkspace, SIGNAL( windowActivated( QWidget * ) ),	     this, SLOT( activeWindowChanged( QWidget * ) ) );    lastActiveFormWindow = 0;    qworkspace->setAcceptDrops( TRUE );}void MainWindow::setupMenuBar(){    menubar = menuBar();}void MainWindow::setupPropertyEditor(){    QDockWindow *dw = new QDockWindow;    dw->setResizeEnabled( TRUE );    dw->setCloseMode( QDockWindow::Always );    propertyEditor = new PropertyEditor( dw );    addToolBar( dw, Qt::DockLeft );    dw->setWidget( propertyEditor );    dw->setFixedExtentWidth( 300 );    dw->setCaption( tr( "Property Editor/Signal Handlers" ) );    QWhatsThis::add( propertyEditor,		     tr("<b>The Property Editor</b>"			"<p>You can change the appearance and behavior of the selected widget in the "			"property editor.</p>"			"<p>You can set properties for components and forms at design time and see the "			"immediately see the effects of the changes. "			"Each property has its own editor which (depending on the property) can be used "			"to enter "			"new values, open a special dialog, or to select values from a predefined list. "			"Click <b>F1</b> to get detailed help for the selected property.</p>"			"<p>You can resize the columns of the editor by dragging the separators in the "			"list's header.</p>"			"<p><b>Signal Handlers</b></p>"			"<p>In the Signal Handlers tab you can define connections between "			"the signals emitted by widgets and the slots in the form. "			"(These connections can also be made using the connection tool.)" ) );    dw->show();}void MainWindow::setupOutputWindow(){    QDockWindow *dw = new QDockWindow;    dw->setResizeEnabled( TRUE );    dw->setCloseMode( QDockWindow::Always );    addToolBar( dw, Qt::DockBottom );    oWindow = new OutputWindow( dw );    dw->setWidget( oWindow );    dw->setFixedExtentHeight( 200 );    dw->setCaption( tr( "Output Window" ) );    dw->hide();}void MainWindow::setupHierarchyView(){    if ( hierarchyView )	return;    QDockWindow *dw = new QDockWindow;    dw->setResizeEnabled( TRUE );    dw->setCloseMode( QDockWindow::Always );    hierarchyView = new HierarchyView( dw );    addToolBar( dw, Qt::DockLeft );    dw->setWidget( hierarchyView );    dw->setCaption( tr( "Object Explorer" ) );    dw->setFixedExtentWidth( 300 );    QWhatsThis::add( hierarchyView,		     tr("<b>The Object Explorer</b>"			"<p>The Object Explorer provides an overview of the relationships "			"between the widgets in a form. You can use the clipboard functions using "			"a context menu for each item in the view. It is also useful for selecting widgets "			"in forms that have complex layouts.</p>"			"<p>The columns can be resized by dragging the separator in the list's header.</p>"			"<p>The second tab shows all the form's slots, class variables, includes, etc.</p>") );    dw->show();}void MainWindow::setupWorkspace(){    QDockWindow *dw = new QDockWindow;    dw->setResizeEnabled( TRUE );    dw->setCloseMode( QDockWindow::Always );    QVBox *vbox = new QVBox( dw );    QCompletionEdit *edit = new QCompletionEdit( vbox );    QToolTip::add( edit, tr( "Start typing the buffer you want to switch to here (ALT+B)" ) );    QAccel *a = new QAccel( this );    a->connectItem( a->insertItem( ALT + Key_B ), edit, SLOT( setFocus() ) );    wspace = new Workspace( vbox, this );    wspace->setBufferEdit( edit );    wspace->setCurrentProject( currentProject );    addToolBar( dw, Qt::DockLeft );    dw->setWidget( vbox );    dw->setCaption( tr( "File Overview" ) );    QWhatsThis::add( wspace, tr("<b>The File Overview Window</b>"				"<p>The File Overview Window displays all the files in all "

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?