]> git.sesse.net Git - kdenlive/blobdiff - src/clipproperties.cpp
edit and delete markers
[kdenlive] / src / clipproperties.cpp
index 6268a478aec22e0890aba5c8116da5289238762a..eec5ede7d414f5241d3f8b0dd0685e043655b675 100644 (file)
@@ -38,7 +38,7 @@
 #define TYPE_BMP 2
 #define TYPE_GIF 3
 
-ClipProperties::ClipProperties(DocClipBase *clip, Timecode tc, double fps, QWidget * parent): QDialog(parent), m_tc(tc), m_clip(clip), m_fps(fps) {
+ClipProperties::ClipProperties(DocClipBase *clip, Timecode tc, double fps, QWidget * parent): QDialog(parent), m_tc(tc), m_clip(clip), m_fps(fps), m_clipNeedsRefresh(false), m_count(0) {
     setFont(KGlobalSettings::toolBarFont());
     m_view.setupUi(this);
     KUrl url = m_clip->fileURL();
@@ -55,30 +55,31 @@ ClipProperties::ClipProperties(DocClipBase *clip, Timecode tc, double fps, QWidg
 
     CLIPTYPE t = m_clip->clipType();
     if (t == COLOR) {
-       m_view.clip_path->setEnabled(false);
-       m_view.tabWidget->removeTab(SLIDETAB);
-       m_view.tabWidget->removeTab(AUDIOTAB);
-       m_view.tabWidget->removeTab(VIDEOTAB);
+        m_view.clip_path->setEnabled(false);
+        m_view.tabWidget->removeTab(SLIDETAB);
+        m_view.tabWidget->removeTab(AUDIOTAB);
+        m_view.tabWidget->removeTab(VIDEOTAB);
         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.tabWidget->removeTab(COLORTAB);
-       m_view.tabWidget->removeTab(AUDIOTAB);
-       m_view.tabWidget->removeTab(VIDEOTAB);
-       QStringList types;
-       types << "JPG" << "PNG" << "BMP" << "GIF";
-       m_view.image_type->addItems(types);
-       m_view.slide_loop->setChecked(props.value("loop").toInt());
-       QString path = props.value("resource");
-       if (path.endsWith("png")) m_view.image_type->setCurrentIndex(TYPE_PNG);
-       else if (path.endsWith("bmp")) m_view.image_type->setCurrentIndex(TYPE_BMP);
-       else if (path.endsWith("gif")) m_view.image_type->setCurrentIndex(TYPE_GIF);
-       m_view.slide_duration->setText(tc.getTimecodeFromFrames(props.value("ttl").toInt()));
-    }
-    else if (t != AUDIO) {
-       m_view.tabWidget->removeTab(SLIDETAB);
-       m_view.tabWidget->removeTab(COLORTAB);
+        m_view.clip_color->setColor(QColor("#" + props.value("colour").right(8).left(6)));
+    } else if (t == SLIDESHOW) {
+        m_view.clip_path->setText(url.directory());
+        m_view.tabWidget->removeTab(COLORTAB);
+        m_view.tabWidget->removeTab(AUDIOTAB);
+        m_view.tabWidget->removeTab(VIDEOTAB);
+        QStringList types;
+        types << "JPG" << "PNG" << "BMP" << "GIF";
+        m_view.image_type->addItems(types);
+        m_view.slide_loop->setChecked(props.value("loop").toInt());
+        QString path = props.value("resource");
+        if (path.endsWith("png")) m_view.image_type->setCurrentIndex(TYPE_PNG);
+        else if (path.endsWith("bmp")) m_view.image_type->setCurrentIndex(TYPE_BMP);
+        else if (path.endsWith("gif")) m_view.image_type->setCurrentIndex(TYPE_GIF);
+        m_view.slide_duration->setText(tc.getTimecodeFromFrames(props.value("ttl").toInt()));
+        parseFolder();
+        connect(m_view.image_type, SIGNAL(currentIndexChanged(int)), this, SLOT(parseFolder()));
+    } else if (t != AUDIO) {
+        m_view.tabWidget->removeTab(SLIDETAB);
+        m_view.tabWidget->removeTab(COLORTAB);
         if (props.contains("frame_size"))
             m_view.clip_size->setText(props.value("frame_size"));
         if (props.contains("videocodec"))
@@ -92,8 +93,8 @@ ClipProperties::ClipProperties(DocClipBase *clip, Timecode tc, double fps, QWidg
         m_view.clip_thumb->setPixmap(pix);
         if (t == IMAGE || t == VIDEO) m_view.tabWidget->removeTab(AUDIOTAB);
     } else {
-       m_view.tabWidget->removeTab(SLIDETAB);
-       m_view.tabWidget->removeTab(COLORTAB);
+        m_view.tabWidget->removeTab(SLIDETAB);
+        m_view.tabWidget->removeTab(COLORTAB);
         m_view.tabWidget->removeTab(VIDEOTAB);
         m_view.clip_thumb->setHidden(true);
     }
@@ -105,7 +106,7 @@ ClipProperties::ClipProperties(DocClipBase *clip, Timecode tc, double fps, QWidg
     adjustSize();
 }
 
-int ClipProperties::clipId() {
+int ClipProperties::clipId() const {
     return m_clip->getId();
 }
 
@@ -114,18 +115,92 @@ QMap <QString, QString> ClipProperties::properties() {
     QMap <QString, QString> props;
     props["description"] = m_view.clip_description->text();
     CLIPTYPE t = m_clip->clipType();
-    if (t == SLIDESHOW) {
-       props["loop"] = QString::number((int) m_view.slide_loop->isChecked());
-    }
-    else if (t == COLOR) {
-       QMap <QString, QString> old_props = m_clip->properties();
-       QString new_color = m_view.clip_color->color().name();
-       if (new_color != QString("#" + old_props.value("colour").right(8).left(6)))
-           props["colour"] = "0x" + new_color.right(6) + "ff";
+    if (t == COLOR) {
+        QMap <QString, QString> old_props = m_clip->properties();
+        QString new_color = m_view.clip_color->color().name();
+        if (new_color != QString("#" + old_props.value("colour").right(8).left(6))) {
+            m_clipNeedsRefresh = true;
+            props["colour"] = "0x" + new_color.right(6) + "ff";
+        }
+    } else if (t == SLIDESHOW) {
+        props["loop"] = QString::number((int) m_view.slide_loop->isChecked());
+        QMap <QString, QString> old_props = m_clip->properties();
+        QString extension;
+        switch (m_view.image_type->currentIndex()) {
+        case TYPE_PNG:
+            extension = "/.all.png";
+            break;
+        case TYPE_BMP:
+            extension = "/.all.bmp";
+            break;
+        case TYPE_GIF:
+            extension = "/.all.gif";
+            break;
+        default:
+            extension = "/.all.jpg";
+            break;
+        }
+        QString new_path = m_view.clip_path->text() + extension;
+        if (new_path != old_props.value("resource")) {
+            m_clipNeedsRefresh = true;
+            props["resource"] = new_path;
+            kDebug() << "////  SLIDE EDIT, NEW:" << new_path << ", OLD; " << old_props.value("resource");
+        }
+        int duration = m_tc.getFrameCount(m_view.slide_duration->text(), m_fps);
+        if (duration != old_props.value("ttl").toInt()) {
+            m_clipNeedsRefresh = true;
+            props["ttl"] = QString::number(duration);
+            props["out"] = QString::number(duration * m_count);
+        }
+        if (duration * m_count != old_props.value("out").toInt()) {
+            m_clipNeedsRefresh = true;
+            props["out"] = QString::number(duration * m_count);
+        }
+
     }
     return props;
 }
 
+bool ClipProperties::needsTimelineRefresh() const {
+    return m_clipNeedsRefresh;
+}
+
+void ClipProperties::parseFolder() {
+
+    QDir dir(m_view.clip_path->text());
+    QStringList filters;
+    QString extension;
+    switch (m_view.image_type->currentIndex()) {
+    case TYPE_PNG:
+        filters << "*.png";
+        extension = "/.all.png";
+        break;
+    case TYPE_BMP:
+        filters << "*.bmp";
+        extension = "/.all.bmp";
+        break;
+    case TYPE_GIF:
+        filters << "*.gif";
+        extension = "/.all.gif";
+        break;
+    default:
+        filters << "*.jpg" << "*.jpeg";
+        extension = "/.all.jpg";
+        break;
+    }
+
+    dir.setNameFilters(filters);
+    QStringList result = dir.entryList(QDir::Files);
+    m_count = result.count();
+    m_view.slide_info->setText(i18n("%1 images found", m_count));
+    QDomElement xml = m_clip->toXML();
+    xml.setAttribute("resource", m_view.clip_path->text() + extension);
+    QPixmap pix = m_clip->thumbProducer()->getImage(xml, 1, 240, 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);
+}
+
 #include "clipproperties.moc"