File indexing completed on 2024-05-12 15:58:43
0001 /* 0002 * SPDX-FileCopyrightText: 2011 Dmitry Kazakov <dimula73@gmail.com> 0003 * 0004 * SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #include "kis_stroke_strategy.h" 0008 #include <KoCompositeOpRegistry.h> 0009 #include "kis_stroke_job_strategy.h" 0010 #include "KisStrokesQueueMutatedJobInterface.h" 0011 0012 0013 KisStrokeStrategy::KisStrokeStrategy(const QLatin1String &id, const KUndo2MagicString &name) 0014 : m_exclusive(false), 0015 m_supportsWrapAroundMode(false), 0016 m_clearsRedoOnStart(true), 0017 m_requestsOtherStrokesToEnd(true), 0018 m_canForgetAboutMe(false), 0019 m_asynchronouslyCancellable(true), 0020 m_needsExplicitCancel(false), 0021 m_forceLodModeIfPossible(false), 0022 m_balancingRatioOverride(-1.0), 0023 m_id(id), 0024 m_name(name), 0025 m_mutatedJobsInterface(0) 0026 { 0027 } 0028 0029 KisStrokeStrategy::KisStrokeStrategy(const KisStrokeStrategy &rhs) 0030 : m_exclusive(rhs.m_exclusive), 0031 m_supportsWrapAroundMode(rhs.m_supportsWrapAroundMode), 0032 m_clearsRedoOnStart(rhs.m_clearsRedoOnStart), 0033 m_requestsOtherStrokesToEnd(rhs.m_requestsOtherStrokesToEnd), 0034 m_canForgetAboutMe(rhs.m_canForgetAboutMe), 0035 m_asynchronouslyCancellable(rhs.m_asynchronouslyCancellable), 0036 m_needsExplicitCancel(rhs.m_needsExplicitCancel), 0037 m_forceLodModeIfPossible(rhs.m_forceLodModeIfPossible), 0038 m_balancingRatioOverride(rhs.m_balancingRatioOverride), 0039 m_id(rhs.m_id), 0040 m_name(rhs.m_name), 0041 m_mutatedJobsInterface(0) 0042 { 0043 KIS_ASSERT_RECOVER_NOOP(!rhs.m_strokeId && !m_mutatedJobsInterface && 0044 "After the stroke has been started, no copying must happen"); 0045 } 0046 0047 bool KisStrokeStrategy::forceLodModeIfPossible() const 0048 { 0049 return m_forceLodModeIfPossible; 0050 } 0051 0052 void KisStrokeStrategy::setForceLodModeIfPossible(bool value) 0053 { 0054 m_forceLodModeIfPossible = value; 0055 } 0056 0057 KisStrokeStrategy::~KisStrokeStrategy() 0058 { 0059 } 0060 0061 void KisStrokeStrategy::notifyUserStartedStroke() 0062 { 0063 } 0064 0065 void KisStrokeStrategy::notifyUserEndedStroke() 0066 { 0067 } 0068 0069 KisStrokeJobStrategy* KisStrokeStrategy::createInitStrategy() 0070 { 0071 return 0; 0072 } 0073 0074 KisStrokeJobStrategy* KisStrokeStrategy::createFinishStrategy() 0075 { 0076 return 0; 0077 } 0078 0079 KisStrokeJobStrategy* KisStrokeStrategy::createCancelStrategy() 0080 { 0081 return 0; 0082 } 0083 0084 KisStrokeJobStrategy* KisStrokeStrategy::createDabStrategy() 0085 { 0086 return 0; 0087 } 0088 0089 KisStrokeJobStrategy* KisStrokeStrategy::createSuspendStrategy() 0090 { 0091 return 0; 0092 } 0093 0094 KisStrokeJobStrategy* KisStrokeStrategy::createResumeStrategy() 0095 { 0096 return 0; 0097 } 0098 0099 KisStrokeJobData* KisStrokeStrategy::createInitData() 0100 { 0101 return 0; 0102 } 0103 0104 KisStrokeJobData* KisStrokeStrategy::createFinishData() 0105 { 0106 return 0; 0107 } 0108 0109 KisStrokeJobData* KisStrokeStrategy::createCancelData() 0110 { 0111 return 0; 0112 } 0113 0114 KisStrokeJobData* KisStrokeStrategy::createSuspendData() 0115 { 0116 return 0; 0117 } 0118 0119 KisStrokeJobData* KisStrokeStrategy::createResumeData() 0120 { 0121 return 0; 0122 } 0123 0124 KisStrokeStrategy* KisStrokeStrategy::createLodClone(int levelOfDetail) 0125 { 0126 Q_UNUSED(levelOfDetail); 0127 return 0; 0128 } 0129 0130 bool KisStrokeStrategy::isExclusive() const 0131 { 0132 return m_exclusive; 0133 } 0134 0135 bool KisStrokeStrategy::supportsWrapAroundMode() const 0136 { 0137 return m_supportsWrapAroundMode; 0138 } 0139 0140 QString KisStrokeStrategy::id() const 0141 { 0142 return m_id; 0143 } 0144 0145 KUndo2MagicString KisStrokeStrategy::name() const 0146 { 0147 return m_name; 0148 } 0149 0150 KisLodPreferences KisStrokeStrategy::currentLodPreferences() const 0151 { 0152 KIS_SAFE_ASSERT_RECOVER_RETURN_VALUE(m_mutatedJobsInterface, KisLodPreferences()); 0153 return m_mutatedJobsInterface->lodPreferences(); 0154 } 0155 0156 void KisStrokeStrategy::setMutatedJobsInterface(KisStrokesQueueMutatedJobInterface *mutatedJobsInterface, KisStrokeId strokeId) 0157 { 0158 m_mutatedJobsInterface = mutatedJobsInterface; 0159 m_strokeId = strokeId; 0160 } 0161 0162 void KisStrokeStrategy::addMutatedJobs(const QVector<KisStrokeJobData *> list) 0163 { 0164 KIS_SAFE_ASSERT_RECOVER(m_mutatedJobsInterface && m_strokeId) { 0165 qDeleteAll(list); 0166 return; 0167 } 0168 0169 m_mutatedJobsInterface->addMutatedJobs(m_strokeId, list); 0170 } 0171 0172 void KisStrokeStrategy::addMutatedJob(KisStrokeJobData *data) 0173 { 0174 addMutatedJobs({data}); 0175 } 0176 0177 void KisStrokeStrategy::setExclusive(bool value) 0178 { 0179 m_exclusive = value; 0180 } 0181 0182 void KisStrokeStrategy::setSupportsWrapAroundMode(bool value) 0183 { 0184 m_supportsWrapAroundMode = value; 0185 } 0186 0187 bool KisStrokeStrategy::clearsRedoOnStart() const 0188 { 0189 return m_clearsRedoOnStart; 0190 } 0191 0192 void KisStrokeStrategy::setClearsRedoOnStart(bool value) 0193 { 0194 m_clearsRedoOnStart = value; 0195 } 0196 0197 bool KisStrokeStrategy::requestsOtherStrokesToEnd() const 0198 { 0199 return m_requestsOtherStrokesToEnd; 0200 } 0201 0202 void KisStrokeStrategy::setRequestsOtherStrokesToEnd(bool value) 0203 { 0204 m_requestsOtherStrokesToEnd = value; 0205 } 0206 0207 bool KisStrokeStrategy::canForgetAboutMe() const 0208 { 0209 return m_canForgetAboutMe; 0210 } 0211 0212 void KisStrokeStrategy::setCanForgetAboutMe(bool value) 0213 { 0214 m_canForgetAboutMe = value; 0215 } 0216 0217 bool KisStrokeStrategy::isAsynchronouslyCancellable() const 0218 { 0219 return m_asynchronouslyCancellable; 0220 } 0221 0222 void KisStrokeStrategy::setAsynchronouslyCancellable(bool value) 0223 { 0224 m_asynchronouslyCancellable = value; 0225 } 0226 0227 bool KisStrokeStrategy::needsExplicitCancel() const 0228 { 0229 return m_needsExplicitCancel; 0230 } 0231 0232 void KisStrokeStrategy::setNeedsExplicitCancel(bool value) 0233 { 0234 m_needsExplicitCancel = value; 0235 } 0236 0237 qreal KisStrokeStrategy::balancingRatioOverride() const 0238 { 0239 return m_balancingRatioOverride; 0240 } 0241 0242 void KisStrokeStrategy::setBalancingRatioOverride(qreal value) 0243 { 0244 m_balancingRatioOverride = value; 0245 }