Add timeline menu to group/ungroup

parent b13ef870
......@@ -20,11 +20,12 @@
***************************************************************************/
#include "groupsmodel.hpp"
#include "timelinemodel.hpp"
#include "timelineitemmodel.hpp"
#include <QDebug>
#include <QModelIndex>
#include <queue>
GroupsModel::GroupsModel(std::weak_ptr<TimelineModel> parent) :
GroupsModel::GroupsModel(std::weak_ptr<TimelineItemModel> parent) :
m_parent(parent)
{
}
......@@ -37,7 +38,8 @@ Fun GroupsModel::groupItems_lambda(int gid, const std::unordered_set<int>& ids)
Q_ASSERT(m_groupIds.count(gid) == 0);
m_groupIds.insert(gid);
if (auto ptr = m_parent.lock()) {
auto ptr = m_parent.lock();
if (ptr) {
ptr->registerGroup(gid);
} else {
qDebug() << "Impossible to create group because the timeline is not available anymore";
......@@ -48,6 +50,8 @@ Fun GroupsModel::groupItems_lambda(int gid, const std::unordered_set<int>& ids)
[&](int id){return getRootId(id);});
for (int id : roots) {
setGroup(getRootId(id), gid);
QModelIndex ix = ptr->makeClipIndexFromID(id);
ptr->dataChanged(ix, ix, {TimelineItemModel::GroupedRole});
}
return true;
};
......@@ -92,8 +96,9 @@ void GroupsModel::createGroupItem(int id)
Fun GroupsModel::destructGroupItem_lambda(int id)
{
return [this, id]() {
auto ptr = m_parent.lock();
if (m_groupIds.count(id) > 0) {
if(auto ptr = m_parent.lock()) {
if(ptr) {
ptr->deregisterGroup(id);
m_groupIds.erase(id);
} else {
......@@ -104,6 +109,8 @@ Fun GroupsModel::destructGroupItem_lambda(int id)
removeFromGroup(id);
for (int child : m_downLink[id]) {
m_upLink[child] = -1;
QModelIndex ix = ptr->makeClipIndexFromID(child);
ptr->dataChanged(ix, ix, {TimelineItemModel::GroupedRole});
}
m_downLink.erase(id);
m_upLink.erase(id);
......
......@@ -27,7 +27,7 @@
#include <memory>
#include "undohelper.hpp"
class TimelineModel;
class TimelineItemModel;
/* @brief This class represents the group hiearchy. This is basically a tree structure
In this class, we consider that a groupItem is either a clip or a group
......@@ -36,7 +36,7 @@ class GroupsModel
{
public:
GroupsModel() = delete;
GroupsModel(std::weak_ptr<TimelineModel> parent);
GroupsModel(std::weak_ptr<TimelineItemModel> parent);
/* @brief Create a group that contains all the given items and returns the id of the created group.
Note that if an item is already part of a group, its topmost group will be considered instead and added in the newly created group.
......@@ -132,7 +132,7 @@ protected:
void removeFromGroup(int id);
private:
std::weak_ptr<TimelineModel> m_parent;
std::weak_ptr<TimelineItemModel> m_parent;
std::unordered_map<int, int> m_upLink; //edges toward parent
std::unordered_map<int, std::unordered_set<int>> m_downLink; //edges toward children
......
......@@ -37,6 +37,7 @@ Rectangle {
property bool isBlank: false
property bool isAudio: false
property bool isTransition: false
property bool grouped: false
property var audioLevels
property int fadeIn: 0
property int fadeOut: 0
......@@ -580,6 +581,17 @@ Rectangle {
}
}
}
MenuItem {
visible: !grouped && trackRoot.selection.length > 1
text: qsTr('Group')
onTriggered: timeline.groupSelection()
}
MenuItem {
visible: grouped
text: qsTr('Ungroup')
onTriggered: timeline.unGroupSelection(clipId)
}
MenuItem {
visible: true //!isBlank && !isTransition
text: qsTr('Copy')
......
......@@ -79,6 +79,7 @@ Column{
height: parent.height
modelStart: model.start
x: modelStart * timeScale
grouped: model.grouped
borderColor: (model.grouped > 0 ? 'yellow' : 'black')
trackIndex: trackRoot.DelegateModel.itemsIndex
trackId: trackRoot.trackId
......@@ -86,7 +87,7 @@ Column{
fadeOut: 0 //model.fadeOut
//hash: model.hash
speed: 1 //model.speed
selected: /*trackRoot.isCurrentTrack &&*/ trackRoot.selection.indexOf(clipId) !== -1
selected: trackRoot.selection.indexOf(clipId) !== -1
onClicked: {
console.log("Clip clicked",clip.clipId)
......
......@@ -342,3 +342,16 @@ void TimelineWidget::gotoPreviousSnap()
seek(m_model->requestPreviousSnapPos(m_position));
}
void TimelineWidget::groupSelection()
{
std::unordered_set<int> clips;
foreach(int id, m_selection.selectedClips) {
clips.insert(id);
}
m_model->requestClipsGroup(clips);
}
void TimelineWidget::unGroupSelection(int cid)
{
m_model->requestClipUngroup(cid);
}
......@@ -160,6 +160,8 @@ public:
/* @brief Remove a timeline track
*/
Q_INVOKABLE void deleteTrack(int tid);
Q_INVOKABLE void groupSelection();
Q_INVOKABLE void unGroupSelection(int cid);
void gotoNextSnap();
void gotoPreviousSnap();
......
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