File indexing completed on 2024-05-12 15:58:37
0001 /* 0002 * SPDX-FileCopyrightText: 2011 Dmitry Kazakov <dimula73@gmail.com> 0003 * 0004 * SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #ifndef __KIS_PROCESSING_APPLICATOR_H 0008 #define __KIS_PROCESSING_APPLICATOR_H 0009 0010 #include "kritaimage_export.h" 0011 #include "kis_types.h" 0012 0013 #include "kis_stroke_job_strategy.h" 0014 #include "KisImageSignals.h" 0015 #include "kundo2magicstring.h" 0016 #include "kundo2commandextradata.h" 0017 0018 0019 class KRITAIMAGE_EXPORT KisProcessingApplicator 0020 { 0021 public: 0022 enum ProcessingFlag { 0023 NONE = 0x0, 0024 RECURSIVE = 0x1, 0025 NO_UI_UPDATES = 0x2, 0026 SUPPORTS_WRAPAROUND_MODE = 0x4, 0027 NO_IMAGE_UPDATES = 0x8 0028 }; 0029 0030 Q_DECLARE_FLAGS(ProcessingFlags, ProcessingFlag) 0031 0032 public: 0033 KisProcessingApplicator(KisImageWSP image, 0034 KisNodeSP node, 0035 ProcessingFlags flags = NONE, 0036 KisImageSignalVector emitSignals = KisImageSignalVector(), 0037 const KUndo2MagicString &name = KUndo2MagicString(), 0038 KUndo2CommandExtraData *extraData = 0, 0039 int macroId = -1); 0040 0041 ~KisProcessingApplicator(); 0042 0043 void applyVisitor(KisProcessingVisitorSP visitor, 0044 KisStrokeJobData::Sequentiality sequentiality = KisStrokeJobData::SEQUENTIAL, 0045 KisStrokeJobData::Exclusivity exclusivity = KisStrokeJobData::NORMAL); 0046 0047 void applyCommand(KUndo2Command *command, 0048 KisStrokeJobData::Sequentiality sequentiality = KisStrokeJobData::SEQUENTIAL, 0049 KisStrokeJobData::Exclusivity exclusivity = KisStrokeJobData::NORMAL); 0050 0051 void applyVisitorAllFrames(KisProcessingVisitorSP visitor, 0052 KisStrokeJobData::Sequentiality sequentiality = KisStrokeJobData::SEQUENTIAL, 0053 KisStrokeJobData::Exclusivity exclusivity = KisStrokeJobData::NORMAL); 0054 0055 /** 0056 * This method emits all the final update signals of the stroke 0057 * without actually ending the stroke. This can be used for 0058 * long-running strokes which are kept open to implement preview 0059 * of the actions. 0060 * 0061 * WARNING: you cannot add new commands/processings after the 0062 * final signals has been emitted. You should either call end() or 0063 * cancel(). 0064 */ 0065 void explicitlyEmitFinalSignals(); 0066 0067 void end(); 0068 void cancel(); 0069 0070 /** 0071 * Returns the underlying stroke. 0072 * Useful if you want to inject additional jobs in the applicator. 0073 */ 0074 const KisStrokeId getStroke() const; 0075 0076 /** 0077 * @brief runSingleCommandStroke creates a stroke and runs \p cmd in it. 0078 * The text() field fo \p cmd is used as a title of the stroke. 0079 * @param image the image to run the stroke on 0080 * @param cmd the command to be executed 0081 * @param sequentiality sequentiality property of the command being executed (see strokes documentation) 0082 * @param exclusivity sequentiality property of the command being executed (see strokes documentation) 0083 */ 0084 static void runSingleCommandStroke(KisImageSP image, 0085 KUndo2Command *cmd, 0086 KisStrokeJobData::Sequentiality sequentiality = KisStrokeJobData::SEQUENTIAL, 0087 KisStrokeJobData::Exclusivity exclusivity = KisStrokeJobData::NORMAL); 0088 0089 private: 0090 void visitRecursively(KisNodeSP node, 0091 KisProcessingVisitorSP visitor, 0092 KisStrokeJobData::Sequentiality sequentiality, 0093 KisStrokeJobData::Exclusivity exclusivity); 0094 0095 private: 0096 KisImageWSP m_image; 0097 KisNodeSP m_node; 0098 ProcessingFlags m_flags; 0099 KisImageSignalVector m_emitSignals; 0100 KisStrokeId m_strokeId; 0101 bool m_finalSignalsEmitted; 0102 QSharedPointer<bool> m_sharedAllFramesToken; 0103 }; 0104 0105 Q_DECLARE_OPERATORS_FOR_FLAGS(KisProcessingApplicator::ProcessingFlags) 0106 0107 0108 #endif /* __KIS_PROCESSING_APPLICATOR_H */