]> git.sesse.net Git - kdenlive/commitdiff
Add option in "Project" menu to adjust profile to current clip
authorJean-Baptiste Mardelle <jb@kdenlive.org>
Mon, 20 Sep 2010 14:11:50 +0000 (14:11 +0000)
committerJean-Baptiste Mardelle <jb@kdenlive.org>
Mon, 20 Sep 2010 14:11:50 +0000 (14:11 +0000)
svn path=/trunk/kdenlive/; revision=4914

src/kdenliveui.rc
src/mainwindow.cpp
src/projectlist.cpp
src/projectlist.h

index 2fd35525d3675c8be17c993e25a0692994c29194..d64136332bdb514d3e9a798d5fdabbd1689a976d 100644 (file)
@@ -44,6 +44,7 @@
       <Separator />
       <Action name="project_clean" />
       <Action name="project_render" />
+      <Action name="project_adjust_profile" />
       <Action name="project_settings" />
     </Menu>
 
index d66ce21f75949d36effd3637988522cbfbcac3b5..06f891e4bde9a58ec04b9e234dd95252c13c5c06 100644 (file)
@@ -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);
index 18562312f62821e09ddc82d3d787e8be209bf200..9e9a15a688cd6f771dd252ce1cbfa30747364708 100644 (file)
@@ -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 <FolderProjectItem *>(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 <QString, QString> 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<QString, QString> 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 <ProjectItem*>(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 <QString, QString> 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<QString, QString> 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);
index 050a9e54bb32ec960e1a3ed5526d007db355434d..3938d92ed453b674e62bb6ece22eced6009d9fdd 100644 (file)
@@ -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: