X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=src%2Fprofilesdialog.cpp;h=c8c4a0dd80c5eb39da00a99446e560c98bc48f7d;hb=ecda842bf2b632f75198d6cf0fac1fcb5ef862ad;hp=fca5e8eac2a9e3693ba22159096e91515f570134;hpb=8f0ae78b0d64b265aa0d99b37b019b2286d75b6e;p=kdenlive diff --git a/src/profilesdialog.cpp b/src/profilesdialog.cpp index fca5e8ea..c8c4a0dd 100644 --- a/src/profilesdialog.cpp +++ b/src/profilesdialog.cpp @@ -35,6 +35,12 @@ ProfilesDialog::ProfilesDialog(QWidget * parent) : { 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 << "*"; @@ -65,6 +71,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; @@ -132,6 +179,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) { @@ -167,7 +218,7 @@ void ProfilesDialog::saveProfile(const QString path) return; } QTextStream out(&file); - out << "description=" << m_view.description->text() << "\n" << "frame_rate_num=" << m_view.frame_num->value() << "\n" << "frame_rate_den=" << m_view.frame_den->value() << "\n" << "width=" << m_view.size_w->value() << "\n" << "height=" << m_view.size_h->value() << "\n" << "progressive=" << m_view.progressive->isChecked() << "\n" << "sample_aspect_num=" << m_view.aspect_num->value() << "\n" << "sample_aspect_den=" << m_view.aspect_den->value() << "\n" << "display_aspect_num=" << m_view.display_num->value() << "\n" << "display_aspect_den=" << m_view.display_den->value() << "\n"; + out << "description=" << m_view.description->text() << "\n" << "frame_rate_num=" << m_view.frame_num->value() << "\n" << "frame_rate_den=" << m_view.frame_den->value() << "\n" << "width=" << m_view.size_w->value() << "\n" << "height=" << m_view.size_h->value() << "\n" << "progressive=" << m_view.progressive->isChecked() << "\n" << "sample_aspect_num=" << m_view.aspect_num->value() << "\n" << "sample_aspect_den=" << m_view.aspect_den->value() << "\n" << "display_aspect_num=" << m_view.display_num->value() << "\n" << "display_aspect_den=" << m_view.display_den->value() << "\n" << "colorspace=" << m_view.colorspace->itemData(m_view.colorspace->currentIndex()).toInt() << "\n"; if (file.error() != QFile::NoError) { KMessageBox::error(this, i18n("Cannot write to file %1", path)); } @@ -225,6 +276,7 @@ MltVideoProfile ProfilesDialog::getVideoProfile(QString name) result.sample_aspect_den = confFile.entryMap().value("sample_aspect_den").toInt(); result.display_aspect_num = confFile.entryMap().value("display_aspect_num").toInt(); result.display_aspect_den = confFile.entryMap().value("display_aspect_den").toInt(); + result.colorspace = confFile.entryMap().value("colorspace").toInt(); return result; } @@ -288,6 +340,7 @@ QString ProfilesDialog::existingProfile(MltVideoProfile profile) if (profile.frame_rate_den != confFile.entryMap().value("frame_rate_den").toInt()) continue; if (profile.frame_rate_num != confFile.entryMap().value("frame_rate_num").toInt()) continue; if (profile.progressive != confFile.entryMap().value("progressive").toInt()) continue; + if (profile.colorspace != confFile.entryMap().value("colorspace").toInt()) continue; return profilesFiles.at(i); } @@ -306,6 +359,7 @@ QString ProfilesDialog::existingProfile(MltVideoProfile profile) if (profile.frame_rate_den != confFile.entryMap().value("frame_rate_den").toInt()) continue; if (profile.frame_rate_num != confFile.entryMap().value("frame_rate_num").toInt()) continue; if (profile.progressive != confFile.entryMap().value("progressive").toInt()) continue; + if (profile.colorspace != confFile.entryMap().value("colorspace").toInt()) continue; return customProfiles.at(i) + profilesFiles.at(j); } } @@ -402,7 +456,7 @@ bool ProfilesDialog::matchProfile(int width, int height, double fps, double par, // 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(profile.frame_rate_num / profile.frame_rate_den - fps) > 0.4) || (par > 0 && qAbs(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; } @@ -444,7 +498,7 @@ QMap ProfilesDialog::getProfilesFromProperties(int width, int double profile_fps = values.value("frame_rate_num").toDouble() / values.value("frame_rate_den").toDouble(); double profile_par = values.value("sample_aspect_num").toDouble() / values.value("sample_aspect_den").toDouble(); if ((fps <= 0 || qAbs(profile_fps - fps) < 0.5) && (par <= 0 || qAbs(profile_par - par) < 0.1)) - result.insert(profiles.at(j), values.value("description")); + result.insert(customProfiles.at(i) + profiles.at(j), values.value("description")); } } } @@ -481,15 +535,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)) { @@ -497,7 +553,7 @@ void ProfilesDialog::saveProfile(MltVideoProfile &profile) return; } QTextStream out(&file); - out << "description=" << profile.description << "\n" << "frame_rate_num=" << profile.frame_rate_num << "\n" << "frame_rate_den=" << profile.frame_rate_den << "\n" << "width=" << profile.width << "\n" << "height=" << profile.height << "\n" << "progressive=" << profile.progressive << "\n" << "sample_aspect_num=" << profile.sample_aspect_num << "\n" << "sample_aspect_den=" << profile.sample_aspect_den << "\n" << "display_aspect_num=" << profile.display_aspect_num << "\n" << "display_aspect_den=" << profile.display_aspect_den << "\n"; + out << "description=" << profile.description << "\n" << "frame_rate_num=" << profile.frame_rate_num << "\n" << "frame_rate_den=" << profile.frame_rate_den << "\n" << "width=" << profile.width << "\n" << "height=" << profile.height << "\n" << "progressive=" << profile.progressive << "\n" << "sample_aspect_num=" << profile.sample_aspect_num << "\n" << "sample_aspect_den=" << profile.sample_aspect_den << "\n" << "display_aspect_num=" << profile.display_aspect_num << "\n" << "display_aspect_den=" << profile.display_aspect_den << "\n" << "colorspace=" << profile.colorspace << "\n"; if (file.error() != QFile::NoError) { KMessageBox::error(0, i18n("Cannot write to file %1", profilePath)); } @@ -506,7 +562,7 @@ void ProfilesDialog::saveProfile(MltVideoProfile &profile) } -void ProfilesDialog::slotUpdateDisplay() +void ProfilesDialog::slotUpdateDisplay(QString currentProfile) { if (askForSave() == false) { m_view.profiles_list->blockSignals(true); @@ -516,7 +572,7 @@ void ProfilesDialog::slotUpdateDisplay() } 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); @@ -538,9 +594,36 @@ void ProfilesDialog::slotUpdateDisplay() } else { m_view.fields->setText(QString::number((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()); + if (colorix > -1) m_view.colorspace->setCurrentIndex(colorix); m_profileIsModified = false; } +//static +QString ProfilesDialog::getColorspaceDescription(int colorspace) +{ + //TODO: should the descriptions be translated? + switch (colorspace) { + case 601: + return QString("ITU-R 601"); + case 709: + return QString("ITU-R 709"); + case 240: + return QString("SMPTE240M"); + default: + return i18n("Unknown"); + } +} + +//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"