Fix remaining marker issues.

Related to #193
parent 407e2e09
Pipeline #3723 passed with stage
in 14 minutes and 39 seconds
......@@ -35,7 +35,7 @@ void ClipSnapModel::addPoint(int position)
return;
}
if (auto ptr = m_registeredSnap.lock()) {
ptr->addPoint(m_speed < 0 ? m_outPoint + m_position + position / m_speed - m_inPoint : m_position + position / m_speed - m_inPoint);
ptr->addPoint(m_speed < 0 ? ceil(m_outPoint + m_position + position / m_speed - m_inPoint) : ceil(m_position + position / m_speed - m_inPoint));
}
}
......@@ -46,7 +46,7 @@ void ClipSnapModel::removePoint(int position)
return;
}
if (auto ptr = m_registeredSnap.lock()) {
ptr->removePoint(m_speed < 0 ? m_outPoint + m_position + position / m_speed - m_inPoint : m_position + position / m_speed - m_inPoint);
ptr->removePoint(m_speed < 0 ? ceil(m_outPoint + m_position + position / m_speed - m_inPoint) : ceil(m_position + position / m_speed - m_inPoint));
}
}
......@@ -73,7 +73,7 @@ void ClipSnapModel::addAllSnaps()
if (auto ptr = m_registeredSnap.lock()) {
for (const auto &snap : m_snapPoints) {
if (snap >= m_inPoint * m_speed && snap < m_outPoint * m_speed) {
ptr->addPoint(m_speed < 0 ? m_outPoint + m_position + snap / m_speed - m_inPoint : m_position + snap / m_speed - m_inPoint);
ptr->addPoint(m_speed < 0 ? ceil(m_outPoint + m_position + snap / m_speed - m_inPoint) : ceil(m_position + snap / m_speed - m_inPoint));
}
}
}
......@@ -84,7 +84,7 @@ void ClipSnapModel::removeAllSnaps()
if (auto ptr = m_registeredSnap.lock()) {
for (const auto &snap : m_snapPoints) {
if (snap >= m_inPoint * m_speed && snap < m_outPoint * m_speed) {
ptr->removePoint(m_speed < 0 ? m_outPoint + m_position + snap / m_speed - m_inPoint : m_position + snap / m_speed - m_inPoint);
ptr->removePoint(m_speed < 0 ? ceil(m_outPoint + m_position + snap / m_speed - m_inPoint) : ceil(m_position + snap / m_speed - m_inPoint));
}
}
}
......
......@@ -410,7 +410,7 @@ Rectangle {
id: markerBase
width: 1
height: parent.height
x: clipRoot.speed < 0 ? clipRoot.clipDuration * timeScale + (model.frame / clipRoot.speed - (clipRoot.maxDuration - clipRoot.outPoint)) * timeScale : (model.frame / clipRoot.speed - clipRoot.inPoint) * timeScale;
x: clipRoot.speed < 0 ? clipRoot.clipDuration * timeScale + (Math.round(model.frame / clipRoot.speed) - (clipRoot.maxDuration - clipRoot.outPoint)) * timeScale : (Math.round(model.frame / clipRoot.speed) - clipRoot.inPoint) * timeScale;
color: model.color
}
Rectangle {
......@@ -430,7 +430,7 @@ Rectangle {
acceptedButtons: Qt.LeftButton
cursorShape: Qt.PointingHandCursor
hoverEnabled: true
onDoubleClicked: timeline.editMarker(clipRoot.clipId, clipRoot.modelStart + model.frame - clipRoot.inPoint)
onDoubleClicked: timeline.editMarker(clipRoot.clipId, model.frame)
onClicked: timeline.position = (clipRoot.x + markerBase.x) / timeline.scaleFactor
}
}
......
......@@ -70,19 +70,19 @@ Menu {
title: i18n('Markers')
MenuItem {
text: i18n('Add Marker')
onTriggered: timeline.addMarker(clipId, timeline.position)
onTriggered: timeline.addMarker(clipId)
}
MenuItem {
text: i18n('Add Marker/Guide quickly')
onTriggered: timeline.addQuickMarker(clipId, timeline.position)
onTriggered: timeline.addQuickMarker(clipId)
}
MenuItem {
text: i18n('Edit Marker')
onTriggered: timeline.editMarker(clipId, timeline.position)
onTriggered: timeline.editMarker(clipId)
}
MenuItem {
text: i18n('Delete Marker')
onTriggered: timeline.deleteMarker(clipId, timeline.position)
onTriggered: timeline.deleteMarker(clipId)
}
MenuItem {
text: i18n('Delete All Markers')
......
......@@ -660,45 +660,58 @@ void TimelineController::setOutPoint()
void TimelineController::editMarker(int cid, int position)
{
Q_ASSERT(m_model->isClip(cid));
double speed = m_model->getClipSpeed(cid);
if (position == -1) {
position = timelinePosition();
// Calculate marker position relative to timeline cursor
position = timelinePosition() - m_model->getClipPosition(cid) + m_model->getClipIn(cid);
position = position * speed;
}
if (position < m_model->getClipPosition(cid) || position > (m_model->getClipPosition(cid) + m_model->getClipPlaytime(cid))) {
if (position < (m_model->getClipIn(cid) * speed) || position > (m_model->getClipIn(cid) * speed + m_model->getClipPlaytime(cid))) {
pCore->displayMessage(i18n("Cannot find clip to edit marker"), InformationMessage, 500);
return;
}
std::shared_ptr<ProjectClip> clip = pCore->bin()->getBinClip(getClipBinId(cid));
GenTime pos((position - m_model->getClipPosition(cid) + m_model->getClipIn(cid)) * m_model->getClipSpeed(cid), pCore->getCurrentFps());
clip->getMarkerModel()->editMarkerGui(pos, qApp->activeWindow(), false, clip.get());
if (clip->getMarkerModel()->hasMarker(position)) {
GenTime pos(position, pCore->getCurrentFps());
clip->getMarkerModel()->editMarkerGui(pos, qApp->activeWindow(), false, clip.get());
} else {
pCore->displayMessage(i18n("Cannot find clip to edit marker"), InformationMessage, 500);
}
}
void TimelineController::addMarker(int cid, int position)
{
Q_ASSERT(m_model->isClip(cid));
double speed = m_model->getClipSpeed(cid);
if (position == -1) {
position = timelinePosition();
// Calculate marker position relative to timeline cursor
position = timelinePosition() - m_model->getClipPosition(cid) + m_model->getClipIn(cid);
position = position * speed;
}
if (position < m_model->getClipPosition(cid) || position > (m_model->getClipPosition(cid) + m_model->getClipPlaytime(cid))) {
pCore->displayMessage(i18n("Cannot find clip to add marker"), InformationMessage, 500);
if (position < (m_model->getClipIn(cid) * speed) || position > (m_model->getClipIn(cid) * speed + m_model->getClipPlaytime(cid))) {
pCore->displayMessage(i18n("Cannot find clip to edit marker"), InformationMessage, 500);
return;
}
std::shared_ptr<ProjectClip> clip = pCore->bin()->getBinClip(getClipBinId(cid));
GenTime pos((position - m_model->getClipPosition(cid) + m_model->getClipIn(cid)) * m_model->getClipSpeed(cid), pCore->getCurrentFps());
GenTime pos(position, pCore->getCurrentFps());
clip->getMarkerModel()->editMarkerGui(pos, qApp->activeWindow(), true, clip.get());
}
void TimelineController::addQuickMarker(int cid, int position)
{
Q_ASSERT(m_model->isClip(cid));
double speed = m_model->getClipSpeed(cid);
if (position == -1) {
position = timelinePosition();
// Calculate marker position relative to timeline cursor
position = timelinePosition() - m_model->getClipPosition(cid) + m_model->getClipIn(cid);
position = position * speed;
}
if (position < m_model->getClipPosition(cid) || position > (m_model->getClipPosition(cid) + m_model->getClipPlaytime(cid))) {
pCore->displayMessage(i18n("Cannot find clip to add marker"), InformationMessage, 500);
if (position < (m_model->getClipIn(cid) * speed) || position > (m_model->getClipIn(cid) * speed + m_model->getClipPlaytime(cid))) {
pCore->displayMessage(i18n("Cannot find clip to edit marker"), InformationMessage, 500);
return;
}
std::shared_ptr<ProjectClip> clip = pCore->bin()->getBinClip(getClipBinId(cid));
GenTime pos((position - m_model->getClipPosition(cid) + m_model->getClipIn(cid)) * m_model->getClipSpeed(cid), pCore->getCurrentFps());
GenTime pos(position, pCore->getCurrentFps());
CommentedTime marker(pos, pCore->currentDoc()->timecode().getDisplayTimecode(pos, false), KdenliveSettings::default_marker_type());
clip->getMarkerModel()->addMarker(marker.time(), marker.comment(), marker.markerType());
}
......@@ -706,15 +719,18 @@ void TimelineController::addQuickMarker(int cid, int position)
void TimelineController::deleteMarker(int cid, int position)
{
Q_ASSERT(m_model->isClip(cid));
double speed = m_model->getClipSpeed(cid);
if (position == -1) {
position = timelinePosition();
// Calculate marker position relative to timeline cursor
position = timelinePosition() - m_model->getClipPosition(cid) + m_model->getClipIn(cid);
position = position * speed;
}
if (position < m_model->getClipPosition(cid) || position > (m_model->getClipPosition(cid) + m_model->getClipPlaytime(cid))) {
pCore->displayMessage(i18n("Cannot find clip to remove marker"), InformationMessage, 500);
if (position < (m_model->getClipIn(cid) * speed) || position > (m_model->getClipIn(cid) * speed + m_model->getClipPlaytime(cid))) {
pCore->displayMessage(i18n("Cannot find clip to edit marker"), InformationMessage, 500);
return;
}
std::shared_ptr<ProjectClip> clip = pCore->bin()->getBinClip(getClipBinId(cid));
GenTime pos((position - m_model->getClipPosition(cid) + m_model->getClipIn(cid)) * m_model->getClipSpeed(cid), pCore->getCurrentFps());
GenTime pos(position, pCore->getCurrentFps());
clip->getMarkerModel()->removeMarker(pos);
}
......
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