tahoma2d/toonz/sources/toonzlib/palettecontroller.cpp

111 lines
3.7 KiB
C++
Raw Normal View History

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"
// TnzBase includes
#include "tenv.h"
2016-03-19 06:57:51 +13:00
#include "toonz/palettecontroller.h"
TEnv::IntVar PaletteControllerAutoApplyState("PaletteControllerAutoApplyState",
1);
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)
, m_colorAutoApplyEnabled(PaletteControllerAutoApplyState != 0)
2016-06-15 18:43:10 +12:00
, m_colorSample() {
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()));
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
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);
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) {
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
}