OSDN Git Service

Update license.
[qt-creator-jp/qt-creator-jp.git] / src / plugins / designer / formwizarddialog.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 (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 #include "formwizarddialog.h"
34 #include "formtemplatewizardpage.h"
35 #include "formeditorw.h"
36
37 #include <coreplugin/icore.h>
38 #include <coreplugin/basefilewizard.h>
39
40 #include <utils/filewizardpage.h>
41
42 #include <QtCore/QDebug>
43 #include <QtGui/QAbstractButton>
44
45 // Make sure there is a gap before the extension pages
46 enum { FormPageId, FilePageId, FirstExtensionPageId = 10 };
47
48 namespace Designer {
49 namespace Internal {
50
51 // ----------------- FormWizardDialog
52 FormWizardDialog::FormWizardDialog(const WizardPageList &extensionPages,
53                                    QWidget *parent)
54     : Utils::Wizard(parent),
55     m_formPage(new FormTemplateWizardPage)
56 {
57     init(extensionPages);
58 }
59
60 void FormWizardDialog::init(const WizardPageList &extensionPages)
61 {
62     Core::BaseFileWizard::setupWizard(this);
63     setWindowTitle(tr("Qt Designer Form"));
64     setPage(FormPageId, m_formPage);
65     wizardProgress()->item(FormPageId)->setTitle(tr("Form Template"));
66
67     if (!extensionPages.empty()) {
68         int id = FirstExtensionPageId;
69         foreach (QWizardPage *p, extensionPages) {
70             setPage(id, p);
71             Core::BaseFileWizard::applyExtensionPageShortTitle(this, id);
72             id++;
73         }
74     }
75 }
76
77 QString FormWizardDialog::templateContents() const
78 {
79     // Template is expensive, cache
80     if (m_templateContents.isEmpty())
81         m_templateContents = m_formPage->templateContents();
82     return m_templateContents;
83 }
84
85 // ----------------- FormFileWizardDialog
86 FormFileWizardDialog::FormFileWizardDialog(const WizardPageList &extensionPages,
87                                            QWidget *parent)
88   : FormWizardDialog(extensionPages, parent),
89     m_filePage(new Utils::FileWizardPage)
90 {
91     setPage(FilePageId, m_filePage);
92     wizardProgress()->item(FilePageId)->setTitle(tr("Location"));
93     connect(m_filePage, SIGNAL(activated()),
94             button(QWizard::FinishButton), SLOT(animateClick()));
95
96     connect(this, SIGNAL(currentIdChanged(int)), this, SLOT(slotCurrentIdChanged(int)));
97 }
98
99 QString FormFileWizardDialog::path() const
100 {
101     return m_filePage->path();
102 }
103
104 void FormFileWizardDialog::setPath(const QString &path)
105 {
106     m_filePage->setPath(path);
107 }
108
109 QString FormFileWizardDialog::fileName() const
110 {
111     return m_filePage->fileName();
112 }
113
114 void FormFileWizardDialog::slotCurrentIdChanged(int id)
115 {
116     if (id == FilePageId) {
117         // Change from form to file: Store template and Suggest a name based on
118         // the ui class
119         QString formBaseClass;
120         QString uiClassName;
121         if (FormTemplateWizardPage::getUIXmlData(templateContents(), &formBaseClass, &uiClassName)) {
122             QString fileName = FormTemplateWizardPage::stripNamespaces(uiClassName).toLower();
123             fileName += QLatin1String(".ui");
124             m_filePage->setFileName(fileName);
125         }
126     }
127 }
128
129 } // namespace Internal
130 } // namespace Designer