// const bool animate = KGlobalSettings::graphicEffectsLevel() & KGlobalSettings::SimpleAnimationEffects;
// const int duration = animate ? 1500 : 1;
-CustomTrackView::CustomTrackView(KdenliveDoc *doc, CustomTrackScene* projectscene, QWidget *parent)
- : QGraphicsView(projectscene, parent), m_scene(projectscene), m_cursorPos(0), m_cursorLine(NULL), m_operationMode(NONE), m_dragItem(NULL), m_visualTip(NULL), m_moveOpMode(NONE), m_animation(NULL), m_projectDuration(0), m_clickPoint(QPoint()), m_document(doc), m_autoScroll(KdenliveSettings::autoscroll()), m_tracksHeight(KdenliveSettings::trackheight()), m_tool(SELECTTOOL), m_dragGuide(NULL), m_findIndex(0), m_menuPosition(QPoint()), m_blockRefresh(false), m_selectionGroup(NULL), m_selectedTrack(0), m_copiedItems(QList<AbstractClipItem *> ()), m_scrollOffset(0), m_changeSpeedAction(NULL), m_pasteEffectsAction(NULL), m_ungroupAction(NULL), m_clipDrag(false)
+CustomTrackView::CustomTrackView(KdenliveDoc *doc, CustomTrackScene* projectscene, QWidget *parent) :
+ QGraphicsView(projectscene, parent),
+ m_tracksHeight(KdenliveSettings::trackheight()),
+ m_projectDuration(0),
+ m_cursorPos(0),
+ m_document(doc),
+ m_scene(projectscene),
+ m_cursorLine(NULL),
+ m_operationMode(NONE),
+ m_moveOpMode(NONE),
+ m_dragItem(NULL),
+ m_dragGuide(NULL),
+ m_visualTip(NULL),
+ m_animation(NULL),
+ m_clickPoint(),
+ m_autoScroll(KdenliveSettings::autoscroll()),
+ m_changeSpeedAction(NULL),
+ m_pasteEffectsAction(NULL),
+ m_ungroupAction(NULL),
+ m_scrollOffset(0),
+ m_clipDrag(false),
+ m_findIndex(0),
+ m_tool(SELECTTOOL),
+ m_copiedItems(),
+ m_menuPosition(),
+ m_blockRefresh(false),
+ m_selectionGroup(NULL)
{
if (doc) m_commandStack = doc->commandStack();
else m_commandStack = NULL;
KIcon spacerIcon("kdenlive-spacer-tool");
m_spacerCursor = QCursor(spacerIcon.pixmap(22, 22));
verticalScrollBar()->setTracking(true);
- connect(verticalScrollBar(), SIGNAL(valueChanged(int)), this, SLOT(slotRefreshGuides()));
+ // Line below was supposed to scroll guides label with scrollbar, not implemented yet
+ //connect(verticalScrollBar(), SIGNAL(valueChanged(int)), this, SLOT(slotRefreshGuides()));
connect(&m_scrollTimer, SIGNAL(timeout()), this, SLOT(slotCheckMouseScrolling()));
m_scrollTimer.setInterval(100);
m_scrollTimer.setSingleShot(true);
m_document->setModified(true);
}
-void CustomTrackView::setContextMenu(QMenu *timeline, QMenu *clip, QMenu *transition)
+void CustomTrackView::setContextMenu(QMenu *timeline, QMenu *clip, QMenu *transition, QActionGroup *clipTypeGroup)
{
m_timelineContextMenu = timeline;
m_timelineContextClipMenu = clip;
+ m_clipTypeGroup = clipTypeGroup;
QList <QAction *> list = m_timelineContextClipMenu->actions();
for (int i = 0; i < list.count(); i++) {
if (list.at(i)->data().toString() == "change_speed") m_changeSpeedAction = list.at(i);
update();
}
-// virtual
-void CustomTrackView::resizeEvent(QResizeEvent * event)
-{
- QGraphicsView::resizeEvent(event);
-}
-
-// virtual
/** Zoom or move viewport on mousewheel
*
* If mousewheel+Ctrl, zooms in/out on the timeline.
int pos = event->x();
int mappedXPos = (int)(mapToScene(event->pos()).x() + 0.5);
emit mousePosition(mappedXPos);
+
if (event->buttons() & Qt::MidButton) return;
- if ((event->modifiers() == Qt::ControlModifier && m_tool != SPACERTOOL) || event->modifiers() == Qt::ShiftModifier) {
+ if (m_operationMode == RUBBERSELECTION || (event->modifiers() == Qt::ControlModifier && m_tool != SPACERTOOL)) {
QGraphicsView::mouseMoveEvent(event);
m_moveOpMode = NONE;
return;
m_dragItem->updateKeyFramePos(keyFramePos, pos);
}
- if (m_animation) delete m_animation;
+ delete m_animation;
m_animation = NULL;
- if (m_visualTip) delete m_visualTip;
+ delete m_visualTip;
m_visualTip = NULL;
return;
} else if (m_operationMode == MOVEGUIDE) {
- if (m_animation) delete m_animation;
+ delete m_animation;
m_animation = NULL;
- if (m_visualTip) delete m_visualTip;
+ delete m_visualTip;
m_visualTip = NULL;
QGraphicsView::mouseMoveEvent(event);
return;
return;
} else {
if (m_visualTip) {
- if (m_animation) delete m_animation;
+ delete m_animation;
m_animation = NULL;
m_animationTimer->stop();
delete m_visualTip;
slotCheckPositionScrolling();
} else m_moveOpMode = NONE;
if (m_visualTip) {
- if (m_animation) delete m_animation;
+ delete m_animation;
m_animationTimer->stop();
m_animation = NULL;
delete m_visualTip;
m_scene->clearSelection();
event->accept();
emit clipItemSelected(NULL);
+ updateClipTypeActions(NULL);
if (m_tool == SPACERTOOL) {
QList<QGraphicsItem *> selection;
if (event->modifiers() == Qt::ControlModifier) {
return;
}
AbstractClipItem *clip = static_cast <AbstractClipItem *>(m_dragItem);
- RazorClipCommand* command = new RazorClipCommand(this, clip->info(), GenTime((int)(mapToScene(event->pos()).x()), m_document->fps()), true);
+ RazorClipCommand* command = new RazorClipCommand(this, clip->info(), GenTime((int)(mapToScene(event->pos()).x()), m_document->fps()));
m_document->renderer()->pause();
m_commandStack->push(command);
m_document->setModified(true);
if (m_dragItem->type() == AVWIDGET && !m_dragItem->isItemLocked()) emit clipItemSelected((ClipItem*) m_dragItem);
else emit clipItemSelected(NULL);
- if (event->modifiers() != Qt::ControlModifier && (m_dragItem->isSelected() || dragGroup && dragGroup->isSelected())) {
+ if (event->modifiers() != Qt::ControlModifier && (m_dragItem->isSelected() || (dragGroup && dragGroup->isSelected()))) {
// If clicked item is selected, allow move
if (dragGroup) dragGroup->setSelected(true);
//event->accept();
bool selected = !m_dragItem->isSelected();
if (dragGroup) dragGroup->setSelected(selected);
else m_dragItem->setSelected(selected);
+
groupSelectedItems();
ClipItem *clip = static_cast <ClipItem *>(m_dragItem);
+ updateClipTypeActions(dragGroup == NULL ? clip : NULL);
m_changeSpeedAction->setEnabled(clip->clipType() == AV || clip->clipType() == VIDEO);
m_pasteEffectsAction->setEnabled(m_copiedItems.count() == 1);
}
m_changeSpeedAction->setEnabled(false);
m_pasteEffectsAction->setEnabled(m_copiedItems.count() == 1);
m_ungroupAction->setEnabled(true);
+ updateClipTypeActions(NULL);
m_timelineContextClipMenu->popup(pos);
} else {
m_ungroupAction->setEnabled(false);
if (clip->type() == AVWIDGET) {
ClipItem *item = static_cast <ClipItem*>(clip);
+ updateClipTypeActions(item);
m_changeSpeedAction->setEnabled(item->clipType() == AV || item->clipType() == VIDEO);
m_pasteEffectsAction->setEnabled(m_copiedItems.count() == 1);
m_timelineContextClipMenu->popup(pos);
void CustomTrackView::slotChangeEffectPosition(ClipItem *clip, int currentPos, int newPos)
{
- MoveEffectCommand *command = new MoveEffectCommand(this, m_document->tracksCount() - clip->track(), clip->startPos(), currentPos, newPos, true);
+ MoveEffectCommand *command = new MoveEffectCommand(this, m_document->tracksCount() - clip->track(), clip->startPos(), currentPos, newPos);
m_commandStack->push(command);
m_document->setModified(true);
}
for (int i = 0; i < items.count(); i++) {
ClipItem *item = static_cast <ClipItem *>(items.at(i));
if (!hasVideoClip && (item->clipType() == AV || item->clipType() == VIDEO)) hasVideoClip = true;
+ if (items.count() == 1) {
+ updateClipTypeActions(item);
+ } else {
+ updateClipTypeActions(NULL);
+ }
AddTimelineClipCommand *command = new AddTimelineClipCommand(this, item->xml(), item->clipProducer(), item->info(), item->effectList(), false, false);
m_commandStack->push(command);
item->baseClip()->addReference();
m_document->renderer()->mltInsertClip(info, item->xml(), item->baseClip()->producer(item->track()));
item->setSelected(true);
}
+ m_document->setModified(true);
m_changeSpeedAction->setEnabled(hasVideoClip);
m_pasteEffectsAction->setEnabled(m_copiedItems.count() == 1);
groupSelectedItems(true);
void CustomTrackView::slotSwitchTrackLock(int ix)
{
int tracknumber = m_document->tracksCount() - ix - 1;
- LockTrackCommand *command = new LockTrackCommand(this, ix, !m_document->trackInfoAt(tracknumber).isLocked, true);
+ LockTrackCommand *command = new LockTrackCommand(this, ix, !m_document->trackInfoAt(tracknumber).isLocked);
m_commandStack->push(command);
}
count++;
if (item->parentItem()) {
// Clip is in a group, destroy the group
- new GroupClipsCommand(this, QList<ItemInfo>() << item->info(), QList<ItemInfo>(), false, true, deleteCommand);
+ new GroupClipsCommand(this, QList<ItemInfo>() << item->info(), QList<ItemInfo>(), false, deleteCommand);
}
new AddTimelineClipCommand(this, item->xml(), item->clipProducer(), item->info(), item->effectList(), true, true, deleteCommand);
}
m_commandStack->push(moveCommand);
} else {
// undo last move and emit error message
- MoveClipCommand *command = new MoveClipCommand(this, info, m_dragItemInfo, true);
- m_commandStack->push(command);
+ bool snap = KdenliveSettings::snaptopoints();
+ KdenliveSettings::setSnaptopoints(false);
+ item->setPos((int) m_dragItemInfo.startPos.frames(m_document->fps()), (int)(m_dragItemInfo.track * m_tracksHeight + 1));
+ KdenliveSettings::setSnaptopoints(snap);
emit displayMessage(i18n("Cannot move clip to position %1", m_document->timecode().getTimecodeFromFrames(m_dragItemInfo.startPos.frames(m_document->fps()))), ErrorMessage);
}
m_document->setModified(true);
scene()->removeItem(item);
if (m_dragItem == item) m_dragItem = NULL;
delete item;
+ m_document->setModified(true);
m_document->renderer()->doRefresh();
}
}
}
if (clipInfos.count() > 0) {
- new GroupClipsCommand(this, clipInfos, transitionInfos, false, true, deleteSelected);
+ new GroupClipsCommand(this, clipInfos, transitionInfos, false, deleteSelected);
}
}
}
ClipItem *item = static_cast <ClipItem *>(itemList.at(i));
if (item->parentItem()) resetGroup = true;
new AddTimelineClipCommand(this, item->xml(), item->clipProducer(), item->info(), item->effectList(), true, true, deleteSelected);
+ emit clipItemSelected(NULL);
} else if (itemList.at(i)->type() == TRANSITIONWIDGET) {
Transition *item = static_cast <Transition *>(itemList.at(i));
if (item->parentItem()) resetGroup = true;
info.endPos = item->endPos();
info.track = item->track();
new AddTransitionCommand(this, info, item->transitionEndTrack(), item->toXML(), true, true, deleteSelected);
+ emit transitionItemSelected(NULL);
}
}
+
m_commandStack->push(deleteSelected);
}
double speed = (double) percent / 100.0;
if (item->speed() != speed && (item->clipType() == VIDEO || item->clipType() == AV)) {
count++;
- new ChangeSpeedCommand(this, info, item->speed(), speed, item->clipProducer(), true, changeSelected);
+ new ChangeSpeedCommand(this, info, item->speed(), speed, item->clipProducer(), changeSelected);
}
}
}
if (item->parentItem() && item->parentItem() != m_selectionGroup) {
emit displayMessage(i18n("Cannot cut a clip in a group"), ErrorMessage);
} else if (currentPos > item->startPos() && currentPos < item->endPos()) {
- RazorClipCommand *command = new RazorClipCommand(this, item->info(), currentPos, true);
+ RazorClipCommand *command = new RazorClipCommand(this, item->info(), currentPos);
m_commandStack->push(command);
}
}
}
}
if (clipInfos.count() > 0) {
- GroupClipsCommand *command = new GroupClipsCommand(this, clipInfos, transitionInfos, group, true);
+ GroupClipsCommand *command = new GroupClipsCommand(this, clipInfos, transitionInfos, group);
m_commandStack->push(command);
}
}
}
ClipItem *item = new ClipItem(baseclip, info, m_document->fps(), xml.attribute("speed", "1").toDouble());
item->setEffectList(effects);
+ if (xml.hasAttribute("audio_only")) item->setAudioOnly(true);
+ else if (xml.hasAttribute("video_only")) item->setVideoOnly(true);
scene()->addItem(item);
int tracknumber = m_document->tracksCount() - info.track - 1;
if (list.at(i)->type() == AVWIDGET) {
clip = static_cast <ClipItem *>(list.at(i));
if (clip->clipProducer() == clipId) {
- clip->refreshClip();
+ clip->refreshClip(true);
ItemInfo info = clip->info();
info.track = m_document->tracksCount() - clip->track();
m_document->renderer()->mltUpdateClip(info, clip->xml(), clip->baseClip()->producer());
void CustomTrackView::slotAddClipMarker(const QString &id, GenTime t, QString c)
{
QString oldcomment = m_document->clipManager()->getClipById(id)->markerComment(t);
- AddMarkerCommand *command = new AddMarkerCommand(this, oldcomment, c, id, t, true);
+ AddMarkerCommand *command = new AddMarkerCommand(this, oldcomment, c, id, t);
m_commandStack->push(command);
}
void CustomTrackView::slotDeleteClipMarker(const QString &comment, const QString &id, const GenTime &position)
{
- AddMarkerCommand *command = new AddMarkerCommand(this, comment, QString(), id, position, true);
+ AddMarkerCommand *command = new AddMarkerCommand(this, comment, QString(), id, position);
m_commandStack->push(command);
}
deleteMarkers->setText("Delete clip markers");
for (int i = 0; i < markers.size(); i++) {
- new AddMarkerCommand(this, markers.at(i).comment(), QString(), id, markers.at(i).time(), true, deleteMarkers);
+ new AddMarkerCommand(this, markers.at(i).comment(), QString(), id, markers.at(i).time(), deleteMarkers);
}
m_commandStack->push(deleteMarkers);
}
bool found = false;
for (int i = 0; i < m_guides.count(); i++) {
if (m_guides.at(i)->position() == oldPos) {
- Guide *item = m_guides.takeAt(i);
- delete item;
+ delete m_guides.takeAt(i);
found = true;
break;
}
m_scene->setScale(scaleFactor);
//scale(scaleFactor, 1);
m_animationTimer->stop();
- if (m_visualTip) {
- delete m_visualTip;
- m_visualTip = NULL;
- }
- if (m_animation) {
- delete m_animation;
- m_animation = NULL;
- }
+ delete m_visualTip;
+ m_visualTip = NULL;
+ delete m_animation;
+ m_animation = NULL;
//setSceneRect(0, 0, m_projectDuration + 100 * scaleFactor, sceneRect().height());
setMatrix(matrix);
void CustomTrackView::copyClip()
{
- while (m_copiedItems.count() > 0) {
- delete m_copiedItems.takeFirst();
- }
+ qDeleteAll(m_copiedItems);
+ m_copiedItems.clear();
QList<QGraphicsItem *> itemList = scene()->selectedItems();
if (itemList.count() == 0) {
emit displayMessage(i18n("Select a clip before copying"), ErrorMessage);
}
}
}
- item->refreshClip();
+ item->refreshClip(false);
qApp->processEvents();
}
}
info.isBlind = true;
info.isLocked = false;
}
- AddTrackCommand *addTrack = new AddTrackCommand(this, ix, info, true, true);
+ AddTrackCommand *addTrack = new AddTrackCommand(this, ix, info, true);
m_commandStack->push(addTrack);
m_document->setModified(true);
}
TrackInfo info = m_document->trackInfoAt(m_document->tracksCount() - ix - 1);
deleteTimelineTrack(ix, info);
m_document->setModified(true);
- /*AddTrackCommand* command = new AddTrackCommand(this, ix, info, false, true);
+ /*AddTrackCommand* command = new AddTrackCommand(this, ix, info, false);
m_commandStack->push(command);*/
}
}
}
}
- new AddTrackCommand(this, ix, trackinfo, false, true, deleteTrack);
+ new AddTrackCommand(this, ix, trackinfo, false, deleteTrack);
m_commandStack->push(deleteTrack);
}
void CustomTrackView::changeTimelineTrack(int ix, TrackInfo trackinfo)
{
TrackInfo oldinfo = m_document->trackInfoAt(m_document->tracksCount() - ix - 1);
- ChangeTrackCommand *changeTrack = new ChangeTrackCommand(this, ix, oldinfo, trackinfo, true);
+ ChangeTrackCommand *changeTrack = new ChangeTrackCommand(this, ix, oldinfo, trackinfo);
m_commandStack->push(changeTrack);
}
if (clip->parentItem()) {
emit displayMessage(i18n("Cannot split audio of grouped clips"), ErrorMessage);
} else {
- new SplitAudioCommand(this, clip->track(), clip->startPos(), true, splitCommand);
+ new SplitAudioCommand(this, clip->track(), clip->startPos(), splitCommand);
}
}
}
}
}
-void CustomTrackView::videoOnly()
+void CustomTrackView::setVideoOnly()
{
resetSelectionGroup();
QList<QGraphicsItem *> selection = scene()->selectedItems();
if (clip->parentItem()) {
emit displayMessage(i18n("Cannot change grouped clips"), ErrorMessage);
} else {
- new ChangeClipTypeCommand(this, clip->track(), clip->startPos(), true, false, clip->isVideoOnly(), clip->isAudioOnly(), true, videoCommand);
+ new ChangeClipTypeCommand(this, clip->track(), clip->startPos(), true, false, clip->isVideoOnly(), clip->isAudioOnly(), videoCommand);
}
}
}
m_commandStack->push(videoCommand);
}
-void CustomTrackView::audioOnly()
+void CustomTrackView::setAudioOnly()
{
resetSelectionGroup();
QList<QGraphicsItem *> selection = scene()->selectedItems();
if (clip->parentItem()) {
emit displayMessage(i18n("Cannot change grouped clips"), ErrorMessage);
} else {
- new ChangeClipTypeCommand(this, clip->track(), clip->startPos(), false, true, clip->isVideoOnly(), clip->isAudioOnly(), true, videoCommand);
+ new ChangeClipTypeCommand(this, clip->track(), clip->startPos(), false, true, clip->isVideoOnly(), clip->isAudioOnly(), videoCommand);
+ }
+ }
+ }
+ }
+ m_commandStack->push(videoCommand);
+}
+
+void CustomTrackView::setAudioAndVideo()
+{
+ resetSelectionGroup();
+ QList<QGraphicsItem *> selection = scene()->selectedItems();
+ if (selection.isEmpty()) {
+ emit displayMessage(i18n("You must select one clip for this action"), ErrorMessage);
+ return;
+ }
+ QUndoCommand *videoCommand = new QUndoCommand();
+ videoCommand->setText(i18n("Audio and Video"));
+ for (int i = 0; i < selection.count(); i++) {
+ if (selection.at(i)->type() == AVWIDGET) {
+ ClipItem *clip = static_cast <ClipItem *>(selection.at(i));
+ if (clip->clipType() == AV || clip->clipType() == PLAYLIST) {
+ if (clip->parentItem()) {
+ emit displayMessage(i18n("Cannot change grouped clips"), ErrorMessage);
+ } else {
+ new ChangeClipTypeCommand(this, clip->track(), clip->startPos(), false, false, clip->isVideoOnly(), clip->isAudioOnly(), videoCommand);
}
}
}
clip->update();
}
+void CustomTrackView::updateClipTypeActions(ClipItem *clip)
+{
+ if (clip == NULL || (clip->clipType() != AV && clip->clipType() != PLAYLIST)) {
+ m_clipTypeGroup->setEnabled(false);
+ } else {
+ m_clipTypeGroup->setEnabled(true);
+ QList <QAction *> actions = m_clipTypeGroup->actions();
+ QString lookup;
+ if (clip->isAudioOnly()) lookup = "clip_audio_only";
+ else if (clip->isVideoOnly()) lookup = "clip_video_only";
+ else lookup = "clip_audio_and_video";
+ for (int i = 0; i < actions.count(); i++) {
+ if (actions.at(i)->data().toString() == lookup) {
+ actions.at(i)->setChecked(true);
+ break;
+ }
+ }
+ }
+}
+
+
#include "customtrackview.moc"