OSDN Git Service

It's 2011 now.
[qt-creator-jp/qt-creator-jp.git] / src / plugins / designer / formeditorfactory.cpp
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 (qt-info@nokia.com)
8 **
9 ** No Commercial Usage
10 **
11 ** This file contains pre-release code and may not be distributed.
12 ** You may use this file in accordance with the terms and conditions
13 ** contained in the Technology Preview License Agreement accompanying
14 ** this package.
15 **
16 ** GNU Lesser General Public License Usage
17 **
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file.  Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Nokia gives you certain additional
26 ** rights.  These rights are described in the Nokia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** If you have questions regarding the use of this file, please contact
30 ** Nokia at qt-info@nokia.com.
31 **
32 **************************************************************************/
33
34 #include "formeditorfactory.h"
35 #include "formeditorw.h"
36 #include "formwindoweditor.h"
37 #include "editordata.h"
38 #include "designerconstants.h"
39 #include "designerxmleditor.h"
40
41 #include <coreplugin/coreconstants.h>
42 #include <coreplugin/icore.h>
43 #include <coreplugin/fileiconprovider.h>
44 #include <coreplugin/editormanager/editormanager.h>
45 #include <coreplugin/modemanager.h>
46
47 #include <QtCore/QFileInfo>
48 #include <QtCore/QDebug>
49
50 using namespace Designer::Constants;
51
52 namespace Designer {
53 namespace Internal {
54
55 FormEditorFactory::FormEditorFactory()
56   : Core::IEditorFactory(Core::ICore::instance()),
57     m_mimeTypes(QLatin1String(FORM_MIMETYPE))
58 {
59     Core::FileIconProvider *iconProvider = Core::FileIconProvider::instance();
60     iconProvider->registerIconOverlayForSuffix(QIcon(QLatin1String(":/formeditor/images/qt_ui.png")),
61                                                QLatin1String("ui"));
62     connect(Core::EditorManager::instance(), SIGNAL(currentEditorChanged(Core::IEditor*)),
63              SLOT(updateEditorInfoBar(Core::IEditor*)));
64 }
65
66 QString FormEditorFactory::id() const
67 {
68     return QLatin1String(DESIGNER_XML_EDITOR_ID);
69 }
70
71 QString FormEditorFactory::displayName() const
72 {
73     return tr(C_DESIGNER_XML_DISPLAY_NAME);
74 }
75
76 Core::IFile *FormEditorFactory::open(const QString &fileName)
77 {
78     Core::IEditor *iface = Core::EditorManager::instance()->openEditor(fileName, id());
79     return iface ? iface->file() : 0;
80 }
81
82 Core::IEditor *FormEditorFactory::createEditor(QWidget *parent)
83 {
84     const EditorData data = FormEditorW::instance()->createEditor(parent);
85     return data.formWindowEditor;
86 }
87
88 QStringList FormEditorFactory::mimeTypes() const
89 {
90     return m_mimeTypes;
91 }
92
93 void FormEditorFactory::updateEditorInfoBar(Core::IEditor *editor)
94 {
95     if (qobject_cast<FormWindowEditor *>(editor)) {
96         Core::EditorManager::instance()->showEditorInfoBar(Constants::INFO_READ_ONLY,
97             tr("This file can only be edited in <b>Design</b> mode."),
98             tr("Switch mode"), this, SLOT(designerModeClicked()));
99     } else {
100         Core::EditorManager::instance()->hideEditorInfoBar(Constants::INFO_READ_ONLY);
101     }
102 }
103
104 void FormEditorFactory::designerModeClicked()
105 {
106     Core::ICore::instance()->modeManager()->activateMode(QLatin1String(Core::Constants::MODE_DESIGN));
107 }
108
109 } // namespace Internal
110 } // namespace Designer
111
112