2022-08-19 15:59:36 +02:00
|
|
|
// Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0+ OR GPL-3.0 WITH Qt-GPL-exception-1.0
|
2009-06-29 14:47:04 +02:00
|
|
|
|
|
|
|
|
#include "classdefinition.h"
|
|
|
|
|
|
2022-08-12 14:36:45 +02:00
|
|
|
#include <utils/layoutbuilder.h>
|
|
|
|
|
#include <utils/pathchooser.h>
|
|
|
|
|
|
|
|
|
|
#include <QCheckBox>
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QFileInfo>
|
2022-08-12 14:36:45 +02:00
|
|
|
#include <QLabel>
|
|
|
|
|
#include <QLineEdit>
|
|
|
|
|
#include <QRadioButton>
|
|
|
|
|
#include <QTextEdit>
|
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)
|
|
|
|
|
{
|
2022-08-12 14:36:45 +02:00
|
|
|
using namespace Utils::Layouting;
|
|
|
|
|
|
|
|
|
|
// "Sources" tab
|
|
|
|
|
auto sourceTab = new QWidget;
|
|
|
|
|
m_libraryRadio = new QRadioButton(tr("&Link library"));
|
|
|
|
|
auto includeRadio = new QRadioButton(tr("Include pro&ject"));
|
|
|
|
|
includeRadio->setChecked(true);
|
|
|
|
|
m_skeletonCheck = new QCheckBox(tr("Create s&keleton"));
|
|
|
|
|
m_widgetLibraryLabel = new QLabel(tr("Widget librar&y:"));
|
|
|
|
|
m_widgetLibraryEdit = new QLineEdit;
|
|
|
|
|
m_widgetProjectLabel = new QLabel(tr("Widget project &file:"));
|
|
|
|
|
m_widgetProjectEdit = new QLineEdit;
|
|
|
|
|
m_widgetHeaderEdit = new QLineEdit;
|
|
|
|
|
m_widgetSourceLabel = new QLabel(tr("Widge&t source file:"));
|
|
|
|
|
m_widgetSourceEdit = new QLineEdit;
|
|
|
|
|
m_widgetBaseClassLabel = new QLabel(tr("Widget &base class:"));
|
|
|
|
|
m_widgetBaseClassEdit = new QLineEdit("QWidget");
|
|
|
|
|
m_pluginClassEdit = new QLineEdit;
|
|
|
|
|
m_pluginHeaderEdit = new QLineEdit;
|
|
|
|
|
m_pluginSourceEdit = new QLineEdit;
|
|
|
|
|
m_iconPathChooser = new Utils::PathChooser;
|
|
|
|
|
m_iconPathChooser->setExpectedKind(Utils::PathChooser::File);
|
|
|
|
|
m_iconPathChooser->setHistoryCompleter(QLatin1String("Qmake.Icon.History"));
|
|
|
|
|
m_iconPathChooser->setPromptDialogTitle(tr("Select Icon"));
|
|
|
|
|
m_iconPathChooser->setPromptDialogFilter(tr("Icon files (*.png *.ico *.jpg *.xpm *.tif *.svg)"));
|
|
|
|
|
Form {
|
|
|
|
|
empty, Row { Column { m_libraryRadio, includeRadio }, m_skeletonCheck}, br,
|
|
|
|
|
m_widgetLibraryLabel, m_widgetLibraryEdit, br,
|
|
|
|
|
m_widgetProjectLabel, m_widgetProjectEdit, br,
|
|
|
|
|
tr("Widget h&eader file:"), m_widgetHeaderEdit, br,
|
|
|
|
|
m_widgetSourceLabel, m_widgetSourceEdit, br,
|
|
|
|
|
m_widgetBaseClassLabel, m_widgetBaseClassEdit, br,
|
|
|
|
|
tr("Plugin class &name:"), m_pluginClassEdit, br,
|
|
|
|
|
tr("Plugin &header file:"), m_pluginHeaderEdit, br,
|
|
|
|
|
tr("Plugin sou&rce file:"), m_pluginSourceEdit, br,
|
|
|
|
|
tr("Icon file:"), m_iconPathChooser, br,
|
|
|
|
|
}.attachTo(sourceTab);
|
|
|
|
|
addTab(sourceTab, tr("&Sources"));
|
|
|
|
|
|
|
|
|
|
// "Description" tab
|
|
|
|
|
auto descriptionTab = new QWidget;
|
|
|
|
|
m_groupEdit = new QLineEdit;
|
|
|
|
|
m_tooltipEdit = new QLineEdit;
|
|
|
|
|
m_whatsthisEdit = new QTextEdit;
|
|
|
|
|
m_containerCheck = new QCheckBox(tr("The widget is a &container"));
|
|
|
|
|
Form {
|
|
|
|
|
tr("G&roup:"), m_groupEdit, br,
|
|
|
|
|
tr("&Tooltip:"), m_tooltipEdit, br,
|
|
|
|
|
tr("W&hat's this:"), m_whatsthisEdit, br,
|
|
|
|
|
empty, m_containerCheck, br,
|
|
|
|
|
}.attachTo(descriptionTab);
|
|
|
|
|
addTab(descriptionTab, tr("&Description"));
|
|
|
|
|
|
|
|
|
|
// "Property defaults" tab
|
|
|
|
|
auto propertyDefaultsTab = new QWidget;
|
|
|
|
|
auto domXmlLabel = new QLabel(tr("dom&XML:"));
|
|
|
|
|
m_domXmlEdit = new QTextEdit;
|
|
|
|
|
domXmlLabel->setBuddy(m_domXmlEdit);
|
|
|
|
|
Column {
|
|
|
|
|
domXmlLabel,
|
|
|
|
|
m_domXmlEdit,
|
|
|
|
|
}.attachTo(propertyDefaultsTab);
|
|
|
|
|
addTab(propertyDefaultsTab, tr("Property defa&ults"));
|
|
|
|
|
|
|
|
|
|
connect(m_libraryRadio, &QRadioButton::toggled, this, &ClassDefinition::enableButtons);
|
|
|
|
|
connect(m_skeletonCheck, &QCheckBox::toggled, this, &ClassDefinition::enableButtons);
|
|
|
|
|
connect(m_widgetLibraryEdit, &QLineEdit::textChanged,
|
2020-11-17 10:49:48 +01:00
|
|
|
this, &ClassDefinition::widgetLibraryChanged);
|
2022-08-12 14:36:45 +02:00
|
|
|
connect(m_widgetHeaderEdit, &QLineEdit::textChanged,
|
2020-11-17 10:49:48 +01:00
|
|
|
this, &ClassDefinition::widgetHeaderChanged);
|
2022-08-12 14:36:45 +02:00
|
|
|
connect(m_pluginClassEdit, &QLineEdit::textChanged,
|
2020-11-17 10:49:48 +01:00
|
|
|
this, &ClassDefinition::pluginClassChanged);
|
2022-08-12 14:36:45 +02:00
|
|
|
connect(m_pluginHeaderEdit, &QLineEdit::textChanged,
|
2020-11-17 10:49:48 +01:00
|
|
|
this, &ClassDefinition::pluginHeaderChanged);
|
2022-08-12 14:36:45 +02:00
|
|
|
connect(m_domXmlEdit, &QTextEdit::textChanged,
|
2020-11-17 10:49:48 +01:00
|
|
|
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
|
|
|
{
|
2022-08-12 14:36:45 +02:00
|
|
|
const bool enLib = m_libraryRadio->isChecked();
|
|
|
|
|
m_widgetLibraryLabel->setEnabled(enLib);
|
|
|
|
|
m_widgetLibraryEdit->setEnabled(enLib);
|
2009-06-29 14:47:04 +02:00
|
|
|
|
2022-08-12 14:36:45 +02:00
|
|
|
const bool enSrc = m_skeletonCheck->isChecked();
|
|
|
|
|
m_widgetSourceLabel->setEnabled(enSrc);
|
|
|
|
|
m_widgetSourceEdit->setEnabled(enSrc);
|
|
|
|
|
m_widgetBaseClassLabel->setEnabled(enSrc);
|
|
|
|
|
m_widgetBaseClassEdit->setEnabled(enSrc);
|
2009-06-29 14:47:04 +02:00
|
|
|
|
|
|
|
|
const bool enPrj = !enLib || enSrc;
|
2022-08-12 14:36:45 +02:00
|
|
|
m_widgetProjectLabel->setEnabled(enPrj);
|
|
|
|
|
m_widgetProjectEdit->setEnabled(enPrj);
|
|
|
|
|
m_widgetProjectEdit->setText(
|
|
|
|
|
QFileInfo(m_widgetProjectEdit->text()).completeBaseName() +
|
|
|
|
|
(m_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)
|
|
|
|
|
{
|
2022-08-12 14:36:45 +02:00
|
|
|
m_widgetLibraryEdit->setText(name.toLower());
|
|
|
|
|
m_widgetHeaderEdit->setText(m_fileNamingParameters.headerFileName(name));
|
|
|
|
|
m_pluginClassEdit->setText(name + QLatin1String("Plugin"));
|
2009-06-29 14:47:04 +02:00
|
|
|
if (!m_domXmlChanged) {
|
2022-08-12 14:36:45 +02:00
|
|
|
m_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
|
|
|
{
|
2022-08-12 14:36:45 +02:00
|
|
|
m_widgetProjectEdit->setText(text +
|
|
|
|
|
(m_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
|
|
|
{
|
2022-08-12 14:36:45 +02:00
|
|
|
m_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
|
|
|
{
|
2022-08-12 14:36:45 +02:00
|
|
|
m_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
|
|
|
{
|
2022-08-12 14:36:45 +02:00
|
|
|
m_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;
|
2022-08-12 14:36:45 +02:00
|
|
|
wo.createSkeleton = m_skeletonCheck->isChecked();
|
2009-06-29 14:47:04 +02:00
|
|
|
wo.sourceType =
|
2022-08-12 14:36:45 +02:00
|
|
|
m_libraryRadio->isChecked() ?
|
2009-06-29 14:47:04 +02:00
|
|
|
PluginOptions::WidgetOptions::LinkLibrary :
|
|
|
|
|
PluginOptions::WidgetOptions::IncludeProject;
|
2022-08-12 14:36:45 +02:00
|
|
|
wo.widgetLibrary = m_widgetLibraryEdit->text();
|
|
|
|
|
wo.widgetProjectFile = m_widgetProjectEdit->text();
|
2009-06-29 14:47:04 +02:00
|
|
|
wo.widgetClassName = className;
|
2022-08-12 14:36:45 +02:00
|
|
|
wo.widgetHeaderFile = m_widgetHeaderEdit->text();
|
|
|
|
|
wo.widgetSourceFile = m_widgetSourceEdit->text();
|
|
|
|
|
wo.widgetBaseClassName = m_widgetBaseClassEdit->text();
|
|
|
|
|
wo.pluginClassName = m_pluginClassEdit->text();
|
|
|
|
|
wo.pluginHeaderFile = m_pluginHeaderEdit->text();
|
|
|
|
|
wo.pluginSourceFile = m_pluginSourceEdit->text();
|
|
|
|
|
wo.iconFile = m_iconPathChooser->filePath().toString();
|
|
|
|
|
wo.group = m_groupEdit->text();
|
|
|
|
|
wo.toolTip = m_tooltipEdit->text();
|
|
|
|
|
wo.whatsThis = m_whatsthisEdit->toPlainText();
|
|
|
|
|
wo.isContainer = m_containerCheck->isChecked();
|
|
|
|
|
wo.domXml = m_domXmlEdit->toPlainText();
|
2009-06-29 14:47:04 +02:00
|
|
|
return wo;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|