2016-03-19 06:57:51 +13:00
|
|
|
|
|
|
|
|
|
|
|
// TnzLib includes
|
|
|
|
#include "toonz/stage2.h"
|
|
|
|
#include "toonz/tpalettehandle.h"
|
|
|
|
#include "toonz/tscenehandle.h"
|
|
|
|
#include "toonz/txshlevelhandle.h"
|
|
|
|
#include "toonz/txshlevel.h"
|
2020-07-26 16:51:26 +12:00
|
|
|
#include "toonz/txshleveltypes.h"
|
|
|
|
#include "toonz/toonzfolders.h"
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-07-05 19:15:29 +12:00
|
|
|
// TnzBase includes
|
|
|
|
#include "tenv.h"
|
2020-07-26 16:51:26 +12:00
|
|
|
#include "tsystem.h"
|
|
|
|
#include "tstream.h"
|
2016-07-05 19:15:29 +12:00
|
|
|
|
2016-03-19 06:57:51 +13:00
|
|
|
#include "toonz/palettecontroller.h"
|
|
|
|
|
2016-07-21 00:49:32 +12:00
|
|
|
TEnv::IntVar PaletteControllerAutoApplyState("PaletteControllerAutoApplyState",
|
|
|
|
1);
|
2016-07-05 19:15:29 +12:00
|
|
|
|
2020-07-26 16:51:26 +12:00
|
|
|
TPalette *loadDefaultPalette(QString levelType) {
|
|
|
|
TFilePath palettePath = ToonzFolder::getMyPalettesDir() +
|
|
|
|
TFilePath(levelType.toStdString() + "_default.tpl");
|
|
|
|
TFileStatus pfs(palettePath);
|
|
|
|
|
|
|
|
TPalette *defaultPalette = new TPalette();
|
|
|
|
|
|
|
|
if (!pfs.doesExist() || !pfs.isReadable()) return defaultPalette;
|
|
|
|
|
|
|
|
TIStream is(palettePath);
|
|
|
|
if (!is) return defaultPalette;
|
|
|
|
|
|
|
|
std::string tagName;
|
|
|
|
if (!is.matchTag(tagName) || tagName != "palette") return defaultPalette;
|
|
|
|
|
|
|
|
std::string gname;
|
|
|
|
is.getTagParam("name", gname);
|
|
|
|
defaultPalette->loadData(is);
|
|
|
|
|
|
|
|
return defaultPalette;
|
|
|
|
}
|
|
|
|
|
2016-03-19 06:57:51 +13:00
|
|
|
PaletteController::PaletteController()
|
2016-06-15 18:43:10 +12:00
|
|
|
: QObject()
|
|
|
|
, m_currentLevelPalette(0)
|
|
|
|
, m_currentCleanupPalette(0)
|
|
|
|
, m_originalCurrentPalette(0)
|
|
|
|
, m_currentPalette(0)
|
2020-06-12 18:11:25 +12:00
|
|
|
, m_colorAutoApplyEnabled(true)
|
2020-07-26 16:51:26 +12:00
|
|
|
, m_colorSample()
|
|
|
|
, m_defaultRaster(0)
|
|
|
|
, m_defaultToonzRaster(0)
|
2021-09-17 02:48:32 +12:00
|
|
|
, m_defaultVector(0)
|
|
|
|
, m_currentPaletteViewer(0) {
|
2016-06-15 18:43:10 +12:00
|
|
|
m_currentLevelPalette = new TPaletteHandle;
|
|
|
|
m_currentCleanupPalette = new TPaletteHandle;
|
|
|
|
m_currentPalette = new TPaletteHandle;
|
|
|
|
|
|
|
|
QObject::connect(m_currentCleanupPalette, SIGNAL(paletteSwitched()), this,
|
|
|
|
SLOT(editCleanupPalette()));
|
|
|
|
QObject::connect(m_currentCleanupPalette, SIGNAL(colorStyleSwitched()), this,
|
|
|
|
SLOT(editCleanupPalette()));
|
|
|
|
|
|
|
|
QObject::connect(m_currentLevelPalette, SIGNAL(paletteSwitched()), this,
|
|
|
|
SLOT(editLevelPalette()));
|
|
|
|
QObject::connect(m_currentLevelPalette, SIGNAL(colorStyleSwitched()), this,
|
|
|
|
SLOT(editLevelPalette()));
|
|
|
|
// QObject::connect(m_currentLevelPalette, SIGNAL(colorStyleSwitched()), this,
|
|
|
|
// SLOT(setColorCheckIndex()));
|
|
|
|
|
|
|
|
QObject::connect(m_currentLevelPalette, SIGNAL(paletteLockChanged()), this,
|
|
|
|
SLOT(editLevelPalette()));
|
2020-07-26 16:51:26 +12:00
|
|
|
|
|
|
|
m_defaultRaster = loadDefaultPalette("raster");
|
|
|
|
m_defaultRaster->setPaletteName(L"Default Raster Palette");
|
|
|
|
m_defaultRaster->setIsDefaultPalette(true);
|
|
|
|
m_defaultRaster->setDefaultPaletteType(OVL_XSHLEVEL);
|
|
|
|
|
|
|
|
m_defaultToonzRaster = loadDefaultPalette("smart_raster");
|
|
|
|
m_defaultToonzRaster->setPaletteName(L"Default Smart Raster Palette");
|
|
|
|
m_defaultToonzRaster->setIsDefaultPalette(true);
|
|
|
|
m_defaultToonzRaster->setDefaultPaletteType(TZP_XSHLEVEL);
|
|
|
|
|
|
|
|
m_defaultVector = loadDefaultPalette("vector");
|
|
|
|
m_defaultVector->setPaletteName(L"Default Vector Palette");
|
|
|
|
m_defaultVector->setIsDefaultPalette(true);
|
|
|
|
m_defaultVector->setDefaultPaletteType(PLI_XSHLEVEL);
|
2016-03-19 06:57:51 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
PaletteController::~PaletteController() {
|
|
|
|
delete m_currentLevelPalette;
|
|
|
|
delete m_currentCleanupPalette;
|
|
|
|
delete m_currentPalette;
|
2016-03-19 06:57:51 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
void PaletteController::setCurrentPalette(TPaletteHandle *paletteHandle) {
|
|
|
|
// Current palette redirects to the palette of another palette handle -
|
|
|
|
// namely one of either the current level palette or current cleanup
|
|
|
|
// palette - even though m_currentPalette is a standalone palette handle.
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
// In order to correctly support the notification system notify*() functions
|
|
|
|
// perform signal BROADCASTING to all palette handles implicitly mapping to
|
|
|
|
// the associated palette:
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2020-01-09 22:28:19 +13:00
|
|
|
// in case the handle is not changed, skip the reconnection
|
|
|
|
if (m_originalCurrentPalette == paletteHandle) {
|
|
|
|
if (!paletteHandle) return;
|
|
|
|
m_currentPalette->setPalette(paletteHandle->getPalette(),
|
|
|
|
paletteHandle->getStyleIndex());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
if (m_originalCurrentPalette) {
|
|
|
|
m_originalCurrentPalette->disconnectBroadcasts(m_currentPalette);
|
|
|
|
m_currentPalette->disconnectBroadcasts(m_originalCurrentPalette);
|
|
|
|
}
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
m_originalCurrentPalette = paletteHandle;
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
if (!paletteHandle) return;
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
m_currentPalette->setPalette(paletteHandle->getPalette(),
|
|
|
|
paletteHandle->getStyleIndex());
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
m_originalCurrentPalette->connectBroadcasts(m_currentPalette);
|
|
|
|
m_currentPalette->connectBroadcasts(m_originalCurrentPalette);
|
2016-03-19 06:57:51 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
void PaletteController::editLevelPalette() {
|
|
|
|
setCurrentPalette(m_currentLevelPalette);
|
2020-06-12 18:11:25 +12:00
|
|
|
emit(checkPaletteLock());
|
2016-03-19 06:57:51 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
void PaletteController::editCleanupPalette() {
|
|
|
|
setCurrentPalette(m_currentCleanupPalette);
|
2016-03-19 06:57:51 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
void PaletteController::enableColorAutoApply(bool enabled) {
|
|
|
|
if (m_colorAutoApplyEnabled != enabled) {
|
2020-06-12 18:11:25 +12:00
|
|
|
m_colorAutoApplyEnabled = enabled;
|
|
|
|
// PaletteControllerAutoApplyState = (enabled) ? 1 : 0;
|
2016-06-15 18:43:10 +12:00
|
|
|
emit colorAutoApplyEnabled(m_colorAutoApplyEnabled);
|
|
|
|
}
|
2016-03-19 06:57:51 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
void PaletteController::setColorSample(const TPixel32 &color) {
|
|
|
|
if (m_colorSample != color) {
|
|
|
|
m_colorSample = color;
|
|
|
|
emit colorSampleChanged(m_colorSample);
|
|
|
|
}
|
2016-03-19 06:57:51 +13:00
|
|
|
}
|
2020-07-26 16:51:26 +12:00
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
TPalette *PaletteController::getDefaultPalette(int levelType) {
|
|
|
|
switch (levelType) {
|
|
|
|
case PLI_XSHLEVEL:
|
|
|
|
return m_defaultVector;
|
|
|
|
case TZP_XSHLEVEL:
|
|
|
|
return m_defaultToonzRaster;
|
|
|
|
case OVL_XSHLEVEL:
|
|
|
|
return m_defaultRaster;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PaletteController::setDefaultPalette(int levelType, TPalette *palette) {
|
|
|
|
switch (levelType) {
|
|
|
|
case PLI_XSHLEVEL:
|
|
|
|
m_defaultVector = palette;
|
|
|
|
break;
|
|
|
|
case TZP_XSHLEVEL:
|
|
|
|
m_defaultToonzRaster = palette;
|
|
|
|
break;
|
|
|
|
case OVL_XSHLEVEL:
|
|
|
|
m_defaultRaster = palette;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|