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 **************************************************************************/
33 #include "formwizarddialog.h"
34 #include "formtemplatewizardpage.h"
35 #include "formeditorw.h"
37 #include <coreplugin/icore.h>
38 #include <coreplugin/basefilewizard.h>
40 #include <utils/filewizardpage.h>
42 #include <QtCore/QDebug>
43 #include <QtGui/QAbstractButton>
45 // Make sure there is a gap before the extension pages
46 enum { FormPageId, FilePageId, FirstExtensionPageId = 10 };
51 // ----------------- FormWizardDialog
52 FormWizardDialog::FormWizardDialog(const WizardPageList &extensionPages,
54 : Utils::Wizard(parent),
55 m_formPage(new FormTemplateWizardPage)
60 void FormWizardDialog::init(const WizardPageList &extensionPages)
62 Core::BaseFileWizard::setupWizard(this);
63 setWindowTitle(tr("Qt Designer Form"));
64 setPage(FormPageId, m_formPage);
65 wizardProgress()->item(FormPageId)->setTitle(tr("Form Template"));
67 if (!extensionPages.empty()) {
68 int id = FirstExtensionPageId;
69 foreach (QWizardPage *p, extensionPages) {
71 Core::BaseFileWizard::applyExtensionPageShortTitle(this, id);
77 QString FormWizardDialog::templateContents() const
79 // Template is expensive, cache
80 if (m_templateContents.isEmpty())
81 m_templateContents = m_formPage->templateContents();
82 return m_templateContents;
85 // ----------------- FormFileWizardDialog
86 FormFileWizardDialog::FormFileWizardDialog(const WizardPageList &extensionPages,
88 : FormWizardDialog(extensionPages, parent),
89 m_filePage(new Utils::FileWizardPage)
91 setPage(FilePageId, m_filePage);
92 wizardProgress()->item(FilePageId)->setTitle(tr("Location"));
93 connect(m_filePage, SIGNAL(activated()),
94 button(QWizard::FinishButton), SLOT(animateClick()));
96 connect(this, SIGNAL(currentIdChanged(int)), this, SLOT(slotCurrentIdChanged(int)));
99 QString FormFileWizardDialog::path() const
101 return m_filePage->path();
104 void FormFileWizardDialog::setPath(const QString &path)
106 m_filePage->setPath(path);
109 QString FormFileWizardDialog::fileName() const
111 return m_filePage->fileName();
114 void FormFileWizardDialog::slotCurrentIdChanged(int id)
116 if (id == FilePageId) {
117 // Change from form to file: Store template and Suggest a name based on
119 QString formBaseClass;
121 if (FormTemplateWizardPage::getUIXmlData(templateContents(), &formBaseClass, &uiClassName)) {
122 QString fileName = FormTemplateWizardPage::stripNamespaces(uiClassName).toLower();
123 fileName += QLatin1String(".ui");
124 m_filePage->setFileName(fileName);
129 } // namespace Internal
130 } // namespace Designer