Commit c870c085 authored by Jean-Baptiste Mardelle's avatar Jean-Baptiste Mardelle

Merge branch '2004'

parents 83db3b00 5625be72
......@@ -615,6 +615,11 @@ void Core::pushUndo(QUndoCommand *command)
undoStack()->push(command);
}
int Core::undoIndex() const
{
return m_projectManager->undoStack()->index();
}
void Core::displayMessage(const QString &message, MessageType type, int timeout)
{
if (m_mainWindow) {
......
......@@ -217,6 +217,8 @@ public:
std::unique_ptr<Mlt::Producer> getMasterProducerInstance();
/** @brief Returns a copy of a track's playlist */
std::unique_ptr<Mlt::Producer> getTrackProducerInstance(int tid);
/** @brief Returns the undo stack index (position). */
int undoIndex() const;
private:
explicit Core();
......
......@@ -381,6 +381,7 @@ Monitor::Monitor(Kdenlive::MonitorId id, MonitorManager *manager, QWidget *paren
// TODO: reimplement
// connect(render, &Render::durationChanged, this, &Monitor::durationChanged);
connect(m_glMonitor->getControllerProxy(), &MonitorProxy::saveZone, this, &Monitor::updateTimelineClipZone);
connect(m_glMonitor->getControllerProxy(), &MonitorProxy::saveZoneWithUndo, this, &Monitor::zoneUpdatedWithUndo);
} else {
connect(m_glMonitor->getControllerProxy(), &MonitorProxy::saveZone, this, &Monitor::updateClipZone);
}
......
......@@ -335,6 +335,7 @@ signals:
void durationChanged(int);
void refreshClipThumbnail(const QString &);
void zoneUpdated(const QPoint &);
void zoneUpdatedWithUndo(const QPoint &, const QPoint &);
void timelineZoneChanged();
/** @brief Editing transitions / effects over the monitor requires the renderer to send frames as QImage.
* This causes a major slowdown, so we only enable it if required */
......
......@@ -150,6 +150,16 @@ void MonitorProxy::setZoneOut(int pos)
emit saveZone();
}
void MonitorProxy::startZoneMove()
{
m_undoZone = QPoint(m_zoneIn, m_zoneOut);
}
void MonitorProxy::endZoneMove()
{
emit saveZoneWithUndo(m_undoZone, QPoint(m_zoneIn, m_zoneOut));
}
void MonitorProxy::setZone(int in, int out, bool sendUpdate)
{
if (m_zoneIn > 0) {
......
......@@ -84,6 +84,8 @@ public:
QPoint zone() const;
QImage extractFrame(int frame_position, const QString &path = QString(), int width = -1, int height = -1, bool useSourceProfile = false);
Q_INVOKABLE QString toTimecode(int frames) const;
Q_INVOKABLE void startZoneMove();
Q_INVOKABLE void endZoneMove();
Q_INVOKABLE double fps() const;
QPoint profile();
void setClipProperties(ClipType::ProducerType type, bool hasAV, const QString clipName);
......@@ -95,6 +97,7 @@ signals:
void requestSeek(int pos);
void zoneChanged();
void saveZone();
void saveZoneWithUndo(const QPoint, const QPoint&);
void markerCommentChanged();
void rulerHeightChanged();
void addSnap(int);
......@@ -122,6 +125,7 @@ private:
QString m_clipName;
int m_clipType;
bool m_seekFinished;
QPoint m_undoZone;
};
#endif
......@@ -165,6 +165,12 @@ Rectangle {
drag.smoothed: false
drag.minimumX: 0
drag.maximumX: ruler.width
onPressed: {
controller.startZoneMove()
}
onReleased: {
controller.endZoneMove()
}
onPositionChanged: {
if (mouse.buttons === Qt.LeftButton) {
controller.zoneIn = Math.round(trimIn.x / root.timeScale)
......@@ -192,6 +198,12 @@ Rectangle {
drag.smoothed: false
drag.minimumX: 0
drag.maximumX: ruler.width - trimOut.width
onPressed: {
controller.startZoneMove()
}
onReleased: {
controller.endZoneMove()
}
onPositionChanged: {
if (mouse.buttons === Qt.LeftButton) {
controller.zoneOut = Math.round((trimOut.x + trimOut.width) / root.timeScale)
......
......@@ -886,7 +886,7 @@ bool ProjectManager::updateTimeline(int pos, int scrollPos)
pCore->monitorManager()->projectMonitor()->slotActivateMonitor();
pCore->monitorManager()->projectMonitor()->setProducer(m_mainTimelineModel->producer(), pos);
pCore->monitorManager()->projectMonitor()->adjustRulerSize(m_mainTimelineModel->duration() - 1, m_project->getGuideModel());
pCore->window()->getMainTimeline()->controller()->setZone(m_project->zone());
pCore->window()->getMainTimeline()->controller()->setZone(m_project->zone(), false);
//pCore->window()->getMainTimeline()->controller()->setTargetTracks(m_project->targetTracks());
pCore->window()->getMainTimeline()->controller()->setScrollPos(m_project->getDocumentProperty(QStringLiteral("scrollPos")).toInt());
int activeTrackPosition = m_project->getDocumentProperty(QStringLiteral("activeTrack"), QString::number( - 1)).toInt();
......
......@@ -398,7 +398,6 @@ bool TimelineFunctions::insertZone(const std::shared_ptr<TimelineItemModel> &tim
}
result = result && TimelineFunctions::requestInsertSpace(timeline, QPoint(insertFrame, insertFrame + (zone.y() - zone.x())), undo, redo, affectedTracks);
}
bool clipInserted = false;
if (result) {
if (!trackIds.isEmpty()) {
int newId = -1;
......@@ -409,9 +408,6 @@ bool TimelineFunctions::insertZone(const std::shared_ptr<TimelineItemModel> &tim
binClipId = QString("%1/%2/%3").arg(binId).arg(zone.x()).arg(zone.y() - 1);
}
result = timeline->requestClipInsertion(binClipId, trackIds.first(), insertFrame, newId, true, true, useTargets, undo, redo, affectedTracks);
if (result) {
clipInserted = true;
}
}
}
return result;
......@@ -1636,7 +1632,6 @@ QDomDocument TimelineFunctions::extractClip(const std::shared_ptr<TimelineItemMo
QDomElement bin = destDoc.createElement(QStringLiteral("bin"));
container.appendChild(bin);
bool isAudio = timeline->isAudioTrack(tid);
int masterTrack = timeline->getTrackPosition(tid);
container.setAttribute(QStringLiteral("offset"), pos);
container.setAttribute(QStringLiteral("documentid"), QStringLiteral("000000"));
// Process producers
......
......@@ -148,13 +148,13 @@ Rectangle {
MouseArea {
id: moveMouseArea
anchors.fill: parent
property double startX
hoverEnabled: true
drag.target: zone
drag.axis: Drag.XAxis
drag.smoothed: false
property var startZone
onPressed: {
startX = zone.x
startZone = Qt.point(timeline.zoneIn, timeline.zoneOut)
}
onEntered: {
resizeActive = true
......@@ -163,6 +163,7 @@ Rectangle {
resizeActive = false
}
onReleased: {
timeline.updateZone(startZone, Qt.point(timeline.zoneIn, timeline.zoneOut), true)
resizeActive = false
}
onPositionChanged: {
......@@ -243,6 +244,7 @@ Rectangle {
drag.target: parent
drag.axis: Drag.XAxis
drag.smoothed: false
property var startZone
onEntered: {
resizeActive = true
parent.opacity = 1
......@@ -254,10 +256,12 @@ Rectangle {
onPressed: {
parent.anchors.left = undefined
parent.opacity = 1
startZone = Qt.point(timeline.zoneIn, timeline.zoneOut)
}
onReleased: {
resizeActive = false
parent.anchors.left = zone.left
timeline.updateZone(startZone, Qt.point(timeline.zoneIn, timeline.zoneOut), true)
}
onPositionChanged: {
if (mouse.buttons === Qt.LeftButton) {
......@@ -289,6 +293,7 @@ Rectangle {
drag.target: parent
drag.axis: Drag.XAxis
drag.smoothed: false
property var startZone
onEntered: {
resizeActive = true
parent.opacity = 1
......@@ -300,10 +305,12 @@ Rectangle {
onPressed: {
parent.anchors.right = undefined
parent.opacity = 1
startZone = Qt.point(timeline.zoneIn, timeline.zoneOut)
}
onReleased: {
resizeActive = false
parent.anchors.right = zone.right
timeline.updateZone(startZone, Qt.point(timeline.zoneIn, timeline.zoneOut), true)
}
onPositionChanged: {
if (mouse.buttons === Qt.LeftButton) {
......
......@@ -69,6 +69,7 @@ TimelineController::TimelineController(QObject *parent)
, m_scale(QFontMetrics(QApplication::font()).maxWidth() / 250)
, m_timelinePreview(nullptr)
, m_ready(false)
, m_snapStackIndex(-1)
{
m_disablePreview = pCore->currentDoc()->getAction(QStringLiteral("disable_preview"));
connect(m_disablePreview, &QAction::triggered, this, &TimelineController::disablePreview);
......@@ -102,6 +103,7 @@ void TimelineController::setModel(std::shared_ptr<TimelineItemModel> model)
m_zone = QPoint(-1, -1);
m_timelinePreview = nullptr;
m_model = std::move(model);
m_activeSnaps.clear();
connect(m_model.get(), &TimelineItemModel::requestClearAssetView, pCore.get(), &Core::clearAssetPanel);
connect(m_model.get(), &TimelineItemModel::checkItemDeletion, [this] (int id) {
if (m_ready) {
......@@ -680,10 +682,14 @@ void TimelineController::showConfig(int page, int tab)
void TimelineController::gotoNextSnap()
{
std::vector<size_t> snaps = pCore->projectManager()->current()->getGuideModel()->getSnapPoints();
snaps.push_back(m_zone.x());
snaps.push_back(m_zone.y() - 1);
int nextSnap = m_model->getNextSnapPos(pCore->getTimelinePosition(), snaps);
if (m_activeSnaps.empty() || pCore->undoIndex() != m_snapStackIndex) {
m_snapStackIndex = pCore->undoIndex();
m_activeSnaps.clear();
m_activeSnaps = pCore->projectManager()->current()->getGuideModel()->getSnapPoints();
m_activeSnaps.push_back(m_zone.x());
m_activeSnaps.push_back(m_zone.y() - 1);
}
int nextSnap = m_model->getNextSnapPos(pCore->getTimelinePosition(), m_activeSnaps);
if (nextSnap > pCore->getTimelinePosition()) {
setPosition(nextSnap);
}
......@@ -692,10 +698,14 @@ void TimelineController::gotoNextSnap()
void TimelineController::gotoPreviousSnap()
{
if (pCore->getTimelinePosition() > 0) {
std::vector<size_t> snaps = pCore->projectManager()->current()->getGuideModel()->getSnapPoints();
snaps.push_back(m_zone.x());
snaps.push_back(m_zone.y() - 1);
setPosition(m_model->getPreviousSnapPos(pCore->getTimelinePosition(), snaps));
if (m_activeSnaps.empty() || pCore->undoIndex() != m_snapStackIndex) {
m_snapStackIndex = pCore->undoIndex();
m_activeSnaps.clear();
m_activeSnaps = pCore->projectManager()->current()->getGuideModel()->getSnapPoints();
m_activeSnaps.push_back(m_zone.x());
m_activeSnaps.push_back(m_zone.y() - 1);
}
setPosition(m_model->getPreviousSnapPos(pCore->getTimelinePosition(), m_activeSnaps));
}
}
......@@ -1111,7 +1121,7 @@ void TimelineController::setActiveTrack(int track)
emit activeTrackChanged();
}
void TimelineController::setZone(const QPoint &zone)
void TimelineController::setZone(const QPoint &zone, bool withUndo)
{
if (m_zone.x() > 0) {
m_model->removeSnap(m_zone.x());
......@@ -1125,8 +1135,33 @@ void TimelineController::setZone(const QPoint &zone)
if (zone.y() > 0) {
m_model->addSnap(zone.y() - 1);
}
m_zone = zone;
emit zoneChanged();
updateZone(m_zone, zone, withUndo);
}
void TimelineController::updateZone(const QPoint oldZone, const QPoint newZone, bool withUndo)
{
if (!withUndo) {
m_zone = newZone;
emit zoneChanged();
return;
}
std::function<bool(void)> undo = []() { return true; };
std::function<bool(void)> redo = []() { return true; };
Fun undo_zone = [this, oldZone]() {
m_zone = oldZone;
emit zoneChanged();
emit zoneMoved(oldZone);
return true;
};
Fun redo_zone = [this, newZone]() {
m_zone = newZone;
emit zoneChanged();
emit zoneMoved(newZone);
return true;
};
redo_zone();
UPDATE_UNDO_REDO_NOLOCK(redo_zone, undo_zone, undo, redo);
pCore->pushUndo(undo, redo, i18n("Set Zone In"));
}
void TimelineController::setZoneIn(int inPoint)
......@@ -1138,6 +1173,7 @@ void TimelineController::setZoneIn(int inPoint)
m_model->addSnap(inPoint);
}
m_zone.setX(inPoint);
emit zoneChanged();
emit zoneMoved(m_zone);
}
......@@ -1150,6 +1186,7 @@ void TimelineController::setZoneOut(int outPoint)
m_model->addSnap(outPoint - 1);
}
m_zone.setY(outPoint);
emit zoneChanged();
emit zoneMoved(m_zone);
}
......
......@@ -169,11 +169,11 @@ public:
/* @brief Request a seek operation
@param position is the desired new timeline position
*/
Q_INVOKABLE int zoneIn() const { return m_zone.x(); }
Q_INVOKABLE int zoneOut() const { return m_zone.y(); }
Q_INVOKABLE void setZoneIn(int inPoint);
Q_INVOKABLE void setZoneOut(int outPoint);
void setZone(const QPoint &zone);
int zoneIn() const { return m_zone.x(); }
int zoneOut() const { return m_zone.y(); }
void setZoneIn(int inPoint);
void setZoneOut(int outPoint);
void setZone(const QPoint &zone, bool withUndo = true);
/* @brief Request a seek operation
@param position is the desired new timeline position
*/
......@@ -546,6 +546,8 @@ public slots:
void saveTimelineSelection(const QDir &targetDir);
/** @brief Restore timeline scroll pos on open. */
void setScrollPos(int pos);
/** @brief change zone info with undo. */
Q_INVOKABLE void updateZone(const QPoint oldZone, const QPoint newZone, bool withUndo = true);
private slots:
void updateClipActions();
......@@ -581,6 +583,8 @@ private:
std::shared_ptr<AudioCorrelation> m_audioCorrelator;
QMutex m_metaMutex;
bool m_ready;
std::vector<size_t> m_activeSnaps;
int m_snapStackIndex;
void initializePreview();
bool darkBackground() const;
......
......@@ -53,6 +53,7 @@ TimelineTabs::TimelineTabs(QWidget *parent)
tabBar()->tabButton(0, QTabBar::RightSide)->resize(0, 0);
}
connect(pCore->monitorManager()->projectMonitor(), &Monitor::zoneUpdated, m_mainTimeline, &TimelineWidget::zoneUpdated);
connect(pCore->monitorManager()->projectMonitor(), &Monitor::zoneUpdatedWithUndo, m_mainTimeline, &TimelineWidget::zoneUpdatedWithUndo);
connect(m_mainTimeline, &TimelineWidget::zoneMoved, pCore->monitorManager()->projectMonitor(), &Monitor::slotLoadClipZone);
connect(pCore->monitorManager()->projectMonitor(), &Monitor::addEffect, m_mainTimeline->controller(), &TimelineController::addEffectToCurrentClip);
}
......
......@@ -341,7 +341,12 @@ std::shared_ptr<TimelineItemModel> TimelineWidget::model()
void TimelineWidget::zoneUpdated(const QPoint &zone)
{
m_proxy->setZone(zone);
m_proxy->setZone(zone, false);
}
void TimelineWidget::zoneUpdatedWithUndo(const QPoint &oldZone, const QPoint &newZone)
{
m_proxy->updateZone(oldZone, newZone);
}
void TimelineWidget::setTool(ProjectTool tool)
......
......@@ -63,6 +63,7 @@ public slots:
void slotChangeZoom(int value, bool zoomOnMouse);
void slotFitZoom();
void zoneUpdated(const QPoint &zone);
void zoneUpdatedWithUndo(const QPoint &oldZone, const QPoint &newZone);
/* @brief Favorite effects have changed, reload model for context menu */
void updateEffectFavorites();
/* @brief Favorite transitions have changed, reload model for context menu */
......
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