Commit abe17b0e authored by Nicolas Carion's avatar Nicolas Carion

fix selection bounds

parent e66eb94e
......@@ -178,7 +178,7 @@ bool TimelineFunctions::requestClipCut(std::shared_ptr<TimelineItemModel> timeli
int TimelineFunctions::requestSpacerStartOperation(std::shared_ptr<TimelineItemModel> timeline, int trackId, int position)
{
std::unordered_set<int> clips = timeline->getItemsAfterPosition(trackId, position, -1);
std::unordered_set<int> clips = timeline->getItemsInRange(trackId, position, -1);
if (clips.size() > 0) {
timeline->requestClipsGroup(clips, false, GroupType::Selection);
return (*clips.cbegin());
......@@ -288,7 +288,7 @@ bool TimelineFunctions::liftZone(std::shared_ptr<TimelineItemModel> timeline, in
TimelineFunctions::requestClipCut(timeline, endClipId, zone.y(), undo, redo);
}
}
std::unordered_set<int> clips = timeline->getItemsAfterPosition(trackId, zone.x(), zone.y());
std::unordered_set<int> clips = timeline->getItemsInRange(trackId, zone.x(), zone.y());
for (const auto &clipId : clips) {
timeline->requestItemDeletion(clipId, undo, redo);
}
......@@ -299,7 +299,7 @@ bool TimelineFunctions::removeSpace(std::shared_ptr<TimelineItemModel> timeline,
{
Q_UNUSED(trackId)
std::unordered_set<int> clips = timeline->getItemsAfterPosition(-1, zone.y() - 1, -1, true);
std::unordered_set<int> clips = timeline->getItemsInRange(-1, zone.y() - 1, -1, true);
bool result = false;
if (clips.size() > 0) {
int clipId = *clips.begin();
......@@ -327,7 +327,7 @@ bool TimelineFunctions::insertSpace(std::shared_ptr<TimelineItemModel> timeline,
{
Q_UNUSED(trackId)
std::unordered_set<int> clips = timeline->getItemsAfterPosition(-1, zone.x(), -1, true);
std::unordered_set<int> clips = timeline->getItemsInRange(-1, zone.x(), -1, true);
bool result = true;
if (clips.size() > 0) {
int clipId = *clips.begin();
......
......@@ -856,23 +856,23 @@ bool TimelineModel::requestCompositionDeletion(int compositionId, Fun &undo, Fun
return false;
}
std::unordered_set<int> TimelineModel::getItemsAfterPosition(int trackId, int position, int end, bool listCompositions)
std::unordered_set<int> TimelineModel::getItemsInRange(int trackId, int start, int end, bool listCompositions)
{
Q_UNUSED(listCompositions)
std::unordered_set<int> allClips;
auto it = m_allTracks.cbegin();
if (trackId == -1) {
while (it != m_allTracks.cend()) {
std::unordered_set<int> clipTracks = (*it)->getClipsAfterPosition(position, end);
for (const auto &track : m_allTracks) {
std::unordered_set<int> clipTracks = getItemsInRange(track->getId(), start, end, listCompositions);
allClips.insert(clipTracks.begin(), clipTracks.end());
++it;
}
} else {
int target_track_position = getTrackPosition(trackId);
std::advance(it, target_track_position);
std::unordered_set<int> clipTracks = (*it)->getClipsAfterPosition(position, end);
std::unordered_set<int> clipTracks = getTrackById(trackId)->getClipsInRange(start, end);
allClips.insert(clipTracks.begin(), clipTracks.end());
if (listCompositions) {
std::unordered_set<int> compoTracks = getTrackById(trackId)->getCompositionsInRange(start, end);
allClips.insert(compoTracks.begin(), compoTracks.end());
}
}
return allClips;
}
......@@ -2233,7 +2233,6 @@ bool TimelineModel::requestClipTimeWarp(int clipId, double speed)
int trackId = getClipTrackId(clipId);
bool result = true;
if (trackId != -1) {
int blankSpace = getTrackById(trackId)->getBlankSizeNearClip(clipId, true);
// Check if clip has a split partner
int splitId = m_groups->getSplitPartner(clipId);
if (splitId > -1) {
......
......@@ -519,13 +519,13 @@ public:
*/
int getCompositionByPosition(int trackId, int position) const;
/* @brief Returns a list of all items that are at or after a given position.
/* @brief Returns a list of all items that are intersect with a given range.
* @param trackId is the id of the track for concerned items. Setting trackId to -1 returns items on all tracks
* @param position is the position where we the items should start
* @param start is the position where we the items should start
* @param end is the position after which items will not be selected, set to -1 to get all clips on track
* @param listCompositions if enabled, the list will also contains composition ids
*/
std::unordered_set<int> getItemsAfterPosition(int trackId, int position, int end = -1, bool listCompositions = true);
std::unordered_set<int> getItemsInRange(int trackId, int start, int end = -1, bool listCompositions = true);
/* @brief Returns a list of all luma files used in the project
*/
......
......@@ -590,16 +590,17 @@ int TrackModel::getClipByRow(int row) const
return (*it).first;
}
std::unordered_set<int> TrackModel::getClipsAfterPosition(int position, int end)
std::unordered_set<int> TrackModel::getClipsInRange(int position, int end)
{
READ_LOCK();
std::unordered_set<int> ids;
for (auto clp : m_allClips) {
for (const auto &clp : m_allClips) {
int pos = clp.second->getPosition();
int length = clp.second->getPlaytime();
if (end > -1 && pos >= end) {
continue;
}
if (pos >= position) {
if (pos >= position || pos + length - 1 >= position) {
ids.insert(clp.first);
}
}
......@@ -613,17 +614,19 @@ int TrackModel::getRowfromClip(int clipId) const
return (int)std::distance(m_allClips.begin(), m_allClips.find(clipId));
}
std::unordered_set<int> TrackModel::getCompositionsAfterPosition(int position, int end)
std::unordered_set<int> TrackModel::getCompositionsInRange(int position, int end)
{
READ_LOCK();
// TODO: this function doesn't take into accounts the fact that there are two tracks
std::unordered_set<int> ids;
for (const auto &compo : m_allCompositions) {
int pos = compo.second->getPosition();
if (pos > position && pos < end) {
if (compo.second->getPlaytime() < end - position) {
ids.insert(compo.first);
}
int length = compo.second->getPlaytime();
if (end > -1 && pos >= end) {
continue;
}
if (pos >= position || pos + length - 1 >= position) {
ids.insert(compo.first);
}
}
return ids;
......
......@@ -97,8 +97,6 @@ public:
// TODO make protected
QVariant getProperty(const QString &name) const;
void setProperty(const QString &name, const QString &value);
std::unordered_set<int> getClipsAfterPosition(int position, int end = -1);
std::unordered_set<int> getCompositionsAfterPosition(int position, int end);
protected:
/* @brief Returns a lambda that performs a resize of the given clip.
......@@ -219,6 +217,10 @@ protected:
int trackDuration();
/* @brief Returns the list of the ids of the clips that intersect the given range */
std::unordered_set<int> getClipsInRange(int position, int end = -1);
/* @brief Returns the list of the ids of the compositions that intersect the given range */
std::unordered_set<int> getCompositionsInRange(int position, int end);
public slots:
/*Delete the current track and all its associated clips */
void slotDelete();
......
......@@ -37,8 +37,8 @@
#include "timeline2/model/groupsmodel.hpp"
#include "timeline2/model/timelineitemmodel.hpp"
#include "timeline2/model/trackmodel.hpp"
#include "timeline2/view/dialogs/trackdialog.h"
#include "timeline2/view/dialogs/clipdurationdialog.h"
#include "timeline2/view/dialogs/trackdialog.h"
#include "timelinewidget.h"
#include "transitions/transitionsrepository.hpp"
#include "utils/KoIconUtils.h"
......@@ -92,7 +92,6 @@ void TimelineController::setTargetTracks(QPair<int, int> targets)
setAudioTarget(targets.second >= 0 ? m_model->getTrackIndexFromPosition(targets.second) : -1);
}
std::shared_ptr<TimelineItemModel> TimelineController::getModel() const
{
return m_model;
......@@ -765,10 +764,8 @@ void TimelineController::selectItems(QVariantList arg, int startFrame, int endFr
}
m_selection.selectedItems.clear();
for (int i = 0; i < arg.count(); i++) {
std::unordered_set<int> trackClips = m_model->getTrackById(arg.at(i).toInt())->getClipsAfterPosition(startFrame, endFrame);
itemsToSelect.insert(trackClips.begin(), trackClips.end());
std::unordered_set<int> trackCompos = m_model->getTrackById(arg.at(i).toInt())->getCompositionsAfterPosition(startFrame, endFrame);
itemsToSelect.insert(trackCompos.begin(), trackCompos.end());
auto currentClips = m_model->getItemsInRange(arg.at(i).toInt(), startFrame, endFrame, true);
itemsToSelect.insert(currentClips.begin(), currentClips.end());
}
if (itemsToSelect.size() > 0) {
for (int x : itemsToSelect) {
......@@ -783,7 +780,6 @@ 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());
}
emit selectionChanged();
}
......@@ -1271,7 +1267,7 @@ void TimelineController::invalidateZone(int in, int out)
void TimelineController::changeItemSpeed(int clipId, double speed)
{
if (qFuzzyCompare(speed,-1)) {
if (qFuzzyCompare(speed, -1)) {
speed = 100 * m_model->getClipSpeed(clipId);
bool ok = false;
double duration = m_model->getItemPlaytime(clipId);
......@@ -1402,7 +1398,8 @@ int TimelineController::insertZone(const QString &binId, QPoint zone, bool overw
insertPoint = timelinePosition();
sourceZone = zone;
}
return TimelineFunctions::insertZone(m_model, targetTrack, binId, insertPoint, sourceZone, overwrite) ? insertPoint + (sourceZone.y() -sourceZone.x()) : -1;
return TimelineFunctions::insertZone(m_model, targetTrack, binId, insertPoint, sourceZone, overwrite) ? insertPoint + (sourceZone.y() - sourceZone.x())
: -1;
}
void TimelineController::updateClip(int clipId, QVector<int> roles)
......@@ -1525,7 +1522,7 @@ void TimelineController::clearSelection()
void TimelineController::selectAll()
{
QList <int> ids;
QList<int> ids;
for (auto clp : m_model->m_allClips) {
ids << clp.first;
}
......@@ -1537,7 +1534,7 @@ void TimelineController::selectAll()
void TimelineController::selectCurrentTrack()
{
QList <int> ids;
QList<int> ids;
for (auto clp : m_model->getTrackById_const(m_activeTrack)->m_allClips) {
ids << clp.first;
}
......@@ -1579,7 +1576,8 @@ void TimelineController::editItemDuration(int id)
int maxFrame = m_model->getTrackById(trackId)->getBlankSizeNearClip(id, true);
int minFrame = in - m_model->getTrackById(trackId)->getBlankSizeNearClip(id, false);
int partner = m_model->getClipSplitPartner(id);
QPointer<ClipDurationDialog> dialog = new ClipDurationDialog(id, pCore->currentDoc()->timecode(), start, minFrame, in, in + duration, maxLength, maxFrame, qApp->activeWindow());
QPointer<ClipDurationDialog> dialog =
new ClipDurationDialog(id, pCore->currentDoc()->timecode(), start, minFrame, in, in + duration, maxLength, maxFrame, qApp->activeWindow());
if (dialog->exec() == QDialog::Accepted) {
std::function<bool(void)> undo = []() { return true; };
std::function<bool(void)> redo = []() { return true; };
......@@ -1640,4 +1638,3 @@ void TimelineController::editItemDuration(int id)
}
}
}
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