]> git.sesse.net Git - kdenlive/blobdiff - src/clipproperties.cpp
Add center-crop option to slideshow clip.
[kdenlive] / src / clipproperties.cpp
index 087e487aeb2c30c8d97a3a386df63d08f1d9cba7..4ff65f02550b139de7a2e216473f53fc2c07c5a6 100644 (file)
@@ -156,7 +156,18 @@ ClipProperties::ClipProperties(DocClipBase *clip, Timecode tc, double fps, QWidg
         m_view.clip_thumb->setHidden(true);
         m_view.clip_color->setColor(QColor('#' + props.value("colour").right(8).left(6)));
     } else if (t == SLIDESHOW) {
-        m_view.clip_path->setText(url.directory());
+        bool isMime = true;
+        if (url.fileName().startsWith(".all.")) {
+            // the image sequence is defined by mimetype
+            m_view.clip_path->setText(url.directory());
+        } else {
+            // the image sequence is defined by pattern
+            m_view.slide_type_label->setHidden(true);
+            m_view.image_type->setHidden(true);
+            m_view.clip_path->setText(url.path());
+            isMime = false;
+        }
+
         m_view.tabWidget->removeTab(METATAB);
         m_view.tabWidget->removeTab(IMAGETAB);
         m_view.tabWidget->removeTab(COLORTAB);
@@ -174,6 +185,7 @@ ClipProperties::ClipProperties(DocClipBase *clip, Timecode tc, double fps, QWidg
         m_view.image_type->addItem("Open EXR (*.exr)", "exr");
 
         m_view.slide_loop->setChecked(props.value("loop").toInt());
+        m_view.slide_crop->setChecked(props.value("crop").toInt());
         m_view.slide_fade->setChecked(props.value("fade").toInt());
         m_view.luma_softness->setValue(props.value("softness").toInt());
         QString path = props.value("resource");
@@ -265,6 +277,8 @@ ClipProperties::ClipProperties(DocClipBase *clip, Timecode tc, double fps, QWidg
         m_view.clip_filesize->setHidden(true);
         m_view.label_size->setHidden(true);
     }
+    m_view.clip_duration->setInputMask("");
+    m_view.clip_duration->setValidator(tc.validator());
     m_view.clip_duration->setText(tc.getTimecode(m_clip->duration()));
     if (t != IMAGE && t != COLOR && t != TEXT) m_view.clip_duration->setReadOnly(true);
     else connect(m_view.clip_duration, SIGNAL(editingFinished()), this, SLOT(slotCheckMaxLength()));
@@ -462,7 +476,7 @@ const QString &ClipProperties::clipId() const
 QMap <QString, QString> ClipProperties::properties()
 {
     QMap <QString, QString> props;
-    CLIPTYPE t;
+    CLIPTYPE t = UNKNOWN;
     if (m_clip != NULL) {
         t = m_clip->clipType();
         m_old_props = m_clip->properties();
@@ -530,7 +544,6 @@ QMap <QString, QString> ClipProperties::properties()
     if (m_clip == NULL) {
         if (m_view.clip_out->isEnabled()) {
             int duration = m_tc.getFrameCount(m_view.clip_out->text());
-            kDebug() << "// DURAT: " << duration << ", OLD: " << m_old_props.value("out").toInt();
             if (duration != m_old_props.value("out").toInt()) {
                 props["out"] = QString::number(duration - 1);
             }
@@ -563,18 +576,23 @@ QMap <QString, QString> ClipProperties::properties()
     } else if (t == SLIDESHOW) {
         QString value = QString::number((int) m_view.slide_loop->isChecked());
         if (m_old_props.value("loop") != value) props["loop"] = value;
+        value = QString::number((int) m_view.slide_crop->isChecked());
+        if (m_old_props.value("crop") != value) props["crop"] = value;
         value = QString::number((int) m_view.slide_fade->isChecked());
         if (m_old_props.value("fade") != value) props["fade"] = value;
         value = QString::number((int) m_view.luma_softness->value());
         if (m_old_props.value("softness") != value) props["softness"] = value;
-
-        QString extension = "/.all." + m_view.image_type->itemData(m_view.image_type->currentIndex()).toString();
-        QString new_path = m_view.clip_path->text() + extension;
-        if (new_path != m_old_props.value("resource")) {
-            m_clipNeedsReLoad = true;
-            props["resource"] = new_path;
-            kDebug() << "////  SLIDE EDIT, NEW:" << new_path << ", OLD; " << m_old_props.value("resource");
-        }
+       
+       bool isMime = !(m_view.clip_path->text().contains('%'));
+       if (isMime) {
+           QString extension = "/.all." + m_view.image_type->itemData(m_view.image_type->currentIndex()).toString();
+           QString new_path = m_view.clip_path->text() + extension;
+           if (new_path != m_old_props.value("resource")) {
+               m_clipNeedsReLoad = true;
+               props["resource"] = new_path;
+               kDebug() << "////  SLIDE EDIT, NEW:" << new_path << ", OLD; " << m_old_props.value("resource");
+           }
+       }
         int duration;
         if (m_view.slide_duration_format->currentIndex() == 1) {
             // we are in frames mode
@@ -627,16 +645,40 @@ bool ClipProperties::needsTimelineReload() const
     return m_clipNeedsReLoad;
 }
 
+
 void ClipProperties::parseFolder()
 {
+    QString path = m_view.clip_path->text();
+    bool isMime = !(path.contains('%'));
+    if (!isMime) path = KUrl(path).directory();
+    QDir dir(path);
 
-    QDir dir(m_view.clip_path->text());
     QStringList filters;
-    filters << "*." + m_view.image_type->itemData(m_view.image_type->currentIndex()).toString();
-    QString extension = "/.all." + m_view.image_type->itemData(m_view.image_type->currentIndex()).toString();
+    QString extension;
+
+    if (isMime) {
+        // TODO: improve jpeg image detection with extension like jpeg, requires change in MLT image producers
+        filters << "*." + m_view.image_type->itemData(m_view.image_type->currentIndex()).toString();
+        extension = "/.all." + m_view.image_type->itemData(m_view.image_type->currentIndex()).toString();
+        dir.setNameFilters(filters);
+    }
 
-    dir.setNameFilters(filters);
     QStringList result = dir.entryList(QDir::Files);
+
+    if (!isMime) {
+        // find pattern
+        QString filter = KUrl(m_view.clip_path->text()).fileName();
+        QString ext = filter.section('.', -1);
+        filter = filter.section('%', 0, -2);
+        QString regexp = "^" + filter + "\\d+\\." + ext + "$";
+        QRegExp rx(regexp);
+        QStringList entries;
+        foreach(const QString &path, result) {
+            if (rx.exactMatch(path)) entries << path;
+        }
+        result = entries;
+    }
+
     m_count = result.count();
     if (m_count == 0) {
         // no images, do not accept that
@@ -650,7 +692,9 @@ void ClipProperties::parseFolder()
     xml.setAttribute("resource", m_view.clip_path->text() + extension);
     int width = 180.0 * KdenliveSettings::project_display_ratio();
     if (width % 2 == 1) width++;
-    QPixmap pix = m_clip->thumbProducer()->getImage(KUrl(m_view.clip_path->text() + extension), 1, width, 180);
+    QString filePath = m_view.clip_path->text();
+    if (isMime) filePath.append(extension);
+    QPixmap pix = m_clip->thumbProducer()->getImage(KUrl(filePath), 1, width, 180);
     QMap <QString, QString> props = m_clip->properties();
     m_view.clip_duration->setText(m_tc.getTimecodeFromFrames(props.value("ttl").toInt() * m_count));
     m_view.clip_thumb->setPixmap(pix);