From 2a223cff6e45c560c28857b72c0cb7e584f9a4ef Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Mardelle Date: Mon, 3 Mar 2008 11:54:36 +0000 Subject: [PATCH] Reindent all source files svn path=/branches/KDE4/; revision=1987 --- src/addclipcommand.cpp | 30 +- src/addclipcommand.h | 19 +- src/addeffectcommand.cpp | 30 +- src/addeffectcommand.h | 21 +- src/addtimelineclipcommand.cpp | 32 +- src/addtimelineclipcommand.h | 29 +- src/clipitem.cpp | 963 +++++++++++----------- src/clipitem.h | 39 +- src/clipmanager.cpp | 85 +- src/clipmanager.h | 6 +- src/complexparameter.cpp | 163 ++-- src/complexparameter.h | 59 +- src/customruler.cpp | 292 ++++--- src/customruler.h | 31 +- src/customtrackview.cpp | 1196 +++++++++++++--------------- src/customtrackview.h | 48 +- src/definitions.h | 8 +- src/docclipbase.cpp | 403 +++++----- src/docclipbase.h | 212 ++--- src/documentaudiotrack.cpp | 5 +- src/documentaudiotrack.h | 17 +- src/documenttrack.cpp | 84 +- src/documenttrack.h | 21 +- src/documentvideotrack.cpp | 5 +- src/documentvideotrack.h | 19 +- src/editeffectcommand.cpp | 44 +- src/editeffectcommand.h | 25 +- src/effectslist.cpp | 100 ++- src/effectslist.h | 20 +- src/effectslistview.cpp | 97 +-- src/effectslistview.h | 21 +- src/effectslistwidget.cpp | 198 +++-- src/effectslistwidget.h | 17 +- src/effectstackedit.cpp | 363 +++++---- src/effectstackedit.h | 31 +- src/effectstackview.cpp | 338 ++++---- src/effectstackview.h | 61 +- src/events.h | 12 +- src/gentime.cpp | 18 +- src/gentime.h | 80 +- src/graphicsscenerectmove.cpp | 240 +++--- src/graphicsscenerectmove.h | 10 +- src/headertrack.cpp | 8 +- src/headertrack.h | 19 +- src/initeffects.cpp | 528 ++++++------ src/initeffects.h | 45 +- src/kdenlivedoc.cpp | 395 +++++---- src/kdenlivedoc.h | 12 +- src/kdenlivesettingsdialog.cpp | 84 +- src/kdenlivesettingsdialog.h | 17 +- src/kthumb.cpp | 374 +++++---- src/kthumb.h | 82 +- src/labelitem.cpp | 27 +- src/labelitem.h | 9 +- src/main.cpp | 50 +- src/mainwindow.cpp | 789 +++++++++--------- src/mainwindow.h | 29 +- src/monitor.cpp | 314 ++++---- src/monitor.h | 27 +- src/monitormanager.cpp | 76 +- src/monitormanager.h | 19 +- src/moveclipcommand.cpp | 26 +- src/moveclipcommand.h | 19 +- src/parameterplotter.cpp | 418 +++++----- src/parameterplotter.h | 72 +- src/profilesdialog.cpp | 258 +++--- src/profilesdialog.h | 19 +- src/projectitem.cpp | 412 +++++----- src/projectitem.h | 7 +- src/projectlist.cpp | 683 ++++++++-------- src/projectlist.h | 123 ++- src/projectlistview.cpp | 259 +++--- src/projectlistview.h | 29 +- src/projectsettings.cpp | 36 +- src/projectsettings.h | 13 +- src/renderer.cpp | 1153 +++++++++++++-------------- src/renderer.h | 184 ++--- src/resizeclipcommand.cpp | 26 +- src/resizeclipcommand.h | 21 +- src/smallruler.cpp | 204 +++-- src/smallruler.h | 29 +- src/timecode.cpp | 148 ++-- src/timecode.h | 24 +- src/titledocument.cpp | 340 ++++---- src/titledocument.h | 24 +- src/titlewidget.cpp | 419 +++++----- src/titlewidget.h | 60 +- src/trackpanelclipmovefunction.cpp | 720 ++++++++--------- src/trackpanelclipmovefunction.h | 146 ++-- src/trackpanelfunction.cpp | 6 +- src/trackpanelfunction.h | 62 +- src/trackpanelfunctionfactory.cpp | 31 +- src/trackpanelfunctionfactory.h | 8 +- src/trackview.cpp | 438 +++++----- src/trackview.h | 23 +- 95 files changed, 7108 insertions(+), 7728 deletions(-) diff --git a/src/addclipcommand.cpp b/src/addclipcommand.cpp index 1408a5b5..7566bf76 100644 --- a/src/addclipcommand.cpp +++ b/src/addclipcommand.cpp @@ -22,25 +22,23 @@ #include "addclipcommand.h" AddClipCommand::AddClipCommand(KdenliveDoc *doc, const QDomElement &xml, const uint id, bool doIt) - : m_doc(doc), m_xml(xml), m_id(id), m_doIt(doIt) { - if (doIt) setText(i18n("Add clip")); - else setText(i18n("Delete clip")); - } + : m_doc(doc), m_xml(xml), m_id(id), m_doIt(doIt) { + if (doIt) setText(i18n("Add clip")); + else setText(i18n("Delete clip")); +} -// virtual -void AddClipCommand::undo() -{ -kDebug()<<"---- undoing action"; - if (m_doIt) m_doc->deleteClip(m_id); - else m_doc->addClip(m_xml, m_id); +// virtual +void AddClipCommand::undo() { + kDebug() << "---- undoing action"; + if (m_doIt) m_doc->deleteClip(m_id); + else m_doc->addClip(m_xml, m_id); } -// virtual -void AddClipCommand::redo() -{ -kDebug()<<"---- redoing action"; - if (m_doIt) m_doc->addClip(m_xml, m_id); - else m_doc->deleteClip(m_id); +// virtual +void AddClipCommand::redo() { + kDebug() << "---- redoing action"; + if (m_doIt) m_doc->addClip(m_xml, m_id); + else m_doc->deleteClip(m_id); } #include "addclipcommand.moc" diff --git a/src/addclipcommand.h b/src/addclipcommand.h index afa2068a..37ee141f 100644 --- a/src/addclipcommand.h +++ b/src/addclipcommand.h @@ -26,20 +26,19 @@ #include "kdenlivedoc.h" -class AddClipCommand : public QUndoCommand - { - public: - AddClipCommand(KdenliveDoc *list, const QDomElement &xml, const uint id, bool doIt); +class AddClipCommand : public QUndoCommand { +public: + AddClipCommand(KdenliveDoc *list, const QDomElement &xml, const uint id, bool doIt); virtual void undo(); virtual void redo(); - private: - KdenliveDoc *m_doc; - QDomElement m_xml; - uint m_id; - bool m_doIt; - }; +private: + KdenliveDoc *m_doc; + QDomElement m_xml; + uint m_id; + bool m_doIt; +}; #endif diff --git a/src/addeffectcommand.cpp b/src/addeffectcommand.cpp index 00bf663d..48a234dc 100644 --- a/src/addeffectcommand.cpp +++ b/src/addeffectcommand.cpp @@ -22,25 +22,23 @@ #include "addeffectcommand.h" AddEffectCommand::AddEffectCommand(CustomTrackView *view, const int track, GenTime pos, QDomElement effect, bool doIt) - : m_view(view), m_track(track), m_pos(pos), m_effect(effect), m_doIt(doIt) { - if (doIt) setText(i18n("Add effect")); - else setText(i18n("Delete effect")); - } + : m_view(view), m_track(track), m_pos(pos), m_effect(effect), m_doIt(doIt) { + if (doIt) setText(i18n("Add effect")); + else setText(i18n("Delete effect")); +} -// virtual -void AddEffectCommand::undo() -{ -kDebug()<<"---- undoing action"; - if (m_doIt) m_view->deleteEffect(m_track, m_pos, m_effect); - else m_view->addEffect(m_track, m_pos, m_effect); +// virtual +void AddEffectCommand::undo() { + kDebug() << "---- undoing action"; + if (m_doIt) m_view->deleteEffect(m_track, m_pos, m_effect); + else m_view->addEffect(m_track, m_pos, m_effect); } -// virtual -void AddEffectCommand::redo() -{ -kDebug()<<"---- redoing action"; - if (m_doIt) m_view->addEffect(m_track, m_pos, m_effect); - else m_view->deleteEffect(m_track, m_pos, m_effect); +// virtual +void AddEffectCommand::redo() { + kDebug() << "---- redoing action"; + if (m_doIt) m_view->addEffect(m_track, m_pos, m_effect); + else m_view->deleteEffect(m_track, m_pos, m_effect); } #include "addeffectcommand.moc" diff --git a/src/addeffectcommand.h b/src/addeffectcommand.h index 942d9fe1..a62f7a81 100644 --- a/src/addeffectcommand.h +++ b/src/addeffectcommand.h @@ -26,21 +26,20 @@ #include "customtrackview.h" -class AddEffectCommand : public QUndoCommand - { - public: - AddEffectCommand(CustomTrackView *view, const int track, GenTime pos, QDomElement effect, bool doIt); +class AddEffectCommand : public QUndoCommand { +public: + AddEffectCommand(CustomTrackView *view, const int track, GenTime pos, QDomElement effect, bool doIt); virtual void undo(); virtual void redo(); - private: - CustomTrackView *m_view; - int m_track; - QDomElement m_effect; - GenTime m_pos; - bool m_doIt; - }; +private: + CustomTrackView *m_view; + int m_track; + QDomElement m_effect; + GenTime m_pos; + bool m_doIt; +}; #endif diff --git a/src/addtimelineclipcommand.cpp b/src/addtimelineclipcommand.cpp index 3d3f66a9..2401fdf3 100644 --- a/src/addtimelineclipcommand.cpp +++ b/src/addtimelineclipcommand.cpp @@ -22,26 +22,24 @@ #include "addtimelineclipcommand.h" AddTimelineClipCommand::AddTimelineClipCommand(CustomTrackView *view, QDomElement xml, int clipId, int track, int startpos, QRectF rect, int duration, bool doIt, bool doRemove) - : m_view(view), m_xml(xml), m_clipId(clipId), m_clipTrack(track), m_clipPos(startpos), m_clipRect(rect), m_clipDuration(duration), m_doIt(doIt), m_remove(doRemove) { - if (!m_remove) setText(i18n("Add timeline clip")); - else setText(i18n("Delete timeline clip")); - } + : m_view(view), m_xml(xml), m_clipId(clipId), m_clipTrack(track), m_clipPos(startpos), m_clipRect(rect), m_clipDuration(duration), m_doIt(doIt), m_remove(doRemove) { + if (!m_remove) setText(i18n("Add timeline clip")); + else setText(i18n("Delete timeline clip")); +} -// virtual -void AddTimelineClipCommand::undo() -{ - if (!m_remove) m_view->deleteClip(m_clipTrack, m_clipPos, m_clipRect); - else m_view->addClip(m_xml, m_clipId, m_clipTrack, m_clipPos, m_clipRect, m_clipDuration); +// virtual +void AddTimelineClipCommand::undo() { + if (!m_remove) m_view->deleteClip(m_clipTrack, m_clipPos, m_clipRect); + else m_view->addClip(m_xml, m_clipId, m_clipTrack, m_clipPos, m_clipRect, m_clipDuration); } -// virtual -void AddTimelineClipCommand::redo() -{ - if (m_doIt) { - if (!m_remove) m_view->addClip(m_xml, m_clipId, m_clipTrack, m_clipPos, m_clipRect, m_clipDuration); - else m_view->deleteClip(m_clipTrack, m_clipPos, m_clipRect); - } - m_doIt = true; +// virtual +void AddTimelineClipCommand::redo() { + if (m_doIt) { + if (!m_remove) m_view->addClip(m_xml, m_clipId, m_clipTrack, m_clipPos, m_clipRect, m_clipDuration); + else m_view->deleteClip(m_clipTrack, m_clipPos, m_clipRect); + } + m_doIt = true; } #include "addtimelineclipcommand.moc" diff --git a/src/addtimelineclipcommand.h b/src/addtimelineclipcommand.h index 8e398941..89ff4340 100644 --- a/src/addtimelineclipcommand.h +++ b/src/addtimelineclipcommand.h @@ -30,24 +30,23 @@ #include "projectlist.h" #include "customtrackview.h" -class AddTimelineClipCommand : public QUndoCommand - { - public: - AddTimelineClipCommand(CustomTrackView *view, QDomElement xml, int clipId, int track, int startpos, QRectF rect, int duration, bool doIt, bool doRemove); +class AddTimelineClipCommand : public QUndoCommand { +public: + AddTimelineClipCommand(CustomTrackView *view, QDomElement xml, int clipId, int track, int startpos, QRectF rect, int duration, bool doIt, bool doRemove); virtual void undo(); virtual void redo(); - private: - CustomTrackView *m_view; - int m_clipDuration; - int m_clipId; - QDomElement m_xml; - int m_clipTrack; - int m_clipPos; - QRectF m_clipRect; - bool m_doIt; - bool m_remove; - }; +private: + CustomTrackView *m_view; + int m_clipDuration; + int m_clipId; + QDomElement m_xml; + int m_clipTrack; + int m_clipPos; + QRectF m_clipRect; + bool m_doIt; + bool m_remove; +}; #endif diff --git a/src/clipitem.cpp b/src/clipitem.cpp index eca55b88..c39b1881 100644 --- a/src/clipitem.cpp +++ b/src/clipitem.cpp @@ -39,289 +39,265 @@ #include "kdenlivesettings.h" ClipItem::ClipItem(DocClipBase *clip, int track, int startpos, const QRectF & rect, int duration) -: QGraphicsRectItem(rect), m_clip(clip), m_resizeMode(NONE), m_grabPoint(0), m_maxTrack(0), m_track(track), m_startPos(startpos), m_hasThumbs(false), startThumbTimer(NULL), endThumbTimer(NULL), m_startFade(0), m_endFade(0), m_effectsCounter(1),audioThumbWasDrawn(false), m_opacity(1.0), m_timeLine(0), m_thumbsRequested(0) -{ - //setToolTip(name); - kDebug()<<"******* CREATING NEW TML CLIP, DUR: "<toXML(); - m_clipName = clip->name(); - m_producer = clip->getId(); - m_clipType = clip->clipType(); - m_cropStart = 0; - m_maxDuration = duration; - if (duration != -1) m_cropDuration = duration; - else m_cropDuration = m_maxDuration; - setAcceptDrops (true); - audioThumbReady = clip->audioThumbCreated(); -/* - 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;*/ - - - setFlags(QGraphicsItem::ItemClipsToShape | QGraphicsItem::ItemClipsChildrenToShape | QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable); - connect (this , SIGNAL (prepareAudioThumb(double,QPainterPath,int,int)) , this, SLOT (slotPrepareAudioThumb(double,QPainterPath,int,int))); - - setBrush(QColor(100, 100, 150)); - if (m_clipType == VIDEO || m_clipType == AV) { - m_hasThumbs = true; - connect(this, SIGNAL(getThumb(int, int)), clip->thumbProducer(), SLOT(extractImage(int, int))); - connect(clip->thumbProducer(), SIGNAL(thumbReady(int, QPixmap)), this, SLOT(slotThumbReady(int, QPixmap))); - connect(clip, SIGNAL (gotAudioData()), this, SLOT (slotGotAudioData())); - QTimer::singleShot(300, this, SLOT(slotFetchThumbs())); - - startThumbTimer = new QTimer(this); - startThumbTimer->setSingleShot(true); - connect(startThumbTimer, SIGNAL(timeout()), this, SLOT(slotGetStartThumb())); - endThumbTimer = new QTimer(this); - endThumbTimer->setSingleShot(true); - connect(endThumbTimer, SIGNAL(timeout()), this, SLOT(slotGetEndThumb())); - - } - else if (m_clipType == COLOR) { - QString colour = m_xml.attribute("colour"); - colour = colour.replace(0, 2, "#"); - setBrush(QColor(colour.left(7))); - } - else if (m_clipType == IMAGE) { - m_startPix = KThumb::getImage(KUrl(m_xml.attribute("resource")), 50 * KdenliveSettings::project_display_ratio(), 50); - } - else if (m_clipType == AUDIO) { - connect(clip, SIGNAL (gotAudioData()), this, SLOT (slotGotAudioData())); - } + : QGraphicsRectItem(rect), m_clip(clip), m_resizeMode(NONE), m_grabPoint(0), m_maxTrack(0), m_track(track), m_startPos(startpos), m_hasThumbs(false), startThumbTimer(NULL), endThumbTimer(NULL), m_startFade(0), m_endFade(0), m_effectsCounter(1), audioThumbWasDrawn(false), m_opacity(1.0), m_timeLine(0), m_thumbsRequested(0) { + //setToolTip(name); + kDebug() << "******* CREATING NEW TML CLIP, DUR: " << duration; + m_xml = clip->toXML(); + m_clipName = clip->name(); + m_producer = clip->getId(); + m_clipType = clip->clipType(); + m_cropStart = 0; + m_maxDuration = duration; + if (duration != -1) m_cropDuration = duration; + else m_cropDuration = m_maxDuration; + setAcceptDrops(true); + audioThumbReady = clip->audioThumbCreated(); + /* + 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;*/ + + + setFlags(QGraphicsItem::ItemClipsToShape | QGraphicsItem::ItemClipsChildrenToShape | QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable); + connect(this , SIGNAL(prepareAudioThumb(double, QPainterPath, int, int)) , this, SLOT(slotPrepareAudioThumb(double, QPainterPath, int, int))); + + setBrush(QColor(100, 100, 150)); + if (m_clipType == VIDEO || m_clipType == AV) { + m_hasThumbs = true; + connect(this, SIGNAL(getThumb(int, int)), clip->thumbProducer(), SLOT(extractImage(int, int))); + connect(clip->thumbProducer(), SIGNAL(thumbReady(int, QPixmap)), this, SLOT(slotThumbReady(int, QPixmap))); + connect(clip, SIGNAL(gotAudioData()), this, SLOT(slotGotAudioData())); + QTimer::singleShot(300, this, SLOT(slotFetchThumbs())); + + startThumbTimer = new QTimer(this); + startThumbTimer->setSingleShot(true); + connect(startThumbTimer, SIGNAL(timeout()), this, SLOT(slotGetStartThumb())); + endThumbTimer = new QTimer(this); + endThumbTimer->setSingleShot(true); + connect(endThumbTimer, SIGNAL(timeout()), this, SLOT(slotGetEndThumb())); + + } else if (m_clipType == COLOR) { + QString colour = m_xml.attribute("colour"); + colour = colour.replace(0, 2, "#"); + setBrush(QColor(colour.left(7))); + } else if (m_clipType == IMAGE) { + m_startPix = KThumb::getImage(KUrl(m_xml.attribute("resource")), 50 * KdenliveSettings::project_display_ratio(), 50); + } else if (m_clipType == AUDIO) { + connect(clip, SIGNAL(gotAudioData()), this, SLOT(slotGotAudioData())); + } } -ClipItem::~ClipItem() -{ - if (startThumbTimer) delete startThumbTimer; - if (endThumbTimer) delete endThumbTimer; +ClipItem::~ClipItem() { + if (startThumbTimer) delete startThumbTimer; + if (endThumbTimer) delete endThumbTimer; } -void ClipItem::slotFetchThumbs() -{ - m_thumbsRequested += 2; - emit getThumb(m_cropStart, m_cropStart + m_cropDuration); +void ClipItem::slotFetchThumbs() { + m_thumbsRequested += 2; + emit getThumb(m_cropStart, m_cropStart + m_cropDuration); } -void ClipItem::slotGetStartThumb() -{ - m_thumbsRequested++; - emit getThumb(m_cropStart, -1); +void ClipItem::slotGetStartThumb() { + m_thumbsRequested++; + emit getThumb(m_cropStart, -1); } -void ClipItem::slotGetEndThumb() -{ - m_thumbsRequested++; - emit getThumb(-1, m_cropStart + m_cropDuration); +void ClipItem::slotGetEndThumb() { + m_thumbsRequested++; + emit getThumb(-1, m_cropStart + m_cropDuration); } -void ClipItem::slotThumbReady(int frame, QPixmap pix) -{ - if (m_thumbsRequested == 0) return; - if (frame == m_cropStart) m_startPix = pix; - else m_endPix = pix; - update(); - m_thumbsRequested--; +void ClipItem::slotThumbReady(int frame, QPixmap pix) { + if (m_thumbsRequested == 0) return; + if (frame == m_cropStart) m_startPix = pix; + else m_endPix = pix; + update(); + m_thumbsRequested--; } -void ClipItem::slotGotAudioData(){ - audioThumbReady=true; - update(); +void ClipItem::slotGotAudioData() { + audioThumbReady = true; + update(); } -int ClipItem::type () const -{ - return 70000; +int ClipItem::type() const { + return 70000; } -DocClipBase *ClipItem::baseClip() -{ - return m_clip; +DocClipBase *ClipItem::baseClip() { + return m_clip; } -QDomElement ClipItem::xml() const -{ - return m_xml; +QDomElement ClipItem::xml() const { + return m_xml; } -int ClipItem::clipType() -{ - return m_clipType; +int ClipItem::clipType() { + return m_clipType; } -QString ClipItem::clipName() -{ - return m_clipName; +QString ClipItem::clipName() { + return m_clipName; } -int ClipItem::clipProducer() -{ - return m_producer; +int ClipItem::clipProducer() { + return m_producer; } -int ClipItem::maxDuration() -{ - return m_maxDuration; +int ClipItem::maxDuration() { + return m_maxDuration; } -int ClipItem::duration() -{ - return m_cropDuration; +int ClipItem::duration() { + return m_cropDuration; } -int ClipItem::startPos() -{ - return m_startPos; +int ClipItem::startPos() { + return m_startPos; } -int ClipItem::cropStart() -{ - return m_cropStart; +int ClipItem::cropStart() { + return m_cropStart; } -int ClipItem::endPos() -{ - return m_startPos + m_cropDuration; +int ClipItem::endPos() { + return m_startPos + m_cropDuration; } -void ClipItem::flashClip() -{ - if (m_timeLine == 0) { - m_timeLine = new QTimeLine(750, this); - connect(m_timeLine, SIGNAL(valueChanged(qreal)), this, SLOT(animate(qreal))); - } - m_timeLine->start(); +void ClipItem::flashClip() { + if (m_timeLine == 0) { + m_timeLine = new QTimeLine(750, this); + connect(m_timeLine, SIGNAL(valueChanged(qreal)), this, SLOT(animate(qreal))); + } + m_timeLine->start(); } -void ClipItem::animate(qreal value) -{ - m_opacity = value; - update(); +void ClipItem::animate(qreal value) { + m_opacity = value; + update(); } -// virtual - void ClipItem::paint(QPainter *painter, - const QStyleOptionGraphicsItem *option, - QWidget *widget) - { +// virtual +void ClipItem::paint(QPainter *painter, + const QStyleOptionGraphicsItem *option, + QWidget *widget) { painter->setOpacity(m_opacity); QBrush paintColor = brush(); if (isSelected()) paintColor = QBrush(QColor(150, 50, 100)); QRectF br = rect(); - QRect rectInView;//this is the rect that is visible by the user - if (scene()->views().size()>0){ - rectInView=scene()->views()[0]->viewport()->rect(); - rectInView.moveTo(scene()->views()[0]->horizontalScrollBar()->value(),scene()->views()[0]->verticalScrollBar()->value()); - rectInView.adjust(-10,-10,10,10);//make view rect 10 pixel greater on each site, or repaint after scroll event - //kDebug() << scene()->views()[0]->viewport()->rect() << " " << scene()->views()[0]->horizontalScrollBar()->value(); - } - if (rectInView.isNull()) - return; - QPainterPath clippath; - clippath.addRect(rectInView); - int startpixel=rectInView.x()-rect().x();//start and endpixel that is viewable from rect() - if (startpixel<0) - startpixel=0; - int endpixel=rectInView.width()+rectInView.x(); - if (endpixel<0) - endpixel=0; - + QRect rectInView;//this is the rect that is visible by the user + if (scene()->views().size() > 0) { + rectInView = scene()->views()[0]->viewport()->rect(); + rectInView.moveTo(scene()->views()[0]->horizontalScrollBar()->value(), scene()->views()[0]->verticalScrollBar()->value()); + rectInView.adjust(-10, -10, 10, 10);//make view rect 10 pixel greater on each site, or repaint after scroll event + //kDebug() << scene()->views()[0]->viewport()->rect() << " " << scene()->views()[0]->horizontalScrollBar()->value(); + } + if (rectInView.isNull()) + return; + QPainterPath clippath; + clippath.addRect(rectInView); + int startpixel = rectInView.x() - rect().x();//start and endpixel that is viewable from rect() + if (startpixel < 0) + startpixel = 0; + int endpixel = rectInView.width() + rectInView.x(); + if (endpixel < 0) + endpixel = 0; + painter->setRenderHints(QPainter::Antialiasing); - QPainterPath roundRectPathUpper,roundRectPathLower; + QPainterPath roundRectPathUpper, roundRectPathLower; 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: "<setClipPath(roundRectPathUpper.united(roundRectPathLower).intersected(clippath), Qt::IntersectClip); - //painter->fillPath(roundRectPath, brush()); //, QBrush(QColor(Qt::red))); - painter->fillRect(br.intersected(rectInView), paintColor); + roundRectPathUpper.moveTo(br.x() + br .width() - offset, br.y() + br.height() / 2 - offset); + roundRectPathUpper.arcTo(br.x() + br .width() - roundingX - offset, br.y(), roundingX, roundingY, 0.0, 90.0); + roundRectPathUpper.lineTo(br.x() + roundingX, br.y()); + roundRectPathUpper.arcTo(br.x() + offset, br.y(), roundingX, roundingY, 90.0, 90.0); + roundRectPathUpper.lineTo(br.x() + offset, br.y() + br.height() / 2 - offset); + roundRectPathUpper.closeSubpath(); + + roundRectPathLower.moveTo(br.x() + offset, br.y() + br.height() / 2 - offset); + roundRectPathLower.arcTo(br.x() + offset, br.y() + br.height() - roundingY - offset, roundingX, roundingY, 180.0, 90.0); + roundRectPathLower.lineTo(br.x() + br .width() - roundingX, br.y() + br.height() - offset); + roundRectPathLower.arcTo(br.x() + br .width() - roundingX - offset, br.y() + br.height() - roundingY - offset, roundingX, roundingY, 270.0, 90.0); + roundRectPathLower.lineTo(br.x() + br .width() - offset, br.y() + br.height() / 2 - offset); + roundRectPathLower.closeSubpath(); + + painter->setClipPath(roundRectPathUpper.united(roundRectPathLower).intersected(clippath), Qt::IntersectClip); + //painter->fillPath(roundRectPath, brush()); //, QBrush(QColor(Qt::red))); + painter->fillRect(br.intersected(rectInView), paintColor); //painter->fillRect(QRectF(br.x() + br.width() - m_endPix.width(), br.y(), m_endPix.width(), br.height()), QBrush(QColor(Qt::black))); // draw thumbnails if (!m_startPix.isNull()) { - if (m_clipType == IMAGE) { - painter->drawPixmap(QPointF(br.x() + br.width() - m_startPix.width(), br.y()), m_startPix); - QLineF l(br.x() + br.width() - m_startPix.width(), br.y(), br.x() + br.width() - m_startPix.width(), br.y() + br.height()); - painter->drawLine(l); - } else { - painter->drawPixmap(QPointF(br.x() + br.width() - m_endPix.width(), br.y()), m_endPix); - QLineF l(br.x() + br.width() - m_endPix.width(), br.y(), br.x() + br.width() - m_endPix.width(), br.y() + br.height()); - painter->drawLine(l); - } - - painter->drawPixmap(QPointF(br.x(), br.y()), m_startPix); - QLineF l2(br.x() + m_startPix.width(), br.y(), br.x() + m_startPix.width(), br.y() + br.height()); - painter->drawLine(l2); + if (m_clipType == IMAGE) { + painter->drawPixmap(QPointF(br.x() + br.width() - m_startPix.width(), br.y()), m_startPix); + QLineF l(br.x() + br.width() - m_startPix.width(), br.y(), br.x() + br.width() - m_startPix.width(), br.y() + br.height()); + painter->drawLine(l); + } else { + painter->drawPixmap(QPointF(br.x() + br.width() - m_endPix.width(), br.y()), m_endPix); + QLineF l(br.x() + br.width() - m_endPix.width(), br.y(), br.x() + br.width() - m_endPix.width(), br.y() + br.height()); + painter->drawLine(l); + } + + painter->drawPixmap(QPointF(br.x(), br.y()), m_startPix); + QLineF l2(br.x() + m_startPix.width(), br.y(), br.x() + m_startPix.width(), br.y() + br.height()); + painter->drawLine(l2); + } + if ((m_clipType == AV || m_clipType == AUDIO || true) && audioThumbReady) { + + QPainterPath path = m_clipType == AV ? roundRectPathLower : roundRectPathUpper.united(roundRectPathLower); + painter->fillPath(path, QBrush(QColor(200, 200, 200, 127))); + + int channels = 2; + double pixelForOneFrame = (double)br.width() / duration(); + if (pixelForOneFrame != framePixelWidth) + audioThumbCachePic.clear(); + emit prepareAudioThumb(pixelForOneFrame, path, startpixel, endpixel + 200);//200 more for less missing parts before repaint after scrolling + + for (int startCache = startpixel - startpixel % 100; startCache < endpixel + 300;startCache += 100) { + if (audioThumbCachePic.contains(startCache) && !audioThumbCachePic[startCache].isNull()) + painter->drawPixmap(path.boundingRect().x() + startCache, path.boundingRect().y(), audioThumbCachePic[startCache]); + } + } - if ( ( m_clipType == AV || m_clipType==AUDIO || true) && audioThumbReady ){ - - QPainterPath path= m_clipType==AV ? roundRectPathLower : roundRectPathUpper.united(roundRectPathLower); - painter->fillPath(path,QBrush(QColor(200,200,200,127))); - - int channels=2; - double pixelForOneFrame=(double)br.width()/duration(); - if (pixelForOneFrame!=framePixelWidth) - audioThumbCachePic.clear(); - emit prepareAudioThumb(pixelForOneFrame,path,startpixel,endpixel+200);//200 more for less missing parts before repaint after scrolling - - for (int startCache=startpixel-startpixel%100; startCache < endpixel+300;startCache+=100){ - if (audioThumbCachePic.contains(startCache) && !audioThumbCachePic[startCache].isNull() ) - painter->drawPixmap(path.boundingRect().x()+startCache,path.boundingRect().y(),audioThumbCachePic[startCache]); - } - - } // draw start / end fades double scale = br.width() / m_cropDuration; QBrush fades; if (isSelected()) { - fades = QBrush(QColor(200, 50, 50, 150)); - } - else fades = QBrush(QColor(200, 200, 200, 200)); + fades = QBrush(QColor(200, 50, 50, 150)); + } else fades = QBrush(QColor(200, 200, 200, 200)); if (m_startFade != 0) { - QPainterPath fadeInPath; - fadeInPath.moveTo(br.x() - offset, br.y()); - fadeInPath.lineTo(br.x() - offset, br.y() + br.height()); - fadeInPath.lineTo(br.x() + m_startFade * scale, br.y()); - fadeInPath.closeSubpath(); - painter->fillPath(fadeInPath, fades); - if (isSelected()) { - QLineF l(br.x() + m_startFade * scale, br.y(), br.x(), br.y() + br.height()); - painter->drawLine(l); - } + QPainterPath fadeInPath; + fadeInPath.moveTo(br.x() - offset, br.y()); + fadeInPath.lineTo(br.x() - offset, br.y() + br.height()); + fadeInPath.lineTo(br.x() + m_startFade * scale, br.y()); + fadeInPath.closeSubpath(); + painter->fillPath(fadeInPath, fades); + if (isSelected()) { + QLineF l(br.x() + m_startFade * scale, br.y(), br.x(), br.y() + br.height()); + painter->drawLine(l); + } } if (m_endFade != 0) { - QPainterPath fadeOutPath; - fadeOutPath.moveTo(br.x() + br.width(), br.y()); - fadeOutPath.lineTo(br.x() + br.width(), br.y() + br.height()); - fadeOutPath.lineTo(br.x() + br.width() - m_endFade * scale, br.y()); - fadeOutPath.closeSubpath(); - painter->fillPath(fadeOutPath, fades); - if (isSelected()) { - QLineF l(br.x() + br.width() - m_endFade * scale, br.y(), br.x() + br.width(), br.y() + br.height()); - painter->drawLine(l); - } + QPainterPath fadeOutPath; + fadeOutPath.moveTo(br.x() + br.width(), br.y()); + fadeOutPath.lineTo(br.x() + br.width(), br.y() + br.height()); + fadeOutPath.lineTo(br.x() + br.width() - m_endFade * scale, br.y()); + fadeOutPath.closeSubpath(); + painter->fillPath(fadeOutPath, fades); + if (isSelected()) { + QLineF l(br.x() + br.width() - m_endFade * scale, br.y(), br.x() + br.width(), br.y() + br.height()); + painter->drawLine(l); + } } QPen pen = painter->pen(); @@ -330,17 +306,17 @@ void ClipItem::animate(qreal value) // Draw clip name QString effects = effectNames().join(" / "); if (!effects.isEmpty()) { - painter->setPen(pen); - QFont font = painter->font(); - QFont smallFont = font; - smallFont.setPointSize(8); - painter->setFont(smallFont); - QRectF txtBounding = painter->boundingRect(br, Qt::AlignLeft | Qt::AlignTop, " " + effects + " "); - painter->fillRect(txtBounding, QBrush(QColor(0,0,0,150))); - painter->drawText(txtBounding, Qt::AlignCenter, effects); - pen.setColor(Qt::black); - painter->setPen(pen); - painter->setFont(font); + painter->setPen(pen); + QFont font = painter->font(); + QFont smallFont = font; + smallFont.setPointSize(8); + painter->setFont(smallFont); + QRectF txtBounding = painter->boundingRect(br, Qt::AlignLeft | Qt::AlignTop, " " + effects + " "); + painter->fillRect(txtBounding, QBrush(QColor(0, 0, 0, 150))); + painter->drawText(txtBounding, Qt::AlignCenter, effects); + pen.setColor(Qt::black); + painter->setPen(pen); + painter->setFont(font); } pen.setColor(Qt::red); @@ -350,11 +326,11 @@ void ClipItem::animate(qreal value) painter->drawPath(roundRectPathUpper.united(roundRectPathLower).intersected(clippath)); QRectF txtBounding = painter->boundingRect(br, Qt::AlignCenter, " " + m_clipName + " "); - painter->fillRect(txtBounding, QBrush(QColor(255,255,255,150))); + painter->fillRect(txtBounding, QBrush(QColor(255, 255, 255, 150))); painter->drawText(txtBounding, Qt::AlignCenter, m_clipName); - //painter->fillRect(startpixel,0,startpixel+endpixel,(int)br.height(), QBrush(QColor(255,255,255,150))); + //painter->fillRect(startpixel,0,startpixel+endpixel,(int)br.height(), QBrush(QColor(255,255,255,150))); //painter->fillRect(QRect(br.x(), br.y(), roundingX, roundingY), QBrush(QColor(Qt::green))); /*QRectF recta(rect().x(), rect().y(), scale,rect().height()); @@ -372,12 +348,11 @@ void ClipItem::animate(qreal value) //kDebug()<<"ITEM REPAINT RECT: "<drawText(rect(), Qt::AlignCenter, m_name); // painter->drawRect(boundingRect()); - //painter->drawRoundRect(-10, -10, 20, 20); - } + //painter->drawRoundRect(-10, -10, 20, 20); +} -OPERATIONTYPE ClipItem::operationMode(QPointF pos, double scale) -{ +OPERATIONTYPE ClipItem::operationMode(QPointF pos, double scale) { if (abs(pos.x() - (rect().x() + scale * m_startFade)) < 6 && abs(pos.y() - rect().y()) < 6) return FADEIN; else if (abs(pos.x() - rect().x()) < 6) return RESIZESTART; else if (abs(pos.x() - (rect().x() + rect().width() - scale * m_endFade)) < 6 && abs(pos.y() - rect().y()) < 6) return FADEOUT; @@ -385,186 +360,174 @@ OPERATIONTYPE ClipItem::operationMode(QPointF pos, double scale) return MOVE; } -void ClipItem::slotPrepareAudioThumb(double pixelForOneFrame,QPainterPath path,int startpixel, int endpixel){ - int channels=2; - - QRectF re=path.boundingRect(); - - //if ( (!audioThumbWasDrawn || framePixelWidth!=pixelForOneFrame ) && !baseClip()->audioFrameChache.isEmpty()){ - - for (int startCache=startpixel-startpixel%100;startCache+100 positiveChannelPaths; - QMap negativeChannelPaths; - QPainter pixpainter(&audioThumbCachePic[startCache]); - QPen audiopen; - audiopen.setWidth(0); - pixpainter.setPen(audiopen); - //pixpainter.setRenderHint(QPainter::Antialiasing,true); - //pixpainter.drawLine(0,0,100,re.height()); - int channelHeight=audioThumbCachePic[startCache].height()/channels; - - for (int i=0;i19 ) - continue; - QMap frame_channel_data=baseClip()->audioFrameChache[(int)frame]; - - for (int channel=0;channel 0;channel++){ - - int y=channelHeight*channel+ channelHeight/2; - int delta=(int)(frame_channel_data[channel][sample] -127/2 ) * channelHeight/ 64; - if (fullAreaDraw){ - positiveChannelPaths[channel].lineTo(samples,0.1+y+qAbs( delta )); - negativeChannelPaths[channel].lineTo(samples,0.1+y-qAbs( delta )); - }else{ - positiveChannelPaths[channel].lineTo(samples,0.1+y+delta); - negativeChannelPaths[channel].lineTo(samples,0.1+y-delta); - } - } - for (int channel=0;channelaudioFrameChache.isEmpty()){ + + for (int startCache = startpixel - startpixel % 100;startCache + 100 < endpixel ;startCache += 100) { + //kDebug() << "creating " << startCache; + //if (framePixelWidth!=pixelForOneFrame || + if (framePixelWidth == pixelForOneFrame && audioThumbCachePic.contains(startCache)) + continue; + if (audioThumbCachePic[startCache].isNull() || framePixelWidth != pixelForOneFrame) { + audioThumbCachePic[startCache] = QPixmap(100, re.height()); + audioThumbCachePic[startCache].fill(QColor(200, 200, 200, 127)); + } + bool fullAreaDraw = pixelForOneFrame < 10; + QMap positiveChannelPaths; + QMap negativeChannelPaths; + QPainter pixpainter(&audioThumbCachePic[startCache]); + QPen audiopen; + audiopen.setWidth(0); + pixpainter.setPen(audiopen); + //pixpainter.setRenderHint(QPainter::Antialiasing,true); + //pixpainter.drawLine(0,0,100,re.height()); + int channelHeight = audioThumbCachePic[startCache].height() / channels; + + for (int i = 0;i < channels;i++) { + + positiveChannelPaths[i].moveTo(0, channelHeight*i + channelHeight / 2); + negativeChannelPaths[i].moveTo(0, channelHeight*i + channelHeight / 2); + } + + for (int samples = 0;samples <= 100;samples++) { + double frame = (double)(samples + startCache - 0) / pixelForOneFrame; + int sample = (frame - (int)(frame)) * 20 ;// AUDIO_FRAME_SIZE + if (frame < 0 || sample < 0 || sample > 19) + continue; + QMap frame_channel_data = baseClip()->audioFrameChache[(int)frame]; + + for (int channel = 0;channel < channels && frame_channel_data[channel].size() > 0;channel++) { + + int y = channelHeight * channel + channelHeight / 2; + int delta = (int)(frame_channel_data[channel][sample] - 127 / 2) * channelHeight / 64; + if (fullAreaDraw) { + positiveChannelPaths[channel].lineTo(samples, 0.1 + y + qAbs(delta)); + negativeChannelPaths[channel].lineTo(samples, 0.1 + y - qAbs(delta)); + } else { + positiveChannelPaths[channel].lineTo(samples, 0.1 + y + delta); + negativeChannelPaths[channel].lineTo(samples, 0.1 + y - delta); + } + } + for (int channel = 0;channel < channels ;channel++) + if (fullAreaDraw && samples == 100) { + positiveChannelPaths[channel].lineTo(samples, channelHeight*channel + channelHeight / 2); + negativeChannelPaths[channel].lineTo(samples, channelHeight*channel + channelHeight / 2); + positiveChannelPaths[channel].lineTo(0, channelHeight*channel + channelHeight / 2); + negativeChannelPaths[channel].lineTo(0, channelHeight*channel + channelHeight / 2); + } + + } + for (int i = 0;i < channels;i++) { + if (fullAreaDraw) { + //pixpainter.fillPath(positiveChannelPaths[i].united(negativeChannelPaths[i]),QBrush(Qt::SolidPattern));//or singleif looks better + pixpainter.setBrush(QBrush(QColor(200, 200, 100, 200))); + pixpainter.drawPath(positiveChannelPaths[i].united(negativeChannelPaths[i]));//or singleif looks better + } else + pixpainter.drawPath(positiveChannelPaths[i]); + } + } + //audioThumbWasDrawn=true; + framePixelWidth = pixelForOneFrame; + + //} } -int ClipItem::fadeOut() const -{ - return m_endFade; +int ClipItem::fadeIn() const { + return m_startFade; } -void ClipItem::setFadeIn(int pos, double scale) -{ - int oldIn = m_startFade; - if (pos < 0) pos = 0; - if (pos > m_cropDuration) pos = m_cropDuration / 2; - m_startFade = pos; - if (oldIn > pos) update(rect().x(), rect().y(), oldIn * scale, rect().height()); - else update(rect().x(), rect().y(), pos * scale, rect().height()); +int ClipItem::fadeOut() const { + return m_endFade; } -void ClipItem::setFadeOut(int pos, double scale) -{ - int oldOut = m_endFade; - if (pos < 0) pos = 0; - if (pos > m_cropDuration) pos = m_cropDuration / 2; - m_endFade = pos; - if (oldOut > pos) update(rect().x() + rect().width() - pos * scale, rect().y(), pos * scale, rect().height()); - else update(rect().x() + rect().width() - oldOut * scale, rect().y(), oldOut * scale, rect().height()); +void ClipItem::setFadeIn(int pos, double scale) { + int oldIn = m_startFade; + if (pos < 0) pos = 0; + if (pos > m_cropDuration) pos = m_cropDuration / 2; + m_startFade = pos; + if (oldIn > pos) update(rect().x(), rect().y(), oldIn * scale, rect().height()); + else update(rect().x(), rect().y(), pos * scale, rect().height()); +} + +void ClipItem::setFadeOut(int pos, double scale) { + int oldOut = m_endFade; + if (pos < 0) pos = 0; + if (pos > m_cropDuration) pos = m_cropDuration / 2; + m_endFade = pos; + if (oldOut > pos) update(rect().x() + rect().width() - pos * scale, rect().y(), pos * scale, rect().height()); + else update(rect().x() + rect().width() - oldOut * scale, rect().y(), oldOut * scale, rect().height()); } // virtual - void ClipItem::mousePressEvent ( QGraphicsSceneMouseEvent * event ) - { +void ClipItem::mousePressEvent(QGraphicsSceneMouseEvent * event) { /*m_resizeMode = operationMode(event->pos()); if (m_resizeMode == MOVE) { m_maxTrack = scene()->sceneRect().height(); m_grabPoint = (int) (event->pos().x() - rect().x()); }*/ QGraphicsRectItem::mousePressEvent(event); - } +} // virtual - void ClipItem::mouseReleaseEvent ( QGraphicsSceneMouseEvent * event ) - { +void ClipItem::mouseReleaseEvent(QGraphicsSceneMouseEvent * event) { m_resizeMode = NONE; QGraphicsRectItem::mouseReleaseEvent(event); - } - - void ClipItem::moveTo(int x, double scale, double offset, int newTrack) - { - double origX = rect().x(); - double origY = rect().y(); - bool success = true; - if (x < 0) return; - setRect(x * scale, 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(); - if (x < m_startPos) { - kDebug()<<"COLLISION, MOVING TO------"; - m_startPos = ((ClipItem *)item)->endPos() + 1; - origX = m_startPos * scale; - } - else { - kDebug()<<"COLLISION, MOVING TO+++"; - m_startPos = ((ClipItem *)item)->startPos() - m_cropDuration; - origX = m_startPos * scale; - } - } - setRect(origX, origY, rect().width(), rect().height()); - offset = 0; - origX = rect().x(); - success = false; - break; - } +} + +void ClipItem::moveTo(int x, double scale, double offset, int newTrack) { + double origX = rect().x(); + double origY = rect().y(); + bool success = true; + if (x < 0) return; + setRect(x * scale, 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(); + if (x < m_startPos) { + kDebug() << "COLLISION, MOVING TO------"; + m_startPos = ((ClipItem *)item)->endPos() + 1; + origX = m_startPos * scale; + } else { + kDebug() << "COLLISION, MOVING TO+++"; + m_startPos = ((ClipItem *)item)->startPos() - m_cropDuration; + origX = m_startPos * scale; + } + } + setRect(origX, origY, rect().width(), rect().height()); + offset = 0; + origX = rect().x(); + success = false; + break; + } } if (success) { - m_track = newTrack; - m_startPos = x; + m_track = newTrack; + m_startPos = x; } -/* QList childrenList = QGraphicsItem::children(); - for (int i = 0; i < childrenList.size(); ++i) { - childrenList.at(i)->moveBy(rect().x() - origX , offset); - }*/ - } + /* QList childrenList = QGraphicsItem::children(); + for (int i = 0; i < childrenList.size(); ++i) { + childrenList.at(i)->moveBy(rect().x() - origX , offset); + }*/ +} -void ClipItem::resizeStart(int posx, double scale) -{ +void ClipItem::resizeStart(int posx, double scale) { int durationDiff = posx - m_startPos; if (durationDiff == 0) return; - kDebug()<<"-- RESCALE: CROP="<= m_cropDuration) { - durationDiff = m_cropDuration - 3; + durationDiff = -m_cropStart; + } else if (durationDiff >= m_cropDuration) { + durationDiff = m_cropDuration - 3; } m_startPos += durationDiff; m_cropStart += durationDiff; @@ -572,162 +535,146 @@ void ClipItem::resizeStart(int posx, double scale) setRect(m_startPos * scale, rect().y(), m_cropDuration * scale, rect().height()); QList collisionList = collidingItems(Qt::IntersectsItemBoundingRect); for (int i = 0; i < collisionList.size(); ++i) { - QGraphicsItem *item = collisionList.at(i); - if (item->type() == 70000) - { - int diff = ((ClipItem *)item)->endPos() + 1 - m_startPos; - setRect((m_startPos + diff) * scale, rect().y(), (m_cropDuration - diff) * scale, rect().height()); - m_startPos += diff; - m_cropStart += diff; - m_cropDuration -= diff; - break; - } + QGraphicsItem *item = collisionList.at(i); + if (item->type() == 70000) { + int diff = ((ClipItem *)item)->endPos() + 1 - m_startPos; + setRect((m_startPos + diff) * scale, rect().y(), (m_cropDuration - diff) * scale, rect().height()); + m_startPos += diff; + m_cropStart += diff; + m_cropDuration -= diff; + break; + } } if (m_hasThumbs) startThumbTimer->start(100); } -void ClipItem::resizeEnd(int posx, double scale) -{ +void ClipItem::resizeEnd(int posx, double scale) { int durationDiff = posx - endPos(); if (durationDiff == 0) return; - kDebug()<<"-- RESCALE: CROP="<= m_maxDuration) { - durationDiff = m_maxDuration - m_cropDuration; + durationDiff = - (m_cropDuration - 3); + } else if (m_cropDuration + durationDiff >= m_maxDuration) { + durationDiff = m_maxDuration - m_cropDuration; } m_cropDuration += durationDiff; setRect(m_startPos * scale, rect().y(), m_cropDuration * scale, rect().height()); QList collisionList = collidingItems(Qt::IntersectsItemBoundingRect); for (int i = 0; i < collisionList.size(); ++i) { - QGraphicsItem *item = collisionList.at(i); - if (item->type() == 70000) - { - int diff = ((ClipItem *)item)->startPos() - 1 - startPos(); - m_cropDuration = diff; - setRect(m_startPos * scale, rect().y(), m_cropDuration * scale, rect().height()); - break; - } + QGraphicsItem *item = collisionList.at(i); + if (item->type() == 70000) { + int diff = ((ClipItem *)item)->startPos() - 1 - startPos(); + m_cropDuration = diff; + setRect(m_startPos * scale, rect().y(), m_cropDuration * scale, rect().height()); + break; + } } if (m_hasThumbs) endThumbTimer->start(100); } // virtual - void ClipItem::mouseMoveEvent ( QGraphicsSceneMouseEvent * event ) - { - } - -int ClipItem::track() -{ - return m_track; +void ClipItem::mouseMoveEvent(QGraphicsSceneMouseEvent * event) { } -void ClipItem::setTrack(int track) -{ - m_track = track; +int ClipItem::track() { + return m_track; } -int ClipItem::effectsCounter() -{ - return m_effectsCounter++; +void ClipItem::setTrack(int track) { + m_track = track; } -int ClipItem::effectsCount() -{ - return m_effectList.size(); +int ClipItem::effectsCounter() { + return m_effectsCounter++; } -QStringList ClipItem::effectNames() -{ - return m_effectList.effectNames(); +int ClipItem::effectsCount() { + return m_effectList.size(); } -QDomElement ClipItem::effectAt(int ix) -{ - return m_effectList.at(ix); +QStringList ClipItem::effectNames() { + return m_effectList.effectNames(); } -void ClipItem::setEffectAt(int ix, QDomElement effect) -{ - kDebug()<<"CHange EFFECT AT: "< ClipItem::addEffect(QDomElement effect) -{ - QMap effectParams; - m_effectList.append(effect); - effectParams["tag"] = effect.attribute("tag"); - effectParams["kdenlive_ix"] = effect.attribute("kdenlive_ix"); - QString state = effect.attribute("disabled"); - if (!state.isEmpty()) effectParams["disabled"] = state; - QDomNodeList params = effect.elementsByTagName("parameter"); - for (int i = 0; i < params.count(); i++) { - QDomElement e = params.item(i).toElement(); - if (!e.isNull()){ - effectParams[e.attribute("name")] = e.attribute("value"); - } - if (!e.attribute("factor").isEmpty()){ - effectParams[e.attribute("name")] = QString::number(effectParams[e.attribute("name")].toDouble()/e.attribute("factor").toDouble()); - } - } - flashClip(); - update(boundingRect()); - return effectParams; +void ClipItem::setEffectAt(int ix, QDomElement effect) { + kDebug() << "CHange EFFECT AT: " << ix << ", CURR: " << m_effectList.at(ix).attribute("tag") << ", NEW: " << effect.attribute("tag"); + m_effectList.insert(ix, effect); + m_effectList.removeAt(ix + 1); + update(boundingRect()); } -QMap ClipItem::getEffectArgs(QDomElement effect) -{ - QMap effectParams; - effectParams["tag"] = effect.attribute("tag"); - effectParams["kdenlive_ix"] = effect.attribute("kdenlive_ix"); - QString state = effect.attribute("disabled"); - if (!state.isEmpty()) effectParams["disabled"] = state; - QDomNodeList params = effect.elementsByTagName("parameter"); - for (int i = 0; i < params.count(); i++) { - QDomElement e = params.item(i).toElement(); - if (e.attribute("name").contains(";")){ - QString format=e.attribute("format"); - QStringList separators=format.split("%d",QString::SkipEmptyParts); - QStringList values=e.attribute("value").split(QRegExp("[,:;x]")); - QString neu; - QTextStream txtNeu(&neu); - if (values.size()>0) - txtNeu << (int)values[0].toDouble(); - for (int i=0;i ClipItem::addEffect(QDomElement effect) { + QMap effectParams; + m_effectList.append(effect); + effectParams["tag"] = effect.attribute("tag"); + effectParams["kdenlive_ix"] = effect.attribute("kdenlive_ix"); + QString state = effect.attribute("disabled"); + if (!state.isEmpty()) effectParams["disabled"] = state; + QDomNodeList params = effect.elementsByTagName("parameter"); + for (int i = 0; i < params.count(); i++) { + QDomElement e = params.item(i).toElement(); + if (!e.isNull()) { + effectParams[e.attribute("name")] = e.attribute("value"); + } + if (!e.attribute("factor").isEmpty()) { + effectParams[e.attribute("name")] = QString::number(effectParams[e.attribute("name")].toDouble() / e.attribute("factor").toDouble()); + } } - if (!e.attribute("factor").isEmpty()){ - effectParams[e.attribute("name")] = QString::number(effectParams[e.attribute("name")].toDouble()/e.attribute("factor").toDouble()); + flashClip(); + update(boundingRect()); + return effectParams; +} + +QMap ClipItem::getEffectArgs(QDomElement effect) { + QMap effectParams; + effectParams["tag"] = effect.attribute("tag"); + effectParams["kdenlive_ix"] = effect.attribute("kdenlive_ix"); + QString state = effect.attribute("disabled"); + if (!state.isEmpty()) effectParams["disabled"] = state; + QDomNodeList params = effect.elementsByTagName("parameter"); + for (int i = 0; i < params.count(); i++) { + QDomElement e = params.item(i).toElement(); + if (e.attribute("name").contains(";")) { + QString format = e.attribute("format"); + QStringList separators = format.split("%d", QString::SkipEmptyParts); + QStringList values = e.attribute("value").split(QRegExp("[,:;x]")); + QString neu; + QTextStream txtNeu(&neu); + if (values.size() > 0) + txtNeu << (int)values[0].toDouble(); + for (int i = 0;i < separators.size() && i + 1 < values.size();i++) { + txtNeu << separators[i]; + txtNeu << (int)(values[i+1].toDouble()); + } + effectParams["start"] = neu; + } else + if (!e.isNull()) { + effectParams[e.attribute("name")] = e.attribute("value"); + } + if (!e.attribute("factor").isEmpty()) { + effectParams[e.attribute("name")] = QString::number(effectParams[e.attribute("name")].toDouble() / e.attribute("factor").toDouble()); + } } - } - return effectParams; + return effectParams; } -void ClipItem::deleteEffect(QString index) -{ - for (int i = 0; i < m_effectList.size(); ++i) { - if (m_effectList.at(i).attribute("kdenlive_ix") == index) { - m_effectList.removeAt(i); - break; +void ClipItem::deleteEffect(QString index) { + for (int i = 0; i < m_effectList.size(); ++i) { + if (m_effectList.at(i).attribute("kdenlive_ix") == index) { + m_effectList.removeAt(i); + break; + } } - } - flashClip(); - update(boundingRect()); + flashClip(); + update(boundingRect()); } //virtual -void ClipItem::dropEvent ( QGraphicsSceneDragDropEvent * event ) -{ +void ClipItem::dropEvent(QGraphicsSceneDragDropEvent * event) { QString effects = QString(event->mimeData()->data("kdenlive/effectslist")); QDomDocument doc; doc.setContent(effects, true); @@ -737,24 +684,22 @@ void ClipItem::dropEvent ( QGraphicsSceneDragDropEvent * event ) } //virtual -void ClipItem::dragEnterEvent(QGraphicsSceneDragDropEvent *event) -{ - event->setAccepted(event->mimeData()->hasFormat("kdenlive/effectslist")); +void ClipItem::dragEnterEvent(QGraphicsSceneDragDropEvent *event) { + event->setAccepted(event->mimeData()->hasFormat("kdenlive/effectslist")); } -void ClipItem::dragLeaveEvent(QGraphicsSceneDragDropEvent *event) -{ +void ClipItem::dragLeaveEvent(QGraphicsSceneDragDropEvent *event) { Q_UNUSED(event); } -// virtual +// virtual /* void CustomTrackView::mousePressEvent ( QMouseEvent * event ) { int pos = event->x(); - if (event->modifiers() == Qt::ControlModifier) + if (event->modifiers() == Qt::ControlModifier) setDragMode(QGraphicsView::ScrollHandDrag); - else if (event->modifiers() == Qt::ShiftModifier) + else if (event->modifiers() == Qt::ShiftModifier) setDragMode(QGraphicsView::RubberBandDrag); else { QGraphicsItem * item = itemAt(event->pos()); diff --git a/src/clipitem.h b/src/clipitem.h index 12eaa1b4..2091de5c 100644 --- a/src/clipitem.h +++ b/src/clipitem.h @@ -33,17 +33,16 @@ #include "kthumb.h" -class ClipItem : public QObject, public QGraphicsRectItem -{ - Q_OBJECT +class ClipItem : public QObject, public QGraphicsRectItem { + Q_OBJECT - public: +public: ClipItem(DocClipBase *clip, int track, int startpos, const QRectF & rect, int duration); virtual ~ ClipItem(); virtual void paint(QPainter *painter, - const QStyleOptionGraphicsItem *option, - QWidget *widget); - virtual int type () const; + const QStyleOptionGraphicsItem *option, + QWidget *widget); + virtual int type() const; void moveTo(int x, double scale, double offset, int newTrack); void resizeStart(int posx, double scale); void resizeEnd(int posx, double scale); @@ -82,15 +81,15 @@ class ClipItem : public QObject, public QGraphicsRectItem void setEffectAt(int ix, QDomElement effect); void flashClip(); - protected: - virtual void mouseMoveEvent ( QGraphicsSceneMouseEvent * event ); - virtual void mouseReleaseEvent ( QGraphicsSceneMouseEvent * event ); - virtual void mousePressEvent ( QGraphicsSceneMouseEvent * event ); +protected: + virtual void mouseMoveEvent(QGraphicsSceneMouseEvent * event); + virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent * event); + virtual void mousePressEvent(QGraphicsSceneMouseEvent * event); virtual void dragEnterEvent(QGraphicsSceneDragDropEvent *event); virtual void dragLeaveEvent(QGraphicsSceneDragDropEvent *event); virtual void dropEvent(QGraphicsSceneDragDropEvent *event); - private: +private: QDomElement m_xml; DocClipBase *m_clip; int m_textWidth; @@ -117,25 +116,25 @@ class ClipItem : public QObject, public QGraphicsRectItem double m_opacity; QTimeLine *m_timeLine; uint m_thumbsRequested; - + EffectsList m_effectList; - QMap audioThumbCachePic; - bool audioThumbWasDrawn,audioThumbReady; + QMap audioThumbCachePic; + bool audioThumbWasDrawn, audioThumbReady; double framePixelWidth; - QMap channelPaths; + QMap channelPaths; - private slots: +private slots: void slotThumbReady(int frame, QPixmap pix); void slotFetchThumbs(); void slotGetStartThumb(); void slotGetEndThumb(); void slotGotAudioData(); - void slotPrepareAudioThumb(double,QPainterPath,int,int); + void slotPrepareAudioThumb(double, QPainterPath, int, int); void animate(qreal value); - signals: +signals: void getThumb(int, int); - void prepareAudioThumb(double,QPainterPath,int,int); + void prepareAudioThumb(double, QPainterPath, int, int); }; diff --git a/src/clipmanager.cpp b/src/clipmanager.cpp index 67f933cc..57f1066b 100644 --- a/src/clipmanager.cpp +++ b/src/clipmanager.cpp @@ -24,69 +24,59 @@ #include "clipmanager.h" #include "docclipbase.h" -ClipManager::ClipManager(KdenliveDoc *doc):m_doc(doc) -{ - m_clipIdCounter = 1; +ClipManager::ClipManager(KdenliveDoc *doc): m_doc(doc) { + m_clipIdCounter = 1; } -ClipManager::~ClipManager() -{ +ClipManager::~ClipManager() { } -void ClipManager::setThumbsProgress(KUrl url, int progress) -{ - m_doc->setThumbsProgress(url, progress); +void ClipManager::setThumbsProgress(KUrl url, int progress) { + m_doc->setThumbsProgress(url, progress); } -void ClipManager::addClip(DocClipBase *clip) -{ - m_clipList.append(clip); +void ClipManager::addClip(DocClipBase *clip) { + m_clipList.append(clip); } -void ClipManager::slotDeleteClip(uint clipId) -{ - for (int i = 0; i < m_clipList.count(); i++) { - if (m_clipList.at(i)->getId() == clipId) { - //m_clipList.removeAt(i); - AddClipCommand *command = new AddClipCommand(m_doc, m_clipList.at(i)->toXML(), clipId, false); - m_doc->commandStack()->push(command); - break; +void ClipManager::slotDeleteClip(uint clipId) { + for (int i = 0; i < m_clipList.count(); i++) { + if (m_clipList.at(i)->getId() == clipId) { + //m_clipList.removeAt(i); + AddClipCommand *command = new AddClipCommand(m_doc, m_clipList.at(i)->toXML(), clipId, false); + m_doc->commandStack()->push(command); + break; + } } - } } -void ClipManager::deleteClip(uint clipId) -{ - for (int i = 0; i < m_clipList.count(); i++) { - if (m_clipList.at(i)->getId() == clipId) { - m_clipList.removeAt(i); - break; +void ClipManager::deleteClip(uint clipId) { + for (int i = 0; i < m_clipList.count(); i++) { + if (m_clipList.at(i)->getId() == clipId) { + m_clipList.removeAt(i); + break; + } } - } } -DocClipBase *ClipManager::getClipAt(int pos) -{ - return m_clipList.at(pos); +DocClipBase *ClipManager::getClipAt(int pos) { + return m_clipList.at(pos); } -DocClipBase *ClipManager::getClipById(int clipId) -{ - kDebug()<<"++++ CLIP MAN, LOOKING FOR CLIP ID: "<getId() == clipId) - { - kDebug()<<"++++ CLIP MAN, FOUND FOR CLIP ID: "<getId() == clipId) { + kDebug() << "++++ CLIP MAN, FOUND FOR CLIP ID: " << clipId; + return m_clipList.at(i); + } } - } - return NULL; + return NULL; } -void ClipManager::slotAddClipFile(const KUrl url, const QString group) -{ - kDebug()<<"///// CLIP MANAGER, ADDING CLIP: "<name().startsWith("image/")) { - prod.setAttribute("type", (int) IMAGE); - prod.setAttribute("in", "0"); - prod.setAttribute("out", m_doc->getFramePos(KdenliveSettings::image_duration())); + prod.setAttribute("type", (int) IMAGE); + prod.setAttribute("in", "0"); + prod.setAttribute("out", m_doc->getFramePos(KdenliveSettings::image_duration())); } AddClipCommand *command = new AddClipCommand(m_doc, prod, id, true); m_doc->commandStack()->push(command); } -void ClipManager::slotAddColorClipFile(const QString name, const QString color, QString duration, const QString group) -{ +void ClipManager::slotAddColorClipFile(const QString name, const QString color, QString duration, const QString group) { QDomDocument doc; QDomElement prod = doc.createElement("producer"); prod.setAttribute("mlt_service", "colour"); diff --git a/src/clipmanager.h b/src/clipmanager.h index 4580cdaa..fece4ee5 100644 --- a/src/clipmanager.h +++ b/src/clipmanager.h @@ -39,8 +39,8 @@ class KdenliveDoc; class DocClipBase; -class ClipManager:public QObject { - Q_OBJECT public: +class ClipManager: public QObject { +Q_OBJECT public: ClipManager(KdenliveDoc *doc); @@ -54,7 +54,7 @@ class ClipManager:public QObject { void slotDeleteClip(uint clipId); void setThumbsProgress(KUrl url, int progress); - private: // Private attributes +private: // Private attributes /** the list of clips in the document */ QList m_clipList; /** the document undo stack*/ diff --git a/src/complexparameter.cpp b/src/complexparameter.cpp index 0882b2f5..8dc1e53f 100644 --- a/src/complexparameter.cpp +++ b/src/complexparameter.cpp @@ -25,115 +25,114 @@ #include ComplexParameter::ComplexParameter(QWidget *parent) -: QWidget(parent) -{ - ui.setupUi(this); - //ui.effectlist->horizontalHeader()->setVisible(false); - //ui.effectlist->verticalHeader()->setVisible(false); - activeRow=-1; - clipref=NULL; - - - ui.buttonLeftRight->setIcon(KIcon("go-next"));//better icons needed - ui.buttonLeftRight->setToolTip(i18n("Allow horizontal moves")); - ui.buttonUpDown->setIcon(KIcon("go-up")); - ui.buttonUpDown->setToolTip(i18n("Allow vertical moves")); - ui.buttonShowInTimeline->setIcon(KIcon("kmplayer")); - ui.buttonShowInTimeline->setToolTip(i18n("Show keyframes in timeline")); - ui.buttonHelp->setIcon(KIcon("help-about")); - ui.buttonHelp->setToolTip(i18n("Parameter info")); - ui.buttonNewPoints->setIcon(KIcon("xedit")); - ui.buttonNewPoints->setToolTip(i18n("Add keyframe")); - - connect (ui.buttonLeftRight, SIGNAL (clicked()), this , SLOT ( slotSetMoveX() ) ); - connect (ui.buttonUpDown, SIGNAL (clicked()), this , SLOT ( slotSetMoveY() ) ); - connect (ui.buttonShowInTimeline, SIGNAL (clicked()), this , SLOT ( slotShowInTimeline() ) ); - connect (ui.buttonNewPoints, SIGNAL (clicked()), this , SLOT ( slotSetNew() ) ); - connect (ui.buttonHelp, SIGNAL (clicked()), this , SLOT ( slotSetHelp() ) ); - connect (ui.parameterList, SIGNAL (currentIndexChanged ( const QString & ) ), this, SLOT( slotParameterChanged(const QString&) ) ); - //connect (ui.effectlist, SIGNAL (itemSelectionChanged() ) , this, SLOT ( itemSelectionChanged())); - connect( this,SIGNAL (transferParamDesc(const QDomElement&,int ,int) ), ui.kplotwidget, SLOT(setPointLists(const QDomElement&,int ,int) )); - connect(ui.kplotwidget, SIGNAL (parameterChanged(QDomElement ) ), this , SLOT (slotUpdateEffectParams(QDomElement))); - connect(ui.kplotwidget, SIGNAL (parameterList(QStringList)), this , SLOT (slotUpdateParameterList(QStringList))); - /*ÜeffectLists["audio"]=audioEffectList; - effectLists["video"]=videoEffectList; - effectLists["custom"]=customEffectList;*/ - setSizePolicy(QSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding)); - ui.infoBox->hide(); - updateButtonStatus(); - + : QWidget(parent) { + ui.setupUi(this); + //ui.effectlist->horizontalHeader()->setVisible(false); + //ui.effectlist->verticalHeader()->setVisible(false); + activeRow = -1; + clipref = NULL; + + + ui.buttonLeftRight->setIcon(KIcon("go-next"));//better icons needed + ui.buttonLeftRight->setToolTip(i18n("Allow horizontal moves")); + ui.buttonUpDown->setIcon(KIcon("go-up")); + ui.buttonUpDown->setToolTip(i18n("Allow vertical moves")); + ui.buttonShowInTimeline->setIcon(KIcon("kmplayer")); + ui.buttonShowInTimeline->setToolTip(i18n("Show keyframes in timeline")); + ui.buttonHelp->setIcon(KIcon("help-about")); + ui.buttonHelp->setToolTip(i18n("Parameter info")); + ui.buttonNewPoints->setIcon(KIcon("xedit")); + ui.buttonNewPoints->setToolTip(i18n("Add keyframe")); + + connect(ui.buttonLeftRight, SIGNAL(clicked()), this , SLOT(slotSetMoveX())); + connect(ui.buttonUpDown, SIGNAL(clicked()), this , SLOT(slotSetMoveY())); + connect(ui.buttonShowInTimeline, SIGNAL(clicked()), this , SLOT(slotShowInTimeline())); + connect(ui.buttonNewPoints, SIGNAL(clicked()), this , SLOT(slotSetNew())); + connect(ui.buttonHelp, SIGNAL(clicked()), this , SLOT(slotSetHelp())); + connect(ui.parameterList, SIGNAL(currentIndexChanged(const QString &)), this, SLOT(slotParameterChanged(const QString&))); + //connect (ui.effectlist, SIGNAL (itemSelectionChanged() ) , this, SLOT ( itemSelectionChanged())); + connect(this, SIGNAL(transferParamDesc(const QDomElement&, int , int)), ui.kplotwidget, SLOT(setPointLists(const QDomElement&, int , int))); + connect(ui.kplotwidget, SIGNAL(parameterChanged(QDomElement)), this , SLOT(slotUpdateEffectParams(QDomElement))); + connect(ui.kplotwidget, SIGNAL(parameterList(QStringList)), this , SLOT(slotUpdateParameterList(QStringList))); + /*ÜeffectLists["audio"]=audioEffectList; + effectLists["video"]=videoEffectList; + effectLists["custom"]=customEffectList;*/ + setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding)); + ui.infoBox->hide(); + updateButtonStatus(); + } -void ComplexParameter::slotSetMoveX(){ - ui.kplotwidget->setMoveX(!ui.kplotwidget->isMoveX()); - updateButtonStatus(); +void ComplexParameter::slotSetMoveX() { + ui.kplotwidget->setMoveX(!ui.kplotwidget->isMoveX()); + updateButtonStatus(); } -void ComplexParameter::slotSetMoveY(){ - ui.kplotwidget->setMoveY(!ui.kplotwidget->isMoveY()); - updateButtonStatus(); +void ComplexParameter::slotSetMoveY() { + ui.kplotwidget->setMoveY(!ui.kplotwidget->isMoveY()); + updateButtonStatus(); } -void ComplexParameter::slotSetNew(){ - ui.kplotwidget->setNewPoints(!ui.kplotwidget->isNewPoints()); - updateButtonStatus(); +void ComplexParameter::slotSetNew() { + ui.kplotwidget->setNewPoints(!ui.kplotwidget->isNewPoints()); + updateButtonStatus(); } -void ComplexParameter::slotSetHelp(){ - ui.infoBox->setVisible(!ui.infoBox->isVisible()); - ui.buttonHelp->setDown(ui.infoBox->isVisible()); +void ComplexParameter::slotSetHelp() { + ui.infoBox->setVisible(!ui.infoBox->isVisible()); + ui.buttonHelp->setDown(ui.infoBox->isVisible()); } -void ComplexParameter::slotShowInTimeline(){ +void ComplexParameter::slotShowInTimeline() { + + ui.kplotwidget->setMoveTimeLine(!ui.kplotwidget->isMoveTimeline()); + updateButtonStatus(); - ui.kplotwidget->setMoveTimeLine(!ui.kplotwidget->isMoveTimeline()); - updateButtonStatus(); - } -void ComplexParameter::updateButtonStatus(){ - ui.buttonLeftRight->setDown(ui.kplotwidget->isMoveX()); - ui.buttonUpDown->setDown(ui.kplotwidget->isMoveY()); - - ui.buttonShowInTimeline->setEnabled( ui.kplotwidget->isMoveX() || ui.kplotwidget->isMoveY () ); - ui.buttonShowInTimeline->setDown(ui.kplotwidget->isMoveTimeline()); - - ui.buttonNewPoints->setEnabled(ui.parameterList->currentText()!="all"); - ui.buttonNewPoints->setDown(ui.kplotwidget->isNewPoints()); +void ComplexParameter::updateButtonStatus() { + ui.buttonLeftRight->setDown(ui.kplotwidget->isMoveX()); + ui.buttonUpDown->setDown(ui.kplotwidget->isMoveY()); + + ui.buttonShowInTimeline->setEnabled(ui.kplotwidget->isMoveX() || ui.kplotwidget->isMoveY()); + ui.buttonShowInTimeline->setDown(ui.kplotwidget->isMoveTimeline()); + + ui.buttonNewPoints->setEnabled(ui.parameterList->currentText() != "all"); + ui.buttonNewPoints->setDown(ui.kplotwidget->isNewPoints()); } -void ComplexParameter::slotParameterChanged(const QString& text){ - - //ui.buttonNewPoints->setEnabled(text!="all"); - ui.kplotwidget->replot(text); - updateButtonStatus(); +void ComplexParameter::slotParameterChanged(const QString& text) { + + //ui.buttonNewPoints->setEnabled(text!="all"); + ui.kplotwidget->replot(text); + updateButtonStatus(); } -void ComplexParameter::setupParam(const QDomElement& d,int from,int to){ - param=d; - ui.kplotwidget->setPointLists(d,from,to); +void ComplexParameter::setupParam(const QDomElement& d, int from, int to) { + param = d; + ui.kplotwidget->setPointLists(d, from, to); } -void ComplexParameter::itemSelectionChanged (){ - //kDebug() << "drop"; +void ComplexParameter::itemSelectionChanged() { + //kDebug() << "drop"; } -void ComplexParameter::slotUpdateEffectParams(QDomElement e){ - param=e; - emit parameterChanged(); +void ComplexParameter::slotUpdateEffectParams(QDomElement e) { + param = e; + emit parameterChanged(); } -QDomElement ComplexParameter::getParamDesc(){ - return param; +QDomElement ComplexParameter::getParamDesc() { + return param; } -void ComplexParameter::slotUpdateParameterList(QStringList l){ - kDebug() << l ; - ui.parameterList->clear(); - ui.parameterList->addItem("all"); - ui.parameterList->addItems(l); +void ComplexParameter::slotUpdateParameterList(QStringList l) { + kDebug() << l ; + ui.parameterList->clear(); + ui.parameterList->addItem("all"); + ui.parameterList->addItems(l); } #include "complexparameter.moc" diff --git a/src/complexparameter.h b/src/complexparameter.h index b0b24087..50eec4db 100644 --- a/src/complexparameter.h +++ b/src/complexparameter.h @@ -25,39 +25,38 @@ class EffectsList; -class ComplexParameter : public QWidget -{ - Q_OBJECT - - public: - ComplexParameter(QWidget *parent=0); - QDomElement getParamDesc(); +class ComplexParameter : public QWidget { + Q_OBJECT + +public: + ComplexParameter(QWidget *parent = 0); + QDomElement getParamDesc(); private: - int activeRow; - QList effects; - Ui::KeyframeWidget_UI ui; - ClipItem* clipref; - void setupListView(); - void updateButtonStatus(); - QMap effectLists; - - QDomElement param; + int activeRow; + QList effects; + Ui::KeyframeWidget_UI ui; + ClipItem* clipref; + void setupListView(); + void updateButtonStatus(); + QMap effectLists; + + QDomElement param; public slots: - void slotSetMoveX(); - void slotSetMoveY(); - void slotSetNew(); - void slotSetHelp(); - void slotShowInTimeline(); - void slotParameterChanged(const QString&); - void itemSelectionChanged(); - void setupParam(const QDomElement&,int,int); - void slotUpdateEffectParams(QDomElement e); - void slotUpdateParameterList(QStringList); + void slotSetMoveX(); + void slotSetMoveY(); + void slotSetNew(); + void slotSetHelp(); + void slotShowInTimeline(); + void slotParameterChanged(const QString&); + void itemSelectionChanged(); + void setupParam(const QDomElement&, int, int); + void slotUpdateEffectParams(QDomElement e); + void slotUpdateParameterList(QStringList); signals: - void transferParamDesc(const QDomElement&,int ,int); - void removeEffect(ClipItem*, QDomElement); - void updateClipEffect(ClipItem*, QDomElement); - void parameterChanged(); + void transferParamDesc(const QDomElement&, int , int); + void removeEffect(ClipItem*, QDomElement); + void updateClipEffect(ClipItem*, QDomElement); + void parameterChanged(); }; diff --git a/src/customruler.cpp b/src/customruler.cpp index 901622bb..88713f23 100644 --- a/src/customruler.cpp +++ b/src/customruler.cpp @@ -70,174 +70,168 @@ #include "definitions.h" -const int CustomRuler::comboScale[] = - { 1, 2, 5, 10, 25, 50, 125, 250, 500, 725, 1500, 3000, 6000, - 12000 }; +const int CustomRuler::comboScale[] = { 1, 2, 5, 10, 25, 50, 125, 250, 500, 725, 1500, 3000, 6000, + 12000 + }; CustomRuler::CustomRuler(Timecode tc, QWidget *parent) - : KRuler(parent), m_timecode(tc) -{ - slotNewOffset(0); - setRulerMetricStyle(KRuler::Pixel); - setLength(1024); - setMaximum(1024); - setPixelPerMark(3); - setLittleMarkDistance (FRAME_SIZE); - setMediumMarkDistance (FRAME_SIZE * 25); - setBigMarkDistance (FRAME_SIZE * 25 * 60); + : KRuler(parent), m_timecode(tc) { + slotNewOffset(0); + setRulerMetricStyle(KRuler::Pixel); + setLength(1024); + setMaximum(1024); + setPixelPerMark(3); + setLittleMarkDistance(FRAME_SIZE); + setMediumMarkDistance(FRAME_SIZE * 25); + setBigMarkDistance(FRAME_SIZE * 25 * 60); } -// virtual -void CustomRuler::mousePressEvent ( QMouseEvent * event ) -{ - int pos = event->x(); - slotMoveCursor( pos, true ); +// virtual +void CustomRuler::mousePressEvent(QMouseEvent * event) { + int pos = event->x(); + slotMoveCursor(pos, true); } // virtual -void CustomRuler::mouseMoveEvent ( QMouseEvent * event ) -{ - int pos = event->x(); - slotMoveCursor( pos, true ); +void CustomRuler::mouseMoveEvent(QMouseEvent * event) { + int pos = event->x(); + slotMoveCursor(pos, true); } -void CustomRuler::slotMoveRuler(int newPos) -{ - int diff = offset() - newPos; - KRuler::slotNewOffset(newPos); - KRuler::slotNewValue(value() + diff); +void CustomRuler::slotMoveRuler(int newPos) { + int diff = offset() - newPos; + KRuler::slotNewOffset(newPos); + KRuler::slotNewValue(m_cursorPosition * FRAME_SIZE * pixelPerMark() - offset());//value() + diff); } -void CustomRuler::slotMoveCursor( int _value, bool emitSignal ) -{ - KRuler::slotNewValue(_value ); - m_cursorPosition= (_value + offset()) / pixelPerMark(); - if (emitSignal) emit cursorMoved(m_cursorPosition / FRAME_SIZE); +void CustomRuler::slotMoveCursor(int _value, bool emitSignal) { + m_cursorPosition = (_value + offset()) / pixelPerMark() / FRAME_SIZE; + kDebug() << "RULER FR SZ: " << FRAME_SIZE << ", PPM: " << pixelPerMark(); + KRuler::slotNewValue(m_cursorPosition * FRAME_SIZE * pixelPerMark() - offset()); + + if (emitSignal) emit cursorMoved(m_cursorPosition); } -void CustomRuler::slotNewValue ( int _value, bool emitSignal ) -{ - m_cursorPosition= _value / pixelPerMark(); - if (emitSignal) emit cursorMoved(m_cursorPosition / FRAME_SIZE); - KRuler::slotNewValue(_value * pixelPerMark() - offset()); +void CustomRuler::slotNewValue(int _value, bool emitSignal) { + m_cursorPosition = _value / pixelPerMark(); + if (emitSignal) emit cursorMoved(m_cursorPosition / FRAME_SIZE); + KRuler::slotNewValue(_value * pixelPerMark() - offset()); } -void CustomRuler::setPixelPerMark (double rate) -{ +void CustomRuler::setPixelPerMark(double rate) { int scale = comboScale[(int) rate]; - int newPos = m_cursorPosition * (1.0 / scale); + int newPos = m_cursorPosition * (1.0 / scale); KRuler::setPixelPerMark(1.0 / scale); - KRuler::slotNewValue( newPos ); + KRuler::slotNewValue(m_cursorPosition * FRAME_SIZE * pixelPerMark() - offset()); + //KRuler::slotNewValue( newPos ); } -// virtual -void CustomRuler::paintEvent(QPaintEvent * /*e*/) - { - // debug ("KRuler::drawContents, %s",(horizontal==dir)?"horizontal":"vertical"); - - QStylePainter p(this); - - - int value = this->value(); - int minval = minimum(); - int maxval = maximum() + offset() - endOffset(); - - //ioffsetval = value-offset; - // pixelpm = (int)ppm; - // left = clip.left(), - // right = clip.right(); - double f, fend, - offsetmin=(double)(minval-offset()), - offsetmax=(double)(maxval-offset()), - fontOffset = (((double)minval)>offsetmin)?(double)minval:offsetmin; - QRect bg = QRect(offsetmin, 0, offsetmax, height()); - - QPalette palette; - //p.fillRect(bg, palette.light()); - // draw labels - QFont font = p.font(); - font.setPointSize(LABEL_SIZE); - p.setFont( font ); - p.setPen(palette.dark().color()); - // draw littlemarklabel - - // draw mediummarklabel - - // draw bigmarklabel - - // draw endlabel - /*if (d->showEndL) { - if (d->dir == Qt::Horizontal) { - p.translate( fontOffset, 0 ); - p.drawText( END_LABEL_X, END_LABEL_Y, d->endlabel ); - }*/ - - // draw the tiny marks - //if (showTinyMarks()) - /*{ - fend = pixelPerMark()*tinyMarkDistance(); - if (fend > 5) for ( f=offsetmin; f 5) for ( f=offsetmin; f 60) { - QString lab = m_timecode.getTimecodeFromFrames((int) ((f - offsetmin) / pixelPerMark() / FRAME_SIZE + 0.5)); - p.drawText( (int)f + 2, LABEL_SIZE, lab ); - } - } - } - if (showMediumMarks()) { - // draw medium marks - fend = pixelPerMark()*mediumMarkDistance(); - if (fend > 5) for ( f=offsetmin; f 60) { - QString lab = m_timecode.getTimecodeFromFrames((int) ((f - offsetmin) / pixelPerMark() / FRAME_SIZE + 0.5) ); - p.drawText( (int)f + 2, LABEL_SIZE, lab ); - } - } - } - if (showBigMarks()) { - // draw big marks - fend = pixelPerMark()*bigMarkDistance(); - if (fend > 5) for ( f=offsetmin; f 60) { - QString lab = m_timecode.getTimecodeFromFrames((int) ((f - offsetmin) / pixelPerMark() / FRAME_SIZE + 0.5) ); - p.drawText( (int)f + 2, LABEL_SIZE, lab ); - } - else if (((int) (f - offsetmin)) % ((int)(fend * 5)) == 0) { - QString lab = m_timecode.getTimecodeFromFrames((int) ((f - offsetmin) / pixelPerMark() / FRAME_SIZE + 0.5) ); - p.drawText( (int)f + 2, LABEL_SIZE, lab ); - } - } - } -/* if (d->showem) { - // draw end marks - if (d->dir == Qt::Horizontal) { - p.drawLine(minval-d->offset, END_MARK_X1, minval-d->offset, END_MARK_X2); - p.drawLine(maxval-d->offset, END_MARK_X1, maxval-d->offset, END_MARK_X2); - } - else { - p.drawLine(END_MARK_X1, minval-d->offset, END_MARK_X2, minval-d->offset); - p.drawLine(END_MARK_X1, maxval-d->offset, END_MARK_X2, maxval-d->offset); - } - }*/ - - // draw pointer - if (showPointer() && value > 0) { - QPolygon pa(4); - pa.setPoints(3, value-6, 9, value+6, 9, value/*+0*/, 16); - p.setBrush( QBrush(Qt::yellow) ); - p.drawPolygon( pa ); - } - - } +// virtual +void CustomRuler::paintEvent(QPaintEvent * /*e*/) { + // debug ("KRuler::drawContents, %s",(horizontal==dir)?"horizontal":"vertical"); + + QStylePainter p(this); + + + int value = this->value(); + int minval = minimum(); + int maxval = maximum() + offset() - endOffset(); + + //ioffsetval = value-offset; + // pixelpm = (int)ppm; + // left = clip.left(), + // right = clip.right(); + double f, fend, + offsetmin = (double)(minval - offset()), + offsetmax = (double)(maxval - offset()), + fontOffset = (((double)minval) > offsetmin) ? (double)minval : offsetmin; + QRect bg = QRect(offsetmin, 0, offsetmax, height()); + + QPalette palette; + //p.fillRect(bg, palette.light()); + // draw labels + QFont font = p.font(); + font.setPointSize(LABEL_SIZE); + p.setFont(font); + p.setPen(palette.dark().color()); + // draw littlemarklabel + + // draw mediummarklabel + + // draw bigmarklabel + + // draw endlabel + /*if (d->showEndL) { + if (d->dir == Qt::Horizontal) { + p.translate( fontOffset, 0 ); + p.drawText( END_LABEL_X, END_LABEL_Y, d->endlabel ); + }*/ + + // draw the tiny marks + //if (showTinyMarks()) + /*{ + fend = pixelPerMark()*tinyMarkDistance(); + if (fend > 5) for ( f=offsetmin; f 5) for (f = offsetmin; f < offsetmax; f += fend) { + p.drawLine((int)f, LITTLE_MARK_X1, (int)f, LITTLE_MARK_X2); + if (fend > 60) { + QString lab = m_timecode.getTimecodeFromFrames((int)((f - offsetmin) / pixelPerMark() / FRAME_SIZE + 0.5)); + p.drawText((int)f + 2, LABEL_SIZE, lab); + } + } + } + if (showMediumMarks()) { + // draw medium marks + fend = pixelPerMark() * mediumMarkDistance(); + if (fend > 5) for (f = offsetmin; f < offsetmax; f += fend) { + p.drawLine((int)f, MIDDLE_MARK_X1, (int)f, MIDDLE_MARK_X2); + if (fend > 60) { + QString lab = m_timecode.getTimecodeFromFrames((int)((f - offsetmin) / pixelPerMark() / FRAME_SIZE + 0.5)); + p.drawText((int)f + 2, LABEL_SIZE, lab); + } + } + } + if (showBigMarks()) { + // draw big marks + fend = pixelPerMark() * bigMarkDistance(); + if (fend > 5) for (f = offsetmin; f < offsetmax; f += fend) { + p.drawLine((int)f, BIG_MARK_X1, (int)f, BIG_MARK_X2); + if (fend > 60) { + QString lab = m_timecode.getTimecodeFromFrames((int)((f - offsetmin) / pixelPerMark() / FRAME_SIZE + 0.5)); + p.drawText((int)f + 2, LABEL_SIZE, lab); + } else if (((int)(f - offsetmin)) % ((int)(fend * 5)) == 0) { + QString lab = m_timecode.getTimecodeFromFrames((int)((f - offsetmin) / pixelPerMark() / FRAME_SIZE + 0.5)); + p.drawText((int)f + 2, LABEL_SIZE, lab); + } + } + } + /* if (d->showem) { + // draw end marks + if (d->dir == Qt::Horizontal) { + p.drawLine(minval-d->offset, END_MARK_X1, minval-d->offset, END_MARK_X2); + p.drawLine(maxval-d->offset, END_MARK_X1, maxval-d->offset, END_MARK_X2); + } + else { + p.drawLine(END_MARK_X1, minval-d->offset, END_MARK_X2, minval-d->offset); + p.drawLine(END_MARK_X1, maxval-d->offset, END_MARK_X2, maxval-d->offset); + } + }*/ + + // draw pointer + if (showPointer() && value > 0) { + QPolygon pa(4); + pa.setPoints(3, value - 6, 9, value + 6, 9, value/*+0*/, 16); + p.setBrush(QBrush(Qt::yellow)); + p.drawPolygon(pa); + } + +} #include "customruler.moc" diff --git a/src/customruler.h b/src/customruler.h index e4b1affc..5fd642c5 100644 --- a/src/customruler.h +++ b/src/customruler.h @@ -5,30 +5,29 @@ #include -class CustomRuler : public KRuler -{ - Q_OBJECT - - public: - CustomRuler(Timecode tc, QWidget *parent=0); - virtual void mousePressEvent ( QMouseEvent * event ); - virtual void mouseMoveEvent ( QMouseEvent * event ); - void setPixelPerMark (double rate); +class CustomRuler : public KRuler { + Q_OBJECT + +public: + CustomRuler(Timecode tc, QWidget *parent = 0); + virtual void mousePressEvent(QMouseEvent * event); + virtual void mouseMoveEvent(QMouseEvent * event); + void setPixelPerMark(double rate); static const int comboScale[]; - protected: +protected: virtual void paintEvent(QPaintEvent * /*e*/); - private: +private: int m_cursorPosition; Timecode m_timecode; - void slotMoveCursor( int _value, bool emitSignal ); + void slotMoveCursor(int _value, bool emitSignal); - public slots: - void slotNewValue ( int _value, bool emitSignal = false ); - void slotMoveRuler (int newPos); +public slots: + void slotNewValue(int _value, bool emitSignal = false); + void slotMoveRuler(int newPos); - signals: +signals: void cursorMoved(int); }; diff --git a/src/customtrackview.cpp b/src/customtrackview.cpp index 0a6a78c2..56b213b5 100644 --- a/src/customtrackview.cpp +++ b/src/customtrackview.cpp @@ -37,471 +37,436 @@ #include "editeffectcommand.h" CustomTrackView::CustomTrackView(KdenliveDoc *doc, QGraphicsScene * projectscene, QWidget *parent) - : QGraphicsView(projectscene, parent), 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), m_document(doc) -{ - if (doc) m_commandStack = doc->commandStack(); - else m_commandStack == NULL; - setMouseTracking(true); - setAcceptDrops(true); - m_animationTimer = new QTimeLine(800); - m_animationTimer->setFrameRange(0, 5); - m_animationTimer->setUpdateInterval(100); - m_animationTimer->setLoopCount(0); - m_tipColor = QColor(0, 192, 0, 200); - QColor border = QColor(255,255,255,100); - m_tipPen.setColor(border); - m_tipPen.setWidth(3); - - 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); - } -} - -void CustomTrackView::initView() -{ + : QGraphicsView(projectscene, parent), 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), m_document(doc) { + if (doc) m_commandStack = doc->commandStack(); + else m_commandStack == NULL; + setMouseTracking(true); + setAcceptDrops(true); + m_animationTimer = new QTimeLine(800); + m_animationTimer->setFrameRange(0, 5); + m_animationTimer->setUpdateInterval(100); + m_animationTimer->setLoopCount(0); + m_tipColor = QColor(0, 192, 0, 200); + QColor border = QColor(255, 255, 255, 100); + m_tipPen.setColor(border); + m_tipPen.setWidth(3); + + 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); + } +} + +void CustomTrackView::initView() { } // virtual -void CustomTrackView::resizeEvent ( QResizeEvent * event ) -{ - QGraphicsView::resizeEvent(event); +void CustomTrackView::resizeEvent(QResizeEvent * event) { + QGraphicsView::resizeEvent(event); } // virtual -void CustomTrackView::wheelEvent ( QWheelEvent * e ) -{ - if (e->modifiers() == Qt::ControlModifier) { - if (e->delta() > 0) emit zoomIn(); - else emit zoomOut(); - } - else { - if (e->delta() > 0) horizontalScrollBar()->setValue (horizontalScrollBar()->value() + horizontalScrollBar()->singleStep ()); - else horizontalScrollBar()->setValue (horizontalScrollBar()->value() - horizontalScrollBar()->singleStep ()); - } +void CustomTrackView::wheelEvent(QWheelEvent * e) { + if (e->modifiers() == Qt::ControlModifier) { + if (e->delta() > 0) emit zoomIn(); + else emit zoomOut(); + } else { + if (e->delta() > 0) horizontalScrollBar()->setValue(horizontalScrollBar()->value() + horizontalScrollBar()->singleStep()); + else horizontalScrollBar()->setValue(horizontalScrollBar()->value() - horizontalScrollBar()->singleStep()); + } } -// virtual -void CustomTrackView::mouseMoveEvent ( QMouseEvent * event ) -{ - int pos = event->x(); - emit mousePosition(mapToScene(event->pos()).x() / m_scale); - /*if (event->modifiers() == Qt::ControlModifier) - setDragMode(QGraphicsView::ScrollHandDrag); - else if (event->modifiers() == Qt::ShiftModifier) - setDragMode(QGraphicsView::RubberBandDrag); - else*/ { - - if (m_dragItem) { //event->button() == Qt::LeftButton) { - // a button was pressed, delete visual tips - if (m_operationMode == MOVE) { - double snappedPos = getSnapPointForPos(mapToScene(event->pos()).x() - m_clickPoint); - double moveX = snappedPos; //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_scale, m_scale, offset, moveTrack); - } - else if (m_operationMode == RESIZESTART) { - int pos = mapToScene(event->pos()).x(); - m_dragItem->resizeStart(pos / m_scale, m_scale); - } - else if (m_operationMode == RESIZEEND) { - int pos = mapToScene(event->pos()).x(); - m_dragItem->resizeEnd(pos / m_scale, m_scale); - } - else if (m_operationMode == FADEIN) { - int pos = mapToScene(event->pos()).x() / m_scale; - m_dragItem->setFadeIn(pos - m_dragItem->startPos(), m_scale); - } - else if (m_operationMode == FADEOUT) { - int pos = mapToScene(event->pos()).x() / m_scale; - m_dragItem->setFadeOut(m_dragItem->endPos() - pos, m_scale); - } - - if (m_animation) delete m_animation; - m_animation = NULL; - if (m_visualTip) delete m_visualTip; - m_visualTip = NULL; - QGraphicsView::mouseMoveEvent(event); - return; - } - - QList itemList = items( event->pos()); - int i = 0; - QGraphicsItem *item = NULL; - for (int i = 0; i < itemList.count(); i++) { - if (itemList.at(i)->type() == 70000) { - item = itemList.at(i); - break; - } - } - if (item && event->buttons() == Qt::NoButton) { - ClipItem *clip = (ClipItem*) item; - double size = 8; - OPERATIONTYPE opMode = clip->operationMode(mapToScene(event->pos()), m_scale); - if (opMode == m_moveOpMode) { - QGraphicsView::mouseMoveEvent(event); - return; - } - else { - if (m_visualTip) { - if (m_animation) delete m_animation; - m_animation = NULL; - m_animationTimer->stop(); - delete m_visualTip; - m_visualTip = NULL; - } - } - m_moveOpMode = opMode; - if (opMode == MOVE) { - setCursor(Qt::OpenHandCursor); - } - else if (opMode == RESIZESTART) { - kDebug()<<"******** RESIZE CLIP START; WIDTH: "<rect().x(), clip->rect().y() + clip->rect().height() / 2 - size * 2); - polygon << QPoint(clip->rect().x() + size * 2, clip->rect().y() + clip->rect().height() / 2 ); - polygon << QPoint(clip->rect().x(), clip->rect().y() + clip->rect().height() / 2 + size * 2); - polygon << QPoint(clip->rect().x(), clip->rect().y() + clip->rect().height() / 2 - size * 2); - - m_visualTip = new QGraphicsPolygonItem(polygon); - ((QGraphicsPolygonItem*) m_visualTip)->setBrush(m_tipColor); - ((QGraphicsPolygonItem*) m_visualTip)->setPen(m_tipPen); - m_visualTip->setZValue (100); - m_animation = new QGraphicsItemAnimation; - m_animation->setItem(m_visualTip); - m_animation->setTimeLine(m_animationTimer); - m_visualTip->setPos(0, 0); - double scale = 2.0; - m_animation->setScaleAt(.5, scale, 1); - m_animation->setPosAt(.5, QPointF(clip->rect().x() - clip->rect().x() * scale, 0)); - scale = 1.0; - m_animation->setScaleAt(1, scale, 1); - m_animation->setPosAt(1, QPointF(clip->rect().x() - clip->rect().x() * scale, 0)); - scene()->addItem(m_visualTip); - m_animationTimer->start(); - } - setCursor(Qt::SizeHorCursor); - } - else if (opMode == RESIZEEND) { - if (m_visualTip == NULL) { - QPolygon polygon; - polygon << QPoint(clip->rect().x() + clip->rect().width(), clip->rect().y() + clip->rect().height() / 2 - size * 2); - polygon << QPoint(clip->rect().x() + clip->rect().width() - size * 2, clip->rect().y() + clip->rect().height() / 2 ); - polygon << QPoint(clip->rect().x() + clip->rect().width(), clip->rect().y() + clip->rect().height() / 2 + size * 2); - polygon << QPoint(clip->rect().x() + clip->rect().width(), clip->rect().y() + clip->rect().height() / 2 - size * 2); - - m_visualTip = new QGraphicsPolygonItem(polygon); - ((QGraphicsPolygonItem*) m_visualTip)->setBrush(m_tipColor); - ((QGraphicsPolygonItem*) m_visualTip)->setPen(m_tipPen); - - m_visualTip->setZValue (100); - m_animation = new QGraphicsItemAnimation; - m_animation->setItem(m_visualTip); - m_animation->setTimeLine(m_animationTimer); - m_visualTip->setPos(0, 0); - double scale = 2.0; - m_animation->setScaleAt(.5, scale, 1); - m_animation->setPosAt(.5, QPointF(clip->rect().x() - clip->rect().x() * scale - clip->rect().width(), 0)); - scale = 1.0; - m_animation->setScaleAt(1, scale, 1); - m_animation->setPosAt(1, QPointF(clip->rect().x() - clip->rect().x() * scale, 0)); - scene()->addItem(m_visualTip); - m_animationTimer->start(); - } - setCursor(Qt::SizeHorCursor); - } - else if (opMode == FADEIN) { - if (m_visualTip == NULL) { - m_visualTip = new QGraphicsEllipseItem(clip->rect().x() + clip->fadeIn() * m_scale - size, clip->rect().y() - 8, size * 2, 16); - ((QGraphicsEllipseItem*) m_visualTip)->setBrush(m_tipColor); - ((QGraphicsEllipseItem*) m_visualTip)->setPen(m_tipPen); - m_visualTip->setZValue (100); - m_animation = new QGraphicsItemAnimation; - m_animation->setItem(m_visualTip); - m_animation->setTimeLine(m_animationTimer); - m_visualTip->setPos(0, 0); - double scale = 2.0; - m_animation->setScaleAt(.5, scale, scale); - m_animation->setPosAt(.5, QPointF(clip->rect().x() - clip->rect().x() * scale - clip->fadeIn() * m_scale, clip->rect().y() - clip->rect().y() * scale)); - scale = 1.0; - m_animation->setScaleAt(1, scale, scale); - m_animation->setPosAt(1, QPointF(clip->rect().x() - clip->rect().x() * scale, clip->rect().y() - clip->rect().y() * scale)); - scene()->addItem(m_visualTip); - m_animationTimer->start(); - } - setCursor(Qt::PointingHandCursor); - } - else if (opMode == FADEOUT) { - if (m_visualTip == NULL) { - m_visualTip = new QGraphicsEllipseItem(clip->rect().x() + clip->rect().width() - clip->fadeOut() * m_scale - size, clip->rect().y() - 8, size*2, 16); - ((QGraphicsEllipseItem*) m_visualTip)->setBrush(m_tipColor); - ((QGraphicsEllipseItem*) m_visualTip)->setPen(m_tipPen); - m_visualTip->setZValue (100); - m_animation = new QGraphicsItemAnimation; - m_animation->setItem(m_visualTip); - m_animation->setTimeLine(m_animationTimer); - m_visualTip->setPos(0, 0); - double scale = 2.0; - m_animation->setScaleAt(.5, scale, scale); - m_animation->setPosAt(.5, QPointF(clip->rect().x() - clip->rect().x() * scale - clip->rect().width() + clip->fadeOut() * m_scale, clip->rect().y() - clip->rect().y() * scale)); - scale = 1.0; - m_animation->setScaleAt(1, scale, scale); - m_animation->setPosAt(1, QPointF(clip->rect().x() - clip->rect().x() * scale, clip->rect().y() - clip->rect().y() * scale)); - scene()->addItem(m_visualTip); - m_animationTimer->start(); - } - setCursor(Qt::PointingHandCursor); - } - } - else { - m_moveOpMode = NONE; - if (event->buttons() != Qt::NoButton) - { - setCursorPos((int) mapToScene(event->pos().x(), 0).x()); - emit cursorMoved(cursorPos()); - } - if (m_visualTip) { - if (m_animation) delete m_animation; - m_animationTimer->stop(); - m_animation = NULL; - delete m_visualTip; - m_visualTip = NULL; - - } - setCursor(Qt::ArrowCursor); +// virtual +void CustomTrackView::mouseMoveEvent(QMouseEvent * event) { + int pos = event->x(); + emit mousePosition(mapToScene(event->pos()).x() / m_scale); + /*if (event->modifiers() == Qt::ControlModifier) + setDragMode(QGraphicsView::ScrollHandDrag); + else if (event->modifiers() == Qt::ShiftModifier) + setDragMode(QGraphicsView::RubberBandDrag); + else*/ + { + + if (m_dragItem) { //event->button() == Qt::LeftButton) { + // a button was pressed, delete visual tips + if (m_operationMode == MOVE) { + double snappedPos = getSnapPointForPos(mapToScene(event->pos()).x() - m_clickPoint); + double moveX = snappedPos; //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_scale, m_scale, offset, moveTrack); + } else if (m_operationMode == RESIZESTART) { + int pos = mapToScene(event->pos()).x(); + m_dragItem->resizeStart(pos / m_scale, m_scale); + } else if (m_operationMode == RESIZEEND) { + int pos = mapToScene(event->pos()).x(); + m_dragItem->resizeEnd(pos / m_scale, m_scale); + } else if (m_operationMode == FADEIN) { + int pos = mapToScene(event->pos()).x() / m_scale; + m_dragItem->setFadeIn(pos - m_dragItem->startPos(), m_scale); + } else if (m_operationMode == FADEOUT) { + int pos = mapToScene(event->pos()).x() / m_scale; + m_dragItem->setFadeOut(m_dragItem->endPos() - pos, m_scale); + } + + if (m_animation) delete m_animation; + m_animation = NULL; + if (m_visualTip) delete m_visualTip; + m_visualTip = NULL; + QGraphicsView::mouseMoveEvent(event); + return; + } + + QList itemList = items(event->pos()); + int i = 0; + QGraphicsItem *item = NULL; + for (int i = 0; i < itemList.count(); i++) { + if (itemList.at(i)->type() == 70000) { + item = itemList.at(i); + break; + } + } + if (item && event->buttons() == Qt::NoButton) { + ClipItem *clip = (ClipItem*) item; + double size = 8; + OPERATIONTYPE opMode = clip->operationMode(mapToScene(event->pos()), m_scale); + if (opMode == m_moveOpMode) { + QGraphicsView::mouseMoveEvent(event); + return; + } else { + if (m_visualTip) { + if (m_animation) delete m_animation; + m_animation = NULL; + m_animationTimer->stop(); + delete m_visualTip; + m_visualTip = NULL; + } + } + m_moveOpMode = opMode; + if (opMode == MOVE) { + setCursor(Qt::OpenHandCursor); + } else if (opMode == RESIZESTART) { + kDebug() << "******** RESIZE CLIP START; WIDTH: " << size; + if (m_visualTip == NULL) { + QPolygon polygon; + polygon << QPoint(clip->rect().x(), clip->rect().y() + clip->rect().height() / 2 - size * 2); + polygon << QPoint(clip->rect().x() + size * 2, clip->rect().y() + clip->rect().height() / 2); + polygon << QPoint(clip->rect().x(), clip->rect().y() + clip->rect().height() / 2 + size * 2); + polygon << QPoint(clip->rect().x(), clip->rect().y() + clip->rect().height() / 2 - size * 2); + + m_visualTip = new QGraphicsPolygonItem(polygon); + ((QGraphicsPolygonItem*) m_visualTip)->setBrush(m_tipColor); + ((QGraphicsPolygonItem*) m_visualTip)->setPen(m_tipPen); + m_visualTip->setZValue(100); + m_animation = new QGraphicsItemAnimation; + m_animation->setItem(m_visualTip); + m_animation->setTimeLine(m_animationTimer); + m_visualTip->setPos(0, 0); + double scale = 2.0; + m_animation->setScaleAt(.5, scale, 1); + m_animation->setPosAt(.5, QPointF(clip->rect().x() - clip->rect().x() * scale, 0)); + scale = 1.0; + m_animation->setScaleAt(1, scale, 1); + m_animation->setPosAt(1, QPointF(clip->rect().x() - clip->rect().x() * scale, 0)); + scene()->addItem(m_visualTip); + m_animationTimer->start(); + } + setCursor(Qt::SizeHorCursor); + } else if (opMode == RESIZEEND) { + if (m_visualTip == NULL) { + QPolygon polygon; + polygon << QPoint(clip->rect().x() + clip->rect().width(), clip->rect().y() + clip->rect().height() / 2 - size * 2); + polygon << QPoint(clip->rect().x() + clip->rect().width() - size * 2, clip->rect().y() + clip->rect().height() / 2); + polygon << QPoint(clip->rect().x() + clip->rect().width(), clip->rect().y() + clip->rect().height() / 2 + size * 2); + polygon << QPoint(clip->rect().x() + clip->rect().width(), clip->rect().y() + clip->rect().height() / 2 - size * 2); + + m_visualTip = new QGraphicsPolygonItem(polygon); + ((QGraphicsPolygonItem*) m_visualTip)->setBrush(m_tipColor); + ((QGraphicsPolygonItem*) m_visualTip)->setPen(m_tipPen); + + m_visualTip->setZValue(100); + m_animation = new QGraphicsItemAnimation; + m_animation->setItem(m_visualTip); + m_animation->setTimeLine(m_animationTimer); + m_visualTip->setPos(0, 0); + double scale = 2.0; + m_animation->setScaleAt(.5, scale, 1); + m_animation->setPosAt(.5, QPointF(clip->rect().x() - clip->rect().x() * scale - clip->rect().width(), 0)); + scale = 1.0; + m_animation->setScaleAt(1, scale, 1); + m_animation->setPosAt(1, QPointF(clip->rect().x() - clip->rect().x() * scale, 0)); + scene()->addItem(m_visualTip); + m_animationTimer->start(); + } + setCursor(Qt::SizeHorCursor); + } else if (opMode == FADEIN) { + if (m_visualTip == NULL) { + m_visualTip = new QGraphicsEllipseItem(clip->rect().x() + clip->fadeIn() * m_scale - size, clip->rect().y() - 8, size * 2, 16); + ((QGraphicsEllipseItem*) m_visualTip)->setBrush(m_tipColor); + ((QGraphicsEllipseItem*) m_visualTip)->setPen(m_tipPen); + m_visualTip->setZValue(100); + m_animation = new QGraphicsItemAnimation; + m_animation->setItem(m_visualTip); + m_animation->setTimeLine(m_animationTimer); + m_visualTip->setPos(0, 0); + double scale = 2.0; + m_animation->setScaleAt(.5, scale, scale); + m_animation->setPosAt(.5, QPointF(clip->rect().x() - clip->rect().x() * scale - clip->fadeIn() * m_scale, clip->rect().y() - clip->rect().y() * scale)); + scale = 1.0; + m_animation->setScaleAt(1, scale, scale); + m_animation->setPosAt(1, QPointF(clip->rect().x() - clip->rect().x() * scale, clip->rect().y() - clip->rect().y() * scale)); + scene()->addItem(m_visualTip); + m_animationTimer->start(); + } + setCursor(Qt::PointingHandCursor); + } else if (opMode == FADEOUT) { + if (m_visualTip == NULL) { + m_visualTip = new QGraphicsEllipseItem(clip->rect().x() + clip->rect().width() - clip->fadeOut() * m_scale - size, clip->rect().y() - 8, size*2, 16); + ((QGraphicsEllipseItem*) m_visualTip)->setBrush(m_tipColor); + ((QGraphicsEllipseItem*) m_visualTip)->setPen(m_tipPen); + m_visualTip->setZValue(100); + m_animation = new QGraphicsItemAnimation; + m_animation->setItem(m_visualTip); + m_animation->setTimeLine(m_animationTimer); + m_visualTip->setPos(0, 0); + double scale = 2.0; + m_animation->setScaleAt(.5, scale, scale); + m_animation->setPosAt(.5, QPointF(clip->rect().x() - clip->rect().x() * scale - clip->rect().width() + clip->fadeOut() * m_scale, clip->rect().y() - clip->rect().y() * scale)); + scale = 1.0; + m_animation->setScaleAt(1, scale, scale); + m_animation->setPosAt(1, QPointF(clip->rect().x() - clip->rect().x() * scale, clip->rect().y() - clip->rect().y() * scale)); + scene()->addItem(m_visualTip); + m_animationTimer->start(); + } + setCursor(Qt::PointingHandCursor); + } + } else { + m_moveOpMode = NONE; + if (event->buttons() != Qt::NoButton) { + setCursorPos((int) mapToScene(event->pos().x(), 0).x()); + emit cursorMoved(cursorPos()); + } + if (m_visualTip) { + if (m_animation) delete m_animation; + m_animationTimer->stop(); + m_animation = NULL; + delete m_visualTip; + m_visualTip = NULL; + + } + setCursor(Qt::ArrowCursor); + } } - } - QGraphicsView::mouseMoveEvent(event); + QGraphicsView::mouseMoveEvent(event); } -// virtual -void CustomTrackView::mousePressEvent ( QMouseEvent * event ) -{ - int pos = event->x(); - if (event->modifiers() == Qt::ControlModifier) { - setDragMode(QGraphicsView::ScrollHandDrag); - QGraphicsView::mousePressEvent(event); - return; - } - else if (event->modifiers() == Qt::ShiftModifier) { - setDragMode(QGraphicsView::RubberBandDrag); - QGraphicsView::mousePressEvent(event); - return; - } - else { - bool collision = false; - QList collisionList = items(event->pos()); - for (int i = 0; i < collisionList.size(); ++i) { - QGraphicsItem *item = collisionList.at(i); - if (item->type() == 70000) { - // select item - if (!item->isSelected()) { - QList itemList = items(); - for (int i = 0; i < itemList.count(); i++) - itemList.at(i)->setSelected(false); - item->setSelected(true); - update(); - } - m_dragItem = (ClipItem *) item; - emit clipItemSelected(m_dragItem); - m_clickPoint = mapToScene(event->pos()).x() - m_dragItem->startPos() * m_scale; - m_operationMode = m_dragItem->operationMode(item->mapFromScene(mapToScene(event->pos())), m_scale); - 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->endPos(), m_dragItem->track()); - kDebug()<<"//////// ITEM CLICKED: "< itemList = items(); - for (int i = 0; i < itemList.count(); i++) - itemList.at(i)->setSelected(false); - emit clipItemSelected(NULL); - setCursorPos((int) mapToScene(event->x(), 0).x()); - emit cursorMoved(cursorPos()); +// virtual +void CustomTrackView::mousePressEvent(QMouseEvent * event) { + int pos = event->x(); + if (event->modifiers() == Qt::ControlModifier) { + setDragMode(QGraphicsView::ScrollHandDrag); + QGraphicsView::mousePressEvent(event); + return; + } else if (event->modifiers() == Qt::ShiftModifier) { + setDragMode(QGraphicsView::RubberBandDrag); + QGraphicsView::mousePressEvent(event); + return; + } else { + bool collision = false; + QList collisionList = items(event->pos()); + for (int i = 0; i < collisionList.size(); ++i) { + QGraphicsItem *item = collisionList.at(i); + if (item->type() == 70000) { + // select item + if (!item->isSelected()) { + QList itemList = items(); + for (int i = 0; i < itemList.count(); i++) + itemList.at(i)->setSelected(false); + item->setSelected(true); + update(); + } + m_dragItem = (ClipItem *) item; + emit clipItemSelected(m_dragItem); + m_clickPoint = mapToScene(event->pos()).x() - m_dragItem->startPos() * m_scale; + m_operationMode = m_dragItem->operationMode(item->mapFromScene(mapToScene(event->pos())), m_scale); + 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->endPos(), m_dragItem->track()); + kDebug() << "//////// ITEM CLICKED: " << m_startPos; + collision = true; + break; + } + } + if (!collision) { + kDebug() << "//////// NO ITEM FOUND ON CLICK"; + m_dragItem = NULL; + setCursor(Qt::ArrowCursor); + QList itemList = items(); + for (int i = 0; i < itemList.count(); i++) + itemList.at(i)->setSelected(false); + emit clipItemSelected(NULL); + setCursorPos((int) mapToScene(event->x(), 0).x()); + emit cursorMoved(cursorPos()); + } } - } - updateSnapPoints(m_dragItem); - //kDebug()<mimeData()->hasFormat("kdenlive/producerslist")) { - kDebug()<<"/////////////// DRAG ENTERED, TEXT: "<mimeData()->data("kdenlive/producerslist"); - QStringList ids = QString(event->mimeData()->data("kdenlive/producerslist")).split(";"); - //TODO: drop of several clips - for (int i = 0; i < ids.size(); ++i) { +void CustomTrackView::dragEnterEvent(QDragEnterEvent * event) { + if (event->mimeData()->hasFormat("kdenlive/producerslist")) { + kDebug() << "/////////////// DRAG ENTERED, TEXT: " << event->mimeData()->data("kdenlive/producerslist"); + QStringList ids = QString(event->mimeData()->data("kdenlive/producerslist")).split(";"); + //TODO: drop of several clips + for (int i = 0; i < ids.size(); ++i) { + } + DocClipBase *clip = m_document->getBaseClip(ids.at(0).toInt()); + if (clip == NULL) kDebug() << " WARNING))))))))) CLIP NOT FOUND : " << ids.at(0).toInt(); + addItem(clip, event->pos()); + event->acceptProposedAction(); + } else QGraphicsView::dragEnterEvent(event); +} + +void CustomTrackView::slotRefreshEffects(ClipItem *clip) { + int track = m_tracksCount - clip->track(); + GenTime pos = GenTime(clip->startPos(), m_document->fps()); + m_document->renderer()->mltRemoveEffect(track, pos, "-1", false); + for (int i = 0; i < clip->effectsCount(); i++) { + m_document->renderer()->mltAddEffect(track, pos, clip->getEffectArgs(clip->effectAt(i)), false); } - DocClipBase *clip = m_document->getBaseClip(ids.at(0).toInt()); - if (clip == NULL) kDebug()<<" WARNING))))))))) CLIP NOT FOUND : "<pos()); - event->acceptProposedAction(); - } - else QGraphicsView::dragEnterEvent(event); -} - -void CustomTrackView::slotRefreshEffects(ClipItem *clip) -{ - int track = m_tracksCount - clip->track(); - GenTime pos = GenTime(clip->startPos(), m_document->fps()); - m_document->renderer()->mltRemoveEffect(track, pos, "-1", false); - for (int i = 0; i < clip->effectsCount(); i++) { - m_document->renderer()->mltAddEffect(track, pos, clip->getEffectArgs(clip->effectAt(i)), false); - } - m_document->renderer()->doRefresh(); + m_document->renderer()->doRefresh(); } -void CustomTrackView::addEffect(int track, GenTime pos, QDomElement effect) -{ - ClipItem *clip = getClipItemAt(pos.frames(m_document->fps()) + 1, m_tracksCount - track); - if (clip){ - QMap effectParams = clip->addEffect(effect); - m_document->renderer()->mltAddEffect(track, pos, effectParams); - emit clipItemSelected(clip); - } +void CustomTrackView::addEffect(int track, GenTime pos, QDomElement effect) { + ClipItem *clip = getClipItemAt(pos.frames(m_document->fps()) + 1, m_tracksCount - track); + if (clip) { + QMap effectParams = clip->addEffect(effect); + m_document->renderer()->mltAddEffect(track, pos, effectParams); + emit clipItemSelected(clip); + } } -void CustomTrackView::deleteEffect(int track, GenTime pos, QDomElement effect) -{ - QString index = effect.attribute("kdenlive_ix"); - m_document->renderer()->mltRemoveEffect(track, pos, index); - ClipItem *clip = getClipItemAt(pos.frames(m_document->fps()) + 1, m_tracksCount - track); - if (clip){ - clip->deleteEffect(index); - emit clipItemSelected(clip); - } +void CustomTrackView::deleteEffect(int track, GenTime pos, QDomElement effect) { + QString index = effect.attribute("kdenlive_ix"); + m_document->renderer()->mltRemoveEffect(track, pos, index); + ClipItem *clip = getClipItemAt(pos.frames(m_document->fps()) + 1, m_tracksCount - track); + if (clip) { + clip->deleteEffect(index); + emit clipItemSelected(clip); + } } -void CustomTrackView::slotAddEffect(QDomElement effect, GenTime pos, int track) -{ - QList itemList; - if (track == -1) - itemList = items(); - else { - ClipItem *clip = getClipItemAt(pos.frames(m_document->fps()) + 1, track); - if (clip) itemList.append(clip); - else kDebug()<<"------ wrning, clip eff not found"; - } - kDebug()<<"// REQUESTING EFFECT ON CLIP: "<type() == 70000 && (itemList.at(i)->isSelected() || track != -1)) { - ClipItem *item = (ClipItem *)itemList.at(i); - // the kdenlive_ix int is used to identify an effect in mlt's playlist, should - // not be changed - if (effect.attribute("kdenlive_ix").toInt() == 0) - effect.setAttribute("kdenlive_ix", QString::number(item->effectsCounter())); - AddEffectCommand *command = new AddEffectCommand(this, m_tracksCount - item->track(),GenTime(item->startPos(), m_document->fps()), effect, true); - m_commandStack->push(command); +void CustomTrackView::slotAddEffect(QDomElement effect, GenTime pos, int track) { + QList itemList; + if (track == -1) + itemList = items(); + else { + ClipItem *clip = getClipItemAt(pos.frames(m_document->fps()) + 1, track); + if (clip) itemList.append(clip); + else kDebug() << "------ wrning, clip eff not found"; + } + kDebug() << "// REQUESTING EFFECT ON CLIP: " << pos.frames(25) << ", TRK: " << track; + for (int i = 0; i < itemList.count(); i++) { + if (itemList.at(i)->type() == 70000 && (itemList.at(i)->isSelected() || track != -1)) { + ClipItem *item = (ClipItem *)itemList.at(i); + // the kdenlive_ix int is used to identify an effect in mlt's playlist, should + // not be changed + if (effect.attribute("kdenlive_ix").toInt() == 0) + effect.setAttribute("kdenlive_ix", QString::number(item->effectsCounter())); + AddEffectCommand *command = new AddEffectCommand(this, m_tracksCount - item->track(), GenTime(item->startPos(), m_document->fps()), effect, true); + m_commandStack->push(command); + } } - } } -void CustomTrackView::slotDeleteEffect(ClipItem *clip, QDomElement effect) -{ - AddEffectCommand *command = new AddEffectCommand(this, m_tracksCount - clip->track(), GenTime(clip->startPos(), m_document->fps()), effect, false); - m_commandStack->push(command); +void CustomTrackView::slotDeleteEffect(ClipItem *clip, QDomElement effect) { + AddEffectCommand *command = new AddEffectCommand(this, m_tracksCount - clip->track(), GenTime(clip->startPos(), m_document->fps()), effect, false); + m_commandStack->push(command); } -void CustomTrackView::updateEffect(int track, GenTime pos, QDomElement effect) -{ - ClipItem *clip = getClipItemAt(pos.frames(m_document->fps()) + 1, m_tracksCount - track); - if (clip){ - QMap effectParams = clip->getEffectArgs(effect); - if (effectParams["disabled"] == "1") { - QString index = effectParams["kdenlive_ix"]; - m_document->renderer()->mltRemoveEffect(track, pos, index); +void CustomTrackView::updateEffect(int track, GenTime pos, QDomElement effect) { + ClipItem *clip = getClipItemAt(pos.frames(m_document->fps()) + 1, m_tracksCount - track); + if (clip) { + QMap effectParams = clip->getEffectArgs(effect); + if (effectParams["disabled"] == "1") { + QString index = effectParams["kdenlive_ix"]; + m_document->renderer()->mltRemoveEffect(track, pos, index); + } else m_document->renderer()->mltEditEffect(m_tracksCount - clip->track(), GenTime(clip->startPos(), m_document->fps()), effectParams); } - else m_document->renderer()->mltEditEffect(m_tracksCount - clip->track(), GenTime(clip->startPos(), m_document->fps()), effectParams); - } } -void CustomTrackView::slotChangeEffectState(ClipItem *clip, QDomElement effect, bool disable) -{ - QDomElement oldEffect = effect.cloneNode().toElement(); - effect.setAttribute("disabled", disable); - EditEffectCommand *command = new EditEffectCommand(this, m_tracksCount - clip->track(), GenTime(clip->startPos(), m_document->fps()), oldEffect, effect, true); - m_commandStack->push(command); +void CustomTrackView::slotChangeEffectState(ClipItem *clip, QDomElement effect, bool disable) { + QDomElement oldEffect = effect.cloneNode().toElement(); + effect.setAttribute("disabled", disable); + EditEffectCommand *command = new EditEffectCommand(this, m_tracksCount - clip->track(), GenTime(clip->startPos(), m_document->fps()), oldEffect, effect, true); + m_commandStack->push(command); } -void CustomTrackView::slotUpdateClipEffect(ClipItem *clip, QDomElement oldeffect, QDomElement effect) -{ - EditEffectCommand *command = new EditEffectCommand(this, m_tracksCount - clip->track(), GenTime(clip->startPos(), m_document->fps()), oldeffect, effect, true); - m_commandStack->push(command); +void CustomTrackView::slotUpdateClipEffect(ClipItem *clip, QDomElement oldeffect, QDomElement effect) { + EditEffectCommand *command = new EditEffectCommand(this, m_tracksCount - clip->track(), GenTime(clip->startPos(), m_document->fps()), oldeffect, effect, true); + m_commandStack->push(command); } -void CustomTrackView::addItem(DocClipBase *clip, QPoint pos) -{ - int in =0; - int out = clip->duration().frames(m_document->fps()); - //kdDebug()<<"- - - -CREATING CLIP, duration = "<fileURL(); - int trackTop = ((int) mapToScene(pos).y()/50) * 50 + 1; - m_dropItem = new ClipItem(clip, ((int) mapToScene(pos).y()/50), in, QRectF(mapToScene(pos).x() * m_scale, trackTop, out * m_scale, 49), out); - scene()->addItem(m_dropItem); +void CustomTrackView::addItem(DocClipBase *clip, QPoint pos) { + int in = 0; + int out = clip->duration().frames(m_document->fps()); + //kdDebug()<<"- - - -CREATING CLIP, duration = "<fileURL(); + int trackTop = ((int) mapToScene(pos).y() / 50) * 50 + 1; + m_dropItem = new ClipItem(clip, ((int) mapToScene(pos).y() / 50), in, QRectF(mapToScene(pos).x() * m_scale, trackTop, out * m_scale, 49), out); + scene()->addItem(m_dropItem); } void CustomTrackView::dragMoveEvent(QDragMoveEvent * event) { - event->setDropAction(Qt::IgnoreAction); - //kDebug()<<"+++++++++++++ DRAG MOVE, : "<pos()).x()<<", SCAL: "<pos()).y()/50; //) * (m_scale * 50) + m_scale; - m_dropItem->moveTo(mapToScene(event->pos()).x() / m_scale, m_scale, (track - m_dropItem->track()) * 50, track); - event->setDropAction(Qt::MoveAction); - if (event->mimeData()->hasFormat("kdenlive/producerslist")) { - event->acceptProposedAction(); + event->setDropAction(Qt::IgnoreAction); + //kDebug()<<"+++++++++++++ DRAG MOVE, : "<pos()).x()<<", SCAL: "<pos()).y() / 50; //) * (m_scale * 50) + m_scale; + m_dropItem->moveTo(mapToScene(event->pos()).x() / m_scale, m_scale, (track - m_dropItem->track()) * 50, track); + event->setDropAction(Qt::MoveAction); + if (event->mimeData()->hasFormat("kdenlive/producerslist")) { + event->acceptProposedAction(); + } + } else { + QGraphicsView::dragMoveEvent(event); } - } - else { - QGraphicsView::dragMoveEvent(event); - } } -void CustomTrackView::dragLeaveEvent ( QDragLeaveEvent * event ) { - if (m_dropItem) { - delete m_dropItem; - m_dropItem = NULL; - } - else QGraphicsView::dragLeaveEvent(event); +void CustomTrackView::dragLeaveEvent(QDragLeaveEvent * event) { + if (m_dropItem) { + delete m_dropItem; + m_dropItem = NULL; + } else QGraphicsView::dragLeaveEvent(event); } -void CustomTrackView::dropEvent ( QDropEvent * event ) { - if (m_dropItem) { - AddTimelineClipCommand *command = new AddTimelineClipCommand(this, m_dropItem->xml(), m_dropItem->clipProducer(), m_dropItem->track(), m_dropItem->startPos(), m_dropItem->rect(), m_dropItem->duration(), false, false); - m_commandStack->push(command); - m_dropItem->baseClip()->addReference(); - m_document->updateClip(m_dropItem->baseClip()->getId()); - // kDebug()<<"IIIIIIIIIIIIIIIIIIIIIIII TRAX CNT: "<track(); - m_document->renderer()->mltInsertClip(m_tracksCount - m_dropItem->track(), GenTime(m_dropItem->startPos(), m_document->fps()), m_dropItem->xml()); - } - else QGraphicsView::dropEvent(event); - m_dropItem = NULL; +void CustomTrackView::dropEvent(QDropEvent * event) { + if (m_dropItem) { + AddTimelineClipCommand *command = new AddTimelineClipCommand(this, m_dropItem->xml(), m_dropItem->clipProducer(), m_dropItem->track(), m_dropItem->startPos(), m_dropItem->rect(), m_dropItem->duration(), false, false); + m_commandStack->push(command); + m_dropItem->baseClip()->addReference(); + m_document->updateClip(m_dropItem->baseClip()->getId()); + // kDebug()<<"IIIIIIIIIIIIIIIIIIIIIIII TRAX CNT: "<track(); + m_document->renderer()->mltInsertClip(m_tracksCount - m_dropItem->track(), GenTime(m_dropItem->startPos(), m_document->fps()), m_dropItem->xml()); + } else QGraphicsView::dropEvent(event); + m_dropItem = NULL; } -QStringList CustomTrackView::mimeTypes () const -{ +QStringList CustomTrackView::mimeTypes() const { QStringList qstrList; // list of accepted mime types for drop qstrList.append("text/plain"); @@ -509,252 +474,231 @@ QStringList CustomTrackView::mimeTypes () const return qstrList; } -Qt::DropActions CustomTrackView::supportedDropActions () const -{ +Qt::DropActions CustomTrackView::supportedDropActions() const { // returns what actions are supported when dropping return Qt::MoveAction; } -void CustomTrackView::setDuration(int duration) -{ - kDebug()<<"///////////// PRO DUR: "<setSceneRect(0, 0, (m_projectDuration + 500) * m_scale, scene()->sceneRect().height()); //50 * m_tracksCount); +void CustomTrackView::setDuration(int duration) { + kDebug() << "///////////// PRO DUR: " << duration << ", height: " << 50 * m_tracksCount; + m_projectDuration = duration; + scene()->setSceneRect(0, 0, (m_projectDuration + 500) * m_scale, scene()->sceneRect().height()); //50 * m_tracksCount); } -void CustomTrackView::addTrack () -{ - m_tracksCount++; - m_cursorLine->setLine(m_cursorLine->line().x1(), 0, m_cursorLine->line().x1(), 50 * m_tracksCount); - //setSceneRect(0, 0, sceneRect().width(), 50 * m_tracksCount); - //verticalScrollBar()->setMaximum(50 * m_tracksCount); - //setFixedHeight(50 * m_tracksCount); +void CustomTrackView::addTrack() { + m_tracksCount++; + m_cursorLine->setLine(m_cursorLine->line().x1(), 0, m_cursorLine->line().x1(), 50 * m_tracksCount); + //setSceneRect(0, 0, sceneRect().width(), 50 * m_tracksCount); + //verticalScrollBar()->setMaximum(50 * m_tracksCount); + //setFixedHeight(50 * m_tracksCount); } -void CustomTrackView::removeTrack () -{ - m_tracksCount--; - m_cursorLine->setLine(m_cursorLine->line().x1(), 0, m_cursorLine->line().x1(), 50 * m_tracksCount); +void CustomTrackView::removeTrack() { + m_tracksCount--; + m_cursorLine->setLine(m_cursorLine->line().x1(), 0, m_cursorLine->line().x1(), 50 * m_tracksCount); } -void CustomTrackView::deleteClip(int clipId) -{ - QList itemList = items(); - for (int i = 0; i < itemList.count(); i++) { - if (itemList.at(i)->type() == 70000) { - ClipItem *item = (ClipItem *)itemList.at(i); - if (item->clipProducer() == clipId) { - AddTimelineClipCommand *command = new AddTimelineClipCommand(this, item->xml(), item->clipProducer(), item->track(), item->startPos(), item->rect(), item->duration(), true, true); - m_commandStack->push(command); - //delete item; - } +void CustomTrackView::deleteClip(int clipId) { + QList itemList = items(); + for (int i = 0; i < itemList.count(); i++) { + if (itemList.at(i)->type() == 70000) { + ClipItem *item = (ClipItem *)itemList.at(i); + if (item->clipProducer() == clipId) { + AddTimelineClipCommand *command = new AddTimelineClipCommand(this, item->xml(), item->clipProducer(), item->track(), item->startPos(), item->rect(), item->duration(), true, true); + m_commandStack->push(command); + //delete item; + } + } } - } } -void CustomTrackView::setCursorPos(int pos, bool seek) -{ - m_cursorPos = pos; - m_cursorLine->setPos(pos, 0); - int frame = pos / m_scale; - if (seek) m_document->renderer()->seek(GenTime(frame, m_document->fps())); -} - -int CustomTrackView::cursorPos() -{ - return m_cursorPos; +void CustomTrackView::setCursorPos(int pos, bool seek) { + m_cursorPos = pos; + m_cursorLine->setPos(pos, 0); + int frame = pos / m_scale; + if (seek) m_document->renderer()->seek(GenTime(frame, m_document->fps())); +} + +int CustomTrackView::cursorPos() { + return m_cursorPos; +} + +void CustomTrackView::mouseReleaseEvent(QMouseEvent * event) { + QGraphicsView::mouseReleaseEvent(event); + setDragMode(QGraphicsView::NoDrag); + if (m_dragItem == NULL) return; + //kDebug()<<"/// MOVING CLIP: "<rect().x(),m_dragItem->rect().y()); + if (m_operationMode == MOVE && m_startPos.x() != m_dragItem->startPos()) { + // move clip + MoveClipCommand *command = new MoveClipCommand(this, m_startPos, QPointF(m_dragItem->startPos(), m_dragItem->track()), false); + m_commandStack->push(command); + m_document->renderer()->mltMoveClip(m_tracksCount - m_startPos.y(), m_tracksCount - m_dragItem->track(), m_startPos.x(), m_dragItem->startPos()); + } else if (m_operationMode == RESIZESTART) { + // resize start + ResizeClipCommand *command = new ResizeClipCommand(this, m_startPos, QPointF(m_dragItem->startPos(), m_dragItem->track()), true, false); + + m_document->renderer()->mltResizeClipStart(m_tracksCount - m_dragItem->track(), GenTime(m_dragItem->endPos(), m_document->fps()), GenTime(m_dragItem->startPos(), m_document->fps()), GenTime(m_startPos.x(), m_document->fps()), GenTime(m_dragItem->cropStart(), m_document->fps()), GenTime(m_dragItem->cropStart(), m_document->fps()) + GenTime(m_dragItem->endPos(), m_document->fps()) - GenTime(m_dragItem->startPos(), m_document->fps())); + m_commandStack->push(command); + m_document->renderer()->doRefresh(); + } else if (m_operationMode == RESIZEEND) { + // resize end + ResizeClipCommand *command = new ResizeClipCommand(this, m_startPos, QPointF(m_dragItem->endPos(), m_dragItem->track()), false, false); + + m_document->renderer()->mltResizeClipEnd(m_tracksCount - m_dragItem->track(), GenTime(m_dragItem->startPos(), m_document->fps()), GenTime(m_dragItem->cropStart(), m_document->fps()), GenTime(m_dragItem->cropStart(), m_document->fps()) + GenTime(m_dragItem->endPos(), m_document->fps()) - GenTime(m_dragItem->startPos(), m_document->fps())); + m_commandStack->push(command); + m_document->renderer()->doRefresh(); + } + m_operationMode = NONE; + m_dragItem = NULL; } -void CustomTrackView::mouseReleaseEvent ( QMouseEvent * event ) -{ - QGraphicsView::mouseReleaseEvent(event); - setDragMode(QGraphicsView::NoDrag); - if (m_dragItem == NULL) return; - //kDebug()<<"/// MOVING CLIP: "<rect().x(),m_dragItem->rect().y()); - if (m_operationMode == MOVE && m_startPos.x() != m_dragItem->startPos()) { - // move clip - MoveClipCommand *command = new MoveClipCommand(this, m_startPos, QPointF(m_dragItem->startPos(), m_dragItem->track()), false); - m_commandStack->push(command); - m_document->renderer()->mltMoveClip(m_tracksCount - m_startPos.y(), m_tracksCount - m_dragItem->track(), m_startPos.x(), m_dragItem->startPos()); - } - else if (m_operationMode == RESIZESTART) { - // resize start - ResizeClipCommand *command = new ResizeClipCommand(this, m_startPos, QPointF(m_dragItem->startPos(), m_dragItem->track()), true, false); - - m_document->renderer()->mltResizeClipStart(m_tracksCount - m_dragItem->track(), GenTime(m_dragItem->endPos(), m_document->fps()), GenTime(m_dragItem->startPos(), m_document->fps()), GenTime(m_startPos.x(), m_document->fps()), GenTime(m_dragItem->cropStart(), m_document->fps()), GenTime(m_dragItem->cropStart(), m_document->fps()) + GenTime(m_dragItem->endPos(), m_document->fps()) - GenTime(m_dragItem->startPos(), m_document->fps())); - m_commandStack->push(command); - m_document->renderer()->doRefresh(); - } - else if (m_operationMode == RESIZEEND) { - // resize end - ResizeClipCommand *command = new ResizeClipCommand(this, m_startPos, QPointF(m_dragItem->endPos(), m_dragItem->track()), false, false); - - m_document->renderer()->mltResizeClipEnd(m_tracksCount - m_dragItem->track(), GenTime(m_dragItem->startPos(), m_document->fps()), GenTime(m_dragItem->cropStart(), m_document->fps()), GenTime(m_dragItem->cropStart(), m_document->fps()) + GenTime(m_dragItem->endPos(), m_document->fps()) - GenTime(m_dragItem->startPos(), m_document->fps())); - m_commandStack->push(command); +void CustomTrackView::deleteClip(int track, int startpos, const QRectF &rect) { + ClipItem *item = getClipItemAt(startpos, track); + if (!item) { + kDebug() << "----------------  ERROR, CANNOT find clip to move at: " << rect.x(); + return; + } + item->baseClip()->removeReference(); + m_document->updateClip(item->baseClip()->getId()); + delete item; + m_document->renderer()->mltRemoveClip(m_tracksCount - track, GenTime(startpos, m_document->fps())); m_document->renderer()->doRefresh(); - } - m_operationMode = NONE; - m_dragItem = NULL; } -void CustomTrackView::deleteClip (int track, int startpos, const QRectF &rect ) -{ - ClipItem *item = getClipItemAt(startpos, track); - if (!item) { - kDebug()<<"----------------  ERROR, CANNOT find clip to move at: "<baseClip()->removeReference(); - m_document->updateClip(item->baseClip()->getId()); - delete item; - m_document->renderer()->mltRemoveClip(m_tracksCount - track, GenTime(startpos, m_document->fps())); - m_document->renderer()->doRefresh(); -} - -void CustomTrackView::addClip ( QDomElement xml, int clipId, int track, int startpos, const QRectF &rect, int duration ) -{ - QRect r(startpos * m_scale, 50 * track, duration * m_scale, 49); - DocClipBase *baseclip = m_document->clipManager()->getClipById(clipId); - ClipItem *item = new ClipItem(baseclip, track, startpos, r, duration); - scene()->addItem(item); - baseclip->addReference(); - m_document->updateClip(baseclip->getId()); - m_document->renderer()->mltInsertClip(m_tracksCount - track, GenTime(startpos, m_document->fps()), xml); - m_document->renderer()->doRefresh(); +void CustomTrackView::addClip(QDomElement xml, int clipId, int track, int startpos, const QRectF &rect, int duration) { + QRect r(startpos * m_scale, 50 * track, duration * m_scale, 49); + DocClipBase *baseclip = m_document->clipManager()->getClipById(clipId); + ClipItem *item = new ClipItem(baseclip, track, startpos, r, duration); + scene()->addItem(item); + baseclip->addReference(); + m_document->updateClip(baseclip->getId()); + m_document->renderer()->mltInsertClip(m_tracksCount - track, GenTime(startpos, m_document->fps()), xml); + m_document->renderer()->doRefresh(); } -ClipItem *CustomTrackView::getClipItemAt(int pos, int track) -{ - return (ClipItem *) scene()->itemAt(pos * m_scale, track * 50 + 25); +ClipItem *CustomTrackView::getClipItemAt(int pos, int track) { + return (ClipItem *) scene()->itemAt(pos * m_scale, track * 50 + 25); } -void CustomTrackView::moveClip ( const QPointF &startPos, const QPointF &endPos ) -{ - ClipItem *item = getClipItemAt(startPos.x() + 1, startPos.y()); - if (!item) { - kDebug()<<"----------------  ERROR, CANNOT find clip to move at: "<moveTo(endPos.x(), m_scale, (endPos.y() - startPos.y()) * 50, endPos.y()); - m_document->renderer()->mltMoveClip(m_tracksCount - startPos.y(), m_tracksCount - endPos.y(), startPos.x(), endPos.x()); +void CustomTrackView::moveClip(const QPointF &startPos, const QPointF &endPos) { + ClipItem *item = getClipItemAt(startPos.x() + 1, startPos.y()); + if (!item) { + kDebug() << "----------------  ERROR, CANNOT find clip to move at: " << startPos.x() * m_scale * FRAME_SIZE + 1 << ", " << startPos.y() * 50 + 25; + return; + } + kDebug() << "----------------  Move CLIP FROM: " << startPos.x() << ", END:" << endPos.x(); + item->moveTo(endPos.x(), m_scale, (endPos.y() - startPos.y()) * 50, endPos.y()); + m_document->renderer()->mltMoveClip(m_tracksCount - startPos.y(), m_tracksCount - endPos.y(), startPos.x(), endPos.x()); +} + +void CustomTrackView::resizeClip(const QPointF &startPos, const QPointF &endPos, bool resizeClipStart) { + int offset; + if (resizeClipStart) offset = 1; + else offset = -1; + ClipItem *item = getClipItemAt(startPos.x() + offset, startPos.y()); + if (!item) { + kDebug() << "----------------  ERROR, CANNOT find clip to resize at: " << startPos; + return; + } + qreal diff = endPos.x() - startPos.x(); + if (resizeClipStart) { + m_document->renderer()->mltResizeClipStart(m_tracksCount - item->track(), GenTime(item->endPos(), m_document->fps()), GenTime(endPos.x(), m_document->fps()), GenTime(item->startPos(), m_document->fps()), GenTime(item->cropStart() + diff, m_document->fps()), GenTime(item->cropStart() + diff, m_document->fps()) + GenTime(item->endPos(), m_document->fps()) - GenTime(endPos.x(), m_document->fps())); + item->resizeStart(endPos.x(), m_scale); + } else { + m_document->renderer()->mltResizeClipEnd(m_tracksCount - item->track(), GenTime(item->startPos(), m_document->fps()), GenTime(item->cropStart(), m_document->fps()), GenTime(item->cropStart(), m_document->fps()) + GenTime(endPos.x(), m_document->fps()) - GenTime(item->startPos(), m_document->fps())); + item->resizeEnd(endPos.x(), m_scale); + } + m_document->renderer()->doRefresh(); } -void CustomTrackView::resizeClip ( const QPointF &startPos, const QPointF &endPos, bool resizeClipStart ) -{ - int offset; - if (resizeClipStart) offset = 1; - else offset = -1; - ClipItem *item = getClipItemAt(startPos.x() + offset, startPos.y()); - if (!item) { - kDebug()<<"----------------  ERROR, CANNOT find clip to resize at: "<renderer()->mltResizeClipStart(m_tracksCount - item->track(), GenTime(item->endPos(), m_document->fps()), GenTime(endPos.x(), m_document->fps()), GenTime(item->startPos(), m_document->fps()), GenTime(item->cropStart() + diff, m_document->fps()), GenTime(item->cropStart() + diff, m_document->fps()) + GenTime(item->endPos(), m_document->fps()) - GenTime(endPos.x(), m_document->fps())); - item->resizeStart(endPos.x(), m_scale); - } - else { - m_document->renderer()->mltResizeClipEnd(m_tracksCount - item->track(), GenTime(item->startPos(), m_document->fps()), GenTime(item->cropStart(), m_document->fps()), GenTime(item->cropStart(), m_document->fps()) + GenTime(endPos.x(), m_document->fps()) - GenTime(item->startPos(), m_document->fps())); - item->resizeEnd(endPos.x(), m_scale); - } - m_document->renderer()->doRefresh(); -} - -double CustomTrackView::getSnapPointForPos(double pos) -{ - for (int i = 0; i < m_snapPoints.size(); ++i) { - //kDebug()<<"SNAP POINT: "< pos) break; } - if (m_snapPoints.at(i) > pos) break; - } - return pos; + return pos; } -void CustomTrackView::updateSnapPoints(ClipItem *selected) -{ - m_snapPoints.clear(); - int offset = 0; - if (selected) offset = selected->duration(); - QList itemList = items(); - for (int i = 0; i < itemList.count(); i++) { - if (itemList.at(i)->type() == 70000 && itemList.at(i) != selected) { - ClipItem *item = (ClipItem *)itemList.at(i); - int start = item->startPos(); - int fadein = item->fadeIn() + start; - int end = item->endPos(); - int fadeout = end - item->fadeOut(); - m_snapPoints.append(start); - if (fadein != start) m_snapPoints.append(fadein); - m_snapPoints.append(end); - if (fadeout != end) m_snapPoints.append(fadeout); - if (offset != 0) { - m_snapPoints.append(start - offset); - if (fadein != start) m_snapPoints.append(fadein - offset); - m_snapPoints.append(end - offset); - if (fadeout != end) m_snapPoints.append(fadeout - offset); - } +void CustomTrackView::updateSnapPoints(ClipItem *selected) { + m_snapPoints.clear(); + int offset = 0; + if (selected) offset = selected->duration(); + QList itemList = items(); + for (int i = 0; i < itemList.count(); i++) { + if (itemList.at(i)->type() == 70000 && itemList.at(i) != selected) { + ClipItem *item = (ClipItem *)itemList.at(i); + int start = item->startPos(); + int fadein = item->fadeIn() + start; + int end = item->endPos(); + int fadeout = end - item->fadeOut(); + m_snapPoints.append(start); + if (fadein != start) m_snapPoints.append(fadein); + m_snapPoints.append(end); + if (fadeout != end) m_snapPoints.append(fadeout); + if (offset != 0) { + m_snapPoints.append(start - offset); + if (fadein != start) m_snapPoints.append(fadein - offset); + m_snapPoints.append(end - offset); + if (fadeout != end) m_snapPoints.append(fadeout - offset); + } + } } - } - kDebug()<<" GOT SNAPPOINTS TOTAL: "< itemList = items(); - scene()->setSceneRect(0, 0, (m_projectDuration + 500) * m_scale, scene()->sceneRect().height()); //50 * - - 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::setScale(double scaleFactor) { + //scale(scaleFactor, scaleFactor); + m_scale = scaleFactor; + kDebug() << " HHHHHHHH SCALING: " << m_scale; + QList itemList = items(); + scene()->setSceneRect(0, 0, (m_projectDuration + 500) * m_scale, scene()->sceneRect().height()); //50 * + + 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 ) -{ - QRect rectInView;//this is the rect that is visible by the user - if (scene()->views().size()>0){ - rectInView=scene()->views()[0]->viewport()->rect(); - rectInView.moveTo(scene()->views()[0]->horizontalScrollBar()->value(),scene()->views()[0]->verticalScrollBar()->value()); - } - if (rectInView.isNull()) return; - - QColor base = palette().button().color(); - painter->setClipRect(rect); - painter->drawLine(rectInView.left(), 0, rectInView.right(), 0); - for (uint i = 0; i < m_tracksCount;i++) - { - painter->drawLine(rectInView.left(), 50 * (i+1), rectInView.right(), 50 * (i+1)); - painter->drawText(QRectF(10, 50 * i, 100, 50 * i + 49), Qt::AlignLeft, i18n(" Track ") + QString::number(i + 1)); - } - int lowerLimit = 50 * m_tracksCount + 1; - if (height() > lowerLimit) - painter->fillRect(QRectF(rectInView.left(), lowerLimit, rectInView.width(), height() - lowerLimit), QBrush(base)); +void CustomTrackView::drawBackground(QPainter * painter, const QRectF & rect) { + QRect rectInView;//this is the rect that is visible by the user + if (scene()->views().size() > 0) { + rectInView = scene()->views()[0]->viewport()->rect(); + rectInView.moveTo(scene()->views()[0]->horizontalScrollBar()->value(), scene()->views()[0]->verticalScrollBar()->value()); + } + if (rectInView.isNull()) return; + + QColor base = palette().button().color(); + painter->setClipRect(rect); + painter->drawLine(rectInView.left(), 0, rectInView.right(), 0); + for (uint i = 0; i < m_tracksCount;i++) { + painter->drawLine(rectInView.left(), 50 * (i + 1), rectInView.right(), 50 * (i + 1)); + painter->drawText(QRectF(10, 50 * i, 100, 50 * i + 49), Qt::AlignLeft, i18n(" Track ") + QString::number(i + 1)); + } + int lowerLimit = 50 * m_tracksCount + 1; + if (height() > lowerLimit) + painter->fillRect(QRectF(rectInView.left(), lowerLimit, rectInView.width(), height() - lowerLimit), QBrush(base)); } /* -void CustomTrackView::drawForeground ( QPainter * painter, const QRectF & rect ) +void CustomTrackView::drawForeground ( QPainter * painter, const QRectF & rect ) { //kDebug()<<"///// DRAWING FB: "<fillRect(rect, QColor(50, rand() % 250,50,100)); diff --git a/src/customtrackview.h b/src/customtrackview.h index 88f523a0..d7e66d78 100644 --- a/src/customtrackview.h +++ b/src/customtrackview.h @@ -30,23 +30,22 @@ #include "kdenlivedoc.h" #include "clipitem.h" -class CustomTrackView : public QGraphicsView -{ - Q_OBJECT - - public: - CustomTrackView(KdenliveDoc *doc, QGraphicsScene * projectscene, QWidget *parent=0); - virtual void mousePressEvent ( QMouseEvent * event ); - virtual void mouseReleaseEvent ( QMouseEvent * event ); - virtual void mouseMoveEvent ( QMouseEvent * event ); +class CustomTrackView : public QGraphicsView { + Q_OBJECT + +public: + CustomTrackView(KdenliveDoc *doc, QGraphicsScene * projectscene, QWidget *parent = 0); + virtual void mousePressEvent(QMouseEvent * event); + virtual void mouseReleaseEvent(QMouseEvent * event); + virtual void mouseMoveEvent(QMouseEvent * event); void addTrack(); void removeTrack(); int cursorPos(); void initView(); - void moveClip ( const QPointF &startPos, const QPointF &endPos ); - void resizeClip ( const QPointF &startPos, const QPointF &endPos, bool resizeClipStart ); - void addClip ( QDomElement xml, int clipId, int track, int startpos, const QRectF &rect, int duration); - void deleteClip ( int track, int startpos, const QRectF &rect ); + void moveClip(const QPointF &startPos, const QPointF &endPos); + void resizeClip(const QPointF &startPos, const QPointF &endPos, bool resizeClipStart); + void addClip(QDomElement xml, int clipId, int track, int startpos, const QRectF &rect, int duration); + void deleteClip(int track, int startpos, const QRectF &rect); void setScale(double scaleFactor); void deleteClip(int clipId); void slotAddEffect(QDomElement effect, GenTime pos, int track); @@ -54,7 +53,7 @@ class CustomTrackView : public QGraphicsView void deleteEffect(int track, GenTime pos, QDomElement effect); void updateEffect(int track, GenTime pos, QDomElement effect); - public slots: +public slots: void setCursorPos(int pos, bool seek = true); void slotDeleteEffect(ClipItem *clip, QDomElement effect); void slotChangeEffectState(ClipItem *clip, QDomElement effect, bool disable); @@ -62,19 +61,19 @@ class CustomTrackView : public QGraphicsView void slotRefreshEffects(ClipItem *clip); void setDuration(int duration); - protected: - virtual void drawBackground ( QPainter * painter, const QRectF & rect ); +protected: + virtual void drawBackground(QPainter * painter, const QRectF & rect); //virtual void drawForeground ( QPainter * painter, const QRectF & rect ); - virtual void dragEnterEvent ( QDragEnterEvent * event ); + virtual void dragEnterEvent(QDragEnterEvent * event); virtual void dragMoveEvent(QDragMoveEvent * event); - virtual void dragLeaveEvent ( QDragLeaveEvent * event ); - virtual void dropEvent ( QDropEvent * event ); - virtual void wheelEvent ( QWheelEvent * e ); + virtual void dragLeaveEvent(QDragLeaveEvent * event); + virtual void dropEvent(QDropEvent * event); + virtual void wheelEvent(QWheelEvent * e); virtual QStringList mimeTypes() const; - virtual Qt::DropActions supportedDropActions () const; - virtual void resizeEvent ( QResizeEvent * event ); + virtual Qt::DropActions supportedDropActions() const; + virtual void resizeEvent(QResizeEvent * event); - private: +private: int m_tracksCount; int m_projectDuration; int m_cursorPos; @@ -100,13 +99,12 @@ class CustomTrackView : public QGraphicsView ClipItem *getClipItemAt(int pos, int track); - signals: +signals: void cursorMoved(int); void zoomIn(); void zoomOut(); void mousePosition(int); void clipItemSelected(ClipItem*); - }; #endif diff --git a/src/definitions.h b/src/definitions.h index b3e883ec..56733d65 100644 --- a/src/definitions.h +++ b/src/definitions.h @@ -28,10 +28,10 @@ enum OPERATIONTYPE { NONE = 0, MOVE = 1, RESIZESTART = 2, RESIZEEND = 3, FADEIN enum CLIPTYPE { UNKNOWN = 0, AUDIO = 1, VIDEO = 2, AV = 3, COLOR = 4, IMAGE = 5, TEXT = 6, SLIDESHOW = 7, VIRTUAL = 8, PLAYLIST = 9}; struct TrackViewClip { - int startTime; - int duration; - int cropTime; - QString producer; + int startTime; + int duration; + int cropTime; + QString producer; }; #endif diff --git a/src/docclipbase.cpp b/src/docclipbase.cpp index 4f5f5d41..42bcd3b6 100644 --- a/src/docclipbase.cpp +++ b/src/docclipbase.cpp @@ -21,34 +21,32 @@ #include "docclipbase.h" DocClipBase::DocClipBase(ClipManager *clipManager, QDomElement xml, uint id): -m_xml(xml), m_id(id), m_description(""), m_refcount(0), m_projectThumbFrame(0), m_audioThumbCreated(false), m_duration(GenTime()), m_thumbProd(NULL), m_audioTimer(NULL) -{ - int type = xml.attribute("type").toInt(); - m_clipType = (CLIPTYPE) type; - m_name = xml.attribute("name"); - m_xml.setAttribute("id", QString::number(id)); - KUrl url = KUrl(xml.attribute("resource")); - int out = xml.attribute("out").toInt(); - if (out != 0) setDuration(GenTime(out, 25)); - if (m_name.isEmpty()) m_name = url.fileName(); - if (!url.isEmpty()){ - m_thumbProd = new KThumb(clipManager, url, KdenliveSettings::track_height() * KdenliveSettings::project_display_ratio(), KdenliveSettings::track_height()); - connect (m_thumbProd, SIGNAL (audioThumbReady(QMap >)), this , SLOT(updateAudioThumbnail(QMap > ))); - connect (this, SIGNAL (getAudioThumbs()), this , SLOT( slotGetAudioThumbs() ) ); - - } - kDebug() << "type is video" << (m_clipType==AV) << " " << m_clipType; - - if (m_clipType == AV || m_clipType==AUDIO || m_clipType==UNKNOWN){ - m_audioTimer = new QTimer( this ); - connect(m_audioTimer, SIGNAL(timeout()), this, SLOT(slotGetAudioThumbs())); - } -} - - - -DocClipBase::DocClipBase(const DocClipBase& clip) -{ + m_xml(xml), m_id(id), m_description(""), m_refcount(0), m_projectThumbFrame(0), m_audioThumbCreated(false), m_duration(GenTime()), m_thumbProd(NULL), m_audioTimer(NULL) { + int type = xml.attribute("type").toInt(); + m_clipType = (CLIPTYPE) type; + m_name = xml.attribute("name"); + m_xml.setAttribute("id", QString::number(id)); + KUrl url = KUrl(xml.attribute("resource")); + int out = xml.attribute("out").toInt(); + if (out != 0) setDuration(GenTime(out, 25)); + if (m_name.isEmpty()) m_name = url.fileName(); + if (!url.isEmpty()) { + m_thumbProd = new KThumb(clipManager, url, KdenliveSettings::track_height() * KdenliveSettings::project_display_ratio(), KdenliveSettings::track_height()); + connect(m_thumbProd, SIGNAL(audioThumbReady(QMap >)), this , SLOT(updateAudioThumbnail(QMap >))); + connect(this, SIGNAL(getAudioThumbs()), this , SLOT(slotGetAudioThumbs())); + + } + kDebug() << "type is video" << (m_clipType == AV) << " " << m_clipType; + + if (m_clipType == AV || m_clipType == AUDIO || m_clipType == UNKNOWN) { + m_audioTimer = new QTimer(this); + connect(m_audioTimer, SIGNAL(timeout()), this, SLOT(slotGetAudioThumbs())); + } +} + + + +DocClipBase::DocClipBase(const DocClipBase& clip) { m_xml = clip.toXML(); m_id = clip.getId(); m_clipType = clip.clipType(); @@ -57,8 +55,7 @@ DocClipBase::DocClipBase(const DocClipBase& clip) m_audioThumbCreated = clip.audioThumbCreated(); } -DocClipBase & DocClipBase::operator=(const DocClipBase & clip) -{ +DocClipBase & DocClipBase::operator=(const DocClipBase & clip) { DocClipBase::operator=(clip); m_xml = clip.toXML(); m_id = clip.getId(); @@ -69,360 +66,324 @@ DocClipBase & DocClipBase::operator=(const DocClipBase & clip) return *this; } -DocClipBase::~DocClipBase() -{ - //if (m_thumbProd) delete m_thumbProd; +DocClipBase::~DocClipBase() { + //if (m_thumbProd) delete m_thumbProd; } -void DocClipBase::slotRequestAudioThumbs() -{ - emit getAudioThumbs(); +void DocClipBase::slotRequestAudioThumbs() { + emit getAudioThumbs(); } -KThumb *DocClipBase::thumbProducer() -{ - return m_thumbProd; +KThumb *DocClipBase::thumbProducer() { + return m_thumbProd; } -bool DocClipBase::audioThumbCreated() const -{ - return m_audioThumbCreated; +bool DocClipBase::audioThumbCreated() const { + return m_audioThumbCreated; } -void DocClipBase::setName(const QString name) -{ +void DocClipBase::setName(const QString name) { m_name = name; } -const QString & DocClipBase::name() const -{ - +const QString & DocClipBase::name() const { + return m_name; } -uint DocClipBase::getId() const -{ +uint DocClipBase::getId() const { return m_id; } -void DocClipBase::setId( const uint &newId) -{ +void DocClipBase::setId(const uint &newId) { m_id = newId; } -const CLIPTYPE & DocClipBase::clipType() const -{ - return m_clipType; +const CLIPTYPE & DocClipBase::clipType() const { + return m_clipType; } -void DocClipBase::setClipType(CLIPTYPE type) -{ - m_clipType = type; +void DocClipBase::setClipType(CLIPTYPE type) { + m_clipType = type; } -KUrl DocClipBase::fileURL() const -{ - QString res = m_xml.attribute("resource"); - if (m_clipType != COLOR && !res.isEmpty()) return KUrl(res); - return KUrl(); +KUrl DocClipBase::fileURL() const { + QString res = m_xml.attribute("resource"); + if (m_clipType != COLOR && !res.isEmpty()) return KUrl(res); + return KUrl(); } -void DocClipBase::setProjectThumbFrame( const uint &ix) -{ +void DocClipBase::setProjectThumbFrame(const uint &ix) { m_projectThumbFrame = ix; } -uint DocClipBase::getProjectThumbFrame() const -{ +uint DocClipBase::getProjectThumbFrame() const { return m_projectThumbFrame; } -void DocClipBase::setDescription(const QString & description) -{ +void DocClipBase::setDescription(const QString & description) { m_description = description; } -const QString & DocClipBase::description() const -{ +const QString & DocClipBase::description() const { return m_description; } -void DocClipBase::setDuration(GenTime dur) -{ +void DocClipBase::setDuration(GenTime dur) { m_duration = dur; } -const GenTime &DocClipBase::duration() const -{ +const GenTime &DocClipBase::duration() const { return m_duration; } -bool DocClipBase::hasFileSize() const -{ - return true; +bool DocClipBase::hasFileSize() const { + return true; } // virtual -QDomElement DocClipBase::toXML() const -{ -/* - QDomDocument doc; - - QDomElement clip = doc.createElement("kdenliveclip"); - QDomText text = doc.createTextNode(description()); - clip.appendChild(text); - doc.appendChild(clip); -*/ +QDomElement DocClipBase::toXML() const { + /* + QDomDocument doc; + + QDomElement clip = doc.createElement("kdenliveclip"); + QDomText text = doc.createTextNode(description()); + clip.appendChild(text); + doc.appendChild(clip); + */ return m_xml; } DocClipBase *DocClipBase:: -createClip(KdenliveDoc *doc, const QDomElement & element) -{ +createClip(KdenliveDoc *doc, const QDomElement & element) { DocClipBase *clip = 0; QString description; QDomNode node = element; node.normalize(); if (element.tagName() != "kdenliveclip") { - kWarning() << - "DocClipBase::createClip() element has unknown tagName : " << - element.tagName() << endl; - return 0; + kWarning() << + "DocClipBase::createClip() element has unknown tagName : " << + element.tagName() << endl; + return 0; } QDomNode n = element.firstChild(); while (!n.isNull()) { - QDomElement e = n.toElement(); - if (!e.isNull()) { - QString tagName = e.tagName(); - if (e.tagName() == "avfile") { - // clip = DocClipAVFile::createClip(e); - } else if (e.tagName() == "DocTrackBaseList") { - // clip = DocClipProject::createClip(doc, e); - } - } else { - QDomText text = n.toText(); - if (!text.isNull()) { - description = text.nodeValue(); - } - } - - n = n.nextSibling(); + QDomElement e = n.toElement(); + if (!e.isNull()) { + QString tagName = e.tagName(); + if (e.tagName() == "avfile") { + // clip = DocClipAVFile::createClip(e); + } else if (e.tagName() == "DocTrackBaseList") { + // clip = DocClipProject::createClip(doc, e); + } + } else { + QDomText text = n.toText(); + if (!text.isNull()) { + description = text.nodeValue(); + } + } + + n = n.nextSibling(); } if (clip == 0) { - kWarning() << "DocClipBase::createClip() unable to create clip" << - endl; + kWarning() << "DocClipBase::createClip() unable to create clip" << + endl; } else { - // setup DocClipBase specifics of the clip. - clip->setDescription(description); - clip->setAudioThumbCreated(false); + // setup DocClipBase specifics of the clip. + clip->setDescription(description); + clip->setAudioThumbCreated(false); } return clip; } -void DocClipBase::setAudioThumbCreated(bool isDone) -{ +void DocClipBase::setAudioThumbCreated(bool isDone) { m_audioThumbCreated = isDone; } -QDomDocument DocClipBase::generateSceneList(bool, bool) const -{ +QDomDocument DocClipBase::generateSceneList(bool, bool) const { } -void DocClipBase::setThumbnail(const QPixmap & pixmap) -{ +void DocClipBase::setThumbnail(const QPixmap & pixmap) { m_thumbnail = pixmap; } -const QPixmap & DocClipBase::thumbnail() const -{ +const QPixmap & DocClipBase::thumbnail() const { return m_thumbnail; } -void DocClipBase::updateAudioThumbnail(QMap > data) -{ - kDebug()<<"CLIPBASE RECIEDVED AUDIO DATA*********************************************"; +void DocClipBase::updateAudioThumbnail(QMap > data) { + kDebug() << "CLIPBASE RECIEDVED AUDIO DATA*********************************************"; audioFrameChache = data; m_audioThumbCreated = true; emit gotAudioData(); } -QList < GenTime > DocClipBase::snapMarkers() const -{ +QList < GenTime > DocClipBase::snapMarkers() const { QList < GenTime > markers; for (uint count = 0; count < m_snapMarkers.count(); ++count) { - markers.append(m_snapMarkers[count].time()); + markers.append(m_snapMarkers[count].time()); } return markers; } -QList < CommentedTime > DocClipBase::commentedSnapMarkers() const -{ +QList < CommentedTime > DocClipBase::commentedSnapMarkers() const { return m_snapMarkers; } -void DocClipBase::setSnapMarkers(QList < CommentedTime > markers) -{ +void DocClipBase::setSnapMarkers(QList < CommentedTime > markers) { m_snapMarkers = markers; } -void DocClipBase::addSnapMarker(const GenTime & time, QString comment) -{ +void DocClipBase::addSnapMarker(const GenTime & time, QString comment) { QList < CommentedTime >::Iterator it = m_snapMarkers.begin(); - for ( it = m_snapMarkers.begin(); it != m_snapMarkers.end(); ++it ) { - if ((*it).time() >= time) - break; + for (it = m_snapMarkers.begin(); it != m_snapMarkers.end(); ++it) { + if ((*it).time() >= time) + break; } if ((it != m_snapMarkers.end()) && ((*it).time() == time)) { - kError() << - "trying to add Snap Marker that already exists, this will cause inconsistancies with undo/redo" - << endl; + kError() << + "trying to add Snap Marker that already exists, this will cause inconsistancies with undo/redo" + << endl; } else { - CommentedTime t(time, comment); - m_snapMarkers.insert(it, t); + CommentedTime t(time, comment); + m_snapMarkers.insert(it, t); } } -void DocClipBase::editSnapMarker(const GenTime & time, QString comment) -{ +void DocClipBase::editSnapMarker(const GenTime & time, QString comment) { QList < CommentedTime >::Iterator it; - for ( it = m_snapMarkers.begin(); it != m_snapMarkers.end(); ++it ) { - if ((*it).time() == time) - break; + for (it = m_snapMarkers.begin(); it != m_snapMarkers.end(); ++it) { + if ((*it).time() == time) + break; } if (it != m_snapMarkers.end()) { - (*it).setComment(comment); + (*it).setComment(comment); } else { - kError() << - "trying to edit Snap Marker that does not already exists" << endl; + kError() << + "trying to edit Snap Marker that does not already exists" << endl; } } -QString DocClipBase::deleteSnapMarker(const GenTime & time) -{ +QString DocClipBase::deleteSnapMarker(const GenTime & time) { QString result = i18n("Marker"); QList < CommentedTime >::Iterator itt = m_snapMarkers.begin(); while (itt != m_snapMarkers.end()) { - if ((*itt).time() == time) - break; - ++itt; + if ((*itt).time() == time) + break; + ++itt; } if ((itt != m_snapMarkers.end()) && ((*itt).time() == time)) { - result = (*itt).comment(); - m_snapMarkers.erase(itt); + result = (*itt).comment(); + m_snapMarkers.erase(itt); } return result; } -GenTime DocClipBase::hasSnapMarkers(const GenTime & time) -{ +GenTime DocClipBase::hasSnapMarkers(const GenTime & time) { QList < CommentedTime >::Iterator itt = m_snapMarkers.begin(); while (itt != m_snapMarkers.end()) { - if ((*itt).time() == time) - return time; - ++itt; + if ((*itt).time() == time) + return time; + ++itt; } return GenTime(0.0); } -GenTime DocClipBase::findPreviousSnapMarker(const GenTime & currTime) -{ +GenTime DocClipBase::findPreviousSnapMarker(const GenTime & currTime) { int it; - for ( it = 0; it < m_snapMarkers.count(); it++ ) { - if (m_snapMarkers[it].time() >= currTime) - break; + for (it = 0; it < m_snapMarkers.count(); it++) { + if (m_snapMarkers[it].time() >= currTime) + break; } if (it == 0) return GenTime(); else if (it == m_snapMarkers.count() - 1 && m_snapMarkers[it].time() < currTime) - return m_snapMarkers[it].time(); + return m_snapMarkers[it].time(); else return m_snapMarkers[it-1].time(); } -GenTime DocClipBase::findNextSnapMarker(const GenTime & currTime) -{ +GenTime DocClipBase::findNextSnapMarker(const GenTime & currTime) { int it; - for ( it = 0; it < m_snapMarkers.count(); it++ ) { - if (m_snapMarkers[it].time() > currTime) - break; + for (it = 0; it < m_snapMarkers.count(); it++) { + if (m_snapMarkers[it].time() > currTime) + break; } if (it < m_snapMarkers.count() && m_snapMarkers[it].time() > currTime) return m_snapMarkers[it].time(); return duration(); } -QString DocClipBase::markerComment(GenTime t) -{ +QString DocClipBase::markerComment(GenTime t) { QList < CommentedTime >::Iterator itt = m_snapMarkers.begin(); while (itt != m_snapMarkers.end()) { - if ((*itt).time() == t) - return (*itt).comment(); - ++itt; + if ((*itt).time() == t) + return (*itt).comment(); + ++itt; } return QString::null; } //static -QString DocClipBase::getTypeName(CLIPTYPE type) -{ +QString DocClipBase::getTypeName(CLIPTYPE type) { QString result; switch (type) { - case AV: - result = i18n("Video Clip"); - break; - case COLOR: - result = i18n("Color Clip"); - break; - case PLAYLIST: - result = i18n("Playlist Clip"); - break; - case IMAGE: - result = i18n("Image Clip"); - break; - case SLIDESHOW: - result = i18n("Slideshow Clip"); - break; - case VIRTUAL: - result = i18n("Virtual Clip"); - break; - case AUDIO: - result = i18n("Audio Clip"); - break; - case VIDEO: - result = i18n("Mute Video Clip"); - break; - case TEXT: - result = i18n("Text Clip"); - break; - default: - result = i18n("None"); - break; + case AV: + result = i18n("Video Clip"); + break; + case COLOR: + result = i18n("Color Clip"); + break; + case PLAYLIST: + result = i18n("Playlist Clip"); + break; + case IMAGE: + result = i18n("Image Clip"); + break; + case SLIDESHOW: + result = i18n("Slideshow Clip"); + break; + case VIRTUAL: + result = i18n("Virtual Clip"); + break; + case AUDIO: + result = i18n("Audio Clip"); + break; + case VIDEO: + result = i18n("Mute Video Clip"); + break; + case TEXT: + result = i18n("Text Clip"); + break; + default: + result = i18n("None"); + break; } return result; } -void DocClipBase::slotGetAudioThumbs(){ - - if (m_audioThumbCreated){ - if (m_audioTimer!=NULL) - m_audioTimer->stop(); - }else{ - if (m_audioTimer!=NULL) - m_audioTimer->start(2000); - double lengthInFrames=duration().frames(/*framesPerSecond()*/25); - m_thumbProd->getAudioThumbs( 2, 0, lengthInFrames /*must be number of frames*/, 20); - } +void DocClipBase::slotGetAudioThumbs() { + + if (m_audioThumbCreated) { + if (m_audioTimer != NULL) + m_audioTimer->stop(); + } else { + if (m_audioTimer != NULL) + m_audioTimer->start(2000); + double lengthInFrames = duration().frames(/*framesPerSecond()*/25); + m_thumbProd->getAudioThumbs(2, 0, lengthInFrames /*must be number of frames*/, 20); + } } diff --git a/src/docclipbase.h b/src/docclipbase.h index c91934f4..0c422332 100644 --- a/src/docclipbase.h +++ b/src/docclipbase.h @@ -33,7 +33,7 @@ #include "gentime.h" #include "clipmanager.h" #include "definitions.h" - #include "kthumb.h" +#include "kthumb.h" /* class DocTrackBase; @@ -43,208 +43,212 @@ class DocClipVirtual; class EffectDescriptionList;*/ class KdenliveDoc; -class CommentedTime - { - public: - CommentedTime(): t(GenTime(0)) {} - CommentedTime( const GenTime time, QString comment) - : t( time ), c( comment ) - { } - - QString comment() const { return (c.isEmpty() ? i18n("Marker") : c);} - GenTime time() const { return t; } - void setComment( QString comm) { c = comm; } - private: - GenTime t; - QString c; - }; - - -class DocClipBase:public QObject { - Q_OBJECT public: - /** this enum determines the types of "feed" available within this clip. types must be non-exclusive - * - e.g. if you can have audio and video seperately, it should be possible to combin the two, as is - * done here. If a new clip type is added then it should be possible to combine it with both audio - * and video. */ - - DocClipBase(ClipManager *clipManager, QDomElement xml, uint id); - DocClipBase(const DocClipBase& clip); - DocClipBase & operator=(const DocClipBase & clip); - virtual ~ DocClipBase(); - - /** sets the name of this clip. */ +class CommentedTime { +public: + CommentedTime(): t(GenTime(0)) {} + CommentedTime(const GenTime time, QString comment) + : t(time), c(comment) { } + + QString comment() const { + return (c.isEmpty() ? i18n("Marker") : c); + } + GenTime time() const { + return t; + } + void setComment(QString comm) { + c = comm; + } +private: + GenTime t; + QString c; +}; + + +class DocClipBase: public QObject { +Q_OBJECT public: + /** this enum determines the types of "feed" available within this clip. types must be non-exclusive + * - e.g. if you can have audio and video seperately, it should be possible to combin the two, as is + * done here. If a new clip type is added then it should be possible to combine it with both audio + * and video. */ + + DocClipBase(ClipManager *clipManager, QDomElement xml, uint id); + DocClipBase(const DocClipBase& clip); + DocClipBase & operator=(const DocClipBase & clip); + virtual ~ DocClipBase(); + + /** sets the name of this clip. */ void setName(const QString name); - /** returns the name of this clip. */ + /** returns the name of this clip. */ const QString & name() const; - /** Sets the description for this clip. */ + /** Sets the description for this clip. */ void setDescription(const QString & descripton); - /** Returns the description of this clip. */ + /** Returns the description of this clip. */ const QString & description() const; /** Returns the internal unique id of the clip. */ uint getId() const; - void setId( const uint &newId); + void setId(const uint &newId); //KThumb *thumbCreator; bool audioThumbCreated() const; - - /** returns the duration of this clip */ + + /** returns the duration of this clip */ const GenTime & duration() const; - /** returns the duration of this clip */ + /** returns the duration of this clip */ void setDuration(GenTime dur); - /** returns clip type (audio, text, image,...) */ + /** returns clip type (audio, text, image,...) */ const CLIPTYPE & clipType() const; - /** set clip type (audio, text, image,...) */ + /** set clip type (audio, text, image,...) */ void setClipType(CLIPTYPE type); - /** remove tmp file if the clip has one (for example text clips) */ + /** remove tmp file if the clip has one (for example text clips) */ void removeTmpFile() const; - /** Returns a url to a file describing this clip. Exactly what this url is, - whether it is temporary or not, and whether it provokes a render will - depend entirely on what the clip consists of. */ + /** Returns a url to a file describing this clip. Exactly what this url is, + whether it is temporary or not, and whether it provokes a render will + depend entirely on what the clip consists of. */ KUrl fileURL() const; - /** Returns true if the clip duration is known, false otherwise. */ + /** Returns true if the clip duration is known, false otherwise. */ bool durationKnown() const; // Returns the number of frames per second that this clip should play at. double framesPerSecond() const; bool isDocClipAVFile() const { - return false; - } - + return false; + } + /*virtual DocClipAVFile *toDocClipAVFile() { - return 0; + return 0; } virtual DocClipTextFile *toDocClipTextFile() { return 0; } - + virtual bool isDocClipTextFile() const { return false; } virtual bool isDocClipVirtual() const { return false; - } - + } + virtual DocClipVirtual *toDocClipVirtual() { return 0; }*/ - - /** Returns true if this clip is a project clip, false otherwise. Overridden in DocClipProject, - * where it returns true. */ + + /** Returns true if this clip is a project clip, false otherwise. Overridden in DocClipProject, + * where it returns true. */ bool isProjectClip() const { - return false; + return false; } // Appends scene times for this clip to the passed vector. -/* virtual void populateSceneTimes(QList < GenTime > - &toPopulate) const = 0;*/ + /* virtual void populateSceneTimes(QList < GenTime > + &toPopulate) const = 0;*/ - /** Reads in the element structure and creates a clip out of it.*/ + /** Reads in the element structure and creates a clip out of it.*/ // Returns an XML document that describes part of the current scene. QDomDocument sceneToXML(const GenTime & startTime, - const GenTime & endTime) const; - /** returns a QString containing all of the XML data required to recreate this clip. */ + const GenTime & endTime) const; + /** returns a QString containing all of the XML data required to recreate this clip. */ QDomElement toXML() const; QDomDocument generateSceneList(bool addProducers = true, bool rendering = false) const; - /** Returns true if the xml passed matches the values in this clip */ + /** Returns true if the xml passed matches the values in this clip */ bool matchesXML(const QDomElement & element) const; void addReference() { - ++m_refcount; + ++m_refcount; } void removeReference() { - --m_refcount; + --m_refcount; } uint numReferences() const { - return m_refcount; + return m_refcount; } - /** Returns true if this clip has a meaningful filesize. */ - bool hasFileSize() const; + /** Returns true if this clip has a meaningful filesize. */ + bool hasFileSize() const; - /** Returns the filesize, or 0 if there is no appropriate filesize. */ + /** Returns the filesize, or 0 if there is no appropriate filesize. */ uint fileSize() const; - /** Returns true if this clip refers to the clip passed in. A clip refers to another clip if - * it uses it as part of it's own composition. */ + /** Returns true if this clip refers to the clip passed in. A clip refers to another clip if + * it uses it as part of it's own composition. */ bool referencesClip(DocClipBase * clip) const; - /** Sets the thumbnail to be used by this clip */ + /** Sets the thumbnail to be used by this clip */ void setThumbnail(const QPixmap & pixmap); - /** Returns the thumbnail producer used by this clip */ + /** Returns the thumbnail producer used by this clip */ KThumb *thumbProducer(); - /** Returns the thumbnail used by this clip */ + /** Returns the thumbnail used by this clip */ const QPixmap & thumbnail() const; static DocClipBase *createClip(KdenliveDoc *doc, const QDomElement & element); /** Cache for every audio Frame with 10 Bytes */ /** format is frame -> channel ->bytes */ - QMap > audioFrameChache; + QMap > audioFrameChache; - /** return english name for clip type */ + /** return english name for clip type */ static QString getTypeName(CLIPTYPE type); - /** Clip is ready to get thumbs */ + /** Clip is ready to get thumbs */ void slotRequestAudioThumbs(); - private: // Private attributes - /** The name of this clip */ +private: // Private attributes + /** The name of this clip */ QString m_name; - /** A description of this clip */ + /** A description of this clip */ QString m_description; - /** The number of times this clip is used in the project - the number of references to this clip - * that exist. */ + /** The number of times this clip is used in the project - the number of references to this clip + * that exist. */ uint m_refcount; CLIPTYPE m_clipType; - /** A list of snap markers; these markers are added to a clips snap-to points, and are displayed as necessary. */ + /** A list of snap markers; these markers are added to a clips snap-to points, and are displayed as necessary. */ QList < CommentedTime > m_snapMarkers; QDomElement m_xml; - /** A thumbnail for this clip */ + /** A thumbnail for this clip */ QPixmap m_thumbnail; GenTime m_duration; QTimer *m_audioTimer; KThumb *m_thumbProd; bool m_audioThumbCreated; - + /** a unique numeric id */ uint m_id; uint m_projectThumbFrame; void setAudioThumbCreated(bool isDone); - - public slots: - void updateAudioThumbnail(QMap > data); - void slotGetAudioThumbs(); - QList < CommentedTime > commentedSnapMarkers() const; - void setSnapMarkers(QList < CommentedTime > markers); - GenTime findNextSnapMarker(const GenTime & currTime); - GenTime findPreviousSnapMarker(const GenTime & currTime); - GenTime hasSnapMarkers(const GenTime & time); - QString deleteSnapMarker(const GenTime & time); - void editSnapMarker(const GenTime & time, QString comment); - void addSnapMarker(const GenTime & time, QString comment); - QList < GenTime > snapMarkers() const; - QString markerComment(GenTime t); - void setProjectThumbFrame( const uint &ix); - uint getProjectThumbFrame() const; - - signals: - void getAudioThumbs(); - void gotAudioData(); + +public slots: + void updateAudioThumbnail(QMap > data); + void slotGetAudioThumbs(); + QList < CommentedTime > commentedSnapMarkers() const; + void setSnapMarkers(QList < CommentedTime > markers); + GenTime findNextSnapMarker(const GenTime & currTime); + GenTime findPreviousSnapMarker(const GenTime & currTime); + GenTime hasSnapMarkers(const GenTime & time); + QString deleteSnapMarker(const GenTime & time); + void editSnapMarker(const GenTime & time, QString comment); + void addSnapMarker(const GenTime & time, QString comment); + QList < GenTime > snapMarkers() const; + QString markerComment(GenTime t); + void setProjectThumbFrame(const uint &ix); + uint getProjectThumbFrame() const; + +signals: + void getAudioThumbs(); + void gotAudioData(); }; #endif diff --git a/src/documentaudiotrack.cpp b/src/documentaudiotrack.cpp index 586e4e00..1869331a 100644 --- a/src/documentaudiotrack.cpp +++ b/src/documentaudiotrack.cpp @@ -11,9 +11,8 @@ #include "documentaudiotrack.h" DocumentAudioTrack::DocumentAudioTrack(QDomElement xml, TrackView * view, QWidget *parent) - : DocumentTrack(xml, view, parent), m_trackView(view) -{ - setFixedHeight(50); + : DocumentTrack(xml, view, parent), m_trackView(view) { + setFixedHeight(50); } // virtual diff --git a/src/documentaudiotrack.h b/src/documentaudiotrack.h index c806243f..7f6c2d07 100644 --- a/src/documentaudiotrack.h +++ b/src/documentaudiotrack.h @@ -4,19 +4,18 @@ #include "documenttrack.h" #include "trackview.h" -class DocumentAudioTrack : public DocumentTrack -{ - Q_OBJECT - - public: - DocumentAudioTrack(QDomElement xml, TrackView * view, QWidget *parent=0); +class DocumentAudioTrack : public DocumentTrack { + Q_OBJECT - protected: +public: + DocumentAudioTrack(QDomElement xml, TrackView * view, QWidget *parent = 0); + +protected: //virtual void paintEvent(QPaintEvent * /*e*/); - private: +private: TrackView *m_trackView; - public slots: +public slots: }; diff --git a/src/documenttrack.cpp b/src/documenttrack.cpp index 676165f1..1aeced91 100644 --- a/src/documenttrack.cpp +++ b/src/documenttrack.cpp @@ -11,67 +11,57 @@ #include "documenttrack.h" DocumentTrack::DocumentTrack(QDomElement xml, TrackView * view, QWidget *parent) - : QWidget(parent), m_xml(xml), m_trackDuration(0) -{ - setFixedHeight(50); - addFunctionDecorator("move", "move"); - parseXml(); + : QWidget(parent), m_xml(xml), m_trackDuration(0) { + setFixedHeight(50); + addFunctionDecorator("move", "move"); + parseXml(); } -int DocumentTrack::documentTrackIndex() -{ - return 0; +int DocumentTrack::documentTrackIndex() { + return 0; } -TrackViewClip *DocumentTrack::getClipAt(GenTime pos) -{ - return 0; +TrackViewClip *DocumentTrack::getClipAt(GenTime pos) { + return 0; } -void DocumentTrack::addFunctionDecorator(const QString & mode, const QString & function) -{ - m_trackPanelFunctions[mode].append(function); +void DocumentTrack::addFunctionDecorator(const QString & mode, const QString & function) { + m_trackPanelFunctions[mode].append(function); } -QStringList DocumentTrack::applicableFunctions(const QString & mode) -{ - return m_trackPanelFunctions[mode]; +QStringList DocumentTrack::applicableFunctions(const QString & mode) { + return m_trackPanelFunctions[mode]; } -void DocumentTrack::parseXml() -{ - m_clipList.clear(); - int position = 0; - for(QDomNode n = m_xml.firstChild(); !n.isNull(); n = n.nextSibling()) - { - QDomElement elem = n.toElement(); - if (elem.tagName() == "blank") { - position += elem.attribute("length", 0).toInt(); - } - else if (elem.tagName() == "entry") { - TrackViewClip clip; - clip.startTime = position; - int in = elem.attribute("in", 0).toInt(); - int out = elem.attribute("out", 0).toInt() - in; - clip.cropTime = in; - clip.duration = out; - position += out; - clip.producer = elem.attribute("producer", QString::null); - kDebug()<<"++++++++++++++\n\n / / /ADDING CLIP: "< DocumentTrack::clipList() -{ - return m_clipList; +QList DocumentTrack::clipList() { + return m_clipList; } // virtual diff --git a/src/documenttrack.h b/src/documenttrack.h index 27caf4d5..856a4a1d 100644 --- a/src/documenttrack.h +++ b/src/documenttrack.h @@ -14,13 +14,12 @@ class TrackPanelFunction; class TrackView; - -class DocumentTrack : public QWidget -{ - Q_OBJECT - - public: - DocumentTrack(QDomElement xml, TrackView * view, QWidget *parent=0); + +class DocumentTrack : public QWidget { + Q_OBJECT + +public: + DocumentTrack(QDomElement xml, TrackView * view, QWidget *parent = 0); QList clipList(); int duration(); @@ -29,19 +28,19 @@ class DocumentTrack : public QWidget void addFunctionDecorator(const QString & mode, const QString & function); QStringList applicableFunctions(const QString & mode); - protected: +protected: //virtual void paintEvent(QPaintEvent * /*e*/); - private: +private: QDomElement m_xml; QList m_clipList; void parseXml(); int m_trackDuration; - /** A map of lists of track panel functions. */ + /** A map of lists of track panel functions. */ QMap < QString, QStringList > m_trackPanelFunctions; - public slots: +public slots: }; diff --git a/src/documentvideotrack.cpp b/src/documentvideotrack.cpp index b92971fc..1a7e0f0d 100644 --- a/src/documentvideotrack.cpp +++ b/src/documentvideotrack.cpp @@ -11,9 +11,8 @@ #include "documentvideotrack.h" DocumentVideoTrack::DocumentVideoTrack(QDomElement xml, TrackView * view, QWidget *parent) - : DocumentTrack(xml, view, parent), m_trackView(view) -{ - setFixedHeight(50); + : DocumentTrack(xml, view, parent), m_trackView(view) { + setFixedHeight(50); } // virtual diff --git a/src/documentvideotrack.h b/src/documentvideotrack.h index 83d45d9c..c6cb6e6a 100644 --- a/src/documentvideotrack.h +++ b/src/documentvideotrack.h @@ -5,19 +5,18 @@ #include "documenttrack.h" #include "trackview.h" -class DocumentVideoTrack : public DocumentTrack -{ - Q_OBJECT - - public: - DocumentVideoTrack(QDomElement xml, TrackView * view, QWidget *parent=0); - - protected: +class DocumentVideoTrack : public DocumentTrack { + Q_OBJECT + +public: + DocumentVideoTrack(QDomElement xml, TrackView * view, QWidget *parent = 0); + +protected: //virtual void paintEvent(QPaintEvent * /*e*/); - private: +private: TrackView *m_trackView; - public slots: +public slots: }; diff --git a/src/editeffectcommand.cpp b/src/editeffectcommand.cpp index 5b6a0d80..7359614b 100644 --- a/src/editeffectcommand.cpp +++ b/src/editeffectcommand.cpp @@ -22,38 +22,34 @@ #include "editeffectcommand.h" EditEffectCommand::EditEffectCommand(CustomTrackView *view, const int track, GenTime pos, QDomElement oldeffect, QDomElement effect, bool doIt) - : m_view(view), m_track(track), m_pos(pos), m_oldeffect(oldeffect), m_doIt(doIt) { - m_effect = effect.cloneNode().toElement(); - setText(i18n("Edit effect")); - } + : m_view(view), m_track(track), m_pos(pos), m_oldeffect(oldeffect), m_doIt(doIt) { + m_effect = effect.cloneNode().toElement(); + setText(i18n("Edit effect")); +} // virtual -int EditEffectCommand::id() const -{ - return 1; +int EditEffectCommand::id() const { + return 1; } // virtual -bool EditEffectCommand::mergeWith ( const QUndoCommand * other ) -{ - if (other->id() != id()) return false; - if (m_track != static_cast(other)->m_track) return false; - if (m_pos != static_cast(other)->m_pos) return false; - m_effect = static_cast(other)->m_effect; - return true; +bool EditEffectCommand::mergeWith(const QUndoCommand * other) { + if (other->id() != id()) return false; + if (m_track != static_cast(other)->m_track) return false; + if (m_pos != static_cast(other)->m_pos) return false; + m_effect = static_cast(other)->m_effect; + return true; } -// virtual -void EditEffectCommand::undo() -{ -kDebug()<<"---- undoing action"; - m_view->updateEffect(m_track, m_pos, m_oldeffect); +// virtual +void EditEffectCommand::undo() { + kDebug() << "---- undoing action"; + m_view->updateEffect(m_track, m_pos, m_oldeffect); } -// virtual -void EditEffectCommand::redo() -{ -kDebug()<<"---- redoing action"; - m_view->updateEffect(m_track, m_pos, m_effect); +// virtual +void EditEffectCommand::redo() { + kDebug() << "---- redoing action"; + m_view->updateEffect(m_track, m_pos, m_effect); } #include "editeffectcommand.moc" diff --git a/src/editeffectcommand.h b/src/editeffectcommand.h index 276d6a95..902011ab 100644 --- a/src/editeffectcommand.h +++ b/src/editeffectcommand.h @@ -26,24 +26,23 @@ #include "customtrackview.h" -class EditEffectCommand : public QUndoCommand - { - public: - EditEffectCommand(CustomTrackView *view, const int track, GenTime pos, QDomElement oldeffect, QDomElement effect, bool doIt); +class EditEffectCommand : public QUndoCommand { +public: + EditEffectCommand(CustomTrackView *view, const int track, GenTime pos, QDomElement oldeffect, QDomElement effect, bool doIt); virtual int id() const; - virtual bool mergeWith ( const QUndoCommand * command ); + virtual bool mergeWith(const QUndoCommand * command); virtual void undo(); virtual void redo(); - private: - CustomTrackView *m_view; - int m_track; - QDomElement m_effect; - QDomElement m_oldeffect; - GenTime m_pos; - bool m_doIt; - }; +private: + CustomTrackView *m_view; + int m_track; + QDomElement m_effect; + QDomElement m_oldeffect; + GenTime m_pos; + bool m_doIt; +}; #endif diff --git a/src/effectslist.cpp b/src/effectslist.cpp index 56521afc..9d309955 100644 --- a/src/effectslist.cpp +++ b/src/effectslist.cpp @@ -22,71 +22,65 @@ EffectsList::EffectsList(): -QList < QDomElement > () -{ + QList < QDomElement > () { } -EffectsList::~EffectsList() -{ +EffectsList::~EffectsList() { } -QMap EffectsList::effect(const QString & name) -{ - QMap filter; - QString effectName; - QDomElement effect; - for (int i = 0; i < this->size(); ++i) { - effect = this->at(i); - QDomNode namenode = effect.elementsByTagName("name").item(0); - if (!namenode.isNull()) { - effectName = i18n(qstrdup(namenode.toElement().text().toUtf8())); - if (name == effectName) break; +QMap EffectsList::effect(const QString & name) { + QMap filter; + QString effectName; + QDomElement effect; + for (int i = 0; i < this->size(); ++i) { + effect = this->at(i); + QDomNode namenode = effect.elementsByTagName("name").item(0); + if (!namenode.isNull()) { + effectName = i18n(qstrdup(namenode.toElement().text().toUtf8())); + if (name == effectName) break; + } } - } - filter.insert("mlt_service", effect.attribute("tag")); - filter.insert("name", name); - return filter; + filter.insert("mlt_service", effect.attribute("tag")); + filter.insert("name", name); + return filter; } -QDomElement EffectsList::getEffectByName(const QString & name) -{ - QString effectName; - for (int i = 0; i < this->size(); ++i) { - QDomElement effect = this->at(i); - QDomNode namenode = effect.elementsByTagName("name").item(0); - if (!namenode.isNull()) effectName = i18n(qstrdup(namenode.toElement().text().toUtf8())); - if (name == effectName) { - QDomNodeList params = effect.elementsByTagName("parameter"); - for (int i = 0; i < params.count(); i++) { - QDomElement e = params.item(i).toElement(); - e.setAttribute("value", e.attribute("default")); - } - return effect; +QDomElement EffectsList::getEffectByName(const QString & name) { + QString effectName; + for (int i = 0; i < this->size(); ++i) { + QDomElement effect = this->at(i); + QDomNode namenode = effect.elementsByTagName("name").item(0); + if (!namenode.isNull()) effectName = i18n(qstrdup(namenode.toElement().text().toUtf8())); + if (name == effectName) { + QDomNodeList params = effect.elementsByTagName("parameter"); + for (int i = 0; i < params.count(); i++) { + QDomElement e = params.item(i).toElement(); + e.setAttribute("value", e.attribute("default")); + } + return effect; + } } - } - return QDomElement(); + return QDomElement(); } -QStringList EffectsList::effectNames() -{ - QStringList list; - for (int i = 0; i < this->size(); ++i) { - QDomElement effect = this->at(i); - QDomNode namenode = effect.elementsByTagName("name").item(0); - if (!namenode.isNull()) list.append(i18n(qstrdup(namenode.toElement().text().toUtf8()))); - } - return list; +QStringList EffectsList::effectNames() { + QStringList list; + for (int i = 0; i < this->size(); ++i) { + QDomElement effect = this->at(i); + QDomNode namenode = effect.elementsByTagName("name").item(0); + if (!namenode.isNull()) list.append(i18n(qstrdup(namenode.toElement().text().toUtf8()))); + } + return list; } -QString EffectsList::getInfo(QString effectName) -{ - QString info; - QDomElement effect = getEffectByName(effectName); - QDomNode namenode = effect.elementsByTagName("description").item(0); - if (!namenode.isNull()) info = i18n(qstrdup(namenode.toElement().text().toUtf8())); - namenode = effect.elementsByTagName("author").item(0); - if (!namenode.isNull()) info.append(i18n("
Author: ") + i18n(qstrdup(namenode.toElement().text().toUtf8()))); - return info; +QString EffectsList::getInfo(QString effectName) { + QString info; + QDomElement effect = getEffectByName(effectName); + QDomNode namenode = effect.elementsByTagName("description").item(0); + if (!namenode.isNull()) info = i18n(qstrdup(namenode.toElement().text().toUtf8())); + namenode = effect.elementsByTagName("author").item(0); + if (!namenode.isNull()) info.append(i18n("
Author: ") + i18n(qstrdup(namenode.toElement().text().toUtf8()))); + return info; } diff --git a/src/effectslist.h b/src/effectslist.h index affb6869..3a16b835 100644 --- a/src/effectslist.h +++ b/src/effectslist.h @@ -21,22 +21,22 @@ #include /**An List for DocClipBase objects. Use this instead of QList so as to sort lists correctly. - * Also contains the ability to set a "master clip", which can be used by a number of operations where - * the need for one clip to act as a reference for what happens to all clips is needed. + * Also contains the ability to set a "master clip", which can be used by a number of operations where + * the need for one clip to act as a reference for what happens to all clips is needed. * @author Jason Wood */ #include -class EffectsList:public QList < QDomElement > { - public: +class EffectsList: public QList < QDomElement > { +public: EffectsList(); - ~EffectsList(); - /** Returns an XML version of this Effect.*/ - QDomElement getEffectByName(const QString & name); - QStringList effectNames(); - QString getInfo(QString effectName); - QMap effect(const QString & name); + ~EffectsList(); + /** Returns an XML version of this Effect.*/ + QDomElement getEffectByName(const QString & name); + QStringList effectNames(); + QString getInfo(QString effectName); + QMap effect(const QString & name); }; #endif diff --git a/src/effectslistview.cpp b/src/effectslistview.cpp index 140e1a4a..727cfbb0 100644 --- a/src/effectslistview.cpp +++ b/src/effectslistview.cpp @@ -24,74 +24,65 @@ #include "effectslistview.h" EffectsListView::EffectsListView(EffectsList *audioEffectList, EffectsList *videoEffectList, EffectsList *customEffectList, QWidget *parent) - : QWidget(parent) -{ - m_effectsList = new EffectsListWidget(audioEffectList, videoEffectList, customEffectList); + : QWidget(parent) { + m_effectsList = new EffectsListWidget(audioEffectList, videoEffectList, customEffectList); - ui.setupUi(this); - QVBoxLayout *lyr = new QVBoxLayout(ui.effectlistframe); - lyr->addWidget(m_effectsList); - ui.search_effect->setListWidget(m_effectsList); - ui.buttonInfo->setIcon(KIcon("help-about")); - ui.infopanel->hide(); + ui.setupUi(this); + QVBoxLayout *lyr = new QVBoxLayout(ui.effectlistframe); + lyr->addWidget(m_effectsList); + ui.search_effect->setListWidget(m_effectsList); + ui.buttonInfo->setIcon(KIcon("help-about")); + ui.infopanel->hide(); - connect(ui.type_combo, SIGNAL(currentIndexChanged(int)), this, SLOT(filterList(int))); - connect (ui.buttonInfo, SIGNAL (clicked()), this, SLOT (showInfoPanel())); - connect(m_effectsList, SIGNAL(itemSelectionChanged()), this, SLOT(slotUpdateInfo())); - connect(m_effectsList, SIGNAL(doubleClicked(QListWidgetItem *,const QPoint &)), this, SLOT(slotEffectSelected())); + connect(ui.type_combo, SIGNAL(currentIndexChanged(int)), this, SLOT(filterList(int))); + connect(ui.buttonInfo, SIGNAL(clicked()), this, SLOT(showInfoPanel())); + connect(m_effectsList, SIGNAL(itemSelectionChanged()), this, SLOT(slotUpdateInfo())); + connect(m_effectsList, SIGNAL(doubleClicked(QListWidgetItem *, const QPoint &)), this, SLOT(slotEffectSelected())); - m_effectsList->setCurrentRow(0); + m_effectsList->setCurrentRow(0); } -void EffectsListView::filterList(int pos) -{ - QListWidgetItem *item; - for (int i = 0; i < m_effectsList->count(); i++) - { - item = m_effectsList->item(i); - if (pos == 0) item->setHidden(false); - else if (item->data(Qt::UserRole).toInt() == pos) item->setHidden(false); - else item->setHidden(true); - } - item = m_effectsList->currentItem(); - if (item) { - if (item->isHidden()) { - int i; - for (i = 0; i < m_effectsList->count() && m_effectsList->item(i)->isHidden(); i++); - m_effectsList->setCurrentRow(i); +void EffectsListView::filterList(int pos) { + QListWidgetItem *item; + for (int i = 0; i < m_effectsList->count(); i++) { + item = m_effectsList->item(i); + if (pos == 0) item->setHidden(false); + else if (item->data(Qt::UserRole).toInt() == pos) item->setHidden(false); + else item->setHidden(true); + } + item = m_effectsList->currentItem(); + if (item) { + if (item->isHidden()) { + int i; + for (i = 0; i < m_effectsList->count() && m_effectsList->item(i)->isHidden(); i++); + m_effectsList->setCurrentRow(i); + } else m_effectsList->scrollToItem(item); } - else m_effectsList->scrollToItem(item); - } } -void EffectsListView::showInfoPanel() -{ - if (ui.infopanel->isVisible()) { - ui.infopanel->hide(); - ui.buttonInfo->setDown(false); - } - else { - ui.infopanel->show(); - ui.buttonInfo->setDown(true); - } +void EffectsListView::showInfoPanel() { + if (ui.infopanel->isVisible()) { + ui.infopanel->hide(); + ui.buttonInfo->setDown(false); + } else { + ui.infopanel->show(); + ui.buttonInfo->setDown(true); + } } -void EffectsListView::slotEffectSelected() -{ - QDomElement effect = m_effectsList->currentEffect(); - if (!effect.isNull()) emit addEffect(effect); +void EffectsListView::slotEffectSelected() { + QDomElement effect = m_effectsList->currentEffect(); + if (!effect.isNull()) emit addEffect(effect); } -void EffectsListView::slotUpdateInfo() -{ - QString info = m_effectsList->currentInfo(); - if (!info.isEmpty()) ui.infopanel->setText(info); +void EffectsListView::slotUpdateInfo() { + QString info = m_effectsList->currentInfo(); + if (!info.isEmpty()) ui.infopanel->setText(info); } -KListWidget *EffectsListView::listView() -{ - return m_effectsList; +KListWidget *EffectsListView::listView() { + return m_effectsList; } #include "effectslistview.moc" diff --git a/src/effectslistview.h b/src/effectslistview.h index 3cca6c59..84eed84f 100644 --- a/src/effectslistview.h +++ b/src/effectslistview.h @@ -28,28 +28,27 @@ #include "gentime.h" #include "effectslist.h" -class EffectsListView : public QWidget -{ - Q_OBJECT - - public: - EffectsListView(EffectsList *audioEffectList, EffectsList *videoEffectList, EffectsList *customEffectList, QWidget *parent=0); - KListWidget *listView(); +class EffectsListView : public QWidget { + Q_OBJECT + +public: + EffectsListView(EffectsList *audioEffectList, EffectsList *videoEffectList, EffectsList *customEffectList, QWidget *parent = 0); + KListWidget *listView(); //void slotAddEffect(GenTime pos, int track, QString name); - private: +private: Ui::EffectList_UI ui; EffectsListWidget *m_effectsList; - private slots: +private slots: void filterList(int pos); void slotUpdateInfo(); void showInfoPanel(); void slotEffectSelected(); - public slots: +public slots: - signals: +signals: void addEffect(QDomElement); }; diff --git a/src/effectslistwidget.cpp b/src/effectslistwidget.cpp index 0754180e..ed76f14c 100644 --- a/src/effectslistwidget.cpp +++ b/src/effectslistwidget.cpp @@ -29,95 +29,85 @@ #define EFFECT_CUSTOM 3 EffectsListWidget::EffectsListWidget(EffectsList *audioEffectList, EffectsList *videoEffectList, EffectsList *customEffectList, QWidget *parent) - : KListWidget(parent), m_audioList(audioEffectList), m_videoList(videoEffectList), m_customList(customEffectList) -{ - //setSelectionMode(QAbstractItemView::ExtendedSelection); - //setDragDropMode(QAbstractItemView::DragDrop); - setDropIndicatorShown(true); - setAlternatingRowColors(true); - setSortingEnabled(true); - setDragEnabled(true); - setAcceptDrops(true); - initList(); + : KListWidget(parent), m_audioList(audioEffectList), m_videoList(videoEffectList), m_customList(customEffectList) { + //setSelectionMode(QAbstractItemView::ExtendedSelection); + //setDragDropMode(QAbstractItemView::DragDrop); + setDropIndicatorShown(true); + setAlternatingRowColors(true); + setSortingEnabled(true); + setDragEnabled(true); + setAcceptDrops(true); + initList(); } -EffectsListWidget::~EffectsListWidget() -{ +EffectsListWidget::~EffectsListWidget() { } -void EffectsListWidget::initList() -{ - clear(); - QStringList names = m_videoList->effectNames(); - QListWidgetItem *item; - foreach (QString str, names) { - item = new QListWidgetItem(str, this); - item->setData(Qt::UserRole, QString::number((int) EFFECT_VIDEO)); - } - - names = m_audioList->effectNames(); - foreach (QString str, names) { - item = new QListWidgetItem(str, this); - item->setData(Qt::UserRole, QString::number((int) EFFECT_AUDIO)); - } - - names = m_customList->effectNames(); - foreach (QString str, names) { - item = new QListWidgetItem(str, this); - item->setData(Qt::UserRole, QString::number((int) EFFECT_CUSTOM)); - } +void EffectsListWidget::initList() { + clear(); + QStringList names = m_videoList->effectNames(); + QListWidgetItem *item; + foreach(QString str, names) { + item = new QListWidgetItem(str, this); + item->setData(Qt::UserRole, QString::number((int) EFFECT_VIDEO)); + } + + names = m_audioList->effectNames(); + foreach(QString str, names) { + item = new QListWidgetItem(str, this); + item->setData(Qt::UserRole, QString::number((int) EFFECT_AUDIO)); + } + + names = m_customList->effectNames(); + foreach(QString str, names) { + item = new QListWidgetItem(str, this); + item->setData(Qt::UserRole, QString::number((int) EFFECT_CUSTOM)); + } } -QDomElement EffectsListWidget::currentEffect() -{ - return itemEffect(currentItem()); +QDomElement EffectsListWidget::currentEffect() { + return itemEffect(currentItem()); } -QDomElement EffectsListWidget::itemEffect(QListWidgetItem *item) -{ - QDomElement effect; - if (!item) return effect; - switch (item->data(Qt::UserRole).toInt()) - { +QDomElement EffectsListWidget::itemEffect(QListWidgetItem *item) { + QDomElement effect; + if (!item) return effect; + switch (item->data(Qt::UserRole).toInt()) { case 1: - effect = m_videoList->getEffectByName(item->text()); - break; + effect = m_videoList->getEffectByName(item->text()); + break; case 2: - effect = m_audioList->getEffectByName(item->text()); - break; + effect = m_audioList->getEffectByName(item->text()); + break; default: - effect = m_customList->getEffectByName(item->text()); - break; - } - return effect; + effect = m_customList->getEffectByName(item->text()); + break; + } + return effect; } -QString EffectsListWidget::currentInfo() -{ - QListWidgetItem *item = currentItem(); - if (!item) return QString(); - QString info; - switch (item->data(Qt::UserRole).toInt()) - { - case 1: - info = m_videoList->getInfo(item->text()); - break; - case 2: - info = m_audioList->getInfo(item->text()); - break; - default: - info = m_customList->getInfo(item->text()); - break; - } - return info; +QString EffectsListWidget::currentInfo() { + QListWidgetItem *item = currentItem(); + if (!item) return QString(); + QString info; + switch (item->data(Qt::UserRole).toInt()) { + case 1: + info = m_videoList->getInfo(item->text()); + break; + case 2: + info = m_audioList->getInfo(item->text()); + break; + default: + info = m_customList->getInfo(item->text()); + break; + } + return info; } // virtual -void EffectsListWidget::mousePressEvent(QMouseEvent *event) -{ - if( event->button() == Qt::LeftButton ) - { +void EffectsListWidget::mousePressEvent(QMouseEvent *event) { + if (event->button() == Qt::LeftButton) { this->m_DragStartPosition = event->pos(); m_dragStarted = true; } @@ -125,44 +115,44 @@ void EffectsListWidget::mousePressEvent(QMouseEvent *event) } // virtual -void EffectsListWidget::mouseMoveEvent(QMouseEvent *event) -{ - if (!m_dragStarted) return; - if ((event->pos() - m_DragStartPosition).manhattanLength() +void EffectsListWidget::mouseMoveEvent(QMouseEvent *event) { + if (!m_dragStarted) return; + if ((event->pos() - m_DragStartPosition).manhattanLength() < QApplication::startDragDistance()) return; - - { - QListWidgetItem *clickItem = itemAt(event->pos()); - if (clickItem) { - QDrag *drag = new QDrag(this); - QMimeData *mimeData = new QMimeData; - QList list; - list = selectedItems(); - QDomDocument doc; - foreach (QListWidgetItem *item, list) { - doc.appendChild(doc.importNode(itemEffect(item), true)); - } - QByteArray data; - data.append(doc.toString().toUtf8()); - mimeData->setData("kdenlive/effectslist", data ); - drag->setMimeData(mimeData); - //drag->setPixmap(clickItem->icon(0).pixmap(50 *16/9.0, 50)); - drag->setHotSpot(QPoint(0, 50)); - drag->start(Qt::MoveAction); + + { + QListWidgetItem *clickItem = itemAt(event->pos()); + if (clickItem) { + QDrag *drag = new QDrag(this); + QMimeData *mimeData = new QMimeData; + QList list; + list = selectedItems(); + QDomDocument doc; + foreach(QListWidgetItem *item, list) { + doc.appendChild(doc.importNode(itemEffect(item), true)); + } + QByteArray data; + data.append(doc.toString().toUtf8()); + mimeData->setData("kdenlive/effectslist", data); + drag->setMimeData(mimeData); + //QPixmap pix = qVariantValue(clickItem->data(Qt::DecorationRole)); + //drag->setPixmap(pix); + //drag->setHotSpot(QPoint(0, 50)); + drag->start(Qt::MoveAction); + } + //event->accept(); } - //event->accept(); - } } void EffectsListWidget::dragMoveEvent(QDragMoveEvent * event) { - event->setDropAction(Qt::IgnoreAction); - //if (item) { - event->setDropAction(Qt::MoveAction); - if (event->mimeData()->hasText()) { - event->acceptProposedAction(); - } - //} + event->setDropAction(Qt::IgnoreAction); + //if (item) { + event->setDropAction(Qt::MoveAction); + if (event->mimeData()->hasText()) { + event->acceptProposedAction(); + } + //} } diff --git a/src/effectslistwidget.h b/src/effectslistwidget.h index ac85e0dd..317b8c7d 100644 --- a/src/effectslistwidget.h +++ b/src/effectslistwidget.h @@ -24,23 +24,22 @@ #include #include "effectslist.h" -class EffectsListWidget : public KListWidget -{ - Q_OBJECT - - public: - EffectsListWidget(EffectsList *audioEffectList, EffectsList *videoEffectList, EffectsList *customEffectList, QWidget *parent=0); +class EffectsListWidget : public KListWidget { + Q_OBJECT + +public: + EffectsListWidget(EffectsList *audioEffectList, EffectsList *videoEffectList, EffectsList *customEffectList, QWidget *parent = 0); virtual ~EffectsListWidget(); QDomElement currentEffect(); QString currentInfo(); QDomElement itemEffect(QListWidgetItem *item); - protected: +protected: virtual void mousePressEvent(QMouseEvent *event); virtual void mouseMoveEvent(QMouseEvent *event); virtual void dragMoveEvent(QDragMoveEvent *event); - private: +private: bool m_dragStarted; QPoint m_DragStartPosition; EffectsList *m_audioList; @@ -48,6 +47,6 @@ class EffectsListWidget : public KListWidget EffectsList *m_customList; void initList(); - }; +}; #endif diff --git a/src/effectstackedit.cpp b/src/effectstackedit.cpp index ab478519..11c02651 100644 --- a/src/effectstackedit.cpp +++ b/src/effectstackedit.cpp @@ -30,194 +30,193 @@ #include "ui_colorval_ui.h" #include "complexparameter.h" -EffectStackEdit::EffectStackEdit(QFrame* frame,QWidget *parent): QObject(parent) -{ - QScrollArea *area; - QVBoxLayout *vbox1=new QVBoxLayout(frame); - QVBoxLayout *vbox2=new QVBoxLayout(frame); - vbox=new QVBoxLayout(frame); - vbox1->setContentsMargins (0,0,0,0); - vbox1->setSpacing(0); - vbox2->setContentsMargins (0,0,0,0); - vbox2->setSpacing(0); - vbox->setContentsMargins (0,0,0,0); - vbox->setSpacing(0); - frame->setLayout(vbox1); - QFont widgetFont = frame->font(); - widgetFont.setPointSize(widgetFont.pointSize() - 2); - frame->setFont(widgetFont); - - area=new QScrollArea(frame); - QWidget *wid=new QWidget(area); - area->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); - area->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded); - wid->setSizePolicy(QSizePolicy(QSizePolicy::Expanding,QSizePolicy::Minimum)); - //area->setSizePolicy(QSizePolicy(QSizePolicy::Expanding,QSizePolicy::MinimumExpanding)); - - vbox1->addWidget(area); - wid->setLayout(vbox2); - vbox2->addLayout(vbox); - vbox2->addItem(new QSpacerItem(0, 0, QSizePolicy::Minimum, QSizePolicy::MinimumExpanding)); - area->setWidget(wid); - area->setWidgetResizable(true); - wid->show(); - +EffectStackEdit::EffectStackEdit(QFrame* frame, QWidget *parent): QObject(parent) { + QScrollArea *area; + QVBoxLayout *vbox1 = new QVBoxLayout(frame); + QVBoxLayout *vbox2 = new QVBoxLayout(frame); + vbox = new QVBoxLayout(frame); + vbox1->setContentsMargins(0, 0, 0, 0); + vbox1->setSpacing(0); + vbox2->setContentsMargins(0, 0, 0, 0); + vbox2->setSpacing(0); + vbox->setContentsMargins(0, 0, 0, 0); + vbox->setSpacing(0); + frame->setLayout(vbox1); + QFont widgetFont = frame->font(); + widgetFont.setPointSize(widgetFont.pointSize() - 2); + frame->setFont(widgetFont); + + area = new QScrollArea(frame); + QWidget *wid = new QWidget(area); + area->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); + area->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded); + wid->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Minimum)); + //area->setSizePolicy(QSizePolicy(QSizePolicy::Expanding,QSizePolicy::MinimumExpanding)); + + vbox1->addWidget(area); + wid->setLayout(vbox2); + vbox2->addLayout(vbox); + vbox2->addItem(new QSpacerItem(0, 0, QSizePolicy::Minimum, QSizePolicy::MinimumExpanding)); + area->setWidget(wid); + area->setWidgetResizable(true); + wid->show(); + } -void EffectStackEdit::transferParamDesc(const QDomElement& d,int ,int){ - kDebug() << "in"; - params=d; - QDomNodeList namenode = params.elementsByTagName("parameter"); - - clearAllItems(); - - for (int i=0;i< namenode.count() ;i++){ - kDebug() << "in form"; - QDomNode pa=namenode.item(i); - QDomNode na=pa.firstChildElement("name"); - QDomNamedNodeMap nodeAtts=pa.attributes(); - QString type=nodeAtts.namedItem("type").nodeValue(); - QString paramName=na.toElement().text(); - QWidget * toFillin=new QWidget; - QString value=nodeAtts.namedItem("value").isNull()? - nodeAtts.namedItem("default").nodeValue(): - nodeAtts.namedItem("value").nodeValue(); - - //TODO constant, list, bool, complex , color, geometry, position - if (type=="double" || type=="constant"){ - createSliderItem(paramName,value.toInt(),nodeAtts.namedItem("min").nodeValue().toInt(),nodeAtts.namedItem("max").nodeValue().toInt() ); - delete toFillin; - toFillin=NULL; - }else if (type=="list"){ - - Ui::Listval_UI *lsval=new Ui::Listval_UI; - lsval->setupUi(toFillin); - nodeAtts.namedItem("paramlist"); - QStringList listitems=nodeAtts.namedItem("paramlist").nodeValue().split(","); - lsval->list->addItems(listitems); - lsval->list->setCurrentIndex(listitems.indexOf(value));; - connect (lsval->list, SIGNAL(currentIndexChanged(int)) , this, SLOT (collectAllParameters())); - lsval->title->setTitle(na.toElement().text() ); - valueItems[paramName]=lsval; - uiItems.append(lsval); - }else if (type=="bool"){ - Ui::Boolval_UI *bval=new Ui::Boolval_UI; - bval->setupUi(toFillin); - bval->checkBox->setCheckState(value=="0" ? Qt::Unchecked : Qt::Checked); - - connect (bval->checkBox, SIGNAL(stateChanged(int)) , this, SLOT (collectAllParameters())); - bval->checkBox->setText(na.toElement().text() ); - valueItems[paramName]=bval; - uiItems.append(bval); - }else if(type=="complex"){ - /*QStringList names=nodeAtts.namedItem("name").nodeValue().split(";"); - QStringList max=nodeAtts.namedItem("max").nodeValue().split(";"); - QStringList min=nodeAtts.namedItem("min").nodeValue().split(";"); - QStringList val=value.split(";"); - kDebug() << "in complex"<setupParam(d,0,100); - vbox->addWidget(pl); - valueItems[paramName+"complex"]=pl; - items.append(pl); - }else if (type=="color"){ - Ui::Colorval_UI *cval=new Ui::Colorval_UI; - cval->setupUi(toFillin); - bool ok; - cval->kcolorbutton->setColor (value.toUInt(&ok,16)); - kDebug() << value.toUInt(&ok,16); - - connect (cval->kcolorbutton, SIGNAL(clicked()) , this, SLOT (collectAllParameters())); - cval->label->setText(na.toElement().text() ); - valueItems[paramName]=cval; - uiItems.append(cval); - }else{ - delete toFillin; - toFillin=NULL; - } - - if (toFillin){ - items.append(toFillin); - vbox->addWidget(toFillin); - } - } +void EffectStackEdit::transferParamDesc(const QDomElement& d, int , int) { + kDebug() << "in"; + params = d; + QDomNodeList namenode = params.elementsByTagName("parameter"); + + clearAllItems(); + + for (int i = 0;i < namenode.count() ;i++) { + kDebug() << "in form"; + QDomNode pa = namenode.item(i); + QDomNode na = pa.firstChildElement("name"); + QDomNamedNodeMap nodeAtts = pa.attributes(); + QString type = nodeAtts.namedItem("type").nodeValue(); + QString paramName = na.toElement().text(); + QWidget * toFillin = new QWidget; + QString value = nodeAtts.namedItem("value").isNull() ? + nodeAtts.namedItem("default").nodeValue() : + nodeAtts.namedItem("value").nodeValue(); + + //TODO constant, list, bool, complex , color, geometry, position + if (type == "double" || type == "constant") { + createSliderItem(paramName, value.toInt(), nodeAtts.namedItem("min").nodeValue().toInt(), nodeAtts.namedItem("max").nodeValue().toInt()); + delete toFillin; + toFillin = NULL; + } else if (type == "list") { + + Ui::Listval_UI *lsval = new Ui::Listval_UI; + lsval->setupUi(toFillin); + nodeAtts.namedItem("paramlist"); + QStringList listitems = nodeAtts.namedItem("paramlist").nodeValue().split(","); + lsval->list->addItems(listitems); + lsval->list->setCurrentIndex(listitems.indexOf(value));; + connect(lsval->list, SIGNAL(currentIndexChanged(int)) , this, SLOT(collectAllParameters())); + lsval->title->setTitle(na.toElement().text()); + valueItems[paramName] = lsval; + uiItems.append(lsval); + } else if (type == "bool") { + Ui::Boolval_UI *bval = new Ui::Boolval_UI; + bval->setupUi(toFillin); + bval->checkBox->setCheckState(value == "0" ? Qt::Unchecked : Qt::Checked); + + connect(bval->checkBox, SIGNAL(stateChanged(int)) , this, SLOT(collectAllParameters())); + bval->checkBox->setText(na.toElement().text()); + valueItems[paramName] = bval; + uiItems.append(bval); + } else if (type == "complex") { + /*QStringList names=nodeAtts.namedItem("name").nodeValue().split(";"); + QStringList max=nodeAtts.namedItem("max").nodeValue().split(";"); + QStringList min=nodeAtts.namedItem("min").nodeValue().split(";"); + QStringList val=value.split(";"); + kDebug() << "in complex"<setupParam(d, 0, 100); + vbox->addWidget(pl); + valueItems[paramName+"complex"] = pl; + items.append(pl); + } else if (type == "color") { + Ui::Colorval_UI *cval = new Ui::Colorval_UI; + cval->setupUi(toFillin); + bool ok; + cval->kcolorbutton->setColor(value.toUInt(&ok, 16)); + kDebug() << value.toUInt(&ok, 16); + + connect(cval->kcolorbutton, SIGNAL(clicked()) , this, SLOT(collectAllParameters())); + cval->label->setText(na.toElement().text()); + valueItems[paramName] = cval; + uiItems.append(cval); + } else { + delete toFillin; + toFillin = NULL; + } + + if (toFillin) { + items.append(toFillin); + vbox->addWidget(toFillin); + } + } } -void EffectStackEdit::collectAllParameters(){ - QDomElement oldparam = params.cloneNode().toElement(); - QDomNodeList namenode = params.elementsByTagName("parameter"); - - for (int i=0;i< namenode.count() ;i++){ - QDomNode pa=namenode.item(i); - QDomNode na=pa.firstChildElement("name"); - QString type=pa.attributes().namedItem("type").nodeValue(); - QString setValue; - if (type=="double" || type=="constant"){ - QSlider* slider=((Ui::Constval_UI*)valueItems[na.toElement().text()])->horizontalSlider; - setValue=QString::number(slider->value()); - }else - if (type=="list"){ - KComboBox *box=((Ui::Listval_UI*)valueItems[na.toElement().text()])->list; - setValue=box->currentText(); - }else - if (type=="bool"){ - QCheckBox *box=((Ui::Boolval_UI*)valueItems[na.toElement().text()])->checkBox; - setValue=box->checkState() == Qt::Checked ? "1" :"0" ; - }else - if (type=="color"){ - KColorButton *color=((Ui::Colorval_UI*)valueItems[na.toElement().text()])->kcolorbutton; - setValue.sprintf("0x%08x",color->color().rgba()); - }else - if (type=="complex"){ - ComplexParameter *complex=((ComplexParameter*)valueItems[na.toElement().text()+"complex"]); - namenode.item(i)=complex->getParamDesc(); - } - if (!setValue.isEmpty()){ - pa.attributes().namedItem("value").setNodeValue(setValue); - } - } - emit parameterChanged(oldparam, params); +void EffectStackEdit::collectAllParameters() { + QDomElement oldparam = params.cloneNode().toElement(); + QDomNodeList namenode = params.elementsByTagName("parameter"); + + for (int i = 0;i < namenode.count() ;i++) { + QDomNode pa = namenode.item(i); + QDomNode na = pa.firstChildElement("name"); + QString type = pa.attributes().namedItem("type").nodeValue(); + QString setValue; + if (type == "double" || type == "constant") { + QSlider* slider = ((Ui::Constval_UI*)valueItems[na.toElement().text()])->horizontalSlider; + setValue = QString::number(slider->value()); + } else + if (type == "list") { + KComboBox *box = ((Ui::Listval_UI*)valueItems[na.toElement().text()])->list; + setValue = box->currentText(); + } else + if (type == "bool") { + QCheckBox *box = ((Ui::Boolval_UI*)valueItems[na.toElement().text()])->checkBox; + setValue = box->checkState() == Qt::Checked ? "1" : "0" ; + } else + if (type == "color") { + KColorButton *color = ((Ui::Colorval_UI*)valueItems[na.toElement().text()])->kcolorbutton; + setValue.sprintf("0x%08x", color->color().rgba()); + } else + if (type == "complex") { + ComplexParameter *complex = ((ComplexParameter*)valueItems[na.toElement().text()+"complex"]); + namenode.item(i) = complex->getParamDesc(); + } + if (!setValue.isEmpty()) { + pa.attributes().namedItem("value").setNodeValue(setValue); + } + } + emit parameterChanged(oldparam, params); } -void EffectStackEdit::createSliderItem(const QString& name, int val ,int min, int max){ - QWidget* toFillin=new QWidget; - Ui::Constval_UI *ctval=new Ui::Constval_UI; - ctval->setupUi(toFillin); - - ctval->horizontalSlider->setMinimum(min); - ctval->horizontalSlider->setMaximum(max); - ctval->spinBox->setMinimum(min); - ctval->spinBox->setMaximum(max); - ctval->horizontalSlider->setPageStep((int) (max - min)/10); - ctval->horizontalSlider->setValue(val); - ctval->label->setText(name); - valueItems[name]=ctval; - uiItems.append(ctval); - connect (ctval->horizontalSlider, SIGNAL(valueChanged(int)) , this, SLOT (collectAllParameters())); - items.append(toFillin); - vbox->addWidget(toFillin); +void EffectStackEdit::createSliderItem(const QString& name, int val , int min, int max) { + QWidget* toFillin = new QWidget; + Ui::Constval_UI *ctval = new Ui::Constval_UI; + ctval->setupUi(toFillin); + + ctval->horizontalSlider->setMinimum(min); + ctval->horizontalSlider->setMaximum(max); + ctval->spinBox->setMinimum(min); + ctval->spinBox->setMaximum(max); + ctval->horizontalSlider->setPageStep((int)(max - min) / 10); + ctval->horizontalSlider->setValue(val); + ctval->label->setText(name); + valueItems[name] = ctval; + uiItems.append(ctval); + connect(ctval->horizontalSlider, SIGNAL(valueChanged(int)) , this, SLOT(collectAllParameters())); + items.append(toFillin); + vbox->addWidget(toFillin); } -void EffectStackEdit::slotSliderMoved(int){ - collectAllParameters(); +void EffectStackEdit::slotSliderMoved(int) { + collectAllParameters(); } -void EffectStackEdit::clearAllItems(){ - foreach (QWidget* w,items){ - vbox->removeWidget(w); - delete w; - } - foreach(void * p, uiItems){ - delete p; - } - uiItems.clear(); - items.clear(); - valueItems.clear(); +void EffectStackEdit::clearAllItems() { + foreach(QWidget* w, items) { + vbox->removeWidget(w); + delete w; + } + foreach(void * p, uiItems) { + delete p; + } + uiItems.clear(); + items.clear(); + valueItems.clear(); } diff --git a/src/effectstackedit.h b/src/effectstackedit.h index a96770eb..7270063e 100644 --- a/src/effectstackedit.h +++ b/src/effectstackedit.h @@ -26,25 +26,24 @@ class QFrame; -class EffectStackEdit : public QObject -{ - Q_OBJECT +class EffectStackEdit : public QObject { + Q_OBJECT public: - EffectStackEdit(QFrame* frame,QWidget *parent ); + EffectStackEdit(QFrame* frame, QWidget *parent); private: - void clearAllItems(); - QVBoxLayout *vbox; - QList items; - QList uiItems; - QDomElement params; - QMap valueItems; - void createSliderItem(const QString& name, int val ,int min, int max); + void clearAllItems(); + QVBoxLayout *vbox; + QList items; + QList uiItems; + QDomElement params; + QMap valueItems; + void createSliderItem(const QString& name, int val , int min, int max); public slots: - void transferParamDesc(const QDomElement&,int ,int); - void slotSliderMoved(int); - void collectAllParameters(); + void transferParamDesc(const QDomElement&, int , int); + void slotSliderMoved(int); + void collectAllParameters(); signals: - void parameterChanged(const QDomElement&, const QDomElement& ); + void parameterChanged(const QDomElement&, const QDomElement&); }; - + #endif diff --git a/src/effectstackview.cpp b/src/effectstackview.cpp index ddf91b31..717586b6 100644 --- a/src/effectstackview.cpp +++ b/src/effectstackview.cpp @@ -25,202 +25,198 @@ #include EffectStackView::EffectStackView(EffectsList *audioEffectList, EffectsList *videoEffectList, EffectsList *customEffectList, QWidget *parent) -: QWidget(parent) -{ - ui.setupUi(this); - effectedit=new EffectStackEdit(ui.frame,this); - //ui.effectlist->horizontalHeader()->setVisible(false); - //ui.effectlist->verticalHeader()->setVisible(false); - clipref=NULL; - - ui.buttonNew->setIcon(KIcon("document-new")); - ui.buttonNew->setToolTip(i18n("Add new effect")); - ui.buttonUp->setIcon(KIcon("go-up")); - ui.buttonUp->setToolTip(i18n("Move effect up")); - ui.buttonDown->setIcon(KIcon("go-down")); - ui.buttonDown->setToolTip(i18n("Move effect down")); - ui.buttonDel->setIcon(KIcon("trash-empty")); - ui.buttonDel->setToolTip(i18n("Delete effect")); - ui.buttonReset->setIcon(KIcon("view-refresh")); - ui.buttonReset->setToolTip(i18n("Reset effect")); - - - ui.effectlist->setDragDropMode(QAbstractItemView::NoDragDrop);//use internal if drop is recognised right - - connect (ui.effectlist, SIGNAL ( itemSelectionChanged()), this , SLOT( slotItemSelectionChanged() )); - connect (ui.effectlist, SIGNAL(itemChanged ( QListWidgetItem *)), this , SLOT( slotItemChanged(QListWidgetItem *) )); - connect (ui.buttonNew, SIGNAL (clicked()), this, SLOT (slotNewEffect()) ); - connect (ui.buttonUp, SIGNAL (clicked()), this, SLOT (slotItemUp()) ); - connect (ui.buttonDown, SIGNAL (clicked()), this, SLOT (slotItemDown()) ); - connect (ui.buttonDel, SIGNAL (clicked()), this, SLOT (slotItemDel()) ); - connect (ui.buttonReset, SIGNAL (clicked()), this, SLOT (slotResetEffect()) ); - connect( this, SIGNAL (transferParamDesc(const QDomElement&,int ,int) ), effectedit , SLOT(transferParamDesc(const QDomElement&,int ,int))); - connect(effectedit, SIGNAL (parameterChanged( const QDomElement&, const QDomElement& ) ), this , SLOT (slotUpdateEffectParams( const QDomElement&, const QDomElement& ))); - effectLists["audio"]=audioEffectList; - effectLists["video"]=videoEffectList; - effectLists["custom"]=customEffectList; - - ui.infoBox->hide(); - setEnabled(false); - setEnabled(false); - + : QWidget(parent) { + ui.setupUi(this); + effectedit = new EffectStackEdit(ui.frame, this); + //ui.effectlist->horizontalHeader()->setVisible(false); + //ui.effectlist->verticalHeader()->setVisible(false); + clipref = NULL; + + ui.buttonNew->setIcon(KIcon("document-new")); + ui.buttonNew->setToolTip(i18n("Add new effect")); + ui.buttonUp->setIcon(KIcon("go-up")); + ui.buttonUp->setToolTip(i18n("Move effect up")); + ui.buttonDown->setIcon(KIcon("go-down")); + ui.buttonDown->setToolTip(i18n("Move effect down")); + ui.buttonDel->setIcon(KIcon("trash-empty")); + ui.buttonDel->setToolTip(i18n("Delete effect")); + ui.buttonReset->setIcon(KIcon("view-refresh")); + ui.buttonReset->setToolTip(i18n("Reset effect")); + + + ui.effectlist->setDragDropMode(QAbstractItemView::NoDragDrop);//use internal if drop is recognised right + + connect(ui.effectlist, SIGNAL(itemSelectionChanged()), this , SLOT(slotItemSelectionChanged())); + connect(ui.effectlist, SIGNAL(itemChanged(QListWidgetItem *)), this , SLOT(slotItemChanged(QListWidgetItem *))); + connect(ui.buttonNew, SIGNAL(clicked()), this, SLOT(slotNewEffect())); + connect(ui.buttonUp, SIGNAL(clicked()), this, SLOT(slotItemUp())); + connect(ui.buttonDown, SIGNAL(clicked()), this, SLOT(slotItemDown())); + connect(ui.buttonDel, SIGNAL(clicked()), this, SLOT(slotItemDel())); + connect(ui.buttonReset, SIGNAL(clicked()), this, SLOT(slotResetEffect())); + connect(this, SIGNAL(transferParamDesc(const QDomElement&, int , int)), effectedit , SLOT(transferParamDesc(const QDomElement&, int , int))); + connect(effectedit, SIGNAL(parameterChanged(const QDomElement&, const QDomElement&)), this , SLOT(slotUpdateEffectParams(const QDomElement&, const QDomElement&))); + effectLists["audio"] = audioEffectList; + effectLists["video"] = videoEffectList; + effectLists["custom"] = customEffectList; + + ui.infoBox->hide(); + setEnabled(false); + setEnabled(false); + } -void EffectStackView::slotUpdateEffectParams(const QDomElement& old, const QDomElement& e){ - if (clipref) - emit updateClipEffect(clipref, old, e); +void EffectStackView::slotUpdateEffectParams(const QDomElement& old, const QDomElement& e) { + if (clipref) + emit updateClipEffect(clipref, old, e); } -void EffectStackView::slotClipItemSelected(ClipItem* c) -{ - clipref=c; - if (clipref==NULL) { - setEnabled(false); - return; - } - setEnabled(true); - setupListView(); - +void EffectStackView::slotClipItemSelected(ClipItem* c) { + clipref = c; + if (clipref == NULL) { + setEnabled(false); + return; + } + setEnabled(true); + setupListView(); + } -void EffectStackView::slotItemChanged(QListWidgetItem *item) -{ +void EffectStackView::slotItemChanged(QListWidgetItem *item) { bool disable = true; if (item->checkState() == Qt::Checked) disable = false; - ui.buttonReset->setEnabled( !disable); + ui.buttonReset->setEnabled(!disable); int activeRow = ui.effectlist->currentRow(); - if ( activeRow>=0 ){ - emit changeEffectState(clipref, clipref->effectAt(activeRow), disable); + if (activeRow >= 0) { + emit changeEffectState(clipref, clipref->effectAt(activeRow), disable); } } -void EffectStackView::setupListView(){ - - ui.effectlist->clear(); - for (int i=0;ieffectsCount();i++){ - QDomElement d=clipref->effectAt(i); - QDomNode namenode = d.elementsByTagName("name").item(0); - if (!namenode.isNull()) { - QListWidgetItem* item = new QListWidgetItem(namenode.toElement().text(), ui.effectlist); - item->setFlags(Qt::ItemIsSelectable|Qt::ItemIsDragEnabled|Qt::ItemIsUserCheckable|Qt::ItemIsEnabled); - if (d.attribute("disabled") == "1") item->setCheckState(Qt::Unchecked); - else item->setCheckState(Qt::Checked); - } - } - if (clipref->effectsCount() == 0) - emit transferParamDesc(QDomElement(), 0, 100); - ui.effectlist->setCurrentRow(0); - +void EffectStackView::setupListView() { + + ui.effectlist->clear(); + for (int i = 0;i < clipref->effectsCount();i++) { + QDomElement d = clipref->effectAt(i); + QDomNode namenode = d.elementsByTagName("name").item(0); + if (!namenode.isNull()) { + QListWidgetItem* item = new QListWidgetItem(namenode.toElement().text(), ui.effectlist); + item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsDragEnabled | Qt::ItemIsUserCheckable | Qt::ItemIsEnabled); + if (d.attribute("disabled") == "1") item->setCheckState(Qt::Unchecked); + else item->setCheckState(Qt::Checked); + } + } + if (clipref->effectsCount() == 0) + emit transferParamDesc(QDomElement(), 0, 100); + ui.effectlist->setCurrentRow(0); + } -void EffectStackView::slotItemSelectionChanged(){ - bool hasItem = ui.effectlist->currentItem(); - int activeRow = ui.effectlist->currentRow(); - bool isChecked = ui.effectlist->currentItem()->checkState() == Qt::Checked; - if (hasItem && ui.effectlist->currentItem()->isSelected() ){ - emit transferParamDesc(clipref->effectAt(activeRow), 0, 100);//minx max frame - } - ui.buttonDel->setEnabled( hasItem ); - ui.buttonReset->setEnabled( hasItem && isChecked); - ui.buttonUp->setEnabled( activeRow >0 ); - ui.buttonDown->setEnabled( (activeRow < ui.effectlist->count()-1) && hasItem ); +void EffectStackView::slotItemSelectionChanged() { + bool hasItem = ui.effectlist->currentItem(); + int activeRow = ui.effectlist->currentRow(); + bool isChecked = ui.effectlist->currentItem()->checkState() == Qt::Checked; + if (hasItem && ui.effectlist->currentItem()->isSelected()) { + emit transferParamDesc(clipref->effectAt(activeRow), 0, 100);//minx max frame + } + ui.buttonDel->setEnabled(hasItem); + ui.buttonReset->setEnabled(hasItem && isChecked); + ui.buttonUp->setEnabled(activeRow > 0); + ui.buttonDown->setEnabled((activeRow < ui.effectlist->count() - 1) && hasItem); } -void EffectStackView::slotItemUp(){ - int activeRow = ui.effectlist->currentRow(); - if (activeRow>0){ - QDomElement act = clipref->effectAt(activeRow).cloneNode().toElement(); - QDomElement before = clipref->effectAt(activeRow-1).cloneNode().toElement(); - clipref->setEffectAt(activeRow-1, act); - clipref->setEffectAt(activeRow, before); - } - QListWidgetItem *item = ui.effectlist->takeItem(activeRow); - ui.effectlist->insertItem (activeRow-1, item); - ui.effectlist->setCurrentItem(item); - emit refreshEffectStack(clipref); +void EffectStackView::slotItemUp() { + int activeRow = ui.effectlist->currentRow(); + if (activeRow > 0) { + QDomElement act = clipref->effectAt(activeRow).cloneNode().toElement(); + QDomElement before = clipref->effectAt(activeRow - 1).cloneNode().toElement(); + clipref->setEffectAt(activeRow - 1, act); + clipref->setEffectAt(activeRow, before); + } + QListWidgetItem *item = ui.effectlist->takeItem(activeRow); + ui.effectlist->insertItem(activeRow - 1, item); + ui.effectlist->setCurrentItem(item); + emit refreshEffectStack(clipref); } -void EffectStackView::slotItemDown(){ - int activeRow = ui.effectlist->currentRow(); - if (activeRow < ui.effectlist->count()-1){ - QDomElement act = clipref->effectAt(activeRow).cloneNode().toElement(); - QDomElement after = clipref->effectAt(activeRow+1).cloneNode().toElement(); - clipref->setEffectAt(activeRow+1, act); - clipref->setEffectAt(activeRow, after); - } - QListWidgetItem *item = ui.effectlist->takeItem(activeRow); - ui.effectlist->insertItem (activeRow+1, item); - ui.effectlist->setCurrentItem(item); - emit refreshEffectStack(clipref); +void EffectStackView::slotItemDown() { + int activeRow = ui.effectlist->currentRow(); + if (activeRow < ui.effectlist->count() - 1) { + QDomElement act = clipref->effectAt(activeRow).cloneNode().toElement(); + QDomElement after = clipref->effectAt(activeRow + 1).cloneNode().toElement(); + clipref->setEffectAt(activeRow + 1, act); + clipref->setEffectAt(activeRow, after); + } + QListWidgetItem *item = ui.effectlist->takeItem(activeRow); + ui.effectlist->insertItem(activeRow + 1, item); + ui.effectlist->setCurrentItem(item); + emit refreshEffectStack(clipref); } -void EffectStackView::slotItemDel(){ - int activeRow = ui.effectlist->currentRow(); - if ( activeRow>=0 ){ - emit removeEffect(clipref, clipref->effectAt(activeRow)); - } +void EffectStackView::slotItemDel() { + int activeRow = ui.effectlist->currentRow(); + if (activeRow >= 0) { + emit removeEffect(clipref, clipref->effectAt(activeRow)); + } } -void EffectStackView::slotResetEffect() -{ - int activeRow = ui.effectlist->currentRow(); - QDomElement old = clipref->effectAt(activeRow).cloneNode().toElement(); - QDomElement dom; - QString effectName = ui.effectlist->currentItem()->text(); - foreach (QString type, effectLists.keys() ){ - EffectsList *list=effectLists[type]; - if (list->effectNames().contains(effectName)) { - dom = list->getEffectByName(effectName); - break; - } - } - if (!dom.isNull()) { - dom.setAttribute("kdenlive_ix", old.attribute("kdenlive_ix")); - emit transferParamDesc(dom, 0, 100);//minx max frame - emit updateClipEffect(clipref, old, dom); - } +void EffectStackView::slotResetEffect() { + int activeRow = ui.effectlist->currentRow(); + QDomElement old = clipref->effectAt(activeRow).cloneNode().toElement(); + QDomElement dom; + QString effectName = ui.effectlist->currentItem()->text(); + foreach(QString type, effectLists.keys()) { + EffectsList *list = effectLists[type]; + if (list->effectNames().contains(effectName)) { + dom = list->getEffectByName(effectName); + break; + } + } + if (!dom.isNull()) { + dom.setAttribute("kdenlive_ix", old.attribute("kdenlive_ix")); + emit transferParamDesc(dom, 0, 100);//minx max frame + emit updateClipEffect(clipref, old, dom); + } } -void EffectStackView::slotNewEffect(){ - - - QMenu *displayMenu=new QMenu (this); - displayMenu->setTitle("Filters"); - foreach (QString type, effectLists.keys() ){ - QAction *a=new QAction(type,displayMenu); - EffectsList *list=effectLists[type]; - - QMenu *parts=new QMenu(type,displayMenu); - parts->setTitle(type); - foreach (QString name, list->effectNames()){ - QAction *entry=new QAction(name,parts); - entry->setData(name); - entry->setToolTip(list->getInfo(name)); - entry->setStatusTip(list->getInfo(name)); - parts->addAction(entry); - //QAction - } - displayMenu->addMenu(parts); - - } - - QAction *result=displayMenu->exec(mapToGlobal(ui.buttonNew->pos()+ui.buttonNew->rect().bottomRight())); - - if (result){ - //TODO effects.append(result->data().toString()); - foreach (EffectsList* e, effectLists.values()){ - QDomElement dom=e->getEffectByName(result->data().toString()); - if (clipref) - clipref->addEffect(dom); - slotClipItemSelected(clipref); - } - - setupListView(); - //kDebug()<< result->data(); - } - delete displayMenu; - +void EffectStackView::slotNewEffect() { + + + QMenu *displayMenu = new QMenu(this); + displayMenu->setTitle("Filters"); + foreach(QString type, effectLists.keys()) { + QAction *a = new QAction(type, displayMenu); + EffectsList *list = effectLists[type]; + + QMenu *parts = new QMenu(type, displayMenu); + parts->setTitle(type); + foreach(QString name, list->effectNames()) { + QAction *entry = new QAction(name, parts); + entry->setData(name); + entry->setToolTip(list->getInfo(name)); + entry->setStatusTip(list->getInfo(name)); + parts->addAction(entry); + //QAction + } + displayMenu->addMenu(parts); + + } + + QAction *result = displayMenu->exec(mapToGlobal(ui.buttonNew->pos() + ui.buttonNew->rect().bottomRight())); + + if (result) { + //TODO effects.append(result->data().toString()); + foreach(EffectsList* e, effectLists.values()) { + QDomElement dom = e->getEffectByName(result->data().toString()); + if (clipref) + clipref->addEffect(dom); + slotClipItemSelected(clipref); + } + + setupListView(); + //kDebug()<< result->data(); + } + delete displayMenu; + } #include "effectstackview.moc" diff --git a/src/effectstackview.h b/src/effectstackview.h index c71789db..63f74544 100644 --- a/src/effectstackview.h +++ b/src/effectstackview.h @@ -24,44 +24,43 @@ class EffectsList; -class EffectStackView : public QWidget -{ - Q_OBJECT - - public: - EffectStackView(EffectsList *audioEffectList, EffectsList *videoEffectList, EffectsList *customEffectList, QWidget *parent=0); - +class EffectStackView : public QWidget { + Q_OBJECT + +public: + EffectStackView(EffectsList *audioEffectList, EffectsList *videoEffectList, EffectsList *customEffectList, QWidget *parent = 0); + private: - Ui::EffectStack_UI ui; - ClipItem* clipref; - QMap effectLists; - EffectStackEdit* effectedit; - void setupListView(); - void updateButtonStatus(); + Ui::EffectStack_UI ui; + ClipItem* clipref; + QMap effectLists; + EffectStackEdit* effectedit; + void setupListView(); + void updateButtonStatus(); public slots: - void slotClipItemSelected(ClipItem*); - void slotUpdateEffectParams(const QDomElement&, const QDomElement&); + void slotClipItemSelected(ClipItem*); + void slotUpdateEffectParams(const QDomElement&, const QDomElement&); private slots: - void slotItemSelectionChanged(); - void slotItemUp(); - void slotItemDown(); - void slotItemDel(); - void slotNewEffect(); - void slotResetEffect(); - void slotItemChanged(QListWidgetItem *item); + void slotItemSelectionChanged(); + void slotItemUp(); + void slotItemDown(); + void slotItemDel(); + void slotNewEffect(); + void slotResetEffect(); + void slotItemChanged(QListWidgetItem *item); signals: - void transferParamDesc(const QDomElement&,int ,int); - void removeEffect(ClipItem*, QDomElement); - /** Parameters for an effect changed, update the filter in playlist */ - void updateClipEffect(ClipItem*, QDomElement, QDomElement); - /** An effect in stack was moved, we need to regenerate - all effects for this clip in the playlist */ - void refreshEffectStack(ClipItem *); - /** Enable or disable an effect */ - void changeEffectState(ClipItem*, QDomElement, bool); + void transferParamDesc(const QDomElement&, int , int); + void removeEffect(ClipItem*, QDomElement); + /** Parameters for an effect changed, update the filter in playlist */ + void updateClipEffect(ClipItem*, QDomElement, QDomElement); + /** An effect in stack was moved, we need to regenerate + all effects for this clip in the playlist */ + void refreshEffectStack(ClipItem *); + /** Enable or disable an effect */ + void changeEffectState(ClipItem*, QDomElement, bool); }; diff --git a/src/events.h b/src/events.h index af35d769..055028a9 100644 --- a/src/events.h +++ b/src/events.h @@ -24,12 +24,14 @@ class ProgressEvent : public QEvent { public: - ProgressEvent( int value, QEvent::Type eventType ) - : QEvent( eventType ), m_val( value ) {}; - int value() const { return m_val; }; + ProgressEvent(int value, QEvent::Type eventType) + : QEvent(eventType), m_val(value) {}; + int value() const { + return m_val; + }; private: - int m_val; - + int m_val; + }; diff --git a/src/gentime.cpp b/src/gentime.cpp index a962e20e..5bb26664 100644 --- a/src/gentime.cpp +++ b/src/gentime.cpp @@ -20,35 +20,29 @@ double GenTime::s_delta = 0.00001; /** Creates a time object, with a time of 0 seconds. */ -GenTime::GenTime() -{ +GenTime::GenTime() { m_time = 0.0; } /** Creates a time object, with time given in seconds. */ -GenTime::GenTime(double seconds) -{ +GenTime::GenTime(double seconds) { m_time = seconds; } /** Creates a time object, by passing number of frames and how many frames per second */ -GenTime::GenTime(int frames, double framesPerSecond) -{ +GenTime::GenTime(int frames, double framesPerSecond) { m_time = (double) frames / framesPerSecond; } /** Returns the time, in milliseconds */ -double GenTime::ms() const -{ +double GenTime::ms() const { return m_time * 1000; } /** Returns the time in frames, after being given the number of frames per second */ -double GenTime::frames(double framesPerSecond) const -{ +double GenTime::frames(double framesPerSecond) const { return (int) floor(m_time * framesPerSecond + 0.5); } -GenTime::~GenTime() -{ +GenTime::~GenTime() { } diff --git a/src/gentime.h b/src/gentime.h index 65e06d3c..1c6ff006 100644 --- a/src/gentime.h +++ b/src/gentime.h @@ -25,79 +25,79 @@ */ class GenTime { - public: - /** Creates a time object, with a time of 0 seconds. */ +public: + /** Creates a time object, with a time of 0 seconds. */ GenTime(); - /** Creates a time object, with time given in seconds. */ + /** Creates a time object, with time given in seconds. */ explicit GenTime(double seconds); - /** Creates a time object, by passing number of frames and how many frames per second */ - GenTime(int frames, double framesPerSecond); + /** Creates a time object, by passing number of frames and how many frames per second */ + GenTime(int frames, double framesPerSecond); - /** returns the time, in seconds */ + /** returns the time, in seconds */ double seconds() const { - return m_time; + return m_time; } - /** Returns the time, in milliseconds */ double ms() const; + /** Returns the time, in milliseconds */ double ms() const; - /** Returns the time in frames, after being given the number of frames per second */ + /** Returns the time in frames, after being given the number of frames per second */ double frames(double framesPerSecond) const; - GenTime & operator+=(GenTime op) { - m_time += op.m_time; - return *this; + GenTime & operator+=(GenTime op) { + m_time += op.m_time; + return *this; } - /** Adds two GenTimes */ GenTime operator+(GenTime op) const { - return GenTime(m_time + op.m_time); + /** Adds two GenTimes */ GenTime operator+(GenTime op) const { + return GenTime(m_time + op.m_time); } - /** Subtracts one genTime from another */ GenTime operator-(GenTime op) const { - return GenTime(m_time - op.m_time); + /** Subtracts one genTime from another */ GenTime operator-(GenTime op) const { + return GenTime(m_time - op.m_time); } - /** Multiplies one GenTime by a double value, returning a GenTime */ - GenTime operator*(double op) const { - return GenTime(m_time * op); + /** Multiplies one GenTime by a double value, returning a GenTime */ + GenTime operator*(double op) const { + return GenTime(m_time * op); } - /** Divides one GenTime by a double value, returning a GenTime */ - GenTime operator/(double op) const { - return GenTime(m_time / op); + /** Divides one GenTime by a double value, returning a GenTime */ + GenTime operator/(double op) const { + return GenTime(m_time / op); } /* Implementation of < operator; Works identically as with basic types. */ - bool operator<(GenTime op) const { - return m_time + s_delta < op.m_time; + bool operator<(GenTime op) const { + return m_time + s_delta < op.m_time; } /* Implementation of > operator; Works identically as with basic types. */ - bool operator>(GenTime op) const { - return m_time > op.m_time + s_delta; + bool operator>(GenTime op) const { + return m_time > op.m_time + s_delta; } /* Implementation of >= operator; Works identically as with basic types. */ - bool operator>=(GenTime op) const { - return m_time + s_delta >= op.m_time; + bool operator>=(GenTime op) const { + return m_time + s_delta >= op.m_time; } /* Implementation of <= operator; Works identically as with basic types. */ - bool operator<=(GenTime op) const { - return m_time <= op.m_time + s_delta; + bool operator<=(GenTime op) const { + return m_time <= op.m_time + s_delta; } /* Implementation of == operator; Works identically as with basic types. */ - bool operator==(GenTime op) const { - return fabs(m_time - op.m_time) < s_delta; + bool operator==(GenTime op) const { + return fabs(m_time - op.m_time) < s_delta; } /* Implementation of != operator; Works identically as with basic types. */ - bool operator!=(GenTime op) const { - return fabs(m_time - op.m_time) >= s_delta; + bool operator!=(GenTime op) const { + return fabs(m_time - op.m_time) >= s_delta; } /* Rounds the GenTIme's value to the nearest frame */ - GenTime & roundNearestFrame(double framesPerSecond) { - m_time = floor((m_time * framesPerSecond) + 0.5) / framesPerSecond; - return *this; + GenTime & roundNearestFrame(double framesPerSecond) { + m_time = floor((m_time * framesPerSecond) + 0.5) / framesPerSecond; + return *this; } ~GenTime(); - private: // Private attributes - /** Holds the time for this object. */ +private: // Private attributes + /** Holds the time for this object. */ double m_time; - /** A delta value that is used to get around floating point rounding issues. */ + /** A delta value that is used to get around floating point rounding issues. */ static double s_delta; }; diff --git a/src/graphicsscenerectmove.cpp b/src/graphicsscenerectmove.cpp index aa554e7e..d0ceb8c8 100644 --- a/src/graphicsscenerectmove.cpp +++ b/src/graphicsscenerectmove.cpp @@ -5,132 +5,132 @@ #include #include -QGraphicsItem* selected=NULL; -int button=0; -int resizeMode=-1; -enum resizeMode {NoResize,TopLeft,BottomLeft,TopRight,BottomRight,Left,Right,Up,Down}; -GraphicsSceneRectMove::GraphicsSceneRectMove(QObject *parent):QGraphicsScene(parent){ - //grabMouse(); - zoom=1.0; +QGraphicsItem* selected = NULL; +int button = 0; +int resizeMode = -1; +enum resizeMode {NoResize, TopLeft, BottomLeft, TopRight, BottomRight, Left, Right, Up, Down}; +GraphicsSceneRectMove::GraphicsSceneRectMove(QObject *parent): QGraphicsScene(parent) { + //grabMouse(); + zoom = 1.0; } -void GraphicsSceneRectMove::mouseMoveEvent(QGraphicsSceneMouseEvent* e){ - - if (selected && selected->type()==3 && e->buttons() & Qt::LeftButton){ - - QGraphicsRectItem *gi=(QGraphicsRectItem*)selected; - QRectF newrect=gi->rect(); - QPointF newpoint=e->scenePos(); - newpoint-=selected->scenePos(); - switch (resizeMode){ - case TopLeft: - newrect.setTopLeft(newpoint); - break; - case BottomLeft: - newrect.setBottomLeft(newpoint); - break; - case TopRight: - newrect.setTopRight(newpoint); - break; - case BottomRight: - newrect.setBottomRight(newpoint); - break; - case Left: - newrect.setLeft(newpoint.x()); - break; - case Right: - newrect.setRight(newpoint.x()); - break; - case Up: - newrect.setTop(newpoint.y()); - break; - case Down: - newrect.setBottom(newpoint.y()); - break; - } - - gi->setRect(newrect); - gi->setPos(selected->scenePos()); - } - - QPointF p=e->scenePos(); - p+=QPoint(-2,-2); - resizeMode=NoResize; - selected=NULL; - foreach(QGraphicsItem* g, items( QRectF( p , QSizeF(4,4) ).toRect() ) ){ +void GraphicsSceneRectMove::mouseMoveEvent(QGraphicsSceneMouseEvent* e) { + + if (selected && selected->type() == 3 && e->buttons() & Qt::LeftButton) { + + QGraphicsRectItem *gi = (QGraphicsRectItem*)selected; + QRectF newrect = gi->rect(); + QPointF newpoint = e->scenePos(); + newpoint -= selected->scenePos(); + switch (resizeMode) { + case TopLeft: + newrect.setTopLeft(newpoint); + break; + case BottomLeft: + newrect.setBottomLeft(newpoint); + break; + case TopRight: + newrect.setTopRight(newpoint); + break; + case BottomRight: + newrect.setBottomRight(newpoint); + break; + case Left: + newrect.setLeft(newpoint.x()); + break; + case Right: + newrect.setRight(newpoint.x()); + break; + case Up: + newrect.setTop(newpoint.y()); + break; + case Down: + newrect.setBottom(newpoint.y()); + break; + } + + gi->setRect(newrect); + gi->setPos(selected->scenePos()); + } + + QPointF p = e->scenePos(); + p += QPoint(-2, -2); + resizeMode = NoResize; + selected = NULL; + foreach(QGraphicsItem* g, items(QRectF(p , QSizeF(4, 4)).toRect())) { + + if (g->type() == 3) { + + QGraphicsRectItem *gi = (QGraphicsRectItem*)g; + QRectF r = gi->rect(); + r.translate(gi->scenePos()); + + if ((r.toRect().topLeft() -= e->scenePos().toPoint()).manhattanLength() < 3) { + resizeMode = TopLeft; + } else if ((r.toRect().bottomLeft() -= e->scenePos().toPoint()).manhattanLength() < 3) { + resizeMode = BottomLeft; + } else if ((r.toRect().topRight() -= e->scenePos().toPoint()).manhattanLength() < 3) { + resizeMode = TopRight; + } else if ((r.toRect().bottomRight() -= e->scenePos().toPoint()).manhattanLength() < 3) { + resizeMode = BottomRight; + } else if (qAbs(r.toRect().left() - e->scenePos().toPoint().x()) < 3) { + resizeMode = Left; + } else if (qAbs(r.toRect().right() - e->scenePos().toPoint().x()) < 3) { + resizeMode = Right; + } else if (qAbs(r.toRect().top() - e->scenePos().toPoint().y()) < 3) { + resizeMode = Up; + } else if (qAbs(r.toRect().bottom() - e->scenePos().toPoint().y()) < 3) { + resizeMode = Down; + } + if (resizeMode != NoResize) + selected = gi; + } + break; + } + switch (resizeMode) { + case TopLeft: + case BottomRight: + setCursor(QCursor(Qt::SizeFDiagCursor)); + break; + case BottomLeft: + case TopRight: + setCursor(QCursor(Qt::SizeBDiagCursor)); + break; + case Left: + case Right: + setCursor(Qt::SizeHorCursor); + break; + case Up: + case Down: + setCursor(Qt::SizeVerCursor); + break; + default: + setCursor(QCursor(Qt::ArrowCursor)); + QGraphicsScene::mouseMoveEvent(e); + } - if (g->type()==3 ){ - - QGraphicsRectItem *gi=(QGraphicsRectItem*)g; - QRectF r=gi->rect(); - r.translate(gi->scenePos()); - - if ( (r.toRect().topLeft()-=e->scenePos().toPoint() ).manhattanLength()<3 ){ - resizeMode=TopLeft; - }else if ((r.toRect().bottomLeft()-=e->scenePos().toPoint() ).manhattanLength()<3 ){ - resizeMode=BottomLeft; - }else if ((r.toRect().topRight()-=e->scenePos().toPoint() ).manhattanLength()<3 ){ - resizeMode=TopRight; - }else if ((r.toRect().bottomRight()-=e->scenePos().toPoint() ).manhattanLength()<3 ){ - resizeMode=BottomRight; - }else if ( qAbs(r.toRect().left()-e->scenePos().toPoint().x() ) <3){ - resizeMode=Left; - }else if ( qAbs(r.toRect().right()-e->scenePos().toPoint().x() ) <3){ - resizeMode=Right; - }else if ( qAbs(r.toRect().top()-e->scenePos().toPoint().y() ) <3){ - resizeMode=Up; - }else if ( qAbs(r.toRect().bottom()-e->scenePos().toPoint().y() ) <3){ - resizeMode=Down; - } - if (resizeMode!=NoResize) - selected=gi; - } - break; - } - switch (resizeMode){ - case TopLeft: - case BottomRight: - setCursor(QCursor(Qt::SizeFDiagCursor)); - break; - case BottomLeft: - case TopRight: - setCursor(QCursor(Qt::SizeBDiagCursor)); - break; - case Left: - case Right: - setCursor(Qt::SizeHorCursor); - break; - case Up: - case Down: - setCursor(Qt::SizeVerCursor); - break; - default: - setCursor(QCursor(Qt::ArrowCursor)); - QGraphicsScene::mouseMoveEvent(e); - } - } -void GraphicsSceneRectMove::wheelEvent ( QGraphicsSceneWheelEvent * wheelEvent ){ - QList viewlist=views(); - kDebug() << wheelEvent->delta() << " " << zoom; - if (viewlist.size()>0){ - if (wheelEvent->delta()<0 && zoom<20.0){ - zoom*=1.1; - - }else if (wheelEvent->delta()>0 && zoom>.05){ - zoom/=1.1; - } - - viewlist[0]->resetTransform(); - viewlist[0]->scale(zoom,zoom); - } +void GraphicsSceneRectMove::wheelEvent(QGraphicsSceneWheelEvent * wheelEvent) { + QList viewlist = views(); + kDebug() << wheelEvent->delta() << " " << zoom; + if (viewlist.size() > 0) { + if (wheelEvent->delta() < 0 && zoom < 20.0) { + zoom *= 1.1; + + } else if (wheelEvent->delta() > 0 && zoom > .05) { + zoom /= 1.1; + } + + viewlist[0]->resetTransform(); + viewlist[0]->scale(zoom, zoom); + } } -void GraphicsSceneRectMove::setCursor(QCursor c){ - QList l=views(); - foreach(QGraphicsView* v, l){ - v->setCursor(c); - } +void GraphicsSceneRectMove::setCursor(QCursor c) { + QList l = views(); + foreach(QGraphicsView* v, l) { + v->setCursor(c); + } } diff --git a/src/graphicsscenerectmove.h b/src/graphicsscenerectmove.h index 3f92250c..82560371 100644 --- a/src/graphicsscenerectmove.h +++ b/src/graphicsscenerectmove.h @@ -5,12 +5,12 @@ class GraphicsSceneRectMove: public QGraphicsScene { public: - GraphicsSceneRectMove(QObject* parent=0); - void mouseMoveEvent(QGraphicsSceneMouseEvent*); - void wheelEvent ( QGraphicsSceneWheelEvent * wheelEvent ); + GraphicsSceneRectMove(QObject* parent = 0); + void mouseMoveEvent(QGraphicsSceneMouseEvent*); + void wheelEvent(QGraphicsSceneWheelEvent * wheelEvent); private: - void setCursor(QCursor); - double zoom; + void setCursor(QCursor); + double zoom; }; #endif diff --git a/src/headertrack.cpp b/src/headertrack.cpp index 4e912bab..3b7508da 100644 --- a/src/headertrack.cpp +++ b/src/headertrack.cpp @@ -11,14 +11,12 @@ #include "headertrack.h" HeaderTrack::HeaderTrack(QWidget *parent) - : QWidget(parent) -{ - setFixedHeight(50); + : QWidget(parent) { + setFixedHeight(50); } // virtual -void HeaderTrack::paintEvent(QPaintEvent *e ) -{ +void HeaderTrack::paintEvent(QPaintEvent *e) { QRect region = e->rect(); region.setBottomRight(QPoint(region.right() - 1, region.bottom() - 1)); QPainter painter(this); diff --git a/src/headertrack.h b/src/headertrack.h index a163b77d..9012055d 100644 --- a/src/headertrack.h +++ b/src/headertrack.h @@ -3,19 +3,18 @@ -class HeaderTrack : public QWidget -{ - Q_OBJECT - - public: - HeaderTrack(QWidget *parent=0); - - protected: +class HeaderTrack : public QWidget { + Q_OBJECT + +public: + HeaderTrack(QWidget *parent = 0); + +protected: virtual void paintEvent(QPaintEvent * /*e*/); - private: +private: - public slots: +public slots: }; diff --git a/src/initeffects.cpp b/src/initeffects.cpp index 30daa767..f43f0a1d 100644 --- a/src/initeffects.cpp +++ b/src/initeffects.cpp @@ -28,17 +28,14 @@ #include "initeffects.h" -initEffects::initEffects() -{ +initEffects::initEffects() { } -initEffects::~initEffects() -{ +initEffects::~initEffects() { } //static -Mlt::Repository *initEffects::parseEffectFiles(EffectsList *audioEffectList, EffectsList *videoEffectList) -{ +Mlt::Repository *initEffects::parseEffectFiles(EffectsList *audioEffectList, EffectsList *videoEffectList) { QStringList::Iterator more; QStringList::Iterator it; QStringList fileList; @@ -47,23 +44,23 @@ Mlt::Repository *initEffects::parseEffectFiles(EffectsList *audioEffectList, Eff // Build effects. Retrieve the list of MLT's available effects first. Mlt::Repository *repository = Mlt::Factory::init(); - if (!repository){ - kDebug() << "Repository did not finish init " ; - return NULL; + if (!repository) { + kDebug() << "Repository did not finish init " ; + return NULL; } Mlt::Properties *filters = repository->filters(); QStringList filtersList; - for (int i=0 ; i count() ; i++){ - filtersList << filters->get_name(i); + for (int i = 0 ; i < filters->count() ; i++) { + filtersList << filters->get_name(i); } // Build effects. check producers first. Mlt::Properties *producers = repository->producers(); QStringList producersList; - for (int i=0 ; i count() ; i++){ - producersList << producers->get_name(i); + for (int i = 0 ; i < producers->count() ; i++) { + producersList << producers->get_name(i); } delete filters; delete producers; @@ -74,31 +71,30 @@ Mlt::Repository *initEffects::parseEffectFiles(EffectsList *audioEffectList, Eff KGlobal::dirs()->addResourceDir("ladspa_plugin", "/opt/lib/ladspa"); KGlobal::dirs()->addResourceDir("ladspa_plugin", "/opt/local/lib/ladspa"); - kDebug()<<"// INIT EFFECT SEARCH"<findDirs("data", "kdenlive/effects"); QDir directory; - for ( more = direc.begin() ; more != direc.end() ; ++more ) { - directory = QDir(*more); - fileList = directory.entryList( QDir::Files ); - for ( it = fileList.begin() ; it != fileList.end() ; ++it ){ - itemName = KUrl(*more + *it).path(); - parseEffectFile(audioEffectList, videoEffectList, itemName, filtersList, producersList); - // kDebug()<<"// FOUND EFFECT FILE: "<append(doc.documentElement()); } - foreach(QString filtername,filtersList){ - QDomDocument doc=createDescriptionFromMlt(repository,"filters",filtername); - if (!doc.isNull()) - videoEffectList->append(doc.documentElement()); - } return repository; } // static -void initEffects::parseEffectFile(EffectsList *audioEffectList, EffectsList *videoEffectList, QString name, QStringList filtersList, QStringList producersList) -{ +void initEffects::parseEffectFile(EffectsList *audioEffectList, EffectsList *videoEffectList, QString name, QStringList filtersList, QStringList producersList) { QDomDocument doc; QFile file(name); doc.setContent(&file, false); @@ -106,309 +102,295 @@ void initEffects::parseEffectFile(EffectsList *audioEffectList, EffectsList *vid QDomNodeList effects = doc.elementsByTagName("effect"); if (effects.count() == 0) { - kDebug()<<"// EFFECT FILET: "<append(documentElement); - else videoEffectList->append(documentElement); - } - -/* - QDomNode n = documentElement.firstChild(); - QString id, effectName, effectTag, paramType; - int paramCount = 0; - EFFECTTYPE type; - - // Create Effect - EffectParamDescFactory effectDescParamFactory; - EffectDesc *effect = NULL; - - // parse effect file - QDomNode namenode = documentElement.elementsByTagName("name").item(0); - if (!namenode.isNull()) effectName = i18n(namenode.toElement().text()); - if (!groupName.isEmpty()) effectName.prepend("_" + groupName + "_"); - - QDomNode propsnode = documentElement.elementsByTagName("properties").item(0); - if (!propsnode.isNull()) { - QDomElement propselement = propsnode.toElement(); - id = propselement.attribute("id", QString::null); - effectTag = propselement.attribute("tag", QString::null); - if (propselement.attribute("type", QString::null) == "audio") type = AUDIOEFFECT; - else if (propselement.attribute("type", QString::null) == "custom") type = CUSTOMEFFECT; - else type = VIDEOEFFECT; - } - - QString effectDescription; - QDomNode descnode = documentElement.elementsByTagName("description").item(0); - if (!descnode.isNull()) effectDescription = descnode.toElement().text() + "
"; - - QString effectAuthor; - QDomNode authnode = documentElement.elementsByTagName("author").item(0); - if (!authnode.isNull()) effectAuthor = authnode.toElement().text() + "
"; - - if (effectName.isEmpty() || id.isEmpty() || effectTag.isEmpty()) return; - - effect = new EffectDesc(effectName, id, effectTag, effectDescription, effectAuthor, type); - - QDomNodeList paramList = documentElement.elementsByTagName("parameter"); - if (paramList.count() == 0) { - QDomElement fixed = doc.createElement("parameter"); - fixed.setAttribute("type", "fixed"); - effect->addParameter(effectDescParamFactory.createParameter(fixed)); - } - else for (int i = 0; i < paramList.count(); i++) { - QDomElement e = paramList.item(i).toElement(); - if (!e.isNull()) { - paramCount++; - QDomNamedNodeMap attrs = e.attributes(); - int i = 0; - QString value; - while (!attrs.item(i).isNull()) { - QDomNode n = attrs.item(i); - value = n.nodeValue(); - if (value.find("MAX_WIDTH") != -1) - value.replace("MAX_WIDTH", QString::number(KdenliveSettings::defaultwidth())); - if (value.find("MID_WIDTH") != -1) - value.replace("MID_WIDTH", QString::number(KdenliveSettings::defaultwidth() / 2)); - if (value.find("MAX_HEIGHT") != -1) - value.replace("MAX_HEIGHT", QString::number(KdenliveSettings::defaultheight())); - if (value.find("MID_HEIGHT") != -1) - value.replace("MID_HEIGHT", QString::number(KdenliveSettings::defaultheight() / 2)); - n.setNodeValue(value); - i++; - } - effect->addParameter(effectDescParamFactory.createParameter(e)); - } - } - effectList->append(effect); - }*/ - i++; + documentElement = effects.item(i).toElement(); + QString tag = documentElement.attribute("tag", QString::null); + bool ladspaOk = true; + if (tag == "ladspa") { + QString library = documentElement.attribute("library", QString::null); + if (KStandardDirs::locate("ladspa_plugin", library).isEmpty()) ladspaOk = false; + } + + // Parse effect file + if ((filtersList.contains(tag) || producersList.contains(tag)) && ladspaOk) { + bool isAudioEffect = false; + QDomNode propsnode = documentElement.elementsByTagName("properties").item(0); + if (!propsnode.isNull()) { + QDomElement propselement = propsnode.toElement(); +// id = propselement.attribute("id", QString::null); +// effectTag = propselement.attribute("tag", QString::null); + if (propselement.attribute("type", QString::null) == "audio") isAudioEffect = true; + //else if (propselement.attribute("type", QString::null) == "custom") type = CUSTOMEFFECT; + //else type = VIDEOEFFECT; + } + if (isAudioEffect) audioEffectList->append(documentElement); + else videoEffectList->append(documentElement); + } + + /* + QDomNode n = documentElement.firstChild(); + QString id, effectName, effectTag, paramType; + int paramCount = 0; + EFFECTTYPE type; + + // Create Effect + EffectParamDescFactory effectDescParamFactory; + EffectDesc *effect = NULL; + + // parse effect file + QDomNode namenode = documentElement.elementsByTagName("name").item(0); + if (!namenode.isNull()) effectName = i18n(namenode.toElement().text()); + if (!groupName.isEmpty()) effectName.prepend("_" + groupName + "_"); + + QDomNode propsnode = documentElement.elementsByTagName("properties").item(0); + if (!propsnode.isNull()) { + QDomElement propselement = propsnode.toElement(); + id = propselement.attribute("id", QString::null); + effectTag = propselement.attribute("tag", QString::null); + if (propselement.attribute("type", QString::null) == "audio") type = AUDIOEFFECT; + else if (propselement.attribute("type", QString::null) == "custom") type = CUSTOMEFFECT; + else type = VIDEOEFFECT; + } + + QString effectDescription; + QDomNode descnode = documentElement.elementsByTagName("description").item(0); + if (!descnode.isNull()) effectDescription = descnode.toElement().text() + "
"; + + QString effectAuthor; + QDomNode authnode = documentElement.elementsByTagName("author").item(0); + if (!authnode.isNull()) effectAuthor = authnode.toElement().text() + "
"; + + if (effectName.isEmpty() || id.isEmpty() || effectTag.isEmpty()) return; + + effect = new EffectDesc(effectName, id, effectTag, effectDescription, effectAuthor, type); + + QDomNodeList paramList = documentElement.elementsByTagName("parameter"); + if (paramList.count() == 0) { + QDomElement fixed = doc.createElement("parameter"); + fixed.setAttribute("type", "fixed"); + effect->addParameter(effectDescParamFactory.createParameter(fixed)); + } + else for (int i = 0; i < paramList.count(); i++) { + QDomElement e = paramList.item(i).toElement(); + if (!e.isNull()) { + paramCount++; + QDomNamedNodeMap attrs = e.attributes(); + int i = 0; + QString value; + while (!attrs.item(i).isNull()) { + QDomNode n = attrs.item(i); + value = n.nodeValue(); + if (value.find("MAX_WIDTH") != -1) + value.replace("MAX_WIDTH", QString::number(KdenliveSettings::defaultwidth())); + if (value.find("MID_WIDTH") != -1) + value.replace("MID_WIDTH", QString::number(KdenliveSettings::defaultwidth() / 2)); + if (value.find("MAX_HEIGHT") != -1) + value.replace("MAX_HEIGHT", QString::number(KdenliveSettings::defaultheight())); + if (value.find("MID_HEIGHT") != -1) + value.replace("MID_HEIGHT", QString::number(KdenliveSettings::defaultheight() / 2)); + n.setNodeValue(value); + i++; + } + effect->addParameter(effectDescParamFactory.createParameter(e)); + } + } + effectList->append(effect); + }*/ + i++; } } -//static -char* initEffects::ladspaEffectString(int ladspaId, QStringList params) -{ - if (ladspaId == 1433 ) //Pitch - return ladspaPitchEffectString(params); - else if (ladspaId == 1216 ) //Room Reverb - return ladspaRoomReverbEffectString(params); - else if (ladspaId == 1423 ) //Reverb - return ladspaReverbEffectString(params); - else if (ladspaId == 1901 ) //Reverb - return ladspaEqualizerEffectString(params); +//static +char* initEffects::ladspaEffectString(int ladspaId, QStringList params) { + if (ladspaId == 1433) //Pitch + return ladspaPitchEffectString(params); + else if (ladspaId == 1216) //Room Reverb + return ladspaRoomReverbEffectString(params); + else if (ladspaId == 1423) //Reverb + return ladspaReverbEffectString(params); + else if (ladspaId == 1901) //Reverb + return ladspaEqualizerEffectString(params); else { - kDebug()<<"++++++++++ ASKING FOR UNKNOWN LADSPA EFFECT: "<"); + kDebug() << "++++++++++ ASKING FOR UNKNOWN LADSPA EFFECT: " << ladspaId << endl; + return(""); } } -//static -void initEffects::ladspaEffectFile(const QString & fname, int ladspaId, QStringList params) -{ +//static +void initEffects::ladspaEffectFile(const QString & fname, int ladspaId, QStringList params) { char *filterString; switch (ladspaId) { case 1433: //Pitch - filterString = ladspaPitchEffectString(params); - break; + filterString = ladspaPitchEffectString(params); + break; case 1905: //Vinyl - filterString = ladspaVinylEffectString(params); - break; + filterString = ladspaVinylEffectString(params); + break; case 1216 : //Room Reverb - filterString = ladspaRoomReverbEffectString(params); - break; + filterString = ladspaRoomReverbEffectString(params); + break; case 1423: //Reverb - filterString = ladspaReverbEffectString(params); - break; + filterString = ladspaReverbEffectString(params); + break; case 1195: //Declipper - filterString = ladspaDeclipEffectString(params); - break; + filterString = ladspaDeclipEffectString(params); + break; case 1901: //Reverb - filterString = ladspaEqualizerEffectString(params); - break; + filterString = ladspaEqualizerEffectString(params); + break; case 1913: // Limiter - filterString = ladspaLimiterEffectString(params); - break; + filterString = ladspaLimiterEffectString(params); + break; case 1193: // Pitch Shifter - filterString = ladspaPitchShifterEffectString(params); - break; + filterString = ladspaPitchShifterEffectString(params); + break; case 1417: // Rate Scaler - filterString = ladspaRateScalerEffectString(params); - break; + filterString = ladspaRateScalerEffectString(params); + break; case 1217: // Phaser - filterString = ladspaPhaserEffectString(params); - break; - default: - kDebug()<<"++++++++++ ASKING FOR UNKNOWN LADSPA EFFECT: "<248000"; -char* initEffects::ladspaDeclipEffectString(QStringList) -{ - return qstrdup(QString(jackString + "1195truefalsetrue1.0000001.000000true").toUtf8()); +char* initEffects::ladspaDeclipEffectString(QStringList) { + return qstrdup(QString(jackString + "1195truefalsetrue1.0000001.000000true").toUtf8()); } /* char* initEffects::ladspaVocoderEffectString(QStringList params) { - return qstrdup( QString(jackString + "1441truefalsetrue1.0000001.000000truetrue0.0000000.000000true%1%1true%1%1true%1%1true%1%1true%2%2true%2%2true%2%2true%2%2true%3%3true%3%3true%3%3true%3%3true%4%4true%4%4true%4%4true%4%4").arg(params[0]).arg(params[1]).arg(params[2]).arg(params[3])); + return qstrdup( QString(jackString + "1441truefalsetrue1.0000001.000000truetrue0.0000000.000000true%1%1true%1%1true%1%1true%1%1true%2%2true%2%2true%2%2true%2%2true%3%3true%3%3true%3%3true%3%3true%4%4true%4%4true%4%4true%4%4").arg(params[0]).arg(params[1]).arg(params[2]).arg(params[3])); }*/ -char* initEffects::ladspaVinylEffectString(QStringList params) -{ - return qstrdup( QString(jackString + "1905truefalsetrue1.0000001.000000%1%2%3%4%5").arg(params[0]).arg(params[1]).arg(params[2]).arg(params[3]).arg(params[4]).toUtf8()); +char* initEffects::ladspaVinylEffectString(QStringList params) { + return qstrdup(QString(jackString + "1905truefalsetrue1.0000001.000000%1%2%3%4%5").arg(params[0]).arg(params[1]).arg(params[2]).arg(params[3]).arg(params[4]).toUtf8()); } -char* initEffects::ladspaPitchEffectString(QStringList params) -{ - return qstrdup( QString(jackString + "1433truefalsetrue1.01.0truetrue%1%1true4.0000004.000000").arg(params[0]).toUtf8()); +char* initEffects::ladspaPitchEffectString(QStringList params) { + return qstrdup(QString(jackString + "1433truefalsetrue1.01.0truetrue%1%1true4.0000004.000000").arg(params[0]).toUtf8()); } -char* initEffects::ladspaRoomReverbEffectString(QStringList params) -{ - return qstrdup( QString(jackString + "1216truefalsetrue1.0000001.000000truetrue%1%1true%2%2true%3%3true0.7500000.750000true-70.000000-70.000000true0.0000000.000000true-17.500000-17.500000").arg(params[0]).arg(params[1]).arg(params[2]).toUtf8()); +char* initEffects::ladspaRoomReverbEffectString(QStringList params) { + return qstrdup(QString(jackString + "1216truefalsetrue1.0000001.000000truetrue%1%1true%2%2true%3%3true0.7500000.750000true-70.000000-70.000000true0.0000000.000000true-17.500000-17.500000").arg(params[0]).arg(params[1]).arg(params[2]).toUtf8()); } -char* initEffects::ladspaReverbEffectString(QStringList params) -{ - return qstrdup( QString(jackString + "1423true falsetrue 1.0000001.000000 truetrue%1 %1true%2%2true0.2500000.250000").arg(params[0]).arg(params[1]).toUtf8()); +char* initEffects::ladspaReverbEffectString(QStringList params) { + return qstrdup(QString(jackString + "1423true falsetrue 1.0000001.000000 truetrue%1 %1true%2%2true0.2500000.250000").arg(params[0]).arg(params[1]).toUtf8()); } -char* initEffects::ladspaEqualizerEffectString(QStringList params) -{ - return qstrdup( QString(jackString + "1901true falsetrue 1.0000001.000000%1%2 %3").arg(params[0]).arg(params[1]).arg(params[2]).toUtf8()); +char* initEffects::ladspaEqualizerEffectString(QStringList params) { + return qstrdup(QString(jackString + "1901true falsetrue 1.0000001.000000%1%2 %3").arg(params[0]).arg(params[1]).arg(params[2]).toUtf8()); } -char* initEffects::ladspaLimiterEffectString(QStringList params) -{ - return qstrdup( QString(jackString + "1913truefalsetrue1.0000001.000000%1%2%3").arg(params[0]).arg(params[1]).arg(params[2]).toUtf8()); +char* initEffects::ladspaLimiterEffectString(QStringList params) { + return qstrdup(QString(jackString + "1913truefalsetrue1.0000001.000000%1%2%3").arg(params[0]).arg(params[1]).arg(params[2]).toUtf8()); } -char* initEffects::ladspaPitchShifterEffectString(QStringList params) -{ - return qstrdup( QString(jackString + "1193truefalsetrue1.0000001.000000truetrue%1%1").arg(params[0]).toUtf8()); +char* initEffects::ladspaPitchShifterEffectString(QStringList params) { + return qstrdup(QString(jackString + "1193truefalsetrue1.0000001.000000truetrue%1%1").arg(params[0]).toUtf8()); } -char* initEffects::ladspaRateScalerEffectString(QStringList params) -{ - return qstrdup( QString(jackString + "1417truefalsetrue1.0000001.000000truetrue%1%1").arg(params[0]).toUtf8()); +char* initEffects::ladspaRateScalerEffectString(QStringList params) { + return qstrdup(QString(jackString + "1417truefalsetrue1.0000001.000000truetrue%1%1").arg(params[0]).toUtf8()); } -char* initEffects::ladspaPhaserEffectString(QStringList params) -{ - return qstrdup( QString(jackString + "1217truefalsetrue1.0000001.000000truetrue%1%1true%2%2true%3%3true%4%4").arg(params[0]).arg(params[1]).arg(params[2]).arg(params[3]).toUtf8()); +char* initEffects::ladspaPhaserEffectString(QStringList params) { + return qstrdup(QString(jackString + "1217truefalsetrue1.0000001.000000truetrue%1%1true%2%2true%3%3true%4%4").arg(params[0]).arg(params[1]).arg(params[2]).arg(params[3]).toUtf8()); } -QDomDocument initEffects::createDescriptionFromMlt(Mlt::Repository* repository, const QString& type, const QString& filtername){ - - QDomDocument ret; - Mlt::Properties *metadata=repository->metadata(filter_type,filtername.toAscii().data()); - kDebug() << filtername; - if (metadata && metadata->is_valid()){ - if (metadata->get("title") && metadata->get("identifier")){ - QDomElement eff=ret.createElement("effect"); - eff.setAttribute("tag",metadata->get("identifier")); - - QDomElement name=ret.createElement("name"); - name.appendChild(ret.createTextNode(metadata->get("title"))); - - QDomElement desc=ret.createElement("description"); - desc.appendChild(ret.createTextNode(metadata->get("description"))); - - QDomElement author=ret.createElement("author"); - author.appendChild(ret.createTextNode(metadata->get("creator"))); - - QDomElement prop=ret.createElement("properties"); - prop.setAttribute("id",metadata->get("identifier")); - prop.setAttribute("tag",metadata->get("identifier")); - eff.appendChild(name); - eff.appendChild(author); - eff.appendChild(desc); - eff.appendChild(prop); - - Mlt::Properties param_props( (mlt_properties) metadata->get_data("parameters") ); - for (int j=0; param_props.is_valid() && jmetadata(filter_type, filtername.toAscii().data()); + kDebug() << filtername; + if (metadata && metadata->is_valid()) { + if (metadata->get("title") && metadata->get("identifier")) { + QDomElement eff = ret.createElement("effect"); + eff.setAttribute("tag", metadata->get("identifier")); + + QDomElement name = ret.createElement("name"); + name.appendChild(ret.createTextNode(metadata->get("title"))); + + QDomElement desc = ret.createElement("description"); + desc.appendChild(ret.createTextNode(metadata->get("description"))); + + QDomElement author = ret.createElement("author"); + author.appendChild(ret.createTextNode(metadata->get("creator"))); + + QDomElement prop = ret.createElement("properties"); + prop.setAttribute("id", metadata->get("identifier")); + prop.setAttribute("tag", metadata->get("identifier")); + eff.appendChild(name); + eff.appendChild(author); + eff.appendChild(desc); + eff.appendChild(prop); + + Mlt::Properties param_props((mlt_properties) metadata->get_data("parameters")); + for (int j = 0; param_props.is_valid() && j < param_props.count();j++) { + QDomElement params = ret.createElement("parameter"); + + Mlt::Properties paramdesc((mlt_properties) param_props.get_data(param_props.get_name(j))); + + params.setAttribute("name", paramdesc.get("identifier")); + + if (paramdesc.get("maximum")) params.setAttribute("max", paramdesc.get("maximum")); + if (paramdesc.get("minimum")) params.setAttribute("min", paramdesc.get("minimum")); + if (QString(paramdesc.get("type")) == "integer") + params.setAttribute("type", "constant"); + if (QString(paramdesc.get("type")) == "boolean") + params.setAttribute("type", "bool"); + if (!QString(paramdesc.get("format")).isEmpty()) { + params.setAttribute("type", "complex"); + params.setAttribute("format", paramdesc.get("format")); + } + if (paramdesc.get("default")) params.setAttribute("default", paramdesc.get("default")); + if (paramdesc.get("value")) { + params.setAttribute("value", paramdesc.get("value")); + } else { + params.setAttribute("value", paramdesc.get("default")); + } + + + QDomElement pname = ret.createElement("name"); + pname.appendChild(ret.createTextNode(paramdesc.get("title"))); + params.appendChild(pname); + + eff.appendChild(params); + } + ret.appendChild(eff); + } + } + QString outstr; + QTextStream str(&outstr); + ret.save(str, 2); + kDebug() << outstr; + return ret; } diff --git a/src/initeffects.h b/src/initeffects.h index d7dc82ac..f2946a37 100644 --- a/src/initeffects.h +++ b/src/initeffects.h @@ -29,29 +29,28 @@ *@author Jean-Baptiste Mardelle */ -class initEffects -{ - public: - initEffects(); - ~initEffects(); - - static Mlt::Repository *parseEffectFiles(EffectsList *audioEffectList, EffectsList *videoEffectList); - static QDomDocument createDescriptionFromMlt(Mlt::Repository* repository,const QString& type, const QString& name); - static void parseEffectFile(EffectsList *audioEffectList, EffectsList *videoEffectList, QString name, QStringList filtersList, QStringList producersList); - static char* ladspaEffectString(int ladspaId, QStringList params); - static void ladspaEffectFile(const QString & fname, int ladspaId, QStringList params); - - static char* ladspaPitchEffectString(QStringList params); - static char* ladspaReverbEffectString(QStringList params); - static char* ladspaRoomReverbEffectString(QStringList params); - static char* ladspaEqualizerEffectString(QStringList params); - static char* ladspaDeclipEffectString(QStringList); - static char* ladspaVinylEffectString(QStringList params); - static char* ladspaLimiterEffectString(QStringList params); - static char* ladspaPitchShifterEffectString(QStringList params); - static char* ladspaPhaserEffectString(QStringList params); - static char* ladspaRateScalerEffectString(QStringList params); +class initEffects { +public: + initEffects(); + ~initEffects(); + + static Mlt::Repository *parseEffectFiles(EffectsList *audioEffectList, EffectsList *videoEffectList); + static QDomDocument createDescriptionFromMlt(Mlt::Repository* repository, const QString& type, const QString& name); + static void parseEffectFile(EffectsList *audioEffectList, EffectsList *videoEffectList, QString name, QStringList filtersList, QStringList producersList); + static char* ladspaEffectString(int ladspaId, QStringList params); + static void ladspaEffectFile(const QString & fname, int ladspaId, QStringList params); + + static char* ladspaPitchEffectString(QStringList params); + static char* ladspaReverbEffectString(QStringList params); + static char* ladspaRoomReverbEffectString(QStringList params); + static char* ladspaEqualizerEffectString(QStringList params); + static char* ladspaDeclipEffectString(QStringList); + static char* ladspaVinylEffectString(QStringList params); + static char* ladspaLimiterEffectString(QStringList params); + static char* ladspaPitchShifterEffectString(QStringList params); + static char* ladspaPhaserEffectString(QStringList params); + static char* ladspaRateScalerEffectString(QStringList params); }; - + #endif diff --git a/src/kdenlivedoc.cpp b/src/kdenlivedoc.cpp index 49aabf69..72da0645 100644 --- a/src/kdenlivedoc.cpp +++ b/src/kdenlivedoc.cpp @@ -28,285 +28,250 @@ #include "kdenlivedoc.h" #include "docclipbase.h" -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()) -{ - m_clipManager = new ClipManager(this); - if (!url.isEmpty()) { - QString tmpFile; - if(KIO::NetAccess::download(url.path(), tmpFile, parent)) - { - QFile file(tmpFile); - m_document.setContent(&file, false); - file.close(); - m_projectName = url.fileName(); - KIO::NetAccess::removeTempFile(tmpFile); - } - else - { - KMessageBox::error(parent, KIO::NetAccess::lastErrorString()); - } - } - else { - // Creating new document - QDomElement westley = m_document.createElement("westley"); - m_document.appendChild(westley); - QDomElement doc = m_document.createElement("kdenlivedoc"); - doc.setAttribute("version", "0.6"); - westley.appendChild(doc); - QDomElement props = m_document.createElement("properties"); - doc.setAttribute("width", m_width); - doc.setAttribute("height", m_height); - doc.setAttribute("projectfps", m_fps); - doc.appendChild(props); - - - /*QDomElement westley = m_document.createElement("westley"); - m_document.appendChild(westley);*/ - - - QDomElement tractor = m_document.createElement("tractor"); - QDomElement multitrack = m_document.createElement("multitrack"); - QDomElement playlist = m_document.createElement("playlist"); - QDomElement producer = m_document.createElement("producer"); - /*producer.setAttribute("mlt_service", "colour"); - producer.setAttribute("colour", "red"); - playlist.appendChild(producer);*/ - multitrack.appendChild(playlist); - QDomElement playlist1 = m_document.createElement("playlist"); - playlist1.setAttribute("id", "playlist1"); - playlist1.setAttribute("hide", "video"); - multitrack.appendChild(playlist1); - QDomElement playlist2 = m_document.createElement("playlist"); - playlist2.setAttribute("id", "playlist2"); - playlist2.setAttribute("hide", "video"); - multitrack.appendChild(playlist2); - QDomElement playlist3 = m_document.createElement("playlist"); - multitrack.appendChild(playlist3); - playlist3.setAttribute("id", "playlist3"); - QDomElement playlist4 = m_document.createElement("playlist"); - multitrack.appendChild(playlist4); - playlist4.setAttribute("id", "playlist4"); - QDomElement playlist5 = m_document.createElement("playlist"); - multitrack.appendChild(playlist5); - playlist5.setAttribute("id", "playlist5"); - tractor.appendChild(multitrack); - - for (uint i = 2; i < 6 ; i++) { - QDomElement transition = m_document.createElement("transition"); - transition.setAttribute("in", "0"); - //TODO: Make audio mix last for all project duration - transition.setAttribute("out", "15000"); - transition.setAttribute("a_track", QString::number(1)); - transition.setAttribute("b_track", QString::number(i)); - transition.setAttribute("mlt_service", "mix"); - transition.setAttribute("combine", "1"); - tractor.appendChild(transition); - } +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()) { + m_clipManager = new ClipManager(this); + if (!url.isEmpty()) { + QString tmpFile; + if (KIO::NetAccess::download(url.path(), tmpFile, parent)) { + QFile file(tmpFile); + m_document.setContent(&file, false); + file.close(); + m_projectName = url.fileName(); + KIO::NetAccess::removeTempFile(tmpFile); + } else { + KMessageBox::error(parent, KIO::NetAccess::lastErrorString()); + } + } else { + // Creating new document + QDomElement westley = m_document.createElement("westley"); + m_document.appendChild(westley); + QDomElement doc = m_document.createElement("kdenlivedoc"); + doc.setAttribute("version", "0.6"); + westley.appendChild(doc); + QDomElement props = m_document.createElement("properties"); + doc.setAttribute("width", m_width); + doc.setAttribute("height", m_height); + doc.setAttribute("projectfps", m_fps); + doc.appendChild(props); + + + /*QDomElement westley = m_document.createElement("westley"); + m_document.appendChild(westley);*/ + + + QDomElement tractor = m_document.createElement("tractor"); + QDomElement multitrack = m_document.createElement("multitrack"); + QDomElement playlist = m_document.createElement("playlist"); + QDomElement producer = m_document.createElement("producer"); + /*producer.setAttribute("mlt_service", "colour"); + producer.setAttribute("colour", "red"); + playlist.appendChild(producer);*/ + multitrack.appendChild(playlist); + QDomElement playlist1 = m_document.createElement("playlist"); + playlist1.setAttribute("id", "playlist1"); + playlist1.setAttribute("hide", "video"); + multitrack.appendChild(playlist1); + QDomElement playlist2 = m_document.createElement("playlist"); + playlist2.setAttribute("id", "playlist2"); + playlist2.setAttribute("hide", "video"); + multitrack.appendChild(playlist2); + QDomElement playlist3 = m_document.createElement("playlist"); + multitrack.appendChild(playlist3); + playlist3.setAttribute("id", "playlist3"); + QDomElement playlist4 = m_document.createElement("playlist"); + multitrack.appendChild(playlist4); + playlist4.setAttribute("id", "playlist4"); + QDomElement playlist5 = m_document.createElement("playlist"); + multitrack.appendChild(playlist5); + playlist5.setAttribute("id", "playlist5"); + tractor.appendChild(multitrack); + + for (uint i = 2; i < 6 ; i++) { + QDomElement transition = m_document.createElement("transition"); + transition.setAttribute("in", "0"); + //TODO: Make audio mix last for all project duration + transition.setAttribute("out", "15000"); + transition.setAttribute("a_track", QString::number(1)); + transition.setAttribute("b_track", QString::number(i)); + transition.setAttribute("mlt_service", "mix"); + transition.setAttribute("combine", "1"); + tractor.appendChild(transition); + } + + doc.appendChild(tractor); - doc.appendChild(tractor); - - } - if (fps == 30000.0 / 1001.0 ) m_timecode.setFormat(30, true); + } + if (fps == 30000.0 / 1001.0) m_timecode.setFormat(30, true); else m_timecode.setFormat((int) fps); } -KdenliveDoc::~KdenliveDoc() -{ - delete m_commandStack; - delete m_clipManager; +KdenliveDoc::~KdenliveDoc() { + delete m_commandStack; + delete m_clipManager; } -ClipManager *KdenliveDoc::clipManager() -{ - return m_clipManager; +ClipManager *KdenliveDoc::clipManager() { + return m_clipManager; } -void KdenliveDoc::setThumbsProgress(KUrl url, int progress) -{ - emit thumbsProgress(url, progress); +void KdenliveDoc::setThumbsProgress(KUrl url, int progress) { + emit thumbsProgress(url, progress); } -KUndoStack *KdenliveDoc::commandStack() -{ - return m_commandStack; +KUndoStack *KdenliveDoc::commandStack() { + return m_commandStack; } -void KdenliveDoc::setRenderer(Render *render) -{ - m_render = render; - if (m_render) m_render->setSceneList(m_document); +void KdenliveDoc::setRenderer(Render *render) { + m_render = render; + if (m_render) m_render->setSceneList(m_document); } -Render *KdenliveDoc::renderer() -{ - return m_render; +Render *KdenliveDoc::renderer() { + return m_render; } -void KdenliveDoc::updateClip(int id) -{ - emit updateClipDisplay(id); +void KdenliveDoc::updateClip(int id) { + emit updateClipDisplay(id); } -int KdenliveDoc::getFramePos(QString duration) -{ - return m_timecode.getFrameCount(duration, m_fps); +int KdenliveDoc::getFramePos(QString duration) { + return m_timecode.getFrameCount(duration, m_fps); } -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; +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; + return result; } -void KdenliveDoc::setProducerDuration(int id, int duration) -{ - 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) { - e.setAttribute("duration", QString::number(duration)); - break; +void KdenliveDoc::setProducerDuration(int id, int duration) { + 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) { + e.setAttribute("duration", QString::number(duration)); + break; + } } - } } -int KdenliveDoc::getProducerDuration(int id) -{ - int result = 0; - 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("duration").toInt(); - break; +int KdenliveDoc::getProducerDuration(int id) { + int result = 0; + 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("duration").toInt(); + break; + } } - } - return result; + return result; } -QDomDocument KdenliveDoc::generateSceneList() -{ +QDomDocument KdenliveDoc::generateSceneList() { QDomDocument doc; QDomElement westley = doc.createElement("westley"); doc.appendChild(westley); QDomElement prod = doc.createElement("producer"); } -QDomDocument KdenliveDoc::toXml() -{ - return m_document; +QDomDocument KdenliveDoc::toXml() { + return m_document; } -Timecode KdenliveDoc::timecode() -{ - return m_timecode; +Timecode KdenliveDoc::timecode() { + return m_timecode; } -QString KdenliveDoc::documentName() -{ - return m_projectName; +QString KdenliveDoc::documentName() { + return m_projectName; } -QDomNodeList KdenliveDoc::producersList() -{ - return m_document.elementsByTagName("producer"); +QDomNodeList KdenliveDoc::producersList() { + return m_document.elementsByTagName("producer"); } -void KdenliveDoc::setProducers(QDomElement doc) -{ - QDomNode kdenlivedocument = m_document.elementsByTagName("kdenlivedoc").item(0); - - QDomNodeList list = m_document.elementsByTagName("producer"); - int ct = list.count(); - kDebug()<<"DELETING CHILD PRODUCERS: "< 0; i--) { - kdenlivedocument.removeChild(list.item(i)); - } - - QDomNode n = doc.firstChild(); - ct = 0; - while(!n.isNull()) { - QDomElement e = n.toElement(); // try to convert the node to an element. - if(!e.isNull() && e.tagName() == "producer") { - kdenlivedocument.appendChild(m_document.importNode(e, true)); - ct++; - } - n = n.nextSibling(); - } - kDebug()<<"ADDING CHILD PRODS: "< 0; i--) { + kdenlivedocument.removeChild(list.item(i)); + } + + QDomNode n = doc.firstChild(); + ct = 0; + while (!n.isNull()) { + QDomElement e = n.toElement(); // try to convert the node to an element. + if (!e.isNull() && e.tagName() == "producer") { + kdenlivedocument.appendChild(m_document.importNode(e, true)); + ct++; + } + n = n.nextSibling(); + } + kDebug() << "ADDING CHILD PRODS: " << ct << "\n"; + //kDebug()<addClip(clip); - emit addProjectClip(clip); +void KdenliveDoc::addClip(const QDomElement &elem, const int clipId) { + kDebug() << "///////// DOCUM, CREATING NEW CLIP, ID:" << clipId; + DocClipBase *clip = new DocClipBase(m_clipManager, elem, clipId); + m_clipManager->addClip(clip); + emit addProjectClip(clip); } -void KdenliveDoc::deleteProjectClip(const uint clipId) -{ - emit deletTimelineClip(clipId); - m_clipManager->slotDeleteClip(clipId); +void KdenliveDoc::deleteProjectClip(const uint clipId) { + emit deletTimelineClip(clipId); + m_clipManager->slotDeleteClip(clipId); } -void KdenliveDoc::deleteClip(const uint clipId) -{ - emit signalDeleteProjectClip(clipId); - m_clipManager->deleteClip(clipId); +void KdenliveDoc::deleteClip(const uint clipId) { + emit signalDeleteProjectClip(clipId); + m_clipManager->deleteClip(clipId); } -void KdenliveDoc::slotAddClipFile(const KUrl url, const QString group) -{ - kDebug()<<"///////// DOCUM, ADD CLP: "<slotAddClipFile(url, group); +void KdenliveDoc::slotAddClipFile(const KUrl url, const QString group) { + kDebug() << "///////// DOCUM, ADD CLP: " << url; + m_clipManager->slotAddClipFile(url, group); } -DocClipBase *KdenliveDoc::getBaseClip(int clipId) -{ - return m_clipManager->getClipById(clipId); +DocClipBase *KdenliveDoc::getBaseClip(int clipId) { + return m_clipManager->getClipById(clipId); } -void KdenliveDoc::slotAddColorClipFile(const QString name, const QString color, QString duration, const QString group) -{ - m_clipManager->slotAddColorClipFile(name, color, duration, group); +void KdenliveDoc::slotAddColorClipFile(const QString name, const QString color, QString duration, const QString group) { + m_clipManager->slotAddColorClipFile(name, color, duration, group); } #include "kdenlivedoc.moc" diff --git a/src/kdenlivedoc.h b/src/kdenlivedoc.h index b62aebe4..4eb8f5ed 100644 --- a/src/kdenlivedoc.h +++ b/src/kdenlivedoc.h @@ -35,8 +35,8 @@ #include "renderer.h" #include "clipmanager.h" -class KdenliveDoc:public QObject { - Q_OBJECT public: +class KdenliveDoc: public QObject { +Q_OBJECT public: KdenliveDoc(const KUrl &url, double fps, int width, int height, QWidget *parent = 0); ~KdenliveDoc(); @@ -67,7 +67,7 @@ class KdenliveDoc:public QObject { /** Inform application of the audio thumbnails generation progress */ void setThumbsProgress(KUrl url, int progress); - private: +private: KUrl m_url; QDomDocument m_document; QString m_projectName; @@ -80,9 +80,9 @@ class KdenliveDoc:public QObject { QDomDocument generateSceneList(); ClipManager *m_clipManager; - public slots: - - signals: +public slots: + +signals: void addProjectClip(DocClipBase *); void signalDeleteProjectClip(int); void updateClipDisplay(int); diff --git a/src/kdenlivesettingsdialog.cpp b/src/kdenlivesettingsdialog.cpp index 4be8b9ab..4e1871d9 100644 --- a/src/kdenlivesettingsdialog.cpp +++ b/src/kdenlivesettingsdialog.cpp @@ -26,56 +26,52 @@ #include "kdenlivesettings.h" #include "kdenlivesettingsdialog.h" -KdenliveSettingsDialog::KdenliveSettingsDialog(QWidget * parent): KConfigDialog(parent, "settings", KdenliveSettings::self()) -{ - - QWidget *p1 = new QWidget; - m_configMisc.setupUi(p1); - page1 = addPage( p1, i18n("Misc"), "misc" ); - - QWidget *p3 = new QWidget; - m_configDisplay.setupUi(p3); - page3 = addPage( p3, i18n("Display"), "display" ); - - QWidget *p2 = new QWidget; - m_configEnv.setupUi(p2); - m_configEnv.mltpathurl->setMode(KFile::Directory); - m_configEnv.mltpathurl->lineEdit()->setObjectName("kcfg_mltpath"); - m_configEnv.rendererpathurl->lineEdit()->setObjectName("kcfg_rendererpath"); - m_configEnv.tmppathurl->setMode(KFile::Directory); - m_configEnv.tmppathurl->lineEdit()->setObjectName("kcfg_currenttmpfolder"); - page2 = addPage( p2, i18n("Environnement"), "env" ); - - QStringList profilesNames = ProfilesDialog::getProfileNames(); - m_configMisc.profiles_list->addItems(profilesNames); - m_defaulfProfile = ProfilesDialog::getSettingsFromFile(KdenliveSettings::default_profile()).value("description"); - if (profilesNames.contains(m_defaulfProfile)) m_configMisc.profiles_list->setCurrentItem(m_defaulfProfile); - - slotUpdateDisplay(); - connect(m_configMisc.profiles_list, SIGNAL(currentIndexChanged( int )), this, SLOT(slotUpdateDisplay())); +KdenliveSettingsDialog::KdenliveSettingsDialog(QWidget * parent): KConfigDialog(parent, "settings", KdenliveSettings::self()) { + + QWidget *p1 = new QWidget; + m_configMisc.setupUi(p1); + page1 = addPage(p1, i18n("Misc"), "misc"); + + QWidget *p3 = new QWidget; + m_configDisplay.setupUi(p3); + page3 = addPage(p3, i18n("Display"), "display"); + + QWidget *p2 = new QWidget; + m_configEnv.setupUi(p2); + m_configEnv.mltpathurl->setMode(KFile::Directory); + m_configEnv.mltpathurl->lineEdit()->setObjectName("kcfg_mltpath"); + m_configEnv.rendererpathurl->lineEdit()->setObjectName("kcfg_rendererpath"); + m_configEnv.tmppathurl->setMode(KFile::Directory); + m_configEnv.tmppathurl->lineEdit()->setObjectName("kcfg_currenttmpfolder"); + page2 = addPage(p2, i18n("Environnement"), "env"); + + QStringList profilesNames = ProfilesDialog::getProfileNames(); + m_configMisc.profiles_list->addItems(profilesNames); + m_defaulfProfile = ProfilesDialog::getSettingsFromFile(KdenliveSettings::default_profile()).value("description"); + if (profilesNames.contains(m_defaulfProfile)) m_configMisc.profiles_list->setCurrentItem(m_defaulfProfile); + + slotUpdateDisplay(); + connect(m_configMisc.profiles_list, SIGNAL(currentIndexChanged(int)), this, SLOT(slotUpdateDisplay())); } -KdenliveSettingsDialog::~KdenliveSettingsDialog() -{} +KdenliveSettingsDialog::~KdenliveSettingsDialog() {} -bool KdenliveSettingsDialog::hasChanged() -{ - kDebug()<<"// // // KCONFIG hasChanged called"; - if (m_configMisc.profiles_list->currentText() != m_defaulfProfile) return true; - return KConfigDialog::hasChanged(); +bool KdenliveSettingsDialog::hasChanged() { + kDebug() << "// // // KCONFIG hasChanged called"; + if (m_configMisc.profiles_list->currentText() != m_defaulfProfile) return true; + return KConfigDialog::hasChanged(); } -void KdenliveSettingsDialog::slotUpdateDisplay() -{ - QString currentProfile = m_configMisc.profiles_list->currentText(); - QMap< QString, QString > values = ProfilesDialog::getSettingsForProfile(currentProfile); - m_configMisc.p_size->setText(values.value("width") + "x" + values.value("height")); - m_configMisc.p_fps->setText(values.value("frame_rate_num") + "/" + values.value("frame_rate_den")); - m_configMisc.p_aspect->setText(values.value("sample_aspect_num") + "/" + values.value("sample_aspect_den")); - m_configMisc.p_display->setText(values.value("display_aspect_num") + "/" + values.value("display_aspect_den")); - if (values.value("progressive").toInt() == 0) m_configMisc.p_progressive->setText(i18n("Interlaced")); - else m_configMisc.p_progressive->setText(i18n("Progressive")); +void KdenliveSettingsDialog::slotUpdateDisplay() { + QString currentProfile = m_configMisc.profiles_list->currentText(); + QMap< QString, QString > values = ProfilesDialog::getSettingsForProfile(currentProfile); + m_configMisc.p_size->setText(values.value("width") + "x" + values.value("height")); + m_configMisc.p_fps->setText(values.value("frame_rate_num") + "/" + values.value("frame_rate_den")); + m_configMisc.p_aspect->setText(values.value("sample_aspect_num") + "/" + values.value("sample_aspect_den")); + m_configMisc.p_display->setText(values.value("display_aspect_num") + "/" + values.value("display_aspect_den")); + if (values.value("progressive").toInt() == 0) m_configMisc.p_progressive->setText(i18n("Interlaced")); + else m_configMisc.p_progressive->setText(i18n("Progressive")); } diff --git a/src/kdenlivesettingsdialog.h b/src/kdenlivesettingsdialog.h index b9b0d463..44bc590e 100644 --- a/src/kdenlivesettingsdialog.h +++ b/src/kdenlivesettingsdialog.h @@ -29,21 +29,20 @@ #include "ui_configenv_ui.h" #include "ui_configdisplay_ui.h" -class KdenliveSettingsDialog : public KConfigDialog -{ - Q_OBJECT - - public: +class KdenliveSettingsDialog : public KConfigDialog { + Q_OBJECT + +public: KdenliveSettingsDialog(QWidget * parent = 0); ~KdenliveSettingsDialog(); - protected: +protected: virtual bool hasChanged(); - private slots: +private slots: void slotUpdateDisplay(); - private: +private: KPageWidgetItem *page1; KPageWidgetItem *page2; KPageWidgetItem *page3; @@ -55,7 +54,7 @@ class KdenliveSettingsDialog : public KConfigDialog bool m_isCustomProfile; QString m_defaulfProfile; - signals: +signals: void customChanged(); }; diff --git a/src/kthumb.cpp b/src/kthumb.cpp index 2358fc7f..50593bd5 100644 --- a/src/kthumb.cpp +++ b/src/kthumb.cpp @@ -4,7 +4,7 @@ begin : Fri Nov 22 2002 copyright : (C) 2002 by Jason Wood email : jasonwood@blueyonder.co.uk - copyright : (C) 2005 Lcio Fl�io Corr� + copyright : (C) 2005 Lcio Fl�io Corr� email : lucio.correa@gmail.com copyright : (C) Marco Gittler email : g.marco@freenet.de @@ -44,94 +44,90 @@ #include "kdenlivesettings.h" #include "events.h" -void MyThread::init(QObject *parent, KUrl url, QString target, double frame, double frameLength, int frequency, int channels, int arrayWidth) - { - stop_me = false; - m_parent = parent; - m_isWorking = false; - f.setFileName(target); - m_url = url; - m_frame = frame; - m_frameLength = frameLength; - m_frequency = frequency; - m_channels = channels; - m_arrayWidth = arrayWidth; - } +void MyThread::init(QObject *parent, KUrl url, QString target, double frame, double frameLength, int frequency, int channels, int arrayWidth) { + stop_me = false; + m_parent = parent; + m_isWorking = false; + f.setFileName(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() { - bool MyThread::isWorking() - { - return m_isWorking; + if (!f.open(QIODevice::WriteOnly)) { + kDebug() << "++++++++ ERROR WRITING TO FILE: " << f.fileName() << endl; + kDebug() << "++++++++ DISABLING AUDIO THUMBS" << endl; + //TODO KdenliveSettings::setAudiothumbnails(false); + return; } + m_isWorking = true; + Mlt::Profile prof((char*) qstrdup(KdenliveSettings::current_profile().toUtf8())); + Mlt::Producer m_producer(prof, m_url.path().toUtf8().data()); + + + /*TODO if (KdenliveSettings::normaliseaudiothumbs()) { + Mlt::Filter m_convert(prof,"volume"); + m_convert.set("gain", "normalise"); + m_producer.attach(m_convert); + }*/ + + //QApplication::postEvent(m_parent, new ProgressEvent(-1, (QEvent::Type)10005)); + + int last_val = 0; + int val = 0; + kDebug() << "for " << m_frame << " " << m_frameLength << " " << m_producer.is_valid(); + 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(m_parent, new ProgressEvent(val, (QEvent::Type)10005)); + + last_val = val; + } + m_producer.seek(z); + Mlt::Frame *mlt_frame = m_producer.get_frame(); + if (mlt_frame && 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_array.resize(m_arrayWidth); + for (uint i = 0; i < m_array.size(); i++) { + m_array[i] = ((*(m_pcm + c + i * m_samples / m_array.size())) >> 9) + 127 / 2 ; + } + f.write(m_array); + + } + } else { + f.write(QByteArray(m_arrayWidth, '\x00')); + } + if (mlt_frame) + delete mlt_frame; + } + kDebug() << "done"; + f.close(); + m_isWorking = false; + if (stop_me) { + f.remove(); + QApplication::postEvent(m_parent, new ProgressEvent(-1, (QEvent::Type)10005)); - void MyThread::run() - { - - if (!f.open( QIODevice::WriteOnly )) { - kDebug()<<"++++++++ ERROR WRITING TO FILE: "< 1){ - QApplication::postEvent(m_parent, new ProgressEvent(val, (QEvent::Type)10005)); - - last_val=val; - } - m_producer.seek( z ); - Mlt::Frame *mlt_frame = m_producer.get_frame(); - if ( mlt_frame && 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_array.resize(m_arrayWidth); - for (uint i = 0; i < m_array.size(); i++){ - m_array[i] = ( (*( m_pcm + c + i * m_samples / m_array.size() )) >> 9 ) +127/2 ; - } - f.write(m_array); - - } - } else{ - f.write(QByteArray(m_arrayWidth,'\x00')); - } - if (mlt_frame) - delete mlt_frame; - } - kDebug() << "done"; - f.close(); - m_isWorking = false; - if (stop_me) { - f.remove(); - QApplication::postEvent(m_parent, new ProgressEvent(-1, (QEvent::Type)10005)); - - } - QApplication::postEvent(m_parent, new ProgressEvent(0, (QEvent::Type)10005)); - } + QApplication::postEvent(m_parent, new ProgressEvent(0, (QEvent::Type)10005)); + +} #define _S(a) (a)>255 ? 255 : (a)<0 ? 0 : (a) @@ -139,37 +135,34 @@ void MyThread::init(QObject *parent, KUrl url, QString target, double frame, dou #define _G(y,u,v) (0x2568*(y) - 0x0c92*(v) - 0x1a1e*(u)) /0x2000 #define _B(y,u,v) (0x2568*(y) + 0x40cf*(v)) /0x2000 -KThumb::KThumb(ClipManager *clipManager, KUrl url, int width, int height, QObject * parent, const char *name):QObject(parent), m_clipManager(clipManager), m_url(url), m_width(width), m_height(height) -{ +KThumb::KThumb(ClipManager *clipManager, KUrl url, int width, int height, QObject * parent, const char *name): QObject(parent), m_clipManager(clipManager), m_url(url), m_width(width), m_height(height) { - m_profile = new Mlt::Profile((char*) KdenliveSettings::current_profile().data()); - QCryptographicHash context(QCryptographicHash::Sha1); - context.addData((KFileItem(m_url,"text/plain", S_IFREG).timeString() + m_url.fileName()).toAscii().data()); - m_thumbFile = KdenliveSettings::currenttmpfolder() + context.result().toHex() + ".thumb"; - kDebug() << "thumbfile=" << m_thumbFile; + m_profile = new Mlt::Profile((char*) KdenliveSettings::current_profile().data()); + QCryptographicHash context(QCryptographicHash::Sha1); + context.addData((KFileItem(m_url, "text/plain", S_IFREG).timeString() + m_url.fileName()).toAscii().data()); + m_thumbFile = KdenliveSettings::currenttmpfolder() + context.result().toHex() + ".thumb"; + kDebug() << "thumbfile=" << m_thumbFile; } -KThumb::~KThumb() -{ +KThumb::~KThumb() { if (m_profile) delete m_profile; - if (thumbProducer.isRunning ()) thumbProducer.exit(); + if (thumbProducer.isRunning()) thumbProducer.exit(); } //static -QPixmap KThumb::getImage(KUrl url, int width, int height) -{ +QPixmap KThumb::getImage(KUrl url, int width, int height) { if (url.isEmpty()) return QPixmap(); QPixmap pix(width, height); - kDebug()<<"+++++++++++ GET THMB IMG FOR: "<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); + uint8_t *thumb = m_frame->get_image(format, width, height); + QImage image(thumb, width, height, QImage::Format_ARGB32); + if (!image.isNull()) { + pix = pix.fromImage(image); + } else pix.fill(Qt::black); } if (m_frame) delete m_frame; return pix; } -void KThumb::extractImage(int frame, int frame2) -{ +void KThumb::extractImage(int frame, int frame2) { if (m_url.isEmpty()) return; QPixmap pix(m_width, m_height); char *tmp = Render::decodedString(m_url.path()); @@ -199,9 +190,9 @@ void KThumb::extractImage(int frame, int frame2) delete tmp; if (m_producer.is_blank()) { - pix.fill(Qt::black); - emit thumbReady(frame, pix); - return; + pix.fill(Qt::black); + emit thumbReady(frame, pix); + return; } Mlt::Frame * m_frame; mlt_image_format format = mlt_image_rgb24a; @@ -209,29 +200,27 @@ void KThumb::extractImage(int frame, int frame2) m_convert.set("forced", mlt_image_rgb24a); m_producer.attach(m_convert); if (frame != -1) { - m_producer.seek(frame); - m_frame = m_producer.get_frame(); - if (m_frame && m_frame->is_valid()) { - uint8_t *thumb = m_frame->get_image(format, m_width, m_height); - QImage image(thumb, m_width, m_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); + m_producer.seek(frame); + m_frame = m_producer.get_frame(); + if (m_frame && m_frame->is_valid()) { + uint8_t *thumb = m_frame->get_image(format, m_width, m_height); + QImage image(thumb, m_width, m_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, m_width, m_height); - QImage image(thumb, m_width, m_height, QImage::Format_ARGB32); - if (!image.isNull()) { - pix = pix.fromImage(image); - } - else pix.fill(Qt::black); + uint8_t *thumb = m_frame->get_image(format, m_width, m_height); + QImage image(thumb, m_width, m_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); @@ -248,8 +237,8 @@ void KThumb::getImage(KUrl url, int frame, int width, int height) image.fill(Qt::black); if (m_producer.is_blank()) { - emit thumbReady(frame, image); - return; + emit thumbReady(frame, image); + return; } Mlt::Filter m_convert("avcolour_space"); m_convert.set("forced", mlt_image_rgb24a); @@ -260,9 +249,9 @@ void KThumb::getImage(KUrl url, int frame, int width, int height) 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); + 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); @@ -278,9 +267,9 @@ void KThumb::getThumbs(KUrl url, int startframe, int endframe, int width, int he image.fill(Qt::black); if (m_producer.is_blank()) { - emit thumbReady(startframe, image); - emit thumbReady(endframe, image); - return; + emit thumbReady(startframe, image); + emit thumbReady(endframe, image); + return; } Mlt::Filter m_convert("avcolour_space"); m_convert.set("forced", mlt_image_rgb24a); @@ -292,9 +281,9 @@ void KThumb::getThumbs(KUrl url, int startframe, int endframe, int width, int he 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); + 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); @@ -304,72 +293,69 @@ void KThumb::getThumbs(KUrl url, int startframe, int endframe, int width, int he 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); + 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.isRunning ()) thumbProducer.stop_me = true; +void KThumb::stopAudioThumbs() { + if (thumbProducer.isRunning()) thumbProducer.stop_me = true; } -void KThumb::removeAudioThumb() -{ - if (m_thumbFile.isEmpty()) return; - stopAudioThumbs(); - QFile f(m_thumbFile); - f.remove(); +void KThumb::removeAudioThumb() { + if (m_thumbFile.isEmpty()) return; + stopAudioThumbs(); + QFile f(m_thumbFile); + f.remove(); } -void KThumb::getAudioThumbs(int channel, double frame, double frameLength, int arrayWidth){ - - if ((thumbProducer.isRunning() && thumbProducer.isWorking()) || channel == 0) { - return; - } - - QMap > storeIn; - //FIXME: Hardcoded!!! - int m_frequency = 48000; - int m_channels = channel; - - QFile f(m_thumbFile); - if (f.open( QIODevice::ReadOnly )) { - QByteArray channelarray = f.readAll(); - f.close(); - if (channelarray.size() != arrayWidth*(frame+frameLength)*m_channels) { - kDebug()<<"--- BROKEN THUMB FOR: "< > storeIn; + //FIXME: Hardcoded!!! + int m_frequency = 48000; + int m_channels = channel; + + QFile f(m_thumbFile); + if (f.open(QIODevice::ReadOnly)) { + QByteArray channelarray = f.readAll(); + f.close(); + if (channelarray.size() != arrayWidth*(frame + frameLength)*m_channels) { + kDebug() << "--- BROKEN THUMB FOR: " << m_url.fileName() << " ---------------------- " << endl; + f.remove(); + return; + } + kDebug() << "reading audio thumbs from file"; + for (int z = (int) frame;z < (int)(frame + frameLength);z++) { + for (int c = 0;c < m_channels;c++) { + QByteArray m_array(arrayWidth, '\x00'); + 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.isRunning()) return; + thumbProducer.init(this, m_url, m_thumbFile, frame, frameLength, m_frequency, m_channels, arrayWidth); + thumbProducer.start(QThread::LowestPriority); + kDebug() << "STARTING GENERATE THMB FOR: " << m_url << " ................................"; + } } -void KThumb::customEvent ( QEvent * event ){ - if (event->type()==10005){ - ProgressEvent* p=(ProgressEvent*) event; - m_clipManager->setThumbsProgress(m_url, p->value()); - } +void KThumb::customEvent(QEvent * event) { + if (event->type() == 10005) { + ProgressEvent* p = (ProgressEvent*) event; + m_clipManager->setThumbsProgress(m_url, p->value()); + } } diff --git a/src/kthumb.h b/src/kthumb.h index fb941223..a0255210 100644 --- a/src/kthumb.h +++ b/src/kthumb.h @@ -38,67 +38,67 @@ relevant signal that get's emitted once the call completes. namespace Mlt { - class Miracle; - class Consumer; - class Producer; - class Frame; - class Profile; +class Miracle; +class Consumer; +class Producer; +class Frame; +class Profile; }; class ClipManager; class MyThread : public QThread { - public: - virtual void run(); - void init(QObject *parent, KUrl url, QString target, double frame, double frameLength, int frequency, int channels, int arrayWidth); - bool isWorking(); - bool stop_me; +public: + virtual void run(); + void init(QObject *parent, 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; - QObject *m_parent; - }; +private: + QFile f; + KUrl m_url; + double m_frame; + double m_frameLength; + int m_frequency; + int m_channels; + int m_arrayWidth; + bool m_isWorking; + QObject *m_parent; +}; -class KThumb:public QObject { - Q_OBJECT public: +class KThumb: public QObject { +Q_OBJECT public: - KThumb(ClipManager *clipManager, KUrl url, int width, int height, QObject * parent = 0, const char *name = 0); + KThumb(ClipManager *clipManager, KUrl url, int width, int height, QObject * parent = 0, const char *name = 0); ~KThumb(); public slots: - void extractImage( int frame, int frame2); - static QPixmap getImage(KUrl url, int width, int height); -/* void getImage(KUrl url, int frame, int width, int height); - void getThumbs(KUrl url, int startframe, int endframe, int width, int height);*/ - void stopAudioThumbs(); - void removeAudioThumb(); - void getAudioThumbs(int channel, double frame, double frameLength, int arrayWidth); + void extractImage(int frame, int frame2); + static QPixmap getImage(KUrl url, int width, int height); + /* void getImage(KUrl url, int frame, int width, int height); + void getThumbs(KUrl url, int startframe, int endframe, int width, int height);*/ + void stopAudioThumbs(); + void removeAudioThumb(); + void getAudioThumbs(int channel, double frame, double frameLength, int arrayWidth); protected: - virtual void customEvent ( QEvent * event ); + virtual void customEvent(QEvent * event); private: - MyThread thumbProducer; - KUrl m_url; - QString m_thumbFile; - int m_width; - int m_height; - Mlt::Profile *m_profile; - ClipManager *m_clipManager; + MyThread thumbProducer; + KUrl m_url; + QString m_thumbFile; + int m_width; + int m_height; + Mlt::Profile *m_profile; + ClipManager *m_clipManager; signals: - void thumbReady(int frame, QPixmap pm); - void audioThumbReady(QMap >); + void thumbReady(int frame, QPixmap pm); + void audioThumbReady(QMap >); }; #endif diff --git a/src/labelitem.cpp b/src/labelitem.cpp index 3805e18e..83076da5 100644 --- a/src/labelitem.cpp +++ b/src/labelitem.cpp @@ -27,37 +27,34 @@ #include "labelitem.h" LabelItem::LabelItem(QString text, QGraphicsRectItem *parent) - : QGraphicsSimpleTextItem(" " + text + " ", parent) -{ - //setParentItem(parent); - //setFlags(QGraphicsItem::ItemIgnoresTransformations); - setZValue(200); + : QGraphicsSimpleTextItem(" " + text + " ", parent) { + //setParentItem(parent); + //setFlags(QGraphicsItem::ItemIgnoresTransformations); + setZValue(200); } -int LabelItem::type () const -{ - return 70001; +int LabelItem::type() const { + return 70001; } -// virtual +// virtual - void LabelItem::paint(QPainter *painter, - const QStyleOptionGraphicsItem *option, - QWidget *widget) - { +void LabelItem::paint(QPainter *painter, + const QStyleOptionGraphicsItem *option, + QWidget *widget) { //kDebug()<<"REPAINT LABEL ------------------------"; QRectF rep = option->exposedRect; //painter->setClipRect(rep); QGraphicsRectItem *parent = (QGraphicsRectItem *) parentItem(); QRectF par = mapFromScene(parent->rect()).boundingRect(); QRectF parrect = option->matrix.map(mapFromScene(par)).boundingRect(); - painter->setClipRect( parrect ); //option->exposedRect ); + painter->setClipRect(parrect); //option->exposedRect ); QGraphicsSimpleTextItem::paint(painter, option, widget); /*QPainterPath path; path.addRoundRect(boundingRect(), 40); painter->fillPath(path, QColor(200, 200, 200, 100)); //painter->fillRect(parrect, QColor(200, 50, 200, 100)); painter->drawText(boundingRect(), Qt::AlignCenter, text());*/ - } +} #include "labelitem.moc" diff --git a/src/labelitem.h b/src/labelitem.h index 3bfc6124..c978dd88 100644 --- a/src/labelitem.h +++ b/src/labelitem.h @@ -25,13 +25,12 @@ #include #include -class LabelItem : public QGraphicsSimpleTextItem -{ - - public: +class LabelItem : public QGraphicsSimpleTextItem { + +public: LabelItem(QString text, QGraphicsRectItem *parent = 0); virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); - virtual int type () const; + virtual int type() const; }; #endif diff --git a/src/main.cpp b/src/main.cpp index 908c9ce8..c1a75e79 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2,32 +2,30 @@ #include #include #include //new - + #include "mainwindow.h" - -int main (int argc, char *argv[]) -{ - KAboutData aboutData( "kdenlive", "kdenlive", - ki18n("Kdenlive"), "1.0", - ki18n("A simple text area which can load and save."), - KAboutData::License_GPL, - ki18n("Copyright (c) 2007 Developer") ); - KCmdLineArgs::init( argc, argv, &aboutData ); - - KCmdLineOptions options; //new - options.add("+[file]", ki18n("Document to open")); //new - KCmdLineArgs::addCmdLineOptions(options); //new - - KApplication app; - MainWindow* window = new MainWindow(); - window->show(); - - KCmdLineArgs *args = KCmdLineArgs::parsedArgs(); //new - if(args->count()) //new - { - window->openFile(args->url(0)); //new - } - - return app.exec(); +int main(int argc, char *argv[]) { + KAboutData aboutData("kdenlive", "kdenlive", + ki18n("Kdenlive"), "1.0", + ki18n("A simple text area which can load and save."), + KAboutData::License_GPL, + ki18n("Copyright (c) 2007 Developer")); + KCmdLineArgs::init(argc, argv, &aboutData); + + KCmdLineOptions options; //new + options.add("+[file]", ki18n("Document to open")); //new + KCmdLineArgs::addCmdLineOptions(options); //new + + KApplication app; + + MainWindow* window = new MainWindow(); + window->show(); + + KCmdLineArgs *args = KCmdLineArgs::parsedArgs(); //new + if (args->count()) { //new + window->openFile(args->url(0)); //new + } + + return app.exec(); } diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 8004e65b..e035ae69 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -57,477 +57,442 @@ #define ID_TIMELINE_MSG 3 #define ID_TIMELINE_POS 4 #define ID_TIMELINE_FORMAT 5 - + MainWindow::MainWindow(QWidget *parent) - : KXmlGuiWindow(parent), - fileName(QString()), m_activeDocument(NULL), m_commandStack(NULL) -{ - parseProfiles(); - m_timelineArea = new KTabWidget(this); - m_timelineArea->setHoverCloseButton(true); - m_timelineArea->setTabReorderingEnabled(true); - connect(m_timelineArea, SIGNAL(currentChanged (int)), this, SLOT(activateDocument())); - - initEffects::parseEffectFiles( &m_audioEffects, &m_videoEffects ); - m_monitorManager = new MonitorManager(); - - projectListDock = new QDockWidget(i18n("Project Tree"), this); - projectListDock->setObjectName("project_tree"); - m_projectList = new ProjectList(this); - projectListDock->setWidget(m_projectList); - addDockWidget(Qt::TopDockWidgetArea, projectListDock); - - effectListDock = new QDockWidget(i18n("Effect List"), this); - effectListDock->setObjectName("effect_list"); - m_effectList = new EffectsListView(&m_audioEffects, &m_videoEffects, &m_customEffects); - - //m_effectList = new KListWidget(this); - effectListDock->setWidget(m_effectList); - addDockWidget(Qt::TopDockWidgetArea, effectListDock); - - effectStackDock = new QDockWidget(i18n("Effect Stack"), this); - effectStackDock->setObjectName("effect_stack"); - effectStack = new EffectStackView(&m_audioEffects, &m_videoEffects, &m_customEffects,this); - effectStackDock->setWidget(effectStack); - addDockWidget(Qt::TopDockWidgetArea, effectStackDock); - - transitionConfigDock = new QDockWidget(i18n("Transition"), this); - transitionConfigDock->setObjectName("transition"); - transitionConfig = new KListWidget(this); - transitionConfigDock->setWidget(transitionConfig); - addDockWidget(Qt::TopDockWidgetArea, transitionConfigDock); - - - clipMonitorDock = new QDockWidget(i18n("Clip Monitor"), this); - clipMonitorDock->setObjectName("clip_monitor"); - m_clipMonitor = new Monitor("clip", m_monitorManager, this); - clipMonitorDock->setWidget(m_clipMonitor); - addDockWidget(Qt::TopDockWidgetArea, clipMonitorDock); - //m_clipMonitor->stop(); - - projectMonitorDock = new QDockWidget(i18n("Project Monitor"), this); - projectMonitorDock->setObjectName("project_monitor"); - m_projectMonitor = new Monitor("project", m_monitorManager, this); - projectMonitorDock->setWidget(m_projectMonitor); - addDockWidget(Qt::TopDockWidgetArea, projectMonitorDock); - - undoViewDock = new QDockWidget(i18n("Undo History"), this); - undoViewDock->setObjectName("undo_history"); - m_undoView = new QUndoView(this); - undoViewDock->setWidget(m_undoView); - m_undoView->setStack(m_commandStack); - addDockWidget(Qt::TopDockWidgetArea, undoViewDock); - - overviewDock = new QDockWidget(i18n("Project Overview"), this); - overviewDock->setObjectName("project_overview"); - m_overView = new CustomTrackView(NULL, NULL, this); - overviewDock->setWidget(m_overView); - addDockWidget(Qt::TopDockWidgetArea, overviewDock); - - setupActions(); - tabifyDockWidget (projectListDock, effectListDock); - tabifyDockWidget (projectListDock, effectStackDock); - tabifyDockWidget (projectListDock, transitionConfigDock); - tabifyDockWidget (projectListDock, undoViewDock); - projectListDock->raise(); - - tabifyDockWidget (clipMonitorDock, projectMonitorDock); - setCentralWidget(m_timelineArea); - - m_timecodeFormat = new KComboBox(this); - m_timecodeFormat->addItem(i18n("hh:mm:ss::ff")); - m_timecodeFormat->addItem(i18n("Frames")); - - statusProgressBar=new QProgressBar(this); - statusProgressBar->setMinimum(0); - statusProgressBar->setMaximum(100); - statusProgressBar->setMaximumWidth(150); - statusProgressBar->setVisible(false); - statusLabel=new QLabel(this); - - statusBar()->insertPermanentWidget(0,statusProgressBar,1); - statusBar()->insertPermanentWidget(1,statusLabel,1); - statusBar()->insertPermanentFixedItem("00:00:00:00", ID_TIMELINE_POS); - statusBar()->insertPermanentWidget(ID_TIMELINE_FORMAT, m_timecodeFormat); - - setupGUI(Default, "kdenliveui.rc"); - - connect(projectMonitorDock, SIGNAL(visibilityChanged (bool)), m_projectMonitor, SLOT(refreshMonitor(bool))); - connect(clipMonitorDock, SIGNAL(visibilityChanged (bool)), m_clipMonitor, SLOT(refreshMonitor(bool))); - connect(m_monitorManager, SIGNAL(connectMonitors ()), this, SLOT(slotConnectMonitors())); - connect(m_monitorManager, SIGNAL(raiseClipMonitor (bool)), this, SLOT(slotRaiseMonitor(bool))); - connect(m_effectList, SIGNAL(addEffect(QDomElement)), this, SLOT(slotAddEffect(QDomElement))); - m_monitorManager->initMonitors(m_clipMonitor, m_projectMonitor); - - setAutoSaveSettings(); - newFile(); + : KXmlGuiWindow(parent), + fileName(QString()), m_activeDocument(NULL), m_commandStack(NULL) { + parseProfiles(); + m_timelineArea = new KTabWidget(this); + m_timelineArea->setHoverCloseButton(true); + m_timelineArea->setTabReorderingEnabled(true); + connect(m_timelineArea, SIGNAL(currentChanged(int)), this, SLOT(activateDocument())); + + initEffects::parseEffectFiles(&m_audioEffects, &m_videoEffects); + m_monitorManager = new MonitorManager(); + + projectListDock = new QDockWidget(i18n("Project Tree"), this); + projectListDock->setObjectName("project_tree"); + m_projectList = new ProjectList(this); + projectListDock->setWidget(m_projectList); + addDockWidget(Qt::TopDockWidgetArea, projectListDock); + + effectListDock = new QDockWidget(i18n("Effect List"), this); + effectListDock->setObjectName("effect_list"); + m_effectList = new EffectsListView(&m_audioEffects, &m_videoEffects, &m_customEffects); + + //m_effectList = new KListWidget(this); + effectListDock->setWidget(m_effectList); + addDockWidget(Qt::TopDockWidgetArea, effectListDock); + + effectStackDock = new QDockWidget(i18n("Effect Stack"), this); + effectStackDock->setObjectName("effect_stack"); + effectStack = new EffectStackView(&m_audioEffects, &m_videoEffects, &m_customEffects, this); + effectStackDock->setWidget(effectStack); + addDockWidget(Qt::TopDockWidgetArea, effectStackDock); + + transitionConfigDock = new QDockWidget(i18n("Transition"), this); + transitionConfigDock->setObjectName("transition"); + transitionConfig = new KListWidget(this); + transitionConfigDock->setWidget(transitionConfig); + addDockWidget(Qt::TopDockWidgetArea, transitionConfigDock); + + + clipMonitorDock = new QDockWidget(i18n("Clip Monitor"), this); + clipMonitorDock->setObjectName("clip_monitor"); + m_clipMonitor = new Monitor("clip", m_monitorManager, this); + clipMonitorDock->setWidget(m_clipMonitor); + addDockWidget(Qt::TopDockWidgetArea, clipMonitorDock); + //m_clipMonitor->stop(); + + projectMonitorDock = new QDockWidget(i18n("Project Monitor"), this); + projectMonitorDock->setObjectName("project_monitor"); + m_projectMonitor = new Monitor("project", m_monitorManager, this); + projectMonitorDock->setWidget(m_projectMonitor); + addDockWidget(Qt::TopDockWidgetArea, projectMonitorDock); + + undoViewDock = new QDockWidget(i18n("Undo History"), this); + undoViewDock->setObjectName("undo_history"); + m_undoView = new QUndoView(this); + undoViewDock->setWidget(m_undoView); + m_undoView->setStack(m_commandStack); + addDockWidget(Qt::TopDockWidgetArea, undoViewDock); + + overviewDock = new QDockWidget(i18n("Project Overview"), this); + overviewDock->setObjectName("project_overview"); + m_overView = new CustomTrackView(NULL, NULL, this); + overviewDock->setWidget(m_overView); + addDockWidget(Qt::TopDockWidgetArea, overviewDock); + + setupActions(); + tabifyDockWidget(projectListDock, effectListDock); + tabifyDockWidget(projectListDock, effectStackDock); + tabifyDockWidget(projectListDock, transitionConfigDock); + tabifyDockWidget(projectListDock, undoViewDock); + projectListDock->raise(); + + tabifyDockWidget(clipMonitorDock, projectMonitorDock); + setCentralWidget(m_timelineArea); + + m_timecodeFormat = new KComboBox(this); + m_timecodeFormat->addItem(i18n("hh:mm:ss::ff")); + m_timecodeFormat->addItem(i18n("Frames")); + + statusProgressBar = new QProgressBar(this); + statusProgressBar->setMinimum(0); + statusProgressBar->setMaximum(100); + statusProgressBar->setMaximumWidth(150); + statusProgressBar->setVisible(false); + statusLabel = new QLabel(this); + + statusBar()->insertPermanentWidget(0, statusProgressBar, 1); + statusBar()->insertPermanentWidget(1, statusLabel, 1); + statusBar()->insertPermanentFixedItem("00:00:00:00", ID_TIMELINE_POS); + statusBar()->insertPermanentWidget(ID_TIMELINE_FORMAT, m_timecodeFormat); + + setupGUI(Default, "kdenliveui.rc"); + + connect(projectMonitorDock, SIGNAL(visibilityChanged(bool)), m_projectMonitor, SLOT(refreshMonitor(bool))); + connect(clipMonitorDock, SIGNAL(visibilityChanged(bool)), m_clipMonitor, SLOT(refreshMonitor(bool))); + connect(m_monitorManager, SIGNAL(connectMonitors()), this, SLOT(slotConnectMonitors())); + connect(m_monitorManager, SIGNAL(raiseClipMonitor(bool)), this, SLOT(slotRaiseMonitor(bool))); + connect(m_effectList, SIGNAL(addEffect(QDomElement)), this, SLOT(slotAddEffect(QDomElement))); + m_monitorManager->initMonitors(m_clipMonitor, m_projectMonitor); + + setAutoSaveSettings(); + newFile(); } //virtual -bool MainWindow::queryClose() -{ - saveOptions(); - switch ( KMessageBox::warningYesNoCancel( this, i18n("Save changes to document ?")) ) { - case KMessageBox::Yes : - // save document here. If saving fails, return false; - return true; - case KMessageBox::No : - return true; - default: // cancel - return false; - } +bool MainWindow::queryClose() { + saveOptions(); + switch (KMessageBox::warningYesNoCancel(this, i18n("Save changes to document ?"))) { + case KMessageBox::Yes : + // save document here. If saving fails, return false; + return true; + case KMessageBox::No : + return true; + default: // cancel + return false; + } } -void MainWindow::slotAddEffect(QDomElement effect, GenTime pos, int track) -{ - if (!m_activeDocument) return; - /*QMap filter; - if (effectType == 0) - filter = m_videoEffects.effect(effectName); - else if (effectType == 1) - filter = m_audioEffects.effect(effectName); - else - filter = m_customEffects.effect(effectName);*/ - if (effect.isNull()) { - kDebug()<<"--- ERROR, TRYING TO APPEND NULL EFFECT"; - return; - } - TrackView *currentTimeLine = (TrackView *) m_timelineArea->currentWidget(); - currentTimeLine->projectView()->slotAddEffect(effect, pos, track); +void MainWindow::slotAddEffect(QDomElement effect, GenTime pos, int track) { + if (!m_activeDocument) return; + if (effect.isNull()) { + kDebug() << "--- ERROR, TRYING TO APPEND NULL EFFECT"; + return; + } + TrackView *currentTimeLine = (TrackView *) m_timelineArea->currentWidget(); + currentTimeLine->projectView()->slotAddEffect(effect, pos, track); } -void MainWindow::slotRaiseMonitor(bool clipMonitor) -{ - if (clipMonitor) clipMonitorDock->raise(); - else projectMonitorDock->raise(); +void MainWindow::slotRaiseMonitor(bool clipMonitor) { + if (clipMonitor) clipMonitorDock->raise(); + else projectMonitorDock->raise(); } -void MainWindow::slotSetClipDuration(int id, int duration) -{ - if (!m_activeDocument) return; - m_activeDocument->setProducerDuration(id, duration); +void MainWindow::slotSetClipDuration(int id, int duration) { + if (!m_activeDocument) return; + m_activeDocument->setProducerDuration(id, duration); } -void MainWindow::slotConnectMonitors() -{ +void MainWindow::slotConnectMonitors() { - m_projectList->setRenderer(m_clipMonitor->render); + m_projectList->setRenderer(m_clipMonitor->render); - connect(m_projectList, SIGNAL(clipSelected(const QDomElement &)), m_clipMonitor, SLOT(slotSetXml(const QDomElement &))); + connect(m_projectList, SIGNAL(clipSelected(const QDomElement &)), m_clipMonitor, SLOT(slotSetXml(const QDomElement &))); - connect(m_projectList, SIGNAL(receivedClipDuration(int, int)), this, SLOT(slotSetClipDuration(int, int))); + connect(m_projectList, SIGNAL(receivedClipDuration(int, int)), this, SLOT(slotSetClipDuration(int, int))); - connect(m_projectList, SIGNAL(getFileProperties(const QDomElement &, int)), m_clipMonitor->render, SLOT(getFileProperties(const QDomElement &, int))); + connect(m_projectList, SIGNAL(getFileProperties(const QDomElement &, int)), m_clipMonitor->render, SLOT(getFileProperties(const QDomElement &, int))); - connect(m_clipMonitor->render, SIGNAL(replyGetImage(int, int, const QPixmap &, int, int)), m_projectList, SLOT(slotReplyGetImage(int, int, const QPixmap &, int, int))); + connect(m_clipMonitor->render, SIGNAL(replyGetImage(int, int, const QPixmap &, int, int)), m_projectList, SLOT(slotReplyGetImage(int, int, const QPixmap &, int, int))); - connect(m_clipMonitor->render, SIGNAL(replyGetFileProperties(int, const QMap < QString, QString > &, const QMap < QString, QString > &)), m_projectList, SLOT(slotReplyGetFileProperties(int, const QMap < QString, QString > &, const QMap < QString, QString > &))); + connect(m_clipMonitor->render, SIGNAL(replyGetFileProperties(int, const QMap < QString, QString > &, const QMap < QString, QString > &)), m_projectList, SLOT(slotReplyGetFileProperties(int, const QMap < QString, QString > &, const QMap < QString, QString > &))); } -void MainWindow::setupActions() -{ - KAction* clearAction = new KAction(this); - clearAction->setText(i18n("Clear")); - clearAction->setIcon(KIcon("document-new")); - clearAction->setShortcut(Qt::CTRL + Qt::Key_W); - actionCollection()->addAction("clear", clearAction); - /*connect(clearAction, SIGNAL(triggered(bool)), - textArea, SLOT(clear()));*/ - - KAction* profilesAction = new KAction(this); - profilesAction->setText(i18n("Manage Profiles")); - profilesAction->setIcon(KIcon("document-new")); - actionCollection()->addAction("manage_profiles", profilesAction); - connect(profilesAction, SIGNAL(triggered(bool)), this, SLOT(slotEditProfiles())); - - KAction* projectAction = new KAction(this); - projectAction->setText(i18n("Project Settings")); - projectAction->setIcon(KIcon("document-new")); - actionCollection()->addAction("project_settings", projectAction); - connect(projectAction, SIGNAL(triggered(bool)), this, SLOT(slotEditProjectSettings())); - - - - KStandardAction::quit(kapp, SLOT(quit()), - actionCollection()); - - KStandardAction::open(this, SLOT(openFile()), - actionCollection()); - - m_fileOpenRecent = KStandardAction::openRecent(this, SLOT(openFile(const KUrl &)), - actionCollection()); - - KStandardAction::save(this, SLOT(saveFile()), - actionCollection()); - - KStandardAction::saveAs(this, SLOT(saveFileAs()), - actionCollection()); - - KStandardAction::openNew(this, SLOT(newFile()), - actionCollection()); - - KStandardAction::preferences(this, SLOT(slotPreferences()), - actionCollection()); - - /*KStandardAction::undo(this, SLOT(undo()), - actionCollection()); - - KStandardAction::redo(this, SLOT(redo()), - actionCollection());*/ - - connect(actionCollection(), SIGNAL( actionHighlighted( QAction* ) ), - this, SLOT( slotDisplayActionMessage( QAction* ) ) ); - //connect(actionCollection(), SIGNAL( clearStatusText() ), +void MainWindow::setupActions() { + KAction* clearAction = new KAction(this); + clearAction->setText(i18n("Clear")); + clearAction->setIcon(KIcon("document-new")); + clearAction->setShortcut(Qt::CTRL + Qt::Key_W); + actionCollection()->addAction("clear", clearAction); + /*connect(clearAction, SIGNAL(triggered(bool)), + textArea, SLOT(clear()));*/ + + KAction* profilesAction = new KAction(this); + profilesAction->setText(i18n("Manage Profiles")); + profilesAction->setIcon(KIcon("document-new")); + actionCollection()->addAction("manage_profiles", profilesAction); + connect(profilesAction, SIGNAL(triggered(bool)), this, SLOT(slotEditProfiles())); + + KAction* projectAction = new KAction(this); + projectAction->setText(i18n("Project Settings")); + projectAction->setIcon(KIcon("document-new")); + actionCollection()->addAction("project_settings", projectAction); + connect(projectAction, SIGNAL(triggered(bool)), this, SLOT(slotEditProjectSettings())); + + + + KStandardAction::quit(kapp, SLOT(quit()), + actionCollection()); + + KStandardAction::open(this, SLOT(openFile()), + actionCollection()); + + m_fileOpenRecent = KStandardAction::openRecent(this, SLOT(openFile(const KUrl &)), + actionCollection()); + + KStandardAction::save(this, SLOT(saveFile()), + actionCollection()); + + KStandardAction::saveAs(this, SLOT(saveFileAs()), + actionCollection()); + + KStandardAction::openNew(this, SLOT(newFile()), + actionCollection()); + + KStandardAction::preferences(this, SLOT(slotPreferences()), + actionCollection()); + + /*KStandardAction::undo(this, SLOT(undo()), + actionCollection()); + + KStandardAction::redo(this, SLOT(redo()), + actionCollection());*/ + + connect(actionCollection(), SIGNAL(actionHighlighted(QAction*)), + this, SLOT(slotDisplayActionMessage(QAction*))); + //connect(actionCollection(), SIGNAL( clearStatusText() ), //statusBar(), SLOT( clear() ) ); - readOptions(); + readOptions(); - /*m_redo = m_commandStack->createRedoAction(actionCollection()); - m_undo = m_commandStack->createUndoAction(actionCollection());*/ + /*m_redo = m_commandStack->createRedoAction(actionCollection()); + m_undo = m_commandStack->createUndoAction(actionCollection());*/ } -void MainWindow::slotDisplayActionMessage( QAction *a) -{ - statusBar()->showMessage(a->data().toString(), 3000); +void MainWindow::slotDisplayActionMessage(QAction *a) { + statusBar()->showMessage(a->data().toString(), 3000); } -void MainWindow::saveOptions() -{ - KSharedConfigPtr config = KGlobal::config (); - m_fileOpenRecent->saveEntries(KConfigGroup (config, "Recent Files")); - config->sync(); +void MainWindow::saveOptions() { + KSharedConfigPtr config = KGlobal::config(); + m_fileOpenRecent->saveEntries(KConfigGroup(config, "Recent Files")); + config->sync(); } -void MainWindow::readOptions() -{ - KSharedConfigPtr config = KGlobal::config (); - m_fileOpenRecent->loadEntries(KConfigGroup (config, "Recent Files")); +void MainWindow::readOptions() { + KSharedConfigPtr config = KGlobal::config(); + m_fileOpenRecent->loadEntries(KConfigGroup(config, "Recent Files")); } - -void MainWindow::newFile() -{ - KdenliveDoc *doc = new KdenliveDoc(KUrl(), 25, 720, 576); - TrackView *trackView = new TrackView(doc); - m_timelineArea->addTab(trackView, "New Project"); - if (m_timelineArea->count() == 1) - connectDocument(trackView, doc); + +void MainWindow::newFile() { + KdenliveDoc *doc = new KdenliveDoc(KUrl(), 25, 720, 576); + TrackView *trackView = new TrackView(doc); + m_timelineArea->addTab(trackView, "New Project"); + if (m_timelineArea->count() == 1) + connectDocument(trackView, doc); } -void MainWindow::activateDocument() -{ - TrackView *currentTab = (TrackView *) m_timelineArea->currentWidget(); - KdenliveDoc *currentDoc = currentTab->document(); - connectDocument(currentTab, currentDoc); +void MainWindow::activateDocument() { + TrackView *currentTab = (TrackView *) m_timelineArea->currentWidget(); + KdenliveDoc *currentDoc = currentTab->document(); + connectDocument(currentTab, currentDoc); } - -void MainWindow::saveFileAs(const QString &outputFileName) -{ - KSaveFile file(outputFileName); - file.open(); - - QByteArray outputByteArray; - //outputByteArray.append(textArea->toPlainText()); - file.write(outputByteArray); - file.finalize(); - file.close(); - - fileName = outputFileName; + +void MainWindow::saveFileAs(const QString &outputFileName) { + KSaveFile file(outputFileName); + file.open(); + + QByteArray outputByteArray; + //outputByteArray.append(textArea->toPlainText()); + file.write(outputByteArray); + file.finalize(); + file.close(); + + fileName = outputFileName; } -void MainWindow::saveFileAs() -{ - saveFileAs(KFileDialog::getSaveFileName()); +void MainWindow::saveFileAs() { + saveFileAs(KFileDialog::getSaveFileName()); } - -void MainWindow::saveFile() -{ - if(!fileName.isEmpty()) - { - saveFileAs(fileName); - } - else - { - saveFileAs(); - } + +void MainWindow::saveFile() { + if (!fileName.isEmpty()) { + saveFileAs(fileName); + } else { + saveFileAs(); + } } - -void MainWindow::openFile() //changed -{ + +void MainWindow::openFile() { //changed KUrl url = KFileDialog::getOpenUrl(KUrl(), "application/vnd.kde.kdenlive;*.kdenlive"); if (url.isEmpty()) return; - m_fileOpenRecent->addUrl (url); + m_fileOpenRecent->addUrl(url); openFile(url); } - -void MainWindow::openFile(const KUrl &url) //new -{ - KdenliveDoc *doc = new KdenliveDoc(url, 25, 720, 576); - TrackView *trackView = new TrackView(doc); - m_timelineArea->setCurrentIndex(m_timelineArea->addTab(trackView, QIcon(), doc->documentName())); - m_timelineArea->setTabToolTip(m_timelineArea->currentIndex(), doc->url().path()); - //connectDocument(trackView, doc); + +void MainWindow::openFile(const KUrl &url) { //new + KdenliveDoc *doc = new KdenliveDoc(url, 25, 720, 576); + TrackView *trackView = new TrackView(doc); + m_timelineArea->setCurrentIndex(m_timelineArea->addTab(trackView, QIcon(), doc->documentName())); + m_timelineArea->setTabToolTip(m_timelineArea->currentIndex(), doc->url().path()); + //connectDocument(trackView, doc); } -void MainWindow::parseProfiles() -{ - //kdDebug()<<" + + YOUR MLT INSTALL WAS FOUND IN: "<< MLT_PREFIX <fileDialog()->setMode(KFile::Directory); - getUrl->exec(); - KUrl mltPath = getUrl->selectedUrl (); - delete getUrl; - if (mltPath.isEmpty()) exit(1); - KdenliveSettings::setMltpath(mltPath.path()); - QStringList profilesList = QDir(KdenliveSettings::mltpath()).entryList(profilesFilter, QDir::Files); - } - } - - if (KdenliveSettings::rendererpath().isEmpty()) { - // Cannot find the MLT inigo renderer, ask for location - KUrlRequesterDialog *getUrl = new KUrlRequesterDialog(KdenliveSettings::mltpath(), i18n("Cannot find the inigo program required for rendering (part of Mlt)"), this); - getUrl->exec(); - KUrl rendererPath = getUrl->selectedUrl(); - delete getUrl; - if (rendererPath.isEmpty()) exit(1); - KdenliveSettings::setRendererpath(rendererPath.path()); - } - - kDebug()<<"RESULTING MLT PATH: "<fileDialog()->setMode(KFile::Directory); + getUrl->exec(); + KUrl mltPath = getUrl->selectedUrl(); + delete getUrl; + if (mltPath.isEmpty()) exit(1); + KdenliveSettings::setMltpath(mltPath.path()); + QStringList profilesList = QDir(KdenliveSettings::mltpath()).entryList(profilesFilter, QDir::Files); + } } + if (KdenliveSettings::rendererpath().isEmpty()) { + // Cannot find the MLT inigo renderer, ask for location + KUrlRequesterDialog *getUrl = new KUrlRequesterDialog(KdenliveSettings::mltpath(), i18n("Cannot find the inigo program required for rendering (part of Mlt)"), this); + getUrl->exec(); + KUrl rendererPath = getUrl->selectedUrl(); + delete getUrl; + if (rendererPath.isEmpty()) exit(1); + KdenliveSettings::setRendererpath(rendererPath.path()); + } + + kDebug() << "RESULTING MLT PATH: " << KdenliveSettings::mltpath(); -void MainWindow::slotEditProfiles() -{ - ProfilesDialog *w = new ProfilesDialog; - w->exec(); - delete w; + // Parse MLT profiles to build a list of available video formats + if (profilesList.isEmpty()) parseProfiles(); } -void MainWindow::slotEditProjectSettings() -{ - ProjectSettings *w = new ProjectSettings; - w->exec(); - delete w; + +void MainWindow::slotEditProfiles() { + ProfilesDialog *w = new ProfilesDialog; + w->exec(); + delete w; } +void MainWindow::slotEditProjectSettings() { + ProjectSettings *w = new ProjectSettings; + w->exec(); + delete w; +} -void MainWindow::slotUpdateMousePosition(int pos) -{ - if (m_activeDocument) - switch(m_timecodeFormat->currentIndex()) { - case 0: - statusBar()->changeItem(m_activeDocument->timecode().getTimecodeFromFrames(pos), ID_TIMELINE_POS); - break; - default: - statusBar()->changeItem(QString::number(pos), ID_TIMELINE_POS); - } + +void MainWindow::slotUpdateMousePosition(int pos) { + if (m_activeDocument) + switch (m_timecodeFormat->currentIndex()) { + case 0: + statusBar()->changeItem(m_activeDocument->timecode().getTimecodeFromFrames(pos), ID_TIMELINE_POS); + break; + default: + statusBar()->changeItem(QString::number(pos), ID_TIMELINE_POS); + } } -void MainWindow::connectDocument(TrackView *trackView, KdenliveDoc *doc) //changed -{ - //m_projectMonitor->stop(); - kDebug()<<"/////////////////// CONNECTING DOC TO PROJECT VIEW ////////////////"; - if (m_activeDocument) { - if (m_activeDocument == doc) return; - m_activeDocument->setProducers(m_projectList->producersList()); - m_activeDocument->setRenderer(NULL); - } - connect(trackView, SIGNAL(cursorMoved()), m_projectMonitor, SLOT(activateMonitor())); - connect(trackView, SIGNAL(mousePosition(int)), this, SLOT(slotUpdateMousePosition(int))); - connect(m_projectMonitor, SIGNAL(renderPosition(int)), trackView, SLOT(moveCursorPos(int))); - connect(m_projectMonitor, SIGNAL(durationChanged(int)), trackView->projectView(), SLOT(setDuration(int))); - connect(doc, SIGNAL(addProjectClip(DocClipBase *)), m_projectList, SLOT(slotAddClip(DocClipBase *))); - connect(doc, SIGNAL(signalDeleteProjectClip(int)), m_projectList, SLOT(slotDeleteClip(int))); - connect(doc, SIGNAL(updateClipDisplay(int)), m_projectList, SLOT(slotUpdateClip(int))); - connect(doc, SIGNAL(deletTimelineClip(int)), trackView, SLOT(slotDeleteClip(int))); - connect(doc, SIGNAL(thumbsProgress(KUrl, int)), this, SLOT(slotGotProgressInfo(KUrl, int))); - - connect(trackView, SIGNAL(clipItemSelected(ClipItem*)), effectStack, SLOT(slotClipItemSelected(ClipItem*))); - connect(effectStack, SIGNAL(updateClipEffect(ClipItem*, QDomElement, QDomElement)), trackView->projectView(), SLOT(slotUpdateClipEffect(ClipItem*, QDomElement, QDomElement))); - connect(effectStack, SIGNAL(removeEffect(ClipItem*, QDomElement)), trackView->projectView(), SLOT(slotDeleteEffect(ClipItem*, QDomElement))); - connect(effectStack, SIGNAL(changeEffectState(ClipItem*, QDomElement, bool)), trackView->projectView(), SLOT(slotChangeEffectState(ClipItem*, QDomElement, bool))); - connect(effectStack, SIGNAL(refreshEffectStack(ClipItem*)), trackView->projectView(), SLOT(slotRefreshEffects(ClipItem*))); - - m_projectList->setDocument(doc); - m_monitorManager->setTimecode(doc->timecode()); - doc->setRenderer(m_projectMonitor->render); - //m_undoView->setStack(0); - m_commandStack = doc->commandStack(); - - m_overView->setScene(trackView->projectScene()); - m_overView->scale(m_overView->width() / trackView->duration(), m_overView->height() / (50 * trackView->tracksNumber())); - //m_overView->fitInView(m_overView->itemAt(0, 50), Qt::KeepAspectRatio); - QAction *redo = m_commandStack->createRedoAction(actionCollection()); - QAction *undo = m_commandStack->createUndoAction(actionCollection()); - - QWidget* w = factory()->container("mainToolBar", this); - if(w) { - if (actionCollection()->action("undo")) - delete actionCollection()->action("undo"); - if(actionCollection()->action("redo")) - delete actionCollection()->action("redo"); - - actionCollection()->addAction("undo", undo); - actionCollection()->addAction("redo", redo); - w->addAction(undo); - w->addAction(redo); - } - m_undoView->setStack(doc->commandStack()); - m_activeDocument = doc; +void MainWindow::connectDocument(TrackView *trackView, KdenliveDoc *doc) { //changed + //m_projectMonitor->stop(); + kDebug() << "/////////////////// CONNECTING DOC TO PROJECT VIEW ////////////////"; + if (m_activeDocument) { + if (m_activeDocument == doc) return; + m_activeDocument->setProducers(m_projectList->producersList()); + m_activeDocument->setRenderer(NULL); + } + connect(trackView, SIGNAL(cursorMoved()), m_projectMonitor, SLOT(activateMonitor())); + connect(trackView, SIGNAL(mousePosition(int)), this, SLOT(slotUpdateMousePosition(int))); + connect(m_projectMonitor, SIGNAL(renderPosition(int)), trackView, SLOT(moveCursorPos(int))); + connect(m_projectMonitor, SIGNAL(durationChanged(int)), trackView->projectView(), SLOT(setDuration(int))); + connect(doc, SIGNAL(addProjectClip(DocClipBase *)), m_projectList, SLOT(slotAddClip(DocClipBase *))); + connect(doc, SIGNAL(signalDeleteProjectClip(int)), m_projectList, SLOT(slotDeleteClip(int))); + connect(doc, SIGNAL(updateClipDisplay(int)), m_projectList, SLOT(slotUpdateClip(int))); + connect(doc, SIGNAL(deletTimelineClip(int)), trackView, SLOT(slotDeleteClip(int))); + connect(doc, SIGNAL(thumbsProgress(KUrl, int)), this, SLOT(slotGotProgressInfo(KUrl, int))); + + connect(trackView, SIGNAL(clipItemSelected(ClipItem*)), effectStack, SLOT(slotClipItemSelected(ClipItem*))); + connect(effectStack, SIGNAL(updateClipEffect(ClipItem*, QDomElement, QDomElement)), trackView->projectView(), SLOT(slotUpdateClipEffect(ClipItem*, QDomElement, QDomElement))); + connect(effectStack, SIGNAL(removeEffect(ClipItem*, QDomElement)), trackView->projectView(), SLOT(slotDeleteEffect(ClipItem*, QDomElement))); + connect(effectStack, SIGNAL(changeEffectState(ClipItem*, QDomElement, bool)), trackView->projectView(), SLOT(slotChangeEffectState(ClipItem*, QDomElement, bool))); + connect(effectStack, SIGNAL(refreshEffectStack(ClipItem*)), trackView->projectView(), SLOT(slotRefreshEffects(ClipItem*))); + + m_projectList->setDocument(doc); + m_monitorManager->setTimecode(doc->timecode()); + doc->setRenderer(m_projectMonitor->render); + //m_undoView->setStack(0); + m_commandStack = doc->commandStack(); + + m_overView->setScene(trackView->projectScene()); + m_overView->scale(m_overView->width() / trackView->duration(), m_overView->height() / (50 * trackView->tracksNumber())); + //m_overView->fitInView(m_overView->itemAt(0, 50), Qt::KeepAspectRatio); + QAction *redo = m_commandStack->createRedoAction(actionCollection()); + QAction *undo = m_commandStack->createUndoAction(actionCollection()); + + QWidget* w = factory()->container("mainToolBar", this); + if (w) { + if (actionCollection()->action("undo")) + delete actionCollection()->action("undo"); + if (actionCollection()->action("redo")) + delete actionCollection()->action("redo"); + + actionCollection()->addAction("undo", undo); + actionCollection()->addAction("redo", redo); + w->addAction(undo); + w->addAction(redo); + } + m_undoView->setStack(doc->commandStack()); + m_activeDocument = doc; } -void MainWindow::slotPreferences() -{ - //An instance of your dialog could be already created and could be - // cached, in which case you want to display the cached dialog - // instead of creating another one - if ( KConfigDialog::showDialog( "settings" ) ) - return; - - // KConfigDialog didn't find an instance of this dialog, so lets - // create it : - KdenliveSettingsDialog* dialog = new KdenliveSettingsDialog(this); - //connect( dialog, SIGNAL(settingsChanged()), this, SLOT(updateConfiguration()) ); - dialog->show(); +void MainWindow::slotPreferences() { + //An instance of your dialog could be already created and could be + // cached, in which case you want to display the cached dialog + // instead of creating another one + if (KConfigDialog::showDialog("settings")) + return; + + // KConfigDialog didn't find an instance of this dialog, so lets + // create it : + KdenliveSettingsDialog* dialog = new KdenliveSettingsDialog(this); + //connect( dialog, SIGNAL(settingsChanged()), this, SLOT(updateConfiguration()) ); + dialog->show(); } -void MainWindow::slotGotProgressInfo( KUrl url, int progress) { - statusProgressBar->setValue(progress); - if (progress>0) { - statusLabel->setText(tr("Creating Audio Thumbs")); - statusProgressBar->setVisible(true); - } - else { - statusLabel->setText(""); - statusProgressBar->setVisible(false); - } +void MainWindow::slotGotProgressInfo(KUrl url, int progress) { + statusProgressBar->setValue(progress); + if (progress > 0) { + statusLabel->setText(tr("Creating Audio Thumbs")); + statusProgressBar->setVisible(true); + } else { + statusLabel->setText(""); + statusProgressBar->setVisible(false); + } } #include "mainwindow.moc" diff --git a/src/mainwindow.h b/src/mainwindow.h index d38d9561..9ec701c8 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -20,7 +20,7 @@ #ifndef MAINWINDOW_H #define MAINWINDOW_H - + #include #include #include @@ -45,19 +45,18 @@ #include "effectstackview.h" -class MainWindow : public KXmlGuiWindow -{ - Q_OBJECT - - public: - MainWindow(QWidget *parent=0); +class MainWindow : public KXmlGuiWindow { + Q_OBJECT + +public: + MainWindow(QWidget *parent = 0); void parseProfiles(); - protected: +protected: virtual bool queryClose(); - - private: + +private: KTabWidget* m_timelineArea; QProgressBar *statusProgressBar; QLabel* statusLabel; @@ -104,10 +103,10 @@ class MainWindow : public KXmlGuiWindow void readOptions(); void saveOptions(); - public slots: +public slots: void openFile(const KUrl &url); - private slots: +private slots: void newFile(); void activateDocument(); void connectDocument(TrackView*, KdenliveDoc*); @@ -123,8 +122,8 @@ class MainWindow : public KXmlGuiWindow void slotAddEffect(QDomElement effect, GenTime pos = GenTime(), int track = -1); void slotEditProfiles(); void slotEditProjectSettings(); - void slotDisplayActionMessage( QAction *a); - void slotGotProgressInfo( KUrl url, int progress); + void slotDisplayActionMessage(QAction *a); + void slotGotProgressInfo(KUrl url, int progress); }; - + #endif diff --git a/src/monitor.cpp b/src/monitor.cpp index 877de78a..7a888242 100644 --- a/src/monitor.cpp +++ b/src/monitor.cpp @@ -28,192 +28,173 @@ #include "monitor.h" Monitor::Monitor(QString name, MonitorManager *manager, QWidget *parent) - : QWidget(parent), render(NULL), m_monitorManager(manager), m_name(name), m_isActive(false) -{ - ui.setupUi(this); - m_scale = 1; - m_ruler = new SmallRuler(); - QVBoxLayout *layout = new QVBoxLayout; - layout->addWidget( m_ruler); - ui.ruler_frame->setLayout( layout ); - //m_ruler->setPixelPerMark(3); - m_playIcon = KIcon("media-playback-start"); - m_pauseIcon = KIcon("media-playback-pause"); - ui.button_play->setIcon(m_playIcon); - ui.button_rew1->setIcon(KIcon("media-skip-backward")); - ui.button_rew->setIcon(KIcon("media-seek-backward")); - ui.button_fwd1->setIcon(KIcon("media-skip-forward")); - ui.button_fwd->setIcon(KIcon("media-seek-forward")); - connect(m_ruler, SIGNAL(seekRenderer(int)), this, SLOT(slotSeek(int))); - connect(ui.button_rew, SIGNAL(clicked()), this, SLOT(slotRewind())); - connect(ui.button_rew1, SIGNAL(clicked()), this, SLOT(slotRewindOneFrame())); - connect(ui.button_fwd, SIGNAL(clicked()), this, SLOT(slotForward())); - connect(ui.button_fwd1, SIGNAL(clicked()), this, SLOT(slotForwardOneFrame())); - connect(ui.button_play, SIGNAL(clicked()), this, SLOT(slotPlay())); - //if ( render ) return; - render = new Render(m_name, (int) ui.video_frame->winId(), -1, this); - connect(render, SIGNAL(durationChanged(int)), this, SLOT(adjustRulerSize(int))); - connect(render, SIGNAL(rendererPosition(int)), this, SLOT(seekCursor(int))); - connect(render, SIGNAL(rendererStopped(int)), this, SLOT(rendererStopped(int))); - if (name != "clip") { - connect(render, SIGNAL(rendererPosition(int)), this, SIGNAL(renderPosition(int))); - connect(render, SIGNAL(durationChanged(int)), this, SIGNAL(durationChanged(int))); - } - //render->createVideoXWindow(ui.video_frame->winId(), -1); - int width = m_ruler->width(); - m_ruler->setLength(width); - m_ruler->setMaximum(width); - m_length = 0; - - kDebug()<<"/////// BUILDING MONITOR, ID: "<winId(); + : QWidget(parent), render(NULL), m_monitorManager(manager), m_name(name), m_isActive(false) { + ui.setupUi(this); + m_scale = 1; + m_ruler = new SmallRuler(); + QVBoxLayout *layout = new QVBoxLayout; + layout->addWidget(m_ruler); + ui.ruler_frame->setLayout(layout); + //m_ruler->setPixelPerMark(3); + m_playIcon = KIcon("media-playback-start"); + m_pauseIcon = KIcon("media-playback-pause"); + ui.button_play->setIcon(m_playIcon); + ui.button_rew1->setIcon(KIcon("media-skip-backward")); + ui.button_rew->setIcon(KIcon("media-seek-backward")); + ui.button_fwd1->setIcon(KIcon("media-skip-forward")); + ui.button_fwd->setIcon(KIcon("media-seek-forward")); + connect(m_ruler, SIGNAL(seekRenderer(int)), this, SLOT(slotSeek(int))); + connect(ui.button_rew, SIGNAL(clicked()), this, SLOT(slotRewind())); + connect(ui.button_rew1, SIGNAL(clicked()), this, SLOT(slotRewindOneFrame())); + connect(ui.button_fwd, SIGNAL(clicked()), this, SLOT(slotForward())); + connect(ui.button_fwd1, SIGNAL(clicked()), this, SLOT(slotForwardOneFrame())); + connect(ui.button_play, SIGNAL(clicked()), this, SLOT(slotPlay())); + //if ( render ) return; + render = new Render(m_name, (int) ui.video_frame->winId(), -1, this); + connect(render, SIGNAL(durationChanged(int)), this, SLOT(adjustRulerSize(int))); + connect(render, SIGNAL(rendererPosition(int)), this, SLOT(seekCursor(int))); + connect(render, SIGNAL(rendererStopped(int)), this, SLOT(rendererStopped(int))); + if (name != "clip") { + connect(render, SIGNAL(rendererPosition(int)), this, SIGNAL(renderPosition(int))); + connect(render, SIGNAL(durationChanged(int)), this, SIGNAL(durationChanged(int))); + } + //render->createVideoXWindow(ui.video_frame->winId(), -1); + int width = m_ruler->width(); + m_ruler->setLength(width); + m_ruler->setMaximum(width); + m_length = 0; + + kDebug() << "/////// BUILDING MONITOR, ID: " << ui.video_frame->winId(); } // virtual -void Monitor::mousePressEvent ( QMouseEvent * event ) -{ - slotPlay(); +void Monitor::mousePressEvent(QMouseEvent * event) { + slotPlay(); } // virtual -void Monitor::wheelEvent ( QWheelEvent * event ) -{ - if (event->delta() > 0) slotForwardOneFrame(); - else slotRewindOneFrame(); -} - -void Monitor::activateMonitor() -{ - if (!m_isActive) m_monitorManager->activateMonitor(m_name); -} - -void Monitor::slotSeek(int pos) -{ - if (!m_isActive) m_monitorManager->activateMonitor(m_name); - if ( render == NULL ) return; - int realPos = ((double) pos) / m_scale; - render->seekToFrame(realPos); - m_position = realPos; - emit renderPosition(m_position); - ui.monitor_time->setText(m_monitorManager->timecode().getTimecodeFromFrames(m_position)); -} - -void Monitor::slotRewind() -{ - if (!m_isActive) m_monitorManager->activateMonitor(m_name); - double speed = render->playSpeed(); - if ( speed >= 0 ) render->play(-2); - else render->play(speed * 2); - ui.button_play->setChecked(true); - ui.button_play->setIcon(m_pauseIcon); -} - -void Monitor::slotForward() -{ - if (!m_isActive) m_monitorManager->activateMonitor(m_name); - double speed = render->playSpeed(); - if ( speed <= 1 ) render->play(2); - else render->play(speed * 2); - ui.button_play->setChecked(true); - ui.button_play->setIcon(m_pauseIcon); -} - -void Monitor::slotRewindOneFrame() -{ - if (!m_isActive) m_monitorManager->activateMonitor(m_name); - render->play(0); - if (m_position < 1) return; - m_position--; - render->seekToFrame(m_position); - emit renderPosition(m_position); - ui.monitor_time->setText(m_monitorManager->timecode().getTimecodeFromFrames(m_position)); -} - -void Monitor::slotForwardOneFrame() -{ - if (!m_isActive) m_monitorManager->activateMonitor(m_name); - render->play(0); - if (m_position >= m_length) return; - m_position++; - render->seekToFrame(m_position); - emit renderPosition(m_position); - ui.monitor_time->setText(m_monitorManager->timecode().getTimecodeFromFrames(m_position)); -} - -void Monitor::seekCursor(int pos) -{ - if (!m_isActive) m_monitorManager->activateMonitor(m_name); - int rulerPos = (int) (pos * m_scale); - m_position = pos; - ui.monitor_time->setText(m_monitorManager->timecode().getTimecodeFromFrames(pos)); - kDebug()<<"seek: "<slotNewValue(rulerPos); -} - -void Monitor::rendererStopped(int pos) -{ - int rulerPos = (int) (pos * m_scale); - m_ruler->slotNewValue(rulerPos); - m_position = pos; - ui.monitor_time->setText(m_monitorManager->timecode().getTimecodeFromFrames(pos)); - ui.button_play->setChecked(false); - ui.button_play->setIcon(m_playIcon); -} - -void Monitor::initMonitor() -{ - kDebug()<<"/////// INITING MONITOR, ID: "<winId(); +void Monitor::wheelEvent(QWheelEvent * event) { + if (event->delta() > 0) slotForwardOneFrame(); + else slotRewindOneFrame(); +} + +void Monitor::activateMonitor() { + if (!m_isActive) m_monitorManager->activateMonitor(m_name); +} + +void Monitor::slotSeek(int pos) { + if (!m_isActive) m_monitorManager->activateMonitor(m_name); + if (render == NULL) return; + int realPos = ((double) pos) / m_scale; + render->seekToFrame(realPos); + m_position = realPos; + emit renderPosition(m_position); + ui.monitor_time->setText(m_monitorManager->timecode().getTimecodeFromFrames(m_position)); +} + +void Monitor::slotRewind() { + if (!m_isActive) m_monitorManager->activateMonitor(m_name); + double speed = render->playSpeed(); + if (speed >= 0) render->play(-2); + else render->play(speed * 2); + ui.button_play->setChecked(true); + ui.button_play->setIcon(m_pauseIcon); +} + +void Monitor::slotForward() { + if (!m_isActive) m_monitorManager->activateMonitor(m_name); + double speed = render->playSpeed(); + if (speed <= 1) render->play(2); + else render->play(speed * 2); + ui.button_play->setChecked(true); + ui.button_play->setIcon(m_pauseIcon); +} + +void Monitor::slotRewindOneFrame() { + if (!m_isActive) m_monitorManager->activateMonitor(m_name); + render->play(0); + if (m_position < 1) return; + m_position--; + render->seekToFrame(m_position); + emit renderPosition(m_position); + ui.monitor_time->setText(m_monitorManager->timecode().getTimecodeFromFrames(m_position)); +} + +void Monitor::slotForwardOneFrame() { + if (!m_isActive) m_monitorManager->activateMonitor(m_name); + render->play(0); + if (m_position >= m_length) return; + m_position++; + render->seekToFrame(m_position); + emit renderPosition(m_position); + ui.monitor_time->setText(m_monitorManager->timecode().getTimecodeFromFrames(m_position)); +} + +void Monitor::seekCursor(int pos) { + if (!m_isActive) m_monitorManager->activateMonitor(m_name); + int rulerPos = (int)(pos * m_scale); + m_position = pos; + ui.monitor_time->setText(m_monitorManager->timecode().getTimecodeFromFrames(pos)); + kDebug() << "seek: " << pos << ", scale: " << m_scale; + m_ruler->slotNewValue(rulerPos); +} + +void Monitor::rendererStopped(int pos) { + int rulerPos = (int)(pos * m_scale); + m_ruler->slotNewValue(rulerPos); + m_position = pos; + ui.monitor_time->setText(m_monitorManager->timecode().getTimecodeFromFrames(pos)); + ui.button_play->setChecked(false); + ui.button_play->setIcon(m_playIcon); +} + +void Monitor::initMonitor() { + kDebug() << "/////// INITING MONITOR, ID: " << ui.video_frame->winId(); } // virtual -void Monitor::resizeEvent ( QResizeEvent * event ) -{ - adjustRulerSize(-1); - if (render) render->askForRefresh(); +void Monitor::resizeEvent(QResizeEvent * event) { + adjustRulerSize(-1); + if (render) render->askForRefresh(); } -void Monitor::adjustRulerSize(int length) -{ - int width = m_ruler->width(); - m_ruler->setLength(width); - if (length > 0) m_length = length; - m_scale = (double) width / m_length; - if (m_scale == 0) m_scale = 1; - kDebug()<<"RULER WIDT: "<setPixelPerMark(m_scale); - m_ruler->setMaximum(width); - //m_ruler->setLength(length); +void Monitor::adjustRulerSize(int length) { + int width = m_ruler->width(); + m_ruler->setLength(width); + if (length > 0) m_length = length; + m_scale = (double) width / m_length; + if (m_scale == 0) m_scale = 1; + kDebug() << "RULER WIDT: " << width << ", RENDER LENGT: " << m_length << ", SCALE: " << m_scale; + m_ruler->setPixelPerMark(m_scale); + m_ruler->setMaximum(width); + //m_ruler->setLength(length); } -void Monitor::stop() -{ - m_isActive = false; - if (render) render->stop(); +void Monitor::stop() { + m_isActive = false; + if (render) render->stop(); } -void Monitor::start() -{ - m_isActive = true; - if (render) render->start(); +void Monitor::start() { + m_isActive = true; + if (render) render->start(); } -void Monitor::refreshMonitor(bool visible) -{ - if (visible && render) render->askForRefresh(); +void Monitor::refreshMonitor(bool visible) { + if (visible && render) render->askForRefresh(); } -void Monitor::slotPlay() -{ - if ( render == NULL ) return; - if (!m_isActive) m_monitorManager->activateMonitor(m_name); - render->switchPlay(); - ui.button_play->setChecked(true); - ui.button_play->setIcon(m_pauseIcon); +void Monitor::slotPlay() { + if (render == NULL) return; + if (!m_isActive) m_monitorManager->activateMonitor(m_name); + render->switchPlay(); + ui.button_play->setChecked(true); + ui.button_play->setIcon(m_pauseIcon); } -void Monitor::slotSetXml(const QDomElement &e) -{ - if ( render == NULL ) return; +void Monitor::slotSetXml(const QDomElement &e) { + if (render == NULL) return; if (!m_isActive) m_monitorManager->activateMonitor(m_name); QDomDocument doc; QDomElement westley = doc.createElement("westley"); @@ -226,9 +207,8 @@ void Monitor::slotSetXml(const QDomElement &e) } -void Monitor::slotOpenFile(const QString &file) -{ - if ( render == NULL ) return; +void Monitor::slotOpenFile(const QString &file) { + if (render == NULL) return; if (!m_isActive) m_monitorManager->activateMonitor(m_name); QDomDocument doc; QDomElement westley = doc.createElement("westley"); diff --git a/src/monitor.h b/src/monitor.h index c4a667e0..ec1e98b8 100644 --- a/src/monitor.h +++ b/src/monitor.h @@ -30,19 +30,18 @@ class MonitorManager; -class Monitor : public QWidget -{ - Q_OBJECT - - public: - Monitor(QString name, MonitorManager *manager, QWidget *parent=0); +class Monitor : public QWidget { + Q_OBJECT + +public: + Monitor(QString name, MonitorManager *manager, QWidget *parent = 0); Render *render; - virtual void resizeEvent ( QResizeEvent * event ); - protected: - virtual void mousePressEvent ( QMouseEvent * event ); - virtual void wheelEvent ( QWheelEvent * event ); + virtual void resizeEvent(QResizeEvent * event); +protected: + virtual void mousePressEvent(QMouseEvent * event); + virtual void wheelEvent(QWheelEvent * event); - private: +private: Ui::Monitor_UI ui; MonitorManager *m_monitorManager; QString m_name; @@ -54,7 +53,7 @@ class Monitor : public QWidget KIcon m_pauseIcon; bool m_isActive; - private slots: +private slots: void slotPlay(); void adjustRulerSize(int length); void seekCursor(int pos); @@ -64,7 +63,7 @@ class Monitor : public QWidget void slotForward(); void slotRewind(); - public slots: +public slots: void slotOpenFile(const QString &); void slotSetXml(const QDomElement &e); void initMonitor(); @@ -74,7 +73,7 @@ class Monitor : public QWidget void start(); void activateMonitor(); - signals: +signals: void renderPosition(int); void durationChanged(int); }; diff --git a/src/monitormanager.cpp b/src/monitormanager.cpp index 5c676a66..e42d7eb7 100644 --- a/src/monitormanager.cpp +++ b/src/monitormanager.cpp @@ -25,62 +25,54 @@ #include MonitorManager::MonitorManager(QWidget *parent) - : QObject(parent) -{ + : QObject(parent) { } -void MonitorManager::setTimecode(Timecode tc) -{ - m_timecode = tc; +void MonitorManager::setTimecode(Timecode tc) { + m_timecode = tc; } -Timecode MonitorManager::timecode() -{ - return m_timecode; +Timecode MonitorManager::timecode() { + return m_timecode; } -void MonitorManager::initMonitors(Monitor *clipMonitor, Monitor *projectMonitor) -{ - m_clipMonitor = clipMonitor; - m_projectMonitor = projectMonitor; - //QTimer::singleShot(1750, this, SLOT(initClipMonitor())); - initClipMonitor(); - //initProjectMonitor(); +void MonitorManager::initMonitors(Monitor *clipMonitor, Monitor *projectMonitor) { + m_clipMonitor = clipMonitor; + m_projectMonitor = projectMonitor; + //QTimer::singleShot(1750, this, SLOT(initClipMonitor())); + initClipMonitor(); + //initProjectMonitor(); } -void MonitorManager::initClipMonitor() -{ - m_clipMonitor->initMonitor(); - emit connectMonitors(); - //initProjectMonitor(); - //QTimer::singleShot(1500, this, SLOT(initProjectMonitor())); +void MonitorManager::initClipMonitor() { + m_clipMonitor->initMonitor(); + emit connectMonitors(); + //initProjectMonitor(); + //QTimer::singleShot(1500, this, SLOT(initProjectMonitor())); } -void MonitorManager::initProjectMonitor() -{ - //m_clipMonitor->stop(); - m_projectMonitor->initMonitor(); - // activateMonitor("project"); - emit connectMonitors(); +void MonitorManager::initProjectMonitor() { + //m_clipMonitor->stop(); + m_projectMonitor->initMonitor(); + // activateMonitor("project"); + emit connectMonitors(); } -void MonitorManager::activateMonitor(QString name) -{ - if (m_activeMonitor == name) return; - if (name == "clip") { - m_projectMonitor->stop(); - m_clipMonitor->start(); - emit raiseClipMonitor(true); - } - else { - m_clipMonitor->stop(); - m_projectMonitor->start(); - m_projectMonitor->raise(); - emit raiseClipMonitor(false); - } - m_activeMonitor = name; +void MonitorManager::activateMonitor(QString name) { + if (m_activeMonitor == name) return; + if (name == "clip") { + m_projectMonitor->stop(); + m_clipMonitor->start(); + emit raiseClipMonitor(true); + } else { + m_clipMonitor->stop(); + m_projectMonitor->start(); + m_projectMonitor->raise(); + emit raiseClipMonitor(false); + } + m_activeMonitor = name; } #include "monitormanager.moc" diff --git a/src/monitormanager.h b/src/monitormanager.h index 4ce7db23..129a49f0 100644 --- a/src/monitormanager.h +++ b/src/monitormanager.h @@ -26,30 +26,29 @@ class Monitor; -class MonitorManager : public QObject -{ - Q_OBJECT - - public: - MonitorManager(QWidget *parent=0); +class MonitorManager : public QObject { + Q_OBJECT + +public: + MonitorManager(QWidget *parent = 0); void initMonitors(Monitor *clipMonitor, Monitor *projectMonitor); Timecode timecode(); void setTimecode(Timecode tc); - public slots: +public slots: void activateMonitor(QString name = QString::null); - private: +private: Monitor *m_clipMonitor; Monitor *m_projectMonitor; QString m_activeMonitor; Timecode m_timecode; - private slots: +private slots: void initProjectMonitor(); void initClipMonitor(); - signals: +signals: void connectMonitors(); void raiseClipMonitor(bool); diff --git a/src/moveclipcommand.cpp b/src/moveclipcommand.cpp index 9b35f85d..5c6c124e 100644 --- a/src/moveclipcommand.cpp +++ b/src/moveclipcommand.cpp @@ -22,24 +22,22 @@ #include "moveclipcommand.h" MoveClipCommand::MoveClipCommand(CustomTrackView *view, const QPointF startPos, const QPointF endPos, bool doIt) - : m_view(view), m_startPos(startPos), m_endPos(endPos), m_doIt(doIt) { - setText(i18n("Move clip")); - } + : m_view(view), m_startPos(startPos), m_endPos(endPos), m_doIt(doIt) { + setText(i18n("Move clip")); +} -// virtual -void MoveClipCommand::undo() -{ +// virtual +void MoveClipCommand::undo() { // kDebug()<<"---- undoing action"; - m_doIt = true; - if (m_doIt) m_view->moveClip(m_endPos, m_startPos); + m_doIt = true; + if (m_doIt) m_view->moveClip(m_endPos, m_startPos); } -// virtual -void MoveClipCommand::redo() -{ -kDebug()<<"---- redoing action"; - if (m_doIt) m_view->moveClip(m_startPos, m_endPos); - m_doIt = true; +// virtual +void MoveClipCommand::redo() { + kDebug() << "---- redoing action"; + if (m_doIt) m_view->moveClip(m_startPos, m_endPos); + m_doIt = true; } #include "moveclipcommand.moc" diff --git a/src/moveclipcommand.h b/src/moveclipcommand.h index 023660de..d31bb2d6 100644 --- a/src/moveclipcommand.h +++ b/src/moveclipcommand.h @@ -30,19 +30,18 @@ #include "projectlist.h" #include "customtrackview.h" -class MoveClipCommand : public QUndoCommand - { - public: - MoveClipCommand(CustomTrackView *view, const QPointF startPos, const QPointF endPos, bool doIt); +class MoveClipCommand : public QUndoCommand { +public: + MoveClipCommand(CustomTrackView *view, const QPointF startPos, const QPointF endPos, bool doIt); virtual void undo(); virtual void redo(); - private: - CustomTrackView *m_view; - QPointF m_startPos; - QPointF m_endPos; - bool m_doIt; - }; +private: + CustomTrackView *m_view; + QPointF m_startPos; + QPointF m_endPos; + bool m_doIt; +}; #endif diff --git a/src/parameterplotter.cpp b/src/parameterplotter.cpp index 988e9036..527e06bc 100644 --- a/src/parameterplotter.cpp +++ b/src/parameterplotter.cpp @@ -23,20 +23,20 @@ #include #include -ParameterPlotter::ParameterPlotter (QWidget *parent):KPlotWidget (parent){ - setAntialiasing(true); - setLeftPadding(20); - setRightPadding(10); - setTopPadding(10); - setBottomPadding(20); - movepoint=NULL; - colors << Qt::white << Qt::red << Qt::green << Qt::blue << Qt::magenta << Qt::gray << Qt::cyan; - maxy=0; - m_moveX=false; - m_moveY=true; - m_moveTimeline=true; - m_newPoints=false; - activeIndexPlot=-1; +ParameterPlotter::ParameterPlotter(QWidget *parent): KPlotWidget(parent) { + setAntialiasing(true); + setLeftPadding(20); + setRightPadding(10); + setTopPadding(10); + setBottomPadding(20); + movepoint = NULL; + colors << Qt::white << Qt::red << Qt::green << Qt::blue << Qt::magenta << Qt::gray << Qt::cyan; + maxy = 0; + m_moveX = false; + m_moveY = true; + m_moveTimeline = true; + m_newPoints = false; + activeIndexPlot = -1; } /* Lines @@ -52,225 +52,225 @@ ParameterPlotter::ParameterPlotter (QWidget *parent):KPlotWidget (parent){ */ -void ParameterPlotter::setPointLists(const QDomElement& d,int startframe,int endframe){ - - //QListIterator > > nameit(params); - itemParameter=d; - QDomNodeList namenode = d.elementsByTagName("parameter"); - - max_y=0; - min_y=0; - removeAllPlotObjects (); - stretchFactors.clear(); - parameterNameList.clear(); - plotobjects.clear(); - - QString dat; - QTextStream stre(&dat); - d.save(stre,2); - kDebug() << dat; - - if ( namenode.count() ){ - - - QDomNode pa=namenode.item(0); - QDomNode na=pa.firstChildElement("name"); - - parameterNameList << pa.attributes().namedItem("name").nodeValue().split(";"); - emit parameterList(parameterNameList); - - //max_y=pa.attributes().namedItem("max").nodeValue().toInt(); - //int val=pa.attributes().namedItem("value").nodeValue().toInt(); - QStringList defaults; - if (pa.attributes().namedItem("start").nodeValue().contains(";")) - defaults=pa.attributes().namedItem("start").nodeValue().split(";"); - else if (pa.attributes().namedItem("value").nodeValue().contains(";")) - defaults=pa.attributes().namedItem("value").nodeValue().split(";"); - else if (pa.attributes().namedItem("default").nodeValue().contains(";")) - defaults=pa.attributes().namedItem("default").nodeValue().split(";"); - QStringList maxv=pa.attributes().namedItem("max").nodeValue().split(";"); - QStringList minv=pa.attributes().namedItem("max").nodeValue().split(";"); - for (int i=0;i minv[i].toInt()) min_y=minv[i].toInt(); - } - - for (int i=0;isetShowLines(true); - if (!stretchFactors.contains(i) ){ - if ( maxv[i].toInt()!=0) - stretchFactors[i]=max_y/maxv[i].toInt(); - else - stretchFactors[i]=1.0; - } - if (defaults[i].toDouble()>max_y) - defaults[i]=max_y; - plot->addPoint(startframe,defaults[i].toInt()*stretchFactors[i],parameterNameList[i]); - //add keyframes here - plot->addPoint(endframe,defaults[i].toInt()*stretchFactors[i]); - - plotobjects.append(plot); - } - - /*TODO keyframes - while (pointit.hasNext()){ - pointit.next(); - plot->addPoint(QPointF(pointit.key(),pointit.value().toDouble()),item.first,1); - if (pointit.value().toInt() >maxy) - max_y=pointit.value().toInt(); - }*/ - - } - maxx=endframe; - maxy=max_y; - setLimits(-1,endframe+1,min_y-10,maxy+10); - addPlotObjects(plotobjects); +void ParameterPlotter::setPointLists(const QDomElement& d, int startframe, int endframe) { + + //QListIterator > > nameit(params); + itemParameter = d; + QDomNodeList namenode = d.elementsByTagName("parameter"); + + max_y = 0; + min_y = 0; + removeAllPlotObjects(); + stretchFactors.clear(); + parameterNameList.clear(); + plotobjects.clear(); + + QString dat; + QTextStream stre(&dat); + d.save(stre, 2); + kDebug() << dat; + + if (namenode.count()) { + + + QDomNode pa = namenode.item(0); + QDomNode na = pa.firstChildElement("name"); + + parameterNameList << pa.attributes().namedItem("name").nodeValue().split(";"); + emit parameterList(parameterNameList); + + //max_y=pa.attributes().namedItem("max").nodeValue().toInt(); + //int val=pa.attributes().namedItem("value").nodeValue().toInt(); + QStringList defaults; + if (pa.attributes().namedItem("start").nodeValue().contains(";")) + defaults = pa.attributes().namedItem("start").nodeValue().split(";"); + else if (pa.attributes().namedItem("value").nodeValue().contains(";")) + defaults = pa.attributes().namedItem("value").nodeValue().split(";"); + else if (pa.attributes().namedItem("default").nodeValue().contains(";")) + defaults = pa.attributes().namedItem("default").nodeValue().split(";"); + QStringList maxv = pa.attributes().namedItem("max").nodeValue().split(";"); + QStringList minv = pa.attributes().namedItem("max").nodeValue().split(";"); + for (int i = 0;i < maxv.size();i++) { + if (max_y < maxv[i].toInt()) max_y = maxv[i].toInt(); + if (min_y > minv[i].toInt()) min_y = minv[i].toInt(); + } + + for (int i = 0;i < parameterNameList.count();i++) { + KPlotObject *plot = new KPlotObject(colors[plotobjects.size()%colors.size()]); + plot->setShowLines(true); + if (!stretchFactors.contains(i)) { + if (maxv[i].toInt() != 0) + stretchFactors[i] = max_y / maxv[i].toInt(); + else + stretchFactors[i] = 1.0; + } + if (defaults[i].toDouble() > max_y) + defaults[i] = max_y; + plot->addPoint(startframe, defaults[i].toInt()*stretchFactors[i], parameterNameList[i]); + //add keyframes here + plot->addPoint(endframe, defaults[i].toInt()*stretchFactors[i]); + + plotobjects.append(plot); + } + + /*TODO keyframes + while (pointit.hasNext()){ + pointit.next(); + plot->addPoint(QPointF(pointit.key(),pointit.value().toDouble()),item.first,1); + if (pointit.value().toInt() >maxy) + max_y=pointit.value().toInt(); + }*/ + + } + maxx = endframe; + maxy = max_y; + setLimits(-1, endframe + 1, min_y - 10, maxy + 10); + addPlotObjects(plotobjects); } -void ParameterPlotter::createParametersNew(){ - - QList plotobjs=plotObjects(); - if (plotobjs.size() != parameterNameList.size() ){ - kDebug() << "ERROR size not equal"; - } - QDomNodeList namenode = itemParameter.elementsByTagName("parameter"); - QString paramlist; - QTextStream txtstr(¶mlist); - QDomNode pa=namenode.item(0); - if (namenode.count()>0){ - for (int i=0;i points=plotobjs[i]->points(); - foreach (KPlotPoint *o,points){ - txtstr << (int)o->y() ; - break;//first no keyframes - } - if (i+1!=plotobjs.count()) - txtstr<< ";"; - } - } - pa.attributes().namedItem("value").setNodeValue(paramlist); - pa.attributes().namedItem("start").setNodeValue(paramlist); - emit parameterChanged(itemParameter); - +void ParameterPlotter::createParametersNew() { + + QList plotobjs = plotObjects(); + if (plotobjs.size() != parameterNameList.size()) { + kDebug() << "ERROR size not equal"; + } + QDomNodeList namenode = itemParameter.elementsByTagName("parameter"); + QString paramlist; + QTextStream txtstr(¶mlist); + QDomNode pa = namenode.item(0); + if (namenode.count() > 0) { + for (int i = 0;i < plotobjs.count();i++) { + QList points = plotobjs[i]->points(); + foreach(KPlotPoint *o, points) { + txtstr << (int)o->y() ; + break;//first no keyframes + } + if (i + 1 != plotobjs.count()) + txtstr << ";"; + } + } + pa.attributes().namedItem("value").setNodeValue(paramlist); + pa.attributes().namedItem("start").setNodeValue(paramlist); + emit parameterChanged(itemParameter); + } -void ParameterPlotter::mouseMoveEvent ( QMouseEvent * event ) { - - if (movepoint!=NULL){ - QList list= pointsUnderPoint (event->pos()-QPoint(leftPadding(), topPadding() ) ) ; - int i=0,j=-1; - foreach (KPlotObject *o, plotObjects() ){ - QList points=o->points(); - for(int p=0;ppos()-oldmousepoint; - double newy=movepoint->y()-delta.y()*dataRect().height()/pixRect().height(); - if (m_moveY && newy>min_y && newysetY(newy); - if (p>0 && px()+delta.x()*dataRect().width()/pixRect().width(); - if ( newx>points[p-1]->x() && newxx() && m_moveX) - movepoint->setX(movepoint->x()+delta.x()*dataRect().width()/pixRect().width() ); - } - if (m_moveTimeline && (m_moveX|| m_moveY) ) - emit updateFrame(0); - replacePlotObject(i,o); - oldmousepoint=event->pos(); - } - } - i++; - } - createParametersNew(); - } +void ParameterPlotter::mouseMoveEvent(QMouseEvent * event) { + + if (movepoint != NULL) { + QList list = pointsUnderPoint(event->pos() - QPoint(leftPadding(), topPadding())) ; + int i = 0, j = -1; + foreach(KPlotObject *o, plotObjects()) { + QList points = o->points(); + for (int p = 0;p < points.size();p++) { + if (points[p] == movepoint && (activeIndexPlot == -1 || activeIndexPlot == i)) { + QPoint delta = event->pos() - oldmousepoint; + double newy = movepoint->y() - delta.y() * dataRect().height() / pixRect().height(); + if (m_moveY && newy > min_y && newy < max_y) + movepoint->setY(newy); + if (p > 0 && p < points.size() - 1) { + double newx = movepoint->x() + delta.x() * dataRect().width() / pixRect().width(); + if (newx > points[p-1]->x() && newx < points[p+1]->x() && m_moveX) + movepoint->setX(movepoint->x() + delta.x()*dataRect().width() / pixRect().width()); + } + if (m_moveTimeline && (m_moveX || m_moveY)) + emit updateFrame(0); + replacePlotObject(i, o); + oldmousepoint = event->pos(); + } + } + i++; + } + createParametersNew(); + } } -void ParameterPlotter::replot(const QString & name){ - //removeAllPlotObjects(); - int i=0; - bool drawAll=name.isEmpty() || name=="all"; - activeIndexPlot=-1; - - foreach (KPlotObject* p, plotObjects() ){ - p->setShowPoints(drawAll || parameterNameList[i]==name); - p->setShowLines(drawAll || parameterNameList[i]==name); - QPen pen=(drawAll || parameterNameList[i]==name ? QPen(Qt::SolidLine) : QPen(Qt::NoPen) ); - pen.setColor(p->linePen().color()); - p->setLabelPen(pen); - if ( parameterNameList[i]==name ) - activeIndexPlot = i; - replacePlotObject(i++,p); - } +void ParameterPlotter::replot(const QString & name) { + //removeAllPlotObjects(); + int i = 0; + bool drawAll = name.isEmpty() || name == "all"; + activeIndexPlot = -1; + + foreach(KPlotObject* p, plotObjects()) { + p->setShowPoints(drawAll || parameterNameList[i] == name); + p->setShowLines(drawAll || parameterNameList[i] == name); + QPen pen = (drawAll || parameterNameList[i] == name ? QPen(Qt::SolidLine) : QPen(Qt::NoPen)); + pen.setColor(p->linePen().color()); + p->setLabelPen(pen); + if (parameterNameList[i] == name) + activeIndexPlot = i; + replacePlotObject(i++, p); + } } -void ParameterPlotter::mousePressEvent ( QMouseEvent * event ) { - //topPadding and other padding can be wrong and this (i hope) will be correctet in newer kde versions - QPoint inPlot=event->pos()-QPoint(leftPadding(), topPadding() ); - QList list= pointsUnderPoint (inPlot ) ; - if (event->button()==Qt::LeftButton){ - if (list.size() > 0){ - movepoint=list[0]; - oldmousepoint=event->pos(); - }else{ - if (m_newPoints && activeIndexPlot>=0){ - //setup new points - KPlotObject* p=plotObjects()[activeIndexPlot]; - QList points=p->points(); - QList newpoints; - - double newx=inPlot.x()*dataRect().width()/pixRect().width(); - double newy=(height()-inPlot.y()-bottomPadding()-topPadding() )*dataRect().height()/pixRect().height(); - bool inserted=false; - foreach (KPlotPoint* pt,points){ - if (pt->x() >newx && !inserted){ - newpoints.append(QPointF(newx,newy)); - inserted=true; - } - newpoints.append(QPointF(pt->x(),pt->y())); - } - p->clearPoints(); - foreach (QPointF qf, newpoints ){ - p->addPoint(qf); - } - replacePlotObject(activeIndexPlot,p); - } - movepoint=NULL; - } - }else if (event->button()==Qt::LeftButton){ - //menu for deleting or exact setup of point - } +void ParameterPlotter::mousePressEvent(QMouseEvent * event) { + //topPadding and other padding can be wrong and this (i hope) will be correctet in newer kde versions + QPoint inPlot = event->pos() - QPoint(leftPadding(), topPadding()); + QList list = pointsUnderPoint(inPlot) ; + if (event->button() == Qt::LeftButton) { + if (list.size() > 0) { + movepoint = list[0]; + oldmousepoint = event->pos(); + } else { + if (m_newPoints && activeIndexPlot >= 0) { + //setup new points + KPlotObject* p = plotObjects()[activeIndexPlot]; + QList points = p->points(); + QList newpoints; + + double newx = inPlot.x() * dataRect().width() / pixRect().width(); + double newy = (height() - inPlot.y() - bottomPadding() - topPadding()) * dataRect().height() / pixRect().height(); + bool inserted = false; + foreach(KPlotPoint* pt, points) { + if (pt->x() > newx && !inserted) { + newpoints.append(QPointF(newx, newy)); + inserted = true; + } + newpoints.append(QPointF(pt->x(), pt->y())); + } + p->clearPoints(); + foreach(QPointF qf, newpoints) { + p->addPoint(qf); + } + replacePlotObject(activeIndexPlot, p); + } + movepoint = NULL; + } + } else if (event->button() == Qt::LeftButton) { + //menu for deleting or exact setup of point + } } -void ParameterPlotter::setMoveX(bool b){ - m_moveX=b; +void ParameterPlotter::setMoveX(bool b) { + m_moveX = b; } -void ParameterPlotter::setMoveY(bool b){ - m_moveY=b; +void ParameterPlotter::setMoveY(bool b) { + m_moveY = b; } -void ParameterPlotter::setMoveTimeLine(bool b){ - m_moveTimeline=b; +void ParameterPlotter::setMoveTimeLine(bool b) { + m_moveTimeline = b; } -void ParameterPlotter::setNewPoints(bool b){ - m_newPoints=b; +void ParameterPlotter::setNewPoints(bool b) { + m_newPoints = b; } -bool ParameterPlotter::isMoveX(){ - return m_moveX; +bool ParameterPlotter::isMoveX() { + return m_moveX; } -bool ParameterPlotter::isMoveY(){ - return m_moveY; +bool ParameterPlotter::isMoveY() { + return m_moveY; } -bool ParameterPlotter::isMoveTimeline(){ - return m_moveTimeline; +bool ParameterPlotter::isMoveTimeline() { + return m_moveTimeline; } -bool ParameterPlotter::isNewPoints(){ - return m_newPoints; +bool ParameterPlotter::isNewPoints() { + return m_newPoints; } diff --git a/src/parameterplotter.h b/src/parameterplotter.h index bee6e45c..e2f64f05 100644 --- a/src/parameterplotter.h +++ b/src/parameterplotter.h @@ -20,40 +20,40 @@ #include class ParameterPlotter : public KPlotWidget { - Q_OBJECT - public: - ParameterPlotter (QWidget *parent=0); - virtual ~ParameterPlotter(){} - void setMoveX(bool); - void setMoveY(bool); - void setMoveTimeLine(bool); - void setNewPoints(bool); - bool isMoveX(); - bool isMoveY(); - bool isMoveTimeline(); - bool isNewPoints(); - void replot(const QString& name=""); - private: - KPlotPoint* movepoint; - int activeIndexPlot; - bool m_moveX,m_moveY,m_moveTimeline,m_newPoints; - QPoint oldmousepoint; - int maxx,maxy; - QStringList parameterNameList; - void createParametersNew(); - QList plotobjects; - QMap stretchFactors; - QList colors; - QDomElement itemParameter; - int max_y,min_y; - protected: - void mouseMoveEvent ( QMouseEvent * event ); - void mousePressEvent ( QMouseEvent * event ); - public slots: - void setPointLists(const QDomElement&,int ,int); - signals: - void parameterChanged(QDomElement ); - void updateFrame(int); - void parameterList(QStringList); - + Q_OBJECT +public: + ParameterPlotter(QWidget *parent = 0); + virtual ~ParameterPlotter() {} + void setMoveX(bool); + void setMoveY(bool); + void setMoveTimeLine(bool); + void setNewPoints(bool); + bool isMoveX(); + bool isMoveY(); + bool isMoveTimeline(); + bool isNewPoints(); + void replot(const QString& name = ""); +private: + KPlotPoint* movepoint; + int activeIndexPlot; + bool m_moveX, m_moveY, m_moveTimeline, m_newPoints; + QPoint oldmousepoint; + int maxx, maxy; + QStringList parameterNameList; + void createParametersNew(); + QList plotobjects; + QMap stretchFactors; + QList colors; + QDomElement itemParameter; + int max_y, min_y; +protected: + void mouseMoveEvent(QMouseEvent * event); + void mousePressEvent(QMouseEvent * event); +public slots: + void setPointLists(const QDomElement&, int , int); +signals: + void parameterChanged(QDomElement); + void updateFrame(int); + void parameterList(QStringList); + }; diff --git a/src/profilesdialog.cpp b/src/profilesdialog.cpp index 0a471c08..9e07d55a 100644 --- a/src/profilesdialog.cpp +++ b/src/profilesdialog.cpp @@ -25,157 +25,151 @@ #include "kdenlivesettings.h" #include "profilesdialog.h" -ProfilesDialog::ProfilesDialog(QWidget * parent): QDialog(parent), m_isCustomProfile(false) -{ - m_view.setupUi(this); - - QStringList profilesFilter; - profilesFilter<<"*"; - - // List the Mlt profiles - m_mltProfilesList = QDir(KdenliveSettings::mltpath()).entryList(profilesFilter, QDir::Files); - m_view.profiles_list->addItems(m_mltProfilesList); - - // List custom profiles - QStringList customProfiles = KGlobal::dirs()->findDirs("appdata", "profiles"); - for (int i = 0; i < customProfiles.size(); ++i) - m_customProfilesList << QDir(customProfiles.at(i)).entryList(profilesFilter, QDir::Files); - m_view.profiles_list->addItems(m_customProfilesList); - - if (!KdenliveSettings::default_profile().isEmpty()) { - int ix = m_view.profiles_list->findText(KdenliveSettings::default_profile()); - m_view.profiles_list->setCurrentIndex(ix); - } - slotUpdateDisplay(); - connect(m_view.profiles_list, SIGNAL(currentIndexChanged( int )), this, SLOT(slotUpdateDisplay())); +ProfilesDialog::ProfilesDialog(QWidget * parent): QDialog(parent), m_isCustomProfile(false) { + m_view.setupUi(this); + + QStringList profilesFilter; + profilesFilter << "*"; + + // List the Mlt profiles + m_mltProfilesList = QDir(KdenliveSettings::mltpath()).entryList(profilesFilter, QDir::Files); + m_view.profiles_list->addItems(m_mltProfilesList); + + // List custom profiles + QStringList customProfiles = KGlobal::dirs()->findDirs("appdata", "profiles"); + for (int i = 0; i < customProfiles.size(); ++i) + m_customProfilesList << QDir(customProfiles.at(i)).entryList(profilesFilter, QDir::Files); + m_view.profiles_list->addItems(m_customProfilesList); + + if (!KdenliveSettings::default_profile().isEmpty()) { + int ix = m_view.profiles_list->findText(KdenliveSettings::default_profile()); + m_view.profiles_list->setCurrentIndex(ix); + } + slotUpdateDisplay(); + connect(m_view.profiles_list, SIGNAL(currentIndexChanged(int)), this, SLOT(slotUpdateDisplay())); } // static -QStringList ProfilesDialog::getProfileNames() -{ - QStringList profilesNames; - QStringList profilesFiles; - QStringList profilesFilter; - profilesFilter<<"*"; - - // List the Mlt profiles - profilesFiles = QDir(KdenliveSettings::mltpath()).entryList(profilesFilter, QDir::Files); - for (int i = 0; i < profilesFiles.size(); ++i) { - KConfig confFile(KdenliveSettings::mltpath() + "/" + profilesFiles.at(i)); - QString desc = confFile.entryMap().value("description"); - if (!desc.isEmpty()) profilesNames.append(desc); - } - - // List custom profiles - QStringList customProfiles = KGlobal::dirs()->findDirs("appdata", "profiles"); - for (int i = 0; i < customProfiles.size(); ++i) { - profilesFiles = QDir(customProfiles.at(i)).entryList(profilesFilter, QDir::Files); +QStringList ProfilesDialog::getProfileNames() { + QStringList profilesNames; + QStringList profilesFiles; + QStringList profilesFilter; + profilesFilter << "*"; + + // List the Mlt profiles + profilesFiles = QDir(KdenliveSettings::mltpath()).entryList(profilesFilter, QDir::Files); for (int i = 0; i < profilesFiles.size(); ++i) { - KConfig confFile(customProfiles.at(i) + "/" + profilesFiles.at(i)); - QString desc = confFile.entryMap().value("description"); - if (!desc.isEmpty()) profilesNames.append(desc); + KConfig confFile(KdenliveSettings::mltpath() + "/" + profilesFiles.at(i)); + QString desc = confFile.entryMap().value("description"); + if (!desc.isEmpty()) profilesNames.append(desc); + } + + // List custom profiles + QStringList customProfiles = KGlobal::dirs()->findDirs("appdata", "profiles"); + for (int i = 0; i < customProfiles.size(); ++i) { + profilesFiles = QDir(customProfiles.at(i)).entryList(profilesFilter, QDir::Files); + for (int i = 0; i < profilesFiles.size(); ++i) { + KConfig confFile(customProfiles.at(i) + "/" + profilesFiles.at(i)); + QString desc = confFile.entryMap().value("description"); + if (!desc.isEmpty()) profilesNames.append(desc); + } } - } - return profilesNames; + return profilesNames; } // static -QMap< QString, QString > ProfilesDialog::getSettingsFromFile(const QString path) -{ - QStringList profilesNames; - QStringList profilesFiles; - QStringList profilesFilter; - profilesFilter<<"*"; - - // List the Mlt profiles - profilesFiles = QDir(KdenliveSettings::mltpath()).entryList(profilesFilter, QDir::Files); - for (int i = 0; i < profilesFiles.size(); ++i) { - if (profilesFiles.at(i) == path) { - KConfig confFile(KdenliveSettings::mltpath() + "/" + profilesFiles.at(i)); - return confFile.entryMap(); +QMap< QString, QString > ProfilesDialog::getSettingsFromFile(const QString path) { + QStringList profilesNames; + QStringList profilesFiles; + QStringList profilesFilter; + profilesFilter << "*"; + + // List the Mlt profiles + profilesFiles = QDir(KdenliveSettings::mltpath()).entryList(profilesFilter, QDir::Files); + for (int i = 0; i < profilesFiles.size(); ++i) { + if (profilesFiles.at(i) == path) { + KConfig confFile(KdenliveSettings::mltpath() + "/" + profilesFiles.at(i)); + return confFile.entryMap(); + } } - } - - // List custom profiles - QStringList customProfiles = KGlobal::dirs()->findDirs("appdata", "profiles"); - for (int i = 0; i < customProfiles.size(); ++i) { - QStringList profiles = QDir(customProfiles.at(i)).entryList(profilesFilter, QDir::Files); - for (int i = 0; i < profiles.size(); ++i) { - if (profiles.at(i) == path) { - KConfig confFile(customProfiles.at(i) + "/" + profiles.at(i)); - return confFile.entryMap(); - } + + // List custom profiles + QStringList customProfiles = KGlobal::dirs()->findDirs("appdata", "profiles"); + for (int i = 0; i < customProfiles.size(); ++i) { + QStringList profiles = QDir(customProfiles.at(i)).entryList(profilesFilter, QDir::Files); + for (int i = 0; i < profiles.size(); ++i) { + if (profiles.at(i) == path) { + KConfig confFile(customProfiles.at(i) + "/" + profiles.at(i)); + return confFile.entryMap(); + } + } } - } - return QMap< QString, QString >(); + return QMap< QString, QString >(); } // static -QMap< QString, QString > ProfilesDialog::getSettingsForProfile(const QString profileName) -{ - QStringList profilesNames; - QStringList profilesFiles; - QStringList profilesFilter; - profilesFilter<<"*"; - - // List the Mlt profiles - profilesFiles = QDir(KdenliveSettings::mltpath()).entryList(profilesFilter, QDir::Files); - for (int i = 0; i < profilesFiles.size(); ++i) { - KConfig confFile(KdenliveSettings::mltpath() + "/" + profilesFiles.at(i)); - QMap< QString, QString > values = confFile.entryMap(); - if (values.value("description") == profileName) return values; - } - - // List custom profiles - QStringList customProfiles = KGlobal::dirs()->findDirs("appdata", "profiles"); - for (int i = 0; i < customProfiles.size(); ++i) { - QStringList profiles = QDir(customProfiles.at(i)).entryList(profilesFilter, QDir::Files); - for (int i = 0; i < profiles.size(); ++i) { - KConfig confFile(customProfiles.at(i) + "/" + profiles.at(i)); - QMap< QString, QString > values = confFile.entryMap(); - if (values.value("description") == profileName) return values; +QMap< QString, QString > ProfilesDialog::getSettingsForProfile(const QString profileName) { + QStringList profilesNames; + QStringList profilesFiles; + QStringList profilesFilter; + profilesFilter << "*"; + + // List the Mlt profiles + profilesFiles = QDir(KdenliveSettings::mltpath()).entryList(profilesFilter, QDir::Files); + for (int i = 0; i < profilesFiles.size(); ++i) { + KConfig confFile(KdenliveSettings::mltpath() + "/" + profilesFiles.at(i)); + QMap< QString, QString > values = confFile.entryMap(); + if (values.value("description") == profileName) return values; } - } - return QMap< QString, QString >(); + + // List custom profiles + QStringList customProfiles = KGlobal::dirs()->findDirs("appdata", "profiles"); + for (int i = 0; i < customProfiles.size(); ++i) { + QStringList profiles = QDir(customProfiles.at(i)).entryList(profilesFilter, QDir::Files); + for (int i = 0; i < profiles.size(); ++i) { + KConfig confFile(customProfiles.at(i) + "/" + profiles.at(i)); + QMap< QString, QString > values = confFile.entryMap(); + if (values.value("description") == profileName) return values; + } + } + return QMap< QString, QString >(); } -void ProfilesDialog::slotUpdateDisplay() -{ - QString currentProfile = m_view.profiles_list->currentText(); - QString currentProfilePath; - if (m_mltProfilesList.indexOf(currentProfile) != -1) { - currentProfilePath = KdenliveSettings::mltpath() + "/" + currentProfile; - m_isCustomProfile = false; - } - else { - m_isCustomProfile = true; - QStringList customProfiles = KGlobal::dirs()->findDirs("appdata", "mltprofiles"); - QStringList profilesFilter; - profilesFilter<<"*"; - int i; - for (i = 0; i < customProfiles.size(); ++i) { - QStringList profs = QDir(customProfiles.at(i)).entryList(profilesFilter, QDir::Files); - if (profs.indexOf(currentProfile) != -1) break; +void ProfilesDialog::slotUpdateDisplay() { + QString currentProfile = m_view.profiles_list->currentText(); + QString currentProfilePath; + if (m_mltProfilesList.indexOf(currentProfile) != -1) { + currentProfilePath = KdenliveSettings::mltpath() + "/" + currentProfile; + m_isCustomProfile = false; + } else { + m_isCustomProfile = true; + QStringList customProfiles = KGlobal::dirs()->findDirs("appdata", "mltprofiles"); + QStringList profilesFilter; + profilesFilter << "*"; + int i; + for (i = 0; i < customProfiles.size(); ++i) { + QStringList profs = QDir(customProfiles.at(i)).entryList(profilesFilter, QDir::Files); + if (profs.indexOf(currentProfile) != -1) break; + } + currentProfilePath = customProfiles.at(i) + "/" + currentProfile; } - currentProfilePath = customProfiles.at(i) + "/" + currentProfile; - } - m_view.button_delete->setEnabled(m_isCustomProfile); - m_view.properties->setEnabled(m_isCustomProfile); - - KConfig confFile(currentProfilePath); - QMap< QString, QString > values = confFile.entryMap(); - m_view.description->setText(values.value("description")); - m_view.size_w->setValue(values.value("width").toInt()); - m_view.size_h->setValue(values.value("height").toInt()); - m_view.aspect_num->setValue(values.value("sample_aspect_num").toInt()); - m_view.aspect_den->setValue(values.value("sample_aspect_den").toInt()); - m_view.display_num->setValue(values.value("display_aspect_num").toInt()); - m_view.display_den->setValue(values.value("display_aspect_den").toInt()); - m_view.frame_num->setValue(values.value("frame_rate_num").toInt()); - m_view.frame_den->setValue(values.value("frame_rate_den").toInt()); - m_view.progressive->setChecked(values.value("progressive").toInt()); + m_view.button_delete->setEnabled(m_isCustomProfile); + m_view.properties->setEnabled(m_isCustomProfile); + + KConfig confFile(currentProfilePath); + QMap< QString, QString > values = confFile.entryMap(); + m_view.description->setText(values.value("description")); + m_view.size_w->setValue(values.value("width").toInt()); + m_view.size_h->setValue(values.value("height").toInt()); + m_view.aspect_num->setValue(values.value("sample_aspect_num").toInt()); + m_view.aspect_den->setValue(values.value("sample_aspect_den").toInt()); + m_view.display_num->setValue(values.value("display_aspect_num").toInt()); + m_view.display_den->setValue(values.value("display_aspect_den").toInt()); + m_view.frame_num->setValue(values.value("frame_rate_num").toInt()); + m_view.frame_den->setValue(values.value("frame_rate_den").toInt()); + m_view.progressive->setChecked(values.value("progressive").toInt()); } diff --git a/src/profilesdialog.h b/src/profilesdialog.h index 8c5c6721..d0039b0a 100644 --- a/src/profilesdialog.h +++ b/src/profilesdialog.h @@ -25,21 +25,20 @@ #include "ui_profiledialog_ui.h" -class ProfilesDialog : public QDialog -{ - Q_OBJECT - - public: +class ProfilesDialog : public QDialog { + Q_OBJECT + +public: ProfilesDialog(QWidget * parent = 0); - static QStringList getProfileNames(); - static QMap< QString, QString > getSettingsForProfile(const QString profileName); - static QMap< QString, QString > getSettingsFromFile(const QString path); + static QStringList getProfileNames(); + static QMap< QString, QString > getSettingsForProfile(const QString profileName); + static QMap< QString, QString > getSettingsFromFile(const QString path); - private slots: +private slots: void slotUpdateDisplay(); - private: +private: Ui::ProfilesDialog_UI m_view; QStringList m_mltProfilesList; QStringList m_customProfilesList; diff --git a/src/projectitem.cpp b/src/projectitem.cpp index 287c27ba..f93c84c3 100644 --- a/src/projectitem.cpp +++ b/src/projectitem.cpp @@ -32,274 +32,258 @@ #include "timecode.h" - const int NameRole = Qt::UserRole; - const int DurationRole = NameRole + 1; - const int UsageRole = NameRole + 2; +const int NameRole = Qt::UserRole; +const int DurationRole = NameRole + 1; +const int UsageRole = NameRole + 2; ProjectItem::ProjectItem(QTreeWidget * parent, const QStringList & strings, QDomElement xml, int clipId) - : QTreeWidgetItem(parent, strings, QTreeWidgetItem::UserType), m_clipType(UNKNOWN), m_clipId(clipId), m_isGroup(false), m_groupName(QString::null) -{ - m_element = xml.cloneNode().toElement(); - setSizeHint(0, QSize(65, 45)); - setFlags(Qt::ItemIsSelectable | Qt::ItemIsDragEnabled | Qt::ItemIsEnabled | Qt::ItemIsEditable); - if (!m_element.isNull()) { - m_element.setAttribute("id", clipId); - QString cType = m_element.attribute("type", QString::null); - if (!cType.isEmpty()) { - m_clipType = (CLIPTYPE) cType.toInt(); - slotSetToolTip(); + : QTreeWidgetItem(parent, strings, QTreeWidgetItem::UserType), m_clipType(UNKNOWN), m_clipId(clipId), m_isGroup(false), m_groupName(QString::null) { + m_element = xml.cloneNode().toElement(); + setSizeHint(0, QSize(65, 45)); + setFlags(Qt::ItemIsSelectable | Qt::ItemIsDragEnabled | Qt::ItemIsEnabled | Qt::ItemIsEditable); + if (!m_element.isNull()) { + m_element.setAttribute("id", clipId); + QString cType = m_element.attribute("type", QString::null); + if (!cType.isEmpty()) { + m_clipType = (CLIPTYPE) cType.toInt(); + slotSetToolTip(); + } + + if (m_clipType == COLOR || m_clipType == IMAGE) m_element.setAttribute("duration", MAXCLIPDURATION); + else if (m_element.attribute("duration").isEmpty() && !m_element.attribute("out").isEmpty()) { + m_element.setAttribute("duration", m_element.attribute("out").toInt() - m_element.attribute("in").toInt()); + } } - - if (m_clipType == COLOR || m_clipType == IMAGE) m_element.setAttribute("duration", MAXCLIPDURATION); - else if (m_element.attribute("duration").isEmpty() && !m_element.attribute("out").isEmpty()) { - m_element.setAttribute("duration", m_element.attribute("out").toInt() - m_element.attribute("in").toInt()); - } - } } ProjectItem::ProjectItem(QTreeWidgetItem * parent, const QStringList & strings, QDomElement xml, int clipId) - : QTreeWidgetItem(parent, strings, QTreeWidgetItem::UserType), m_clipType(UNKNOWN), m_clipId(clipId), m_isGroup(false), m_groupName(QString::null) -{ - m_element = xml.cloneNode().toElement(); - setSizeHint(0, QSize(65, 45)); - setFlags(Qt::ItemIsSelectable | Qt::ItemIsDragEnabled | Qt::ItemIsEnabled | Qt::ItemIsEditable); - if (!m_element.isNull()) { - m_element.setAttribute("id", clipId); - QString cType = m_element.attribute("type", QString::null); - if (!cType.isEmpty()) { - m_clipType = (CLIPTYPE) cType.toInt(); - slotSetToolTip(); + : QTreeWidgetItem(parent, strings, QTreeWidgetItem::UserType), m_clipType(UNKNOWN), m_clipId(clipId), m_isGroup(false), m_groupName(QString::null) { + m_element = xml.cloneNode().toElement(); + setSizeHint(0, QSize(65, 45)); + setFlags(Qt::ItemIsSelectable | Qt::ItemIsDragEnabled | Qt::ItemIsEnabled | Qt::ItemIsEditable); + if (!m_element.isNull()) { + m_element.setAttribute("id", clipId); + QString cType = m_element.attribute("type", QString::null); + if (!cType.isEmpty()) { + m_clipType = (CLIPTYPE) cType.toInt(); + slotSetToolTip(); + } } - } } ProjectItem::ProjectItem(QTreeWidget * parent, const QStringList & strings, int clipId) - : QTreeWidgetItem(parent, strings, QTreeWidgetItem::UserType), m_element(QDomElement()), m_clipType(UNKNOWN), m_clipId(clipId), m_isGroup(true), m_groupName(strings.at(1)) -{ - setSizeHint(0, QSize(65, 45)); - setFlags(Qt::ItemIsSelectable | Qt::ItemIsDragEnabled | Qt::ItemIsEnabled | Qt::ItemIsEditable); - setIcon(0, KIcon("folder")); + : QTreeWidgetItem(parent, strings, QTreeWidgetItem::UserType), m_element(QDomElement()), m_clipType(UNKNOWN), m_clipId(clipId), m_isGroup(true), m_groupName(strings.at(1)) { + setSizeHint(0, QSize(65, 45)); + setFlags(Qt::ItemIsSelectable | Qt::ItemIsDragEnabled | Qt::ItemIsEnabled | Qt::ItemIsEditable); + setIcon(0, KIcon("folder")); } ProjectItem::ProjectItem(QTreeWidget * parent, DocClipBase *clip) - : QTreeWidgetItem(parent, QStringList(), QTreeWidgetItem::UserType), m_isGroup(false) -{ - setSizeHint(0, QSize(65, 45)); - setFlags(Qt::ItemIsSelectable | Qt::ItemIsDragEnabled | Qt::ItemIsEnabled | Qt::ItemIsEditable); - m_clip = clip; - m_element = clip->toXML(); - m_clipId = clip->getId(); - QString name = m_element.attribute("name"); - if (name.isEmpty()) name = KUrl(m_element.attribute("resource")).fileName(); - m_clipType = (CLIPTYPE) m_element.attribute("type").toInt(); - m_groupName = m_element.attribute("group"); - setText(1, name); - kDebug()<<"PROJECT ITE;. ADDING LCIP: "<< m_clipId; + : QTreeWidgetItem(parent, QStringList(), QTreeWidgetItem::UserType), m_isGroup(false) { + setSizeHint(0, QSize(65, 45)); + setFlags(Qt::ItemIsSelectable | Qt::ItemIsDragEnabled | Qt::ItemIsEnabled | Qt::ItemIsEditable); + m_clip = clip; + m_element = clip->toXML(); + m_clipId = clip->getId(); + QString name = m_element.attribute("name"); + if (name.isEmpty()) name = KUrl(m_element.attribute("resource")).fileName(); + m_clipType = (CLIPTYPE) m_element.attribute("type").toInt(); + m_groupName = m_element.attribute("group"); + setText(1, name); + kDebug() << "PROJECT ITE;. ADDING LCIP: " << m_clipId; } -ProjectItem::~ProjectItem() -{ +ProjectItem::~ProjectItem() { } -int ProjectItem::numReferences() const -{ - if (!m_clip) return 0; - return m_clip->numReferences(); +int ProjectItem::numReferences() const { + if (!m_clip) return 0; + return m_clip->numReferences(); } -int ProjectItem::clipId() const -{ - return m_clipId; +int ProjectItem::clipId() const { + return m_clipId; } -CLIPTYPE ProjectItem::clipType() const -{ - return m_clipType; +CLIPTYPE ProjectItem::clipType() const { + return m_clipType; } -int ProjectItem::clipMaxDuration() const -{ - return m_element.attribute("duration").toInt(); +int ProjectItem::clipMaxDuration() const { + return m_element.attribute("duration").toInt(); } -bool ProjectItem::isGroup() const -{ - return m_isGroup; +bool ProjectItem::isGroup() const { + return m_isGroup; } -const QString ProjectItem::groupName() const -{ - return m_groupName; +const QString ProjectItem::groupName() const { + return m_groupName; } -QStringList ProjectItem::names() const -{ - QStringList result; - result.append(text(0)); - result.append(text(1)); - result.append(text(2)); - return result; +QStringList ProjectItem::names() const { + QStringList result; + result.append(text(0)); + result.append(text(1)); + result.append(text(2)); + return result; } -QDomElement ProjectItem::toXml() const -{ +QDomElement ProjectItem::toXml() const { return m_element; } -const KUrl ProjectItem::clipUrl() const -{ +const KUrl ProjectItem::clipUrl() const { if (m_clipType != COLOR && m_clipType != VIRTUAL && m_clipType != UNKNOWN) - return KUrl(m_element.attribute("resource")); + return KUrl(m_element.attribute("resource")); else return KUrl(); } -void ProjectItem::slotSetToolTip() -{ - QString tip = ""; - switch (m_clipType) { +void ProjectItem::slotSetToolTip() { + QString tip = ""; + switch (m_clipType) { case 1: - tip.append(i18n("Audio clip")); - break; + tip.append(i18n("Audio clip")); + break; case 2: - tip.append(i18n("Mute video clip")); - break; + tip.append(i18n("Mute video clip")); + break; case 3: - tip.append(i18n("Video clip")); - break; + tip.append(i18n("Video clip")); + break; case 4: - tip.append(i18n("Color clip")); - setData(1, DurationRole, Timecode::getEasyTimecode(GenTime(m_element.attribute("out", "250").toInt(), 25), 25)); - break; + tip.append(i18n("Color clip")); + setData(1, DurationRole, Timecode::getEasyTimecode(GenTime(m_element.attribute("out", "250").toInt(), 25), 25)); + break; case 5: - tip.append(i18n("Image clip")); - break; + tip.append(i18n("Image clip")); + break; case 6: - tip.append(i18n("Text clip")); - break; + tip.append(i18n("Text clip")); + break; case 7: - tip.append(i18n("Slideshow clip")); - break; + tip.append(i18n("Slideshow clip")); + break; case 8: - tip.append(i18n("Virtual clip")); - break; + tip.append(i18n("Virtual clip")); + break; case 9: - tip.append(i18n("Playlist clip")); - break; + tip.append(i18n("Playlist clip")); + break; default: - tip.append(i18n("Unknown clip")); - break; - } + tip.append(i18n("Unknown clip")); + break; + } - setToolTip(1, tip); + setToolTip(1, tip); } -void ProjectItem::setProperties(const QMap < QString, QString > &attributes, const QMap < QString, QString > &metadata) -{ - if (attributes.contains("duration")) { - if (m_clipType == AUDIO || m_clipType == VIDEO || m_clipType == AV) m_element.setAttribute("duration", attributes["duration"].toInt()); - m_duration = GenTime(attributes["duration"].toInt(), 25); - setData(1, DurationRole, Timecode::getEasyTimecode(m_duration, 25)); - m_durationKnown = true; - m_clip->setDuration(m_duration); - kDebug()<<"//// LOADED CLIP, DURATION SET TO: "<setClipType(m_clipType); - } - slotSetToolTip(); - if (m_element.isNull()) { - QDomDocument doc; - m_element = doc.createElement("producer"); - } - if (m_element.attribute("duration") == QString::null) m_element.setAttribute("duration", attributes["duration"].toInt()); - m_element.setAttribute("resource", attributes["filename"]); - m_element.setAttribute("type", (int) m_clipType); - - m_clip->slotRequestAudioThumbs(); -/* - if (attributes.contains("height")) { - m_height = attributes["height"].toInt(); - } else { - m_height = 0; - } - if (attributes.contains("width")) { - m_width = attributes["width"].toInt(); - } else { - m_width = 0; - } - //decoder name - if (attributes.contains("name")) { - m_decompressor = attributes["name"]; - } else { - m_decompressor = "n/a"; - } - //video type ntsc/pal - if (attributes.contains("system")) { - m_system = attributes["system"]; - } else { - m_system = "n/a"; - } - if (attributes.contains("fps")) { - m_framesPerSecond = attributes["fps"].toInt(); - } else { - // No frame rate known. - m_framesPerSecond = 0; - } - //audio attributes -reh - if (attributes.contains("channels")) { - m_channels = attributes["channels"].toInt(); - } else { - m_channels = 0; - } - if (attributes.contains("format")) { - m_format = attributes["format"]; - } else { - m_format = "n/a"; - } - if (attributes.contains("frequency")) { - m_frequency = attributes["frequency"].toInt(); - } else { - m_frequency = 0; - } - if (attributes.contains("videocodec")) { - m_videoCodec = attributes["videocodec"]; - } - if (attributes.contains("audiocodec")) { - m_audioCodec = attributes["audiocodec"]; - } - - m_metadata = metadata; - - if (m_metadata.contains("description")) { - setDescription (m_metadata["description"]); - } - else if (m_metadata.contains("comment")) { - setDescription (m_metadata["comment"]); - } -*/ +void ProjectItem::setProperties(const QMap < QString, QString > &attributes, const QMap < QString, QString > &metadata) { + if (attributes.contains("duration")) { + if (m_clipType == AUDIO || m_clipType == VIDEO || m_clipType == AV) m_element.setAttribute("duration", attributes["duration"].toInt()); + m_duration = GenTime(attributes["duration"].toInt(), 25); + setData(1, DurationRole, Timecode::getEasyTimecode(m_duration, 25)); + m_durationKnown = true; + m_clip->setDuration(m_duration); + kDebug() << "//// LOADED CLIP, DURATION SET TO: " << m_duration.frames(25); + } else { + // No duration known, use an arbitrary one until it is. + m_duration = GenTime(0.0); + m_durationKnown = false; + } + + + //extend attributes -reh + + if (m_clipType == UNKNOWN) { + if (attributes.contains("type")) { + if (attributes["type"] == "audio") + m_clipType = AUDIO; + else if (attributes["type"] == "video") + m_clipType = VIDEO; + else if (attributes["type"] == "av") + m_clipType = AV; + else if (attributes["type"] == "playlist") + m_clipType = PLAYLIST; + } else { + m_clipType = AV; + } + m_clip->setClipType(m_clipType); + } + slotSetToolTip(); + if (m_element.isNull()) { + QDomDocument doc; + m_element = doc.createElement("producer"); + } + if (m_element.attribute("duration") == QString::null) m_element.setAttribute("duration", attributes["duration"].toInt()); + m_element.setAttribute("resource", attributes["filename"]); + m_element.setAttribute("type", (int) m_clipType); + + m_clip->slotRequestAudioThumbs(); + /* + if (attributes.contains("height")) { + m_height = attributes["height"].toInt(); + } else { + m_height = 0; + } + if (attributes.contains("width")) { + m_width = attributes["width"].toInt(); + } else { + m_width = 0; + } + //decoder name + if (attributes.contains("name")) { + m_decompressor = attributes["name"]; + } else { + m_decompressor = "n/a"; + } + //video type ntsc/pal + if (attributes.contains("system")) { + m_system = attributes["system"]; + } else { + m_system = "n/a"; + } + if (attributes.contains("fps")) { + m_framesPerSecond = attributes["fps"].toInt(); + } else { + // No frame rate known. + m_framesPerSecond = 0; + } + //audio attributes -reh + if (attributes.contains("channels")) { + m_channels = attributes["channels"].toInt(); + } else { + m_channels = 0; + } + if (attributes.contains("format")) { + m_format = attributes["format"]; + } else { + m_format = "n/a"; + } + if (attributes.contains("frequency")) { + m_frequency = attributes["frequency"].toInt(); + } else { + m_frequency = 0; + } + if (attributes.contains("videocodec")) { + m_videoCodec = attributes["videocodec"]; + } + if (attributes.contains("audiocodec")) { + m_audioCodec = attributes["audiocodec"]; + } + + m_metadata = metadata; + + if (m_metadata.contains("description")) { + setDescription (m_metadata["description"]); + } + else if (m_metadata.contains("comment")) { + setDescription (m_metadata["comment"]); + } + */ } diff --git a/src/projectitem.h b/src/projectitem.h index ec6804ce..47bc56b9 100644 --- a/src/projectitem.h +++ b/src/projectitem.h @@ -31,9 +31,8 @@ #include "definitions.h" #include "docclipbase.h" -class ProjectItem : public QTreeWidgetItem -{ - public: +class ProjectItem : public QTreeWidgetItem { +public: ProjectItem(QTreeWidget * parent, const QStringList & strings, QDomElement xml, int clipId); ProjectItem(QTreeWidgetItem * parent, const QStringList & strings, QDomElement xml, int clipId); ProjectItem(QTreeWidget * parent, const QStringList & strings, int clipId); @@ -51,7 +50,7 @@ class ProjectItem : public QTreeWidgetItem int clipMaxDuration() const; CLIPTYPE clipType() const; - private: +private: QDomElement m_element; GenTime m_duration; bool m_durationKnown; diff --git a/src/projectlist.cpp b/src/projectlist.cpp index 08c1582f..b2ee5011 100644 --- a/src/projectlist.cpp +++ b/src/projectlist.cpp @@ -47,427 +47,394 @@ #include ProjectList::ProjectList(QWidget *parent) - : QWidget(parent), m_render(NULL), m_fps(-1), m_commandStack(NULL) -{ - - QWidget *vbox = new QWidget; - listView = new ProjectListView(this);; - QVBoxLayout *layout = new QVBoxLayout; - m_clipIdCounter = 0; - - // setup toolbar - searchView = new KTreeWidgetSearchLine (this); - m_toolbar = new QToolBar("projectToolBar", this); - m_toolbar->addWidget (searchView); - - QToolButton *addButton = new QToolButton( m_toolbar ); - QMenu *addMenu = new QMenu(this); - addButton->setMenu( addMenu ); - addButton->setPopupMode(QToolButton::MenuButtonPopup); - m_toolbar->addWidget (addButton); - - QAction *addClipButton = addMenu->addAction (KIcon("document-new"), i18n("Add Clip")); - connect(addClipButton, SIGNAL(triggered()), this, SLOT(slotAddClip())); - - QAction *addColorClip = addMenu->addAction (KIcon("document-new"), i18n("Add Color Clip")); - connect(addColorClip, SIGNAL(triggered()), this, SLOT(slotAddColorClip())); - - QAction *addTitleClip = addMenu->addAction (KIcon("document-new"), i18n("Add Title Clip")); - connect(addTitleClip, SIGNAL(triggered()), this, SLOT(slotAddTitleClip())); - - m_deleteAction = m_toolbar->addAction (KIcon("edit-delete"), i18n("Delete Clip")); - connect(m_deleteAction, SIGNAL(triggered()), this, SLOT(slotRemoveClip())); - - m_editAction = m_toolbar->addAction (KIcon("document-properties"), i18n("Edit Clip")); - connect(m_editAction, SIGNAL(triggered()), this, SLOT(slotEditClip())); - - QAction *addFolderButton = addMenu->addAction (KIcon("folder-new"), i18n("Create Folder")); - connect(addFolderButton, SIGNAL(triggered()), this, SLOT(slotAddFolder())); - - addButton->setDefaultAction( addClipButton ); - - layout->addWidget( m_toolbar ); - layout->addWidget( listView ); - setLayout( layout ); - //m_toolbar->setEnabled(false); - - searchView->setTreeWidget(listView); - listView->setColumnCount(3); - QStringList headers; - headers<setHeaderLabels(headers); - listView->sortByColumn(1, Qt::AscendingOrder); - - m_menu = new QMenu(); - m_menu->addAction(addClipButton); - m_menu->addAction(addColorClip); - m_menu->addAction(addTitleClip); - m_menu->addAction(m_editAction); - m_menu->addAction(m_deleteAction); - m_menu->addAction(addFolderButton); - m_menu->insertSeparator(m_deleteAction); - - connect(listView, SIGNAL(itemSelectionChanged()), this, SLOT(slotClipSelected())); - connect(listView, SIGNAL(requestMenu ( const QPoint &, QTreeWidgetItem * )), this, SLOT(slotContextMenu(const QPoint &, QTreeWidgetItem *))); - connect(listView, SIGNAL(addClip ()), this, SLOT(slotAddClip())); - connect(listView, SIGNAL(addClip (QUrl, const QString &)), this, SLOT(slotAddClip(QUrl, const QString &))); - connect(listView, SIGNAL (itemChanged ( QTreeWidgetItem *, int )), this, SLOT(slotUpdateItemDescription(QTreeWidgetItem *, int ))); - - m_listViewDelegate = new ItemDelegate(listView); - listView->setItemDelegate(m_listViewDelegate); - listView->setIconSize(QSize(60, 40)); - listView->setSortingEnabled (true); + : QWidget(parent), m_render(NULL), m_fps(-1), m_commandStack(NULL) { + + QWidget *vbox = new QWidget; + listView = new ProjectListView(this);; + QVBoxLayout *layout = new QVBoxLayout; + m_clipIdCounter = 0; + + // setup toolbar + searchView = new KTreeWidgetSearchLine(this); + m_toolbar = new QToolBar("projectToolBar", this); + m_toolbar->addWidget(searchView); + + QToolButton *addButton = new QToolButton(m_toolbar); + QMenu *addMenu = new QMenu(this); + addButton->setMenu(addMenu); + addButton->setPopupMode(QToolButton::MenuButtonPopup); + m_toolbar->addWidget(addButton); + + QAction *addClipButton = addMenu->addAction(KIcon("document-new"), i18n("Add Clip")); + connect(addClipButton, SIGNAL(triggered()), this, SLOT(slotAddClip())); + + QAction *addColorClip = addMenu->addAction(KIcon("document-new"), i18n("Add Color Clip")); + connect(addColorClip, SIGNAL(triggered()), this, SLOT(slotAddColorClip())); + + QAction *addTitleClip = addMenu->addAction(KIcon("document-new"), i18n("Add Title Clip")); + connect(addTitleClip, SIGNAL(triggered()), this, SLOT(slotAddTitleClip())); + + m_deleteAction = m_toolbar->addAction(KIcon("edit-delete"), i18n("Delete Clip")); + connect(m_deleteAction, SIGNAL(triggered()), this, SLOT(slotRemoveClip())); + + m_editAction = m_toolbar->addAction(KIcon("document-properties"), i18n("Edit Clip")); + connect(m_editAction, SIGNAL(triggered()), this, SLOT(slotEditClip())); + + QAction *addFolderButton = addMenu->addAction(KIcon("folder-new"), i18n("Create Folder")); + connect(addFolderButton, SIGNAL(triggered()), this, SLOT(slotAddFolder())); + + addButton->setDefaultAction(addClipButton); + + layout->addWidget(m_toolbar); + layout->addWidget(listView); + setLayout(layout); + //m_toolbar->setEnabled(false); + + searchView->setTreeWidget(listView); + listView->setColumnCount(3); + QStringList headers; + headers << i18n("Thumbnail") << i18n("Filename") << i18n("Description"); + listView->setHeaderLabels(headers); + listView->sortByColumn(1, Qt::AscendingOrder); + + m_menu = new QMenu(); + m_menu->addAction(addClipButton); + m_menu->addAction(addColorClip); + m_menu->addAction(addTitleClip); + m_menu->addAction(m_editAction); + m_menu->addAction(m_deleteAction); + m_menu->addAction(addFolderButton); + m_menu->insertSeparator(m_deleteAction); + + connect(listView, SIGNAL(itemSelectionChanged()), this, SLOT(slotClipSelected())); + connect(listView, SIGNAL(requestMenu(const QPoint &, QTreeWidgetItem *)), this, SLOT(slotContextMenu(const QPoint &, QTreeWidgetItem *))); + connect(listView, SIGNAL(addClip()), this, SLOT(slotAddClip())); + connect(listView, SIGNAL(addClip(QUrl, const QString &)), this, SLOT(slotAddClip(QUrl, const QString &))); + connect(listView, SIGNAL(itemChanged(QTreeWidgetItem *, int)), this, SLOT(slotUpdateItemDescription(QTreeWidgetItem *, int))); + + m_listViewDelegate = new ItemDelegate(listView); + listView->setItemDelegate(m_listViewDelegate); + listView->setIconSize(QSize(60, 40)); + listView->setSortingEnabled(true); } -ProjectList::~ProjectList() -{ - delete m_menu; - delete m_toolbar; +ProjectList::~ProjectList() { + delete m_menu; + delete m_toolbar; } -void ProjectList::setRenderer(Render *projectRender) -{ - m_render = projectRender; +void ProjectList::setRenderer(Render *projectRender) { + m_render = projectRender; } -void ProjectList::slotClipSelected() -{ - ProjectItem *item = (ProjectItem*) listView->currentItem(); - if (item && !item->isGroup()) emit clipSelected(item->toXml()); +void ProjectList::slotClipSelected() { + ProjectItem *item = (ProjectItem*) listView->currentItem(); + if (item && !item->isGroup()) emit clipSelected(item->toXml()); } -void ProjectList::slotUpdateItemDescription( QTreeWidgetItem *item, int column) -{ - if (column != 2) return; - ProjectItem *clip = (ProjectItem*) item; - CLIPTYPE type = clip->clipType(); - if (type == AUDIO || type == VIDEO || type == AV || type == IMAGE || type == PLAYLIST) { - // Use Nepomuk system to store clip description - Nepomuk::Resource f( clip->clipUrl().path() ); - f.setDescription(item->text(2)); - kDebug()<<"NEPOMUK, SETTING CLIP: "<clipUrl().path()<<", TO TEXT: "<text(2); - } +void ProjectList::slotUpdateItemDescription(QTreeWidgetItem *item, int column) { + if (column != 2) return; + ProjectItem *clip = (ProjectItem*) item; + CLIPTYPE type = clip->clipType(); + if (type == AUDIO || type == VIDEO || type == AV || type == IMAGE || type == PLAYLIST) { + // Use Nepomuk system to store clip description + Nepomuk::Resource f(clip->clipUrl().path()); + f.setDescription(item->text(2)); + kDebug() << "NEPOMUK, SETTING CLIP: " << clip->clipUrl().path() << ", TO TEXT: " << item->text(2); + } } -void ProjectList::slotEditClip() -{ - kDebug()<<"//////////////////////////////////////// DBL CLK"; +void ProjectList::slotEditClip() { + kDebug() << "//////////////////////////////////////// DBL CLK"; } -void ProjectList::slotEditClip(QTreeWidgetItem *item, int column) -{ - kDebug()<<"//////////////////////////////////////// DBL CLK"; +void ProjectList::slotEditClip(QTreeWidgetItem *item, int column) { + kDebug() << "//////////////////////////////////////// DBL CLK"; } -void ProjectList::slotContextMenu( const QPoint &pos, QTreeWidgetItem *item ) -{ - bool enable = false; - if (item) { - QFrame *w = new QFrame; - w->setFrameShape(QFrame::StyledPanel); - w->setLineWidth(2); - w->setAutoFillBackground(true); - QHBoxLayout *layout = new QHBoxLayout; - layout->addWidget( new QLabel(i18n("Color:"))); - layout->addWidget( new KColorButton()); - layout->addWidget( new QLabel(i18n("Duration:"))); - layout->addWidget( new KRestrictedLine()); - w->setLayout( layout ); - m_listViewDelegate->extendItem(w, listView->currentIndex()); - enable = true; - } - m_editAction->setEnabled(enable); - m_deleteAction->setEnabled(enable); - - m_menu->popup(pos); +void ProjectList::slotContextMenu(const QPoint &pos, QTreeWidgetItem *item) { + bool enable = false; + if (item) { + QFrame *w = new QFrame; + w->setFrameShape(QFrame::StyledPanel); + w->setLineWidth(2); + w->setAutoFillBackground(true); + QHBoxLayout *layout = new QHBoxLayout; + layout->addWidget(new QLabel(i18n("Color:"))); + layout->addWidget(new KColorButton()); + layout->addWidget(new QLabel(i18n("Duration:"))); + layout->addWidget(new KRestrictedLine()); + w->setLayout(layout); + m_listViewDelegate->extendItem(w, listView->currentIndex()); + enable = true; + } + m_editAction->setEnabled(enable); + m_deleteAction->setEnabled(enable); + + m_menu->popup(pos); } -void ProjectList::slotRemoveClip() -{ +void ProjectList::slotRemoveClip() { - if (!m_commandStack) kDebug()<<"!!!!!!!!!!!!!!!!  NO CMD STK"; - if (!listView->currentItem()) return; - ProjectItem *item = ((ProjectItem *)listView->currentItem()); - if (item->numReferences() > 0) { - if (KMessageBox::questionYesNo(this, i18n("Delete clip %1 ?
This will also remove its %2 clips in timeline").arg(item->names().at(1)).arg(item->numReferences()), i18n("Delete Clip")) != KMessageBox::Yes) return; - } - m_doc->deleteProjectClip(item->clipId()); + if (!m_commandStack) kDebug() << "!!!!!!!!!!!!!!!!  NO CMD STK"; + if (!listView->currentItem()) return; + ProjectItem *item = ((ProjectItem *)listView->currentItem()); + if (item->numReferences() > 0) { + if (KMessageBox::questionYesNo(this, i18n("Delete clip %1 ?
This will also remove its %2 clips in timeline").arg(item->names().at(1)).arg(item->numReferences()), i18n("Delete Clip")) != KMessageBox::Yes) return; + } + m_doc->deleteProjectClip(item->clipId()); } -void ProjectList::selectItemById(const int clipId) -{ - ProjectItem *item = getItemById(clipId); - if (item) listView->setCurrentItem(item); +void ProjectList::selectItemById(const int clipId) { + ProjectItem *item = getItemById(clipId); + if (item) listView->setCurrentItem(item); } -void ProjectList::addClip(const QStringList &name, const QDomElement &elem, const int clipId, const KUrl &url, const QString &group, int parentId) -{ - kDebug()<<"///////// ADDING VCLIP=: "< groupList = listView->findItems(groupName, Qt::MatchExactly, 1); - if (groupList.isEmpty()) { - (void) new ProjectItem(listView, name, clipId); +void ProjectList::addClip(const QStringList &name, const QDomElement &elem, const int clipId, const KUrl &url, const QString &group, int parentId) { + kDebug() << "///////// ADDING VCLIP=: " << name; + ProjectItem *item; + ProjectItem *groupItem = NULL; + QString groupName; + if (group.isEmpty()) groupName = elem.attribute("group", QString::null); + else groupName = group; + if (elem.isNull() && url.isEmpty()) { + // this is a folder + groupName = name.at(1); + QList groupList = listView->findItems(groupName, Qt::MatchExactly, 1); + if (groupList.isEmpty()) { + (void) new ProjectItem(listView, name, clipId); + } + return; } - return; - } - - if (parentId != -1) { - groupItem = getItemById(parentId); - } - else if (!groupName.isEmpty()) { - // Clip is in a group - QList groupList = listView->findItems(groupName, Qt::MatchExactly, 1); - - if (groupList.isEmpty()) { - QStringList itemName; - itemName<setText(2, annotation); - QString resource = url.path(); - if (resource.endsWith("westley") || resource.endsWith("kdenlive")) { - QString tmpfile; - QDomDocument doc; - if (KIO::NetAccess::download(url, tmpfile, 0)) { - QFile file(tmpfile); - if (file.open(QIODevice::ReadOnly)) { - doc.setContent(&file, false); - file.close(); - } - KIO::NetAccess::removeTempFile(tmpfile); - - QDomNodeList subProds = doc.elementsByTagName("producer"); - int ct = subProds.count(); - for (int i = 0; i < ct ; i++) - { - QDomElement e = subProds.item(i).toElement(); - if (!e.isNull()) { - addProducer(e, clipId); - } - } - } + + if (parentId != -1) { + groupItem = getItemById(parentId); + } else if (!groupName.isEmpty()) { + // Clip is in a group + QList groupList = listView->findItems(groupName, Qt::MatchExactly, 1); + + if (groupList.isEmpty()) { + QStringList itemName; + itemName << QString::null << groupName; + kDebug() << "------- CREATING NEW GRP: " << itemName; + groupItem = new ProjectItem(listView, itemName, m_clipIdCounter++); + } else groupItem = (ProjectItem *) groupList.first(); } + if (groupItem) item = new ProjectItem(groupItem, name, elem, clipId); + else item = new ProjectItem(listView, name, elem, clipId); + if (!url.isEmpty()) { + // if file has Nepomuk comment, use it + Nepomuk::Resource f(url.path()); + QString annotation = f.description(); + if (!annotation.isEmpty()) item->setText(2, annotation); + QString resource = url.path(); + if (resource.endsWith("westley") || resource.endsWith("kdenlive")) { + QString tmpfile; + QDomDocument doc; + if (KIO::NetAccess::download(url, tmpfile, 0)) { + QFile file(tmpfile); + if (file.open(QIODevice::ReadOnly)) { + doc.setContent(&file, false); + file.close(); + } + KIO::NetAccess::removeTempFile(tmpfile); + + QDomNodeList subProds = doc.elementsByTagName("producer"); + int ct = subProds.count(); + for (int i = 0; i < ct ; i++) { + QDomElement e = subProds.item(i).toElement(); + if (!e.isNull()) { + addProducer(e, clipId); + } + } + } + } - } + } - if (elem.isNull() ) { - QDomDocument doc; - QDomElement element = doc.createElement("producer"); - element.setAttribute("resource", url.path()); - emit getFileProperties(element, clipId); - } - else emit getFileProperties(elem, clipId); - selectItemById(clipId); + if (elem.isNull()) { + QDomDocument doc; + QDomElement element = doc.createElement("producer"); + element.setAttribute("resource", url.path()); + emit getFileProperties(element, clipId); + } else emit getFileProperties(elem, clipId); + selectItemById(clipId); } -void ProjectList::slotDeleteClip( int clipId) -{ - ProjectItem *item = getItemById(clipId); - if (item) delete item; +void ProjectList::slotDeleteClip(int clipId) { + ProjectItem *item = getItemById(clipId); + if (item) delete item; } -void ProjectList::slotAddFolder() -{ -/* - QString folderName = KInputDialog::getText(i18n("New Folder"), i18n("Enter new folder name: ")); - if (folderName.isEmpty()) return; - QStringList itemEntry; - itemEntry.append(QString::null); - itemEntry.append(folderName); - AddClipCommand *command = new AddClipCommand(this, itemEntry, QDomElement(), m_clipIdCounter++, KUrl(), folderName, true); - m_commandStack->push(command);*/ +void ProjectList::slotAddFolder() { + /* + QString folderName = KInputDialog::getText(i18n("New Folder"), i18n("Enter new folder name: ")); + if (folderName.isEmpty()) return; + QStringList itemEntry; + itemEntry.append(QString::null); + itemEntry.append(folderName); + AddClipCommand *command = new AddClipCommand(this, itemEntry, QDomElement(), m_clipIdCounter++, KUrl(), folderName, true); + m_commandStack->push(command);*/ } -void ProjectList::slotAddClip(DocClipBase *clip) -{ - ProjectItem *item = new ProjectItem(listView, clip); - listView->setCurrentItem(item); - emit getFileProperties(clip->toXML(), clip->getId()); +void ProjectList::slotAddClip(DocClipBase *clip) { + ProjectItem *item = new ProjectItem(listView, clip); + listView->setCurrentItem(item); + emit getFileProperties(clip->toXML(), clip->getId()); } -void ProjectList::slotUpdateClip(int id) -{ - ProjectItem *item = getItemById(id); - item->setData(1, UsageRole, QString::number(item->numReferences())); +void ProjectList::slotUpdateClip(int id) { + ProjectItem *item = getItemById(id); + item->setData(1, UsageRole, QString::number(item->numReferences())); } -void ProjectList::slotAddClip(QUrl givenUrl, const QString &group) -{ - if (!m_commandStack) kDebug()<<"!!!!!!!!!!!!!!!!  NO CMD STK"; - KUrl::List list; - if (givenUrl.isEmpty()) - list = KFileDialog::getOpenUrls( KUrl(), "application/vnd.kde.kdenlive application/vnd.westley.scenelist application/flv application/vnd.rn-realmedia video/x-dv video/x-msvideo video/mpeg video/x-ms-wmv audio/mpeg audio/x-mp3 audio/x-wav application/ogg *.m2t *.dv video/mp4 video/quicktime image/gif image/jpeg image/png image/x-bmp image/svg+xml image/tiff image/x-xcf-gimp image/x-vnd.adobe.photoshop image/x-pcx image/x-exr"); - else list.append(givenUrl); - if (list.isEmpty()) return; - KUrl::List::Iterator it; - - for (it = list.begin(); it != list.end(); it++) { - m_doc->slotAddClipFile(*it, group); - } +void ProjectList::slotAddClip(QUrl givenUrl, const QString &group) { + if (!m_commandStack) kDebug() << "!!!!!!!!!!!!!!!!  NO CMD STK"; + KUrl::List list; + if (givenUrl.isEmpty()) + list = KFileDialog::getOpenUrls(KUrl(), "application/vnd.kde.kdenlive application/vnd.westley.scenelist application/flv application/vnd.rn-realmedia video/x-dv video/x-msvideo video/mpeg video/x-ms-wmv audio/mpeg audio/x-mp3 audio/x-wav application/ogg *.m2t *.dv video/mp4 video/quicktime image/gif image/jpeg image/png image/x-bmp image/svg+xml image/tiff image/x-xcf-gimp image/x-vnd.adobe.photoshop image/x-pcx image/x-exr"); + else list.append(givenUrl); + if (list.isEmpty()) return; + KUrl::List::Iterator it; + + for (it = list.begin(); it != list.end(); it++) { + m_doc->slotAddClipFile(*it, group); + } } -void ProjectList::slotAddColorClip() -{ - if (!m_commandStack) kDebug()<<"!!!!!!!!!!!!!!!!  NO CMD STK"; - QDialog *dia = new QDialog; - Ui::ColorClip_UI *dia_ui = new Ui::ColorClip_UI(); - dia_ui->setupUi(dia); - dia_ui->clip_name->setText(i18n("Color Clip")); - dia_ui->clip_duration->setText(KdenliveSettings::color_duration()); - if (dia->exec() == QDialog::Accepted) - { - QString color = dia_ui->clip_color->color().name(); - color = color.replace(0, 1, "0x") + "ff"; - m_doc->slotAddColorClipFile(dia_ui->clip_name->text(), color, dia_ui->clip_duration->text(), QString::null); - } - delete dia_ui; - delete dia; +void ProjectList::slotAddColorClip() { + if (!m_commandStack) kDebug() << "!!!!!!!!!!!!!!!!  NO CMD STK"; + QDialog *dia = new QDialog; + Ui::ColorClip_UI *dia_ui = new Ui::ColorClip_UI(); + dia_ui->setupUi(dia); + dia_ui->clip_name->setText(i18n("Color Clip")); + dia_ui->clip_duration->setText(KdenliveSettings::color_duration()); + if (dia->exec() == QDialog::Accepted) { + QString color = dia_ui->clip_color->color().name(); + color = color.replace(0, 1, "0x") + "ff"; + m_doc->slotAddColorClipFile(dia_ui->clip_name->text(), color, dia_ui->clip_duration->text(), QString::null); + } + delete dia_ui; + delete dia; } -void ProjectList::slotAddTitleClip() -{ - - if (!m_commandStack) kDebug()<<"!!!!!!!!!!!!!!!!  NO CMD STK"; - //QDialog *dia = new QDialog; - - TitleWidget *dia_ui = new TitleWidget(); - //dia_ui->setupUi(dia); - //dia_ui->clip_name->setText(i18n("Title Clip")); - //dia_ui->clip_duration->setText(KdenliveSettings::color_duration()); - if (dia_ui->exec() == QDialog::Accepted) - { - //QString color = dia_ui->clip_color->color().name(); - //color = color.replace(0, 1, "0x") + "ff"; - //m_doc->slotAddColorClipFile(dia_ui->clip_name->text(), color, dia_ui->clip_duration->text(), QString::null); - } - delete dia_ui; - //delete dia; +void ProjectList::slotAddTitleClip() { + + if (!m_commandStack) kDebug() << "!!!!!!!!!!!!!!!!  NO CMD STK"; + //QDialog *dia = new QDialog; + + TitleWidget *dia_ui = new TitleWidget(); + //dia_ui->setupUi(dia); + //dia_ui->clip_name->setText(i18n("Title Clip")); + //dia_ui->clip_duration->setText(KdenliveSettings::color_duration()); + if (dia_ui->exec() == QDialog::Accepted) { + //QString color = dia_ui->clip_color->color().name(); + //color = color.replace(0, 1, "0x") + "ff"; + //m_doc->slotAddColorClipFile(dia_ui->clip_name->text(), color, dia_ui->clip_duration->text(), QString::null); + } + delete dia_ui; + //delete dia; } -void ProjectList::setDocument(KdenliveDoc *doc) -{ - m_fps = doc->fps(); - m_timecode = doc->timecode(); - m_commandStack = doc->commandStack(); - m_doc = doc; - QDomNodeList prods = doc->producersList(); - int ct = prods.count(); - kDebug()<<"//////////// SETTING DOC, FOUND CLIPS: "<clear(); - for (int i = 0; i < ct ; i++) - { - QDomElement e = prods.item(i).toElement(); - kDebug()<<"// IMPORT: "<topLevelItem(0); - if (first) listView->setCurrentItem(first); - m_toolbar->setEnabled(true); +void ProjectList::setDocument(KdenliveDoc *doc) { + m_fps = doc->fps(); + m_timecode = doc->timecode(); + m_commandStack = doc->commandStack(); + m_doc = doc; + QDomNodeList prods = doc->producersList(); + int ct = prods.count(); + kDebug() << "//////////// SETTING DOC, FOUND CLIPS: " << prods.count(); + listView->clear(); + for (int i = 0; i < ct ; i++) { + QDomElement e = prods.item(i).toElement(); + kDebug() << "// IMPORT: " << i << ", :" << e.attribute("id", "non") << ", NAME: " << e.attribute("name", "non"); + if (!e.isNull()) addProducer(e); + } + QTreeWidgetItem *first = listView->topLevelItem(0); + if (first) listView->setCurrentItem(first); + m_toolbar->setEnabled(true); } -QDomElement ProjectList::producersList() -{ - QDomDocument doc; - QDomElement prods = doc.createElement("producerlist"); - doc.appendChild(prods); - kDebug()<<"//////////// PRO LIST BUILD PRDSLIST "; +QDomElement ProjectList::producersList() { + QDomDocument doc; + QDomElement prods = doc.createElement("producerlist"); + doc.appendChild(prods); + kDebug() << "//////////// PRO LIST BUILD PRDSLIST "; QTreeWidgetItemIterator it(listView); - while (*it) { - if (!((ProjectItem *)(*it))->isGroup()) - prods.appendChild(doc.importNode(((ProjectItem *)(*it))->toXml(), true)); - ++it; - } - return prods; + while (*it) { + if (!((ProjectItem *)(*it))->isGroup()) + prods.appendChild(doc.importNode(((ProjectItem *)(*it))->toXml(), true)); + ++it; + } + return prods; } -void ProjectList::slotReplyGetFileProperties(int clipId, const QMap < QString, QString > &properties, const QMap < QString, QString > &metadata) -{ - ProjectItem *item = getItemById(clipId); - if (item) { - item->setProperties(properties, metadata); - emit receivedClipDuration(clipId, item->clipMaxDuration()); - } +void ProjectList::slotReplyGetFileProperties(int clipId, const QMap < QString, QString > &properties, const QMap < QString, QString > &metadata) { + ProjectItem *item = getItemById(clipId); + if (item) { + item->setProperties(properties, metadata); + emit receivedClipDuration(clipId, item->clipMaxDuration()); + } } -void ProjectList::slotReplyGetImage(int clipId, int pos, const QPixmap &pix, int w, int h) -{ - ProjectItem *item = getItemById(clipId); - if (item) item->setIcon(0, pix); +void ProjectList::slotReplyGetImage(int clipId, int pos, const QPixmap &pix, int w, int h) { + ProjectItem *item = getItemById(clipId); + if (item) item->setIcon(0, pix); } -ProjectItem *ProjectList::getItemById(int id) -{ +ProjectItem *ProjectList::getItemById(int id) { QTreeWidgetItemIterator it(listView); - while (*it) { - if (((ProjectItem *)(*it))->clipId() == id) - break; - ++it; - } - return ((ProjectItem *)(*it)); + while (*it) { + if (((ProjectItem *)(*it))->clipId() == id) + break; + ++it; + } + return ((ProjectItem *)(*it)); } -void ProjectList::addProducer(QDomElement producer, int parentId) -{ - if (!m_commandStack) kDebug()<<"!!!!!!!!!!!!!!!!  NO CMD STK"; - CLIPTYPE type = (CLIPTYPE) producer.attribute("type").toInt(); +void ProjectList::addProducer(QDomElement producer, int parentId) { + if (!m_commandStack) kDebug() << "!!!!!!!!!!!!!!!!  NO CMD STK"; + CLIPTYPE type = (CLIPTYPE) producer.attribute("type").toInt(); /*QDomDocument doc; QDomElement prods = doc.createElement("list"); doc.appendChild(prods); prods.appendChild(doc.importNode(producer, true));*/ - - - //kDebug()<<"////// ADDING PRODUCER:\n "<= m_clipIdCounter) m_clipIdCounter = id + 1; - else if (id == 0) id = m_clipIdCounter++; - - if (parentId != -1) { - // item is a westley playlist, adjust subproducers ids - id = (parentId + 1) * 10000 + id; - } - if (type == AUDIO || type == VIDEO || type == AV || type == IMAGE || type == PLAYLIST) - { - KUrl resource = KUrl(producer.attribute("resource")); - if (!resource.isEmpty()) { - QStringList itemEntry; - itemEntry.append(QString::null); - itemEntry.append(resource.fileName()); - addClip(itemEntry, producer, id, resource, groupName, parentId); + + + //kDebug()<<"////// ADDING PRODUCER:\n "<= m_clipIdCounter) m_clipIdCounter = id + 1; + else if (id == 0) id = m_clipIdCounter++; + + if (parentId != -1) { + // item is a westley playlist, adjust subproducers ids + id = (parentId + 1) * 10000 + id; + } + if (type == AUDIO || type == VIDEO || type == AV || type == IMAGE || type == PLAYLIST) { + KUrl resource = KUrl(producer.attribute("resource")); + if (!resource.isEmpty()) { + QStringList itemEntry; + itemEntry.append(QString::null); + itemEntry.append(resource.fileName()); + addClip(itemEntry, producer, id, resource, groupName, parentId); + } + } else if (type == COLOR) { + QString colour = producer.attribute("colour"); + QPixmap pix(60, 40); + colour = colour.replace(0, 2, "#"); + pix.fill(QColor(colour.left(7))); + QStringList itemEntry; + itemEntry.append(QString::null); + itemEntry.append(producer.attribute("name", i18n("Color clip"))); + addClip(itemEntry, producer, id, KUrl(), groupName, parentId); } - } - else if (type == COLOR) { - QString colour = producer.attribute("colour"); - QPixmap pix(60, 40); - colour = colour.replace(0, 2, "#"); - pix.fill(QColor(colour.left(7))); - QStringList itemEntry; - itemEntry.append(QString::null); - itemEntry.append(producer.attribute("name", i18n("Color clip"))); - addClip(itemEntry, producer, id, KUrl(), groupName, parentId); - } - + } #include "projectlist.moc" diff --git a/src/projectlist.h b/src/projectlist.h index 35a69d4e..fe3e6c0b 100644 --- a/src/projectlist.h +++ b/src/projectlist.h @@ -38,71 +38,64 @@ class ProjectItem; - const int NameRole = Qt::UserRole; - const int DurationRole = NameRole + 1; - const int UsageRole = NameRole + 2; - -class ItemDelegate: public KExtendableItemDelegate -{ - public: - ItemDelegate(QAbstractItemView* parent = 0): KExtendableItemDelegate(parent) +const int NameRole = Qt::UserRole; +const int DurationRole = NameRole + 1; +const int UsageRole = NameRole + 2; + +class ItemDelegate: public KExtendableItemDelegate { +public: + ItemDelegate(QAbstractItemView* parent = 0): KExtendableItemDelegate(parent) { + } + /* + void expand() { + QWidget *w = new QWidget; + QVBoxLayout *layout = new QVBoxLayout; + layout->addWidget( new KColorButton(w)); + w->setLayout( layout ); + extendItem(w, } -/* -void expand() -{ - QWidget *w = new QWidget; - QVBoxLayout *layout = new QVBoxLayout; - layout->addWidget( new KColorButton(w)); - w->setLayout( layout ); - extendItem(w, -} -*/ - -void paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const -{ - if (index.column() == 1) - { - const bool hover = option.state & (QStyle::State_Selected|QStyle::State_MouseOver|QStyle::State_HasFocus); - QRect r1 = option.rect; - painter->save(); - if (hover) { - painter->setPen(option.palette.color(QPalette::HighlightedText)); - QColor backgroundColor = option.palette.color(QPalette::Highlight); - painter->setBrush(QBrush(backgroundColor)); - painter->fillRect(r1, QBrush(backgroundColor)); + */ + + void paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const { + if (index.column() == 1) { + const bool hover = option.state & (QStyle::State_Selected | QStyle::State_MouseOver | QStyle::State_HasFocus); + QRect r1 = option.rect; + painter->save(); + if (hover) { + painter->setPen(option.palette.color(QPalette::HighlightedText)); + QColor backgroundColor = option.palette.color(QPalette::Highlight); + painter->setBrush(QBrush(backgroundColor)); + painter->fillRect(r1, QBrush(backgroundColor)); + } + QFont font = painter->font(); + font.setPointSize(font.pointSize() - 1); + font.setBold(true); + painter->setFont(font); + int mid = (int)((r1.height() / 2)); + r1.setBottom(r1.y() + mid); + QRect r2 = option.rect; + r2.setTop(r2.y() + mid); + painter->drawText(r1, Qt::AlignLeft | Qt::AlignBottom , index.data().toString()); + //painter->setPen(Qt::green); + font.setBold(false); + painter->setFont(font); + QString subText = index.data(DurationRole).toString(); + int usage = index.data(UsageRole).toInt(); + if (usage != 0) subText.append(QString(" (%1)").arg(usage)); + painter->drawText(r2, Qt::AlignLeft | Qt::AlignVCenter , subText); + painter->restore(); + } else { + KExtendableItemDelegate::paint(painter, option, index); + } } - QFont font = painter->font(); - font.setPointSize(font.pointSize() - 1 ); - font.setBold(true); - painter->setFont(font); - int mid = (int) ((r1.height() / 2 )); - r1.setBottom(r1.y() + mid); - QRect r2 = option.rect; - r2.setTop(r2.y() + mid); - painter->drawText(r1, Qt::AlignLeft | Qt::AlignBottom , index.data().toString()); - //painter->setPen(Qt::green); - font.setBold(false); - painter->setFont(font); - QString subText = index.data(DurationRole).toString(); - int usage = index.data(UsageRole).toInt(); - if (usage != 0) subText.append(QString(" (%1)").arg(usage)); - painter->drawText(r2, Qt::AlignLeft | Qt::AlignVCenter , subText); - painter->restore(); - } - else - { - KExtendableItemDelegate::paint(painter, option, index); - } -} }; -class ProjectList : public QWidget -{ - Q_OBJECT - - public: - ProjectList(QWidget *parent=0); +class ProjectList : public QWidget { + Q_OBJECT + +public: + ProjectList(QWidget *parent = 0); virtual ~ProjectList(); QDomElement producersList(); @@ -110,7 +103,7 @@ class ProjectList : public QWidget void addClip(const QStringList &name, const QDomElement &elem, const int clipId, const KUrl &url = KUrl(), const QString &group = QString::null, int parentId = -1); - public slots: +public slots: void setDocument(KdenliveDoc *doc); void addProducer(QDomElement producer, int parentId = -1); void slotReplyGetImage(int clipId, int pos, const QPixmap &pix, int w, int h); @@ -120,7 +113,7 @@ class ProjectList : public QWidget void slotUpdateClip(int id); - private: +private: ProjectListView *listView; KTreeWidgetSearchLine *searchView; Render *m_render; @@ -137,7 +130,7 @@ class ProjectList : public QWidget ItemDelegate *m_listViewDelegate; KdenliveDoc *m_doc; - private slots: +private slots: void slotAddClip(QUrl givenUrl = QUrl(), const QString &group = QString::null); void slotRemoveClip(); void slotEditClip(); @@ -145,7 +138,7 @@ class ProjectList : public QWidget void slotAddColorClip(); void slotAddTitleClip(); void slotEditClip(QTreeWidgetItem *, int); - void slotContextMenu( const QPoint &pos, QTreeWidgetItem * ); + void slotContextMenu(const QPoint &pos, QTreeWidgetItem *); void slotAddFolder(); /** This is triggered when a clip description has been modified */ void slotUpdateItemDescription(QTreeWidgetItem *item, int column); @@ -153,7 +146,7 @@ class ProjectList : public QWidget - signals: +signals: void clipSelected(const QDomElement &); void getFileProperties(const QDomElement&, int); void receivedClipDuration(int, int); diff --git a/src/projectlistview.cpp b/src/projectlistview.cpp index ab2b7b92..f35f5abb 100644 --- a/src/projectlistview.cpp +++ b/src/projectlistview.cpp @@ -26,112 +26,100 @@ ProjectListView::ProjectListView(QWidget *parent) - : QTreeWidget(parent), m_dragStarted(false) -{ - setSelectionMode(QAbstractItemView::ExtendedSelection); - setDragDropMode(QAbstractItemView::DragDrop); - setDropIndicatorShown(true); - setAlternatingRowColors(true); - setDragEnabled(true); - setAcceptDrops(true); + : QTreeWidget(parent), m_dragStarted(false) { + setSelectionMode(QAbstractItemView::ExtendedSelection); + setDragDropMode(QAbstractItemView::DragDrop); + setDropIndicatorShown(true); + setAlternatingRowColors(true); + setDragEnabled(true); + setAcceptDrops(true); } -ProjectListView::~ProjectListView() -{ +ProjectListView::~ProjectListView() { } -void ProjectListView::editItem ( QTreeWidgetItem * item, int column ) -{ - kDebug()<<"//////////////// EDIT ITEM, COL: "<globalPos(), itemAt(event->pos())); +void ProjectListView::contextMenuEvent(QContextMenuEvent * event) { + emit requestMenu(event->globalPos(), itemAt(event->pos())); } // virtual -void ProjectListView::mouseDoubleClickEvent ( QMouseEvent * event ) -{ - if (!itemAt(event->pos())) emit addClip(); - else if (columnAt(event->pos().x()) == 2) QTreeWidget::mouseDoubleClickEvent( event ); +void ProjectListView::mouseDoubleClickEvent(QMouseEvent * event) { + if (!itemAt(event->pos())) emit addClip(); + else if (columnAt(event->pos().x()) == 2) QTreeWidget::mouseDoubleClickEvent(event); } // virtual -void ProjectListView::dragEnterEvent(QDragEnterEvent *event) -{ - if (event->mimeData()->hasUrls() || event->mimeData()->hasText()) { - kDebug()<<"//////////////// DRAG ENTR OK"; - } - event->acceptProposedAction(); +void ProjectListView::dragEnterEvent(QDragEnterEvent *event) { + if (event->mimeData()->hasUrls() || event->mimeData()->hasText()) { + kDebug() << "//////////////// DRAG ENTR OK"; + } + event->acceptProposedAction(); } // virtual -void ProjectListView::dropEvent(QDropEvent *event) -{ - kDebug()<<"//////////////// DROPPED EVENT"; - if (event->mimeData()->hasUrls()) { - QTreeWidgetItem *item = itemAt(event->pos()); - QString groupName; - if (item) { - if (((ProjectItem *) item)->isGroup()) groupName = item->text(1); - else if (item->parent() && ((ProjectItem *) item->parent())->isGroup()) - groupName = item->parent()->text(1); - } - QList list; - list = event->mimeData()->urls(); - foreach (QUrl url, list) { - emit addClip(url, groupName); - } - - } - else if (event->mimeData()->hasText()) - { - QTreeWidgetItem *item = itemAt(event->pos()); - if (item) { - if (item->parent()) item = item->parent(); - if (((ProjectItem *) item)->isGroup()) { - //emit addClip(event->mimeData->text()); - kDebug()<<"//////////////// DROPPED RIGHT 1 "; - QList list; - list = selectedItems (); - ProjectItem *clone; - foreach (QTreeWidgetItem *it, list) { - // TODO allow dragging of folders ? - if (!((ProjectItem *) it)->isGroup() && ((ProjectItem *) it)->clipId() < 10000) { - if (it->parent()) clone = (ProjectItem* ) it->parent()->takeChild(it->parent()->indexOfChild(it)); - else clone = (ProjectItem* ) takeTopLevelItem(indexOfTopLevelItem(it)); - if (clone) item->addChild(clone); - } - } - } - else item = NULL; +void ProjectListView::dropEvent(QDropEvent *event) { + kDebug() << "//////////////// DROPPED EVENT"; + if (event->mimeData()->hasUrls()) { + QTreeWidgetItem *item = itemAt(event->pos()); + QString groupName; + if (item) { + if (((ProjectItem *) item)->isGroup()) groupName = item->text(1); + else if (item->parent() && ((ProjectItem *) item->parent())->isGroup()) + groupName = item->parent()->text(1); + } + QList list; + list = event->mimeData()->urls(); + foreach(QUrl url, list) { + emit addClip(url, groupName); + } + + } else if (event->mimeData()->hasText()) { + QTreeWidgetItem *item = itemAt(event->pos()); + if (item) { + if (item->parent()) item = item->parent(); + if (((ProjectItem *) item)->isGroup()) { + //emit addClip(event->mimeData->text()); + kDebug() << "//////////////// DROPPED RIGHT 1 "; + QList list; + list = selectedItems(); + ProjectItem *clone; + foreach(QTreeWidgetItem *it, list) { + // TODO allow dragging of folders ? + if (!((ProjectItem *) it)->isGroup() && ((ProjectItem *) it)->clipId() < 10000) { + if (it->parent()) clone = (ProjectItem*) it->parent()->takeChild(it->parent()->indexOfChild(it)); + else clone = (ProjectItem*) takeTopLevelItem(indexOfTopLevelItem(it)); + if (clone) item->addChild(clone); + } + } + } else item = NULL; + } + if (!item) { + kDebug() << "//////////////// DROPPED ON EMPTY ZONE"; + // item dropped in empty zone, move it to top level + QList list; + list = selectedItems(); + ProjectItem *clone; + foreach(QTreeWidgetItem *it, list) { + QTreeWidgetItem *parent = it->parent(); + if (parent && ((ProjectItem *) it)->clipId() < 10000) { + kDebug() << "++ item parent: " << parent->text(1); + clone = (ProjectItem*) parent->takeChild(parent->indexOfChild(it)); + if (clone) addTopLevelItem(clone); + } + } + } } - if (!item) { - kDebug()<<"//////////////// DROPPED ON EMPTY ZONE"; - // item dropped in empty zone, move it to top level - QList list; - list = selectedItems(); - ProjectItem *clone; - foreach (QTreeWidgetItem *it, list) { - QTreeWidgetItem *parent = it->parent(); - if (parent && ((ProjectItem *) it)->clipId() < 10000) { - kDebug()<<"++ item parent: "<text(1); - clone = (ProjectItem* ) parent->takeChild(parent->indexOfChild(it)); - if (clone) addTopLevelItem(clone); - } - } - } - } - event->acceptProposedAction(); + event->acceptProposedAction(); } // virtual -void ProjectListView::mousePressEvent(QMouseEvent *event) -{ - if( event->button() == Qt::LeftButton ) - { +void ProjectListView::mousePressEvent(QMouseEvent *event) { + if (event->button() == Qt::LeftButton) { this->m_DragStartPosition = event->pos(); m_dragStarted = true; } @@ -140,72 +128,69 @@ void ProjectListView::mousePressEvent(QMouseEvent *event) // virtual -void ProjectListView::mouseMoveEvent(QMouseEvent *event) -{ - kDebug()<<"// DRAG STARTED, MOUSE MOVED: "; - if (!m_dragStarted) return; +void ProjectListView::mouseMoveEvent(QMouseEvent *event) { + kDebug() << "// DRAG STARTED, MOUSE MOVED: "; + if (!m_dragStarted) return; - if ((event->pos() - m_DragStartPosition).manhattanLength() + if ((event->pos() - m_DragStartPosition).manhattanLength() < QApplication::startDragDistance()) return; - - { - ProjectItem *clickItem = (ProjectItem *) itemAt(event->pos()); - if (clickItem) { - QDrag *drag = new QDrag(this); - QMimeData *mimeData = new QMimeData; - QDomDocument doc; - QList list; - list = selectedItems (); - QStringList ids; - foreach (QTreeWidgetItem *item, list) { - // TODO allow dragging of folders - if (!((ProjectItem *) item)->isGroup()) - ids.append(QString::number(((ProjectItem *) item)->clipId())); - } - QByteArray data; - data.append(ids.join(";").toUtf8()); //doc.toString().toUtf8()); - mimeData->setData("kdenlive/producerslist",data ); - //mimeData->setText(ids.join(";")); //doc.toString()); - //mimeData->setImageData(image); - drag->setMimeData(mimeData); - drag->setPixmap(clickItem->icon(0).pixmap(50 *16/9.0, 50)); - drag->setHotSpot(QPoint(0, 50)); - drag->start(Qt::MoveAction); - - //Qt::DropAction dropAction; - //dropAction = drag->start(Qt::CopyAction | Qt::MoveAction); - - //Qt::DropAction dropAction = drag->exec(); - + + { + ProjectItem *clickItem = (ProjectItem *) itemAt(event->pos()); + if (clickItem) { + QDrag *drag = new QDrag(this); + QMimeData *mimeData = new QMimeData; + QDomDocument doc; + QList list; + list = selectedItems(); + QStringList ids; + foreach(QTreeWidgetItem *item, list) { + // TODO allow dragging of folders + if (!((ProjectItem *) item)->isGroup()) + ids.append(QString::number(((ProjectItem *) item)->clipId())); + } + QByteArray data; + data.append(ids.join(";").toUtf8()); //doc.toString().toUtf8()); + mimeData->setData("kdenlive/producerslist", data); + //mimeData->setText(ids.join(";")); //doc.toString()); + //mimeData->setImageData(image); + drag->setMimeData(mimeData); + drag->setPixmap(clickItem->icon(0).pixmap(50 *16 / 9.0, 50)); + drag->setHotSpot(QPoint(0, 50)); + drag->start(Qt::MoveAction); + + //Qt::DropAction dropAction; + //dropAction = drag->start(Qt::CopyAction | Qt::MoveAction); + + //Qt::DropAction dropAction = drag->exec(); + + } + //event->accept(); } - //event->accept(); - } } void ProjectListView::dragMoveEvent(QDragMoveEvent * event) { - QTreeWidgetItem * item = itemAt(event->pos()); - event->setDropAction(Qt::IgnoreAction); - //if (item) { - event->setDropAction(Qt::MoveAction); - if (event->mimeData()->hasText()) { - event->acceptProposedAction(); - } - //} + QTreeWidgetItem * item = itemAt(event->pos()); + event->setDropAction(Qt::IgnoreAction); + //if (item) { + event->setDropAction(Qt::MoveAction); + if (event->mimeData()->hasText()) { + event->acceptProposedAction(); + } + //} } -QStringList ProjectListView::mimeTypes () const -{ +QStringList ProjectListView::mimeTypes() const { QStringList qstrList; // list of accepted mime types for drop qstrList.append("text/uri-list"); qstrList.append("text/plain"); return qstrList; } - - -Qt::DropActions ProjectListView::supportedDropActions () const -{ + + +Qt::DropActions ProjectListView::supportedDropActions() const { // returns what actions are supported when dropping return Qt::MoveAction; } diff --git a/src/projectlistview.h b/src/projectlistview.h index 55dd920b..17885b4f 100644 --- a/src/projectlistview.h +++ b/src/projectlistview.h @@ -24,37 +24,36 @@ #include #include -class ProjectListView : public QTreeWidget -{ - Q_OBJECT - - public: - ProjectListView(QWidget *parent=0); +class ProjectListView : public QTreeWidget { + Q_OBJECT + +public: + ProjectListView(QWidget *parent = 0); virtual ~ProjectListView(); - void editItem ( QTreeWidgetItem * item, int column = 0 ); + void editItem(QTreeWidgetItem * item, int column = 0); - protected: - virtual void contextMenuEvent ( QContextMenuEvent * event ); - virtual void mouseDoubleClickEvent ( QMouseEvent * event ); +protected: + virtual void contextMenuEvent(QContextMenuEvent * event); + virtual void mouseDoubleClickEvent(QMouseEvent * event); virtual void mousePressEvent(QMouseEvent *event); virtual void mouseMoveEvent(QMouseEvent *event); virtual void dragEnterEvent(QDragEnterEvent *event); virtual void dropEvent(QDropEvent *event); virtual QStringList mimeTypes() const; - virtual Qt::DropActions supportedDropActions () const; + virtual Qt::DropActions supportedDropActions() const; virtual void dragMoveEvent(QDragMoveEvent * event); - public slots: +public slots: - private: +private: bool m_dragStarted; QPoint m_DragStartPosition; - private slots: +private slots: - signals: +signals: void requestMenu(const QPoint &, QTreeWidgetItem *); void addClip(); void addClip(QUrl, const QString &); diff --git a/src/projectsettings.cpp b/src/projectsettings.cpp index 261633cd..1a3988a0 100644 --- a/src/projectsettings.cpp +++ b/src/projectsettings.cpp @@ -26,30 +26,28 @@ #include "profilesdialog.h" #include "projectsettings.h" -ProjectSettings::ProjectSettings(QWidget * parent): QDialog(parent), m_isCustomProfile(false) -{ - m_view.setupUi(this); +ProjectSettings::ProjectSettings(QWidget * parent): QDialog(parent), m_isCustomProfile(false) { + m_view.setupUi(this); - QStringList profilesNames = ProfilesDialog::getProfileNames(); - m_view.profiles_list->addItems(profilesNames); - QString defaulfProf = ProfilesDialog::getSettingsFromFile(KdenliveSettings::current_profile()).value("description"); - if (profilesNames.contains(defaulfProf)) m_view.profiles_list->setCurrentItem(defaulfProf); + QStringList profilesNames = ProfilesDialog::getProfileNames(); + m_view.profiles_list->addItems(profilesNames); + QString defaulfProf = ProfilesDialog::getSettingsFromFile(KdenliveSettings::current_profile()).value("description"); + if (profilesNames.contains(defaulfProf)) m_view.profiles_list->setCurrentItem(defaulfProf); - slotUpdateDisplay(); - connect(m_view.profiles_list, SIGNAL(currentIndexChanged( int )), this, SLOT(slotUpdateDisplay())); + slotUpdateDisplay(); + connect(m_view.profiles_list, SIGNAL(currentIndexChanged(int)), this, SLOT(slotUpdateDisplay())); } -void ProjectSettings::slotUpdateDisplay() -{ - QString currentProfile = m_view.profiles_list->currentText(); - QMap< QString, QString > values = ProfilesDialog::getSettingsForProfile(currentProfile); - m_view.p_size->setText(values.value("width") + "x" + values.value("height")); - m_view.p_fps->setText(values.value("frame_rate_num") + "/" + values.value("frame_rate_den")); - m_view.p_aspect->setText(values.value("sample_aspect_num") + "/" + values.value("sample_aspect_den")); - m_view.p_display->setText(values.value("display_aspect_num") + "/" + values.value("display_aspect_den")); - if (values.value("progressive").toInt() == 0) m_view.p_progressive->setText(i18n("Interlaced")); - else m_view.p_progressive->setText(i18n("Progressive")); +void ProjectSettings::slotUpdateDisplay() { + QString currentProfile = m_view.profiles_list->currentText(); + QMap< QString, QString > values = ProfilesDialog::getSettingsForProfile(currentProfile); + m_view.p_size->setText(values.value("width") + "x" + values.value("height")); + m_view.p_fps->setText(values.value("frame_rate_num") + "/" + values.value("frame_rate_den")); + m_view.p_aspect->setText(values.value("sample_aspect_num") + "/" + values.value("sample_aspect_den")); + m_view.p_display->setText(values.value("display_aspect_num") + "/" + values.value("display_aspect_den")); + if (values.value("progressive").toInt() == 0) m_view.p_progressive->setText(i18n("Interlaced")); + else m_view.p_progressive->setText(i18n("Progressive")); } diff --git a/src/projectsettings.h b/src/projectsettings.h index 756915df..e165d47b 100644 --- a/src/projectsettings.h +++ b/src/projectsettings.h @@ -25,17 +25,16 @@ #include "ui_projectsettings_ui.h" -class ProjectSettings : public QDialog -{ - Q_OBJECT - - public: +class ProjectSettings : public QDialog { + Q_OBJECT + +public: ProjectSettings(QWidget * parent = 0); - private slots: +private slots: void slotUpdateDisplay(); - private: +private: Ui::ProjectSettings_UI m_view; QStringList m_mltProfilesList; QStringList m_customProfilesList; diff --git a/src/renderer.cpp b/src/renderer.cpp index 2586f078..b890f0eb 100644 --- a/src/renderer.cpp +++ b/src/renderer.cpp @@ -40,52 +40,48 @@ extern "C" { #include "renderer.h" #include "kdenlivesettings.h" -static void consumer_frame_show(mlt_consumer, Render * self, mlt_frame frame_ptr) -{ +static void consumer_frame_show(mlt_consumer, Render * self, mlt_frame frame_ptr) { // detect if the producer has finished playing. Is there a better way to do it ? //if (self->isBlocked) return; - if (mlt_properties_get_double( MLT_FRAME_PROPERTIES( frame_ptr ), "_speed" ) == 0.0) { + if (mlt_properties_get_double(MLT_FRAME_PROPERTIES(frame_ptr), "_speed") == 0.0) { self->emitConsumerStopped(); - } - else - { - self->emitFrameNumber(mlt_frame_get_position(frame_ptr)); + } else { + self->emitFrameNumber(mlt_frame_get_position(frame_ptr)); } } -Render::Render(const QString & rendererName, int winid, int extid, QWidget *parent):QObject(parent), m_name(rendererName), m_mltConsumer(NULL), m_mltProducer(NULL), m_mltTextProducer(NULL), m_sceneList(QDomDocument()), m_winid(-1), m_framePosition(0), m_generateScenelist(false), m_isBlocked(true) -{ - kDebug()<<"////////// USING PROFILE: "<set("resize", 1); - m_mltConsumer->set("window_id", winid); - m_mltConsumer->set("terminate_on_pause", 1); - m_externalwinid = extid; - m_winid = winid; - m_mltConsumer->listen("consumer-frame-show", this, (mlt_listener) consumer_frame_show); - Mlt::Producer *producer = new Mlt::Producer( *m_mltProfile , "westley-xml", ""); - m_mltProducer = producer; - m_mltConsumer->connect(*m_mltProducer); - m_mltProducer->set_speed(0.0); - //m_mltConsumer->start(); - //refresh(); - //initSceneList(); + //Mlt::Consumer *consumer = new Mlt::Consumer( profile , "sdl_preview"); + m_mltConsumer = new Mlt::Consumer(*m_mltProfile , "sdl_preview"); //consumer; + m_mltConsumer->set("resize", 1); + m_mltConsumer->set("window_id", winid); + m_mltConsumer->set("terminate_on_pause", 1); + m_externalwinid = extid; + m_winid = winid; + m_mltConsumer->listen("consumer-frame-show", this, (mlt_listener) consumer_frame_show); + Mlt::Producer *producer = new Mlt::Producer(*m_mltProfile , "westley-xml", ""); + m_mltProducer = producer; + m_mltConsumer->connect(*m_mltProducer); + m_mltProducer->set_speed(0.0); + //m_mltConsumer->start(); + //refresh(); + //initSceneList(); } /*m_osdInfo = new Mlt::Filter("data_show"); char *tmp = decodedString(m_osdProfile); @@ -100,83 +96,75 @@ Render::Render(const QString & rendererName, int winid, int extid, QWidget *pare } */ } -Render::~Render() -{ +Render::~Render() { closeMlt(); } -void Render::closeMlt() -{ +void Render::closeMlt() { delete m_connectTimer; delete osdTimer; delete refreshTimer; if (m_mltConsumer) delete m_mltConsumer; if (m_mltProducer) - delete m_mltProducer; + delete m_mltProducer; //delete m_osdInfo; } -int Render::resetRendererProfile(char * profile) -{ +int Render::resetRendererProfile(char * profile) { if (!m_mltConsumer) return 0; if (!m_mltConsumer->is_stopped()) m_mltConsumer->stop(); m_mltConsumer->set("refresh", 0); //m_mltConsumer->set("profile", profile); - kDebug()<<" + + RESET CONSUMER WITH PROFILE: "<get_consumer() ); + kDebug() << " + + RESET CONSUMER WITH PROFILE: " << profile; + mlt_properties properties = MLT_CONSUMER_PROPERTIES(m_mltConsumer->get_consumer()); // apply_profile_properties( m_profile, m_mltConsumer->get_consumer(), properties ); refresh(); return 1; } /** Wraps the VEML command of the same name; Seeks the renderer clip to the given time. */ -void Render::seek(GenTime time) -{ +void Render::seek(GenTime time) { sendSeekCommand(time); //emit positionChanged(time); } //static -char *Render::decodedString(QString str) -{ +char *Render::decodedString(QString str) { /*QCString fn = QFile::encodeName(str); char *t = new char[fn.length() + 1]; strcpy(t, (const char *)fn);*/ - return qstrdup( str.toUtf8().data() ); //toLatin1 + return qstrdup(str.toUtf8().data()); //toLatin1 } //static -QPixmap Render::frameThumbnail(Mlt::Frame *frame, int width, int height, bool border) -{ +QPixmap Render::frameThumbnail(Mlt::Frame *frame, int width, int height, bool border) { QPixmap pix(width, height); mlt_image_format format = mlt_image_rgb24a; uint8_t *thumb = frame->get_image(format, width, height); QImage image(thumb, width, height, QImage::Format_ARGB32); - + if (!image.isNull()) { - pix = pix.fromImage(image); - if (border) { - QPainter painter(&pix); - painter.drawRect(0, 0, width - 1, height - 1); - } - } - else pix.fill(Qt::black); + pix = pix.fromImage(image); + if (border) { + QPainter painter(&pix); + painter.drawRect(0, 0, width - 1, height - 1); + } + } else pix.fill(Qt::black); return pix; } -QPixmap Render::extractFrame(int frame_position, int width, int height) -{ +QPixmap Render::extractFrame(int frame_position, int width, int height) { QPixmap pix(width, height); if (!m_mltProducer) { - pix.fill(Qt::black); - return pix; + pix.fill(Qt::black); + return pix; } Mlt::Producer *mlt_producer = m_mltProducer->cut(frame_position, frame_position + 1); Mlt::Filter m_convert(*m_mltProfile, "avcolour_space"); @@ -185,49 +173,45 @@ QPixmap Render::extractFrame(int frame_position, int width, int height) Mlt::Frame *frame = mlt_producer->get_frame(); if (frame) { - pix = frameThumbnail(frame, width, height); - delete frame; - } - else pix.fill(Qt::black); + pix = frameThumbnail(frame, width, height); + delete frame; + } else pix.fill(Qt::black); delete mlt_producer; return pix; } -QPixmap Render::getImageThumbnail(KUrl url, int width, int height) -{ +QPixmap Render::getImageThumbnail(KUrl url, int width, int height) { QImage im; QPixmap pixmap; if (url.fileName().startsWith(".all.")) { // check for slideshow - QString fileType = url.fileName().right(3); - QStringList more; - QStringList::Iterator it; + QString fileType = url.fileName().right(3); + QStringList more; + QStringList::Iterator it; - QDir dir( url.directory() ); - more = dir.entryList( QDir::Files ); - - for ( it = more.begin() ; it != more.end() ; ++it ) { - if ((*it).endsWith("."+fileType, Qt::CaseInsensitive)) { - im.load(url.directory() + "/" + *it); - break; - } - } - } - else im.load(url.path()); + QDir dir(url.directory()); + more = dir.entryList(QDir::Files); + + for (it = more.begin() ; it != more.end() ; ++it) { + if ((*it).endsWith("." + fileType, Qt::CaseInsensitive)) { + im.load(url.directory() + "/" + *it); + break; + } + } + } else im.load(url.path()); //pixmap = im.scaled(width, height); return pixmap; } //static -QPixmap Render::getVideoThumbnail(char *profile, QString file, int frame_position, int width, int height) -{ +QPixmap Render::getVideoThumbnail(char *profile, QString file, int frame_position, int width, int height) { QPixmap pix(width, height); char *tmp = decodedString(file); Mlt::Profile *prof = new Mlt::Profile(profile); Mlt::Producer m_producer(*prof, tmp); delete[] tmp; if (m_producer.is_blank()) { - pix.fill(Qt::black); - return pix; + pix.fill(Qt::black); + return pix; } Mlt::Filter m_convert(*prof, "avcolour_space"); @@ -236,8 +220,8 @@ QPixmap Render::getVideoThumbnail(char *profile, QString file, int frame_positio m_producer.seek(frame_position); Mlt::Frame * frame = m_producer.get_frame(); if (frame) { - pix = frameThumbnail(frame, width, height, true); - delete frame; + pix = frameThumbnail(frame, width, height, true); + delete frame; } if (prof) delete prof; return pix; @@ -250,7 +234,7 @@ void Render::getImage(KUrl url, int frame_position, QPoint size) Mlt::Producer m_producer(tmp); delete[] tmp; if (m_producer.is_blank()) { - return; + return; } Mlt::Filter m_convert("avcolour_space"); m_convert.set("forced", mlt_image_rgb24a); @@ -260,9 +244,9 @@ void Render::getImage(KUrl url, int frame_position, QPoint size) Mlt::Frame * frame = m_producer.get_frame(); if (frame) { - QPixmap pix = frameThumbnail(frame, size.x(), size.y(), true); - delete frame; - emit replyGetImage(url, frame_position, pix, size.x(), size.y()); + QPixmap pix = frameThumbnail(frame, size.x(), size.y(), true); + delete frame; + emit replyGetImage(url, frame_position, pix, size.x(), size.y()); } }*/ @@ -286,19 +270,19 @@ void Render::getImage(KUrl url, int frame_position, QPoint size) QImage im; QPixmap pixmap; if (url.fileName().startsWith(".all.")) { // check for slideshow - QString fileType = url.fileName().right(3); - QStringList more; - QStringList::Iterator it; + QString fileType = url.fileName().right(3); + QStringList more; + QStringList::Iterator it; QDir dir( url.directory() ); more = dir.entryList( QDir::Files ); for ( it = more.begin() ; it != more.end() ; ++it ) { if ((*it).endsWith("."+fileType, Qt::CaseInsensitive)) { - if (!im.load(url.directory() + "/" + *it)) - kDebug()<<"++ ERROR LOADIN IMAGE: "<get_double("aspect_ratio_num")/m_mltConsumer->get_double("aspect_ratio_den")); + return (m_mltConsumer->get_double("aspect_ratio_num") / m_mltConsumer->get_double("aspect_ratio_den")); } -int Render::getLength() -{ +int Render::getLength() { - if (m_mltProducer) - { - // kDebug()<<"////// LENGTH: "<get_producer()); - return mlt_producer_get_playtime(m_mltProducer->get_producer()); + if (m_mltProducer) { + // kDebug()<<"////// LENGTH: "<get_producer()); + return mlt_producer_get_playtime(m_mltProducer->get_producer()); } return 0; } -bool Render::isValid(KUrl url) -{ +bool Render::isValid(KUrl url) { char *tmp = decodedString(url.path()); Mlt::Producer producer(*m_mltProfile, tmp); delete[] tmp; if (producer.is_blank()) - return false; + return false; return true; } -void Render::getFileProperties(const QDomElement &xml, int clipId) -{ - int height = 40; - int width = height * 16/9.0; //KdenliveSettings::displayratio(); - QDomDocument doc; - QDomElement westley = doc.createElement("westley"); - doc.appendChild(westley); - westley.appendChild(doc.importNode(xml, true)); - kDebug()<<"////////////\n"< filePropertyMap; - QMap < QString, QString > metadataPropertyMap; - - KUrl url = xml.attribute("resource", QString::null); - filePropertyMap["filename"] = url.path(); - filePropertyMap["duration"] = QString::number(producer.get_playtime()); - kDebug()<<"/////// PRODUCER: "<is_valid()) { - filePropertyMap["width"] = - QString::number(frame->get_int("width")); - filePropertyMap["height"] = - QString::number(frame->get_int("height")); - filePropertyMap["frequency"] = - QString::number(frame->get_int("frequency")); - filePropertyMap["channels"] = - QString::number(frame->get_int("channels")); - - if (frame->get_int("test_image") == 0) { - if (url.path().endsWith(".westley") || url.path().endsWith(".kdenlive")) { - filePropertyMap["type"] = "playlist"; - metadataPropertyMap["comment"] = QString::fromUtf8(mlt_properties_get( MLT_SERVICE_PROPERTIES( producer.get_service() ), "title")); - } - else if (frame->get_int("test_audio") == 0) - filePropertyMap["type"] = "av"; - else - filePropertyMap["type"] = "video"; - - // Generate thumbnail for this frame - QPixmap pixmap = frameThumbnail(frame, width, height, true); - - emit replyGetImage(clipId, 0, pixmap, width, height); - - } else if (frame->get_int("test_audio") == 0) { - QPixmap pixmap(KStandardDirs::locate("appdata", "graphics/music.png")); - emit replyGetImage(clipId, 0, pixmap, width, height); - filePropertyMap["type"] = "audio"; - } - } +void Render::getFileProperties(const QDomElement &xml, int clipId) { + int height = 40; + int width = height * 16 / 9.0; //KdenliveSettings::displayratio(); + QDomDocument doc; + QDomElement westley = doc.createElement("westley"); + doc.appendChild(westley); + westley.appendChild(doc.importNode(xml, true)); + kDebug() << "////////////\n" << doc.toString() << "////////////////\n"; + char *tmp = decodedString(doc.toString()); + + Mlt::Producer producer(*m_mltProfile, "westley-xml", tmp); + delete[] tmp; + + if (producer.is_blank()) { + return; + } + int frameNumber = xml.attribute("frame_thumbnail", 0).toInt(); + if (frameNumber != 0) producer.seek(frameNumber); + mlt_properties properties = MLT_PRODUCER_PROPERTIES(producer.get_producer()); - // Retrieve audio / video codec name + QMap < QString, QString > filePropertyMap; + QMap < QString, QString > metadataPropertyMap; - // Fetch the video_context + KUrl url = xml.attribute("resource", QString::null); + filePropertyMap["filename"] = url.path(); + filePropertyMap["duration"] = QString::number(producer.get_playtime()); + kDebug() << "/////// PRODUCER: " << url.path() << " IS: " << producer.get_playtime(); + Mlt::Filter m_convert(*m_mltProfile, "avcolour_space"); + m_convert.set("forced", mlt_image_rgb24a); + producer.attach(m_convert); + Mlt::Frame * frame = producer.get_frame(); + + filePropertyMap["fps"] = + QString::number(mlt_producer_get_fps(producer.get_producer())); + + if (frame && frame->is_valid()) { + filePropertyMap["width"] = + QString::number(frame->get_int("width")); + filePropertyMap["height"] = + QString::number(frame->get_int("height")); + filePropertyMap["frequency"] = + QString::number(frame->get_int("frequency")); + filePropertyMap["channels"] = + QString::number(frame->get_int("channels")); + + if (frame->get_int("test_image") == 0) { + if (url.path().endsWith(".westley") || url.path().endsWith(".kdenlive")) { + filePropertyMap["type"] = "playlist"; + metadataPropertyMap["comment"] = QString::fromUtf8(mlt_properties_get(MLT_SERVICE_PROPERTIES(producer.get_service()), "title")); + } else if (frame->get_int("test_audio") == 0) + filePropertyMap["type"] = "av"; + else + filePropertyMap["type"] = "video"; + + // Generate thumbnail for this frame + QPixmap pixmap = frameThumbnail(frame, width, height, true); + + emit replyGetImage(clipId, 0, pixmap, width, height); + + } else if (frame->get_int("test_audio") == 0) { + QPixmap pixmap(KStandardDirs::locate("appdata", "graphics/music.png")); + emit replyGetImage(clipId, 0, pixmap, width, height); + filePropertyMap["type"] = "audio"; + } + } + + // Retrieve audio / video codec name + + // Fetch the video_context #if 0 //until the reason for the chrashs is found - AVFormatContext *context = (AVFormatContext *) mlt_properties_get_data( properties, "video_context", NULL ); - if (context != NULL) { - // Get the video_index - int index = mlt_properties_get_int( properties, "video_index" ); - if (context->streams && context->streams [index] && context->streams[ index ]->codec && context->streams[ index ]->codec->codec->name ) - filePropertyMap["videocodec"] = context->streams[ index ]->codec->codec->name; - } - context = (AVFormatContext *) mlt_properties_get_data( properties, "audio_context", NULL ); - if (context != NULL) { - // Get the video_index - int index = mlt_properties_get_int( properties, "audio_index" ); - if (context->streams && context->streams [index] && context->streams[ index ]->codec && context->streams[ index ]->codec->codec->name ) - filePropertyMap["audiocodec"] = context->streams[ index ]->codec->codec->name; - } + AVFormatContext *context = (AVFormatContext *) mlt_properties_get_data(properties, "video_context", NULL); + if (context != NULL) { + // Get the video_index + int index = mlt_properties_get_int(properties, "video_index"); + if (context->streams && context->streams [index] && context->streams[ index ]->codec && context->streams[ index ]->codec->codec->name) + filePropertyMap["videocodec"] = context->streams[ index ]->codec->codec->name; + } + context = (AVFormatContext *) mlt_properties_get_data(properties, "audio_context", NULL); + if (context != NULL) { + // Get the video_index + int index = mlt_properties_get_int(properties, "audio_index"); + if (context->streams && context->streams [index] && context->streams[ index ]->codec && context->streams[ index ]->codec->codec->name) + filePropertyMap["audiocodec"] = context->streams[ index ]->codec->codec->name; + } #endif - // metadata + // metadata - mlt_properties metadata = mlt_properties_new( ); - mlt_properties_pass( metadata, properties, "meta.attr." ); - int count = mlt_properties_count( metadata ); - for ( int i = 0; i < count; i ++ ) - { - QString name = mlt_properties_get_name( metadata, i ); - QString value = QString::fromUtf8(mlt_properties_get_value( metadata, i )); - if (name.endsWith("markup") && !value.isEmpty()) - metadataPropertyMap[ name.section(".", 0, -2) ] = value; - } + mlt_properties metadata = mlt_properties_new(); + mlt_properties_pass(metadata, properties, "meta.attr."); + int count = mlt_properties_count(metadata); + for (int i = 0; i < count; i ++) { + QString name = mlt_properties_get_name(metadata, i); + QString value = QString::fromUtf8(mlt_properties_get_value(metadata, i)); + if (name.endsWith("markup") && !value.isEmpty()) + metadataPropertyMap[ name.section(".", 0, -2)] = value; + } - emit replyGetFileProperties(clipId, filePropertyMap, metadataPropertyMap); - kDebug()<<"REquested fuile info for: "<");*/ + /* + QString tmp = QString("");*/ setSceneList(doc, 0); } /** Create the producer from the Westley QDomDocument */ -void Render::setSceneList(QDomDocument list, int position) -{ +void Render::setSceneList(QDomDocument list, int position) { if (m_winid == -1) return; m_generateScenelist = true; - kWarning()<<"////// RENDER, SET SCENE LIST"; + kWarning() << "////// RENDER, SET SCENE LIST"; -/* - if (!clip.is_valid()) { - kWarning()<<" ++++ WARNING, UNABLE TO CREATE MLT PRODUCER"; - m_generateScenelist = false; - return; - }*/ + /* + if (!clip.is_valid()) { + kWarning()<<" ++++ WARNING, UNABLE TO CREATE MLT PRODUCER"; + m_generateScenelist = false; + return; + }*/ if (m_mltConsumer) { - m_mltConsumer->set("refresh", 0); - if (!m_mltConsumer->is_stopped()) { - //emitConsumerStopped(); - m_mltConsumer->stop(); - } + m_mltConsumer->set("refresh", 0); + if (!m_mltConsumer->is_stopped()) { + //emitConsumerStopped(); + m_mltConsumer->stop(); + } } if (m_mltProducer) { - m_mltProducer->set_speed(0.0); + m_mltProducer->set_speed(0.0); - //if (KdenliveSettings::osdtimecode() && m_osdInfo) m_mltProducer->detach(*m_osdInfo); + //if (KdenliveSettings::osdtimecode() && m_osdInfo) m_mltProducer->detach(*m_osdInfo); - delete m_mltProducer; - m_mltProducer = NULL; - emit stopped(); + delete m_mltProducer; + m_mltProducer = NULL; + emit stopped(); } char *tmp = decodedString(list.toString()); @@ -531,83 +505,81 @@ void Render::setSceneList(QDomDocument list, int position) if (position != 0) m_mltProducer->seek(position); /*if (KdenliveSettings::osdtimecode()) { - // Attach filter for on screen display of timecode - delete m_osdInfo; - QString attr = "attr_check"; - mlt_filter filter = mlt_factory_filter( "data_feed", (char*) attr.ascii() ); - mlt_properties_set_int( MLT_FILTER_PROPERTIES( filter ), "_fezzik", 1 ); - mlt_producer_attach( m_mltProducer->get_producer(), filter ); - mlt_filter_close( filter ); - - m_osdInfo = new Mlt::Filter("data_show"); - tmp = decodedString(m_osdProfile); - m_osdInfo->set("resource", tmp); - delete[] tmp; - mlt_properties properties = MLT_PRODUCER_PROPERTIES(m_mltProducer->get_producer()); - mlt_properties_set_int( properties, "meta.attr.timecode", 1); - mlt_properties_set( properties, "meta.attr.timecode.markup", "#timecode#"); - m_osdInfo->set("dynamic", "1"); - - if (m_mltProducer->attach(*m_osdInfo) == 1) kDebug()<<"////// error attaching filter"; - } else { - m_osdInfo->set("dynamic", "0"); - }*/ - - m_fps = m_mltProducer->get_fps(); - - emit durationChanged(m_mltProducer->get_playtime()); - //m_connectTimer->start( 500 ); - connectPlaylist(); - m_generateScenelist = false; - + // Attach filter for on screen display of timecode + delete m_osdInfo; + QString attr = "attr_check"; + mlt_filter filter = mlt_factory_filter( "data_feed", (char*) attr.ascii() ); + mlt_properties_set_int( MLT_FILTER_PROPERTIES( filter ), "_fezzik", 1 ); + mlt_producer_attach( m_mltProducer->get_producer(), filter ); + mlt_filter_close( filter ); + + m_osdInfo = new Mlt::Filter("data_show"); + tmp = decodedString(m_osdProfile); + m_osdInfo->set("resource", tmp); + delete[] tmp; + mlt_properties properties = MLT_PRODUCER_PROPERTIES(m_mltProducer->get_producer()); + mlt_properties_set_int( properties, "meta.attr.timecode", 1); + mlt_properties_set( properties, "meta.attr.timecode.markup", "#timecode#"); + m_osdInfo->set("dynamic", "1"); + + if (m_mltProducer->attach(*m_osdInfo) == 1) kDebug()<<"////// error attaching filter"; + } else { + m_osdInfo->set("dynamic", "0"); + }*/ + + m_fps = m_mltProducer->get_fps(); + + emit durationChanged(m_mltProducer->get_playtime()); + //m_connectTimer->start( 500 ); + connectPlaylist(); + m_generateScenelist = false; + } -const double Render::fps() const -{ +const double Render::fps() const { return m_fps; } void Render::connectPlaylist() { - m_connectTimer->stop(); - m_mltConsumer->connect(*m_mltProducer); - m_mltProducer->set_speed(0.0); - m_mltConsumer->start(); - //refresh(); -/* - if (m_mltConsumer->start() == -1) { - KMessageBox::error(qApp->activeWindow(), i18n("Could not create the video preview window.\nThere is something wrong with your Kdenlive install or your driver settings, please fix it.")); - m_mltConsumer = NULL; - } - else { - refresh(); - }*/ + m_connectTimer->stop(); + m_mltConsumer->connect(*m_mltProducer); + m_mltProducer->set_speed(0.0); + m_mltConsumer->start(); + //refresh(); + /* + if (m_mltConsumer->start() == -1) { + KMessageBox::error(qApp->activeWindow(), i18n("Could not create the video preview window.\nThere is something wrong with your Kdenlive install or your driver settings, please fix it.")); + m_mltConsumer = NULL; + } + else { + refresh(); + }*/ } void Render::refreshDisplay() { - if (!m_mltProducer) return; - m_mltConsumer->set("refresh", 0); - - mlt_properties properties = MLT_PRODUCER_PROPERTIES(m_mltProducer->get_producer()); - /*if (KdenliveSettings::osdtimecode()) { - mlt_properties_set_int( properties, "meta.attr.timecode", 1); - mlt_properties_set( properties, "meta.attr.timecode.markup", "#timecode#"); - m_osdInfo->set("dynamic", "1"); - m_mltProducer->attach(*m_osdInfo); - } - else { - m_mltProducer->detach(*m_osdInfo); - m_osdInfo->set("dynamic", "0"); - }*/ - refresh(); + if (!m_mltProducer) return; + m_mltConsumer->set("refresh", 0); + + mlt_properties properties = MLT_PRODUCER_PROPERTIES(m_mltProducer->get_producer()); + /*if (KdenliveSettings::osdtimecode()) { + mlt_properties_set_int( properties, "meta.attr.timecode", 1); + mlt_properties_set( properties, "meta.attr.timecode.markup", "#timecode#"); + m_osdInfo->set("dynamic", "1"); + m_mltProducer->attach(*m_osdInfo); + } + else { + m_mltProducer->detach(*m_osdInfo); + m_osdInfo->set("dynamic", "0"); + }*/ + refresh(); } -void Render::setVolume(double volume) -{ +void Render::setVolume(double volume) { if (!m_mltConsumer || !m_mltProducer) return; /*osdTimer->stop(); - m_mltConsumer->set("refresh", 0); + m_mltConsumer->set("refresh", 0); // Attach filter for on screen display of timecode mlt_properties properties = MLT_PRODUCER_PROPERTIES(m_mltProducer->get_producer()); mlt_properties_set_double( properties, "meta.volume", volume ); @@ -615,16 +587,15 @@ void Render::setVolume(double volume) mlt_properties_set( properties, "meta.attr.osdvolume.markup", i18n("Volume: ") + QString::number(volume * 100)); if (!KdenliveSettings::osdtimecode()) { - m_mltProducer->detach(*m_osdInfo); - mlt_properties_set_int( properties, "meta.attr.timecode", 0); - if (m_mltProducer->attach(*m_osdInfo) == 1) kDebug()<<"////// error attaching filter"; + m_mltProducer->detach(*m_osdInfo); + mlt_properties_set_int( properties, "meta.attr.timecode", 0); + if (m_mltProducer->attach(*m_osdInfo) == 1) kDebug()<<"////// error attaching filter"; }*/ refresh(); - osdTimer->setSingleShot(2500 ); + osdTimer->setSingleShot(2500); } -void Render::slotOsdTimeout() -{ +void Render::slotOsdTimeout() { mlt_properties properties = MLT_PRODUCER_PROPERTIES(m_mltProducer->get_producer()); mlt_properties_set_int(properties, "meta.attr.osdvolume", 0); mlt_properties_set(properties, "meta.attr.osdvolume.markup", NULL); @@ -632,241 +603,218 @@ void Render::slotOsdTimeout() refresh(); } -void Render::start() -{ - kDebug()<<"----- STARTING MONITOR: "<is_stopped()) { - kDebug()<<"----- MONITOR: "<start() == -1) { - KMessageBox::error(qApp->activeWindow(), i18n("Could not create the video preview window.\nThere is something wrong with your Kdenlive install or your driver settings, please fix it.")); - m_mltConsumer = NULL; - return; - } - else { - kDebug()<<"----- MONITOR: "<start() == -1) { + KMessageBox::error(qApp->activeWindow(), i18n("Could not create the video preview window.\nThere is something wrong with your Kdenlive install or your driver settings, please fix it.")); + m_mltConsumer = NULL; + return; + } else { + kDebug() << "----- MONITOR: " << m_name << " REFRESH"; + refresh(); + } } m_isBlocked = false; } -void Render::clear() -{ +void Render::clear() { if (m_mltConsumer) { - m_mltConsumer->set("refresh", 0); - if (!m_mltConsumer->is_stopped()) m_mltConsumer->stop(); + m_mltConsumer->set("refresh", 0); + if (!m_mltConsumer->is_stopped()) m_mltConsumer->stop(); } if (m_mltProducer) { - //if (KdenliveSettings::osdtimecode() && m_osdInfo) m_mltProducer->detach(*m_osdInfo); - m_mltProducer->set_speed(0.0); - delete m_mltProducer; - m_mltProducer = NULL; - emit stopped(); + //if (KdenliveSettings::osdtimecode() && m_osdInfo) m_mltProducer->detach(*m_osdInfo); + m_mltProducer->set_speed(0.0); + delete m_mltProducer; + m_mltProducer = NULL; + emit stopped(); } } -void Render::stop() -{ +void Render::stop() { if (m_mltConsumer && !m_mltConsumer->is_stopped()) { - kDebug()<<"///////////// RENDER STOPPED: "<set("refresh", 0); - m_mltConsumer->stop(); + kDebug() << "///////////// RENDER STOPPED: " << m_name; + m_mltConsumer->set("refresh", 0); + m_mltConsumer->stop(); } - kDebug()<<"///////////// RENDER STOP2-------"; + kDebug() << "///////////// RENDER STOP2-------"; m_isBlocked = true; if (m_mltProducer) { - m_mltProducer->set_speed(0.0); - m_mltProducer->set("out", m_mltProducer->get_length() - 1); + m_mltProducer->set_speed(0.0); + m_mltProducer->set("out", m_mltProducer->get_length() - 1); } - kDebug()<<"///////////// RENDER STOP3-------"; + kDebug() << "///////////// RENDER STOP3-------"; } -void Render::stop(const GenTime & startTime) -{ - kDebug()<<"///////////// RENDER STOP-------2"; +void Render::stop(const GenTime & startTime) { + kDebug() << "///////////// RENDER STOP-------2"; if (m_mltProducer) { - m_mltProducer->set_speed(0.0); - m_mltProducer->seek((int) startTime.frames(m_fps)); + m_mltProducer->set_speed(0.0); + m_mltProducer->seek((int) startTime.frames(m_fps)); } m_mltConsumer->purge(); } -void Render::switchPlay() -{ +void Render::switchPlay() { if (!m_mltProducer) - return; + return; if (m_mltProducer->get_speed() == 0.0) m_mltProducer->set_speed(1.0); else { - m_mltProducer->set_speed(0.0); - kDebug()<<"// POSITON: "<seek((int) m_framePosition); + m_mltProducer->set_speed(0.0); + kDebug() << "// POSITON: " << m_framePosition; + m_mltProducer->seek((int) m_framePosition); } /*if (speed == 0.0) { - m_mltProducer->seek((int) m_framePosition + 1); + m_mltProducer->seek((int) m_framePosition + 1); m_mltConsumer->purge(); }*/ refresh(); } -void Render::play(double speed) -{ +void Render::play(double speed) { if (!m_mltProducer) - return; + return; if (speed == 0.0) m_mltProducer->set("out", m_mltProducer->get_length() - 1); m_mltProducer->set_speed(speed); /*if (speed == 0.0) { - m_mltProducer->seek((int) m_framePosition + 1); + m_mltProducer->seek((int) m_framePosition + 1); m_mltConsumer->purge(); }*/ refresh(); } -void Render::play(double speed, const GenTime & startTime) -{ - kDebug()<<"///////////// RENDER PLAY2-------"<set("out", m_mltProducer->get_length() - 1); //if (speed == 0.0) m_mltConsumer->set("refresh", 0); m_mltProducer->set_speed(speed); - m_mltProducer->seek((int) (startTime.frames(m_fps))); + m_mltProducer->seek((int)(startTime.frames(m_fps))); //m_mltConsumer->purge(); //refresh(); } void Render::play(double speed, const GenTime & startTime, - const GenTime & stopTime) -{ - kDebug()<<"///////////// RENDER PLAY3-------"<set("out", stopTime.frames(m_fps)); - m_mltProducer->seek((int) (startTime.frames(m_fps))); + m_mltProducer->seek((int)(startTime.frames(m_fps))); m_mltConsumer->purge(); m_mltProducer->set_speed(speed); refresh(); } -void Render::render(const KUrl & url) -{ +void Render::render(const KUrl & url) { QDomDocument doc; QDomElement elem = doc.createElement("render"); elem.setAttribute("filename", url.path()); doc.appendChild(elem); } -void Render::sendSeekCommand(GenTime time) -{ +void Render::sendSeekCommand(GenTime time) { if (!m_mltProducer) - return; + return; //kDebug()<<"////////// KDENLIVE SEEK: "<<(int) (time.frames(m_fps)); - m_mltProducer->seek((int) (time.frames(m_fps))); + m_mltProducer->seek((int)(time.frames(m_fps))); refresh(); } -void Render::seekToFrame(int pos) -{ +void Render::seekToFrame(int pos) { if (!m_mltProducer) - return; + return; //kDebug()<<"////////// KDENLIVE SEEK: "<<(int) (time.frames(m_fps)); m_mltProducer->seek(pos); refresh(); } -void Render::askForRefresh() -{ +void Render::askForRefresh() { // Use a Timer so that we don't refresh too much - refreshTimer->start( 200 ); + refreshTimer->start(200); } -void Render::doRefresh() -{ +void Render::doRefresh() { // Use a Timer so that we don't refresh too much refresh(); } -void Render::refresh() -{ +void Render::refresh() { if (!m_mltProducer || m_isBlocked) - return; + return; refreshTimer->stop(); if (m_mltConsumer) { - m_mltConsumer->set("refresh", 1); + m_mltConsumer->set("refresh", 1); } } /** Sets the description of this renderer to desc. */ -void Render::setDescription(const QString & description) -{ +void Render::setDescription(const QString & description) { m_description = description; } /** Returns the description of this renderer */ -QString Render::description() -{ +QString Render::description() { return m_description; } -double Render::playSpeed() -{ +double Render::playSpeed() { if (m_mltProducer) return m_mltProducer->get_speed(); return 0.0; } -const GenTime & Render::seekPosition() const -{ +const GenTime & Render::seekPosition() const { if (m_mltProducer) return GenTime((int) m_mltProducer->position(), m_fps); else return GenTime(); } -const QString & Render::rendererName() const -{ +const QString & Render::rendererName() const { return m_name; } -void Render::emitFrameNumber(double position) -{ - //kDebug()<<"// POSITON: "<activeWindow()) QApplication::postEvent(qApp->activeWindow(), new PositionChangeEvent( GenTime((int) position, m_fps), m_monitorId)); +void Render::emitFrameNumber(double position) { + //kDebug()<<"// POSITON: "<activeWindow()) QApplication::postEvent(qApp->activeWindow(), new PositionChangeEvent( GenTime((int) position, m_fps), m_monitorId)); } -void Render::emitConsumerStopped() -{ +void Render::emitConsumerStopped() { // This is used to know when the playing stopped if (m_mltProducer && !m_generateScenelist) { - double pos = m_mltProducer->position(); - emit rendererStopped((int) pos); + double pos = m_mltProducer->position(); + emit rendererStopped((int) pos); //if (qApp->activeWindow()) QApplication::postEvent(qApp->activeWindow(), new PositionChangeEvent(GenTime((int) pos, m_fps), m_monitorId + 100)); - //new QCustomEvent(10002)); + //new QCustomEvent(10002)); } } -void Render::exportFileToFirewire(QString srcFileName, int port, GenTime startTime, GenTime endTime) -{ -KMessageBox::sorry(0, i18n("Firewire is not enabled on your system.\n Please install Libiec61883 and recompile Kdenlive")); +void Render::exportFileToFirewire(QString srcFileName, int port, GenTime startTime, GenTime endTime) { + KMessageBox::sorry(0, i18n("Firewire is not enabled on your system.\n Please install Libiec61883 and recompile Kdenlive")); } void Render::exportCurrentFrame(KUrl url, bool notify) { if (!m_mltProducer) { - KMessageBox::sorry(qApp->activeWindow(), i18n("There is no clip, cannot extract frame.")); - return; + KMessageBox::sorry(qApp->activeWindow(), i18n("There is no clip, cannot extract frame.")); + return; } int height = 1080;//KdenliveSettings::defaultheight(); @@ -879,81 +827,79 @@ void Render::exportCurrentFrame(KUrl url, bool notify) { Mlt::Frame * frame = m_mltProducer->get_frame(); m_mltProducer->detach(m_convert); if (frame) { - pix = frameThumbnail(frame, width, height); - delete frame; + pix = frameThumbnail(frame, width, height); + delete frame; } pix.save(url.path(), "PNG"); //if (notify) QApplication::postEvent(qApp->activeWindow(), new UrlEvent(url, 10003)); } -/** MLT PLAYLIST DIRECT MANIPULATON **/ +/** MLT PLAYLIST DIRECT MANIPULATON **/ -void Render::mltCheckLength() -{ +void Render::mltCheckLength() { //kDebug()<<"checking track length: "<get_service()); Mlt::Tractor tractor(service); - int trackNb = tractor.count( ); + int trackNb = tractor.count(); double duration = 0; double trackDuration; if (trackNb == 1) { Mlt::Producer trackProducer(tractor.track(0)); - Mlt::Playlist trackPlaylist(( mlt_playlist ) trackProducer.get_service()); + Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service()); duration = Mlt::Producer(trackPlaylist.get_producer()).get_playtime() - 1; - m_mltProducer->set("out", duration); - emit durationChanged(duration); - return; + m_mltProducer->set("out", duration); + emit durationChanged(duration); + return; } while (trackNb > 1) { Mlt::Producer trackProducer(tractor.track(trackNb - 1)); - Mlt::Playlist trackPlaylist(( mlt_playlist ) trackProducer.get_service()); + Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service()); trackDuration = Mlt::Producer(trackPlaylist.get_producer()).get_playtime() - 1; - kDebug()<<" / / /DURATON FOR TRACK "< 14000) { // - mltInsertClip(0, GenTime(i * 14000, m_fps), black); - dur = dur - 14000; - i++; + mltInsertClip(0, GenTime(i * 14000, m_fps), black); + dur = dur - 14000; + i++; } - black.setAttribute("out", QString::number(dur)); - mltInsertClip(0, GenTime(), black); + black.setAttribute("out", QString::number(dur)); + mltInsertClip(0, GenTime(), black); - m_mltProducer->set("out", duration); - emit durationChanged(duration); + m_mltProducer->set("out", duration); + emit durationChanged(duration); } } -void Render::mltInsertClip(int track, GenTime position, QDomElement element) -{ +void Render::mltInsertClip(int track, GenTime position, QDomElement element) { if (!m_mltProducer) { - kDebug()<<"PLAYLIST NOT INITIALISED //////"; - return; + kDebug() << "PLAYLIST NOT INITIALISED //////"; + return; } Mlt::Producer parentProd(m_mltProducer->parent()); if (parentProd.get_producer() == NULL) { - kDebug()<<"PLAYLIST BROKEN, CANNOT INSERT CLIP //////"; - return; + kDebug() << "PLAYLIST BROKEN, CANNOT INSERT CLIP //////"; + return; } m_isBlocked = true; Mlt::Service service(parentProd.get_service()); @@ -962,9 +908,9 @@ void Render::mltInsertClip(int track, GenTime position, QDomElement element) QDomDocument doc; doc.appendChild(doc.importNode(element, true)); QString resource = doc.toString(); - kDebug()<<"/////// ADDING CLIP TMLNE: "<parent().get_service()); Mlt::Tractor tractor(service); Mlt::Producer trackProducer(tractor.track(track)); - Mlt::Playlist trackPlaylist(( mlt_playlist ) trackProducer.get_service()); + Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service()); trackPlaylist.split_at(position.frames(m_fps)); trackPlaylist.consolidate_blanks(0); - kDebug()<<"/ / / /CUTTING CLIP AT: "<parent().get_service()); Mlt::Tractor tractor(service); Mlt::Producer trackProducer(tractor.track(track)); - Mlt::Playlist trackPlaylist(( mlt_playlist ) trackProducer.get_service()); + Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service()); int clipIndex = trackPlaylist.get_clip_index_at(position.frames(m_fps)); //trackPlaylist.remove(clipIndex); trackPlaylist.replace_with_blank(clipIndex); @@ -1007,19 +951,18 @@ void Render::mltRemoveClip(int track, GenTime position) m_isBlocked = false; } -void Render::mltRemoveEffect(int track, GenTime position, QString index, bool doRefresh) -{ +void Render::mltRemoveEffect(int track, GenTime position, QString index, bool doRefresh) { Mlt::Service service(m_mltProducer->parent().get_service()); Mlt::Tractor tractor(service); Mlt::Producer trackProducer(tractor.track(track)); - Mlt::Playlist trackPlaylist(( mlt_playlist ) trackProducer.get_service()); + Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service()); //int clipIndex = trackPlaylist.get_clip_index_at(position.frames(m_fps)); Mlt::Producer *clip = trackPlaylist.get_clip_at(position.frames(m_fps)); if (!clip) { - kDebug()<<" / / / CANNOT FIND CLIP TO REMOVE EFFECT"; - return; + kDebug() << " / / / CANNOT FIND CLIP TO REMOVE EFFECT"; + return; } m_isBlocked = true; Mlt::Service clipService(clip->get_service()); @@ -1027,32 +970,30 @@ void Render::mltRemoveEffect(int track, GenTime position, QString index, bool do // if (tag.startsWith("ladspa")) tag = "ladspa"; int ct = 0; - Mlt::Filter *filter = clipService.filter( ct ); - while (filter) { - if (index == "-1" || filter->get("kdenlive_ix") == index) {// && filter->get("kdenlive_id") == id) { - clipService.detach(*filter); - kDebug()<<" / / / DLEETED EFFECT: "<get("kdenlive_ix") == index) {// && filter->get("kdenlive_id") == id) { + clipService.detach(*filter); + kDebug() << " / / / DLEETED EFFECT: " << ct; + } else ct++; + filter = clipService.filter(ct); + } m_isBlocked = false; if (doRefresh) refresh(); } -void Render::mltAddEffect(int track, GenTime position, QMap args, bool doRefresh) -{ +void Render::mltAddEffect(int track, GenTime position, QMap args, bool doRefresh) { Mlt::Service service(m_mltProducer->parent().get_service()); Mlt::Tractor tractor(service); Mlt::Producer trackProducer(tractor.track(track)); - Mlt::Playlist trackPlaylist(( mlt_playlist ) trackProducer.get_service()); + Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service()); Mlt::Producer *clip = trackPlaylist.get_clip_at(position.frames(m_fps)); if (!clip) { - kDebug()<<"********** CANNOT FIND CLIP TO APPLY EFFECT-----------"; - return; + kDebug() << "********** CANNOT FIND CLIP TO APPLY EFFECT-----------"; + return; } Mlt::Service clipService(clip->get_service()); m_isBlocked = true; @@ -1063,36 +1004,35 @@ void Render::mltAddEffect(int track, GenTime position, QMap a char *filterId = decodedString(tag); Mlt::Filter *filter = new Mlt::Filter(*m_mltProfile, filterId); if (filter && filter->is_valid()) - filter->set("kdenlive_id", filterId); + filter->set("kdenlive_id", filterId); else { - kDebug() << "filter is NULL"; - return; + kDebug() << "filter is NULL"; + return; } QMap::Iterator it; QString keyFrameNumber = "#0"; - for ( it = args.begin(); it != args.end(); ++it ) { - //kDebug()<<" / / INSERTING EFFECT ARGS: "<set("kdenlive_id", filterId); - keyFrameNumber = currentKeyFrameNumber; - } - key = it.key().section(":", 1); - } - else key = it.key(); + for (it = args.begin(); it != args.end(); ++it) { + //kDebug()<<" / / INSERTING EFFECT ARGS: "<set("kdenlive_id", filterId); + keyFrameNumber = currentKeyFrameNumber; + } + key = it.key().section(":", 1); + } else key = it.key(); char *name = decodedString(key); char *value = decodedString(it.value()); filter->set(name, value); - delete[] name; - delete[] value; + delete[] name; + delete[] value; } // attach filter to the clip clipService.attach(*filter); @@ -1102,16 +1042,15 @@ void Render::mltAddEffect(int track, GenTime position, QMap a } -void Render::mltEditEffect(int track, GenTime position, QMap args) -{ +void Render::mltEditEffect(int track, GenTime position, QMap args) { QString index = args.value("kdenlive_ix"); QString tag = args.value("tag"); QMap::Iterator it = args.begin(); if (it.key().startsWith("#") || tag.startsWith("ladspa") || tag == "sox" || tag == "autotrack_rectangle") { - // This is a keyframe effect, to edit it, we remove it and re-add it. - mltRemoveEffect(track, position,index); - mltAddEffect(track, position, args); - return; + // This is a keyframe effect, to edit it, we remove it and re-add it. + mltRemoveEffect(track, position, index); + mltAddEffect(track, position, args); + return; } m_isBlocked = true; // create filter @@ -1119,13 +1058,13 @@ void Render::mltEditEffect(int track, GenTime position, QMap Mlt::Tractor tractor(service); Mlt::Producer trackProducer(tractor.track(track)); - Mlt::Playlist trackPlaylist(( mlt_playlist ) trackProducer.get_service()); + Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service()); //int clipIndex = trackPlaylist.get_clip_index_at(position.frames(m_fps)); Mlt::Producer *clip = trackPlaylist.get_clip_at(position.frames(m_fps)); if (!clip) { - kDebug()<<"WARINIG, CANNOT FIND CLIP ON track: "<get_service()); @@ -1133,61 +1072,59 @@ void Render::mltEditEffect(int track, GenTime position, QMap // if (tag.startsWith("ladspa")) tag = "ladspa"; int ct = 0; - Mlt::Filter *filter = clipService.filter( ct ); + Mlt::Filter *filter = clipService.filter(ct); while (filter) { - if (filter->get("kdenlive_ix") == index) { - break; - } - ct++; - filter = clipService.filter( ct ); + if (filter->get("kdenlive_ix") == index) { + break; + } + ct++; + filter = clipService.filter(ct); } if (!filter) { - kDebug()<<"WARINIG, FILTER FOR EDITING NOT FOUND, ADDING IT!!!!!"; - mltAddEffect(track, position, args); - m_isBlocked = false; - return; + kDebug() << "WARINIG, FILTER FOR EDITING NOT FOUND, ADDING IT!!!!!"; + mltAddEffect(track, position, args); + m_isBlocked = false; + return; } - for ( it = args.begin(); it != args.end(); ++it ) { - kDebug()<<" / / EDITING EFFECT ARGS: "<set(name, value); - delete[] name; - delete[] value; + delete[] name; + delete[] value; } m_isBlocked = false; refresh(); } -void Render::mltResizeClipEnd(int track, GenTime pos, GenTime in, GenTime out) -{ +void Render::mltResizeClipEnd(int track, GenTime pos, GenTime in, GenTime out) { m_isBlocked = true; Mlt::Service service(m_mltProducer->parent().get_service()); Mlt::Tractor tractor(service); Mlt::Producer trackProducer(tractor.track(track)); - Mlt::Playlist trackPlaylist(( mlt_playlist ) trackProducer.get_service()); - if (trackPlaylist.is_blank_at(pos.frames(m_fps) + 1)) - kDebug()<<"//////// ERROR RSIZING BLANK CLIP!!!!!!!!!!!"; + Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service()); + if (trackPlaylist.is_blank_at(pos.frames(m_fps) + 1)) + kDebug() << "//////// ERROR RSIZING BLANK CLIP!!!!!!!!!!!"; int clipIndex = trackPlaylist.get_clip_index_at(pos.frames(m_fps) + 1); int previousDuration = trackPlaylist.clip_length(clipIndex) - 1; int newDuration = out.frames(m_fps) - 1; - kDebug()<<" ** RESIZING CLIP END:" << clipIndex << " on track:"<< track <<", mid pos: "<refresh(); @@ -1196,154 +1133,145 @@ void Render::mltResizeClipEnd(int track, GenTime pos, GenTime in, GenTime out) m_isBlocked = false; } -void Render::mltChangeTrackState(int track, bool mute, bool blind) -{ +void Render::mltChangeTrackState(int track, bool mute, bool blind) { Mlt::Service service(m_mltProducer->parent().get_service()); Mlt::Tractor tractor(service); Mlt::Producer trackProducer(tractor.track(track)); - Mlt::Playlist trackPlaylist(( mlt_playlist ) trackProducer.get_service()); + Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service()); if (mute) { - if (blind) trackProducer.set("hide", 3); - else trackProducer.set("hide", 2); - } - else if (blind) { - trackProducer.set("hide", 1); - } - else { - trackProducer.set("hide", 0); + if (blind) trackProducer.set("hide", 3); + else trackProducer.set("hide", 2); + } else if (blind) { + trackProducer.set("hide", 1); + } else { + trackProducer.set("hide", 0); } tractor.multitrack()->refresh(); tractor.refresh(); refresh(); } -void Render::mltResizeClipStart(int track, GenTime pos, GenTime moveEnd, GenTime moveStart, GenTime in, GenTime out) -{ +void Render::mltResizeClipStart(int track, GenTime pos, GenTime moveEnd, GenTime moveStart, GenTime in, GenTime out) { m_isBlocked = true; Mlt::Service service(m_mltProducer->parent().get_service()); int moveFrame = (moveEnd - moveStart).frames(m_fps); Mlt::Tractor tractor(service); Mlt::Producer trackProducer(tractor.track(track)); - Mlt::Playlist trackPlaylist(( mlt_playlist ) trackProducer.get_service()); - if (trackPlaylist.is_blank_at(pos.frames(m_fps) - 1)) - kDebug()<<"//////// ERROR RSIZING BLANK CLIP!!!!!!!!!!!"; + Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service()); + if (trackPlaylist.is_blank_at(pos.frames(m_fps) - 1)) + kDebug() << "//////// ERROR RSIZING BLANK CLIP!!!!!!!!!!!"; int clipIndex = trackPlaylist.get_clip_index_at(pos.frames(m_fps) - 1); - kDebug()<<" ** RESIZING CLIP START:" << clipIndex << " on track:"<< track <<", mid pos: "< 0) trackPlaylist.insert_blank(clipIndex, moveFrame - 1); else { - int midpos = moveStart.frames(m_fps) - 1; //+ (moveFrame / 2) - int blankIndex = trackPlaylist.get_clip_index_at(midpos); - int blankLength = trackPlaylist.clip_length(blankIndex); + int midpos = moveStart.frames(m_fps) - 1; //+ (moveFrame / 2) + int blankIndex = trackPlaylist.get_clip_index_at(midpos); + int blankLength = trackPlaylist.clip_length(blankIndex); + + kDebug() << " + resizing blank: " << blankIndex << ", Mid: " << midpos << ", Length: " << blankLength << ", SIZE DIFF: " << moveFrame; - kDebug()<<" + resizing blank: "<set("refresh", 0); Mlt::Service service(m_mltProducer->parent().get_service()); Mlt::Tractor tractor(service); Mlt::Producer trackProducer(tractor.track(startTrack)); - Mlt::Playlist trackPlaylist(( mlt_playlist ) trackProducer.get_service()); + Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service()); int clipIndex = trackPlaylist.get_clip_index_at(moveStart + 1); mlt_field field = mlt_tractor_field(tractor.get_tractor()); mlt_multitrack multitrack = mlt_field_multitrack(field); //mlt_tractor_multitrack(tractor.get_tractor()); - kDebug()<<" -- CURRENT MULTIOTRACK HAS: "<set("refresh", 1); } -void Render::mltMoveTransition(QString type, int startTrack, int trackOffset, GenTime oldIn, GenTime oldOut, GenTime newIn, GenTime newOut) -{ +void Render::mltMoveTransition(QString type, int startTrack, int trackOffset, GenTime oldIn, GenTime oldOut, GenTime newIn, GenTime newOut) { m_isBlocked = true; m_mltConsumer->set("refresh", 0); mlt_service serv = m_mltProducer->parent().get_service(); mlt_service nextservice = mlt_service_get_producer(serv); - mlt_properties properties = MLT_SERVICE_PROPERTIES( nextservice ); - QString mlt_type = mlt_properties_get( properties, "mlt_type" ); - QString resource = mlt_properties_get( properties, "mlt_service"); + mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice); + QString mlt_type = mlt_properties_get(properties, "mlt_type"); + QString resource = mlt_properties_get(properties, "mlt_service"); int old_pos = (oldIn.frames(m_fps) + oldOut.frames(m_fps)) / 2; int new_in = newIn.frames(m_fps); int new_out = newOut.frames(m_fps) - 1; while (mlt_type == "transition") { - mlt_transition tr = (mlt_transition) nextservice; - int currentTrack = mlt_transition_get_b_track(tr); - int currentIn = (int) mlt_transition_get_in(tr); + mlt_transition tr = (mlt_transition) nextservice; + int currentTrack = mlt_transition_get_b_track(tr); + int currentIn = (int) mlt_transition_get_in(tr); int currentOut = (int) mlt_transition_get_out(tr); - kDebug()<<"// FOUND EXISTING TRANS, IN: "<= old_pos) { + kDebug() << "// FOUND EXISTING TRANS, IN: " << currentIn << ", OUT: " << currentOut << ", TRACK: " << currentTrack; + //kDebug()<<"// LOOKING FOR IN: "<= old_pos) { mlt_transition_set_in_and_out(tr, new_in, new_out); if (trackOffset != 0) { - mlt_properties properties = MLT_TRANSITION_PROPERTIES( tr ); - mlt_properties_set_int( properties, "a_track", mlt_transition_get_a_track(tr) + trackOffset ); - mlt_properties_set_int( properties, "b_track", mlt_transition_get_b_track(tr) + trackOffset ); + mlt_properties properties = MLT_TRANSITION_PROPERTIES(tr); + mlt_properties_set_int(properties, "a_track", mlt_transition_get_a_track(tr) + trackOffset); + mlt_properties_set_int(properties, "b_track", mlt_transition_get_b_track(tr) + trackOffset); } break; } - nextservice = mlt_service_producer(nextservice); - properties = MLT_SERVICE_PROPERTIES( nextservice ); - mlt_type = mlt_properties_get( properties, "mlt_type" ); - resource = mlt_properties_get( properties, "mlt_service" ); + nextservice = mlt_service_producer(nextservice); + properties = MLT_SERVICE_PROPERTIES(nextservice); + mlt_type = mlt_properties_get(properties, "mlt_type"); + resource = mlt_properties_get(properties, "mlt_service"); } m_isBlocked = false; } -void Render::mltAddTransition(QString tag, int a_track, int b_track, GenTime in, GenTime out, QMap args) -{ +void Render::mltAddTransition(QString tag, int a_track, int b_track, GenTime in, GenTime out, QMap args) { m_isBlocked = true; Mlt::Service service(m_mltProducer->parent().get_service()); @@ -1355,17 +1283,17 @@ void Render::mltAddTransition(QString tag, int a_track, int b_track, GenTime in, QMap::Iterator it; QString key; - kDebug()<<" ------ ADDING TRANSITION PARAMs: "<set(name, value); - kDebug()<<" ------ ADDING TRANS PARAM: "<set("kdenlive_id", id); - delete[] name; - delete[] value; + kDebug() << " ------ ADDING TRANS PARAM: " << name << ": " << value; + //filter->set("kdenlive_id", id); + delete[] name; + delete[] value; } // attach filter to the clip field->plant_transition(*transition, a_track, b_track); @@ -1375,9 +1303,8 @@ void Render::mltAddTransition(QString tag, int a_track, int b_track, GenTime in, } -void Render::mltSavePlaylist() -{ - kWarning()<<"// UPDATING PLAYLIST TO DISK++++++++++++++++"; +void Render::mltSavePlaylist() { + kWarning() << "// UPDATING PLAYLIST TO DISK++++++++++++++++"; Mlt::Consumer *fileConsumer = new Mlt::Consumer(*m_mltProfile, "westley"); fileConsumer->set("resource", "/home/one/playlist.xml"); diff --git a/src/renderer.h b/src/renderer.h index be3d937d..fadc295f 100644 --- a/src/renderer.h +++ b/src/renderer.h @@ -46,87 +46,87 @@ class Render; class QPixmap; namespace Mlt { - class Consumer; - class Playlist; - class Tractor; - class Frame; - class Producer; - class Filter; - class Profile; - class Multitrack; +class Consumer; +class Playlist; +class Tractor; +class Frame; +class Producer; +class Filter; +class Profile; +class Multitrack; }; -class Render:public QObject { - Q_OBJECT public: +class Render: public QObject { +Q_OBJECT public: enum FailStates { OK = 0, - APP_NOEXIST - }; + APP_NOEXIST + }; - Render(const QString & rendererName, int winid, int extid, QWidget *parent = 0); + Render(const QString & rendererName, int winid, int extid, QWidget *parent = 0); ~Render(); - /** Seeks the renderer clip to the given time. */ + /** Seeks the renderer clip to the given time. */ void seek(GenTime time); void seekToFrame(int pos); - + static QPixmap getVideoThumbnail(char *profile, QString file, int frame, int width, int height); QPixmap getImageThumbnail(KUrl url, int width, int height); - /** Return thumbnail for color clip */ + /** Return thumbnail for color clip */ //void getImage(int id, QString color, QPoint size); static QPixmap frameThumbnail(Mlt::Frame *frame, int width, int height, bool border = false); - + /** Return thumbnail for image clip */ //void getImage(KUrl url, QPoint size); - /** Requests a particular frame from the given file. - * - * The pixmap will be returned by emitting the replyGetImage() signal. - * */ + /** Requests a particular frame from the given file. + * + * The pixmap will be returned by emitting the replyGetImage() signal. + * */ //void getImage(KUrl url, int frame, QPoint size); - /** Wraps the VEML command of the same name. Sets the current scene list to - be list. */ + /** Wraps the VEML command of the same name. Sets the current scene list to + be list. */ void setSceneList(QDomDocument list, int position = 0); - /** Wraps the VEML command of the same name. Tells the renderer to - play the current scene at the speed specified, relative to normal - playback. e.g. 1.0 is normal speed, 0.0 is paused, -1.0 means play - backwards. Does not specify start/stop times for playback.*/ + /** Wraps the VEML command of the same name. Tells the renderer to + play the current scene at the speed specified, relative to normal + playback. e.g. 1.0 is normal speed, 0.0 is paused, -1.0 means play + backwards. Does not specify start/stop times for playback.*/ void play(double speed); void switchPlay(); - /** stop playing */ + /** stop playing */ void stop(const GenTime & startTime); void setVolume(double volume); QPixmap extractFrame(int frame_position, int width, int height); - /** Wraps the VEML command of the same name. Tells the renderer to - play the current scene at the speed specified, relative to normal - playback. e.g. 1.0 is normal speed, 0.0 is paused, -1.0 means play - backwards. Specifes the start/stop times for playback.*/ + /** Wraps the VEML command of the same name. Tells the renderer to + play the current scene at the speed specified, relative to normal + playback. e.g. 1.0 is normal speed, 0.0 is paused, -1.0 means play + backwards. Specifes the start/stop times for playback.*/ void play(double speed, const GenTime & startTime); void play(double speed, const GenTime & startTime, - const GenTime & stopTime); - /** Wraps the VEML command of the same name - render the currently - specified sceneList - set with setSceneList() - to the document - name specified. */ + const GenTime & stopTime); + /** Wraps the VEML command of the same name - render the currently + specified sceneList - set with setSceneList() - to the document + name specified. */ void render(const KUrl & url); - /** Returns the description of this renderer */ + /** Returns the description of this renderer */ QString description(); - /** Returns the name of the renderer. */ + /** Returns the name of the renderer. */ const QString & rendererName() const; - /** Returns the speed at which the renderer is currently playing, 0.0 if the renderer is - not playing anything. */ + /** Returns the speed at which the renderer is currently playing, 0.0 if the renderer is + not playing anything. */ double playSpeed(); - /** Returns the current seek position of the renderer. */ + /** Returns the current seek position of the renderer. */ const GenTime & seekPosition() const; void emitFrameNumber(double position); @@ -137,7 +137,7 @@ class Render:public QObject { void askForRefresh(); void doRefresh(); - + /** Save current producer frame as image */ void exportCurrentFrame(KUrl url, bool notify); @@ -163,92 +163,92 @@ class Render:public QObject { void mltMoveTransition(QString type, int startTrack, int trackOffset, GenTime oldIn, GenTime oldOut, GenTime newIn, GenTime newOut); void mltAddTransition(QString tag, int a_track, int b_track, GenTime in, GenTime out, QMap args); - - private: // Private attributes & methods - /** The name of this renderer - useful to identify the renderes by what they do - e.g. background rendering, workspace monitor, etc... */ - QString m_name; - Mlt::Consumer * m_mltConsumer; - Mlt::Producer * m_mltProducer; - Mlt::Producer *m_mltTextProducer; - Mlt::Filter *m_osdInfo; - Mlt::Profile *m_mltProfile; - double m_framePosition; - double m_fps; - uint m_monitorId; - bool m_generateScenelist; - bool m_isBlocked; - - /** Holds the path to on screen display profile */ - QString m_osdProfile; - - QTimer *refreshTimer; - QTimer *osdTimer; - QTimer *m_connectTimer; - KUrl m_exportedFile; - int exportDuration, firstExportFrame, lastExportFrame; - - /** Holds the scenelist to be sent, if pending. */ + +private: // Private attributes & methods + /** The name of this renderer - useful to identify the renderes by what they do - e.g. background rendering, workspace monitor, etc... */ + QString m_name; + Mlt::Consumer * m_mltConsumer; + Mlt::Producer * m_mltProducer; + Mlt::Producer *m_mltTextProducer; + Mlt::Filter *m_osdInfo; + Mlt::Profile *m_mltProfile; + double m_framePosition; + double m_fps; + uint m_monitorId; + bool m_generateScenelist; + bool m_isBlocked; + + /** Holds the path to on screen display profile */ + QString m_osdProfile; + + QTimer *refreshTimer; + QTimer *osdTimer; + QTimer *m_connectTimer; + KUrl m_exportedFile; + int exportDuration, firstExportFrame, lastExportFrame; + + /** Holds the scenelist to be sent, if pending. */ QDomDocument m_sceneList; - /** A human-readable description of this renderer. */ + /** A human-readable description of this renderer. */ QString m_description; int m_winid; int m_externalwinid; - /** The actually seek command, private so people can't avoid the buffering of multiple seek commands. */ + /** The actually seek command, private so people can't avoid the buffering of multiple seek commands. */ void sendSeekCommand(GenTime time); - /** Sets the description of this renderer to desc. */ + /** Sets the description of this renderer to desc. */ void setDescription(const QString & description); void closeMlt(); void mltCheckLength(); - private slots: // Private slots - /** refresh monitor display */ - void refresh(); - void slotOsdTimeout(); - void connectPlaylist(); - void initSceneList(); +private slots: // Private slots + /** refresh monitor display */ + void refresh(); + void slotOsdTimeout(); + void connectPlaylist(); + void initSceneList(); - signals: // Signals - /** emitted when the renderer recieves a reply to a getFileProperties request. */ +signals: // Signals + /** emitted when the renderer recieves a reply to a getFileProperties request. */ void replyGetFileProperties(int clipId, const QMap < QString, QString > &, const QMap < QString, QString > &); - /** emitted when the renderer recieves a reply to a getImage request. */ + /** emitted when the renderer recieves a reply to a getImage request. */ void replyGetImage(int , int, const QPixmap &, int, int); void replyGetImage(int, const QPixmap &, int, int); - /** Emitted when the renderer stops, either playing or rendering. */ + /** Emitted when the renderer stops, either playing or rendering. */ void stopped(); - /** Emitted when the renderer starts playing. */ + /** Emitted when the renderer starts playing. */ void playing(double); - /** Emitted when the renderer is rendering. */ + /** Emitted when the renderer is rendering. */ void rendering(const GenTime &); - /** Emitted when rendering has finished */ + /** Emitted when rendering has finished */ void renderFinished(); - /** Emitted when the current seek position has been changed by the renderer. */ + /** Emitted when the current seek position has been changed by the renderer. */ // void positionChanged(const GenTime &); - /** Emitted when an error occurs within this renderer. */ + /** Emitted when an error occurs within this renderer. */ void error(const QString &, const QString &); void durationChanged(int); void rendererPosition(int); void rendererStopped(int); - - public slots: // Public slots - /** Start Consumer */ + +public slots: // Public slots + /** Start Consumer */ void start(); - /** Stop Consumer */ + /** Stop Consumer */ void stop(); void clear(); int getLength(); - /** If the file is readable by mlt, return true, otherwise false */ + /** If the file is readable by mlt, return true, otherwise false */ bool isValid(KUrl url); - /** Wraps the VEML command of the same name. Requests the file properties + /** Wraps the VEML command of the same name. Requests the file properties for the specified url from the renderer. Upon return, the result will be emitted via replyGetFileProperties(). */ void getFileProperties(const QDomElement &xml, int clipId); - + void exportFileToFirewire(QString srcFileName, int port, GenTime startTime, GenTime endTime); static char *decodedString(QString str); void mltSavePlaylist(); diff --git a/src/resizeclipcommand.cpp b/src/resizeclipcommand.cpp index 887c80ea..9e97e462 100644 --- a/src/resizeclipcommand.cpp +++ b/src/resizeclipcommand.cpp @@ -22,24 +22,22 @@ #include "resizeclipcommand.h" ResizeClipCommand::ResizeClipCommand(CustomTrackView *view, const QPointF startPos, const QPointF endPos, bool resizeClipStart, bool doIt) - : m_view(view), m_startPos(startPos), m_endPos(endPos), m_resizeClipStart(resizeClipStart), m_doIt(doIt) { - setText(i18n("Resize clip")); - } + : m_view(view), m_startPos(startPos), m_endPos(endPos), m_resizeClipStart(resizeClipStart), m_doIt(doIt) { + setText(i18n("Resize clip")); +} -// virtual -void ResizeClipCommand::undo() -{ +// virtual +void ResizeClipCommand::undo() { // kDebug()<<"---- undoing action"; - m_doIt = true; - if (m_doIt) m_view->resizeClip(m_endPos, m_startPos, m_resizeClipStart); + m_doIt = true; + if (m_doIt) m_view->resizeClip(m_endPos, m_startPos, m_resizeClipStart); } -// virtual -void ResizeClipCommand::redo() -{ -kDebug()<<"---- redoing action"; - if (m_doIt) m_view->resizeClip(m_startPos, m_endPos, m_resizeClipStart); - m_doIt = true; +// virtual +void ResizeClipCommand::redo() { + kDebug() << "---- redoing action"; + if (m_doIt) m_view->resizeClip(m_startPos, m_endPos, m_resizeClipStart); + m_doIt = true; } #include "resizeclipcommand.moc" diff --git a/src/resizeclipcommand.h b/src/resizeclipcommand.h index 8b575f0f..6247df12 100644 --- a/src/resizeclipcommand.h +++ b/src/resizeclipcommand.h @@ -30,20 +30,19 @@ #include "projectlist.h" #include "customtrackview.h" -class ResizeClipCommand : public QUndoCommand - { - public: - ResizeClipCommand(CustomTrackView *view, const QPointF startPos, const QPointF endPos, bool resizeClipStart, bool doIt); +class ResizeClipCommand : public QUndoCommand { +public: + ResizeClipCommand(CustomTrackView *view, const QPointF startPos, const QPointF endPos, bool resizeClipStart, bool doIt); virtual void undo(); virtual void redo(); - private: - CustomTrackView *m_view; - QPointF m_startPos; - QPointF m_endPos; - bool m_resizeClipStart; - bool m_doIt; - }; +private: + CustomTrackView *m_view; + QPointF m_startPos; + QPointF m_endPos; + bool m_resizeClipStart; + bool m_doIt; +}; #endif diff --git a/src/smallruler.cpp b/src/smallruler.cpp index b9e42022..5d9d23ca 100644 --- a/src/smallruler.cpp +++ b/src/smallruler.cpp @@ -34,123 +34,115 @@ SmallRuler::SmallRuler(QWidget *parent) - : KRuler(parent) -{ - setShowPointer(true); - setShowBigMarks(false); - setShowTinyMarks(false); - slotNewOffset(0); - setRulerMetricStyle(KRuler::Custom); - setLengthFixed(true); + : KRuler(parent) { + setShowPointer(true); + setShowBigMarks(false); + setShowTinyMarks(false); + slotNewOffset(0); + setRulerMetricStyle(KRuler::Custom); + setLengthFixed(true); } -void SmallRuler::setPixelPerMark ( double rate ) -{ - kDebug()<<" RULER SET RATE: "< 0.5) { - setLittleMarkDistance(25); - setMediumMarkDistance(5 * 25); - } - else if (rate > 0.09) { - setLittleMarkDistance(5 * 25); - setMediumMarkDistance(30 * 25); - } - else { - setLittleMarkDistance(30 * 25); - setMediumMarkDistance(60 * 25); - } - - KRuler::setPixelPerMark( rate ); +void SmallRuler::setPixelPerMark(double rate) { + kDebug() << " RULER SET RATE: " << rate; + if (rate > 0.5) { + setLittleMarkDistance(25); + setMediumMarkDistance(5 * 25); + } else if (rate > 0.09) { + setLittleMarkDistance(5 * 25); + setMediumMarkDistance(30 * 25); + } else { + setLittleMarkDistance(30 * 25); + setMediumMarkDistance(60 * 25); + } + + KRuler::setPixelPerMark(rate); } -// virtual -void SmallRuler::mousePressEvent ( QMouseEvent * event ) -{ - int pos = event->x(); - //slotNewValue( pos ); - emit seekRenderer(pos); - kDebug()<x(); + //slotNewValue( pos ); + emit seekRenderer(pos); + kDebug() << pos; } // virtual -void SmallRuler::mouseMoveEvent ( QMouseEvent * event ) -{ - int pos = event->x(); - //slotNewValue( pos ); - emit seekRenderer(pos); - kDebug()<x(); + //slotNewValue( pos ); + emit seekRenderer(pos); + kDebug() << pos; } -void SmallRuler::slotNewValue ( int _value ) -{ - m_cursorPosition = _value / pixelPerMark(); - KRuler::slotNewValue(_value); +void SmallRuler::slotNewValue(int _value) { + m_cursorPosition = _value / pixelPerMark(); + KRuler::slotNewValue(_value); } // virtual -void SmallRuler::paintEvent(QPaintEvent *e) - { - // debug ("KRuler::drawContents, %s",(horizontal==dir)?"horizontal":"vertical"); - - QStylePainter p(this); - p.fillRect(e->rect(), QBrush(QColor(Qt::white))); - - - int value = this->value(), - minval = minimum(), - maxval; - maxval = maximum() - + offset() - endOffset(); - - //ioffsetval = value-offset; - // pixelpm = (int)ppm; - // left = clip.left(), - // right = clip.right(); - double f, fend, - offsetmin=(double)(minval-offset()), - offsetmax=(double)(maxval-offset()), - fontOffset = (((double)minval)>offsetmin)?(double)minval:offsetmin; - - // draw labels - QFont font = p.font(); - font.setPointSize(LABEL_SIZE); - p.setFont( font ); - - if (showLittleMarks()) { - // draw the little marks - fend = pixelPerMark()*littleMarkDistance(); - if (fend > 2) for ( f=offsetmin; f 2) for ( f=offsetmin; fshowem) { - // draw end marks - if (d->dir == Qt::Horizontal) { - p.drawLine(minval-d->offset, END_MARK_X1, minval-d->offset, END_MARK_X2); - p.drawLine(maxval-d->offset, END_MARK_X1, maxval-d->offset, END_MARK_X2); - } - else { - p.drawLine(END_MARK_X1, minval-d->offset, END_MARK_X2, minval-d->offset); - p.drawLine(END_MARK_X1, maxval-d->offset, END_MARK_X2, maxval-d->offset); - } - }*/ - - // draw pointer - if (showPointer()) { - QPolygon pa(3); - pa.setPoints(3, value-6, 0, value+6, 0, value/*+0*/, 8); - p.setBrush( QBrush(Qt::yellow) ); - p.drawPolygon( pa ); - } - - } +void SmallRuler::paintEvent(QPaintEvent *e) { + // debug ("KRuler::drawContents, %s",(horizontal==dir)?"horizontal":"vertical"); + + QStylePainter p(this); + p.fillRect(e->rect(), QBrush(QColor(Qt::white))); + + + int value = this->value(), + minval = minimum(), + maxval; + maxval = maximum() + + offset() - endOffset(); + + //ioffsetval = value-offset; + // pixelpm = (int)ppm; + // left = clip.left(), + // right = clip.right(); + double f, fend, + offsetmin = (double)(minval - offset()), + offsetmax = (double)(maxval - offset()), + fontOffset = (((double)minval) > offsetmin) ? (double)minval : offsetmin; + + // draw labels + QFont font = p.font(); + font.setPointSize(LABEL_SIZE); + p.setFont(font); + + if (showLittleMarks()) { + // draw the little marks + fend = pixelPerMark() * littleMarkDistance(); + if (fend > 2) for (f = offsetmin; f < offsetmax; f += fend) { + p.drawLine((int)f, LITTLE_MARK_X1, (int)f, LITTLE_MARK_X2); + } + } + if (showMediumMarks()) { + // draw medium marks + fend = pixelPerMark() * mediumMarkDistance(); + if (fend > 2) for (f = offsetmin; f < offsetmax; f += fend) { + p.drawLine((int)f, MIDDLE_MARK_X1, (int)f, MIDDLE_MARK_X2); + } + } + + /* if (d->showem) { + // draw end marks + if (d->dir == Qt::Horizontal) { + p.drawLine(minval-d->offset, END_MARK_X1, minval-d->offset, END_MARK_X2); + p.drawLine(maxval-d->offset, END_MARK_X1, maxval-d->offset, END_MARK_X2); + } + else { + p.drawLine(END_MARK_X1, minval-d->offset, END_MARK_X2, minval-d->offset); + p.drawLine(END_MARK_X1, maxval-d->offset, END_MARK_X2, maxval-d->offset); + } + }*/ + + // draw pointer + if (showPointer()) { + QPolygon pa(3); + pa.setPoints(3, value - 6, 0, value + 6, 0, value/*+0*/, 8); + p.setBrush(QBrush(Qt::yellow)); + p.drawPolygon(pa); + } + +} #include "smallruler.moc" diff --git a/src/smallruler.h b/src/smallruler.h index c4731b16..46ebb9ce 100644 --- a/src/smallruler.h +++ b/src/smallruler.h @@ -23,27 +23,26 @@ #include -class SmallRuler : public KRuler -{ - Q_OBJECT - - public: - SmallRuler(QWidget *parent=0); - virtual void mousePressEvent ( QMouseEvent * event ); - virtual void mouseMoveEvent ( QMouseEvent * event ); - void setPixelPerMark ( double rate ); - - protected: +class SmallRuler : public KRuler { + Q_OBJECT + +public: + SmallRuler(QWidget *parent = 0); + virtual void mousePressEvent(QMouseEvent * event); + virtual void mouseMoveEvent(QMouseEvent * event); + void setPixelPerMark(double rate); + +protected: virtual void paintEvent(QPaintEvent * /*e*/); - private: +private: int m_cursorPosition; double m_scale; - public slots: - void slotNewValue ( int _value ); +public slots: + void slotNewValue(int _value); - signals: +signals: void seekRenderer(int); }; diff --git a/src/timecode.cpp b/src/timecode.cpp index 7437dcf2..deb86526 100644 --- a/src/timecode.cpp +++ b/src/timecode.cpp @@ -20,79 +20,73 @@ #include Timecode::Timecode(Formats format, int framesPerSecond, - bool dropFrame):m_format(format), m_dropFrame(dropFrame), -m_displayedFramesPerSecond(framesPerSecond) -{ + bool dropFrame): m_format(format), m_dropFrame(dropFrame), + m_displayedFramesPerSecond(framesPerSecond) { } -Timecode::~Timecode() -{ +Timecode::~Timecode() { } -int Timecode::getFrameCount(const QString duration, double fps) const -{ +int Timecode::getFrameCount(const QString duration, double fps) const { if (m_dropFrame) { - // calculate how many frames need to be dropped every minute. - int frames; - int toDrop = (int) floor (600.0 * (m_displayedFramesPerSecond - fps) + 0.5); - - int perMinute = toDrop / 9; - int tenthMinute = toDrop % 9; - - // calculate how many frames are in a normal minute, and how many are in a tenth minute. - int normalMinuteFrames = (m_displayedFramesPerSecond * 60) - perMinute; - int tenthMinuteFrames = (m_displayedFramesPerSecond * 60) - tenthMinute;; - - // Number of actual frames in a 10 minute interval : - int tenMinutes = (normalMinuteFrames * 9) + tenthMinuteFrames; - frames = 6 * duration.section(":",0,0).toInt() * tenMinutes; - int minutes = duration.section(":",1,1).toInt(); - frames += ((int) minutes / 10) * tenMinutes; - int mins = minutes % 10; - if (mins > 0) { - frames += tenthMinuteFrames; - mins--; - if (mins > 0) frames += mins * normalMinuteFrames; - } - if (minutes % 10 > 0) frames -= perMinute; - frames += duration.section(":",2,2).toInt() * m_displayedFramesPerSecond + duration.section(":",3,3).toInt(); - return frames; + // calculate how many frames need to be dropped every minute. + int frames; + int toDrop = (int) floor(600.0 * (m_displayedFramesPerSecond - fps) + 0.5); + + int perMinute = toDrop / 9; + int tenthMinute = toDrop % 9; + + // calculate how many frames are in a normal minute, and how many are in a tenth minute. + int normalMinuteFrames = (m_displayedFramesPerSecond * 60) - perMinute; + int tenthMinuteFrames = (m_displayedFramesPerSecond * 60) - tenthMinute;; + + // Number of actual frames in a 10 minute interval : + int tenMinutes = (normalMinuteFrames * 9) + tenthMinuteFrames; + frames = 6 * duration.section(":", 0, 0).toInt() * tenMinutes; + int minutes = duration.section(":", 1, 1).toInt(); + frames += ((int) minutes / 10) * tenMinutes; + int mins = minutes % 10; + if (mins > 0) { + frames += tenthMinuteFrames; + mins--; + if (mins > 0) frames += mins * normalMinuteFrames; + } + if (minutes % 10 > 0) frames -= perMinute; + frames += duration.section(":", 2, 2).toInt() * m_displayedFramesPerSecond + duration.section(":", 3, 3).toInt(); + return frames; } - return (int) ((duration.section(":",0,0).toInt()*3600.0 + duration.section(":",1,1).toInt()*60.0 + duration.section(":",2,2).toInt()) * fps + duration.section(":",3,3).toInt()); + return (int)((duration.section(":", 0, 0).toInt()*3600.0 + duration.section(":", 1, 1).toInt()*60.0 + duration.section(":", 2, 2).toInt()) * fps + duration.section(":", 3, 3).toInt()); } -QString Timecode::getTimecode(const GenTime & time, double fps) const -{ +QString Timecode::getTimecode(const GenTime & time, double fps) const { switch (m_format) { case HH_MM_SS_FF: - return getTimecodeHH_MM_SS_FF(time, fps); - break; + return getTimecodeHH_MM_SS_FF(time, fps); + break; case HH_MM_SS_HH: - return getTimecodeHH_MM_SS_HH(time); - break; + return getTimecodeHH_MM_SS_HH(time); + break; case Frames: - return getTimecodeFrames(time, fps); - break; + return getTimecodeFrames(time, fps); + break; case Seconds: - return getTimecodeSeconds(time); - break; + return getTimecodeSeconds(time); + break; default: - kWarning() << - "Unknown timecode format specified, defaulting to HH_MM_SS_FF" - << endl; - return getTimecodeHH_MM_SS_FF(time, fps); + kWarning() << + "Unknown timecode format specified, defaulting to HH_MM_SS_FF" + << endl; + return getTimecodeHH_MM_SS_FF(time, fps); } } -QString Timecode::getTimecodeFromFrames(int frames) -{ +QString Timecode::getTimecodeFromFrames(int frames) { return getTimecodeHH_MM_SS_FF(frames); } -//static -QString Timecode::getEasyTimecode(const GenTime & time, const double &fps) -{ +//static +QString Timecode::getEasyTimecode(const GenTime & time, const double &fps) { // Returns the timecode in an easily read display, like 3 min. 5 sec. int frames = (int)time.frames(fps); int seconds = frames / (int) floor(fps + 0.5); @@ -106,48 +100,44 @@ QString Timecode::getEasyTimecode(const GenTime & time, const double &fps) QString text; bool trim = false; - if (hours!= 0) { + if (hours != 0) { text.append(QString::number(hours).rightJustified(2, '0', FALSE)); text.append(" " + i18n("hour") + " "); trim = true; } - if (minutes!= 0 || trim) { + if (minutes != 0 || trim) { if (!trim) { text.append(QString::number(minutes)); - } - else + } else text.append(QString::number(minutes).rightJustified(2, '0', FALSE)); text.append(" " + i18n("min.") + " "); trim = true; } - if (seconds!= 0 || trim) { + if (seconds != 0 || trim) { if (!trim) { text.append(QString::number(seconds)); - } - else + } else text.append(QString::number(seconds).rightJustified(2, '0', FALSE)); text.append(" " + i18n("sec.")); trim = true; } if (!trim) { - text.append(QString::number(frames)); - text.append(" " + i18n("frames")); + text.append(QString::number(frames)); + text.append(" " + i18n("frames")); } return text; } -QString Timecode::getTimecodeHH_MM_SS_FF(const GenTime & time, double fps) const -{ +QString Timecode::getTimecodeHH_MM_SS_FF(const GenTime & time, double fps) const { if (m_dropFrame) - return getTimecodeDropFrame(time, fps); + return getTimecodeDropFrame(time, fps); return getTimecodeHH_MM_SS_FF((int)time.frames(fps)); } -QString Timecode::getTimecodeHH_MM_SS_FF(int frames) const -{ +QString Timecode::getTimecodeHH_MM_SS_FF(int frames) const { int seconds = frames / m_displayedFramesPerSecond; frames = frames % m_displayedFramesPerSecond; @@ -169,8 +159,7 @@ QString Timecode::getTimecodeHH_MM_SS_FF(int frames) const return text; } -QString Timecode::getTimecodeHH_MM_SS_HH(const GenTime & time) const -{ +QString Timecode::getTimecodeHH_MM_SS_HH(const GenTime & time) const { int hundredths = (int)(time.seconds() * 100); int seconds = hundredths / 100; hundredths = hundredths % 100; @@ -192,24 +181,21 @@ QString Timecode::getTimecodeHH_MM_SS_HH(const GenTime & time) const return text; } -QString Timecode::getTimecodeFrames(const GenTime & time, double fps) const -{ +QString Timecode::getTimecodeFrames(const GenTime & time, double fps) const { return QString::number(time.frames(fps)); } -QString Timecode::getTimecodeSeconds(const GenTime & time) const -{ +QString Timecode::getTimecodeSeconds(const GenTime & time) const { return QString::number(time.seconds()); } -QString Timecode::getTimecodeDropFrame(const GenTime & time, double fps) const -{ +QString Timecode::getTimecodeDropFrame(const GenTime & time, double fps) const { // Calculate the timecode using dropframes to remove the difference in fps. Note that this algorithm should work // for NTSC times, but is untested for any others - it is in no way an "official" algorithm, unless it's by fluke. int frames = (int)time.frames(fps); // calculate how many frames need to be dropped every minute. - int toDrop = (int) floor (600.0 * (m_displayedFramesPerSecond - fps) + 0.5); + int toDrop = (int) floor(600.0 * (m_displayedFramesPerSecond - fps) + 0.5); int perMinute = toDrop / 9; int tenthMinute = toDrop % 9; @@ -232,13 +218,13 @@ QString Timecode::getTimecodeDropFrame(const GenTime & time, double fps) const int numMinutes; if (frames < tenthMinuteFrames) { - // tenth minute logic applies. - numMinutes = 0; + // tenth minute logic applies. + numMinutes = 0; } else { - // normal minute logic applies. - numMinutes = 1 + (frames - tenthMinuteFrames) / normalMinuteFrames; - frames = (frames - tenthMinuteFrames) % normalMinuteFrames; - frames += tenthMinute + perMinute; + // normal minute logic applies. + numMinutes = 1 + (frames - tenthMinuteFrames) / normalMinuteFrames; + frames = (frames - tenthMinuteFrames) % normalMinuteFrames; + frames += tenthMinute + perMinute; } // We now have HH:MM:??:?? diff --git a/src/timecode.h b/src/timecode.h index fb8e5afe..7a2fb91b 100644 --- a/src/timecode.h +++ b/src/timecode.h @@ -27,32 +27,32 @@ Handles the conversion of a GenTime into a nicely formatted string, taking into @author Jason Wood */ class Timecode { - public: +public: enum Formats { HH_MM_SS_FF, HH_MM_SS_HH, Frames, Seconds }; - Timecode(Formats format = HH_MM_SS_FF, int framesPerSecond = - 25, bool dropFrame = false); + Timecode(Formats format = HH_MM_SS_FF, int framesPerSecond = + 25, bool dropFrame = false); - /** Set the current timecode format; this is the output format for this timecode. */ + /** Set the current timecode format; this is the output format for this timecode. */ void setFormat(int framesPerSecond, bool dropFrame = false, Formats format = HH_MM_SS_FF) { - m_displayedFramesPerSecond = framesPerSecond; - m_dropFrame = dropFrame; - m_format = format; - } + m_displayedFramesPerSecond = framesPerSecond; + m_dropFrame = dropFrame; + m_format = format; + } Formats format() const { - return m_format; - } + return m_format; + } ~Timecode(); - /** Returns the timecode for a given time */ + /** Returns the timecode for a given time */ QString getTimecode(const GenTime & time, double fps) const; int getFrameCount(const QString duration, double fps) const; static QString getEasyTimecode(const GenTime & time, const double &fps); QString getTimecodeFromFrames(int frames); - private: +private: Formats m_format; bool m_dropFrame; int m_displayedFramesPerSecond; diff --git a/src/titledocument.cpp b/src/titledocument.cpp index ab41c53a..5a71bfe6 100644 --- a/src/titledocument.cpp +++ b/src/titledocument.cpp @@ -25,189 +25,189 @@ #include #include -TitleDocument::TitleDocument(){ - scene=NULL; +TitleDocument::TitleDocument() { + scene = NULL; } -void TitleDocument::setScene(QGraphicsScene* _scene){ - scene=_scene; +void TitleDocument::setScene(QGraphicsScene* _scene) { + scene = _scene; } -bool TitleDocument::saveDocument(const KUrl& url,QGraphicsPolygonItem* startv, QGraphicsPolygonItem* endv){ - QDomDocument doc; - - if (!scene) - return false; - - QDomElement main=doc.createElement("kdenlivetitle"); - doc.appendChild(main); - - foreach(QGraphicsItem* item, scene->items()){ - QDomElement e=doc.createElement("item"); - QDomElement content=doc.createElement("content"); - - switch (item->type()){ - case 3: - e.setAttribute("type","QGraphicsRectItem"); - content.setAttribute("rect",rectFToString(((QGraphicsRectItem*)item)->rect() )); - content.setAttribute("pencolor",colorToString(((QGraphicsRectItem*)item)->pen().color()) ); - content.setAttribute("penwidth",((QGraphicsRectItem*)item)->pen().width() ); - content.setAttribute("brushcolor",colorToString(((QGraphicsRectItem*)item)->brush().color()) ); - break; - case 8: - e.setAttribute("type","QGraphicsTextItem"); - content.appendChild(doc.createTextNode( ((QGraphicsTextItem*)item)->toHtml() ) ); - break; - default: - continue; - } - QDomElement pos=doc.createElement("position"); - pos.setAttribute("x",item->pos().x()); - pos.setAttribute("y",item->pos().y()); - QTransform transform=item->transform(); - QDomElement tr=doc.createElement("transform"); - tr.appendChild(doc.createTextNode( - QString("%1,%2,%3,%4,%5,%6,%7,%8,%9").arg( - transform.m11()).arg(transform.m12()).arg(transform.m13()).arg(transform.m21()).arg(transform.m22()).arg(transform.m23()).arg(transform.m31()).arg(transform.m32()).arg(transform.m33()) - ) - ); - pos.appendChild(tr); - - - e.appendChild(pos); - e.appendChild(content); - main.appendChild(e); - } - if (startv && endv){ - QDomElement endp=doc.createElement("endviewport"); - QDomElement startp=doc.createElement("startviewport"); - endp.setAttribute("x",endv->pos().x()); - endp.setAttribute("y",endv->pos().y()); - endp.setAttribute("size",endv->sceneBoundingRect().width()/2); - - startp.setAttribute("x",startv->pos().x()); - startp.setAttribute("y",startv->pos().y()); - startp.setAttribute("size",startv->sceneBoundingRect().width()/2); - - main.appendChild(startp); - main.appendChild(endp); - } - QDomElement backgr=doc.createElement("background"); - backgr.setAttribute("color",colorToString(scene->backgroundBrush().color())); - main.appendChild(backgr); - - QString tmpfile="/tmp/newtitle"; - QFile xmlf(tmpfile); - xmlf.open(QIODevice::WriteOnly); - xmlf.write(doc.toString().toAscii()); - xmlf.close(); - kDebug() << KIO::NetAccess::upload(tmpfile,url,0); +bool TitleDocument::saveDocument(const KUrl& url, QGraphicsPolygonItem* startv, QGraphicsPolygonItem* endv) { + QDomDocument doc; + + if (!scene) + return false; + + QDomElement main = doc.createElement("kdenlivetitle"); + doc.appendChild(main); + + foreach(QGraphicsItem* item, scene->items()) { + QDomElement e = doc.createElement("item"); + QDomElement content = doc.createElement("content"); + + switch (item->type()) { + case 3: + e.setAttribute("type", "QGraphicsRectItem"); + content.setAttribute("rect", rectFToString(((QGraphicsRectItem*)item)->rect())); + content.setAttribute("pencolor", colorToString(((QGraphicsRectItem*)item)->pen().color())); + content.setAttribute("penwidth", ((QGraphicsRectItem*)item)->pen().width()); + content.setAttribute("brushcolor", colorToString(((QGraphicsRectItem*)item)->brush().color())); + break; + case 8: + e.setAttribute("type", "QGraphicsTextItem"); + content.appendChild(doc.createTextNode(((QGraphicsTextItem*)item)->toHtml())); + break; + default: + continue; + } + QDomElement pos = doc.createElement("position"); + pos.setAttribute("x", item->pos().x()); + pos.setAttribute("y", item->pos().y()); + QTransform transform = item->transform(); + QDomElement tr = doc.createElement("transform"); + tr.appendChild(doc.createTextNode( + QString("%1,%2,%3,%4,%5,%6,%7,%8,%9").arg( + transform.m11()).arg(transform.m12()).arg(transform.m13()).arg(transform.m21()).arg(transform.m22()).arg(transform.m23()).arg(transform.m31()).arg(transform.m32()).arg(transform.m33()) + ) + ); + pos.appendChild(tr); + + + e.appendChild(pos); + e.appendChild(content); + main.appendChild(e); + } + if (startv && endv) { + QDomElement endp = doc.createElement("endviewport"); + QDomElement startp = doc.createElement("startviewport"); + endp.setAttribute("x", endv->pos().x()); + endp.setAttribute("y", endv->pos().y()); + endp.setAttribute("size", endv->sceneBoundingRect().width() / 2); + + startp.setAttribute("x", startv->pos().x()); + startp.setAttribute("y", startv->pos().y()); + startp.setAttribute("size", startv->sceneBoundingRect().width() / 2); + + main.appendChild(startp); + main.appendChild(endp); + } + QDomElement backgr = doc.createElement("background"); + backgr.setAttribute("color", colorToString(scene->backgroundBrush().color())); + main.appendChild(backgr); + + QString tmpfile = "/tmp/newtitle"; + QFile xmlf(tmpfile); + xmlf.open(QIODevice::WriteOnly); + xmlf.write(doc.toString().toAscii()); + xmlf.close(); + kDebug() << KIO::NetAccess::upload(tmpfile, url, 0); } -bool TitleDocument::loadDocument(const KUrl& url ,QGraphicsPolygonItem* startv, QGraphicsPolygonItem* endv) { - QString tmpfile; - QDomDocument doc; - double aspect_ratio=4.0/3.0; - if (!scene) - return false; - - if (KIO::NetAccess::download(url, tmpfile, 0)) { - QFile file(tmpfile); - if (file.open(QIODevice::ReadOnly)) { - doc.setContent(&file, false); - file.close(); - }else - return false; - KIO::NetAccess::removeTempFile(tmpfile); - QDomNodeList titles=doc.elementsByTagName("kdenlivetitle"); - if (titles.size()){ - - QDomNodeList items=titles.item(0).childNodes(); - for(int i=0;iaddText(""); - txt->setHtml(items.item(i).namedItem("content").firstChild().nodeValue()); - gitem=txt; - }else - if (items.item(i).attributes().namedItem("type").nodeValue()=="QGraphicsRectItem"){ - QString rect=items.item(i).namedItem("content").attributes().namedItem("rect").nodeValue(); - QString br_str=items.item(i).namedItem("content").attributes().namedItem("brushcolor").nodeValue(); - QString pen_str=items.item(i).namedItem("content").attributes().namedItem("pencolor").nodeValue(); - double penwidth=items.item(i).namedItem("content").attributes().namedItem("penwidth").nodeValue().toDouble(); - QGraphicsRectItem *rec=scene->addRect(stringToRect(rect),QPen(QBrush(stringToColor(pen_str)),penwidth),QBrush(stringToColor(br_str) ) ); - gitem=rec; - } - //pos and transform - if (gitem ){ - QPointF p(items.item(i).namedItem("position").attributes().namedItem("x").nodeValue().toDouble(), - items.item(i).namedItem("position").attributes().namedItem("y").nodeValue().toDouble()); - gitem->setPos(p); - gitem->setTransform(stringToTransform(items.item(i).namedItem("position").firstChild().firstChild().nodeValue())); - } - if (items.item(i).nodeName()=="background"){ - kDebug() << items.item(i).attributes().namedItem("color").nodeValue(); - scene->setBackgroundBrush(QBrush(stringToColor(items.item(i).attributes().namedItem("color").nodeValue()))); - }else if (items.item(i).nodeName()=="startviewport" && startv){ - QPointF p(items.item(i).attributes().namedItem("x").nodeValue().toDouble(),items.item(i).attributes().namedItem("y").nodeValue().toDouble()); - double width=items.item(i).attributes().namedItem("size").nodeValue().toDouble(); - QRectF rect(-width,-width/aspect_ratio,width*2.0,width/aspect_ratio*2.0); - kDebug() << width << rect; - startv->setPolygon(rect); - startv->setPos(p); - }else if (items.item(i).nodeName()=="endviewport" && endv){ - QPointF p(items.item(i).attributes().namedItem("x").nodeValue().toDouble(),items.item(i).attributes().namedItem("y").nodeValue().toDouble()); - double width=items.item(i).attributes().namedItem("size").nodeValue().toDouble(); - QRectF rect(-width,-width/aspect_ratio,width*2.0,width/aspect_ratio*2.0); - kDebug() << width << rect; - endv->setPolygon(rect); - endv->setPos(p); - } - - } - - - } - - - } - return true; +bool TitleDocument::loadDocument(const KUrl& url , QGraphicsPolygonItem* startv, QGraphicsPolygonItem* endv) { + QString tmpfile; + QDomDocument doc; + double aspect_ratio = 4.0 / 3.0; + if (!scene) + return false; + + if (KIO::NetAccess::download(url, tmpfile, 0)) { + QFile file(tmpfile); + if (file.open(QIODevice::ReadOnly)) { + doc.setContent(&file, false); + file.close(); + } else + return false; + KIO::NetAccess::removeTempFile(tmpfile); + QDomNodeList titles = doc.elementsByTagName("kdenlivetitle"); + if (titles.size()) { + + QDomNodeList items = titles.item(0).childNodes(); + for (int i = 0;i < items.count();i++) { + QGraphicsItem *gitem = NULL; + kDebug() << items.item(i).attributes().namedItem("type").nodeValue(); + if (items.item(i).attributes().namedItem("type").nodeValue() == "QGraphicsTextItem") { + QGraphicsTextItem *txt = scene->addText(""); + txt->setHtml(items.item(i).namedItem("content").firstChild().nodeValue()); + gitem = txt; + } else + if (items.item(i).attributes().namedItem("type").nodeValue() == "QGraphicsRectItem") { + QString rect = items.item(i).namedItem("content").attributes().namedItem("rect").nodeValue(); + QString br_str = items.item(i).namedItem("content").attributes().namedItem("brushcolor").nodeValue(); + QString pen_str = items.item(i).namedItem("content").attributes().namedItem("pencolor").nodeValue(); + double penwidth = items.item(i).namedItem("content").attributes().namedItem("penwidth").nodeValue().toDouble(); + QGraphicsRectItem *rec = scene->addRect(stringToRect(rect), QPen(QBrush(stringToColor(pen_str)), penwidth), QBrush(stringToColor(br_str))); + gitem = rec; + } + //pos and transform + if (gitem) { + QPointF p(items.item(i).namedItem("position").attributes().namedItem("x").nodeValue().toDouble(), + items.item(i).namedItem("position").attributes().namedItem("y").nodeValue().toDouble()); + gitem->setPos(p); + gitem->setTransform(stringToTransform(items.item(i).namedItem("position").firstChild().firstChild().nodeValue())); + } + if (items.item(i).nodeName() == "background") { + kDebug() << items.item(i).attributes().namedItem("color").nodeValue(); + scene->setBackgroundBrush(QBrush(stringToColor(items.item(i).attributes().namedItem("color").nodeValue()))); + } else if (items.item(i).nodeName() == "startviewport" && startv) { + QPointF p(items.item(i).attributes().namedItem("x").nodeValue().toDouble(), items.item(i).attributes().namedItem("y").nodeValue().toDouble()); + double width = items.item(i).attributes().namedItem("size").nodeValue().toDouble(); + QRectF rect(-width, -width / aspect_ratio, width*2.0, width / aspect_ratio*2.0); + kDebug() << width << rect; + startv->setPolygon(rect); + startv->setPos(p); + } else if (items.item(i).nodeName() == "endviewport" && endv) { + QPointF p(items.item(i).attributes().namedItem("x").nodeValue().toDouble(), items.item(i).attributes().namedItem("y").nodeValue().toDouble()); + double width = items.item(i).attributes().namedItem("size").nodeValue().toDouble(); + QRectF rect(-width, -width / aspect_ratio, width*2.0, width / aspect_ratio*2.0); + kDebug() << width << rect; + endv->setPolygon(rect); + endv->setPos(p); + } + + } + + + } + + + } + return true; } -QString TitleDocument::colorToString(const QColor& c){ - QString ret="%1,%2,%3,%4"; - ret=ret.arg(c.red()).arg(c.green()).arg(c.blue()).arg(c.alpha()); - return ret; +QString TitleDocument::colorToString(const QColor& c) { + QString ret = "%1,%2,%3,%4"; + ret = ret.arg(c.red()).arg(c.green()).arg(c.blue()).arg(c.alpha()); + return ret; } -QString TitleDocument::rectFToString(const QRectF& c){ - QString ret="%1,%2,%3,%4"; - ret=ret.arg(c.x()).arg(c.y()).arg(c.width()).arg(c.height()); - return ret; +QString TitleDocument::rectFToString(const QRectF& c) { + QString ret = "%1,%2,%3,%4"; + ret = ret.arg(c.x()).arg(c.y()).arg(c.width()).arg(c.height()); + return ret; } -QRectF TitleDocument::stringToRect(const QString & s){ - - QStringList l=s.split(","); - if (l.size()<4) - return QRectF(); - return QRectF(l[0].toDouble(),l[1].toDouble(),l[2].toDouble(),l[3].toDouble()); +QRectF TitleDocument::stringToRect(const QString & s) { + + QStringList l = s.split(","); + if (l.size() < 4) + return QRectF(); + return QRectF(l[0].toDouble(), l[1].toDouble(), l[2].toDouble(), l[3].toDouble()); } -QColor TitleDocument::stringToColor(const QString & s){ - QStringList l=s.split(","); - if (l.size()<4) - return QColor(); - return QColor(l[0].toInt(),l[1].toInt(),l[2].toInt(),l[3].toInt());; +QColor TitleDocument::stringToColor(const QString & s) { + QStringList l = s.split(","); + if (l.size() < 4) + return QColor(); + return QColor(l[0].toInt(), l[1].toInt(), l[2].toInt(), l[3].toInt());; } -QTransform TitleDocument::stringToTransform(const QString& s){ - QStringList l=s.split(","); - if (l.size()<9) - return QTransform(); - return QTransform( - l[0].toDouble(),l[1].toDouble(),l[2].toDouble(), - l[3].toDouble(),l[4].toDouble(),l[5].toDouble(), - l[6].toDouble(),l[7].toDouble(),l[8].toDouble() - ); +QTransform TitleDocument::stringToTransform(const QString& s) { + QStringList l = s.split(","); + if (l.size() < 9) + return QTransform(); + return QTransform( + l[0].toDouble(), l[1].toDouble(), l[2].toDouble(), + l[3].toDouble(), l[4].toDouble(), l[5].toDouble(), + l[6].toDouble(), l[7].toDouble(), l[8].toDouble() + ); } diff --git a/src/titledocument.h b/src/titledocument.h index 47733a79..fab51a5e 100644 --- a/src/titledocument.h +++ b/src/titledocument.h @@ -22,18 +22,18 @@ class QGraphicsScene; class QGraphicsPolygonItem; class TitleDocument { - QGraphicsScene* scene; - public: - TitleDocument(); - void setScene(QGraphicsScene* scene); - bool saveDocument(const KUrl& url,QGraphicsPolygonItem* startv, QGraphicsPolygonItem* endv); - bool loadDocument(const KUrl& url,QGraphicsPolygonItem* startv, QGraphicsPolygonItem* endv); - private: - QString colorToString(const QColor&); - QString rectFToString(const QRectF&); - QRectF stringToRect(const QString &); - QColor stringToColor(const QString &); - QTransform stringToTransform(const QString &); + QGraphicsScene* scene; +public: + TitleDocument(); + void setScene(QGraphicsScene* scene); + bool saveDocument(const KUrl& url, QGraphicsPolygonItem* startv, QGraphicsPolygonItem* endv); + bool loadDocument(const KUrl& url, QGraphicsPolygonItem* startv, QGraphicsPolygonItem* endv); +private: + QString colorToString(const QColor&); + QString rectFToString(const QRectF&); + QRectF stringToRect(const QString &); + QColor stringToColor(const QString &); + QTransform stringToTransform(const QString &); }; #endif diff --git a/src/titlewidget.cpp b/src/titlewidget.cpp index 4614ec4c..95555376 100644 --- a/src/titlewidget.cpp +++ b/src/titlewidget.cpp @@ -24,248 +24,247 @@ #include #include -int settingUp=false; - -TitleWidget::TitleWidget (QDialog *parent):QDialog(parent){ - setupUi(this); - connect (newTextButton,SIGNAL(clicked()), this, SLOT( slotNewText())); - connect (newRectButton,SIGNAL(clicked()), this, SLOT( slotNewRect())); - connect (kcolorbutton, SIGNAL ( clicked()), this, SLOT( slotChangeBackground()) ) ; - connect (horizontalSlider, SIGNAL ( valueChanged(int) ), this, SLOT( slotChangeBackground()) ) ; - connect (ktextedit, SIGNAL(textChanged()), this , SLOT (textChanged())); - connect (fontColorButton, SIGNAL ( clicked()), this, SLOT( textChanged()) ) ; - //connect (fontBold, SIGNAL ( clicked()), this, SLOT( setBold()) ) ; - connect (loadButton, SIGNAL ( clicked()), this, SLOT( loadTitle() ) ) ; - connect (saveButton, SIGNAL ( clicked()), this, SLOT( saveTitle() ) ) ; - - - connect (kfontrequester, SIGNAL ( fontSelected(const QFont &)), this, SLOT( textChanged()) ) ; - connect(textAlpha, SIGNAL( valueChanged(int) ), this, SLOT (textChanged())); - //connect (ktextedit, SIGNAL(selectionChanged()), this , SLOT (textChanged())); - - connect(rectFAlpha, SIGNAL( valueChanged(int) ), this, SLOT (rectChanged())); - connect(rectBAlpha, SIGNAL( valueChanged(int) ), this, SLOT (rectChanged())); - connect(rectFColor, SIGNAL( clicked() ), this, SLOT (rectChanged())); - connect(rectBColor, SIGNAL( clicked() ), this, SLOT (rectChanged())); - connect(rectLineWidth, SIGNAL( valueChanged(int) ), this, SLOT (rectChanged())); - - connect (startViewportX,SIGNAL(valueChanged(int)), this, SLOT( setupViewports())); - connect (startViewportY,SIGNAL(valueChanged(int)), this, SLOT( setupViewports())); - connect (startViewportSize,SIGNAL(valueChanged(int)), this, SLOT( setupViewports())); - connect (endViewportX,SIGNAL(valueChanged(int)), this, SLOT( setupViewports())); - connect (endViewportY,SIGNAL(valueChanged(int)), this, SLOT( setupViewports())); - connect (endViewportSize,SIGNAL(valueChanged(int)), this, SLOT( setupViewports())); - - connect (zValue, SIGNAL (valueChanged(int)), this, SLOT (zIndexChanged(int))); - connect (svgfilename, SIGNAL (urlSelected(const KUrl&) ), this,SLOT( svgSelected(const KUrl &)) ); - connect (itemzoom, SIGNAL (valueChanged(int) ), this,SLOT( itemScaled(int)) ); - connect (itemrotate, SIGNAL (valueChanged(int) ), this,SLOT( itemRotate(int)) ); - - GraphicsSceneRectMove *scene=new GraphicsSceneRectMove(this); - - // a gradient background - QRadialGradient *gradient=new QRadialGradient(0, 0, 10); - gradient->setSpread(QGradient::ReflectSpread); - //scene->setBackgroundBrush(*gradient); - - graphicsView->setScene(scene); - m_titledocument.setScene(scene); - connect (graphicsView->scene(), SIGNAL (selectionChanged()), this , SLOT( selectionChanged())); - initViewports(); - - graphicsView->show(); - graphicsView->setRenderHint(QPainter::Antialiasing); - graphicsView->setInteractive(true); - graphicsView->resize(400, 300); - - toolBox->setItemEnabled(2,false); - toolBox->setItemEnabled(3,false); +int settingUp = false; + +TitleWidget::TitleWidget(QDialog *parent): QDialog(parent) { + setupUi(this); + connect(newTextButton, SIGNAL(clicked()), this, SLOT(slotNewText())); + connect(newRectButton, SIGNAL(clicked()), this, SLOT(slotNewRect())); + connect(kcolorbutton, SIGNAL(clicked()), this, SLOT(slotChangeBackground())) ; + connect(horizontalSlider, SIGNAL(valueChanged(int)), this, SLOT(slotChangeBackground())) ; + connect(ktextedit, SIGNAL(textChanged()), this , SLOT(textChanged())); + connect(fontColorButton, SIGNAL(clicked()), this, SLOT(textChanged())) ; + //connect (fontBold, SIGNAL ( clicked()), this, SLOT( setBold()) ) ; + connect(loadButton, SIGNAL(clicked()), this, SLOT(loadTitle())) ; + connect(saveButton, SIGNAL(clicked()), this, SLOT(saveTitle())) ; + + + connect(kfontrequester, SIGNAL(fontSelected(const QFont &)), this, SLOT(textChanged())) ; + connect(textAlpha, SIGNAL(valueChanged(int)), this, SLOT(textChanged())); + //connect (ktextedit, SIGNAL(selectionChanged()), this , SLOT (textChanged())); + + connect(rectFAlpha, SIGNAL(valueChanged(int)), this, SLOT(rectChanged())); + connect(rectBAlpha, SIGNAL(valueChanged(int)), this, SLOT(rectChanged())); + connect(rectFColor, SIGNAL(clicked()), this, SLOT(rectChanged())); + connect(rectBColor, SIGNAL(clicked()), this, SLOT(rectChanged())); + connect(rectLineWidth, SIGNAL(valueChanged(int)), this, SLOT(rectChanged())); + + connect(startViewportX, SIGNAL(valueChanged(int)), this, SLOT(setupViewports())); + connect(startViewportY, SIGNAL(valueChanged(int)), this, SLOT(setupViewports())); + connect(startViewportSize, SIGNAL(valueChanged(int)), this, SLOT(setupViewports())); + connect(endViewportX, SIGNAL(valueChanged(int)), this, SLOT(setupViewports())); + connect(endViewportY, SIGNAL(valueChanged(int)), this, SLOT(setupViewports())); + connect(endViewportSize, SIGNAL(valueChanged(int)), this, SLOT(setupViewports())); + + connect(zValue, SIGNAL(valueChanged(int)), this, SLOT(zIndexChanged(int))); + connect(svgfilename, SIGNAL(urlSelected(const KUrl&)), this, SLOT(svgSelected(const KUrl &))); + connect(itemzoom, SIGNAL(valueChanged(int)), this, SLOT(itemScaled(int))); + connect(itemrotate, SIGNAL(valueChanged(int)), this, SLOT(itemRotate(int))); + + GraphicsSceneRectMove *scene = new GraphicsSceneRectMove(this); + + // a gradient background + QRadialGradient *gradient = new QRadialGradient(0, 0, 10); + gradient->setSpread(QGradient::ReflectSpread); + //scene->setBackgroundBrush(*gradient); + + graphicsView->setScene(scene); + m_titledocument.setScene(scene); + connect(graphicsView->scene(), SIGNAL(selectionChanged()), this , SLOT(selectionChanged())); + initViewports(); + + graphicsView->show(); + graphicsView->setRenderHint(QPainter::Antialiasing); + graphicsView->setInteractive(true); + graphicsView->resize(400, 300); + + toolBox->setItemEnabled(2, false); + toolBox->setItemEnabled(3, false); } -void TitleWidget::initViewports(){ - startViewport=new QGraphicsPolygonItem(QPolygonF(QRectF(0,0,0,0))); - endViewport=new QGraphicsPolygonItem(QPolygonF(QRectF(0,0,0,0))); - - QPen startpen(Qt::DotLine); - QPen endpen(Qt::DashDotLine); - startpen.setColor(QColor(100,200,100,140)); - endpen.setColor(QColor(200,100,100,140)); - - startViewport->setPen(startpen); - endViewport->setPen(endpen); - - startViewportSize->setValue(40); - endViewportSize->setValue(40); - - startViewport->setZValue(-1000); - endViewport->setZValue(-1000); - - startViewport->setFlags(/*QGraphicsItem::ItemIsMovable|*/QGraphicsItem::ItemIsSelectable); - endViewport->setFlags(/*QGraphicsItem::ItemIsMovable|*/QGraphicsItem::ItemIsSelectable); - - graphicsView->scene()->addItem(startViewport); - graphicsView->scene()->addItem(endViewport); +void TitleWidget::initViewports() { + startViewport = new QGraphicsPolygonItem(QPolygonF(QRectF(0, 0, 0, 0))); + endViewport = new QGraphicsPolygonItem(QPolygonF(QRectF(0, 0, 0, 0))); + + QPen startpen(Qt::DotLine); + QPen endpen(Qt::DashDotLine); + startpen.setColor(QColor(100, 200, 100, 140)); + endpen.setColor(QColor(200, 100, 100, 140)); + + startViewport->setPen(startpen); + endViewport->setPen(endpen); + + startViewportSize->setValue(40); + endViewportSize->setValue(40); + + startViewport->setZValue(-1000); + endViewport->setZValue(-1000); + + startViewport->setFlags(/*QGraphicsItem::ItemIsMovable|*/QGraphicsItem::ItemIsSelectable); + endViewport->setFlags(/*QGraphicsItem::ItemIsMovable|*/QGraphicsItem::ItemIsSelectable); + + graphicsView->scene()->addItem(startViewport); + graphicsView->scene()->addItem(endViewport); } -void TitleWidget::slotNewRect(){ - - QGraphicsRectItem * ri=graphicsView->scene()->addRect(-50,-50,100,100); - ri->setFlags(QGraphicsItem::ItemIsMovable|QGraphicsItem::ItemIsSelectable); +void TitleWidget::slotNewRect() { + + QGraphicsRectItem * ri = graphicsView->scene()->addRect(-50, -50, 100, 100); + ri->setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable); } -void TitleWidget::slotNewText(){ - QGraphicsTextItem *tt=graphicsView->scene()->addText("Text here"); - tt->setFlags(QGraphicsItem::ItemIsMovable|QGraphicsItem::ItemIsSelectable); - tt->setTextInteractionFlags (Qt::TextEditorInteraction); - connect (tt->document(), SIGNAL (contentsChanged()), this, SLOT(selectionChanged())); - kDebug() << tt->metaObject()->className(); - /*QGraphicsRectItem * ri=graphicsView->scene()->addRect(-50,-50,100,100); - ri->setFlags(QGraphicsItem::ItemIsMovable|QGraphicsItem::ItemIsSelectable);*/ - +void TitleWidget::slotNewText() { + QGraphicsTextItem *tt = graphicsView->scene()->addText("Text here"); + tt->setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable); + tt->setTextInteractionFlags(Qt::TextEditorInteraction); + connect(tt->document(), SIGNAL(contentsChanged()), this, SLOT(selectionChanged())); + kDebug() << tt->metaObject()->className(); + /*QGraphicsRectItem * ri=graphicsView->scene()->addRect(-50,-50,100,100); + ri->setFlags(QGraphicsItem::ItemIsMovable|QGraphicsItem::ItemIsSelectable);*/ + } -void TitleWidget::zIndexChanged(int v){ - QList l=graphicsView->scene()->selectedItems(); - if (l.size()>=1){ - l[0]->setZValue(v); - } +void TitleWidget::zIndexChanged(int v) { + QList l = graphicsView->scene()->selectedItems(); + if (l.size() >= 1) { + l[0]->setZValue(v); + } } -void TitleWidget::selectionChanged(){ - QList l=graphicsView->scene()->selectedItems(); - toolBox->setItemEnabled(2,false); - toolBox->setItemEnabled(3,false); - if (l.size()==1){ - - if ((l[0])->type()==8 ){ - QGraphicsTextItem* i=((QGraphicsTextItem*)l[0]); - if (l[0]->hasFocus() ) - ktextedit->setHtml(i->toHtml()); - toolBox->setCurrentIndex(2); - toolBox->setItemEnabled(2,true); - }else - if ((l[0])->type()==3){ - settingUp=true; - QGraphicsRectItem *rec=((QGraphicsRectItem*)l[0]); - toolBox->setCurrentIndex(3); - toolBox->setItemEnabled(3,true); - rectFAlpha->setValue(rec->pen().color().alpha()); - rectBAlpha->setValue(rec->brush().isOpaque() ? rec->brush().color().alpha() : 0); - kDebug() << rec->brush().color().alpha(); - QColor fcol=rec->pen().color(); - QColor bcol=rec->brush().color(); - //fcol.setAlpha(255); - //bcol.setAlpha(255); - rectFColor->setColor(fcol); - rectBColor->setColor(bcol); - settingUp=false; - rectLineWidth->setValue(rec->pen().width()); - } - else{ - //toolBox->setCurrentIndex(0); - } - zValue->setValue((int)l[0]->zValue()); - itemzoom->setValue((int)transformations[l[0]].scalex*100); - itemrotate->setValue((int)transformations[l[0]].rotate); - } +void TitleWidget::selectionChanged() { + QList l = graphicsView->scene()->selectedItems(); + toolBox->setItemEnabled(2, false); + toolBox->setItemEnabled(3, false); + if (l.size() == 1) { + + if ((l[0])->type() == 8) { + QGraphicsTextItem* i = ((QGraphicsTextItem*)l[0]); + if (l[0]->hasFocus()) + ktextedit->setHtml(i->toHtml()); + toolBox->setCurrentIndex(2); + toolBox->setItemEnabled(2, true); + } else + if ((l[0])->type() == 3) { + settingUp = true; + QGraphicsRectItem *rec = ((QGraphicsRectItem*)l[0]); + toolBox->setCurrentIndex(3); + toolBox->setItemEnabled(3, true); + rectFAlpha->setValue(rec->pen().color().alpha()); + rectBAlpha->setValue(rec->brush().isOpaque() ? rec->brush().color().alpha() : 0); + kDebug() << rec->brush().color().alpha(); + QColor fcol = rec->pen().color(); + QColor bcol = rec->brush().color(); + //fcol.setAlpha(255); + //bcol.setAlpha(255); + rectFColor->setColor(fcol); + rectBColor->setColor(bcol); + settingUp = false; + rectLineWidth->setValue(rec->pen().width()); + } else { + //toolBox->setCurrentIndex(0); + } + zValue->setValue((int)l[0]->zValue()); + itemzoom->setValue((int)transformations[l[0]].scalex*100); + itemrotate->setValue((int)transformations[l[0]].rotate); + } } -void TitleWidget::slotChangeBackground(){ - QColor color=kcolorbutton->color(); - color.setAlpha(horizontalSlider->value()); - graphicsView->scene()->setBackgroundBrush(QBrush(color)); +void TitleWidget::slotChangeBackground() { + QColor color = kcolorbutton->color(); + color.setAlpha(horizontalSlider->value()); + graphicsView->scene()->setBackgroundBrush(QBrush(color)); } -void TitleWidget::textChanged(){ - QList l=graphicsView->scene()->selectedItems(); - if (l.size()==1 && (l[0])->type()==8 && !l[0]->hasFocus()){ - kDebug() << ktextedit->document()->toHtml(); - ((QGraphicsTextItem*)l[0])->setHtml(ktextedit->toHtml()); - } +void TitleWidget::textChanged() { + QList l = graphicsView->scene()->selectedItems(); + if (l.size() == 1 && (l[0])->type() == 8 && !l[0]->hasFocus()) { + kDebug() << ktextedit->document()->toHtml(); + ((QGraphicsTextItem*)l[0])->setHtml(ktextedit->toHtml()); + } } -void TitleWidget::rectChanged(){ - QList l=graphicsView->scene()->selectedItems(); - if (l.size()==1 && (l[0])->type()==3 && !settingUp){ - QGraphicsRectItem *rec=(QGraphicsRectItem*)l[0]; - QColor f=rectFColor->color(); - f.setAlpha(rectFAlpha->value()); - QPen penf(f); - penf.setWidth(rectLineWidth->value()); - rec->setPen(penf); - QColor b=rectBColor->color(); - b.setAlpha(rectBAlpha->value()); - rec->setBrush(QBrush(b)); - } +void TitleWidget::rectChanged() { + QList l = graphicsView->scene()->selectedItems(); + if (l.size() == 1 && (l[0])->type() == 3 && !settingUp) { + QGraphicsRectItem *rec = (QGraphicsRectItem*)l[0]; + QColor f = rectFColor->color(); + f.setAlpha(rectFAlpha->value()); + QPen penf(f); + penf.setWidth(rectLineWidth->value()); + rec->setPen(penf); + QColor b = rectBColor->color(); + b.setAlpha(rectBAlpha->value()); + rec->setBrush(QBrush(b)); + } } -void TitleWidget::fontBold(){ - QList l=graphicsView->scene()->selectedItems(); - if (l.size()==1 && (l[0])->type()==8 && !l[0]->hasFocus()){ - //ktextedit->document()->setTextOption(); - } +void TitleWidget::fontBold() { + QList l = graphicsView->scene()->selectedItems(); + if (l.size() == 1 && (l[0])->type() == 8 && !l[0]->hasFocus()) { + //ktextedit->document()->setTextOption(); + } } -void TitleWidget::svgSelected(const KUrl& u){ - QGraphicsSvgItem *svg=new QGraphicsSvgItem(u.toLocalFile()); - svg->setFlags(QGraphicsItem::ItemIsMovable|QGraphicsItem::ItemIsSelectable); - graphicsView->scene()->addItem(svg); +void TitleWidget::svgSelected(const KUrl& u) { + QGraphicsSvgItem *svg = new QGraphicsSvgItem(u.toLocalFile()); + svg->setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable); + graphicsView->scene()->addItem(svg); } void TitleWidget::itemScaled(int val) { - QList l=graphicsView->scene()->selectedItems(); - if (l.size()==1){ - Transform x=transformations[l[0]]; - x.scalex=(double)val/100.0; - x.scaley=(double)val/100.0; - QTransform qtrans; - qtrans.scale(x.scalex,x.scaley); - qtrans.rotate(x.rotate); - l[0]->setTransform(qtrans); - transformations[l[0]]=x; - } + QList l = graphicsView->scene()->selectedItems(); + if (l.size() == 1) { + Transform x = transformations[l[0]]; + x.scalex = (double)val / 100.0; + x.scaley = (double)val / 100.0; + QTransform qtrans; + qtrans.scale(x.scalex, x.scaley); + qtrans.rotate(x.rotate); + l[0]->setTransform(qtrans); + transformations[l[0]] = x; + } } void TitleWidget::itemRotate(int val) { - QList l=graphicsView->scene()->selectedItems(); - if (l.size()==1){ - Transform x=transformations[l[0]]; - x.rotate=(double)val; - QTransform qtrans; - qtrans.scale(x.scalex,x.scaley); - qtrans.rotate(x.rotate); - l[0]->setTransform(qtrans); - transformations[l[0]]=x; - } + QList l = graphicsView->scene()->selectedItems(); + if (l.size() == 1) { + Transform x = transformations[l[0]]; + x.rotate = (double)val; + QTransform qtrans; + qtrans.scale(x.scalex, x.scaley); + qtrans.rotate(x.rotate); + l[0]->setTransform(qtrans); + transformations[l[0]] = x; + } } -void TitleWidget::setupViewports(){ - double aspect_ratio=4.0/3.0;//read from project - - QRectF sp(0,0,0,0); - QRectF ep(0,0,0,0); - - double sv_size=startViewportSize->value(); - double ev_size=endViewportSize->value(); - sp.adjust(-sv_size,-sv_size/aspect_ratio,sv_size,sv_size/aspect_ratio); - ep.adjust(-ev_size,-ev_size/aspect_ratio,ev_size,ev_size/aspect_ratio); - - startViewport->setPos(startViewportX->value(), startViewportY->value()); - endViewport->setPos(endViewportX->value(),endViewportY->value()); - - startViewport->setPolygon(QPolygonF(sp)); - endViewport->setPolygon(QPolygonF(ep)); - +void TitleWidget::setupViewports() { + double aspect_ratio = 4.0 / 3.0;//read from project + + QRectF sp(0, 0, 0, 0); + QRectF ep(0, 0, 0, 0); + + double sv_size = startViewportSize->value(); + double ev_size = endViewportSize->value(); + sp.adjust(-sv_size, -sv_size / aspect_ratio, sv_size, sv_size / aspect_ratio); + ep.adjust(-ev_size, -ev_size / aspect_ratio, ev_size, ev_size / aspect_ratio); + + startViewport->setPos(startViewportX->value(), startViewportY->value()); + endViewport->setPos(endViewportX->value(), endViewportY->value()); + + startViewport->setPolygon(QPolygonF(sp)); + endViewport->setPolygon(QPolygonF(ep)); + } -void TitleWidget::loadTitle(){ - KUrl url= KFileDialog::getOpenUrl( KUrl(), "*.kdenlivetitle",this,tr("Save Title")); - m_titledocument.loadDocument(url,startViewport,endViewport); +void TitleWidget::loadTitle() { + KUrl url = KFileDialog::getOpenUrl(KUrl(), "*.kdenlivetitle", this, tr("Save Title")); + m_titledocument.loadDocument(url, startViewport, endViewport); } -void TitleWidget::saveTitle(){ - KUrl url= KFileDialog::getSaveUrl( KUrl(), "*.kdenlivetitle",this,tr("Save Title")); - m_titledocument.saveDocument(url,startViewport,endViewport); +void TitleWidget::saveTitle() { + KUrl url = KFileDialog::getSaveUrl(KUrl(), "*.kdenlivetitle", this, tr("Save Title")); + m_titledocument.saveDocument(url, startViewport, endViewport); } #include "moc_titlewidget.cpp" diff --git a/src/titlewidget.h b/src/titlewidget.h index c6c9362b..ab91abf6 100644 --- a/src/titlewidget.h +++ b/src/titlewidget.h @@ -23,41 +23,41 @@ #include #include -class Transform{ - public: - Transform(){ - scalex=1.0; - scaley=1.0; - rotate=0.0; - } - double scalex,scaley; - double rotate; +class Transform { +public: + Transform() { + scalex = 1.0; + scaley = 1.0; + rotate = 0.0; + } + double scalex, scaley; + double rotate; }; -class TitleWidget : public QDialog , public Ui::TitleWidget_UI{ - Q_OBJECT +class TitleWidget : public QDialog , public Ui::TitleWidget_UI { + Q_OBJECT public: - TitleWidget(QDialog *parent=0); + TitleWidget(QDialog *parent = 0); private: - QGraphicsPolygonItem *startViewport,*endViewport; - void initViewports(); - QMap transformations; - TitleDocument m_titledocument; + QGraphicsPolygonItem *startViewport, *endViewport; + void initViewports(); + QMap transformations; + TitleDocument m_titledocument; public slots: - void slotNewText(); - void slotNewRect(); - void slotChangeBackground(); - void selectionChanged(); - void textChanged(); - void rectChanged(); - void fontBold(); - void setupViewports(); - void zIndexChanged(int); - void svgSelected(const KUrl&); - void itemScaled(int); - void itemRotate(int); - void saveTitle(); - void loadTitle(); + void slotNewText(); + void slotNewRect(); + void slotChangeBackground(); + void selectionChanged(); + void textChanged(); + void rectChanged(); + void fontBold(); + void setupViewports(); + void zIndexChanged(int); + void svgSelected(const KUrl&); + void itemScaled(int); + void itemRotate(int); + void saveTitle(); + void loadTitle(); }; diff --git a/src/trackpanelclipmovefunction.cpp b/src/trackpanelclipmovefunction.cpp index bd7167f0..6f42453b 100644 --- a/src/trackpanelclipmovefunction.cpp +++ b/src/trackpanelclipmovefunction.cpp @@ -25,389 +25,374 @@ TrackPanelClipMoveFunction::TrackPanelClipMoveFunction(TrackView *view): -m_view(view), m_dragging(false), m_startedClipMove(false), m_masterClip(0), m_clipOffset(0) -{ - // m_moveClipsCommand = 0; + m_view(view), m_dragging(false), m_startedClipMove(false), m_masterClip(0), m_clipOffset(0) { + // m_moveClipsCommand = 0; //m_deleteClipsCommand = 0; m_addingClips = false; m_firststep = true; } -TrackPanelClipMoveFunction::~TrackPanelClipMoveFunction() -{ +TrackPanelClipMoveFunction::~TrackPanelClipMoveFunction() { } bool TrackPanelClipMoveFunction::mouseApplies(DocumentTrack *, - QMouseEvent * event) const -{ + QMouseEvent * event) const { return mouseApplies(event->pos()); } -bool TrackPanelClipMoveFunction::mouseApplies(const QPoint & pos) const -{ +bool TrackPanelClipMoveFunction::mouseApplies(const QPoint & pos) const { TrackViewClip *clipUnderMouse = 0; DocumentTrack * panel = m_view->panelAt(pos.y()); if (panel) { - kDebug()<<" TESTING CURSOR AT: "<mapLocalToValue(pos.x()); - GenTime mouseTime((int)(m_view->mapLocalToValue(pos.x())), m_document->fps()); - clipUnderMouse = panel->getClipAt(mouseTime); + kDebug() << " TESTING CURSOR AT: " << pos.x() << ", MAPPED VAL: " << m_view->mapLocalToValue(pos.x()); + GenTime mouseTime((int)(m_view->mapLocalToValue(pos.x())), m_document->fps()); + clipUnderMouse = panel->getClipAt(mouseTime); } return clipUnderMouse; } -QCursor TrackPanelClipMoveFunction::getMouseCursor(DocumentTrack *, QMouseEvent * event) -{ +QCursor TrackPanelClipMoveFunction::getMouseCursor(DocumentTrack *, QMouseEvent * event) { return QCursor(Qt::SizeAllCursor); } bool TrackPanelClipMoveFunction::mousePressed(DocumentTrack * panel, - QMouseEvent * event) -{ + QMouseEvent * event) { bool result = false; -/* - if (panel->hasDocumentTrackIndex()) { - DocTrackBase *track = - m_document->track(panel->documentTrackIndex()); - if (track) { - GenTime mouseTime((int)(m_timeline->mapLocalToValue(event->x())), - m_document->framesPerSecond()); - m_clipUnderMouse = 0; - m_clipUnderMouse = track->getClipAt(mouseTime); - - if (m_clipUnderMouse) { - emit checkTransition(m_clipUnderMouse); - if (event->state() & Qt::ControlButton) { - m_app->addCommand(Command::KSelectClipCommand::toggleSelectClipAt(m_document, *track, mouseTime), true); - } - else { - if (!track->clipSelected(m_clipUnderMouse)) { - KMacroCommand *macroCommand = new KMacroCommand(i18n("Select Clip")); - macroCommand->addCommand(Command::KSelectClipCommand::selectNone(m_document)); - macroCommand->addCommand(new Command::KSelectClipCommand(m_document, m_clipUnderMouse, true)); - m_app->addCommand(macroCommand, true); - } - } - result = true; - } - } - } -*/ + /* + if (panel->hasDocumentTrackIndex()) { + DocTrackBase *track = + m_document->track(panel->documentTrackIndex()); + if (track) { + GenTime mouseTime((int)(m_timeline->mapLocalToValue(event->x())), + m_document->framesPerSecond()); + m_clipUnderMouse = 0; + m_clipUnderMouse = track->getClipAt(mouseTime); + + if (m_clipUnderMouse) { + emit checkTransition(m_clipUnderMouse); + if (event->state() & Qt::ControlButton) { + m_app->addCommand(Command::KSelectClipCommand::toggleSelectClipAt(m_document, *track, mouseTime), true); + } + else { + if (!track->clipSelected(m_clipUnderMouse)) { + KMacroCommand *macroCommand = new KMacroCommand(i18n("Select Clip")); + macroCommand->addCommand(Command::KSelectClipCommand::selectNone(m_document)); + macroCommand->addCommand(new Command::KSelectClipCommand(m_document, m_clipUnderMouse, true)); + m_app->addCommand(macroCommand, true); + } + } + result = true; + } + } + } + */ return result; } -bool TrackPanelClipMoveFunction::mouseDoubleClicked(DocumentTrack * panel, QMouseEvent *event) -{ -/* - if (panel->hasDocumentTrackIndex()) { - DocTrackBase *track = - m_document->track(panel->documentTrackIndex()); - if (track) { - GenTime mouseTime((int)(m_timeline->mapLocalToValue(event->x())), - m_document->framesPerSecond()); - m_clipUnderMouse = track->getClipAt(mouseTime); - if (m_clipUnderMouse) { - track->openClip(m_clipUnderMouse); - } - } - }*/ - return false; ///FIXME is that right ? +bool TrackPanelClipMoveFunction::mouseDoubleClicked(DocumentTrack * panel, QMouseEvent *event) { + /* + if (panel->hasDocumentTrackIndex()) { + DocTrackBase *track = + m_document->track(panel->documentTrackIndex()); + if (track) { + GenTime mouseTime((int)(m_timeline->mapLocalToValue(event->x())), + m_document->framesPerSecond()); + m_clipUnderMouse = track->getClipAt(mouseTime); + if (m_clipUnderMouse) { + track->openClip(m_clipUnderMouse); + } + } + }*/ + return false; ///FIXME is that right ? } -bool TrackPanelClipMoveFunction::mouseReleased(DocumentTrack *, QMouseEvent *) -{ +bool TrackPanelClipMoveFunction::mouseReleased(DocumentTrack *, QMouseEvent *) { //m_timeline->stopScrollTimer(); return true; } bool TrackPanelClipMoveFunction::mouseMoved(DocumentTrack * panel, - QMouseEvent * event) -{ + QMouseEvent * event) { bool result = false; /*if (panel->hasDocumentTrackIndex()) { - DocTrackBase *track = - m_document->track(panel->documentTrackIndex()); - if (track) { - GenTime mouseTime((int)(m_timeline->mapLocalToValue(event->x())), - m_document->framesPerSecond()); - - if (m_dragging) { - m_dragging = false; - result = true; - } else { - if (m_clipUnderMouse) { - if (!m_document->projectClip().clipSelected(m_clipUnderMouse)) { - if ((event->state() & Qt::ControlButton) - || (event->state() & Qt::ShiftButton)) { - m_app-> - addCommand(Command::KSelectClipCommand:: - selectClipAt(m_document, *track, - mouseTime), true); - } else { - KMacroCommand *macroCommand = new KMacroCommand(i18n("Select Clip")); - macroCommand->addCommand(Command::KSelectClipCommand::selectNone(m_document)); - macroCommand->addCommand(new Command::KSelectClipCommand(m_document, m_clipUnderMouse, true)); - m_app->addCommand(macroCommand, true); - } - } - m_dragging = true; - initiateDrag(m_clipUnderMouse, mouseTime); - result = true; - } - } - } + DocTrackBase *track = + m_document->track(panel->documentTrackIndex()); + if (track) { + GenTime mouseTime((int)(m_timeline->mapLocalToValue(event->x())), + m_document->framesPerSecond()); + + if (m_dragging) { + m_dragging = false; + result = true; + } else { + if (m_clipUnderMouse) { + if (!m_document->projectClip().clipSelected(m_clipUnderMouse)) { + if ((event->state() & Qt::ControlButton) + || (event->state() & Qt::ShiftButton)) { + m_app-> + addCommand(Command::KSelectClipCommand:: + selectClipAt(m_document, *track, + mouseTime), true); + } else { + KMacroCommand *macroCommand = new KMacroCommand(i18n("Select Clip")); + macroCommand->addCommand(Command::KSelectClipCommand::selectNone(m_document)); + macroCommand->addCommand(new Command::KSelectClipCommand(m_document, m_clipUnderMouse, true)); + m_app->addCommand(macroCommand, true); } -*/ + } + m_dragging = true; + initiateDrag(m_clipUnderMouse, mouseTime); + result = true; + } + } + } + } + */ return result; } // virtual bool TrackPanelClipMoveFunction::dragEntered(DocumentTrack * panel, - QDragEnterEvent * event) -{ -/* if (m_startedClipMove) { - m_document->activateSceneListGeneration(false); - event->accept(true); - } else if (ClipDrag::canDecode(event)) { - m_document->activateSceneListGeneration(false); - m_selection = ClipDrag::decode(m_document, event); - - - if (!m_selection.isEmpty()) { - if (m_selection.masterClip() == 0) - m_selection.setMasterClip(m_selection.first()); - m_masterClip = m_selection.masterClip(); - m_clipOffset = GenTime(); - if (m_selection.isEmpty()) { - event->accept(false); - } else { - setupSnapToGrid(); - event->accept(true); - } - } else { - kdError() << - "ERROR! ERROR! ERROR! ClipDrag:decode decoded a null clip!!!" - << endl; - } - } else if (EffectDrag::canDecode(event)) { - event->accept(true); - } else { - event->accept(false); - } - //m_startedClipMove = false; -*/ + QDragEnterEvent * event) { + /* if (m_startedClipMove) { + m_document->activateSceneListGeneration(false); + event->accept(true); + } else if (ClipDrag::canDecode(event)) { + m_document->activateSceneListGeneration(false); + m_selection = ClipDrag::decode(m_document, event); + + + if (!m_selection.isEmpty()) { + if (m_selection.masterClip() == 0) + m_selection.setMasterClip(m_selection.first()); + m_masterClip = m_selection.masterClip(); + m_clipOffset = GenTime(); + if (m_selection.isEmpty()) { + event->accept(false); + } else { + setupSnapToGrid(); + event->accept(true); + } + } else { + kdError() << + "ERROR! ERROR! ERROR! ClipDrag:decode decoded a null clip!!!" + << endl; + } + } else if (EffectDrag::canDecode(event)) { + event->accept(true); + } else { + event->accept(false); + } + //m_startedClipMove = false; + */ return true; } // virtual -bool TrackPanelClipMoveFunction::dragMoved(DocumentTrack *, QDragMoveEvent * event) -{ -/* QPoint pos = event->pos(); - if (ClipDrag::canDecode(event)) { - GenTime mouseTime = m_timeline->timeUnderMouse((double) pos.x()) - m_clipOffset; - mouseTime = m_snapToGrid.getSnappedTime(mouseTime); - mouseTime = mouseTime + m_clipOffset; - int trackUnder = trackUnderPoint(pos); - - if (m_selection.isEmpty() || m_dragging) { - moveSelectedClips(trackUnder, mouseTime - m_clipOffset); - } else { - if (m_document->projectClip().canAddClipsToTracks(m_selection, - trackUnder, mouseTime)) { - m_selection_to_add = m_selection; - addClipsToTracks(m_selection, trackUnder, mouseTime, true); - setupSnapToGrid(); - m_selection.clear(); - m_dragging = true; - } - } - } else if (EffectDrag::canDecode(event)) { - if (mouseApplies(pos)) { - event->accept(); - } else { - event->ignore(); - } - } else { - event->ignore(); - } - m_timeline->checkScrolling(pos); -*/ +bool TrackPanelClipMoveFunction::dragMoved(DocumentTrack *, QDragMoveEvent * event) { + /* QPoint pos = event->pos(); + if (ClipDrag::canDecode(event)) { + GenTime mouseTime = m_timeline->timeUnderMouse((double) pos.x()) - m_clipOffset; + mouseTime = m_snapToGrid.getSnappedTime(mouseTime); + mouseTime = mouseTime + m_clipOffset; + int trackUnder = trackUnderPoint(pos); + + if (m_selection.isEmpty() || m_dragging) { + moveSelectedClips(trackUnder, mouseTime - m_clipOffset); + } else { + if (m_document->projectClip().canAddClipsToTracks(m_selection, + trackUnder, mouseTime)) { + m_selection_to_add = m_selection; + addClipsToTracks(m_selection, trackUnder, mouseTime, true); + setupSnapToGrid(); + m_selection.clear(); + m_dragging = true; + } + } + } else if (EffectDrag::canDecode(event)) { + if (mouseApplies(pos)) { + event->accept(); + } else { + event->ignore(); + } + } else { + event->ignore(); + } + m_timeline->checkScrolling(pos); + */ return true; } -int TrackPanelClipMoveFunction::trackUnderPoint(const QPoint & pos) -{ +int TrackPanelClipMoveFunction::trackUnderPoint(const QPoint & pos) { uint y = pos.y(); DocumentTrack * panel = m_view->panelAt(y); -/* - if (panel) { - return panel->documentTrackIndex(); - }*/ + /* + if (panel) { + return panel->documentTrackIndex(); + }*/ return -1; } // virtual -bool TrackPanelClipMoveFunction::dragLeft(DocumentTrack *, QDragLeaveEvent *) -{ +bool TrackPanelClipMoveFunction::dragLeft(DocumentTrack *, QDragLeaveEvent *) { m_dragging = false; -/* - if (!m_selection.isEmpty()) { - m_selection.setAutoDelete(true); - m_selection.clear(); - m_selection.setAutoDelete(false); - } - - if (m_addingClips) { - m_addingClips = false; - - QPtrListIterator < DocTrackBase > - trackItt(m_document->trackList()); - - while (trackItt.current()) { - (*trackItt)->deleteClips(true); - ++trackItt; - } - - m_document->activateSceneListGeneration(true); - } - - if (m_moveClipsCommand) { - m_moveClipsCommand->setEndLocation(m_masterClip); - m_app->addCommand(m_moveClipsCommand, false); - // In a drag Leave Event, any clips in the selection are removed from the timeline. - //delete m_moveClipsCommand; - m_moveClipsCommand = 0; - m_document->activateSceneListGeneration(true); - } - - if (m_deleteClipsCommand) { - m_app->addCommand(m_deleteClipsCommand, false); - m_deleteClipsCommand = 0; - - QPtrListIterator < DocTrackBase > - trackItt(m_document->trackList()); - - while (trackItt.current()) { - trackItt.current()->deleteClips(true); - ++trackItt; - } - } - - m_timeline->drawTrackViewBackBuffer(); - m_timeline->stopScrollTimer(); -*/ + /* + if (!m_selection.isEmpty()) { + m_selection.setAutoDelete(true); + m_selection.clear(); + m_selection.setAutoDelete(false); + } + + if (m_addingClips) { + m_addingClips = false; + + QPtrListIterator < DocTrackBase > + trackItt(m_document->trackList()); + + while (trackItt.current()) { + (*trackItt)->deleteClips(true); + ++trackItt; + } + + m_document->activateSceneListGeneration(true); + } + + if (m_moveClipsCommand) { + m_moveClipsCommand->setEndLocation(m_masterClip); + m_app->addCommand(m_moveClipsCommand, false); + // In a drag Leave Event, any clips in the selection are removed from the timeline. + //delete m_moveClipsCommand; + m_moveClipsCommand = 0; + m_document->activateSceneListGeneration(true); + } + + if (m_deleteClipsCommand) { + m_app->addCommand(m_deleteClipsCommand, false); + m_deleteClipsCommand = 0; + + QPtrListIterator < DocTrackBase > + trackItt(m_document->trackList()); + + while (trackItt.current()) { + trackItt.current()->deleteClips(true); + ++trackItt; + } + } + + m_timeline->drawTrackViewBackBuffer(); + m_timeline->stopScrollTimer(); + */ return true; } // virtual bool TrackPanelClipMoveFunction::dragDropped(DocumentTrack * panel, - QDropEvent * event) -{ -/* - m_dragging = false; - m_startedClipMove = false; - if (ClipDrag::canDecode(event)) { - if (!m_selection.isEmpty()) { - m_selection.setAutoDelete(true); - m_selection.clear(); - m_selection.setAutoDelete(false); - } - - if (m_addingClips) { - - m_app->addCommand(createAddClipsCommand(), true); - m_addingClips = false; - m_app->clipReferenceChanged(); - - //if (m_firststep) m_document->activateSceneListGeneration(true); - m_firststep = false; - } - - if (m_deleteClipsCommand) { - delete m_deleteClipsCommand; - m_deleteClipsCommand = 0; - } - - if (m_moveClipsCommand) { - m_moveClipsCommand->setEndLocation(m_masterClip); - if (!m_moveClipsCommand->doesMove()) - { - //m_document->activateSceneListGeneration(true); - moveSelectedClips(m_moveClipsCommand->startTrack(), m_moveClipsCommand->startTime()); - m_app->addCommand(m_moveClipsCommand, true); - m_moveClipsCommand = 0; - m_document->slotUpdateMonitorPlaytime(); - // KdenliveApp is now managing this command, we do not need to delete it. - } - else { - m_document->activateSceneListGeneration(true, false); - delete m_moveClipsCommand; - m_moveClipsCommand = 0; - } - } - event->accept(); - } else if (EffectDrag::canDecode(event)) { - DocClipRef *clipUnderMouse = 0; - DocumentTrack * panel = - m_view->panelAt(event->pos().y()); - if (panel) { - DocTrackBase *track = - m_document->track(panel->documentTrackIndex()); - if (track) { - GenTime mouseTime((int)(m_timeline->mapLocalToValue(event->pos(). - x())), m_document->framesPerSecond()); - clipUnderMouse = track->getClipAt(mouseTime); - } - } - - if (clipUnderMouse) { - Effect *effect = EffectDrag::decode(m_document, event); - if (effect) { - m_app-> - addCommand(Command::KAddEffectCommand:: - appendEffect(m_document, clipUnderMouse, effect), - true); - if (effect->name() == i18n("Freeze")) m_app->getDocument()->emitCurrentClipPosition(); - } else { - kdWarning() << - "EffectDrag::decode did not return an effect, ignoring drag drop..." - << endl; - } - delete effect; - } - } - m_timeline->stopScrollTimer(); - m_timeline->drawTrackViewBackBuffer(); -*/ + QDropEvent * event) { + /* + m_dragging = false; + m_startedClipMove = false; + if (ClipDrag::canDecode(event)) { + if (!m_selection.isEmpty()) { + m_selection.setAutoDelete(true); + m_selection.clear(); + m_selection.setAutoDelete(false); + } + + if (m_addingClips) { + + m_app->addCommand(createAddClipsCommand(), true); + m_addingClips = false; + m_app->clipReferenceChanged(); + + //if (m_firststep) m_document->activateSceneListGeneration(true); + m_firststep = false; + } + + if (m_deleteClipsCommand) { + delete m_deleteClipsCommand; + m_deleteClipsCommand = 0; + } + + if (m_moveClipsCommand) { + m_moveClipsCommand->setEndLocation(m_masterClip); + if (!m_moveClipsCommand->doesMove()) + { + //m_document->activateSceneListGeneration(true); + moveSelectedClips(m_moveClipsCommand->startTrack(), m_moveClipsCommand->startTime()); + m_app->addCommand(m_moveClipsCommand, true); + m_moveClipsCommand = 0; + m_document->slotUpdateMonitorPlaytime(); + // KdenliveApp is now managing this command, we do not need to delete it. + } + else { + m_document->activateSceneListGeneration(true, false); + delete m_moveClipsCommand; + m_moveClipsCommand = 0; + } + } + event->accept(); + } else if (EffectDrag::canDecode(event)) { + DocClipRef *clipUnderMouse = 0; + DocumentTrack * panel = + m_view->panelAt(event->pos().y()); + if (panel) { + DocTrackBase *track = + m_document->track(panel->documentTrackIndex()); + if (track) { + GenTime mouseTime((int)(m_timeline->mapLocalToValue(event->pos(). + x())), m_document->framesPerSecond()); + clipUnderMouse = track->getClipAt(mouseTime); + } + } + + if (clipUnderMouse) { + Effect *effect = EffectDrag::decode(m_document, event); + if (effect) { + m_app-> + addCommand(Command::KAddEffectCommand:: + appendEffect(m_document, clipUnderMouse, effect), + true); + if (effect->name() == i18n("Freeze")) m_app->getDocument()->emitCurrentClipPosition(); + } else { + kdWarning() << + "EffectDrag::decode did not return an effect, ignoring drag drop..." + << endl; + } + delete effect; + } + } + m_timeline->stopScrollTimer(); + m_timeline->drawTrackViewBackBuffer(); + */ return true; } bool TrackPanelClipMoveFunction::moveSelectedClips(int newTrack, - GenTime start) -{ -/* - if (!m_masterClip) return false; - int trackOffset = - m_document->trackIndex(m_document->findTrack(m_masterClip)); - GenTime startOffset; - - if (trackOffset == -1) { - kdError() << - "Trying to move selected clips, master clip is not set." << - endl; - return false; - } else { - startOffset = m_masterClip->trackStart(); - } - - trackOffset = newTrack - trackOffset; - startOffset = start - startOffset; - if (startOffset == GenTime()) return false; - m_document->moveSelectedClips(startOffset, trackOffset); -*/ + GenTime start) { + /* + if (!m_masterClip) return false; + int trackOffset = + m_document->trackIndex(m_document->findTrack(m_masterClip)); + GenTime startOffset; + + if (trackOffset == -1) { + kdError() << + "Trying to move selected clips, master clip is not set." << + endl; + return false; + } else { + startOffset = m_masterClip->trackStart(); + } + + trackOffset = newTrack - trackOffset; + startOffset = start - startOffset; + if (startOffset == GenTime()) return false; + m_document->moveSelectedClips(startOffset, trackOffset); + */ return true; } @@ -417,76 +402,75 @@ void TrackPanelClipMoveFunction::addClipsToTracks(DocClipRefList & clips, { if (clips.isEmpty()) - return; + return; if (selected) { - m_app-> - addCommand(Command::KSelectClipCommand::selectNone(m_document), - true); + m_app-> + addCommand(Command::KSelectClipCommand::selectNone(m_document), + true); } DocClipRef *masterClip = clips.masterClip(); if (!masterClip) - masterClip = clips.first(); + masterClip = clips.first(); GenTime startOffset = value - masterClip->trackStart(); int trackOffset = masterClip->trackNum(); if (trackOffset == -1) - trackOffset = 0; + trackOffset = 0; trackOffset = track - trackOffset; QPtrListIterator < DocClipRef > itt(clips); int moveToTrack; while (itt.current() != 0) { - moveToTrack = itt.current()->trackNum(); + moveToTrack = itt.current()->trackNum(); - if (moveToTrack == -1) { - moveToTrack = track; - itt.current()->moveTrackStart(itt.current()->trackStart() + startOffset); - startOffset += itt.current()->cropDuration(); - } else { - moveToTrack += trackOffset; - itt.current()->moveTrackStart(itt.current()->trackStart() + startOffset); - } + if (moveToTrack == -1) { + moveToTrack = track; + itt.current()->moveTrackStart(itt.current()->trackStart() + startOffset); + startOffset += itt.current()->cropDuration(); + } else { + moveToTrack += trackOffset; + itt.current()->moveTrackStart(itt.current()->trackStart() + startOffset); + } - if ((moveToTrack >= 0) && (moveToTrack < (int)m_document->numTracks())) { - //if (itt.current()->referencedClip()->numReferences() == 0) - m_document->track(moveToTrack)->addClip(itt.current(), selected); - } + if ((moveToTrack >= 0) && (moveToTrack < (int)m_document->numTracks())) { + //if (itt.current()->referencedClip()->numReferences() == 0) + m_document->track(moveToTrack)->addClip(itt.current(), selected); + } - ++itt; + ++itt; } m_addingClips = true; } */ -void TrackPanelClipMoveFunction::setupSnapToGrid() -{ -/* - m_snapToGrid.clearSnapList(); - if (m_timeline->snapToSeekTime()) - m_snapToGrid.addToSnapList(m_timeline->seekPosition()); - m_snapToGrid.setSnapToFrame(m_timeline->snapToFrame()); - - m_snapToGrid.addToSnapList(m_document->getSnapTimes(m_timeline-> - snapToBorders(), m_timeline->snapToMarkers(), true, false)); - - QValueVector < GenTime > cursor = - m_document->getSnapTimes(m_timeline->snapToBorders(), - m_timeline->snapToMarkers(), false, true, false); - m_snapToGrid.setCursorTimes(cursor); - - m_snapToGrid.setSnapTolerance(GenTime((int)(m_timeline-> - mapLocalToValue(Gui::KTimeLine::snapTolerance) - - m_timeline->mapLocalToValue(0)), - m_document->framesPerSecond())); -*/ +void TrackPanelClipMoveFunction::setupSnapToGrid() { + /* + m_snapToGrid.clearSnapList(); + if (m_timeline->snapToSeekTime()) + m_snapToGrid.addToSnapList(m_timeline->seekPosition()); + m_snapToGrid.setSnapToFrame(m_timeline->snapToFrame()); + + m_snapToGrid.addToSnapList(m_document->getSnapTimes(m_timeline-> + snapToBorders(), m_timeline->snapToMarkers(), true, false)); + + QValueVector < GenTime > cursor = + m_document->getSnapTimes(m_timeline->snapToBorders(), + m_timeline->snapToMarkers(), false, true, false); + m_snapToGrid.setCursorTimes(cursor); + + m_snapToGrid.setSnapTolerance(GenTime((int)(m_timeline-> + mapLocalToValue(Gui::KTimeLine::snapTolerance) - + m_timeline->mapLocalToValue(0)), + m_document->framesPerSecond())); + */ } /*void TrackPanelClipMoveFunction::initiateDrag(DocClipRef * clipUnderMouse, @@ -496,12 +480,12 @@ void TrackPanelClipMoveFunction::setupSnapToGrid() m_clipOffset = mouseTime - clipUnderMouse->trackStart(); m_moveClipsCommand = - new Command::KMoveClipsCommand(m_document, m_masterClip); + new Command::KMoveClipsCommand(m_document, m_masterClip); m_moveClipsCommand->setClipList(m_document->listSelected()); m_deleteClipsCommand = - Command::KAddRefClipCommand::deleteSelectedClips(m_document); + Command::KAddRefClipCommand::deleteSelectedClips(m_document); setupSnapToGrid(); m_startedClipMove = true; @@ -518,18 +502,18 @@ KMacroCommand *TrackPanelClipMoveFunction::createAddClipsCommand() { KMacroCommand *macroCommand = new KMacroCommand(i18n("Add Clips")); - for (int count = 0; count < (int)m_document->numTracks(); ++count) { - DocTrackBase *track = m_document->track(count); + for (int count = 0; count < (int)m_document->numTracks(); ++count) { + DocTrackBase *track = m_document->track(count); - QPtrListIterator < DocClipRef > itt = track->firstClip(true); + QPtrListIterator < DocClipRef > itt = track->firstClip(true); - while (itt.current()) { - Command::KAddRefClipCommand * command = - new Command::KAddRefClipCommand(*m_document, itt.current(), true); - macroCommand->addCommand(command); - ++itt; - } - m_document->generateProducersList(); + while (itt.current()) { + Command::KAddRefClipCommand * command = + new Command::KAddRefClipCommand(*m_document, itt.current(), true); + macroCommand->addCommand(command); + ++itt; + } + m_document->generateProducersList(); } return macroCommand; } diff --git a/src/trackpanelclipmovefunction.h b/src/trackpanelclipmovefunction.h index 8d40e223..b8d09db7 100644 --- a/src/trackpanelclipmovefunction.h +++ b/src/trackpanelclipmovefunction.h @@ -31,139 +31,139 @@ Abstract Base Class for track panel functionality decorators. This and it's derived classes allow different behaviours to be added to panels as required. @author Jason Wood -*/ class TrackPanelClipMoveFunction:public TrackPanelFunction -{ - Q_OBJECT public: +*/ +class TrackPanelClipMoveFunction: public TrackPanelFunction { +Q_OBJECT public: TrackPanelClipMoveFunction(TrackView * view); virtual ~ TrackPanelClipMoveFunction(); - /** - Returns true if the specified position should cause this function to activate, - otherwise returns false. - */ + /** + Returns true if the specified position should cause this function to activate, + otherwise returns false. + */ virtual bool mouseApplies(DocumentTrack *, - QMouseEvent * event) const; + QMouseEvent * event) const; - /** - Returns a relevant mouse cursor for the given mouse position - */ + /** + Returns a relevant mouse cursor for the given mouse position + */ virtual QCursor getMouseCursor(DocumentTrack *, QMouseEvent * event); - /** - A mouse button has been pressed. Returns true if we want to handle this event - */ + /** + A mouse button has been pressed. Returns true if we want to handle this event + */ virtual bool mousePressed(DocumentTrack * panel, - QMouseEvent * event); + QMouseEvent * event); - /** - Processes Mouse double click.*/ + /** + Processes Mouse double click.*/ virtual bool mouseDoubleClicked(DocumentTrack * panel, QMouseEvent *); - /** - Mouse Release Events in the track view area. Returns true if we have finished - an operation now. - */ + /** + Mouse Release Events in the track view area. Returns true if we have finished + an operation now. + */ virtual bool mouseReleased(DocumentTrack *, QMouseEvent *); - /** - Processes Mouse Move events in the track view area. Returns true if we are - continuing with the drag.*/ + /** + Processes Mouse Move events in the track view area. Returns true if we are + continuing with the drag.*/ virtual bool mouseMoved(DocumentTrack * panel, QMouseEvent * event); - /** - Process drag events - */ + /** + Process drag events + */ virtual bool dragEntered(DocumentTrack * panel, QDragEnterEvent *); virtual bool dragMoved(DocumentTrack *, QDragMoveEvent *); virtual bool dragLeft(DocumentTrack *, QDragLeaveEvent *); virtual bool dragDropped(DocumentTrack * panel, QDropEvent *); - private: +private: TrackView * m_view; KdenliveDoc *m_document; TrackViewClip *m_clipUnderMouse; bool m_dragging; bool m_firststep; - /** - This variable should be set to true if we have initiated a drag which - is going to be moving, rather than adding, clips. + /** + This variable should be set to true if we have initiated a drag which + is going to be moving, rather than adding, clips. - set to false otherwise. The purpose of this variable is to prevent the - selection group from being re-created on drag entry if we are only - moving it - this prevents a copy of the clips from being created. - */ + set to false otherwise. The purpose of this variable is to prevent the + selection group from being re-created on drag entry if we are only + moving it - this prevents a copy of the clips from being created. + */ bool m_startedClipMove; - /** - This list is used to group clips together when they are being dragged away from the - timeline, or are being dragged onto the timeline. It gives a home to clips that have not yet - been placed. - */ + /** + This list is used to group clips together when they are being dragged away from the + timeline, or are being dragged onto the timeline. It gives a home to clips that have not yet + been placed. + */ //DocClipRefList m_selection; //DocClipRefList m_selection_to_add; - /** - This is the "master" Clip - the clip that is actively being dragged by the mouse. - All other clips move in relation to the master clip. - */ + /** + This is the "master" Clip - the clip that is actively being dragged by the mouse. + All other clips move in relation to the master clip. + */ TrackViewClip *m_masterClip; - /** - When dragging a clip, this is the time offset that should be applied to where - the mouse cursor to find the beginning of the master clip. - */ + /** + When dragging a clip, this is the time offset that should be applied to where + the mouse cursor to find the beginning of the master clip. + */ GenTime m_clipOffset; - /** A snap to grid object used for calculating snap-to-grid calculations. */ + /** A snap to grid object used for calculating snap-to-grid calculations. */ //SnapToGrid m_snapToGrid; - /** Moves all selected clips to a new position. The new start position is that for the master clip, - all other clips are moved in relation to it. Returns true on success, false on failure.*/ + /** Moves all selected clips to a new position. The new start position is that for the master clip, + all other clips are moved in relation to it. Returns true on success, false on failure.*/ bool moveSelectedClips(int newTrack, GenTime start); - /** Adds a Clipgroup to the tracks in the timeline. It there are some currently selected clips and - we add new clips with this method, the previously selected clips are dselected. */ + /** Adds a Clipgroup to the tracks in the timeline. It there are some currently selected clips and + we add new clips with this method, the previously selected clips are dselected. */ //void addClipsToTracks(DocClipRefList & clips, int track, GenTime value,bool selected); - /** set up the snap-to-grid class */ + /** set up the snap-to-grid class */ void setupSnapToGrid(); - /** Find the index of the document track underneath the specified point on the track. */ + /** Find the index of the document track underneath the specified point on the track. */ int trackUnderPoint(const QPoint & pos); - /** Initiates a drag operation on the selected clip, setting the master clip to clipUnderMouse, - and specifying the time that the mouse is currently pointing at. */ + /** Initiates a drag operation on the selected clip, setting the master clip to clipUnderMouse, + and specifying the time that the mouse is currently pointing at. */ //void initiateDrag(DocClipRef * clipUnderMouse, GenTime mouseTime); - /** - True if we are currently in the process of adding clips to the timeline. - False otherwise. - */ + /** + True if we are currently in the process of adding clips to the timeline. + False otherwise. + */ bool m_addingClips; - /** - A moveClipCommand action, used to record clip movement for undo/redo functionality. - */ - //Command::KMoveClipsCommand * m_moveClipsCommand; - /** - This command is used to record clip deletion for undo/redo functionality. - */ + /** + A moveClipCommand action, used to record clip movement for undo/redo functionality. + */ + //Command::KMoveClipsCommand * m_moveClipsCommand; + /** + This command is used to record clip deletion for undo/redo functionality. + */ //KMacroCommand *m_deleteClipsCommand; #warning - The following method is a bad example for programming design. - /** Returns a command that would create those clips in the document that are currently selected. - */ + /** Returns a command that would create those clips in the document that are currently selected. + */ //KMacroCommand *createAddClipsCommand(); - /** Returns true if the x,y position is over a clip (and therefore, the move function applies) */ + /** Returns true if the x,y position is over a clip (and therefore, the move function applies) */ bool mouseApplies(const QPoint & pos) const; - signals: - //void checkTransition(DocClipRef*); +signals: + //void checkTransition(DocClipRef*); }; #endif diff --git a/src/trackpanelfunction.cpp b/src/trackpanelfunction.cpp index 91c8ac1d..3e0408ee 100644 --- a/src/trackpanelfunction.cpp +++ b/src/trackpanelfunction.cpp @@ -16,13 +16,11 @@ ***************************************************************************/ #include "trackpanelfunction.h" -TrackPanelFunction::TrackPanelFunction() -{ +TrackPanelFunction::TrackPanelFunction() { } -TrackPanelFunction::~TrackPanelFunction() -{ +TrackPanelFunction::~TrackPanelFunction() { } #include "trackpanelfunction.moc" diff --git a/src/trackpanelfunction.h b/src/trackpanelfunction.h index 0f22231f..5927d71a 100644 --- a/src/trackpanelfunction.h +++ b/src/trackpanelfunction.h @@ -30,60 +30,60 @@ Abstract Base Class for track panel functionality decorators. This and it's derived classes allow different behaviours to be added to panels as required. @author Jason Wood -*/ class TrackPanelFunction:public QObject -{ - Q_OBJECT public: +*/ +class TrackPanelFunction: public QObject { +Q_OBJECT public: TrackPanelFunction(); virtual ~ TrackPanelFunction(); - /** - Returns true if the specified position should cause this function to activate, - otherwise returns false. - */ + /** + Returns true if the specified position should cause this function to activate, + otherwise returns false. + */ virtual bool mouseApplies(DocumentTrack * panel, - QMouseEvent * event) const = 0; + QMouseEvent * event) const = 0; - /** - Returns a relevant mouse cursor for the given mouse position - */ + /** + Returns a relevant mouse cursor for the given mouse position + */ virtual QCursor getMouseCursor(DocumentTrack * panel, - QMouseEvent * event) = 0; + QMouseEvent * event) = 0; - /** - A mouse button has been pressed. Returns true if we want to handle this event - */ + /** + A mouse button has been pressed. Returns true if we want to handle this event + */ virtual bool mousePressed(DocumentTrack * panel, - QMouseEvent * event) = 0; + QMouseEvent * event) = 0; virtual bool mouseDoubleClicked(DocumentTrack * panel, QMouseEvent * event) = 0; - /** - Mouse Release Events in the track view area. Returns true if we have finished - an operation now. - */ + /** + Mouse Release Events in the track view area. Returns true if we have finished + an operation now. + */ virtual bool mouseReleased(DocumentTrack * panel, - QMouseEvent * event) = 0; + QMouseEvent * event) = 0; - /** - Processes Mouse Move events in the track view area. Returns true if we are - continuing with the drag.*/ + /** + Processes Mouse Move events in the track view area. Returns true if we are + continuing with the drag.*/ virtual bool mouseMoved(DocumentTrack * panel, - QMouseEvent * event) = 0; + QMouseEvent * event) = 0; - /** - Process Drag events*/ + /** + Process Drag events*/ virtual bool dragEntered(DocumentTrack * , QDragEnterEvent *) { - return false; + return false; }; virtual bool dragMoved(DocumentTrack * , QDragMoveEvent *) { - return false; + return false; }; virtual bool dragLeft(DocumentTrack * , QDragLeaveEvent *) { - return false; + return false; }; virtual bool dragDropped(DocumentTrack * , QDropEvent *) { - return false; + return false; }; }; diff --git a/src/trackpanelfunctionfactory.cpp b/src/trackpanelfunctionfactory.cpp index 08e9b5a1..7e8c6ee6 100644 --- a/src/trackpanelfunctionfactory.cpp +++ b/src/trackpanelfunctionfactory.cpp @@ -20,46 +20,41 @@ #include -TrackPanelFunctionFactory::TrackPanelFunctionFactory() -{ +TrackPanelFunctionFactory::TrackPanelFunctionFactory() { } -TrackPanelFunctionFactory::~TrackPanelFunctionFactory() -{ +TrackPanelFunctionFactory::~TrackPanelFunctionFactory() { clearFactory(); } -void TrackPanelFunctionFactory::clearFactory() -{ +void TrackPanelFunctionFactory::clearFactory() { QMap < QString, TrackPanelFunction * >::iterator itt = - m_functionMap.begin(); + m_functionMap.begin(); while (itt != m_functionMap.end()) { - delete(itt.value()); - itt.value() = 0; - ++itt; + delete(itt.value()); + itt.value() = 0; + ++itt; } m_functionMap.clear(); } void TrackPanelFunctionFactory::registerFunction(const QString & name, - TrackPanelFunction * function) -{ + TrackPanelFunction * function) { if (!m_functionMap.contains(name)) { - m_functionMap[name] = function; + m_functionMap[name] = function; } else { - kError() << "Factory already contains a function called " << name; + kError() << "Factory already contains a function called " << name; } } TrackPanelFunction *TrackPanelFunctionFactory:: -function(const QString & name) -{ +function(const QString & name) { if (m_functionMap.contains(name)) { - return m_functionMap[name]; + return m_functionMap[name]; } else { - kError() << "No function called " << name << " found in factory"; + kError() << "No function called " << name << " found in factory"; } return 0; diff --git a/src/trackpanelfunctionfactory.h b/src/trackpanelfunctionfactory.h index f57dbb6a..b891e2b1 100644 --- a/src/trackpanelfunctionfactory.h +++ b/src/trackpanelfunctionfactory.h @@ -27,19 +27,19 @@ A factory containing all known trackpanel functions. @author Jason Wood */ class TrackPanelFunctionFactory { - public: +public: TrackPanelFunctionFactory(); ~TrackPanelFunctionFactory(); void registerFunction(const QString & name, - TrackPanelFunction * function); + TrackPanelFunction * function); TrackPanelFunction *function(const QString & name); void clearFactory(); - private: - QMap < QString, TrackPanelFunction * >m_functionMap; +private: + QMap < QString, TrackPanelFunction * >m_functionMap; }; #endif diff --git a/src/trackview.cpp b/src/trackview.cpp index 23ff6534..ed099789 100644 --- a/src/trackview.cpp +++ b/src/trackview.cpp @@ -33,293 +33,267 @@ #include "trackpanelclipmovefunction.h" TrackView::TrackView(KdenliveDoc *doc, QWidget *parent) - : QWidget(parent), m_doc(doc), m_scale(1.0), m_panelUnderMouse(NULL), m_function(NULL), m_projectTracks(0), m_projectDuration(0) -{ - setMouseTracking(true); - view = new Ui::TimeLine_UI(); - view->setupUi(this); - m_ruler = new CustomRuler(doc->timecode()); - QVBoxLayout *layout = new QVBoxLayout; - view->ruler_frame->setLayout(layout); - layout->addWidget(m_ruler); - - m_scene = new QGraphicsScene(); - m_trackview = new CustomTrackView(doc, m_scene, this); - m_trackview->scale(1, 1); - m_trackview->setAlignment(Qt::AlignLeft | Qt::AlignTop); - //m_scene->addRect(QRectF(0, 0, 100, 100), QPen(), QBrush(Qt::red)); - - m_headersLayout = new QVBoxLayout; - m_headersLayout->setContentsMargins (0, 0, 0, 0); - view->headers_frame->setLayout(m_headersLayout); - - QVBoxLayout *tracksLayout = new QVBoxLayout; - tracksLayout->setContentsMargins (0, 0, 0, 0); - view->tracks_frame->setLayout(tracksLayout); - tracksLayout->addWidget(m_trackview); - - parseDocument(doc->toXml()); -/* - TrackPanelClipMoveFunction *m_moveFunction = new TrackPanelClipMoveFunction(this); - registerFunction("move", m_moveFunction); - setEditMode("move");*/ - - connect(view->horizontalSlider, SIGNAL(valueChanged ( int )), this, SLOT(slotChangeZoom( int ))); - connect(m_ruler, SIGNAL(cursorMoved ( int )), this, SLOT(setCursorPos( int ))); - connect(m_trackview, SIGNAL(cursorMoved ( int )), this, SLOT(slotCursorMoved( int ))); - connect(m_trackview, SIGNAL(zoomIn ()), this, SLOT(slotZoomIn())); - connect(m_trackview, SIGNAL(zoomOut ()), this, SLOT(slotZoomOut())); - connect(m_trackview->horizontalScrollBar(), SIGNAL(sliderMoved( int )), m_ruler, SLOT(slotMoveRuler( int ))); - connect(m_trackview, SIGNAL(mousePosition(int)), this, SIGNAL(mousePosition(int))); - connect(m_trackview, SIGNAL(clipItemSelected(ClipItem*)),this,SLOT(slotClipItemSelected(ClipItem*))); - view->horizontalSlider->setValue(4); - m_currentZoom = view->horizontalSlider->value(); - m_trackview->initView(); + : QWidget(parent), m_doc(doc), m_scale(1.0), m_panelUnderMouse(NULL), m_function(NULL), m_projectTracks(0), m_projectDuration(0) { + setMouseTracking(true); + view = new Ui::TimeLine_UI(); + view->setupUi(this); + m_ruler = new CustomRuler(doc->timecode()); + QVBoxLayout *layout = new QVBoxLayout; + view->ruler_frame->setLayout(layout); + layout->addWidget(m_ruler); + + m_scene = new QGraphicsScene(); + m_trackview = new CustomTrackView(doc, m_scene, this); + m_trackview->scale(1, 1); + m_trackview->setAlignment(Qt::AlignLeft | Qt::AlignTop); + //m_scene->addRect(QRectF(0, 0, 100, 100), QPen(), QBrush(Qt::red)); + + m_headersLayout = new QVBoxLayout; + m_headersLayout->setContentsMargins(0, 0, 0, 0); + view->headers_frame->setLayout(m_headersLayout); + + QVBoxLayout *tracksLayout = new QVBoxLayout; + tracksLayout->setContentsMargins(0, 0, 0, 0); + view->tracks_frame->setLayout(tracksLayout); + tracksLayout->addWidget(m_trackview); + + parseDocument(doc->toXml()); + /* + TrackPanelClipMoveFunction *m_moveFunction = new TrackPanelClipMoveFunction(this); + registerFunction("move", m_moveFunction); + setEditMode("move");*/ + + connect(view->horizontalSlider, SIGNAL(valueChanged(int)), this, SLOT(slotChangeZoom(int))); + connect(m_ruler, SIGNAL(cursorMoved(int)), this, SLOT(setCursorPos(int))); + connect(m_trackview, SIGNAL(cursorMoved(int)), this, SLOT(slotCursorMoved(int))); + connect(m_trackview, SIGNAL(zoomIn()), this, SLOT(slotZoomIn())); + connect(m_trackview, SIGNAL(zoomOut()), this, SLOT(slotZoomOut())); + connect(m_trackview->horizontalScrollBar(), SIGNAL(valueChanged(int)), m_ruler, SLOT(slotMoveRuler(int))); + connect(m_trackview, SIGNAL(mousePosition(int)), this, SIGNAL(mousePosition(int))); + connect(m_trackview, SIGNAL(clipItemSelected(ClipItem*)), this, SLOT(slotClipItemSelected(ClipItem*))); + view->horizontalSlider->setValue(4); + m_currentZoom = view->horizontalSlider->value(); + m_trackview->initView(); } -void TrackView::registerFunction(const QString & name, TrackPanelFunction * function) -{ - m_factory.registerFunction(name, function); +void TrackView::registerFunction(const QString & name, TrackPanelFunction * function) { + m_factory.registerFunction(name, function); } -int TrackView::duration() -{ - return m_projectDuration; +int TrackView::duration() { + return m_projectDuration; } -int TrackView::tracksNumber() -{ - return m_projectTracks; +int TrackView::tracksNumber() { + return m_projectTracks; } -void TrackView::slotClipItemSelected(ClipItem*c){ - emit clipItemSelected(c); +void TrackView::slotClipItemSelected(ClipItem*c) { + emit clipItemSelected(c); } -void TrackView::parseDocument(QDomDocument doc) -{ - int cursorPos = 0; - kDebug()<<"//// DOCUMENT: "< m_projectDuration) m_projectDuration = duration; - } - m_trackview->setDuration(m_projectDuration); - slotCursorMoved(cursorPos, true); - //m_scrollBox->setGeometry(0, 0, 300 * zoomFactor(), m_scrollArea->height()); + QDomNodeList tracks = doc.elementsByTagName("playlist"); + m_projectDuration = 300; + m_projectTracks = tracks.count(); + int duration = 0; + kDebug() << "//////////// TIMELINE FOUND: " << m_projectTracks << " tracks"; + for (int i = 0; i < m_projectTracks; i++) { + if (tracks.item(i).toElement().attribute("hide", QString::null) == "video") { + // this is an audio track + duration = slotAddAudioTrack(i, tracks.item(i).toElement()); + } else if (!tracks.item(i).toElement().attribute("id", QString::null).isEmpty()) + duration = slotAddVideoTrack(i, tracks.item(i).toElement()); + kDebug() << " PRO DUR: " << m_projectDuration << ", TRACK DUR: " << duration; + if (duration > m_projectDuration) m_projectDuration = duration; + } + m_trackview->setDuration(m_projectDuration); + slotCursorMoved(cursorPos, true); + //m_scrollBox->setGeometry(0, 0, 300 * zoomFactor(), m_scrollArea->height()); } -void TrackView::slotDeleteClip(int clipId) -{ - m_trackview->deleteClip(clipId); +void TrackView::slotDeleteClip(int clipId) { + m_trackview->deleteClip(clipId); } -void TrackView::setCursorPos(int pos) -{ - emit cursorMoved(); - m_trackview->setCursorPos(pos * m_scale); +void TrackView::setCursorPos(int pos) { + emit cursorMoved(); + m_trackview->setCursorPos(pos * m_scale); } -void TrackView::moveCursorPos(int pos) -{ - m_trackview->setCursorPos(pos * m_scale, false); - m_ruler->slotNewValue(pos * FRAME_SIZE, false); +void TrackView::moveCursorPos(int pos) { + m_trackview->setCursorPos(pos * m_scale, false); + m_ruler->slotNewValue(pos * FRAME_SIZE, false); } -void TrackView::slotCursorMoved(int pos, bool emitSignal) -{ - m_ruler->slotNewValue(pos * FRAME_SIZE / m_scale, emitSignal); //(int) m_trackview->mapToScene(QPoint(pos, 0)).x()); - //m_trackview->setCursorPos(pos); - //m_trackview->invalidateScene(QRectF(), QGraphicsScene::ForegroundLayer); +void TrackView::slotCursorMoved(int pos, bool emitSignal) { + m_ruler->slotNewValue(pos * FRAME_SIZE / m_scale, emitSignal); //(int) m_trackview->mapToScene(QPoint(pos, 0)).x()); + //m_trackview->setCursorPos(pos); + //m_trackview->invalidateScene(QRectF(), QGraphicsScene::ForegroundLayer); } -void TrackView::slotChangeZoom(int factor) -{ - double pos = m_trackview->cursorPos() / m_scale; - m_ruler->setPixelPerMark(factor); - m_scale = (double) FRAME_SIZE / m_ruler->comboScale[factor]; // m_ruler->comboScale[m_currentZoom] / - m_currentZoom = factor; - m_trackview->setScale(m_scale); - m_trackview->setCursorPos(pos * m_scale, false); - m_ruler->slotNewValue(pos * FRAME_SIZE, false); - m_trackview->centerOn(QPointF(m_trackview->cursorPos(), 50)); +void TrackView::slotChangeZoom(int factor) { + double pos = m_trackview->cursorPos() / m_scale; + m_ruler->setPixelPerMark(factor); + m_scale = (double) FRAME_SIZE / m_ruler->comboScale[factor]; // m_ruler->comboScale[m_currentZoom] / + m_currentZoom = factor; + m_trackview->setScale(m_scale); + m_trackview->setCursorPos(pos * m_scale, false); + m_ruler->slotNewValue(pos * FRAME_SIZE, false); + m_trackview->centerOn(QPointF(m_trackview->cursorPos(), 50)); } -const double TrackView::zoomFactor() const -{ - return m_scale; +const double TrackView::zoomFactor() const { + return m_scale; } -void TrackView::slotZoomIn() -{ - view->horizontalSlider->setValue(view->horizontalSlider->value() - 1); +void TrackView::slotZoomIn() { + view->horizontalSlider->setValue(view->horizontalSlider->value() - 1); } -void TrackView::slotZoomOut() -{ - view->horizontalSlider->setValue(view->horizontalSlider->value() + 1); +void TrackView::slotZoomOut() { + view->horizontalSlider->setValue(view->horizontalSlider->value() + 1); } -const int TrackView::mapLocalToValue(int x) const -{ - return (int) x * zoomFactor(); +const int TrackView::mapLocalToValue(int x) const { + return (int) x * zoomFactor(); } -KdenliveDoc *TrackView::document() -{ - return m_doc; +KdenliveDoc *TrackView::document() { + return m_doc; } -int TrackView::slotAddAudioTrack(int ix, QDomElement xml) -{ - kDebug()<<"************* ADD AUDIO TRACK "<addTrack(); - //DocumentTrack *track = new DocumentAudioTrack(xml, this, m_trackview); - HeaderTrack *header = new HeaderTrack(); - //m_tracksAreaLayout->addWidget(track); //, ix, Qt::AlignTop); - m_headersLayout->addWidget(header); //, ix, Qt::AlignTop); - //documentTracks.insert(ix, track); - return 0; - //track->show(); +int TrackView::slotAddAudioTrack(int ix, QDomElement xml) { + kDebug() << "************* ADD AUDIO TRACK " << ix; + m_trackview->addTrack(); + //DocumentTrack *track = new DocumentAudioTrack(xml, this, m_trackview); + HeaderTrack *header = new HeaderTrack(); + //m_tracksAreaLayout->addWidget(track); //, ix, Qt::AlignTop); + m_headersLayout->addWidget(header); //, ix, Qt::AlignTop); + //documentTracks.insert(ix, track); + return 0; + //track->show(); } -int TrackView::slotAddVideoTrack(int ix, QDomElement xml) -{ - m_trackview->addTrack(); - //DocumentTrack *track = new DocumentVideoTrack(xml, this, m_trackview); - HeaderTrack *header = new HeaderTrack(); - int trackTop = 50 * ix; - int trackBottom = trackTop + 50; - // parse track - int position = 0; - for(QDomNode n = xml.firstChild(); !n.isNull(); n = n.nextSibling()) - { - QDomElement elem = n.toElement(); - if (elem.tagName() == "blank") { - position += elem.attribute("length", 0).toInt(); +int TrackView::slotAddVideoTrack(int ix, QDomElement xml) { + m_trackview->addTrack(); + //DocumentTrack *track = new DocumentVideoTrack(xml, this, m_trackview); + HeaderTrack *header = new HeaderTrack(); + int trackTop = 50 * ix; + int trackBottom = trackTop + 50; + // parse track + int position = 0; + for (QDomNode n = xml.firstChild(); !n.isNull(); n = n.nextSibling()) { + QDomElement elem = n.toElement(); + if (elem.tagName() == "blank") { + position += elem.attribute("length", 0).toInt(); + } else if (elem.tagName() == "entry") { + int in = elem.attribute("in", 0).toInt(); + int id = elem.attribute("producer", 0).toInt(); + DocClipBase *clip = m_doc->clipManager()->getClipById(id); + int out = elem.attribute("out", 0).toInt() - in; + //kDebug()<<"++++++++++++++\n\n / / /ADDING CLIP: "<addItem(item); + position += out; + + //m_clipList.append(clip); + } } - else if (elem.tagName() == "entry") { - int in = elem.attribute("in", 0).toInt(); - int id = elem.attribute("producer", 0).toInt(); - DocClipBase *clip = m_doc->clipManager()->getClipById(id); - int out = elem.attribute("out", 0).toInt() - in; - //kDebug()<<"++++++++++++++\n\n / / /ADDING CLIP: "<addItem(item); - position += out; - - //m_clipList.append(clip); - } - } - //m_trackDuration = position; - - //m_tracksAreaLayout->addWidget(track); //, ix, Qt::AlignTop); - m_headersLayout->addWidget(header); //, ix, Qt::AlignTop); - //documentTracks.insert(ix, track); - kDebug()<<"************* ADD VIDEO TRACK "<show(); + //m_trackDuration = position; + + //m_tracksAreaLayout->addWidget(track); //, ix, Qt::AlignTop); + m_headersLayout->addWidget(header); //, ix, Qt::AlignTop); + //documentTracks.insert(ix, track); + kDebug() << "************* ADD VIDEO TRACK " << ix << ", DURATION: " << position; + return position; + //track->show(); } -DocumentTrack *TrackView::panelAt(int y) -{ - return NULL; +DocumentTrack *TrackView::panelAt(int y) { + return NULL; } -QGraphicsScene *TrackView::projectScene() -{ - return m_scene; +QGraphicsScene *TrackView::projectScene() { + return m_scene; } -CustomTrackView *TrackView::projectView() -{ - return m_trackview; +CustomTrackView *TrackView::projectView() { + return m_trackview; } -void TrackView::setEditMode(const QString & editMode) -{ - m_editMode = editMode; +void TrackView::setEditMode(const QString & editMode) { + m_editMode = editMode; } -const QString & TrackView::editMode() const -{ - return m_editMode; +const QString & TrackView::editMode() const { + return m_editMode; } /** This event occurs when the mouse has been moved. */ - void TrackView::mouseMoveEvent(QMouseEvent * event) { - if (m_panelUnderMouse) { - if (event->buttons() & Qt::LeftButton) { - bool result = false; - if (m_function) - result = - m_function->mouseMoved(m_panelUnderMouse, event); - if (!result) { - m_panelUnderMouse = 0; - m_function = 0; - } - } else { - if (m_function) { - m_function->mouseReleased(m_panelUnderMouse, event); - m_function = 0; - } - m_panelUnderMouse = 0; - } - } else { - DocumentTrack *panel = panelAt(event->y()); - if (panel) { - QCursor result(Qt::ArrowCursor); - - TrackPanelFunction *function = - getApplicableFunction(panel, editMode(), - event); - if (function) - result = function->getMouseCursor(panel, event); - - setCursor(result); - } else { - setCursor(QCursor(Qt::ArrowCursor)); - } - } +void TrackView::mouseMoveEvent(QMouseEvent * event) { + if (m_panelUnderMouse) { + if (event->buttons() & Qt::LeftButton) { + bool result = false; + if (m_function) + result = + m_function->mouseMoved(m_panelUnderMouse, event); + if (!result) { + m_panelUnderMouse = 0; + m_function = 0; + } + } else { + if (m_function) { + m_function->mouseReleased(m_panelUnderMouse, event); + m_function = 0; + } + m_panelUnderMouse = 0; + } + } else { + DocumentTrack *panel = panelAt(event->y()); + if (panel) { + QCursor result(Qt::ArrowCursor); + + TrackPanelFunction *function = + getApplicableFunction(panel, editMode(), + event); + if (function) + result = function->getMouseCursor(panel, event); + + setCursor(result); + } else { + setCursor(QCursor(Qt::ArrowCursor)); + } } +} - TrackPanelFunction *TrackView::getApplicableFunction(DocumentTrack * - panel, const QString & editMode, QMouseEvent * event) { - TrackPanelFunction *function = 0; - - QStringList list = panel->applicableFunctions(editMode); - QStringList::iterator itt = list.begin(); +TrackPanelFunction *TrackView::getApplicableFunction(DocumentTrack * + panel, const QString & editMode, QMouseEvent * event) { + TrackPanelFunction *function = 0; - while (itt != list.end()) { - TrackPanelFunction *testFunction = m_factory.function(*itt); - if (testFunction) { - if (testFunction->mouseApplies(panel, event)) { - function = testFunction; - break; - } - } + QStringList list = panel->applicableFunctions(editMode); + QStringList::iterator itt = list.begin(); - ++itt; - } + while (itt != list.end()) { + TrackPanelFunction *testFunction = m_factory.function(*itt); + if (testFunction) { + if (testFunction->mouseApplies(panel, event)) { + function = testFunction; + break; + } + } - return function; + ++itt; } + return function; +} + #include "trackview.moc" diff --git a/src/trackview.h b/src/trackview.h index f4010fb1..2c576f13 100644 --- a/src/trackview.h +++ b/src/trackview.h @@ -39,14 +39,13 @@ #include "customtrackview.h" class ClipItem; -class TrackView : public QWidget -{ - Q_OBJECT - - public: - TrackView(KdenliveDoc *doc, QWidget *parent=0); +class TrackView : public QWidget { + Q_OBJECT - /** This event occurs when the mouse has been moved. */ +public: + TrackView(KdenliveDoc *doc, QWidget *parent = 0); + + /** This event occurs when the mouse has been moved. */ void mouseMoveEvent(QMouseEvent * event); const double zoomFactor() const; @@ -60,10 +59,10 @@ class TrackView : public QWidget int tracksNumber(); KdenliveDoc *document(); - public slots: +public slots: void slotDeleteClip(int clipId); - private: +private: Ui::TimeLine_UI *view; CustomRuler *m_ruler; CustomTrackView *m_trackview; @@ -73,7 +72,7 @@ class TrackView : public QWidget int m_projectTracks; TrackPanelFunctionFactory m_factory; DocumentTrack *m_panelUnderMouse; - /** The currently applied function. This lasts from mousePressed until mouseRelease. */ + /** The currently applied function. This lasts from mousePressed until mouseRelease. */ TrackPanelFunction *m_function; QString m_editMode; QGraphicsScene *m_scene; @@ -92,7 +91,7 @@ class TrackView : public QWidget void registerFunction(const QString & name, TrackPanelFunction * function); TrackPanelFunction *getApplicableFunction(DocumentTrack * panel, const QString & editMode, QMouseEvent * event); - private slots: +private slots: void slotChangeZoom(int factor); void slotCursorMoved(int pos, bool slotCursorMoved = false); void slotZoomIn(); @@ -100,7 +99,7 @@ class TrackView : public QWidget void setCursorPos(int pos); void moveCursorPos(int pos); void slotClipItemSelected(ClipItem*); - signals: +signals: void mousePosition(int); void cursorMoved(); void clipItemSelected(ClipItem*); -- 2.39.2