Fix clip grab state not updated on deselection

Fixes #203
parent 7099b8ac
Pipeline #3855 passed with stage
in 23 minutes and 7 seconds
......@@ -730,6 +730,16 @@ void ClipModel::setOffset(int offset)
}
}
void ClipModel::setGrab(bool grab)
{
QWriteLocker locker(&m_lock);
m_grabbed = grab;
if (auto ptr = m_parent.lock()) {
QModelIndex ix = ptr->makeClipIndexFromID(m_id);
ptr->dataChanged(ix, ix, {TimelineModel::GrabbedRole});
}
}
void ClipModel::clearOffset()
{
if (m_positionOffset != 0) {
......
......@@ -99,6 +99,7 @@ public:
void setFakeTrackId(int fid);
int getFakePosition() const;
void setFakePosition(int fid);
void setGrab(bool grab) override;
/* @brief Returns an XML representation of the clip with its effects */
QDomElement toXml(QDomDocument &document);
......
......@@ -250,6 +250,16 @@ void CompositionModel::setInOut(int in, int out)
setPosition(in);
}
void CompositionModel::setGrab(bool grab)
{
QWriteLocker locker(&m_lock);
m_grabbed = grab;
if (auto ptr = m_parent.lock()) {
QModelIndex ix = ptr->makeCompositionIndexFromID(m_id);
ptr->dataChanged(ix, ix, {TimelineModel::GrabbedRole});
}
}
void CompositionModel::setCurrentTrackId(int tid, bool finalMove)
{
Q_UNUSED(finalMove);
......
......@@ -95,6 +95,7 @@ public:
/* @brief Returns an XML representation of the clip with its effects */
QDomElement toXml(QDomDocument &document);
void setGrab(bool grab) override;
protected:
Mlt::Transition *service() const override;
......
......@@ -62,6 +62,9 @@ public:
virtual int getIn() const;
virtual int getOut() const;
/* Set grab status */
virtual void setGrab(bool grab) = 0;
friend class TrackModel;
friend class TimelineModel;
/* Implicit conversion operator to access the underlying producer
......@@ -78,7 +81,6 @@ public:
/* Set if the item is in grab state */
bool isGrabbed() const;
void setGrab(bool grab);
protected:
/* @brief Returns a pointer to the service. It may be used but do NOT store it*/
......
......@@ -100,8 +100,3 @@ template <typename Service> bool MoveableItem<Service>::isGrabbed() const
return m_grabbed;
}
template <typename Service> void MoveableItem<Service>::setGrab(bool grab)
{
QWriteLocker locker(&m_lock);
m_grabbed = grab;
}
......@@ -3118,11 +3118,27 @@ bool TimelineModel::requestClearSelection(bool onDeletion)
for (auto &id : items) {
if (isClip(id)) {
m_allClips[id]->clearOffset();
if (m_allClips[id]->isGrabbed()) {
m_allClips[id]->setGrab(false);
}
} else if (isComposition(id)) {
if (m_allCompositions[id]->isGrabbed()) {
m_allCompositions[id]->setGrab(false);
}
}
}
m_groups->destructGroupItem(m_currentSelection);
}
} else {
if (isClip(m_currentSelection)) {
if (m_allClips[m_currentSelection]->isGrabbed()) {
m_allClips[m_currentSelection]->setGrab(false);
}
} else if (isComposition(m_currentSelection)) {
if (m_allCompositions[m_currentSelection]->isGrabbed()) {
m_allCompositions[m_currentSelection]->setGrab(false);
}
}
Q_ASSERT(onDeletion || isClip(m_currentSelection) || isComposition(m_currentSelection));
}
m_currentSelection = -1;
......
......@@ -2107,17 +2107,9 @@ void TimelineController::grabCurrent()
if (m_model->isClip(id)) {
std::shared_ptr<ClipModel> clip = m_model->getClipPtr(id);
clip->setGrab(!clip->isGrabbed());
QModelIndex ix = m_model->makeClipIndexFromID(id);
if (ix.isValid()) {
m_model->dataChanged(ix, ix, {TimelineItemModel::GrabbedRole});
}
} else if (m_model->isComposition(id)) {
std::shared_ptr<CompositionModel> clip = m_model->getCompositionPtr(id);
clip->setGrab(!clip->isGrabbed());
QModelIndex ix = m_model->makeCompositionIndexFromID(id);
if (ix.isValid()) {
m_model->dataChanged(ix, ix, {TimelineItemModel::GrabbedRole});
}
}
}
......
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