OSDN Git Service

It's 2011 now.
[qt-creator-jp/qt-creator-jp.git] / src / plugins / qt4projectmanager / wizards / modulespage.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 "modulespage.h"
35
36 #include "qtmodulesinfo.h"
37
38 #include <utils/qtcassert.h>
39
40 #include <QtCore/QDebug>
41 #include <QtCore/QVariant>
42
43 #include <QtGui/QCheckBox>
44 #include <QtGui/QLabel>
45 #include <QtGui/QLayout>
46 #include <QtGui/QWidget>
47
48 #include <math.h>
49
50 using namespace Qt4ProjectManager::Internal;
51
52 ModulesPage::ModulesPage(QWidget *parent)
53     : QWizardPage(parent)
54 {
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);
59
60     QVBoxLayout *vlayout = new QVBoxLayout();
61     vlayout->addWidget(label);
62     vlayout->addItem(new QSpacerItem(0, 20));
63
64     QGridLayout *layout = new QGridLayout;
65
66     const QStringList &modulesList = QtModulesInfo::modules();
67     int moduleId = 0;
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;
78         moduleId++;
79     }
80
81     vlayout->addLayout(layout);
82     setLayout(vlayout);
83 }
84
85 // Return the key that goes into the Qt config line for a module
86 QString ModulesPage::idOfModule(const QString &module)
87 {
88     const QStringList &moduleIdList = QtModulesInfo::modules();
89     foreach (const QString &id, moduleIdList)
90         if (QtModulesInfo::moduleName(id).startsWith(module))
91             return id;
92     return QString();
93 }
94
95 QString ModulesPage::selectedModules() const
96 {
97     return modules(true);
98 }
99
100 QString ModulesPage::deselectedModules() const
101 {
102     return modules(false);
103 }
104
105 void ModulesPage::setModuleSelected(const QString &module, bool selected) const
106 {
107     QCheckBox *checkBox = m_moduleCheckBoxMap[module];
108     Q_ASSERT(checkBox);
109     checkBox->setCheckState(selected?Qt::Checked:Qt::Unchecked);
110 }
111
112 void ModulesPage::setModuleEnabled(const QString &module, bool enabled) const
113 {
114     QCheckBox *checkBox = m_moduleCheckBoxMap[module];
115     Q_ASSERT(checkBox);
116     checkBox->setEnabled(enabled);
117 }
118
119 QString ModulesPage::modules(bool selected) const
120 {
121     QStringList modules;
122     foreach (const QString &module, QtModulesInfo::modules()) {
123         if (selected != QtModulesInfo::moduleIsDefault(module)
124             && selected == field(module).toBool())
125             modules << module;
126     }
127     return modules.join(QString(QLatin1Char(' ')));
128 }