Commit 31a36a4a authored by Jason Wood's avatar Jason Wood

Spacer tool can now move clips, and honours snap to grid settings in the process.

svn path=/trunk/kdenlive/; revision=306
parent 84a16dda
......@@ -616,3 +616,28 @@ QPtrList<DocClipBase> KdenliveDoc::referencedClips(AVFile *file)
return list;
}
bool KdenliveDoc::hasSelectedClips()
{
bool result = false;
if(m_projectClip) {
result = m_projectClip->hasSelectedClips();
} else {
kdError() << "No selection in the project because m_projectClip is null!!" << endl;
}
return result;
}
DocClipBase *KdenliveDoc::selectedClip()
{
DocClipBase *pResult = 0;
if(m_projectClip) {
pResult = m_projectClip->selectedClip();
} else {
kdError() << "No selection in the project because m_projectClip is null!!!" << endl;
}
return pResult;
}
......@@ -101,6 +101,14 @@ class KdenliveDoc : public QObject
/** Returns a list of all clips directly or indirectly accessed by the specified avfile. */
QPtrList<DocClipBase> referencedClips(AVFile *file);
/** Returns true if at least one clip in the project is selected. */
bool hasSelectedClips();
/** Returns a clip that is currently selected. Only one clip is returned!
* This function is intended for times when you need a "master" clip. but have no preferred
* choice. */
DocClipBase *selectedClip();
public slots:
/** calls repaint() on all views connected to the document object and is called by the view
* by which the document has been changed. As this view normally repaints itself, it is
......
......@@ -29,12 +29,12 @@
<Action name="load_layout_2"/>
<Action name="load_layout_3"/>
<Action name="load_layout_4"/>
<Separator lineSeperator="true"/>
<Separator lineSeperator="true"/>
<Action name="save_layout_1"/>
<Action name="save_layout_2"/>
<Action name="save_layout_3"/>
<Action name="save_layout_4"/>
</Menu>
</Menu>
</MenuBar>
<Menu name="projectlist_context">
......
......@@ -54,6 +54,11 @@ public:
snap point before the snap takes effect.
*/
static uint snapTolerance;
/**
Returns a list of times of selected clips, including both start and end times.
*/
QValueList<GenTime> selectedClipTimes();
private: // attributes
/** GUI elements */
QHBox *m_rulerBox; // Horizontal box holding the ruler
......@@ -265,10 +270,6 @@ it does not remove the clips from the timeline. */
*/
void setupSnapToGrid();
/**
Returns a list of times of selected clips, including both start and end times.
*/
QValueList<GenTime> selectedClipTimes();
public slots: // Public slots
/** Called when a track within the project has been added or removed.
* The timeline needs to be updated to show these changes. */
......
......@@ -45,7 +45,7 @@ KMMTrackKeyFramePanel::KMMTrackKeyFramePanel(KMMTimeLine *timeline,
this, SIGNAL(signalClipCropEndChanged(const GenTime &)));
addFunctionDecorator(KdenliveApp::Razor, new TrackPanelRazorFunction(timeline, doc));
addFunctionDecorator(KdenliveApp::Spacer, new TrackPanelSpacerFunction(timeline, doc));
addFunctionDecorator(KdenliveApp::Spacer, new TrackPanelSpacerFunction(timeline, doc, doc->document()));
}
KMMTrackKeyFramePanel::~KMMTrackKeyFramePanel()
......
......@@ -51,7 +51,9 @@ KMMTrackVideoPanel::KMMTrackVideoPanel(KMMTimeLine *timeline,
this, SIGNAL(signalClipCropEndChanged(const GenTime &)));
addFunctionDecorator(KdenliveApp::Razor, new TrackPanelRazorFunction(timeline, docTrack));
addFunctionDecorator(KdenliveApp::Spacer, new TrackPanelSpacerFunction(timeline, docTrack));
addFunctionDecorator(KdenliveApp::Spacer, new TrackPanelSpacerFunction(timeline, docTrack, docTrack->document()));
m_pixmap.load("test.png");
}
KMMTrackVideoPanel::~KMMTrackVideoPanel()
......@@ -76,7 +78,14 @@ void KMMTrackVideoPanel::paintClip(QPainter &painter, DocClipBase *clip, QRect &
QColor col = selected ? QColor(128, 64, 64) : QColor(255, 128, 128);
// draw outline box
painter.fillRect( sx, rect.y(), ex, rect.height(), col);
// for(uint mycount = sx; mycount < sx+ex; mycount += m_pixmap.width())
// {
// painter.drawPixmap(mycount, rect.y(), m_pixmap, 0, 0, -1, rect.height());
// }
painter.drawRect( sx, rect.y(), ex, rect.height());
painter.setClipping(true);
......
......@@ -21,6 +21,7 @@
#include <qwidget.h>
#include <qlabel.h>
#include <qhbox.h>
#include <qpixmap.h>
#include "doctrackvideo.h"
#include "kmmtrackpanel.h"
......@@ -42,6 +43,9 @@ private:
QLabel m_trackLabel;
/** True if we are inside a dragging operation, false otherwise. */
bool m_dragging;
/** Test image to display on track */
QPixmap m_pixmap;
};
#endif
......@@ -124,163 +124,3 @@ bool TrackPanelClipResizeFunction::mouseMoved(QMouseEvent *event)
}
}
}
/**
bool KMMTrackVideoPanel::mousePressed(QMouseEvent *event)
{
GenTime mouseTime(m_timeline->mapLocalToValue(event->x()), m_docTrack->document()->framesPerSecond());
GenTime roundedMouseTime = m_timeline->timeUnderMouse(event->x());
m_clipUnderMouse = 0;
switch(m_timeline->editMode()) {
case KdenliveApp::Move :
m_clipUnderMouse = docTrack()->getClipAt(mouseTime);
if(m_clipUnderMouse) {
if(m_resizeState != None) {
}
if (event->state() & ControlButton) {
m_timeline->toggleSelectClipAt(*m_docTrack, mouseTime);
} else if(event->state() & ShiftButton) {
m_timeline->selectClipAt(*m_docTrack, mouseTime);
}
return true;
} else {
m_timeline->addCommand(m_timeline->selectNone(), true);
}
break;
case KdenliveApp::Razor :
m_clipUnderMouse = docTrack()->getClipAt(mouseTime);
if(m_clipUnderMouse) {
if (event->state() & ShiftButton) {
m_timeline->razorAllClipsAt(roundedMouseTime);
} else {
m_timeline->addCommand(m_timeline->razorClipAt(*m_docTrack, roundedMouseTime), true);
}
return true;
}
break;
case KdenliveApp::Spacer :
if (event->state() & ShiftButton) {
m_timeline->addCommand(m_timeline->selectLaterClips(mouseTime, true), true);
} else {
m_timeline->addCommand(m_timeline->selectLaterClips(mouseTime, false), true);
}
return true;
break;
default :
kdWarning() << "Error, mouse pressed over clips, unknown mode" << endl;
}
return false;
}
bool KMMTrackVideoPanel::mouseReleased(QMouseEvent *event)
{
GenTime mouseTime = m_timeline->timeUnderMouse(event->x());
switch(m_timeline->editMode()) {
case KdenliveApp::Move :
if(m_resizeState != None) {
} else {
if(m_dragging) {
m_dragging = false;
} else {
if(m_clipUnderMouse) {
if (event->state() & ControlButton) {
} else if(event->state() & ShiftButton) {
} else {
m_timeline->addCommand(m_timeline->selectNone(), true);
m_timeline->selectClipAt(*m_docTrack, mouseTime);
}
} else {
m_timeline->addCommand(m_timeline->selectNone(), true);
}
}
}
break;
case KdenliveApp::Razor :
break;
case KdenliveApp::Spacer :
break;
default :
kdWarning() << "Error, mouse released over clips, unknown mode" << endl;
}
m_clipUnderMouse = 0;
return true;
}
QCursor KMMTrackVideoPanel::getMouseCursor(QMouseEvent *event)
{
GenTime mouseTime(m_timeline->mapLocalToValue(event->x()), m_docTrack->document()->framesPerSecond());
DocClipBase *clip;
m_resizeState = None;
switch(m_timeline->editMode()) {
case KdenliveApp::Move :
clip = docTrack()->getClipAt(mouseTime);
if(clip) {
if( fabs(m_timeline->mapValueToLocal(clip->trackStart().frames(m_docTrack->document()->framesPerSecond())) - event->x()) < resizeTolerance) {
m_resizeState = Start;
return QCursor(Qt::SizeHorCursor);
}
if( fabs(m_timeline->mapValueToLocal((clip->trackEnd()).frames(m_docTrack->document()->framesPerSecond())) - event->x()) < resizeTolerance) {
m_resizeState = End;
return QCursor(Qt::SizeHorCursor);
}
}
return QCursor(Qt::ArrowCursor);
case KdenliveApp::Razor :
clip = docTrack()->getClipAt(mouseTime);
if(clip) {
emit lookingAtClip(clip, mouseTime - clip->trackStart() + clip->cropStartTime());
}
return QCursor(Qt::SplitVCursor);
case KdenliveApp::Spacer :
return QCursor(Qt::SizeHorCursor);
default:
return QCursor(Qt::ArrowCursor);
}
}
bool KMMTrackVideoPanel::mouseMoved(QMouseEvent *event)
{
GenTime mouseTime = m_snapToGrid.getSnappedTime(m_timeline->timeUnderMouse(event->x()));
switch(m_timeline->editMode()) {
case KdenliveApp::Move :
if(m_clipUnderMouse) {
if(m_resizeState != None) {
} else {
if(!m_timeline->clipSelected(m_clipUnderMouse)) {
if ((event->state() & ControlButton) || (event->state() & ShiftButton)) {
m_timeline->selectClipAt(*m_docTrack,mouseTime);
} else {
m_timeline->addCommand(m_timeline->selectNone(), true);
m_timeline->selectClipAt(*m_docTrack,mouseTime);
}
}
m_dragging = true;
m_timeline->initiateDrag(m_clipUnderMouse, mouseTime);
}
}
break;
case KdenliveApp::Razor :
break;
case KdenliveApp::Spacer :
break;
default:
kdWarning() << "Error, mouse moved over clips, unknown mode" << endl;
}
return true;
}
*/
......@@ -18,10 +18,18 @@
#include "doctrackbase.h"
#include "kmmtimeline.h"
#include "kdenlivedoc.h"
#include "kmoveclipscommand.h"
TrackPanelSpacerFunction::TrackPanelSpacerFunction(KMMTimeLine *timeline, DocTrackBase *docTrack) :
m_timeline(timeline),
m_docTrack(docTrack)
TrackPanelSpacerFunction::TrackPanelSpacerFunction(KMMTimeLine *timeline,
DocTrackBase *docTrack,
KdenliveDoc *doc) :
m_timeline(timeline),
m_docTrack(docTrack),
m_doc(doc),
m_masterClip(0),
m_moveClipsCommand(0),
m_snapToGrid(doc)
{
}
......@@ -47,19 +55,56 @@ bool TrackPanelSpacerFunction::mousePressed(QMouseEvent *event)
m_clipUnderMouse = 0;
if (event->state() & ShiftButton) {
m_timeline->addCommand(m_timeline->selectLaterClips(mouseTime, true), true);
} else {
m_timeline->addCommand(m_timeline->selectLaterClips(mouseTime, false), true);
} else {
m_timeline->addCommand(m_timeline->selectLaterClips(mouseTime, true), true);
}
if(m_doc->hasSelectedClips()) {
m_masterClip = m_doc->selectedClip();
m_moveClipsCommand = new Command::KMoveClipsCommand(m_timeline, m_doc, m_masterClip);
m_clipOffset = mouseTime - m_masterClip->trackStart();
m_snapToGrid.setSnapToClipStart(m_timeline->snapToBorders());
m_snapToGrid.setSnapToClipEnd(m_timeline->snapToBorders());
m_snapToGrid.setSnapToFrame(m_timeline->snapToFrame());
m_snapToGrid.setSnapToSeekTime(m_timeline->snapToSeekTime());
m_snapToGrid.setSnapTolerance(GenTime(m_timeline->mapLocalToValue(KMMTimeLine::snapTolerance) - m_timeline->mapLocalToValue(0), m_docTrack->document()->framesPerSecond()));
m_snapToGrid.setIncludeSelectedClips(false);
m_snapToGrid.clearSeekTimes();
m_snapToGrid.addSeekTime(m_timeline->seekPosition());
QValueList<GenTime> cursor = m_timeline->selectedClipTimes();
m_snapToGrid.setCursorTimes(cursor);
}
return true;
}
bool TrackPanelSpacerFunction::mouseReleased(QMouseEvent *event)
{
if(m_moveClipsCommand) {
m_moveClipsCommand->setEndLocation(m_masterClip);
m_timeline->addCommand(m_moveClipsCommand, false);
m_moveClipsCommand = 0;
}
return true;
}
bool TrackPanelSpacerFunction::mouseMoved(QMouseEvent *event)
{
GenTime mouseTime = m_timeline->timeUnderMouse(event->x()) - m_clipOffset;
mouseTime = m_snapToGrid.getSnappedTime(mouseTime);
mouseTime = mouseTime + m_clipOffset;
if(m_moveClipsCommand) {
GenTime startOffset = mouseTime - m_clipOffset - m_masterClip->trackStart();
m_doc->moveSelectedClips(startOffset, 0);
m_timeline->drawTrackViewBackBuffer();
}
return true;
}
......@@ -21,9 +21,15 @@
#include "kdenlive.h"
#include "trackpanelfunction.h"
#include "snaptogrid.h"
class QMouseEvent;
class DocTrackBase;
class KdenliveDoc;
namespace Command {
class KMoveClipsCommand;
}
/**
Abstract Base Class for track panel functionality decorators. This and it's
......@@ -35,7 +41,7 @@ class TrackPanelSpacerFunction : public TrackPanelFunction
{
Q_OBJECT
public:
TrackPanelSpacerFunction(KMMTimeLine *timeline, DocTrackBase *docTrack);
TrackPanelSpacerFunction(KMMTimeLine *timeline, DocTrackBase *docTrack, KdenliveDoc *doc);
virtual ~TrackPanelSpacerFunction();
......@@ -69,6 +75,16 @@ private:
KMMTimeLine *m_timeline;
DocTrackBase *m_docTrack;
DocClipBase * m_clipUnderMouse;
KdenliveDoc *m_doc;
DocClipBase *m_masterClip;
Command::KMoveClipsCommand *m_moveClipsCommand;
/**
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;
SnapToGrid m_snapToGrid;
};
#endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment