]> git.sesse.net Git - kdenlive/commitdiff
Fix crop effect max value so that the slider has a useful range:
authorJean-Baptiste Mardelle <jb@kdenlive.org>
Sun, 3 Jul 2011 09:40:12 +0000 (09:40 +0000)
committerJean-Baptiste Mardelle <jb@kdenlive.org>
Sun, 3 Jul 2011 09:40:12 +0000 (09:40 +0000)
http://kdenlive.org/mantis/view.php?id=2202

svn path=/trunk/kdenlive/; revision=5756

effects/crop.xml
src/clipitem.cpp
src/customtrackview.cpp
src/effectstackedit.cpp
src/kdenlivedoc.cpp
src/profilesdialog.cpp
src/profilesdialog.h
src/trackview.cpp

index 57ba7084a1d7640e07e1a433b3bc115e8f881639..66af0afe73fa9e1e69da845c21bbb8d6a5e7b31c 100644 (file)
@@ -3,22 +3,22 @@
        <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">
index 0e85b25c80097edc46fca5672e962695464ae75a..aa7c5e8f1224bc9258338d4346b891c257fe2578 100644 (file)
@@ -241,7 +241,7 @@ void ClipItem::initEffect(QDomElement effect, int diff)
             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('%')) {
@@ -1461,7 +1461,7 @@ EffectsParameterList ClipItem::addEffect(const QDomElement effect, bool /*animat
                 }
             } 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));
index 766dc2470abb33c09cdb0ed4051f5b3a43c25d2f..2ed7b65bf65400def82574a71fde868595d4d2c2 100644 (file)
@@ -6589,7 +6589,7 @@ EffectsParameterList CustomTrackView::getEffectArgs(const QDomElement effect)
         } 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));
index a2d2b5ff1e07e45b81a26514f4d9f8ddee8d6241..5f6e8e41359d15e994ad5983752d8871b0bd7268 100644 (file)
@@ -261,12 +261,12 @@ void EffectStackEdit::transferParamDesc(const QDomElement d, ItemInfo info, bool
         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();
 
index b9cb39f4e5e6647623e64ddf71ba0d92dc386fb2..c4ca548dba24db61b5cc4ea1372e9c0296a7d2f7 100644 (file)
@@ -1426,7 +1426,7 @@ void KdenliveDoc::addTrackEffect(int ix, QDomElement effect)
         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('%')) {
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();
 }
 
 
index c83cb4638b45619f313bb02df8c6c0960197368c..d9f1c0d77898b3bca8ac34999ae791a84c5a6a83 100644 (file)
@@ -67,7 +67,7 @@ public:
      *  @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
index f42104b9b48152ffdc90e89fb566a813c3235439..a1783fc5ddc95b729d66fb8d06662ba15151cf31 100644 (file)
@@ -384,7 +384,7 @@ void TrackView::parseDocument(QDomDocument doc)
                                         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;
@@ -769,7 +769,7 @@ void TrackView::slotAddProjectEffects(QDomNodeList effects, QDomElement parentNo
                 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()) {
@@ -847,7 +847,7 @@ void TrackView::slotAddProjectEffects(QDomNodeList effects, QDomElement parentNo
                         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();