File indexing completed on 2024-12-22 04:12:58
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_PAINTING_INFORMATION_BUILDER_H 0008 #define __KIS_PAINTING_INFORMATION_BUILDER_H 0009 0010 #include <QObject> 0011 #include <QVector> 0012 0013 #include "kis_types.h" 0014 #include "kritaui_export.h" 0015 #include <brushengine/kis_paint_information.h> 0016 0017 class KoPointerEvent; 0018 class KisToolFreehand; 0019 class KisCoordinatesConverter; 0020 class KisSpeedSmoother; 0021 class KoCanvasResourceProvider; 0022 0023 class KRITAUI_EXPORT KisPaintingInformationBuilder : public QObject 0024 { 0025 Q_OBJECT 0026 0027 public: 0028 KisPaintingInformationBuilder(); 0029 ~KisPaintingInformationBuilder() override; 0030 0031 KisPaintInformation startStroke(KoPointerEvent *event, int timeElapsed, const KoCanvasResourceProvider *manager); 0032 0033 KisPaintInformation continueStroke(KoPointerEvent *event, 0034 int timeElapsed); 0035 0036 KisPaintInformation hover(const QPointF &imagePoint, 0037 const KoPointerEvent *event, 0038 bool isStrokeStarted); 0039 0040 qreal pressureToCurve(qreal pressure); 0041 0042 void reset(); 0043 0044 protected Q_SLOTS: 0045 void updateSettings(); 0046 0047 protected: 0048 virtual QPointF adjustDocumentPoint(const QPointF &point, const QPointF &startPoint); 0049 virtual QPointF documentToImage(const QPointF &point); 0050 virtual QPointF imageToView(const QPointF &point); 0051 virtual qreal calculatePerspective(const QPointF &documentPoint); 0052 0053 virtual qreal canvasRotation() const; 0054 virtual bool canvasMirroredX() const; 0055 virtual bool canvasMirroredY() const; 0056 0057 private: 0058 0059 KisPaintInformation createPaintingInformation(KoPointerEvent *event, 0060 int timeElapsed); 0061 0062 /** 0063 * Defines how many discrete samples are stored in a precomputed array 0064 * of different pressures. 0065 */ 0066 static const int LEVEL_OF_PRESSURE_RESOLUTION; 0067 0068 private: 0069 QVector<qreal> m_pressureSamples; 0070 QPointF m_startPoint; 0071 QScopedPointer<KisSpeedSmoother> m_speedSmoother; 0072 bool m_pressureDisabled; 0073 int m_maxAllowedSpeedValue = 30; 0074 }; 0075 0076 class KRITAUI_EXPORT KisConverterPaintingInformationBuilder : public KisPaintingInformationBuilder 0077 { 0078 Q_OBJECT 0079 0080 public: 0081 KisConverterPaintingInformationBuilder(const KisCoordinatesConverter *converter); 0082 0083 protected: 0084 QPointF documentToImage(const QPointF &point) override; 0085 QPointF imageToView(const QPointF &point) override; 0086 0087 qreal canvasRotation() const override; 0088 bool canvasMirroredX() const override; 0089 bool canvasMirroredY() const override; 0090 0091 private: 0092 const KisCoordinatesConverter *m_converter; 0093 }; 0094 0095 class KRITAUI_EXPORT KisToolFreehandPaintingInformationBuilder : public KisPaintingInformationBuilder 0096 { 0097 Q_OBJECT 0098 0099 public: 0100 KisToolFreehandPaintingInformationBuilder(KisToolFreehand *tool); 0101 0102 protected: 0103 QPointF documentToImage(const QPointF &point) override; 0104 QPointF imageToView(const QPointF &point) override; 0105 QPointF adjustDocumentPoint(const QPointF &point, const QPointF &startPoint) override; 0106 qreal calculatePerspective(const QPointF &documentPoint) override; 0107 0108 qreal canvasRotation() const override; 0109 bool canvasMirroredX() const override; 0110 bool canvasMirroredY() const override; 0111 0112 private: 0113 KisToolFreehand *m_tool; 0114 }; 0115 0116 #endif /* __KIS_PAINTING_INFORMATION_BUILDER_H */