From 8ba04e65e1a7db1b579cf110ffccbc9eda4265ca Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Mardelle Date: Mon, 20 Sep 2010 14:11:50 +0000 Subject: [PATCH] Add option in "Project" menu to adjust profile to current clip svn path=/trunk/kdenlive/; revision=4914 --- src/kdenliveui.rc | 1 + src/mainwindow.cpp | 4 ++ src/projectlist.cpp | 104 +++++++++++++++++++++++++------------------- src/projectlist.h | 2 + 4 files changed, 67 insertions(+), 44 deletions(-) diff --git a/src/kdenliveui.rc b/src/kdenliveui.rc index 2fd35525..d6413633 100644 --- a/src/kdenliveui.rc +++ b/src/kdenliveui.rc @@ -44,6 +44,7 @@ + diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index d66ce21f..06f891e4 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -1092,6 +1092,10 @@ void MainWindow::setupActions() collection->addAction("project_clean", projectClean); connect(projectClean, SIGNAL(triggered(bool)), this, SLOT(slotCleanProject())); + KAction* projectAdjust = new KAction(KIcon(), i18n("Adjust Profile to Current Clip"), this); + collection->addAction("project_adjust_profile", projectAdjust); + connect(projectAdjust, SIGNAL(triggered(bool)), m_projectList, SLOT(adjustProjectProfileToItem())); + KAction* monitorPlay = new KAction(KIcon("media-playback-start"), i18n("Play"), this); KShortcut playShortcut; playShortcut.setPrimary(Qt::Key_Space); diff --git a/src/projectlist.cpp b/src/projectlist.cpp index 18562312..9e9a15a6 100644 --- a/src/projectlist.cpp +++ b/src/projectlist.cpp @@ -1473,56 +1473,15 @@ void ProjectList::slotReplyGetFileProperties(const QString &clipId, Mlt::Produce int max = m_doc->clipManager()->clipsCount(); if (item && m_infoQueue.isEmpty() && m_thumbnailQueue.isEmpty()) { m_listView->setCurrentItem(item); - bool displayClipInMonitor = true; + bool updatedProfile = false; if (item->parent()) { if (item->parent()->type() == PROJECTFOLDERTYPE) static_cast (item->parent())->switchIcon(); } else if (KdenliveSettings::checkfirstprojectclip() && m_listView->topLevelItemCount() == 1) { // this is the first clip loaded in project, check if we want to adjust project settings to the clip - int width = properties.value("frame_size").section('x', 0, 0).toInt(); - int height = properties.value("frame_size").section('x', -1).toInt(); - double fps = properties.value("fps").toDouble(); - double par = properties.value("aspect_ratio").toDouble(); - if (item->clipType() == IMAGE || item->clipType() == AV || item->clipType() == VIDEO) { - if (ProfilesDialog::matchProfile(width, height, fps, par, item->clipType() == IMAGE, m_doc->mltProfile()) == false) { - // get a list of compatible profiles - QMap suggestedProfiles = ProfilesDialog::getProfilesFromProperties(width, height, fps, par, item->clipType() == IMAGE); - if (!suggestedProfiles.isEmpty()) { - KDialog *dialog = new KDialog(this); - dialog->setCaption(i18n("Change project profile")); - dialog->setButtons(KDialog::Ok | KDialog::Cancel); - - QWidget container; - QVBoxLayout *l = new QVBoxLayout; - QLabel *label = new QLabel(i18n("Your clip does not match current project's profile.\nDo you want to change the project profile?\n\nThe following profiles match the clip (size: %1, fps: %2)", properties.value("frame_size"), fps)); - l->addWidget(label); - QListWidget *list = new QListWidget; - list->setAlternatingRowColors(true); - QMapIterator i(suggestedProfiles); - while (i.hasNext()) { - i.next(); - QListWidgetItem *item = new QListWidgetItem(i.value(), list); - item->setData(Qt::UserRole, i.key()); - item->setToolTip(i.key()); - } - list->setCurrentRow(0); - l->addWidget(list); - container.setLayout(l); - dialog->setButtonText(KDialog::Ok, i18n("Update profile")); - dialog->setMainWidget(&container); - if (dialog->exec() == QDialog::Accepted) { - //Change project profile - displayClipInMonitor = false; - if (list->currentItem()) - emit updateProfile(list->currentItem()->data(Qt::UserRole).toString()); - } - delete list; - delete label; - } else KMessageBox::information(this, i18n("Your clip does not match current project's profile.\nNo existing profile found to match the clip's properties.\nClip size: %1\nFps: %2\n", properties.value("frame_size"), fps)); - } - } + updatedProfile = adjustProjectProfileToItem(item); } - if (displayClipInMonitor) emit clipSelected(item->referencedClip()); + if (updatedProfile == false) emit clipSelected(item->referencedClip()); } else { emit displayMessage(i18n("Loading clips"), (int)(100 *(max - m_infoQueue.count()) / max)); } @@ -1532,6 +1491,63 @@ void ProjectList::slotReplyGetFileProperties(const QString &clipId, Mlt::Produce QTimer::singleShot(30, this, SLOT(slotProcessNextClipInQueue())); } +bool ProjectList::adjustProjectProfileToItem(ProjectItem *item) +{ + if (item == NULL) { + if (m_listView->currentItem() && m_listView->currentItem()->type() != PROJECTFOLDERTYPE) + item = static_cast (m_listView->currentItem()); + } + if (item == NULL || item->referencedClip() == NULL) { + KMessageBox::information(this, i18n("Cannot find profile from current clip")); + return false; + } + bool profileUpdated = false; + QString size = item->referencedClip()->getProperty("frame_size"); + int width = size.section('x', 0, 0).toInt(); + int height = size.section('x', -1).toInt(); + double fps = item->referencedClip()->getProperty("fps").toDouble(); + double par = item->referencedClip()->getProperty("aspect_ratio").toDouble(); + if (item->clipType() == IMAGE || item->clipType() == AV || item->clipType() == VIDEO) { + if (ProfilesDialog::matchProfile(width, height, fps, par, item->clipType() == IMAGE, m_doc->mltProfile()) == false) { + // get a list of compatible profiles + QMap suggestedProfiles = ProfilesDialog::getProfilesFromProperties(width, height, fps, par, item->clipType() == IMAGE); + if (!suggestedProfiles.isEmpty()) { + KDialog *dialog = new KDialog(this); + dialog->setCaption(i18n("Change project profile")); + dialog->setButtons(KDialog::Ok | KDialog::Cancel); + + QWidget container; + QVBoxLayout *l = new QVBoxLayout; + QLabel *label = new QLabel(i18n("Your clip does not match current project's profile.\nDo you want to change the project profile?\n\nThe following profiles match the clip (size: %1, fps: %2)", size, fps)); + l->addWidget(label); + QListWidget *list = new QListWidget; + list->setAlternatingRowColors(true); + QMapIterator i(suggestedProfiles); + while (i.hasNext()) { + i.next(); + QListWidgetItem *item = new QListWidgetItem(i.value(), list); + item->setData(Qt::UserRole, i.key()); + item->setToolTip(i.key()); + } + list->setCurrentRow(0); + l->addWidget(list); + container.setLayout(l); + dialog->setButtonText(KDialog::Ok, i18n("Update profile")); + dialog->setMainWidget(&container); + if (dialog->exec() == QDialog::Accepted) { + //Change project profile + profileUpdated = true; + if (list->currentItem()) + emit updateProfile(list->currentItem()->data(Qt::UserRole).toString()); + } + delete list; + delete label; + } else KMessageBox::information(this, i18n("Your clip does not match current project's profile.\nNo existing profile found to match the clip's properties.\nClip size: %1\nFps: %2\n", size, fps)); + } + } + return profileUpdated; +} + void ProjectList::slotReplyGetImage(const QString &clipId, const QPixmap &pix) { ProjectItem *item = getItemById(clipId); diff --git a/src/projectlist.h b/src/projectlist.h index 050a9e54..3938d92e 100644 --- a/src/projectlist.h +++ b/src/projectlist.h @@ -261,6 +261,8 @@ private slots: void slotModifiedClip(const QString &id); void slotMissingClip(const QString &id); void slotAvailableClip(const QString &id); + /** @brief Try to find a matching profile for given item. */ + bool adjustProjectProfileToItem(ProjectItem *item = NULL); //void slotShowMenu(const QPoint &pos); signals: -- 2.39.2