Fix curves effect

parent 99db2c63
......@@ -4,7 +4,7 @@
<name>Alpha operations</name>
<description>Display and manipulation of the alpha channel</description>
<author>Marko Cebokli</author>
<parameter type="list" name="Display" default="0.0" paramlist="0.0;0.21;0.36;0.50;0.64;0.79;1.0">
<paramlistdisplay>Image,Alpha as gray,Gray + red,Selection on black,Selection on gray,Selection on white,Selection on checkers</paramlistdisplay>
<name>Display</name>
......
......@@ -71,39 +71,39 @@
</parameter>
<!-- No actual parameter: Represents the curve widget -->
<parameter type="curve" default="0" depends="Channel" list1="6 8 10 12 14" list2="7 9 11 13 15" min="1" max="5" />
<parameter type="curve" name="kdenlive:curve" default="0/0;1/1" depends="Channel" list1="6 8 10 12 14" list2="7 9 11 13 15" min="1" max="5" />
<parameter type="fixed" name="3" default="0.2" min="0.2" max="0.5">
<parameter type="hidden" name="3" default="0.2" min="0.2" max="0.5">
<name>Number of curve points</name>
</parameter>
<parameter type="fixed" name="6" default="0" min="0" max="1">
<parameter type="hidden" name="6" default="0" min="0" max="1">
<name>Point 1 input value</name>
</parameter>
<parameter type="fixed" name="7" default="0" min="0" max="1">
<parameter type="hidden" name="7" default="0" min="0" max="1">
<name>Point 1 output value</name>
</parameter>
<parameter type="fixed" name="8" default="1" min="0" max="1">
<parameter type="hidden" name="8" default="1" min="0" max="1">
<name>Point 2 input value</name>
</parameter>
<parameter type="fixed" name="9" default="1" min="0" max="1">
<parameter type="hidden" name="9" default="1" min="0" max="1">
<name>Point 2 output value</name>
</parameter>
<parameter type="fixed" name="10" default="0" min="0" max="1">
<parameter type="hidden" name="10" default="0" min="0" max="1">
<name>Point 3 input value</name>
</parameter>
<parameter type="fixed" name="11" default="0" min="0" max="1">
<parameter type="hidden" name="11" default="0" min="0" max="1">
<name>Point 3 output value</name>
</parameter>
<parameter type="fixed" name="12" default="0" min="0" max="1">
<parameter type="hidden" name="12" default="0" min="0" max="1">
<name>Point 4 input value</name>
</parameter>
<parameter type="fixed" name="13" default="0" min="0" max="1">
<parameter type="hidden" name="13" default="0" min="0" max="1">
<name>Point 4 output value</name>
</parameter>
<parameter type="fixed" name="14" default="0" min="0" max="1">
<parameter type="hidden" name="14" default="0" min="0" max="1">
<name>Point 5 input value</name>
</parameter>
<parameter type="fixed" name="15" default="0" min="0" max="1">
<parameter type="hidden" name="15" default="0" min="0" max="1">
<name>Point 5 output value</name>
</parameter>
<parameter type="bool" name="1" default="0">
......
......@@ -30,7 +30,7 @@ set(kdenlive_SRCS
assets/view/widgets/geometryeditwidget.cpp
assets/view/widgets/positioneditwidget.cpp
assets/view/widgets/coloreditwidget.cpp
assets/view/widgets/hideparamwidget.cpp
# curves widget
assets/view/widgets/curves/abstractcurvewidget.h
assets/view/widgets/curves/bezier/beziersplineeditor.cpp
......
......@@ -48,15 +48,11 @@ AssetCommand::AssetCommand(std::shared_ptr<AssetParameterModel> model, const QMo
void AssetCommand::undo()
{
m_model->setParameter(m_name, m_oldValue, true, m_index);
// m_model->dataChanged(m_index, m_index, QVector<int>());
}
// virtual
void AssetCommand::redo()
{
m_model->setParameter(m_name, m_value, m_updateView, m_index);
/*if (m_updateView) {
m_model->dataChanged(m_index, m_index, QVector<int>());
}*/
m_updateView = true;
}
......
......@@ -176,14 +176,29 @@ void AssetParameterModel::setParameter(const QString &name, const int value, boo
}
}
void AssetParameterModel::setParameter(const QString &name, const QString &value, bool update, const QModelIndex &paramIndex)
void AssetParameterModel::setParameter(const QString &name, const QString &paramValue, bool update, const QModelIndex &paramIndex)
{
Q_ASSERT(m_asset->is_valid());
QLocale locale;
locale.setNumberOptions(QLocale::OmitGroupSeparator);
qDebug() << "// PROCESSING PARAM CHANGE: " << name << ", UPDATE: "<<update;
// TODO: this does not really belong here, but I don't see another way to do it so that undo works
if (data(paramIndex, AssetParameterModel::TypeRole).value<ParamType>() == ParamType::Curve) {
QStringList vals = paramValue.split(QLatin1Char(';'), QString::SkipEmptyParts);
int points = vals.size();
m_asset->set("3", points / 10.);
// for the curve, inpoints are numbered: 6, 8, 10, 12, 14
// outpoints, 7, 9, 11, 13,15 so we need to deduce these enums
for (int i = 0; i < points; i++) {
QString pointVal = vals.at(i);
int idx = 2 * i + 6;
m_asset->set(QString::number(idx).toLatin1().constData(), pointVal.section(QLatin1Char('/'), 0, 0).toDouble());
idx++;
m_asset->set(QString::number(idx).toLatin1().constData(), pointVal.section(QLatin1Char('/'), 1, 1).toDouble());
}
}
bool conversionSuccess;
double doubleValue = locale.toDouble(value, &conversionSuccess);
double doubleValue = locale.toDouble(paramValue, &conversionSuccess);
if (conversionSuccess) {
m_asset->set(name.toLatin1().constData(), doubleValue);
if (m_fixedParams.count(name) == 0) {
......@@ -192,12 +207,12 @@ void AssetParameterModel::setParameter(const QString &name, const QString &value
m_fixedParams[name] = doubleValue;
}
} else {
m_asset->set(name.toLatin1().constData(), value.toUtf8().constData());
qDebug() << " = = SET EFFECT PARAM: " << name << " = " << value;
m_asset->set(name.toLatin1().constData(), paramValue.toUtf8().constData());
qDebug() << " = = SET EFFECT PARAM: " << name << " = " << paramValue;
if (m_fixedParams.count(name) == 0) {
m_params[name].value = value;
m_params[name].value = paramValue;
} else {
m_fixedParams[name] = value;
m_fixedParams[name] = paramValue;
}
}
if (update) {
......@@ -346,29 +361,35 @@ QVariant AssetParameterModel::data(const QModelIndex &index, int role) const
case List2Role:
return parseAttribute(m_ownerId, QStringLiteral("list2"), element);
case Enum1Role:
return parseAttribute(m_ownerId, QStringLiteral("1"), element);
return m_asset->get_double("1");
case Enum2Role:
return parseAttribute(m_ownerId, QStringLiteral("2"), element);
return m_asset->get_double("2");
case Enum3Role:
return parseAttribute(m_ownerId, QStringLiteral("3"), element);
return m_asset->get_double("3");
case Enum4Role:
return parseAttribute(m_ownerId, QStringLiteral("4"), element);
return m_asset->get_double("4");
case Enum5Role:
return parseAttribute(m_ownerId, QStringLiteral("5"), element);
return m_asset->get_double("5");
case Enum6Role:
return parseAttribute(m_ownerId, QStringLiteral("6"), element);
return m_asset->get_double("6");
case Enum7Role:
return parseAttribute(m_ownerId, QStringLiteral("7"), element);
return m_asset->get_double("7");
case Enum8Role:
return parseAttribute(m_ownerId, QStringLiteral("8"), element);
return m_asset->get_double("8");
case Enum9Role:
return parseAttribute(m_ownerId, QStringLiteral("9"), element);
return m_asset->get_double("9");
case Enum10Role:
return parseAttribute(m_ownerId, QStringLiteral("10"), element);
return m_asset->get_double("10");
case Enum11Role:
return parseAttribute(m_ownerId, QStringLiteral("11"), element);
return m_asset->get_double("11");
case Enum12Role:
return parseAttribute(m_ownerId, QStringLiteral("12"), element);
return m_asset->get_double("12");
case Enum13Role:
return m_asset->get_double("13");
case Enum14Role:
return m_asset->get_double("14");
case Enum15Role:
return m_asset->get_double("15");
}
return QVariant();
}
......@@ -428,6 +449,8 @@ ParamType AssetParameterModel::paramTypeFromStr(const QString &type)
return ParamType::Filterjob;
} else if (type == QLatin1String("readonly")) {
return ParamType::Readonly;
} else if (type == QLatin1String("hidden")) {
return ParamType::Hidden;
}
qDebug() << "WARNING: Unknown type :" << type;
return ParamType::Double;
......
......@@ -63,7 +63,8 @@ enum class ParamType {
Keywords,
Fontfamily,
Filterjob,
Readonly
Readonly,
Hidden
};
Q_DECLARE_METATYPE(ParamType)
class AssetParameterModel : public QAbstractListModel, public enable_shared_from_this_virtual<AssetParameterModel>
......@@ -124,7 +125,7 @@ public:
/* @brief Set the parameter with given name to the given value
*/
Q_INVOKABLE void setParameter(const QString &name, const QString &value, bool update = true, const QModelIndex &paramIndex = QModelIndex());
Q_INVOKABLE void setParameter(const QString &name, const QString &paramValue, bool update = true, const QModelIndex &paramIndex = QModelIndex());
void setParameter(const QString &name, const int value, bool update = true);
Q_INVOKABLE void setParameter(const QString &name, double &value);
......
......@@ -26,6 +26,7 @@
#include "curves/cubic/kis_curve_widget.h"
#include "curves/curveparamwidget.h"
#include "doubleparamwidget.hpp"
#include "hideparamwidget.hpp"
#include "geometryeditwidget.hpp"
#include "keyframewidget.hpp"
#include "listparamwidget.h"
......@@ -120,6 +121,10 @@ AbstractParamWidget *AbstractParamWidget::construct(const std::shared_ptr<AssetP
widget = new Widget_t(model, index, parent);
break;
}
case ParamType::Hidden: {
widget = new HideParamWidget(model, index, parent);
break;
}
case ParamType::Animated:
case ParamType::RestrictedAnim:
// widget = new AnimationWidget(model, index, range, parent);
......
......@@ -37,7 +37,7 @@ AbstractCurveWidget<Curve_t>::AbstractCurveWidget(QWidget *parent)
setAutoFillBackground(false);
setAttribute(Qt::WA_OpaquePaintEvent);
setMinimumSize(150, 150);
QSizePolicy sp(QSizePolicy::Preferred, QSizePolicy::Preferred);
QSizePolicy sp(QSizePolicy::Preferred, QSizePolicy::MinimumExpanding);
sp.setHeightForWidth(true); // force widget to have a height dependent on width;
setSizePolicy(sp);
setFocusPolicy(Qt::StrongFocus);
......@@ -153,7 +153,6 @@ template <typename Curve_t> void AbstractCurveWidget<Curve_t>::setFromString(con
m_curve.fromString(str);
m_currentPointIndex = -1;
emit currentPoint(Point_t(), true);
emit modified();
update();
}
......
......@@ -402,7 +402,7 @@ void KisCubicCurve::removePoint(int idx)
d->data->invalidate();
}
QString KisCubicCurve::toString() const
const QString KisCubicCurve::toString() const
{
QString sCurve;
QLocale locale;
......
......@@ -66,7 +66,7 @@ public:
QVector<qreal> floatTransfer(int size = 256) const;
public:
QString toString() const;
const QString toString() const;
void fromString(const QString &);
private:
......
......@@ -64,7 +64,6 @@ KisCurveWidget::KisCurveWidget(QWidget *parent)
m_maxPoints = 0;
m_curve = KisCubicCurve();
update();
emit modified();
}
KisCurveWidget::~KisCurveWidget() {}
......@@ -166,7 +165,6 @@ void KisCurveWidget::mousePressEvent(QMouseEvent *e)
m_state = State_t::DRAG;
update();
emit modified();
emit currentPoint(point, isCurrentPointExtremal());
}
......
......@@ -393,19 +393,19 @@ template <typename CurveWidget_t> void CurveParamWidget<CurveWidget_t>::slotShow
template <typename CurveWidget_t> void CurveParamWidget<CurveWidget_t>::slotRefresh()
{
if (m_model->data(m_index, AssetParameterModel::TypeRole).toInt() == (int)ParamType::Curve) {
if (m_model->data(m_index, AssetParameterModel::TypeRole).value<ParamType>() == ParamType::Curve) {
QList<QPointF> points;
QLocale locale;
// Rounding gives really weird results. (int) (10 * 0.3) gives 2! So for now, add 0.5 to get correct result
int number = locale.toDouble(m_model->data(m_index, AssetParameterModel::Enum3Role).toString()) * 10 + 0.5;
int number = m_model->data(m_index, AssetParameterModel::Enum3Role).toDouble() * 10 + 0.5;
int start = m_model->data(m_index, AssetParameterModel::MinRole).toInt();
// for the curve, inpoints are numbered: 6, 8, 10, 12, 14
// outpoints, 7, 9, 11, 13,15 so we need to deduce these enums
int inRef = (int)AssetParameterModel::Enum6Role + 2 * (start - 1);
int outRef = (int)AssetParameterModel::Enum7Role + 2 * (start - 1);
for (int j = start; j <= number; ++j) {
double inVal = locale.toDouble(m_model->data(m_index, (AssetParameterModel::DataRoles)inRef).toString());
double outVal = locale.toDouble(m_model->data(m_index, (AssetParameterModel::DataRoles)outRef).toString());
double inVal = m_model->data(m_index, (AssetParameterModel::DataRoles)inRef).toDouble();
double outVal = m_model->data(m_index, (AssetParameterModel::DataRoles)outRef).toDouble();
points << QPointF(inVal, outVal);
inRef += 2;
outRef += 2;
......
/***************************************************************************
* Copyright (C) 2019 by Jean-Baptiste Mardelle *
* This file is part of Kdenlive. See www.kdenlive.org. *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) version 3 or any later version accepted by the *
* membership of KDE e.V. (or its successor approved by the membership *
* of KDE e.V.), which shall act as a proxy defined in Section 14 of *
* version 3 of the license. *
* *
* This program 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 General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
***************************************************************************/
#include "hideparamwidget.hpp"
#include "assets/model/assetparametermodel.hpp"
HideParamWidget::HideParamWidget(std::shared_ptr<AssetParameterModel> model, QModelIndex index, QWidget *parent)
: AbstractParamWidget(std::move(model), index, parent)
{
setFixedSize(QSize(0, 0));
setVisible(false);
}
void HideParamWidget::slotShowComment(bool show)
{
}
void HideParamWidget::slotRefresh()
{
}
/***************************************************************************
* Copyright (C) 2019 by Jean-Baptiste Mardelle *
* This file is part of Kdenlive. See www.kdenlive.org. *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) version 3 or any later version accepted by the *
* membership of KDE e.V. (or its successor approved by the membership *
* of KDE e.V.), which shall act as a proxy defined in Section 14 of *
* version 3 of the license. *
* *
* This program 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 General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
***************************************************************************/
#ifndef HIDEPARAMWIDGET_H
#define HIDEPARAMWIDGET_H
#include "abstractparamwidget.hpp"
#include <QWidget>
/** @brief This class represents a parameter that requires
no display
*/
class HideParamWidget : public AbstractParamWidget
{
Q_OBJECT
public:
/** @brief Constructor for the widgetComment
@param model The asset model
@param index The parameter model index
@param parent Parent widget
*/
HideParamWidget(std::shared_ptr<AssetParameterModel> model, QModelIndex index, QWidget *parent);
public slots:
/** @brief Toggle the comments on or off
*/
void slotShowComment(bool show) override;
/** @brief refresh the properties to reflect changes in the model
*/
void slotRefresh() override;
};
#endif
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment