Krita Source Code Documentation
Loading...
Searching...
No Matches
KisPaintingInformationBuilder Class Reference

#include <kis_painting_information_builder.h>

+ Inheritance diagram for KisPaintingInformationBuilder:

Public Member Functions

KisPaintInformation continueStroke (KoPointerEvent *event, int timeElapsed)
 
KisPaintInformation hover (const QPointF &imagePoint, const KoPointerEvent *event, bool isStrokeStarted)
 
 KisPaintingInformationBuilder ()
 
qreal pressureToCurve (qreal pressure)
 
void reset ()
 
KisPaintInformation startStroke (KoPointerEvent *event, int timeElapsed, const KoCanvasResourceProvider *manager)
 
 ~KisPaintingInformationBuilder () override
 

Protected Slots

void updateSettings ()
 

Protected Member Functions

virtual QPointF adjustDocumentPoint (const QPointF &point, const QPointF &startPoint)
 
virtual qreal calculatePerspective (const QPointF &documentPoint)
 
virtual bool canvasMirroredX () const
 
virtual bool canvasMirroredY () const
 
virtual qreal canvasRotation () const
 
virtual QPointF documentToImage (const QPointF &point)
 
virtual QPointF imageToDocument (const QPointF &point)
 
virtual QPointF imageToView (const QPointF &point)
 

Private Member Functions

KisPaintInformation createPaintingInformation (KoPointerEvent *event, int timeElapsed)
 

Private Attributes

int m_maxAllowedSpeedValue = 30
 
bool m_pressureDisabled
 
QVector< qreal > m_pressureSamples
 
QScopedPointer< KisSpeedSmootherm_speedSmoother
 
QPointF m_startPoint
 
qreal m_tiltDirectionOffset = 0
 

Static Private Attributes

static const int LEVEL_OF_PRESSURE_RESOLUTION = 1024
 

Detailed Description

Definition at line 23 of file kis_painting_information_builder.h.

Constructor & Destructor Documentation

◆ KisPaintingInformationBuilder()

KisPaintingInformationBuilder::KisPaintingInformationBuilder ( )

Definition at line 29 of file kis_painting_information_builder.cpp.

32{
33 connect(KisConfigNotifier::instance(), SIGNAL(configChanged()),
34 SLOT(updateSettings()));
35
37}
connect(this, SIGNAL(optionsChanged()), this, SLOT(saveOptions()))
static KisConfigNotifier * instance()
QScopedPointer< KisSpeedSmoother > m_speedSmoother

References connect(), KisConfigNotifier::instance(), and updateSettings().

◆ ~KisPaintingInformationBuilder()

KisPaintingInformationBuilder::~KisPaintingInformationBuilder ( )
override

Definition at line 39 of file kis_painting_information_builder.cpp.

40{
41
42}

Member Function Documentation

◆ adjustDocumentPoint()

QPointF KisPaintingInformationBuilder::adjustDocumentPoint ( const QPointF & point,
const QPointF & startPoint )
protectedvirtual

Reimplemented in KisToolFreehandPaintingInformationBuilder.

Definition at line 80 of file kis_painting_information_builder.cpp.

81{
82 return point;
83}

◆ calculatePerspective()

qreal KisPaintingInformationBuilder::calculatePerspective ( const QPointF & documentPoint)
protectedvirtual

Reimplemented in KisToolFreehandPaintingInformationBuilder.

Definition at line 100 of file kis_painting_information_builder.cpp.

101{
102 Q_UNUSED(documentPoint);
103 return 1.0;
104}

◆ canvasMirroredX()

bool KisPaintingInformationBuilder::canvasMirroredX ( ) const
protectedvirtual

Reimplemented in KisConverterPaintingInformationBuilder, and KisToolFreehandPaintingInformationBuilder.

Definition at line 111 of file kis_painting_information_builder.cpp.

112{
113 return false;
114}

◆ canvasMirroredY()

bool KisPaintingInformationBuilder::canvasMirroredY ( ) const
protectedvirtual

Reimplemented in KisConverterPaintingInformationBuilder, and KisToolFreehandPaintingInformationBuilder.

Definition at line 116 of file kis_painting_information_builder.cpp.

117{
118 return false;
119}

◆ canvasRotation()

qreal KisPaintingInformationBuilder::canvasRotation ( ) const
protectedvirtual

Reimplemented in KisConverterPaintingInformationBuilder, and KisToolFreehandPaintingInformationBuilder.

Definition at line 106 of file kis_painting_information_builder.cpp.

107{
108 return 0;
109}

◆ continueStroke()

KisPaintInformation KisPaintingInformationBuilder::continueStroke ( KoPointerEvent * event,
int timeElapsed )

Definition at line 74 of file kis_painting_information_builder.cpp.

76{
77 return createPaintingInformation(event, timeElapsed);
78}
KisPaintInformation createPaintingInformation(KoPointerEvent *event, int timeElapsed)

References createPaintingInformation().

◆ createPaintingInformation()

KisPaintInformation KisPaintingInformationBuilder::createPaintingInformation ( KoPointerEvent * event,
int timeElapsed )
private

Definition at line 121 of file kis_painting_information_builder.cpp.

123{
124
125 QPointF adjusted = adjustDocumentPoint(event->point, m_startPoint);
126 QPointF imagePoint = documentToImage(adjusted);
127 qreal perspective = calculatePerspective(adjusted);
128 const qreal speed = m_speedSmoother->getNextSpeed(imageToView(imagePoint), event->time());
129
130 KisPaintInformation pi(imagePoint,
131 !m_pressureDisabled ? 1.0 : pressureToCurve(event->pressure()),
132 event->xTilt(), event->yTilt(),
133 event->rotation(),
134 event->tangentialPressure(),
135 perspective,
136 timeElapsed,
137 qMin(1.0, speed / qreal(m_maxAllowedSpeedValue)));
138
143
144 return pi;
145}
void setTiltDirectionOffset(qreal angle)
void setCanvasMirroredV(bool value)
void setCanvasMirroredH(bool value)
void setCanvasRotation(qreal rotation)
virtual qreal calculatePerspective(const QPointF &documentPoint)
virtual QPointF imageToView(const QPointF &point)
virtual QPointF adjustDocumentPoint(const QPointF &point, const QPointF &startPoint)
virtual QPointF documentToImage(const QPointF &point)
ulong time() const
QPointF point
The point in document coordinates.

References adjustDocumentPoint(), calculatePerspective(), canvasMirroredX(), canvasMirroredY(), canvasRotation(), documentToImage(), imageToView(), m_maxAllowedSpeedValue, m_pressureDisabled, m_speedSmoother, m_startPoint, m_tiltDirectionOffset, KoPointerEvent::point, KoPointerEvent::pressure(), pressureToCurve(), KisPaintInformation::setCanvasMirroredH(), KisPaintInformation::setCanvasMirroredV(), KisPaintInformation::setCanvasRotation(), KisPaintInformation::setTiltDirectionOffset(), and KoPointerEvent::time().

◆ documentToImage()

QPointF KisPaintingInformationBuilder::documentToImage ( const QPointF & point)
protectedvirtual

Reimplemented in KisConverterPaintingInformationBuilder, and KisToolFreehandPaintingInformationBuilder.

Definition at line 85 of file kis_painting_information_builder.cpp.

86{
87 return point;
88}

◆ hover()

KisPaintInformation KisPaintingInformationBuilder::hover ( const QPointF & imagePoint,
const KoPointerEvent * event,
bool isStrokeStarted )

Definition at line 147 of file kis_painting_information_builder.cpp.

150{
151 const qreal perspective = calculatePerspective(imageToDocument(imagePoint));
152
153 const qreal speed = !isStrokeStarted && event ?
154 m_speedSmoother->getNextSpeed(imageToView(imagePoint), event->time()) :
155 m_speedSmoother->lastSpeed();
156
157 if (event) {
160 event->xTilt(), event->yTilt(),
161 event->rotation(),
162 event->tangentialPressure(),
163 perspective,
164 qMin(1.0, speed / qreal(m_maxAllowedSpeedValue)),
169 } else {
175 return pi;
176 }
177}
static KisPaintInformation createHoveringModeInfo(const QPointF &pos, qreal pressure=PRESSURE_DEFAULT, qreal xTilt=0.0, qreal yTilt=0.0, qreal rotation=0.0, qreal tangentialPressure=0.0, qreal perspective=1.0, qreal speed=0.0, qreal canvasrotation=0.0, bool canvasMirroredH=false, bool canvasMirroredV=false, qreal tiltDirectionOffset=0.0)
virtual QPointF imageToDocument(const QPointF &point)
qreal rotation() const
return the rotation (or a default value)
qreal yTilt() const
qreal tangentialPressure() const
qreal xTilt() const
const double PRESSURE_DEFAULT
Definition kis_global.h:99

References calculatePerspective(), canvasMirroredX(), canvasMirroredY(), canvasRotation(), KisPaintInformation::createHoveringModeInfo(), imageToDocument(), imageToView(), m_maxAllowedSpeedValue, m_speedSmoother, m_tiltDirectionOffset, PRESSURE_DEFAULT, KoPointerEvent::rotation(), KisPaintInformation::setCanvasMirroredH(), KisPaintInformation::setCanvasMirroredV(), KisPaintInformation::setCanvasRotation(), KisPaintInformation::setTiltDirectionOffset(), KoPointerEvent::tangentialPressure(), KoPointerEvent::time(), KoPointerEvent::xTilt(), and KoPointerEvent::yTilt().

◆ imageToDocument()

QPointF KisPaintingInformationBuilder::imageToDocument ( const QPointF & point)
protectedvirtual

Reimplemented in KisConverterPaintingInformationBuilder, and KisToolFreehandPaintingInformationBuilder.

Definition at line 90 of file kis_painting_information_builder.cpp.

91{
92 return point;
93}

◆ imageToView()

QPointF KisPaintingInformationBuilder::imageToView ( const QPointF & point)
protectedvirtual

◆ pressureToCurve()

qreal KisPaintingInformationBuilder::pressureToCurve ( qreal pressure)

Definition at line 179 of file kis_painting_information_builder.cpp.

180{
182}
static qreal interpolateLinear(qreal normalizedValue, const QVector< qreal > &transfer)

References KisCubicCurve::interpolateLinear(), and m_pressureSamples.

◆ reset()

void KisPaintingInformationBuilder::reset ( )

Definition at line 184 of file kis_painting_information_builder.cpp.

185{
186 m_speedSmoother->clear();
187}

References m_speedSmoother.

◆ startStroke()

KisPaintInformation KisPaintingInformationBuilder::startStroke ( KoPointerEvent * event,
int timeElapsed,
const KoCanvasResourceProvider * manager )

◆ updateSettings

void KisPaintingInformationBuilder::updateSettings ( )
protectedslot

Definition at line 44 of file kis_painting_information_builder.cpp.

45{
46 KisConfig cfg(true);
47 const KisCubicCurve curve(cfg.pressureTabletCurve());
48 m_pressureSamples = curve.floatTransfer(LEVEL_OF_PRESSURE_RESOLUTION + 1);
49 m_maxAllowedSpeedValue = cfg.readEntry("maxAllowedSpeedValue", 30);
50
51 // The setting is stored in [-180, 180] degrees range to match the UI.
52 // We now need to convert it to [0, 360) range.
53 m_tiltDirectionOffset = cfg.readEntry("tiltDirectionOffset", 0);
54 if (m_tiltDirectionOffset < 0.0) {
55 m_tiltDirectionOffset += 360.0;
56 }
57
58 m_speedSmoother->updateSettings();
59}

References KisCubicCurve::floatTransfer(), LEVEL_OF_PRESSURE_RESOLUTION, m_maxAllowedSpeedValue, m_pressureSamples, m_speedSmoother, m_tiltDirectionOffset, KisConfig::pressureTabletCurve(), and KisConfig::readEntry().

Member Data Documentation

◆ LEVEL_OF_PRESSURE_RESOLUTION

const int KisPaintingInformationBuilder::LEVEL_OF_PRESSURE_RESOLUTION = 1024
staticprivate

Defines how many discrete samples are stored in a precomputed array of different pressures.

Definition at line 67 of file kis_painting_information_builder.h.

◆ m_maxAllowedSpeedValue

int KisPaintingInformationBuilder::m_maxAllowedSpeedValue = 30
private

Definition at line 74 of file kis_painting_information_builder.h.

◆ m_pressureDisabled

bool KisPaintingInformationBuilder::m_pressureDisabled
private

Definition at line 73 of file kis_painting_information_builder.h.

◆ m_pressureSamples

QVector<qreal> KisPaintingInformationBuilder::m_pressureSamples
private

Definition at line 70 of file kis_painting_information_builder.h.

◆ m_speedSmoother

QScopedPointer<KisSpeedSmoother> KisPaintingInformationBuilder::m_speedSmoother
private

Definition at line 72 of file kis_painting_information_builder.h.

◆ m_startPoint

QPointF KisPaintingInformationBuilder::m_startPoint
private

Definition at line 71 of file kis_painting_information_builder.h.

◆ m_tiltDirectionOffset

qreal KisPaintingInformationBuilder::m_tiltDirectionOffset = 0
private

Definition at line 75 of file kis_painting_information_builder.h.


The documentation for this class was generated from the following files: