classdefinition.cpp 5.46 KB
Newer Older
1
2
3
4
/**************************************************************************
**
** This file is part of Qt Creator
**
con's avatar
con committed
5
** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
6
7
8
**
** Contact: Nokia Corporation (qt-info@nokia.com)
**
con's avatar
con committed
9
** No Commercial Usage
10
**
con's avatar
con committed
11
12
13
14
** This file contains pre-release code and may not be distributed.
** You may use this file in accordance with the terms and conditions
** contained in the Technology Preview License Agreement accompanying
** this package.
15
16
17
18
19
20
21
22
23
24
**
** GNU Lesser General Public License Usage
**
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file.  Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
con's avatar
con committed
25
26
27
28
29
30
** In addition, as a special exception, Nokia gives you certain additional
** rights.  These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** If you have questions regarding the use of this file, please contact
** Nokia at qt-info@nokia.com.
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
**
**************************************************************************/

#include "classdefinition.h"

#include <QtCore/QFileInfo>
#include <QtGui/QFileDialog>

namespace Qt4ProjectManager {
namespace Internal {

ClassDefinition::ClassDefinition(QWidget *parent) :
    QTabWidget(parent),
    m_domXmlChanged(false)
{
46
47
48
49
50
51
52
53
54
    m_ui.setupUi(this);
    m_ui.iconPathChooser->setExpectedKind(Utils::PathChooser::File);
    m_ui.iconPathChooser->setPromptDialogTitle(tr("Select Icon"));
    m_ui.iconPathChooser->setPromptDialogFilter(tr("Icon files (*.png *.ico *.jpg *.xpm *.tif *.svg)"));
}

void ClassDefinition::enableButtons()
{
    on_libraryRadio_toggled();
55
56
57
58
}

void ClassDefinition::on_libraryRadio_toggled()
{
59
60
61
    const bool enLib = m_ui.libraryRadio->isChecked();
    m_ui.widgetLibraryLabel->setEnabled(enLib);
    m_ui.widgetLibraryEdit->setEnabled(enLib);
62

63
64
65
66
67
    const bool enSrc = m_ui.skeletonCheck->isChecked();
    m_ui.widgetSourceLabel->setEnabled(enSrc);
    m_ui.widgetSourceEdit->setEnabled(enSrc);
    m_ui.widgetBaseClassLabel->setEnabled(enSrc);
    m_ui.widgetBaseClassEdit->setEnabled(enSrc);
68
69

    const bool enPrj = !enLib || enSrc;
70
71
72
73
74
    m_ui.widgetProjectLabel->setEnabled(enPrj);
    m_ui.widgetProjectEdit->setEnabled(enPrj);
    m_ui.widgetProjectEdit->setText(
        QFileInfo(m_ui.widgetProjectEdit->text()).completeBaseName() +
        (m_ui.libraryRadio->isChecked() ? QLatin1String(".pro") : QLatin1String(".pri")));
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
}

void ClassDefinition::on_skeletonCheck_toggled()
{
    on_libraryRadio_toggled();
}

static inline QString xmlFromClassName(const QString &name)
{
    QString rc = QLatin1String("<widget class=\"");
    rc += name;
    rc += QLatin1String("\" name=\"");
    if (!name.isEmpty()) {
        rc += name.left(1).toLower();
        if (name.size() > 1)
            rc += name.mid(1);
    }
    rc += QLatin1String("\">\n</widget>\n");
    return rc;
}

void ClassDefinition::setClassName(const QString &name)
{
98
99
100
    m_ui.widgetLibraryEdit->setText(name.toLower());
    m_ui.widgetHeaderEdit->setText(m_fileNamingParameters.headerFileName(name));
    m_ui.pluginClassEdit->setText(name + QLatin1String("Plugin"));
101
    if (!m_domXmlChanged) {
102
        m_ui.domXmlEdit->setText(xmlFromClassName(name));
103
104
105
106
107
108
        m_domXmlChanged = false;
    }
}

void ClassDefinition::on_widgetLibraryEdit_textChanged()
{
109
110
111
    m_ui.widgetProjectEdit->setText(
        m_ui.widgetLibraryEdit->text() +
        (m_ui.libraryRadio->isChecked() ? QLatin1String(".pro") : QLatin1String(".pri")));
112
113
114
115
}

void ClassDefinition::on_widgetHeaderEdit_textChanged()
{
116
    m_ui.widgetSourceEdit->setText(m_fileNamingParameters.headerToSourceFileName(m_ui.widgetHeaderEdit->text()));
117
118
119
120
}

void ClassDefinition::on_pluginClassEdit_textChanged()
{
121
    m_ui.pluginHeaderEdit->setText(m_fileNamingParameters.headerFileName(m_ui.pluginClassEdit->text()));
122
123
124
125
}

void ClassDefinition::on_pluginHeaderEdit_textChanged()
{
126
    m_ui.pluginSourceEdit->setText(m_fileNamingParameters.headerToSourceFileName(m_ui.pluginHeaderEdit->text()));
127
128
129
130
131
132
133
134
135
136
}

void ClassDefinition::on_domXmlEdit_textChanged()
{
    m_domXmlChanged = true;
}

PluginOptions::WidgetOptions ClassDefinition::widgetOptions(const QString &className) const
{
    PluginOptions::WidgetOptions wo;
137
    wo.createSkeleton = m_ui.skeletonCheck->isChecked();
138
    wo.sourceType =
139
            m_ui.libraryRadio->isChecked() ?
140
141
            PluginOptions::WidgetOptions::LinkLibrary :
            PluginOptions::WidgetOptions::IncludeProject;
142
143
    wo.widgetLibrary = m_ui.widgetLibraryEdit->text();
    wo.widgetProjectFile = m_ui.widgetProjectEdit->text();
144
    wo.widgetClassName = className;
145
146
147
148
149
150
151
152
153
154
155
156
    wo.widgetHeaderFile = m_ui.widgetHeaderEdit->text();
    wo.widgetSourceFile = m_ui.widgetSourceEdit->text();
    wo.widgetBaseClassName = m_ui.widgetBaseClassEdit->text();
    wo.pluginClassName = m_ui.pluginClassEdit->text();
    wo.pluginHeaderFile = m_ui.pluginHeaderEdit->text();
    wo.pluginSourceFile = m_ui.pluginSourceEdit->text();
    wo.iconFile = m_ui.iconPathChooser->path();
    wo.group = m_ui.groupEdit->text();
    wo.toolTip = m_ui.tooltipEdit->text();
    wo.whatsThis = m_ui.whatsthisEdit->toPlainText();
    wo.isContainer = m_ui.containerCheck->isChecked();
    wo.domXml = m_ui.domXmlEdit->toPlainText();
157
158
159
160
161
    return wo;
}

}
}