Fix clip monitor zone, snap to zone

parent 17411d21
...@@ -1898,9 +1898,7 @@ void Bin::selectClip(const std::shared_ptr<ProjectClip> &clip) ...@@ -1898,9 +1898,7 @@ void Bin::selectClip(const std::shared_ptr<ProjectClip> &clip)
if (id.isValid() && id2.isValid()) { if (id.isValid() && id2.isValid()) {
m_proxyModel->selectionModel()->select(QItemSelection(m_proxyModel->mapFromSource(id), m_proxyModel->mapFromSource(id2)), QItemSelectionModel::Select); m_proxyModel->selectionModel()->select(QItemSelection(m_proxyModel->mapFromSource(id), m_proxyModel->mapFromSource(id2)), QItemSelectionModel::Select);
} }
selectProxyModel(m_proxyModel->mapFromSource(ix));
m_itemView->scrollTo(m_proxyModel->mapFromSource(ix)); m_itemView->scrollTo(m_proxyModel->mapFromSource(ix));
emit openClip(clip);
} }
void Bin::slotOpenCurrent() void Bin::slotOpenCurrent()
......
...@@ -1781,6 +1781,8 @@ void GLWidget::setRulerInfo(int duration, std::shared_ptr<MarkerListModel> model ...@@ -1781,6 +1781,8 @@ void GLWidget::setRulerInfo(int duration, std::shared_ptr<MarkerListModel> model
{ {
rootObject()->setProperty("duration", duration); rootObject()->setProperty("duration", duration);
if (model != nullptr) { if (model != nullptr) {
// we are resetting marker/snap model, reset zone
m_proxy->resetZone();
rootContext()->setContextProperty("markersModel", model.get()); rootContext()->setContextProperty("markersModel", model.get());
} }
} }
......
...@@ -350,25 +350,52 @@ public: ...@@ -350,25 +350,52 @@ public:
int zoneOut() const { return m_zoneOut; } int zoneOut() const { return m_zoneOut; }
void setZoneIn(int pos) void setZoneIn(int pos)
{ {
if (m_zoneIn > 0) {
emit removeSnap(m_zoneIn);
}
m_zoneIn = pos; m_zoneIn = pos;
if (pos > 0) {
emit addSnap(pos);
}
emit zoneChanged(); emit zoneChanged();
} }
void setZoneOut(int pos) void setZoneOut(int pos)
{ {
if (m_zoneOut > 0) {
emit removeSnap(m_zoneOut);
}
m_zoneOut = pos; m_zoneOut = pos;
if (pos > 0) {
emit addSnap(pos);
}
emit zoneChanged(); emit zoneChanged();
} }
Q_INVOKABLE void setZone(int in, int out) Q_INVOKABLE void setZone(int in, int out)
{ {
if (m_zoneIn > 0) {
emit removeSnap(m_zoneIn);
}
if (m_zoneOut > 0) {
emit removeSnap(m_zoneOut);
}
m_zoneIn = in; m_zoneIn = in;
m_zoneOut = out; m_zoneOut = out;
if (m_zoneIn > 0) {
emit addSnap(m_zoneIn);
}
if (m_zoneOut > 0) {
emit addSnap(m_zoneOut);
}
emit zoneChanged(); emit zoneChanged();
} }
void setZone(QPoint zone) void setZone(QPoint zone)
{ {
m_zoneIn = zone.x(); setZone(zone.x(), zone.y());
m_zoneOut = zone.y(); }
emit zoneChanged(); void resetZone()
{
m_zoneIn = 0;
m_zoneOut = -1;
} }
QPoint zone() const { return QPoint(m_zoneIn, m_zoneOut); } QPoint zone() const { return QPoint(m_zoneIn, m_zoneOut); }
signals: signals:
...@@ -378,6 +405,8 @@ signals: ...@@ -378,6 +405,8 @@ signals:
void zoneChanged(); void zoneChanged();
void markerCommentChanged(); void markerCommentChanged();
void rulerHeightChanged(); void rulerHeightChanged();
void addSnap(int);
void removeSnap(int);
private: private:
GLWidget *q; GLWidget *q;
......
...@@ -637,10 +637,6 @@ int Monitor::position() ...@@ -637,10 +637,6 @@ int Monitor::position()
GenTime Monitor::getSnapForPos(bool previous) GenTime Monitor::getSnapForPos(bool previous)
{ {
QPoint zone = m_glMonitor->getControllerProxy()->zone();
// TODO: move points with the zone
m_snaps->addPoint(zone.x());
m_snaps->addPoint(zone.y());
int frame = previous ? m_snaps->getPreviousPoint(m_glMonitor->getCurrentPos()) : m_snaps->getNextPoint(m_glMonitor->getCurrentPos()); int frame = previous ? m_snaps->getPreviousPoint(m_glMonitor->getCurrentPos()) : m_snaps->getNextPoint(m_glMonitor->getCurrentPos());
return GenTime(frame, pCore->getCurrentFps()); return GenTime(frame, pCore->getCurrentFps());
} }
...@@ -1219,6 +1215,9 @@ void Monitor::adjustRulerSize(int length, std::shared_ptr<MarkerListModel> marke ...@@ -1219,6 +1215,9 @@ void Monitor::adjustRulerSize(int length, std::shared_ptr<MarkerListModel> marke
connect(markerModel.get(), SIGNAL(dataChanged(const QModelIndex &, const QModelIndex &, const QVector<int> &)), this, SLOT(checkOverlay())); connect(markerModel.get(), SIGNAL(dataChanged(const QModelIndex &, const QModelIndex &, const QVector<int> &)), this, SLOT(checkOverlay()));
connect(markerModel.get(), SIGNAL(rowsInserted(const QModelIndex &, int, int)), this, SLOT(checkOverlay())); connect(markerModel.get(), SIGNAL(rowsInserted(const QModelIndex &, int, int)), this, SLOT(checkOverlay()));
connect(markerModel.get(), SIGNAL(rowsRemoved(const QModelIndex &, int, int)), this, SLOT(checkOverlay())); connect(markerModel.get(), SIGNAL(rowsRemoved(const QModelIndex &, int, int)), this, SLOT(checkOverlay()));
if (m_controller) {
markerModel->registerSnapModel(m_snaps);
}
} }
} }
...@@ -1350,13 +1349,11 @@ void Monitor::slotOpenClip(std::shared_ptr<ProjectClip> controller, int in, int ...@@ -1350,13 +1349,11 @@ void Monitor::slotOpenClip(std::shared_ptr<ProjectClip> controller, int in, int
loadQmlScene(MonitorSceneDefault); loadQmlScene(MonitorSceneDefault);
m_snaps.reset(new SnapModel()); m_snaps.reset(new SnapModel());
if (controller) { if (controller) {
m_controller->getMarkerModel()->registerSnapModel(m_snaps);
connect(m_controller->getMarkerModel().get(), SIGNAL(dataChanged(const QModelIndex &, const QModelIndex &, const QVector<int> &)), this, connect(m_controller->getMarkerModel().get(), SIGNAL(dataChanged(const QModelIndex &, const QModelIndex &, const QVector<int> &)), this,
SLOT(checkOverlay())); SLOT(checkOverlay()));
connect(m_controller->getMarkerModel().get(), SIGNAL(rowsInserted(const QModelIndex &, int, int)), this, SLOT(checkOverlay())); connect(m_controller->getMarkerModel().get(), SIGNAL(rowsInserted(const QModelIndex &, int, int)), this, SLOT(checkOverlay()));
connect(m_controller->getMarkerModel().get(), SIGNAL(rowsRemoved(const QModelIndex &, int, int)), this, SLOT(checkOverlay())); connect(m_controller->getMarkerModel().get(), SIGNAL(rowsRemoved(const QModelIndex &, int, int)), this, SLOT(checkOverlay()));
m_snaps->addPoint(m_controller->frameDuration());
if (m_recManager->toolbar()->isVisible()) { if (m_recManager->toolbar()->isVisible()) {
// we are in record mode, don't display clip // we are in record mode, don't display clip
return; return;
...@@ -1364,7 +1361,10 @@ void Monitor::slotOpenClip(std::shared_ptr<ProjectClip> controller, int in, int ...@@ -1364,7 +1361,10 @@ void Monitor::slotOpenClip(std::shared_ptr<ProjectClip> controller, int in, int
m_glMonitor->setRulerInfo(m_controller->frameDuration(), controller->getMarkerModel()); m_glMonitor->setRulerInfo(m_controller->frameDuration(), controller->getMarkerModel());
m_timePos->setRange(0, m_controller->frameDuration()); m_timePos->setRange(0, m_controller->frameDuration());
updateMarkers(); updateMarkers();
connect(m_glMonitor->getControllerProxy(), &MonitorProxy::addSnap, this, &Monitor::addSnapPoint, Qt::DirectConnection);
connect(m_glMonitor->getControllerProxy(), &MonitorProxy::removeSnap, this, &Monitor::removeSnapPoint, Qt::DirectConnection);
m_glMonitor->getControllerProxy()->setZone(m_controller->zone()); m_glMonitor->getControllerProxy()->setZone(m_controller->zone());
m_snaps->addPoint(m_controller->frameDuration());
// Loading new clip / zone, stop if playing // Loading new clip / zone, stop if playing
if (m_playAction->isActive()) { if (m_playAction->isActive()) {
m_playAction->setActive(false); m_playAction->setActive(false);
...@@ -2151,3 +2151,14 @@ void Monitor::slotEnd() ...@@ -2151,3 +2151,14 @@ void Monitor::slotEnd()
m_glMonitor->switchPlay(false); m_glMonitor->switchPlay(false);
m_glMonitor->seek(m_glMonitor->duration()); m_glMonitor->seek(m_glMonitor->duration());
} }
void Monitor::addSnapPoint(int pos)
{
m_snaps->addPoint(pos);
}
void Monitor::removeSnapPoint(int pos)
{
m_snaps->removePoint(pos);
}
...@@ -275,6 +275,8 @@ private slots: ...@@ -275,6 +275,8 @@ private slots:
/** @brief Project monitor zone changed, inform timeline */ /** @brief Project monitor zone changed, inform timeline */
void updateTimelineClipZone(); void updateTimelineClipZone();
void slotSeekPosition(int); void slotSeekPosition(int);
void addSnapPoint(int pos);
void removeSnapPoint(int pos);
public slots: public slots:
void slotOpenDvdFile(const QString &); void slotOpenDvdFile(const QString &);
......
...@@ -194,7 +194,7 @@ Item { ...@@ -194,7 +194,7 @@ Item {
style: TextFieldStyle { style: TextFieldStyle {
textColor: "white" textColor: "white"
background: Rectangle { background: Rectangle {
color: "#66ff0000" color: controller.position == controller.zoneIn ? "#9900ff00" : controller.position == controller.zoneOut ? "#99ff0000" : "#990000ff"
width: marker.width width: marker.width
} }
} }
......
...@@ -162,7 +162,7 @@ Item { ...@@ -162,7 +162,7 @@ Item {
style: TextFieldStyle { style: TextFieldStyle {
textColor: "white" textColor: "white"
background: Rectangle { background: Rectangle {
color: "#99ff0000" color: controller.position == controller.zoneIn ? "#9900ff00" : controller.position == controller.zoneOut ? "#99ff0000" : "#990000ff"
width: marker.width width: marker.width
} }
} }
......
...@@ -902,3 +902,4 @@ std::shared_ptr<DocUndoStack> ProjectManager::undoStack() ...@@ -902,3 +902,4 @@ std::shared_ptr<DocUndoStack> ProjectManager::undoStack()
{ {
return current()->commandStack(); return current()->commandStack();
} }
...@@ -1443,6 +1443,16 @@ int TimelineModel::requestPreviousSnapPos(int pos) ...@@ -1443,6 +1443,16 @@ int TimelineModel::requestPreviousSnapPos(int pos)
return m_snaps->getPreviousPoint(pos); return m_snaps->getPreviousPoint(pos);
} }
void TimelineModel::addSnap(int pos)
{
return m_snaps->addPoint(pos);
}
void TimelineModel::removeSnap(int pos)
{
return m_snaps->removePoint(pos);
}
void TimelineModel::registerComposition(const std::shared_ptr<CompositionModel> &composition) void TimelineModel::registerComposition(const std::shared_ptr<CompositionModel> &composition)
{ {
int id = composition->getId(); int id = composition->getId();
......
...@@ -447,6 +447,16 @@ public: ...@@ -447,6 +447,16 @@ public:
*/ */
int requestPreviousSnapPos(int pos); int requestPreviousSnapPos(int pos);
/* @brief Add a new snap point
@param pos is the current position
*/
void addSnap(int pos);
/* @brief Remove snap point
@param pos is the current position
*/
void removeSnap(int pos);
/* @brief Request composition insertion at given position. /* @brief Request composition insertion at given position.
This action is undoable This action is undoable
Returns true on success. If it fails, nothing is modified. Returns true on success. If it fails, nothing is modified.
......
...@@ -699,18 +699,42 @@ void TimelineController::onSeeked(int position) ...@@ -699,18 +699,42 @@ void TimelineController::onSeeked(int position)
void TimelineController::setZone(const QPoint &zone) void TimelineController::setZone(const QPoint &zone)
{ {
if (m_zone.x() > 0) {
m_model->removeSnap(m_zone.x());
}
if (m_zone.y() > 0) {
m_model->removeSnap(m_zone.y());
}
if (zone.x() > 0) {
m_model->addSnap(zone.x());
}
if (zone.y() > 0) {
m_model->addSnap(zone.y());
}
m_zone = zone; m_zone = zone;
emit zoneChanged(); emit zoneChanged();
} }
void TimelineController::setZoneIn(int inPoint) void TimelineController::setZoneIn(int inPoint)
{ {
if (m_zone.x() > 0) {
m_model->removeSnap(m_zone.x());
}
if (inPoint > 0) {
m_model->addSnap(inPoint);
}
m_zone.setX(inPoint); m_zone.setX(inPoint);
emit zoneMoved(m_zone); emit zoneMoved(m_zone);
} }
void TimelineController::setZoneOut(int outPoint) void TimelineController::setZoneOut(int outPoint)
{ {
if (m_zone.y() > 0) {
m_model->removeSnap(m_zone.y());
}
if (outPoint > 0) {
m_model->addSnap(outPoint);
}
m_zone.setY(outPoint); m_zone.setY(outPoint);
emit zoneMoved(m_zone); emit zoneMoved(m_zone);
} }
......
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