diff --git a/libs/image/kis_signal_compressor.h b/libs/image/kis_signal_compressor.h --- a/libs/image/kis_signal_compressor.h +++ b/libs/image/kis_signal_compressor.h @@ -36,7 +36,7 @@ * * FIRST_ACTIVE emits the timeout() event immediately and sets a timer of * duration \p delay. If the compressor is triggered during this time, it will - * fire another signal at the end of the delay period. Further events are + * wait until the end of the delay period to fire the signal. Further events are * ignored until the timer elapses. Think of it as a queue with size 1, and * where the leading element is popped every \p delay ms. * diff --git a/plugins/tools/basictools/kis_tool_line.h b/plugins/tools/basictools/kis_tool_line.h --- a/plugins/tools/basictools/kis_tool_line.h +++ b/plugins/tools/basictools/kis_tool_line.h @@ -77,6 +77,7 @@ void paintLine(QPainter& gc, const QRect& rc); QPointF straightLine(QPointF point); void updatePreview(); + void updatePreviewTimer(bool showGuide); virtual QWidget* createOptionWidget(); void endStroke(); diff --git a/plugins/tools/basictools/kis_tool_line.cc b/plugins/tools/basictools/kis_tool_line.cc --- a/plugins/tools/basictools/kis_tool_line.cc +++ b/plugins/tools/basictools/kis_tool_line.cc @@ -64,7 +64,7 @@ m_strokeIsRunning(false), m_infoBuilder(new KisConverterPaintingInformationBuilder(getCoordinatesConverter(canvas))), m_helper(new KisToolLineHelper(m_infoBuilder.data(), kundo2_i18n("Draw Line"))), - m_strokeUpdateCompressor(500, KisSignalCompressor::FIRST_ACTIVE), + m_strokeUpdateCompressor(500, KisSignalCompressor::POSTPONE), m_longStrokeUpdateCompressor(1000, KisSignalCompressor::FIRST_INACTIVE) { setObjectName("tool_line"); @@ -120,8 +120,9 @@ // read values in from configuration m_chkUseSensors->setChecked(configGroup.readEntry("useSensors", true)); - m_chkShowOutline->setChecked(configGroup.readEntry("showOutline", false)); + m_chkShowOutline->setChecked(configGroup.readEntry("showOutline", true)); + updatePreviewTimer(m_chkShowOutline); return widget; } @@ -132,6 +133,7 @@ void KisToolLine::setShowOutline(bool value) { + updatePreviewTimer(value); configGroup.writeEntry("showOutline", value); } @@ -145,6 +147,22 @@ endStroke(); } +void KisToolLine::updatePreviewTimer(bool showOutline) +{ + // If the user disables the guideline, we will want to try to draw some + // preview lines even if they're slow, so set the timer to FIRST_ACTIVE. If + // the user has a guideline showing, we can take our time and wait until the + // user has hovered the mouse for 200ms before doing any rendering. + if (showOutline) { + m_strokeUpdateCompressor.setMode(KisSignalCompressor::POSTPONE); + m_strokeUpdateCompressor.setDelay(200); + } else { + m_strokeUpdateCompressor.setMode(KisSignalCompressor::FIRST_ACTIVE); + m_strokeUpdateCompressor.setDelay(500); + } +} + + void KisToolLine::paint(QPainter& gc, const KoViewConverter &converter) { Q_UNUSED(converter); @@ -210,7 +228,10 @@ m_helper->addPoint(event); } + // If the cursor has moved a significant amount, immediately clear the + // current preview and redraw. Otherwise, do slow redraws periodically. if ((pixelToView(m_lastUpdatedPoint) - pixelToView(pos)).manhattanLength() > 10) { + m_helper->clearPaint(); m_longStrokeUpdateCompressor.stop(); m_strokeUpdateCompressor.start(); m_lastUpdatedPoint = pos; diff --git a/plugins/tools/basictools/kis_tool_line_helper.h b/plugins/tools/basictools/kis_tool_line_helper.h --- a/plugins/tools/basictools/kis_tool_line_helper.h +++ b/plugins/tools/basictools/kis_tool_line_helper.h @@ -45,6 +45,7 @@ void translatePoints(const QPointF &offset); void end(); void cancel(); + void clearPaint(); using KisToolFreehandHelper::isRunning; diff --git a/plugins/tools/basictools/kis_tool_line_helper.cpp b/plugins/tools/basictools/kis_tool_line_helper.cpp --- a/plugins/tools/basictools/kis_tool_line_helper.cpp +++ b/plugins/tools/basictools/kis_tool_line_helper.cpp @@ -161,3 +161,11 @@ cancelPaint(); m_d->linePoints.clear(); } + + +void KisToolLineHelper::clearPaint() +{ + if (!m_d->enabled) return; + + cancelPaint(); +}