From b7aa7cd3f38b4b58150b48ca72207647437712c1 Mon Sep 17 00:00:00 2001 From: shun_iwasawa Date: Nov 07 2017 04:11:02 +0000 Subject: undo for autopaint --- diff --git a/toonz/sources/common/tvrender/tcolorstyles.cpp b/toonz/sources/common/tvrender/tcolorstyles.cpp index a67f8f1..49932d6 100644 --- a/toonz/sources/common/tvrender/tcolorstyles.cpp +++ b/toonz/sources/common/tvrender/tcolorstyles.cpp @@ -104,6 +104,7 @@ bool TColorStyle::operator==(const TColorStyle &cs) const { if (m_globalName != cs.getGlobalName()) return false; if (m_isEditedFromOriginal != cs.getIsEditedFlag()) return false; if (m_pickedPosition != cs.getPickedPosition()) return false; + if (m_flags != cs.getFlags()) return false; for (int p = 0; p < colorParamCount; ++p) if (getColorParamValue(p) != cs.getColorParamValue(p)) return false; diff --git a/toonz/sources/include/toonz/tpalettehandle.h b/toonz/sources/include/toonz/tpalettehandle.h index 2f0a27e..d953b21 100644 --- a/toonz/sources/include/toonz/tpalettehandle.h +++ b/toonz/sources/include/toonz/tpalettehandle.h @@ -62,6 +62,7 @@ public: void notifyPaletteDirtyFlagChanged() { emit paletteDirtyFlagChanged(); } void notifyPaletteLockChanged() { emit paletteLockChanged(); } + void toggleAutopaint(); public: signals: diff --git a/toonz/sources/toonz/mainwindow.cpp b/toonz/sources/toonz/mainwindow.cpp index b10db67..52472d7 100644 --- a/toonz/sources/toonz/mainwindow.cpp +++ b/toonz/sources/toonz/mainwindow.cpp @@ -1096,12 +1096,7 @@ void MainWindow::onAbout() { void MainWindow::autofillToggle() { TPaletteHandle *h = TApp::instance()->getCurrentPalette(); - int index = h->getStyleIndex(); - if (index > 0) { - TColorStyle *s = h->getPalette()->getStyle(index); - s->setFlags(s->getFlags() == 0 ? 1 : 0); - h->notifyColorStyleChanged(); - } + h->toggleAutopaint(); } void MainWindow::resetRoomsLayout() { diff --git a/toonz/sources/toonzlib/tpalettehandle.cpp b/toonz/sources/toonzlib/tpalettehandle.cpp index c3315ac..f300da4 100644 --- a/toonz/sources/toonzlib/tpalettehandle.cpp +++ b/toonz/sources/toonzlib/tpalettehandle.cpp @@ -2,6 +2,59 @@ #include "toonz/tpalettehandle.h" +#include "tundo.h" +#include "historytypes.h" + +//============================================================================= +// AutopaintToggleUndo +//----------------------------------------------------------------------------- + +namespace { + class AutopaintToggleUndo final : public TUndo { + TPaletteHandle *m_paletteHandle; + TPaletteP m_palette; + int m_styleId; + bool m_flag; + + public: + AutopaintToggleUndo(TPaletteHandle *paletteHandle, int styleId) + : m_paletteHandle(paletteHandle) + , m_palette(paletteHandle->getPalette()) + , m_styleId(styleId) + {} + + void toggleAutopaint() const { + TColorStyle *s = m_palette->getStyle(m_styleId); + s->setFlags(s->getFlags() == 0 ? 1 : 0); + m_paletteHandle->notifyColorStyleChanged(); + } + + void undo() const override { + toggleAutopaint(); + } + + void redo() const override { + toggleAutopaint(); + } + + void onAdd() { redo(); } + + int getSize() const override { + return sizeof(*this); + } + + QString getHistoryString() override { + return QObject::tr( + "Toggle Autopaint Option Palette : %1 Style#%2") + .arg(QString::fromStdWString(m_palette->getPaletteName())) + .arg(QString::number(m_styleId)); + } + + int getHistoryType() override { return HistoryType::Palette; } + }; + +} // namespace + //============================================================================= // TPaletteHandle //----------------------------------------------------------------------------- @@ -143,3 +196,12 @@ void TPaletteHandle::notifyColorStyleChanged(bool onDragging, if (!onDragging) emit broadcastColorStyleChangedOnMouseRelease(); } + +//----------------------------------------------------------------------------- + +void TPaletteHandle::toggleAutopaint() { + int index = getStyleIndex(); + if (index > 0) { + TUndoManager::manager()->add(new AutopaintToggleUndo(this, index)); + } +} \ No newline at end of file