Skip to content

Commit

Permalink
Merge pull request #1472 from manongjohn/fix_level_strip_empty_selection
Browse files Browse the repository at this point in the history
Fix level strip empty space selection and commands
  • Loading branch information
manongjohn committed May 20, 2024
2 parents 59c100c + a35a7f5 commit fb2b466
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 20 deletions.
69 changes: 60 additions & 9 deletions toonz/sources/toonz/filmstrip.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,40 @@ void FilmstripFrames::mouseDoubleClickEvent(QMouseEvent *event) {
} else {
index = x2index(event->pos().x());
}
select(index, ONLY_SELECT); // ONLY_SELECT

int frameHeight = m_iconSize.height() + fs_frameSpacing + fs_iconMarginTop +
fs_iconMarginBottom;
int frameWidth = m_iconSize.width() + fs_frameSpacing + fs_iconMarginLR +
fs_leftMargin + fs_rightMargin;

bool clickedEmptySpace = false;

// If accessed after 1st frame on a Single Frame level
// Block movement so we can't create new images
TXshSimpleLevel *sl = getLevel();
if (index > 0 && sl) {
std::vector<TFrameId> fids;
sl->getFids(fids);
if (fids.empty() ||
(fids.size() == 1 && (fids[0].getNumber() == TFrameId::EMPTY_FRAME ||
fids[0].getNumber() == TFrameId::NO_FRAME)))
return;

// If we overshoot last frame, move back to 1st empty spot
int emptyIndex = 0;
if (m_isVertical)
emptyIndex = y2index(fids.size() * frameHeight);
else
emptyIndex = x2index(fids.size() * frameWidth);

if (index >= emptyIndex) {
index = emptyIndex;
clickedEmptySpace = true;
}
}

select(index,
clickedEmptySpace ? SELECT_EMPTY_SPACE : ONLY_SELECT); // ONLY_SELECT
}

//-----------------------------------------------------------------------------
Expand All @@ -323,13 +356,14 @@ void FilmstripFrames::select(int index, SelectionMode mode) {
bool outOfRange = !sl || index < 0 || index >= sl->getFrameCount();

TFrameId fid;
if (!outOfRange) fid = index2fid(index);
if (!outOfRange || SELECT_EMPTY_SPACE) fid = index2fid(index);

switch (mode) {
// select one frame only
case ONLY_SELECT:
case SELECT_EMPTY_SPACE:
m_selection->selectNone();
if (!outOfRange) m_selection->select(fid);
if (!outOfRange || SELECT_EMPTY_SPACE) m_selection->select(fid);
break;
case SIMPLE_SELECT:
// Bail out if fid is already selected
Expand Down Expand Up @@ -860,6 +894,13 @@ void FilmstripFrames::mousePressEvent(QMouseEvent *event) {
sl->getType() == TZI_XSHLEVEL);
CommandManager::instance()->enable(MI_CanvasSize, isRasterLevel);

int frameHeight = m_iconSize.height() + fs_frameSpacing + fs_iconMarginTop +
fs_iconMarginBottom;
int frameWidth = m_iconSize.width() + fs_frameSpacing + fs_iconMarginLR +
fs_leftMargin + fs_rightMargin;

bool clickedEmptySpace = false;

// If accessed after 1st frame on a Single Frame level
// Block movement so we can't create new images
if (index > 0) {
Expand All @@ -869,12 +910,20 @@ void FilmstripFrames::mousePressEvent(QMouseEvent *event) {
(fids.size() == 1 && (fids[0].getNumber() == TFrameId::EMPTY_FRAME ||
fids[0].getNumber() == TFrameId::NO_FRAME)))
return;
}

int frameHeight = m_iconSize.height() + fs_frameSpacing + fs_iconMarginTop +
fs_iconMarginBottom;
int frameWidth = m_iconSize.width() + fs_frameSpacing + fs_iconMarginLR +
fs_leftMargin + fs_rightMargin;
// If we overshoot last frame, move back to 1st empty spot
int emptyIndex = 0;
if (m_isVertical)
emptyIndex = y2index(fids.size() * frameHeight);
else
emptyIndex = x2index(fids.size() * frameWidth);

if (index >= emptyIndex) {
index = emptyIndex;
fid = fids.back().getNumber() + 1;
clickedEmptySpace = true;
}
}

int i0;
QPoint clickedPos;
Expand All @@ -888,6 +937,7 @@ void FilmstripFrames::mousePressEvent(QMouseEvent *event) {
clickedPos = event->pos() - QPoint((index - i0) * frameWidth, 0);
}
actualIconClicked =
!clickedEmptySpace &&
QRect(QPoint(fs_leftMargin + fs_iconMarginLR,
fs_frameSpacing / 2 +
fs_iconMarginTop) //<- top-left position of the icon
Expand Down Expand Up @@ -950,6 +1000,7 @@ void FilmstripFrames::mousePressEvent(QMouseEvent *event) {
TXshLevel *level = tapp->getCurrentLevel()->getLevel();
level->getFids(fids);

if(clickedEmptySpace) fids.push_back(fid);
tapp->getCurrentFrame()->setFrameIds(fids);
tapp->getCurrentFrame()->setFid(fid);

Expand All @@ -968,7 +1019,7 @@ void FilmstripFrames::mousePressEvent(QMouseEvent *event) {
m_indexForResetSelection = index;
} else if (!actualIconClicked) {
// this allows clicking the frame number to trigger an instant drag
select(index, ONLY_SELECT);
select(index, clickedEmptySpace ? SELECT_EMPTY_SPACE : ONLY_SELECT);
m_dragDropArmed = true;
m_pos = event->pos();
}
Expand Down
3 changes: 2 additions & 1 deletion toonz/sources/toonz/filmstrip.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,8 @@ class FilmstripFrames final : public QFrame, public TSelection::View {
CTRL_SELECT,
START_DRAG_SELECT,
DRAG_SELECT,
ONLY_SELECT
ONLY_SELECT,
SELECT_EMPTY_SPACE
};
void select(int index, SelectionMode mode = SIMPLE_SELECT);

Expand Down
10 changes: 5 additions & 5 deletions toonz/sources/toonz/filmstripcommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1764,7 +1764,7 @@ void FilmstripCmd::paste(TXshSimpleLevel *sl, std::set<TFrameId> &frames) {
//-----------------------------------------------------------------------------

void FilmstripCmd::merge(TXshSimpleLevel *sl, std::set<TFrameId> &frames) {
if (!sl || sl->isReadOnly() || sl->isSubsequence()) return;
if (!sl || sl->isReadOnly() || sl->isSubsequence() || !frames.size()) return;

std::vector<TFrameId> oldLevelFrameId;
sl->getFids(oldLevelFrameId);
Expand Down Expand Up @@ -2080,7 +2080,7 @@ class FilmstripReverseUndo final : public TUndo {
//-----------------------------------------------------------------------------

void FilmstripCmd::reverse(TXshSimpleLevel *sl, std::set<TFrameId> &frames) {
if (!sl || sl->isSubsequence() || sl->isReadOnly()) return;
if (!sl || sl->isSubsequence() || sl->isReadOnly() || !frames.size()) return;
performReverse(sl, frames);
TUndoManager::manager()->add(new FilmstripReverseUndo(sl, frames));
TApp::instance()->getCurrentScene()->setDirtyFlag(true);
Expand Down Expand Up @@ -2169,7 +2169,7 @@ class FilmstripSwingUndo final : public TUndo {
//-----------------------------------------------------------------------------

void FilmstripCmd::swing(TXshSimpleLevel *sl, std::set<TFrameId> &frames) {
if (!sl || sl->isSubsequence() || sl->isReadOnly()) return;
if (!sl || sl->isSubsequence() || sl->isReadOnly() || !frames.size()) return;
performSwing(sl, frames);
TUndoManager::manager()->add(new FilmstripSwingUndo(sl, frames));
TApp::instance()->getCurrentScene()->setDirtyFlag(true);
Expand Down Expand Up @@ -2285,7 +2285,7 @@ class StepFilmstripUndo final : public TUndo {

void FilmstripCmd::step(TXshSimpleLevel *sl, std::set<TFrameId> &frames,
int step) {
if (!sl || sl->isSubsequence() || sl->isReadOnly()) return;
if (!sl || sl->isSubsequence() || sl->isReadOnly() || !frames.size()) return;
QApplication::setOverrideCursor(Qt::WaitCursor);
StepFilmstripUndo *undo = new StepFilmstripUndo(sl, frames, step);
stepFilmstripFrames(sl, frames, step);
Expand Down Expand Up @@ -2381,7 +2381,7 @@ class EachFilmstripUndo final : public TUndo {

void FilmstripCmd::each(TXshSimpleLevel *sl, std::set<TFrameId> &frames,
int each) {
if (!sl || sl->isSubsequence() || sl->isReadOnly()) return;
if (!sl || sl->isSubsequence() || sl->isReadOnly() || !frames.size()) return;
std::map<TFrameId, QString> deletedFrames =
eachFilmstripFrames(sl, frames, each);
TUndoManager::manager()->add(
Expand Down
19 changes: 14 additions & 5 deletions toonz/sources/toonz/filmstripselection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,17 +141,18 @@ void TFilmstripSelection::updateInbetweenRange() {
void TFilmstripSelection::select(const TFrameId &fid, bool selected) {
TApp *app = TApp::instance();

if (selected)
TXshSimpleLevel *sl = app->getCurrentLevel()->getSimpleLevel();

if (selected) {
if (sl && !sl->getFrame(fid, false)) return;
m_selectedFrames.insert(fid);
else
} else
m_selectedFrames.erase(fid);

updateInbetweenRange();

TTool *tool = app->getCurrentTool()->getTool();
if (tool) tool->setSelectedFrames(m_selectedFrames);

TXshSimpleLevel *sl = app->getCurrentLevel()->getSimpleLevel();
}

//-----------------------------------------------------------------------------
Expand Down Expand Up @@ -286,6 +287,7 @@ void TFilmstripSelection::deleteFrames() {
DVGui::warning(QObject::tr("Can't delete the last drawing in a level."));
return;
}
if (!m_selectedFrames.size()) return;
// find highest numbered frame
int highestFrame = -1;
TFrameId fid;
Expand Down Expand Up @@ -329,7 +331,14 @@ void TFilmstripSelection::clearFrames() {

void TFilmstripSelection::insertEmptyFrames() {
TXshSimpleLevel *sl = TApp::instance()->getCurrentLevel()->getSimpleLevel();
if (sl) FilmstripCmd::insert(sl, m_selectedFrames, true);
if (sl) {
if (!m_selectedFrames.size() && sl && sl->getFrameCount()) {
TFrameId fid = sl->getLastFid().getNumber() + 1;
m_selectedFrames.insert(fid);
}

FilmstripCmd::insert(sl, m_selectedFrames, true);
}
}

//-----------------------------------------------------------------------------
Expand Down

0 comments on commit fb2b466

Please sign in to comment.