Index: libs/ui/tool/KisStabilizerDelayedPaintHelper.h =================================================================== --- libs/ui/tool/KisStabilizerDelayedPaintHelper.h +++ libs/ui/tool/KisStabilizerDelayedPaintHelper.h @@ -19,9 +19,9 @@ #ifndef KIS_STABILIZER_DELAYED_PAINT_HELPER_H #define KIS_STABILIZER_DELAYED_PAINT_HELPER_H +#include #include #include -#include #include #include @@ -40,21 +40,21 @@ TimedPaintInfo(int elapsedTime, KisPaintInformation paintInfo); }; - QTimer m_paintTimer; + bool m_isRunning; QQueue m_paintQueue; int m_lastPendingTime; + int m_paintInterval; QElapsedTimer m_elapsedTimer; // Callbacks std::function m_paintLine; - std::function m_requestUpdateOutline; public: KisStabilizerDelayedPaintHelper(); ~KisStabilizerDelayedPaintHelper() override {} bool running() const { - return m_paintTimer.isActive(); + return m_isRunning; } bool hasLastPaintInformation() const { @@ -70,17 +70,11 @@ m_paintLine = paintLine; } - void setUpdateOutlineCallback(std::function requestUpdateOutline) { - m_requestUpdateOutline = requestUpdateOutline; - } - void start(int paintInterval, const KisPaintInformation &firstPaintInfo); void update(const QVector &newPaintInfos); + void paintSome(); void end(); void cancel(); - -private Q_SLOTS: - void stabilizerDelayedPaint(bool isEndStroke = false); }; #endif // KIS_STABILIZER_DELAYED_PAINT_HELPER_H Index: libs/ui/tool/KisStabilizerDelayedPaintHelper.cpp =================================================================== --- libs/ui/tool/KisStabilizerDelayedPaintHelper.cpp +++ libs/ui/tool/KisStabilizerDelayedPaintHelper.cpp @@ -18,6 +18,8 @@ #include "KisStabilizerDelayedPaintHelper.h" +#include + KisStabilizerDelayedPaintHelper::TimedPaintInfo::TimedPaintInfo(int elapsedTime, KisPaintInformation paintInfo) : elapsedTime(elapsedTime) , paintInfo(paintInfo) @@ -26,18 +28,17 @@ KisStabilizerDelayedPaintHelper::KisStabilizerDelayedPaintHelper() { - connect(&m_paintTimer, SIGNAL(timeout()), SLOT(stabilizerDelayedPaint())); } void KisStabilizerDelayedPaintHelper::start(int paintInterval, const KisPaintInformation &firstPaintInfo) { if (running()) { cancel(); } - m_paintTimer.setInterval(paintInterval); - m_paintTimer.start(); + m_paintInterval = paintInterval; m_elapsedTimer.start(); m_lastPendingTime = m_elapsedTimer.elapsed(); m_paintQueue.enqueue(TimedPaintInfo(m_lastPendingTime, firstPaintInfo)); + m_isRunning = true; } void KisStabilizerDelayedPaintHelper::update(const QVector &newPaintInfos) { @@ -51,35 +52,32 @@ m_lastPendingTime = now; } -void KisStabilizerDelayedPaintHelper::end() { - stabilizerDelayedPaint(true); - m_paintTimer.stop(); -} - -void KisStabilizerDelayedPaintHelper::cancel() { - m_paintTimer.stop(); - m_paintQueue.clear(); -} - -void KisStabilizerDelayedPaintHelper::stabilizerDelayedPaint(bool isEndStroke) { +void KisStabilizerDelayedPaintHelper::paintSome() { if (m_paintQueue.isEmpty()) { return; } - if (isEndStroke) { - TimedPaintInfo dequeued = m_paintQueue.dequeue(); - while (!m_paintQueue.isEmpty()) { - const TimedPaintInfo dequeued2 = m_paintQueue.dequeue(); - m_paintLine(dequeued.paintInfo, dequeued2.paintInfo); - dequeued = dequeued2; - } - m_requestUpdateOutline(); - return; - } int now = m_elapsedTimer.elapsed(); // Always keep one in the queue since painting requires two points while (m_paintQueue.size() > 1 && m_paintQueue.head().elapsedTime <= now) { const TimedPaintInfo dequeued = m_paintQueue.dequeue(); m_paintLine(dequeued.paintInfo, m_paintQueue.head().paintInfo); } - m_requestUpdateOutline(); +} + +void KisStabilizerDelayedPaintHelper::end() { + m_isRunning = false; + if (m_paintQueue.isEmpty()) { + return; + } + TimedPaintInfo dequeued = m_paintQueue.dequeue(); + while (!m_paintQueue.isEmpty()) { + const TimedPaintInfo dequeued2 = m_paintQueue.dequeue(); + m_paintLine(dequeued.paintInfo, dequeued2.paintInfo); + dequeued = dequeued2; + } +} + +void KisStabilizerDelayedPaintHelper::cancel() { + m_isRunning = false; + m_paintQueue.clear(); } Index: libs/ui/tool/kis_tool_freehand_helper.h =================================================================== --- libs/ui/tool/kis_tool_freehand_helper.h +++ libs/ui/tool/kis_tool_freehand_helper.h @@ -137,6 +137,8 @@ const QPointF &control2, const KisPaintInformation &pi2); + virtual void timerEvent(QTimerEvent *event) override; + private: void paint(KisPaintInformation &info); void paintBezierSegment(KisPaintInformation pi1, KisPaintInformation pi2, Index: libs/ui/tool/kis_tool_freehand_helper.cpp =================================================================== --- libs/ui/tool/kis_tool_freehand_helper.cpp +++ libs/ui/tool/kis_tool_freehand_helper.cpp @@ -18,6 +18,7 @@ #include "kis_tool_freehand_helper.h" +#include #include #include @@ -97,7 +98,7 @@ // Stabilizer data QQueue stabilizerDeque; - QTimer stabilizerPollTimer; + QBasicTimer stabilizerPollTimer; KisStabilizedEventsSampler stabilizedSampler; KisStabilizerDelayedPaintHelper stabilizerDelayedPaintHelper; @@ -124,16 +125,11 @@ m_d->strokeTimeoutTimer.setSingleShot(true); connect(&m_d->strokeTimeoutTimer, SIGNAL(timeout()), SLOT(finishStroke())); connect(&m_d->airbrushingTimer, SIGNAL(timeout()), SLOT(doAirbrushing())); - connect(&m_d->stabilizerPollTimer, SIGNAL(timeout()), SLOT(stabilizerPollAndPaint())); m_d->stabilizerDelayedPaintHelper.setPaintLineCallback( [this](const KisPaintInformation &pi1, const KisPaintInformation &pi2) { paintLine(pi1, pi2); }); - m_d->stabilizerDelayedPaintHelper.setUpdateOutlineCallback( - [this]() { - emit requestExplicitUpdateOutline(); - }); } KisToolFreehandHelper::~KisToolFreehandHelper() @@ -586,6 +582,10 @@ if (m_d->smoothingOptions->smoothingType() == KisSmoothingOptions::STABILIZER) { m_d->stabilizedSampler.addEvent(info); + if (m_d->stabilizerDelayedPaintHelper.running()) { + // Paint here so we don't have to rely on the timer + m_d->stabilizerDelayedPaintHelper.paintSome(); + } } else { m_d->previousPaintInformation = info; } @@ -678,8 +678,7 @@ // Poll and draw regularly KisConfig cfg; int stabilizerSampleSize = cfg.stabilizerSampleSize(); - m_d->stabilizerPollTimer.setInterval(stabilizerSampleSize); - m_d->stabilizerPollTimer.start(); + m_d->stabilizerPollTimer.start(stabilizerSampleSize, Qt::PreciseTimer, this); int delayedPaintInterval = cfg.stabilizerDelayedPaintInterval(); if (delayedPaintInterval < stabilizerSampleSize) { @@ -976,3 +975,9 @@ m_d->canvasMirroredH = mirrored; } +void KisToolFreehandHelper::timerEvent(QTimerEvent *event) +{ + if (event->timerId() == m_d->stabilizerPollTimer.timerId()) { + stabilizerPollAndPaint(); + } +}