Commit 9bec87f1 authored by Daniel Mensinger's avatar Daniel Mensinger
Browse files

meson: Basic rewriter ui config elements

parent bdb45718
......@@ -23,6 +23,7 @@ set(mesonbuilder_SRCS
settings/mesonnewbuilddir.cpp
settings/mesonoptionbaseview.cpp
settings/mesonoptionsview.cpp
settings/mesonrewriterinput.cpp
settings/mesonrewriterpage.cpp
)
......@@ -35,6 +36,7 @@ ki18n_wrap_ui(mesonbuilder_SRCS
settings/mesonnewbuilddir.ui
settings/mesonoptionbaseview.ui
settings/mesonoptionsview.ui
settings/mesonrewriterinput.ui
settings/mesonrewriterpage.ui
)
ecm_qt_declare_logging_category(mesonbuilder_SRCS
......
......@@ -40,7 +40,7 @@ QJsonObject MesonKWARGSInfo::command()
return QStringLiteral("dependency");
}
return QStringLiteral("ERROR");
return QStringLiteral("ERROR");
};
res[QStringLiteral("type")] = QStringLiteral("kwargs");
......@@ -87,6 +87,9 @@ QJsonObject MesonKWARGSInfo::result() const
QString MesonKWARGSInfo::getString(QString kwarg) const
{
if (!m_result.contains(kwarg)) {
return QString();
}
return m_result[kwarg].toString();
}
......
/* This file is part of KDevelop
Copyright 2019 Daniel Mensinger <daniel@mensinger-ka.de>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#include "mesonrewriterinput.h"
#include "ui_mesonrewriterinput.h"
#include <KColorScheme>
#include <QLineEdit>
#include <debug.h>
MesonRewriterInputBase::MesonRewriterInputBase(QWidget* parent)
: QWidget(parent)
{
m_ui = new Ui::MesonRewriterInputBase;
m_ui->setupUi(this);
connect(this, &MesonRewriterInputBase::configChanged, this, &MesonRewriterInputBase::updateUi);
}
MesonRewriterInputBase::~MesonRewriterInputBase() {}
int MesonRewriterInputBase::nameWidth()
{
return m_ui->l_name->fontMetrics().boundingRect(m_ui->l_name->text()).width() + 25;
}
void MesonRewriterInputBase::setMinNameWidth(int width)
{
m_ui->l_name->setMinimumWidth(width);
}
void MesonRewriterInputBase::setInputWidget(QWidget* input)
{
QSizePolicy sizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
sizePolicy.setHorizontalStretch(0);
sizePolicy.setVerticalStretch(0);
sizePolicy.setHeightForWidth(input->sizePolicy().hasHeightForWidth());
input->setSizePolicy(sizePolicy);
m_ui->layout->insertWidget(1, input);
updateUi();
}
void MesonRewriterInputBase::updateUi()
{
m_ui->l_name->setText(m_name + QStringLiteral(":"));
KColorScheme scheme(QPalette::Normal);
KColorScheme::ForegroundRole role;
if (hasChanged()) {
m_ui->l_name->setStyleSheet(QStringLiteral("font-weight: bold"));
m_ui->b_reset->setDisabled(false || !m_enabled);
role = KColorScheme::NeutralText;
} else {
m_ui->l_name->setStyleSheet(QString());
m_ui->b_reset->setDisabled(true);
role = KColorScheme::NormalText;
}
role = m_enabled ? role : KColorScheme::InactiveText;
QPalette pal = m_ui->l_name->palette();
pal.setColor(QPalette::Foreground, scheme.foreground(role).color());
m_ui->l_name->setPalette(pal);
m_ui->l_name->setDisabled(!m_enabled);
inputWidget()->setDisabled(!m_enabled);
m_ui->b_add->setHidden(m_enabled);
m_ui->b_delete->setHidden(!m_enabled);
}
void MesonRewriterInputBase::reset()
{
doReset();
emit configChanged();
}
void MesonRewriterInputBase::remove()
{
m_enabled = false;
reset();
}
void MesonRewriterInputBase::add()
{
m_enabled = true;
reset();
}
void MesonRewriterInputBase::resetWidgetBase(bool enabled)
{
m_default_enabled = m_enabled = enabled;
if (m_enabled) {
add();
} else {
remove();
}
}
bool MesonRewriterInputBase::hasChanged() const
{
return hasValueChanged() || (m_default_enabled != m_enabled);
}
bool MesonRewriterInputBase::isEnabled() const
{
return m_enabled;
}
// String input class
MesonRewriterInputString::MesonRewriterInputString(QWidget* parent)
: MesonRewriterInputBase(parent)
{
m_lineEdit = new QLineEdit(this);
connect(m_lineEdit, &QLineEdit::textChanged, this, [=]() { emit configChanged(); });
setInputWidget(m_lineEdit);
}
MesonRewriterInputString::~MesonRewriterInputString() {}
MesonRewriterInputBase::Type MesonRewriterInputString::type() const
{
return STRING;
}
bool MesonRewriterInputString::hasValueChanged() const
{
return m_lineEdit->text() != m_initialValue;
}
QWidget* MesonRewriterInputString::inputWidget()
{
return m_lineEdit;
}
void MesonRewriterInputString::doReset()
{
m_lineEdit->setText(m_initialValue);
}
void MesonRewriterInputString::resetWidget(QString initialValue)
{
m_initialValue = initialValue;
resetWidgetBase(!initialValue.isNull());
}
/* This file is part of KDevelop
Copyright 2019 Daniel Mensinger <daniel@mensinger-ka.de>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#pragma once
#include <QWidget>
namespace Ui
{
class MesonRewriterInputBase;
}
class QLineEdit;
class MesonRewriterInputBase : public QWidget
{
Q_OBJECT
public:
enum Type { STRING };
Q_PROPERTY(QString name MEMBER m_name NOTIFY configChanged)
public:
explicit MesonRewriterInputBase(QWidget* parent);
virtual ~MesonRewriterInputBase();
int nameWidth();
void setMinNameWidth(int width);
bool isEnabled() const;
bool hasChanged() const;
virtual Type type() const = 0;
protected:
void setInputWidget(QWidget* input);
void resetWidgetBase(bool enabled);
virtual bool hasValueChanged() const = 0;
virtual void doReset() = 0;
virtual QWidget* inputWidget() = 0;
public Q_SLOTS:
void reset();
void remove();
void add();
void updateUi();
Q_SIGNALS:
void configChanged();
private:
Ui::MesonRewriterInputBase* m_ui = nullptr;
QString m_name;
bool m_enabled = false;
bool m_default_enabled = false;
};
class MesonRewriterInputString : public MesonRewriterInputBase
{
Q_OBJECT
public:
explicit MesonRewriterInputString(QWidget* parent);
virtual ~MesonRewriterInputString();
MesonRewriterInputBase::Type type() const override;
void resetWidget(QString initialValue);
protected:
void doReset() override;
QWidget* inputWidget() override;
bool hasValueChanged() const override;
private:
QString m_initialValue;
QLineEdit* m_lineEdit = nullptr;
};
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>MesonRewriterInputBase</class>
<widget class="QWidget" name="MesonRewriterInputBase">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>500</width>
<height>32</height>
</rect>
</property>
<layout class="QHBoxLayout" name="layout">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QLabel" name="l_name">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>50</width>
<height>0</height>
</size>
</property>
<property name="text">
<string>Name:</string>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="b_reset">
<property name="icon">
<iconset theme="document-revert">
<normaloff>../../../../../.designer/backup</normaloff>../../../../../.designer/backup</iconset>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="b_delete">
<property name="icon">
<iconset theme="edit-delete">
<normaloff>../../../../../.designer/backup</normaloff>../../../../../.designer/backup</iconset>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="b_add">
<property name="icon">
<iconset theme="list-add">
<normaloff>../../../../../.designer/backup</normaloff>../../../../../.designer/backup</iconset>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections>
<connection>
<sender>b_reset</sender>
<signal>clicked()</signal>
<receiver>MesonRewriterInputBase</receiver>
<slot>reset()</slot>
<hints>
<hint type="sourcelabel">
<x>488</x>
<y>15</y>
</hint>
<hint type="destinationlabel">
<x>271</x>
<y>15</y>
</hint>
</hints>
</connection>
<connection>
<sender>b_add</sender>
<signal>clicked()</signal>
<receiver>MesonRewriterInputBase</receiver>
<slot>add()</slot>
<hints>
<hint type="sourcelabel">
<x>526</x>
<y>15</y>
</hint>
<hint type="destinationlabel">
<x>271</x>
<y>15</y>
</hint>
</hints>
</connection>
<connection>
<sender>b_delete</sender>
<signal>clicked()</signal>
<receiver>MesonRewriterInputBase</receiver>
<slot>remove()</slot>
<hints>
<hint type="sourcelabel">
<x>488</x>
<y>15</y>
</hint>
<hint type="destinationlabel">
<x>271</x>
<y>15</y>
</hint>
</hints>
</connection>
</connections>
<slots>
<slot>reset()</slot>
<slot>remove()</slot>
<slot>add()</slot>
</slots>
</ui>
......@@ -33,9 +33,11 @@
#include <KColorScheme>
#include <QIcon>
#include <algorithm>
#include <debug.h>
using namespace KDevelop;
using namespace std;
class JobDeleter
{
......@@ -64,6 +66,19 @@ MesonRewriterPage::MesonRewriterPage(IPlugin* plugin, IProject* project, QWidget
m_ui = new Ui::MesonRewriterPage;
m_ui->setupUi(this);
int maxWidth = 50;
m_projectKwargs = { m_ui->w_version, m_ui->w_license, m_ui->w_mesonVersion };
for (auto* i : m_projectKwargs) {
maxWidth = std::max(maxWidth, i->nameWidth());
}
for (auto* i : m_projectKwargs) {
i->setMinNameWidth(maxWidth);
connect(i, &MesonRewriterInputBase::configChanged, this, &MesonRewriterPage::emitChanged);
}
m_ui->l_dispProject->setMinimumWidth(maxWidth);
reset();
}
......@@ -121,7 +136,8 @@ void MesonRewriterPage::checkStatus()
KColorScheme scheme(QPalette::Normal);
KColorScheme::ForegroundRole role;
int numChanged = 0;
// TODO compute num of changes here
numChanged += count_if(begin(m_projectKwargs), end(m_projectKwargs), [](auto* x) { return x->hasChanged(); });
if (numChanged == 0) {
role = KColorScheme::NormalText;
......@@ -187,9 +203,9 @@ void MesonRewriterPage::reset()
m_ui->l_project->setText(QStringLiteral("<html><head/><body><h3>") + prInfo->name()
+ QStringLiteral("</h3></body></html>"));
m_ui->l_version->setText(projectInfo->version());
m_ui->l_license->setText(projectInfo->license());
m_ui->l_mversion->setText(projectInfo->mesonVersion());
m_ui->w_version->resetWidget(projectInfo->version());
m_ui->w_license->resetWidget(projectInfo->license());
m_ui->w_mesonVersion->resetWidget(projectInfo->mesonVersion());
setStatus(READY);
return;
......
......@@ -21,6 +21,7 @@
#include <interfaces/configpage.h>
#include <QAbstractButton>
#include <vector>
namespace KDevelop
{
......@@ -33,6 +34,8 @@ namespace Ui
class MesonRewriterPage;
}
class MesonRewriterInputBase;
class MesonRewriterPage : public KDevelop::ConfigPage
{
Q_OBJECT
......@@ -63,4 +66,6 @@ private:
Ui::MesonRewriterPage* m_ui = nullptr;
bool m_configChanged = false;
State m_state = START;
std::vector<MesonRewriterInputBase *> m_projectKwargs;
};
......@@ -26,39 +26,65 @@
<attribute name="toolTip">
<string>Project settings</string>
</attribute>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="1">
<widget class="QLabel" name="l_project">
<property name="text">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;h3&gt;projectName&lt;/h3&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
</widget>
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<widget class="QLabel" name="l_dispProject">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>150</width>
<height>0</height>
</size>
</property>
<property name="text">
<string>Name:</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="l_project">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;h3&gt;projectName&lt;/h3&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
</widget>
</item>
</layout>
</item>
<item row="2" column="0">
<widget class="QLabel" name="l_dispLicense">
<property name="text">
<string>License:</string>
<item>
<widget class="MesonRewriterInputString" name="w_version" native="true">
<property name="name" stdset="0">
<string>Version</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="l_dispVersion">
<property name="text">
<string>Project version:</string>
<item>
<widget class="MesonRewriterInputString" name="w_license" native="true">
<property name="name" stdset="0">
<string>License</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLabel" name="l_version">
<property name="text">
<string>version</string>
</property>
<property name="textFormat">
<enum>Qt::RichText</enum>
<item>
<widget class="MesonRewriterInputString" name="w_mesonVersion" native="true">
<property name="name" stdset="0">
<string>Meson version</string>
</property>
</widget>
</item>
<item row="4" column="0" colspan="2">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QListWidget" name="listWidget"/>
......@@ -71,7 +97,8 @@
<string>+</string>
</property>
<property name="icon">
<iconset theme="list-add"/>
<iconset theme="list-add">
<normaloff>../../../../../.designer/backup</normaloff>../../../../../.designer/backup</iconset>
</property>
</widget>
</item>
......@@ -81,7 +108,8 @@
<string>-</string>
</property>
<property name="icon">
<iconset theme="list-remove"/>
<iconset theme="list-remove">
<normaloff>../../../../../.designer/backup</normaloff>../../../../../.designer/backup</iconset>
</property>
</widget>
</item>
......@@ -102,34 +130,6 @@
</item>
</layout>
</item>
<item row="0" column="0">
<widget class="QLabel" name="l_dispProject">
<property name="text">