1
2
3 // TnzLib includes
4 #include "toonz/stage2.h"
5 #include "toonz/tpalettehandle.h"
6 #include "toonz/tscenehandle.h"
7 #include "toonz/txshlevelhandle.h"
8 #include "toonz/txshlevel.h"
9
10 // TnzBase includes
11 #include "tenv.h"
12
13 #include "toonz/palettecontroller.h"
14
15 TEnv::IntVar PaletteControllerAutoApplyState("PaletteControllerAutoApplyState",
16 1);
17
PaletteController()18 PaletteController::PaletteController()
19 : QObject()
20 , m_currentLevelPalette(0)
21 , m_currentCleanupPalette(0)
22 , m_originalCurrentPalette(0)
23 , m_currentPalette(0)
24 , m_colorAutoApplyEnabled(PaletteControllerAutoApplyState != 0)
25 , m_colorSample() {
26 m_currentLevelPalette = new TPaletteHandle;
27 m_currentCleanupPalette = new TPaletteHandle;
28 m_currentPalette = new TPaletteHandle;
29
30 QObject::connect(m_currentCleanupPalette, SIGNAL(paletteSwitched()), this,
31 SLOT(editCleanupPalette()));
32 QObject::connect(m_currentCleanupPalette, SIGNAL(colorStyleSwitched()), this,
33 SLOT(editCleanupPalette()));
34
35 QObject::connect(m_currentLevelPalette, SIGNAL(paletteSwitched()), this,
36 SLOT(editLevelPalette()));
37 QObject::connect(m_currentLevelPalette, SIGNAL(colorStyleSwitched()), this,
38 SLOT(editLevelPalette()));
39 // QObject::connect(m_currentLevelPalette, SIGNAL(colorStyleSwitched()), this,
40 // SLOT(setColorCheckIndex()));
41
42 QObject::connect(m_currentLevelPalette, SIGNAL(paletteLockChanged()), this,
43 SLOT(editLevelPalette()));
44 }
45
46 //-----------------------------------------------------------------------------
47
~PaletteController()48 PaletteController::~PaletteController() {
49 delete m_currentLevelPalette;
50 delete m_currentCleanupPalette;
51 delete m_currentPalette;
52 }
53
54 //-----------------------------------------------------------------------------
55
setCurrentPalette(TPaletteHandle * paletteHandle)56 void PaletteController::setCurrentPalette(TPaletteHandle *paletteHandle) {
57 // Current palette redirects to the palette of another palette handle -
58 // namely one of either the current level palette or current cleanup
59 // palette - even though m_currentPalette is a standalone palette handle.
60
61 // In order to correctly support the notification system notify*() functions
62 // perform signal BROADCASTING to all palette handles implicitly mapping to
63 // the associated palette:
64
65 // in case the handle is not changed, skip the reconnection
66 if (m_originalCurrentPalette == paletteHandle) {
67 if (!paletteHandle) return;
68 m_currentPalette->setPalette(paletteHandle->getPalette(),
69 paletteHandle->getStyleIndex());
70 return;
71 }
72
73 if (m_originalCurrentPalette) {
74 m_originalCurrentPalette->disconnectBroadcasts(m_currentPalette);
75 m_currentPalette->disconnectBroadcasts(m_originalCurrentPalette);
76 }
77
78 m_originalCurrentPalette = paletteHandle;
79
80 if (!paletteHandle) return;
81
82 m_currentPalette->setPalette(paletteHandle->getPalette(),
83 paletteHandle->getStyleIndex());
84
85 m_originalCurrentPalette->connectBroadcasts(m_currentPalette);
86 m_currentPalette->connectBroadcasts(m_originalCurrentPalette);
87 }
88
89 //-----------------------------------------------------------------------------
90
editLevelPalette()91 void PaletteController::editLevelPalette() {
92 setCurrentPalette(m_currentLevelPalette);
93 emit(checkPaletteLock());
94 }
95
96 //-----------------------------------------------------------------------------
97
editCleanupPalette()98 void PaletteController::editCleanupPalette() {
99 setCurrentPalette(m_currentCleanupPalette);
100 }
101
102 //-----------------------------------------------------------------------------
103
enableColorAutoApply(bool enabled)104 void PaletteController::enableColorAutoApply(bool enabled) {
105 if (m_colorAutoApplyEnabled != enabled) {
106 m_colorAutoApplyEnabled = enabled;
107 PaletteControllerAutoApplyState = (enabled) ? 1 : 0;
108 emit colorAutoApplyEnabled(m_colorAutoApplyEnabled);
109 }
110 }
111
112 //-----------------------------------------------------------------------------
113
setColorSample(const TPixel32 & color)114 void PaletteController::setColorSample(const TPixel32 &color) {
115 if (m_colorSample != color) {
116 m_colorSample = color;
117 emit colorSampleChanged(m_colorSample);
118 }
119 }
120