📄 qdesigner_workbench.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_workbench.h"#include "qdesigner_actions.h"#include "qdesigner_toolwindow.h"#include "qdesigner_formwindow.h"#include "qdesigner_settings.h"#include "qdesigner_widgetbox.h"#include "qdesigner_propertyeditor.h"#include "qdesigner_objectinspector.h"#include "qdesigner_signalsloteditor.h"#include "qdesigner_actioneditor.h"#include "qdesigner_resourceeditor.h"#include <QtDesigner/QtDesigner>#include <QtDesigner/QDesignerComponents>#include <QtDesigner/private/qdesigner_integration_p.h>#include <QtDesigner/private/pluginmanager_p.h>#include <QtGui/QDockWidget>#include <QtGui/QWorkspace>#include <QtGui/QCloseEvent>#include <QtGui/QDesktopWidget>#include <QtGui/QLabel>#include <QtGui/QMenu>#include <QtGui/QMenuBar>#include <QtGui/QToolBar>#include <QtGui/QActionGroup>#include <QtGui/QMessageBox>#include <QtGui/QHeaderView>#include <QtCore/QVariant>#include <QtCore/QUrl>#include <QtCore/QPluginLoader>#include <QtCore/qdebug.h>QDesignerWorkbench::QDesignerWorkbench() : m_mode(QDesignerWorkbench::NeutralMode), m_workspace(0){ m_initializing = true; initialize(); setUIMode(UIMode(QDesignerSettings().uiMode())); m_initializing = false;}QDesignerWorkbench::~QDesignerWorkbench(){ if (m_mode == DockedMode) { Q_ASSERT(m_workspace != 0); QMainWindow *mw = qobject_cast<QMainWindow*>(m_workspace->window()); Q_ASSERT(mw != 0); QDesignerSettings settings; settings.setMainWindowState(mw->saveState(2)); } while (!m_toolWindows.isEmpty()) delete m_toolWindows.takeLast();}QDesignerWorkbench::UIMode QDesignerWorkbench::mode() const{ return m_mode;}void QDesignerWorkbench::addToolWindow(QDesignerToolWindow *toolWindow){ Q_ASSERT(m_toolWindowExtras.contains(toolWindow) == false); Q_ASSERT(toolWindow->windowTitle().isEmpty() == false); m_toolWindows.append(toolWindow); if (QAction *action = toolWindow->action()) { Q_ASSERT(m_toolMenu->actions().isEmpty() == false); QList<QAction*> lst = m_toolActions->actions(); QAction *before = lst.count() ? lst.last() : m_toolMenu->actions().first(); m_toolMenu->insertAction(before, action); m_toolActions->addAction(action); }}void QDesignerWorkbench::addFormWindow(QDesignerFormWindow *formWindow){ Q_ASSERT(m_formWindowExtras.contains(formWindow) == false); // ### Q_ASSERT(formWindow->windowTitle().isEmpty() == false); m_formWindows.append(formWindow); if (m_windowActions->actions().isEmpty()) m_windowMenu->addSeparator(); if (QAction *action = formWindow->action()) { m_windowActions->addAction(action); m_windowMenu->addAction(action); action->setChecked(true); } m_actionManager->minimizeAction()->setEnabled(true); m_actionManager->editWidgets()->trigger();}void QDesignerWorkbench::initialize(){ QDesignerSettings settings; m_core = QDesignerComponents::createFormEditor(this); (void) QDesignerComponents::createTaskMenu(core(), this); initializeCorePlugins(); QDesignerComponents::initializePlugins(core()); m_toolActions = new QActionGroup(this); m_toolActions->setExclusive(false); m_windowActions = new QActionGroup(this); m_windowActions->setExclusive(true); connect(m_windowActions, SIGNAL(triggered(QAction*)), this, SLOT(formWindowActionTriggered(QAction*))); m_actionManager = new QDesignerActions(this); m_globalMenuBar = new QMenuBar; m_fileMenu = m_globalMenuBar->addMenu(tr("&File")); foreach (QAction *action, m_actionManager->fileActions()->actions()) { m_fileMenu->addAction(action); if (action->text() == QDesignerActions::tr("&Open Form...")) { QMenu *recentFilesMenu = m_fileMenu->addMenu(tr("&Recent Forms")); // Pop the "Recent Files" stuff in here. foreach(QAction *recentAction, m_actionManager->recentFilesActions()->actions()) recentFilesMenu->addAction(recentAction); } } m_editMenu = m_globalMenuBar->addMenu(tr("&Edit")); foreach (QAction *action, m_actionManager->editActions()->actions()) { m_editMenu->addAction(action); } m_editMenu->addSeparator(); foreach (QAction *action, m_actionManager->toolActions()->actions()) { m_editMenu->addAction(action); } m_editMenu->addSeparator(); QMenu *menu = m_editMenu->addMenu(tr("User Interface &Mode")); foreach (QAction *action, m_actionManager->uiMode()->actions()) menu->addAction(action); m_formMenu = m_globalMenuBar->addMenu(tr("F&orm")); foreach (QAction *action, m_actionManager->formActions()->actions()) { m_formMenu->addAction(action); } QMenu *previewSubMenu = new QMenu(tr("Preview in"), m_formMenu); m_formMenu->insertMenu(m_actionManager->previewFormAction(), previewSubMenu); foreach (QAction *action, m_actionManager->styleActions()->actions()) { previewSubMenu->addAction(action); } m_toolMenu = m_globalMenuBar->addMenu(tr("&Tools")); m_toolMenu->addSeparator(); m_windowMenu = m_globalMenuBar->addMenu(tr("&Window")); foreach (QAction *action, m_actionManager->windowActions()->actions()) { m_windowMenu->addAction(action); } m_helpMenu = m_globalMenuBar->addMenu(tr("&Help")); foreach (QAction *action, m_actionManager->helpActions()->actions()) { m_helpMenu->addAction(action); } QDesignerToolWindow *tw = new QDesignerWidgetBox(this); tw->setObjectName(QLatin1String("qt_designer_widgetbox")); addToolWindow(tw); tw = new QDesignerObjectInspector(this); tw->setObjectName(QLatin1String("qt_designer_objectinspector")); addToolWindow(tw); tw = new QDesignerPropertyEditor(this); tw->setObjectName(QLatin1String("qt_designer_propertyeditor")); addToolWindow(tw); tw = new QDesignerSignalSlotEditor(this); tw->setObjectName(QLatin1String("qt_designer_signalsloteditor")); addToolWindow(tw); tw = new QDesignerResourceEditor(this); tw->setObjectName(QLatin1String("qt_designer_resourceeditor")); addToolWindow(tw); tw = new QDesignerActionEditor(this); tw->setObjectName(QLatin1String("qt_designer_actioneditor")); addToolWindow(tw); m_integration = new qdesigner_internal::QDesignerIntegration(core(), this); // create the toolbars m_editToolBar = new QToolBar; m_editToolBar->setObjectName(QLatin1String("editToolBar")); m_editToolBar->setWindowTitle(tr("Edit")); foreach (QAction *action, m_actionManager->editActions()->actions()) { if (action->icon().isNull() == false) m_editToolBar->addAction(action); } m_toolToolBar = new QToolBar; m_toolToolBar->setObjectName(QLatin1String("toolsToolBar")); m_toolToolBar->setWindowTitle(tr("Tools")); foreach (QAction *action, m_actionManager->toolActions()->actions()) { if (action->icon().isNull() == false) m_toolToolBar->addAction(action); } m_formToolBar = new QToolBar; m_formToolBar->setObjectName(QLatin1String("formToolBar")); m_formToolBar->setWindowTitle(tr("Form")); foreach (QAction *action, m_actionManager->formActions()->actions()) { if (action->icon().isNull() == false) m_formToolBar->addAction(action); } QMenu *toolbarMenu = m_toolMenu->addMenu(tr("Toolbars")); toolbarMenu->addAction(m_editToolBar->toggleViewAction()); toolbarMenu->addAction(m_toolToolBar->toggleViewAction()); toolbarMenu->addAction(m_formToolBar->toggleViewAction()); m_geometries.clear(); emit initialized(); connect(m_core->formWindowManager(), SIGNAL(activeFormWindowChanged(QDesignerFormWindowInterface*)), this, SLOT(updateWindowMenu(QDesignerFormWindowInterface*)));}Qt::WindowFlags QDesignerWorkbench::magicalWindowFlags(const QWidget *widgetForFlags) const{ switch (m_mode) { case TopLevelMode: {#ifdef Q_WS_MAC if (qobject_cast<const QDesignerToolWindow *>(widgetForFlags)) return Qt::Tool;#else Q_UNUSED(widgetForFlags);#endif return Qt::Window; } case DockedMode: Q_ASSERT(m_workspace != 0); return Qt::Window | Qt::WindowShadeButtonHint | Qt::WindowSystemMenuHint | Qt::WindowTitleHint; case NeutralMode: return Qt::Window; default: Q_ASSERT(0); return 0; }}QWidget *QDesignerWorkbench::magicalParent() const{ switch (m_mode) { case TopLevelMode: return 0; case DockedMode: Q_ASSERT(m_workspace != 0); return m_workspace; case NeutralMode: return 0; default: Q_ASSERT(0); return 0; }}void QDesignerWorkbench::switchToNeutralMode(){ if (m_mode == NeutralMode) { return; } else if (m_mode == DockedMode) { Q_ASSERT(m_workspace != 0); QMainWindow *mw = qobject_cast<QMainWindow*>(m_workspace->window()); QDesignerSettings settings; settings.setMainWindowState(mw->saveState(2)); } QPoint desktopOffset = QPoint(0, 0); QPoint workspaceOffset = QPoint(0, 0); if (m_mode == TopLevelMode) desktopOffset = QApplication::desktop()->availableGeometry().topLeft(); else if (m_mode == DockedMode) workspaceOffset = m_workspace->mapToGlobal(QPoint(0, 0)); m_mode = NeutralMode; m_geometries.clear(); m_visibilities.clear(); foreach (QDesignerToolWindow *tw, m_toolWindows) { m_visibilities.insert(tw, tw->isVisible()); if (tw->isVisible()) { // use the actual geometry QPoint pos = tw->window()->pos(); if (!tw->isWindow()) { if (const QWidget *pw = tw->parentWidget()) { pos = pw->mapTo(tw->window(), QPoint(0, 0)); pos += tw->window()->pos(); } } m_geometries.insert(tw, QRect(pos - desktopOffset, tw->size())); } tw->setSaveSettingsOnClose(false); tw->setParent(0); } foreach (QDesignerFormWindow *fw, m_formWindows) { if (fw->isVisible()) { // use the actual geometry QPoint pos = fw->window()->pos(); if (!fw->isWindow()) if (QWidget *p = fw->parentWidget()) pos = p->pos(); // in workspace m_geometries.insert(fw, QRect(pos - desktopOffset + workspaceOffset, fw->size())); } fw->setParent(0); }#ifndef Q_WS_MAC m_globalMenuBar->setParent(0);#endif m_editToolBar->setParent(0); m_toolToolBar->setParent(0); m_formToolBar->setParent(0); m_core->setTopLevel(0); qDesigner->setMainWindow(0); if (m_workspace) delete m_workspace->parentWidget(); m_workspace = 0;}void QDesignerWorkbench::switchToDockedMode(){ bool wasTopLevel = (m_mode == TopLevelMode); if (m_mode == DockedMode) return; switchToNeutralMode(); m_mode = DockedMode; QDesignerToolWindow *widgetBoxWrapper = 0; if (0 != (widgetBoxWrapper = findToolWindow(core()->widgetBox()))) { widgetBoxWrapper->action()->setEnabled(true); widgetBoxWrapper->setWindowTitle(tr("Widget Box")); } Q_ASSERT(m_workspace == 0); QDesignerSettings settings; QDesignerToolWindow *mw = new QDesignerToolWindow(this); // Just to have a copy of mw->setSaveSettingsOnClose(true); mw->setObjectName(QLatin1String("MDIWindow")); mw->setWindowTitle(tr("Qt Designer")); m_workspace = new QWorkspace(mw); m_workspace->setAcceptDrops(true); m_workspace->installEventFilter(this); m_workspace->setScrollBarsEnabled(true); connect(m_workspace, SIGNAL(windowActivated(QWidget*)), this, SLOT(activateWorkspaceChildWindow(QWidget*))); mw->setCentralWidget(m_workspace); m_core->setTopLevel(mw); (void) mw->statusBar(); if (m_geometries.isEmpty()) { settings.setGeometryFor(mw, qApp->desktop()->availableGeometry(0)); } else { if (QDesignerToolWindow *widgetBox = findToolWindow(core()->widgetBox())) { QRect r = m_geometries.value(widgetBox, QRect(0, 0, 200, 200)); mw->move(r.topLeft()); } mw->setWindowState(mw->windowState() | Qt::WindowMaximized); }#ifndef Q_WS_MAC mw->setMenuBar(m_globalMenuBar); m_globalMenuBar->show();#endif mw->addToolBar(m_editToolBar); mw->addToolBar(m_toolToolBar); mw->addToolBar(m_formToolBar); m_editToolBar->show(); m_toolToolBar->show(); m_formToolBar->show(); qDesigner->setMainWindow(mw); foreach (QDesignerToolWindow *tw, m_toolWindows) { if (wasTopLevel) settings.saveGeometryFor(tw); QDockWidget *dockWidget = magicalDockWidget(tw); if (dockWidget == 0) { dockWidget = new QDockWidget(mw); dockWidget->setObjectName(tw->objectName() + QLatin1String("_dock")); dockWidget->setWindowTitle(tw->windowTitle()); mw->addDockWidget(tw->dockWidgetAreaHint(), dockWidget); } dockWidget->setWidget(tw); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -