📄 mainwindowactions.cpp
字号:
/************************************************************************ Copyright (C) 2000-2001 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 <stdlib.h>#include <qaction.h>#include <qwhatsthis.h>#include <qpopupmenu.h>#include <qmenubar.h>#include <qlineedit.h>#include <qtooltip.h>#include <qapplication.h>#include <qsignalmapper.h>#include <qstylefactory.h>#include <qworkspace.h>#include <qmessagebox.h>#include <qstatusbar.h>#include <qlistbox.h>#include <qclipboard.h>#include <qcombobox.h>#include <qspinbox.h>#include <qinputdialog.h>#include "defs.h"#include "project.h"#include "widgetdatabase.h"#include "widgetfactory.h"#include "preferences.h"#include "formwindow.h"#include "newformimpl.h"#include "resource.h"#include "projectsettingsimpl.h"#include "workspace.h"#include "createtemplate.h"#include "hierarchyview.h"#include "editfunctionsimpl.h"#include "finddialog.h"#include "replacedialog.h"#include "gotolinedialog.h"#include "formsettingsimpl.h"#include "pixmapcollectioneditor.h"#include "styledbutton.h"#include "customwidgeteditorimpl.h"#ifndef QT_NO_SQL#include "dbconnectionsimpl.h"#include "dbconnectionimpl.h"#endif#include "widgetaction.h"#include "qcategorywidget.h"#include "startdialogimpl.h"#include "designerappiface.h"#include "connectiondialog.h"#include "configtoolboxdialog.h"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 QString 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>";static QIconSet createIconSet( const QString &name ){ QIconSet ic( QPixmap::fromMimeSource( "" + name ) ); ic.setPixmap( QPixmap::fromMimeSource( "d_" + name ), QIconSet::Small, QIconSet::Disabled ); return ic;}void MainWindow::setupEditActions(){ actionEditUndo = new QAction( tr("Undo"), createIconSet( "undo.png" ),tr("&Undo: Not Available"), CTRL + Key_Z, this, 0 ); actionEditUndo->setStatusTip( tr( "Undoes the last action" ) ); actionEditUndo->setWhatsThis( whatsThisFrom( "Edit|Undo" ) ); connect( actionEditUndo, SIGNAL( activated() ), this, SLOT( editUndo() ) ); actionEditUndo->setEnabled( FALSE ); actionEditRedo = new QAction( tr( "Redo" ), createIconSet("redo.png"), tr( "&Redo: Not Available" ), CTRL + Key_Y, this, 0 ); actionEditRedo->setStatusTip( tr( "Redoes the last undone operation") ); actionEditRedo->setWhatsThis( whatsThisFrom( "Edit|Redo" ) ); connect( actionEditRedo, SIGNAL( activated() ), this, SLOT( editRedo() ) ); actionEditRedo->setEnabled( FALSE ); actionEditCut = new QAction( tr( "Cut" ), createIconSet("editcut.png"), tr( "Cu&t" ), CTRL + Key_X, this, 0 ); actionEditCut->setStatusTip( tr( "Cuts the selected widgets and puts them on the clipboard" ) ); actionEditCut->setWhatsThis( whatsThisFrom( "Edit|Cut" ) ); connect( actionEditCut, SIGNAL( activated() ), this, SLOT( editCut() ) ); actionEditCut->setEnabled( FALSE ); actionEditCopy = new QAction( tr( "Copy" ), createIconSet("editcopy.png"), tr( "&Copy" ), CTRL + Key_C, this, 0 ); actionEditCopy->setStatusTip( tr( "Copies the selected widgets to the clipboard" ) ); actionEditCopy->setWhatsThis( whatsThisFrom( "Edit|Copy" ) ); connect( actionEditCopy, SIGNAL( activated() ), this, SLOT( editCopy() ) ); actionEditCopy->setEnabled( FALSE ); actionEditPaste = new QAction( tr( "Paste" ), createIconSet("editpaste.png"), tr( "&Paste" ), CTRL + Key_V, this, 0 ); actionEditPaste->setStatusTip( tr( "Pastes the clipboard's contents" ) ); actionEditPaste->setWhatsThis( whatsThisFrom( "Edit|Paste" ) ); 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( whatsThisFrom( "Edit|Delete" ) ); 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( whatsThisFrom( "Edit|Select All" ) ); connect( actionEditSelectAll, SIGNAL( activated() ), this, SLOT( editSelectAll() ) ); actionEditSelectAll->setEnabled( TRUE ); actionEditRaise = new QAction( tr( "Bring to Front" ), createIconSet("editraise.png"), 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.png"), 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( "Chec&k Accelerators" ), ALT + Key_R, this, 0 ); actionEditAccels->setStatusTip( tr("Checks if the accelerators used in the form are unique") ); actionEditAccels->setWhatsThis( whatsThisFrom( "Edit|Check Accelerator" ) ); connect( actionEditAccels, SIGNAL( activated() ), this, SLOT( editAccels() ) ); connect( this, SIGNAL( hasActiveForm(bool) ), actionEditAccels, SLOT( setEnabled(bool) ) ); actionEditFunctions = new QAction( tr( "Slots" ), createIconSet("editslots.png"), tr( "S&lots..." ), 0, this, 0 ); actionEditFunctions->setStatusTip( tr("Opens a dialog for editing slots") ); actionEditFunctions->setWhatsThis( whatsThisFrom( "Edit|Slots" ) ); connect( actionEditFunctions, SIGNAL( activated() ), this, SLOT( editFunctions() ) ); connect( this, SIGNAL( hasActiveForm(bool) ), actionEditFunctions, SLOT( setEnabled(bool) ) ); actionEditConnections = new QAction( tr( "Connections" ), createIconSet("connecttool.png"), tr( "Co&nnections..." ), 0, this, 0 ); actionEditConnections->setStatusTip( tr("Opens a dialog for editing connections") ); actionEditConnections->setWhatsThis( whatsThisFrom( "Edit|Connections" ) ); connect( actionEditConnections, SIGNAL( activated() ), this, SLOT( editConnections() ) ); connect( this, SIGNAL( hasActiveForm(bool) ), actionEditConnections, SLOT( setEnabled(bool) ) ); actionEditSource = new QAction( tr( "Source" ), QIconSet(), tr( "&Source..." ), CTRL + Key_E, this, 0 ); actionEditSource->setStatusTip( tr("Opens an editor to edit the form's source code") ); actionEditSource->setWhatsThis( whatsThisFrom( "Edit|Source" ) ); connect( actionEditSource, SIGNAL( activated() ), this, SLOT( editSource() ) ); connect( this, SIGNAL( hasActiveForm(bool) ), actionEditSource, 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 form's settings") ); actionEditFormSettings->setWhatsThis( whatsThisFrom( "Edit|Form Settings" ) ); connect( actionEditFormSettings, SIGNAL( activated() ), this, SLOT( editFormSettings() ) ); connect( this, SIGNAL( hasActiveForm(bool) ), actionEditFormSettings, SLOT( setEnabled(bool) ) ); actionEditPreferences = new QAction( tr( "Preferences" ), QPixmap(), tr( "Preferences..." ), 0, this, 0 ); actionEditPreferences->setStatusTip( tr("Opens a dialog to change preferences") ); actionEditPreferences->setWhatsThis( whatsThisFrom( "Edit|Preferences" ) ); connect( actionEditPreferences, SIGNAL( activated() ), this, SLOT( editPreferences() ) ); QToolBar *tb = new QToolBar( this, "Edit" ); tb->setCloseMode( QDockWindow::Undocked ); QWhatsThis::add( tb, tr( "<b>The Edit toolbar</b>%1").arg(tr(toolbarHelp).arg("")) ); addToolBar( tb, tr( "Edit" ) ); actionEditUndo->addTo( tb ); actionEditRedo->addTo( tb ); tb->addSeparator(); actionEditCut->addTo( tb ); actionEditCopy->addTo( tb ); actionEditPaste->addTo( tb );#if 0 tb->addSeparator(); actionEditLower->addTo( tb ); actionEditRaise->addTo( tb );#endif QPopupMenu *menu = new QPopupMenu( this, "Edit" ); connect( menu, SIGNAL( aboutToShow() ), this, SLOT( updateEditorUndoRedo() ) ); menubar->insertItem( tr( "&Edit" ), menu ); actionEditUndo->addTo( menu ); actionEditRedo->addTo( menu ); menu->insertSeparator(); actionEditCut->addTo( menu ); actionEditCopy->addTo( menu ); actionEditPaste->addTo( menu ); actionEditDelete->addTo( menu ); actionEditSelectAll->addTo( menu ); actionEditAccels->addTo( menu );#if 0 menu->insertSeparator(); actionEditLower->addTo( menu ); actionEditRaise->addTo( menu );#endif menu->insertSeparator(); if ( !singleProjectMode() ) { actionEditFunctions->addTo( menu ); actionEditConnections->addTo( menu ); } actionEditFormSettings->addTo( menu ); menu->insertSeparator(); actionEditPreferences->addTo( menu );}void MainWindow::setupSearchActions(){ actionSearchFind = new QAction( tr( "Find" ), createIconSet( "searchfind.png" ), tr( "&Find..." ), CTRL + Key_F, this, 0 ); connect( actionSearchFind, SIGNAL( activated() ), this, SLOT( searchFind() ) ); actionSearchFind->setEnabled( FALSE ); actionSearchFind->setWhatsThis( whatsThisFrom( "Search|Find" ) ); actionSearchIncremetal = new QAction( tr( "Find Incremental" ), QIconSet(), tr( "Find &Incremental" ), ALT + Key_I, this, 0 ); connect( actionSearchIncremetal, SIGNAL( activated() ), this, SLOT( searchIncremetalFindMenu() ) ); actionSearchIncremetal->setEnabled( FALSE ); actionSearchIncremetal->setWhatsThis( whatsThisFrom( "Search|Find Incremental" ) ); actionSearchReplace = new QAction( tr( "Replace" ), QIconSet(), tr( "&Replace..." ), CTRL + Key_R, this, 0 ); connect( actionSearchReplace, SIGNAL( activated() ), this, SLOT( searchReplace() ) ); actionSearchReplace->setEnabled( FALSE ); actionSearchReplace->setWhatsThis( whatsThisFrom( "Search|Replace" ) ); actionSearchGotoLine = new QAction( tr( "Goto Line" ), QIconSet(), tr( "&Goto Line..." ), ALT + Key_G, this, 0 ); connect( actionSearchGotoLine, SIGNAL( activated() ), this, SLOT( searchGotoLine() ) ); actionSearchGotoLine->setEnabled( FALSE ); actionSearchGotoLine->setWhatsThis( whatsThisFrom( "Search|Goto line" ) ); QToolBar *tb = new QToolBar( this, "Search" ); tb->setCloseMode( QDockWindow::Undocked ); addToolBar( tb, tr( "Search" ) ); actionSearchFind->addTo( tb ); incrementalSearch = new QLineEdit( tb ); QToolTip::add( incrementalSearch, tr( "Incremetal Search (Alt+I)" ) ); connect( incrementalSearch, SIGNAL( textChanged( const QString & ) ), this, SLOT( searchIncremetalFind() ) ); connect( incrementalSearch, SIGNAL( returnPressed() ), this, SLOT( searchIncremetalFindNext() ) ); incrementalSearch->setEnabled( FALSE ); QPopupMenu *menu = new QPopupMenu( this, "Search" ); menubar->insertItem( tr( "&Search" ), menu ); actionSearchFind->addTo( menu ); actionSearchIncremetal->addTo( menu ); actionSearchReplace->addTo( menu ); menu->insertSeparator(); actionSearchGotoLine->addTo( menu );}void MainWindow::setupLayoutActions(){ if ( !actionGroupTools ) { actionGroupTools = new QActionGroup( this ); actionGroupTools->setExclusive( TRUE ); connect( actionGroupTools, SIGNAL( selected(QAction*) ), this, SLOT( toolSelected(QAction*) ) ); } actionEditAdjustSize = new QAction( tr( "Adjust Size" ), createIconSet("adjustsize.png"), tr( "Adjust &Size" ), CTRL + Key_J, this, 0 ); actionEditAdjustSize->setStatusTip(tr("Adjusts the size of the selected widget") ); actionEditAdjustSize->setWhatsThis( whatsThisFrom( "Layout|Adjust Size" ) ); connect( actionEditAdjustSize, SIGNAL( activated() ), this, SLOT( editAdjustSize() ) ); actionEditAdjustSize->setEnabled( FALSE ); actionEditHLayout = new QAction( tr( "Lay Out Horizontally" ), createIconSet("edithlayout.png"), tr( "Lay Out &Horizontally" ), CTRL + Key_H, this, 0 ); actionEditHLayout->setStatusTip(tr("Lays out the selected widgets horizontally") ); actionEditHLayout->setWhatsThis( whatsThisFrom( "Layout|Lay Out Horizontally" ) ); connect( actionEditHLayout, SIGNAL( activated() ), this, SLOT( editLayoutHorizontal() ) ); actionEditHLayout->setEnabled( FALSE ); actionEditVLayout = new QAction( tr( "Lay Out Vertically" ), createIconSet("editvlayout.png"), tr( "Lay Out &Vertically" ), CTRL + Key_L, this, 0 ); actionEditVLayout->setStatusTip(tr("Lays out the selected widgets vertically") ); actionEditVLayout->setWhatsThis( whatsThisFrom( "Layout|Lay Out Vertically" ) ); connect( actionEditVLayout, SIGNAL( activated() ), this, SLOT( editLayoutVertical() ) ); actionEditVLayout->setEnabled( FALSE ); actionEditGridLayout = new QAction( tr( "Lay Out in a Grid" ), createIconSet("editgrid.png"), tr( "Lay Out in a &Grid" ), CTRL + Key_G, this, 0 ); actionEditGridLayout->setStatusTip(tr("Lays out the selected widgets in a grid") ); actionEditGridLayout->setWhatsThis( whatsThisFrom( "Layout|Lay Out in a Grid" ) ); connect( actionEditGridLayout, SIGNAL( activated() ), this, SLOT( editLayoutGrid() ) ); actionEditGridLayout->setEnabled( FALSE ); actionEditSplitHorizontal = new QAction( tr( "Lay Out Horizontally (in Splitter)" ), createIconSet("editvlayoutsplit.png"), tr( "Lay Out Horizontally (in S&plitter)" ), 0, this, 0 ); actionEditSplitHorizontal->setStatusTip(tr("Lays out the selected widgets horizontally in a splitter") ); actionEditSplitHorizontal->setWhatsThis( whatsThisFrom( "Layout|Lay Out Horizontally (in Splitter)" ) ); connect( actionEditSplitHorizontal, SIGNAL( activated() ), this, SLOT( editLayoutHorizontalSplit() ) ); actionEditSplitHorizontal->setEnabled( FALSE ); actionEditSplitVertical = new QAction( tr( "Lay Out Vertically (in Splitter)" ), createIconSet("edithlayoutsplit.png"), tr( "Lay Out Vertically (in Sp&litter)" ), 0, this, 0 ); actionEditSplitVertical->setStatusTip(tr("Lays out the selected widgets vertically in a splitter") ); actionEditSplitVertical->setWhatsThis( whatsThisFrom( "Layout|Lay Out Vertically (in Splitter)" ) ); connect( actionEditSplitVertical, SIGNAL( activated() ), this, SLOT( editLayoutVerticalSplit() ) ); actionEditSplitVertical->setEnabled( FALSE );
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -