File indexing completed on 2024-05-19 04:26:35
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 void KisStrokeStrategy::tryCancelCurrentStrokeJobAsync() 0131 { 0132 // noop 0133 } 0134 0135 bool KisStrokeStrategy::isExclusive() const 0136 { 0137 return m_exclusive; 0138 } 0139 0140 bool KisStrokeStrategy::supportsWrapAroundMode() const 0141 { 0142 return m_supportsWrapAroundMode; 0143 } 0144 0145 QString KisStrokeStrategy::id() const 0146 { 0147 return m_id; 0148 } 0149 0150 KUndo2MagicString KisStrokeStrategy::name() const 0151 { 0152 return m_name; 0153 } 0154 0155 KisLodPreferences KisStrokeStrategy::currentLodPreferences() const 0156 { 0157 KIS_SAFE_ASSERT_RECOVER_RETURN_VALUE(m_mutatedJobsInterface, KisLodPreferences()); 0158 return m_mutatedJobsInterface->lodPreferences(); 0159 } 0160 0161 void KisStrokeStrategy::setMutatedJobsInterface(KisStrokesQueueMutatedJobInterface *mutatedJobsInterface, KisStrokeId strokeId) 0162 { 0163 m_mutatedJobsInterface = mutatedJobsInterface; 0164 m_strokeId = strokeId; 0165 } 0166 0167 void KisStrokeStrategy::addMutatedJobs(const QVector<KisStrokeJobData *> list) 0168 { 0169 KIS_SAFE_ASSERT_RECOVER(m_mutatedJobsInterface && m_strokeId) { 0170 qDeleteAll(list); 0171 return; 0172 } 0173 0174 m_mutatedJobsInterface->addMutatedJobs(m_strokeId, list); 0175 } 0176 0177 void KisStrokeStrategy::addMutatedJob(KisStrokeJobData *data) 0178 { 0179 addMutatedJobs({data}); 0180 } 0181 0182 void KisStrokeStrategy::setExclusive(bool value) 0183 { 0184 m_exclusive = value; 0185 } 0186 0187 void KisStrokeStrategy::setSupportsWrapAroundMode(bool value) 0188 { 0189 m_supportsWrapAroundMode = value; 0190 } 0191 0192 bool KisStrokeStrategy::clearsRedoOnStart() const 0193 { 0194 return m_clearsRedoOnStart; 0195 } 0196 0197 void KisStrokeStrategy::setClearsRedoOnStart(bool value) 0198 { 0199 m_clearsRedoOnStart = value; 0200 } 0201 0202 bool KisStrokeStrategy::requestsOtherStrokesToEnd() const 0203 { 0204 return m_requestsOtherStrokesToEnd; 0205 } 0206 0207 void KisStrokeStrategy::setRequestsOtherStrokesToEnd(bool value) 0208 { 0209 m_requestsOtherStrokesToEnd = value; 0210 } 0211 0212 bool KisStrokeStrategy::canForgetAboutMe() const 0213 { 0214 return m_canForgetAboutMe; 0215 } 0216 0217 void KisStrokeStrategy::setCanForgetAboutMe(bool value) 0218 { 0219 m_canForgetAboutMe = value; 0220 } 0221 0222 bool KisStrokeStrategy::isAsynchronouslyCancellable() const 0223 { 0224 return m_asynchronouslyCancellable; 0225 } 0226 0227 void KisStrokeStrategy::setAsynchronouslyCancellable(bool value) 0228 { 0229 m_asynchronouslyCancellable = value; 0230 } 0231 0232 bool KisStrokeStrategy::needsExplicitCancel() const 0233 { 0234 return m_needsExplicitCancel; 0235 } 0236 0237 void KisStrokeStrategy::setNeedsExplicitCancel(bool value) 0238 { 0239 m_needsExplicitCancel = value; 0240 } 0241 0242 qreal KisStrokeStrategy::balancingRatioOverride() const 0243 { 0244 return m_balancingRatioOverride; 0245 } 0246 0247 void KisStrokeStrategy::setBalancingRatioOverride(qreal value) 0248 { 0249 m_balancingRatioOverride = value; 0250 }