File indexing completed on 2024-12-22 04:12:57
0001 /* 0002 * SPDX-FileCopyrightText: 2011 Dmitry Kazakov <dimula73@gmail.com> 0003 * 0004 * SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #ifndef __MOVE_STROKE_STRATEGY_H 0008 #define __MOVE_STROKE_STRATEGY_H 0009 0010 #include <QHash> 0011 #include <QObject> 0012 0013 #include "kritaui_export.h" 0014 #include "kis_stroke_strategy_undo_command_based.h" 0015 #include "kis_types.h" 0016 #include "kis_lod_transform.h" 0017 #include <QElapsedTimer> 0018 #include "KisAsynchronousStrokeUpdateHelper.h" 0019 #include "KisNodeSelectionRecipe.h" 0020 #include "kis_transaction.h" 0021 0022 #include <memory> 0023 #include <unordered_map> 0024 0025 class KisUpdatesFacade; 0026 class KisPostExecutionUndoAdapter; 0027 0028 0029 class KRITAUI_EXPORT MoveStrokeStrategy : public QObject, public KisStrokeStrategyUndoCommandBased 0030 { 0031 Q_OBJECT 0032 public: 0033 class KRITAUI_EXPORT Data : public KisStrokeJobData { 0034 public: 0035 Data(QPoint _offset); 0036 KisStrokeJobData* createLodClone(int levelOfDetail) override; 0037 0038 QPoint offset; 0039 0040 private: 0041 Data(const Data &rhs, int levelOfDetail); 0042 }; 0043 0044 class KRITAUI_EXPORT PickLayerData : public KisStrokeJobData { 0045 public: 0046 PickLayerData(QPoint _pos); 0047 0048 KisStrokeJobData* createLodClone(int levelOfDetail) override; 0049 0050 QPoint pos; 0051 0052 private: 0053 PickLayerData(const PickLayerData &rhs, int levelOfDetail); 0054 }; 0055 0056 0057 struct KRITAUI_EXPORT BarrierUpdateData : public KisAsynchronousStrokeUpdateHelper::UpdateData 0058 { 0059 BarrierUpdateData(bool forceUpdate); 0060 KisStrokeJobData* createLodClone(int levelOfDetail) override; 0061 protected: 0062 BarrierUpdateData(const BarrierUpdateData &rhs, int levelOfDetail); 0063 }; 0064 0065 public: 0066 MoveStrokeStrategy(KisNodeSelectionRecipe nodeSelection, 0067 KisUpdatesFacade *updatesFacade, 0068 KisStrokeUndoFacade *undoFacade); 0069 0070 MoveStrokeStrategy(KisNodeList nodes, 0071 KisUpdatesFacade *updatesFacade, 0072 KisStrokeUndoFacade *undoFacade); 0073 0074 ~MoveStrokeStrategy() override; 0075 0076 void initStrokeCallback() override; 0077 void finishStrokeCallback() override; 0078 void cancelStrokeCallback() override; 0079 void doStrokeCallback(KisStrokeJobData *data) override; 0080 0081 KisStrokeStrategy* createLodClone(int levelOfDetail) override; 0082 0083 Q_SIGNALS: 0084 void sigHandlesRectCalculated(const QRect &handlesRect); 0085 void sigStrokeStartedEmpty(); 0086 void sigLayersPicked(const KisNodeList &nodes); 0087 0088 private: 0089 MoveStrokeStrategy(const MoveStrokeStrategy &rhs, int lod); 0090 void setUndoEnabled(bool value); 0091 void setUpdatesEnabled(bool value); 0092 private: 0093 void doCanvasUpdate(bool forceUpdate = false); 0094 void tryPostUpdateJob(bool forceUpdate); 0095 0096 private: 0097 struct Private; 0098 QScopedPointer<Private> m_d; 0099 0100 KisNodeSelectionRecipe m_requestedNodeSelection; 0101 KisNodeList m_nodes; 0102 QSharedPointer<std::pair<KisNodeList, QSet<KisNodeSP>>> m_sharedNodes; 0103 QSet<KisNodeSP> m_blacklistedNodes; 0104 KisUpdatesFacade *m_updatesFacade {nullptr}; 0105 QPoint m_finalOffset; 0106 QHash<KisNodeSP, QRect> m_dirtyRects; 0107 bool m_updatesEnabled {true}; 0108 0109 QElapsedTimer m_updateTimer; 0110 bool m_hasPostponedJob {false}; 0111 const int m_updateInterval {30}; 0112 0113 template <typename Functor> 0114 void recursiveApplyNodes(KisNodeList nodes, Functor &&func); 0115 }; 0116 0117 #endif /* __MOVE_STROKE_STRATEGY_H */