|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#include "toonz/tpalettehandle.h"
|
|
Toshihiro Shimizu |
890ddd |
|
|
shun_iwasawa |
b7aa7c |
#include "tundo.h"
|
|
shun_iwasawa |
b7aa7c |
#include "historytypes.h"
|
|
shun_iwasawa |
b7aa7c |
|
|
shun_iwasawa |
b7aa7c |
//=============================================================================
|
|
shun_iwasawa |
b7aa7c |
// AutopaintToggleUndo
|
|
shun_iwasawa |
b7aa7c |
//-----------------------------------------------------------------------------
|
|
shun_iwasawa |
b7aa7c |
|
|
shun_iwasawa |
b7aa7c |
namespace {
|
|
shun_iwasawa |
e553fc |
class AutopaintToggleUndo final : public TUndo {
|
|
shun_iwasawa |
e553fc |
TPaletteHandle *m_paletteHandle;
|
|
shun_iwasawa |
e553fc |
TPaletteP m_palette;
|
|
shun_iwasawa |
e553fc |
int m_styleId;
|
|
shun_iwasawa |
e553fc |
bool m_flag;
|
|
shun_iwasawa |
e553fc |
|
|
shun_iwasawa |
e553fc |
public:
|
|
shun_iwasawa |
e553fc |
AutopaintToggleUndo(TPaletteHandle *paletteHandle, int styleId)
|
|
shun_iwasawa |
b7aa7c |
: m_paletteHandle(paletteHandle)
|
|
shun_iwasawa |
b7aa7c |
, m_palette(paletteHandle->getPalette())
|
|
shun_iwasawa |
e553fc |
, m_styleId(styleId) {}
|
|
shun_iwasawa |
b7aa7c |
|
|
shun_iwasawa |
e553fc |
void toggleAutopaint() const {
|
|
shun_iwasawa |
e553fc |
TColorStyle *s = m_palette->getStyle(m_styleId);
|
|
shun_iwasawa |
e553fc |
s->setFlags(s->getFlags() == 0 ? 1 : 0);
|
|
shun_iwasawa |
e553fc |
m_paletteHandle->notifyColorStyleChanged();
|
|
shun_iwasawa |
e553fc |
}
|
|
shun_iwasawa |
b7aa7c |
|
|
shun_iwasawa |
e553fc |
void undo() const override { toggleAutopaint(); }
|
|
shun_iwasawa |
b7aa7c |
|
|
shun_iwasawa |
e553fc |
void redo() const override { toggleAutopaint(); }
|
|
shun_iwasawa |
b7aa7c |
|
|
shun_iwasawa |
e553fc |
void onAdd() { redo(); }
|
|
shun_iwasawa |
b7aa7c |
|
|
shun_iwasawa |
e553fc |
int getSize() const override { return sizeof(*this); }
|
|
shun_iwasawa |
b7aa7c |
|
|
shun_iwasawa |
e553fc |
QString getHistoryString() override {
|
|
shun_iwasawa |
e553fc |
return QObject::tr("Toggle Autopaint Option Palette : %1 Style#%2")
|
|
shun_iwasawa |
b7aa7c |
.arg(QString::fromStdWString(m_palette->getPaletteName()))
|
|
shun_iwasawa |
b7aa7c |
.arg(QString::number(m_styleId));
|
|
shun_iwasawa |
e553fc |
}
|
|
shun_iwasawa |
b7aa7c |
|
|
shun_iwasawa |
e553fc |
int getHistoryType() override { return HistoryType::Palette; }
|
|
shun_iwasawa |
e553fc |
};
|
|
shun_iwasawa |
b7aa7c |
|
|
shun_iwasawa |
b7aa7c |
} // namespace
|
|
shun_iwasawa |
b7aa7c |
|
|
Toshihiro Shimizu |
890ddd |
//=============================================================================
|
|
Toshihiro Shimizu |
890ddd |
// TPaletteHandle
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TPaletteHandle::TPaletteHandle()
|
|
Shinya Kitaoka |
120a6e |
: m_palette(0), m_styleIndex(-1), m_styleParamIndex(-1) {
|
|
Shinya Kitaoka |
120a6e |
connectBroadcasts(this);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
TPaletteHandle::~TPaletteHandle() {}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
TPalette *TPaletteHandle::getPalette() const { return m_palette; }
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
int TPaletteHandle::getStyleIndex() const { return m_styleIndex; }
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
int TPaletteHandle::getStyleParamIndex() const { return m_styleParamIndex; }
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
TColorStyle *TPaletteHandle::getStyle() const {
|
|
Shinya Kitaoka |
120a6e |
if (!m_palette || m_styleIndex == -1) return 0;
|
|
Shinya Kitaoka |
120a6e |
return m_palette->getStyle(m_styleIndex);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
bool TPaletteHandle::connectBroadcasts(const QObject *receiver) {
|
|
Shinya Kitaoka |
120a6e |
bool ret = true;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
ret = connect(this, SIGNAL(broadcastPaletteChanged()), receiver,
|
|
Shinya Kitaoka |
120a6e |
SIGNAL(paletteChanged())) &&
|
|
Shinya Kitaoka |
120a6e |
ret;
|
|
Shinya Kitaoka |
120a6e |
ret = connect(this, SIGNAL(broadcastPaletteTitleChanged()), receiver,
|
|
Shinya Kitaoka |
120a6e |
SIGNAL(paletteTitleChanged())) &&
|
|
Shinya Kitaoka |
120a6e |
ret;
|
|
Shinya Kitaoka |
120a6e |
ret = connect(this, SIGNAL(broadcastColorStyleSwitched()), receiver,
|
|
Shinya Kitaoka |
120a6e |
SIGNAL(colorStyleSwitched())) &&
|
|
Shinya Kitaoka |
120a6e |
ret;
|
|
shun_iwasawa |
e553fc |
ret = connect(this, SIGNAL(broadcastColorStyleChanged(bool)), receiver,
|
|
shun_iwasawa |
e553fc |
SIGNAL(colorStyleChanged(bool))) &&
|
|
Shinya Kitaoka |
120a6e |
ret;
|
|
Shinya Kitaoka |
120a6e |
ret = connect(this, SIGNAL(broadcastColorStyleChangedOnMouseRelease()),
|
|
Shinya Kitaoka |
120a6e |
receiver, SIGNAL(colorStyleChangedOnMouseRelease())) &&
|
|
Shinya Kitaoka |
120a6e |
ret;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
return ret;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
bool TPaletteHandle::disconnectBroadcasts(const QObject *receiver) {
|
|
Shinya Kitaoka |
120a6e |
bool ret = true;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
ret = disconnect(this, SIGNAL(broadcastPaletteChanged()), receiver,
|
|
Shinya Kitaoka |
120a6e |
SIGNAL(paletteChanged())) &&
|
|
Shinya Kitaoka |
120a6e |
ret;
|
|
Shinya Kitaoka |
120a6e |
ret = disconnect(this, SIGNAL(broadcastPaletteTitleChanged()), receiver,
|
|
Shinya Kitaoka |
120a6e |
SIGNAL(paletteTitleChanged())) &&
|
|
Shinya Kitaoka |
120a6e |
ret;
|
|
Shinya Kitaoka |
120a6e |
ret = disconnect(this, SIGNAL(broadcastColorStyleSwitched()), receiver,
|
|
Shinya Kitaoka |
120a6e |
SIGNAL(colorStyleSwitched())) &&
|
|
Shinya Kitaoka |
120a6e |
ret;
|
|
shun_iwasawa |
e553fc |
ret = disconnect(this, SIGNAL(broadcastColorStyleChanged(bool)), receiver,
|
|
shun_iwasawa |
e553fc |
SIGNAL(colorStyleChanged(bool))) &&
|
|
Shinya Kitaoka |
120a6e |
ret;
|
|
Shinya Kitaoka |
120a6e |
ret = disconnect(this, SIGNAL(broadcastColorStyleChangedOnMouseRelease()),
|
|
Shinya Kitaoka |
120a6e |
receiver, SIGNAL(colorStyleChangedOnMouseRelease())) &&
|
|
Shinya Kitaoka |
120a6e |
ret;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
return ret;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void TPaletteHandle::setPalette(TPalette *palette, int styleIndex) {
|
|
manongjohn |
649b9a |
if (palette) {
|
|
manongjohn |
649b9a |
if (styleIndex < 0) {
|
|
manongjohn |
649b9a |
styleIndex = palette->getCurrentStyleId();
|
|
manongjohn |
649b9a |
if (!palette->getStylePage(styleIndex)) { // in case the style is deleted
|
|
manongjohn |
649b9a |
styleIndex = 1;
|
|
manongjohn |
649b9a |
palette->setCurrentStyleId(styleIndex);
|
|
manongjohn |
649b9a |
}
|
|
manongjohn |
649b9a |
} else
|
|
manongjohn |
649b9a |
palette->setCurrentStyleId(styleIndex);
|
|
manongjohn |
649b9a |
}
|
|
manongjohn |
649b9a |
|
|
Shinya Kitaoka |
120a6e |
if (m_palette == palette)
|
|
Shinya Kitaoka |
120a6e |
setStyleIndex(styleIndex);
|
|
Shinya Kitaoka |
120a6e |
else {
|
|
Shinya Kitaoka |
120a6e |
m_palette = palette;
|
|
Shinya Kitaoka |
120a6e |
m_styleIndex = styleIndex;
|
|
Shinya Kitaoka |
120a6e |
m_styleParamIndex = 0;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
emit paletteSwitched();
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
shun-iwasawa |
558228 |
// forceEmit flag is used in PageViewer and StylePicker tool.
|
|
shun-iwasawa |
fcbc0a |
// See the function PageViewer::setCurrentStyleIndex() in paletteviewergui.cpp
|
|
shun-iwasawa |
558228 |
// Also see the function StylePickerTool::pick() in stylepickertool.cpp
|
|
Toshihiro Shimizu |
890ddd |
|
|
shun-iwasawa |
fcbc0a |
void TPaletteHandle::setStyleIndex(int index, bool forceEmit) {
|
|
shun-iwasawa |
fcbc0a |
if (m_styleIndex != index || m_styleParamIndex != 0 || forceEmit) {
|
|
manongjohn |
649b9a |
if (m_palette) m_palette->setCurrentStyleId(index);
|
|
shun-iwasawa |
11adda |
m_styleIndex = index;
|
|
shun-iwasawa |
11adda |
m_styleParamIndex = 0;
|
|
shun-iwasawa |
11adda |
emit broadcastColorStyleSwitched();
|
|
shun-iwasawa |
11adda |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void TPaletteHandle::setStyleParamIndex(int index) {
|
|
Shinya Kitaoka |
120a6e |
if (m_styleParamIndex != index) {
|
|
Shinya Kitaoka |
120a6e |
m_styleParamIndex = index;
|
|
Shinya Kitaoka |
120a6e |
emit broadcastColorStyleSwitched();
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void TPaletteHandle::notifyPaletteChanged() { emit broadcastPaletteChanged(); }
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void TPaletteHandle::notifyPaletteTitleChanged() {
|
|
Shinya Kitaoka |
120a6e |
emit broadcastPaletteTitleChanged();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void TPaletteHandle::notifyColorStyleSwitched() {
|
|
Shinya Kitaoka |
120a6e |
emit broadcastColorStyleSwitched();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void TPaletteHandle::notifyColorStyleChanged(bool onDragging,
|
|
Shinya Kitaoka |
120a6e |
bool setDirtyFlag) {
|
|
Shinya Kitaoka |
120a6e |
if (setDirtyFlag && getPalette() && !getPalette()->getDirtyFlag())
|
|
Shinya Kitaoka |
120a6e |
getPalette()->setDirtyFlag(true);
|
|
Toshihiro Shimizu |
890ddd |
|
|
shun_iwasawa |
e553fc |
emit broadcastColorStyleChanged(onDragging);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
if (!onDragging) emit broadcastColorStyleChangedOnMouseRelease();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
shun_iwasawa |
b7aa7c |
|
|
shun_iwasawa |
b7aa7c |
//-----------------------------------------------------------------------------
|
|
shun_iwasawa |
b7aa7c |
|
|
shun_iwasawa |
b7aa7c |
void TPaletteHandle::toggleAutopaint() {
|
|
shun_iwasawa |
b7aa7c |
int index = getStyleIndex();
|
|
shun_iwasawa |
b7aa7c |
if (index > 0) {
|
|
shun_iwasawa |
b7aa7c |
TUndoManager::manager()->add(new AutopaintToggleUndo(this, index));
|
|
shun_iwasawa |
b7aa7c |
}
|
|
shun_iwasawa |
b7aa7c |
}
|