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

#include <KisStabilizerDelayedPaintHelper.h>

+ Inheritance diagram for KisStabilizerDelayedPaintHelper:

Classes

struct  TimedPaintInfo
 

Public Member Functions

void cancel ()
 
void end ()
 
bool hasLastPaintInformation () const
 
 KisStabilizerDelayedPaintHelper ()
 
KisPaintInformation lastPaintInformation () const
 
void paintSome ()
 
bool running () const
 
void setPaintLineCallback (std::function< void(const KisPaintInformation &, const KisPaintInformation &)> paintLine)
 
void setUpdateOutlineCallback (std::function< void()> requestUpdateOutline)
 
void start (const KisPaintInformation &firstPaintInfo)
 
void update (const QVector< KisPaintInformation > &newPaintInfos)
 
 ~KisStabilizerDelayedPaintHelper () override
 

Private Slots

void stabilizerDelayedPaintTimer ()
 

Private Attributes

QElapsedTimer m_elapsedTimer
 
int m_lastPaintTime {0}
 
int m_lastPendingTime {0}
 
std::function< void(const KisPaintInformation &, const KisPaintInformation &) m_paintLine )
 
QQueue< TimedPaintInfom_paintQueue
 
QTimer m_paintTimer
 
std::function< void()> m_requestUpdateOutline
 

Detailed Description

Definition at line 20 of file KisStabilizerDelayedPaintHelper.h.

Constructor & Destructor Documentation

◆ KisStabilizerDelayedPaintHelper()

KisStabilizerDelayedPaintHelper::KisStabilizerDelayedPaintHelper ( )

Definition at line 17 of file KisStabilizerDelayedPaintHelper.cpp.

18{
19 connect(&m_paintTimer, SIGNAL(timeout()), SLOT(stabilizerDelayedPaintTimer()));
20}
connect(this, SIGNAL(optionsChanged()), this, SLOT(saveOptions()))

References connect(), m_paintTimer, and stabilizerDelayedPaintTimer().

◆ ~KisStabilizerDelayedPaintHelper()

KisStabilizerDelayedPaintHelper::~KisStabilizerDelayedPaintHelper ( )
inlineoverride

Definition at line 43 of file KisStabilizerDelayedPaintHelper.h.

43{}

Member Function Documentation

◆ cancel()

void KisStabilizerDelayedPaintHelper::cancel ( )

Definition at line 73 of file KisStabilizerDelayedPaintHelper.cpp.

73 {
74 m_paintTimer.stop();
75 m_paintQueue.clear();
76}

References m_paintQueue, and m_paintTimer.

◆ end()

void KisStabilizerDelayedPaintHelper::end ( )

Definition at line 59 of file KisStabilizerDelayedPaintHelper.cpp.

59 {
60 m_paintTimer.stop();
61 m_elapsedTimer.invalidate();
62 if (m_paintQueue.isEmpty()) {
63 return;
64 }
65 TimedPaintInfo dequeued = m_paintQueue.dequeue();
66 while (!m_paintQueue.isEmpty()) {
67 const TimedPaintInfo dequeued2 = m_paintQueue.dequeue();
68 m_paintLine(dequeued.paintInfo, dequeued2.paintInfo);
69 dequeued = dequeued2;
70 }
71}
std::function< void(const KisPaintInformation &, const KisPaintInformation &) m_paintLine)

References m_elapsedTimer, m_paintLine, m_paintQueue, m_paintTimer, and KisStabilizerDelayedPaintHelper::TimedPaintInfo::paintInfo.

◆ hasLastPaintInformation()

bool KisStabilizerDelayedPaintHelper::hasLastPaintInformation ( ) const
inline

Definition at line 49 of file KisStabilizerDelayedPaintHelper.h.

49 {
50 return !m_paintQueue.isEmpty();
51 }

◆ lastPaintInformation()

KisPaintInformation KisStabilizerDelayedPaintHelper::lastPaintInformation ( ) const
inline

Definition at line 53 of file KisStabilizerDelayedPaintHelper.h.

53 {
54 // Please call hasLastPaintInformation before this
55 return m_paintQueue.head().paintInfo;
56 }

◆ paintSome()

void KisStabilizerDelayedPaintHelper::paintSome ( )

Definition at line 45 of file KisStabilizerDelayedPaintHelper.cpp.

45 {
46 // This function is also called from KisToolFreehandHelper::paint
48 if (m_paintQueue.isEmpty()) {
49 return;
50 }
51 int now = m_lastPaintTime;
52 // Always keep one in the queue since painting requires two points
53 while (m_paintQueue.size() > 1 && m_paintQueue.head().elapsedTime <= now) {
54 const TimedPaintInfo dequeued = m_paintQueue.dequeue();
55 m_paintLine(dequeued.paintInfo, m_paintQueue.head().paintInfo);
56 }
57}

References m_elapsedTimer, m_lastPaintTime, m_paintLine, m_paintQueue, and KisStabilizerDelayedPaintHelper::TimedPaintInfo::paintInfo.

◆ running()

bool KisStabilizerDelayedPaintHelper::running ( ) const
inline

Definition at line 45 of file KisStabilizerDelayedPaintHelper.h.

45 {
46 return m_paintTimer.isActive();
47 }

◆ setPaintLineCallback()

void KisStabilizerDelayedPaintHelper::setPaintLineCallback ( std::function< void(const KisPaintInformation &, const KisPaintInformation &)> paintLine)
inline

Definition at line 58 of file KisStabilizerDelayedPaintHelper.h.

58 {
60 }
void paintLine(PaintOp &op, const KisPaintInformation &pi1, const KisPaintInformation &pi2, KisDistanceInformation *currentDistance, bool fanCornersEnabled, qreal fanCornersStep)

◆ setUpdateOutlineCallback()

void KisStabilizerDelayedPaintHelper::setUpdateOutlineCallback ( std::function< void()> requestUpdateOutline)
inline

Definition at line 62 of file KisStabilizerDelayedPaintHelper.h.

62 {
63 m_requestUpdateOutline = requestUpdateOutline;
64 }

◆ stabilizerDelayedPaintTimer

void KisStabilizerDelayedPaintHelper::stabilizerDelayedPaintTimer ( )
privateslot

Definition at line 78 of file KisStabilizerDelayedPaintHelper.cpp.

78 {
80 return;
81 }
82 paintSome();
83 // Explicitly update the outline because this is outside the pointer event
85}
constexpr int fixedPaintTimerInterval

References fixedPaintTimerInterval, m_elapsedTimer, m_lastPaintTime, m_requestUpdateOutline, and paintSome().

◆ start()

◆ update()

void KisStabilizerDelayedPaintHelper::update ( const QVector< KisPaintInformation > & newPaintInfos)

Definition at line 34 of file KisStabilizerDelayedPaintHelper.cpp.

34 {
35 int now = m_elapsedTimer.elapsed();
36 int delayedPaintInterval = m_elapsedTimer.elapsed() - m_lastPendingTime;
37 for (int i = 0; i < newPaintInfos.size(); i++) {
38 // TODO: Risk of overflowing?
39 int offsetTime = (delayedPaintInterval * i) / newPaintInfos.size();
40 m_paintQueue.enqueue(TimedPaintInfo(now + offsetTime, newPaintInfos[i]));
41 }
43}

References m_elapsedTimer, m_lastPendingTime, and m_paintQueue.

Member Data Documentation

◆ m_elapsedTimer

QElapsedTimer KisStabilizerDelayedPaintHelper::m_elapsedTimer
private

Definition at line 35 of file KisStabilizerDelayedPaintHelper.h.

◆ m_lastPaintTime

int KisStabilizerDelayedPaintHelper::m_lastPaintTime {0}
private

Definition at line 34 of file KisStabilizerDelayedPaintHelper.h.

34{0};

◆ m_lastPendingTime

int KisStabilizerDelayedPaintHelper::m_lastPendingTime {0}
private

Definition at line 33 of file KisStabilizerDelayedPaintHelper.h.

33{0};

◆ m_paintLine

std::function<void(const KisPaintInformation &, const KisPaintInformation &) KisStabilizerDelayedPaintHelper::m_paintLine)
private

Definition at line 38 of file KisStabilizerDelayedPaintHelper.h.

◆ m_paintQueue

QQueue<TimedPaintInfo> KisStabilizerDelayedPaintHelper::m_paintQueue
private

Definition at line 32 of file KisStabilizerDelayedPaintHelper.h.

◆ m_paintTimer

QTimer KisStabilizerDelayedPaintHelper::m_paintTimer
private

Definition at line 31 of file KisStabilizerDelayedPaintHelper.h.

◆ m_requestUpdateOutline

std::function<void()> KisStabilizerDelayedPaintHelper::m_requestUpdateOutline
private

Definition at line 39 of file KisStabilizerDelayedPaintHelper.h.


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