From d7e36a99467373e2a33cec7c693e91c8c3371c88 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Mardelle Date: Fri, 25 Jan 2008 23:31:09 +0000 Subject: [PATCH] More work on timeline widget svn path=/branches/KDE4/; revision=1819 --- src/CMakeLists.txt | 1 + src/addtimelineclipcommand.cpp | 6 +- src/addtimelineclipcommand.h | 10 +- src/clipitem.cpp | 156 ++++++++++++---- src/clipitem.h | 31 +++- src/customtrackview.cpp | 98 +++++++--- src/customtrackview.h | 5 +- src/kdenlivesettings.kcfg | 7 + src/kthumb.cpp | 323 +++++++++++++++++++++++++++++++++ src/kthumb.h | 91 ++++++++++ src/labelitem.cpp | 5 +- src/trackview.cpp | 13 +- 12 files changed, 662 insertions(+), 84 deletions(-) create mode 100644 src/kthumb.cpp create mode 100644 src/kthumb.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 6a8c9637..a6800013 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -56,6 +56,7 @@ set(kdenlive_SRCS moveclipcommand.cpp resizeclipcommand.cpp addtimelineclipcommand.cpp + kthumb.cpp ) kde4_add_kcfg_files(kdenlive_SRCS GENERATE_MOC kdenlivesettings.kcfgc ) diff --git a/src/addtimelineclipcommand.cpp b/src/addtimelineclipcommand.cpp index b8ab71b0..de33fa99 100644 --- a/src/addtimelineclipcommand.cpp +++ b/src/addtimelineclipcommand.cpp @@ -19,8 +19,8 @@ #include "addtimelineclipcommand.h" -AddTimelineClipCommand::AddTimelineClipCommand(CustomTrackView *view, int clipType, QString clipName, int clipProducer, int maxDuration, QRectF rect, bool doIt) - : m_view(view), m_clipType(clipType), m_clipName(clipName), m_clipProducer(clipProducer), m_maxDuration(maxDuration), m_clipRect(rect), m_doIt(doIt) { +AddTimelineClipCommand::AddTimelineClipCommand(CustomTrackView *view, QDomElement xml, int track, int startpos, QRectF rect, int duration, bool doIt) + : m_view(view), m_xml(xml), m_clipTrack(track), m_clipPos(startpos), m_clipRect(rect), m_clipDuration(duration), m_doIt(doIt) { setText(i18n("Add timeline clip")); } @@ -36,7 +36,7 @@ void AddTimelineClipCommand::undo() void AddTimelineClipCommand::redo() { //kDebug()<<"---- redoing action"; - if (m_doIt) m_view->addClip(m_clipType, m_clipName, m_clipProducer, m_maxDuration, m_clipRect); + if (m_doIt) m_view->addClip(m_xml, m_clipTrack, m_clipPos, m_clipRect, m_clipDuration); m_doIt = true; } diff --git a/src/addtimelineclipcommand.h b/src/addtimelineclipcommand.h index ad907a02..e163d810 100644 --- a/src/addtimelineclipcommand.h +++ b/src/addtimelineclipcommand.h @@ -33,16 +33,16 @@ class AddTimelineClipCommand : public QUndoCommand { public: - AddTimelineClipCommand(CustomTrackView *view, int clipType, QString clipName, int clipProducer, int maxDuration, QRectF rect, bool doIt); + AddTimelineClipCommand(CustomTrackView *view, QDomElement xml, int track, int startpos, QRectF rect, int duration, bool doIt); virtual void undo(); virtual void redo(); private: CustomTrackView *m_view; - int m_clipType; - QString m_clipName; - int m_clipProducer; - int m_maxDuration; + int m_clipDuration; + QDomElement m_xml; + int m_clipTrack; + int m_clipPos; QRectF m_clipRect; bool m_doIt; }; diff --git a/src/clipitem.cpp b/src/clipitem.cpp index a97ffb9a..1e1049f5 100644 --- a/src/clipitem.cpp +++ b/src/clipitem.cpp @@ -20,24 +20,63 @@ #include +#include #include #include + + #include +#include #include "clipitem.h" +#include "renderer.h" +#include "kdenlivesettings.h" -ClipItem::ClipItem(int clipType, QString name, int producer, int maxDuration, const QRectF & rect) - : QGraphicsRectItem(rect), m_resizeMode(NONE), m_grabPoint(0), m_clipType(clipType), m_clipName(name), m_producer(producer), m_cropStart(0), m_cropDuration(maxDuration), m_maxDuration(maxDuration), m_maxTrack(0) +ClipItem::ClipItem(QDomElement xml, int track, int startpos, const QRectF & rect, int duration) + : QGraphicsRectItem(rect), m_xml(xml), m_resizeMode(NONE), m_grabPoint(0), m_maxTrack(0), m_track(track), m_startPos(startpos) { - setToolTip(name); + //setToolTip(name); + + m_clipName = xml.attribute("name"); + if (m_clipName.isEmpty()) m_clipName = KUrl(xml.attribute("resource")).fileName(); + + m_producer = xml.attribute("id").toInt(); + + m_clipType = xml.attribute("type").toInt(); + + m_cropStart = xml.attribute("in", 0).toInt(); + m_maxDuration = xml.attribute("duration", 0).toInt(); + if (m_maxDuration == 0) m_maxDuration = xml.attribute("out", 0).toInt() - m_cropStart; + + if (duration != -1) m_cropDuration = duration; + else m_cropDuration = m_maxDuration; + //setCursor(Qt::SizeHorCursor); setFlags(QGraphicsItem::ItemClipsToShape | QGraphicsItem::ItemClipsChildrenToShape | QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable); - m_label = new LabelItem( name, this); + m_label = new LabelItem( m_clipName, this); QRectF textRect = m_label->boundingRect(); m_textWidth = textRect.width(); m_label->setPos(rect.x() + rect.width()/2 - m_textWidth/2, rect.y() + rect.height() / 2 - textRect.height()/2); setBrush(QColor(100, 100, 150)); + m_thumbProd = new KThumb(KUrl(xml.attribute("resource"))); + connect(this, SIGNAL(getThumb(int, int, int, int)), m_thumbProd, SLOT(extractImage(int, int, int, int))); + connect(m_thumbProd, SIGNAL(thumbReady(int, QPixmap)), this, SLOT(slotThumbReady(int, QPixmap))); + QTimer::singleShot(300, this, SLOT(slotFetchThumbs())); + + //m_startPix.load("/home/one/Desktop/thumb.jpg"); +} + +void ClipItem::slotFetchThumbs() +{ + emit getThumb(m_cropStart, m_cropStart + m_cropDuration, 50 * KdenliveSettings::project_display_ratio(), 50); +} + +void ClipItem::slotThumbReady(int frame, QPixmap pix) +{ + if (frame == m_cropStart) m_startPix = pix; + else m_endPix = pix; + update(); } int ClipItem::type () const @@ -45,6 +84,11 @@ int ClipItem::type () const return 70000; } +QDomElement ClipItem::xml() const +{ + return m_xml; +} + int ClipItem::clipType() { return m_clipType; @@ -65,34 +109,64 @@ int ClipItem::maxDuration() return m_maxDuration; } +int ClipItem::duration() +{ + return m_cropDuration; +} + +int ClipItem::startPos() +{ + return m_startPos; +} + // virtual void ClipItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) { + QRectF br = rect(); + painter->setRenderHints(QPainter::Antialiasing); + QPainterPath roundRectPath; + double roundingY = 20; + double roundingX = 20; + double offset = 1; + painter->setClipRect(option->exposedRect); + if (roundingX > br.width() / 2) roundingX = br.width() / 2; + //kDebug()<<"-----PAINTING, SCAL: "<fillPath(roundRectPath, brush()); //, QBrush(QColor(Qt::red))); + painter->setClipPath(roundRectPath, Qt::IntersectClip); + 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->setClipRect( option->exposedRect ); - /*painter->setRenderHint(QPainter::TextAntialiasing); - painter->fillRect(rect(), QColor(200, 50, 50, 150)); - QPointF pos = option->matrix.map(QPointF(1.0, 1.0)); - //painter->setPen(QPen(Qt::black, 1.0 / option->levelOfDetail)); - painter->setPen(QPen(Qt::black, 1.0 / pos.x())); - double scale = 1.0 / pos.x(); - //QPointF size = option->matrix.map(QPointF(1, 1)); - //double off = painter->pen().width(); - QRectF br = boundingRect(); - QRectF recta(rect().x(), rect().y(), scale,rect().height()); + 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()); + painter->drawLine(l2); + painter->setClipRect(option->exposedRect); + painter->drawPath(roundRectPath); + //painter->fillRect(QRect(br.x(), br.y(), roundingX, roundingY), QBrush(QColor(Qt::green))); + + /*QRectF recta(rect().x(), rect().y(), scale,rect().height()); painter->drawRect(recta); - //painter->drawLine(rect().x() + 1, rect().y(), rect().x() + 1, rect().y() + rect().height()); + painter->drawLine(rect().x() + 1, rect().y(), rect().x() + 1, rect().y() + rect().height()); painter->drawLine(rect().x() + rect().width(), rect().y(), rect().x() + rect().width(), rect().y() + rect().height()); - painter->setPen(QPen(Qt::black, 1.0 / pos.y())); + painter->setPen(QPen(Qt::black, 1.0)); painter->drawLine(rect().x(), rect().y(), rect().x() + rect().width(), rect().y()); painter->drawLine(rect().x(), rect().y() + rect().height(), rect().x() + rect().width(), rect().y() + rect().height());*/ - QGraphicsRectItem::paint(painter, option, widget); + //QGraphicsRectItem::paint(painter, option, widget); //QPen pen(Qt::green, 1.0 / size.x() + 0.5); //painter->setPen(pen); - //painter->drawLine(rect().x(), rect().y(), rect().x() + rect().width(), rect().y());*/ + //painter->drawLine(rect().x(), rect().y(), rect().x() + rect().width(), rect().y()); //kDebug()<<"ITEM REPAINT RECT: "<drawText(rect(), Qt::AlignCenter, m_name); // painter->drawRect(boundingRect()); @@ -113,6 +187,7 @@ OPERATIONTYPE ClipItem::operationMode(QPointF pos) return MOVE; } + // virtual void ClipItem::mousePressEvent ( QGraphicsSceneMouseEvent * event ) { @@ -131,17 +206,18 @@ OPERATIONTYPE ClipItem::operationMode(QPointF pos) QGraphicsRectItem::mouseReleaseEvent(event); } - void ClipItem::moveTo(double x, double offset) + void ClipItem::moveTo(double x, double scale, double offset, int newTrack) { double origX = rect().x(); double origY = rect().y(); - setRect(x, origY + offset, rect().width(), rect().height()); - - QList collisionList = collidingItems(Qt::IntersectsItemBoundingRect); - for (int i = 0; i < collisionList.size(); ++i) { - QGraphicsItem *item = collisionList.at(i); - if (item->type() == 70000) - { + bool success = true; + setRect(x, origY + offset, rect().width(), rect().height()); + QList collisionList = collidingItems(Qt::IntersectsItemBoundingRect); + if (collisionList.size() == 0) m_track = newTrack; + for (int i = 0; i < collisionList.size(); ++i) { + QGraphicsItem *item = collisionList.at(i); + if (item->type() == 70000) + { if (offset == 0) { QRectF other = ((QGraphicsRectItem *)item)->rect(); @@ -157,11 +233,15 @@ OPERATIONTYPE ClipItem::operationMode(QPointF pos) setRect(origX, origY, rect().width(), rect().height()); offset = 0; origX = rect().x(); + success = false; break; } } - - QList childrenList = children(); + if (success) { + m_track = newTrack; + m_startPos = x / scale; + } + QList childrenList = QGraphicsItem::children(); for (int i = 0; i < childrenList.size(); ++i) { childrenList.at(i)->moveBy(rect().x() - origX , offset); } @@ -192,7 +272,7 @@ OPERATIONTYPE ClipItem::operationMode(QPointF pos) break; } } - QList childrenList = children(); + QList childrenList = QGraphicsItem::children(); for (int i = 0; i < childrenList.size(); ++i) { childrenList.at(i)->moveBy((moveX - originalX) / 2 , 0); } @@ -216,13 +296,13 @@ OPERATIONTYPE ClipItem::operationMode(QPointF pos) } } - QList childrenList = children(); + QList childrenList = QGraphicsItem::children(); for (int i = 0; i < childrenList.size(); ++i) { childrenList.at(i)->moveBy((newWidth - originalWidth) / 2 , 0); } return; } - if (m_resizeMode == MOVE) { + /*if (m_resizeMode == MOVE) { kDebug()<<"/////// MOVE CLIP, EVENT Y: "<scenePos().y()<<", SCENE HEIGHT: "<sceneRect().height(); int moveTrack = (int) event->scenePos().y() / 50; int currentTrack = (int) rect().y() / 50; @@ -233,9 +313,19 @@ OPERATIONTYPE ClipItem::operationMode(QPointF pos) } if (offset != 0) offset = 50 * offset; moveTo(moveX - m_grabPoint, offset); - } + }*/ } +int ClipItem::track() +{ + return m_track; +} + +void ClipItem::setTrack(int track) +{ + m_track = track; +} + // virtual /* diff --git a/src/clipitem.h b/src/clipitem.h index 9f548a00..853c24e0 100644 --- a/src/clipitem.h +++ b/src/clipitem.h @@ -22,26 +22,35 @@ #define CLIPITEM_H #include +#include #include #include "labelitem.h" #include "definitions.h" +#include "kthumb.h" -class ClipItem : public QGraphicsRectItem + +class ClipItem : public QObject, public QGraphicsRectItem { - + Q_OBJECT + public: - ClipItem(int clipType, QString name, int producer, int maxDuration, const QRectF & rect); + ClipItem(QDomElement xml, int track, int startpos, const QRectF & rect, int duration = -1); virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); virtual int type () const; - void moveTo(double x, double offset); + void moveTo(double x, double scale, double offset, int newTrack); OPERATIONTYPE operationMode(QPointF pos); int clipProducer(); int clipType(); QString clipName(); int maxDuration(); + int track(); + void setTrack(int track); + int startPos(); + int duration(); + QDomElement xml() const; protected: virtual void mouseMoveEvent ( QGraphicsSceneMouseEvent * event ); @@ -49,6 +58,7 @@ class ClipItem : public QGraphicsRectItem virtual void mousePressEvent ( QGraphicsSceneMouseEvent * event ); private: + QDomElement m_xml; LabelItem *m_label; int m_textWidth; OPERATIONTYPE m_resizeMode; @@ -60,6 +70,19 @@ class ClipItem : public QGraphicsRectItem int m_cropStart; int m_cropDuration; int m_maxTrack; + int m_track; + int m_startPos; + QPixmap m_startPix; + QPixmap m_endPix; + KThumb *m_thumbProd; + + private slots: + void slotThumbReady(int frame, QPixmap pix); + void slotFetchThumbs(); + + signals: + void getThumb(int, int, int, int); + }; #endif diff --git a/src/customtrackview.cpp b/src/customtrackview.cpp index cee97f92..d92fcd54 100644 --- a/src/customtrackview.cpp +++ b/src/customtrackview.cpp @@ -35,7 +35,7 @@ #include "addtimelineclipcommand.h" CustomTrackView::CustomTrackView(KUndoStack *commandStack, QGraphicsScene * projectscene, QWidget *parent) - : QGraphicsView(projectscene, parent), m_commandStack(commandStack), m_tracksCount(0), m_cursorPos(0), m_dropItem(NULL), m_cursorLine(NULL), m_operationMode(NONE), m_startPos(QPointF()), m_dragItem(NULL), m_visualTip(NULL), m_moveOpMode(NONE), m_animation(NULL), m_projectDuration(0) + : QGraphicsView(projectscene, parent), m_commandStack(commandStack), m_tracksCount(0), m_cursorPos(0), m_dropItem(NULL), m_cursorLine(NULL), m_operationMode(NONE), m_startPos(QPointF()), m_dragItem(NULL), m_visualTip(NULL), m_moveOpMode(NONE), m_animation(NULL), m_projectDuration(0), m_scale(1.0), m_clickPoint(0) { setMouseTracking(true); setAcceptDrops(true); @@ -47,6 +47,7 @@ CustomTrackView::CustomTrackView(KUndoStack *commandStack, QGraphicsScene * proj setContentsMargins(0, 0, 0, 0); if (projectscene) { m_cursorLine = projectscene->addLine(0, 0, 0, 50); + m_cursorLine->setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIgnoresTransformations); m_cursorLine->setZValue(1000); } } @@ -86,8 +87,23 @@ void CustomTrackView::mouseMoveEvent ( QMouseEvent * event ) setDragMode(QGraphicsView::RubberBandDrag); else*/ { - if (event->button() == Qt::LeftButton) { + if (m_dragItem) { //event->button() == Qt::LeftButton) { // a button was pressed, delete visual tips + +if (m_operationMode == MOVE) { + int moveX = mapToScene(event->pos()).x(); + //kDebug()<<"/////// MOVE CLIP, EVENT Y: "<scenePos().y()<<", SCENE HEIGHT: "<sceneRect().height(); + int moveTrack = (int) mapToScene(event->pos()).y() / 50; + int currentTrack = m_dragItem->track(); + + if (moveTrack > m_tracksCount - 1) moveTrack = m_tracksCount - 1; + else if (moveTrack < 0) moveTrack = 0; + + int offset = moveTrack - currentTrack; + if (offset != 0) offset = 50 * offset; + m_dragItem->moveTo(moveX - m_clickPoint, m_scale, offset, moveTrack); + } + if (m_animation) delete m_animation; m_animation = NULL; if (m_visualTip) delete m_visualTip; @@ -238,8 +254,9 @@ void CustomTrackView::mousePressEvent ( QMouseEvent * event ) if (item && item->type() != 70000) item = item->parentItem(); if (item && item->type() == 70000) { m_dragItem = (ClipItem *) item; + m_clickPoint = mapToScene(event->pos()).x() - m_dragItem->startPos() * m_scale; m_operationMode = m_dragItem->operationMode(item->mapFromScene(mapToScene(event->pos()))); - if (m_operationMode == MOVE || m_operationMode == RESIZESTART) m_startPos = QPointF(m_dragItem->rect().x(), m_dragItem->rect().y()); + if (m_operationMode == MOVE || m_operationMode == RESIZESTART) m_startPos = QPointF(m_dragItem->startPos(), m_dragItem->track()); else if (m_operationMode == RESIZEEND) m_startPos = QPointF(m_dragItem->rect().x() + m_dragItem->rect().width(), m_dragItem->rect().y()); kDebug()<<"//////// ITEM CLICKED: "<addItem(m_dropItem); } @@ -297,14 +312,15 @@ void CustomTrackView::addItem(QString producer, QPoint pos) void CustomTrackView::dragMoveEvent(QDragMoveEvent * event) { event->setDropAction(Qt::IgnoreAction); if (m_dropItem) { - int trackTop = ((int) mapToScene(event->pos()).y()/50) * 50 + 1; - m_dropItem->moveTo(mapToScene(event->pos()).x(), trackTop - m_dropItem->rect().y()); + int track = (int) mapToScene(event->pos()).y()/50; //) * (m_scale * 50) + m_scale; + kDebug()<<"+++++++++++++ DRAG MOVE, : "<pos()).x()<<", SCAL: "<moveTo(mapToScene(event->pos()).x(), m_scale, (track - m_dropItem->track()) * 50, track); + } + //if (item) { + event->setDropAction(Qt::MoveAction); + if (event->mimeData()->hasText()) { + event->acceptProposedAction(); } - //if (item) { - event->setDropAction(Qt::MoveAction); - if (event->mimeData()->hasText()) { - event->acceptProposedAction(); - } //} } @@ -317,7 +333,7 @@ void CustomTrackView::dragLeaveEvent ( QDragLeaveEvent * event ) { void CustomTrackView::dropEvent ( QDropEvent * event ) { if (m_dropItem) { - AddTimelineClipCommand *command = new AddTimelineClipCommand(this, m_dropItem->clipType(), m_dropItem->clipName(), m_dropItem->clipProducer(), m_dropItem->maxDuration(), m_dropItem->rect(), false); + AddTimelineClipCommand *command = new AddTimelineClipCommand(this, m_dropItem->xml(), m_dropItem->track(), m_dropItem->startPos(), m_dropItem->rect(), m_dropItem->duration(), false); m_commandStack->push(command); } m_dropItem = NULL; @@ -380,7 +396,7 @@ void CustomTrackView::mouseReleaseEvent ( QMouseEvent * event ) //kDebug()<<"/// MOVING CLIP: "<rect().x(),m_dragItem->rect().y()); if (m_operationMode == MOVE) { // move clip - MoveClipCommand *command = new MoveClipCommand(this, m_startPos, QPointF(m_dragItem->rect().x(), m_dragItem->rect().y()), false); + MoveClipCommand *command = new MoveClipCommand(this, m_startPos, QPointF(m_dragItem->startPos(), m_dragItem->track()), false); m_commandStack->push(command); } else if (m_operationMode == RESIZESTART) { @@ -393,6 +409,7 @@ void CustomTrackView::mouseReleaseEvent ( QMouseEvent * event ) ResizeClipCommand *command = new ResizeClipCommand(this, m_startPos, QPointF(m_dragItem->rect().x() + m_dragItem->rect().width(), m_dragItem->rect().y()), false, false); m_commandStack->push(command); } + m_dragItem = NULL; } void CustomTrackView::deleteClip ( const QRectF &rect ) @@ -405,24 +422,27 @@ void CustomTrackView::deleteClip ( const QRectF &rect ) delete item; } -void CustomTrackView::addClip ( int clipType, QString clipName, int clipProducer, int maxDuration, const QRectF &rect ) +void CustomTrackView::addClip ( QDomElement xml, int track, int startpos, const QRectF &rect, int duration ) { - ClipItem *item = new ClipItem(clipType, clipName, clipProducer, maxDuration, rect); + QRect r(startpos * m_scale, 50 * track, duration * m_scale, 49); + ClipItem *item = new ClipItem(xml, track, startpos, r, duration); scene()->addItem(item); } void CustomTrackView::moveClip ( const QPointF &startPos, const QPointF &endPos ) { - ClipItem *item = (ClipItem *) scene()->itemAt(startPos.x() + 1, startPos.y() + 1); + ClipItem *item = (ClipItem *) scene()->itemAt((startPos.x() + 1) * m_scale, startPos.y() * 50 + 25); if (!item) { - kDebug()<<"----------------  ERROR, CANNOT find clip to move at: "<setRect(QRectF(endPos.x(), endPos.y(), item->rect().width(), item->rect().height())); - QList childrenList = item->children(); + kDebug()<<"----------------  Move CLIP FROM: "<setRect(QRectF(endPos.x() * m_scale, endPos.y() * 50, item->rect().width(), item->rect().height())); + item->moveTo(endPos.x() * m_scale, m_scale, (endPos.y() - startPos.y()) * 50, endPos.y()); + /*QList childrenList = item->children(); for (int i = 0; i < childrenList.size(); ++i) { - childrenList.at(i)->moveBy(endPos.x() - startPos.x() , endPos.y() - startPos.y()); - } + childrenList.at(i)->moveBy((endPos.x() - startPos.x()) * m_scale , (endPos.y() - startPos.y()) * 50); + }*/ } void CustomTrackView::resizeClip ( const QPointF &startPos, const QPointF &endPos, bool resizeClipStart ) @@ -438,7 +458,7 @@ void CustomTrackView::resizeClip ( const QPointF &startPos, const QPointF &endPo qreal diff = endPos.x() - startPos.x(); if (resizeClipStart) { item->setRect(QRectF(endPos.x(), endPos.y(), item->rect().width() - diff, item->rect().height())); - QList childrenList = item->children(); + QList childrenList = item->QGraphicsItem::children(); for (int i = 0; i < childrenList.size(); ++i) { childrenList.at(i)->moveBy(diff / 2 , endPos.y() - startPos.y()); } @@ -446,7 +466,7 @@ void CustomTrackView::resizeClip ( const QPointF &startPos, const QPointF &endPo else { //kdDebug()<<"/////// RESIZE CLIP END: "<rect().x()<<", "<rect().width()<<", "<setRect(QRectF(item->rect().x(), item->rect().y(), endPos.x() - item->rect().x(), item->rect().height())); - QList childrenList = item->children(); + QList childrenList = item->QGraphicsItem::children(); for (int i = 0; i < childrenList.size(); ++i) { childrenList.at(i)->moveBy(-diff/2, endPos.y() - startPos.y()); } @@ -454,21 +474,43 @@ void CustomTrackView::resizeClip ( const QPointF &startPos, const QPointF &endPo } +void CustomTrackView::setScale(double scaleFactor) +{ + //scale(scaleFactor, scaleFactor); + m_scale = scaleFactor; + kDebug()<<" HHHHHHHH SCALING: "< itemList = items(); + + for (int i = 0; i < itemList.count(); i++) { + if (itemList.at(i)->type() == 70000) { + ClipItem *clip = (ClipItem *)itemList.at(i); + clip->setRect(clip->startPos() * m_scale, clip->rect().y(), clip->duration() * m_scale, clip->rect().height()); + } + else if (itemList.at(i)->type() == 70001) { + LabelItem *label = (LabelItem *)itemList.at(i); + QGraphicsItem *parent = label->parentItem(); + QRectF r = label->boundingRect(); + QRectF p = parent->boundingRect(); + label->setPos(p.x() + p.width() / 2 - r.width() / 2, p.y() + p.height() / 2 - r.height() / 2); + //label->setRect(clip->startPos() * m_scale, clip->rect().y(), clip->duration() * m_scale, clip->rect().height()); + } + } +} + void CustomTrackView::drawBackground ( QPainter * painter, const QRectF & rect ) { - kDebug()<<"///// DRAWING BG TRACKS: "<setPen(base); painter->setClipRect(rect); painter->drawLine(0, 0, rect.width(), 0); for (uint i = 0; i < m_tracksCount;i++) { - painter->drawLine(0, 50 * (i+1), rect.width(), 50 * (i+1)); + painter->drawLine(0, 50 * (i+1), width(), 50 * (i+1)); //painter->drawText(QRectF(10, 50 * i, 100, 50 * i + 49), Qt::AlignLeft, i18n(" Track ") + QString::number(i)); } int lowerLimit = 50 * m_tracksCount; if (height() > lowerLimit) - painter->fillRect(QRectF(0, lowerLimit - rect.y(), rect.width(), height() - lowerLimit - rect.y()), QBrush(base)); + painter->fillRect(QRectF(0, lowerLimit, rect.width(), height() - lowerLimit), QBrush(base)); } /* void CustomTrackView::drawForeground ( QPainter * painter, const QRectF & rect ) diff --git a/src/customtrackview.h b/src/customtrackview.h index 23cf3e10..4ee97e31 100644 --- a/src/customtrackview.h +++ b/src/customtrackview.h @@ -44,9 +44,10 @@ class CustomTrackView : public QGraphicsView void initView(); void moveClip ( const QPointF &startPos, const QPointF &endPos ); void resizeClip ( const QPointF &startPos, const QPointF &endPos, bool resizeClipStart ); - void addClip ( int clipType, QString clipName, int clipProducer, int maxDuration, const QRectF &rect ); + void addClip ( QDomElement xml, int track, int startpos, const QRectF &rect, int duration); void deleteClip ( const QRectF &rect ); void setDuration(int duration); + void setScale(double scaleFactor); public slots: void setCursorPos(int pos); @@ -79,6 +80,8 @@ class CustomTrackView : public QGraphicsView QGraphicsItemAnimation *m_animation; QTimeLine *m_animationTimer; QColor m_tipColor; + double m_scale; + int m_clickPoint; signals: void cursorMoved(int); diff --git a/src/kdenlivesettings.kcfg b/src/kdenlivesettings.kcfg index ecac2374..f7875f8a 100644 --- a/src/kdenlivesettings.kcfg +++ b/src/kdenlivesettings.kcfg @@ -13,4 +13,11 @@ 00:00:05:00 + + + + + 1.7777778 + + \ No newline at end of file diff --git a/src/kthumb.cpp b/src/kthumb.cpp new file mode 100644 index 00000000..70300718 --- /dev/null +++ b/src/kthumb.cpp @@ -0,0 +1,323 @@ +/*************************************************************************** + krender.cpp - description + ------------------- + begin : Fri Nov 22 2002 + copyright : (C) 2002 by Jason Wood + email : jasonwood@blueyonder.co.uk + copyright : (C) 2005 Lcio Fl�io Corr� + email : lucio.correa@gmail.com + copyright : (C) Marco Gittler + email : g.marco@freenet.de + +***************************************************************************/ + +/*************************************************************************** + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ***************************************************************************/ + +#include + +#include +#include +#include +#include +#include +#include + +#include + +#include +#include +#include +#include +#include + + + +#include "renderer.h" +#include "kthumb.h" + +/* + void MyThread::init(KUrl url, QString target, double frame, double frameLength, int frequency, int channels, int arrayWidth) + { + stop_me = false; + m_isWorking = false; + f.setName(target); + m_url = url; + m_frame = frame; + m_frameLength = frameLength; + m_frequency = frequency; + m_channels = channels; + m_arrayWidth = arrayWidth; + + } + + bool MyThread::isWorking() + { + return m_isWorking; + } + + void MyThread::run() + { + if (!f.open( IO_WriteOnly )) { + kdDebug()<<"++++++++ ERROR WRITING TO FILE: "<mainWidget()) + QApplication::postEvent(qApp->mainWidget(), new ProgressEvent(-1, 10005)); + + int last_val = 0; + int val = 0; + for (int z=(int) m_frame;z<(int) (m_frame+m_frameLength) && m_producer.is_valid();z++){ + if (stop_me) break; + val=(int)((z-m_frame)/(m_frame+m_frameLength)*100.0); + if (last_val!=val & val > 1){ + QApplication::postEvent(qApp->mainWidget(), new ProgressEvent(val, 10005)); + last_val=val; + } + m_producer.seek( z ); + Mlt::Frame *mlt_frame = m_producer.get_frame(); + if ( mlt_frame->is_valid() ) + { + double m_framesPerSecond = mlt_producer_get_fps( m_producer.get_producer() ); //mlt_frame->get_double( "fps" ); + int m_samples = mlt_sample_calculator( m_framesPerSecond, m_frequency, mlt_frame_get_position(mlt_frame->get_frame()) ); + mlt_audio_format m_audioFormat = mlt_audio_pcm; + + int16_t* m_pcm = mlt_frame->get_audio(m_audioFormat, m_frequency, m_channels, m_samples ); + + for (int c=0;c< m_channels;c++){ + QByteArray m_array(m_arrayWidth); + for (uint i = 0; i < m_array.size(); i++){ + m_array[i] = QABS((*( m_pcm + c + i * m_samples / m_array.size() ))>>8); + } + f.writeBlock(m_array); + } + } else{ + f.writeBlock(QByteArray(m_arrayWidth)); + } + if (mlt_frame) + delete mlt_frame; + } + f.close(); + m_isWorking = false; + if (stop_me) { + f.remove(); + QApplication::postEvent(qApp->mainWidget(), new ProgressEvent(-1, 10005)); + } + else QApplication::postEvent(qApp->mainWidget(), new ProgressEvent(0, 10005)); + } + + +#define _S(a) (a)>255 ? 255 : (a)<0 ? 0 : (a) +#define _R(y,u,v) (0x2568*(y) + 0x3343*(u)) /0x2000 +#define _G(y,u,v) (0x2568*(y) - 0x0c92*(v) - 0x1a1e*(u)) /0x2000 +#define _B(y,u,v) (0x2568*(y) + 0x40cf*(v)) /0x2000 +*/ +KThumb::KThumb(KUrl url, QObject * parent, const char *name):QObject(parent), m_url(url) +{ +} + +KThumb::~KThumb() +{ + //if (thumbProducer.running ()) thumbProducer.exit(); +} + +void KThumb::extractImage(int frame, int frame2, int width, int height) +{ + if (m_url.isEmpty()) return; + QPixmap pix(width, height); + char *tmp = Render::decodedString(m_url.path()); + Mlt::Producer m_producer(tmp); + delete tmp; + pix.fill(Qt::black); + + if (m_producer.is_blank()) { + emit thumbReady(frame, pix); + return; + } + + 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); + Mlt::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; + emit thumbReady(frame, pix); + + if (frame2 == -1) return; + m_producer.seek(frame2); + 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; + emit thumbReady(frame2, pix); + +} +/* +void KThumb::getImage(KUrl url, int frame, int width, int height) +{ + if (url.isEmpty()) return; + QPixmap image(width, height); + char *tmp = KRender::decodedString(url.path()); + Mlt::Producer m_producer(tmp); + delete tmp; + image.fill(Qt::black); + + if (m_producer.is_blank()) { + emit thumbReady(frame, image); + return; + } + Mlt::Filter m_convert("avcolour_space"); + m_convert.set("forced", mlt_image_rgb24a); + m_producer.attach(m_convert); + m_producer.seek(frame); + Mlt::Frame * m_frame = m_producer.get_frame(); + mlt_image_format format = mlt_image_rgb24a; + width = width - 2; + height = height - 2; + if (m_frame && m_frame->is_valid()) { + uint8_t *thumb = m_frame->get_image(format, width, height); + QImage tmpimage(thumb, width, height, 32, NULL, 0, QImage::IgnoreEndian); + if (!tmpimage.isNull()) bitBlt(&image, 1, 1, &tmpimage, 0, 0, width + 2, height + 2); + } + if (m_frame) delete m_frame; + emit thumbReady(frame, image); +} + +void KThumb::getThumbs(KUrl url, int startframe, int endframe, int width, int height) +{ + if (url.isEmpty()) return; + QPixmap image(width, height); + char *tmp = KRender::decodedString(url.path()); + Mlt::Producer m_producer(tmp); + delete tmp; + image.fill(Qt::black); + + if (m_producer.is_blank()) { + emit thumbReady(startframe, image); + emit thumbReady(endframe, image); + return; + } + Mlt::Filter m_convert("avcolour_space"); + m_convert.set("forced", mlt_image_rgb24a); + m_producer.attach(m_convert); + m_producer.seek(startframe); + Mlt::Frame * m_frame = m_producer.get_frame(); + mlt_image_format format = mlt_image_rgb24a; + width = width - 2; + height = height - 2; + + if (m_frame && m_frame->is_valid()) { + uint8_t *thumb = m_frame->get_image(format, width, height); + QImage tmpimage(thumb, width, height, 32, NULL, 0, QImage::IgnoreEndian); + if (!tmpimage.isNull()) bitBlt(&image, 1, 1, &tmpimage, 0, 0, width - 2, height - 2); + } + if (m_frame) delete m_frame; + emit thumbReady(startframe, image); + + image.fill(Qt::black); + m_producer.seek(endframe); + m_frame = m_producer.get_frame(); + + if (m_frame && m_frame->is_valid()) { + uint8_t *thumb = m_frame->get_image(format, width, height); + QImage tmpimage(thumb, width, height, 32, NULL, 0, QImage::IgnoreEndian); + if (!tmpimage.isNull()) bitBlt(&image, 1, 1, &tmpimage, 0, 0, width - 2, height - 2); + } + if (m_frame) delete m_frame; + emit thumbReady(endframe, image); +} + +void KThumb::stopAudioThumbs() +{ + if (thumbProducer.running ()) thumbProducer.stop_me = true; +} + + +void KThumb::removeAudioThumb() +{ + if (m_thumbFile.isEmpty()) return; + stopAudioThumbs(); + QFile f(m_thumbFile); + f.remove(); +} + +void KThumb::getAudioThumbs(KUrl url, int channel, double frame, double frameLength, int arrayWidth){ + if ((thumbProducer.running () && thumbProducer.isWorking()) || channel == 0) { + return; + } + + QMap > storeIn; + //FIXME: Hardcoded!!! + int m_frequency = 48000; + int m_channels = channel; + if (m_url != url) { + m_url = url; + KMD5 context ((KFileItem(m_url,"text/plain", S_IFREG).timeString() + m_url.fileName()).ascii()); + m_thumbFile = KdenliveSettings::currenttmpfolder() + context.hexDigest().data() + ".thumb"; + } + QFile f(m_thumbFile); + if (f.open( IO_ReadOnly )) { + QByteArray channelarray = f.readAll(); + f.close(); + if (channelarray.size() != arrayWidth*(frame+frameLength)*m_channels) { + kdDebug()<<"--- BROKEN THUMB FOR: "< +#include +#include +#include + +#include + + +/**KRender encapsulates the client side of the interface to a renderer. +From Kdenlive's point of view, you treat the KRender object as the +renderer, and simply use it as if it was local. Calls are asyncrhonous - +you send a call out, and then recieve the return value through the +relevant signal that get's emitted once the call completes. + *@author Jason Wood + */ + + +namespace Mlt { + class Miracle; + class Consumer; + class Producer; + class Frame; +}; + + + /* class MyThread : public QThread { + + public: + virtual void run(); + void init(KUrl url, QString target, double frame, double frameLength, int frequency, int channels, int arrayWidth); + bool isWorking(); + bool stop_me; + + private: + QFile f; + KUrl m_url; + double m_frame; + double m_frameLength; + int m_frequency; + int m_channels; + int m_arrayWidth; + bool m_isWorking; + }; + +*/ +class KThumb:public QObject { + Q_OBJECT public: + + + KThumb(KUrl url, QObject * parent = 0, const char *name = 0); + ~KThumb(); + +public slots: + void extractImage( int frame, int frame2, 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(); + void removeAudioThumb(); + void getAudioThumbs(KUrl url, int channel, double frame, double frameLength, int arrayWidth); +*/ +private: +// MyThread thumbProducer; + KUrl m_url; + QString m_thumbFile; + +signals: + void thumbReady(int frame, QPixmap pm); + void audioThumbReady(QMap >); +}; + +#endif diff --git a/src/labelitem.cpp b/src/labelitem.cpp index 5cd54e22..3805e18e 100644 --- a/src/labelitem.cpp +++ b/src/labelitem.cpp @@ -30,7 +30,8 @@ LabelItem::LabelItem(QString text, QGraphicsRectItem *parent) : QGraphicsSimpleTextItem(" " + text + " ", parent) { //setParentItem(parent); - setFlags(QGraphicsItem::ItemIgnoresTransformations); + //setFlags(QGraphicsItem::ItemIgnoresTransformations); + setZValue(200); } int LabelItem::type () const @@ -44,7 +45,7 @@ int LabelItem::type () const const QStyleOptionGraphicsItem *option, QWidget *widget) { - kDebug()<<"REPAINT LABEL ------------------------"; + //kDebug()<<"REPAINT LABEL ------------------------"; QRectF rep = option->exposedRect; //painter->setClipRect(rep); QGraphicsRectItem *parent = (QGraphicsRectItem *) parentItem(); diff --git a/src/trackview.cpp b/src/trackview.cpp index 269929f8..9a5e0984 100644 --- a/src/trackview.cpp +++ b/src/trackview.cpp @@ -45,7 +45,7 @@ TrackView::TrackView(KdenliveDoc *doc, QWidget *parent) m_scene = new QGraphicsScene(); m_trackview = new CustomTrackView(m_doc->commandStack(), m_scene, this); - m_trackview->scale(FRAME_SIZE, 1); + m_trackview->scale(1, 1); m_trackview->setAlignment(Qt::AlignLeft | Qt::AlignTop); //m_scene->addRect(QRectF(0, 0, 100, 100), QPen(), QBrush(Qt::red)); @@ -130,15 +130,15 @@ void TrackView::slotCursorMoved(int pos, bool emitSignal) void TrackView::slotChangeZoom(int factor) { m_ruler->setPixelPerMark(factor); - m_scale = (double) m_ruler->comboScale[m_currentZoom] / m_ruler->comboScale[factor]; + m_scale = (double) FRAME_SIZE / m_ruler->comboScale[factor]; // m_ruler->comboScale[m_currentZoom] / m_currentZoom = factor; - m_trackview->scale(m_scale, 1); + m_trackview->setScale(m_scale); m_trackview->centerOn(QPointF(m_trackview->cursorPos(), 50)); } const double TrackView::zoomFactor() const { - return m_scale * FRAME_SIZE; + return m_scale; } void TrackView::slotZoomIn() @@ -192,10 +192,8 @@ int TrackView::slotAddVideoTrack(int ix, QDomElement xml) else if (elem.tagName() == "entry") { int in = elem.attribute("in", 0).toInt(); int out = elem.attribute("out", 0).toInt() - in; - QString clipName = m_doc->producerName(elem.attribute("producer").toInt()); - int clipMaxDuration = m_doc->getProducerDuration(elem.attribute("producer").toInt()); //kDebug()<<"++++++++++++++\n\n / / /ADDING CLIP: "<addItem(item); position += out; @@ -239,7 +237,6 @@ const QString & TrackView::editMode() const /** This event occurs when the mouse has been moved. */ void TrackView::mouseMoveEvent(QMouseEvent * event) { - kDebug()<<"-------- TRACKVIEW MOUSE MOVE EVENT -----"; if (m_panelUnderMouse) { if (event->buttons() & Qt::LeftButton) { bool result = false; -- 2.39.2