Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
// TnzLib includes
Toshihiro Shimizu 890ddd
#include "toonz/stage2.h"
Toshihiro Shimizu 890ddd
#include "toonz/tpalettehandle.h"
Toshihiro Shimizu 890ddd
#include "toonz/tscenehandle.h"
Toshihiro Shimizu 890ddd
#include "toonz/txshlevelhandle.h"
Toshihiro Shimizu 890ddd
#include "toonz/txshlevel.h"
Toshihiro Shimizu 890ddd
shun_iwasawa fd6c3c
// TnzBase includes
shun_iwasawa fd6c3c
#include "tenv.h"
shun_iwasawa fd6c3c
Toshihiro Shimizu 890ddd
#include "toonz/palettecontroller.h"
Toshihiro Shimizu 890ddd
Shinya Kitaoka 2a7129
TEnv::IntVar PaletteControllerAutoApplyState("PaletteControllerAutoApplyState",
Shinya Kitaoka 2a7129
                                             1);
shun_iwasawa fd6c3c
Toshihiro Shimizu 890ddd
PaletteController::PaletteController()
Shinya Kitaoka 120a6e
    : QObject()
Shinya Kitaoka 120a6e
    , m_currentLevelPalette(0)
Shinya Kitaoka 120a6e
    , m_currentCleanupPalette(0)
Shinya Kitaoka 120a6e
    , m_originalCurrentPalette(0)
Shinya Kitaoka 120a6e
    , m_currentPalette(0)
Shinya Kitaoka 2a7129
    , m_colorAutoApplyEnabled(PaletteControllerAutoApplyState != 0)
Shinya Kitaoka 120a6e
    , m_colorSample() {
Shinya Kitaoka 120a6e
  m_currentLevelPalette   = new TPaletteHandle;
Shinya Kitaoka 120a6e
  m_currentCleanupPalette = new TPaletteHandle;
Shinya Kitaoka 120a6e
  m_currentPalette        = new TPaletteHandle;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  QObject::connect(m_currentCleanupPalette, SIGNAL(paletteSwitched()), this,
Shinya Kitaoka 120a6e
                   SLOT(editCleanupPalette()));
Shinya Kitaoka 120a6e
  QObject::connect(m_currentCleanupPalette, SIGNAL(colorStyleSwitched()), this,
Shinya Kitaoka 120a6e
                   SLOT(editCleanupPalette()));
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  QObject::connect(m_currentLevelPalette, SIGNAL(paletteSwitched()), this,
Shinya Kitaoka 120a6e
                   SLOT(editLevelPalette()));
Shinya Kitaoka 120a6e
  QObject::connect(m_currentLevelPalette, SIGNAL(colorStyleSwitched()), this,
Shinya Kitaoka 120a6e
                   SLOT(editLevelPalette()));
Shinya Kitaoka 120a6e
  // QObject::connect(m_currentLevelPalette, SIGNAL(colorStyleSwitched()), this,
Shinya Kitaoka 120a6e
  // SLOT(setColorCheckIndex()));
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  QObject::connect(m_currentLevelPalette, SIGNAL(paletteLockChanged()), this,
Shinya Kitaoka 120a6e
                   SLOT(editLevelPalette()));
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
PaletteController::~PaletteController() {
Shinya Kitaoka 120a6e
  delete m_currentLevelPalette;
Shinya Kitaoka 120a6e
  delete m_currentCleanupPalette;
Shinya Kitaoka 120a6e
  delete m_currentPalette;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void PaletteController::setCurrentPalette(TPaletteHandle *paletteHandle) {
Shinya Kitaoka 120a6e
  // Current palette redirects to the palette of another palette handle -
Shinya Kitaoka 120a6e
  // namely one of either the current level palette or current cleanup
Shinya Kitaoka 120a6e
  // palette - even though m_currentPalette is a standalone palette handle.
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  // In order to correctly support the notification system notify*() functions
Shinya Kitaoka 120a6e
  // perform signal BROADCASTING to all palette handles implicitly mapping to
Shinya Kitaoka 120a6e
  // the associated palette:
Toshihiro Shimizu 890ddd
shun-iwasawa 794fda
  // in case the handle is not changed, skip the reconnection
shun-iwasawa 794fda
  if (m_originalCurrentPalette == paletteHandle) {
shun-iwasawa 794fda
    if (!paletteHandle) return;
shun-iwasawa 794fda
    m_currentPalette->setPalette(paletteHandle->getPalette(),
shun-iwasawa 794fda
                                 paletteHandle->getStyleIndex());
shun-iwasawa 794fda
    return;
shun-iwasawa 794fda
  }
shun-iwasawa 794fda
Shinya Kitaoka 120a6e
  if (m_originalCurrentPalette) {
Shinya Kitaoka 120a6e
    m_originalCurrentPalette->disconnectBroadcasts(m_currentPalette);
Shinya Kitaoka 120a6e
    m_currentPalette->disconnectBroadcasts(m_originalCurrentPalette);
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  m_originalCurrentPalette = paletteHandle;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  if (!paletteHandle) return;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  m_currentPalette->setPalette(paletteHandle->getPalette(),
Shinya Kitaoka 120a6e
                               paletteHandle->getStyleIndex());
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  m_originalCurrentPalette->connectBroadcasts(m_currentPalette);
Shinya Kitaoka 120a6e
  m_currentPalette->connectBroadcasts(m_originalCurrentPalette);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void PaletteController::editLevelPalette() {
Shinya Kitaoka 120a6e
  setCurrentPalette(m_currentLevelPalette);
shun-iwasawa 2888cd
  emit(checkPaletteLock());
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void PaletteController::editCleanupPalette() {
Shinya Kitaoka 120a6e
  setCurrentPalette(m_currentCleanupPalette);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void PaletteController::enableColorAutoApply(bool enabled) {
Shinya Kitaoka 120a6e
  if (m_colorAutoApplyEnabled != enabled) {
Shinya Kitaoka 2a7129
    m_colorAutoApplyEnabled         = enabled;
shun_iwasawa fd6c3c
    PaletteControllerAutoApplyState = (enabled) ? 1 : 0;
Shinya Kitaoka 120a6e
    emit colorAutoApplyEnabled(m_colorAutoApplyEnabled);
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void PaletteController::setColorSample(const TPixel32 &color) {
Shinya Kitaoka 120a6e
  if (m_colorSample != color) {
Shinya Kitaoka 120a6e
    m_colorSample = color;
Shinya Kitaoka 120a6e
    emit colorSampleChanged(m_colorSample);
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}