]> git.sesse.net Git - kdenlive/blobdiff - src/profilesdialog.cpp
Fix crop effect max value so that the slider has a useful range:
[kdenlive] / src / profilesdialog.cpp
index c8c4a0dd80c5eb39da00a99446e560c98bc48f7d..156aa17eec318a16157e2db5d16803c6250123df 100644 (file)
@@ -26,7 +26,9 @@
 #include <KIO/NetAccess>
 
 #include <QDir>
+#include <qscriptengine.h>
 #include <QCloseEvent>
+#include <QScriptEngine>
 
 ProfilesDialog::ProfilesDialog(QWidget * parent) :
     QDialog(parent),
@@ -281,17 +283,14 @@ MltVideoProfile ProfilesDialog::getVideoProfile(QString name)
 }
 
 // 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();
 }