From 09a7882d8a0f2a897f1be4fb8e9418d0666d712a Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Mardelle Date: Sat, 26 Jan 2008 10:37:51 +0000 Subject: [PATCH] Start of image clips svn path=/branches/KDE4/; revision=1822 --- src/addclipcommand.cpp | 2 ++ src/addtimelineclipcommand.cpp | 2 ++ src/clipitem.cpp | 20 +++++++++++++++---- src/customtrackview.cpp | 6 +++--- src/definitions.h | 1 + src/kthumb.cpp | 35 +++++++++++++++++++++++++++++++++- src/kthumb.h | 1 + src/moveclipcommand.cpp | 2 ++ src/projectitem.cpp | 34 +++++++++++++++++++-------------- src/projectitem.h | 7 ++++--- src/projectlist.cpp | 20 ++++++++++++++----- src/projectlist.h | 2 +- src/resizeclipcommand.cpp | 2 ++ 13 files changed, 103 insertions(+), 31 deletions(-) diff --git a/src/addclipcommand.cpp b/src/addclipcommand.cpp index 80e43df7..1e8b961e 100644 --- a/src/addclipcommand.cpp +++ b/src/addclipcommand.cpp @@ -17,6 +17,8 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ +#include + #include "addclipcommand.h" AddClipCommand::AddClipCommand(ProjectList *list, const QStringList &names, const QDomElement &xml, const int id, const KUrl &url, const QString &group, bool doIt) diff --git a/src/addtimelineclipcommand.cpp b/src/addtimelineclipcommand.cpp index de33fa99..27504a0b 100644 --- a/src/addtimelineclipcommand.cpp +++ b/src/addtimelineclipcommand.cpp @@ -17,6 +17,8 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ +#include + #include "addtimelineclipcommand.h" AddTimelineClipCommand::AddTimelineClipCommand(CustomTrackView *view, QDomElement xml, int track, int startpos, QRectF rect, int duration, bool doIt) diff --git a/src/clipitem.cpp b/src/clipitem.cpp index e901c8f2..da4a72f0 100644 --- a/src/clipitem.cpp +++ b/src/clipitem.cpp @@ -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); diff --git a/src/customtrackview.cpp b/src/customtrackview.cpp index 94ae3628..8ab4773c 100644 --- a/src/customtrackview.cpp +++ b/src/customtrackview.cpp @@ -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: "<addItem(m_dropItem); } diff --git a/src/definitions.h b/src/definitions.h index 41b8976e..b3e883ec 100644 --- a/src/definitions.h +++ b/src/definitions.h @@ -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}; diff --git a/src/kthumb.cpp b/src/kthumb.cpp index b3a3cb0f..57104951 100644 --- a/src/kthumb.cpp +++ b/src/kthumb.cpp @@ -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; } diff --git a/src/kthumb.h b/src/kthumb.h index a3b73b01..27cfd6a9 100644 --- a/src/kthumb.h +++ b/src/kthumb.h @@ -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(); diff --git a/src/moveclipcommand.cpp b/src/moveclipcommand.cpp index e0f04325..9b35f85d 100644 --- a/src/moveclipcommand.cpp +++ b/src/moveclipcommand.cpp @@ -17,6 +17,8 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ +#include + #include "moveclipcommand.h" MoveClipCommand::MoveClipCommand(CustomTrackView *view, const QPointF startPos, const QPointF endPos, bool doIt) diff --git a/src/projectitem.cpp b/src/projectitem.cpp index 3b4cdf40..a2dd1724 100644 --- a/src/projectitem.cpp +++ b/src/projectitem.cpp @@ -31,13 +31,14 @@ #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); /* diff --git a/src/projectitem.h b/src/projectitem.h index 692d4581..083db29a 100644 --- a/src/projectitem.h +++ b/src/projectitem.h @@ -25,9 +25,10 @@ #include #include -#include "gentime.h" -#include "docclipbase.h" +#include +#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; diff --git a/src/projectlist.cpp b/src/projectlist.cpp index ea663189..d7464702 100644 --- a/src/projectlist.cpp +++ b/src/projectlist.cpp @@ -39,6 +39,7 @@ #include "ui_colorclip_ui.h" #include "addclipcommand.h" +#include "definitions.h" #include @@ -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, "#"); diff --git a/src/projectlist.h b/src/projectlist.h index 6495944a..66ce9c6c 100644 --- a/src/projectlist.h +++ b/src/projectlist.h @@ -28,7 +28,7 @@ #include #include -#include "docclipbase.h" +#include "definitions.h" #include "kdenlivedoc.h" #include "renderer.h" #include "timecode.h" diff --git a/src/resizeclipcommand.cpp b/src/resizeclipcommand.cpp index 52634cc3..887c80ea 100644 --- a/src/resizeclipcommand.cpp +++ b/src/resizeclipcommand.cpp @@ -17,6 +17,8 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ +#include + #include "resizeclipcommand.h" ResizeClipCommand::ResizeClipCommand(CustomTrackView *view, const QPointF startPos, const QPointF endPos, bool resizeClipStart, bool doIt) -- 2.39.5