X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=src%2Fprofilesdialog.cpp;h=8fc0b01882fb37d045bb317d681dd76a5dea6fe7;hb=4f9bd66f4c236423b440b10ae1e543d162cec0ed;hp=15517ec533832ad0ca1b19b5d553af5e5cbec464;hpb=308fdd5fe327cb337e96774aebb55783b6e84f54;p=kdenlive diff --git a/src/profilesdialog.cpp b/src/profilesdialog.cpp index 15517ec5..8fc0b018 100644 --- a/src/profilesdialog.cpp +++ b/src/profilesdialog.cpp @@ -26,7 +26,9 @@ #include #include +#include #include +#include ProfilesDialog::ProfilesDialog(QWidget * parent) : QDialog(parent), @@ -59,7 +61,48 @@ ProfilesDialog::ProfilesDialog(QWidget * parent) : connect(m_view.button_delete, SIGNAL(clicked()), this, SLOT(slotDeleteProfile())); connect(m_view.button_default, SIGNAL(clicked()), this, SLOT(slotSetDefaultProfile())); - connect(m_view.description, SIGNAL(textChanged(const QString &)), this, SLOT(slotProfileEdited())); + connect(m_view.description, SIGNAL(textChanged(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())); +} + + +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(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())); @@ -76,7 +119,7 @@ void ProfilesDialog::slotProfileEdited() m_profileIsModified = true; } -void ProfilesDialog::fillList(const QString selectedProfile) +void ProfilesDialog::fillList(const QString &selectedProfile) { // List the Mlt profiles m_view.profiles_list->clear(); @@ -88,7 +131,7 @@ void ProfilesDialog::fillList(const QString selectedProfile) } if (!KdenliveSettings::default_profile().isEmpty()) { - for (int i = 0; i < m_view.profiles_list->count(); i++) { + for (int i = 0; i < m_view.profiles_list->count(); ++i) { if (m_view.profiles_list->itemData(i).toString() == KdenliveSettings::default_profile()) { m_view.profiles_list->setCurrentIndex(i); break; @@ -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) { @@ -154,7 +201,7 @@ bool ProfilesDialog::slotSaveProfile() QString profilePath = KStandardDirs::locateLocal("appdata", customName + QString::number(i)); kDebug() << " TYING PROFILE FILE: " << profilePath; while (KIO::NetAccess::exists(KUrl(profilePath), KIO::NetAccess::SourceSide, this)) { - i++; + ++i; profilePath = KStandardDirs::locateLocal("appdata", customName + QString::number(i)); } saveProfile(profilePath); @@ -165,7 +212,7 @@ bool ProfilesDialog::slotSaveProfile() return true; } -void ProfilesDialog::saveProfile(const QString path) +void ProfilesDialog::saveProfile(QString path) { QFile file(path); if (!file.open(QIODevice::WriteOnly)) { @@ -190,7 +237,7 @@ void ProfilesDialog::slotDeleteProfile() } // static -MltVideoProfile ProfilesDialog::getVideoProfile(QString name) +MltVideoProfile ProfilesDialog::getVideoProfile(const QString &name) { MltVideoProfile result; QStringList profilesNames; @@ -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, const 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(); } @@ -350,7 +394,7 @@ QMap ProfilesDialog::getProfilesInfo() } // static -QMap< QString, QString > ProfilesDialog::getSettingsFromFile(const QString path) +QMap< QString, QString > ProfilesDialog::getSettingsFromFile(const QString& path) { QStringList profilesNames; QStringList profilesFiles; @@ -369,7 +413,7 @@ QMap< QString, QString > ProfilesDialog::getSettingsFromFile(const QString path) } // static -QMap< QString, QString > ProfilesDialog::getSettingsForProfile(const QString profileName) +QMap< QString, QString > ProfilesDialog::getSettingsForProfile(const QString& profileName) { QStringList profilesNames; QStringList profilesFiles; @@ -404,14 +448,14 @@ QMap< QString, QString > ProfilesDialog::getSettingsForProfile(const QString pro } // static -bool ProfilesDialog::matchProfile(int width, int height, double fps, double par, bool isImage, MltVideoProfile profile) +bool ProfilesDialog::matchProfile(int width, int height, double fps, double par, bool isImage, const MltVideoProfile &profile) { int profileWidth; if (isImage) { // when using image, compare with display width profileWidth = profile.height * profile.display_aspect_num / profile.display_aspect_den + 0.5; } else profileWidth = profile.width; - if (width != profileWidth || height != profile.height || (fps > 0 && qAbs((double) profile.frame_rate_num / profile.frame_rate_den - fps) > 0.4) || (par > 0 && qAbs((double) profile.sample_aspect_num / profile.sample_aspect_den - par) > 0.1)) return false; + if (width != profileWidth || height != profile.height || (fps > 0 && qAbs((double) profile.frame_rate_num / profile.frame_rate_den - fps) > 0.4) || (!isImage && par > 0 && qAbs((double) profile.sample_aspect_num / profile.sample_aspect_den - par) > 0.1)) return false; return true; } @@ -461,7 +505,7 @@ QMap ProfilesDialog::getProfilesFromProperties(int width, int } // static -QString ProfilesDialog::getPathFromDescription(const QString profileDesc) +QString ProfilesDialog::getPathFromDescription(const QString& profileDesc) { QStringList profilesNames; QStringList profilesFiles; @@ -490,15 +534,17 @@ QString ProfilesDialog::getPathFromDescription(const QString profileDesc) } // static -void ProfilesDialog::saveProfile(MltVideoProfile &profile) +void ProfilesDialog::saveProfile(MltVideoProfile &profile, QString profilePath) { - int i = 0; - QString customName = "profiles/customprofile"; - QString profilePath = KStandardDirs::locateLocal("appdata", customName + QString::number(i)); - kDebug() << " TYING PROFILE FILE: " << profilePath; - while (KIO::NetAccess::exists(KUrl(profilePath), KIO::NetAccess::SourceSide, 0)) { - i++; + if (profilePath.isEmpty()) { + int i = 0; + QString customName = "profiles/customprofile"; profilePath = KStandardDirs::locateLocal("appdata", customName + QString::number(i)); + kDebug() << " TYING PROFILE FILE: " << profilePath; + while (KIO::NetAccess::exists(KUrl(profilePath), KIO::NetAccess::SourceSide, 0)) { + ++i; + profilePath = KStandardDirs::locateLocal("appdata", customName + QString::number(i)); + } } QFile file(profilePath); if (!file.open(QIODevice::WriteOnly)) { @@ -515,7 +561,7 @@ void ProfilesDialog::saveProfile(MltVideoProfile &profile) } -void ProfilesDialog::slotUpdateDisplay() +void ProfilesDialog::slotUpdateDisplay(QString currentProfile) { if (askForSave() == false) { m_view.profiles_list->blockSignals(true); @@ -523,9 +569,10 @@ 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); @@ -543,9 +590,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()); @@ -569,6 +616,15 @@ QString ProfilesDialog::getColorspaceDescription(int colorspace) } } +//static +int ProfilesDialog::getColorspaceFromDescription(const QString &description) +{ + //TODO: should the descriptions be translated? + if (description == "SMPTE240M") return 240; + if (description == "ITU-R 709") return 709; + return 601; +} + #include "profilesdialog.moc"