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

Resize clip/composition with shortcuts

parent 7bcae91d
......@@ -3069,15 +3069,15 @@ void MainWindow::hideEvent(QHideEvent */*event*/)
void MainWindow::slotResizeItemStart()
{
if (pCore->projectManager()->currentTimeline()) {
pCore->projectManager()->currentTimeline()->projectView()->setInPoint();
if (pCore->projectManager()->currentTimelineWidget()) {
pCore->projectManager()->currentTimelineWidget()->setInPoint();
}
}
void MainWindow::slotResizeItemEnd()
{
if (pCore->projectManager()->currentTimeline()) {
pCore->projectManager()->currentTimeline()->projectView()->setOutPoint();
if (pCore->projectManager()->currentTimelineWidget()) {
pCore->projectManager()->currentTimelineWidget()->setOutPoint();
}
}
......
......@@ -1231,3 +1231,38 @@ bool TimelineModel::removeComposition(int compoId, int pos)
field->unlock();
return found;
}
bool TimelineModel::requestItemResizeToPos(int itemId, int position, bool right)
{
QWriteLocker locker(&m_lock);
Q_ASSERT(isClip(itemId) || isComposition(itemId));
int in, out;
if (isClip(itemId)) {
in = getClipPosition(itemId);
out = in + getClipPlaytime(itemId) - 1;
} else {
in = getCompositionPosition(itemId);
out = in + getCompositionPlaytime(itemId) - 1;
}
int size = 0;
if (!right) {
if (position < out) {
size = out - position;
}
} else {
if (position > in) {
size = position - in;
}
}
Fun undo = [](){return true;};
Fun redo = [](){return true;};
bool result = requestItemResize(itemId, size, right, true, undo, redo);
if (result) {
if (isClip(itemId)) {
PUSH_UNDO(undo, redo, i18n("Resize clip"));
} else {
PUSH_UNDO(undo, redo, i18n("Resize composition"));
}
}
return result;
}
......@@ -160,8 +160,8 @@ public:
Q_INVOKABLE bool requestCompositionMove(int compoId, int trackId, int position, bool updateView = true, bool logUndo = true);
Q_INVOKABLE int getCompositionPosition(int compoId) const;
Q_INVOKABLE int getCompositionPlaytime(int compoId) const;
Q_INVOKABLE int suggestCompositionMove(int compoId, int trackId, int position);
int getCompositionPlaytime(int compoId) const;
protected:
/* Same function, but accumulates undo and redo, and doesn't check for group*/
......@@ -232,6 +232,15 @@ public:
@param snap if set to true, the resize order will be coerced to use the snapping grid
*/
Q_INVOKABLE bool requestItemResize(int itemId, int size, bool right, bool logUndo = true, bool snap = false);
/* @brief Change the duration of an item (clip or composition)
This action is undoable
Returns true on success. If it fails, nothing is modified.
@param itemId is the ID of the item
@param position is the requested start or end position
@param resizeStart is true if we want to resize clip start, false to resize clip end
*/
bool requestItemResizeToPos(int itemId, int position, bool right);
/* Same function, but accumulates undo and redo and doesn't deal with snapping*/
bool requestItemResize(int itemId, int size, bool right, bool logUndo, Fun& undo, Fun& redo);
......
......@@ -54,7 +54,6 @@ Rectangle {
property string hash: 'ccc' //TODO
property double speed: 1.0
property color borderColor: 'black'
x: modelStart * timeScale
width : clipDuration * timeScale;
signal clicked(var clip, int shiftClick)
......@@ -70,7 +69,12 @@ Rectangle {
onClipDurationChanged: {
width = clipDuration * timeScale;
}
onModelStartChanged: {
x = modelStart * timeScale;
}
onTimeScaleChanged: {
x = modelStart * timeScale;
width = clipDuration * timeScale;
labelRect.x = scrollX > modelStart * timeScale ? scrollX - modelStart * timeScale : 0
}
......
......@@ -58,8 +58,6 @@ Item {
property double speed: 1.0
property color color: displayRect.color
property color borderColor: 'black'
x: modelStart * timeScale
width : clipDuration * timeScale;
signal clicked(var clip, int shiftClick)
signal moved(var clip)
......@@ -75,10 +73,15 @@ Item {
a_trackPos = root.getTrackYFromId(a_track) - mapToItem(trackRoot, 0, 0).y - trackRoot.mapToItem(null, 0, 0).y + ruler.height
}
onModelStartChanged: {
x = modelStart * timeScale;
}
onClipDurationChanged: {
width = clipDuration * timeScale;
}
onTimeScaleChanged: {
x = modelStart * timeScale;
width = clipDuration * timeScale;
labelRect.x = scrollX > modelStart * timeScale ? scrollX - modelStart * timeScale : 0
}
......
......@@ -353,3 +353,28 @@ void TimelineWidget::unGroupSelection(int cid)
m_model->requestClipUngroup(cid);
}
void TimelineWidget::setInPoint()
{
int cursorPos = rootObject()->property("seekPos").toInt();
if (cursorPos < 0) {
cursorPos = m_position;
}
if (!m_selection.selectedClips.isEmpty()) {
for(int id : m_selection.selectedClips) {
m_model->requestItemResizeToPos(id, cursorPos, false);
}
}
}
void TimelineWidget::setOutPoint()
{
int cursorPos = rootObject()->property("seekPos").toInt();
if (cursorPos < 0) {
cursorPos = m_position;
}
if (!m_selection.selectedClips.isEmpty()) {
for(int id : m_selection.selectedClips) {
m_model->requestItemResizeToPos(id, cursorPos, true);
}
}
}
......@@ -135,11 +135,26 @@ public:
/* @brief Remove a timeline track
*/
Q_INVOKABLE void deleteTrack(int tid);
/* @brief Group selected items in timeline
*/
Q_INVOKABLE void groupSelection();
/* @brief Ungroup selected items in timeline
*/
Q_INVOKABLE void unGroupSelection(int cid);
/* @brief Seek to next snap point
*/
void gotoNextSnap();
/* @brief Seek to previous snap point
*/
void gotoPreviousSnap();
/* @brief Set current item's start point to cursor position
*/
void setInPoint();
/* @brief Set current item's end point to cursor position
*/
void setOutPoint();
protected:
void mousePressEvent(QMouseEvent *event) Q_DECL_OVERRIDE;
void wheelEvent(QWheelEvent *event) Q_DECL_OVERRIDE;
......
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