Merge pull request #963 from manongjohn/allow_level_extender_to_shift_sound

Allow Level Extender to shift Sound cells
This commit is contained in:
manongjohn 2022-04-16 09:46:30 -04:00 committed by GitHub
commit d9726e0028
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -334,15 +334,19 @@ class LevelExtenderUndo final : public TUndo {
bool m_insert;
bool m_invert; // upper-directional
bool m_refreshSound;
public:
LevelExtenderUndo(bool insert = true, bool invert = false)
LevelExtenderUndo(bool insert = true, bool invert = false,
bool refreshSound = false)
: m_colCount(0)
, m_rowCount(0)
, m_col(0)
, m_row(0)
, m_deltaRow(0)
, m_insert(insert)
, m_invert(invert) {}
, m_invert(invert)
, m_refreshSound(refreshSound) {}
void setCells(TXsheet *xsh, int row, int col, int rowCount, int colCount) {
assert(rowCount > 0 && colCount > 0);
@ -368,9 +372,7 @@ public:
int count = abs(m_deltaRow);
int r = m_row + m_rowCount - count;
for (int c = m_col; c < m_col + m_colCount; c++) {
// Se e' una colonna sound l'extender non deve fare nulla.
TXshColumn *column = xsh->getColumn(c);
if (column && column->getSoundColumn()) continue;
xsh->removeCells(r, c, count);
}
}
@ -382,15 +384,17 @@ public:
int r0 = m_row + m_rowCount - count;
int r1 = m_row + m_rowCount - 1;
for (int c = 0; c < m_colCount; c++) {
// Se e' una colonna sound l'extender non deve fare nulla.
TXshColumn *column = xsh->getColumn(c);
if (column && column->getSoundColumn()) continue;
bool isSoundColumn = (column && column->getSoundColumn());
int col = m_col + c;
xsh->insertCells(r0, col, count);
int r;
for (r = r0; r <= r1; r++) {
int k = (r - m_row) * m_colCount + c;
xsh->setCell(r, col, m_cells[k]);
if (isSoundColumn)
xsh->setCell(r, col, TXshCell());
else
xsh->setCell(r, col, m_cells[k]);
}
}
}
@ -403,7 +407,6 @@ public:
int count = abs(m_deltaRow);
for (int c = m_col; c < m_col + m_colCount; c++) {
TXshColumn *column = xsh->getColumn(c);
if (column && column->getSoundColumn()) continue;
if (m_invert)
xsh->clearCells(m_row, c, count);
else
@ -428,11 +431,14 @@ public:
}
for (int c = 0; c < m_colCount; c++) {
TXshColumn *column = xsh->getColumn(c);
if (column && column->getSoundColumn()) continue;
bool isSoundColumn = (column && column->getSoundColumn());
int col = m_col + c;
for (int r = r0; r <= r1; r++) {
int k = (r - m_row) * m_colCount + c;
xsh->setCell(r, col, m_cells[k]);
if (isSoundColumn)
xsh->setCell(r, col, TXshCell());
else
xsh->setCell(r, col, m_cells[k]);
}
}
}
@ -450,6 +456,8 @@ public:
TApp::instance()->getCurrentSelection()->getSelection();
if (selection) selection->selectNone();
TApp::instance()->getCurrentXsheet()->notifyXsheetChanged();
if (m_refreshSound)
TApp::instance()->getCurrentXsheet()->notifyXsheetSoundChanged();
}
void redo() const override {
@ -465,6 +473,8 @@ public:
TApp::instance()->getCurrentSelection()->getSelection();
if (selection) selection->selectNone();
TApp::instance()->getCurrentXsheet()->notifyXsheetChanged();
if (m_refreshSound)
TApp::instance()->getCurrentXsheet()->notifyXsheetSoundChanged();
}
int getSize() const override {
@ -649,14 +659,17 @@ class LevelExtenderTool final : public XsheetGUI::DragTool {
bool m_invert; // upper directional smart tab
bool m_insert;
bool m_refreshSound;
public:
LevelExtenderTool(XsheetViewer *viewer, bool insert = true,
bool invert = false)
bool invert = false, bool refreshSound = false)
: XsheetGUI::DragTool(viewer)
, m_colCount(0)
, m_undo(0)
, m_insert(insert)
, m_invert(invert) {}
, m_invert(invert)
, m_refreshSound(refreshSound) {}
// called when the smart tab is clicked
void onClick(const CellPosition &pos) override {
@ -680,7 +693,7 @@ public:
TXsheet *xsh = getViewer()->getXsheet();
for (int c = c0; c <= c1; c++) {
TXshColumn *column = xsh->getColumn(c);
if (!column || column->getSoundColumn()) continue;
if (!column) continue;
if (!column->isCellEmpty(r1 + 1)) {
m_insert = true; // switch the behavior
break;
@ -690,9 +703,12 @@ public:
m_columns.reserve(m_colCount);
TXsheet *xsh = getViewer()->getXsheet();
for (int c = c0; c <= c1; c++)
for (int c = c0; c <= c1; c++) {
TXshColumn *column = xsh->getColumn(c);
if (column && column->getSoundColumn()) m_refreshSound = true;
m_columns.push_back(CellBuilder(xsh, r0, c, m_rowCount, m_invert));
m_undo = new LevelExtenderUndo(m_insert, m_invert);
}
m_undo = new LevelExtenderUndo(m_insert, m_invert, m_refreshSound);
m_undo->setCells(xsh, r0, c0, m_rowCount, m_colCount);
}
@ -716,9 +732,7 @@ public:
// shrink
if (dr < 0) {
for (int c = 0; c < m_colCount; c++) {
// Se e' una colonna sound l'extender non deve fare nulla.
TXshColumn *column = xsh->getColumn(m_c0 + c);
if (column && column->getSoundColumn()) continue;
if (m_insert)
xsh->removeCells(row, m_c0 + c, -dr);
else {
@ -736,7 +750,7 @@ public:
for (tmp_dr = 1; tmp_dr <= dr; tmp_dr++) {
for (int c = 0; c < m_colCount; c++) {
TXshColumn *column = xsh->getColumn(m_c0 + c);
if (!column || column->getSoundColumn()) continue;
if (!column) continue;
if (!column->isCellEmpty(m_r1 + tmp_dr)) {
found = true;
break;
@ -750,12 +764,14 @@ public:
}
for (int c = 0; c < m_colCount; c++) {
// Se e' una colonna sound l'extender non deve fare nulla.
TXshColumn *column = xsh->getColumn(m_c0 + c);
if (column && column->getSoundColumn()) continue;
bool isSoundColumn = (column && column->getSoundColumn());
if (m_insert) xsh->insertCells(m_r1 + 1, m_c0 + c, dr);
for (int r = m_r1 + 1; r <= r1; r++)
xsh->setCell(r, m_c0 + c, m_columns[c].generate(r));
if (isSoundColumn)
xsh->setCell(r, m_c0 + c, TXshCell());
else
xsh->setCell(r, m_c0 + c, m_columns[c].generate(r));
}
}
m_r1 = r1;
@ -779,7 +795,7 @@ public:
bool found = false;
for (int c = 0; c < m_colCount; c++) {
TXshColumn *column = xsh->getColumn(m_c0 + c);
if (!column || column->getSoundColumn()) continue;
if (!column) continue;
if (!column->isCellEmpty(emptyRow)) {
emptyRow += 1;
found = true;
@ -800,7 +816,7 @@ public:
// clear cells
for (int c = 0; c < m_colCount; c++) {
TXshColumn *column = xsh->getColumn(m_c0 + c);
if (!column || column->getSoundColumn()) continue;
if (!column) continue;
xsh->clearCells(m_r0, m_c0 + c, dr);
}
}
@ -808,9 +824,12 @@ public:
else {
for (int c = 0; c < m_colCount; c++) {
TXshColumn *column = xsh->getColumn(m_c0 + c);
if (!column || column->getSoundColumn()) continue;
bool isSoundColumn = (column && column->getSoundColumn());
for (int r = r0; r <= m_r0 - 1; r++) {
xsh->setCell(r, m_c0 + c, m_columns[c].generate(r));
if (isSoundColumn)
xsh->setCell(r, m_c0 + c, TXshCell());
else
xsh->setCell(r, m_c0 + c, m_columns[c].generate(r));
}
}
}
@ -832,6 +851,8 @@ public:
TUndoManager::manager()->add(m_undo);
TApp::instance()->getCurrentScene()->setDirtyFlag(true);
TApp::instance()->getCurrentXsheet()->notifyXsheetChanged();
if (m_refreshSound)
TApp::instance()->getCurrentXsheet()->notifyXsheetSoundChanged();
}
m_undo = 0;
}