📄 qdesigner_actions.cpp
字号:
/******************************************************************************** Copyright (C) 1992-2006 Trolltech ASA. All rights reserved.**** This file is part of the Qt Designer of the Qt Toolkit.**** This file may be used under the terms of the GNU General Public** License version 2.0 as published by the Free Software Foundation** and appearing in the file LICENSE.GPL included in the packaging of** this file. Please review the following information to ensure GNU** General Public Licensing requirements will be met:** http://www.trolltech.com/products/qt/opensource.html**** If you are unsure which license is appropriate for your use, please** review the following information:** http://www.trolltech.com/products/qt/licensing.html or contact the** sales department at sales@trolltech.com.**** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.******************************************************************************/#include "qdesigner.h"#include "qdesigner_actions.h"#include "qdesigner_workbench.h"#include "qdesigner_formwindow.h"#include "qdesigner_settings.h"#include "newform.h"#include "versiondialog.h"#include "oublietteview.h"#include "saveformastemplate.h"#include "plugindialog.h"#include "formwindowsettings.h"// sdk#include <QtDesigner/QtDesigner>#include <qdesigner_formbuilder_p.h>#include <qtundo_p.h>#include <pluginmanager_p.h>#include <QtAssistant/QAssistantClient>#include <QtGui/QStyleFactory>#include <QtGui/QAction>#include <QtGui/QActionGroup>#include <QtGui/QCloseEvent>#include <QtGui/QFileDialog>#include <QtGui/QMenu>#include <QtGui/QMessageBox>#include <QtGui/QIcon>#include <QtCore/QLibraryInfo>#include <QtCore/QBuffer>#include <QtCore/QPluginLoader>#include <QtCore/qdebug.h>QDesignerActions::QDesignerActions(QDesignerWorkbench *workbench) : QObject(workbench), m_workbench(workbench), m_assistantClient(0), m_openDirectory(QString()){ Q_ASSERT(m_workbench != 0); m_core = m_workbench->core(); Q_ASSERT(m_core != 0); QDesignerFormWindowManagerInterface *formWindowManager = m_core->formWindowManager(); Q_ASSERT(formWindowManager != 0); QDesignerSettings settings; m_fileActions = new QActionGroup(this); m_fileActions->setExclusive(false); m_recentFilesActions = new QActionGroup(this); m_recentFilesActions->setExclusive(false); m_editActions = new QActionGroup(this); m_editActions->setExclusive(false); m_formActions = new QActionGroup(this); m_formActions->setExclusive(false); m_windowActions = new QActionGroup(this); m_windowActions->setExclusive(false); m_toolActions = new QActionGroup(this); m_toolActions->setExclusive(true); m_helpActions = new QActionGroup(this); m_helpActions->setExclusive(false);//// file actions// m_newFormAction = new QAction(tr("&New Form..."), this); m_newFormAction->setShortcut(tr("CTRL+N")); connect(m_newFormAction, SIGNAL(triggered()), this, SLOT(createForm())); m_fileActions->addAction(m_newFormAction); m_openFormAction = new QAction(tr("&Open Form..."), this); m_openFormAction->setShortcut(tr("CTRL+O")); connect(m_openFormAction, SIGNAL(triggered()), this, SLOT(openForm())); m_fileActions->addAction(m_openFormAction); QAction *act; // Need to insert this into the QAction. for (int i = 0; i < MaxRecentFiles; ++i) { act = new QAction(this); act->setVisible(false); connect(act, SIGNAL(triggered()), this, SLOT(openRecentForm())); m_recentFilesActions->addAction(act); } updateRecentFileActions(); act = new QAction(this); act->setSeparator(true); m_recentFilesActions->addAction(act); act = new QAction(tr("Clear &Menu"), this); connect(act, SIGNAL(triggered()), this, SLOT(clearRecentFiles())); m_recentFilesActions->addAction(act); QAction *sep = new QAction(this); sep->setSeparator(true); m_fileActions->addAction(sep); m_saveFormAction = new QAction(tr("&Save Form"), this); m_saveFormAction->setShortcut(tr("CTRL+S")); connect(m_saveFormAction, SIGNAL(triggered()), this, SLOT(saveForm())); m_fileActions->addAction(m_saveFormAction); m_saveFormAsAction = new QAction(tr("Save Form &As..."), this); connect(m_saveFormAsAction, SIGNAL(triggered()), this, SLOT(saveFormAs())); m_fileActions->addAction(m_saveFormAsAction); m_saveFormAsTemplateAction = new QAction(tr("Save Form As &Template..."), this); connect(m_saveFormAsTemplateAction, SIGNAL(triggered()), this, SLOT(saveFormAsTemplate())); m_fileActions->addAction(m_saveFormAsTemplateAction); sep = new QAction(this); sep->setSeparator(true); m_fileActions->addAction(sep); m_closeFormAction = new QAction(tr("&Close Form"), this); m_closeFormAction->setShortcut(tr("CTRL+W")); connect(m_closeFormAction, SIGNAL(triggered()), this, SLOT(closeForm())); m_fileActions->addAction(m_closeFormAction); sep = new QAction(this); sep->setSeparator(true); m_fileActions->addAction(sep); m_quitAction = new QAction(tr("&Quit"), this); m_quitAction->setShortcut(tr("CTRL+Q")); connect(m_quitAction, SIGNAL(triggered()), this, SLOT(shutdown())); m_fileActions->addAction(m_quitAction);//// edit actions// m_undoAction = formWindowManager->actionUndo(); m_undoAction->setShortcut(tr("CTRL+Z")); m_editActions->addAction(m_undoAction); m_redoAction = formWindowManager->actionRedo(); m_redoAction->setShortcut(tr("CTRL+SHIFT+Z")); m_editActions->addAction(m_redoAction); sep = new QAction(this); sep->setSeparator(true); m_editActions->addAction(sep); m_cutAction = formWindowManager->actionCut(); m_editActions->addAction(m_cutAction); m_copyAction = formWindowManager->actionCopy(); m_editActions->addAction(m_copyAction); m_pasteAction = formWindowManager->actionPaste(); m_editActions->addAction(m_pasteAction); m_deleteAction = formWindowManager->actionDelete(); m_editActions->addAction(m_deleteAction); m_selectAllAction = formWindowManager->actionSelectAll(); m_editActions->addAction(m_selectAllAction); sep = new QAction(this); sep->setSeparator(true); m_editActions->addAction(sep); m_sendToBackAction = formWindowManager->actionLower(); m_editActions->addAction(m_sendToBackAction); m_bringToFrontAction = formWindowManager->actionRaise(); m_editActions->addAction(m_bringToFrontAction);//// edit mode actions// m_editWidgetsAction = new QAction(tr("Edit Widgets"), this); m_editWidgetsAction->setCheckable(true); m_editWidgetsAction->setShortcut(tr("F3")); m_editWidgetsAction->setIcon(QIcon(m_core->resourceLocation() + QLatin1String("/widgettool.png"))); connect(formWindowManager, SIGNAL(activeFormWindowChanged(QDesignerFormWindowInterface*)), this, SLOT(activeFormWindowChanged(QDesignerFormWindowInterface*))); connect(m_editWidgetsAction, SIGNAL(triggered()), this, SLOT(editWidgetsSlot())); m_toolActions->addAction(m_editWidgetsAction); m_editWidgetsAction->setChecked(true); m_editWidgetsAction->setEnabled(false); QList<QObject*> builtinPlugins = QPluginLoader::staticInstances(); builtinPlugins += m_core->pluginManager()->instances(); foreach (QObject *plugin, builtinPlugins) { if (QDesignerFormEditorPluginInterface *formEditorPlugin = qobject_cast<QDesignerFormEditorPluginInterface*>(plugin)) { m_toolActions->addAction(formEditorPlugin->action()); formEditorPlugin->action()->setCheckable(true); } } m_uiMode = new QActionGroup(this); m_uiMode->setExclusive(true); m_sdiAction = m_uiMode->addAction(tr("Multiple Top-Level Windows")); m_sdiAction->setCheckable(true); m_dockedMdiAction = m_uiMode->addAction(tr("Docked Window")); m_dockedMdiAction->setCheckable(true); switch (settings.uiMode()) { default: Q_ASSERT(0); break; case QDesignerWorkbench::TopLevelMode: m_sdiAction->setChecked(true); break; case QDesignerWorkbench::DockedMode: m_dockedMdiAction->setChecked(true); break; } connect(m_uiMode, SIGNAL(triggered(QAction*)), this, SLOT(updateUIMode(QAction*)));//// form actions// m_layoutHorizontallyAction = formWindowManager->actionHorizontalLayout(); m_formActions->addAction(m_layoutHorizontallyAction); m_layoutVerticallyAction = formWindowManager->actionVerticalLayout(); m_formActions->addAction(m_layoutVerticallyAction); m_layoutHorizontallyInSplitterAction = formWindowManager->actionSplitHorizontal(); m_formActions->addAction(m_layoutHorizontallyInSplitterAction); m_layoutVerticallyInSplitterAction = formWindowManager->actionSplitVertical(); m_formActions->addAction(m_layoutVerticallyInSplitterAction); m_layoutGridAction = formWindowManager->actionGridLayout(); m_formActions->addAction(m_layoutGridAction); m_breakLayoutAction = formWindowManager->actionBreakLayout(); m_formActions->addAction(m_breakLayoutAction); m_adjustSizeAction = formWindowManager->actionAdjustSize(); m_formActions->addAction(m_adjustSizeAction); sep = new QAction(this); sep->setSeparator(true); m_formActions->addAction(sep); m_previewFormAction = new QAction(tr("&Preview"), this); m_previewFormAction->setShortcut(tr("CTRL+R")); connect(m_previewFormAction, SIGNAL(triggered()), this, SLOT(previewFormLater())); m_formActions->addAction(m_previewFormAction); m_styleActions = new QActionGroup(this); m_styleActions->setExclusive(true); connect(m_styleActions, SIGNAL(triggered(QAction*)), this, SLOT(previewForm(QAction*))); QAction *sep2 = new QAction(this); sep2->setSeparator(true); m_formActions->addAction(sep2); m_formSettings = new QAction(tr("Form &Settings..."), this); m_formSettings->setEnabled(false); connect(m_formSettings, SIGNAL(triggered()), this, SLOT(showFormSettings())); m_formActions->addAction(m_formSettings); QStringList availableStyleList = QStyleFactory::keys(); foreach (QString style, availableStyleList) { QAction *a = new QAction(this); a->setText(tr("%1 Style").arg(style)); a->setObjectName(QLatin1String("__qt_action_style_") + style); m_styleActions->addAction(a); }//// window actions// m_minimizeAction = new QAction(tr("&Minimize"), this); m_minimizeAction->setEnabled(false); m_minimizeAction->setShortcut(tr("CTRL+M")); connect(m_minimizeAction, SIGNAL(triggered()), this, SLOT(minimizeForm())); m_windowActions->addAction(m_minimizeAction); sep = new QAction(this); sep->setSeparator(true); m_windowActions->addAction(sep); m_bringToFrontAction = new QAction(tr("Bring All to Front"), this); connect(m_bringToFrontAction, SIGNAL(triggered()), this, SLOT(bringAllToFront())); m_windowActions->addAction(m_bringToFrontAction);//// Help actions// m_mainHelpAction = new QAction(tr("Qt Designer &Help"), this); connect(m_mainHelpAction, SIGNAL(triggered()), this, SLOT(showDesignerHelp())); m_mainHelpAction->setShortcut(Qt::CTRL + Qt::Key_Question); m_helpActions->addAction(m_mainHelpAction); sep = new QAction(this); sep->setSeparator(true); m_helpActions->addAction(sep); m_widgetHelp = new QAction(tr("Current Widget Help"), this); m_widgetHelp->setShortcut(Qt::Key_F1);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -