Drawing Substitution - Works Now (#410)
* it works now * Added default menu position * Undo Fixed and Now Works with Whole Selections * Now works with ctrl to affect all sequential cells of the same drawing * Fixed undo * fixed mainwindow.cpp
This commit is contained in:
parent
b0c6a6c68f
commit
48def29a14
6 changed files with 268 additions and 2 deletions
|
@ -156,6 +156,8 @@
|
|||
<command>MI_Rollup</command>
|
||||
<command>MI_Rolldown</command>
|
||||
<command>MI_TimeStretch</command>
|
||||
<command>MI_DrawingSubForward</command>
|
||||
<command>MI_DrawingSubBackward</command>
|
||||
<separator/>
|
||||
<command>MI_Autorenumber</command>
|
||||
<command>MI_Duplicate</command>
|
||||
|
|
|
@ -1727,6 +1727,11 @@ void MainWindow::defineActions() {
|
|||
createMenuCellsAction(MI_Duplicate, tr("&Duplicate Drawing "), "D");
|
||||
createMenuCellsAction(MI_Autorenumber, tr("&Autorenumber"), "");
|
||||
createMenuCellsAction(MI_CloneLevel, tr("&Clone"), "");
|
||||
createMenuCellsAction(MI_DrawingSubForward, tr("Drawing Substitution Forward"), ".");
|
||||
createMenuCellsAction(MI_DrawingSubBackward, tr("Drawing Substitution Backward"), ",");
|
||||
createMenuCellsAction(MI_DrawingSubGroupForward, tr("Similar Drawing Substitution Forward"), "Ctrl+.");
|
||||
createMenuCellsAction(MI_DrawingSubGroupBackward, tr("Similar Drawing Substitution Backward"), "Ctrl+,");
|
||||
|
||||
|
||||
createMenuCellsAction(MI_Reframe1, tr("1's"), "");
|
||||
createMenuCellsAction(MI_Reframe2, tr("2's"), "");
|
||||
|
|
|
@ -1252,6 +1252,8 @@ QMenuBar *StackedMenuBar::createFullMenuBar() {
|
|||
addMenuItem(cellsMenu, MI_Rollup);
|
||||
addMenuItem(cellsMenu, MI_Rolldown);
|
||||
addMenuItem(cellsMenu, MI_TimeStretch);
|
||||
addMenuItem(xsheetMenu, MI_DrawingSubForward);
|
||||
addMenuItem(xsheetMenu, MI_DrawingSubBackward);
|
||||
cellsMenu->addSeparator();
|
||||
addMenuItem(cellsMenu, MI_Autorenumber);
|
||||
addMenuItem(cellsMenu, MI_Duplicate);
|
||||
|
|
|
@ -127,6 +127,10 @@
|
|||
|
||||
#define MI_InsertGlobalKeyframe "MI_InsertGlobalKeyframe"
|
||||
#define MI_RemoveGlobalKeyframe "MI_RemoveGlobalKeyframe"
|
||||
#define MI_DrawingSubForward "MI_DrawingSubForward"
|
||||
#define MI_DrawingSubBackward "MI_DrawingSubBackward"
|
||||
#define MI_DrawingSubGroupForward "MI_DrawingSubGroupForward"
|
||||
#define MI_DrawingSubGroupBackward "MI_DrawingSubGroupBackward"
|
||||
|
||||
#define MI_InsertFx "MI_InsertFx"
|
||||
#define MI_NewOutputFx "MI_NewOutputFx"
|
||||
|
|
|
@ -557,7 +557,259 @@ public:
|
|||
}
|
||||
} removeGlobalKeyframeCommand;
|
||||
|
||||
} // namespace XshCmd
|
||||
//============================================================
|
||||
// Drawing Substitution
|
||||
//============================================================
|
||||
class DrawingSubtitutionUndo : public TUndo {
|
||||
|
||||
private:
|
||||
int m_direction, m_row, m_col;
|
||||
TCellSelection::Range m_range;
|
||||
bool m_selected;
|
||||
|
||||
public:
|
||||
DrawingSubtitutionUndo(int dir, TCellSelection::Range range, int row, int col, bool selected)
|
||||
: m_direction(dir), m_range(range), m_row(row), m_col(col), m_selected(selected){}
|
||||
|
||||
void undo() const {
|
||||
if (!m_selected) {
|
||||
changeDrawing(-m_direction, m_row, m_col);
|
||||
return;
|
||||
}
|
||||
int col, row;
|
||||
int c = m_range.m_c0;
|
||||
int r = m_range.m_r0;
|
||||
while (c <= m_range.m_c1) {
|
||||
col = c;
|
||||
while (r <= m_range.m_r1) {
|
||||
row = r;
|
||||
changeDrawing(-m_direction, row, col);
|
||||
r++;
|
||||
}
|
||||
r = m_range.m_r0;
|
||||
c++;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void redo() const {
|
||||
if (!m_selected) {
|
||||
changeDrawing(m_direction, m_row, m_col);
|
||||
return;
|
||||
}
|
||||
|
||||
int col, row;
|
||||
int c = m_range.m_c0;
|
||||
int r = m_range.m_r0;
|
||||
while (c <= m_range.m_c1) {
|
||||
col = c;
|
||||
while (r <= m_range.m_r1) {
|
||||
row = r;
|
||||
changeDrawing(m_direction, row, col);
|
||||
r++;
|
||||
}
|
||||
r = m_range.m_r0;
|
||||
c++;
|
||||
}
|
||||
}
|
||||
|
||||
int getSize() const {
|
||||
return sizeof(*this);
|
||||
}
|
||||
|
||||
QString getHistoryString() {
|
||||
return QObject::tr("Change current drawing %1").arg(QString::number(m_direction));
|
||||
}
|
||||
|
||||
int getHistoryType() {
|
||||
return HistoryType::Xsheet;
|
||||
}
|
||||
protected:
|
||||
|
||||
static bool changeDrawing(int delta, int row, int col);
|
||||
static void setDrawing(const TFrameId &fid, int row, int col, TXshCell cell);
|
||||
friend class DrawingSubtitutionGroupUndo;
|
||||
};
|
||||
|
||||
//============================================================
|
||||
|
||||
class DrawingSubtitutionGroupUndo : public TUndo {
|
||||
|
||||
private:
|
||||
int m_direction;
|
||||
int m_row;
|
||||
int m_col;
|
||||
int m_count;
|
||||
|
||||
public:
|
||||
DrawingSubtitutionGroupUndo(int dir, int row, int col) : m_direction(dir), m_col(col), m_row(row)
|
||||
{
|
||||
m_count = 1;
|
||||
TXshCell cell = TTool::getApplication()->getCurrentScene()->getScene()->getXsheet()->getCell(m_row, m_col);
|
||||
if (!cell.m_level || !cell.m_level->getSimpleLevel()) return;
|
||||
|
||||
TFrameId id = cell.m_frameId;
|
||||
|
||||
TXshCell nextCell = TTool::getApplication()->getCurrentScene()->getScene()->getXsheet()->getCell(m_row + m_count, m_col);
|
||||
if (!nextCell.m_level || !nextCell.m_level->getSimpleLevel()) return;
|
||||
|
||||
TFrameId nextId = nextCell.m_frameId;
|
||||
|
||||
while (id == nextId) {
|
||||
m_count++;
|
||||
nextCell = TTool::getApplication()->getCurrentScene()->getScene()->getXsheet()->getCell(m_row + m_count, m_col);
|
||||
nextId = nextCell.m_frameId;
|
||||
}
|
||||
}
|
||||
|
||||
void undo() const {
|
||||
int n = 1;
|
||||
DrawingSubtitutionUndo::changeDrawing(-m_direction, m_row, m_col);
|
||||
while (n < m_count) {
|
||||
DrawingSubtitutionUndo::changeDrawing(-m_direction, m_row + n, m_col);
|
||||
n++;
|
||||
}
|
||||
}
|
||||
|
||||
void redo() const {
|
||||
int n = 1;
|
||||
DrawingSubtitutionUndo::changeDrawing(m_direction, m_row, m_col);
|
||||
while (n < m_count) {
|
||||
DrawingSubtitutionUndo::changeDrawing(m_direction, m_row + n, m_col);
|
||||
n++;
|
||||
}
|
||||
}
|
||||
|
||||
int getSize() const {
|
||||
return sizeof(*this);
|
||||
}
|
||||
|
||||
QString getHistoryString() {
|
||||
return QObject::tr("Change current drawing %1").arg(QString::number(m_direction));
|
||||
}
|
||||
|
||||
int getHistoryType() {
|
||||
return HistoryType::Xsheet;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
//============================================================
|
||||
|
||||
bool DrawingSubtitutionUndo::changeDrawing(int delta, int row, int col) {
|
||||
TTool::Application *app = TTool::getApplication();
|
||||
TXsheet *xsh = app->getCurrentScene()->getScene()->getXsheet();
|
||||
TXshCell cell = xsh->getCell(row, col);
|
||||
|
||||
if (!cell.m_level || !cell.m_level->getSimpleLevel()) return false;
|
||||
|
||||
std::vector<TFrameId> fids;
|
||||
cell.m_level->getSimpleLevel()->getFids(fids);
|
||||
int n = fids.size();
|
||||
|
||||
if (n < 2) return false;
|
||||
|
||||
std::vector<TFrameId>::iterator it;
|
||||
it = std::find(fids.begin(), fids.end(), cell.m_frameId);
|
||||
|
||||
if (it == fids.end()) return false;
|
||||
|
||||
int index = std::distance(fids.begin(), it);
|
||||
while (delta < 0) delta += n;
|
||||
index = (index + delta) % n;
|
||||
|
||||
setDrawing(fids[index], row, col, cell);
|
||||
|
||||
}
|
||||
|
||||
void DrawingSubtitutionUndo::setDrawing(const TFrameId &fid, int row, int col, TXshCell cell) {
|
||||
TTool::Application *app = TTool::getApplication();
|
||||
TXsheet *xsh = app->getCurrentScene()->getScene()->getXsheet();
|
||||
cell.m_frameId = fid;
|
||||
xsh->setCell(row, col, cell);
|
||||
TStageObject *pegbar = xsh->getStageObject(TStageObjectId::ColumnId(col));
|
||||
pegbar->setOffset(pegbar->getOffset());
|
||||
|
||||
app->getCurrentXsheet()->notifyXsheetChanged();
|
||||
TApp::instance()->getCurrentScene()->setDirtyFlag(true);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
void drawingSubstituion(int dir) {
|
||||
//TTool::Application *app = TTool::getApplication();
|
||||
//TCellSelection *selection = dynamic_cast<TCellSelection *>(app->getCurrentSelection()->getSelection());
|
||||
TCellSelection *selection = dynamic_cast<TCellSelection *>(TTool::getApplication()->getCurrentSelection()->getSelection());
|
||||
TCellSelection::Range range;
|
||||
bool selected = false;
|
||||
if (selection) {
|
||||
range = selection->getSelectedCells();
|
||||
if (!(range.isEmpty()))
|
||||
selected = true;
|
||||
}
|
||||
int row = TTool::getApplication()->getCurrentFrame()->getFrame();
|
||||
int col = TTool::getApplication()->getCurrentColumn()->getColumnIndex();
|
||||
|
||||
DrawingSubtitutionUndo *undo = new DrawingSubtitutionUndo(dir, range, row, col, selected);
|
||||
TUndoManager::manager()->add(undo);
|
||||
|
||||
undo->redo();
|
||||
}
|
||||
|
||||
void drawingSubstituionGroup(int dir) {
|
||||
int row = TTool::getApplication()->getCurrentFrame()->getFrame();
|
||||
int col = TTool::getApplication()->getCurrentColumn()->getColumnIndex();
|
||||
DrawingSubtitutionGroupUndo *undo = new DrawingSubtitutionGroupUndo(dir, row, col);
|
||||
TUndoManager::manager()->add(undo);
|
||||
undo->redo();
|
||||
}
|
||||
|
||||
//=============================================================================
|
||||
|
||||
class DrawingSubstitutionForwardCommand : public MenuItemHandler {
|
||||
public:
|
||||
DrawingSubstitutionForwardCommand() : MenuItemHandler(MI_DrawingSubForward) {}
|
||||
void execute() {
|
||||
XshCmd::drawingSubstituion(1);
|
||||
}
|
||||
} DrawingSubstitutionForwardCommand;
|
||||
|
||||
|
||||
//============================================================
|
||||
|
||||
class DrawingSubstitutionBackwardCommand : public MenuItemHandler {
|
||||
public:
|
||||
DrawingSubstitutionBackwardCommand() : MenuItemHandler(MI_DrawingSubBackward) {}
|
||||
void execute() {
|
||||
XshCmd::drawingSubstituion(-1);
|
||||
}
|
||||
} DrawingSubstitutionBackwardCommand;
|
||||
|
||||
//=============================================================================
|
||||
|
||||
class DrawingSubstitutionGroupForwardCommand : public MenuItemHandler {
|
||||
public:
|
||||
DrawingSubstitutionGroupForwardCommand() : MenuItemHandler(MI_DrawingSubGroupForward) {}
|
||||
void execute() {
|
||||
XshCmd::drawingSubstituionGroup(1);
|
||||
}
|
||||
} DrawingSubstitutionGroupForwardCommand;
|
||||
|
||||
|
||||
//============================================================
|
||||
|
||||
class DrawingSubstitutionGroupBackwardCommand : public MenuItemHandler {
|
||||
public:
|
||||
DrawingSubstitutionGroupBackwardCommand() : MenuItemHandler(MI_DrawingSubGroupBackward) {}
|
||||
void execute() {
|
||||
XshCmd::drawingSubstituionGroup(-1);
|
||||
}
|
||||
} DrawingSubstitutionGroupBackwardCommand;
|
||||
|
||||
|
||||
//============================================================
|
||||
|
||||
} // namespace XshCmd
|
||||
|
||||
//*****************************************************************************
|
||||
// Selection commands
|
||||
|
|
|
@ -707,7 +707,8 @@ void RowArea::contextMenuEvent(QContextMenuEvent *event) {
|
|||
menu->addAction(cmdManager->getAction(MI_RemoveSceneFrame));
|
||||
menu->addAction(cmdManager->getAction(MI_InsertGlobalKeyframe));
|
||||
menu->addAction(cmdManager->getAction(MI_RemoveGlobalKeyframe));
|
||||
|
||||
menu->addAction(cmdManager->getAction(MI_DrawingSubForward));
|
||||
menu->addAction(cmdManager->getAction(MI_DrawingSubBackward));
|
||||
menu->addSeparator();
|
||||
menu->addAction(cmdManager->getAction(MI_ShiftTrace));
|
||||
menu->addAction(cmdManager->getAction(MI_EditShift));
|
||||
|
|
Loading…
Reference in a new issue