2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2009-06-29 14:47:04 +02:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
2009-06-29 14:47:04 +02:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** This file is part of Qt Creator.
|
2009-06-29 14:47:04 +02:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** Commercial License Usage
|
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
2016-01-15 14:57:40 +01:00
|
|
|
** a written agreement between you and The Qt Company. For licensing terms
|
|
|
|
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
|
|
|
** information use the contact form at https://www.qt.io/contact-us.
|
2009-06-29 14:47:04 +02:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** GNU General Public License Usage
|
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU
|
|
|
|
|
** General Public License version 3 as published by the Free Software
|
|
|
|
|
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
|
|
|
|
** included in the packaging of this file. Please review the following
|
|
|
|
|
** information to ensure the GNU General Public License requirements will
|
|
|
|
|
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
2010-12-17 16:01:08 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
****************************************************************************/
|
2009-06-29 14:47:04 +02:00
|
|
|
|
|
|
|
|
#include "classdefinition.h"
|
|
|
|
|
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QFileInfo>
|
2009-06-29 14:47:04 +02:00
|
|
|
|
2013-10-16 11:02:37 +02:00
|
|
|
namespace QmakeProjectManager {
|
2009-06-29 14:47:04 +02:00
|
|
|
namespace Internal {
|
|
|
|
|
|
|
|
|
|
ClassDefinition::ClassDefinition(QWidget *parent) :
|
|
|
|
|
QTabWidget(parent),
|
|
|
|
|
m_domXmlChanged(false)
|
|
|
|
|
{
|
2010-04-13 16:13:06 +02:00
|
|
|
m_ui.setupUi(this);
|
|
|
|
|
m_ui.iconPathChooser->setExpectedKind(Utils::PathChooser::File);
|
2013-11-25 14:36:18 +01:00
|
|
|
m_ui.iconPathChooser->setHistoryCompleter(QLatin1String("Qmake.Icon.History"));
|
2010-04-13 16:13:06 +02:00
|
|
|
m_ui.iconPathChooser->setPromptDialogTitle(tr("Select Icon"));
|
|
|
|
|
m_ui.iconPathChooser->setPromptDialogFilter(tr("Icon files (*.png *.ico *.jpg *.xpm *.tif *.svg)"));
|
|
|
|
|
|
2020-11-17 10:49:48 +01:00
|
|
|
connect(m_ui.libraryRadio, &QRadioButton::toggled, this, &ClassDefinition::enableButtons);
|
|
|
|
|
connect(m_ui.skeletonCheck, &QCheckBox::toggled, this, &ClassDefinition::enableButtons);
|
|
|
|
|
connect(m_ui.widgetLibraryEdit, &QLineEdit::textChanged,
|
|
|
|
|
this, &ClassDefinition::widgetLibraryChanged);
|
|
|
|
|
connect(m_ui.widgetHeaderEdit, &QLineEdit::textChanged,
|
|
|
|
|
this, &ClassDefinition::widgetHeaderChanged);
|
|
|
|
|
connect(m_ui.pluginClassEdit, &QLineEdit::textChanged,
|
|
|
|
|
this, &ClassDefinition::pluginClassChanged);
|
|
|
|
|
connect(m_ui.pluginHeaderEdit, &QLineEdit::textChanged,
|
|
|
|
|
this, &ClassDefinition::pluginHeaderChanged);
|
|
|
|
|
connect(m_ui.domXmlEdit, &QTextEdit::textChanged,
|
|
|
|
|
this, [this] { m_domXmlChanged = true; });
|
2009-06-29 14:47:04 +02:00
|
|
|
}
|
|
|
|
|
|
2020-11-17 10:49:48 +01:00
|
|
|
void ClassDefinition::enableButtons()
|
2009-06-29 14:47:04 +02:00
|
|
|
{
|
2010-04-13 16:13:06 +02:00
|
|
|
const bool enLib = m_ui.libraryRadio->isChecked();
|
|
|
|
|
m_ui.widgetLibraryLabel->setEnabled(enLib);
|
|
|
|
|
m_ui.widgetLibraryEdit->setEnabled(enLib);
|
2009-06-29 14:47:04 +02:00
|
|
|
|
2010-04-13 16:13:06 +02:00
|
|
|
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);
|
2009-06-29 14:47:04 +02:00
|
|
|
|
|
|
|
|
const bool enPrj = !enLib || enSrc;
|
2010-04-13 16:13:06 +02:00
|
|
|
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")));
|
2009-06-29 14:47:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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)
|
2020-09-18 13:15:18 +02:00
|
|
|
rc += name.mid(1);
|
2009-06-29 14:47:04 +02:00
|
|
|
}
|
|
|
|
|
rc += QLatin1String("\">\n</widget>\n");
|
|
|
|
|
return rc;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ClassDefinition::setClassName(const QString &name)
|
|
|
|
|
{
|
2010-04-13 16:13:06 +02:00
|
|
|
m_ui.widgetLibraryEdit->setText(name.toLower());
|
|
|
|
|
m_ui.widgetHeaderEdit->setText(m_fileNamingParameters.headerFileName(name));
|
|
|
|
|
m_ui.pluginClassEdit->setText(name + QLatin1String("Plugin"));
|
2009-06-29 14:47:04 +02:00
|
|
|
if (!m_domXmlChanged) {
|
2010-04-13 16:13:06 +02:00
|
|
|
m_ui.domXmlEdit->setText(xmlFromClassName(name));
|
2009-06-29 14:47:04 +02:00
|
|
|
m_domXmlChanged = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-11-17 10:49:48 +01:00
|
|
|
void ClassDefinition::widgetLibraryChanged(const QString &text)
|
2009-06-29 14:47:04 +02:00
|
|
|
{
|
2020-11-17 10:49:48 +01:00
|
|
|
m_ui.widgetProjectEdit->setText(text +
|
2010-04-13 16:13:06 +02:00
|
|
|
(m_ui.libraryRadio->isChecked() ? QLatin1String(".pro") : QLatin1String(".pri")));
|
2009-06-29 14:47:04 +02:00
|
|
|
}
|
|
|
|
|
|
2020-11-17 10:49:48 +01:00
|
|
|
void ClassDefinition::widgetHeaderChanged(const QString &text)
|
2009-06-29 14:47:04 +02:00
|
|
|
{
|
2020-11-17 10:49:48 +01:00
|
|
|
m_ui.widgetSourceEdit->setText(m_fileNamingParameters.headerToSourceFileName(text));
|
2009-06-29 14:47:04 +02:00
|
|
|
}
|
|
|
|
|
|
2020-11-17 10:49:48 +01:00
|
|
|
void ClassDefinition::pluginClassChanged(const QString &text)
|
2009-06-29 14:47:04 +02:00
|
|
|
{
|
2020-11-17 10:49:48 +01:00
|
|
|
m_ui.pluginHeaderEdit->setText(m_fileNamingParameters.headerFileName(text));
|
2009-06-29 14:47:04 +02:00
|
|
|
}
|
|
|
|
|
|
2020-11-17 10:49:48 +01:00
|
|
|
void ClassDefinition::pluginHeaderChanged(const QString &text)
|
2009-06-29 14:47:04 +02:00
|
|
|
{
|
2020-11-17 10:49:48 +01:00
|
|
|
m_ui.pluginSourceEdit->setText(m_fileNamingParameters.headerToSourceFileName(text));
|
2009-06-29 14:47:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
PluginOptions::WidgetOptions ClassDefinition::widgetOptions(const QString &className) const
|
|
|
|
|
{
|
|
|
|
|
PluginOptions::WidgetOptions wo;
|
2010-04-13 16:13:06 +02:00
|
|
|
wo.createSkeleton = m_ui.skeletonCheck->isChecked();
|
2009-06-29 14:47:04 +02:00
|
|
|
wo.sourceType =
|
2010-04-13 16:13:06 +02:00
|
|
|
m_ui.libraryRadio->isChecked() ?
|
2009-06-29 14:47:04 +02:00
|
|
|
PluginOptions::WidgetOptions::LinkLibrary :
|
|
|
|
|
PluginOptions::WidgetOptions::IncludeProject;
|
2010-04-13 16:13:06 +02:00
|
|
|
wo.widgetLibrary = m_ui.widgetLibraryEdit->text();
|
|
|
|
|
wo.widgetProjectFile = m_ui.widgetProjectEdit->text();
|
2009-06-29 14:47:04 +02:00
|
|
|
wo.widgetClassName = className;
|
2010-04-13 16:13:06 +02:00
|
|
|
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();
|
2020-04-09 11:35:12 +02:00
|
|
|
wo.iconFile = m_ui.iconPathChooser->filePath().toString();
|
2010-04-13 16:13:06 +02:00
|
|
|
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();
|
2009-06-29 14:47:04 +02:00
|
|
|
return wo;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|