Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

Fix incoherent group / ungroup actions

parent f68fa5f1
......@@ -141,8 +141,13 @@ Fun GroupsModel::destructGroupItem_lambda(int id)
if (!ptr) Q_ASSERT(false);
for (int child : m_downLink[id]) {
m_upLink[child] = -1;
QModelIndex ix;
if (ptr->isClip(child)) {
QModelIndex ix = ptr->makeClipIndexFromID(child);
ix = ptr->makeClipIndexFromID(child);
} else if (ptr->isComposition(child)) {
ix = ptr->makeCompositionIndexFromID(child);
}
if (ix.isValid()) {
ptr->dataChanged(ix, ix, {TimelineModel::GroupedRole});
}
}
......
......@@ -297,7 +297,7 @@ QVariant TimelineItemModel::data(const QModelIndex &index, int role) const
case DurationRole:
return clip->getPlaytime();
case GroupedRole:
return (m_groups->isInGroup(id) && !isInSelection(id));
return (m_groups->isInGroup(id) && !isInMultiSelection(id));
case EffectNamesRole:
return clip->effectNames();
case InPointRole:
......@@ -485,12 +485,12 @@ bool TimelineItemModel::loadGroups(const QString &groupsData)
return m_groups->fromJson(groupsData);
}
bool TimelineItemModel::isInSelection(int cid) const
bool TimelineItemModel::isInMultiSelection(int cid) const
{
if (m_temporarySelectionGroup == -1 || !m_groups->isInGroup(cid)) {
if (m_temporarySelectionGroup == -1) {
return false;
}
bool res = (m_groups->getRootId(cid) == m_temporarySelectionGroup);
bool res = (m_groups->getRootId(cid) == m_temporarySelectionGroup) && (m_groups->getDirectChildren(m_temporarySelectionGroup).size() != 1);
return res;
}
......
......@@ -101,7 +101,7 @@ public:
bool loadGroups(const QString &groupsData);
/* @brief returns true if clip is in temporary selection group.
*/
bool isInSelection(int cid) const;
bool isInMultiSelection(int cid) const;
virtual void _beginRemoveRows(const QModelIndex &, int, int) override;
virtual void _beginInsertRows(const QModelIndex &, int, int) override;
......
......@@ -10,17 +10,21 @@ Menu {
property bool grouped
property bool canBeAudio
property bool canBeVideo
property bool canBeGrouped: timeline.isInSelection(clipId)
onAboutToHide: {
timeline.ungrabHack()
}
onAboutToShow: {
canBeGrouped = timeline.isInSelection(clipId)
}
MenuItem {
text: i18n('Copy')
onTriggered: root.copiedClip = clipId
}
MenuItem {
visible: !grouped && timeline.selection.length > 1
visible: canBeGrouped
text: i18n('Group')
onTriggered: timeline.triggerAction('group_clip')
}
......
......@@ -588,6 +588,7 @@ void TimelineController::groupSelection()
clips.insert(id);
}
m_model->requestClipsGroup(clips);
emit selectionChanged();
}
void TimelineController::unGroupSelection(int cid)
......@@ -861,6 +862,17 @@ void TimelineController::selectItems(QVariantList arg, int startFrame, int endFr
std::unordered_set<int> newIds;
if (m_model->m_temporarySelectionGroup >= 0) {
newIds = m_model->getGroupElements(m_selection.selectedItems.constFirst());
for (int child : newIds) {
QModelIndex ix;
if (m_model->isClip(child)) {
ix = m_model->makeClipIndexFromID(child);
} else if (m_model->isComposition(child)) {
ix = m_model->makeCompositionIndexFromID(child);
}
if (ix.isValid()) {
m_model->dataChanged(ix, ix, {TimelineModel::GroupedRole});
}
}
}
emit selectionChanged();
}
......@@ -1840,9 +1852,9 @@ void TimelineController::updateClipActions()
bool enableAction = true;
const QChar actionData = act->data().toChar();
if (actionData == QLatin1Char('G')) {
enableAction = m_selection.selectedItems.size() > 1;
enableAction = m_model->isInMultiSelection(item);
} else if (actionData == QLatin1Char('U')) {
enableAction = m_model->m_groups->isInGroup(item) && !m_model->isInSelection(item);
enableAction = m_model->m_groups->isInGroup(item) && !m_model->isInMultiSelection(item);
} else if (actionData == QLatin1Char('A')) {
enableAction = clip && clip->clipState() == PlaylistState::AudioOnly;
} else if (actionData == QLatin1Char('V')) {
......@@ -2073,3 +2085,8 @@ QStringList TimelineController::getThumbKeys()
result.removeDuplicates();
return result;
}
bool TimelineController::isInSelection(int itemId)
{
return m_model->isInMultiSelection(itemId);
}
......@@ -224,6 +224,8 @@ public:
Q_INVOKABLE void showTrackAsset(int trackId);
Q_INVOKABLE void selectItems(QVariantList arg, int startFrame, int endFrame, bool addToSelect);
/* @brief Returns true is item is selected as well as other items */
Q_INVOKABLE bool isInSelection(int itemId);
Q_INVOKABLE int headerWidth() const;
Q_INVOKABLE void setHeaderWidth(int width);
......
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