qdesigner_actions.cpp

来自「奇趣公司比较新的qt/emd版本」· C++ 代码 · 共 1,325 行 · 第 1/3 页

CPP
1,325
字号
/******************************************************************************** Copyright (C) 1992-2007 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://trolltech.com/products/qt/licenses/licensing/opensource/**** If you are unsure which license is appropriate for your use, please** review the following information:** http://trolltech.com/products/qt/licenses/licensing/licensingoverview** or contact the sales department at sales@trolltech.com.**** In addition, as a special exception, Trolltech gives you certain** additional rights. These rights are described in the Trolltech GPL** Exception version 1.0, which can be found at** http://www.trolltech.com/products/qt/gplexception/ and in the file** GPL_EXCEPTION.txt in this package.**** In addition, as a special exception, Trolltech, as the sole copyright** holder for Qt Designer, grants users of the Qt/Eclipse Integration** plug-in the right for the Qt/Eclipse Integration to link to** functionality provided by Qt Designer and its related libraries.**** Trolltech reserves all rights not expressly granted herein.**** 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_actions.h"#include "designer_enums.h"#include "qdesigner.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"#include "qdesigner_toolwindow.h"#include "preferencesdialog.h"#include "preferences.h"#include <pluginmanager_p.h>#include <qdesigner_formbuilder_p.h>#include <qdesigner_utils_p.h>#include <iconloader_p.h>#include <qsimpleresource_p.h>// sdk#include <QtDesigner/QDesignerFormEditorInterface>#include <QtDesigner/QDesignerFormWindowInterface>#include <QtDesigner/QDesignerLanguageExtension>#include <QtDesigner/QDesignerWidgetDataBaseInterface>#include <QtDesigner/QDesignerMetaDataBaseInterface>#include <QtDesigner/QDesignerFormWindowManagerInterface>#include <QtDesigner/QDesignerFormWindowCursorInterface>#include <QtDesigner/QDesignerPropertySheetExtension>#include <QtDesigner/QDesignerPropertyEditorInterface>#include <QtDesigner/QDesignerFormEditorPluginInterface>#include <QtDesigner/QExtensionManager>#include <QtAssistant/QAssistantClient>#include <QtGui/QAction>#include <QtGui/QActionGroup>#include <QtGui/QStyleFactory>#include <QtGui/QCloseEvent>#include <QtGui/QFileDialog>#include <QtGui/QMenu>#include <QtGui/QMessageBox>#include <QtGui/QPushButton>#include <QtGui/QIcon>#include <QtGui/QMdiSubWindow>#include <QtCore/QLibraryInfo>#include <QtCore/QBuffer>#include <QtCore/QPluginLoader>#include <QtCore/qdebug.h>#include <QtCore/QTimer>#include <QtCore/QMetaObject>#include <QtCore/QFileInfo>#include <QtGui/QStatusBar>#include <QtGui/QDesktopWidget>#include <QtXml/QDomDocument>#ifdef Q_WS_MAC#  define NONMODAL_PREVIEW#endifstatic QString getFileExtension(QDesignerFormEditorInterface *core){    QDesignerLanguageExtension *lang        = qt_extension<QDesignerLanguageExtension *>(core->extensionManager(), core);    if (lang)        return lang->uiExtension();    return QLatin1String("ui");}static QAction *createSeparator(QObject *parent) {    QAction * rc = new QAction(parent);    rc->setSeparator(true);    return rc;}static QActionGroup *createActionGroup(QObject *parent, bool exclusive = false) {    QActionGroup * rc = new QActionGroup(parent);    rc->setExclusive(exclusive);    return rc;}static inline QString savedMessage(const QString &fileName){    return QDesignerActions::tr("Saved %1.").arg(fileName);}QDesignerActions::QDesignerActions(QDesignerWorkbench *workbench)    : QObject(workbench),      m_workbench(workbench),      m_assistantClient(0),      m_backupTimer(new QTimer(this)),      m_fileActions(createActionGroup(this)),      m_recentFilesActions(createActionGroup(this)),      m_editActions(createActionGroup(this)),      m_formActions(createActionGroup(this)),      m_windowActions(createActionGroup(this)),      m_toolActions(createActionGroup(this, true)),      m_helpActions(0),      m_styleActions(createActionGroup(this, true)),      m_editWidgetsAction(new QAction(tr("Edit Widgets"), this)),      m_newFormAction(new QAction(qdesigner_internal::createIconSet(QLatin1String("filenew.png")), tr("&New Form..."), this)),      m_openFormAction(new QAction(qdesigner_internal::createIconSet(QLatin1String("fileopen.png")), tr("&Open Form..."), this)),      m_saveFormAction(new QAction(qdesigner_internal::createIconSet(QLatin1String("filesave.png")), tr("&Save Form"), this)),      m_saveFormAsAction(new QAction(tr("Save Form &As..."), this)),      m_saveAllFormsAction(new QAction(tr("Save A&ll Forms"), this)),      m_saveFormAsTemplateAction(new QAction(tr("Save Form As &Template..."), this)),      m_closeFormAction(new QAction(tr("&Close Form"), this)),      m_quitAction(new QAction(tr("&Quit"), this)),      m_previewFormAction(new QAction(tr("&Preview"), this)),      m_formSettings(new QAction(tr("Form &Settings..."), this)),      m_minimizeAction(new QAction(tr("&Minimize"), this)),      m_bringAllToFrontSeparator(createSeparator(this)),      m_bringAllToFrontAction(new QAction(tr("Bring All to Front"), this)),      m_windowListSeparatorAction(createSeparator(this)),      m_preferencesAction(new QAction(tr("Preferences..."), this)){    Q_ASSERT(m_workbench != 0);    m_core = m_workbench->core();    Q_ASSERT(m_core != 0);    m_helpActions = createHelpActions();    QDesignerFormWindowManagerInterface *formWindowManager = m_core->formWindowManager();    Q_ASSERT(formWindowManager != 0);    QDesignerSettings settings;//// file actions//    m_newFormAction->setShortcut(tr("CTRL+N"));    connect(m_newFormAction, SIGNAL(triggered()), this, SLOT(createForm()));    m_fileActions->addAction(m_newFormAction);    m_openFormAction->setShortcut(tr("CTRL+O"));    connect(m_openFormAction, SIGNAL(triggered()), this, SLOT(slotOpenForm()));    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();    m_recentFilesActions->addAction(createSeparator(this));    act = new QAction(tr("Clear &Menu"), this);    act->setObjectName(QLatin1String("__qt_action_clear_menu_"));    connect(act, SIGNAL(triggered()), this, SLOT(clearRecentFiles()));    m_recentFilesActions->addAction(act);    m_fileActions->addAction(createSeparator(this));    m_saveFormAction->setShortcut(tr("CTRL+S"));    connect(m_saveFormAction, SIGNAL(triggered()), this, SLOT(saveForm()));    m_fileActions->addAction(m_saveFormAction);    connect(m_saveFormAsAction, SIGNAL(triggered()), this, SLOT(saveFormAs()));    m_fileActions->addAction(m_saveFormAsAction);    m_saveAllFormsAction->setShortcut(tr("CTRL+SHIFT+S"));    connect(m_saveAllFormsAction, SIGNAL(triggered()), this, SLOT(saveAllForms()));    m_fileActions->addAction(m_saveAllFormsAction);    connect(m_saveFormAsTemplateAction, SIGNAL(triggered()), this, SLOT(saveFormAsTemplate()));    m_fileActions->addAction(m_saveFormAsTemplateAction);    m_fileActions->addAction(createSeparator(this));    m_closeFormAction = new QAction(this);    m_closeFormAction->setShortcut(tr("CTRL+W"));    connect(m_closeFormAction, SIGNAL(triggered()), this, SLOT(closeForm()));    m_fileActions->addAction(m_closeFormAction);    updateCloseAction();    m_fileActions->addAction(createSeparator(this));    m_quitAction->setShortcut(tr("CTRL+Q"));    m_quitAction->setMenuRole(QAction::QuitRole);    connect(m_quitAction, SIGNAL(triggered()), this, SLOT(shutdown()));    m_fileActions->addAction(m_quitAction);//// edit actions//    QAction *undoAction = formWindowManager->actionUndo();    undoAction->setShortcut(tr("CTRL+Z"));    m_editActions->addAction(undoAction);    QAction *redoAction = formWindowManager->actionRedo();    redoAction->setShortcut(tr("CTRL+SHIFT+Z"));    m_editActions->addAction(redoAction);    m_editActions->addAction(createSeparator(this));    m_editActions->addAction(formWindowManager->actionCut());    m_editActions->addAction(formWindowManager->actionCopy());    m_editActions->addAction(formWindowManager->actionPaste());    m_editActions->addAction(formWindowManager->actionDelete());    m_editActions->addAction(formWindowManager->actionSelectAll());    m_editActions->addAction(createSeparator(this));    m_editActions->addAction(formWindowManager->actionLower());    m_editActions->addAction(formWindowManager->actionRaise());//// edit mode actions//    m_editWidgetsAction->setCheckable(true);    m_editWidgetsAction->setShortcut(tr("F3"));    m_editWidgetsAction->setIcon(QIcon(m_core->resourceLocation() + QLatin1String("/widgettool.png")));    connect(m_editWidgetsAction, SIGNAL(triggered()), this, SLOT(editWidgetsSlot()));    m_editWidgetsAction->setChecked(true);    m_editWidgetsAction->setEnabled(false);    m_toolActions->addAction(m_editWidgetsAction);    connect(formWindowManager, SIGNAL(activeFormWindowChanged(QDesignerFormWindowInterface*)),                this, SLOT(activeFormWindowChanged(QDesignerFormWindowInterface*)));    QList<QObject*> builtinPlugins = QPluginLoader::staticInstances();    builtinPlugins += m_core->pluginManager()->instances();    foreach (QObject *plugin, builtinPlugins) {        if (QDesignerFormEditorPluginInterface *formEditorPlugin = qobject_cast<QDesignerFormEditorPluginInterface*>(plugin)) {            if (QAction *action = formEditorPlugin->action()) {                m_toolActions->addAction(action);                action->setCheckable(true);            }        }    }    connect(m_preferencesAction, SIGNAL(triggered()),  this, SLOT(showPreferencesDialog()));    m_preferencesAction->setMenuRole(QAction::PreferencesRole);//// form actions//    m_formActions->addAction(formWindowManager->actionHorizontalLayout());    m_formActions->addAction(formWindowManager->actionVerticalLayout());    m_formActions->addAction(formWindowManager->actionSplitHorizontal());    m_formActions->addAction(formWindowManager->actionSplitVertical());    m_formActions->addAction(formWindowManager->actionGridLayout());    m_formActions->addAction(formWindowManager->actionBreakLayout());    m_formActions->addAction(formWindowManager->actionAdjustSize());    m_formActions->addAction(createSeparator(this));    m_previewFormAction->setShortcut(tr("CTRL+R"));    connect(m_previewFormAction, SIGNAL(triggered()), this, SLOT(previewFormLater()));    m_formActions->addAction(m_previewFormAction);    connect(m_styleActions, SIGNAL(triggered(QAction*)), this, SLOT(previewForm(QAction*)));    m_formActions->addAction(createSeparator(this));    m_formSettings->setEnabled(false);    connect(m_formSettings, SIGNAL(triggered()), this, SLOT(showFormSettings()));    m_formActions->addAction(m_formSettings);    foreach (QString style,  QStyleFactory::keys()) {        QAction *a = new QAction(tr("%1 Style").arg(style), this);        a->setData(style);        m_styleActions->addAction(a);    }//// window actions//    m_minimizeAction->setEnabled(false);    m_minimizeAction->setCheckable(true);    m_minimizeAction->setShortcut(tr("CTRL+M"));    connect(m_minimizeAction, SIGNAL(triggered()), m_workbench, SLOT(toggleFormMinimizationState()));    m_windowActions->addAction(m_minimizeAction);    m_windowActions->addAction(m_bringAllToFrontSeparator);    connect(m_bringAllToFrontAction, SIGNAL(triggered()), m_workbench, SLOT(bringAllToFront()));    m_windowActions->addAction(m_bringAllToFrontAction);    m_windowActions->addAction(m_windowListSeparatorAction);    setWindowListSeparatorVisible(false);//// connections//    fixActionContext();    activeFormWindowChanged(core()->formWindowManager()->activeFormWindow());    m_backupTimer->start(180000); // 3min    connect(m_backupTimer, SIGNAL(timeout()), this, SLOT(backupForms()));}QActionGroup *QDesignerActions::createHelpActions(){    QActionGroup *helpActions = createActionGroup(this);#ifndef QT_JAMBI_BUILD    QAction *mainHelpAction = new QAction(tr("Qt Designer &Help"), this);    connect(mainHelpAction, SIGNAL(triggered()), this, SLOT(showDesignerHelp()));    mainHelpAction->setShortcut(Qt::CTRL + Qt::Key_Question);    helpActions->addAction(mainHelpAction);    helpActions->addAction(createSeparator(this));    QAction *widgetHelp = new QAction(tr("Current Widget Help"), this);    widgetHelp->setShortcut(Qt::Key_F1);    connect(widgetHelp, SIGNAL(triggered()), this, SLOT(showWidgetSpecificHelp()));    helpActions->addAction(widgetHelp);    helpActions->addAction(createSeparator(this));    QAction *whatsNewAction = new QAction(tr("What's New in Qt Designer?"), this);    connect(whatsNewAction, SIGNAL(triggered()), this, SLOT(showWhatsNew()));    helpActions->addAction(whatsNewAction);#endif    helpActions->addAction(createSeparator(this));    QAction *aboutPluginsAction = new QAction(tr("About Plugins"), this);    aboutPluginsAction->setMenuRole(QAction::ApplicationSpecificRole);    connect(aboutPluginsAction, SIGNAL(triggered()), this, SLOT(aboutPlugins()));    helpActions->addAction(aboutPluginsAction);    QAction *aboutDesignerAction = new QAction(tr("About Qt Designer"), this);    aboutDesignerAction->setMenuRole(QAction::AboutRole);    connect(aboutDesignerAction, SIGNAL(triggered()), this, SLOT(aboutDesigner()));    helpActions->addAction(aboutDesignerAction);    QAction *aboutQtAction = new QAction(tr("About Qt"), this);    aboutQtAction->setMenuRole(QAction::AboutQtRole);    connect(aboutQtAction, SIGNAL(triggered()), qApp, SLOT(aboutQt()));    helpActions->addAction(aboutQtAction);    return helpActions;}QDesignerActions::~QDesignerActions(){}QActionGroup *QDesignerActions::toolActions() const{ return m_toolActions; }QDesignerWorkbench *QDesignerActions::workbench() const{ return m_workbench; }QDesignerFormEditorInterface *QDesignerActions::core() const{ return m_core; }QActionGroup *QDesignerActions::fileActions() const{ return m_fileActions; }QActionGroup *QDesignerActions::editActions() const{ return m_editActions; }QActionGroup *QDesignerActions::formActions() const{ return m_formActions; }QActionGroup *QDesignerActions::windowActions() const{ return m_windowActions; }QActionGroup *QDesignerActions::helpActions() const{ return m_helpActions; }QActionGroup *QDesignerActions::styleActions() const{ return m_styleActions; }QAction *QDesignerActions::previewFormAction() const{ return m_previewFormAction; }void QDesignerActions::editWidgetsSlot(){    QDesignerFormWindowManagerInterface *formWindowManager = core()->formWindowManager();    for (int i=0; i<formWindowManager->formWindowCount(); ++i) {        QDesignerFormWindowInterface *formWindow = formWindowManager->formWindow(i);        formWindow->editWidgets();    }}void QDesignerActions::createForm(){    showNewFormDialog(QString());}void QDesignerActions::showNewFormDialog(const QString &fileName){#ifdef NONMODAL_PREVIEW    closePreview();#endif    NewForm *dlg = new NewForm(workbench(), workbench()->core()->topLevel(), fileName);    dlg->setAttribute(Qt::WA_DeleteOnClose);    dlg->setAttribute(Qt::WA_ShowModal);    dlg->setGeometry(fixDialogRect(dlg->rect()));    dlg->exec();}void QDesignerActions::slotOpenForm(){    openForm(core()->topLevel());}

⌨️ 快捷键说明

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