|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#include "toonz/studiopalettecmd.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "toonz/tpalettehandle.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "toonz/txsheethandle.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "toonz/txshlevelhandle.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "tundo.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "tcolorstyles.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "tsystem.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "tconvert.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "ttoonzimage.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "timagecache.h"
|
|
shun-iwasawa |
ff99e1 |
#include "tmsgcore.h"
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#include "toonz/studiopalette.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "toonz/toonzscene.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "toonz/levelset.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "toonz/txshsimplelevel.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "toonz/txshleveltypes.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "toonz/sceneproperties.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "toonz/toonzfolders.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "toonz/txsheet.h"
|
|
Campbell Barton |
d0e335 |
#include <qapplication></qapplication>
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#include "historytypes.h"
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/*! \namespace StudioPaletteCmd
|
|
Shinya Kitaoka |
120a6e |
\brief Provides a collection of methods to manage \b
|
|
Shinya Kitaoka |
120a6e |
StudioPalette.
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//=============================================================================
|
|
Shinya Kitaoka |
120a6e |
namespace {
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
shun-iwasawa |
7f18c9 |
bool trySetStudioPalette(const TFilePath &palettePath, const TPalette *plt,
|
|
shun-iwasawa |
7f18c9 |
bool notifyPaletteChanged) {
|
|
shun-iwasawa |
7f18c9 |
try {
|
|
shun-iwasawa |
7f18c9 |
StudioPalette::instance()->setPalette(palettePath, plt,
|
|
shun-iwasawa |
7f18c9 |
notifyPaletteChanged);
|
|
shun-iwasawa |
7f18c9 |
} catch (TSystemException se) {
|
|
shun-iwasawa |
7f18c9 |
DVGui::warning(QString::fromStdWString(se.getMessage()));
|
|
shun-iwasawa |
7f18c9 |
return false;
|
|
shun-iwasawa |
7f18c9 |
} catch (...) {
|
|
shun-iwasawa |
7f18c9 |
DVGui::warning(
|
|
shun-iwasawa |
7f18c9 |
QString::fromStdWString(palettePath.getWideString() + L"\n") +
|
|
shun-iwasawa |
7f18c9 |
QObject::tr("Failed to save palette."));
|
|
shun-iwasawa |
7f18c9 |
return false;
|
|
shun-iwasawa |
7f18c9 |
}
|
|
shun-iwasawa |
7f18c9 |
return true;
|
|
shun-iwasawa |
7f18c9 |
}
|
|
shun-iwasawa |
7f18c9 |
|
|
Toshihiro Shimizu |
890ddd |
//=============================================================================
|
|
Shinya Kitaoka |
120a6e |
// PaletteAssignUndo : Undo for the "Load into Current Palette" command.
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
d1f6c4 |
class PaletteAssignUndo final : public TUndo {
|
|
Shinya Kitaoka |
120a6e |
TPaletteP m_targetPalette, m_oldPalette, m_newPalette;
|
|
Shinya Kitaoka |
120a6e |
TPaletteHandle *m_paletteHandle;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
public:
|
|
Shinya Kitaoka |
120a6e |
PaletteAssignUndo(const TPaletteP &targetPalette, const TPaletteP &oldPalette,
|
|
Shinya Kitaoka |
120a6e |
const TPaletteP &newPalette, TPaletteHandle *paletteHandle)
|
|
Shinya Kitaoka |
120a6e |
: m_targetPalette(targetPalette)
|
|
Shinya Kitaoka |
120a6e |
, m_oldPalette(oldPalette)
|
|
Shinya Kitaoka |
120a6e |
, m_newPalette(newPalette)
|
|
Shinya Kitaoka |
120a6e |
, m_paletteHandle(paletteHandle) {}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
473e70 |
void undo() const override {
|
|
Shinya Kitaoka |
120a6e |
m_targetPalette->assign(m_oldPalette.getPointer());
|
|
Shinya Kitaoka |
120a6e |
m_paletteHandle->notifyPaletteChanged();
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
473e70 |
void redo() const override {
|
|
Shinya Kitaoka |
120a6e |
m_targetPalette->assign(m_newPalette.getPointer());
|
|
Shinya Kitaoka |
120a6e |
m_paletteHandle->notifyPaletteChanged();
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
473e70 |
int getSize() const override {
|
|
Shinya Kitaoka |
120a6e |
return sizeof(*this) +
|
|
Shinya Kitaoka |
120a6e |
(m_targetPalette->getStyleCount() + m_oldPalette->getStyleCount() +
|
|
Shinya Kitaoka |
120a6e |
m_newPalette->getStyleCount()) *
|
|
Shinya Kitaoka |
120a6e |
100;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
473e70 |
QString getHistoryString() override {
|
|
Shinya Kitaoka |
120a6e |
return QObject::tr("Load into Current Palette > %1")
|
|
Shinya Kitaoka |
120a6e |
.arg(QString::fromStdWString(m_targetPalette->getPaletteName()));
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
473e70 |
int getHistoryType() override { return HistoryType::Palette; }
|
|
Toshihiro Shimizu |
890ddd |
};
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//=============================================================================
|
|
Shinya Kitaoka |
120a6e |
// StudioPaletteAssignUndo : Undo for the "Replace with Current Palette"
|
|
Shinya Kitaoka |
120a6e |
// command.
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
d1f6c4 |
class StudioPaletteAssignUndo final : public TUndo {
|
|
Shinya Kitaoka |
120a6e |
TPaletteP m_oldPalette, m_newPalette;
|
|
Shinya Kitaoka |
120a6e |
TFilePath m_fp;
|
|
Shinya Kitaoka |
120a6e |
TPaletteHandle *m_paletteHandle;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
public:
|
|
Shinya Kitaoka |
120a6e |
StudioPaletteAssignUndo(const TFilePath &targetPath,
|
|
Shinya Kitaoka |
120a6e |
const TPaletteP &oldPalette,
|
|
Shinya Kitaoka |
120a6e |
const TPaletteP &newPalette,
|
|
Shinya Kitaoka |
120a6e |
TPaletteHandle *paletteHandle)
|
|
Shinya Kitaoka |
120a6e |
: m_fp(targetPath)
|
|
Shinya Kitaoka |
120a6e |
, m_oldPalette(oldPalette)
|
|
Shinya Kitaoka |
120a6e |
, m_newPalette(newPalette)
|
|
Shinya Kitaoka |
120a6e |
, m_paletteHandle(paletteHandle) {}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
473e70 |
void undo() const override {
|
|
shun-iwasawa |
7f18c9 |
trySetStudioPalette(m_fp, m_oldPalette.getPointer(), true);
|
|
Shinya Kitaoka |
120a6e |
m_paletteHandle->notifyPaletteChanged();
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
473e70 |
void redo() const override {
|
|
shun-iwasawa |
7f18c9 |
trySetStudioPalette(m_fp, m_newPalette.getPointer(), true);
|
|
Shinya Kitaoka |
120a6e |
m_paletteHandle->notifyPaletteChanged();
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
473e70 |
int getSize() const override {
|
|
Shinya Kitaoka |
120a6e |
return sizeof(*this) +
|
|
Shinya Kitaoka |
120a6e |
(m_oldPalette->getStyleCount() + m_newPalette->getStyleCount()) *
|
|
Shinya Kitaoka |
120a6e |
100;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
473e70 |
QString getHistoryString() override {
|
|
Shinya Kitaoka |
120a6e |
return QObject::tr("Replace with Current Palette > %1")
|
|
Shinya Kitaoka |
120a6e |
.arg(QString::fromStdString(m_fp.getLevelName()));
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
473e70 |
int getHistoryType() override { return HistoryType::Palette; }
|
|
Toshihiro Shimizu |
890ddd |
};
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//=============================================================================
|
|
Shinya Kitaoka |
120a6e |
// DeletePaletteUndo
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
d1f6c4 |
class DeletePaletteUndo final : public TUndo {
|
|
Shinya Kitaoka |
120a6e |
TFilePath m_palettePath;
|
|
Shinya Kitaoka |
120a6e |
TPaletteP m_palette;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
public:
|
|
Shinya Kitaoka |
120a6e |
DeletePaletteUndo(const TFilePath &palettePath) : m_palettePath(palettePath) {
|
|
Shinya Kitaoka |
120a6e |
m_palette = StudioPalette::instance()->getPalette(m_palettePath);
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
473e70 |
void undo() const override {
|
|
shun-iwasawa |
7f18c9 |
trySetStudioPalette(m_palettePath, m_palette->clone(), true);
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
38fd86 |
void redo() const override {
|
|
Shinya Kitaoka |
38fd86 |
StudioPalette::instance()->deletePalette(m_palettePath);
|
|
Shinya Kitaoka |
38fd86 |
}
|
|
Shinya Kitaoka |
473e70 |
int getSize() const override { return sizeof(*this) + sizeof(TPalette); }
|
|
Shinya Kitaoka |
473e70 |
QString getHistoryString() override {
|
|
Shinya Kitaoka |
120a6e |
return QObject::tr("Delete Studio Palette : %1")
|
|
Shinya Kitaoka |
120a6e |
.arg(QString::fromStdString(m_palettePath.getLevelName()));
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
473e70 |
int getHistoryType() override { return HistoryType::Palette; }
|
|
Toshihiro Shimizu |
890ddd |
};
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//=============================================================================
|
|
Shinya Kitaoka |
120a6e |
// CreatePaletteUndo
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
d1f6c4 |
class CreatePaletteUndo final : public TUndo {
|
|
Shinya Kitaoka |
120a6e |
TFilePath m_palettePath;
|
|
Shinya Kitaoka |
120a6e |
TPaletteP m_palette;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
public:
|
|
Shinya Kitaoka |
120a6e |
CreatePaletteUndo(const TFilePath &palettePath) : m_palettePath(palettePath) {
|
|
Shinya Kitaoka |
120a6e |
m_palette = StudioPalette::instance()->getPalette(m_palettePath);
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
38fd86 |
void undo() const override {
|
|
Shinya Kitaoka |
38fd86 |
StudioPalette::instance()->deletePalette(m_palettePath);
|
|
Shinya Kitaoka |
38fd86 |
}
|
|
Shinya Kitaoka |
473e70 |
void redo() const override {
|
|
shun-iwasawa |
7f18c9 |
trySetStudioPalette(m_palettePath, m_palette->clone(), true);
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
473e70 |
int getSize() const override { return sizeof(*this) + sizeof(TPalette); }
|
|
Shinya Kitaoka |
473e70 |
QString getHistoryString() override {
|
|
Shinya Kitaoka |
120a6e |
return QObject::tr("Create Studio Palette : %1")
|
|
Shinya Kitaoka |
120a6e |
.arg(QString::fromStdString(m_palettePath.getLevelName()));
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
473e70 |
int getHistoryType() override { return HistoryType::Palette; }
|
|
Toshihiro Shimizu |
890ddd |
};
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//=============================================================================
|
|
Shinya Kitaoka |
120a6e |
// DeleteFolderUndo
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
d1f6c4 |
class DeleteFolderUndo final : public TUndo {
|
|
Shinya Kitaoka |
120a6e |
TFilePath m_path;
|
|
Shinya Kitaoka |
120a6e |
TFilePathSet m_pathSet;
|
|
Shinya Kitaoka |
120a6e |
QList<tpalettep> m_paletteList;</tpalettep>
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
public:
|
|
Shinya Kitaoka |
120a6e |
DeleteFolderUndo(const TFilePath &path, const TFilePathSet &pathSet)
|
|
Shinya Kitaoka |
120a6e |
: m_path(path), m_pathSet(pathSet), m_paletteList() {
|
|
Shinya Kitaoka |
120a6e |
for (TFilePathSet::const_iterator it = m_pathSet.begin();
|
|
Shinya Kitaoka |
120a6e |
it != m_pathSet.end(); it++) {
|
|
Shinya Kitaoka |
120a6e |
TFilePath path = *it;
|
|
Shinya Kitaoka |
120a6e |
if (path.getType() == "tpl")
|
|
Shinya Kitaoka |
120a6e |
m_paletteList.push_back(StudioPalette::instance()->getPalette(path));
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
473e70 |
void undo() const override {
|
|
Shinya Kitaoka |
120a6e |
StudioPalette::instance()->createFolder(m_path.getParentDir(),
|
|
Shinya Kitaoka |
120a6e |
m_path.getWideName());
|
|
Shinya Kitaoka |
120a6e |
int paletteCount = -1;
|
|
Shinya Kitaoka |
120a6e |
for (TFilePathSet::const_iterator it = m_pathSet.begin();
|
|
Shinya Kitaoka |
120a6e |
it != m_pathSet.end(); it++) {
|
|
Shinya Kitaoka |
120a6e |
TFilePath path = *it;
|
|
Shinya Kitaoka |
120a6e |
if (path.getType() == "tpl") // Is a palette
|
|
shun-iwasawa |
7f18c9 |
trySetStudioPalette(path, m_paletteList.at(++paletteCount)->clone(),
|
|
shun-iwasawa |
7f18c9 |
true);
|
|
Shinya Kitaoka |
120a6e |
else // Is a folder
|
|
Shinya Kitaoka |
120a6e |
StudioPalette::instance()->createFolder(path.getParentDir(),
|
|
Shinya Kitaoka |
120a6e |
path.getWideName());
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
38fd86 |
void redo() const override {
|
|
Shinya Kitaoka |
38fd86 |
StudioPalette::instance()->deleteFolder(m_path);
|
|
Shinya Kitaoka |
38fd86 |
}
|
|
Shinya Kitaoka |
473e70 |
int getSize() const override { return sizeof(*this) + sizeof(TPalette); }
|
|
Shinya Kitaoka |
473e70 |
QString getHistoryString() override {
|
|
Shinya Kitaoka |
120a6e |
return QObject::tr("Delete Studio Palette Folder : %1")
|
|
Shinya Kitaoka |
120a6e |
.arg(QString::fromStdString(m_path.getName()));
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
473e70 |
int getHistoryType() override { return HistoryType::Palette; }
|
|
Toshihiro Shimizu |
890ddd |
};
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//=============================================================================
|
|
Shinya Kitaoka |
120a6e |
// CreateFolderUndo
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
d1f6c4 |
class CreateFolderUndo final : public TUndo {
|
|
Shinya Kitaoka |
120a6e |
TFilePath m_folderPath;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
public:
|
|
Shinya Kitaoka |
120a6e |
CreateFolderUndo(const TFilePath &folderPath) : m_folderPath(folderPath) {}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
38fd86 |
void undo() const override {
|
|
Shinya Kitaoka |
38fd86 |
StudioPalette::instance()->deleteFolder(m_folderPath);
|
|
Shinya Kitaoka |
38fd86 |
}
|
|
Shinya Kitaoka |
473e70 |
void redo() const override {
|
|
Shinya Kitaoka |
120a6e |
StudioPalette::instance()->createFolder(m_folderPath.getParentDir(),
|
|
Shinya Kitaoka |
120a6e |
m_folderPath.getWideName());
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
473e70 |
int getSize() const override { return sizeof(*this) + sizeof(TPalette); }
|
|
Shinya Kitaoka |
473e70 |
QString getHistoryString() override {
|
|
Shinya Kitaoka |
120a6e |
return QObject::tr("Create Studio Palette Folder : %1")
|
|
Shinya Kitaoka |
120a6e |
.arg(QString::fromStdString(m_folderPath.getName()));
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
473e70 |
int getHistoryType() override { return HistoryType::Palette; }
|
|
Toshihiro Shimizu |
890ddd |
};
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//=============================================================================
|
|
Shinya Kitaoka |
120a6e |
// MovePaletteUndo
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
d1f6c4 |
class MovePaletteUndo final : public TUndo {
|
|
Shinya Kitaoka |
120a6e |
TFilePath m_dstPath, m_srcPath;
|
|
shun-iwasawa |
ff99e1 |
bool m_isRename;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
public:
|
|
Shinya Kitaoka |
120a6e |
MovePaletteUndo(const TFilePath &dstPath, const TFilePath &srcPath)
|
|
shun-iwasawa |
ff99e1 |
: m_dstPath(dstPath), m_srcPath(srcPath) {
|
|
shun-iwasawa |
ff99e1 |
m_isRename = (m_srcPath.getParentDir() == m_dstPath.getParentDir());
|
|
shun-iwasawa |
ff99e1 |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
473e70 |
void undo() const override {
|
|
shun-iwasawa |
ff99e1 |
QString errorStr = (m_isRename) ? QObject::tr("Can't undo rename palette")
|
|
shun-iwasawa |
ff99e1 |
: QObject::tr("Can't undo move palette");
|
|
shun-iwasawa |
ff99e1 |
try {
|
|
shun-iwasawa |
ff99e1 |
StudioPalette::instance()->movePalette(m_srcPath, m_dstPath);
|
|
shun-iwasawa |
ff99e1 |
} catch (TException &e) {
|
|
shun-iwasawa |
ff99e1 |
DVGui::error(errorStr + " : " +
|
|
shun-iwasawa |
ff99e1 |
QString(::to_string(e.getMessage()).c_str()));
|
|
shun-iwasawa |
ff99e1 |
} catch (...) {
|
|
shun-iwasawa |
ff99e1 |
DVGui::error(errorStr);
|
|
shun-iwasawa |
ff99e1 |
}
|
|
Shinya Kitaoka |
120a6e |
}
|
|
shun-iwasawa |
ff99e1 |
|
|
Shinya Kitaoka |
473e70 |
void redo() const override {
|
|
shun-iwasawa |
ff99e1 |
QString errorStr = (m_isRename) ? QObject::tr("Can't redo rename palette")
|
|
shun-iwasawa |
ff99e1 |
: QObject::tr("Can't redo move palette");
|
|
shun-iwasawa |
ff99e1 |
try {
|
|
shun-iwasawa |
ff99e1 |
StudioPalette::instance()->movePalette(m_dstPath, m_srcPath);
|
|
shun-iwasawa |
ff99e1 |
} catch (TException &e) {
|
|
shun-iwasawa |
ff99e1 |
DVGui::error(errorStr + ":" +
|
|
shun-iwasawa |
ff99e1 |
QString(::to_string(e.getMessage()).c_str()));
|
|
shun-iwasawa |
ff99e1 |
} catch (...) {
|
|
shun-iwasawa |
ff99e1 |
DVGui::error(errorStr);
|
|
shun-iwasawa |
ff99e1 |
}
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
473e70 |
int getSize() const override { return sizeof(*this); }
|
|
Shinya Kitaoka |
473e70 |
QString getHistoryString() override {
|
|
shun-iwasawa |
ff99e1 |
if (m_isRename)
|
|
shun-iwasawa |
ff99e1 |
return QObject::tr("Rename Studio Palette : %1 > %2")
|
|
shun-iwasawa |
ff99e1 |
.arg(QString::fromStdString(m_srcPath.getName()))
|
|
shun-iwasawa |
ff99e1 |
.arg(QString::fromStdString(m_dstPath.getName()));
|
|
shun-iwasawa |
ff99e1 |
else
|
|
shun-iwasawa |
ff99e1 |
return QObject::tr("Move Studio Palette Folder : %1 : %2 > %3")
|
|
shun-iwasawa |
ff99e1 |
.arg(QString::fromStdString(m_srcPath.getName()))
|
|
shun-iwasawa |
ff99e1 |
.arg(QString::fromStdString(m_srcPath.getParentDir().getName()))
|
|
shun-iwasawa |
ff99e1 |
.arg(QString::fromStdString(m_dstPath.getParentDir().getName()));
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
473e70 |
int getHistoryType() override { return HistoryType::Palette; }
|
|
Toshihiro Shimizu |
890ddd |
};
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-------------------------------------------------------------
|
|
Shinya Kitaoka |
120a6e |
void adaptLevelToPalette(TXshLevelHandle *currentLevelHandle,
|
|
Shinya Kitaoka |
120a6e |
TPaletteHandle *paletteHandle, TPalette *plt,
|
|
Shinya Kitaoka |
120a6e |
int tolerance, bool noUndo);
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
d1f6c4 |
class AdjustIntoCurrentPaletteUndo final : public TUndo {
|
|
Shinya Kitaoka |
120a6e |
TXshLevelHandle *m_currentLevelHandle;
|
|
Shinya Kitaoka |
120a6e |
TPaletteHandle *m_paletteHandle;
|
|
Shinya Kitaoka |
120a6e |
TPaletteP m_oldPalette, m_newPalette;
|
|
Shinya Kitaoka |
120a6e |
TFrameId m_fid;
|
|
Shinya Kitaoka |
120a6e |
std::string m_oldImageId;
|
|
Shinya Kitaoka |
120a6e |
static int m_idCount;
|
|
Shinya Kitaoka |
120a6e |
int m_undoSize;
|
|
Shinya Kitaoka |
120a6e |
int m_tolerance;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
public:
|
|
Shinya Kitaoka |
120a6e |
AdjustIntoCurrentPaletteUndo(TXshLevelHandle *currentLevelHandle,
|
|
Shinya Kitaoka |
120a6e |
TPaletteHandle *paletteHandle,
|
|
Shinya Kitaoka |
120a6e |
const TFrameId &fid, const TImageP &oldImage,
|
|
Shinya Kitaoka |
120a6e |
const TPaletteP &oldPalette,
|
|
Shinya Kitaoka |
120a6e |
const TPaletteP &newPalette, int tolerance)
|
|
Shinya Kitaoka |
120a6e |
: TUndo()
|
|
Shinya Kitaoka |
120a6e |
, m_currentLevelHandle(currentLevelHandle)
|
|
Shinya Kitaoka |
120a6e |
, m_paletteHandle(paletteHandle)
|
|
Shinya Kitaoka |
120a6e |
, m_fid(fid)
|
|
Shinya Kitaoka |
120a6e |
, m_oldPalette(oldPalette)
|
|
Shinya Kitaoka |
120a6e |
, m_newPalette(newPalette)
|
|
Shinya Kitaoka |
120a6e |
, m_tolerance(tolerance) {
|
|
Shinya Kitaoka |
120a6e |
m_oldImageId =
|
|
Shinya Kitaoka |
120a6e |
"AdjustIntoCurrentPaletteUndo_oldImage_" + std::to_string(m_idCount++);
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
TImageCache::instance()->add(m_oldImageId, (const TImageP)oldImage);
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
m_undoSize = ((TToonzImageP)oldImage)->getRaster()->getLx() *
|
|
Shinya Kitaoka |
120a6e |
((TToonzImageP)oldImage)->getRaster()->getLy() *
|
|
Shinya Kitaoka |
120a6e |
((TToonzImageP)oldImage)->getRaster()->getPixelSize();
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
~AdjustIntoCurrentPaletteUndo() {
|
|
Shinya Kitaoka |
120a6e |
TImageCache::instance()->remove(m_oldImageId);
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
473e70 |
void undo() const override {
|
|
Shinya Kitaoka |
120a6e |
TImageP img = TImageCache::instance()->get(m_oldImageId, true);
|
|
Shinya Kitaoka |
120a6e |
TXshSimpleLevel *level = m_currentLevelHandle->getSimpleLevel();
|
|
Shinya Kitaoka |
120a6e |
level->setPalette(m_oldPalette.getPointer());
|
|
Shinya Kitaoka |
120a6e |
// img->setPalette(m_oldPalette.getPointer());
|
|
Shinya Kitaoka |
120a6e |
level->setFrame(m_fid, img->cloneImage());
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
level->touchFrame(m_fid);
|
|
Shinya Kitaoka |
120a6e |
if (level->getFirstFid() == m_fid) {
|
|
Shinya Kitaoka |
120a6e |
m_currentLevelHandle->notifyLevelChange();
|
|
Shinya Kitaoka |
120a6e |
m_paletteHandle->setPalette(m_oldPalette.getPointer());
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
m_oldPalette->setDirtyFlag(true);
|
|
Shinya Kitaoka |
120a6e |
m_paletteHandle->notifyPaletteChanged();
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
473e70 |
void redo() const override {
|
|
Shinya Kitaoka |
120a6e |
adaptLevelToPalette(m_currentLevelHandle, m_paletteHandle,
|
|
Shinya Kitaoka |
120a6e |
m_newPalette.getPointer(), m_tolerance, true);
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
473e70 |
int getSize() const override { return m_undoSize; }
|
|
Toshihiro Shimizu |
890ddd |
};
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
int AdjustIntoCurrentPaletteUndo::m_idCount = 0;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Shinya Kitaoka |
120a6e |
} // namespace
|
|
Toshihiro Shimizu |
890ddd |
//=============================================================================
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void StudioPaletteCmd::loadIntoCurrentPalette(TPaletteHandle *paletteHandle,
|
|
Shinya Kitaoka |
120a6e |
const TFilePath &fp) {
|
|
Shinya Kitaoka |
120a6e |
TPalette *palette = StudioPalette::instance()->getPalette(fp, false);
|
|
Shinya Kitaoka |
120a6e |
if (!palette) return;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
loadIntoCurrentPalette(paletteHandle, palette);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Shinya Kitaoka |
120a6e |
namespace {
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
3bfa54 |
std::map<tpixel, int=""> ToleranceMap;</tpixel,>
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
int findClosest(const TPixel &color, std::map<tpixel, int=""> &colorMap,</tpixel,>
|
|
Shinya Kitaoka |
120a6e |
int tolerance) {
|
|
Shinya Kitaoka |
120a6e |
std::map<tpixel, int="">::const_iterator it;</tpixel,>
|
|
Shinya Kitaoka |
120a6e |
it = ToleranceMap.find(color);
|
|
Shinya Kitaoka |
120a6e |
if (it != ToleranceMap.end()) return it->second;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
tolerance *= tolerance;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
it = colorMap.begin();
|
|
Shinya Kitaoka |
120a6e |
int index = -1, minDist = 99999999;
|
|
Shinya Kitaoka |
120a6e |
int dr, dg, db, dm;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
for (; it != colorMap.end(); ++it) {
|
|
Shinya Kitaoka |
120a6e |
if ((dr = (color.r - it->first.r) * (color.r - it->first.r)) > tolerance)
|
|
Shinya Kitaoka |
120a6e |
continue;
|
|
Shinya Kitaoka |
120a6e |
if ((dg = (color.g - it->first.g) * (color.g - it->first.g)) > tolerance)
|
|
Shinya Kitaoka |
120a6e |
continue;
|
|
Shinya Kitaoka |
120a6e |
if ((db = (color.b - it->first.b) * (color.b - it->first.b)) > tolerance)
|
|
Shinya Kitaoka |
120a6e |
continue;
|
|
Shinya Kitaoka |
120a6e |
if ((dm = (color.m - it->first.m) * (color.m - it->first.m)) > tolerance)
|
|
Shinya Kitaoka |
120a6e |
continue;
|
|
Shinya Kitaoka |
120a6e |
|
|
shun-iwasawa |
7f18c9 |
int currDist = dr + dg + db + dm;
|
|
Shinya Kitaoka |
120a6e |
if (currDist < minDist) minDist = currDist, index = it->second;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
ToleranceMap[color] = index;
|
|
Shinya Kitaoka |
120a6e |
return index;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//--------------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
int getIndex(const TPixel &color, std::map<tpixel, int=""> &colorMap,</tpixel,>
|
|
Shinya Kitaoka |
120a6e |
TPalette *plt, int tolerance) {
|
|
Shinya Kitaoka |
120a6e |
std::map<tpixel, int="">::const_iterator it;</tpixel,>
|
|
Shinya Kitaoka |
120a6e |
it = colorMap.find(color);
|
|
Shinya Kitaoka |
120a6e |
if (it != colorMap.end()) return it->second;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
if (tolerance > 0) {
|
|
Shinya Kitaoka |
120a6e |
int index = findClosest(color, colorMap, tolerance);
|
|
Shinya Kitaoka |
120a6e |
if (index != -1) return index;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
int index = plt->addStyle(color);
|
|
Shinya Kitaoka |
120a6e |
plt->getPage(0)->addStyle(index);
|
|
Shinya Kitaoka |
120a6e |
colorMap[color] = index;
|
|
Shinya Kitaoka |
120a6e |
return index;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void adaptIndexes(TToonzImageP timg, std::map<tpixel, int=""> &colorMap,</tpixel,>
|
|
Shinya Kitaoka |
120a6e |
TPalette *plt, int tolerance) {
|
|
Shinya Kitaoka |
120a6e |
TPalette *origPlt = timg->getPalette();
|
|
Shinya Kitaoka |
120a6e |
TRasterCM32P r = timg->getRaster();
|
|
Shinya Kitaoka |
120a6e |
TPixelCM32 oldPrev = TPixelCM32(), newPrev = TPixelCM32();
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
for (int i = 0; i < r->getLy(); i++) {
|
|
Shinya Kitaoka |
120a6e |
TPixelCM32 *pix = r->pixels(i);
|
|
Shinya Kitaoka |
120a6e |
for (int j = 0; j < r->getLx(); j++, pix++) {
|
|
Shinya Kitaoka |
120a6e |
if (*pix == TPixelCM32()) continue;
|
|
Shinya Kitaoka |
120a6e |
if (*pix == oldPrev) {
|
|
Shinya Kitaoka |
120a6e |
*pix = newPrev;
|
|
Shinya Kitaoka |
120a6e |
continue;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
oldPrev = *pix;
|
|
Shinya Kitaoka |
120a6e |
int ink = pix->getInk();
|
|
Shinya Kitaoka |
120a6e |
int paint = pix->getPaint();
|
|
Shinya Kitaoka |
120a6e |
if (ink > 0) {
|
|
Shinya Kitaoka |
120a6e |
TPixel color = origPlt->getStyle(ink)->getMainColor();
|
|
Shinya Kitaoka |
120a6e |
int newIndex = getIndex(color, colorMap, plt, tolerance);
|
|
Shinya Kitaoka |
120a6e |
pix->setInk(newIndex);
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
if (paint > 0) {
|
|
Shinya Kitaoka |
120a6e |
TPixel color = origPlt->getStyle(paint)->getMainColor();
|
|
Shinya Kitaoka |
120a6e |
int newIndex = getIndex(color, colorMap, plt, tolerance);
|
|
Shinya Kitaoka |
120a6e |
pix->setPaint(newIndex);
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
newPrev = *pix;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void adaptLevelToPalette(TXshLevelHandle *currentLevelHandle,
|
|
Shinya Kitaoka |
120a6e |
TPaletteHandle *paletteHandle, TPalette *plt,
|
|
Shinya Kitaoka |
120a6e |
int tolerance, bool noUndo) {
|
|
Shinya Kitaoka |
120a6e |
TXshSimpleLevel *sl = currentLevelHandle->getSimpleLevel();
|
|
Shinya Kitaoka |
120a6e |
QApplication::setOverrideCursor(Qt::WaitCursor);
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
TPalette *oldPalette = sl->getPalette();
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
ToleranceMap.clear();
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
std::map<tpixel, int=""> colorMap;</tpixel,>
|
|
Shinya Kitaoka |
120a6e |
for (int i = 0; i < plt->getStyleCount(); i++) {
|
|
Shinya Kitaoka |
120a6e |
if (!plt->getStylePage(i)) continue;
|
|
Shinya Kitaoka |
120a6e |
colorMap[plt->getStyle(i)->getMainColor()] = i;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
std::vector<tframeid> fids;</tframeid>
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
sl->getFids(fids);
|
|
Shinya Kitaoka |
120a6e |
for (int i = 0; i < (int)fids.size(); i++) {
|
|
Shinya Kitaoka |
120a6e |
TToonzImageP timg = (TToonzImageP)sl->getFrame(fids[i], true);
|
|
Shinya Kitaoka |
120a6e |
if (!timg) continue;
|
|
Shinya Kitaoka |
120a6e |
if (!noUndo)
|
|
Shinya Kitaoka |
120a6e |
TUndoManager::manager()->add(new AdjustIntoCurrentPaletteUndo(
|
|
Shinya Kitaoka |
120a6e |
currentLevelHandle, paletteHandle, fids[i], timg->cloneImage(),
|
|
Shinya Kitaoka |
120a6e |
oldPalette->clone(), plt->clone(), tolerance));
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
adaptIndexes(timg, colorMap, plt, tolerance);
|
|
Shinya Kitaoka |
120a6e |
timg->setPalette(plt);
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
QApplication::restoreOverrideCursor();
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
currentLevelHandle->getSimpleLevel()->setPalette(plt);
|
|
manongjohn |
fb50b4 |
|
|
manongjohn |
fb50b4 |
std::wstring oldGlobalName = paletteHandle->getPalette()->getGlobalName();
|
|
Shinya Kitaoka |
120a6e |
paletteHandle->setPalette(plt);
|
|
manongjohn |
fb50b4 |
paletteHandle->getPalette()->setGlobalName(oldGlobalName);
|
|
Shinya Kitaoka |
120a6e |
plt->setDirtyFlag(true);
|
|
Shinya Kitaoka |
120a6e |
paletteHandle->notifyPaletteChanged();
|
|
Shinya Kitaoka |
120a6e |
currentLevelHandle->notifyLevelChange();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
shun-iwasawa |
7f18c9 |
} // namespace
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void StudioPaletteCmd::loadIntoCurrentPalette(
|
|
Shinya Kitaoka |
120a6e |
TPaletteHandle *paletteHandle, TPalette *plt,
|
|
Shinya Kitaoka |
120a6e |
TXshLevelHandle *currentLevelHandle, int tolerance) {
|
|
Shinya Kitaoka |
120a6e |
adaptLevelToPalette(currentLevelHandle, paletteHandle, plt, tolerance, false);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//---------------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void StudioPaletteCmd::loadIntoCurrentPalette(TPaletteHandle *paletteHandle,
|
|
Shinya Kitaoka |
120a6e |
TPalette *palette) {
|
|
Shinya Kitaoka |
120a6e |
assert(paletteHandle);
|
|
Shinya Kitaoka |
120a6e |
TPalette *current = paletteHandle->getPalette();
|
|
Shinya Kitaoka |
120a6e |
if (!current) return;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
int styleId = paletteHandle->getStyleIndex();
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
TPalette *old = current->clone();
|
|
Shinya Kitaoka |
120a6e |
while (palette->getStyleCount() < current->getStyleCount()) {
|
|
Shinya Kitaoka |
120a6e |
int index = palette->getStyleCount();
|
|
Shinya Kitaoka |
120a6e |
assert(index < current->getStyleCount());
|
|
Shinya Kitaoka |
120a6e |
TColorStyle *style = current->getStyle(index)->clone();
|
|
Shinya Kitaoka |
120a6e |
palette->addStyle(style);
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
// keep the color model path unchanged
|
|
Shinya Kitaoka |
120a6e |
TFilePath oldRefImagePath = current->getRefImgPath();
|
|
Shinya Kitaoka |
120a6e |
|
|
shun_iwasawa |
9f19cf |
std::wstring oldGlobalName = current->getGlobalName();
|
|
Shinya Kitaoka |
120a6e |
current->assign(palette, true);
|
|
shun_iwasawa |
9f19cf |
// keep global name unchanged
|
|
shun_iwasawa |
9f19cf |
current->setGlobalName(oldGlobalName);
|
|
shun_iwasawa |
9f19cf |
|
|
Shinya Kitaoka |
120a6e |
current->setDirtyFlag(true);
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
current->setRefImgPath(oldRefImagePath);
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
if (paletteHandle->getPalette() == current &&
|
|
Shinya Kitaoka |
120a6e |
styleId >= current->getStyleCount())
|
|
Shinya Kitaoka |
120a6e |
paletteHandle->setStyleIndex(1);
|
|
Shinya Kitaoka |
120a6e |
TUndoManager::manager()->add(
|
|
Shinya Kitaoka |
120a6e |
new PaletteAssignUndo(current, old, current->clone(), paletteHandle));
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
palette->setDirtyFlag(true);
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
paletteHandle->notifyPaletteChanged();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void StudioPaletteCmd::mergeIntoCurrentPalette(TPaletteHandle *paletteHandle,
|
|
Shinya Kitaoka |
120a6e |
const TFilePath &fp) {
|
|
Shinya Kitaoka |
120a6e |
TPalette *palette = StudioPalette::instance()->getPalette(fp);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
if (!palette) return;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
mergeIntoCurrentPalette(paletteHandle, palette);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void StudioPaletteCmd::mergeIntoCurrentPalette(TPaletteHandle *paletteHandle,
|
|
Shinya Kitaoka |
120a6e |
TPalette *palette) {
|
|
Shinya Kitaoka |
120a6e |
assert(paletteHandle);
|
|
Shinya Kitaoka |
120a6e |
TPalette *current = paletteHandle->getPalette();
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
if (!current) return;
|
|
Shinya Kitaoka |
120a6e |
if (current->isLocked()) return;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
TPalette *old = current->clone();
|
|
Shinya Kitaoka |
120a6e |
current->merge(palette, true);
|
|
Shinya Kitaoka |
120a6e |
TUndoManager::manager()->add(
|
|
Shinya Kitaoka |
120a6e |
new PaletteAssignUndo(current, old, current->clone(), paletteHandle));
|
|
Shinya Kitaoka |
120a6e |
|
|
shun-iwasawa |
e818fe |
current->setDirtyFlag(true);
|
|
Shinya Kitaoka |
120a6e |
paletteHandle->notifyPaletteChanged();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void StudioPaletteCmd::replaceWithCurrentPalette(
|
|
Shinya Kitaoka |
120a6e |
TPaletteHandle *paletteHandle, TPaletteHandle *stdPaletteHandle,
|
|
Shinya Kitaoka |
120a6e |
const TFilePath &fp) {
|
|
Shinya Kitaoka |
120a6e |
StudioPalette *sp = StudioPalette::instance();
|
|
Shinya Kitaoka |
120a6e |
TPalette *palette = sp->getPalette(fp);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
if (!palette || palette->isLocked()) return;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
assert(paletteHandle);
|
|
Shinya Kitaoka |
120a6e |
TPalette *current = paletteHandle->getPalette();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
if (!current) return;
|
|
Shinya Kitaoka |
120a6e |
// keep the studio palette's global name unchanged
|
|
Shinya Kitaoka |
120a6e |
std::wstring oldGlobalName = palette->getGlobalName();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
TPalette *old = palette->clone();
|
|
Shinya Kitaoka |
120a6e |
palette->assign(current);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
// put back the global name
|
|
Shinya Kitaoka |
120a6e |
palette->setGlobalName(oldGlobalName);
|
|
Toshihiro Shimizu |
890ddd |
|
|
shun-iwasawa |
7f18c9 |
if (!trySetStudioPalette(fp, current, true)) {
|
|
shun-iwasawa |
7f18c9 |
palette->assign(old);
|
|
shun-iwasawa |
7f18c9 |
return;
|
|
shun-iwasawa |
7f18c9 |
}
|
|
shun-iwasawa |
7f18c9 |
|
|
Shinya Kitaoka |
120a6e |
TUndoManager::manager()->add(
|
|
Shinya Kitaoka |
120a6e |
new StudioPaletteAssignUndo(fp, old, current->clone(), paletteHandle));
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
// Cambio la studioPalette correntette(palette);
|
|
Shinya Kitaoka |
120a6e |
stdPaletteHandle->setPalette(palette);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
stdPaletteHandle->notifyPaletteSwitched();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void StudioPaletteCmd::updateAllLinkedStyles(TPaletteHandle *paletteHandle,
|
|
Shinya Kitaoka |
120a6e |
TXsheetHandle *xsheetHandle) {
|
|
Shinya Kitaoka |
120a6e |
if (!xsheetHandle) return;
|
|
Shinya Kitaoka |
120a6e |
TXsheet *xsheet = xsheetHandle->getXsheet();
|
|
Shinya Kitaoka |
120a6e |
if (!xsheet) return;
|
|
Shinya Kitaoka |
120a6e |
ToonzScene *scene = xsheet->getScene();
|
|
Shinya Kitaoka |
120a6e |
if (!scene) return;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
// emit signal only if something changed
|
|
Shinya Kitaoka |
120a6e |
bool somethingChanged = false;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
StudioPalette *sp = StudioPalette::instance();
|
|
Shinya Kitaoka |
120a6e |
TLevelSet *levelSet = scene->getLevelSet();
|
|
Shinya Kitaoka |
120a6e |
for (int i = 0; i < levelSet->getLevelCount(); i++) {
|
|
Shinya Kitaoka |
120a6e |
TXshLevel *xl = levelSet->getLevel(i);
|
|
Shinya Kitaoka |
120a6e |
TXshSimpleLevel *sl = xl ? xl->getSimpleLevel() : 0;
|
|
Shinya Kitaoka |
120a6e |
if (!sl) continue;
|
|
Shinya Kitaoka |
120a6e |
TPalette *palette = sl->getPalette();
|
|
Shinya Kitaoka |
120a6e |
if (palette) {
|
|
Shinya Kitaoka |
120a6e |
somethingChanged = somethingChanged | sp->updateLinkedColors(palette);
|
|
Shinya Kitaoka |
120a6e |
if (sl->getType() == TZP_XSHLEVEL) {
|
|
Shinya Kitaoka |
120a6e |
std::vector<tframeid> fids;</tframeid>
|
|
Shinya Kitaoka |
120a6e |
sl->getFids(fids);
|
|
Shinya Kitaoka |
120a6e |
std::vector<tframeid>::iterator it;</tframeid>
|
|
Shinya Kitaoka |
120a6e |
for (it = fids.begin(); it != fids.end(); ++it) {
|
|
Shinya Kitaoka |
120a6e |
TFrameId fid = *it;
|
|
Shinya Kitaoka |
120a6e |
std::string id = sl->getImageId(fid);
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
if (!paletteHandle || !paletteHandle->getPalette()) return;
|
|
Shinya Kitaoka |
120a6e |
if (somethingChanged) paletteHandle->notifyColorStyleChanged();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
/*! Delete palette identified by \b fp in \b StudioPalette. If there are any
|
|
Shinya Kitaoka |
120a6e |
problems in loading send an error message.
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Shinya Kitaoka |
120a6e |
void StudioPaletteCmd::deletePalette(const TFilePath &fp) {
|
|
Shinya Kitaoka |
120a6e |
TUndo *undo = new DeletePaletteUndo(fp);
|
|
Shinya Kitaoka |
120a6e |
StudioPalette::instance()->deletePalette(fp);
|
|
Shinya Kitaoka |
120a6e |
TUndoManager::manager()->add(undo);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
/*! Move palette from TFilePath \b srcPath to \b TFilePath \b dstPath. If there
|
|
Shinya Kitaoka |
120a6e |
are any problems in moving send an error message.
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Shinya Kitaoka |
120a6e |
void StudioPaletteCmd::movePalette(const TFilePath &dstPath,
|
|
Shinya Kitaoka |
120a6e |
const TFilePath &srcPath) {
|
|
Shinya Kitaoka |
120a6e |
TSystem::touchParentDir(dstPath);
|
|
Shinya Kitaoka |
120a6e |
StudioPalette::instance()->movePalette(dstPath, srcPath);
|
|
Shinya Kitaoka |
120a6e |
TUndoManager::manager()->add(new MovePaletteUndo(dstPath, srcPath));
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
/*! Create palette \b palette in folder \b folderName with name \b paletteName.
|
|
Shinya Kitaoka |
120a6e |
If there are any problems send an error message.
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
TFilePath StudioPaletteCmd::createPalette(const TFilePath &folderName,
|
|
Shinya Kitaoka |
120a6e |
std::string paletteName,
|
|
Shinya Kitaoka |
120a6e |
const TPalette *palette) {
|
|
Shinya Kitaoka |
120a6e |
TFilePath palettePath;
|
|
Shinya Kitaoka |
120a6e |
TFileStatus status(folderName);
|
|
shun-iwasawa |
7f18c9 |
// exception will be caught either in StudioPaletteTreeViewer::addNewPalette()
|
|
shun-iwasawa |
7f18c9 |
// or StudioPaletteTreeViewer::dropEvent()
|
|
Shinya Kitaoka |
120a6e |
if (!status.isDirectory()) throw TException("Select a folder.");
|
|
Shinya Kitaoka |
120a6e |
if (!status.doesExist()) {
|
|
Shinya Kitaoka |
120a6e |
TSystem::mkDir(folderName);
|
|
Shinya Kitaoka |
120a6e |
FolderListenerManager::instance()->notifyFolderChanged(
|
|
Shinya Kitaoka |
120a6e |
folderName.getParentDir());
|
|
Shinya Kitaoka |
120a6e |
}
|
|
shun-iwasawa |
7f18c9 |
// StudioPalette::setPalette() and createPalette() may throw exception on
|
|
shun-iwasawa |
7f18c9 |
// saving, it will be caught in the upper functions as wel
|
|
Shinya Kitaoka |
120a6e |
palettePath =
|
|
Shinya Kitaoka |
120a6e |
StudioPalette::instance()->createPalette(folderName, paletteName);
|
|
Shinya Kitaoka |
120a6e |
if (palette)
|
|
Shinya Kitaoka |
120a6e |
StudioPalette::instance()->setPalette(palettePath, palette, true);
|
|
Shinya Kitaoka |
120a6e |
TUndoManager::manager()->add(new CreatePaletteUndo(palettePath));
|
|
Shinya Kitaoka |
120a6e |
return palettePath;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
/*! Add a folder in StudioPalette TFilePath \b parentFolderPath. If there
|
|
Shinya Kitaoka |
120a6e |
are any problems send an error message.
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Shinya Kitaoka |
120a6e |
TFilePath StudioPaletteCmd::addFolder(const TFilePath &parentFolderPath) {
|
|
Shinya Kitaoka |
120a6e |
TFilePath folderPath;
|
|
Shinya Kitaoka |
120a6e |
folderPath = StudioPalette::instance()->createFolder(parentFolderPath);
|
|
Shinya Kitaoka |
120a6e |
if (!folderPath.isEmpty())
|
|
Shinya Kitaoka |
120a6e |
TUndoManager::manager()->add(new CreateFolderUndo(folderPath));
|
|
Shinya Kitaoka |
120a6e |
return folderPath;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
/*! Delete folder \b folderPath. If there are any problems in deleting send an
|
|
Shinya Kitaoka |
120a6e |
error message.
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Shinya Kitaoka |
120a6e |
void StudioPaletteCmd::deleteFolder(const TFilePath &folderPath) {
|
|
Shinya Kitaoka |
120a6e |
TFilePathSet folderPathSet;
|
|
Shinya Kitaoka |
120a6e |
TSystem::readDirectoryTree(folderPathSet, folderPath, true, false);
|
|
Shinya Kitaoka |
120a6e |
TUndo *undo = new DeleteFolderUndo(folderPath, folderPathSet);
|
|
Shinya Kitaoka |
120a6e |
StudioPalette::instance()->deleteFolder(folderPath);
|
|
Shinya Kitaoka |
120a6e |
TUndoManager::manager()->add(undo);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void StudioPaletteCmd::scanPalettes(const TFilePath &folder,
|
|
Shinya Kitaoka |
120a6e |
const TFilePath &sourcePath) {
|
|
Shinya Kitaoka |
120a6e |
// error("uh oh");
|
|
Toshihiro Shimizu |
890ddd |
}
|