OSDN Git Service

Update license.
[qt-creator-jp/qt-creator-jp.git] / src / plugins / designer / formeditorw.h
1 /**************************************************************************
2 **
3 ** This file is part of Qt Creator
4 **
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
6 **
7 ** Contact: Nokia Corporation (info@qt.nokia.com)
8 **
9 **
10 ** GNU Lesser General Public License Usage
11 **
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.
18 **
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.
22 **
23 ** Other Usage
24 **
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.
27 **
28 ** If you have questions regarding the use of this file, please contact
29 ** Nokia at qt-info@nokia.com.
30 **
31 **************************************************************************/
32
33 #ifndef FORMEDITORW_H
34 #define FORMEDITORW_H
35
36 #include "designerconstants.h"
37
38 #include <coreplugin/icontext.h>
39 #include <coreplugin/dialogs/ioptionspage.h>
40
41 #include <QtCore/QMap>
42 #include <QtCore/QObject>
43 #include <QtCore/QStringList>
44
45 QT_BEGIN_NAMESPACE
46
47 class QDesignerIntegrationInterface;
48 class QDesignerFormEditorInterface;
49 class QDesignerFormWindowInterface;
50
51 class QAction;
52 class QActionGroup;
53 class QMenu;
54 class QSignalMapper;
55 class QSettings;
56 class QToolBar;
57
58 namespace qdesigner_internal {
59     class QDesignerFormWindowManager;
60 }
61
62 QT_END_NAMESPACE
63
64 namespace Core {
65 class ActionManager;
66 class ActionContainer;
67 class ICore;
68 class IEditor;
69 class Command;
70 class DesignMode;
71 class EditorToolBar;
72 }
73
74 namespace Designer {
75 namespace Internal {
76
77 struct EditorData;
78 class EditorWidget;
79 class SettingsPage;
80 class DesignerContext;
81
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
92   * no plugins loaded.
93   *
94   * The form editor shows a read-only XML editor in edit mode and Qt Designer
95   * in Design mode. */
96 class FormEditorW : public QObject
97 {
98     Q_OBJECT
99 public:
100     enum InitializationStage {
101         // Register Creator plugins (settings pages, actions)
102         RegisterPlugins,
103         // Fully initialized for handling editor requests
104         FullyInitialized
105     };
106
107     virtual ~FormEditorW();
108
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();
115
116     EditorData createEditor(QWidget *parent);
117
118     inline QDesignerFormEditorInterface *designerEditor() const { return m_formeditor; }
119     inline QWidget * const*designerSubWindows() const { return m_designerSubWindows; }
120
121     EditorData activeEditor() const;
122     QList<Core::IOptionsPage *> optionsPages() const;
123
124 private slots:
125     void activateEditMode(int id);
126     void activateEditMode(QAction*);
127     void activeFormWindowChanged(QDesignerFormWindowInterface *);
128     void currentEditorChanged(Core::IEditor *editor);
129     void toolChanged(int);
130     void print();
131     void setPreviewMenuEnabled(bool e);
132     void switchSourceForm();
133     void updateShortcut(QObject *command);
134     void closeFormEditorsForXmlEditors(QList<Core::IEditor*> editors);
135
136 private:
137     FormEditorW();
138     void fullInit();
139
140     void saveSettings(QSettings *s);
141
142     void initDesignerSubWindows();
143
144     void setupActions();
145     void setupViewActions();
146     void addDockViewAction(Core::ActionManager *am,
147                            Core::ActionContainer *viewMenu,
148                            int index,
149                            const Core::Context &context,
150                            const QString &title, const QString &id);
151
152     Core::ActionContainer *createPreviewStyleMenu(Core::ActionManager *am,
153                                                    QActionGroup *actionGroup);
154
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,
162                                          const QString &name,
163                                          int toolNumber,
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;
170
171     static FormEditorW *m_self;
172
173     QDesignerFormEditorInterface *m_formeditor;
174     QDesignerIntegrationInterface *m_integration;
175     qdesigner_internal::QDesignerFormWindowManager *m_fwm;
176     Core::ICore *m_core;
177     InitializationStage m_initStage;
178
179     QWidget *m_designerSubWindows[Designer::Constants::DesignerSubWindowCount];
180
181     QAction *m_lockAction;
182     QAction *m_resetLayoutAction;
183
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;
194
195     DesignerContext *m_context;
196     Core::Context m_contexts;
197
198     QStringList m_toolActionIds;
199     QWidget *m_modeWidget;
200     EditorWidget *m_editorWidget;
201     Core::DesignMode *m_designMode;
202
203     QWidget *m_editorToolBar;
204     Core::EditorToolBar *m_toolBar;
205
206     QMap<Core::Command *, QAction *> m_commandToDesignerAction;
207 };
208
209 } // namespace Internal
210 } // namespace Designer
211
212 #endif // FORMEDITORW_H