Commit 008503fb authored by Dmitry Kazakov's avatar Dmitry Kazakov

Make shape painting tools unblocking (use strokes)

Opening a waiting dialog may make the shortcuts matcher unhappy,
so we should avoid that.

CCBUG:409968,408826,409275
parent b8870d02
......@@ -51,6 +51,7 @@
#include <commands/KoKeepShapesSelectedCommand.h>
#include "kis_selection_mask.h"
#include "kis_shape_selection.h"
#include "kis_processing_applicator.h"
KisToolShape::KisToolShape(KoCanvasBase * canvas, const QCursor & cursor)
......@@ -223,13 +224,13 @@ void KisToolShape::addShape(KoShape* shape)
parentCommand->setText(cmd->text());
new KoKeepShapesSelectedCommand(oldSelectedShapes, {shape}, canvas()->selectedShapesProxy(), true, parentCommand);
canvas()->addCommand(parentCommand);
KisProcessingApplicator::runSingleCommandStroke(image(), cmd);
}
void KisToolShape::addPathShape(KoPathShape* pathShape, const KUndo2MagicString& name)
{
KisNodeSP node = currentNode();
if (!node || !blockUntilOperationsFinished()) {
if (!node) {
return;
}
......@@ -253,6 +254,4 @@ void KisToolShape::addPathShape(KoPathShape* pathShape, const KUndo2MagicString&
addShape(pathShape);
}
notifyModified();
}
......@@ -54,7 +54,7 @@ void KisToolEllipse::finishRect(const QRectF& rect, qreal roundCornersX, qreal r
Q_UNUSED(roundCornersX);
Q_UNUSED(roundCornersY);
if (rect.isEmpty() || !blockUntilOperationsFinished())
if (rect.isEmpty())
return;
const KisToolShape::ShapeAddInfo info =
......@@ -78,6 +78,5 @@ void KisToolEllipse::finishRect(const QRectF& rect, qreal roundCornersX, qreal r
addShape(shape);
}
notifyModified();
}
......@@ -57,6 +57,9 @@
#include <kis_cursor.h>
#include <kis_config.h>
#include "kis_resources_snapshot.h"
#include "kis_command_utils.h"
#include "kis_processing_applicator.h"
#include "kis_processing_visitor.h"
KisToolGradient::KisToolGradient(KoCanvasBase * canvas)
......@@ -145,44 +148,58 @@ void KisToolGradient::endPrimaryAction(KoPointerEvent *event)
CHECK_MODE_SANITY_OR_RETURN(KisTool::PAINT_MODE);
setMode(KisTool::HOVER_MODE);
if (!currentNode() || !blockUntilOperationsFinished())
if (!currentNode())
return;
if (m_startPos == m_endPos) {
return;
}
KisPaintDeviceSP device;
KisImageSP image = this->image();
KisResourcesSnapshotSP resources =
new KisResourcesSnapshot(image, currentNode(), this->canvas()->resourceManager());
if (image && (device = resources->currentNode()->paintDevice())) {
QApplication::setOverrideCursor(Qt::BusyCursor);
if (image && resources->currentNode()->paintDevice()) {
// TODO: refactor out local variables when we switch to C++14
QPointF startPos = m_startPos;
QPointF endPos = m_endPos;
KisGradientPainter::enumGradientShape shape = m_shape;
KisGradientPainter::enumGradientRepeat repeat = m_repeat;
bool reverse = m_reverse;
double antiAliasThreshold = m_antiAliasThreshold;
KUndo2MagicString actionName = kundo2_i18n("Gradient");
KisUndoAdapter *undoAdapter = image->undoAdapter();
undoAdapter->beginMacro(actionName);
KisGradientPainter painter(device, resources->activeSelection());
resources->setupPainter(&painter);
painter.beginTransaction();
KisCanvas2 * canvas = dynamic_cast<KisCanvas2 *>(this->canvas());
KoUpdaterPtr updater = canvas->viewManager()->createUnthreadedUpdater(i18nc("@info:progress", "Gradient..."));
painter.setProgress(updater);
painter.setGradientShape(m_shape);
painter.paintGradient(m_startPos, m_endPos, m_repeat, m_antiAliasThreshold, m_reverse, 0, 0, image->width(), image->height());
painter.endTransaction(undoAdapter);
undoAdapter->endMacro();
QApplication::restoreOverrideCursor();
currentNode()->setDirty();
notifyModified();
KisProcessingApplicator applicator(image, resources->currentNode(),
KisProcessingApplicator::NONE,
KisImageSignalVector() << ModifiedSignal,
actionName);
applicator.applyCommand(
new KisCommandUtils::LambdaCommand(
[resources, startPos, endPos,
shape, repeat, reverse, antiAliasThreshold] () mutable {
KisNodeSP node = resources->currentNode();
KisPaintDeviceSP device = node->paintDevice();
KisProcessingVisitor::ProgressHelper helper(node);
const QRect bounds = device->defaultBounds()->bounds();
KisGradientPainter painter(device, resources->activeSelection());
resources->setupPainter(&painter);
painter.setProgress(helper.updater());
painter.beginTransaction();
painter.setGradientShape(shape);
painter.paintGradient(startPos, endPos,
repeat, antiAliasThreshold,
reverse, 0, 0,
bounds.width(), bounds.height());
return painter.endAndTakeTransaction();
}));
applicator.end();
}
canvas()->updateCanvas(convertToPt(currentImage()->bounds()));
}
......
......@@ -55,7 +55,7 @@ void KisToolRectangle::resetCursorStyle()
void KisToolRectangle::finishRect(const QRectF &rect, qreal roundCornersX, qreal roundCornersY)
{
if (rect.isNull() || !blockUntilOperationsFinished())
if (rect.isNull())
return;
const KisToolShape::ShapeAddInfo info =
......@@ -94,7 +94,5 @@ void KisToolRectangle::finishRect(const QRectF &rect, qreal roundCornersX, qreal
addShape(shape);
}
notifyModified();
}
......@@ -50,8 +50,6 @@ void KisToolPolygon::resetCursorStyle()
void KisToolPolygon::finishPolyline(const QVector<QPointF>& points)
{
if (!blockUntilOperationsFinished()) return;
const KisToolShape::ShapeAddInfo info =
shouldAddShape(currentNode());
......
......@@ -54,8 +54,6 @@ QWidget* KisToolPolyline::createOptionWidget()
void KisToolPolyline::finishPolyline(const QVector<QPointF>& points)
{
if (!blockUntilOperationsFinished()) return;
const KisToolShape::ShapeAddInfo info =
shouldAddShape(currentNode());
......@@ -80,6 +78,5 @@ void KisToolPolyline::finishPolyline(const QVector<QPointF>& points)
addShape(path);
}
notifyModified();
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment