1 /**************************************************************************
3 ** This file is part of Qt Creator
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
7 ** Contact: Nokia Corporation (qt-info@nokia.com)
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
16 ** GNU Lesser General Public License Usage
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.
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.
29 ** If you have questions regarding the use of this file, please contact
30 ** Nokia at qt-info@nokia.com.
32 **************************************************************************/
34 #include "modulespage.h"
36 #include "qtmodulesinfo.h"
38 #include <utils/qtcassert.h>
40 #include <QtCore/QDebug>
41 #include <QtCore/QVariant>
43 #include <QtGui/QCheckBox>
44 #include <QtGui/QLabel>
45 #include <QtGui/QLayout>
46 #include <QtGui/QWidget>
50 using namespace Qt4ProjectManager::Internal;
52 ModulesPage::ModulesPage(QWidget *parent)
55 setTitle(tr("Select Required Modules"));
56 QLabel *label = new QLabel(tr("Select the modules you want to include in your "
57 "project. The recommended modules for this project are selected by default."));
58 label->setWordWrap(true);
60 QVBoxLayout *vlayout = new QVBoxLayout();
61 vlayout->addWidget(label);
62 vlayout->addItem(new QSpacerItem(0, 20));
64 QGridLayout *layout = new QGridLayout;
66 const QStringList &modulesList = QtModulesInfo::modules();
68 int rowsCount = (modulesList.count() + 1) / 2;
69 foreach (const QString &module, modulesList) {
70 QCheckBox *moduleCheckBox = new QCheckBox(QtModulesInfo::moduleName(module));
71 moduleCheckBox->setToolTip(QtModulesInfo::moduleDescription(module));
72 moduleCheckBox->setWhatsThis(QtModulesInfo::moduleDescription(module));
73 registerField(module, moduleCheckBox);
74 int row = moduleId % rowsCount;
75 int column = moduleId / rowsCount;
76 layout->addWidget(moduleCheckBox, row, column);
77 m_moduleCheckBoxMap[module] = moduleCheckBox;
81 vlayout->addLayout(layout);
85 // Return the key that goes into the Qt config line for a module
86 QString ModulesPage::idOfModule(const QString &module)
88 const QStringList &moduleIdList = QtModulesInfo::modules();
89 foreach (const QString &id, moduleIdList)
90 if (QtModulesInfo::moduleName(id).startsWith(module))
95 QString ModulesPage::selectedModules() const
100 QString ModulesPage::deselectedModules() const
102 return modules(false);
105 void ModulesPage::setModuleSelected(const QString &module, bool selected) const
107 QCheckBox *checkBox = m_moduleCheckBoxMap[module];
109 checkBox->setCheckState(selected?Qt::Checked:Qt::Unchecked);
112 void ModulesPage::setModuleEnabled(const QString &module, bool enabled) const
114 QCheckBox *checkBox = m_moduleCheckBoxMap[module];
116 checkBox->setEnabled(enabled);
119 QString ModulesPage::modules(bool selected) const
122 foreach (const QString &module, QtModulesInfo::modules()) {
123 if (selected != QtModulesInfo::moduleIsDefault(module)
124 && selected == field(module).toBool())
127 return modules.join(QString(QLatin1Char(' ')));