From a6b9fba3ddca6e3e1a4b3d48aef2dcb9228c79c9 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Mardelle Date: Sun, 3 Jul 2011 09:40:12 +0000 Subject: [PATCH] Fix crop effect max value so that the slider has a useful range: http://kdenlive.org/mantis/view.php?id=2202 svn path=/trunk/kdenlive/; revision=5756 --- effects/crop.xml | 10 +++++----- src/clipitem.cpp | 4 ++-- src/customtrackview.cpp | 2 +- src/effectstackedit.cpp | 8 ++++---- src/kdenlivedoc.cpp | 2 +- src/profilesdialog.cpp | 19 +++++++++---------- src/profilesdialog.h | 2 +- src/trackview.cpp | 6 +++--- 8 files changed, 26 insertions(+), 27 deletions(-) diff --git a/effects/crop.xml b/effects/crop.xml index 57ba7084..66af0afe 100644 --- a/effects/crop.xml +++ b/effects/crop.xml @@ -3,22 +3,22 @@ Crop Trim the edges of a clip Dan Dennedy - + Top - + Left - + Bottom - + Right Automatic center-crop - + Center balance diff --git a/src/clipitem.cpp b/src/clipitem.cpp index 0e85b25c..aa7c5e8f 100644 --- a/src/clipitem.cpp +++ b/src/clipitem.cpp @@ -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)); diff --git a/src/customtrackview.cpp b/src/customtrackview.cpp index 766dc247..2ed7b65b 100644 --- a/src/customtrackview.cpp +++ b/src/customtrackview.cpp @@ -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)); diff --git a/src/effectstackedit.cpp b/src/effectstackedit.cpp index a2d2b5ff..5f6e8e41 100644 --- a/src/effectstackedit.cpp +++ b/src/effectstackedit.cpp @@ -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(); diff --git a/src/kdenlivedoc.cpp b/src/kdenlivedoc.cpp index b9cb39f4..c4ca548d 100644 --- a/src/kdenlivedoc.cpp +++ b/src/kdenlivedoc.cpp @@ -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('%')) { diff --git a/src/profilesdialog.cpp b/src/profilesdialog.cpp index c8c4a0dd..156aa17e 100644 --- a/src/profilesdialog.cpp +++ b/src/profilesdialog.cpp @@ -26,7 +26,9 @@ #include #include +#include #include +#include 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(); } diff --git a/src/profilesdialog.h b/src/profilesdialog.h index c83cb463..d9f1c0d7 100644 --- a/src/profilesdialog.h +++ b/src/profilesdialog.h @@ -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 diff --git a/src/trackview.cpp b/src/trackview.cpp index f42104b9..a1783fc5 100644 --- a/src/trackview.cpp +++ b/src/trackview.cpp @@ -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(); -- 2.39.2