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 #ifndef __KIS_STROKE_H
0008 #define __KIS_STROKE_H
0009 
0010 #include <QQueue>
0011 #include <QScopedPointer>
0012 
0013 #include <kis_types.h>
0014 #include "kritaimage_export.h"
0015 #include "kis_stroke_job.h"
0016 
0017 class KisStrokeStrategy;
0018 class KUndo2MagicString;
0019 
0020 
0021 class KRITAIMAGE_EXPORT KisStroke
0022 {
0023 public:
0024     enum Type {
0025         LEGACY,
0026         LOD0,
0027         LODN,
0028         SUSPEND,
0029         RESUME
0030     };
0031 
0032 public:
0033     KisStroke(KisStrokeStrategy *strokeStrategy, Type type = LEGACY, int levelOfDetail = 0);
0034     ~KisStroke();
0035 
0036     void addJob(KisStrokeJobData *data);
0037     void addMutatedJobs(const QVector<KisStrokeJobData *> list);
0038 
0039     KUndo2MagicString name() const;
0040     QString id() const;
0041 
0042     bool hasJobs() const;
0043     qint32 numJobs() const;
0044     KisStrokeJob* popOneJob();
0045 
0046     void endStroke();
0047     void cancelStroke();
0048 
0049     bool canCancel() const;
0050 
0051     bool supportsSuspension();
0052     void suspendStroke(KisStrokeSP recipient);
0053 
0054     bool isInitialized() const;
0055     bool isEnded() const;
0056     bool isCancelled() const;
0057 
0058     bool isExclusive() const;
0059     bool supportsWrapAroundMode() const;
0060     int worksOnLevelOfDetail() const;
0061     bool canForgetAboutMe() const;
0062     bool isAsynchronouslyCancellable() const;
0063     bool clearsRedoOnStart() const;
0064     qreal balancingRatioOverride() const;
0065 
0066     KisStrokeJobData::Sequentiality nextJobSequentiality() const;
0067 
0068     int nextJobLevelOfDetail() const;
0069 
0070     void setLodBuddy(KisStrokeSP buddy);
0071     KisStrokeSP lodBuddy() const;
0072 
0073     Type type() const;
0074 
0075 private:
0076     void enqueue(KisStrokeJobStrategy *strategy,
0077                  KisStrokeJobData *data);
0078 
0079     // for suspend/resume jobs
0080     void prepend(KisStrokeJobStrategy *strategy,
0081                  KisStrokeJobData *data,
0082                  int levelOfDetail,
0083                  bool isOwnJob);
0084 
0085     KisStrokeJob* dequeue();
0086 
0087     void clearQueueOnCancel();
0088     bool sanityCheckAllJobsAreCancellable() const;
0089 
0090 private:
0091     // for testing use only, do not use in real code
0092     friend class KisStrokeTest;
0093     friend class KisStrokeStrategyUndoCommandBasedTest;
0094     QQueue<KisStrokeJob*>& testingGetQueue() {
0095         return m_jobsQueue;
0096     }
0097 
0098 private:
0099     // the strategies are owned by the stroke
0100     QScopedPointer<KisStrokeStrategy> m_strokeStrategy;
0101     QScopedPointer<KisStrokeJobStrategy> m_initStrategy;
0102     QScopedPointer<KisStrokeJobStrategy> m_dabStrategy;
0103     QScopedPointer<KisStrokeJobStrategy> m_cancelStrategy;
0104     QScopedPointer<KisStrokeJobStrategy> m_finishStrategy;
0105     QScopedPointer<KisStrokeJobStrategy> m_suspendStrategy;
0106     QScopedPointer<KisStrokeJobStrategy> m_resumeStrategy;
0107 
0108     QQueue<KisStrokeJob*> m_jobsQueue;
0109     bool m_strokeInitialized;
0110     bool m_strokeEnded;
0111     bool m_strokeSuspended;
0112     bool m_isCancelled; // cancelled strokes are always 'ended' as well
0113 
0114     int m_worksOnLevelOfDetail;
0115     Type m_type;
0116     KisStrokeSP m_lodBuddy;
0117 };
0118 
0119 #endif /* __KIS_STROKE_H */