From: Till T. <ro...@tt...> - 2012-05-31 10:15:06
|
Git commit 4381f2976aa592e072c402e1447e6215f2598c76 by Till Theato. Committed on 27/05/2012 at 11:17. Pushed by theato into branch 'refactoring'. First work on timeline view (read only). M +2 -0 src/core/CMakeLists.txt M +25 -0 src/core/project/abstracttimelineclip.cpp M +7 -0 src/core/project/abstracttimelineclip.h M +5 -0 src/core/project/timeline.cpp M +1 -0 src/core/project/timeline.h M +36 -2 src/core/project/timelinetrack.cpp M +12 -1 src/core/project/timelinetrack.h A +7 -0 src/core/timelineview/CMakeLists.txt A +54 -0 src/core/timelineview/timelineclipitem.cpp [License: GPL] A +35 -0 src/core/timelineview/timelineclipitem.h [License: GPL] A +61 -0 src/core/timelineview/timelinescene.cpp [License: GPL] A +41 -0 src/core/timelineview/timelinescene.h [License: GPL] A +60 -0 src/core/timelineview/timelinetrackitem.cpp [License: GPL] A +40 -0 src/core/timelineview/timelinetrackitem.h [License: GPL] M +9 -2 src/mainwindow.cpp http://commits.kde.org/kdenlive/4381f2976aa592e072c402e1447e6215f2598c76 diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index 08b8a0f..ad1e3ef 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -2,12 +2,14 @@ add_subdirectory(bin) add_subdirectory(effectsystem) add_subdirectory(project) +add_subdirectory(timelineview) add_subdirectory(widgets) set(kdenlivecore_LIB_SRCS ${bin_SRCS} ${effectsystem_SRCS} ${project_SRCS} + ${timelineview_SRCS} ${widget_SRCS} ) diff --git a/src/core/project/abstracttimelineclip.cpp b/src/core/project/abstracttimelineclip.cpp index 2af6d48..08b941d 100644 --- a/src/core/project/abstracttimelineclip.cpp +++ b/src/core/project/abstracttimelineclip.cpp @@ -43,4 +43,29 @@ TimelineTrack* AbstractTimelineClip::track() return m_parent; } +int AbstractTimelineClip::position() const +{ + return m_parent->clipPosition(this); +} + +int AbstractTimelineClip::duration() const +{ + return m_producer->get_playtime(); +} + +int AbstractTimelineClip::in() const +{ + return m_producer->get_in(); +} + +int AbstractTimelineClip::out() const +{ + return m_producer->get_out(); +} + +QString AbstractTimelineClip::name() const +{ + return m_projectClip->name(); +} + #include "abstracttimelineclip.moc" diff --git a/src/core/project/abstracttimelineclip.h b/src/core/project/abstracttimelineclip.h index 21b08fb..1adc3ce 100644 --- a/src/core/project/abstracttimelineclip.h +++ b/src/core/project/abstracttimelineclip.h @@ -31,6 +31,13 @@ public: AbstractProjectClip *projectClip(); TimelineTrack *track(); + int position() const; + int duration() const; + int in() const; + int out() const; + + QString name() const; + protected: ProducerWrapper *m_producer; AbstractProjectClip *m_projectClip; diff --git a/src/core/project/timeline.cpp b/src/core/project/timeline.cpp index 0283ecd..4c92c35 100644 --- a/src/core/project/timeline.cpp +++ b/src/core/project/timeline.cpp @@ -59,4 +59,9 @@ Project* Timeline::project() return m_parent; } +QList< TimelineTrack* > Timeline::tracks() +{ + return m_tracks; +} + #include "timeline.moc" diff --git a/src/core/project/timeline.h b/src/core/project/timeline.h index b8a597b..69f8900 100644 --- a/src/core/project/timeline.h +++ b/src/core/project/timeline.h @@ -32,6 +32,7 @@ public: virtual ~Timeline(); Project *project(); + QList<TimelineTrack *> tracks(); private: Project *m_parent; diff --git a/src/core/project/timelinetrack.cpp b/src/core/project/timelinetrack.cpp index 4d04bdd..d16a84c 100644 --- a/src/core/project/timelinetrack.cpp +++ b/src/core/project/timelinetrack.cpp @@ -33,7 +33,7 @@ TimelineTrack::TimelineTrack(ProducerWrapper* producer, Timeline* parent) : if (projectClip) { kDebug() << "project clip found" << id; AbstractTimelineClip *clip = projectClip->addInstance(clipProducer, this); - m_clips.append(clip); + m_clips.insert(i, clip); } else { kDebug() << "project clip not found" << id; delete clipProducer; @@ -42,7 +42,7 @@ TimelineTrack::TimelineTrack(ProducerWrapper* producer, Timeline* parent) : delete clipProducer; } } - kDebug() << "track created" << m_clips.count() << m_playlist->count(); + kDebug() << "track created" << producer->get("name") << m_clips.count() << m_playlist->count(); } TimelineTrack::~TimelineTrack() @@ -51,5 +51,39 @@ TimelineTrack::~TimelineTrack() delete m_producer; } +Timeline* TimelineTrack::timeline() +{ + return m_parent; +} + +ProducerWrapper* TimelineTrack::producer() +{ + return m_producer; +} + +Mlt::Playlist* TimelineTrack::playlist() +{ + return m_playlist; +} + +QList< AbstractTimelineClip* > TimelineTrack::clips() +{ + return m_clips.values(); +} + +int TimelineTrack::clipPosition(const AbstractTimelineClip* clip) const +{ + return m_playlist->clip(mlt_whence_relative_start, m_clips.key(const_cast<AbstractTimelineClip*>(clip))); +} + +QString TimelineTrack::name() const +{ + return QString(); +} + +void TimelineTrack::setName(const QString& name) +{ + +} #include "timelinetrack.moc" diff --git a/src/core/project/timelinetrack.h b/src/core/project/timelinetrack.h index 673c4ee..bc920f5 100644 --- a/src/core/project/timelinetrack.h +++ b/src/core/project/timelinetrack.h @@ -12,6 +12,7 @@ the Free Software Foundation, either version 3 of the License, or #define TIMELINETRACK_H #include <QObject> +#include <QMap> #include <kdemacros.h> class Timeline; @@ -32,12 +33,22 @@ public: TimelineTrack(ProducerWrapper *producer, Timeline* parent = 0); virtual ~TimelineTrack(); + Timeline *timeline(); + ProducerWrapper *producer(); + Mlt::Playlist *playlist(); + + QList<AbstractTimelineClip*> clips(); + int clipPosition(const AbstractTimelineClip *clip) const; + + QString name() const; + void setName(const QString &name); + private: Timeline *m_parent; ProducerWrapper *m_producer; Mlt::Playlist *m_playlist; EffectDevice *m_effectDevice; - QList<AbstractTimelineClip *> m_clips; + QMap<int, AbstractTimelineClip *> m_clips; }; #endif diff --git a/src/core/timelineview/CMakeLists.txt b/src/core/timelineview/CMakeLists.txt new file mode 100644 index 0000000..1e74f83 --- /dev/null +++ b/src/core/timelineview/CMakeLists.txt @@ -0,0 +1,7 @@ + +set(timelineview_SRCS + timelineview/timelineclipitem.cpp + timelineview/timelinescene.cpp + timelineview/timelinetrackitem.cpp + PARENT_SCOPE +) diff --git a/src/core/timelineview/timelineclipitem.cpp b/src/core/timelineview/timelineclipitem.cpp new file mode 100644 index 0000000..f647385 --- /dev/null +++ b/src/core/timelineview/timelineclipitem.cpp @@ -0,0 +1,54 @@ +/* +Copyright (C) 2012 Till Theato <ro...@tt...> +This file is part of kdenlive. See www.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 3 of the License, or +(at your option) any later version. +*/ + +#include "timelineclipitem.h" +#include "project/abstracttimelineclip.h" +#include <QPainter> +#include <QStyleOptionGraphicsItem> + + +TimelineClipItem::TimelineClipItem(AbstractTimelineClip* clip, QGraphicsRectItem* parent) : + QGraphicsRectItem(parent), + m_clip(clip) +{ + setRect(m_clip->position(), 0, m_clip->duration(), parent->rect().height()); + + setBrush(Qt::green); +} + +TimelineClipItem::~TimelineClipItem() +{ +} + + +AbstractTimelineClip* TimelineClipItem::clip() +{ + return m_clip; +} + +void TimelineClipItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) +{ + Q_UNUSED(option) + Q_UNUSED(widget) + + painter->fillRect(boundingRect(), brush()); + + const QRectF textBounding = painter->boundingRect(rect(), Qt::AlignHCenter | Qt::AlignVCenter, ' ' + m_clip->name() + ' '); + painter->setRenderHint(QPainter::Antialiasing, true); + painter->setBrush(Qt::blue); + painter->setPen(Qt::NoPen); + painter->drawRoundedRect(textBounding, 3, 3); + painter->setBrush(Qt::NoBrush); + + painter->setPen(Qt::white); + painter->drawText(textBounding, Qt::AlignCenter, m_clip->name()); +} + +#include "timelineclipitem.moc" diff --git a/src/core/timelineview/timelineclipitem.h b/src/core/timelineview/timelineclipitem.h new file mode 100644 index 0000000..8d7d4ef --- /dev/null +++ b/src/core/timelineview/timelineclipitem.h @@ -0,0 +1,35 @@ +/* +Copyright (C) 2012 Till Theato <ro...@tt...> +This file is part of kdenlive. See www.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 3 of the License, or +(at your option) any later version. +*/ + +#ifndef TIMELINECLIPITEM_H +#define TIMELINECLIPITEM_H + +#include <QGraphicsRectItem> + +class AbstractTimelineClip; + + +class TimelineClipItem : public QObject, public QGraphicsRectItem +{ + Q_OBJECT + +public: + TimelineClipItem(AbstractTimelineClip *clip, QGraphicsRectItem* parent = 0); + virtual ~TimelineClipItem(); + + AbstractTimelineClip *clip(); + + void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0); + +private: + AbstractTimelineClip *m_clip; +}; + +#endif diff --git a/src/core/timelineview/timelinescene.cpp b/src/core/timelineview/timelinescene.cpp new file mode 100644 index 0000000..b307285 --- /dev/null +++ b/src/core/timelineview/timelinescene.cpp @@ -0,0 +1,61 @@ +/* +Copyright (C) 2012 Till Theato <ro...@tt...> +This file is part of kdenlive. See www.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 3 of the License, or +(at your option) any later version. +*/ + +#include "timelinescene.h" +#include "timelinetrackitem.h" +#include "project/timeline.h" +#include "project/timelinetrack.h" + + +TimelineScene::TimelineScene(Timeline* timeline, QObject* parent) : + QGraphicsScene(parent), + m_timeline(timeline) +{ + setupTimeline(); + positionTracks(); +} + +TimelineScene::~TimelineScene() +{ +} + +Timeline* TimelineScene::timeline() +{ + return m_timeline; +} + +void TimelineScene::positionTracks(TimelineTrackItem *after) +{ + int i = 0; + qreal position = 0; + + if (after) { + i = m_trackItems.indexOf(after) + 1; + position = after->rect().bottom(); + } + + for (; i < m_trackItems.count(); ++i) { + m_trackItems.at(i)->setY(position); + position += m_trackItems.at(i)->rect().height(); + } +} + +void TimelineScene::setupTimeline() +{ + QList<TimelineTrack*> tracks = m_timeline->tracks(); + foreach (TimelineTrack *track, tracks) { + TimelineTrackItem *trackItem = new TimelineTrackItem(track, this); + addItem(trackItem); + m_trackItems.append(trackItem); + } +} + + +#include "timelinescene.moc" diff --git a/src/core/timelineview/timelinescene.h b/src/core/timelineview/timelinescene.h new file mode 100644 index 0000000..3915360 --- /dev/null +++ b/src/core/timelineview/timelinescene.h @@ -0,0 +1,41 @@ +/* +Copyright (C) 2012 Till Theato <ro...@tt...> +This file is part of kdenlive. See www.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 3 of the License, or +(at your option) any later version. +*/ + +#ifndef TIMELINESCENE_H +#define TIMELINESCENE_H + +#include <QGraphicsScene> +#include <kdemacros.h> + +class Timeline; +class TimelineTrackItem; + + +class KDE_EXPORT TimelineScene : public QGraphicsScene +{ + Q_OBJECT + +public: + TimelineScene(Timeline *timeline, QObject* parent = 0); + ~TimelineScene(); + + Timeline *timeline(); + +public slots: + void positionTracks(TimelineTrackItem *after = 0); + +private: + void setupTimeline(); + + Timeline *m_timeline; + QList <TimelineTrackItem*> m_trackItems; +}; + +#endif diff --git a/src/core/timelineview/timelinetrackitem.cpp b/src/core/timelineview/timelinetrackitem.cpp new file mode 100644 index 0000000..2a764c1 --- /dev/null +++ b/src/core/timelineview/timelinetrackitem.cpp @@ -0,0 +1,60 @@ +/* +Copyright (C) 2012 Till Theato <ro...@tt...> +This file is part of kdenlive. See www.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 3 of the License, or +(at your option) any later version. +*/ + +#include "timelinetrackitem.h" +#include "timelinescene.h" +#include "timelineclipitem.h" +#include "project/timelinetrack.h" +#include "project/abstracttimelineclip.h" + + +TimelineTrackItem::TimelineTrackItem(TimelineTrack* track, QObject* parent) : + QObject(parent), + m_track(track) +{ + setRect(0, 0, 0, 50); + setBrush(Qt::red); + + loadClips(); + adjustLength(); +} + +TimelineTrackItem::~TimelineTrackItem() +{ + +} + +TimelineTrack* TimelineTrackItem::track() +{ + return m_track; +} + +void TimelineTrackItem::adjustLength() +{ + QRectF r = rect(); + if (m_clipItems.isEmpty()) { + r.setWidth(0); + } else { + r.setWidth(m_clipItems.last()->rect().right()); + } + setRect(r); +} + +void TimelineTrackItem::loadClips() +{ + QList <AbstractTimelineClip*> clips = m_track->clips(); + foreach(AbstractTimelineClip *clip, clips) { + TimelineClipItem *item = new TimelineClipItem(clip, this); + m_clipItems.append(item); + } +} + + +#include "timelinetrackitem.moc" diff --git a/src/core/timelineview/timelinetrackitem.h b/src/core/timelineview/timelinetrackitem.h new file mode 100644 index 0000000..d6cf183 --- /dev/null +++ b/src/core/timelineview/timelinetrackitem.h @@ -0,0 +1,40 @@ +/* +Copyright (C) 2012 Till Theato <ro...@tt...> +This file is part of kdenlive. See www.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 3 of the License, or +(at your option) any later version. +*/ + +#ifndef TIMELINETRACKITEM_H +#define TIMELINETRACKITEM_H + +#include <QGraphicsRectItem> + +class TimelineTrack; +class TimelineClipItem; + + +class TimelineTrackItem : public QObject, public QGraphicsRectItem +{ + Q_OBJECT + +public: + TimelineTrackItem(TimelineTrack *track, QObject* parent = 0); + virtual ~TimelineTrackItem(); + + TimelineTrack *track(); + +public slots: + void adjustLength(); + +private: + void loadClips(); + + TimelineTrack *m_track; + QList<TimelineClipItem*> m_clipItems; +}; + +#endif diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index d67e4c8..cf56118 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -123,6 +123,8 @@ #include "core/project/project.h" #include "core/project/clippluginmanager.h" #include "core/bin/bin.h" +#include "core/timelineview/timelinescene.h" +#include <QGraphicsView> // Uncomment for deeper debugging @@ -233,8 +235,13 @@ MainWindow::MainWindow(const QString &MltPath, const KUrl & Url, const QString & m_project = new Project(Url, m_cpm); m_bin->setProject(m_project); - - + + QDockWidget *timelineTest = new QDockWidget(i18n("Timeline"), this); + timelineTest->setObjectName("timeline_test"); + TimelineScene *scene = new TimelineScene(m_project->timeline(), this);//static_cast<QObject*>(this)); + QGraphicsView *viewT = new QGraphicsView(scene, timelineTest); + timelineTest->setWidget(viewT); + addDockWidget(Qt::BottomDockWidgetArea, timelineTest); m_monitorManager = new MonitorManager(); m_shortcutRemoveFocus = new QShortcut(QKeySequence("Esc"), this); |