📄 mainwindow.cpp
字号:
/************************************************************************ 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 "mainwindow.h"#include "defs.h"#include "formwindow.h"#include "widgetdatabase.h"#include "widgetfactory.h"#include "propertyeditor.h"#include "qmetaobject.h"#include "qaction.h"#include "metadatabase.h"#include "resource.h"#include "pixmapchooser.h"#include "config.h"#include "hierarchyview.h"#include "editslotsimpl.h"#include "newformimpl.h"#include "formlist.h"#include "help.h"#include "connectionviewerimpl.h"#include "customwidgeteditorimpl.h"#include "preferences.h"#include "styledbutton.h"#include "formsettingsimpl.h"#include "about.h"#include "import.h"#include "multilineeditorimpl.h"#include "createtemplate.h"#include <qinputdialog.h>#if defined(HAVE_KDE)#include <ktoolbar.h>#include <kmenubar.h>#else#include <qtoolbar.h>#include <qmenubar.h>#endif#include <qpixmap.h>#include <qbuttongroup.h>#include <qapplication.h>#include <qworkspace.h>#include <qfiledialog.h>#include <qapplication.h>#include <qclipboard.h>#include <qmessagebox.h>#include <qbuffer.h>#include <qdir.h>#include <qstyle.h>#include <qmotifstyle.h>#include <qcdestyle.h>#include <qplatinumstyle.h>#include <qwindowsstyle.h>#include <qsgistyle.h>#include <qmotifplusstyle.h>#include <qlabel.h>#include <qcombobox.h>#include <qstatusbar.h>#include <qfile.h>#include <qmessagebox.h>#include <qcheckbox.h>#include <qspinbox.h>#include <qradiobutton.h>#include <qtoolbutton.h>#include <qobjectlist.h>#include <qurl.h>#include <qwhatsthis.h>#include <qwizard.h>#include <qpushbutton.h>#include <qdir.h>#include <stdlib.h>static int forms = 0;static const char * whatsthis_image[] = { "16 16 3 1", " c None", "o c #000000", "a c #000080", "o aaaaa ", "oo aaa aaa ", "ooo aaa aaa", "oooo aa aa", "ooooo aa aa", "oooooo a aaa", "ooooooo aaa ", "oooooooo aaa ", "ooooooooo aaa ", "ooooo aaa ", "oo ooo ", "o ooo aaa ", " ooo aaa ", " ooo ", " ooo ", " ooo "};const char toolbarHelp[] = "<p>Toolbars contain a number of buttons to ""provide quick access to often used functions.%1""<br>Click on the toolbar handle to hide the toolbar, ""or drag and place the toolbar to a different location.</p>";MainWindow *MainWindow::self = 0;MainWindow::MainWindow( bool asClient )#if defined(HAVE_KDE) : KMainWindow( 0, "mainwindow", WType_TopLevel | WDestructiveClose ),#else : QMainWindow( 0, "mainwindow", WType_TopLevel | WDestructiveClose ),#endif grd( 10, 10 ), sGrid( TRUE ), snGrid( TRUE ), restoreConfig( TRUE ), splashScreen( TRUE ), docPath( "$QTDIR/doc/html" ), client( asClient ){ self = this; setIcon( PixmapChooser::loadPixmap( "logo" ) ); actionGroupTools = 0; prefDia = 0; windowMenu = 0; actionWindowPropertyEditor = 0; hierarchyView = 0; statusBar()->clear(); statusBar()->addWidget( new QLabel("Ready", statusBar()), 1 ); setupMDI(); setupMenuBar(); setupFileActions(); setupEditActions();#if defined(HAVE_KDE) layoutToolBar = new KToolBar( this ); ( (KToolBar*)layoutToolBar )->setFullSize( FALSE );#else layoutToolBar = new QToolBar( this );#endif addToolBar( layoutToolBar, tr( "Layout" ) ); setupToolActions(); setupLayoutActions(); setupPreviewActions(); setupWindowActions(); setupHelpActions(); setupRMBMenus(); emit hasActiveForm( FALSE ); lastPressWidget = 0; qApp->installEventFilter( this ); setupPropertyEditor(); setupHierarchyView(); setupFormList(); QSize as( qApp->desktop()->size() ); as -= QSize( 30, 30 ); resize( QSize( 1000, 800 ).boundedTo( as ) ); connect( qApp->clipboard(), SIGNAL( dataChanged() ), this, SLOT( clipboardChanged() ) ); clipboardChanged(); layoutChilds = FALSE; layoutSelected = FALSE; breakLayout = FALSE; backPix = TRUE; 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; statusBar()->setSizeGripEnabled( TRUE );}MainWindow::~MainWindow(){}void MainWindow::setupMDI(){ QVBox *vbox = new QVBox( this ); setCentralWidget( vbox ); vbox->setFrameStyle( QFrame::StyledPanel | QFrame::Sunken ); vbox->setMargin( 1 ); vbox->setLineWidth( 1 ); workspace = new QWorkspace( vbox ); workspace->setBackgroundMode( PaletteDark ); workspace->setBackgroundPixmap( PixmapChooser::loadPixmap( "background.png", PixmapChooser::NoSize ) ); connect( workspace, SIGNAL( windowActivated( QWidget * ) ), this, SLOT( activeWindowChanged( QWidget * ) ) ); lastActiveFormWindow = 0; workspace->setAcceptDrops( TRUE );}void MainWindow::setupMenuBar(){ menubar = menuBar();}static QIconSet createIconSet( const QString &name ){ QIconSet ic( PixmapChooser::loadPixmap( name, PixmapChooser::Small ) ); ic.setPixmap( PixmapChooser::loadPixmap( name, PixmapChooser::Disabled ), QIconSet::Small, QIconSet::Disabled ); return ic;}void MainWindow::setupEditActions(){ actionEditUndo = new QAction( tr("Undo"), createIconSet( "undo.xpm" ),tr("&Undo: Not Available"), CTRL + Key_Z, this, 0 ); actionEditUndo->setStatusTip( tr( "Reverses the last action" ) ); actionEditUndo->setWhatsThis( tr( "Reverses the last action" ) ); connect( actionEditUndo, SIGNAL( activated() ), this, SLOT( editUndo() ) ); actionEditUndo->setEnabled( FALSE ); actionEditRedo = new QAction( tr( "Redo" ), createIconSet("redo.xpm"), tr( "&Redo: Not Available" ), CTRL + Key_Y, this, 0 ); actionEditRedo->setStatusTip( tr( "Redoes the last undone operation") ); actionEditRedo->setWhatsThis( tr("Redoes the last undone operation") ); connect( actionEditRedo, SIGNAL( activated() ), this, SLOT( editRedo() ) ); actionEditRedo->setEnabled( FALSE ); actionEditCut = new QAction( tr( "Cut" ), createIconSet("editcut.xpm"), tr( "Cu&t" ), CTRL + Key_X, this, 0 ); actionEditCut->setStatusTip( tr( "Cuts the selected widgets and puts them on the clipboard" ) ); actionEditCut->setWhatsThis( tr( "Cuts the selected widgets and puts them on the clipboard" ) ); connect( actionEditCut, SIGNAL( activated() ), this, SLOT( editCut() ) ); actionEditCut->setEnabled( FALSE ); actionEditCopy = new QAction( tr( "Copy" ), createIconSet("editcopy.xpm"), tr( "&Copy" ), CTRL + Key_C, this, 0 ); actionEditCopy->setStatusTip( tr( "Copies the selected widgets to the clipboard" ) ); actionEditCopy->setWhatsThis( tr( "Copies the selected widgets to the clipboard" ) ); connect( actionEditCopy, SIGNAL( activated() ), this, SLOT( editCopy() ) ); actionEditCopy->setEnabled( FALSE ); actionEditPaste = new QAction( tr( "Paste" ), createIconSet("editpaste.xpm"), tr( "&Paste" ), CTRL + Key_V, this, 0 ); actionEditPaste->setStatusTip( tr( "Pastes clipboard contents" ) ); actionEditPaste->setWhatsThis( tr( "Pastes the widgets on the clipboard into the formwindow" ) ); connect( actionEditPaste, SIGNAL( activated() ), this, SLOT( editPaste() ) ); actionEditPaste->setEnabled( FALSE ); actionEditDelete = new QAction( tr( "Delete" ), QPixmap(), tr( "&Delete" ), Key_Delete, this, 0 ); actionEditDelete->setStatusTip( tr( "Deletes the selected widgets" ) ); actionEditDelete->setWhatsThis( tr( "Deletes the selected widgets" ) ); connect( actionEditDelete, SIGNAL( activated() ), this, SLOT( editDelete() ) ); actionEditDelete->setEnabled( FALSE ); actionEditSelectAll = new QAction( tr( "Select All" ), QPixmap(), tr( "Select &All" ), CTRL + Key_A, this, 0 ); actionEditSelectAll->setStatusTip( tr( "Selects all widgets" ) ); actionEditSelectAll->setWhatsThis( tr( "Selects all widgets in the current form" ) ); connect( actionEditSelectAll, SIGNAL( activated() ), this, SLOT( editSelectAll() ) ); actionEditSelectAll->setEnabled( TRUE ); actionEditRaise = new QAction( tr( "Bring to Front" ), createIconSet("editraise.xpm"), tr( "Bring to &Front" ), 0, this, 0 ); actionEditRaise->setStatusTip( tr( "Raises the selected widgets" ) ); actionEditRaise->setWhatsThis( tr( "Raises the selected widgets" ) ); connect( actionEditRaise, SIGNAL( activated() ), this, SLOT( editRaise() ) ); actionEditRaise->setEnabled( FALSE ); actionEditLower = new QAction( tr( "Send to Back" ), createIconSet("editlower.xpm"), tr( "Send to &Back" ), 0, this, 0 ); actionEditLower->setStatusTip( tr( "Lowers the selected widgets" ) ); actionEditLower->setWhatsThis( tr( "Lowers the selected widgets" ) ); connect( actionEditLower, SIGNAL( activated() ), this, SLOT( editLower() ) ); actionEditLower->setEnabled( FALSE ); actionEditAccels = new QAction( tr( "Check Accelerators" ), QPixmap(), tr( "Check Accele&rators" ), CTRL + Key_R, this, 0 ); actionEditAccels->setStatusTip( tr("Checks if the accelerators used in the form are unique") ); actionEditAccels->setWhatsThis( tr("<b>Check Accelerators</b>" "<p>Checks if the accelerators used in the form are unique. If this " "is not the case, the desiner helps you to fix that problem.</p>") ); connect( actionEditAccels, SIGNAL( activated() ), this, SLOT( editAccels() ) ); connect( this, SIGNAL( hasActiveForm(bool) ), actionEditAccels, SLOT( setEnabled(bool) ) ); actionEditSlots = new QAction( tr( "Slots" ), createIconSet("editslots.xpm"), tr( "S&lots..." ), 0, this, 0 ); actionEditSlots->setStatusTip( tr("Opens a dialog to edit slots") ); actionEditSlots->setWhatsThis( tr("<b>Edit slots</b>" "<p>Opens a dialog where slots of the current form can be added and changed. " "The slots will be virtual in the generated C++ source, and you may wish to " "reimplement them in subclasses.</p>") ); connect( actionEditSlots, SIGNAL( activated() ), this, SLOT( editSlots() ) ); connect( this, SIGNAL( hasActiveForm(bool) ), actionEditSlots, SLOT( setEnabled(bool) ) ); actionEditConnections = new QAction( tr( "Connections" ), createIconSet("connecttool.xpm"), tr( "Co&nnections..." ), 0, this, 0 ); actionEditConnections->setStatusTip( tr("Opens a dialog to edit connections") ); actionEditConnections->setWhatsThis( tr("<b>Edit connections</b>" "<p>Opens a dialog where the connections of the current form can be " "changed.</p>") ); connect( actionEditConnections, SIGNAL( activated() ), this, SLOT( editConnections() ) ); connect( this, SIGNAL( hasActiveForm(bool) ), actionEditConnections, SLOT( setEnabled(bool) ) ); actionEditFormSettings = new QAction( tr( "Form Settings" ), QPixmap(), tr( "&Form Settings..." ), 0, this, 0 ); actionEditFormSettings->setStatusTip( tr("Opens a dialog to change the settings of the form") ); actionEditFormSettings->setWhatsThis( tr("<b>Edit settings of the form</b>" "<p>Opens a dialog to change the classname and add comments to the current formwindow.</p>") ); connect( actionEditFormSettings, SIGNAL( activated() ), this, SLOT( editFormSettings() ) ); connect( this, SIGNAL( hasActiveForm(bool) ), actionEditFormSettings, SLOT( setEnabled(bool) ) ); actionEditPreferences = new QAction( tr( "Preferences" ), QPixmap(), tr( "P&references..." ), 0, this, 0 ); actionEditPreferences->setStatusTip( tr("Opens a dialog to change preferences") ); actionEditPreferences->setWhatsThis( tr("<b>Change preferences</b>" "<p>The settings will be saved on exit. They will be restored " "the next time the Designer starts if \"Restore last Workspace\" " "has been selected.</p>") ); connect( actionEditPreferences, SIGNAL( activated() ), this, SLOT( editPreferences() ) );#if defined(HAVE_KDE) KToolBar *tb = new KToolBar( this ); tb->setFullSize( FALSE );#else QToolBar *tb = new QToolBar( this );#endif QWhatsThis::add( tb, tr( "<b>The Edit toolbar</b>%1").arg(tr(toolbarHelp).arg("")) ); addToolBar( tb, tr( "Edit" ) ); actionEditUndo->addTo( tb );
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -