]> git.sesse.net Git - kdenlive/commitdiff
Start of image clips
authorJean-Baptiste Mardelle <jb@kdenlive.org>
Sat, 26 Jan 2008 10:37:51 +0000 (10:37 +0000)
committerJean-Baptiste Mardelle <jb@kdenlive.org>
Sat, 26 Jan 2008 10:37:51 +0000 (10:37 +0000)
svn path=/branches/KDE4/; revision=1822

13 files changed:
src/addclipcommand.cpp
src/addtimelineclipcommand.cpp
src/clipitem.cpp
src/customtrackview.cpp
src/definitions.h
src/kthumb.cpp
src/kthumb.h
src/moveclipcommand.cpp
src/projectitem.cpp
src/projectitem.h
src/projectlist.cpp
src/projectlist.h
src/resizeclipcommand.cpp

index 80e43df79dba7bce857d7a77fbc7d7220512d04b..1e8b961e2436b57d98aa79c511dabcafbd2b4e53 100644 (file)
@@ -17,6 +17,8 @@
  *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA          *
  ***************************************************************************/
 
+#include <KLocale>
+
 #include "addclipcommand.h"
 
 AddClipCommand::AddClipCommand(ProjectList *list, const QStringList &names, const QDomElement &xml, const int id, const KUrl &url, const QString &group, bool doIt)
index de33fa997fd1945bbabfede279fdf9e4346691dc..27504a0b74e420312010b879d75ff9a93e9d1dd6 100644 (file)
@@ -17,6 +17,8 @@
  *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA          *
  ***************************************************************************/
 
+#include <KLocale>
+
 #include "addtimelineclipcommand.h"
 
 AddTimelineClipCommand::AddTimelineClipCommand(CustomTrackView *view, QDomElement xml, int track, int startpos, QRectF rect, int duration, bool doIt)
index e901c8f225a066efc6b2f966cf73292d6d637944..da4a72f0b28dba323ced9dabb2878e28fddf012a 100644 (file)
@@ -74,6 +74,9 @@ ClipItem::ClipItem(QDomElement xml, int track, int startpos, const QRectF & rect
     colour = colour.replace(0, 2, "#");
     setBrush(QColor(colour.left(7)));
   }
+  else if (m_clipType == IMAGE) {
+    m_startPix = KThumb::getImage(KUrl(xml.attribute("resource")), 50 * KdenliveSettings::project_display_ratio(), 50);
+  }
   //m_startPix.load("/home/one/Desktop/thumb.jpg");
 }
 
@@ -178,10 +181,18 @@ int ClipItem::endPos()
     //painter->fillPath(roundRectPath, brush()); //, QBrush(QColor(Qt::red)));
     painter->fillRect(br, brush());
     //painter->fillRect(QRectF(br.x() + br.width() - m_endPix.width(), br.y(), m_endPix.width(), br.height()), QBrush(QColor(Qt::black)));
+
+    // draw thumbnails
     if (!m_startPix.isNull()) {
-      painter->drawPixmap(QPointF(br.x() + br.width() - m_endPix.width(), br.y()), m_endPix);
-      QLineF l(br.x() + br.width() - m_endPix.width(), br.y(), br.x() + br.width() - m_endPix.width(), br.y() + br.height());
-      painter->drawLine(l);
+      if (m_clipType == IMAGE) {
+       painter->drawPixmap(QPointF(br.x() + br.width() - m_startPix.width(), br.y()), m_startPix);
+       QLineF l(br.x() + br.width() - m_startPix.width(), br.y(), br.x() + br.width() - m_startPix.width(), br.y() + br.height());
+       painter->drawLine(l);
+      } else {
+       painter->drawPixmap(QPointF(br.x() + br.width() - m_endPix.width(), br.y()), m_endPix);
+       QLineF l(br.x() + br.width() - m_endPix.width(), br.y(), br.x() + br.width() - m_endPix.width(), br.y() + br.height());
+       painter->drawLine(l);
+      }
 
       painter->drawPixmap(QPointF(br.x(), br.y()), m_startPix);
       QLineF l2(br.x() + m_startPix.width(), br.y(), br.x() + m_startPix.width(), br.y() + br.height());
@@ -191,7 +202,8 @@ int ClipItem::endPos()
     QPen pen = painter->pen();
     pen.setColor(Qt::red);
     pen.setStyle(Qt::DashDotDotLine); //Qt::DotLine);
-    
+
+    // Draw clip name
     QRectF txtBounding = painter->boundingRect(br, Qt::AlignCenter, " " + m_clipName + " ");
     painter->fillRect(txtBounding, QBrush(QColor(255,255,255,150)));
     painter->drawText(txtBounding, Qt::AlignCenter, m_clipName);
index 94ae3628851d01754a51489e6e65356e547118c1..8ab4773cae7f7e2cbf3959b7acc17ba6b335f825 100644 (file)
@@ -300,11 +300,11 @@ void CustomTrackView::addItem(QString producer, QPoint pos)
   doc.setContent(producer);
   QDomElement elem = doc.documentElement();
   int in = elem.attribute("in", 0).toInt();
-  int out = elem.attribute("duration", 0).toInt();
-  if (out == 0) out = elem.attribute("out", 0).toInt() - in;
+  int out = elem.attribute("out", 0).toInt() - in;
+  if (out == 0) out = elem.attribute("duration", 0).toInt();
   kDebug()<<"ADDING CLIP: "<<producer<<", OUT: "<<out<<", POS: "<<mapToScene(pos);
   int trackTop = ((int) mapToScene(pos).y()/50) * 50 + 1;
-  m_dropItem = new ClipItem(elem, ((int) mapToScene(pos).y()/50), in, QRectF(mapToScene(pos).x() * m_scale, trackTop, out * m_scale, 49));
+  m_dropItem = new ClipItem(elem, ((int) mapToScene(pos).y()/50), in, QRectF(mapToScene(pos).x() * m_scale, trackTop, out * m_scale, 49), out);
   scene()->addItem(m_dropItem);
 }
 
index 41b8976ef451eb9c65116d486c81bb5c83344e40..b3e883ecd6af28d97f2264ec30ead5d1d8179444 100644 (file)
@@ -22,6 +22,7 @@
 #define DEFINITIONS_H
 
 #define FRAME_SIZE 90
+#define MAXCLIPDURATION 15000
 
 enum OPERATIONTYPE { NONE = 0, MOVE = 1, RESIZESTART = 2, RESIZEEND = 3, FADEIN = 4, FADEOUT = 5};
 enum CLIPTYPE { UNKNOWN = 0, AUDIO = 1, VIDEO = 2, AV = 3, COLOR = 4, IMAGE = 5, TEXT = 6, SLIDESHOW = 7, VIRTUAL = 8, PLAYLIST = 9};
index b3a3cb0f7e3a0bf32c20e1b40bae3e7761a5b265..571049510c1fcf0cb91eedacd43892f91ec9bbb5 100644 (file)
@@ -140,6 +140,39 @@ KThumb::~KThumb()
     //if (thumbProducer.running ()) thumbProducer.exit();
 }
 
+
+//static
+QPixmap KThumb::getImage(KUrl url, int width, int height)
+{
+    if (url.isEmpty()) return QPixmap();
+    QPixmap pix(width, height);
+    char *tmp = Render::decodedString(url.path());
+    Mlt::Producer m_producer(tmp);
+    delete tmp;
+
+    if (m_producer.is_blank()) {
+       pix.fill(Qt::black);
+       return pix;
+    }
+    Mlt::Frame * m_frame;
+    mlt_image_format format = mlt_image_rgb24a;
+    Mlt::Filter m_convert("avcolour_space");
+    m_convert.set("forced", mlt_image_rgb24a);
+    m_producer.attach(m_convert);
+    //m_producer.seek(frame);
+    m_frame = m_producer.get_frame();
+    if (m_frame && m_frame->is_valid()) {
+      uint8_t *thumb = m_frame->get_image(format, width, height);
+      QImage image(thumb, width, height, QImage::Format_ARGB32);
+      if (!image.isNull()) {
+       pix = pix.fromImage(image);
+      }
+      else pix.fill(Qt::black);
+    }
+    if (m_frame) delete m_frame;
+    return pix;
+}
+
 void KThumb::extractImage(int frame, int frame2, int width, int height)
 {
     if (m_url.isEmpty()) return;
@@ -147,9 +180,9 @@ void KThumb::extractImage(int frame, int frame2, int width, int height)
     char *tmp = Render::decodedString(m_url.path());
     Mlt::Producer m_producer(tmp);
     delete tmp;
-    pix.fill(Qt::black);
 
     if (m_producer.is_blank()) {
+       pix.fill(Qt::black);
        emit thumbReady(frame, pix);
        return;
     }
index a3b73b013b6aa2ad13fc73025de9626179aa7c8f..27cfd6a98c3d484515dd3b4ed60cabcaea08918c 100644 (file)
@@ -72,6 +72,7 @@ class KThumb:public QObject {
 
 public slots:
        void extractImage( int frame, int frame2, int width, int height);
+       static QPixmap getImage(KUrl url, int width, int height);
 /*     void getImage(KUrl url, int frame, int width, int height);
        void getThumbs(KUrl url, int startframe, int endframe, int width, int height);
        void stopAudioThumbs();
index e0f04325bdbc9489935ab1a7fd16655de5e7b15b..9b35f85d335655ef5c40a962a48f84684aa8a9b5 100644 (file)
@@ -17,6 +17,8 @@
  *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA          *
  ***************************************************************************/
 
+#include <KLocale>
+
 #include "moveclipcommand.h"
 
 MoveClipCommand::MoveClipCommand(CustomTrackView *view, const QPointF startPos, const QPointF endPos, bool doIt)
index 3b4cdf40adf77c521998b980f4b6359cfa50c178..a2dd17244285b1a7f76cf73f419abc02992a6031 100644 (file)
 #include "projectitem.h"
 #include "timecode.h"
 
+
   const int NameRole = Qt::UserRole;
   const int DurationRole = NameRole + 1;
   const int FullPathRole = NameRole + 2;
   const int ClipTypeRole = NameRole + 3;
 
 ProjectItem::ProjectItem(QTreeWidget * parent, const QStringList & strings, QDomElement xml, int clipId)
-    : QTreeWidgetItem(parent, strings, QTreeWidgetItem::UserType), m_clipType(DocClipBase::NONE), m_clipId(clipId), m_isGroup(false), m_groupName(QString::null)
+    : QTreeWidgetItem(parent, strings, QTreeWidgetItem::UserType), m_clipType(UNKNOWN), m_clipId(clipId), m_isGroup(false), m_groupName(QString::null)
 {
   m_element = xml.cloneNode().toElement();
   setSizeHint(0, QSize(65, 45));
@@ -46,14 +47,19 @@ ProjectItem::ProjectItem(QTreeWidget * parent, const QStringList & strings, QDom
     m_element.setAttribute("id", clipId);
     QString cType = m_element.attribute("type", QString::null);
     if (!cType.isEmpty()) {
-      m_clipType = (DocClipBase::CLIPTYPE) cType.toInt();
+      m_clipType = (CLIPTYPE) cType.toInt();
       slotSetToolTip();
     }
+
+    if (m_clipType == COLOR || m_clipType == IMAGE) m_element.setAttribute("duration", MAXCLIPDURATION);
+    else if (m_element.attribute("duration").isEmpty() && !m_element.attribute("out").isEmpty()) {
+      m_element.setAttribute("duration", m_element.attribute("out").toInt() - m_element.attribute("in").toInt());
+    }
   }
 }
 
 ProjectItem::ProjectItem(QTreeWidgetItem * parent, const QStringList & strings, QDomElement xml, int clipId)
-    : QTreeWidgetItem(parent, strings, QTreeWidgetItem::UserType), m_clipType(DocClipBase::NONE), m_clipId(clipId), m_isGroup(false), m_groupName(QString::null)
+    : QTreeWidgetItem(parent, strings, QTreeWidgetItem::UserType), m_clipType(UNKNOWN), m_clipId(clipId), m_isGroup(false), m_groupName(QString::null)
 {
   m_element = xml.cloneNode().toElement();
   setSizeHint(0, QSize(65, 45));
@@ -62,14 +68,14 @@ ProjectItem::ProjectItem(QTreeWidgetItem * parent, const QStringList & strings,
     m_element.setAttribute("id", clipId);
     QString cType = m_element.attribute("type", QString::null);
     if (!cType.isEmpty()) {
-      m_clipType = (DocClipBase::CLIPTYPE) cType.toInt();
+      m_clipType = (CLIPTYPE) cType.toInt();
       slotSetToolTip();
     }
   }
 }
 
 ProjectItem::ProjectItem(QTreeWidget * parent, const QStringList & strings, int clipId)
-    : QTreeWidgetItem(parent, strings, QTreeWidgetItem::UserType), m_element(QDomElement()), m_clipType(DocClipBase::NONE), m_clipId(clipId), m_isGroup(true), m_groupName(strings.at(1))
+    : QTreeWidgetItem(parent, strings, QTreeWidgetItem::UserType), m_element(QDomElement()), m_clipType(UNKNOWN), m_clipId(clipId), m_isGroup(true), m_groupName(strings.at(1))
 {
   setSizeHint(0, QSize(65, 45));
   setFlags(Qt::ItemIsSelectable | Qt::ItemIsDragEnabled | Qt::ItemIsEnabled);
@@ -116,7 +122,7 @@ QDomElement ProjectItem::toXml() const
 
 const KUrl ProjectItem::clipUrl() const
 {
-    if (m_clipType != DocClipBase::COLOR && m_clipType != DocClipBase::VIRTUAL && m_clipType != DocClipBase::NONE)
+    if (m_clipType != COLOR && m_clipType != VIRTUAL && m_clipType != UNKNOWN)
       return KUrl(m_element.attribute("resouce"));
     else return KUrl();
 }
@@ -165,7 +171,7 @@ void ProjectItem::slotSetToolTip()
 void ProjectItem::setProperties(const QMap < QString, QString > &attributes, const QMap < QString, QString > &metadata)
 {
        if (attributes.contains("duration")) {
-           if (m_clipType == DocClipBase::AUDIO || m_clipType == DocClipBase::VIDEO || m_clipType == DocClipBase::AV) m_element.setAttribute("duration", attributes["duration"].toInt());
+           if (m_clipType == AUDIO || m_clipType == VIDEO || m_clipType == AV) m_element.setAttribute("duration", attributes["duration"].toInt());
            m_duration = GenTime(attributes["duration"].toInt(), 25);
            setData(1, DurationRole, Timecode::getEasyTimecode(m_duration, 25));
            m_durationKnown = true;
@@ -178,18 +184,18 @@ void ProjectItem::setProperties(const QMap < QString, QString > &attributes, con
 
        //extend attributes -reh
 
-       if (m_clipType == DocClipBase::NONE) {
+       if (m_clipType == UNKNOWN) {
          if (attributes.contains("type")) {
            if (attributes["type"] == "audio")
-               m_clipType = DocClipBase::AUDIO;
+               m_clipType = AUDIO;
            else if (attributes["type"] == "video")
-               m_clipType = DocClipBase::VIDEO;
+               m_clipType = VIDEO;
            else if (attributes["type"] == "av")
-               m_clipType = DocClipBase::AV;
+               m_clipType = AV;
            else if (attributes["type"] == "playlist")
-               m_clipType = DocClipBase::PLAYLIST;
+               m_clipType = PLAYLIST;
          } else {
-           m_clipType = DocClipBase::AV;
+           m_clipType = AV;
          }
        }
        slotSetToolTip();
@@ -197,8 +203,8 @@ void ProjectItem::setProperties(const QMap < QString, QString > &attributes, con
        if (m_element.isNull()) {
          QDomDocument doc;
          m_element = doc.createElement("producer");
-         m_element.setAttribute("duration", attributes["duration"].toInt());
        }
+       if (m_element.attribute("duration") == QString::null) m_element.setAttribute("duration", attributes["duration"].toInt());
        m_element.setAttribute("resource", attributes["filename"]);
        m_element.setAttribute("type", (int) m_clipType);
 /*
index 692d4581a8d5ca0b5e40288e9914b6753795576e..083db29a2b505296bd9dd51af9a549c08ab6ceb5 100644 (file)
 #include <QTreeWidget>
 #include <QDomElement>
 
-#include "gentime.h"
-#include "docclipbase.h"
+#include <KUrl>
 
+#include "gentime.h"
+#include "definitions.h"
 
 class ProjectItem : public QTreeWidgetItem
 {
@@ -50,7 +51,7 @@ class ProjectItem : public QTreeWidgetItem
     QDomElement m_element;
     GenTime m_duration;
     bool m_durationKnown;
-    DocClipBase::CLIPTYPE m_clipType;
+    CLIPTYPE m_clipType;
     int m_clipId;
     void slotSetToolTip();
     bool m_isGroup;
index ea66318916ce7a79b1c0fce46e1e5d1076c34e45..d7464702df91695b97c12485e0f9bff53d8e6c92 100644 (file)
@@ -39,6 +39,7 @@
 #include "ui_colorclip_ui.h"
 
 #include "addclipcommand.h"
+#include "definitions.h"
 
 #include <QtGui>
 
@@ -323,9 +324,18 @@ void ProjectList::slotAddClip(QUrl givenUrl, const QString &group)
 
   for (it = list.begin(); it != list.end(); it++) {
       QStringList itemEntry;
+      QDomDocument doc;
+      QDomElement prod = doc.createElement("producer");
+      prod.setAttribute("resource", (*it).path());
       itemEntry.append(QString::null);
       itemEntry.append((*it).fileName());
-      AddClipCommand *command = new AddClipCommand(this, itemEntry, QDomElement(), m_clipIdCounter++, *it, group, true);
+      KMimeType::Ptr type = KMimeType::findByUrl(*it);
+      if (type->name().startsWith("image/")) {
+       prod.setAttribute("type", (int) IMAGE);
+       prod.setAttribute("in", "0");
+       prod.setAttribute("out", m_timecode.getFrameCount(KdenliveSettings::image_duration(), m_fps));
+      }
+      AddClipCommand *command = new AddClipCommand(this, itemEntry, prod, m_clipIdCounter++, *it, group, true);
       m_commandStack->push(command);
       //item = new ProjectItem(listView, itemEntry, QDomElement());
       //item->setData(1, FullPathRole, (*it).path());
@@ -349,7 +359,7 @@ void ProjectList::slotAddColorClip()
     QString color = dia_ui->clip_color->color().name();
     color = color.replace(0, 1, "0x") + "ff";
     element.setAttribute("colour", color);
-    element.setAttribute("type", (int) DocClipBase::COLOR);
+    element.setAttribute("type", (int) COLOR);
     element.setAttribute("in", "0");
     element.setAttribute("out", m_timecode.getFrameCount(dia_ui->clip_duration->text(), m_fps));
     element.setAttribute("name", dia_ui->clip_name->text());
@@ -437,7 +447,7 @@ ProjectItem *ProjectList::getItemById(int id)
 void ProjectList::addProducer(QDomElement producer, int parentId)
 {
   if (!m_commandStack) kDebug()<<"!!!!!!!!!!!!!!!!  NO CMD STK";
-  DocClipBase::CLIPTYPE type = (DocClipBase::CLIPTYPE) producer.attribute("type").toInt();
+  CLIPTYPE type = (CLIPTYPE) producer.attribute("type").toInt();
 
     /*QDomDocument doc;
     QDomElement prods = doc.createElement("list");
@@ -455,7 +465,7 @@ void ProjectList::addProducer(QDomElement producer, int parentId)
     // item is a westley playlist, adjust subproducers ids 
     id = (parentId + 1) * 10000 + id;
   }
-  if (type == DocClipBase::AUDIO || type == DocClipBase::VIDEO || type == DocClipBase::AV || type == DocClipBase::IMAGE  || type == DocClipBase::PLAYLIST)
+  if (type == AUDIO || type == VIDEO || type == AV || type == IMAGE  || type == PLAYLIST)
   {
     KUrl resource = KUrl(producer.attribute("resource"));
     if (!resource.isEmpty()) {
@@ -473,7 +483,7 @@ void ProjectList::addProducer(QDomElement producer, int parentId)
       
     }
   }
-  else if (type == DocClipBase::COLOR) {
+  else if (type == COLOR) {
     QString colour = producer.attribute("colour");
     QPixmap pix(60, 40);
     colour = colour.replace(0, 2, "#");
index 6495944a3f9f489b2dbface814d3f89086434eda..66ce9c6c8ee73d47ade2788482226eaa9d099cc7 100644 (file)
@@ -28,7 +28,7 @@
 #include <KUndoStack>
 #include <KTreeWidgetSearchLine>
 
-#include "docclipbase.h"
+#include "definitions.h"
 #include "kdenlivedoc.h"
 #include "renderer.h"
 #include "timecode.h"
index 52634cc30d5a06cefeb2962eaa52dc429d27a897..887c80ea2208f1723397f2b742125e9e44636b82 100644 (file)
@@ -17,6 +17,8 @@
  *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA          *
  ***************************************************************************/
 
+#include <KLocale>
+
 #include "resizeclipcommand.h"
 
 ResizeClipCommand::ResizeClipCommand(CustomTrackView *view, const QPointF startPos, const QPointF endPos, bool resizeClipStart, bool doIt)