]> git.sesse.net Git - kdenlive/blobdiff - src/profilesdialog.cpp
Stop using 'mlt_profile' in render profiles. Instead use 's' and 'aspect'.
[kdenlive] / src / profilesdialog.cpp
index c9aa53c29f53d02588d7f7c357910ade2a2df235..68aff4698fce879418471f83f7a5890c307b4ab1 100644 (file)
@@ -26,7 +26,9 @@
 #include <KIO/NetAccess>
 
 #include <QDir>
+#include <qscriptengine.h>
 #include <QCloseEvent>
+#include <QScriptEngine>
 
 ProfilesDialog::ProfilesDialog(QWidget * parent) :
     QDialog(parent),
@@ -71,6 +73,47 @@ ProfilesDialog::ProfilesDialog(QWidget * parent) :
     connect(m_view.size_w, SIGNAL(valueChanged(int)), this, SLOT(slotProfileEdited()));
 }
 
+
+ProfilesDialog::ProfilesDialog(QString profilePath, QWidget * parent) :
+    QDialog(parent),
+    m_profileIsModified(false),
+    m_isCustomProfile(true),
+    m_customProfilePath(profilePath)
+{
+    m_view.setupUi(this);
+
+    // Fill colorspace list (see mlt_profile.h)
+    m_view.colorspace->addItem(getColorspaceDescription(601), 601);
+    m_view.colorspace->addItem(getColorspaceDescription(709), 709);
+    m_view.colorspace->addItem(getColorspaceDescription(240), 240);
+    m_view.colorspace->addItem(getColorspaceDescription(0), 0);
+
+    QStringList profilesFilter;
+    profilesFilter << "*";
+
+    m_view.button_save->setIcon(KIcon("document-save"));
+    m_view.button_save->setToolTip(i18n("Save profile"));
+    m_view.button_create->setHidden(true);
+    m_view.profiles_list->setHidden(true);
+    m_view.button_delete->setHidden(true);
+    m_view.button_default->setHidden(true);
+    m_view.description->setEnabled(false);
+
+    slotUpdateDisplay(profilePath);
+    connect(m_view.button_save, SIGNAL(clicked()), this, SLOT(slotSaveProfile()));
+
+    connect(m_view.description, SIGNAL(textChanged(const QString &)), this, SLOT(slotProfileEdited()));
+    connect(m_view.frame_num, SIGNAL(valueChanged(int)), this, SLOT(slotProfileEdited()));
+    connect(m_view.frame_den, SIGNAL(valueChanged(int)), this, SLOT(slotProfileEdited()));
+    connect(m_view.aspect_num, SIGNAL(valueChanged(int)), this, SLOT(slotProfileEdited()));
+    connect(m_view.aspect_den, SIGNAL(valueChanged(int)), this, SLOT(slotProfileEdited()));
+    connect(m_view.display_num, SIGNAL(valueChanged(int)), this, SLOT(slotProfileEdited()));
+    connect(m_view.display_den, SIGNAL(valueChanged(int)), this, SLOT(slotProfileEdited()));
+    connect(m_view.progressive, SIGNAL(stateChanged(int)), this, SLOT(slotProfileEdited()));
+    connect(m_view.size_h, SIGNAL(valueChanged(int)), this, SLOT(slotProfileEdited()));
+    connect(m_view.size_w, SIGNAL(valueChanged(int)), this, SLOT(slotProfileEdited()));
+}
+
 void ProfilesDialog::slotProfileEdited()
 {
     m_profileIsModified = true;
@@ -138,6 +181,10 @@ void ProfilesDialog::slotSetDefaultProfile()
 
 bool ProfilesDialog::slotSaveProfile()
 {
+    if (!m_customProfilePath.isEmpty()) {
+        saveProfile(m_customProfilePath);
+        return true;
+    }
     const QString profileDesc = m_view.description->text();
     int ix = m_view.profiles_list->findText(profileDesc);
     if (ix != -1) {
@@ -236,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();
 }
 
 
@@ -517,7 +561,7 @@ void ProfilesDialog::saveProfile(MltVideoProfile &profile, QString profilePath)
 }
 
 
-void ProfilesDialog::slotUpdateDisplay()
+void ProfilesDialog::slotUpdateDisplay(QString currentProfile)
 {
     if (askForSave() == false) {
         m_view.profiles_list->blockSignals(true);
@@ -525,9 +569,9 @@ void ProfilesDialog::slotUpdateDisplay()
         m_view.profiles_list->blockSignals(false);
         return;
     }
-
+    QLocale locale;
     m_selectedProfileIndex = m_view.profiles_list->currentIndex();
-    QString currentProfile = m_view.profiles_list->itemData(m_view.profiles_list->currentIndex()).toString();
+    if (currentProfile.isEmpty()) currentProfile = m_view.profiles_list->itemData(m_view.profiles_list->currentIndex()).toString();
     m_isCustomProfile = currentProfile.contains('/');
     m_view.button_create->setEnabled(true);
     m_view.button_delete->setEnabled(m_isCustomProfile);
@@ -545,9 +589,9 @@ void ProfilesDialog::slotUpdateDisplay()
     m_view.frame_den->setValue(values.value("frame_rate_den").toInt());
     m_view.progressive->setChecked(values.value("progressive").toInt());
     if (values.value("progressive").toInt()) {
-        m_view.fields->setText(QString::number((double) values.value("frame_rate_num").toInt() / values.value("frame_rate_den").toInt(), 'f', 2));
+        m_view.fields->setText(locale.toString((double) values.value("frame_rate_num").toInt() / values.value("frame_rate_den").toInt(), 'f', 2));
     } else {
-        m_view.fields->setText(QString::number((double) 2 * values.value("frame_rate_num").toInt() / values.value("frame_rate_den").toInt(), 'f', 2));
+        m_view.fields->setText(locale.toString((double) 2 * values.value("frame_rate_num").toInt() / values.value("frame_rate_den").toInt(), 'f', 2));
     }
 
     int colorix = m_view.colorspace->findData(values.value("colorspace").toInt());