Skip to content

Commit

Permalink
introduce pivot row instead of the current frame
Browse files Browse the repository at this point in the history
  • Loading branch information
shun-iwasawa committed May 2, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent 7754b04 commit 6e950f5
Showing 3 changed files with 18 additions and 7 deletions.
11 changes: 9 additions & 2 deletions toonz/sources/toonz/cellselection.cpp
Original file line number Diff line number Diff line change
@@ -1502,7 +1502,8 @@ int TCellSelection::Range::getColCount() const { return m_c1 - m_c0 + 1; }
// TCellSelection
//-----------------------------------------------------------------------------

TCellSelection::TCellSelection() : m_timeStretchPopup(0), m_reframePopup(0) {
TCellSelection::TCellSelection()
: m_timeStretchPopup(0), m_reframePopup(0), m_resizePivotRow(-1) {
setAlternativeCommandNames();
}

@@ -1650,6 +1651,10 @@ void TCellSelection::selectCells(int r0, int c0, int r1, int c1) {
m_range.m_r1 = r1;
m_range.m_c1 = c1;
bool onlyOneRasterLevel = containsOnlyOneRasterLevel(r0, c0, r1, c1);
// set the nearest row
m_resizePivotRow =
(std::abs(r0 - m_resizePivotRow) < std::abs(r1 - m_resizePivotRow)) ? r0
: r1;
CommandManager::instance()->enable(MI_CanvasSize, onlyOneRasterLevel);
}

@@ -1661,13 +1666,15 @@ void TCellSelection::selectCell(int row, int col) {
m_range.m_r1 = row;
m_range.m_c1 = col;
bool onlyOneRasterLevel = containsOnlyOneRasterLevel(row, col, row, col);
m_resizePivotRow = row;
CommandManager::instance()->enable(MI_CanvasSize, onlyOneRasterLevel);
}

//-----------------------------------------------------------------------------

void TCellSelection::selectNone() {
m_range = Range();
m_range = Range();
m_resizePivotRow = -1;
CommandManager::instance()->enable(MI_CanvasSize, false);
}

3 changes: 3 additions & 0 deletions toonz/sources/toonz/cellselection.h
Original file line number Diff line number Diff line change
@@ -33,6 +33,8 @@ class TCellSelection final : public TSelection {

private:
Range m_range;
int m_resizePivotRow; // pivot frame when resizing the selection with
// ctrl+arrow keys

public:
TCellSelection();
@@ -129,6 +131,7 @@ class TCellSelection final : public TSelection {
void createBlankDrawing(int row, int col, bool inRange);
void createBlankDrawings();
void fillEmptyCell();
int getResizePivotRow() const { return m_resizePivotRow; }
};

#endif // TCELLSELECTION_H
11 changes: 6 additions & 5 deletions toonz/sources/toonz/xsheetviewer.cpp
Original file line number Diff line number Diff line change
@@ -1268,7 +1268,8 @@ void XsheetViewer::keyPressEvent(QKeyEvent *event) {
if (m_cellArea->isControlPressed()) { // resize

// resize selection of frames/rows forward or backwards
if (rowA < getCurrentRow())
assert(cellSel->getResizePivotRow() >= 0);
if (rowA < cellSel->getResizePivotRow())
rowA += shift.frame();
else
rowB += shift.frame();
@@ -1290,10 +1291,10 @@ void XsheetViewer::keyPressEvent(QKeyEvent *event) {

} else { // shift
CellPosition offset(shift * stride);
int movedRow0 = std::max(0, rowA + offset.frame());
int movedCol0 = std::max(firstCol, colA + offset.layer());
int diffRow = movedRow0 - rowA;
int diffCol = movedCol0 - colA;
int movedRow0 = std::max(0, rowA + offset.frame());
int movedCol0 = std::max(firstCol, colA + offset.layer());
int diffRow = movedRow0 - rowA;
int diffCol = movedCol0 - colA;
cellSel->selectCells(rowA + diffRow, colA + diffCol, rowB + diffRow,
colB + diffCol);
TApp::instance()->getCurrentSelection()->notifySelectionChanged();

0 comments on commit 6e950f5

Please sign in to comment.