moveclipcommand.cpp
resizeclipcommand.cpp
addtimelineclipcommand.cpp
+ kthumb.cpp
)
kde4_add_kcfg_files(kdenlive_SRCS GENERATE_MOC kdenlivesettings.kcfgc )
#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"));
}
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;
}
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;
};
#include <QPainter>
+#include <QTimer>
#include <QStyleOptionGraphicsItem>
#include <QGraphicsScene>
+
+
#include <KDebug>
+#include <mlt++/Mlt.h>
#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
return 70000;
}
+QDomElement ClipItem::xml() const
+{
+ return m_xml;
+}
+
int ClipItem::clipType()
{
return m_clipType;
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: "<<scale<<", height: "<<br.height();
+ roundRectPath.moveTo(br.x() + br .width() - offset, br.y() + roundingY);
+ roundRectPath.arcTo(br.x() + br .width() - roundingX - offset, br.y(), roundingX, roundingY, 0.0, 90.0);
+ roundRectPath.lineTo(br.x() + roundingX, br.y());
+ roundRectPath.arcTo(br.x() + offset, br.y(), roundingX, roundingY, 90.0, 90.0);
+ roundRectPath.lineTo(br.x() + offset, br.y() + br.height() - roundingY);
+ roundRectPath.arcTo(br.x() + offset, br.y() + br.height() - roundingY - offset, roundingX, roundingY, 180.0, 90.0);
+ roundRectPath.lineTo(br.x() + br .width() - roundingX, br.y() + br.height() - offset);
+ roundRectPath.arcTo(br.x() + br .width() - roundingX - offset, br.y() + br.height() - roundingY - offset, roundingX, roundingY, 270.0, 90.0);
+ roundRectPath.closeSubpath();
+ painter->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: "<<boundingRect().width();
//painter->drawText(rect(), Qt::AlignCenter, m_name);
// painter->drawRect(boundingRect());
return MOVE;
}
+
// virtual
void ClipItem::mousePressEvent ( QGraphicsSceneMouseEvent * event )
{
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 <QGraphicsItem *> 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 <QGraphicsItem *> 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();
setRect(origX, origY, rect().width(), rect().height());
offset = 0;
origX = rect().x();
+ success = false;
break;
}
}
-
- QList <QGraphicsItem *> childrenList = children();
+ if (success) {
+ m_track = newTrack;
+ m_startPos = x / scale;
+ }
+ QList <QGraphicsItem *> childrenList = QGraphicsItem::children();
for (int i = 0; i < childrenList.size(); ++i) {
childrenList.at(i)->moveBy(rect().x() - origX , offset);
}
break;
}
}
- QList <QGraphicsItem *> childrenList = children();
+ QList <QGraphicsItem *> childrenList = QGraphicsItem::children();
for (int i = 0; i < childrenList.size(); ++i) {
childrenList.at(i)->moveBy((moveX - originalX) / 2 , 0);
}
}
}
- QList <QGraphicsItem *> childrenList = children();
+ QList <QGraphicsItem *> 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: "<<event->scenePos().y()<<", SCENE HEIGHT: "<<scene()->sceneRect().height();
int moveTrack = (int) event->scenePos().y() / 50;
int currentTrack = (int) rect().y() / 50;
}
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
/*
#define CLIPITEM_H
#include <QGraphicsRectItem>
+#include <QDomElement>
#include <QGraphicsSceneMouseEvent>
#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 );
virtual void mousePressEvent ( QGraphicsSceneMouseEvent * event );
private:
+ QDomElement m_xml;
LabelItem *m_label;
int m_textWidth;
OPERATIONTYPE m_resizeMode;
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
#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);
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);
}
}
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: "<<event->scenePos().y()<<", SCENE HEIGHT: "<<scene()->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;
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: "<<m_startPos;
if (out == 0) out = elem.attribute("out", 0).toInt() - in;
kDebug()<<"ADDING CLIP: "<<producer<<", OUT: "<<out<<", POS: "<<mapToScene(pos);
int trackTop = ((int) mapToScene(pos).y()/50) * 50 + 1;
- QString clipName = elem.attribute("name");
- if (clipName.isEmpty()) clipName = KUrl(elem.attribute("resource")).fileName();
- m_dropItem = new ClipItem(elem.attribute("type").toInt(), clipName, elem.attribute("id").toInt(), out, QRectF(mapToScene(pos).x(), trackTop, out, 49));
+ m_dropItem = new ClipItem(elem, ((int) mapToScene(pos).y()/50), in, QRectF(mapToScene(pos).x() * m_scale, trackTop, out * m_scale, 49));
scene()->addItem(m_dropItem);
}
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, : "<<mapToScene(event->pos()).x()<<", SCAL: "<<m_scale;
+ m_dropItem->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();
- }
//}
}
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;
//kDebug()<<"/// MOVING CLIP: "<<m_startPos<<", END: "<<QPoint(m_dragItem->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) {
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 )
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: "<<startPos;
+ kDebug()<<"---------------- ERROR, CANNOT find clip to move at: "<<startPos.x() * m_scale * FRAME_SIZE + 1<<", "<<startPos.y() * 50 + 25;
return;
}
- item->setRect(QRectF(endPos.x(), endPos.y(), item->rect().width(), item->rect().height()));
- QList <QGraphicsItem *> childrenList = item->children();
+ kDebug()<<"---------------- Move CLIP FROM: "<<startPos.x()<<", END:"<<endPos.x();
+ //item->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 <QGraphicsItem *> 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 )
qreal diff = endPos.x() - startPos.x();
if (resizeClipStart) {
item->setRect(QRectF(endPos.x(), endPos.y(), item->rect().width() - diff, item->rect().height()));
- QList <QGraphicsItem *> childrenList = item->children();
+ QList <QGraphicsItem *> childrenList = item->QGraphicsItem::children();
for (int i = 0; i < childrenList.size(); ++i) {
childrenList.at(i)->moveBy(diff / 2 , endPos.y() - startPos.y());
}
else {
//kdDebug()<<"/////// RESIZE CLIP END: "<<item->rect().x()<<", "<<item->rect().width()<<", "<<startPos<<", "<<endPos;
item->setRect(QRectF(item->rect().x(), item->rect().y(), endPos.x() - item->rect().x(), item->rect().height()));
- QList <QGraphicsItem *> childrenList = item->children();
+ QList <QGraphicsItem *> childrenList = item->QGraphicsItem::children();
for (int i = 0; i < childrenList.size(); ++i) {
childrenList.at(i)->moveBy(-diff/2, endPos.y() - startPos.y());
}
}
+void CustomTrackView::setScale(double scaleFactor)
+{
+ //scale(scaleFactor, scaleFactor);
+ m_scale = scaleFactor;
+ kDebug()<<" HHHHHHHH SCALING: "<<m_scale;
+ QList<QGraphicsItem *> 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: "<<m_tracksCount;
QColor base = palette().button().color();
painter->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 )
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);
QGraphicsItemAnimation *m_animation;
QTimeLine *m_animationTimer;
QColor m_tipColor;
+ double m_scale;
+ int m_clickPoint;
signals:
void cursorMoved(int);
<default>00:00:05:00</default>
</entry>
</group>
+
+ <group name="unmanaged">
+ <entry name="project_display_ratio" type="Double">
+ <label>Current project display ratio.</label>
+ <default>1.7777778</default>
+ </entry>
+ </group>
</kcfg>
\ No newline at end of file
--- /dev/null
+/***************************************************************************
+ 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 <qapplication.h>
+
+#include <kio/netaccess.h>
+#include <kdebug.h>
+#include <klocale.h>
+#include <kdenlivesettings.h>
+#include <kfileitem.h>
+#include <kmessagebox.h>
+
+#include <mlt++/Mlt.h>
+
+#include <qxml.h>
+#include <qimage.h>
+#include <qlabel.h>
+#include <qthread.h>
+#include <qapplication.h>
+
+
+
+#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: "<<f.name()<<endl;
+ kdDebug()<<"++++++++ DISABLING AUDIO THUMBS"<<endl;
+ KdenliveSettings::setAudiothumbnails(false);
+ return;
+ }
+ m_isWorking = true;
+ char *tmp = KRender::decodedString(m_url.path());
+ Mlt::Producer m_producer(tmp);
+ delete tmp;
+
+ if (KdenliveSettings::normaliseaudiothumbs()) {
+ Mlt::Filter m_convert("volume");
+ m_convert.set("gain", "normalise");
+ m_producer.attach(m_convert);
+ }
+
+ if (qApp->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 <int, QMap <int, QByteArray> > 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: "<<m_url.filename()<<" ---------------------- "<<endl;
+ f.remove();
+ return;
+ }
+
+ for (int z=(int) frame;z<(int) (frame+frameLength);z++) {
+ for (int c=0;c< m_channels;c++){
+ QByteArray m_array(arrayWidth);
+ for (int i = 0; i < arrayWidth; i++)
+ m_array[i] = channelarray[z*arrayWidth*m_channels + c*arrayWidth + i];
+ storeIn[z][c] = m_array;
+ }
+ }
+ emit audioThumbReady(storeIn);
+ }
+ else {
+ if (thumbProducer.running()) return;
+ thumbProducer.init(m_url, m_thumbFile, frame, frameLength, m_frequency, m_channels, arrayWidth);
+ thumbProducer.start(QThread::LowestPriority );
+ }
+}
+*/
+
+
--- /dev/null
+/***************************************************************************
+ krender.h - description
+ -------------------
+ begin : Fri Nov 22 2002
+ copyright : (C) 2002 by Jason Wood
+ email : jasonwood@blueyonder.co.uk
+***************************************************************************/
+
+/***************************************************************************
+ * *
+ * 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. *
+ * *
+ ***************************************************************************/
+
+#ifndef KTHUMB_H
+#define KTHUMB_H
+
+#include <qobject.h>
+#include <qpixmap.h>
+#include <qfile.h>
+#include <qthread.h>
+
+#include <kurl.h>
+
+
+/**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 <int, QMap <int, QByteArray> >);
+};
+
+#endif
: QGraphicsSimpleTextItem(" " + text + " ", parent)
{
//setParentItem(parent);
- setFlags(QGraphicsItem::ItemIgnoresTransformations);
+ //setFlags(QGraphicsItem::ItemIgnoresTransformations);
+ setZValue(200);
}
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();
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));
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()
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: "<<clip.cropTime<<", out: "<<clip.duration<<", Producer: "<<clip.producer<<"\n\n++++++++++++++++++++";
- ClipItem *item = new ClipItem(elem.attribute("type").toInt(), clipName, elem.attribute("producer").toInt(), clipMaxDuration, QRectF(position, trackTop + 1, out, 49));
+ ClipItem *item = new ClipItem(elem, ix, in, QRectF(position * m_scale, trackTop + 1, out * m_scale, 49), out);
m_scene->addItem(item);
position += out;
/** 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;