1 /**************************************************************************
3 ** This file is part of Qt Creator
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
7 ** Contact: Nokia Corporation (info@qt.nokia.com)
10 ** GNU Lesser General Public License Usage
12 ** This file may be used under the terms of the GNU Lesser General Public
13 ** License version 2.1 as published by the Free Software Foundation and
14 ** appearing in the file LICENSE.LGPL included in the packaging of this file.
15 ** Please review the following information to ensure the GNU Lesser General
16 ** Public License version 2.1 requirements will be met:
17 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
19 ** In addition, as a special exception, Nokia gives you certain additional
20 ** rights. These rights are described in the Nokia Qt LGPL Exception
21 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
25 ** Alternatively, this file may be used in accordance with the terms and
26 ** conditions contained in a signed written agreement between you and Nokia.
28 ** If you have questions regarding the use of this file, please contact
29 ** Nokia at qt-info@nokia.com.
31 **************************************************************************/
36 #include "designerconstants.h"
38 #include <coreplugin/icontext.h>
39 #include <coreplugin/dialogs/ioptionspage.h>
41 #include <QtCore/QMap>
42 #include <QtCore/QObject>
43 #include <QtCore/QStringList>
47 class QDesignerIntegrationInterface;
48 class QDesignerFormEditorInterface;
49 class QDesignerFormWindowInterface;
58 namespace qdesigner_internal {
59 class QDesignerFormWindowManager;
66 class ActionContainer;
80 class DesignerContext;
82 /** FormEditorW is a singleton that stores the Designer CoreInterface and
83 * performs centralized operations. The instance() method will return an
84 * instance. However, it must be manually deleted when unloading the
85 * plugin. Since fully initializing Designer at startup is expensive, the
86 * class has an internal partial initialisation stage "RegisterPlugins"
87 * which is there to register the Creator plugin objects
88 * that must be present at startup (settings pages, actions).
89 * The plugin uses this stage at first by calling ensureInitStage().
90 * Requesting an editor via instance() will fully initialize the class.
91 * This is based on the assumption that the Designer settings work with
94 * The form editor shows a read-only XML editor in edit mode and Qt Designer
96 class FormEditorW : public QObject
100 enum InitializationStage {
101 // Register Creator plugins (settings pages, actions)
103 // Fully initialized for handling editor requests
107 virtual ~FormEditorW();
109 // Create an instance and initialize up to stage s
110 static void ensureInitStage(InitializationStage s);
111 // Returns fully initialized instance
112 static FormEditorW *instance();
113 // Deletes an existing instance if there is one.
114 static void deleteInstance();
116 EditorData createEditor(QWidget *parent);
118 inline QDesignerFormEditorInterface *designerEditor() const { return m_formeditor; }
119 inline QWidget * const*designerSubWindows() const { return m_designerSubWindows; }
121 EditorData activeEditor() const;
122 QList<Core::IOptionsPage *> optionsPages() const;
125 void activateEditMode(int id);
126 void activateEditMode(QAction*);
127 void activeFormWindowChanged(QDesignerFormWindowInterface *);
128 void currentEditorChanged(Core::IEditor *editor);
129 void toolChanged(int);
131 void setPreviewMenuEnabled(bool e);
132 void switchSourceForm();
133 void updateShortcut(QObject *command);
134 void closeFormEditorsForXmlEditors(QList<Core::IEditor*> editors);
140 void saveSettings(QSettings *s);
142 void initDesignerSubWindows();
145 void setupViewActions();
146 void addDockViewAction(Core::ActionManager *am,
147 Core::ActionContainer *viewMenu,
149 const Core::Context &context,
150 const QString &title, const QString &id);
152 Core::ActionContainer *createPreviewStyleMenu(Core::ActionManager *am,
153 QActionGroup *actionGroup);
155 void critical(const QString &errorMessage);
156 void bindShortcut(Core::Command *command, QAction *action);
157 QAction *createEditModeAction(QActionGroup *ag,
158 const Core::Context &context,
159 Core::ActionManager *am,
160 Core::ActionContainer *medit,
161 const QString &actionName,
164 const QString &iconName = QString(),
165 const QString &keySequence = QString());
166 Core::Command *addToolAction(QAction *a, Core::ActionManager *am,
167 const Core::Context &context, const QString &name,
168 Core::ActionContainer *c1, const QString &keySequence = QString());
169 QToolBar *createEditorToolBar() const;
171 static FormEditorW *m_self;
173 QDesignerFormEditorInterface *m_formeditor;
174 QDesignerIntegrationInterface *m_integration;
175 qdesigner_internal::QDesignerFormWindowManager *m_fwm;
177 InitializationStage m_initStage;
179 QWidget *m_designerSubWindows[Designer::Constants::DesignerSubWindowCount];
181 QAction *m_lockAction;
182 QAction *m_resetLayoutAction;
184 QList<Core::IOptionsPage *> m_settingsPages;
185 QActionGroup *m_actionGroupEditMode;
186 QAction *m_actionPrint;
187 QAction *m_actionPreview;
188 QActionGroup *m_actionGroupPreviewInStyle;
189 QMenu *m_previewInStyleMenu;
190 QAction *m_actionAboutPlugins;
191 QAction *m_modeActionSeparator;
192 QAction *m_actionSwitchSource;
193 QSignalMapper *m_shortcutMapper;
195 DesignerContext *m_context;
196 Core::Context m_contexts;
198 QStringList m_toolActionIds;
199 QWidget *m_modeWidget;
200 EditorWidget *m_editorWidget;
201 Core::DesignMode *m_designMode;
203 QWidget *m_editorToolBar;
204 Core::EditorToolBar *m_toolBar;
206 QMap<Core::Command *, QAction *> m_commandToDesignerAction;
209 } // namespace Internal
210 } // namespace Designer
212 #endif // FORMEDITORW_H