]> git.sesse.net Git - kdenlive/blobdiff - src/renderwidget.cpp
Improve visual feedback in render dialog when clips are missing:
[kdenlive] / src / renderwidget.cpp
index 81d657c2672dd6eb7b22df87fc075ece2bb20b21..fccfef86767e6165f2d0a2807f332dbe685293c0 100644 (file)
@@ -32,7 +32,6 @@
 #include <KColorScheme>
 #include <KNotification>
 #include <KStartupInfo>
-// #include <knewstuff2/engine.h>
 
 #include <QDomDocument>
 #include <QItemDelegate>
@@ -105,16 +104,20 @@ RenderWidget::RenderWidget(const QString &projectfolder, QWidget * parent) :
     m_view.format_list->setAlternatingRowColors(true);
     m_view.size_list->setAlternatingRowColors(true);
 
-    KColorScheme scheme(palette().currentColorGroup(), KColorScheme::Window);
-    QPalette p = m_view.errorLabel->palette();
-    p.setColor(QPalette::Background, scheme.background(KColorScheme::NegativeBackground).color());
-    m_view.errorLabel->setAutoFillBackground(true);
-    m_view.errorLabel->setPalette(p);
-    m_view.errorLabel->setHidden(true);
+    KColorScheme scheme(palette().currentColorGroup(), KColorScheme::Window, KSharedConfig::openConfig(KdenliveSettings::colortheme()));
+    QColor bg = scheme.background(KColorScheme::NegativeBackground).color();
+    m_view.errorBox->setStyleSheet(QString("QGroupBox { background-color: rgb(%1, %2, %3); border-radius: 5px;}; ").arg(bg.red()).arg(bg.green()).arg(bg.blue()));
+    int height = QFontInfo(font()).pixelSize();
+    m_view.errorIcon->setPixmap(KIcon("dialog-warning").pixmap(height, height));
+    m_view.errorBox->setHidden(true);
+
+    connect(m_view.export_audio, SIGNAL(stateChanged(int)), this, SLOT(slotUpdateAudioLabel(int)));
+    m_view.export_audio->setCheckState(Qt::PartiallyChecked);
 
     parseProfiles();
     parseScriptFiles();
-
+    m_view.running_jobs->setUniformRowHeights(false);
+    m_view.scripts_list->setUniformRowHeights(false);
     connect(m_view.start_script, SIGNAL(clicked()), this, SLOT(slotStartScript()));
     connect(m_view.delete_script, SIGNAL(clicked()), this, SLOT(slotDeleteScript()));
     connect(m_view.scripts_list, SIGNAL(itemSelectionChanged()), this, SLOT(slotCheckScript()));
@@ -173,7 +176,6 @@ RenderWidget::RenderWidget(const QString &projectfolder, QWidget * parent) :
     m_view.running_jobs->setItemDelegate(m_jobsDelegate);
 
     QHeaderView *header = m_view.running_jobs->header();
-    QFontMetrics fm = fontMetrics();
     header->setResizeMode(0, QHeaderView::Fixed);
     header->resizeSection(0, 30);
     header->setResizeMode(1, QHeaderView::Interactive);
@@ -343,7 +345,7 @@ void RenderWidget::slotSaveProfile()
     QString dest = ui.destination_list->itemData(ui.destination_list->currentIndex(), Qt::UserRole).toString();
 
     QString customGroup = m_view.format_list->currentItem()->text();
-    if (customGroup.isEmpty()) customGroup = i18n("Custom");
+    if (customGroup.isEmpty()) customGroup = i18nc("Group Name", "Custom");
     ui.group_name->setText(customGroup);
 
     ui.parameters->setText(m_view.advanced_params->toPlainText());
@@ -353,7 +355,7 @@ void RenderWidget::slotSaveProfile()
     if (d->exec() == QDialog::Accepted && !ui.profile_name->text().simplified().isEmpty()) {
         QString newProfileName = ui.profile_name->text().simplified();
         QString newGroupName = ui.group_name->text().simplified();
-        if (newGroupName.isEmpty()) newGroupName = i18n("Custom");
+        if (newGroupName.isEmpty()) newGroupName = i18nc("Group Name", "Custom");
         QString newMetaGroupId = ui.destination_list->itemData(ui.destination_list->currentIndex(), Qt::UserRole).toString();
 
         QDomDocument doc;
@@ -446,7 +448,7 @@ void RenderWidget::slotCopyToFavorites()
     QDomDocument doc;
     QDomElement profileElement = doc.createElement("profile");
     profileElement.setAttribute("name", currentProfile);
-    profileElement.setAttribute("category", i18n("Custom"));
+    profileElement.setAttribute("category", i18nc("Category Name", "Custom"));
     profileElement.setAttribute("destinationid", "favorites");
     profileElement.setAttribute("extension", extension);
     profileElement.setAttribute("args", params);
@@ -476,7 +478,7 @@ void RenderWidget::slotEditProfile()
     QString dest = ui.destination_list->itemData(ui.destination_list->currentIndex(), Qt::UserRole).toString();
 
     QString customGroup = m_view.format_list->currentItem()->text();
-    if (customGroup.isEmpty()) customGroup = i18n("Custom");
+    if (customGroup.isEmpty()) customGroup = i18nc("Group Name", "Custom");
     ui.group_name->setText(customGroup);
 
     ui.profile_name->setText(currentProfile);
@@ -512,7 +514,7 @@ void RenderWidget::slotEditProfile()
 
         QString newProfileName = ui.profile_name->text().simplified();
         QString newGroupName = ui.group_name->text().simplified();
-        if (newGroupName.isEmpty()) newGroupName = i18n("Custom");
+        if (newGroupName.isEmpty()) newGroupName = i18nc("Group Name", "Custom");
         QString newMetaGroupId = ui.destination_list->itemData(ui.destination_list->currentIndex(), Qt::UserRole).toString();
         QDomNodeList profilelist = doc.elementsByTagName("profile");
         int i = 0;
@@ -661,8 +663,9 @@ void RenderWidget::slotPrepareExport(bool scriptExport)
         KMessageBox::sorry(this, i18n("Cannot find the melt program required for rendering (part of Mlt)"));
         return;
     }
-    if (m_view.play_after->isChecked() && KdenliveSettings::defaultplayerapp().isEmpty())
+    if (m_view.play_after->isChecked() && KdenliveSettings::defaultplayerapp().isEmpty()) {
         KMessageBox::sorry(this, i18n("Cannot play video after rendering because the default video player application is not set.\nPlease define it in Kdenlive settings dialog."));
+    }
     QString chapterFile;
     if (m_view.create_chapter->isChecked()) chapterFile = m_view.out_file->url().path() + ".dvdchapter";
 
@@ -676,7 +679,7 @@ void RenderWidget::slotPrepareExport(bool scriptExport)
 }
 
 
-void RenderWidget::slotExport(bool scriptExport, int zoneIn, int zoneOut, const QString &playlistPath, const QString &scriptPath)
+void RenderWidget::slotExport(bool scriptExport, int zoneIn, int zoneOut, const QString &playlistPath, const QString &scriptPath, bool exportAudio)
 {
     QListWidgetItem *item = m_view.size_list->currentItem();
     if (!item) return;
@@ -748,8 +751,7 @@ void RenderWidget::slotExport(bool scriptExport, int zoneIn, int zoneOut, const
     else if (m_view.scanning_list->currentIndex() == 2) renderArgs.append(" progressive=0");
 
     // disable audio if requested
-    if (!m_view.export_audio->isChecked())
-        renderArgs.append(" an=1 ");
+    if (!exportAudio) renderArgs.append(" an=1 ");
 
     // Check if the rendering profile is different from project profile,
     // in which case we need to use the producer_comsumer from MLT
@@ -759,7 +761,7 @@ void RenderWidget::slotExport(bool scriptExport, int zoneIn, int zoneOut, const
     QString subsize = currentSize;
     if (std.startsWith("s=")) {
         subsize = std.section(' ', 0, 0).toLower();
-        subsize = subsize.section("=", 1, 1);
+        subsize = subsize.section('=', 1, 1);
     } else if (std.contains(" s=")) {
         subsize = std.section(" s=", 1, 1);
         subsize = subsize.section(' ', 0, 0).toLower();
@@ -818,10 +820,31 @@ void RenderWidget::slotExport(bool scriptExport, int zoneIn, int zoneOut, const
         return;
     }
     renderParameters << scriptName;
-    m_view.tabWidget->setCurrentIndex(1);
 
     // Save rendering profile to document
-    emit selectedRenderProfile(m_view.size_list->currentItem()->data(MetaGroupRole).toString(), m_view.size_list->currentItem()->data(GroupRole).toString(), m_view.size_list->currentItem()->text(), dest);
+    QMap <QString, QString> renderProps;
+    renderProps.insert("renderdestination", m_view.size_list->currentItem()->data(MetaGroupRole).toString());
+    renderProps.insert("rendercategory", m_view.size_list->currentItem()->data(GroupRole).toString());
+    renderProps.insert("renderprofile", m_view.size_list->currentItem()->text());
+    renderProps.insert("renderurl", dest);
+    renderProps.insert("renderzone", QString::number(m_view.render_zone->isChecked()));
+    renderProps.insert("renderguide", QString::number(m_view.render_guide->isChecked()));
+    renderProps.insert("renderstartguide", QString::number(m_view.guide_start->currentIndex()));
+    renderProps.insert("renderendguide", QString::number(m_view.guide_end->currentIndex()));
+    renderProps.insert("renderendguide", QString::number(m_view.guide_end->currentIndex()));
+    renderProps.insert("renderscanning", QString::number(m_view.scanning_list->currentIndex()));
+    int export_audio = 0;
+    if (m_view.export_audio->checkState() == Qt::Checked) export_audio = 2;
+    else if (m_view.export_audio->checkState() == Qt::Unchecked) export_audio = 1;
+    renderProps.insert("renderexportaudio", QString::number(export_audio));
+    renderProps.insert("renderrescale", QString::number(m_view.rescale->isChecked()));
+    renderProps.insert("renderrescalewidth", QString::number(m_view.rescale_width->value()));
+    renderProps.insert("renderrescaleheight", QString::number(m_view.rescale_height->value()));
+    renderProps.insert("rendertcoverlay", QString::number(m_view.tc_overlay->isChecked()));
+    renderProps.insert("renderratio", QString::number(m_view.rescale_keep->isChecked()));
+    renderProps.insert("renderplay", QString::number(m_view.play_after->isChecked()));
+
+    emit selectedRenderProfile(renderProps);
 
     // insert item in running jobs list
     QTreeWidgetItem *renderItem;
@@ -863,6 +886,10 @@ void RenderWidget::slotExport(bool scriptExport, int zoneIn, int zoneOut, const
         }
     }
     renderItem->setData(1, Qt::UserRole + 3, render_process_args);
+    if (exportAudio == false) renderItem->setData(1, Qt::UserRole + 5, i18n("Video without audio track"));
+    else  renderItem->setData(1, Qt::UserRole + 5, QString());
+    m_view.running_jobs->setCurrentItem(renderItem);
+    m_view.tabWidget->setCurrentIndex(1);
     checkRenderStatus();
 }
 
@@ -1256,7 +1283,7 @@ void RenderWidget::parseFile(QString exportFile, bool editable)
             newdoc.appendChild(newprofiles);
             QDomNodeList profilelist = doc.elementsByTagName("profile");
             for (int i = 0; i < profilelist.count(); i++) {
-                QString category = i18n("Custom");
+                QString category = i18nc("Category Name", "Custom");
                 QString extension;
                 QDomNode parent = profilelist.at(i).parentNode();
                 if (!parent.isNull()) {
@@ -1301,7 +1328,7 @@ void RenderWidget::parseFile(QString exportFile, bool editable)
                 params = params.replace("aac", "libfaac");
             }
 
-            QString category = profile.attribute("category", i18n("Custom"));
+            QString category = profile.attribute("category", i18nc("Category Name", "Custom"));
             QString dest = profile.attribute("destinationid");
             QString prof_extension = profile.attribute("extension");
             if (!prof_extension.isEmpty()) extension = prof_extension;
@@ -1381,7 +1408,7 @@ void RenderWidget::parseFile(QString exportFile, bool editable)
                 m_view.destination_list->addItem(icon, i18n(metagroupName.toUtf8().data()), metagroupId);
             }
         }
-        groupName = documentElement.attribute("name", i18n("Custom"));
+        groupName = documentElement.attribute("name", i18nc("Attribute Name", "Custom"));
         extension = documentElement.attribute("extension", QString());
         renderer = documentElement.attribute("renderer", QString());
         bool exists = false;
@@ -1547,6 +1574,12 @@ void RenderWidget::slotCheckJob()
         activate = true;
     }
     m_view.abort_job->setEnabled(activate);
+    for (int i = 0; i < m_view.running_jobs->topLevelItemCount(); i++) {
+        current = m_view.running_jobs->topLevelItem(i);
+        if (current == m_view.running_jobs->currentItem()) {
+            current->setSizeHint(1, QSize(m_view.running_jobs->columnWidth(1), fontMetrics().height() * 3));
+        } else current->setSizeHint(1, QSize(m_view.running_jobs->columnWidth(1), fontMetrics().height() * 2));
+    }
 }
 
 void RenderWidget::slotCLeanUpJobs()
@@ -1621,10 +1654,16 @@ void RenderWidget::parseScriptFiles()
 
 void RenderWidget::slotCheckScript()
 {
-    QTreeWidgetItem *item = m_view.scripts_list->currentItem();
-    if (item == NULL) return;
-    m_view.start_script->setEnabled(item->data(0, Qt::UserRole).toString().isEmpty());
+    QTreeWidgetItem *current = m_view.scripts_list->currentItem();
+    if (current == NULL) return;
+    m_view.start_script->setEnabled(current->data(0, Qt::UserRole).toString().isEmpty());
     m_view.delete_script->setEnabled(true);
+    for (int i = 0; i < m_view.scripts_list->topLevelItemCount(); i++) {
+        current = m_view.scripts_list->topLevelItem(i);
+        if (current == m_view.scripts_list->currentItem()) {
+            current->setSizeHint(1, QSize(m_view.scripts_list->columnWidth(1), fontMetrics().height() * 3));
+        } else current->setSizeHint(1, QSize(m_view.scripts_list->columnWidth(1), fontMetrics().height() * 2));
+    }
 }
 
 void RenderWidget::slotStartScript()
@@ -1679,16 +1718,43 @@ void RenderWidget::slotHideLog()
     m_view.error_box->setVisible(false);
 }
 
-void RenderWidget::setRenderProfile(const QString &dest, const QString &group, const QString &name, const QString &url)
+void RenderWidget::setRenderProfile(QMap <QString, QString> props)
 {
     m_view.destination_list->blockSignals(true);
     m_view.format_list->blockSignals(true);
-
+    m_view.scanning_list->setCurrentIndex(props.value("renderscanning").toInt());
+    int exportAudio = props.value("renderexportaudio").toInt();
+    switch (exportAudio) {
+    case 1:
+        m_view.export_audio->setCheckState(Qt::Unchecked);
+        break;
+    case 2:
+        m_view.export_audio->setCheckState(Qt::Checked);
+        break;
+    default:
+        m_view.export_audio->setCheckState(Qt::PartiallyChecked);
+    }
+    if (props.contains("renderrescale")) m_view.rescale->setChecked(props.value("renderrescale").toInt());
+    if (props.contains("renderrescalewidth")) m_view.rescale_width->setValue(props.value("renderrescalewidth").toInt());
+    if (props.contains("renderrescaleheight")) m_view.rescale_height->setValue(props.value("renderrescaleheight").toInt());
+    if (props.contains("rendertcoverlay")) m_view.tc_overlay->setChecked(props.value("rendertcoverlay").toInt());
+    if (props.contains("renderratio")) m_view.rescale_keep->setChecked(props.value("renderratio").toInt());
+    if (props.contains("renderplay")) m_view.play_after->setChecked(props.value("renderplay").toInt());
+
+    if (props.value("renderzone") == "1") m_view.render_zone->setChecked(true);
+    else if (props.value("renderguide") == "1") {
+        m_view.render_guide->setChecked(true);
+        m_view.guide_start->setCurrentIndex(props.value("renderstartguide").toInt());
+        m_view.guide_end->setCurrentIndex(props.value("renderendguide").toInt());
+    } else m_view.render_full->setChecked(true);
+    slotUpdateGuideBox();
+
+    QString url = props.value("renderurl");
     if (!url.isEmpty()) m_view.out_file->setUrl(KUrl(url));
 
     // set destination
     for (int i = 0; i < m_view.destination_list->count(); i++) {
-        if (m_view.destination_list->itemData(i, Qt::UserRole) == dest) {
+        if (m_view.destination_list->itemData(i, Qt::UserRole) == props.value("renderdestination")) {
             m_view.destination_list->setCurrentIndex(i);
             break;
         }
@@ -1696,6 +1762,7 @@ void RenderWidget::setRenderProfile(const QString &dest, const QString &group, c
     refreshCategory();
 
     // set category
+    QString group = props.value("rendercategory");
     if (!group.isEmpty()) {
         QList<QListWidgetItem *> childs = m_view.format_list->findItems(group, Qt::MatchExactly);
         if (!childs.isEmpty()) {
@@ -1706,7 +1773,7 @@ void RenderWidget::setRenderProfile(const QString &dest, const QString &group, c
     }
 
     // set profile
-    QList<QListWidgetItem *> childs = m_view.size_list->findItems(name, Qt::MatchExactly);
+    QList<QListWidgetItem *> childs = m_view.size_list->findItems(props.value("renderprofile"), Qt::MatchExactly);
     if (!childs.isEmpty()) {
         m_view.size_list->setCurrentItem(childs.at(0));
         m_view.size_list->scrollToItem(childs.at(0));
@@ -1783,8 +1850,8 @@ void RenderWidget::missingClips(bool hasMissing)
 {
     if (hasMissing) {
         m_view.errorLabel->setText(i18n("Check missing clips"));
-        m_view.errorLabel->setHidden(false);
-    } else m_view.errorLabel->setHidden(true);
+        m_view.errorBox->setHidden(false);
+    } else m_view.errorBox->setHidden(true);
 }
 
 void RenderWidget::slotUpdateRescaleWidth(int val)
@@ -1813,3 +1880,21 @@ void RenderWidget::slotSwitchAspectRatio()
     if (m_view.rescale_keep->isChecked()) slotUpdateRescaleWidth(m_view.rescale_width->value());
 }
 
+void RenderWidget::slotUpdateAudioLabel(int ix)
+{
+    if (ix == Qt::PartiallyChecked)
+        m_view.export_audio->setText(i18n("Export audio (automatic)"));
+    else
+        m_view.export_audio->setText(i18n("Export audio"));
+}
+
+bool RenderWidget::automaticAudioExport() const
+{
+    return (m_view.export_audio->checkState() == Qt::PartiallyChecked);
+}
+
+bool RenderWidget::selectedAudioExport() const
+{
+    return (m_view.export_audio->checkState() != Qt::Unchecked);
+}
+