2016-03-19 06:57:51 +13:00
|
|
|
|
|
|
|
|
|
|
|
#include "toonz/tpalettehandle.h"
|
|
|
|
|
2017-11-07 17:11:02 +13:00
|
|
|
#include "tundo.h"
|
|
|
|
#include "historytypes.h"
|
|
|
|
|
|
|
|
//=============================================================================
|
|
|
|
// AutopaintToggleUndo
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
namespace {
|
2017-11-07 20:24:20 +13:00
|
|
|
class AutopaintToggleUndo final : public TUndo {
|
|
|
|
TPaletteHandle *m_paletteHandle;
|
|
|
|
TPaletteP m_palette;
|
|
|
|
int m_styleId;
|
|
|
|
bool m_flag;
|
|
|
|
|
|
|
|
public:
|
|
|
|
AutopaintToggleUndo(TPaletteHandle *paletteHandle, int styleId)
|
2017-11-07 17:11:02 +13:00
|
|
|
: m_paletteHandle(paletteHandle)
|
|
|
|
, m_palette(paletteHandle->getPalette())
|
2017-11-07 20:24:20 +13:00
|
|
|
, m_styleId(styleId) {}
|
2017-11-07 17:11:02 +13:00
|
|
|
|
2017-11-07 20:24:20 +13:00
|
|
|
void toggleAutopaint() const {
|
|
|
|
TColorStyle *s = m_palette->getStyle(m_styleId);
|
|
|
|
s->setFlags(s->getFlags() == 0 ? 1 : 0);
|
|
|
|
m_paletteHandle->notifyColorStyleChanged();
|
|
|
|
}
|
2017-11-07 17:11:02 +13:00
|
|
|
|
2017-11-07 20:24:20 +13:00
|
|
|
void undo() const override { toggleAutopaint(); }
|
2017-11-07 17:11:02 +13:00
|
|
|
|
2017-11-07 20:24:20 +13:00
|
|
|
void redo() const override { toggleAutopaint(); }
|
2017-11-07 17:11:02 +13:00
|
|
|
|
2020-09-16 09:49:57 +12:00
|
|
|
void onAdd() override { redo(); }
|
2017-11-07 17:11:02 +13:00
|
|
|
|
2017-11-07 20:24:20 +13:00
|
|
|
int getSize() const override { return sizeof(*this); }
|
2017-11-07 17:11:02 +13:00
|
|
|
|
2017-11-07 20:24:20 +13:00
|
|
|
QString getHistoryString() override {
|
|
|
|
return QObject::tr("Toggle Autopaint Option Palette : %1 Style#%2")
|
2017-11-07 17:11:02 +13:00
|
|
|
.arg(QString::fromStdWString(m_palette->getPaletteName()))
|
|
|
|
.arg(QString::number(m_styleId));
|
2017-11-07 20:24:20 +13:00
|
|
|
}
|
2017-11-07 17:11:02 +13:00
|
|
|
|
2017-11-07 20:24:20 +13:00
|
|
|
int getHistoryType() override { return HistoryType::Palette; }
|
|
|
|
};
|
2017-11-07 17:11:02 +13:00
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
2016-03-19 06:57:51 +13:00
|
|
|
//=============================================================================
|
|
|
|
// TPaletteHandle
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
TPaletteHandle::TPaletteHandle()
|
2016-06-15 18:43:10 +12:00
|
|
|
: m_palette(0), m_styleIndex(-1), m_styleParamIndex(-1) {
|
|
|
|
connectBroadcasts(this);
|
2016-03-19 06:57:51 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
TPaletteHandle::~TPaletteHandle() {}
|
2016-03-19 06:57:51 +13:00
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
TPalette *TPaletteHandle::getPalette() const { return m_palette; }
|
2016-03-19 06:57:51 +13:00
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
int TPaletteHandle::getStyleIndex() const { return m_styleIndex; }
|
2016-03-19 06:57:51 +13:00
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
int TPaletteHandle::getStyleParamIndex() const { return m_styleParamIndex; }
|
2016-03-19 06:57:51 +13:00
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
TColorStyle *TPaletteHandle::getStyle() const {
|
|
|
|
if (!m_palette || m_styleIndex == -1) return 0;
|
|
|
|
return m_palette->getStyle(m_styleIndex);
|
2016-03-19 06:57:51 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
bool TPaletteHandle::connectBroadcasts(const QObject *receiver) {
|
|
|
|
bool ret = true;
|
|
|
|
|
|
|
|
ret = connect(this, SIGNAL(broadcastPaletteChanged()), receiver,
|
|
|
|
SIGNAL(paletteChanged())) &&
|
|
|
|
ret;
|
|
|
|
ret = connect(this, SIGNAL(broadcastPaletteTitleChanged()), receiver,
|
|
|
|
SIGNAL(paletteTitleChanged())) &&
|
|
|
|
ret;
|
|
|
|
ret = connect(this, SIGNAL(broadcastColorStyleSwitched()), receiver,
|
|
|
|
SIGNAL(colorStyleSwitched())) &&
|
|
|
|
ret;
|
2017-11-07 20:24:20 +13:00
|
|
|
ret = connect(this, SIGNAL(broadcastColorStyleChanged(bool)), receiver,
|
|
|
|
SIGNAL(colorStyleChanged(bool))) &&
|
2016-06-15 18:43:10 +12:00
|
|
|
ret;
|
|
|
|
ret = connect(this, SIGNAL(broadcastColorStyleChangedOnMouseRelease()),
|
|
|
|
receiver, SIGNAL(colorStyleChangedOnMouseRelease())) &&
|
|
|
|
ret;
|
|
|
|
|
|
|
|
return ret;
|
2016-03-19 06:57:51 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
bool TPaletteHandle::disconnectBroadcasts(const QObject *receiver) {
|
|
|
|
bool ret = true;
|
|
|
|
|
|
|
|
ret = disconnect(this, SIGNAL(broadcastPaletteChanged()), receiver,
|
|
|
|
SIGNAL(paletteChanged())) &&
|
|
|
|
ret;
|
|
|
|
ret = disconnect(this, SIGNAL(broadcastPaletteTitleChanged()), receiver,
|
|
|
|
SIGNAL(paletteTitleChanged())) &&
|
|
|
|
ret;
|
|
|
|
ret = disconnect(this, SIGNAL(broadcastColorStyleSwitched()), receiver,
|
|
|
|
SIGNAL(colorStyleSwitched())) &&
|
|
|
|
ret;
|
2017-11-07 20:24:20 +13:00
|
|
|
ret = disconnect(this, SIGNAL(broadcastColorStyleChanged(bool)), receiver,
|
|
|
|
SIGNAL(colorStyleChanged(bool))) &&
|
2016-06-15 18:43:10 +12:00
|
|
|
ret;
|
|
|
|
ret = disconnect(this, SIGNAL(broadcastColorStyleChangedOnMouseRelease()),
|
|
|
|
receiver, SIGNAL(colorStyleChangedOnMouseRelease())) &&
|
|
|
|
ret;
|
|
|
|
|
|
|
|
return ret;
|
2016-03-19 06:57:51 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
void TPaletteHandle::setPalette(TPalette *palette, int styleIndex) {
|
2019-07-12 03:57:23 +12:00
|
|
|
if (palette) {
|
|
|
|
if (styleIndex < 0) {
|
|
|
|
styleIndex = palette->getCurrentStyleId();
|
|
|
|
if (!palette->getStylePage(styleIndex)) { // in case the style is deleted
|
|
|
|
styleIndex = 1;
|
|
|
|
palette->setCurrentStyleId(styleIndex);
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
palette->setCurrentStyleId(styleIndex);
|
|
|
|
}
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
if (m_palette == palette)
|
|
|
|
setStyleIndex(styleIndex);
|
|
|
|
else {
|
|
|
|
m_palette = palette;
|
|
|
|
m_styleIndex = styleIndex;
|
|
|
|
m_styleParamIndex = 0;
|
|
|
|
|
|
|
|
emit paletteSwitched();
|
2020-08-07 18:11:19 +12:00
|
|
|
// to let ToonzCheck to update the current index
|
|
|
|
emit broadcastColorStyleSwitched();
|
2016-06-15 18:43:10 +12:00
|
|
|
}
|
2016-03-19 06:57:51 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
2019-08-02 21:06:02 +12:00
|
|
|
// forceEmit flag is used in PageViewer and StylePicker tool.
|
2019-04-01 21:18:10 +13:00
|
|
|
// See the function PageViewer::setCurrentStyleIndex() in paletteviewergui.cpp
|
2019-08-02 21:06:02 +12:00
|
|
|
// Also see the function StylePickerTool::pick() in stylepickertool.cpp
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2019-04-01 21:18:10 +13:00
|
|
|
void TPaletteHandle::setStyleIndex(int index, bool forceEmit) {
|
|
|
|
if (m_styleIndex != index || m_styleParamIndex != 0 || forceEmit) {
|
2019-07-12 03:57:23 +12:00
|
|
|
if (m_palette) m_palette->setCurrentStyleId(index);
|
2018-11-12 22:58:53 +13:00
|
|
|
m_styleIndex = index;
|
|
|
|
m_styleParamIndex = 0;
|
|
|
|
emit broadcastColorStyleSwitched();
|
|
|
|
}
|
2016-03-19 06:57:51 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
void TPaletteHandle::setStyleParamIndex(int index) {
|
|
|
|
if (m_styleParamIndex != index) {
|
|
|
|
m_styleParamIndex = index;
|
|
|
|
emit broadcastColorStyleSwitched();
|
|
|
|
}
|
2016-03-19 06:57:51 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
void TPaletteHandle::notifyPaletteChanged() { emit broadcastPaletteChanged(); }
|
2016-03-19 06:57:51 +13:00
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
void TPaletteHandle::notifyPaletteTitleChanged() {
|
|
|
|
emit broadcastPaletteTitleChanged();
|
2016-03-19 06:57:51 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
void TPaletteHandle::notifyColorStyleSwitched() {
|
|
|
|
emit broadcastColorStyleSwitched();
|
2016-03-19 06:57:51 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
void TPaletteHandle::notifyColorStyleChanged(bool onDragging,
|
|
|
|
bool setDirtyFlag) {
|
|
|
|
if (setDirtyFlag && getPalette() && !getPalette()->getDirtyFlag())
|
|
|
|
getPalette()->setDirtyFlag(true);
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2017-11-07 20:24:20 +13:00
|
|
|
emit broadcastColorStyleChanged(onDragging);
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
if (!onDragging) emit broadcastColorStyleChangedOnMouseRelease();
|
2016-03-19 06:57:51 +13:00
|
|
|
}
|
2017-11-07 17:11:02 +13:00
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
void TPaletteHandle::toggleAutopaint() {
|
|
|
|
int index = getStyleIndex();
|
|
|
|
if (index > 0) {
|
|
|
|
TUndoManager::manager()->add(new AutopaintToggleUndo(this, index));
|
|
|
|
}
|
2020-09-16 09:49:57 +12:00
|
|
|
}
|