Add logic to support odd only numbers in params. Fixes avfilter.unsharp

parent e852812f
Pipeline #10116 passed with stage
in 31 minutes and 36 seconds
......@@ -5,4 +5,5 @@ aecho.xml
agate.xml
selectivecolor.xml
avfilter_lut3d.xml
unsharp.xml
DESTINATION ${DATA_INSTALL_DIR}/kdenlive/effects)
<!DOCTYPE kpartgui>
<effect tag="avfilter.unsharp">
<name>Unsharp (avfilter)</name>
<description>Sharpen or blur your video</description>
<author>libavfilter</author>
<parameter type="constant" name="av.lx" max="23" min="3" default="5" odd="1">
<name>Luma horizontal matrix</name>
</parameter>
<parameter type="constant" name="av.ly" max="23" min="3" default="5" odd="1">
<name>Luma vertical matrix</name>
</parameter>
<parameter type="constant" name="av.la" max="1.5" min="-1.5" default="1" decimals="2">
<name>Luma strength</name>
</parameter>
<parameter type="constant" name="av.cx" max="23" min="3" default="5" odd="1">
<name>Chroma horizontal matrix</name>
</parameter>
<parameter type="constant" name="av.cy" max="23" min="3" default="5" odd="1">
<name>Chroma vertical matrix</name>
</parameter>
<parameter type="constant" name="av.ca" max="1.5" min="-1.5" default="0" decimals="2">
<name>Chroma strength</name>
</parameter>
</effect>
......@@ -339,6 +339,8 @@ QVariant AssetParameterModel::data(const QModelIndex &index, int role) const
return parseAttribute(m_ownerId, QStringLiteral("scale"), element, 0);
case DecimalsRole:
return parseAttribute(m_ownerId, QStringLiteral("decimals"), element);
case OddRole:
return element.attribute(QStringLiteral("odd")) == QLatin1String("1");
case DefaultRole:
return parseAttribute(m_ownerId, QStringLiteral("default"), element);
case FilterRole:
......
......@@ -84,6 +84,7 @@ public:
DefaultRole,
SuffixRole,
DecimalsRole,
OddRole,
ValueRole,
AlphaRole,
ListValuesRole,
......
......@@ -791,7 +791,7 @@ void AnimationWidget::buildSliderWidget(const QString &paramTag, QModelIndex ix)
DoubleWidget *doubleparam = new DoubleWidget(
paramName, 0, m_model->data(ix, AssetParameterModel::MinRole).toDouble(), m_model->data(ix, AssetParameterModel::MaxRole).toDouble(),
m_model->data(ix, AssetParameterModel::FactorRole).toDouble() m_model->data(ix, AssetParameterModel::DefaultRole).toDouble(), comment, index,
m_model->data(ix, AssetParameterModel::SuffixRole).toString(), m_model->data(ix, AssetParameterModel::DecimalsRole).toInt(), this);
m_model->data(ix, AssetParameterModel::SuffixRole).toString(), m_model->data(ix, AssetParameterModel::DecimalsRole).toInt(), m_model->data(ix, AssetParameterModel::OddRole).toBool(), this);
doubleparam->setObjectName(paramTag);
doubleparam->setProperty("index", ix);
connect(doubleparam, &DoubleWidget::valueChanged, this, &AnimationWidget::slotAdjustKeyframeValue);
......@@ -816,16 +816,16 @@ void AnimationWidget::buildRectWidget(const QString &paramTag, QModelIndex ix)
}
auto *horLayout = new QHBoxLayout;
m_spinX = new DragValue(i18nc("x axis position", "X"), 0, 0, -99000, 99000, -1, QString(), false, this);
m_spinX = new DragValue(i18nc("x axis position", "X"), 0, 0, -99000, 99000, -1, QString(), false, false, this);
connect(m_spinX, &DragValue::valueChanged, this, &AnimationWidget::slotAdjustRectKeyframeValue);
horLayout->addWidget(m_spinX);
m_spinX->setProperty("index", ix);
m_spinY = new DragValue(i18nc("y axis position", "Y"), 0, 0, -99000, 99000, -1, QString(), false, this);
m_spinY = new DragValue(i18nc("y axis position", "Y"), 0, 0, -99000, 99000, -1, QString(), false, false, this);
connect(m_spinY, &DragValue::valueChanged, this, &AnimationWidget::slotAdjustRectKeyframeValue);
horLayout->addWidget(m_spinY);
m_spinWidth = new DragValue(i18nc("Frame width", "W"), m_monitorSize.width(), 0, 1, 99000, -1, QString(), false, this);
m_spinWidth = new DragValue(i18nc("Frame width", "W"), m_monitorSize.width(), 0, 1, 99000, -1, QString(), false, false, this);
connect(m_spinWidth, &DragValue::valueChanged, this, &AnimationWidget::slotAdjustRectWidth);
horLayout->addWidget(m_spinWidth);
......@@ -837,18 +837,18 @@ void AnimationWidget::buildRectWidget(const QString &paramTag, QModelIndex ix)
ratioButton->setDefaultAction(m_lockRatio);
horLayout->addWidget(ratioButton);
m_spinHeight = new DragValue(i18nc("Frame height", "H"), m_monitorSize.height(), 0, 1, 99000, -1, QString(), false, this);
m_spinHeight = new DragValue(i18nc("Frame height", "H"), m_monitorSize.height(), 0, 1, 99000, -1, QString(), false, false, this);
connect(m_spinHeight, &DragValue::valueChanged, this, &AnimationWidget::slotAdjustRectHeight);
horLayout->addWidget(m_spinHeight);
horLayout->addStretch(10);
auto *horLayout2 = new QHBoxLayout;
m_spinSize = new DragValue(i18n("Size"), 100, 2, 1, 99000, -1, i18n("%"), false, this);
m_spinSize = new DragValue(i18n("Size"), 100, 2, 1, 99000, -1, i18n("%"), false, false, this);
m_spinSize->setStep(10);
connect(m_spinSize, &DragValue::valueChanged, this, &AnimationWidget::slotResize);
horLayout2->addWidget(m_spinSize);
if (m_model->data(ix, AssetParameterModel::OpacityRole).toBool()) {
m_spinOpacity = new DragValue(i18n("Opacity"), 100, 0, 0, 100, -1, i18n("%"), true, this);
m_spinOpacity = new DragValue(i18n("Opacity"), 100, 0, 0, 100, -1, i18n("%"), true, false, this);
connect(m_spinOpacity, &DragValue::valueChanged, this, &AnimationWidget::slotAdjustRectKeyframeValue);
horLayout2->addWidget(m_spinOpacity);
}
......
......@@ -46,7 +46,7 @@ DoubleParamWidget::DoubleParamWidget(std::shared_ptr<AssetParameterModel> model,
int decimals = m_model->data(m_index, AssetParameterModel::DecimalsRole).toInt();
double factor = m_model->data(m_index, AssetParameterModel::FactorRole).toDouble();
// Construct object
m_doubleWidget = new DoubleWidget(name, value, min, max, factor, defaultValue, comment, -1, suffix, decimals, this);
m_doubleWidget = new DoubleWidget(name, value, min, max, factor, defaultValue, comment, -1, suffix, decimals, m_model->data(m_index, AssetParameterModel::OddRole).toBool(), this);
m_lay->addWidget(m_doubleWidget);
setMinimumHeight(m_doubleWidget->height());
......
......@@ -129,7 +129,7 @@ void KeyframeEdit::addParameter(QModelIndex index, int activeKeyframe)
keyframe_list->insertColumn(columnId);
keyframe_list->setHorizontalHeaderItem(columnId, new QTableWidgetItem(name));
DoubleWidget *doubleparam = new DoubleWidget(name, value, min, max, m_model->data(index, AssetParameterModel::FactorRole).toDouble(), defaultValue, comment,
-1, suffix, decimals, this);
-1, suffix, decimals, m_model->data(index, AssetParameterModel::OddRole).toBool(), this);
/*DoubleParameterWidget *doubleparam = new DoubleParameterWidget(
paramName, 0, m_params.at(columnId).attribute(QStringLiteral("min")).toDouble(), m_params.at(columnId).attribute(QStringLiteral("max")).toDouble(),
......
......@@ -382,7 +382,7 @@ void KeyframeWidget::addParameter(const QPersistentModelIndex &index)
int decimals = m_model->data(index, AssetParameterModel::DecimalsRole).toInt();
double factor = locale.toDouble(m_model->data(index, AssetParameterModel::FactorRole).toString());
factor = qFuzzyIsNull(factor) ? 1 : factor;
auto doubleWidget = new DoubleWidget(name, value, min, max, factor, defaultValue, comment, -1, suffix, decimals, this);
auto doubleWidget = new DoubleWidget(name, value, min, max, factor, defaultValue, comment, -1, suffix, decimals, m_model->data(index, AssetParameterModel::OddRole).toBool(), this);
connect(doubleWidget, &DoubleWidget::valueChanged,
[this, index](double v) { m_keyframes->updateKeyframe(GenTime(getPosition(), pCore->getCurrentFps()), QVariant(v), index); });
paramWidget = doubleWidget;
......
......@@ -23,7 +23,7 @@
#include <QVBoxLayout>
DoubleWidget::DoubleWidget(const QString &name, double value, double min, double max, double factor, double defaultValue, const QString &comment, int id,
const QString &suffix, int decimals, QWidget *parent)
const QString &suffix, int decimals, bool oddOnly, QWidget *parent)
: QWidget(parent)
, m_factor(factor)
{
......@@ -32,7 +32,7 @@ DoubleWidget::DoubleWidget(const QString &name, double value, double min, double
layout->setContentsMargins(0, 0, 0, 0);
layout->setSpacing(0);
m_dragVal = new DragValue(name, defaultValue * m_factor, decimals, min, max, id, suffix, true, this);
m_dragVal = new DragValue(name, defaultValue * m_factor, decimals, min, max, id, suffix, true, oddOnly, this);
layout->addWidget(m_dragVal);
setMinimumHeight(m_dragVal->height());
......
......@@ -47,7 +47,7 @@ public:
* @param suffix (optional) Suffix to display in spinbox
* @param parent (optional) Parent Widget */
explicit DoubleWidget(const QString &name, double value, double min, double max, double factor, double defaultValue, const QString &comment, int id,
const QString &suffix = QString(), int decimals = 0, QWidget *parent = nullptr);
const QString &suffix = QString(), int decimals = 0, bool oddOnly = false, QWidget *parent = nullptr);
~DoubleWidget() override;
/** @brief Gets the parameter's value. */
......
......@@ -35,7 +35,7 @@
#include <QStyle>
#include <klocalizedstring.h>
DragValue::DragValue(const QString &label, double defaultValue, int decimals, double min, double max, int id, const QString &suffix, bool showSlider,
DragValue::DragValue(const QString &label, double defaultValue, int decimals, double min, double max, int id, const QString &suffix, bool showSlider, bool oddOnly,
QWidget *parent)
: QWidget(parent)
, m_maximum(max)
......@@ -63,7 +63,7 @@ DragValue::DragValue(const QString &label, double defaultValue, int decimals, do
setMinimumHeight(m_label->sizeHint().height());
if (decimals == 0) {
m_label->setMaximum(max - min);
m_label->setStep(1);
m_label->setStep(oddOnly ? 2 : 1);
m_intEdit = new QSpinBox(this);
m_intEdit->setObjectName(QStringLiteral("dragBox"));
m_intEdit->setFocusPolicy(Qt::StrongFocus);
......@@ -76,6 +76,9 @@ DragValue::DragValue(const QString &label, double defaultValue, int decimals, do
m_intEdit->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum);
m_intEdit->setRange((int)m_minimum, (int)m_maximum);
m_intEdit->setValue((int)m_default);
if (oddOnly) {
m_intEdit->setSingleStep(2);
}
l->addWidget(m_intEdit);
connect(m_intEdit, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged), this,
static_cast<void (DragValue::*)(int)>(&DragValue::slotSetValue));
......@@ -456,7 +459,13 @@ void CustomLabel::mouseMoveEvent(QMouseEvent *e)
} else {
double nv = minimum() + ((double)maximum() - minimum()) / width() * e->pos().x();
if (!qFuzzyCompare(nv, value())) {
setNewValue(nv, KdenliveSettings::dragvalue_directupdate());
if (m_step > 1) {
int current = (int) value();
int diff = (nv - current) / m_step;
setNewValue(current + diff * m_step, true);
} else {
setNewValue(nv, KdenliveSettings::dragvalue_directupdate());
}
}
}
m_dragLastPosition = e->pos();
......@@ -483,7 +492,14 @@ void CustomLabel::mouseReleaseEvent(QMouseEvent *e)
m_dragLastPosition = m_dragStartPosition;
e->accept();
} else if (m_showSlider) {
setNewValue((double)maximum() * e->pos().x() / width(), true);
if (m_step > 1) {
int current = (int) value();
int newVal = (double)maximum() * e->pos().x() / width();
int diff = (newVal - current) / m_step;
setNewValue(current + diff * m_step, true);
} else {
setNewValue((double)maximum() * e->pos().x() / width(), true);
}
m_dragLastPosition = m_dragStartPosition;
e->accept();
}
......
......@@ -84,7 +84,7 @@ public:
* @param showSlider If disabled, user can still drag on the label but no progress bar is shown
*/
explicit DragValue(const QString &label, double defaultValue, int decimals, double min = 0, double max = 100, int id = -1,
const QString &suffix = QString(), bool showSlider = true, QWidget *parent = nullptr);
const QString &suffix = QString(), bool showSlider = true, bool oddOnly = false, QWidget *parent = nullptr);
~DragValue() override;
/** @brief Returns the precision = number of decimals */
......
......@@ -53,15 +53,15 @@ GeometryWidget::GeometryWidget(Monitor *monitor, QPair<int, int> range, const QR
auto *horLayout = new QHBoxLayout;
horLayout->setSpacing(2);
m_spinX = new DragValue(i18nc("x axis position", "X"), 0, 0, -99000, 99000, -1, QString(), false, this);
m_spinX = new DragValue(i18nc("x axis position", "X"), 0, 0, -99000, 99000, -1, QString(), false, false, this);
connect(m_spinX, &DragValue::valueChanged, this, &GeometryWidget::slotAdjustRectKeyframeValue);
horLayout->addWidget(m_spinX);
m_spinY = new DragValue(i18nc("y axis position", "Y"), 0, 0, -99000, 99000, -1, QString(), false, this);
m_spinY = new DragValue(i18nc("y axis position", "Y"), 0, 0, -99000, 99000, -1, QString(), false, false, this);
connect(m_spinY, &DragValue::valueChanged, this, &GeometryWidget::slotAdjustRectKeyframeValue);
horLayout->addWidget(m_spinY);
m_spinWidth = new DragValue(i18nc("Frame width", "W"), m_defaultSize.width(), 0, 1, 99000, -1, QString(), false, this);
m_spinWidth = new DragValue(i18nc("Frame width", "W"), m_defaultSize.width(), 0, 1, 99000, -1, QString(), false, false, this);
connect(m_spinWidth, &DragValue::valueChanged, this, &GeometryWidget::slotAdjustRectWidth);
horLayout->addWidget(m_spinWidth);
......@@ -73,20 +73,20 @@ GeometryWidget::GeometryWidget(Monitor *monitor, QPair<int, int> range, const QR
ratioButton->setDefaultAction(m_lockRatio);
horLayout->addWidget(ratioButton);
m_spinHeight = new DragValue(i18nc("Frame height", "H"), m_defaultSize.height(), 0, 1, 99000, -1, QString(), false, this);
m_spinHeight = new DragValue(i18nc("Frame height", "H"), m_defaultSize.height(), 0, 1, 99000, -1, QString(), false, false, this);
connect(m_spinHeight, &DragValue::valueChanged, this, &GeometryWidget::slotAdjustRectHeight);
horLayout->addWidget(m_spinHeight);
horLayout->addStretch(10);
auto *horLayout2 = new QHBoxLayout;
horLayout2->setSpacing(2);
m_spinSize = new DragValue(i18n("Size"), 100, 2, 1, 99000, -1, i18n("%"), false, this);
m_spinSize = new DragValue(i18n("Size"), 100, 2, 1, 99000, -1, i18n("%"), false, false, this);
m_spinSize->setStep(5);
connect(m_spinSize, &DragValue::valueChanged, this, &GeometryWidget::slotResize);
horLayout2->addWidget(m_spinSize);
if (useOpacity) {
m_opacity = new DragValue(i18n("Opacity"), 100, 0, 0, 100, -1, i18n("%"), true, this);
m_opacity = new DragValue(i18n("Opacity"), 100, 0, 0, 100, -1, i18n("%"), true, false, this);
m_opacity->setValue((int)(opacity * m_opacityFactor));
connect(m_opacity, &DragValue::valueChanged, [&]() { emit valueChanged(getValue()); });
horLayout2->addWidget(m_opacity);
......
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