Default column names to 1st level name

This commit is contained in:
manongjohn 2022-03-24 18:13:19 -04:00
parent ccee82315f
commit 087394160d
8 changed files with 278 additions and 1 deletions

View file

@ -28,6 +28,8 @@
#include "toonz/mypaintbrushstyle.h"
#include "toonz/preferences.h"
#include "toonz/toonzfolders.h"
#include "toonz/tcolumnhandle.h"
#include "toonz/tstageobjectcmd.h"
// TnzCore includes
#include "tgl.h"
@ -656,6 +658,8 @@ void FullColorBrushTool::leftButtonUp(const TPointD &pos,
if (m_tileSet->getTileCount() > 0) {
delete m_tileSaver;
bool isEditingLevel = m_application->getCurrentFrame()->isEditingLevel();
if (!isEditingLevel) TUndoManager::manager()->beginBlock();
TTool::Application *app = TTool::getApplication();
TXshLevel *level = app->getCurrentLevel()->getLevel();
TXshSimpleLevelP simLevel = level->getSimpleLevel();
@ -664,6 +668,22 @@ void FullColorBrushTool::leftButtonUp(const TPointD &pos,
TUndoManager::manager()->add(new FullColorBrushUndo(
m_tileSet, simLevel.getPointer(), frameId, m_isFrameCreated, subras,
m_strokeRect.getP00()));
// Column name renamed to level name only if was originally empty
if (!isEditingLevel) {
int col = app->getCurrentColumn()->getColumnIndex();
TXshColumn *column = app->getCurrentXsheet()->getXsheet()->getColumn(col);
int r0, r1;
column->getRange(r0, r1);
if (r0 == r1) {
TStageObjectId columnId = TStageObjectId::ColumnId(col);
std::string columnName =
QString::fromStdWString(simLevel->getName()).toStdString();
TStageObjectCmd::rename(columnId, columnName, app->getCurrentXsheet());
}
TUndoManager::manager()->endBlock();
}
}
notifyImageChanged();

View file

@ -33,6 +33,8 @@
#include "tpixelutils.h"
#include "historytypes.h"
#include "toonzvectorbrushtool.h"
#include "toonz/tcolumnhandle.h"
#include "toonz/tstageobjectcmd.h"
#include "toonz/mypaintbrushstyle.h"
@ -1256,7 +1258,32 @@ public:
}
void leftButtonUp(const TPointD &p, const TMouseEvent &e) override {
if (!m_active) return;
bool isEditingLevel = m_application->getCurrentFrame()->isEditingLevel();
if (!isEditingLevel) TUndoManager::manager()->beginBlock();
if (m_primitive) m_primitive->leftButtonUp(p, e);
// Column name renamed to level name only if was originally empty
if (!isEditingLevel) {
int col = m_application->getCurrentColumn()->getColumnIndex();
TXshColumn *column =
m_application->getCurrentXsheet()->getXsheet()->getColumn(col);
int r0, r1;
column->getRange(r0, r1);
if (r0 == r1) {
TXshLevel *level = m_application->getCurrentLevel()->getLevel();
TXshSimpleLevelP simLevel = level->getSimpleLevel();
TStageObjectId columnId = TStageObjectId::ColumnId(col);
std::string columnName =
QString::fromStdWString(simLevel->getName()).toStdString();
TStageObjectCmd::rename(columnId, columnName,
m_application->getCurrentXsheet());
}
TUndoManager::manager()->endBlock();
}
invalidate();
}
void leftButtonDoubleClick(const TPointD &p, const TMouseEvent &e) override {

View file

@ -31,6 +31,7 @@
#include "toonz/tpalettehandle.h"
#include "toonz/mypaintbrushstyle.h"
#include "toonz/toonzfolders.h"
#include "toonz/tstageobjectcmd.h"
// TnzCore includes
#include "tstream.h"
@ -1859,6 +1860,9 @@ void ToonzRasterBrushTool::finishRasterBrush(const TPointD &pos,
TXshLevel *level = app->getCurrentLevel()->getLevel();
TXshSimpleLevelP simLevel = level->getSimpleLevel();
bool isEditingLevel = m_application->getCurrentFrame()->isEditingLevel();
if (!isEditingLevel) TUndoManager::manager()->beginBlock();
/*--
* Fidに対してUndoを記録する
* --*/
@ -2081,6 +2085,23 @@ void ToonzRasterBrushTool::finishRasterBrush(const TPointD &pos,
m_isFrameCreated, m_isLevelCreated, m_isStraight));
}
}
// Column name renamed to level name only if was originally empty
if (!isEditingLevel) {
int col = app->getCurrentColumn()->getColumnIndex();
TXshColumn *column = app->getCurrentXsheet()->getXsheet()->getColumn(col);
int r0, r1;
column->getRange(r0, r1);
if (r0 == r1) {
TStageObjectId columnId = TStageObjectId::ColumnId(col);
std::string columnName =
QString::fromStdWString(simLevel->getName()).toStdString();
TStageObjectCmd::rename(columnId, columnName, app->getCurrentXsheet());
}
TUndoManager::manager()->endBlock();
}
delete m_tileSaver;
m_isStraight = false;
m_oldPressure = -1.0;

View file

@ -30,6 +30,7 @@
#include "toonz/preferences.h"
#include "toonz/tonionskinmaskhandle.h"
#include "toonz/toonzfolders.h"
#include "toonz/tstageobjectcmd.h"
// TnzCore includes
#include "tstream.h"
@ -1145,6 +1146,10 @@ void ToonzVectorBrushTool::leftButtonUp(const TPointD &pos,
// autoclose proprio dal fatto che
// hanno 1 solo chunk.
stroke->insertControlPoints(0.5);
bool isEditingLevel = m_application->getCurrentFrame()->isEditingLevel();
if (!isEditingLevel) TUndoManager::manager()->beginBlock();
if (m_frameRange.getIndex()) {
if (m_firstFrameId == -1) {
if (m_autoClose.getValue()) stroke->setSelfLoop(true);
@ -1250,6 +1255,28 @@ void ToonzVectorBrushTool::leftButtonUp(const TPointD &pos,
getApplication()->getCurrentFrame()->setFid(fId);
}
}
// Column name renamed to level name only if was originally empty
if (!isEditingLevel) {
int col = getApplication()->getCurrentColumn()->getColumnIndex();
TXshColumn *column =
getApplication()->getCurrentXsheet()->getXsheet()->getColumn(col);
int r0, r1;
column->getRange(r0, r1);
if (r0 == r1) {
TXshLevel *level = getApplication()->getCurrentLevel()->getLevel();
TXshSimpleLevelP simLevel = level->getSimpleLevel();
TStageObjectId columnId = TStageObjectId::ColumnId(col);
std::string columnName =
QString::fromStdWString(simLevel->getName()).toStdString();
TStageObjectCmd::rename(columnId, columnName,
getApplication()->getCurrentXsheet());
}
TUndoManager::manager()->endBlock();
}
assert(stroke);
m_track.clear();
m_toggleSnap = false;

View file

@ -24,6 +24,7 @@
#include "tregion.h"
#include "tvectorrenderdata.h"
#include "toonz/tpalettehandle.h"
#include "toonz/tcolumnhandle.h"
#include "toonzqt/selection.h"
#include "toonzqt/imageutils.h"
@ -31,6 +32,7 @@
#include "toonz/ttileset.h"
#include "toonz/glrasterpainter.h"
#include "toonz/stage.h"
#include "toonz/tstageobjectcmd.h"
#include "tfont.h"
@ -730,8 +732,32 @@ void TypeTool::stopEditing() {
m_preeditRange = std::make_pair(0, 0);
invalidate();
if (m_undo) {
bool isEditingLevel = getApplication()->getCurrentFrame()->isEditingLevel();
if (!isEditingLevel) TUndoManager::manager()->beginBlock();
TUndoManager::manager()->add(m_undo);
m_undo = 0;
// Column name renamed to level name only if was originally empty
if (!isEditingLevel) {
int col = getApplication()->getCurrentColumn()->getColumnIndex();
TXshColumn *column =
getApplication()->getCurrentXsheet()->getXsheet()->getColumn(col);
int r0, r1;
column->getRange(r0, r1);
if (r0 == r1) {
TXshLevel *level = getApplication()->getCurrentLevel()->getLevel();
TXshSimpleLevelP simLevel = level->getSimpleLevel();
TStageObjectId columnId = TStageObjectId::ColumnId(col);
std::string columnName =
QString::fromStdWString(simLevel->getName()).toStdString();
TStageObjectCmd::rename(columnId, columnName,
getApplication()->getCurrentXsheet());
}
TUndoManager::manager()->endBlock();
}
}
}
@ -1209,6 +1235,9 @@ void TypeTool::addTextToImage() {
if (!vi && !ti && !ri) return;
bool isEditingLevel = getApplication()->getCurrentFrame()->isEditingLevel();
if (!isEditingLevel) TUndoManager::manager()->beginBlock();
if (vi) {
QMutexLocker lock(vi->getMutex());
std::vector<const TVectorImage *> images;
@ -1232,6 +1261,26 @@ void TypeTool::addTextToImage() {
else if (ri)
addTextToRasterImage(ri);
if (!isEditingLevel) {
int col = getApplication()->getCurrentColumn()->getColumnIndex();
TXshColumn *column =
getApplication()->getCurrentXsheet()->getXsheet()->getColumn(col);
int r0, r1;
column->getRange(r0, r1);
if (r0 == r1) {
TXshLevel *level = getApplication()->getCurrentLevel()->getLevel();
TXshSimpleLevelP simLevel = level->getSimpleLevel();
TStageObjectId columnId = TStageObjectId::ColumnId(column->getIndex());
std::string columnName =
QString::fromStdWString(simLevel->getName()).toStdString();
TStageObjectCmd::rename(columnId, columnName,
getApplication()->getCurrentXsheet());
}
TUndoManager::manager()->endBlock();
}
notifyImageChanged();
// getApplication()->notifyImageChanges();

View file

@ -59,6 +59,7 @@
#include "tools/rasterselection.h"
#include "tools/strokeselection.h"
#include "toonz/sceneproperties.h"
#include "toonz/tstageobjectcmd.h"
#include "toutputproperties.h"
// TnzCore includes
@ -1747,6 +1748,11 @@ static void pasteRasterImageInCell(int row, int col,
}
createdFrame = true;
}
TStageObjectId columnId = TStageObjectId::ColumnId(col);
TXshColumn *column = xsh->getColumn(columnId.getIndex());
bool wasColumnEmpty = !column ? true : column->isEmpty();
// get the current cell
TXshCell cell = xsh->getCell(row, col);
// if the cell doesn't have a level. . .
@ -1793,6 +1799,14 @@ static void pasteRasterImageInCell(int row, int col,
rasterImageData, fullColorTiles, cell.getSimpleLevel(),
cell.getFrameId(), oldPalette, createdFrame, isLevelCreated, col));
}
// Column name renamed to level name only if was originally empty
if (wasColumnEmpty) {
std::string columnName =
QString::fromStdWString(cell.getSimpleLevel()->getName()).toStdString();
TStageObjectCmd::rename(columnId, columnName,
TApp::instance()->getCurrentXsheet());
}
}
//-----------------------------------------------------------------------------
@ -1863,7 +1877,7 @@ void TCellSelection::pasteCells() {
int newCr0, newCr1;
column->getRange(newCr0, newCr1);
areColumnsEmpty.push_back(!column || column->isEmpty() ||
(newCr0 == r0 && newCr1 == r1));
(newCr0 >= r0 && newCr1 <= r1));
}
if (!isPaste) return;
@ -1879,6 +1893,25 @@ void TCellSelection::pasteCells() {
TUndoManager::manager()->add(new PasteCellsUndo(
r0, c0, r1, c1, oldR0, oldC0, oldR1, oldC1, areColumnsEmpty));
TApp::instance()->getCurrentScene()->setDirtyFlag(true);
// Column name renamed to level name only if was originally empty
int x = 0;
for (c = c0; c <= c1; c++, x++) {
if (!areColumnsEmpty[x]) continue;
TXshColumn *column = xsh->getColumn(c);
if (!column || column->isEmpty()) continue;
int lr0, lr1;
column->getRange(lr0, lr1);
TStageObjectId columnId = TStageObjectId::ColumnId(c);
std::string columnName =
QString::fromStdWString(column->getCellColumn()
->getCell(lr0)
.m_level.getPointer()
->getName())
.toStdString();
TStageObjectCmd::rename(columnId, columnName,
TApp::instance()->getCurrentXsheet());
}
}
const TKeyframeData *keyframeData =
@ -2818,10 +2851,25 @@ void TCellSelection::createBlankDrawing(int row, int col, bool multiple) {
TPalette *palette = sl->getPalette();
TFrameId frame = cell.getFrameId();
TUndoManager::manager()->beginBlock();
CreateBlankDrawingUndo *undo = new CreateBlankDrawingUndo(
sl, frame, toolHandle->getTool()->m_isLevelCreated, palette);
TUndoManager::manager()->add(undo);
// Column name renamed to level name only if was originally empty
int r0, r1;
xsh->getCellRange(col, r0, r1);
if (r0 == r1) {
TStageObjectId columnId = TStageObjectId::ColumnId(col);
std::string columnName =
QString::fromStdWString(sl->getName()).toStdString();
TStageObjectCmd::rename(columnId, columnName,
TApp::instance()->getCurrentXsheet());
}
TUndoManager::manager()->endBlock();
IconGenerator::instance()->invalidate(sl, frame);
//----- Restore previous states of autocreation

View file

@ -66,6 +66,7 @@
#include "toutputproperties.h"
#include "toonz/studiopalette.h"
#include "toonz/tpalettehandle.h"
#include "toonz/tstageobjectcmd.h"
// TnzCore includes
#include "tofflinegl.h"
@ -579,12 +580,22 @@ TXshLevel *loadPalette(ToonzScene *scene, TFilePath actualPath,
xsh->setCell(row, col, cell);
xsh->updateFrameCount();
// Undo
TUndoManager::manager()->beginBlock();
LoadLevelUndo *undo = new LoadLevelUndo();
undo->setLevel(level);
undo->setLevelSetFolder(castFolder);
undo->setCells(scene->getXsheet(), row, col, 1);
undo->setColumnInserted(true);
TUndoManager::manager()->add(undo);
// Column name renamed to level name only if was originally empty
TStageObjectId columnId = TStageObjectId::ColumnId(col);
std::string columnName =
QString::fromStdWString(level->getName()).toStdString();
TStageObjectCmd::rename(columnId, columnName,
TApp::instance()->getCurrentXsheet());
TUndoManager::manager()->endBlock();
return level;
}
@ -878,6 +889,26 @@ TXshLevel *loadChildLevel(ToonzScene *parentScene, TFilePath actualPath,
for (int i = 0; i < parentScene->getLevelSet()->getLevelCount(); i++)
parentScene->getLevelSet()->getLevel(i)->setScene(parentScene);
// Column name renamed to level name only if was originally empty
bool wasColumnEmpty = shiftColumn;
if (!wasColumnEmpty) {
TXshColumn *column = parentXsh->getColumn(col);
int r0, r1;
column->getRange(r0, r1);
if ((r1 - r0 + 1) == frameCount) wasColumnEmpty = true;
}
if (wasColumnEmpty) {
TStageObjectId columnId = TStageObjectId::ColumnId(col);
std::string columnName =
QString::fromStdWString(childLevel->getName()).toStdString();
TStageObjectCmd::rename(columnId, columnName,
TApp::instance()->getCurrentXsheet());
// For now, let's remove the rename undo since loading child level is not
// undoable
TUndoManager::manager()->popUndo();
}
// Inform the cache fx command that a scene was loaded
CacheFxCommand::instance()->onSceneLoaded();
@ -983,6 +1014,7 @@ TXshLevel *loadLevel(ToonzScene *scene,
}
}
// if the level can be obtained (from scene cast or file)
bool wasColumnEmpty = false;
if (xl) {
// placing in the xsheet
if (expose) {
@ -993,6 +1025,8 @@ TXshLevel *loadLevel(ToonzScene *scene,
undo->setIsFirstTime(isFirstTime);
}
TUndoManager::manager()->beginBlock();
int levelType = xl->getType();
TXshColumn::ColumnType newLevelColumnType =
TXshColumn::toColumnType(levelType);
@ -1008,6 +1042,14 @@ TXshLevel *loadLevel(ToonzScene *scene,
else
undo->setCells(scene->getXsheet(), row0, col0, xl->getFrameCount());
undo->setColumnInserted(columnInserted);
wasColumnEmpty = columnInserted;
if (!wasColumnEmpty) {
TXshColumn *column = xsh->getColumn(col0);
int r0, r1;
column->getRange(r0, r1);
if ((r1 - r0 + 1) == xl->getFrameCount()) wasColumnEmpty = true;
}
}
if (row1 != -1 || col1 != -1)
replaceUndo = new LoadAndReplaceLevelUndo(xl->getSimpleLevel(), row0,
@ -1018,6 +1060,18 @@ TXshLevel *loadLevel(ToonzScene *scene,
if (replaceUndo) TUndoManager::manager()->add(replaceUndo);
// Column name renamed to level name only if was originally empty
if (expose) {
if (wasColumnEmpty) {
TStageObjectId columnId = TStageObjectId::ColumnId(col0);
std::string columnName =
QString::fromStdWString(xl->getName()).toStdString();
TStageObjectCmd::rename(columnId, columnName,
TApp::instance()->getCurrentXsheet());
}
TUndoManager::manager()->endBlock();
}
return xl;
}
@ -2642,11 +2696,31 @@ bool IoCmd::exposeLevel(TXshSimpleLevel *sl, int row, int col,
ExposeType type = eNone;
if (insert) type = eShiftCells;
if (overWrite) type = eOverWrite;
TUndoManager::manager()->beginBlock();
ExposeLevelUndo *undo =
new ExposeLevelUndo(sl, row, col, frameCount, insertEmptyColumn, type);
xsh->exposeLevel(row, col, sl, fids, overWrite);
undo->setFids(fids);
TUndoManager::manager()->add(undo);
// Column name renamed to level name only if was originally empty
bool wasColumnEmpty = insertEmptyColumn;
if (!wasColumnEmpty) {
TXshColumn *column = xsh->getColumn(col);
int r0, r1;
column->getRange(r0, r1);
if ((r1 - r0 + 1) == fids.size()) wasColumnEmpty = true;
}
if (wasColumnEmpty) {
TStageObjectId columnId = TStageObjectId::ColumnId(col);
std::string columnName =
QString::fromStdWString(sl->getName()).toStdString();
TStageObjectCmd::rename(columnId, columnName, app->getCurrentXsheet());
}
TUndoManager::manager()->endBlock();
app->getCurrentXsheet()->notifyXsheetChanged();
return true;
}

View file

@ -37,6 +37,7 @@
#include "toonz/tproject.h"
#include "toonz/namebuilder.h"
#include "toonz/childstack.h"
#include "toonz/tstageobjectcmd.h"
#include "toutputproperties.h"
// TnzCore includes
@ -638,6 +639,10 @@ bool LevelCreatePopup::apply() {
scene->createNewLevel(lType, levelName, TDimension(), 0, fp);
TXshSimpleLevel *sl = dynamic_cast<TXshSimpleLevel *>(level);
TStageObjectId columnId = TStageObjectId::ColumnId(col);
TXshColumn *column = xsh->getColumn(columnId.getIndex());
bool wasColumnEmpty = !column ? true : column->isEmpty();
assert(sl);
// sl->setPath(fp, true);
if (lType == TZP_XSHLEVEL || lType == OVL_XSHLEVEL) {
@ -684,6 +689,12 @@ bool LevelCreatePopup::apply() {
undo->onAdd(sl);
// Column name renamed to level name only if was originally empty
if (wasColumnEmpty) {
std::string columnName = QString::fromStdWString(levelName).toStdString();
TStageObjectCmd::rename(columnId, columnName, app->getCurrentXsheet());
}
TUndoManager::manager()->endBlock();
app->getCurrentScene()->notifySceneChanged();