Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

Start porting timeline to QGraphicsView

svn path=/branches/KDE4/; revision=1805
parent 5c2a350c
......@@ -50,6 +50,9 @@ set(kdenlive_SRCS
trackpanelfunctionfactory.cpp
trackpanelfunction.cpp
trackpanelclipmovefunction.cpp
customtrackview.cpp
clipitem.cpp
labelitem.cpp
)
kde4_add_kcfg_files(kdenlive_SRCS GENERATE_MOC kdenlivesettings.kcfgc )
......
......@@ -23,7 +23,7 @@ AddClipCommand::AddClipCommand(ProjectList *list, const QStringList &names, cons
: m_list(list), m_names(names), m_xml(xml), m_id(id), m_url(url), m_group(group), m_doIt(doIt) {
if (doIt) setText(i18n("Add clip"));
else setText(i18n("Delete clip"));
}
}
// virtual
......
/***************************************************************************
* Copyright (C) 2007 by Jean-Baptiste Mardelle (jb@kdenlive.org) *
* *
* 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. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
***************************************************************************/
#include <QPainter>
#include <QStyleOptionGraphicsItem>
#include <KDebug>
#include "clipitem.h"
ClipItem::ClipItem(int clipType, QString name, int producer, const QRectF & rect)
: QGraphicsRectItem(rect), m_resizeMode(0), m_grabPoint(0), m_producer(producer)
{
setToolTip(name);
//setCursor(Qt::SizeHorCursor);
setFlags(QGraphicsItem::ItemClipsToShape | QGraphicsItem::ItemClipsChildrenToShape | QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
//producer = "sjis isjisjsi sij ssao sa sao ";
m_label = new LabelItem( name, 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);
}
int ClipItem::type () const
{
return 70000;
}
// virtual
void ClipItem::paint(QPainter *painter,
const QStyleOptionGraphicsItem *option,
QWidget *widget)
{
painter->setClipRect( option->exposedRect );
painter->fillRect(rect(), Qt::red);
//kDebug()<<"ITEM REPAINT RECT: "<<boundingRect().width();
//painter->drawText(rect(), Qt::AlignCenter, m_name);
painter->drawRect(rect());
//painter->drawRoundRect(-10, -10, 20, 20);
}
// virtual
void ClipItem::mousePressEvent ( QGraphicsSceneMouseEvent * event )
{
if (abs(event->pos().x() - rect().x()) < 6)
m_resizeMode = 1;
else if (abs(event->pos().x() - (rect().x() + rect().width())) < 6)
m_resizeMode = 2;
else {
m_resizeMode = 0;
m_grabPoint = event->pos().x() - rect().x();
}
QGraphicsRectItem::mousePressEvent(event);
}
// virtual
void ClipItem::mouseReleaseEvent ( QGraphicsSceneMouseEvent * event )
{
m_resizeMode = 0;
QGraphicsRectItem::mouseReleaseEvent(event);
}
void ClipItem::moveTo(double x, double offset)
{
double origX = rect().x();
double origY = rect().y();
setRect(x, origY + offset, rect().width(), rect().height());
QList <QGraphicsItem *> collisionList = collidingItems();
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();
QPointF pos = mapFromItem(item, other.x()+other.width(), 0);
//mapToItem(collisionList.at(i), collisionList.at(i)->boundingRect()).boundingRect();
if (x < origX) {
kDebug()<<"COLLISION, MOVING TO------";
origX = other.x() + other.width();
}
else if (x > origX) {
kDebug()<<"COLLISION, MOVING TO+++";
origX = other.x() - rect().width();
}
}
setRect(origX, origY, rect().width(), rect().height());
offset = 0;
origX = rect().x();
break;
}
}
QList <QGraphicsItem *> childrenList = children();
for (int i = 0; i < childrenList.size(); ++i) {
childrenList.at(i)->moveBy(rect().x() - origX , offset);
}
}
// virtual
void ClipItem::mouseMoveEvent ( QGraphicsSceneMouseEvent * event )
{
double moveX = event->scenePos().x();
double originalX = rect().x();
if (m_resizeMode == 1) {
setRect(moveX, rect().y(), originalX + rect().width() - moveX, rect().height());
return;
}
if (m_resizeMode == 2) {
setRect(originalX, rect().y(), moveX - originalX, rect().height());
return;
}
int moveTrack = (int) event->scenePos().y() / 50;
int currentTrack = (int) rect().y() / 50;
int offset = moveTrack - currentTrack;
if (offset != 0) offset = 50 * offset;
moveTo(moveX - m_grabPoint, offset);
}
// virtual
/*
void CustomTrackView::mousePressEvent ( QMouseEvent * event )
{
int pos = event->x();
if (event->modifiers() == Qt::ControlModifier)
setDragMode(QGraphicsView::ScrollHandDrag);
else if (event->modifiers() == Qt::ShiftModifier)
setDragMode(QGraphicsView::RubberBandDrag);
else {
QGraphicsItem * item = itemAt(event->pos());
if (item) {
}
else emit cursorMoved((int) mapToScene(event->x(), 0).x());
}
kDebug()<<pos;
QGraphicsView::mousePressEvent(event);
}
void CustomTrackView::mouseReleaseEvent ( QMouseEvent * event )
{
QGraphicsView::mouseReleaseEvent(event);
setDragMode(QGraphicsView::NoDrag);
}
*/
#include "clipitem.moc"
/***************************************************************************
* Copyright (C) 2007 by Jean-Baptiste Mardelle (jb@kdenlive.org) *
* *
* 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. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
***************************************************************************/
#ifndef CLIPITEM_H
#define CLIPITEM_H
#include <QGraphicsRectItem>
#include <QGraphicsSceneMouseEvent>
#include "labelitem.h"
class ClipItem : public QGraphicsRectItem
{
public:
ClipItem(int clipType, QString name, int producer, const QRectF & rect);
virtual void paint(QPainter *painter,
const QStyleOptionGraphicsItem *option,
QWidget *widget);
virtual int type () const;
void moveTo(double x, double offset);
protected:
virtual void mouseMoveEvent ( QGraphicsSceneMouseEvent * event );
virtual void mouseReleaseEvent ( QGraphicsSceneMouseEvent * event );
virtual void mousePressEvent ( QGraphicsSceneMouseEvent * event );
private:
LabelItem *m_label;
int m_textWidth;
uint m_resizeMode;
int m_grabPoint;
int m_producer;
};
#endif
/***************************************************************************
* Copyright (C) 2007 by Jean-Baptiste Mardelle (jb@kdenlive.org) *
* *
* 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. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
***************************************************************************/
#include <QMouseEvent>
#include <QStylePainter>
......@@ -88,6 +106,7 @@ void CustomRuler::mouseMoveEvent ( QMouseEvent * event )
void CustomRuler::slotNewValue ( int _value )
{
m_cursorPosition = _value / pixelPerMark();
emit cursorMoved(m_cursorPosition / FRAME_SIZE);
KRuler::slotNewValue(_value);
}
......
......@@ -24,6 +24,9 @@ class CustomRuler : public KRuler
public slots:
void slotNewValue ( int _value );
signals:
void cursorMoved(int);
};
#endif
/***************************************************************************
* Copyright (C) 2007 by Jean-Baptiste Mardelle (jb@kdenlive.org) *
* *
* 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. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
***************************************************************************/
#include <QMouseEvent>
#include <QStylePainter>
#include <QGraphicsItem>
#include <QDomDocument>
#include <KDebug>
#include <KUrl>
#include "customtrackview.h"
#include "clipitem.h"
#include "definitions.h"
CustomTrackView::CustomTrackView(QGraphicsScene * scene, QWidget *parent)
: QGraphicsView(scene, parent), m_tracksCount(0), m_cursorPos(0), m_dropItem(NULL)
{
setMouseTracking(true);
setAcceptDrops(true);
}
// virtual
void CustomTrackView::mouseMoveEvent ( QMouseEvent * event )
{
int pos = event->x();
if (event->modifiers() == Qt::ControlModifier)
setDragMode(QGraphicsView::ScrollHandDrag);
else if (event->modifiers() == Qt::ShiftModifier)
setDragMode(QGraphicsView::RubberBandDrag);
else {
QGraphicsItem * item = itemAt(event->pos());
if (item) {
while (item->parentItem())
item = item->parentItem();
int cursorPos = event->x();
QRectF itemRect = item->sceneBoundingRect();
int itemStart = mapFromScene(itemRect.x(), 0).x();
int itemEnd = mapFromScene(itemRect.x() + itemRect.width(), 0).x();
if (abs(itemStart - cursorPos) < 6 || abs(itemEnd - cursorPos) < 6)
setCursor(Qt::SizeHorCursor);
else setCursor(Qt::OpenHandCursor);
}
else {
setCursor(Qt::ArrowCursor);
}
}
QGraphicsView::mouseMoveEvent(event);
}
// virtual
void CustomTrackView::mousePressEvent ( QMouseEvent * event )
{
int pos = event->x();
if (event->modifiers() == Qt::ControlModifier)
setDragMode(QGraphicsView::ScrollHandDrag);
else if (event->modifiers() == Qt::ShiftModifier)
setDragMode(QGraphicsView::RubberBandDrag);
else {
QGraphicsItem * item = itemAt(event->pos());
if (item) {
/*while (item->parentItem())
item = item->parentItem();
int cursorPos = event->x();
QRectF itemRect = item->sceneBoundingRect();
int itemStart = mapFromScene(itemRect.x(), 0).x();
int itemEnd = mapFromScene(itemRect.x() + itemRect.width(), 0).x();
if (abs(itemStart - cursorPos) < 6)
((ClipItem *) item )->setResizeMode(1);
else if (abs(itemEnd - cursorPos) < 6)
((ClipItem *) item )->setResizeMode(2);
*/}
else {
setCursor(Qt::ArrowCursor);
emit cursorMoved((int) mapToScene(event->x(), 0).x());
}
}
//kDebug()<<pos;
QGraphicsView::mousePressEvent(event);
}
void CustomTrackView::dragEnterEvent ( QDragEnterEvent * event )
{
if (event->mimeData()->hasText()) {
QString clip = event->mimeData()->text();
addItem(clip, event->pos());
event->acceptProposedAction();
}
}
void CustomTrackView::addItem(QString producer, QPoint pos)
{
QDomDocument doc;
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;
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(), QRectF(mapToScene(pos).x(), trackTop, out, 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());
}
//if (item) {
event->setDropAction(Qt::MoveAction);
if (event->mimeData()->hasText()) {
event->acceptProposedAction();
}
//}
}
void CustomTrackView::dragLeaveEvent ( QDragLeaveEvent * event ) {
if (m_dropItem) delete m_dropItem;
m_dropItem = NULL;
}
void CustomTrackView::dropEvent ( QDropEvent * event ) {
m_dropItem = NULL;
}
QStringList CustomTrackView::mimeTypes () const
{
QStringList qstrList;
// list of accepted mime types for drop
qstrList.append("text/plain");
return qstrList;
}
Qt::DropActions CustomTrackView::supportedDropActions () const
{
// returns what actions are supported when dropping
return Qt::MoveAction;
}
void CustomTrackView::addTrack ()
{
m_tracksCount++;
}
void CustomTrackView::removeTrack ()
{
m_tracksCount--;
}
void CustomTrackView::setCursorPos(int pos)
{
m_cursorPos = pos;
}
int CustomTrackView::cursorPos()
{
return m_cursorPos;
}
void CustomTrackView::mouseReleaseEvent ( QMouseEvent * event )
{
QGraphicsView::mouseReleaseEvent(event);
setDragMode(QGraphicsView::NoDrag);
}
void CustomTrackView::drawBackground ( QPainter * painter, const QRectF & rect )
{
//kDebug()<<"///// DRAWING BG: "<<rect.x()<<", width: "<<rect.width();
painter->drawRect(rect);
for (uint i = 0; i < m_tracksCount;i++)
{
painter->drawLine(rect.x(), 50 * i, rect.x() + rect.width(), 50 * i);
}
}
void CustomTrackView::drawForeground ( QPainter * painter, const QRectF & rect )
{
//kDebug()<<"///// DRAWING FB: "<<rect.x()<<", width: "<<rect.width();
painter->drawLine(m_cursorPos, rect.y(), m_cursorPos, rect.y() + rect.height());
}
#include "customtrackview.moc"
/***************************************************************************
* Copyright (C) 2007 by Jean-Baptiste Mardelle (jb@kdenlive.org) *
* *
* 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. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
***************************************************************************/
#ifndef CUSTOMTRACKVIEW_H
#define CUSTOMTRACKVIEW_H
#include <QGraphicsView>
#include "clipitem.h"
class CustomTrackView : public QGraphicsView
{
Q_OBJECT
public:
CustomTrackView(QGraphicsScene * scene, QWidget *parent=0);
virtual void mousePressEvent ( QMouseEvent * event );
virtual void mouseReleaseEvent ( QMouseEvent * event );
virtual void mouseMoveEvent ( QMouseEvent * event );
void addTrack();
void removeTrack();
void setCursorPos(int pos);
int cursorPos();
protected:
virtual void drawBackground ( QPainter * painter, const QRectF & rect );
virtual void drawForeground ( QPainter * painter, const QRectF & rect );
virtual void dragEnterEvent ( QDragEnterEvent * event );
virtual void dragMoveEvent(QDragMoveEvent * event);
virtual void dragLeaveEvent ( QDragLeaveEvent * event );
virtual void dropEvent ( QDropEvent * event );
virtual QStringList mimeTypes() const;
virtual Qt::DropActions supportedDropActions () const;
private:
int m_tracksCount;
int m_cursorPos;
ClipItem *m_dropItem;
void addItem(QString producer, QPoint pos);
signals:
void cursorMoved(int);
};
#endif
......@@ -17,6 +17,7 @@ DocumentAudioTrack::DocumentAudioTrack(QDomElement xml, TrackView * view, QWidge
}
// virtual
/*
void DocumentAudioTrack::paintEvent(QPaintEvent *e )
{
QRect region = e->rect();
......@@ -24,6 +25,6 @@ void DocumentAudioTrack::paintEvent(QPaintEvent *e )
painter.fillRect(region, QBrush(Qt::green));
painter.drawLine(region.bottomLeft (), region.bottomRight ());
}
*/
#include "documentaudiotrack.moc"
......@@ -12,7 +12,7 @@ class DocumentAudioTrack : public DocumentTrack
DocumentAudioTrack(QDomElement xml, TrackView * view, QWidget *parent=0);
protected:
virtual void paintEvent(QPaintEvent * /*e*/);
//virtual void paintEvent(QPaintEvent * /*e*/);
private:
TrackView *m_trackView;
......
......@@ -75,6 +75,7 @@ QList <TrackViewClip> DocumentTrack::clipList()
}
// virtual
/*
void DocumentTrack::paintEvent(QPaintEvent *e )
{
QRect region = e->rect();
......@@ -83,6 +84,6 @@ void DocumentTrack::paintEvent(QPaintEvent *e )
painter.fillRect(region, QBrush(Qt::red));
painter.drawLine(region.bottomLeft (), region.bottomRight ());
}
*/
#include "documenttrack.moc"
......@@ -30,7 +30,7 @@ class DocumentTrack : public QWidget
QStringList applicableFunctions(const QString & mode);
protected:
virtual void paintEvent(QPaintEvent * /*e*/);
//virtual void paintEvent(QPaintEvent * /*e*/);
private:
QDomElement m_xml;
......
......@@ -17,6 +17,7 @@ DocumentVideoTrack::DocumentVideoTrack(QDomElement xml, TrackView * view, QWidge
}
// virtual
/*
void DocumentVideoTrack::paintEvent(QPaintEvent *e )
{
QList <TrackViewClip> trackClipList = clipList();
......@@ -39,6 +40,6 @@ void DocumentVideoTrack::paintEvent(QPaintEvent *e )
painter.drawText(clipRect, Qt::AlignCenter, trackClipList.at(i).producer);
}
}
*/
#include "documentvideotrack.moc"
......@@ -13,7 +13,7 @@ class DocumentVideoTrack : public DocumentTrack
DocumentVideoTrack(QDomElement xml, TrackView * view, QWidget *parent=0);
protected:
virtual void paintEvent(QPaintEvent * /*e*/);
//virtual void paintEvent(QPaintEvent * /*e*/);
private:
TrackView *m_trackView;
......
......@@ -28,7 +28,7 @@
#include "kdenlivedoc.h"
KdenliveDoc::KdenliveDoc(KUrl url, double fps, int width, int height, QWidget *parent):QObject(parent), m_render(NULL), m_url(url), m_fps(fps), m_width(width), m_height(height), m_projectName(NULL)
KdenliveDoc::KdenliveDoc(const KUrl &url, double fps, int width, int height, QWidget *parent):QObject(parent), m_render(NULL), m_url(url), m_fps(fps), m_width(width), m_height(height), m_projectName(NULL)
{
m_commandStack = new KUndoStack();
......@@ -110,6 +110,23 @@ void KdenliveDoc::setRenderer(Render *render)
if (m_render) m_render->setSceneList(m_document);
}
QString KdenliveDoc::producerName(int id)
{
QString result = "unnamed";
QDomNodeList prods = producersList();
int ct = prods.count();
for (int i = 0; i < ct ; i++)
{
QDomElement e = prods.item(i).toElement();
if (e.attribute("id") != "black" && e.attribute("id").toInt() == id) {
result = e.attribute("name");
if (result.isEmpty()) result = KUrl(e.attribute("resource")).fileName();
break;
}
}
return result;
}
QDomDocument KdenliveDoc::generateSceneList()
{
QDomDocument doc;
......
......@@ -37,7 +37,7 @@
class KdenliveDoc:public QObject {
Q_OBJECT public:
KdenliveDoc(KUrl url, double fps, int width, int height, QWidget *parent = 0);
KdenliveDoc(const KUrl &url, double fps, int width, int height, QWidget *parent = 0);
~KdenliveDoc();
QString documentName();
QDomNodeList producersList();
......@@ -50,6 +50,7 @@ class KdenliveDoc:public QObject {
QDomDocument toXml();
void setRenderer(Render *render);
KUndoStack *commandStack();
QString producerName(int id);
private:
KUrl m_url;
......
/***************************************************************************
* Copyright (C) 2007 by Jean-Baptiste Mardelle (jb@kdenlive.org) *
* *