File indexing completed on 2024-05-12 16:01:55

0001 /*
0002  *  SPDX-FileCopyrightText: 2018 Dmitry Kazakov <dimula73@gmail.com>
0003  *
0004  *  SPDX-License-Identifier: GPL-2.0-or-later
0005  */
0006 
0007 #include "KisUndoActionsUpdateManager.h"
0008 
0009 #include <QAction>
0010 #include <kundo2stack.h>
0011 
0012 #include <KisDocument.h>
0013 
0014 
0015 KisUndoActionsUpdateManager::KisUndoActionsUpdateManager(QAction *undoAction, QAction *redoAction, QObject *parent)
0016     : QObject(parent),
0017       m_undoAction(undoAction),
0018       m_redoAction(redoAction)
0019 {
0020 
0021 }
0022 
0023 void KisUndoActionsUpdateManager::setCurrentDocument(KisDocument *document)
0024 {
0025     m_documentConnections.clear();
0026 
0027     if (document) {
0028 
0029         KUndo2Stack *stack = document->undoStack();
0030 
0031         m_documentConnections.addConnection(stack, SIGNAL(undoTextChanged(QString)), this, SLOT(slotUndoTextChanged(QString)));
0032         m_documentConnections.addConnection(stack, SIGNAL(redoTextChanged(QString)), this, SLOT(slotRedoTextChanged(QString)));
0033 
0034         slotUndoTextChanged(stack->undoText());
0035         slotRedoTextChanged(stack->redoText());
0036 
0037         m_undoAction->setEnabled(stack->canUndo());
0038         m_redoAction->setEnabled(stack->canRedo());
0039     }
0040 }
0041 
0042 void KisUndoActionsUpdateManager::slotUndoTextChanged(const QString &text)
0043 {
0044     m_undoAction->setText(i18n("Undo %1", text));
0045 }
0046 
0047 void KisUndoActionsUpdateManager::slotRedoTextChanged(const QString &text)
0048 {
0049     m_redoAction->setText(i18n("Redo %1", text));
0050 }
0051