Commit c92aa046 authored by Vincent Pinon's avatar Vincent Pinon

remove QScript dependency

parent 42a40132
......@@ -1268,14 +1268,6 @@ void RenderWidget::slotExport(bool scriptExport, int zoneIn, int zoneOut,
QStringList paramsList = renderArgs.split(' ', QString::SkipEmptyParts);
QScriptEngine sEngine;
sEngine.globalObject().setProperty(QStringLiteral("bitrate"), m_view.video->value());
sEngine.globalObject().setProperty(QStringLiteral("quality"), m_view.video->value());
sEngine.globalObject().setProperty(QStringLiteral("audiobitrate"), m_view.audio->value());
sEngine.globalObject().setProperty(QStringLiteral("audioquality"), m_view.audio->value());
sEngine.globalObject().setProperty(QStringLiteral("dar"), '@' + QString::number(profile->display_aspect_num()) + QLatin1Char('/') + QString::number(profile->display_aspect_den()));
sEngine.globalObject().setProperty(QStringLiteral("passes"), static_cast<int>(m_view.checkTwoPass->isChecked()) + 1);
for (int i = 0; i < paramsList.count(); ++i) {
QString paramName = paramsList.at(i).section(QLatin1Char('='), 0, -2);
QString paramValue = paramsList.at(i).section(QLatin1Char('='), -1);
......@@ -1285,10 +1277,26 @@ void RenderWidget::slotExport(bool scriptExport, int zoneIn, int zoneOut,
}
// evaluate expression
if (paramValue.startsWith(QLatin1Char('%'))) {
paramValue = sEngine.evaluate(paramValue.remove(0, 1)).toString();
if (paramValue.startsWith(QStringLiteral("%bitrate"))
|| paramValue == QStringLiteral("%quality")) {
if (paramValue.contains("+'k'"))
paramValue = QString::number(m_view.video->value()) + 'k';
else
paramValue = QString::number(m_view.video->value());
}
if (paramValue.startsWith(QStringLiteral("%audiobitrate"))
|| paramValue == QStringLiteral("%audioquality")) {
if (paramValue.contains("+'k'"))
paramValue = QString::number(m_view.audio->value()) + 'k';
else
paramValue = QString::number(m_view.audio->value());
}
if (paramValue == QStringLiteral("%dar"))
paramValue = '@' + QString::number(profile->display_aspect_num()) + QLatin1Char('/') + QString::number(profile->display_aspect_den());
if (paramValue == QStringLiteral("%passes"))
paramValue = QString::number(static_cast<int>(m_view.checkTwoPass->isChecked()) + 1);
paramsList[i] = paramName + QLatin1Char('=') + paramValue;
}
sEngine.globalObject().setProperty(paramName.toUtf8().constData(), paramValue);
}
if (resizeProfile && !KdenliveSettings::gpu_accel()) {
......
......@@ -33,7 +33,6 @@
#include <QColor>
#include <QString>
#include <QDir>
#include <QScriptEngine>
#include <mlt++/Mlt.h>
......@@ -1809,135 +1808,6 @@ bool DocumentValidator::isModified() const
return m_modified;
}
/*
void DocumentValidator::updateEffects()
{
// WARNING: order by findDirs will determine which js file to use (in case multiple scripts for the same filter exist)
QMap<QString, QUrl> paths;
QMap<QString, QScriptProgram> scripts;
QStringList directories = QStandardPaths::locateAll(QStandardPaths::AppDataLocation, "effects/update");
foreach (const QString &directoryName, directories) {
QDir directory(directoryName);
QStringList fileList = directory.entryList(QStringList() << "*.js", QDir::Files);
foreach (const QString &fileName, fileList) {
QString identifier = fileName;
// remove extension (".js")
identifier.chop(3);
paths.insert(identifier, QUrl(directoryName + fileName));
}
}
QDomNodeList effects = m_doc.elementsByTagName("filter");
int max = effects.count();
QStringList safeEffects;
for(int i = 0; i < max; ++i) {
QDomElement effect = effects.at(i).toElement();
QString effectId = EffectsList::property(effect, "kdenlive_id");
if (safeEffects.contains(effectId)) {
// Do not check the same effect twice if it is at the correct version
// (assume we don't have different versions of the same effect in a project file)
continue;
}
QString effectTag = EffectsList::property(effect, "tag");
QString effectVersionStr = EffectsList::property(effect, "version");
double effectVersion = effectVersionStr.isNull() ? -1 : effectVersionStr.toDouble();
QDomElement effectDescr = MainWindow::customEffects.getEffectByTag(QString(), effectId);
if (effectDescr.isNull()) {
effectDescr = MainWindow::videoEffects.getEffectByTag(effectTag, effectId);
}
if (effectDescr.isNull()) {
effectDescr = MainWindow::audioEffects.getEffectByTag(effectTag, effectId);
}
if (!effectDescr.isNull()) {
double serviceVersion = -1;
QDomElement serviceVersionElem = effectDescr.firstChildElement("version");
if (!serviceVersionElem.isNull()) {
serviceVersion = serviceVersionElem.text().toDouble();
}
if (serviceVersion != effectVersion && paths.contains(effectId)) {
if (!scripts.contains(effectId)) {
QFile scriptFile(paths.value(effectId).path());
if (!scriptFile.open(QIODevice::ReadOnly)) {
continue;
}
QScriptProgram scriptProgram(scriptFile.readAll());
scriptFile.close();
scripts.insert(effectId, scriptProgram);
}
QScriptEngine scriptEngine;
scriptEngine.importExtension("qt.core");
scriptEngine.importExtension("qt.xml");
scriptEngine.evaluate(scripts.value(effectId));
QScriptValue updateRules = scriptEngine.globalObject().property("update");
if (!updateRules.isValid())
continue;
if (updateRules.isFunction()) {
QDomDocument scriptDoc;
scriptDoc.appendChild(scriptDoc.importNode(effect, true));
QString effectString = updateRules.call(QScriptValue(), QScriptValueList() << serviceVersion << effectVersion << scriptDoc.toString()).toString();
if (!effectString.isEmpty() && !scriptEngine.hasUncaughtException()) {
scriptDoc.setContent(effectString);
QDomNode updatedEffect = effect.ownerDocument().importNode(scriptDoc.documentElement(), true);
effect.parentNode().replaceChild(updatedEffect, effect);
m_modified = true;
}
} else {
m_modified = updateEffectParameters(effect.childNodes(), &updateRules, serviceVersion, effectVersion);
}
// set version number since MLT won't change it (only initially set it)
QDomElement versionElem = effect.firstChildElement("version");
if (EffectsList::property(effect, "version").isNull()) {
versionElem = effect.ownerDocument().createTextNode(QLocale().toString(serviceVersion)).toElement();
versionElem.setTagName("property");
versionElem.setAttribute("name", "version");
effect.appendChild(versionElem);
} else {
EffectsList::setProperty(effect, "version", QLocale().toString(serviceVersion));
}
}
else safeEffects.append(effectId);
}
}
}
bool DocumentValidator::updateEffectParameters(const QDomNodeList &parameters, const QScriptValue* updateRules, const double serviceVersion, const double effectVersion)
{
bool updated = false;
bool isDowngrade = serviceVersion < effectVersion;
for (int i = 0; i < parameters.count(); ++i) {
QDomElement parameter = parameters.at(i).toElement();
QScriptValue rules = updateRules->property(parameter.attribute("name"));
if (rules.isValid() && rules.isArray()) {
int rulesCount = rules.property("length").toInt32();
if (isDowngrade) {
// start with the highest version and downgrade step by step
for (int j = rulesCount - 1; j >= 0; --j) {
double version = rules.property(j).property(0).toNumber();
if (version <= effectVersion && version > serviceVersion) {
parameter.firstChild().setNodeValue(rules.property(j).property(1).call(QScriptValue(), QScriptValueList() << parameter.text() << isDowngrade).toString());
updated = true;
}
}
} else {
for (int j = 0; j < rulesCount; ++j) {
double version = rules.property(j).property(0).toNumber();
if (version > effectVersion && version <= serviceVersion) {
parameter.firstChild().setNodeValue(rules.property(j).property(1).call(QScriptValue(), QScriptValueList() << parameter.text() << isDowngrade).toString());
updated = true;
}
}
}
}
}
return updated;
}
*/
bool DocumentValidator::checkMovit()
{
QString playlist = m_doc.toString();
......
......@@ -26,8 +26,6 @@
#include <QUrl>
#include <QMap>
class QScriptValue;
class DocumentValidator
{
......@@ -51,13 +49,6 @@ private:
void checkOrphanedProducers();
QStringList getInfoFromEffectName(const QString &oldName);
QString colorToString(const QColor &c);
/*
/// @brief Updates effects that were created using a different version of the underlaying filter than the one installed.
void updateEffects();
/// @brief Updates the parameters according to the updateRules.
/// @see the related in README in effects/update
bool updateEffectParameters(const QDomNodeList &parameters, const QScriptValue *updateRules, const double serviceVersion, const double effectVersion);
*/
QString factorizeGeomValue(const QString &value, double factor);
/** @brief Kdenlive <= 0.9.10 saved title clip item position/opacity with locale which was wrong, fix. */
void fixTitleProducerLocale(QDomElement &producer);
......
......@@ -25,7 +25,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "effectstack/widgets/animationwidget.h"
#include "kdenlive_debug.h"
#include <QScriptEngine>
EffectInfo::EffectInfo()
{
......@@ -227,12 +226,13 @@ void EffectsController::adjustEffectParameters(EffectsParameterList &parameters,
double EffectsController::getStringEval(const ProfileInfo &info, QString eval, const QPoint &frameSize)
{
QScriptEngine sEngine;
sEngine.globalObject().setProperty(QStringLiteral("maxWidth"), info.profileSize.width() > frameSize.x() ? info.profileSize.width() : frameSize.x());
sEngine.globalObject().setProperty(QStringLiteral("maxHeight"), info.profileSize.height() > frameSize.y() ? info.profileSize.height() : frameSize.y());
sEngine.globalObject().setProperty(QStringLiteral("width"), info.profileSize.width());
sEngine.globalObject().setProperty(QStringLiteral("height"), info.profileSize.height());
return sEngine.evaluate(eval.remove('%')).toNumber();
eval.replace(QLatin1String("%maxWidth"), QString::number(info.profileSize.width() > frameSize.x() ? info.profileSize.width() : frameSize.x()))
.replace(QLatin1String("%maxHeight"), QString::number(info.profileSize.height() > frameSize.y() ? info.profileSize.height() : frameSize.y()))
.replace(QLatin1String("%width"), QString::number(info.profileSize.width()))
.replace(QLatin1String("%height"), QString::number(info.profileSize.height()));
Mlt::Properties p;
p.set("eval", eval.toLatin1().constData());
return p.get_double("eval");
}
QString EffectsController::getStringRectEval(const ProfileInfo &info, QString eval)
......
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