undo for autopaint

This commit is contained in:
shun_iwasawa 2017-11-07 13:11:02 +09:00
parent 4183496bdc
commit b7aa7cd3f3
4 changed files with 65 additions and 6 deletions

View file

@ -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;

View file

@ -62,6 +62,7 @@ public:
void notifyPaletteDirtyFlagChanged() { emit paletteDirtyFlagChanged(); }
void notifyPaletteLockChanged() { emit paletteLockChanged(); }
void toggleAutopaint();
public:
signals:

View file

@ -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() {

View file

@ -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));
}
}