<name>Crop</name>
<description>Trim the edges of a clip</description>
<author>Dan Dennedy</author>
- <parameter type="constant" name="top" max="5000" min="0" default="0">
+ <parameter type="constant" name="top" max="%maxHeight" min="0" default="0" suffix="pixels">
<name>Top</name>
</parameter>
- <parameter type="constant" name="left" max="5000" min="0" default="0">
+ <parameter type="constant" name="left" max="%maxWidth" min="0" default="0" suffix="pixels">
<name>Left</name>
</parameter>
- <parameter type="constant" name="bottom" max="5000" min="0" default="0">
+ <parameter type="constant" name="bottom" max="%maxHeight" min="0" default="0" suffix="pixels">
<name>Bottom</name>
</parameter>
- <parameter type="constant" name="right" max="5000" min="0" default="0">
+ <parameter type="constant" name="right" max="%maxWidth" min="0" default="0" suffix="pixels">
<name>Right</name>
</parameter>
<parameter type="bool" name="center" default="0">
<name>Automatic center-crop</name>
</parameter>
- <parameter type="constant" name="center_bias" max="5000" min="-5000" default="0">
+ <parameter type="constant" name="center_bias" max="%maxWidth" min="-%maxWidth" default="0">
<name>Center balance</name>
</parameter>
<parameter type="bool" name="use_profile" default="0">
continue;
// Check if this effect has a variable parameter
- if (e.attribute("default").startsWith('%')) {
+ if (e.attribute("default").contains('%')) {
double evaluatedValue = ProfilesDialog::getStringEval(projectScene()->profile(), e.attribute("default"));
e.setAttribute("default", evaluatedValue);
if (e.hasAttribute("value") && e.attribute("value").startsWith('%')) {
}
} else {
double fact;
- if (e.attribute("factor").startsWith('%')) {
+ if (e.attribute("factor").contains('%')) {
fact = ProfilesDialog::getStringEval(projectScene()->profile(), e.attribute("factor"));
} else fact = e.attribute("factor", "1").toDouble();
parameters.addParam(e.attribute("name"), QString::number(e.attribute("value").toDouble() / fact));
} else {
if (e.attribute("factor", "1") != "1") {
double fact;
- if (e.attribute("factor").startsWith('%')) {
+ if (e.attribute("factor").contains('%')) {
fact = ProfilesDialog::getStringEval(m_document->mltProfile(), e.attribute("factor"));
} else fact = e.attribute("factor", "1").toDouble();
parameters.addParam(e.attribute("name"), QString::number(e.attribute("value").toDouble() / fact));
if (type == "double" || type == "constant") {
double min;
double max;
- if (pa.attribute("min").startsWith('%'))
- min = ProfilesDialog::getStringEval(m_profile, pa.attribute("min"));
+ if (pa.attribute("min").contains('%'))
+ min = ProfilesDialog::getStringEval(m_profile, pa.attribute("min"), m_frameSize);
else
min = pa.attribute("min").toDouble();
- if (pa.attribute("max").startsWith('%'))
- max = ProfilesDialog::getStringEval(m_profile, pa.attribute("max"));
+ if (pa.attribute("max").contains('%'))
+ max = ProfilesDialog::getStringEval(m_profile, pa.attribute("max"), m_frameSize);
else
max = pa.attribute("max").toDouble();
QDomElement e = params.item(i).toElement();
// Check if this effect has a variable parameter
- if (e.attribute("default").startsWith('%')) {
+ if (e.attribute("default").contains('%')) {
double evaluatedValue = ProfilesDialog::getStringEval(m_profile, e.attribute("default"));
e.setAttribute("default", evaluatedValue);
if (e.hasAttribute("value") && e.attribute("value").startsWith('%')) {
#include <KIO/NetAccess>
#include <QDir>
+#include <qscriptengine.h>
#include <QCloseEvent>
+#include <QScriptEngine>
ProfilesDialog::ProfilesDialog(QWidget * parent) :
QDialog(parent),
}
// static
-double ProfilesDialog::getStringEval(const MltVideoProfile &profile, QString eval)
+double ProfilesDialog::getStringEval(const MltVideoProfile &profile, QString eval, QPoint frameSize)
{
- double result;
- eval.replace("%width", QString::number(profile.width));
- eval.replace("%height", QString::number(profile.height));
- if (eval.contains('/')) result = (double) eval.section('/', 0, 0).toInt() / eval.section('/', 1, 1).toInt();
- else if (eval.contains('*')) result = (double) eval.section('*', 0, 0).toInt() * eval.section('*', 1, 1).toInt();
- else if (eval.contains('+')) result = (double) eval.section('+', 0, 0).toInt() + eval.section('+', 1, 1).toInt();
- else if (eval.contains('-')) result = (double) eval.section('-', 0, 0).toInt() - eval.section('-', 1, 1).toInt();
- else result = eval.toDouble();
- return result;
+ QScriptEngine sEngine;
+ sEngine.globalObject().setProperty("maxWidth", profile.width > frameSize.x() ? profile.width : frameSize.x());
+ sEngine.globalObject().setProperty("maxHeight", profile.height > frameSize.y() ? profile.height : frameSize.y());
+ sEngine.globalObject().setProperty("width", profile.width);
+ sEngine.globalObject().setProperty("height", profile.height);
+ return sEngine.evaluate(eval.remove('%')).toNumber();
}
* @param profile The profile that gives width & height
* @param eval The string to be evaluated, for example: "%width / 2"
* @return the evaluated value */
- static double getStringEval(const MltVideoProfile &profile, QString eval);
+ static double getStringEval(const MltVideoProfile &profile, QString eval, QPoint frameSize = QPoint());
/** @brief Get the descriptive text for given colorspace code (defined by MLT)
* @param colorspace An int as defined in mlt_profile.h
QString factor = e.attribute("factor", "1");
if (factor != "1") {
double fact;
- if (factor.startsWith('%')) {
+ if (factor.contains('%')) {
fact = ProfilesDialog::getStringEval(m_doc->mltProfile(), factor);
} else fact = factor.toDouble();
double val = paramValue.toDouble() * fact;
double endvalue = 0;
double fact;
if (factor.isEmpty()) fact = 1;
- else if (factor.startsWith('%')) {
+ else if (factor.contains('%')) {
fact = ProfilesDialog::getStringEval(m_doc->mltProfile(), factor);
} else fact = factor.toDouble();
for (QDomNode n3 = effect.firstChild(); !n3.isNull(); n3 = n3.nextSibling()) {
QString type = e.attribute("type");
QString factor = e.attribute("factor", "1");
double fact;
- if (factor.startsWith('%')) {
+ if (factor.contains('%')) {
fact = ProfilesDialog::getStringEval(m_doc->mltProfile(), factor);
} else {
fact = factor.toDouble();